zodvex 0.2.1 → 0.2.3
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 +383 -406
- package/dist/index.d.mts +22 -28
- package/dist/index.d.ts +22 -28
- package/dist/index.js +5 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/builders.ts +6 -6
- package/src/custom.ts +5 -1
- package/src/index.ts +1 -1
- package/src/mapping/types.ts +65 -10
package/dist/index.d.mts
CHANGED
|
@@ -13,16 +13,29 @@ type IsZid<T> = T extends {
|
|
|
13
13
|
type ExtractTableName<T> = T extends {
|
|
14
14
|
_tableName: infer TableName;
|
|
15
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
|
+
];
|
|
16
23
|
type ZodValidator = Record<string, z.ZodTypeAny>;
|
|
17
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>;
|
|
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
|
|
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, [
|
|
19
29
|
ConvexValidatorFromZodBase<InnerInner>,
|
|
20
30
|
VNull<null, 'required'>
|
|
21
31
|
], 'required'>> : VUnion<z.infer<Inner> | null, [
|
|
22
32
|
ConvexValidatorFromZodBase<Inner>,
|
|
23
33
|
VNull<null, 'required'>
|
|
24
34
|
], 'required'> : Z extends z.ZodAny ? VAny<'required'> : Z extends z.ZodUnknown ? VAny<'required'> : VAny<'required'>;
|
|
25
|
-
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
|
|
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'>;
|
|
26
39
|
type ConvexValidatorFromZodFields<T extends {
|
|
27
40
|
[key: string]: any;
|
|
28
41
|
}, Constraint extends 'required' | 'optional' = 'required'> = {
|
|
@@ -228,13 +241,13 @@ declare function zActionBuilder<Builder extends (fn: any) => any>(builder: Build
|
|
|
228
241
|
*
|
|
229
242
|
* @example
|
|
230
243
|
* ```ts
|
|
231
|
-
* import { query } from './_generated/server'
|
|
244
|
+
* import { type QueryCtx, query } from './_generated/server'
|
|
232
245
|
* import { zCustomQueryBuilder, customCtx } from 'zodvex'
|
|
233
246
|
*
|
|
234
247
|
* // Create a builder with auth context
|
|
235
248
|
* export const authQuery = zCustomQueryBuilder(
|
|
236
249
|
* query,
|
|
237
|
-
* customCtx(async (ctx) => {
|
|
250
|
+
* customCtx(async (ctx: QueryCtx) => {
|
|
238
251
|
* const user = await getUserOrThrow(ctx)
|
|
239
252
|
* return { user }
|
|
240
253
|
* })
|
|
@@ -257,13 +270,13 @@ declare function zCustomQueryBuilder<Builder extends (fn: any) => any, CustomArg
|
|
|
257
270
|
*
|
|
258
271
|
* @example
|
|
259
272
|
* ```ts
|
|
260
|
-
* import { mutation } from './_generated/server'
|
|
273
|
+
* import { type MutationCtx, mutation } from './_generated/server'
|
|
261
274
|
* import { zCustomMutationBuilder, customCtx } from 'zodvex'
|
|
262
275
|
*
|
|
263
276
|
* // Create a builder with auth context
|
|
264
277
|
* export const authMutation = zCustomMutationBuilder(
|
|
265
278
|
* mutation,
|
|
266
|
-
* customCtx(async (ctx) => {
|
|
279
|
+
* customCtx(async (ctx: MutationCtx) => {
|
|
267
280
|
* const user = await getUserOrThrow(ctx)
|
|
268
281
|
* return { user }
|
|
269
282
|
* })
|
|
@@ -286,13 +299,13 @@ declare function zCustomMutationBuilder<Builder extends (fn: any) => any, Custom
|
|
|
286
299
|
*
|
|
287
300
|
* @example
|
|
288
301
|
* ```ts
|
|
289
|
-
* import { action } from './_generated/server'
|
|
302
|
+
* import { type ActionCtx, action } from './_generated/server'
|
|
290
303
|
* import { zCustomActionBuilder, customCtx } from 'zodvex'
|
|
291
304
|
*
|
|
292
305
|
* // Create a builder with auth context
|
|
293
306
|
* export const authAction = zCustomActionBuilder(
|
|
294
307
|
* action,
|
|
295
|
-
* customCtx(async (ctx) => {
|
|
308
|
+
* customCtx(async (ctx: ActionCtx) => {
|
|
296
309
|
* const identity = await ctx.auth.getUserIdentity()
|
|
297
310
|
* if (!identity) throw new Error('Unauthorized')
|
|
298
311
|
* return { userId: identity.subject }
|
|
@@ -473,23 +486,4 @@ declare function safePick(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any
|
|
|
473
486
|
*/
|
|
474
487
|
declare function safeOmit(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any>;
|
|
475
488
|
|
|
476
|
-
|
|
477
|
-
returns?: R;
|
|
478
|
-
}): RegisteredQuery<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
479
|
-
declare function zInternalQuery<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalQuery: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
480
|
-
returns?: R;
|
|
481
|
-
}): RegisteredQuery<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
482
|
-
declare function zMutation<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(mutation: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
483
|
-
returns?: R;
|
|
484
|
-
}): RegisteredMutation<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
485
|
-
declare function zInternalMutation<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalMutation: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
486
|
-
returns?: R;
|
|
487
|
-
}): RegisteredMutation<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
488
|
-
declare function zAction<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(action: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
489
|
-
returns?: R;
|
|
490
|
-
}): RegisteredAction<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
491
|
-
declare function zInternalAction<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalAction: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
492
|
-
returns?: R;
|
|
493
|
-
}): RegisteredAction<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
494
|
-
|
|
495
|
-
export { type ConvexCodec, type ConvexValidatorFromZod, type ConvexValidatorFromZodFieldsAuto, type CustomBuilder, type ExtractCtx, type ExtractVisibility, type InferArgs, type InferHandlerReturns, type InferReturns, type PreserveReturnType, type Zid, type ZodToConvexArgs, type ZodValidator, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, handleZodValidationError, isDateSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, zAction, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zInternalAction, zInternalMutation, zInternalQuery, zMutation, zMutationBuilder, zPaginated, zQuery, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields };
|
|
489
|
+
export { type ConvexCodec, type ConvexValidatorFromZod, type ConvexValidatorFromZodFieldsAuto, type CustomBuilder, type ExtractCtx, type ExtractVisibility, type InferArgs, type InferHandlerReturns, type InferReturns, type PreserveReturnType, type Zid, type ZodToConvexArgs, type ZodValidator, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, handleZodValidationError, isDateSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zMutationBuilder, zPaginated, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,16 +13,29 @@ type IsZid<T> = T extends {
|
|
|
13
13
|
type ExtractTableName<T> = T extends {
|
|
14
14
|
_tableName: infer TableName;
|
|
15
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
|
+
];
|
|
16
23
|
type ZodValidator = Record<string, z.ZodTypeAny>;
|
|
17
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>;
|
|
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
|
|
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, [
|
|
19
29
|
ConvexValidatorFromZodBase<InnerInner>,
|
|
20
30
|
VNull<null, 'required'>
|
|
21
31
|
], 'required'>> : VUnion<z.infer<Inner> | null, [
|
|
22
32
|
ConvexValidatorFromZodBase<Inner>,
|
|
23
33
|
VNull<null, 'required'>
|
|
24
34
|
], 'required'> : Z extends z.ZodAny ? VAny<'required'> : Z extends z.ZodUnknown ? VAny<'required'> : VAny<'required'>;
|
|
25
|
-
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
|
|
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'>;
|
|
26
39
|
type ConvexValidatorFromZodFields<T extends {
|
|
27
40
|
[key: string]: any;
|
|
28
41
|
}, Constraint extends 'required' | 'optional' = 'required'> = {
|
|
@@ -228,13 +241,13 @@ declare function zActionBuilder<Builder extends (fn: any) => any>(builder: Build
|
|
|
228
241
|
*
|
|
229
242
|
* @example
|
|
230
243
|
* ```ts
|
|
231
|
-
* import { query } from './_generated/server'
|
|
244
|
+
* import { type QueryCtx, query } from './_generated/server'
|
|
232
245
|
* import { zCustomQueryBuilder, customCtx } from 'zodvex'
|
|
233
246
|
*
|
|
234
247
|
* // Create a builder with auth context
|
|
235
248
|
* export const authQuery = zCustomQueryBuilder(
|
|
236
249
|
* query,
|
|
237
|
-
* customCtx(async (ctx) => {
|
|
250
|
+
* customCtx(async (ctx: QueryCtx) => {
|
|
238
251
|
* const user = await getUserOrThrow(ctx)
|
|
239
252
|
* return { user }
|
|
240
253
|
* })
|
|
@@ -257,13 +270,13 @@ declare function zCustomQueryBuilder<Builder extends (fn: any) => any, CustomArg
|
|
|
257
270
|
*
|
|
258
271
|
* @example
|
|
259
272
|
* ```ts
|
|
260
|
-
* import { mutation } from './_generated/server'
|
|
273
|
+
* import { type MutationCtx, mutation } from './_generated/server'
|
|
261
274
|
* import { zCustomMutationBuilder, customCtx } from 'zodvex'
|
|
262
275
|
*
|
|
263
276
|
* // Create a builder with auth context
|
|
264
277
|
* export const authMutation = zCustomMutationBuilder(
|
|
265
278
|
* mutation,
|
|
266
|
-
* customCtx(async (ctx) => {
|
|
279
|
+
* customCtx(async (ctx: MutationCtx) => {
|
|
267
280
|
* const user = await getUserOrThrow(ctx)
|
|
268
281
|
* return { user }
|
|
269
282
|
* })
|
|
@@ -286,13 +299,13 @@ declare function zCustomMutationBuilder<Builder extends (fn: any) => any, Custom
|
|
|
286
299
|
*
|
|
287
300
|
* @example
|
|
288
301
|
* ```ts
|
|
289
|
-
* import { action } from './_generated/server'
|
|
302
|
+
* import { type ActionCtx, action } from './_generated/server'
|
|
290
303
|
* import { zCustomActionBuilder, customCtx } from 'zodvex'
|
|
291
304
|
*
|
|
292
305
|
* // Create a builder with auth context
|
|
293
306
|
* export const authAction = zCustomActionBuilder(
|
|
294
307
|
* action,
|
|
295
|
-
* customCtx(async (ctx) => {
|
|
308
|
+
* customCtx(async (ctx: ActionCtx) => {
|
|
296
309
|
* const identity = await ctx.auth.getUserIdentity()
|
|
297
310
|
* if (!identity) throw new Error('Unauthorized')
|
|
298
311
|
* return { userId: identity.subject }
|
|
@@ -473,23 +486,4 @@ declare function safePick(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any
|
|
|
473
486
|
*/
|
|
474
487
|
declare function safeOmit(schema: z.ZodObject<any>, mask: Mask): z.ZodObject<any>;
|
|
475
488
|
|
|
476
|
-
|
|
477
|
-
returns?: R;
|
|
478
|
-
}): RegisteredQuery<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
479
|
-
declare function zInternalQuery<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalQuery: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
480
|
-
returns?: R;
|
|
481
|
-
}): RegisteredQuery<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
482
|
-
declare function zMutation<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(mutation: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
483
|
-
returns?: R;
|
|
484
|
-
}): RegisteredMutation<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
485
|
-
declare function zInternalMutation<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalMutation: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
486
|
-
returns?: R;
|
|
487
|
-
}): RegisteredMutation<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
488
|
-
declare function zAction<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(action: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
489
|
-
returns?: R;
|
|
490
|
-
}): RegisteredAction<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
491
|
-
declare function zInternalAction<Builder extends (fn: any) => any, A extends z.ZodTypeAny | Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny | undefined = undefined, Visibility extends FunctionVisibility = ExtractVisibility<Builder>>(internalAction: Builder, input: A, handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>, options?: {
|
|
492
|
-
returns?: R;
|
|
493
|
-
}): RegisteredAction<Visibility, ZodToConvexArgs<A>, Promise<InferReturns<R>>>;
|
|
494
|
-
|
|
495
|
-
export { type ConvexCodec, type ConvexValidatorFromZod, type ConvexValidatorFromZodFieldsAuto, type CustomBuilder, type ExtractCtx, type ExtractVisibility, type InferArgs, type InferHandlerReturns, type InferReturns, type PreserveReturnType, type Zid, type ZodToConvexArgs, type ZodValidator, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, handleZodValidationError, isDateSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, zAction, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zInternalAction, zInternalMutation, zInternalQuery, zMutation, zMutationBuilder, zPaginated, zQuery, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields };
|
|
489
|
+
export { type ConvexCodec, type ConvexValidatorFromZod, type ConvexValidatorFromZodFieldsAuto, type CustomBuilder, type ExtractCtx, type ExtractVisibility, type InferArgs, type InferHandlerReturns, type InferReturns, type PreserveReturnType, type Zid, type ZodToConvexArgs, type ZodValidator, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, handleZodValidationError, isDateSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zMutationBuilder, zPaginated, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields };
|
package/dist/index.js
CHANGED
|
@@ -724,7 +724,11 @@ function customFnBuilder(builder, customization) {
|
|
|
724
724
|
handleZodValidationError(e, "returns");
|
|
725
725
|
}
|
|
726
726
|
if (added?.onSuccess) {
|
|
727
|
-
await added.onSuccess({
|
|
727
|
+
await added.onSuccess({
|
|
728
|
+
ctx,
|
|
729
|
+
args: parsed.data,
|
|
730
|
+
result: validated
|
|
731
|
+
});
|
|
728
732
|
}
|
|
729
733
|
return toConvexJS(returns, validated);
|
|
730
734
|
}
|
|
@@ -849,9 +853,6 @@ function zQuery(query, input, handler, options) {
|
|
|
849
853
|
}
|
|
850
854
|
});
|
|
851
855
|
}
|
|
852
|
-
function zInternalQuery(internalQuery, input, handler, options) {
|
|
853
|
-
return zQuery(internalQuery, input, handler, options);
|
|
854
|
-
}
|
|
855
856
|
function zMutation(mutation, input, handler, options) {
|
|
856
857
|
let zodSchema;
|
|
857
858
|
let args;
|
|
@@ -891,9 +892,6 @@ function zMutation(mutation, input, handler, options) {
|
|
|
891
892
|
}
|
|
892
893
|
});
|
|
893
894
|
}
|
|
894
|
-
function zInternalMutation(internalMutation, input, handler, options) {
|
|
895
|
-
return zMutation(internalMutation, input, handler, options);
|
|
896
|
-
}
|
|
897
895
|
function zAction(action, input, handler, options) {
|
|
898
896
|
let zodSchema;
|
|
899
897
|
let args;
|
|
@@ -933,9 +931,6 @@ function zAction(action, input, handler, options) {
|
|
|
933
931
|
}
|
|
934
932
|
});
|
|
935
933
|
}
|
|
936
|
-
function zInternalAction(internalAction, input, handler, options) {
|
|
937
|
-
return zAction(internalAction, input, handler, options);
|
|
938
|
-
}
|
|
939
934
|
|
|
940
935
|
// src/builders.ts
|
|
941
936
|
function zQueryBuilder(builder) {
|
|
@@ -1020,7 +1015,6 @@ exports.returnsAs = returnsAs;
|
|
|
1020
1015
|
exports.safeOmit = safeOmit;
|
|
1021
1016
|
exports.safePick = safePick;
|
|
1022
1017
|
exports.toConvexJS = toConvexJS;
|
|
1023
|
-
exports.zAction = zAction;
|
|
1024
1018
|
exports.zActionBuilder = zActionBuilder;
|
|
1025
1019
|
exports.zCustomAction = zCustomAction;
|
|
1026
1020
|
exports.zCustomActionBuilder = zCustomActionBuilder;
|
|
@@ -1028,13 +1022,8 @@ exports.zCustomMutation = zCustomMutation;
|
|
|
1028
1022
|
exports.zCustomMutationBuilder = zCustomMutationBuilder;
|
|
1029
1023
|
exports.zCustomQuery = zCustomQuery;
|
|
1030
1024
|
exports.zCustomQueryBuilder = zCustomQueryBuilder;
|
|
1031
|
-
exports.zInternalAction = zInternalAction;
|
|
1032
|
-
exports.zInternalMutation = zInternalMutation;
|
|
1033
|
-
exports.zInternalQuery = zInternalQuery;
|
|
1034
|
-
exports.zMutation = zMutation;
|
|
1035
1025
|
exports.zMutationBuilder = zMutationBuilder;
|
|
1036
1026
|
exports.zPaginated = zPaginated;
|
|
1037
|
-
exports.zQuery = zQuery;
|
|
1038
1027
|
exports.zQueryBuilder = zQueryBuilder;
|
|
1039
1028
|
exports.zid = zid;
|
|
1040
1029
|
exports.zodDoc = zodDoc;
|