diff options
Diffstat (limited to 'cloud/core/src/util/fn.ts')
| -rw-r--r-- | cloud/core/src/util/fn.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/cloud/core/src/util/fn.ts b/cloud/core/src/util/fn.ts new file mode 100644 index 000000000..038a50719 --- /dev/null +++ b/cloud/core/src/util/fn.ts @@ -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 +} |
