mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-21 16:54:58 +01:00
wip: gateway
This commit is contained in:
14
cloud/core/src/util/fn.ts
Normal file
14
cloud/core/src/util/fn.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export function fn<T extends z.ZodType, Result>(
|
||||
schema: T,
|
||||
cb: (input: z.output<T>) => Result,
|
||||
) {
|
||||
const result = (input: z.input<T>) => {
|
||||
const parsed = schema.parse(input)
|
||||
return cb(parsed)
|
||||
}
|
||||
result.force = (input: z.input<T>) => cb(input)
|
||||
result.schema = schema
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user