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
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ConvexValidatorFromZod, ConvexValidatorFromZodFieldsAuto, ZodValidator } from './types';
|
|
3
|
+
export declare function zodToConvex<Z extends z.ZodTypeAny | ZodValidator>(zod: Z): Z extends z.ZodTypeAny ? ConvexValidatorFromZod<Z, 'required'> : Z extends ZodValidator ? ConvexValidatorFromZodFieldsAuto<Z> : never;
|
|
4
|
+
export declare function zodToConvexFields<Z extends z.ZodRawShape>(zod: Z): ConvexValidatorFromZodFieldsAuto<Z>;
|
|
5
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/mapping/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAUvB,OAAO,KAAK,EACV,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACb,MAAM,SAAS,CAAA;AA0ShB,wBAAgB,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,GAAG,YAAY,EAC/D,GAAG,EAAE,CAAC,GACL,CAAC,SAAS,CAAC,CAAC,UAAU,GACrB,sBAAsB,CAAC,CAAC,EAAE,UAAU,CAAC,GACrC,CAAC,SAAS,YAAY,GACpB,gCAAgC,CAAC,CAAC,CAAC,GACnC,KAAK,CAMV;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EACvD,GAAG,EAAE,CAAC,GACL,gCAAgC,CAAC,CAAC,CAAC,CAWrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../src/mapping/handlers/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAa,MAAM,eAAe,CAAA;AAEhE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,wBAAgB,eAAe,CAAC,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAwBjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mapping/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC5C,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GenericValidator } from 'convex/values';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare function convertNullableType(actualValidator: z.ZodNullable<any>, visited: Set<z.ZodTypeAny>, zodToConvexInternal: (schema: z.ZodTypeAny, visited: Set<z.ZodTypeAny>) => any): {
|
|
4
|
+
validator: GenericValidator;
|
|
5
|
+
isOptional: boolean;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=nullable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullable.d.ts","sourceRoot":"","sources":["../../../src/mapping/handlers/nullable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,EACnC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAC1B,mBAAmB,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,GAC7E;IAAE,SAAS,EAAE,gBAAgB,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAyBtD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GenericValidator } from 'convex/values';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare function convertRecordType(actualValidator: z.ZodRecord<any, any>, visited: Set<z.ZodTypeAny>, zodToConvexInternal: (schema: z.ZodTypeAny, visited: Set<z.ZodTypeAny>) => any): GenericValidator;
|
|
4
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../../src/mapping/handlers/record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAErD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EACtC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAC1B,mBAAmB,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,GAC7E,gBAAgB,CA8DlB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GenericValidator } from 'convex/values';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare function convertDiscriminatedUnionType(actualValidator: z.ZodDiscriminatedUnion<any, any>, visited: Set<z.ZodTypeAny>, zodToConvexInternal: (schema: z.ZodTypeAny, visited: Set<z.ZodTypeAny>) => any): GenericValidator;
|
|
4
|
+
export declare function convertUnionType(actualValidator: z.ZodUnion<any>, visited: Set<z.ZodTypeAny>, zodToConvexInternal: (schema: z.ZodTypeAny, visited: Set<z.ZodTypeAny>) => any): GenericValidator;
|
|
5
|
+
//# sourceMappingURL=union.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../../src/mapping/handlers/union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAa,MAAM,eAAe,CAAA;AAEhE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,CAAC,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,EAClD,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAC1B,mBAAmB,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,GAC7E,gBAAgB,CAwBlB;AAGD,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAChC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAC1B,mBAAmB,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,GAAG,GAC7E,gBAAgB,CA8BlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mapping/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AACvD,YAAY,EACV,sBAAsB,EACtB,gCAAgC,EAChC,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GenericId, VAny, VArray, VBoolean, VFloat64, VId, VInt64, VLiteral, VNull, VObject, VOptional, VRecord, VString, VUnion } from 'convex/values';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
type IsZid<T> = T extends {
|
|
4
|
+
_tableName: infer _TableName extends string;
|
|
5
|
+
} ? true : false;
|
|
6
|
+
type ExtractTableName<T> = T extends {
|
|
7
|
+
_tableName: infer TableName;
|
|
8
|
+
} ? TableName : never;
|
|
9
|
+
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'>] : [
|
|
10
|
+
VLiteral<T[0], 'required'>,
|
|
11
|
+
VLiteral<T[1], 'required'>,
|
|
12
|
+
...{
|
|
13
|
+
[K in keyof T]: K extends '0' | '1' ? never : K extends keyof T ? VLiteral<T[K], 'required'> : never;
|
|
14
|
+
}[keyof T & number][]
|
|
15
|
+
];
|
|
16
|
+
export type ZodValidator = Record<string, z.ZodTypeAny>;
|
|
17
|
+
type ConvexValidatorFromZodRequired<Z extends z.ZodTypeAny> = Z extends z.ZodOptional<infer T extends z.ZodTypeAny> ? VUnion<z.infer<T> | null, any[], 'required'> : ConvexValidatorFromZodBase<Z>;
|
|
18
|
+
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], [
|
|
19
|
+
VLiteral<T[0], 'required'>,
|
|
20
|
+
VLiteral<T[1], 'required'>
|
|
21
|
+
], '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, [
|
|
22
|
+
ConvexValidatorFromZodBase<InnerInner>,
|
|
23
|
+
VNull<null, 'required'>
|
|
24
|
+
], 'required'>> : VUnion<z.infer<Inner> | null, [
|
|
25
|
+
ConvexValidatorFromZodBase<Inner>,
|
|
26
|
+
VNull<null, 'required'>
|
|
27
|
+
], 'required'> : Z extends z.ZodAny ? VAny<'required'> : Z extends z.ZodUnknown ? VAny<'required'> : Z extends z.ZodCodec<infer A extends z.ZodTypeAny, any> ? ConvexValidatorFromZodBase<A> : VAny<'required'>;
|
|
28
|
+
export 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], [
|
|
29
|
+
VLiteral<T[0], 'required'>,
|
|
30
|
+
VLiteral<T[1], 'required'>
|
|
31
|
+
], 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> : Z extends z.ZodCodec<infer A extends z.ZodTypeAny, any> ? ConvexValidatorFromZod<A, Constraint> : VAny<'required'>;
|
|
32
|
+
type ConvexValidatorFromZodFields<T extends {
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}, Constraint extends 'required' | 'optional' = 'required'> = {
|
|
35
|
+
[K in keyof T]: T[K] extends z.ZodTypeAny ? ConvexValidatorFromZod<T[K], Constraint> : VAny<'required'>;
|
|
36
|
+
};
|
|
37
|
+
export type ConvexValidatorFromZodFieldsAuto<T extends {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}> = {
|
|
40
|
+
[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'>;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mapping/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,EACH,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,OAAO,EACP,MAAM,EACP,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,UAAU,EAAE,MAAM,UAAU,SAAS,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,KAAK,CAAA;AAGxF,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,UAAU,EAAE,MAAM,SAAS,CAAA;CAAE,GAAG,SAAS,GAAG,KAAK,CAAA;AAKxF,KAAK,mBAAmB,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GACtF,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,GAC5B,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GACnB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,QAAQ,CAAC,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ACxC,IAAI,CAAC,UAAU,CAAC;CACrB,CAAA;AAGD,MAAM,MAAM,gCAAgC,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI;KAC9E,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,GAC3C,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GACxC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAC5B,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GACxC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,GAC7B,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GACxC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GACzB,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GACxC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,GACvB,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GACxC,IAAI,CAAC,UAAU,CAAC;CAC7B,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Zid } from '../ids';
|
|
3
|
+
export declare function isZid<T extends string>(schema: z.ZodType): schema is Zid<T>;
|
|
4
|
+
export declare function makeUnion(members: any[]): any;
|
|
5
|
+
export declare function getObjectShape(obj: any): Record<string, any>;
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/mapping/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAmB,KAAK,GAAG,EAAE,MAAM,QAAQ,CAAA;AAGlD,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAM3E;AAGD,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAK7C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAU5D"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type BaseCodec = {
|
|
3
|
+
check: (schema: any) => boolean;
|
|
4
|
+
toValidator: (schema: any) => any;
|
|
5
|
+
fromConvex: (value: any, schema: any) => any;
|
|
6
|
+
toConvex: (value: any, schema: any) => any;
|
|
7
|
+
};
|
|
8
|
+
export declare function registerBaseCodec(codec: BaseCodec): void;
|
|
9
|
+
export declare function findBaseCodec(schema: any): BaseCodec | undefined;
|
|
10
|
+
export declare function isDateSchema(schema: any): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if a schema is a zid (Convex ID) schema by looking at its description.
|
|
13
|
+
* zid schemas are marked with "convexId:{tableName}" in their description.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isZidSchema(schema: z.ZodTypeAny): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts the table name from a zid schema's description.
|
|
18
|
+
* Returns undefined if not a zid schema.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getZidTableName(schema: z.ZodTypeAny): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Context object passed to the JSON Schema override function.
|
|
23
|
+
* Uses 'any' types for compatibility with Zod's internal types.
|
|
24
|
+
*/
|
|
25
|
+
export interface JSONSchemaOverrideContext {
|
|
26
|
+
zodSchema: any;
|
|
27
|
+
jsonSchema: any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Override function for z.toJSONSchema that handles zodvex-managed types.
|
|
31
|
+
*
|
|
32
|
+
* Handles:
|
|
33
|
+
* - zid schemas: Converts to { type: "string" } with convexId format
|
|
34
|
+
* - z.date(): Converts to { type: "string", format: "date-time" }
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { z } from 'zod'
|
|
39
|
+
* import { zid, zodvexJSONSchemaOverride } from 'zodvex'
|
|
40
|
+
*
|
|
41
|
+
* const schema = z.object({
|
|
42
|
+
* userId: zid('users'),
|
|
43
|
+
* name: z.string()
|
|
44
|
+
* })
|
|
45
|
+
*
|
|
46
|
+
* const jsonSchema = z.toJSONSchema(schema, {
|
|
47
|
+
* unrepresentable: 'any',
|
|
48
|
+
* override: zodvexJSONSchemaOverride
|
|
49
|
+
* })
|
|
50
|
+
* // => { type: "object", properties: { userId: { type: "string" }, name: { type: "string" } } }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function zodvexJSONSchemaOverride(ctx: JSONSchemaOverrideContext): void;
|
|
54
|
+
/**
|
|
55
|
+
* Composes multiple JSON Schema override functions into one.
|
|
56
|
+
* Overrides run in order - first override runs first.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { composeOverrides, zodvexJSONSchemaOverride } from 'zodvex'
|
|
61
|
+
*
|
|
62
|
+
* const myOverride = (ctx) => {
|
|
63
|
+
* if (ctx.zodSchema.description?.startsWith('myType:')) {
|
|
64
|
+
* ctx.jsonSchema.type = 'string'
|
|
65
|
+
* ctx.jsonSchema.format = 'my-format'
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* // User's override runs first, then zodvex's
|
|
70
|
+
* z.toJSONSchema(schema, {
|
|
71
|
+
* unrepresentable: 'any',
|
|
72
|
+
* override: composeOverrides(myOverride, zodvexJSONSchemaOverride)
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function composeOverrides(...overrides: Array<((ctx: JSONSchemaOverrideContext) => void) | undefined>): (ctx: JSONSchemaOverrideContext) => void;
|
|
77
|
+
/**
|
|
78
|
+
* Options for toJSONSchema, matching Zod's interface.
|
|
79
|
+
*/
|
|
80
|
+
export interface ToJSONSchemaOptions {
|
|
81
|
+
target?: 'draft-4' | 'draft-7' | 'draft-2020-12' | 'openapi-3.0';
|
|
82
|
+
unrepresentable?: 'throw' | 'any';
|
|
83
|
+
cycles?: 'ref' | 'throw';
|
|
84
|
+
reused?: 'ref' | 'inline';
|
|
85
|
+
io?: 'input' | 'output';
|
|
86
|
+
override?: (ctx: JSONSchemaOverrideContext) => void;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Converts a Zod schema to JSON Schema with zodvex-aware overrides.
|
|
90
|
+
*
|
|
91
|
+
* This is a convenience wrapper around z.toJSONSchema that automatically
|
|
92
|
+
* handles zodvex-managed types like zid and dates.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { zid, toJSONSchema } from 'zodvex'
|
|
97
|
+
*
|
|
98
|
+
* const schema = z.object({
|
|
99
|
+
* userId: zid('users'),
|
|
100
|
+
* createdAt: z.date(),
|
|
101
|
+
* name: z.string()
|
|
102
|
+
* })
|
|
103
|
+
*
|
|
104
|
+
* const jsonSchema = toJSONSchema(schema)
|
|
105
|
+
* // Works with AI SDK's generateObject, etc.
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function toJSONSchema<T extends z.ZodTypeAny>(schema: T, options?: ToJSONSchemaOptions): Record<string, any>;
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"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AW,mBAAmB;IAClC,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,CAAA;IAChE,eAAe,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IACjC,MAAM,CAAC,EAAE,KAAK,GAAG,OAAO,CAAA;IACxB,MAAM,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAA;IACzB,EAAE,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IACvB,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,yBAAyB,KAAK,IAAI,CAAA;CACpD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACjD,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,mBAAmB,GAC5B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAarB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Result type for mutations that return data on success.
|
|
4
|
+
*/
|
|
5
|
+
export type MutationResult<T> = {
|
|
6
|
+
success: true;
|
|
7
|
+
data: T;
|
|
8
|
+
} | {
|
|
9
|
+
success: false;
|
|
10
|
+
error: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Result type for mutations that don't return data (void operations).
|
|
14
|
+
*/
|
|
15
|
+
export type VoidMutationResult = {
|
|
16
|
+
success: true;
|
|
17
|
+
} | {
|
|
18
|
+
success: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Error structure for form validation results.
|
|
23
|
+
*/
|
|
24
|
+
export type FormError = {
|
|
25
|
+
formErrors: string[];
|
|
26
|
+
fieldErrors: Record<string, string[]>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Result type for form submissions with field-level error support.
|
|
30
|
+
* Preserves submitted data on failure for form re-population.
|
|
31
|
+
*/
|
|
32
|
+
export type FormResult<TData> = {
|
|
33
|
+
success: true;
|
|
34
|
+
data: TData;
|
|
35
|
+
} | {
|
|
36
|
+
success: false;
|
|
37
|
+
data: TData;
|
|
38
|
+
error: FormError;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Create a success result with data.
|
|
42
|
+
* @example success({ id: '123' })
|
|
43
|
+
*/
|
|
44
|
+
export declare const success: <T>(data: T) => {
|
|
45
|
+
readonly success: true;
|
|
46
|
+
readonly data: T;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Create a failure result with an error message.
|
|
50
|
+
* @example failure('Not found')
|
|
51
|
+
*/
|
|
52
|
+
export declare const failure: (error: string) => {
|
|
53
|
+
readonly success: false;
|
|
54
|
+
readonly error: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Create a void success result (no data).
|
|
58
|
+
* @example ok()
|
|
59
|
+
*/
|
|
60
|
+
export declare const ok: () => {
|
|
61
|
+
readonly success: true;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Create a form success result with data.
|
|
65
|
+
* @example formSuccess({ email: 'user@example.com' })
|
|
66
|
+
*/
|
|
67
|
+
export declare const formSuccess: <T>(data: T) => {
|
|
68
|
+
readonly success: true;
|
|
69
|
+
readonly data: T;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Create a form failure result with data and errors.
|
|
73
|
+
* @example formFailure({ email: 'bad' }, { formErrors: [], fieldErrors: { email: ['Invalid'] } })
|
|
74
|
+
*/
|
|
75
|
+
export declare const formFailure: <T>(data: T, error: FormError) => {
|
|
76
|
+
readonly success: false;
|
|
77
|
+
readonly data: T;
|
|
78
|
+
readonly error: FormError;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Zod schema for MutationResult<T>.
|
|
82
|
+
* Use in `returns` option to validate mutation responses.
|
|
83
|
+
* @example zMutationResult(z.object({ id: zid('users') }))
|
|
84
|
+
*/
|
|
85
|
+
export declare const zMutationResult: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
86
|
+
success: z.ZodLiteral<true>;
|
|
87
|
+
data: T;
|
|
88
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
89
|
+
success: z.ZodLiteral<false>;
|
|
90
|
+
error: z.ZodString;
|
|
91
|
+
}, z.core.$strip>], "success">;
|
|
92
|
+
/**
|
|
93
|
+
* Zod schema for VoidMutationResult.
|
|
94
|
+
* Use in `returns` option for void mutations.
|
|
95
|
+
* @example returns: zVoidMutationResult
|
|
96
|
+
*/
|
|
97
|
+
export declare const zVoidMutationResult: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
98
|
+
success: z.ZodLiteral<true>;
|
|
99
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
100
|
+
success: z.ZodLiteral<false>;
|
|
101
|
+
error: z.ZodString;
|
|
102
|
+
}, z.core.$strip>], "success">;
|
|
103
|
+
/**
|
|
104
|
+
* Zod schema for FormError.
|
|
105
|
+
*/
|
|
106
|
+
export declare const zFormError: z.ZodObject<{
|
|
107
|
+
formErrors: z.ZodArray<z.ZodString>;
|
|
108
|
+
fieldErrors: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
/**
|
|
111
|
+
* Zod schema for FormResult<T>.
|
|
112
|
+
* Use in `returns` option for form submissions.
|
|
113
|
+
* @example zFormResult(z.object({ email: z.string() }))
|
|
114
|
+
*/
|
|
115
|
+
export declare const zFormResult: <T extends z.ZodTypeAny>(dataSchema: T) => z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
116
|
+
success: z.ZodLiteral<true>;
|
|
117
|
+
data: T;
|
|
118
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
119
|
+
success: z.ZodLiteral<false>;
|
|
120
|
+
data: T;
|
|
121
|
+
error: z.ZodObject<{
|
|
122
|
+
formErrors: z.ZodArray<z.ZodString>;
|
|
123
|
+
fieldErrors: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
}, z.core.$strip>], "success">;
|
|
126
|
+
//# sourceMappingURL=results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9F;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAEtF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CACtC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,KAAK,IACxB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GAC9B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAA;AAMrD;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,MAAM,CAAC;;;CAAuC,CAAA;AAEzE;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM;;;CAAyC,CAAA;AAE9E;;;GAGG;AACH,eAAO,MAAM,EAAE;;CAAqC,CAAA;AAEpD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,MAAM,CAAC;;;CAAuC,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,SAAS;;;;CACZ,CAAA;AAM5C;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;;;;;8BAIjE,CAAA;AAEJ;;;;GAIG;AACH,eAAO,MAAM,mBAAmB;;;;;8BAG9B,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU;;;iBAGrB,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC;;;;;;;;;;8BAI7D,CAAA"}
|
package/dist/tables.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { defineTable } from 'convex/server';
|
|
2
|
+
import { Table } from 'convex-helpers/server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { zid } from './ids';
|
|
5
|
+
import { type ConvexValidatorFromZodFieldsAuto, zodToConvex } from './mapping';
|
|
6
|
+
/**
|
|
7
|
+
* Makes all properties of a Zod object shape optional.
|
|
8
|
+
*/
|
|
9
|
+
type PartialShape<Shape extends z.ZodRawShape> = {
|
|
10
|
+
[K in keyof Shape]: z.ZodOptional<Shape[K]>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Helper type for Convex system fields added to documents
|
|
14
|
+
*/
|
|
15
|
+
type SystemFields<TableName extends string> = {
|
|
16
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
17
|
+
_creationTime: z.ZodNumber;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Maps over union options, extending each ZodObject variant with system fields.
|
|
21
|
+
* Non-object variants are preserved as-is.
|
|
22
|
+
*/
|
|
23
|
+
type MapSystemFields<TableName extends string, Options extends readonly z.ZodTypeAny[]> = {
|
|
24
|
+
[K in keyof Options]: Options[K] extends z.ZodObject<infer Shape extends z.ZodRawShape> ? z.ZodObject<Shape & SystemFields<TableName>> : Options[K];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if a schema is a union type (ZodUnion or ZodDiscriminatedUnion).
|
|
28
|
+
*/
|
|
29
|
+
export declare function isZodUnion(schema: z.ZodTypeAny): schema is z.ZodUnion<readonly z.ZodTypeAny[]> | z.ZodDiscriminatedUnion<readonly z.ZodObject<z.ZodRawShape>[], string>;
|
|
30
|
+
/**
|
|
31
|
+
* Extracts the options array from a ZodUnion or ZodDiscriminatedUnion.
|
|
32
|
+
* Both union types have an `.options` property, but TypeScript doesn't
|
|
33
|
+
* create a common accessor after instanceof checks.
|
|
34
|
+
*
|
|
35
|
+
* @param schema - A ZodUnion or ZodDiscriminatedUnion schema
|
|
36
|
+
* @returns The array of union variant schemas
|
|
37
|
+
*/
|
|
38
|
+
export declare function getUnionOptions(schema: z.ZodUnion<readonly z.ZodTypeAny[]> | z.ZodDiscriminatedUnion<readonly z.ZodObject<z.ZodRawShape>[], string>): readonly z.ZodTypeAny[];
|
|
39
|
+
/**
|
|
40
|
+
* Minimum tuple type required by z.union() - at least 2 elements.
|
|
41
|
+
*/
|
|
42
|
+
type UnionTuple<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [T, T, ...T[]];
|
|
43
|
+
/**
|
|
44
|
+
* Asserts that an array has at least 2 elements, as required by z.union().
|
|
45
|
+
* Throws an error if the array has fewer than 2 elements.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Array of Zod schemas
|
|
48
|
+
* @throws Error if array has fewer than 2 elements
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertUnionOptions<T extends z.ZodTypeAny>(options: readonly T[]): asserts options is UnionTuple<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a z.union() from an array of options with runtime validation.
|
|
53
|
+
* Ensures the array has at least 2 elements as required by Zod.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Array of Zod schemas (must have at least 2 elements)
|
|
56
|
+
* @returns A ZodUnion schema
|
|
57
|
+
* @throws Error if array has fewer than 2 elements
|
|
58
|
+
*/
|
|
59
|
+
export declare function createUnionFromOptions<T extends z.ZodTypeAny>(options: readonly T[]): z.ZodUnion<UnionTuple<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Adds Convex system fields (_id, _creationTime) to a Zod schema.
|
|
62
|
+
*
|
|
63
|
+
* For object schemas: extends with system fields
|
|
64
|
+
* For union schemas: adds system fields to each variant
|
|
65
|
+
*
|
|
66
|
+
* @param tableName - The Convex table name
|
|
67
|
+
* @param schema - The Zod schema (object or union)
|
|
68
|
+
* @returns Schema with system fields added
|
|
69
|
+
*/
|
|
70
|
+
export declare function addSystemFields<TableName extends string, Shape extends z.ZodRawShape>(tableName: TableName, schema: z.ZodObject<Shape>): z.ZodObject<Shape & SystemFields<TableName>>;
|
|
71
|
+
export declare function addSystemFields<TableName extends string, Options extends readonly z.ZodTypeAny[]>(tableName: TableName, schema: z.ZodUnion<Options>): z.ZodUnion<MapSystemFields<TableName, Options>>;
|
|
72
|
+
export 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>;
|
|
73
|
+
export declare function addSystemFields<TableName extends string, S extends z.ZodTypeAny>(tableName: TableName, schema: S): S;
|
|
74
|
+
/**
|
|
75
|
+
* System fields added to Convex documents.
|
|
76
|
+
*/
|
|
77
|
+
type DocSystemFields<TableName extends string> = {
|
|
78
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
79
|
+
_creationTime: z.ZodNumber;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Creates a Zod schema for a Convex document with system fields.
|
|
83
|
+
* Uses .extend() to preserve object-level options like .passthrough(), .strict(),
|
|
84
|
+
* .catchall(), and object-level refinements.
|
|
85
|
+
*
|
|
86
|
+
* @param tableName - The Convex table name
|
|
87
|
+
* @param schema - The Zod object schema for user fields
|
|
88
|
+
* @returns A Zod object schema with _id and _creationTime added
|
|
89
|
+
*/
|
|
90
|
+
export declare function zodDoc<TableName extends string, Shape extends z.ZodRawShape>(tableName: TableName, schema: z.ZodObject<Shape>): z.ZodObject<Shape & DocSystemFields<TableName>>;
|
|
91
|
+
export declare function zodDocOrNull<TableName extends string, Shape extends z.ZodRawShape, Schema extends z.ZodObject<Shape>>(tableName: TableName, schema: Schema): z.ZodUnion<readonly [z.ZodObject<Shape & DocSystemFields<TableName>, z.core.$strip>, z.ZodNull]>;
|
|
92
|
+
/**
|
|
93
|
+
* Defines a Convex table using either:
|
|
94
|
+
* - A raw Zod shape (an object mapping field names to Zod types)
|
|
95
|
+
* - A Zod union schema (for polymorphic tables)
|
|
96
|
+
*
|
|
97
|
+
* For object shapes, this function intentionally accepts a raw shape instead of a ZodObject instance.
|
|
98
|
+
* Accepting raw shapes allows TypeScript to infer field types more accurately and efficiently,
|
|
99
|
+
* leading to better type inference and performance throughout the codebase.
|
|
100
|
+
*
|
|
101
|
+
* For union schemas, this enables polymorphic tables with discriminated unions.
|
|
102
|
+
*
|
|
103
|
+
* Returns the Table definition along with Zod schemas for documents and arrays.
|
|
104
|
+
*
|
|
105
|
+
* @param name - The table name
|
|
106
|
+
* @param schemaOrShape - Either a raw object shape or a Zod union schema
|
|
107
|
+
* @returns A Table with attached helpers (shape, schema, zDoc, docArray, withSystemFields)
|
|
108
|
+
*
|
|
109
|
+
* @example Object shape
|
|
110
|
+
* ```ts
|
|
111
|
+
* const Users = zodTable('users', {
|
|
112
|
+
* name: z.string(),
|
|
113
|
+
* email: z.string().email(),
|
|
114
|
+
* age: z.number().optional()
|
|
115
|
+
* })
|
|
116
|
+
*
|
|
117
|
+
* // Use in schema
|
|
118
|
+
* export default defineSchema({ users: Users.table })
|
|
119
|
+
*
|
|
120
|
+
* // Use for return types
|
|
121
|
+
* export const getUsers = zQuery(query, {},
|
|
122
|
+
* async (ctx) => ctx.db.query('users').collect(),
|
|
123
|
+
* { returns: Users.docArray }
|
|
124
|
+
* )
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example Union schema (polymorphic table)
|
|
128
|
+
* ```ts
|
|
129
|
+
* const shapeSchema = z.union([
|
|
130
|
+
* z.object({ kind: z.literal('circle'), r: z.number() }),
|
|
131
|
+
* z.object({ kind: z.literal('rectangle'), width: z.number() })
|
|
132
|
+
* ])
|
|
133
|
+
*
|
|
134
|
+
* const Shapes = zodTable('shapes', shapeSchema)
|
|
135
|
+
*
|
|
136
|
+
* // Use in schema
|
|
137
|
+
* export default defineSchema({ shapes: Shapes.table })
|
|
138
|
+
*
|
|
139
|
+
* // Use for return types with system fields
|
|
140
|
+
* export const getShapes = zQuery(query, {},
|
|
141
|
+
* async (ctx) => ctx.db.query('shapes').collect(),
|
|
142
|
+
* { returns: Shapes.docArray }
|
|
143
|
+
* )
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
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;
|
|
147
|
+
/**
|
|
148
|
+
* Update schema shape: _id required, _creationTime optional, user fields partial
|
|
149
|
+
*/
|
|
150
|
+
type UpdateShape<TableName extends string, Shape extends z.ZodRawShape> = {
|
|
151
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
152
|
+
_creationTime: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
} & PartialShape<Shape>;
|
|
154
|
+
/**
|
|
155
|
+
* Maps over union options for update schema.
|
|
156
|
+
* Each variant gets _id required, _creationTime optional, and user fields partial.
|
|
157
|
+
*/
|
|
158
|
+
type MapUpdateVariants<TableName extends string, Options extends readonly z.ZodTypeAny[]> = {
|
|
159
|
+
[K in keyof Options]: Options[K] extends z.ZodObject<infer Shape extends z.ZodRawShape> ? z.ZodObject<UpdateShape<TableName, Shape>> : Options[K];
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Computes the update schema type for a given schema.
|
|
163
|
+
* Includes _id (required), _creationTime (optional), and partial user fields.
|
|
164
|
+
* For unions: each variant gets update shape
|
|
165
|
+
* For objects: the whole object gets update shape
|
|
166
|
+
* For other types: returns as-is
|
|
167
|
+
*/
|
|
168
|
+
type UpdateSchemaType<TableName extends string, Schema extends z.ZodTypeAny> = Schema extends z.ZodUnion<infer Options extends readonly z.ZodTypeAny[]> ? z.ZodUnion<MapUpdateVariants<TableName, Options>> : Schema extends z.ZodDiscriminatedUnion<infer Options extends readonly z.ZodObject<z.ZodRawShape>[], infer _Disc extends string> ? z.ZodUnion<MapUpdateVariants<TableName, Options>> : Schema extends z.ZodObject<infer Shape extends z.ZodRawShape> ? z.ZodObject<UpdateShape<TableName, Shape>> : Schema;
|
|
169
|
+
export declare function zodTable<TableName extends string, Shape extends Record<string, z.ZodTypeAny>>(name: TableName, shape: Shape): ReturnType<typeof Table<ConvexValidatorFromZodFieldsAuto<Shape>, TableName>> & {
|
|
170
|
+
shape: Shape;
|
|
171
|
+
zDoc: z.ZodObject<Shape & {
|
|
172
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
173
|
+
_creationTime: z.ZodNumber;
|
|
174
|
+
}>;
|
|
175
|
+
docArray: z.ZodArray<z.ZodObject<Shape & {
|
|
176
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
177
|
+
_creationTime: z.ZodNumber;
|
|
178
|
+
}>>;
|
|
179
|
+
schema: {
|
|
180
|
+
doc: z.ZodObject<Shape & {
|
|
181
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
182
|
+
_creationTime: z.ZodNumber;
|
|
183
|
+
}>;
|
|
184
|
+
docArray: z.ZodArray<z.ZodObject<Shape & {
|
|
185
|
+
_id: ReturnType<typeof zid<TableName>>;
|
|
186
|
+
_creationTime: z.ZodNumber;
|
|
187
|
+
}>>;
|
|
188
|
+
/** The base schema - user fields without system fields */
|
|
189
|
+
base: z.ZodObject<Shape>;
|
|
190
|
+
/** Alias for base - user fields for insert operations */
|
|
191
|
+
insert: z.ZodObject<Shape>;
|
|
192
|
+
/** Update schema - _id required, _creationTime optional, user fields partial */
|
|
193
|
+
update: z.ZodObject<UpdateShape<TableName, Shape>>;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
export declare function zodTable<TableName extends string, Schema extends z.ZodTypeAny>(name: TableName, schema: Schema): {
|
|
197
|
+
table: ReturnType<typeof defineTable>;
|
|
198
|
+
tableName: TableName;
|
|
199
|
+
validator: ReturnType<typeof zodToConvex<Schema>>;
|
|
200
|
+
schema: {
|
|
201
|
+
doc: AddSystemFieldsResult<TableName, Schema>;
|
|
202
|
+
docArray: z.ZodArray<AddSystemFieldsResult<TableName, Schema>>;
|
|
203
|
+
/** The base schema - user fields without system fields */
|
|
204
|
+
base: Schema;
|
|
205
|
+
/** Alias for base - user fields for insert operations */
|
|
206
|
+
insert: Schema;
|
|
207
|
+
/** Update schema - _id required, _creationTime optional, user fields partial */
|
|
208
|
+
update: UpdateSchemaType<TableName, Schema>;
|
|
209
|
+
};
|
|
210
|
+
docArray: z.ZodArray<AddSystemFieldsResult<TableName, Schema>>;
|
|
211
|
+
withSystemFields: () => AddSystemFieldsResult<TableName, Schema>;
|
|
212
|
+
};
|
|
213
|
+
export {};
|
|
214
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables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