import type { z } from "zod/v4"; import type { GenericDataModel } from "convex/server"; import type { PropertyValidators, GenericValidator, Validator } from "convex/values"; import { ConvexBuilderWithFunctionKind } from "../ConvexBuilderWithFunctionKind.js"; import type { ConvexMiddleware } from "../middleware.js"; import type { FunctionType, Context, EmptyObject, ConvexArgsValidator, ConvexReturnsValidator, ConvexBuilderDef, handlerArgsType, handlerReturnType } from "../types.js"; export declare function isZodSchema(value: unknown): value is z.ZodType; type PublicScalar = string | number | boolean | null; /** The shape of each entry in a ConvexError's `data.ZodError`. */ export type PublicZodIssue = { code: string; message: string; path: (string | number)[]; /** Branch failures of an `invalid_union` issue, one list per branch. */ errors?: PublicZodIssue[][]; /** Nested failures, e.g. a record key that failed its key schema. */ issues?: PublicZodIssue[]; [field: string]: PublicScalar | PublicScalar[] | PublicZodIssue[] | PublicZodIssue[][] | undefined; }; export type ValidatorInput = PropertyValidators | GenericValidator | z.ZodObject; export type ReturnsValidatorInput = GenericValidator | z.ZodType; /** * `.optional()` and `.default()` are what make a registered field optional, * including when they sit inside a wrapper the converter looks through (the * input stage of a pipe, `.nullable()`, `.readonly()`, `.catch()`, `z.lazy()`). */ type IsOptionalField = F extends z.ZodOptional | z.ZodDefault ? true : F extends z.ZodPipe ? IsOptionalField : F extends z.ZodNullable | z.ZodReadonly | z.ZodCatch | z.ZodLazy ? IsOptionalField : false; /** The value a client may send for a schema, per the registered validator. */ type ClientValue = F extends z.ZodPipe ? ClientValue : F extends z.ZodTransform ? any : F extends z.ZodDefault | z.ZodOptional ? ClientValue | undefined : F extends z.ZodNullable ? ClientValue | null : F extends z.ZodObject ? ClientObject : F extends z.ZodArray ? ClientValue[] : F extends z.ZodUnion ? ClientValue : F extends z.ZodRecord ? IsOptionalField extends true ? Partial & PropertyKey, ClientValue>> : Record & PropertyKey, ClientValue> : F extends z.ZodTuple ? ClientTuple : F extends z.ZodNonOptional ? Exclude, undefined> : F extends z.ZodCatch | z.ZodReadonly | z.ZodLazy ? ClientValue : z.output; type ClientTuple = Items extends readonly unknown[] ? Rest extends z.ZodType ? [...{ [I in keyof Items]: ClientValue; }, ...ClientValue[]] : { [I in keyof Items]: ClientValue; } : never; type ClientObject = { [K in keyof Shape as IsOptionalField extends true ? never : K]: ClientValue; } & { [K in keyof Shape as IsOptionalField extends true ? K : never]?: ClientValue; }; /** * Args for a Zod object schema: one Convex validator type per declared field, * typed by what the client may send. The handler gets Zod's parsed output, * carried on the type-only `handlerArgsType` key. */ type ZodObjectArgsValidator> = { [K in keyof T["shape"]]: Validator, IsOptionalField extends true ? "optional" : "required", any>; } & { readonly [handlerArgsType]: z.output; }; export type ToConvexArgsValidator = T extends z.ZodObject ? ZodObjectArgsValidator : T extends ConvexArgsValidator ? T : ConvexArgsValidator; /** * Returns for a Zod schema: the client gets Zod's *output* type (what the * registered zodOutputToConvex validator checks), while the handler returns * the *input* type, which the schema then parses/transforms. */ export type ToConvexReturnsValidator = T extends z.ZodType ? Validator, "required", any> & { readonly [handlerReturnType]: z.input; } : T extends GenericValidator ? T : GenericValidator; /** * Zod plugin for fluent-convex. Extends the builder to accept Zod schemas * in `.input()` and `.returns()`, with full runtime validation including * refinements (`.min()`, `.max()`, `.email()`, etc.). * * Usage: * ```ts * import { WithZod } from "fluent-convex/zod"; * * export const myQuery = convex * .query() * .extend(WithZod) * .input(z.object({ count: z.number().min(1).max(100) })) * .handler(async (ctx, input) => { ... }) * .public(); * ``` */ export declare class WithZod extends ConvexBuilderWithFunctionKind { constructor(builderOrDef: ConvexBuilderWithFunctionKind | ConvexBuilderDef); /** * Preserve WithZod through the chain. When .use(), .input(), .returns() * create a new builder, they call _clone() which returns a new WithZod. */ protected _clone(def: ConvexBuilderDef): any; /** * Override use() to return WithZod type (runtime behavior is inherited from base). * * The suppression has to live on the last line of this doc comment, not in a * `//` comment: tsc drops `//` comments from the emitted .d.ts, and without it * consumers with `skipLibCheck: false` get TS2416 on this override. * @ts-ignore -- narrows return type from base to WithZod */ use(middleware: ConvexMiddleware): WithZod; /** * Accepts Zod schemas in addition to Convex validators. * When a Zod schema is detected, converts to Convex validator and sets * argsTransform for full runtime validation including refinements. * @ts-ignore -- widens the parameter to accept Zod schemas (see use() above) */ input(validator: UInput): WithZod, TReturnsValidator>; /** * Accepts Zod schemas in addition to Convex validators. * When a Zod schema is detected, converts to Convex validator and sets * returnsTransform for full runtime validation including refinements. * @ts-ignore -- widens the parameter to accept Zod schemas (see use() above) */ returns(validator: UReturns): WithZod>; } export {}; //# sourceMappingURL=withZod.d.ts.map