UNPKG

@code-pushup/models

Version:

Model definitions and validators for the Code PushUp CLI

23 lines (22 loc) 1.7 kB
import { z } from 'zod/v4'; import type { $ZodFunction } from 'zod/v4/core'; /** * Converts Zod v4 function factory (returned by `z.function`) to Zod schema. * * Supports asynchronous functions. For synchronous functions, you can use {@link convertSyncZodFunctionToSchema}. * * @param factory `z.function({ input: [...], output: ... })` * @returns Zod schema with compile-time and runtime validations. */ export declare function convertAsyncZodFunctionToSchema<T extends $ZodFunction>(factory: T): z.ZodPipe<z.ZodCustom<unknown, unknown>, z.ZodTransform<Awaited<Parameters<T["implementAsync"]>[0] extends infer T_1 ? T_1 extends Parameters<T["implementAsync"]>[0] ? T_1 extends z.core.$InferOuterFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut> ? T_1 : z.core.$InferOuterFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut> : never : never>, unknown>>; /** * Converts Zod v4 function factory (returned by `z.function`) to Zod schema. * * **IMPORTANT!** Use for synchronous functions only. For asynchronous functions use {@link convertAsyncZodFunctionToSchema}. * * @throws `Encountered Promise during synchronous parse. Use .parseAsync() instead.` if used with async functions. * * @param factory `z.function({ input: [...], output: ... })` * @returns Zod schema with compile-time and runtime validations. */ export declare function convertSyncZodFunctionToSchema<T extends $ZodFunction>(factory: T): z.ZodPipe<z.ZodCustom<unknown, unknown>, z.ZodTransform<(...args: Parameters<T["_output"]>) => ReturnType<Parameters<T["implement"]>[0]> extends ReturnType<T["_output"]> ? ReturnType<Parameters<T["implement"]>[0]> : ReturnType<T["_output"]>, unknown>>;