@@ -0,0 +1,18 @@
+{
+ "name": "@opencode-ai/util",
+ "version": "0.0.0",
+ "private": true,
+ "type": "module",
+ "exports": {
+ "./*": "./src/*.ts"
+ },
+ "scripts": {
+ "typecheck": "tsc --noEmit"
+ "dependencies": {
+ "zod": "catalog:"
+ "devDependencies": {
+ "typescript": "catalog:"
+ }
+}
@@ -0,0 +1,11 @@
+import { z } from "zod"
+
+export function fn<T extends z.ZodType, Result>(schema: T, cb: (input: z.infer<T>) => Result) {
+ const result = (input: z.infer<T>) => {
+ const parsed = schema.parse(input)
+ return cb(parsed)
+ result.force = (input: z.infer<T>) => cb(input)
+ result.schema = schema
+ return result
@@ -0,0 +1,3 @@
+export function iife<T>(fn: () => T) {
+ return fn()
+export function lazy<T>(fn: () => T) {
+ let value: T | undefined
+ let loaded = false
+ return (): T => {
+ if (loaded) return value as T
+ loaded = true
+ value = fn()
+ return value as T
@@ -0,0 +1,14 @@
+ "compilerOptions": {
+ "target": "ESNext",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "skipLibCheck": true,
+ "allowSyntheticDefaultImports": true,
+ "esModuleInterop": true,
+ "allowJs": true,
+ "noEmit": true,
+ "strict": true,
+ "isolatedModules": true