zodvex 0.2.4 → 0.3.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 +319 -7
- package/dist/index.d.ts +159 -66
- package/dist/index.js +273 -209
- package/dist/index.js.map +1 -1
- package/package.json +13 -24
- package/src/__type-tests__/infer-returns.ts +154 -0
- package/src/custom.ts +15 -6
- package/src/ids.ts +8 -8
- package/src/registry.ts +171 -0
- package/src/tables.ts +173 -30
- package/src/types.ts +10 -22
- package/src/wrappers.ts +2 -2
- package/dist/index.d.mts +0 -489
- package/dist/index.mjs +0 -1001
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { NoOp } from 'convex-helpers/server/customFunctions';
|
|
2
|
+
export { customCtx } from 'convex-helpers/server/customFunctions';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { v, ConvexError } from 'convex/values';
|
|
5
|
+
import { defineTable } from 'convex/server';
|
|
6
|
+
import { Table } from 'convex-helpers/server';
|
|
7
7
|
|
|
8
|
+
// src/index.ts
|
|
8
9
|
var metadata = /* @__PURE__ */ new WeakMap();
|
|
9
10
|
var registryHelpers = {
|
|
10
11
|
getMetadata: (type) => metadata.get(type),
|
|
11
12
|
setMetadata: (type, meta) => metadata.set(type, meta)
|
|
12
13
|
};
|
|
13
14
|
function zid(tableName) {
|
|
14
|
-
const baseSchema =
|
|
15
|
+
const baseSchema = z.string().refine((val) => typeof val === "string" && val.length > 0, {
|
|
15
16
|
message: `Invalid ID for table "${tableName}"`
|
|
16
|
-
}).
|
|
17
|
-
return val;
|
|
18
|
-
}).brand(`ConvexId_${tableName}`).describe(`convexId:${tableName}`);
|
|
17
|
+
}).describe(`convexId:${tableName}`);
|
|
19
18
|
registryHelpers.setMetadata(baseSchema, {
|
|
20
19
|
isConvexId: true,
|
|
21
20
|
tableName
|
|
@@ -32,8 +31,8 @@ function findBaseCodec(schema) {
|
|
|
32
31
|
return baseCodecs.find((codec) => codec.check(schema));
|
|
33
32
|
}
|
|
34
33
|
registerBaseCodec({
|
|
35
|
-
check: (schema) => schema instanceof
|
|
36
|
-
toValidator: () =>
|
|
34
|
+
check: (schema) => schema instanceof z.ZodDate,
|
|
35
|
+
toValidator: () => v.float64(),
|
|
37
36
|
fromConvex: (value) => {
|
|
38
37
|
if (typeof value === "number") {
|
|
39
38
|
return new Date(value);
|
|
@@ -51,54 +50,104 @@ function asZodType(schema) {
|
|
|
51
50
|
return schema;
|
|
52
51
|
}
|
|
53
52
|
function isDateSchema(schema) {
|
|
54
|
-
if (schema instanceof
|
|
55
|
-
if (schema instanceof
|
|
53
|
+
if (schema instanceof z.ZodDate) return true;
|
|
54
|
+
if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable) {
|
|
56
55
|
return isDateSchema(asZodType(schema.unwrap()));
|
|
57
56
|
}
|
|
58
57
|
return false;
|
|
59
58
|
}
|
|
59
|
+
function isZidSchema(schema) {
|
|
60
|
+
const description = schema.description;
|
|
61
|
+
return typeof description === "string" && description.startsWith("convexId:");
|
|
62
|
+
}
|
|
63
|
+
function getZidTableName(schema) {
|
|
64
|
+
const description = schema.description;
|
|
65
|
+
if (typeof description === "string" && description.startsWith("convexId:")) {
|
|
66
|
+
return description.slice("convexId:".length);
|
|
67
|
+
}
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
function zodvexJSONSchemaOverride(ctx) {
|
|
71
|
+
const { zodSchema, jsonSchema } = ctx;
|
|
72
|
+
if (isZidSchema(zodSchema)) {
|
|
73
|
+
const tableName = getZidTableName(zodSchema);
|
|
74
|
+
jsonSchema.type = "string";
|
|
75
|
+
if (tableName) {
|
|
76
|
+
jsonSchema.format = `convex-id:${tableName}`;
|
|
77
|
+
}
|
|
78
|
+
if (zodSchema.description) {
|
|
79
|
+
jsonSchema.description = zodSchema.description;
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (zodSchema instanceof z.ZodDate || zodSchema.type === "date") {
|
|
84
|
+
jsonSchema.type = "string";
|
|
85
|
+
jsonSchema.format = "date-time";
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function composeOverrides(...overrides) {
|
|
90
|
+
return (ctx) => {
|
|
91
|
+
for (const override of overrides) {
|
|
92
|
+
override?.(ctx);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function toJSONSchema(schema, options) {
|
|
97
|
+
const userOverride = options?.override;
|
|
98
|
+
return z.toJSONSchema(schema, {
|
|
99
|
+
...options,
|
|
100
|
+
// Default to 'any' so transforms don't throw
|
|
101
|
+
unrepresentable: options?.unrepresentable ?? "any",
|
|
102
|
+
// Chain our override with user's override
|
|
103
|
+
override: (ctx) => {
|
|
104
|
+
zodvexJSONSchemaOverride(ctx);
|
|
105
|
+
userOverride?.(ctx);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
60
109
|
function convertEnumType(actualValidator) {
|
|
61
110
|
const options = actualValidator.options;
|
|
62
111
|
if (options && Array.isArray(options) && options.length > 0) {
|
|
63
|
-
const validLiterals = options.filter((opt) => opt !== void 0 && opt !== null).map((opt) =>
|
|
112
|
+
const validLiterals = options.filter((opt) => opt !== void 0 && opt !== null).map((opt) => v.literal(opt));
|
|
64
113
|
if (validLiterals.length === 1) {
|
|
65
114
|
const [first] = validLiterals;
|
|
66
115
|
return first;
|
|
67
116
|
} else if (validLiterals.length >= 2) {
|
|
68
117
|
const [first, second, ...rest] = validLiterals;
|
|
69
|
-
return
|
|
118
|
+
return v.union(
|
|
70
119
|
first,
|
|
71
120
|
second,
|
|
72
121
|
...rest
|
|
73
122
|
);
|
|
74
123
|
} else {
|
|
75
|
-
return
|
|
124
|
+
return v.any();
|
|
76
125
|
}
|
|
77
126
|
} else {
|
|
78
|
-
return
|
|
127
|
+
return v.any();
|
|
79
128
|
}
|
|
80
129
|
}
|
|
81
130
|
function convertNullableType(actualValidator, visited, zodToConvexInternal2) {
|
|
82
131
|
const innerSchema = actualValidator.unwrap();
|
|
83
|
-
if (innerSchema && innerSchema instanceof
|
|
84
|
-
if (innerSchema instanceof
|
|
132
|
+
if (innerSchema && innerSchema instanceof z.ZodType) {
|
|
133
|
+
if (innerSchema instanceof z.ZodOptional) {
|
|
85
134
|
const innerInnerSchema = innerSchema.unwrap();
|
|
86
135
|
const innerInnerValidator = zodToConvexInternal2(innerInnerSchema, visited);
|
|
87
136
|
return {
|
|
88
|
-
validator:
|
|
137
|
+
validator: v.union(innerInnerValidator, v.null()),
|
|
89
138
|
isOptional: true
|
|
90
139
|
// Mark as optional so it gets wrapped later
|
|
91
140
|
};
|
|
92
141
|
} else {
|
|
93
142
|
const innerValidator = zodToConvexInternal2(innerSchema, visited);
|
|
94
143
|
return {
|
|
95
|
-
validator:
|
|
144
|
+
validator: v.union(innerValidator, v.null()),
|
|
96
145
|
isOptional: false
|
|
97
146
|
};
|
|
98
147
|
}
|
|
99
148
|
} else {
|
|
100
149
|
return {
|
|
101
|
-
validator:
|
|
150
|
+
validator: v.any(),
|
|
102
151
|
isOptional: false
|
|
103
152
|
};
|
|
104
153
|
}
|
|
@@ -108,37 +157,37 @@ function convertRecordType(actualValidator, visited, zodToConvexInternal2) {
|
|
|
108
157
|
if (!valueType) {
|
|
109
158
|
valueType = actualValidator._def?.keyType;
|
|
110
159
|
}
|
|
111
|
-
if (valueType && valueType instanceof
|
|
112
|
-
const isZodOptional = valueType instanceof
|
|
160
|
+
if (valueType && valueType instanceof z.ZodType) {
|
|
161
|
+
const isZodOptional = valueType instanceof z.ZodOptional || valueType instanceof z.ZodDefault || valueType instanceof z.ZodDefault && valueType.def.innerType instanceof z.ZodOptional;
|
|
113
162
|
if (isZodOptional) {
|
|
114
163
|
let innerType;
|
|
115
164
|
let recordDefaultValue = void 0;
|
|
116
165
|
let recordHasDefault = false;
|
|
117
|
-
if (valueType instanceof
|
|
166
|
+
if (valueType instanceof z.ZodDefault) {
|
|
118
167
|
recordHasDefault = true;
|
|
119
168
|
recordDefaultValue = valueType.def.defaultValue;
|
|
120
169
|
const innerFromDefault = valueType.def.innerType;
|
|
121
|
-
if (innerFromDefault instanceof
|
|
170
|
+
if (innerFromDefault instanceof z.ZodOptional) {
|
|
122
171
|
innerType = innerFromDefault.unwrap();
|
|
123
172
|
} else {
|
|
124
173
|
innerType = innerFromDefault;
|
|
125
174
|
}
|
|
126
|
-
} else if (valueType instanceof
|
|
175
|
+
} else if (valueType instanceof z.ZodOptional) {
|
|
127
176
|
innerType = valueType.unwrap();
|
|
128
177
|
} else {
|
|
129
178
|
innerType = valueType;
|
|
130
179
|
}
|
|
131
180
|
const innerConvex = zodToConvexInternal2(innerType, visited);
|
|
132
|
-
const unionValidator =
|
|
181
|
+
const unionValidator = v.union(innerConvex, v.null());
|
|
133
182
|
if (recordHasDefault) {
|
|
134
183
|
unionValidator._zodDefault = recordDefaultValue;
|
|
135
184
|
}
|
|
136
|
-
return
|
|
185
|
+
return v.record(v.string(), unionValidator);
|
|
137
186
|
} else {
|
|
138
|
-
return
|
|
187
|
+
return v.record(v.string(), zodToConvexInternal2(valueType, visited));
|
|
139
188
|
}
|
|
140
189
|
} else {
|
|
141
|
-
return
|
|
190
|
+
return v.record(v.string(), v.any());
|
|
142
191
|
}
|
|
143
192
|
}
|
|
144
193
|
function convertDiscriminatedUnionType(actualValidator, visited, zodToConvexInternal2) {
|
|
@@ -151,16 +200,16 @@ function convertDiscriminatedUnionType(actualValidator, visited, zodToConvexInte
|
|
|
151
200
|
return zodToConvexInternal2(opt, branchVisited);
|
|
152
201
|
});
|
|
153
202
|
const [first, second, ...rest] = convexOptions;
|
|
154
|
-
return
|
|
203
|
+
return v.union(
|
|
155
204
|
first,
|
|
156
205
|
second,
|
|
157
206
|
...rest
|
|
158
207
|
);
|
|
159
208
|
} else {
|
|
160
|
-
return
|
|
209
|
+
return v.any();
|
|
161
210
|
}
|
|
162
211
|
} else {
|
|
163
|
-
return
|
|
212
|
+
return v.any();
|
|
164
213
|
}
|
|
165
214
|
}
|
|
166
215
|
function convertUnionType(actualValidator, visited, zodToConvexInternal2) {
|
|
@@ -175,17 +224,17 @@ function convertUnionType(actualValidator, visited, zodToConvexInternal2) {
|
|
|
175
224
|
});
|
|
176
225
|
if (convexOptions.length >= 2) {
|
|
177
226
|
const [first, second, ...rest] = convexOptions;
|
|
178
|
-
return
|
|
227
|
+
return v.union(
|
|
179
228
|
first,
|
|
180
229
|
second,
|
|
181
230
|
...rest
|
|
182
231
|
);
|
|
183
232
|
} else {
|
|
184
|
-
return
|
|
233
|
+
return v.any();
|
|
185
234
|
}
|
|
186
235
|
}
|
|
187
236
|
} else {
|
|
188
|
-
return
|
|
237
|
+
return v.any();
|
|
189
238
|
}
|
|
190
239
|
}
|
|
191
240
|
function isZid(schema) {
|
|
@@ -194,12 +243,12 @@ function isZid(schema) {
|
|
|
194
243
|
}
|
|
195
244
|
function makeUnion(members) {
|
|
196
245
|
const nonNull = members.filter(Boolean);
|
|
197
|
-
if (nonNull.length === 0) return
|
|
246
|
+
if (nonNull.length === 0) return v.any();
|
|
198
247
|
if (nonNull.length === 1) return nonNull[0];
|
|
199
|
-
return
|
|
248
|
+
return v.union(nonNull[0], nonNull[1], ...nonNull.slice(2));
|
|
200
249
|
}
|
|
201
250
|
function getObjectShape(obj) {
|
|
202
|
-
if (obj instanceof
|
|
251
|
+
if (obj instanceof z.ZodObject) {
|
|
203
252
|
return obj.shape;
|
|
204
253
|
}
|
|
205
254
|
if (obj && typeof obj === "object" && typeof obj.shape === "object") {
|
|
@@ -211,25 +260,25 @@ function getObjectShape(obj) {
|
|
|
211
260
|
// src/mapping/core.ts
|
|
212
261
|
function zodToConvexInternal(zodValidator, visited = /* @__PURE__ */ new Set()) {
|
|
213
262
|
if (!zodValidator) {
|
|
214
|
-
return
|
|
263
|
+
return v.any();
|
|
215
264
|
}
|
|
216
265
|
if (visited.has(zodValidator)) {
|
|
217
|
-
return
|
|
266
|
+
return v.any();
|
|
218
267
|
}
|
|
219
268
|
visited.add(zodValidator);
|
|
220
269
|
let actualValidator = zodValidator;
|
|
221
270
|
let isOptional = false;
|
|
222
271
|
let defaultValue = void 0;
|
|
223
272
|
let hasDefault = false;
|
|
224
|
-
if (zodValidator instanceof
|
|
273
|
+
if (zodValidator instanceof z.ZodDefault) {
|
|
225
274
|
hasDefault = true;
|
|
226
275
|
defaultValue = zodValidator.def?.defaultValue;
|
|
227
276
|
actualValidator = zodValidator.def?.innerType;
|
|
228
277
|
}
|
|
229
|
-
if (actualValidator instanceof
|
|
278
|
+
if (actualValidator instanceof z.ZodOptional) {
|
|
230
279
|
isOptional = true;
|
|
231
280
|
actualValidator = actualValidator.unwrap();
|
|
232
|
-
if (actualValidator instanceof
|
|
281
|
+
if (actualValidator instanceof z.ZodDefault) {
|
|
233
282
|
hasDefault = true;
|
|
234
283
|
defaultValue = actualValidator.def?.defaultValue;
|
|
235
284
|
actualValidator = actualValidator.def?.innerType;
|
|
@@ -239,64 +288,64 @@ function zodToConvexInternal(zodValidator, visited = /* @__PURE__ */ new Set())
|
|
|
239
288
|
if (isZid(actualValidator)) {
|
|
240
289
|
const metadata2 = registryHelpers.getMetadata(actualValidator);
|
|
241
290
|
const tableName = metadata2?.tableName || "unknown";
|
|
242
|
-
convexValidator =
|
|
291
|
+
convexValidator = v.id(tableName);
|
|
243
292
|
} else {
|
|
244
293
|
const defType = actualValidator.def?.type;
|
|
245
294
|
switch (defType) {
|
|
246
295
|
case "string":
|
|
247
|
-
convexValidator =
|
|
296
|
+
convexValidator = v.string();
|
|
248
297
|
break;
|
|
249
298
|
case "number":
|
|
250
|
-
convexValidator =
|
|
299
|
+
convexValidator = v.float64();
|
|
251
300
|
break;
|
|
252
301
|
case "bigint":
|
|
253
|
-
convexValidator =
|
|
302
|
+
convexValidator = v.int64();
|
|
254
303
|
break;
|
|
255
304
|
case "boolean":
|
|
256
|
-
convexValidator =
|
|
305
|
+
convexValidator = v.boolean();
|
|
257
306
|
break;
|
|
258
307
|
case "date":
|
|
259
|
-
convexValidator =
|
|
308
|
+
convexValidator = v.float64();
|
|
260
309
|
break;
|
|
261
310
|
case "null":
|
|
262
|
-
convexValidator =
|
|
311
|
+
convexValidator = v.null();
|
|
263
312
|
break;
|
|
264
313
|
case "nan":
|
|
265
|
-
convexValidator =
|
|
314
|
+
convexValidator = v.float64();
|
|
266
315
|
break;
|
|
267
316
|
case "array": {
|
|
268
|
-
if (actualValidator instanceof
|
|
317
|
+
if (actualValidator instanceof z.ZodArray) {
|
|
269
318
|
const element = actualValidator.element;
|
|
270
|
-
if (element && element instanceof
|
|
271
|
-
convexValidator =
|
|
319
|
+
if (element && element instanceof z.ZodType) {
|
|
320
|
+
convexValidator = v.array(zodToConvexInternal(element, visited));
|
|
272
321
|
} else {
|
|
273
|
-
convexValidator =
|
|
322
|
+
convexValidator = v.array(v.any());
|
|
274
323
|
}
|
|
275
324
|
} else {
|
|
276
|
-
convexValidator =
|
|
325
|
+
convexValidator = v.array(v.any());
|
|
277
326
|
}
|
|
278
327
|
break;
|
|
279
328
|
}
|
|
280
329
|
case "object": {
|
|
281
|
-
if (actualValidator instanceof
|
|
330
|
+
if (actualValidator instanceof z.ZodObject) {
|
|
282
331
|
const shape = actualValidator.shape;
|
|
283
332
|
const convexShape = {};
|
|
284
333
|
for (const [key, value] of Object.entries(shape)) {
|
|
285
|
-
if (value && value instanceof
|
|
334
|
+
if (value && value instanceof z.ZodType) {
|
|
286
335
|
convexShape[key] = zodToConvexInternal(value, visited);
|
|
287
336
|
}
|
|
288
337
|
}
|
|
289
|
-
convexValidator =
|
|
338
|
+
convexValidator = v.object(convexShape);
|
|
290
339
|
} else {
|
|
291
|
-
convexValidator =
|
|
340
|
+
convexValidator = v.object({});
|
|
292
341
|
}
|
|
293
342
|
break;
|
|
294
343
|
}
|
|
295
344
|
case "union": {
|
|
296
|
-
if (actualValidator instanceof
|
|
345
|
+
if (actualValidator instanceof z.ZodUnion) {
|
|
297
346
|
convexValidator = convertUnionType(actualValidator, visited, zodToConvexInternal);
|
|
298
347
|
} else {
|
|
299
|
-
convexValidator =
|
|
348
|
+
convexValidator = v.any();
|
|
300
349
|
}
|
|
301
350
|
break;
|
|
302
351
|
}
|
|
@@ -309,31 +358,31 @@ function zodToConvexInternal(zodValidator, visited = /* @__PURE__ */ new Set())
|
|
|
309
358
|
break;
|
|
310
359
|
}
|
|
311
360
|
case "literal": {
|
|
312
|
-
if (actualValidator instanceof
|
|
361
|
+
if (actualValidator instanceof z.ZodLiteral) {
|
|
313
362
|
const literalValue = actualValidator.value;
|
|
314
363
|
if (literalValue !== void 0 && literalValue !== null) {
|
|
315
|
-
convexValidator =
|
|
364
|
+
convexValidator = v.literal(literalValue);
|
|
316
365
|
} else {
|
|
317
|
-
convexValidator =
|
|
366
|
+
convexValidator = v.any();
|
|
318
367
|
}
|
|
319
368
|
} else {
|
|
320
|
-
convexValidator =
|
|
369
|
+
convexValidator = v.any();
|
|
321
370
|
}
|
|
322
371
|
break;
|
|
323
372
|
}
|
|
324
373
|
case "enum": {
|
|
325
|
-
if (actualValidator instanceof
|
|
374
|
+
if (actualValidator instanceof z.ZodEnum) {
|
|
326
375
|
convexValidator = convertEnumType(actualValidator);
|
|
327
376
|
} else {
|
|
328
|
-
convexValidator =
|
|
377
|
+
convexValidator = v.any();
|
|
329
378
|
}
|
|
330
379
|
break;
|
|
331
380
|
}
|
|
332
381
|
case "record": {
|
|
333
|
-
if (actualValidator instanceof
|
|
382
|
+
if (actualValidator instanceof z.ZodRecord) {
|
|
334
383
|
convexValidator = convertRecordType(actualValidator, visited, zodToConvexInternal);
|
|
335
384
|
} else {
|
|
336
|
-
convexValidator =
|
|
385
|
+
convexValidator = v.record(v.string(), v.any());
|
|
337
386
|
}
|
|
338
387
|
break;
|
|
339
388
|
}
|
|
@@ -347,75 +396,75 @@ function zodToConvexInternal(zodValidator, visited = /* @__PURE__ */ new Set())
|
|
|
347
396
|
if (metadata2?.brand && metadata2?.originalSchema) {
|
|
348
397
|
convexValidator = zodToConvexInternal(metadata2.originalSchema, visited);
|
|
349
398
|
} else {
|
|
350
|
-
convexValidator =
|
|
399
|
+
convexValidator = v.any();
|
|
351
400
|
}
|
|
352
401
|
}
|
|
353
402
|
break;
|
|
354
403
|
}
|
|
355
404
|
case "nullable": {
|
|
356
|
-
if (actualValidator instanceof
|
|
405
|
+
if (actualValidator instanceof z.ZodNullable) {
|
|
357
406
|
const result = convertNullableType(actualValidator, visited, zodToConvexInternal);
|
|
358
407
|
convexValidator = result.validator;
|
|
359
408
|
if (result.isOptional) {
|
|
360
409
|
isOptional = true;
|
|
361
410
|
}
|
|
362
411
|
} else {
|
|
363
|
-
convexValidator =
|
|
412
|
+
convexValidator = v.any();
|
|
364
413
|
}
|
|
365
414
|
break;
|
|
366
415
|
}
|
|
367
416
|
case "tuple": {
|
|
368
|
-
if (actualValidator instanceof
|
|
417
|
+
if (actualValidator instanceof z.ZodTuple) {
|
|
369
418
|
const items = actualValidator.def?.items;
|
|
370
419
|
if (items && items.length > 0) {
|
|
371
420
|
const convexShape = {};
|
|
372
421
|
items.forEach((item, index) => {
|
|
373
422
|
convexShape[`_${index}`] = zodToConvexInternal(item, visited);
|
|
374
423
|
});
|
|
375
|
-
convexValidator =
|
|
424
|
+
convexValidator = v.object(convexShape);
|
|
376
425
|
} else {
|
|
377
|
-
convexValidator =
|
|
426
|
+
convexValidator = v.object({});
|
|
378
427
|
}
|
|
379
428
|
} else {
|
|
380
|
-
convexValidator =
|
|
429
|
+
convexValidator = v.object({});
|
|
381
430
|
}
|
|
382
431
|
break;
|
|
383
432
|
}
|
|
384
433
|
case "lazy": {
|
|
385
|
-
if (actualValidator instanceof
|
|
434
|
+
if (actualValidator instanceof z.ZodLazy) {
|
|
386
435
|
try {
|
|
387
436
|
const getter = actualValidator.def?.getter;
|
|
388
437
|
if (getter) {
|
|
389
438
|
const resolvedSchema = getter();
|
|
390
|
-
if (resolvedSchema && resolvedSchema instanceof
|
|
439
|
+
if (resolvedSchema && resolvedSchema instanceof z.ZodType) {
|
|
391
440
|
convexValidator = zodToConvexInternal(resolvedSchema, visited);
|
|
392
441
|
} else {
|
|
393
|
-
convexValidator =
|
|
442
|
+
convexValidator = v.any();
|
|
394
443
|
}
|
|
395
444
|
} else {
|
|
396
|
-
convexValidator =
|
|
445
|
+
convexValidator = v.any();
|
|
397
446
|
}
|
|
398
447
|
} catch {
|
|
399
|
-
convexValidator =
|
|
448
|
+
convexValidator = v.any();
|
|
400
449
|
}
|
|
401
450
|
} else {
|
|
402
|
-
convexValidator =
|
|
451
|
+
convexValidator = v.any();
|
|
403
452
|
}
|
|
404
453
|
break;
|
|
405
454
|
}
|
|
406
455
|
case "any":
|
|
407
|
-
convexValidator =
|
|
456
|
+
convexValidator = v.any();
|
|
408
457
|
break;
|
|
409
458
|
case "unknown":
|
|
410
|
-
convexValidator =
|
|
459
|
+
convexValidator = v.any();
|
|
411
460
|
break;
|
|
412
461
|
case "undefined":
|
|
413
462
|
case "void":
|
|
414
463
|
case "never":
|
|
415
|
-
convexValidator =
|
|
464
|
+
convexValidator = v.any();
|
|
416
465
|
break;
|
|
417
466
|
case "intersection":
|
|
418
|
-
convexValidator =
|
|
467
|
+
convexValidator = v.any();
|
|
419
468
|
break;
|
|
420
469
|
default:
|
|
421
470
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -425,24 +474,24 @@ function zodToConvexInternal(zodValidator, visited = /* @__PURE__ */ new Set())
|
|
|
425
474
|
actualValidator
|
|
426
475
|
);
|
|
427
476
|
}
|
|
428
|
-
convexValidator =
|
|
477
|
+
convexValidator = v.any();
|
|
429
478
|
break;
|
|
430
479
|
}
|
|
431
480
|
}
|
|
432
|
-
const finalValidator = isOptional || hasDefault ?
|
|
481
|
+
const finalValidator = isOptional || hasDefault ? v.optional(convexValidator) : convexValidator;
|
|
433
482
|
if (hasDefault && typeof finalValidator === "object" && finalValidator !== null) {
|
|
434
483
|
finalValidator._zodDefault = defaultValue;
|
|
435
484
|
}
|
|
436
485
|
return finalValidator;
|
|
437
486
|
}
|
|
438
|
-
function zodToConvex(zod
|
|
439
|
-
if (typeof zod
|
|
440
|
-
return zodToConvexFields(zod
|
|
487
|
+
function zodToConvex(zod) {
|
|
488
|
+
if (typeof zod === "object" && zod !== null && !(zod instanceof z.ZodType)) {
|
|
489
|
+
return zodToConvexFields(zod);
|
|
441
490
|
}
|
|
442
|
-
return zodToConvexInternal(zod
|
|
491
|
+
return zodToConvexInternal(zod);
|
|
443
492
|
}
|
|
444
|
-
function zodToConvexFields(zod
|
|
445
|
-
const fields = zod
|
|
493
|
+
function zodToConvexFields(zod) {
|
|
494
|
+
const fields = zod instanceof z.ZodObject ? zod.shape : zod;
|
|
446
495
|
const result = {};
|
|
447
496
|
for (const [key, value] of Object.entries(fields)) {
|
|
448
497
|
result[key] = zodToConvexInternal(value);
|
|
@@ -461,7 +510,7 @@ function convexCodec(schema) {
|
|
|
461
510
|
encode: (value) => toConvexJS(schema, value),
|
|
462
511
|
decode: (value) => fromConvexJS(value, schema),
|
|
463
512
|
pick: (keys) => {
|
|
464
|
-
if (!(schema instanceof
|
|
513
|
+
if (!(schema instanceof z.ZodObject)) {
|
|
465
514
|
throw new Error("pick() can only be called on object schemas");
|
|
466
515
|
}
|
|
467
516
|
const pickObj = Array.isArray(keys) ? keys.reduce((acc, k) => ({ ...acc, [k]: true }), {}) : keys;
|
|
@@ -501,18 +550,18 @@ function schemaToConvex(value, schema) {
|
|
|
501
550
|
if (codec) {
|
|
502
551
|
return codec.toConvex(value, schema);
|
|
503
552
|
}
|
|
504
|
-
if (schema instanceof
|
|
553
|
+
if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault) {
|
|
505
554
|
const inner = schema.unwrap();
|
|
506
555
|
return schemaToConvex(value, asZodType2(inner));
|
|
507
556
|
}
|
|
508
|
-
if (schema instanceof
|
|
557
|
+
if (schema instanceof z.ZodDate && value instanceof Date) {
|
|
509
558
|
return value.getTime();
|
|
510
559
|
}
|
|
511
|
-
if (schema instanceof
|
|
560
|
+
if (schema instanceof z.ZodArray) {
|
|
512
561
|
if (!Array.isArray(value)) return value;
|
|
513
562
|
return value.map((item) => schemaToConvex(item, schema.element));
|
|
514
563
|
}
|
|
515
|
-
if (schema instanceof
|
|
564
|
+
if (schema instanceof z.ZodObject) {
|
|
516
565
|
if (!value || typeof value !== "object") return value;
|
|
517
566
|
const shape = schema.shape;
|
|
518
567
|
const result = {};
|
|
@@ -523,7 +572,7 @@ function schemaToConvex(value, schema) {
|
|
|
523
572
|
}
|
|
524
573
|
return result;
|
|
525
574
|
}
|
|
526
|
-
if (schema instanceof
|
|
575
|
+
if (schema instanceof z.ZodUnion) {
|
|
527
576
|
for (const option of schema.options) {
|
|
528
577
|
try {
|
|
529
578
|
;
|
|
@@ -533,7 +582,7 @@ function schemaToConvex(value, schema) {
|
|
|
533
582
|
}
|
|
534
583
|
}
|
|
535
584
|
}
|
|
536
|
-
if (schema instanceof
|
|
585
|
+
if (schema instanceof z.ZodRecord) {
|
|
537
586
|
if (!value || typeof value !== "object") return value;
|
|
538
587
|
const result = {};
|
|
539
588
|
for (const [k, v8] of Object.entries(value)) {
|
|
@@ -551,21 +600,21 @@ function fromConvexJS(value, schema) {
|
|
|
551
600
|
if (codec) {
|
|
552
601
|
return codec.fromConvex(value, schema);
|
|
553
602
|
}
|
|
554
|
-
if (schema instanceof
|
|
603
|
+
if (schema instanceof z.ZodOptional || schema instanceof z.ZodNullable || schema instanceof z.ZodDefault) {
|
|
555
604
|
const inner = schema.unwrap();
|
|
556
605
|
return fromConvexJS(value, asZodType2(inner));
|
|
557
606
|
}
|
|
558
|
-
if (schema instanceof
|
|
607
|
+
if (schema instanceof z.ZodDate && typeof value === "number") {
|
|
559
608
|
return new Date(value);
|
|
560
609
|
}
|
|
561
610
|
if (isDateSchema(schema) && typeof value === "number") {
|
|
562
611
|
return new Date(value);
|
|
563
612
|
}
|
|
564
|
-
if (schema instanceof
|
|
613
|
+
if (schema instanceof z.ZodArray) {
|
|
565
614
|
if (!Array.isArray(value)) return value;
|
|
566
615
|
return value.map((item) => fromConvexJS(item, schema.element));
|
|
567
616
|
}
|
|
568
|
-
if (schema instanceof
|
|
617
|
+
if (schema instanceof z.ZodObject) {
|
|
569
618
|
if (!value || typeof value !== "object") return value;
|
|
570
619
|
const shape = schema.shape;
|
|
571
620
|
const result = {};
|
|
@@ -574,7 +623,7 @@ function fromConvexJS(value, schema) {
|
|
|
574
623
|
}
|
|
575
624
|
return result;
|
|
576
625
|
}
|
|
577
|
-
if (schema instanceof
|
|
626
|
+
if (schema instanceof z.ZodUnion) {
|
|
578
627
|
for (const option of schema.options) {
|
|
579
628
|
try {
|
|
580
629
|
const decoded = fromConvexJS(value, option);
|
|
@@ -584,7 +633,7 @@ function fromConvexJS(value, schema) {
|
|
|
584
633
|
}
|
|
585
634
|
}
|
|
586
635
|
}
|
|
587
|
-
if (schema instanceof
|
|
636
|
+
if (schema instanceof z.ZodRecord) {
|
|
588
637
|
if (!value || typeof value !== "object") return value;
|
|
589
638
|
const result = {};
|
|
590
639
|
for (const [k, v8] of Object.entries(value)) {
|
|
@@ -592,7 +641,7 @@ function fromConvexJS(value, schema) {
|
|
|
592
641
|
}
|
|
593
642
|
return result;
|
|
594
643
|
}
|
|
595
|
-
if (schema instanceof
|
|
644
|
+
if (schema instanceof z.ZodTransform) {
|
|
596
645
|
return value;
|
|
597
646
|
}
|
|
598
647
|
return value;
|
|
@@ -621,32 +670,32 @@ function formatZodIssues(error, context) {
|
|
|
621
670
|
};
|
|
622
671
|
}
|
|
623
672
|
function handleZodValidationError(e, context) {
|
|
624
|
-
if (e instanceof
|
|
625
|
-
throw new
|
|
673
|
+
if (e instanceof z.ZodError) {
|
|
674
|
+
throw new ConvexError(formatZodIssues(e, context));
|
|
626
675
|
}
|
|
627
676
|
throw e;
|
|
628
677
|
}
|
|
629
678
|
function zPaginated(item) {
|
|
630
|
-
return
|
|
631
|
-
page:
|
|
632
|
-
isDone:
|
|
633
|
-
continueCursor:
|
|
679
|
+
return z.object({
|
|
680
|
+
page: z.array(item),
|
|
681
|
+
isDone: z.boolean(),
|
|
682
|
+
continueCursor: z.string().nullable().optional()
|
|
634
683
|
});
|
|
635
684
|
}
|
|
636
685
|
function mapDateFieldToNumber(field) {
|
|
637
|
-
if (field instanceof
|
|
638
|
-
return
|
|
686
|
+
if (field instanceof z.ZodDate) {
|
|
687
|
+
return z.number();
|
|
639
688
|
}
|
|
640
|
-
if (field instanceof
|
|
641
|
-
return
|
|
689
|
+
if (field instanceof z.ZodOptional && field.unwrap() instanceof z.ZodDate) {
|
|
690
|
+
return z.number().optional();
|
|
642
691
|
}
|
|
643
|
-
if (field instanceof
|
|
644
|
-
return
|
|
692
|
+
if (field instanceof z.ZodNullable && field.unwrap() instanceof z.ZodDate) {
|
|
693
|
+
return z.number().nullable();
|
|
645
694
|
}
|
|
646
|
-
if (field instanceof
|
|
695
|
+
if (field instanceof z.ZodDefault) {
|
|
647
696
|
const inner = field.removeDefault();
|
|
648
|
-
if (inner instanceof
|
|
649
|
-
return
|
|
697
|
+
if (inner instanceof z.ZodDate) {
|
|
698
|
+
return z.number().optional();
|
|
650
699
|
}
|
|
651
700
|
}
|
|
652
701
|
return field;
|
|
@@ -657,7 +706,7 @@ function toKeys(mask) {
|
|
|
657
706
|
}
|
|
658
707
|
function pickShape(schemaOrShape, mask) {
|
|
659
708
|
const keys = toKeys(mask);
|
|
660
|
-
const shape = schemaOrShape instanceof
|
|
709
|
+
const shape = schemaOrShape instanceof z.ZodObject ? getObjectShape(schemaOrShape) : schemaOrShape || {};
|
|
661
710
|
const out = {};
|
|
662
711
|
for (const k of keys) {
|
|
663
712
|
if (k in shape) out[k] = shape[k];
|
|
@@ -665,29 +714,30 @@ function pickShape(schemaOrShape, mask) {
|
|
|
665
714
|
return out;
|
|
666
715
|
}
|
|
667
716
|
function safePick(schema, mask) {
|
|
668
|
-
return
|
|
717
|
+
return z.object(pickShape(schema, mask));
|
|
669
718
|
}
|
|
670
719
|
function safeOmit(schema, mask) {
|
|
671
720
|
const shape = getObjectShape(schema);
|
|
672
721
|
const omit = new Set(toKeys(mask));
|
|
673
722
|
const keep = Object.keys(shape).filter((k) => !omit.has(k));
|
|
674
723
|
const picked = pickShape(schema, keep);
|
|
675
|
-
return
|
|
724
|
+
return z.object(picked);
|
|
676
725
|
}
|
|
677
726
|
|
|
678
727
|
// src/custom.ts
|
|
679
728
|
function customFnBuilder(builder, customization) {
|
|
680
|
-
const customInput = customization.input ??
|
|
681
|
-
const inputArgs = customization.args ??
|
|
729
|
+
const customInput = customization.input ?? NoOp.input;
|
|
730
|
+
const inputArgs = customization.args ?? NoOp.args;
|
|
682
731
|
return function customBuilder(fn) {
|
|
683
732
|
const { args, handler = fn, returns: maybeObject, ...extra } = fn;
|
|
684
|
-
const
|
|
685
|
-
const
|
|
686
|
-
|
|
733
|
+
const skipConvexValidation = fn.skipConvexValidation ?? false;
|
|
734
|
+
const returns = maybeObject && !(maybeObject instanceof z.ZodType) ? z.object(maybeObject) : maybeObject;
|
|
735
|
+
const returnValidator = returns && !skipConvexValidation ? { returns: zodToConvex(returns) } : void 0;
|
|
736
|
+
if (args) {
|
|
687
737
|
let argsValidator = args;
|
|
688
738
|
let argsSchema;
|
|
689
|
-
if (argsValidator instanceof
|
|
690
|
-
if (argsValidator instanceof
|
|
739
|
+
if (argsValidator instanceof z.ZodType) {
|
|
740
|
+
if (argsValidator instanceof z.ZodObject) {
|
|
691
741
|
argsSchema = argsValidator;
|
|
692
742
|
argsValidator = argsValidator.shape;
|
|
693
743
|
} else {
|
|
@@ -696,11 +746,11 @@ function customFnBuilder(builder, customization) {
|
|
|
696
746
|
);
|
|
697
747
|
}
|
|
698
748
|
} else {
|
|
699
|
-
argsSchema =
|
|
749
|
+
argsSchema = z.object(argsValidator);
|
|
700
750
|
}
|
|
701
|
-
const
|
|
751
|
+
const convexArgs = skipConvexValidation ? inputArgs : { ...zodToConvexFields(argsValidator), ...inputArgs };
|
|
702
752
|
return builder({
|
|
703
|
-
args:
|
|
753
|
+
args: convexArgs,
|
|
704
754
|
...returnValidator,
|
|
705
755
|
handler: async (ctx, allArgs) => {
|
|
706
756
|
const added = await customInput(
|
|
@@ -720,7 +770,7 @@ function customFnBuilder(builder, customization) {
|
|
|
720
770
|
const addedArgs = added?.args ?? {};
|
|
721
771
|
const finalArgs = { ...baseArgs, ...addedArgs };
|
|
722
772
|
const ret = await handler(finalCtx, finalArgs);
|
|
723
|
-
if (returns
|
|
773
|
+
if (returns) {
|
|
724
774
|
let validated;
|
|
725
775
|
try {
|
|
726
776
|
validated = returns.parse(ret);
|
|
@@ -757,7 +807,7 @@ function customFnBuilder(builder, customization) {
|
|
|
757
807
|
const addedArgs = added?.args ?? {};
|
|
758
808
|
const finalArgs = { ...baseArgs, ...addedArgs };
|
|
759
809
|
const ret = await handler(finalCtx, finalArgs);
|
|
760
|
-
if (returns
|
|
810
|
+
if (returns) {
|
|
761
811
|
let validated;
|
|
762
812
|
try {
|
|
763
813
|
validated = returns.parse(ret);
|
|
@@ -802,17 +852,17 @@ function containsCustom(schema, maxDepth = 50, currentDepth = 0) {
|
|
|
802
852
|
return false;
|
|
803
853
|
}
|
|
804
854
|
let result = false;
|
|
805
|
-
if (schema
|
|
855
|
+
if (schema instanceof z.ZodCustom) {
|
|
806
856
|
result = true;
|
|
807
|
-
} else if (schema instanceof
|
|
857
|
+
} else if (schema instanceof z.ZodUnion) {
|
|
808
858
|
result = schema.options.some(
|
|
809
859
|
(opt) => containsCustom(opt, maxDepth, currentDepth + 1)
|
|
810
860
|
);
|
|
811
|
-
} else if (schema instanceof
|
|
861
|
+
} else if (schema instanceof z.ZodOptional) {
|
|
812
862
|
result = containsCustom(schema.unwrap(), maxDepth, currentDepth + 1);
|
|
813
|
-
} else if (schema instanceof
|
|
863
|
+
} else if (schema instanceof z.ZodNullable) {
|
|
814
864
|
result = containsCustom(schema.unwrap(), maxDepth, currentDepth + 1);
|
|
815
|
-
} else if (schema instanceof
|
|
865
|
+
} else if (schema instanceof z.ZodDefault) {
|
|
816
866
|
result = containsCustom(schema.removeDefault(), maxDepth, currentDepth + 1);
|
|
817
867
|
}
|
|
818
868
|
customCheckCache.set(schema, result);
|
|
@@ -821,15 +871,15 @@ function containsCustom(schema, maxDepth = 50, currentDepth = 0) {
|
|
|
821
871
|
function zQuery(query, input, handler, options) {
|
|
822
872
|
let zodSchema;
|
|
823
873
|
let args;
|
|
824
|
-
if (input instanceof
|
|
874
|
+
if (input instanceof z.ZodObject) {
|
|
825
875
|
const zodObj = input;
|
|
826
876
|
zodSchema = zodObj;
|
|
827
877
|
args = zodToConvexFields(getObjectShape(zodObj));
|
|
828
|
-
} else if (input instanceof
|
|
829
|
-
zodSchema =
|
|
878
|
+
} else if (input instanceof z.ZodType) {
|
|
879
|
+
zodSchema = z.object({ value: input });
|
|
830
880
|
args = { value: zodToConvex(input) };
|
|
831
881
|
} else {
|
|
832
|
-
zodSchema =
|
|
882
|
+
zodSchema = z.object(input);
|
|
833
883
|
args = zodToConvexFields(input);
|
|
834
884
|
}
|
|
835
885
|
const returns = options?.returns && !containsCustom(options.returns) ? zodToConvex(options.returns) : void 0;
|
|
@@ -860,15 +910,15 @@ function zQuery(query, input, handler, options) {
|
|
|
860
910
|
function zMutation(mutation, input, handler, options) {
|
|
861
911
|
let zodSchema;
|
|
862
912
|
let args;
|
|
863
|
-
if (input instanceof
|
|
913
|
+
if (input instanceof z.ZodObject) {
|
|
864
914
|
const zodObj = input;
|
|
865
915
|
zodSchema = zodObj;
|
|
866
916
|
args = zodToConvexFields(getObjectShape(zodObj));
|
|
867
|
-
} else if (input instanceof
|
|
868
|
-
zodSchema =
|
|
917
|
+
} else if (input instanceof z.ZodType) {
|
|
918
|
+
zodSchema = z.object({ value: input });
|
|
869
919
|
args = { value: zodToConvex(input) };
|
|
870
920
|
} else {
|
|
871
|
-
zodSchema =
|
|
921
|
+
zodSchema = z.object(input);
|
|
872
922
|
args = zodToConvexFields(input);
|
|
873
923
|
}
|
|
874
924
|
const returns = options?.returns && !containsCustom(options.returns) ? zodToConvex(options.returns) : void 0;
|
|
@@ -899,15 +949,15 @@ function zMutation(mutation, input, handler, options) {
|
|
|
899
949
|
function zAction(action, input, handler, options) {
|
|
900
950
|
let zodSchema;
|
|
901
951
|
let args;
|
|
902
|
-
if (input instanceof
|
|
952
|
+
if (input instanceof z.ZodObject) {
|
|
903
953
|
const zodObj = input;
|
|
904
954
|
zodSchema = zodObj;
|
|
905
955
|
args = zodToConvexFields(getObjectShape(zodObj));
|
|
906
|
-
} else if (input instanceof
|
|
907
|
-
zodSchema =
|
|
956
|
+
} else if (input instanceof z.ZodType) {
|
|
957
|
+
zodSchema = z.object({ value: input });
|
|
908
958
|
args = { value: zodToConvex(input) };
|
|
909
959
|
} else {
|
|
910
|
-
zodSchema =
|
|
960
|
+
zodSchema = z.object(input);
|
|
911
961
|
args = zodToConvexFields(input);
|
|
912
962
|
}
|
|
913
963
|
const returns = options?.returns && !containsCustom(options.returns) ? zodToConvex(options.returns) : void 0;
|
|
@@ -976,64 +1026,78 @@ function zCustomActionBuilder(action, customization) {
|
|
|
976
1026
|
customization
|
|
977
1027
|
);
|
|
978
1028
|
}
|
|
1029
|
+
function addSystemFields(tableName, schema) {
|
|
1030
|
+
if (schema instanceof z.ZodUnion || schema instanceof z.ZodDiscriminatedUnion) {
|
|
1031
|
+
const options = schema.options.map((variant) => {
|
|
1032
|
+
if (variant instanceof z.ZodObject) {
|
|
1033
|
+
return variant.extend({
|
|
1034
|
+
_id: zid(tableName),
|
|
1035
|
+
_creationTime: z.number()
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
return variant;
|
|
1039
|
+
});
|
|
1040
|
+
return z.union(options);
|
|
1041
|
+
}
|
|
1042
|
+
if (schema instanceof z.ZodObject) {
|
|
1043
|
+
return schema.extend({
|
|
1044
|
+
_id: zid(tableName),
|
|
1045
|
+
_creationTime: z.number()
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
return schema;
|
|
1049
|
+
}
|
|
979
1050
|
function zodDoc(tableName, schema) {
|
|
980
1051
|
return schema.extend({
|
|
981
1052
|
_id: zid(tableName),
|
|
982
|
-
_creationTime:
|
|
1053
|
+
_creationTime: z.number()
|
|
983
1054
|
});
|
|
984
1055
|
}
|
|
985
1056
|
function zodDocOrNull(tableName, schema) {
|
|
986
|
-
return
|
|
1057
|
+
return z.union([zodDoc(tableName, schema), z.null()]);
|
|
987
1058
|
}
|
|
988
|
-
function
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1059
|
+
function isObjectShape(input) {
|
|
1060
|
+
if (!input || typeof input !== "object") return false;
|
|
1061
|
+
if (input instanceof z.ZodType) return false;
|
|
1062
|
+
for (const key in input) {
|
|
1063
|
+
if (!(input[key] instanceof z.ZodType)) {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
return true;
|
|
1068
|
+
}
|
|
1069
|
+
function zodTable(name, schemaOrShape) {
|
|
1070
|
+
if (isObjectShape(schemaOrShape)) {
|
|
1071
|
+
const shape = schemaOrShape;
|
|
1072
|
+
const convexFields = zodToConvexFields(shape);
|
|
1073
|
+
const table = Table(
|
|
1074
|
+
name,
|
|
1075
|
+
convexFields
|
|
1076
|
+
);
|
|
1077
|
+
const zDoc = zodDoc(name, z.object(shape));
|
|
1078
|
+
const docArray = z.array(zDoc);
|
|
1079
|
+
return Object.assign(table, {
|
|
1080
|
+
shape,
|
|
1081
|
+
zDoc,
|
|
1082
|
+
docArray
|
|
1083
|
+
});
|
|
1084
|
+
} else {
|
|
1085
|
+
const schema = schemaOrShape;
|
|
1086
|
+
const convexValidator = zodToConvex(schema);
|
|
1087
|
+
const table = defineTable(convexValidator);
|
|
1088
|
+
const withFields = addSystemFields(name, schema);
|
|
1089
|
+
const docArray = z.array(withFields);
|
|
1090
|
+
return {
|
|
1091
|
+
table,
|
|
1092
|
+
tableName: name,
|
|
1093
|
+
validator: convexValidator,
|
|
1094
|
+
schema,
|
|
1095
|
+
docArray,
|
|
1096
|
+
withSystemFields: () => addSystemFields(name, schema)
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
998
1099
|
}
|
|
999
1100
|
|
|
1000
|
-
|
|
1001
|
-
enumerable: true,
|
|
1002
|
-
get: function () { return customFunctions.customCtx; }
|
|
1003
|
-
});
|
|
1004
|
-
exports.convexCodec = convexCodec;
|
|
1005
|
-
exports.customFnBuilder = customFnBuilder;
|
|
1006
|
-
exports.findBaseCodec = findBaseCodec;
|
|
1007
|
-
exports.formatZodIssues = formatZodIssues;
|
|
1008
|
-
exports.fromConvexJS = fromConvexJS;
|
|
1009
|
-
exports.getObjectShape = getObjectShape;
|
|
1010
|
-
exports.handleZodValidationError = handleZodValidationError;
|
|
1011
|
-
exports.isDateSchema = isDateSchema;
|
|
1012
|
-
exports.makeUnion = makeUnion;
|
|
1013
|
-
exports.mapDateFieldToNumber = mapDateFieldToNumber;
|
|
1014
|
-
exports.pick = pick;
|
|
1015
|
-
exports.pickShape = pickShape;
|
|
1016
|
-
exports.registerBaseCodec = registerBaseCodec;
|
|
1017
|
-
exports.registryHelpers = registryHelpers;
|
|
1018
|
-
exports.returnsAs = returnsAs;
|
|
1019
|
-
exports.safeOmit = safeOmit;
|
|
1020
|
-
exports.safePick = safePick;
|
|
1021
|
-
exports.toConvexJS = toConvexJS;
|
|
1022
|
-
exports.zActionBuilder = zActionBuilder;
|
|
1023
|
-
exports.zCustomAction = zCustomAction;
|
|
1024
|
-
exports.zCustomActionBuilder = zCustomActionBuilder;
|
|
1025
|
-
exports.zCustomMutation = zCustomMutation;
|
|
1026
|
-
exports.zCustomMutationBuilder = zCustomMutationBuilder;
|
|
1027
|
-
exports.zCustomQuery = zCustomQuery;
|
|
1028
|
-
exports.zCustomQueryBuilder = zCustomQueryBuilder;
|
|
1029
|
-
exports.zMutationBuilder = zMutationBuilder;
|
|
1030
|
-
exports.zPaginated = zPaginated;
|
|
1031
|
-
exports.zQueryBuilder = zQueryBuilder;
|
|
1032
|
-
exports.zid = zid;
|
|
1033
|
-
exports.zodDoc = zodDoc;
|
|
1034
|
-
exports.zodDocOrNull = zodDocOrNull;
|
|
1035
|
-
exports.zodTable = zodTable;
|
|
1036
|
-
exports.zodToConvex = zodToConvex;
|
|
1037
|
-
exports.zodToConvexFields = zodToConvexFields;
|
|
1101
|
+
export { addSystemFields, composeOverrides, convexCodec, customFnBuilder, findBaseCodec, formatZodIssues, fromConvexJS, getObjectShape, getZidTableName, handleZodValidationError, isDateSchema, isZidSchema, makeUnion, mapDateFieldToNumber, pick, pickShape, registerBaseCodec, registryHelpers, returnsAs, safeOmit, safePick, toConvexJS, toJSONSchema, zActionBuilder, zCustomAction, zCustomActionBuilder, zCustomMutation, zCustomMutationBuilder, zCustomQuery, zCustomQueryBuilder, zMutationBuilder, zPaginated, zQueryBuilder, zid, zodDoc, zodDocOrNull, zodTable, zodToConvex, zodToConvexFields, zodvexJSONSchemaOverride };
|
|
1038
1102
|
//# sourceMappingURL=index.js.map
|
|
1039
1103
|
//# sourceMappingURL=index.js.map
|