convex-helpers 0.1.5 → 0.1.7
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/dist/server/customFunctions.d.ts +18 -4
- package/dist/server/customFunctions.js +1 -1
- package/dist/server/zod.d.ts +231 -0
- package/dist/server/zod.js +415 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
- package/server/customFunctions.ts +7 -6
- package/server/zod.test.ts +266 -0
- package/server/zod.ts +734 -0
|
@@ -209,11 +209,24 @@ export declare function customMutation<ModArgsValidator extends PropertyValidato
|
|
|
209
209
|
* @returns A new action builder to define queries with modified ctx and args.
|
|
210
210
|
*/
|
|
211
211
|
export declare function customAction<ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel>(action: ActionBuilder<DataModel, Visibility>, mod: Mod<GenericActionCtx<DataModel>, ModArgsValidator, ModCtx, ModMadeArgs>): CustomBuilder<"action", ModArgsValidator, ModCtx, ModMadeArgs, GenericActionCtx<DataModel>, Visibility>;
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
* @param splitArgsValidator The args that should be split out from the rest.
|
|
215
|
+
* As an object mapping arg names to validators (v.* from convex/values).
|
|
216
|
+
* @param args The arguments to a function, including values to be split out.
|
|
217
|
+
* @returns The args split into two objects: `split` and `rest` based on keys.
|
|
218
|
+
*/
|
|
219
|
+
export declare function splitArgs<SplitArgsValidator extends PropertyValidators, Args extends Record<string, any>>(splitArgsValidator: SplitArgsValidator, args: Args & ObjectType<SplitArgsValidator>): {
|
|
220
|
+
split: ObjectType<SplitArgsValidator>;
|
|
221
|
+
rest: {
|
|
222
|
+
[k in Exclude<keyof Args, keyof SplitArgsValidator>]: Args[k];
|
|
223
|
+
};
|
|
224
|
+
};
|
|
212
225
|
/**
|
|
213
226
|
* A Convex function (query, mutation, or action) to be registered for the API.
|
|
214
227
|
* Convenience to specify the registration type based on function type.
|
|
215
228
|
*/
|
|
216
|
-
type Registration<FuncType extends "query" | "mutation" | "action", Visibility extends FunctionVisibility, Args extends DefaultFunctionArgs, Output> = {
|
|
229
|
+
export type Registration<FuncType extends "query" | "mutation" | "action", Visibility extends FunctionVisibility, Args extends DefaultFunctionArgs, Output> = {
|
|
217
230
|
query: RegisteredQuery<Visibility, Args, Output>;
|
|
218
231
|
mutation: RegisteredMutation<Visibility, Args, Output>;
|
|
219
232
|
action: RegisteredAction<Visibility, Args, Output>;
|
|
@@ -224,15 +237,15 @@ type Registration<FuncType extends "query" | "mutation" | "action", Visibility e
|
|
|
224
237
|
*/
|
|
225
238
|
type ValidatedBuilder<FuncType extends "query" | "mutation" | "action", ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = <ExistingArgsValidator extends PropertyValidators, Output>(fn: {
|
|
226
239
|
args: ExistingArgsValidator;
|
|
227
|
-
handler: (ctx: InputCtx
|
|
240
|
+
handler: (ctx: Overwrite<InputCtx, ModCtx>, args: Overwrite<ObjectType<ExistingArgsValidator>, ModMadeArgs>) => Output;
|
|
228
241
|
}) => Registration<FuncType, Visibility, ObjectType<ExistingArgsValidator & ModArgsValidator>, Output>;
|
|
229
242
|
/**
|
|
230
243
|
* A builder that customizes a Convex function which doesn't validate arguments.
|
|
231
244
|
* e.g. `query(async (ctx, args) => {})`
|
|
232
245
|
* or `query({ handler: async (ctx, args) => {} })`
|
|
233
246
|
*/
|
|
234
|
-
type UnvalidatedBuilder<FuncType extends "query" | "mutation" | "action", ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = <Output, ExistingArgs extends DefaultFunctionArgs = DefaultFunctionArgs>(fn: UnvalidatedFunction<InputCtx
|
|
235
|
-
ExistingArgs
|
|
247
|
+
type UnvalidatedBuilder<FuncType extends "query" | "mutation" | "action", ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = <Output, ExistingArgs extends DefaultFunctionArgs = DefaultFunctionArgs>(fn: UnvalidatedFunction<Overwrite<InputCtx, ModCtx>, [
|
|
248
|
+
Overwrite<ExistingArgs, ModMadeArgs>
|
|
236
249
|
], Output>) => Registration<FuncType, Visibility, ExistingArgs, Output>;
|
|
237
250
|
/**
|
|
238
251
|
* A builder that customizes a Convex function, whether or not it validates
|
|
@@ -240,6 +253,7 @@ type UnvalidatedBuilder<FuncType extends "query" | "mutation" | "action", ModCtx
|
|
|
240
253
|
* builder will require argument validation too.
|
|
241
254
|
*/
|
|
242
255
|
type CustomBuilder<FuncType extends "query" | "mutation" | "action", ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = ModArgsValidator extends EmptyObject ? ValidatedBuilder<FuncType, ModArgsValidator, ModCtx, ModMadeArgs, InputCtx, Visibility> & UnvalidatedBuilder<FuncType, ModCtx, ModMadeArgs, InputCtx, Visibility> : ValidatedBuilder<FuncType, ModArgsValidator, ModCtx, ModMadeArgs, InputCtx, Visibility>;
|
|
256
|
+
type Overwrite<T, U> = Omit<T, keyof U> & U;
|
|
243
257
|
type EmptyObject = Record<string, never>;
|
|
244
258
|
type DefaultFunctionArgs = Record<string, unknown>;
|
|
245
259
|
export {};
|
|
@@ -280,7 +280,7 @@ export function customAction(action, mod) {
|
|
|
280
280
|
* @param args The arguments to a function, including values to be split out.
|
|
281
281
|
* @returns The args split into two objects: `split` and `rest` based on keys.
|
|
282
282
|
*/
|
|
283
|
-
function splitArgs(splitArgsValidator, args) {
|
|
283
|
+
export function splitArgs(splitArgsValidator, args) {
|
|
284
284
|
const rest = {};
|
|
285
285
|
const split = {};
|
|
286
286
|
for (const arg in args) {
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { ZodTypeDef, z } from "zod";
|
|
2
|
+
import { GenericId, ObjectType, PropertyValidators, Validator } from "convex/values";
|
|
3
|
+
import { FunctionVisibility, GenericDataModel, GenericActionCtx, GenericQueryCtx, MutationBuilder, QueryBuilder, UnvalidatedFunction, GenericMutationCtx, ActionBuilder } from "convex/server";
|
|
4
|
+
import { v } from "convex/values";
|
|
5
|
+
import { Mod, Registration } from "./customFunctions";
|
|
6
|
+
export type ZodValidator = Record<string, z.ZodTypeAny>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a validator for a Convex `Id`.
|
|
9
|
+
*
|
|
10
|
+
* When used as a validator, it will check that it's for the right table.
|
|
11
|
+
* When used as a parser, it will only check that the Id is a string.
|
|
12
|
+
*
|
|
13
|
+
* @param tableName - The table that the `Id` references. i.e.` Id<tableName>`
|
|
14
|
+
* @returns - A Zod object representing a Convex `Id`
|
|
15
|
+
*/
|
|
16
|
+
export declare const zid: <TableName extends string>(tableName: TableName) => Zid<TableName>;
|
|
17
|
+
/**
|
|
18
|
+
* zCustomQuery is like customQuery, but allows validation via zod.
|
|
19
|
+
* You can define custom behavior on top of `query` or `internalQuery`
|
|
20
|
+
* by passing a function that modifies the ctx and args. Or NoOp to do nothing.
|
|
21
|
+
*
|
|
22
|
+
* Example usage:
|
|
23
|
+
* ```js
|
|
24
|
+
* const myQueryBuilder = zCustomQuery(query, {
|
|
25
|
+
* args: { sessionId: v.id("sessions") },
|
|
26
|
+
* input: async (ctx, args) => {
|
|
27
|
+
* const user = await getUserOrNull(ctx);
|
|
28
|
+
* const session = await db.get(sessionId);
|
|
29
|
+
* const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
|
|
30
|
+
* return { ctx: { db, user, session }, args: {} };
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Using the custom builder
|
|
35
|
+
* export const getSomeData = myQueryBuilder({
|
|
36
|
+
* args: { someArg: z.string() },
|
|
37
|
+
* handler: async (ctx, args) => {
|
|
38
|
+
* const { db, user, session, scheduler } = ctx;
|
|
39
|
+
* const { someArg } = args;
|
|
40
|
+
* // ...
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* Simple usage only modifying ctx:
|
|
46
|
+
* ```js
|
|
47
|
+
* const myInternalQuery = zCustomQuery(
|
|
48
|
+
* internalQuery,
|
|
49
|
+
* customCtx(async (ctx) => {
|
|
50
|
+
* return {
|
|
51
|
+
* // Throws an exception if the user isn't logged in
|
|
52
|
+
* user: await getUserByTokenIdentifier(ctx),
|
|
53
|
+
* };
|
|
54
|
+
* })
|
|
55
|
+
* );
|
|
56
|
+
*
|
|
57
|
+
* // Using it
|
|
58
|
+
* export const getUser = myInternalQuery({
|
|
59
|
+
* args: { email: z.string().email() },
|
|
60
|
+
* handler: async (ctx, args) => {
|
|
61
|
+
* console.log(args.email);
|
|
62
|
+
* return ctx.user;
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* @param query The query to be modified. Usually `query` or `internalQuery`
|
|
67
|
+
* from `_generated/server`.
|
|
68
|
+
* @param mod The modifier to be applied to the query, changing ctx and args.
|
|
69
|
+
* @returns A new query builder using zod validation to define queries.
|
|
70
|
+
*/
|
|
71
|
+
export declare function zCustomQuery<ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel>(query: QueryBuilder<DataModel, Visibility>, mod: Mod<GenericQueryCtx<DataModel>, ModArgsValidator, ModCtx, ModMadeArgs>): CustomBuilder<"query", ModArgsValidator, ModCtx, ModMadeArgs, GenericQueryCtx<DataModel>, Visibility>;
|
|
72
|
+
/**
|
|
73
|
+
* zCustomMutation is like customMutation, but allows validation via zod.
|
|
74
|
+
* You can define custom behavior on top of `mutation` or `internalMutation`
|
|
75
|
+
* by passing a function that modifies the ctx and args. Or NoOp to do nothing.
|
|
76
|
+
*
|
|
77
|
+
* Example usage:
|
|
78
|
+
* ```js
|
|
79
|
+
* const myMutationBuilder = zCustomMutation(mutation, {
|
|
80
|
+
* args: { sessionId: v.id("sessions") },
|
|
81
|
+
* input: async (ctx, args) => {
|
|
82
|
+
* const user = await getUserOrNull(ctx);
|
|
83
|
+
* const session = await db.get(sessionId);
|
|
84
|
+
* const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
|
|
85
|
+
* return { ctx: { db, user, session }, args: {} };
|
|
86
|
+
* },
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // Using the custom builder
|
|
90
|
+
* export const getSomeData = myMutationBuilder({
|
|
91
|
+
* args: { someArg: z.string() },
|
|
92
|
+
* handler: async (ctx, args) => {
|
|
93
|
+
* const { db, user, session, scheduler } = ctx;
|
|
94
|
+
* const { someArg } = args;
|
|
95
|
+
* // ...
|
|
96
|
+
* }
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Simple usage only modifying ctx:
|
|
101
|
+
* ```js
|
|
102
|
+
* const myInternalMutation = zCustomMutation(
|
|
103
|
+
* internalMutation,
|
|
104
|
+
* customCtx(async (ctx) => {
|
|
105
|
+
* return {
|
|
106
|
+
* // Throws an exception if the user isn't logged in
|
|
107
|
+
* user: await getUserByTokenIdentifier(ctx),
|
|
108
|
+
* };
|
|
109
|
+
* })
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* // Using it
|
|
113
|
+
* export const getUser = myInternalMutation({
|
|
114
|
+
* args: { email: z.string().email() },
|
|
115
|
+
* handler: async (ctx, args) => {
|
|
116
|
+
* console.log(args.email);
|
|
117
|
+
* return ctx.user;
|
|
118
|
+
* },
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* @param mutation The mutation to be modified. Usually `mutation` or `internalMutation`
|
|
122
|
+
* from `_generated/server`.
|
|
123
|
+
* @param mod The modifier to be applied to the mutation, changing ctx and args.
|
|
124
|
+
* @returns A new mutation builder using zod validation to define queries.
|
|
125
|
+
*/
|
|
126
|
+
export declare function zCustomMutation<ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel>(mutation: MutationBuilder<DataModel, Visibility>, mod: Mod<GenericMutationCtx<DataModel>, ModArgsValidator, ModCtx, ModMadeArgs>): CustomBuilder<"mutation", ModArgsValidator, ModCtx, ModMadeArgs, GenericMutationCtx<DataModel>, Visibility>;
|
|
127
|
+
/**
|
|
128
|
+
* zCustomAction is like customAction, but allows validation via zod.
|
|
129
|
+
* You can define custom behavior on top of `action` or `internalAction`
|
|
130
|
+
* by passing a function that modifies the ctx and args. Or NoOp to do nothing.
|
|
131
|
+
*
|
|
132
|
+
* Example usage:
|
|
133
|
+
* ```js
|
|
134
|
+
* const myActionBuilder = zCustomAction(action, {
|
|
135
|
+
* args: { sessionId: v.id("sessions") },
|
|
136
|
+
* input: async (ctx, args) => {
|
|
137
|
+
* const user = await getUserOrNull(ctx);
|
|
138
|
+
* const session = await db.get(sessionId);
|
|
139
|
+
* const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
|
|
140
|
+
* return { ctx: { db, user, session }, args: {} };
|
|
141
|
+
* },
|
|
142
|
+
* });
|
|
143
|
+
*
|
|
144
|
+
* // Using the custom builder
|
|
145
|
+
* export const getSomeData = myActionBuilder({
|
|
146
|
+
* args: { someArg: z.string() },
|
|
147
|
+
* handler: async (ctx, args) => {
|
|
148
|
+
* const { db, user, session, scheduler } = ctx;
|
|
149
|
+
* const { someArg } = args;
|
|
150
|
+
* // ...
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* Simple usage only modifying ctx:
|
|
156
|
+
* ```js
|
|
157
|
+
* const myInternalAction = zCustomAction(
|
|
158
|
+
* internalAction,
|
|
159
|
+
* customCtx(async (ctx) => {
|
|
160
|
+
* return {
|
|
161
|
+
* // Throws an exception if the user isn't logged in
|
|
162
|
+
* user: await getUserByTokenIdentifier(ctx),
|
|
163
|
+
* };
|
|
164
|
+
* })
|
|
165
|
+
* );
|
|
166
|
+
*
|
|
167
|
+
* // Using it
|
|
168
|
+
* export const getUser = myInternalAction({
|
|
169
|
+
* args: { email: z.string().email() },
|
|
170
|
+
* handler: async (ctx, args) => {
|
|
171
|
+
* console.log(args.email);
|
|
172
|
+
* return ctx.user;
|
|
173
|
+
* },
|
|
174
|
+
* });
|
|
175
|
+
*
|
|
176
|
+
* @param action The action to be modified. Usually `action` or `internalAction`
|
|
177
|
+
* from `_generated/server`.
|
|
178
|
+
* @param mod The modifier to be applied to the action, changing ctx and args.
|
|
179
|
+
* @returns A new action builder using zod validation to define queries.
|
|
180
|
+
*/
|
|
181
|
+
export declare function zCustomAction<ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, Visibility extends FunctionVisibility, DataModel extends GenericDataModel>(action: ActionBuilder<DataModel, Visibility>, mod: Mod<GenericActionCtx<DataModel>, ModArgsValidator, ModCtx, ModMadeArgs>): CustomBuilder<"action", ModArgsValidator, ModCtx, ModMadeArgs, GenericActionCtx<DataModel>, Visibility>;
|
|
182
|
+
/**
|
|
183
|
+
* A builder that customizes a Convex function using argument validation.
|
|
184
|
+
* e.g. `query({ args: {}, handler: async (ctx, args) => {} })`
|
|
185
|
+
*/
|
|
186
|
+
type ValidatedBuilder<FuncType extends "query" | "mutation" | "action", ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = <ExistingArgsValidator extends ZodValidator, Output, ZodOutput extends z.ZodTypeAny | undefined = undefined>(fn: {
|
|
187
|
+
args: ExistingArgsValidator;
|
|
188
|
+
handler: (ctx: InputCtx & ModCtx, args: z.output<z.ZodObject<ExistingArgsValidator>> & ModMadeArgs) => ZodOutput extends z.ZodTypeAny ? z.input<ZodOutput> | Promise<z.input<ZodOutput>> : Output;
|
|
189
|
+
output?: ZodOutput;
|
|
190
|
+
}) => Registration<FuncType, Visibility, z.input<z.ZodObject<ExistingArgsValidator>> & ObjectType<ModArgsValidator>, ZodOutput extends z.ZodTypeAny ? Promise<z.output<ZodOutput>> : Output>;
|
|
191
|
+
/**
|
|
192
|
+
* A builder that customizes a Convex function which doesn't validate arguments.
|
|
193
|
+
* e.g. `query(async (ctx, args) => {})`
|
|
194
|
+
* or `query({ handler: async (ctx, args) => {} })`
|
|
195
|
+
*/
|
|
196
|
+
type UnvalidatedBuilder<FuncType extends "query" | "mutation" | "action", ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = <Output, ExistingArgs extends DefaultFunctionArgs = DefaultFunctionArgs>(fn: UnvalidatedFunction<InputCtx & ModCtx, [
|
|
197
|
+
ExistingArgs & ModMadeArgs
|
|
198
|
+
], Output>) => Registration<FuncType, Visibility, ExistingArgs, Output>;
|
|
199
|
+
/**
|
|
200
|
+
* A builder that customizes a Convex function, whether or not it validates
|
|
201
|
+
* arguments. If the customization requires arguments, however, the resulting
|
|
202
|
+
* builder will require argument validation too.
|
|
203
|
+
*/
|
|
204
|
+
type CustomBuilder<FuncType extends "query" | "mutation" | "action", ModArgsValidator extends PropertyValidators, ModCtx extends Record<string, any>, ModMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility> = ModArgsValidator extends EmptyObject ? ValidatedBuilder<FuncType, ModArgsValidator, ModCtx, ModMadeArgs, InputCtx, Visibility> & UnvalidatedBuilder<FuncType, ModCtx, ModMadeArgs, InputCtx, Visibility> : ValidatedBuilder<FuncType, ModArgsValidator, ModCtx, ModMadeArgs, InputCtx, Visibility>;
|
|
205
|
+
type EmptyObject = Record<string, never>;
|
|
206
|
+
type DefaultFunctionArgs = Record<string, unknown>;
|
|
207
|
+
type ConvexValidatorFromZod<Z extends z.ZodTypeAny> = Z extends Zid<infer TableName> ? Validator<GenericId<TableName>> : Z extends z.ZodString ? Validator<string> : Z extends z.ZodNumber ? Validator<number> : Z extends z.ZodNaN ? Validator<number> : Z extends z.ZodBigInt ? Validator<bigint> : Z extends z.ZodBoolean ? Validator<boolean> : Z extends z.ZodNull ? Validator<null> : Z extends z.ZodUnknown ? Validator<any, false, string> : Z extends z.ZodAny ? Validator<any, false, string> : Z extends z.ZodArray<infer Inner> ? Validator<ConvexValidatorFromZod<Inner>["type"][]> : Z extends z.ZodObject<infer ZodShape> ? ReturnType<typeof v.object<{
|
|
208
|
+
[key in keyof ZodShape]: ConvexValidatorFromZod<ZodShape[key]>;
|
|
209
|
+
}>> : Z extends z.ZodUnion<infer T> ? Validator<ConvexValidatorFromZod<T[number]>["type"], false, ConvexValidatorFromZod<T[number]>["fieldPaths"]> : Z extends z.ZodDiscriminatedUnion<any, infer T> ? Validator<ConvexValidatorFromZod<T[number]>["type"], false, ConvexValidatorFromZod<T[number]>["fieldPaths"]> : Z extends z.ZodTuple<infer Inner> ? Validator<ConvexValidatorFromZod<Inner[number]>["type"][]> : Z extends z.ZodLazy<infer Inner> ? ConvexValidatorFromZod<Inner> : Z extends z.ZodLiteral<infer Literal> ? Validator<Literal> : Z extends z.ZodEnum<infer T> ? Validator<T[number]> : Z extends z.ZodEffects<infer Inner> ? ConvexValidatorFromZod<Inner> : Z extends z.ZodOptional<infer Inner> ? ConvexValidatorFromZod<Inner> extends Validator<infer InnerConvex, false, infer InnerFieldPaths> ? Validator<InnerConvex | undefined, true, InnerFieldPaths> : never : Z extends z.ZodNullable<infer Inner> ? ConvexValidatorFromZod<Inner> extends Validator<infer InnerConvex, infer InnerOptional, infer InnerFieldPaths> ? Validator<null | InnerConvex, InnerOptional, InnerFieldPaths> : never : Z extends z.ZodBranded<infer Inner, any> ? ConvexValidatorFromZod<Inner> : Z extends z.ZodDefault<infer Inner> ? ConvexValidatorFromZod<Inner> extends Validator<infer InnerConvex, false, infer InnerFieldPaths> ? Validator<InnerConvex | undefined, true, InnerFieldPaths> : never : Z extends z.ZodReadonly<infer Inner> ? ConvexValidatorFromZod<Inner> : Z extends z.ZodPipeline<infer Inner, any> ? ConvexValidatorFromZod<Inner> : never;
|
|
210
|
+
/**
|
|
211
|
+
* Turn a Zod validator into a Convex Validator.
|
|
212
|
+
* @param zod Zod validator can be a Zod object, or a Zod type like `z.string()`
|
|
213
|
+
* @returns Convex Validator (e.g. `v.string()` from "convex/values")
|
|
214
|
+
*/
|
|
215
|
+
export declare function zodToConvex<Z extends z.ZodTypeAny>(zod: Z): ConvexValidatorFromZod<Z>;
|
|
216
|
+
/**
|
|
217
|
+
* Like zodToConvex, but it takes in a bare object, as expected by Convex
|
|
218
|
+
* function arguments, or the argument to defineTable.
|
|
219
|
+
*
|
|
220
|
+
* @param zod Object with string keys and Zod validators as values
|
|
221
|
+
* @returns Object with the same keys, but with Convex validators as values
|
|
222
|
+
*/
|
|
223
|
+
export declare function zodToConvexFields<Z extends ZodValidator>(zod: Z): { [k in keyof Z]: ConvexValidatorFromZod<Z[k]>; };
|
|
224
|
+
interface ZidDef<TableName extends string> extends ZodTypeDef {
|
|
225
|
+
typeName: "ConvexId";
|
|
226
|
+
tableName: TableName;
|
|
227
|
+
}
|
|
228
|
+
declare class Zid<TableName extends string> extends z.ZodType<GenericId<TableName>, ZidDef<TableName>> {
|
|
229
|
+
_parse(input: z.ParseInput): z.ParseReturnType<GenericId<TableName>>;
|
|
230
|
+
}
|
|
231
|
+
export {};
|