zodvex 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/__type-tests__/infer-returns.d.ts +2 -0
- package/dist/__type-tests__/infer-returns.d.ts.map +1 -0
- package/dist/__type-tests__/zodTable-inference.d.ts +2 -0
- package/dist/__type-tests__/zodTable-inference.d.ts.map +1 -0
- package/dist/builders.d.ts +173 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/codec.d.ts +11 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/custom.d.ts +147 -0
- package/dist/custom.d.ts.map +1 -0
- package/dist/ids.d.ts +23 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/index.d.ts +11 -599
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +203 -58
- package/dist/index.js.map +1 -1
- package/dist/mapping/core.d.ts +5 -0
- package/dist/mapping/core.d.ts.map +1 -0
- package/dist/mapping/handlers/enum.d.ts +4 -0
- package/dist/mapping/handlers/enum.d.ts.map +1 -0
- package/dist/mapping/handlers/index.d.ts +5 -0
- package/dist/mapping/handlers/index.d.ts.map +1 -0
- package/dist/mapping/handlers/nullable.d.ts +7 -0
- package/dist/mapping/handlers/nullable.d.ts.map +1 -0
- package/dist/mapping/handlers/record.d.ts +4 -0
- package/dist/mapping/handlers/record.d.ts.map +1 -0
- package/dist/mapping/handlers/union.d.ts +5 -0
- package/dist/mapping/handlers/union.d.ts.map +1 -0
- package/dist/mapping/index.d.ts +4 -0
- package/dist/mapping/index.d.ts.map +1 -0
- package/dist/mapping/types.d.ts +43 -0
- package/dist/mapping/types.d.ts.map +1 -0
- package/dist/mapping/utils.d.ts +6 -0
- package/dist/mapping/utils.d.ts.map +1 -0
- package/dist/registry.d.ts +110 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/results.d.ts +126 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/tables.d.ts +214 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/transform/index.d.ts +26 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +442 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/transform/transform.d.ts +47 -0
- package/dist/transform/transform.d.ts.map +1 -0
- package/dist/transform/traverse.d.ts +62 -0
- package/dist/transform/traverse.d.ts.map +1 -0
- package/dist/transform/types.d.ts +115 -0
- package/dist/transform/types.d.ts.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +55 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/wrappers.d.ts +22 -0
- package/dist/wrappers.d.ts.map +1 -0
- package/package.json +13 -6
- package/src/__type-tests__/infer-returns.ts +24 -0
- package/src/__type-tests__/zodTable-inference.ts +5 -5
- package/src/custom.ts +205 -28
- package/src/index.ts +1 -0
- package/src/mapping/core.ts +23 -11
- package/src/mapping/types.ts +6 -2
- package/src/results.ts +110 -0
- package/src/tables.ts +306 -28
- package/src/transform/index.ts +38 -0
- package/src/transform/transform.ts +409 -0
- package/src/transform/traverse.ts +320 -0
- package/src/transform/types.ts +128 -0
- package/src/types.ts +3 -2
- package/src/utils.ts +35 -0
- package/src/wrappers.ts +10 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,600 +1,12 @@
|
|
|
1
|
-
import { Customization } from 'convex-helpers/server/customFunctions';
|
|
2
1
|
export { customCtx } from 'convex-helpers/server/customFunctions';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_tableName: infer TableName;
|
|
15
|
-
} ? TableName : never;
|
|
16
|
-
type EnumToLiteralsTuple<T extends readonly [string, ...string[]]> = T['length'] extends 1 ? [VLiteral<T[0], 'required'>] : T['length'] extends 2 ? [VLiteral<T[0], 'required'>, VLiteral<T[1], 'required'>] : [
|
|
17
|
-
VLiteral<T[0], 'required'>,
|
|
18
|
-
VLiteral<T[1], 'required'>,
|
|
19
|
-
...{
|
|
20
|
-
[K in keyof T]: K extends '0' | '1' ? never : K extends keyof T ? VLiteral<T[K], 'required'> : never;
|
|
21
|
-
}[keyof T & number][]
|
|
22
|
-
];
|
|
23
|
-
type ZodValidator = Record<string, z.ZodTypeAny>;
|
|
24
|
-
type ConvexValidatorFromZodRequired<Z extends z.ZodTypeAny> = Z extends z.ZodOptional<infer T extends z.ZodTypeAny> ? VUnion<z.infer<T> | null, any[], 'required'> : ConvexValidatorFromZodBase<Z>;
|
|
25
|
-
type ConvexValidatorFromZodBase<Z extends z.ZodTypeAny> = IsZid<Z> extends true ? ExtractTableName<Z> extends infer TableName extends string ? VId<GenericId<TableName>, 'required'> : VAny<'required'> : Z extends z.ZodString ? VString<z.infer<Z>, 'required'> : Z extends z.ZodNumber ? VFloat64<z.infer<Z>, 'required'> : Z extends z.ZodDate ? VFloat64<number, 'required'> : Z extends z.ZodBigInt ? VInt64<z.infer<Z>, 'required'> : Z extends z.ZodBoolean ? VBoolean<z.infer<Z>, 'required'> : Z extends z.ZodNull ? VNull<null, 'required'> : Z extends z.ZodArray<infer T extends z.ZodTypeAny> ? VArray<z.infer<Z>, ConvexValidatorFromZodRequired<T>, 'required'> : Z extends z.ZodObject<infer T> ? VObject<z.infer<Z>, ConvexValidatorFromZodFieldsAuto<T>, 'required', string> : Z extends z.ZodUnion<infer T> ? T extends readonly [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]] ? VUnion<z.infer<Z>, any[], 'required'> : never : Z extends z.ZodLiteral<infer T> ? VLiteral<T, 'required'> : Z extends z.ZodEnum<infer T> ? T extends readonly [string, ...string[]] ? T['length'] extends 1 ? VLiteral<T[0], 'required'> : T['length'] extends 2 ? VUnion<T[number], [
|
|
26
|
-
VLiteral<T[0], 'required'>,
|
|
27
|
-
VLiteral<T[1], 'required'>
|
|
28
|
-
], 'required', never> : VUnion<T[number], EnumToLiteralsTuple<T>, 'required', never> : T extends Record<string, string | number> ? VUnion<T[keyof T], Array<VLiteral<T[keyof T], 'required'>>, 'required', never> : VUnion<string, any[], 'required', any> : Z extends z.ZodRecord<z.ZodString, infer V extends z.ZodTypeAny> ? VRecord<Record<string, z.infer<V>>, VString<string, 'required'>, ConvexValidatorFromZodRequired<V>, 'required', string> : Z extends z.ZodNullable<infer Inner extends z.ZodTypeAny> ? Inner extends z.ZodOptional<infer InnerInner extends z.ZodTypeAny> ? VOptional<VUnion<z.infer<InnerInner> | null, [
|
|
29
|
-
ConvexValidatorFromZodBase<InnerInner>,
|
|
30
|
-
VNull<null, 'required'>
|
|
31
|
-
], 'required'>> : VUnion<z.infer<Inner> | null, [
|
|
32
|
-
ConvexValidatorFromZodBase<Inner>,
|
|
33
|
-
VNull<null, 'required'>
|
|
34
|
-
], 'required'> : Z extends z.ZodAny ? VAny<'required'> : Z extends z.ZodUnknown ? VAny<'required'> : VAny<'required'>;
|
|
35
|
-
type ConvexValidatorFromZod<Z extends z.ZodTypeAny, Constraint extends 'required' | 'optional' = 'required'> = Z extends z.ZodAny ? VAny<'required'> : Z extends z.ZodUnknown ? VAny<'required'> : Z extends z.ZodDefault<infer T extends z.ZodTypeAny> ? ConvexValidatorFromZod<T, Constraint> : Z extends z.ZodOptional<infer T extends z.ZodTypeAny> ? T extends z.ZodNullable<infer Inner extends z.ZodTypeAny> ? VOptional<VUnion<z.infer<Inner> | null, any[], 'required'>> : Constraint extends 'required' ? VUnion<z.infer<T>, any[], 'required'> : VOptional<ConvexValidatorFromZod<T, 'required'>> : Z extends z.ZodNullable<infer T extends z.ZodTypeAny> ? VUnion<z.infer<T> | null, any[], Constraint> : IsZid<Z> extends true ? ExtractTableName<Z> extends infer TableName extends string ? VId<GenericId<TableName>, Constraint> : VAny<'required'> : Z extends z.ZodString ? VString<z.infer<Z>, Constraint> : Z extends z.ZodNumber ? VFloat64<z.infer<Z>, Constraint> : Z extends z.ZodDate ? VFloat64<number, Constraint> : Z extends z.ZodBigInt ? VInt64<z.infer<Z>, Constraint> : Z extends z.ZodBoolean ? VBoolean<z.infer<Z>, Constraint> : Z extends z.ZodNull ? VNull<null, Constraint> : Z extends z.ZodArray<infer T extends z.ZodTypeAny> ? VArray<z.infer<Z>, ConvexValidatorFromZodRequired<T>, Constraint> : Z extends z.ZodObject<infer T> ? VObject<z.infer<Z>, ConvexValidatorFromZodFields<T, 'required'>, Constraint, string> : Z extends z.ZodUnion<infer T> ? T extends readonly [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]] ? VUnion<z.infer<Z>, any[], Constraint> : never : Z extends z.ZodLiteral<infer T> ? VLiteral<T, Constraint> : Z extends z.ZodEnum<infer T> ? T extends readonly [string, ...string[]] ? T['length'] extends 1 ? VLiteral<T[0], Constraint> : T['length'] extends 2 ? VUnion<T[number], [
|
|
36
|
-
VLiteral<T[0], 'required'>,
|
|
37
|
-
VLiteral<T[1], 'required'>
|
|
38
|
-
], Constraint, never> : VUnion<T[number], EnumToLiteralsTuple<T>, Constraint, never> : T extends Record<string, string | number> ? VUnion<T[keyof T], Array<VLiteral<T[keyof T], 'required'>>, Constraint, never> : VUnion<string, any[], Constraint, any> : Z extends z.ZodRecord<z.ZodString, infer V extends z.ZodTypeAny> ? VRecord<Record<string, z.infer<V>>, VString<string, 'required'>, ConvexValidatorFromZodRequired<V>, Constraint, string> : VAny<'required'>;
|
|
39
|
-
type ConvexValidatorFromZodFields<T extends {
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
}, Constraint extends 'required' | 'optional' = 'required'> = {
|
|
42
|
-
[K in keyof T]: T[K] extends z.ZodTypeAny ? ConvexValidatorFromZod<T[K], Constraint> : VAny<'required'>;
|
|
43
|
-
};
|
|
44
|
-
type ConvexValidatorFromZodFieldsAuto<T extends {
|
|
45
|
-
[key: string]: any;
|
|
46
|
-
}> = {
|
|
47
|
-
[K in keyof T]: T[K] extends z.ZodOptional<any> ? ConvexValidatorFromZod<T[K], 'optional'> : T[K] extends z.ZodDefault<any> ? ConvexValidatorFromZod<T[K], 'optional'> : T[K] extends z.ZodNullable<any> ? ConvexValidatorFromZod<T[K], 'required'> : T[K] extends z.ZodEnum<any> ? ConvexValidatorFromZod<T[K], 'required'> : T[K] extends z.ZodTypeAny ? ConvexValidatorFromZod<T[K], 'required'> : VAny<'required'>;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
declare function zodToConvex<Z extends z.ZodTypeAny | ZodValidator>(zod: Z): Z extends z.ZodTypeAny ? ConvexValidatorFromZod<Z, 'required'> : Z extends ZodValidator ? ConvexValidatorFromZodFieldsAuto<Z> : never;
|
|
51
|
-
declare function zodToConvexFields<Z extends z.ZodRawShape>(zod: Z): ConvexValidatorFromZodFieldsAuto<Z>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* IDs + registry for Convex + Zod v4
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
declare const registryHelpers: {
|
|
58
|
-
getMetadata: (type: z.ZodTypeAny) => any;
|
|
59
|
-
setMetadata: (type: z.ZodTypeAny, meta: any) => WeakMap<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, any>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Create a Zod validator for a Convex Id
|
|
63
|
-
*
|
|
64
|
-
* Compatible with AI SDK and other tools that don't support transforms.
|
|
65
|
-
* Uses type-level branding instead of runtime transforms for GenericId<T> compatibility.
|
|
66
|
-
*
|
|
67
|
-
* @param tableName - The Convex table name for this ID
|
|
68
|
-
* @returns A Zod string validator typed as GenericId<TableName>
|
|
69
|
-
*/
|
|
70
|
-
declare function zid<TableName extends string>(tableName: TableName): z.ZodType<GenericId<TableName>> & {
|
|
71
|
-
_tableName: TableName;
|
|
72
|
-
};
|
|
73
|
-
type Zid<TableName extends string> = ReturnType<typeof zid<TableName>>;
|
|
74
|
-
|
|
75
|
-
declare function makeUnion(members: any[]): any;
|
|
76
|
-
declare function getObjectShape(obj: any): Record<string, any>;
|
|
77
|
-
|
|
78
|
-
type InferArgs<A> = A extends z.ZodObject<infer S> ? z.infer<z.ZodObject<S>> : A extends Record<string, z.ZodTypeAny> ? {
|
|
79
|
-
[K in keyof A]: z.infer<A[K]>;
|
|
80
|
-
} : A extends z.ZodTypeAny ? z.infer<A> : Record<string, never>;
|
|
81
|
-
type InferReturns<R> = R extends z.ZodType<any, any, any> ? z.output<R> : R extends undefined ? any : R;
|
|
82
|
-
type InferHandlerReturns<R> = R extends z.ZodType<any, any, any> ? z.input<R> : any;
|
|
83
|
-
/**
|
|
84
|
-
* Extract the visibility type from a Convex builder function
|
|
85
|
-
*/
|
|
86
|
-
type ExtractVisibility<Builder extends (...args: any) => any> = ReturnType<Builder> extends RegisteredQuery<infer V, any, any> ? V : ReturnType<Builder> extends RegisteredMutation<infer V, any, any> ? V : ReturnType<Builder> extends RegisteredAction<infer V, any, any> ? V : 'public';
|
|
87
|
-
/**
|
|
88
|
-
* @deprecated Use GenericQueryCtx, GenericMutationCtx, or GenericActionCtx directly instead
|
|
89
|
-
*/
|
|
90
|
-
type ExtractCtx<Builder> = Builder extends {
|
|
91
|
-
(fn: {
|
|
92
|
-
handler: (ctx: infer Ctx, ...args: any[]) => any;
|
|
93
|
-
}): any;
|
|
94
|
-
} ? Ctx : never;
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Return types are now specified explicitly using RegisteredQuery, RegisteredMutation, or RegisteredAction
|
|
97
|
-
*/
|
|
98
|
-
type PreserveReturnType<Builder extends (...args: any) => any, ArgsType, ReturnsType> = ReturnType<Builder> extends RegisteredQuery<infer V, any, any> ? RegisteredQuery<V, ArgsType extends DefaultFunctionArgs ? ArgsType : DefaultFunctionArgs, Promise<ReturnsType>> : ReturnType<Builder> extends RegisteredMutation<infer V, any, any> ? RegisteredMutation<V, ArgsType extends DefaultFunctionArgs ? ArgsType : DefaultFunctionArgs, Promise<ReturnsType>> : ReturnType<Builder> extends RegisteredAction<infer V, any, any> ? RegisteredAction<V, ArgsType extends DefaultFunctionArgs ? ArgsType : DefaultFunctionArgs, Promise<ReturnsType>> : ReturnType<Builder>;
|
|
99
|
-
type ZodToConvexArgs<A> = A extends z.ZodObject<any> ? z.infer<A> : A extends Record<string, z.ZodTypeAny> ? {
|
|
100
|
-
[K in keyof A]: z.infer<A[K]>;
|
|
101
|
-
} : A extends z.ZodTypeAny ? {
|
|
102
|
-
value: z.infer<A>;
|
|
103
|
-
} : Record<string, never>;
|
|
104
|
-
|
|
105
|
-
type OneArgArray<ArgsObject extends DefaultFunctionArgs = DefaultFunctionArgs> = [ArgsObject];
|
|
106
|
-
type NullToUndefinedOrNull<T> = T extends null ? T | undefined | void : T;
|
|
107
|
-
type Returns<T> = Promise<NullToUndefinedOrNull<T>> | NullToUndefinedOrNull<T>;
|
|
108
|
-
type ReturnValueInput<ReturnsValidator extends z.ZodTypeAny | ZodValidator | void> = [
|
|
109
|
-
ReturnsValidator
|
|
110
|
-
] extends [z.ZodTypeAny] ? Returns<z.input<ReturnsValidator>> : [ReturnsValidator] extends [ZodValidator] ? Returns<z.input<z.ZodObject<ReturnsValidator>>> : any;
|
|
111
|
-
type ReturnValueOutput<ReturnsValidator extends z.ZodTypeAny | ZodValidator | void> = [
|
|
112
|
-
ReturnsValidator
|
|
113
|
-
] extends [z.ZodTypeAny] ? Returns<z.output<ReturnsValidator>> : [ReturnsValidator] extends [ZodValidator] ? Returns<z.output<z.ZodObject<ReturnsValidator>>> : any;
|
|
114
|
-
type ArgsInput<ArgsValidator extends ZodValidator | z.ZodObject<any> | void> = [
|
|
115
|
-
ArgsValidator
|
|
116
|
-
] extends [z.ZodObject<any>] ? [z.input<ArgsValidator>] : [ArgsValidator] extends [ZodValidator] ? [z.input<z.ZodObject<ArgsValidator>>] : OneArgArray;
|
|
117
|
-
type ArgsOutput<ArgsValidator extends ZodValidator | z.ZodObject<any> | void> = [
|
|
118
|
-
ArgsValidator
|
|
119
|
-
] extends [z.ZodObject<any>] ? [z.output<ArgsValidator>] : [ArgsValidator] extends [ZodValidator] ? [z.output<z.ZodObject<ArgsValidator>>] : OneArgArray;
|
|
120
|
-
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
121
|
-
type Expand<ObjectType extends Record<any, any>> = ObjectType extends Record<any, any> ? {
|
|
122
|
-
[Key in keyof ObjectType]: ObjectType[Key];
|
|
123
|
-
} : never;
|
|
124
|
-
type ArgsForHandlerType<OneOrZeroArgs extends [] | [Record<string, any>], CustomMadeArgs extends Record<string, any>> = CustomMadeArgs extends Record<string, never> ? OneOrZeroArgs : OneOrZeroArgs extends [infer A] ? [Expand<A & CustomMadeArgs>] : [CustomMadeArgs];
|
|
125
|
-
type Registration<FuncType extends 'query' | 'mutation' | 'action', Visibility extends FunctionVisibility, Args extends DefaultFunctionArgs, Output> = FuncType extends 'query' ? convex_server.RegisteredQuery<Visibility, Args, Output> : FuncType extends 'mutation' ? convex_server.RegisteredMutation<Visibility, Args, Output> : convex_server.RegisteredAction<Visibility, Args, Output>;
|
|
126
|
-
/**
|
|
127
|
-
* A builder that customizes a Convex function, whether or not it validates
|
|
128
|
-
* arguments. If the customization requires arguments, however, the resulting
|
|
129
|
-
* builder will require argument validation too.
|
|
130
|
-
*
|
|
131
|
-
* This is our own Zod-aware CustomBuilder type that properly handles Zod validators.
|
|
132
|
-
*/
|
|
133
|
-
type CustomBuilder<FuncType extends 'query' | 'mutation' | 'action', CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, any>> = {
|
|
134
|
-
<ArgsValidator extends ZodValidator | z.ZodObject<any> | void, ReturnsZodValidator extends z.ZodTypeAny | ZodValidator | void = void, ReturnValue extends ReturnValueInput<ReturnsZodValidator> = any>(func: ({
|
|
135
|
-
/**
|
|
136
|
-
* Specify the arguments to the function as a Zod validator.
|
|
137
|
-
*/
|
|
138
|
-
args?: ArgsValidator;
|
|
139
|
-
handler: (ctx: Overwrite<InputCtx, CustomCtx>, ...args: ArgsForHandlerType<ArgsOutput<ArgsValidator>, CustomMadeArgs>) => ReturnValue;
|
|
140
|
-
/**
|
|
141
|
-
* Validates the value returned by the function.
|
|
142
|
-
* Note: you can't pass an object directly without wrapping it
|
|
143
|
-
* in `z.object()`.
|
|
144
|
-
*/
|
|
145
|
-
returns?: ReturnsZodValidator;
|
|
146
|
-
/**
|
|
147
|
-
* If true, the function will not be validated by Convex,
|
|
148
|
-
* in case you're seeing performance issues with validating twice.
|
|
149
|
-
*/
|
|
150
|
-
skipConvexValidation?: boolean;
|
|
151
|
-
} & {
|
|
152
|
-
[key in keyof ExtraArgs as key extends 'args' | 'handler' | 'skipConvexValidation' | 'returns' ? never : key]: ExtraArgs[key];
|
|
153
|
-
}) | {
|
|
154
|
-
(ctx: Overwrite<InputCtx, CustomCtx>, ...args: ArgsForHandlerType<ArgsOutput<ArgsValidator>, CustomMadeArgs>): ReturnValue;
|
|
155
|
-
}): Registration<FuncType, Visibility, ArgsArrayToObject<CustomArgsValidator extends Record<string, never> ? ArgsInput<ArgsValidator> : ArgsInput<ArgsValidator> extends [infer A] ? [Expand<A & convex_values.ObjectType<CustomArgsValidator>>] : [convex_values.ObjectType<CustomArgsValidator>]>, ReturnsZodValidator extends void ? ReturnValue : ReturnValueOutput<ReturnsZodValidator>>;
|
|
156
|
-
};
|
|
157
|
-
declare function customFnBuilder<Ctx extends Record<string, any>, Builder extends (fn: any) => any, CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, ExtraArgs extends Record<string, any> = Record<string, any>>(builder: Builder, customization: Customization<Ctx, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): (fn: any) => any;
|
|
158
|
-
declare function zCustomQuery<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel, ExtraArgs extends Record<string, any> = Record<string, any>>(query: QueryBuilder<DataModel, Visibility>, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'query', CustomArgsValidator, CustomCtx, CustomMadeArgs, GenericQueryCtx<DataModel>, Visibility, ExtraArgs>;
|
|
159
|
-
declare function zCustomQuery<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, any> = Record<string, any>>(query: QueryBuilder<any, Visibility>, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'query', CustomArgsValidator, CustomCtx, CustomMadeArgs, any, Visibility, ExtraArgs>;
|
|
160
|
-
declare function zCustomMutation<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Builder extends (fn: any) => any, Visibility extends FunctionVisibility = 'public', ExtraArgs extends Record<string, any> = Record<string, any>>(mutation: Builder, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'mutation', CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtractCtx<Builder>, Visibility, ExtraArgs>;
|
|
161
|
-
declare function zCustomAction<CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Builder extends (fn: any) => any, Visibility extends FunctionVisibility = 'public', ExtraArgs extends Record<string, any> = Record<string, any>>(action: Builder, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'action', CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtractCtx<Builder>, Visibility, ExtraArgs>;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Creates a reusable query builder from a Convex query builder.
|
|
165
|
-
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```ts
|
|
169
|
-
* import { query } from './_generated/server'
|
|
170
|
-
* import { zQueryBuilder } from 'zodvex'
|
|
171
|
-
*
|
|
172
|
-
* // Create a reusable builder
|
|
173
|
-
* export const zq = zQueryBuilder(query)
|
|
174
|
-
*
|
|
175
|
-
* // Use it with Convex-style object syntax
|
|
176
|
-
* export const getUser = zq({
|
|
177
|
-
* args: { id: z.string() },
|
|
178
|
-
* handler: async (ctx, { id }) => {
|
|
179
|
-
* return ctx.db.get(id)
|
|
180
|
-
* }
|
|
181
|
-
* })
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
declare function zQueryBuilder<Builder extends (fn: any) => any>(builder: Builder): <A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(config: {
|
|
185
|
-
args?: A;
|
|
186
|
-
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
187
|
-
returns?: R;
|
|
188
|
-
}) => RegisteredQuery<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
189
|
-
/**
|
|
190
|
-
* Creates a reusable mutation builder from a Convex mutation builder.
|
|
191
|
-
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* import { mutation } from './_generated/server'
|
|
196
|
-
* import { zMutationBuilder } from 'zodvex'
|
|
197
|
-
*
|
|
198
|
-
* // Create a reusable builder
|
|
199
|
-
* export const zm = zMutationBuilder(mutation)
|
|
200
|
-
*
|
|
201
|
-
* // Use it with Convex-style object syntax
|
|
202
|
-
* export const updateUser = zm({
|
|
203
|
-
* args: { id: z.string(), name: z.string() },
|
|
204
|
-
* handler: async (ctx, { id, name }) => {
|
|
205
|
-
* return ctx.db.patch(id, { name })
|
|
206
|
-
* }
|
|
207
|
-
* })
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
declare function zMutationBuilder<Builder extends (fn: any) => any>(builder: Builder): <A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(config: {
|
|
211
|
-
args?: A;
|
|
212
|
-
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
213
|
-
returns?: R;
|
|
214
|
-
}) => RegisteredMutation<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
215
|
-
/**
|
|
216
|
-
* Creates a reusable action builder from a Convex action builder.
|
|
217
|
-
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* import { action } from './_generated/server'
|
|
222
|
-
* import { zActionBuilder } from 'zodvex'
|
|
223
|
-
*
|
|
224
|
-
* // Create a reusable builder
|
|
225
|
-
* export const za = zActionBuilder(action)
|
|
226
|
-
*
|
|
227
|
-
* // Use it with Convex-style object syntax
|
|
228
|
-
* export const sendEmail = za({
|
|
229
|
-
* args: { to: z.string().email(), subject: z.string() },
|
|
230
|
-
* handler: async (ctx, { to, subject }) => {
|
|
231
|
-
* // Send email
|
|
232
|
-
* }
|
|
233
|
-
* })
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
declare function zActionBuilder<Builder extends (fn: any) => any>(builder: Builder): <A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(config: {
|
|
237
|
-
args?: A;
|
|
238
|
-
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
239
|
-
returns?: R;
|
|
240
|
-
}) => RegisteredAction<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
241
|
-
/**
|
|
242
|
-
* Creates a custom query builder with context injection from a Convex query builder.
|
|
243
|
-
* Allows you to add custom context (like auth, permissions, etc.) to your queries.
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```ts
|
|
247
|
-
* import { type QueryCtx, query } from './_generated/server'
|
|
248
|
-
* import { zCustomQueryBuilder, customCtx } from 'zodvex'
|
|
249
|
-
*
|
|
250
|
-
* // Create a builder with auth context
|
|
251
|
-
* export const authQuery = zCustomQueryBuilder(
|
|
252
|
-
* query,
|
|
253
|
-
* customCtx(async (ctx: QueryCtx) => {
|
|
254
|
-
* const user = await getUserOrThrow(ctx)
|
|
255
|
-
* return { user }
|
|
256
|
-
* })
|
|
257
|
-
* )
|
|
258
|
-
*
|
|
259
|
-
* // Use it with automatic user injection
|
|
260
|
-
* export const getMyProfile = authQuery({
|
|
261
|
-
* args: {},
|
|
262
|
-
* handler: async (ctx) => {
|
|
263
|
-
* // ctx.user is automatically available
|
|
264
|
-
* return ctx.db.get(ctx.user._id)
|
|
265
|
-
* }
|
|
266
|
-
* })
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
declare function zCustomQueryBuilder<Builder extends (fn: any) => any, CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility = ExtractVisibility<Builder>, ExtraArgs extends Record<string, any> = Record<string, any>>(query: Builder, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'query', CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtractCtx<Builder>, Visibility, ExtraArgs>;
|
|
270
|
-
/**
|
|
271
|
-
* Creates a custom mutation builder with context injection from a Convex mutation builder.
|
|
272
|
-
* Allows you to add custom context (like auth, permissions, etc.) to your mutations.
|
|
273
|
-
*
|
|
274
|
-
* @example
|
|
275
|
-
* ```ts
|
|
276
|
-
* import { type MutationCtx, mutation } from './_generated/server'
|
|
277
|
-
* import { zCustomMutationBuilder, customCtx } from 'zodvex'
|
|
278
|
-
*
|
|
279
|
-
* // Create a builder with auth context
|
|
280
|
-
* export const authMutation = zCustomMutationBuilder(
|
|
281
|
-
* mutation,
|
|
282
|
-
* customCtx(async (ctx: MutationCtx) => {
|
|
283
|
-
* const user = await getUserOrThrow(ctx)
|
|
284
|
-
* return { user }
|
|
285
|
-
* })
|
|
286
|
-
* )
|
|
287
|
-
*
|
|
288
|
-
* // Use it with automatic user injection
|
|
289
|
-
* export const updateProfile = authMutation({
|
|
290
|
-
* args: { name: z.string() },
|
|
291
|
-
* handler: async (ctx, { name }) => {
|
|
292
|
-
* // ctx.user is automatically available
|
|
293
|
-
* await ctx.db.patch(ctx.user._id, { name })
|
|
294
|
-
* }
|
|
295
|
-
* })
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
declare function zCustomMutationBuilder<Builder extends (fn: any) => any, CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility = ExtractVisibility<Builder>, ExtraArgs extends Record<string, any> = Record<string, any>>(mutation: Builder, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'mutation', CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtractCtx<Builder>, Visibility, ExtraArgs>;
|
|
299
|
-
/**
|
|
300
|
-
* Creates a custom action builder with context injection from a Convex action builder.
|
|
301
|
-
* Allows you to add custom context (like auth, permissions, etc.) to your actions.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```ts
|
|
305
|
-
* import { type ActionCtx, action } from './_generated/server'
|
|
306
|
-
* import { zCustomActionBuilder, customCtx } from 'zodvex'
|
|
307
|
-
*
|
|
308
|
-
* // Create a builder with auth context
|
|
309
|
-
* export const authAction = zCustomActionBuilder(
|
|
310
|
-
* action,
|
|
311
|
-
* customCtx(async (ctx: ActionCtx) => {
|
|
312
|
-
* const identity = await ctx.auth.getUserIdentity()
|
|
313
|
-
* if (!identity) throw new Error('Unauthorized')
|
|
314
|
-
* return { userId: identity.subject }
|
|
315
|
-
* })
|
|
316
|
-
* )
|
|
317
|
-
*
|
|
318
|
-
* // Use it with automatic auth injection
|
|
319
|
-
* export const sendEmail = authAction({
|
|
320
|
-
* args: { to: z.string().email() },
|
|
321
|
-
* handler: async (ctx, { to }) => {
|
|
322
|
-
* // ctx.userId is automatically available
|
|
323
|
-
* await sendEmailService(to, ctx.userId)
|
|
324
|
-
* }
|
|
325
|
-
* })
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
declare function zCustomActionBuilder<Builder extends (fn: any) => any, CustomArgsValidator extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility = ExtractVisibility<Builder>, ExtraArgs extends Record<string, any> = Record<string, any>>(action: Builder, customization: Customization<any, CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtraArgs>): CustomBuilder<'action', CustomArgsValidator, CustomCtx, CustomMadeArgs, ExtractCtx<Builder>, Visibility, ExtraArgs>;
|
|
329
|
-
|
|
330
|
-
type ConvexCodec<T> = {
|
|
331
|
-
validator: any;
|
|
332
|
-
encode: (value: T) => any;
|
|
333
|
-
decode: (value: any) => T;
|
|
334
|
-
pick: <K extends keyof T>(keys: K[]) => ConvexCodec<Pick<T, K>>;
|
|
335
|
-
};
|
|
336
|
-
declare function convexCodec<T>(schema: z.ZodType<T>): ConvexCodec<T>;
|
|
337
|
-
declare function toConvexJS(schema?: any, value?: any): any;
|
|
338
|
-
declare function fromConvexJS(value: any, schema: any): any;
|
|
339
|
-
|
|
340
|
-
type BaseCodec = {
|
|
341
|
-
check: (schema: any) => boolean;
|
|
342
|
-
toValidator: (schema: any) => any;
|
|
343
|
-
fromConvex: (value: any, schema: any) => any;
|
|
344
|
-
toConvex: (value: any, schema: any) => any;
|
|
345
|
-
};
|
|
346
|
-
declare function registerBaseCodec(codec: BaseCodec): void;
|
|
347
|
-
declare function findBaseCodec(schema: any): BaseCodec | undefined;
|
|
348
|
-
declare function isDateSchema(schema: any): boolean;
|
|
349
|
-
/**
|
|
350
|
-
* Checks if a schema is a zid (Convex ID) schema by looking at its description.
|
|
351
|
-
* zid schemas are marked with "convexId:{tableName}" in their description.
|
|
352
|
-
*/
|
|
353
|
-
declare function isZidSchema(schema: z.ZodTypeAny): boolean;
|
|
354
|
-
/**
|
|
355
|
-
* Extracts the table name from a zid schema's description.
|
|
356
|
-
* Returns undefined if not a zid schema.
|
|
357
|
-
*/
|
|
358
|
-
declare function getZidTableName(schema: z.ZodTypeAny): string | undefined;
|
|
359
|
-
/**
|
|
360
|
-
* Context object passed to the JSON Schema override function.
|
|
361
|
-
* Uses 'any' types for compatibility with Zod's internal types.
|
|
362
|
-
*/
|
|
363
|
-
interface JSONSchemaOverrideContext {
|
|
364
|
-
zodSchema: any;
|
|
365
|
-
jsonSchema: any;
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Override function for z.toJSONSchema that handles zodvex-managed types.
|
|
369
|
-
*
|
|
370
|
-
* Handles:
|
|
371
|
-
* - zid schemas: Converts to { type: "string" } with convexId format
|
|
372
|
-
* - z.date(): Converts to { type: "string", format: "date-time" }
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```ts
|
|
376
|
-
* import { z } from 'zod'
|
|
377
|
-
* import { zid, zodvexJSONSchemaOverride } from 'zodvex'
|
|
378
|
-
*
|
|
379
|
-
* const schema = z.object({
|
|
380
|
-
* userId: zid('users'),
|
|
381
|
-
* name: z.string()
|
|
382
|
-
* })
|
|
383
|
-
*
|
|
384
|
-
* const jsonSchema = z.toJSONSchema(schema, {
|
|
385
|
-
* unrepresentable: 'any',
|
|
386
|
-
* override: zodvexJSONSchemaOverride
|
|
387
|
-
* })
|
|
388
|
-
* // => { type: "object", properties: { userId: { type: "string" }, name: { type: "string" } } }
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
declare function zodvexJSONSchemaOverride(ctx: JSONSchemaOverrideContext): void;
|
|
392
|
-
/**
|
|
393
|
-
* Composes multiple JSON Schema override functions into one.
|
|
394
|
-
* Overrides run in order - first override runs first.
|
|
395
|
-
*
|
|
396
|
-
* @example
|
|
397
|
-
* ```ts
|
|
398
|
-
* import { composeOverrides, zodvexJSONSchemaOverride } from 'zodvex'
|
|
399
|
-
*
|
|
400
|
-
* const myOverride = (ctx) => {
|
|
401
|
-
* if (ctx.zodSchema.description?.startsWith('myType:')) {
|
|
402
|
-
* ctx.jsonSchema.type = 'string'
|
|
403
|
-
* ctx.jsonSchema.format = 'my-format'
|
|
404
|
-
* }
|
|
405
|
-
* }
|
|
406
|
-
*
|
|
407
|
-
* // User's override runs first, then zodvex's
|
|
408
|
-
* z.toJSONSchema(schema, {
|
|
409
|
-
* unrepresentable: 'any',
|
|
410
|
-
* override: composeOverrides(myOverride, zodvexJSONSchemaOverride)
|
|
411
|
-
* })
|
|
412
|
-
* ```
|
|
413
|
-
*/
|
|
414
|
-
declare function composeOverrides(...overrides: Array<((ctx: JSONSchemaOverrideContext) => void) | undefined>): (ctx: JSONSchemaOverrideContext) => void;
|
|
415
|
-
/**
|
|
416
|
-
* Options for toJSONSchema, matching Zod's interface.
|
|
417
|
-
*/
|
|
418
|
-
interface ToJSONSchemaOptions {
|
|
419
|
-
target?: 'draft-4' | 'draft-7' | 'draft-2020-12' | 'openapi-3.0';
|
|
420
|
-
unrepresentable?: 'throw' | 'any';
|
|
421
|
-
cycles?: 'ref' | 'throw';
|
|
422
|
-
reused?: 'ref' | 'inline';
|
|
423
|
-
io?: 'input' | 'output';
|
|
424
|
-
override?: (ctx: JSONSchemaOverrideContext) => void;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Converts a Zod schema to JSON Schema with zodvex-aware overrides.
|
|
428
|
-
*
|
|
429
|
-
* This is a convenience wrapper around z.toJSONSchema that automatically
|
|
430
|
-
* handles zodvex-managed types like zid and dates.
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```ts
|
|
434
|
-
* import { zid, toJSONSchema } from 'zodvex'
|
|
435
|
-
*
|
|
436
|
-
* const schema = z.object({
|
|
437
|
-
* userId: zid('users'),
|
|
438
|
-
* createdAt: z.date(),
|
|
439
|
-
* name: z.string()
|
|
440
|
-
* })
|
|
441
|
-
*
|
|
442
|
-
* const jsonSchema = toJSONSchema(schema)
|
|
443
|
-
* // Works with AI SDK's generateObject, etc.
|
|
444
|
-
* ```
|
|
445
|
-
*/
|
|
446
|
-
declare function toJSONSchema<T extends z.ZodTypeAny>(schema: T, options?: ToJSONSchemaOptions): Record<string, any>;
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Helper type for Convex system fields added to documents
|
|
450
|
-
*/
|
|
451
|
-
type SystemFields<TableName extends string> = {
|
|
452
|
-
_id: ReturnType<typeof zid<TableName>>;
|
|
453
|
-
_creationTime: z.ZodNumber;
|
|
454
|
-
};
|
|
455
|
-
/**
|
|
456
|
-
* Maps over union options, extending each ZodObject variant with system fields.
|
|
457
|
-
* Non-object variants are preserved as-is.
|
|
458
|
-
*/
|
|
459
|
-
type MapSystemFields<TableName extends string, Options extends readonly z.ZodTypeAny[]> = {
|
|
460
|
-
[K in keyof Options]: Options[K] extends z.ZodObject<infer Shape extends z.ZodRawShape> ? z.ZodObject<Shape & SystemFields<TableName>> : Options[K];
|
|
461
|
-
};
|
|
462
|
-
/**
|
|
463
|
-
* Adds Convex system fields (_id, _creationTime) to a Zod schema.
|
|
464
|
-
*
|
|
465
|
-
* For object schemas: extends with system fields
|
|
466
|
-
* For union schemas: adds system fields to each variant
|
|
467
|
-
*
|
|
468
|
-
* @param tableName - The Convex table name
|
|
469
|
-
* @param schema - The Zod schema (object or union)
|
|
470
|
-
* @returns Schema with system fields added
|
|
471
|
-
*/
|
|
472
|
-
declare function addSystemFields<TableName extends string, Shape extends z.ZodRawShape>(tableName: TableName, schema: z.ZodObject<Shape>): z.ZodObject<Shape & SystemFields<TableName>>;
|
|
473
|
-
declare function addSystemFields<TableName extends string, Options extends readonly z.ZodTypeAny[]>(tableName: TableName, schema: z.ZodUnion<Options>): z.ZodUnion<MapSystemFields<TableName, Options>>;
|
|
474
|
-
declare function addSystemFields<TableName extends string, Options extends readonly z.ZodObject<z.ZodRawShape>[], Discriminator extends string>(tableName: TableName, schema: z.ZodDiscriminatedUnion<Options, Discriminator>): z.ZodDiscriminatedUnion<MapSystemFields<TableName, Options>, Discriminator>;
|
|
475
|
-
declare function addSystemFields<TableName extends string, S extends z.ZodTypeAny>(tableName: TableName, schema: S): S;
|
|
476
|
-
declare function zodDoc<TableName extends string, Shape extends z.ZodRawShape, Schema extends z.ZodObject<Shape>>(tableName: TableName, schema: Schema): z.ZodObject<Shape & {
|
|
477
|
-
_id: ReturnType<typeof zid<TableName>>;
|
|
478
|
-
_creationTime: z.ZodNumber;
|
|
479
|
-
}>;
|
|
480
|
-
declare function zodDocOrNull<TableName extends string, Shape extends z.ZodRawShape, Schema extends z.ZodObject<Shape>>(tableName: TableName, schema: Schema): z.ZodUnion<readonly [z.ZodObject<Readonly<{
|
|
481
|
-
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
482
|
-
}> & {
|
|
483
|
-
_id: z.ZodType<GenericId<TableName>, unknown, z.core.$ZodTypeInternals<GenericId<TableName>, unknown>> & {
|
|
484
|
-
_tableName: TableName;
|
|
485
|
-
};
|
|
486
|
-
_creationTime: z.ZodNumber;
|
|
487
|
-
}, z.core.$strip>, z.ZodNull]>;
|
|
488
|
-
/**
|
|
489
|
-
* Defines a Convex table using either:
|
|
490
|
-
* - A raw Zod shape (an object mapping field names to Zod types)
|
|
491
|
-
* - A Zod union schema (for polymorphic tables)
|
|
492
|
-
*
|
|
493
|
-
* For object shapes, this function intentionally accepts a raw shape instead of a ZodObject instance.
|
|
494
|
-
* Accepting raw shapes allows TypeScript to infer field types more accurately and efficiently,
|
|
495
|
-
* leading to better type inference and performance throughout the codebase.
|
|
496
|
-
*
|
|
497
|
-
* For union schemas, this enables polymorphic tables with discriminated unions.
|
|
498
|
-
*
|
|
499
|
-
* Returns the Table definition along with Zod schemas for documents and arrays.
|
|
500
|
-
*
|
|
501
|
-
* @param name - The table name
|
|
502
|
-
* @param schemaOrShape - Either a raw object shape or a Zod union schema
|
|
503
|
-
* @returns A Table with attached helpers (shape, schema, zDoc, docArray, withSystemFields)
|
|
504
|
-
*
|
|
505
|
-
* @example Object shape
|
|
506
|
-
* ```ts
|
|
507
|
-
* const Users = zodTable('users', {
|
|
508
|
-
* name: z.string(),
|
|
509
|
-
* email: z.string().email(),
|
|
510
|
-
* age: z.number().optional()
|
|
511
|
-
* })
|
|
512
|
-
*
|
|
513
|
-
* // Use in schema
|
|
514
|
-
* export default defineSchema({ users: Users.table })
|
|
515
|
-
*
|
|
516
|
-
* // Use for return types
|
|
517
|
-
* export const getUsers = zQuery(query, {},
|
|
518
|
-
* async (ctx) => ctx.db.query('users').collect(),
|
|
519
|
-
* { returns: Users.docArray }
|
|
520
|
-
* )
|
|
521
|
-
* ```
|
|
522
|
-
*
|
|
523
|
-
* @example Union schema (polymorphic table)
|
|
524
|
-
* ```ts
|
|
525
|
-
* const shapeSchema = z.union([
|
|
526
|
-
* z.object({ kind: z.literal('circle'), r: z.number() }),
|
|
527
|
-
* z.object({ kind: z.literal('rectangle'), width: z.number() })
|
|
528
|
-
* ])
|
|
529
|
-
*
|
|
530
|
-
* const Shapes = zodTable('shapes', shapeSchema)
|
|
531
|
-
*
|
|
532
|
-
* // Use in schema
|
|
533
|
-
* export default defineSchema({ shapes: Shapes.table })
|
|
534
|
-
*
|
|
535
|
-
* // Use for return types with system fields
|
|
536
|
-
* export const getShapes = zQuery(query, {},
|
|
537
|
-
* async (ctx) => ctx.db.query('shapes').collect(),
|
|
538
|
-
* { returns: Shapes.docArray }
|
|
539
|
-
* )
|
|
540
|
-
* ```
|
|
541
|
-
*/
|
|
542
|
-
type AddSystemFieldsResult<TableName extends string, Schema extends z.ZodTypeAny> = Schema extends z.ZodObject<infer Shape extends z.ZodRawShape> ? z.ZodObject<Shape & SystemFields<TableName>> : Schema extends z.ZodUnion<infer Options extends readonly z.ZodTypeAny[]> ? z.ZodUnion<MapSystemFields<TableName, Options>> : Schema extends z.ZodDiscriminatedUnion<infer Options extends readonly z.ZodObject<z.ZodRawShape>[], infer Disc extends string> ? z.ZodDiscriminatedUnion<MapSystemFields<TableName, Options>, Disc> : Schema;
|
|
543
|
-
declare function zodTable<TableName extends string, Shape extends Record<string, z.ZodTypeAny>>(name: TableName, shape: Shape): ReturnType<typeof Table<ConvexValidatorFromZodFieldsAuto<Shape>, TableName>> & {
|
|
544
|
-
shape: Shape;
|
|
545
|
-
zDoc: z.ZodObject<Shape & {
|
|
546
|
-
_id: ReturnType<typeof zid<TableName>>;
|
|
547
|
-
_creationTime: z.ZodNumber;
|
|
548
|
-
}>;
|
|
549
|
-
docArray: z.ZodArray<z.ZodObject<Shape & {
|
|
550
|
-
_id: ReturnType<typeof zid<TableName>>;
|
|
551
|
-
_creationTime: z.ZodNumber;
|
|
552
|
-
}>>;
|
|
553
|
-
};
|
|
554
|
-
declare function zodTable<TableName extends string, Schema extends z.ZodTypeAny>(name: TableName, schema: Schema): {
|
|
555
|
-
table: ReturnType<typeof defineTable>;
|
|
556
|
-
tableName: TableName;
|
|
557
|
-
validator: ReturnType<typeof zodToConvex<Schema>>;
|
|
558
|
-
schema: Schema;
|
|
559
|
-
docArray: z.ZodArray<AddSystemFieldsResult<TableName, Schema>>;
|
|
560
|
-
withSystemFields: () => AddSystemFieldsResult<TableName, Schema>;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
564
|
-
declare function returnsAs<R extends z.ZodTypeAny>(): <T extends z.input<R>>(v: T) => T;
|
|
565
|
-
declare function formatZodIssues(error: z.ZodError, context?: 'args' | 'returns' | 'input' | 'output' | 'codec'): {
|
|
566
|
-
error: string;
|
|
567
|
-
context: "output" | "input" | "args" | "returns" | "codec" | undefined;
|
|
568
|
-
issues: {
|
|
569
|
-
path: string;
|
|
570
|
-
code: "custom" | "invalid_type" | "unrecognized_keys" | "invalid_union" | "invalid_value" | "invalid_key" | "too_big" | "too_small" | "invalid_format" | "not_multiple_of" | "invalid_element";
|
|
571
|
-
message: string;
|
|
572
|
-
}[];
|
|
573
|
-
flatten: any;
|
|
574
|
-
};
|
|
575
|
-
declare function handleZodValidationError(e: unknown, context: 'args' | 'returns' | 'input' | 'output' | 'codec'): never;
|
|
576
|
-
declare function zPaginated<T extends z.ZodTypeAny>(item: T): z.ZodObject<{
|
|
577
|
-
page: z.ZodArray<T>;
|
|
578
|
-
isDone: z.ZodBoolean;
|
|
579
|
-
continueCursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
580
|
-
}, z.core.$strip>;
|
|
581
|
-
/**
|
|
582
|
-
* Maps Date fields to number fields for docSchema generation.
|
|
583
|
-
* Handles Date, Date.optional(), Date.nullable(), and Date.default() cases.
|
|
584
|
-
* Returns the original field for non-Date types.
|
|
585
|
-
*/
|
|
586
|
-
declare function mapDateFieldToNumber(field: z.ZodTypeAny): z.ZodTypeAny;
|
|
587
|
-
type Mask = readonly string[] | Record<string, boolean | 1 | true>;
|
|
588
|
-
/**
|
|
589
|
-
* Returns a plain shape object containing only the selected fields.
|
|
590
|
-
* Accepts either a ZodObject or a raw shape object.
|
|
591
|
-
*/
|
|
592
|
-
declare function pickShape(schemaOrShape: z.ZodObject<any> | Record<string, any>, mask: Mask): Record<string, any>;
|
|
593
|
-
declare function safePick(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any>;
|
|
594
|
-
/**
|
|
595
|
-
* Convenience: omit a set of keys by building the complement.
|
|
596
|
-
* Avoids using Zod's .omit() which can cause type depth issues.
|
|
597
|
-
*/
|
|
598
|
-
declare function safeOmit(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any>;
|
|
599
|
-
|
|
600
|
-
export { type ConvexCodec, type ConvexValidatorFromZod, type ConvexValidatorFromZodFieldsAuto, type CustomBuilder, type ExtractCtx, type ExtractVisibility, type InferArgs, type InferHandlerReturns, type InferReturns, type JSONSchemaOverrideContext, type PreserveReturnType, type ToJSONSchemaOptions, type Zid, type ZodToConvexArgs, type ZodValidator, addSystemFields, composeOverrides, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, getZidTableName, handleZodValidationError, isDateSchema, isZidSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, toJSONSchema, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zMutationBuilder, zPaginated, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields, zodvexJSONSchemaOverride };
|
|
2
|
+
export * from './builders';
|
|
3
|
+
export * from './codec';
|
|
4
|
+
export * from './custom';
|
|
5
|
+
export * from './ids';
|
|
6
|
+
export * from './mapping';
|
|
7
|
+
export * from './registry';
|
|
8
|
+
export * from './results';
|
|
9
|
+
export * from './tables';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * from './utils';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAA;AACjE,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|