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/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Type-safe Convex functions with Zod schemas. Preserve Convex's optional/nullable
|
|
|
19
19
|
- [API Reference](#api-reference)
|
|
20
20
|
- [Advanced Usage](#advanced-usage)
|
|
21
21
|
- [Custom Context Builders](#custom-context-builders)
|
|
22
|
+
- [Hooks and Transforms](#hooks-and-transforms)
|
|
22
23
|
- [Date Handling](#date-handling)
|
|
23
24
|
- [Return Type Helpers](#return-type-helpers)
|
|
24
25
|
- [Working with Large Schemas](#working-with-large-schemas)
|
|
@@ -446,6 +447,80 @@ export const updateProfile = authMutation({
|
|
|
446
447
|
})
|
|
447
448
|
```
|
|
448
449
|
|
|
450
|
+
#### Hooks and Transforms
|
|
451
|
+
|
|
452
|
+
For advanced use cases like logging, analytics, or data transformations, use `customCtxWithHooks`:
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
import { zCustomMutationBuilder, customCtxWithHooks } from 'zodvex'
|
|
456
|
+
import { type MutationCtx, mutation } from './_generated/server'
|
|
457
|
+
|
|
458
|
+
export const secureMutation = zCustomMutationBuilder(
|
|
459
|
+
mutation,
|
|
460
|
+
customCtxWithHooks(async (ctx: MutationCtx) => {
|
|
461
|
+
const securityCtx = await getSecurityContext(ctx)
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
// Custom context (same as customCtx)
|
|
465
|
+
ctx: { securityCtx },
|
|
466
|
+
|
|
467
|
+
// Hooks: observe execution (side effects, no return value)
|
|
468
|
+
hooks: {
|
|
469
|
+
onSuccess: ({ ctx, args, result }) => {
|
|
470
|
+
// Called after successful execution
|
|
471
|
+
console.log('Mutation succeeded:', { args, result })
|
|
472
|
+
analytics.track('mutation_success', { userId: ctx.securityCtx.userId })
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
// Transforms: modify data in the flow
|
|
477
|
+
transforms: {
|
|
478
|
+
// Transform args after validation, before handler
|
|
479
|
+
input: (args, schema) => {
|
|
480
|
+
// e.g., Convert wire format to runtime objects
|
|
481
|
+
return transformIncomingArgs(args, securityCtx)
|
|
482
|
+
},
|
|
483
|
+
// Transform result after handler, before response
|
|
484
|
+
output: (result, schema) => {
|
|
485
|
+
// e.g., Mask sensitive fields based on permissions
|
|
486
|
+
return transformOutgoingResult(result, securityCtx)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
})
|
|
491
|
+
)
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**Execution order:**
|
|
495
|
+
|
|
496
|
+
1. Args received from client
|
|
497
|
+
2. Zod validation on args
|
|
498
|
+
3. `transforms.input` runs (if provided)
|
|
499
|
+
4. Handler executes
|
|
500
|
+
5. Zod validation on returns (if provided)
|
|
501
|
+
6. `hooks.onSuccess` runs (if provided)
|
|
502
|
+
7. `transforms.output` runs (if provided)
|
|
503
|
+
8. Response sent to client
|
|
504
|
+
|
|
505
|
+
**Use cases:**
|
|
506
|
+
|
|
507
|
+
| Feature | Use Case |
|
|
508
|
+
|---------|----------|
|
|
509
|
+
| `hooks.onSuccess` | Logging, analytics, audit trails, cache invalidation |
|
|
510
|
+
| `transforms.input` | Wire format → runtime objects, field decryption, data hydration |
|
|
511
|
+
| `transforms.output` | Sensitive field masking, data redaction, format conversion |
|
|
512
|
+
|
|
513
|
+
**Note:** Both `transforms.input` and `transforms.output` can be async:
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
transforms: {
|
|
517
|
+
input: async (args, schema) => {
|
|
518
|
+
const decrypted = await decrypt(args.sensitiveField)
|
|
519
|
+
return { ...args, sensitiveField: decrypted }
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
449
524
|
### Date Handling
|
|
450
525
|
|
|
451
526
|
zodvex automatically converts dates between JavaScript `Date` objects and Convex timestamps when using `z.date()` in your schemas.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-returns.d.ts","sourceRoot":"","sources":["../../src/__type-tests__/infer-returns.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zodTable-inference.d.ts","sourceRoot":"","sources":["../../src/__type-tests__/zodTable-inference.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { FunctionVisibility, RegisteredAction, RegisteredMutation, RegisteredQuery } from 'convex/server';
|
|
2
|
+
import type { PropertyValidators } from 'convex/values';
|
|
3
|
+
import type { Customization } from 'convex-helpers/server/customFunctions';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { type CustomBuilder } from './custom';
|
|
6
|
+
import type { ExtractCtx, ExtractVisibility, InferHandlerReturns, InferReturns, ZodToConvexArgs } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a reusable query builder from a Convex query builder.
|
|
9
|
+
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { query } from './_generated/server'
|
|
14
|
+
* import { zQueryBuilder } from 'zodvex'
|
|
15
|
+
*
|
|
16
|
+
* // Create a reusable builder
|
|
17
|
+
* export const zq = zQueryBuilder(query)
|
|
18
|
+
*
|
|
19
|
+
* // Use it with Convex-style object syntax
|
|
20
|
+
* export const getUser = zq({
|
|
21
|
+
* args: { id: z.string() },
|
|
22
|
+
* handler: async (ctx, { id }) => {
|
|
23
|
+
* return ctx.db.get(id)
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export 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: {
|
|
29
|
+
args?: A;
|
|
30
|
+
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
31
|
+
returns?: R;
|
|
32
|
+
}) => RegisteredQuery<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a reusable mutation builder from a Convex mutation builder.
|
|
35
|
+
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { mutation } from './_generated/server'
|
|
40
|
+
* import { zMutationBuilder } from 'zodvex'
|
|
41
|
+
*
|
|
42
|
+
* // Create a reusable builder
|
|
43
|
+
* export const zm = zMutationBuilder(mutation)
|
|
44
|
+
*
|
|
45
|
+
* // Use it with Convex-style object syntax
|
|
46
|
+
* export const updateUser = zm({
|
|
47
|
+
* args: { id: z.string(), name: z.string() },
|
|
48
|
+
* handler: async (ctx, { id, name }) => {
|
|
49
|
+
* return ctx.db.patch(id, { name })
|
|
50
|
+
* }
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export 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: {
|
|
55
|
+
args?: A;
|
|
56
|
+
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
57
|
+
returns?: R;
|
|
58
|
+
}) => RegisteredMutation<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a reusable action builder from a Convex action builder.
|
|
61
|
+
* Returns a builder function that accepts Convex-style config objects with args, handler, and returns.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { action } from './_generated/server'
|
|
66
|
+
* import { zActionBuilder } from 'zodvex'
|
|
67
|
+
*
|
|
68
|
+
* // Create a reusable builder
|
|
69
|
+
* export const za = zActionBuilder(action)
|
|
70
|
+
*
|
|
71
|
+
* // Use it with Convex-style object syntax
|
|
72
|
+
* export const sendEmail = za({
|
|
73
|
+
* args: { to: z.string().email(), subject: z.string() },
|
|
74
|
+
* handler: async (ctx, { to, subject }) => {
|
|
75
|
+
* // Send email
|
|
76
|
+
* }
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export 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: {
|
|
81
|
+
args?: A;
|
|
82
|
+
handler: (ctx: ExtractCtx<Builder>, args: ZodToConvexArgs<A extends undefined ? Record<string, never> : A>) => InferHandlerReturns<R> | Promise<InferHandlerReturns<R>>;
|
|
83
|
+
returns?: R;
|
|
84
|
+
}) => RegisteredAction<Visibility, ZodToConvexArgs<A extends undefined ? Record<string, never> : A>, Promise<InferReturns<R>>>;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a custom query builder with context injection from a Convex query builder.
|
|
87
|
+
* Allows you to add custom context (like auth, permissions, etc.) to your queries.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { type QueryCtx, query } from './_generated/server'
|
|
92
|
+
* import { zCustomQueryBuilder, customCtx } from 'zodvex'
|
|
93
|
+
*
|
|
94
|
+
* // Create a builder with auth context
|
|
95
|
+
* export const authQuery = zCustomQueryBuilder(
|
|
96
|
+
* query,
|
|
97
|
+
* customCtx(async (ctx: QueryCtx) => {
|
|
98
|
+
* const user = await getUserOrThrow(ctx)
|
|
99
|
+
* return { user }
|
|
100
|
+
* })
|
|
101
|
+
* )
|
|
102
|
+
*
|
|
103
|
+
* // Use it with automatic user injection
|
|
104
|
+
* export const getMyProfile = authQuery({
|
|
105
|
+
* args: {},
|
|
106
|
+
* handler: async (ctx) => {
|
|
107
|
+
* // ctx.user is automatically available
|
|
108
|
+
* return ctx.db.get(ctx.user._id)
|
|
109
|
+
* }
|
|
110
|
+
* })
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export 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>;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a custom mutation builder with context injection from a Convex mutation builder.
|
|
116
|
+
* Allows you to add custom context (like auth, permissions, etc.) to your mutations.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { type MutationCtx, mutation } from './_generated/server'
|
|
121
|
+
* import { zCustomMutationBuilder, customCtx } from 'zodvex'
|
|
122
|
+
*
|
|
123
|
+
* // Create a builder with auth context
|
|
124
|
+
* export const authMutation = zCustomMutationBuilder(
|
|
125
|
+
* mutation,
|
|
126
|
+
* customCtx(async (ctx: MutationCtx) => {
|
|
127
|
+
* const user = await getUserOrThrow(ctx)
|
|
128
|
+
* return { user }
|
|
129
|
+
* })
|
|
130
|
+
* )
|
|
131
|
+
*
|
|
132
|
+
* // Use it with automatic user injection
|
|
133
|
+
* export const updateProfile = authMutation({
|
|
134
|
+
* args: { name: z.string() },
|
|
135
|
+
* handler: async (ctx, { name }) => {
|
|
136
|
+
* // ctx.user is automatically available
|
|
137
|
+
* await ctx.db.patch(ctx.user._id, { name })
|
|
138
|
+
* }
|
|
139
|
+
* })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export 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>;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a custom action builder with context injection from a Convex action builder.
|
|
145
|
+
* Allows you to add custom context (like auth, permissions, etc.) to your actions.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { type ActionCtx, action } from './_generated/server'
|
|
150
|
+
* import { zCustomActionBuilder, customCtx } from 'zodvex'
|
|
151
|
+
*
|
|
152
|
+
* // Create a builder with auth context
|
|
153
|
+
* export const authAction = zCustomActionBuilder(
|
|
154
|
+
* action,
|
|
155
|
+
* customCtx(async (ctx: ActionCtx) => {
|
|
156
|
+
* const identity = await ctx.auth.getUserIdentity()
|
|
157
|
+
* if (!identity) throw new Error('Unauthorized')
|
|
158
|
+
* return { userId: identity.subject }
|
|
159
|
+
* })
|
|
160
|
+
* )
|
|
161
|
+
*
|
|
162
|
+
* // Use it with automatic auth injection
|
|
163
|
+
* export const sendEmail = authAction({
|
|
164
|
+
* args: { to: z.string().email() },
|
|
165
|
+
* handler: async (ctx, { to }) => {
|
|
166
|
+
* // ctx.userId is automatically available
|
|
167
|
+
* await sendEmailService(to, ctx.userId)
|
|
168
|
+
* }
|
|
169
|
+
* })
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export 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>;
|
|
173
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,M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
package/dist/codec.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type ConvexCodec<T> = {
|
|
3
|
+
validator: any;
|
|
4
|
+
encode: (value: T) => any;
|
|
5
|
+
decode: (value: any) => T;
|
|
6
|
+
pick: <K extends keyof T>(keys: K[]) => ConvexCodec<Pick<T, K>>;
|
|
7
|
+
};
|
|
8
|
+
export declare function convexCodec<T>(schema: z.ZodType<T>): ConvexCodec<T>;
|
|
9
|
+
export declare function toConvexJS(schema?: any, value?: any): any;
|
|
10
|
+
export declare function fromConvexJS(value: any, schema: any): any;
|
|
11
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AASvB,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,SAAS,EAAE,GAAG,CAAA;IACd,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAA;IACzB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,CAAA;IACzB,IAAI,EAAE,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;CAChE,CAAA;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAmBnE;AAGD,wBAAgB,UAAU,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG,CASzD;AAkGD,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAG,GAAG,CA+EzD"}
|
package/dist/custom.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type ArgsArrayToObject, type DefaultFunctionArgs, type FunctionVisibility, type GenericDataModel, type GenericQueryCtx, type QueryBuilder } from 'convex/server';
|
|
2
|
+
import { type PropertyValidators } from 'convex/values';
|
|
3
|
+
import { type Customization } from 'convex-helpers/server/customFunctions';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { type ZodValidator } from './mapping';
|
|
6
|
+
import type { ExtractCtx } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Hooks for observing the function execution (side effects, no return value).
|
|
9
|
+
*/
|
|
10
|
+
export type CustomizationHooks = {
|
|
11
|
+
/** Called after successful execution with access to ctx, args, and result */
|
|
12
|
+
onSuccess?: (info: {
|
|
13
|
+
ctx: unknown;
|
|
14
|
+
args: Record<string, unknown>;
|
|
15
|
+
result: unknown;
|
|
16
|
+
}) => void | Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Transforms for modifying data in the function flow.
|
|
20
|
+
*/
|
|
21
|
+
export type CustomizationTransforms = {
|
|
22
|
+
/** Transform args after validation but before handler receives them */
|
|
23
|
+
input?: (args: unknown, schema: z.ZodTypeAny) => unknown | Promise<unknown>;
|
|
24
|
+
/** Transform the output after validation but before wire encoding */
|
|
25
|
+
output?: (result: unknown, schema: z.ZodTypeAny) => unknown | Promise<unknown>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Result returned from a customization input function.
|
|
29
|
+
* Separates Convex concepts (ctx, args) from hooks (side effects) and transforms (data modifications).
|
|
30
|
+
*/
|
|
31
|
+
export type CustomizationResult<CustomCtx extends Record<string, any> = Record<string, any>, CustomArgs extends Record<string, any> = Record<string, any>> = {
|
|
32
|
+
/** Custom context to merge with base context */
|
|
33
|
+
ctx?: CustomCtx;
|
|
34
|
+
/** Custom args to merge with parsed args */
|
|
35
|
+
args?: CustomArgs;
|
|
36
|
+
/** Hooks for observing execution (side effects) */
|
|
37
|
+
hooks?: CustomizationHooks;
|
|
38
|
+
/** Transforms for modifying the data flow */
|
|
39
|
+
transforms?: CustomizationTransforms;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Extended input result that includes hooks and transforms.
|
|
43
|
+
* This is what the input function returns internally.
|
|
44
|
+
*/
|
|
45
|
+
export type CustomizationInputResult<OutCtx extends Record<string, any>, OutArgs extends Record<string, any>> = {
|
|
46
|
+
ctx: OutCtx;
|
|
47
|
+
args: OutArgs;
|
|
48
|
+
hooks?: CustomizationHooks;
|
|
49
|
+
transforms?: CustomizationTransforms;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Customization type that supports hooks and transforms.
|
|
53
|
+
* This extends convex-helpers' Customization pattern to include
|
|
54
|
+
* hooks (side effects) and transforms (data modifications).
|
|
55
|
+
*
|
|
56
|
+
* Use customCtxWithHooks() to create instances of this type.
|
|
57
|
+
*/
|
|
58
|
+
export type CustomizationWithHooks<InCtx extends Record<string, any>, OutCtx extends Record<string, any> = Record<string, any>, OutArgs extends Record<string, any> = Record<string, any>, ExtraArgs extends Record<string, any> = Record<string, any>> = {
|
|
59
|
+
args: Record<string, never>;
|
|
60
|
+
input: (ctx: InCtx, args?: Record<string, unknown>, extra?: ExtraArgs) => Promise<CustomizationInputResult<OutCtx, OutArgs>> | CustomizationInputResult<OutCtx, OutArgs>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* A helper for defining a Customization with full support for hooks and transforms.
|
|
64
|
+
* Use this instead of customCtx when you need onSuccess, transforms.input, transforms.output, etc.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const secureMutation = zCustomMutationBuilder(
|
|
69
|
+
* mutation,
|
|
70
|
+
* customCtxWithHooks(async (ctx: MutationCtx) => {
|
|
71
|
+
* const securityCtx = await getSecurityContext(ctx)
|
|
72
|
+
* return {
|
|
73
|
+
* ctx: { securityCtx },
|
|
74
|
+
* hooks: {
|
|
75
|
+
* onSuccess: ({ result }) => console.log('Mutation returned:', result),
|
|
76
|
+
* },
|
|
77
|
+
* transforms: {
|
|
78
|
+
* // Transform incoming args (e.g., wire format → runtime objects)
|
|
79
|
+
* input: (args, schema) => transformIncomingArgs(args, securityCtx),
|
|
80
|
+
* // Transform outgoing result (e.g., runtime objects → wire format)
|
|
81
|
+
* output: (result, schema) => transformOutgoingResult(result, securityCtx),
|
|
82
|
+
* },
|
|
83
|
+
* }
|
|
84
|
+
* })
|
|
85
|
+
* )
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function customCtxWithHooks<InCtx extends Record<string, any>, OutCtx extends Record<string, any> = Record<string, any>, OutArgs extends Record<string, any> = Record<string, any>>(fn: (ctx: InCtx) => Promise<CustomizationResult<OutCtx, OutArgs>> | CustomizationResult<OutCtx, OutArgs>): CustomizationWithHooks<InCtx, OutCtx, OutArgs>;
|
|
89
|
+
type OneArgArray<ArgsObject extends DefaultFunctionArgs = DefaultFunctionArgs> = [ArgsObject];
|
|
90
|
+
type NullToUndefinedOrNull<T> = T extends null ? T | undefined | void : T;
|
|
91
|
+
type Returns<T> = Promise<NullToUndefinedOrNull<T>> | NullToUndefinedOrNull<T>;
|
|
92
|
+
type ReturnValueInput<ReturnsValidator extends z.ZodTypeAny | ZodValidator | void> = [
|
|
93
|
+
ReturnsValidator
|
|
94
|
+
] extends [z.ZodTypeAny] ? Returns<z.output<ReturnsValidator>> : [ReturnsValidator] extends [ZodValidator] ? Returns<z.output<z.ZodObject<ReturnsValidator>>> : any;
|
|
95
|
+
type ReturnValueOutput<ReturnsValidator extends z.ZodTypeAny | ZodValidator | void> = [
|
|
96
|
+
ReturnsValidator
|
|
97
|
+
] extends [z.ZodTypeAny] ? Returns<z.output<ReturnsValidator>> : [ReturnsValidator] extends [ZodValidator] ? Returns<z.output<z.ZodObject<ReturnsValidator>>> : any;
|
|
98
|
+
type ArgsInput<ArgsValidator extends ZodValidator | z.ZodObject<any> | void> = [
|
|
99
|
+
ArgsValidator
|
|
100
|
+
] extends [z.ZodObject<any>] ? [z.input<ArgsValidator>] : [ArgsValidator] extends [ZodValidator] ? [z.input<z.ZodObject<ArgsValidator>>] : OneArgArray;
|
|
101
|
+
type ArgsOutput<ArgsValidator extends ZodValidator | z.ZodObject<any> | void> = [
|
|
102
|
+
ArgsValidator
|
|
103
|
+
] extends [z.ZodObject<any>] ? [z.output<ArgsValidator>] : [ArgsValidator] extends [ZodValidator] ? [z.output<z.ZodObject<ArgsValidator>>] : OneArgArray;
|
|
104
|
+
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
105
|
+
type Expand<ObjectType extends Record<any, any>> = ObjectType extends Record<any, any> ? {
|
|
106
|
+
[Key in keyof ObjectType]: ObjectType[Key];
|
|
107
|
+
} : never;
|
|
108
|
+
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];
|
|
109
|
+
type Registration<FuncType extends 'query' | 'mutation' | 'action', Visibility extends FunctionVisibility, Args extends DefaultFunctionArgs, Output> = FuncType extends 'query' ? import('convex/server').RegisteredQuery<Visibility, Args, Output> : FuncType extends 'mutation' ? import('convex/server').RegisteredMutation<Visibility, Args, Output> : import('convex/server').RegisteredAction<Visibility, Args, Output>;
|
|
110
|
+
/**
|
|
111
|
+
* A builder that customizes a Convex function, whether or not it validates
|
|
112
|
+
* arguments. If the customization requires arguments, however, the resulting
|
|
113
|
+
* builder will require argument validation too.
|
|
114
|
+
*
|
|
115
|
+
* This is our own Zod-aware CustomBuilder type that properly handles Zod validators.
|
|
116
|
+
*/
|
|
117
|
+
export 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>> = {
|
|
118
|
+
<ArgsValidator extends ZodValidator | z.ZodObject<any> | void, ReturnsZodValidator extends z.ZodTypeAny | ZodValidator | void = void, ReturnValue extends ReturnValueInput<ReturnsZodValidator> = any>(func: ({
|
|
119
|
+
/**
|
|
120
|
+
* Specify the arguments to the function as a Zod validator.
|
|
121
|
+
*/
|
|
122
|
+
args?: ArgsValidator;
|
|
123
|
+
handler: (ctx: Overwrite<InputCtx, CustomCtx>, ...args: ArgsForHandlerType<ArgsOutput<ArgsValidator>, CustomMadeArgs>) => ReturnValue;
|
|
124
|
+
/**
|
|
125
|
+
* Validates the value returned by the function.
|
|
126
|
+
* Note: you can't pass an object directly without wrapping it
|
|
127
|
+
* in `z.object()`.
|
|
128
|
+
*/
|
|
129
|
+
returns?: ReturnsZodValidator;
|
|
130
|
+
/**
|
|
131
|
+
* If true, the function will not be validated by Convex,
|
|
132
|
+
* in case you're seeing performance issues with validating twice.
|
|
133
|
+
*/
|
|
134
|
+
skipConvexValidation?: boolean;
|
|
135
|
+
} & {
|
|
136
|
+
[key in keyof ExtraArgs as key extends 'args' | 'handler' | 'skipConvexValidation' | 'returns' ? never : key]: ExtraArgs[key];
|
|
137
|
+
}) | {
|
|
138
|
+
(ctx: Overwrite<InputCtx, CustomCtx>, ...args: ArgsForHandlerType<ArgsOutput<ArgsValidator>, CustomMadeArgs>): ReturnValue;
|
|
139
|
+
}): Registration<FuncType, Visibility, ArgsArrayToObject<CustomArgsValidator extends Record<string, never> ? ArgsInput<ArgsValidator> : ArgsInput<ArgsValidator> extends [infer A] ? [Expand<A & import('convex/values').ObjectType<CustomArgsValidator>>] : [import('convex/values').ObjectType<CustomArgsValidator>]>, ReturnsZodValidator extends void ? ReturnValue : ReturnValueOutput<ReturnsZodValidator>>;
|
|
140
|
+
};
|
|
141
|
+
export 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> | CustomizationWithHooks<Ctx, CustomCtx, CustomMadeArgs, ExtraArgs>): (fn: any) => any;
|
|
142
|
+
export 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>;
|
|
143
|
+
export 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>;
|
|
144
|
+
export 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>;
|
|
145
|
+
export 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>;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../src/custom.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EAErB,KAAK,eAAe,EAEpB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACpE,OAAO,EAAE,KAAK,aAAa,EAAQ,MAAM,uCAAuC,CAAA;AAChF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,WAAW,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAqB,MAAM,SAAS,CAAA;AAG5D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6EAA6E;IAC7E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE;QACjB,GAAG,EAAE,OAAO,CAAA;QACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7B,MAAM,EAAE,OAAO,CAAA;KAChB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,uEAAuE;IACvE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,UAAU,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,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,OAAO,SAAS,CAAC,EAAE,EAAE,GAAG,KAAK,GAAG,EAChC,UAAU,SAAS,kBAAkB,GAAG,QAAQ,EAChD,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE3D,QAAQ,EAAE,OAAO,EACjB,aAAa,EAAE,aAAa,CAAC,GAAG,EAAE,mBAAmB,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,GAC3F,aAAa,CACd,UAAU,EACV,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,UAAU,CAAC,OAAO,CAAC,EACnB,UAAU,EACV,SAAS,CACV,CAAA;AAuBD,wBAAgB,aAAa,CAC3B,mBAAmB,SAAS,kBAAkB,EAC9C,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrC,cAAc,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1C,OAAO,SAAS,CAAC,EAAE,EAAE,GAAG,KAAK,GAAG,EAChC,UAAU,SAAS,kBAAkB,GAAG,QAAQ,EAChD,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE3D,MAAM,EAAE,OAAO,EACf,aAAa,EAAE,aAAa,CAAC,GAAG,EAAE,mBAAmB,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,GAC3F,aAAa,CACd,QAAQ,EACR,mBAAmB,EACnB,SAAS,EACT,cAAc,EACd,UAAU,CAAC,OAAO,CAAC,EACnB,UAAU,EACV,SAAS,CACV,CAAA"}
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IDs + registry for Convex + Zod v4
|
|
3
|
+
*/
|
|
4
|
+
import type { GenericId } from 'convex/values';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
export declare const registryHelpers: {
|
|
7
|
+
getMetadata: (type: z.ZodTypeAny) => any;
|
|
8
|
+
setMetadata: (type: z.ZodTypeAny, meta: any) => WeakMap<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, any>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a Zod validator for a Convex Id
|
|
12
|
+
*
|
|
13
|
+
* Compatible with AI SDK and other tools that don't support transforms.
|
|
14
|
+
* Uses type-level branding instead of runtime transforms for GenericId<T> compatibility.
|
|
15
|
+
*
|
|
16
|
+
* @param tableName - The Convex table name for this ID
|
|
17
|
+
* @returns A Zod string validator typed as GenericId<TableName>
|
|
18
|
+
*/
|
|
19
|
+
export declare function zid<TableName extends string>(tableName: TableName): z.ZodType<GenericId<TableName>> & {
|
|
20
|
+
_tableName: TableName;
|
|
21
|
+
};
|
|
22
|
+
export type Zid<TableName extends string> = ReturnType<typeof zid<TableName>>;
|
|
23
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAKvB,eAAO,MAAM,eAAe;wBACN,CAAC,CAAC,UAAU;wBACZ,CAAC,CAAC,UAAU,QAAQ,GAAG;CAC5C,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,SAAS,SAAS,MAAM,EAC1C,SAAS,EAAE,SAAS,GACnB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG;IAAE,UAAU,EAAE,SAAS,CAAA;CAAE,CAwB7D;AAED,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,MAAM,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,CAAA"}
|