UNPKG

@serwist/build

Version:

A module that integrates into your build process, helping you generate a manifest of local files that should be precached.

28 lines (25 loc) 856 B
import { z } from "zod"; export const fn = <TInput extends [z.ZodType, ...z.ZodType[]], TOutput extends z.ZodType>({ input, output }: { input: TInput; output: TOutput }) => { const schema = z.function({ input: z.tuple(input), output, }); return z .custom<z.core.$InferInnerFunctionType<z.ZodTuple<TInput, null>, TOutput>>((arg) => typeof arg === "function") .transform((arg) => schema.implement(arg)); }; export const asyncFn = <TInput extends [z.ZodType, ...z.ZodType[]], TOutput extends z.ZodType>({ input, output, }: { input: TInput; output: TOutput; }) => { const schema = z.function({ input: z.tuple(input), output, }); return z .custom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<TInput, null>, TOutput>>((arg) => typeof arg === "function") .transform((arg) => schema.implementAsync(arg)); };