import { PaginationValidatorOptions } from "./querying/shared/filters.mjs"; import { ExactScalarSelection, ScalarPaginationSchema, ScalarSelection } from "./querying/filters.mjs"; import { zodToConvex } from "./zod-convex.mjs"; import { ConvexValidatorFromZod, Zid, convexToZod, zid, zid as zid$1 } from "convex-helpers/server/zod4"; import { PaginationResult, TableDefinition } from "convex/server"; import { z } from "zod"; import { GenericId } from "convex/values"; //#region src/zod-table.d.ts type FieldSchemas = Record; type FieldKey = Extract; /** * Opinionated lifecycle timestamps — every table has them, server-owned, * always excluded from insert/command boundaries. Maintained by the * `timestamps` trigger helper (see cvx-kit/triggers). */ declare const timestampFields: { createdAt: z.ZodOptional; updatedAt: z.ZodOptional; archivedAt: z.ZodOptional; }; type TimestampFields = typeof timestampFields; type ReservedStorageField = '_id' | '_creationTime' | keyof TimestampFields; type OwnedFields = { [Key in keyof Fields]: Key extends ReservedStorageField ? never : Fields[Key]; }; type SystemFields = { _id: Zid
; _creationTime: z.ZodNumber; }; export declare const TIMESTAMP_FIELDS: readonly ['createdAt', 'updatedAt', 'archivedAt']; export type TableBoundaryOptions[], CommandFields extends readonly FieldKey[], PublicFields extends readonly FieldKey[]> = { serverFields?: ServerFields; commandFields?: CommandFields & readonly Exclude, ServerFields[number] | keyof TimestampFields>[]; publicFields?: PublicFields; }; type StrictObject = z.ZodObject; type WriteFields[]> = Omit; type PartialFields = { [Key in keyof Fields]: z.ZodOptional; }; /** Options shared by the DTO return schema and row projector. * Promised contributions must be present, including in reusable options. * New extension schemas support validation only: no transforms, pipes, * coercion, preprocess, defaults, catches, or overwrites, even when nested. * Refinements must validate without mutating their input. */ export type DtoOptions = ([IncludeId] extends [true] ? { _id: IncludeId; } : { _id?: IncludeId; }) & (keyof Extension extends never ? { extend?: Extension; } : { extend: Extension; }); type DtoProjectionOptions = DtoOptions & { extend?: Record; values?: never; }; type ReservedDtoField = '_id' | '_creationTime' | 'tenant' | '__proto__' | (typeof TIMESTAMP_FIELDS)[number]; type DtoExtension = { [Key in keyof Extension]: Key extends keyof Public | ReservedDtoField ? never : Extension[Key] extends z.ZodPipe | z.ZodTransform ? never : unknown; }; type KnownExtension = string extends keyof Extension ? {} : Extension; type DtoSchema
= IncludeId extends true ? StrictObject; } & KnownExtension> : StrictObject>; type DtoRow = Row & (true extends IncludeId ? { _id: string; } : {}); type DtoValues = keyof Extension extends never ? { values?: never; } : { values: z.input>>; }; type DtoBoundary
= { dto(): StrictObject; dto(includeId: IncludeId): DtoSchema; dto(options: DtoProjectionOptions): DtoSchema; dto(options: DtoOptions & { extend?: DtoExtension; }): DtoSchema; toPublicDto(row: z.input>): z.output>; toPublicDto(row: DtoRow>, IncludeId>, includeId: IncludeId): z.output>; toPublicDto(row: DtoRow>, IncludeId>, options: DtoProjectionOptions): z.output>; toPublicDto(row: DtoRow>, IncludeId>, options: DtoOptions & { extend?: DtoExtension; } & DtoValues): z.output>; }; /** Named schema relationships keep generated declarations bounded and consumers fully typed. */ export type TableBoundary
[], CommandFields extends readonly FieldKey[], PublicFields extends readonly FieldKey[]> = DtoBoundary> & { paginationOpts>>(selection: ExactScalarSelection, Selection>, options?: PaginationValidatorOptions): ScalarPaginationSchema, Selection>; tableName: Table; storage: StrictObject; schema: ReturnType>; insertSchema: StrictObject>; updateSchema: StrictObject>>; commandInput: StrictObject>; publicDto: StrictObject>; table: TableDefinition, 'required'>>; insert(): StrictObject>; insert>>(omit: Mask): ZodObjectOmit>, Mask>; update(): StrictObject>>; update>>(omit: Mask): ZodObjectOmit>>, Mask>; tools: { insert: StrictObject>; update: StrictObject<{ data: StrictObject>>; id: z.ZodType, string>; }>; id: StrictObject<{ id: z.ZodType, string>; }>; }; }; /** Defines one table and derives its storage, document, write, and DTO boundaries. */ export declare function zodTable
[] = readonly [], const CommandFields extends readonly FieldKey[] = readonly [], const PublicFields extends readonly FieldKey[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields, options?: TableBoundaryOptions): TableBoundary; /** Reuses ordinary fields while deriving every boundary through zodTable. */ export declare function createTable(shared: Shared & OwnedFields):
[] = readonly [], const CommandFields extends readonly FieldKey[] = readonly [], const PublicFields extends readonly FieldKey[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields & { [Key in keyof Fields]: Key extends (string extends keyof Shared ? never : keyof Shared) ? never : Fields[Key]; }, options?: TableBoundaryOptions) => TableBoundary; declare const tenantFields: { tenant: z.ZodString; }; type TenantFields = typeof tenantFields; /** * A zodTable whose rows are tenant-owned: injects the server-owned `tenant` * field (the tenancy boundary — see cvx-kit/tenancy). Like timestamps, it is * excluded from insert/update/command boundaries; handlers stamp it from * ctx.tenant, row-level security matches on it, and the tenantOwnership * trigger forbids reassigning it. Expose it via publicFields only when a DTO * genuinely needs it. */ export declare function tenantTable
[] = readonly [], const CommandFields extends readonly FieldKey[] = readonly [], const PublicFields extends readonly FieldKey[] = readonly []>(tableName: Table, fields: (id: typeof zid$1) => Fields & OwnedFields & { [Key in keyof Fields]: Key extends 'tenant' ? never : Fields[Key]; }, options?: TableBoundaryOptions): TableBoundary; /** * Merges per-module table maps into the application schema map, rejecting * duplicate table names across modules — the module-registry combinator for * domain/table.ts: `defineSchema(createModule(catalogTables, salesTables))`. */ export declare function createModule>[]>(...maps: Maps): UnionToIntersection; type UnionToIntersection = (Union extends unknown ? (member: Union) => void : never) extends ((member: infer Intersection) => void) ? Intersection : never; /** * Cursor-pagination boundary schemas bridged from Convex's own validators: * `args.paginationOpts` for function args, `result` for the page shape. * Pair with `include(...).paginate(opts)` (cvx-kit/auth). The result object * is deliberately non-strict — Convex may attach engine fields (splitCursor, * pageStatus); the page items themselves are validated against the dto. * Note: under row-level security, pages may be SHORTER than numItems when * rules reject rows mid-page; cursors remain correct. */ /** Completeness of the requested page, independently of global isDone exhaustion. */ export type PageCompleteness = 'complete' | 'row-budget' | 'byte-budget' | 'native-limit' | 'result-cap'; export type EnginePaginationResult = PaginationResult & { paginationMode?: 'native-search'; completeness?: PageCompleteness; }; export declare function paginated(dto: Dto): { args: { paginationOpts: z.ZodObject<{ numItems: z.ZodNumber; cursor: z.ZodUnion; endCursor: z.ZodOptional>; id: z.ZodOptional; maximumRowsRead: z.ZodOptional; maximumBytesRead: z.ZodOptional; }, z.core.$strict>; }; result: z.ZodObject<{ page: z.ZodArray; paginationMode: z.ZodOptional>; isDone: z.ZodBoolean; continueCursor: z.ZodString; splitCursor: z.ZodOptional>; pageStatus: z.ZodOptional>>; completeness: z.ZodOptional>; }, z.core.$strip>; }; type VariantSchema = z.ZodDiscriminatedUnion[], string>; type VariantDiscriminator = Schema['_zod']['def']['discriminator']; type VariantTags = Extract[VariantDiscriminator], string>; type VariantBranch = Extract]: z.ZodLiteral; }, z.core.$strict>>; type VariantKeys = FieldKey['shape']>; /** Boundary mode supports strict object branches with one string literal tag each. */ export type VariantBoundaryOptions = { discriminator: VariantDiscriminator; timestamps?: boolean; variants: { [Tag in VariantTags]: { serverFields?: readonly Exclude, VariantDiscriminator>[]; commandFields?: readonly Exclude, VariantDiscriminator>[]; publicFields?: readonly (Exclude, VariantDiscriminator> | keyof TimestampFields)[]; }; }; }; type VariantMaskKeys = Config extends { [Key in Mask]?: readonly (infer Field)[]; } ? Extract : never; type CheckedVariantOptions> = { variants: { [Tag in keyof Options['variants']]: Tag extends VariantTags ? { commandFields?: readonly Exclude, VariantDiscriminator | VariantMaskKeys>[]; publicFields?: readonly (Exclude, VariantDiscriminator> | (Options extends { timestamps: true; } ? keyof TimestampFields : never))[]; } : never; }; }; type VariantMode = 'storage' | 'document' | 'insert' | 'update' | 'command' | 'commandUpdate' | 'public'; type VariantFields
, Discriminator extends string, Config, Timestamps extends boolean, Mode extends VariantMode> = Mode extends 'storage' ? Branch['shape'] & (true extends Timestamps ? TimestampFields : {}) : Mode extends 'document' ? VariantFields & SystemFields
: Mode extends 'public' | 'command' ? Pick, Extract, keyof VariantFields>> : Mode extends 'insert' ? Omit> : PartialFields, Discriminator>> & Pick>; type DerivedVariantBranches
, Mode extends VariantMode, IncludeId extends boolean, Branches extends readonly StrictObject[]> = { [Index in keyof Branches]: Branches[Index] extends StrictObject ? StrictObject, Options['variants'][Extract[VariantDiscriminator], keyof Options['variants']>], Options extends { timestamps: infer Enabled; } ? true extends Enabled ? true : false : false, Mode> & (IncludeId extends true ? { _id: Zid
; } : {})> : never; }; type DerivedVariant
, Mode extends VariantMode, IncludeId extends boolean = false> = IncludeId extends true ? z.ZodDiscriminatedUnion, VariantDiscriminator> : z.ZodDiscriminatedUnion, VariantDiscriminator>; export type VariantTableBoundary
> = { tableName: Table; storage: DerivedVariant; schema: DerivedVariant; insertSchema: DerivedVariant; updateSchema: DerivedVariant; commandInput: DerivedVariant; publicDto: DerivedVariant; table: TableDefinition, 'required'>>; dto(): DerivedVariant; dto(includeId: IncludeId): DerivedVariant; toPublicDto(row: z.input>): z.output>; toPublicDto(row: DtoRow>, IncludeId>, includeId: IncludeId): z.output>; tools: { id: StrictObject<{ id: z.ZodType, string>; }>; insert: z.ZodType>, z.input>>; update: StrictObject<{ id: z.ZodType, string>; data: z.ZodType>, z.input>>; }>; }; }; /** Legacy mode preserves arbitrary storage; the third argument opts into derived boundaries. */ export declare function zodVariantTable
(tableName: Table, storage: Schema): { tableName: Table; storage: Schema; insertSchema: Schema; table: TableDefinition>; }; export declare function zodVariantTable
>(tableName: Table, storage: Schema, options: Options & CheckedVariantOptions>): VariantTableBoundary; /** * A zid that presents as a plain string in generated JSON schemas so * LLM-tool inputs stay primitive, while keeping the Id type at compile time. */ export declare function jsonSafeZid
(tableName: Table): z.ZodType, string>; type ZodObjectOmit, OmitMask extends z.util.Mask> = Schema extends z.ZodObject ? z.ZodObject>>, Config> : never; declare function documentSchema(fields: Fields, tableName: Table): z.ZodObject; _creationTime: z.ZodNumber; } extends (infer T) ? { -readonly [P in keyof T]: T[P]; } : never, z.core.$strict>; //#endregion export { convexToZod, zid, zodToConvex }; //# sourceMappingURL=zod-table.d.mts.map