@cipherstash/stack 0.16.0 → 0.19.0
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/CHANGELOG.md +225 -0
- package/README.md +2 -2
- package/dist/{chunk-CY5B4LIF.js → chunk-36AA7IBJ.js} +303 -204
- package/dist/chunk-36AA7IBJ.js.map +1 -0
- package/dist/{chunk-MD6742R6.js → chunk-4AVL4VZD.js} +1 -1
- package/dist/chunk-4AVL4VZD.js.map +1 -0
- package/dist/{chunk-4RNBI3UH.js → chunk-BNO32ZMV.js} +1 -1
- package/dist/chunk-BNO32ZMV.js.map +1 -0
- package/dist/{chunk-6FD7OBGM.js → chunk-HQANMV7R.js} +3 -3
- package/dist/chunk-HQANMV7R.js.map +1 -0
- package/dist/chunk-IADZCZEA.js +23 -0
- package/dist/chunk-IADZCZEA.js.map +1 -0
- package/dist/chunk-IBSK6P33.js +209 -0
- package/dist/chunk-IBSK6P33.js.map +1 -0
- package/dist/chunk-JSG2AMDI.js +17 -0
- package/dist/chunk-JSG2AMDI.js.map +1 -0
- package/dist/chunk-MP3SSDNN.js +4439 -0
- package/dist/chunk-MP3SSDNN.js.map +1 -0
- package/dist/chunk-OFQ555AX.js +191 -0
- package/dist/chunk-OFQ555AX.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-U66S7VIF.js +435 -0
- package/dist/chunk-U66S7VIF.js.map +1 -0
- package/dist/{client-C_7TF8EL.d.cts → client-DSGHBN-g.d.cts} +209 -72
- package/dist/{client-BLbA6aFD.d.ts → client-DfCrlHXh.d.ts} +209 -72
- package/dist/client.cjs +4103 -43
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/client.js +3 -1
- package/dist/drizzle/index.cjs +4139 -77
- package/dist/drizzle/index.cjs.map +1 -1
- package/dist/drizzle/index.d.cts +33 -33
- package/dist/drizzle/index.d.ts +33 -33
- package/dist/drizzle/index.js +39 -33
- package/dist/drizzle/index.js.map +1 -1
- package/dist/dynamodb/index.cjs +31 -14
- package/dist/dynamodb/index.cjs.map +1 -1
- package/dist/dynamodb/index.d.cts +12 -12
- package/dist/dynamodb/index.d.ts +12 -12
- package/dist/dynamodb/index.js +16 -12
- package/dist/dynamodb/index.js.map +1 -1
- package/dist/encryption/index.cjs +4611 -257
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +3 -3
- package/dist/encryption/index.d.ts +3 -3
- package/dist/encryption/index.js +35 -7
- package/dist/encryption/v3.cjs +7791 -0
- package/dist/encryption/v3.cjs.map +1 -0
- package/dist/encryption/v3.d.cts +100 -0
- package/dist/encryption/v3.d.ts +100 -0
- package/dist/encryption/v3.js +161 -0
- package/dist/encryption/v3.js.map +1 -0
- package/dist/eql/v3/index.cjs +612 -0
- package/dist/eql/v3/index.cjs.map +1 -0
- package/dist/eql/v3/index.d.cts +71 -0
- package/dist/eql/v3/index.d.ts +71 -0
- package/dist/eql/v3/index.js +89 -0
- package/dist/eql/v3/index.js.map +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/identity/index.cjs +55 -35
- package/dist/identity/index.cjs.map +1 -1
- package/dist/identity/index.d.cts +54 -30
- package/dist/identity/index.d.ts +54 -30
- package/dist/identity/index.js +9 -177
- package/dist/identity/index.js.map +1 -1
- package/dist/index.cjs +4625 -273
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -7
- package/dist/index.d.ts +18 -7
- package/dist/index.js +20 -5
- package/dist/index.js.map +1 -1
- package/dist/schema/index.cjs +4108 -44
- package/dist/schema/index.cjs.map +1 -1
- package/dist/schema/index.d.cts +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +3 -1
- package/dist/supabase/index.cjs +4500 -75
- package/dist/supabase/index.cjs.map +1 -1
- package/dist/supabase/index.d.cts +113 -34
- package/dist/supabase/index.d.ts +113 -34
- package/dist/supabase/index.js +350 -32
- package/dist/supabase/index.js.map +1 -1
- package/dist/table-CIH7jZ2h.d.ts +603 -0
- package/dist/table-DihEAlxG.d.cts +603 -0
- package/dist/{types-public-Dv-r6Ik0.d.ts → types-public-CpS5KjwX.d.cts} +209 -36
- package/dist/{types-public-Dv-r6Ik0.d.cts → types-public-CpS5KjwX.d.ts} +209 -36
- package/dist/types-public.cjs.map +1 -1
- package/dist/types-public.d.cts +2 -2
- package/dist/types-public.d.ts +2 -2
- package/dist/types-public.js +2 -1
- package/dist/wasm-inline.d.ts +1269 -0
- package/dist/wasm-inline.js +4594 -0
- package/dist/wasm-inline.js.map +1 -0
- package/package.json +63 -13
- package/dist/chunk-4RNBI3UH.js.map +0 -1
- package/dist/chunk-6FD7OBGM.js.map +0 -1
- package/dist/chunk-CY5B4LIF.js.map +0 -1
- package/dist/chunk-JDZ2QUUF.js +0 -381
- package/dist/chunk-JDZ2QUUF.js.map +0 -1
- package/dist/chunk-MD6742R6.js.map +0 -1
package/dist/supabase/index.cjs
CHANGED
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/supabase/index.ts
|
|
21
21
|
var supabase_exports = {};
|
|
22
22
|
__export(supabase_exports, {
|
|
23
|
-
encryptedSupabase: () => encryptedSupabase
|
|
23
|
+
encryptedSupabase: () => encryptedSupabase,
|
|
24
|
+
encryptedSupabaseV3: () => encryptedSupabaseV3
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(supabase_exports);
|
|
26
27
|
|
|
@@ -54,9 +55,4060 @@ function isEncryptedPayload(value) {
|
|
|
54
55
|
return true;
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
59
|
+
var external_exports = {};
|
|
60
|
+
__export(external_exports, {
|
|
61
|
+
BRAND: () => BRAND,
|
|
62
|
+
DIRTY: () => DIRTY,
|
|
63
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
64
|
+
INVALID: () => INVALID,
|
|
65
|
+
NEVER: () => NEVER,
|
|
66
|
+
OK: () => OK,
|
|
67
|
+
ParseStatus: () => ParseStatus,
|
|
68
|
+
Schema: () => ZodType,
|
|
69
|
+
ZodAny: () => ZodAny,
|
|
70
|
+
ZodArray: () => ZodArray,
|
|
71
|
+
ZodBigInt: () => ZodBigInt,
|
|
72
|
+
ZodBoolean: () => ZodBoolean,
|
|
73
|
+
ZodBranded: () => ZodBranded,
|
|
74
|
+
ZodCatch: () => ZodCatch,
|
|
75
|
+
ZodDate: () => ZodDate,
|
|
76
|
+
ZodDefault: () => ZodDefault,
|
|
77
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
78
|
+
ZodEffects: () => ZodEffects,
|
|
79
|
+
ZodEnum: () => ZodEnum,
|
|
80
|
+
ZodError: () => ZodError,
|
|
81
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
82
|
+
ZodFunction: () => ZodFunction,
|
|
83
|
+
ZodIntersection: () => ZodIntersection,
|
|
84
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
85
|
+
ZodLazy: () => ZodLazy,
|
|
86
|
+
ZodLiteral: () => ZodLiteral,
|
|
87
|
+
ZodMap: () => ZodMap,
|
|
88
|
+
ZodNaN: () => ZodNaN,
|
|
89
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
90
|
+
ZodNever: () => ZodNever,
|
|
91
|
+
ZodNull: () => ZodNull,
|
|
92
|
+
ZodNullable: () => ZodNullable,
|
|
93
|
+
ZodNumber: () => ZodNumber,
|
|
94
|
+
ZodObject: () => ZodObject,
|
|
95
|
+
ZodOptional: () => ZodOptional,
|
|
96
|
+
ZodParsedType: () => ZodParsedType,
|
|
97
|
+
ZodPipeline: () => ZodPipeline,
|
|
98
|
+
ZodPromise: () => ZodPromise,
|
|
99
|
+
ZodReadonly: () => ZodReadonly,
|
|
100
|
+
ZodRecord: () => ZodRecord,
|
|
101
|
+
ZodSchema: () => ZodType,
|
|
102
|
+
ZodSet: () => ZodSet,
|
|
103
|
+
ZodString: () => ZodString,
|
|
104
|
+
ZodSymbol: () => ZodSymbol,
|
|
105
|
+
ZodTransformer: () => ZodEffects,
|
|
106
|
+
ZodTuple: () => ZodTuple,
|
|
107
|
+
ZodType: () => ZodType,
|
|
108
|
+
ZodUndefined: () => ZodUndefined,
|
|
109
|
+
ZodUnion: () => ZodUnion,
|
|
110
|
+
ZodUnknown: () => ZodUnknown,
|
|
111
|
+
ZodVoid: () => ZodVoid,
|
|
112
|
+
addIssueToContext: () => addIssueToContext,
|
|
113
|
+
any: () => anyType,
|
|
114
|
+
array: () => arrayType,
|
|
115
|
+
bigint: () => bigIntType,
|
|
116
|
+
boolean: () => booleanType,
|
|
117
|
+
coerce: () => coerce,
|
|
118
|
+
custom: () => custom,
|
|
119
|
+
date: () => dateType,
|
|
120
|
+
datetimeRegex: () => datetimeRegex,
|
|
121
|
+
defaultErrorMap: () => en_default,
|
|
122
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
123
|
+
effect: () => effectsType,
|
|
124
|
+
enum: () => enumType,
|
|
125
|
+
function: () => functionType,
|
|
126
|
+
getErrorMap: () => getErrorMap,
|
|
127
|
+
getParsedType: () => getParsedType,
|
|
128
|
+
instanceof: () => instanceOfType,
|
|
129
|
+
intersection: () => intersectionType,
|
|
130
|
+
isAborted: () => isAborted,
|
|
131
|
+
isAsync: () => isAsync,
|
|
132
|
+
isDirty: () => isDirty,
|
|
133
|
+
isValid: () => isValid,
|
|
134
|
+
late: () => late,
|
|
135
|
+
lazy: () => lazyType,
|
|
136
|
+
literal: () => literalType,
|
|
137
|
+
makeIssue: () => makeIssue,
|
|
138
|
+
map: () => mapType,
|
|
139
|
+
nan: () => nanType,
|
|
140
|
+
nativeEnum: () => nativeEnumType,
|
|
141
|
+
never: () => neverType,
|
|
142
|
+
null: () => nullType,
|
|
143
|
+
nullable: () => nullableType,
|
|
144
|
+
number: () => numberType,
|
|
145
|
+
object: () => objectType,
|
|
146
|
+
objectUtil: () => objectUtil,
|
|
147
|
+
oboolean: () => oboolean,
|
|
148
|
+
onumber: () => onumber,
|
|
149
|
+
optional: () => optionalType,
|
|
150
|
+
ostring: () => ostring,
|
|
151
|
+
pipeline: () => pipelineType,
|
|
152
|
+
preprocess: () => preprocessType,
|
|
153
|
+
promise: () => promiseType,
|
|
154
|
+
quotelessJson: () => quotelessJson,
|
|
155
|
+
record: () => recordType,
|
|
156
|
+
set: () => setType,
|
|
157
|
+
setErrorMap: () => setErrorMap,
|
|
158
|
+
strictObject: () => strictObjectType,
|
|
159
|
+
string: () => stringType,
|
|
160
|
+
symbol: () => symbolType,
|
|
161
|
+
transformer: () => effectsType,
|
|
162
|
+
tuple: () => tupleType,
|
|
163
|
+
undefined: () => undefinedType,
|
|
164
|
+
union: () => unionType,
|
|
165
|
+
unknown: () => unknownType,
|
|
166
|
+
util: () => util,
|
|
167
|
+
void: () => voidType
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
171
|
+
var util;
|
|
172
|
+
(function(util2) {
|
|
173
|
+
util2.assertEqual = (_) => {
|
|
174
|
+
};
|
|
175
|
+
function assertIs(_arg) {
|
|
176
|
+
}
|
|
177
|
+
util2.assertIs = assertIs;
|
|
178
|
+
function assertNever(_x) {
|
|
179
|
+
throw new Error();
|
|
180
|
+
}
|
|
181
|
+
util2.assertNever = assertNever;
|
|
182
|
+
util2.arrayToEnum = (items) => {
|
|
183
|
+
const obj = {};
|
|
184
|
+
for (const item of items) {
|
|
185
|
+
obj[item] = item;
|
|
186
|
+
}
|
|
187
|
+
return obj;
|
|
188
|
+
};
|
|
189
|
+
util2.getValidEnumValues = (obj) => {
|
|
190
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
191
|
+
const filtered = {};
|
|
192
|
+
for (const k of validKeys) {
|
|
193
|
+
filtered[k] = obj[k];
|
|
194
|
+
}
|
|
195
|
+
return util2.objectValues(filtered);
|
|
196
|
+
};
|
|
197
|
+
util2.objectValues = (obj) => {
|
|
198
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
199
|
+
return obj[e];
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
203
|
+
const keys = [];
|
|
204
|
+
for (const key in object) {
|
|
205
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
206
|
+
keys.push(key);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return keys;
|
|
210
|
+
};
|
|
211
|
+
util2.find = (arr, checker) => {
|
|
212
|
+
for (const item of arr) {
|
|
213
|
+
if (checker(item))
|
|
214
|
+
return item;
|
|
215
|
+
}
|
|
216
|
+
return void 0;
|
|
217
|
+
};
|
|
218
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
219
|
+
function joinValues(array, separator = " | ") {
|
|
220
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
221
|
+
}
|
|
222
|
+
util2.joinValues = joinValues;
|
|
223
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
224
|
+
if (typeof value === "bigint") {
|
|
225
|
+
return value.toString();
|
|
226
|
+
}
|
|
227
|
+
return value;
|
|
228
|
+
};
|
|
229
|
+
})(util || (util = {}));
|
|
230
|
+
var objectUtil;
|
|
231
|
+
(function(objectUtil2) {
|
|
232
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
233
|
+
return {
|
|
234
|
+
...first,
|
|
235
|
+
...second
|
|
236
|
+
// second overwrites first
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
})(objectUtil || (objectUtil = {}));
|
|
240
|
+
var ZodParsedType = util.arrayToEnum([
|
|
241
|
+
"string",
|
|
242
|
+
"nan",
|
|
243
|
+
"number",
|
|
244
|
+
"integer",
|
|
245
|
+
"float",
|
|
246
|
+
"boolean",
|
|
247
|
+
"date",
|
|
248
|
+
"bigint",
|
|
249
|
+
"symbol",
|
|
250
|
+
"function",
|
|
251
|
+
"undefined",
|
|
252
|
+
"null",
|
|
253
|
+
"array",
|
|
254
|
+
"object",
|
|
255
|
+
"unknown",
|
|
256
|
+
"promise",
|
|
257
|
+
"void",
|
|
258
|
+
"never",
|
|
259
|
+
"map",
|
|
260
|
+
"set"
|
|
261
|
+
]);
|
|
262
|
+
var getParsedType = (data) => {
|
|
263
|
+
const t = typeof data;
|
|
264
|
+
switch (t) {
|
|
265
|
+
case "undefined":
|
|
266
|
+
return ZodParsedType.undefined;
|
|
267
|
+
case "string":
|
|
268
|
+
return ZodParsedType.string;
|
|
269
|
+
case "number":
|
|
270
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
271
|
+
case "boolean":
|
|
272
|
+
return ZodParsedType.boolean;
|
|
273
|
+
case "function":
|
|
274
|
+
return ZodParsedType.function;
|
|
275
|
+
case "bigint":
|
|
276
|
+
return ZodParsedType.bigint;
|
|
277
|
+
case "symbol":
|
|
278
|
+
return ZodParsedType.symbol;
|
|
279
|
+
case "object":
|
|
280
|
+
if (Array.isArray(data)) {
|
|
281
|
+
return ZodParsedType.array;
|
|
282
|
+
}
|
|
283
|
+
if (data === null) {
|
|
284
|
+
return ZodParsedType.null;
|
|
285
|
+
}
|
|
286
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
287
|
+
return ZodParsedType.promise;
|
|
288
|
+
}
|
|
289
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
290
|
+
return ZodParsedType.map;
|
|
291
|
+
}
|
|
292
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
293
|
+
return ZodParsedType.set;
|
|
294
|
+
}
|
|
295
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
296
|
+
return ZodParsedType.date;
|
|
297
|
+
}
|
|
298
|
+
return ZodParsedType.object;
|
|
299
|
+
default:
|
|
300
|
+
return ZodParsedType.unknown;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
305
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
306
|
+
"invalid_type",
|
|
307
|
+
"invalid_literal",
|
|
308
|
+
"custom",
|
|
309
|
+
"invalid_union",
|
|
310
|
+
"invalid_union_discriminator",
|
|
311
|
+
"invalid_enum_value",
|
|
312
|
+
"unrecognized_keys",
|
|
313
|
+
"invalid_arguments",
|
|
314
|
+
"invalid_return_type",
|
|
315
|
+
"invalid_date",
|
|
316
|
+
"invalid_string",
|
|
317
|
+
"too_small",
|
|
318
|
+
"too_big",
|
|
319
|
+
"invalid_intersection_types",
|
|
320
|
+
"not_multiple_of",
|
|
321
|
+
"not_finite"
|
|
322
|
+
]);
|
|
323
|
+
var quotelessJson = (obj) => {
|
|
324
|
+
const json = JSON.stringify(obj, null, 2);
|
|
325
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
326
|
+
};
|
|
327
|
+
var ZodError = class _ZodError extends Error {
|
|
328
|
+
get errors() {
|
|
329
|
+
return this.issues;
|
|
330
|
+
}
|
|
331
|
+
constructor(issues) {
|
|
332
|
+
super();
|
|
333
|
+
this.issues = [];
|
|
334
|
+
this.addIssue = (sub) => {
|
|
335
|
+
this.issues = [...this.issues, sub];
|
|
336
|
+
};
|
|
337
|
+
this.addIssues = (subs = []) => {
|
|
338
|
+
this.issues = [...this.issues, ...subs];
|
|
339
|
+
};
|
|
340
|
+
const actualProto = new.target.prototype;
|
|
341
|
+
if (Object.setPrototypeOf) {
|
|
342
|
+
Object.setPrototypeOf(this, actualProto);
|
|
343
|
+
} else {
|
|
344
|
+
this.__proto__ = actualProto;
|
|
345
|
+
}
|
|
346
|
+
this.name = "ZodError";
|
|
347
|
+
this.issues = issues;
|
|
348
|
+
}
|
|
349
|
+
format(_mapper) {
|
|
350
|
+
const mapper = _mapper || function(issue) {
|
|
351
|
+
return issue.message;
|
|
352
|
+
};
|
|
353
|
+
const fieldErrors = { _errors: [] };
|
|
354
|
+
const processError = (error) => {
|
|
355
|
+
for (const issue of error.issues) {
|
|
356
|
+
if (issue.code === "invalid_union") {
|
|
357
|
+
issue.unionErrors.map(processError);
|
|
358
|
+
} else if (issue.code === "invalid_return_type") {
|
|
359
|
+
processError(issue.returnTypeError);
|
|
360
|
+
} else if (issue.code === "invalid_arguments") {
|
|
361
|
+
processError(issue.argumentsError);
|
|
362
|
+
} else if (issue.path.length === 0) {
|
|
363
|
+
fieldErrors._errors.push(mapper(issue));
|
|
364
|
+
} else {
|
|
365
|
+
let curr = fieldErrors;
|
|
366
|
+
let i = 0;
|
|
367
|
+
while (i < issue.path.length) {
|
|
368
|
+
const el = issue.path[i];
|
|
369
|
+
const terminal = i === issue.path.length - 1;
|
|
370
|
+
if (!terminal) {
|
|
371
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
372
|
+
} else {
|
|
373
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
374
|
+
curr[el]._errors.push(mapper(issue));
|
|
375
|
+
}
|
|
376
|
+
curr = curr[el];
|
|
377
|
+
i++;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
processError(this);
|
|
383
|
+
return fieldErrors;
|
|
384
|
+
}
|
|
385
|
+
static assert(value) {
|
|
386
|
+
if (!(value instanceof _ZodError)) {
|
|
387
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
toString() {
|
|
391
|
+
return this.message;
|
|
392
|
+
}
|
|
393
|
+
get message() {
|
|
394
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
395
|
+
}
|
|
396
|
+
get isEmpty() {
|
|
397
|
+
return this.issues.length === 0;
|
|
398
|
+
}
|
|
399
|
+
flatten(mapper = (issue) => issue.message) {
|
|
400
|
+
const fieldErrors = {};
|
|
401
|
+
const formErrors = [];
|
|
402
|
+
for (const sub of this.issues) {
|
|
403
|
+
if (sub.path.length > 0) {
|
|
404
|
+
const firstEl = sub.path[0];
|
|
405
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
406
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
407
|
+
} else {
|
|
408
|
+
formErrors.push(mapper(sub));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return { formErrors, fieldErrors };
|
|
412
|
+
}
|
|
413
|
+
get formErrors() {
|
|
414
|
+
return this.flatten();
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
ZodError.create = (issues) => {
|
|
418
|
+
const error = new ZodError(issues);
|
|
419
|
+
return error;
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
423
|
+
var errorMap = (issue, _ctx) => {
|
|
424
|
+
let message;
|
|
425
|
+
switch (issue.code) {
|
|
426
|
+
case ZodIssueCode.invalid_type:
|
|
427
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
428
|
+
message = "Required";
|
|
429
|
+
} else {
|
|
430
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
431
|
+
}
|
|
432
|
+
break;
|
|
433
|
+
case ZodIssueCode.invalid_literal:
|
|
434
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
435
|
+
break;
|
|
436
|
+
case ZodIssueCode.unrecognized_keys:
|
|
437
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
438
|
+
break;
|
|
439
|
+
case ZodIssueCode.invalid_union:
|
|
440
|
+
message = `Invalid input`;
|
|
441
|
+
break;
|
|
442
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
443
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
444
|
+
break;
|
|
445
|
+
case ZodIssueCode.invalid_enum_value:
|
|
446
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
447
|
+
break;
|
|
448
|
+
case ZodIssueCode.invalid_arguments:
|
|
449
|
+
message = `Invalid function arguments`;
|
|
450
|
+
break;
|
|
451
|
+
case ZodIssueCode.invalid_return_type:
|
|
452
|
+
message = `Invalid function return type`;
|
|
453
|
+
break;
|
|
454
|
+
case ZodIssueCode.invalid_date:
|
|
455
|
+
message = `Invalid date`;
|
|
456
|
+
break;
|
|
457
|
+
case ZodIssueCode.invalid_string:
|
|
458
|
+
if (typeof issue.validation === "object") {
|
|
459
|
+
if ("includes" in issue.validation) {
|
|
460
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
461
|
+
if (typeof issue.validation.position === "number") {
|
|
462
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
463
|
+
}
|
|
464
|
+
} else if ("startsWith" in issue.validation) {
|
|
465
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
466
|
+
} else if ("endsWith" in issue.validation) {
|
|
467
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
468
|
+
} else {
|
|
469
|
+
util.assertNever(issue.validation);
|
|
470
|
+
}
|
|
471
|
+
} else if (issue.validation !== "regex") {
|
|
472
|
+
message = `Invalid ${issue.validation}`;
|
|
473
|
+
} else {
|
|
474
|
+
message = "Invalid";
|
|
475
|
+
}
|
|
476
|
+
break;
|
|
477
|
+
case ZodIssueCode.too_small:
|
|
478
|
+
if (issue.type === "array")
|
|
479
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
480
|
+
else if (issue.type === "string")
|
|
481
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
482
|
+
else if (issue.type === "number")
|
|
483
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
484
|
+
else if (issue.type === "bigint")
|
|
485
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
486
|
+
else if (issue.type === "date")
|
|
487
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
488
|
+
else
|
|
489
|
+
message = "Invalid input";
|
|
490
|
+
break;
|
|
491
|
+
case ZodIssueCode.too_big:
|
|
492
|
+
if (issue.type === "array")
|
|
493
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
494
|
+
else if (issue.type === "string")
|
|
495
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
496
|
+
else if (issue.type === "number")
|
|
497
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
498
|
+
else if (issue.type === "bigint")
|
|
499
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
500
|
+
else if (issue.type === "date")
|
|
501
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
502
|
+
else
|
|
503
|
+
message = "Invalid input";
|
|
504
|
+
break;
|
|
505
|
+
case ZodIssueCode.custom:
|
|
506
|
+
message = `Invalid input`;
|
|
507
|
+
break;
|
|
508
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
509
|
+
message = `Intersection results could not be merged`;
|
|
510
|
+
break;
|
|
511
|
+
case ZodIssueCode.not_multiple_of:
|
|
512
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
513
|
+
break;
|
|
514
|
+
case ZodIssueCode.not_finite:
|
|
515
|
+
message = "Number must be finite";
|
|
516
|
+
break;
|
|
517
|
+
default:
|
|
518
|
+
message = _ctx.defaultError;
|
|
519
|
+
util.assertNever(issue);
|
|
520
|
+
}
|
|
521
|
+
return { message };
|
|
522
|
+
};
|
|
523
|
+
var en_default = errorMap;
|
|
524
|
+
|
|
525
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
526
|
+
var overrideErrorMap = en_default;
|
|
527
|
+
function setErrorMap(map) {
|
|
528
|
+
overrideErrorMap = map;
|
|
529
|
+
}
|
|
530
|
+
function getErrorMap() {
|
|
531
|
+
return overrideErrorMap;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
535
|
+
var makeIssue = (params) => {
|
|
536
|
+
const { data, path, errorMaps, issueData } = params;
|
|
537
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
538
|
+
const fullIssue = {
|
|
539
|
+
...issueData,
|
|
540
|
+
path: fullPath
|
|
541
|
+
};
|
|
542
|
+
if (issueData.message !== void 0) {
|
|
543
|
+
return {
|
|
544
|
+
...issueData,
|
|
545
|
+
path: fullPath,
|
|
546
|
+
message: issueData.message
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
let errorMessage = "";
|
|
550
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
551
|
+
for (const map of maps) {
|
|
552
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
...issueData,
|
|
556
|
+
path: fullPath,
|
|
557
|
+
message: errorMessage
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
var EMPTY_PATH = [];
|
|
561
|
+
function addIssueToContext(ctx, issueData) {
|
|
562
|
+
const overrideMap = getErrorMap();
|
|
563
|
+
const issue = makeIssue({
|
|
564
|
+
issueData,
|
|
565
|
+
data: ctx.data,
|
|
566
|
+
path: ctx.path,
|
|
567
|
+
errorMaps: [
|
|
568
|
+
ctx.common.contextualErrorMap,
|
|
569
|
+
// contextual error map is first priority
|
|
570
|
+
ctx.schemaErrorMap,
|
|
571
|
+
// then schema-bound map if available
|
|
572
|
+
overrideMap,
|
|
573
|
+
// then global override map
|
|
574
|
+
overrideMap === en_default ? void 0 : en_default
|
|
575
|
+
// then global default map
|
|
576
|
+
].filter((x) => !!x)
|
|
577
|
+
});
|
|
578
|
+
ctx.common.issues.push(issue);
|
|
579
|
+
}
|
|
580
|
+
var ParseStatus = class _ParseStatus {
|
|
581
|
+
constructor() {
|
|
582
|
+
this.value = "valid";
|
|
583
|
+
}
|
|
584
|
+
dirty() {
|
|
585
|
+
if (this.value === "valid")
|
|
586
|
+
this.value = "dirty";
|
|
587
|
+
}
|
|
588
|
+
abort() {
|
|
589
|
+
if (this.value !== "aborted")
|
|
590
|
+
this.value = "aborted";
|
|
591
|
+
}
|
|
592
|
+
static mergeArray(status, results) {
|
|
593
|
+
const arrayValue = [];
|
|
594
|
+
for (const s of results) {
|
|
595
|
+
if (s.status === "aborted")
|
|
596
|
+
return INVALID;
|
|
597
|
+
if (s.status === "dirty")
|
|
598
|
+
status.dirty();
|
|
599
|
+
arrayValue.push(s.value);
|
|
600
|
+
}
|
|
601
|
+
return { status: status.value, value: arrayValue };
|
|
602
|
+
}
|
|
603
|
+
static async mergeObjectAsync(status, pairs) {
|
|
604
|
+
const syncPairs = [];
|
|
605
|
+
for (const pair of pairs) {
|
|
606
|
+
const key = await pair.key;
|
|
607
|
+
const value = await pair.value;
|
|
608
|
+
syncPairs.push({
|
|
609
|
+
key,
|
|
610
|
+
value
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
614
|
+
}
|
|
615
|
+
static mergeObjectSync(status, pairs) {
|
|
616
|
+
const finalObject = {};
|
|
617
|
+
for (const pair of pairs) {
|
|
618
|
+
const { key, value } = pair;
|
|
619
|
+
if (key.status === "aborted")
|
|
620
|
+
return INVALID;
|
|
621
|
+
if (value.status === "aborted")
|
|
622
|
+
return INVALID;
|
|
623
|
+
if (key.status === "dirty")
|
|
624
|
+
status.dirty();
|
|
625
|
+
if (value.status === "dirty")
|
|
626
|
+
status.dirty();
|
|
627
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
628
|
+
finalObject[key.value] = value.value;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return { status: status.value, value: finalObject };
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
var INVALID = Object.freeze({
|
|
635
|
+
status: "aborted"
|
|
636
|
+
});
|
|
637
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
638
|
+
var OK = (value) => ({ status: "valid", value });
|
|
639
|
+
var isAborted = (x) => x.status === "aborted";
|
|
640
|
+
var isDirty = (x) => x.status === "dirty";
|
|
641
|
+
var isValid = (x) => x.status === "valid";
|
|
642
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
643
|
+
|
|
644
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
645
|
+
var errorUtil;
|
|
646
|
+
(function(errorUtil2) {
|
|
647
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
648
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
649
|
+
})(errorUtil || (errorUtil = {}));
|
|
650
|
+
|
|
651
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
652
|
+
var ParseInputLazyPath = class {
|
|
653
|
+
constructor(parent, value, path, key) {
|
|
654
|
+
this._cachedPath = [];
|
|
655
|
+
this.parent = parent;
|
|
656
|
+
this.data = value;
|
|
657
|
+
this._path = path;
|
|
658
|
+
this._key = key;
|
|
659
|
+
}
|
|
660
|
+
get path() {
|
|
661
|
+
if (!this._cachedPath.length) {
|
|
662
|
+
if (Array.isArray(this._key)) {
|
|
663
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
664
|
+
} else {
|
|
665
|
+
this._cachedPath.push(...this._path, this._key);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return this._cachedPath;
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
var handleResult = (ctx, result) => {
|
|
672
|
+
if (isValid(result)) {
|
|
673
|
+
return { success: true, data: result.value };
|
|
674
|
+
} else {
|
|
675
|
+
if (!ctx.common.issues.length) {
|
|
676
|
+
throw new Error("Validation failed but no issues detected.");
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
success: false,
|
|
680
|
+
get error() {
|
|
681
|
+
if (this._error)
|
|
682
|
+
return this._error;
|
|
683
|
+
const error = new ZodError(ctx.common.issues);
|
|
684
|
+
this._error = error;
|
|
685
|
+
return this._error;
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
function processCreateParams(params) {
|
|
691
|
+
if (!params)
|
|
692
|
+
return {};
|
|
693
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
694
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
695
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
696
|
+
}
|
|
697
|
+
if (errorMap2)
|
|
698
|
+
return { errorMap: errorMap2, description };
|
|
699
|
+
const customMap = (iss, ctx) => {
|
|
700
|
+
const { message } = params;
|
|
701
|
+
if (iss.code === "invalid_enum_value") {
|
|
702
|
+
return { message: message ?? ctx.defaultError };
|
|
703
|
+
}
|
|
704
|
+
if (typeof ctx.data === "undefined") {
|
|
705
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
706
|
+
}
|
|
707
|
+
if (iss.code !== "invalid_type")
|
|
708
|
+
return { message: ctx.defaultError };
|
|
709
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
710
|
+
};
|
|
711
|
+
return { errorMap: customMap, description };
|
|
712
|
+
}
|
|
713
|
+
var ZodType = class {
|
|
714
|
+
get description() {
|
|
715
|
+
return this._def.description;
|
|
716
|
+
}
|
|
717
|
+
_getType(input) {
|
|
718
|
+
return getParsedType(input.data);
|
|
719
|
+
}
|
|
720
|
+
_getOrReturnCtx(input, ctx) {
|
|
721
|
+
return ctx || {
|
|
722
|
+
common: input.parent.common,
|
|
723
|
+
data: input.data,
|
|
724
|
+
parsedType: getParsedType(input.data),
|
|
725
|
+
schemaErrorMap: this._def.errorMap,
|
|
726
|
+
path: input.path,
|
|
727
|
+
parent: input.parent
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
_processInputParams(input) {
|
|
731
|
+
return {
|
|
732
|
+
status: new ParseStatus(),
|
|
733
|
+
ctx: {
|
|
734
|
+
common: input.parent.common,
|
|
735
|
+
data: input.data,
|
|
736
|
+
parsedType: getParsedType(input.data),
|
|
737
|
+
schemaErrorMap: this._def.errorMap,
|
|
738
|
+
path: input.path,
|
|
739
|
+
parent: input.parent
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
_parseSync(input) {
|
|
744
|
+
const result = this._parse(input);
|
|
745
|
+
if (isAsync(result)) {
|
|
746
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
747
|
+
}
|
|
748
|
+
return result;
|
|
749
|
+
}
|
|
750
|
+
_parseAsync(input) {
|
|
751
|
+
const result = this._parse(input);
|
|
752
|
+
return Promise.resolve(result);
|
|
753
|
+
}
|
|
754
|
+
parse(data, params) {
|
|
755
|
+
const result = this.safeParse(data, params);
|
|
756
|
+
if (result.success)
|
|
757
|
+
return result.data;
|
|
758
|
+
throw result.error;
|
|
759
|
+
}
|
|
760
|
+
safeParse(data, params) {
|
|
761
|
+
const ctx = {
|
|
762
|
+
common: {
|
|
763
|
+
issues: [],
|
|
764
|
+
async: params?.async ?? false,
|
|
765
|
+
contextualErrorMap: params?.errorMap
|
|
766
|
+
},
|
|
767
|
+
path: params?.path || [],
|
|
768
|
+
schemaErrorMap: this._def.errorMap,
|
|
769
|
+
parent: null,
|
|
770
|
+
data,
|
|
771
|
+
parsedType: getParsedType(data)
|
|
772
|
+
};
|
|
773
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
774
|
+
return handleResult(ctx, result);
|
|
775
|
+
}
|
|
776
|
+
"~validate"(data) {
|
|
777
|
+
const ctx = {
|
|
778
|
+
common: {
|
|
779
|
+
issues: [],
|
|
780
|
+
async: !!this["~standard"].async
|
|
781
|
+
},
|
|
782
|
+
path: [],
|
|
783
|
+
schemaErrorMap: this._def.errorMap,
|
|
784
|
+
parent: null,
|
|
785
|
+
data,
|
|
786
|
+
parsedType: getParsedType(data)
|
|
787
|
+
};
|
|
788
|
+
if (!this["~standard"].async) {
|
|
789
|
+
try {
|
|
790
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
791
|
+
return isValid(result) ? {
|
|
792
|
+
value: result.value
|
|
793
|
+
} : {
|
|
794
|
+
issues: ctx.common.issues
|
|
795
|
+
};
|
|
796
|
+
} catch (err) {
|
|
797
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
798
|
+
this["~standard"].async = true;
|
|
799
|
+
}
|
|
800
|
+
ctx.common = {
|
|
801
|
+
issues: [],
|
|
802
|
+
async: true
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
807
|
+
value: result.value
|
|
808
|
+
} : {
|
|
809
|
+
issues: ctx.common.issues
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
async parseAsync(data, params) {
|
|
813
|
+
const result = await this.safeParseAsync(data, params);
|
|
814
|
+
if (result.success)
|
|
815
|
+
return result.data;
|
|
816
|
+
throw result.error;
|
|
817
|
+
}
|
|
818
|
+
async safeParseAsync(data, params) {
|
|
819
|
+
const ctx = {
|
|
820
|
+
common: {
|
|
821
|
+
issues: [],
|
|
822
|
+
contextualErrorMap: params?.errorMap,
|
|
823
|
+
async: true
|
|
824
|
+
},
|
|
825
|
+
path: params?.path || [],
|
|
826
|
+
schemaErrorMap: this._def.errorMap,
|
|
827
|
+
parent: null,
|
|
828
|
+
data,
|
|
829
|
+
parsedType: getParsedType(data)
|
|
830
|
+
};
|
|
831
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
832
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
833
|
+
return handleResult(ctx, result);
|
|
834
|
+
}
|
|
835
|
+
refine(check, message) {
|
|
836
|
+
const getIssueProperties = (val) => {
|
|
837
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
838
|
+
return { message };
|
|
839
|
+
} else if (typeof message === "function") {
|
|
840
|
+
return message(val);
|
|
841
|
+
} else {
|
|
842
|
+
return message;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
return this._refinement((val, ctx) => {
|
|
846
|
+
const result = check(val);
|
|
847
|
+
const setError = () => ctx.addIssue({
|
|
848
|
+
code: ZodIssueCode.custom,
|
|
849
|
+
...getIssueProperties(val)
|
|
850
|
+
});
|
|
851
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
852
|
+
return result.then((data) => {
|
|
853
|
+
if (!data) {
|
|
854
|
+
setError();
|
|
855
|
+
return false;
|
|
856
|
+
} else {
|
|
857
|
+
return true;
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
if (!result) {
|
|
862
|
+
setError();
|
|
863
|
+
return false;
|
|
864
|
+
} else {
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
refinement(check, refinementData) {
|
|
870
|
+
return this._refinement((val, ctx) => {
|
|
871
|
+
if (!check(val)) {
|
|
872
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
873
|
+
return false;
|
|
874
|
+
} else {
|
|
875
|
+
return true;
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
_refinement(refinement) {
|
|
880
|
+
return new ZodEffects({
|
|
881
|
+
schema: this,
|
|
882
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
883
|
+
effect: { type: "refinement", refinement }
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
superRefine(refinement) {
|
|
887
|
+
return this._refinement(refinement);
|
|
888
|
+
}
|
|
889
|
+
constructor(def) {
|
|
890
|
+
this.spa = this.safeParseAsync;
|
|
891
|
+
this._def = def;
|
|
892
|
+
this.parse = this.parse.bind(this);
|
|
893
|
+
this.safeParse = this.safeParse.bind(this);
|
|
894
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
895
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
896
|
+
this.spa = this.spa.bind(this);
|
|
897
|
+
this.refine = this.refine.bind(this);
|
|
898
|
+
this.refinement = this.refinement.bind(this);
|
|
899
|
+
this.superRefine = this.superRefine.bind(this);
|
|
900
|
+
this.optional = this.optional.bind(this);
|
|
901
|
+
this.nullable = this.nullable.bind(this);
|
|
902
|
+
this.nullish = this.nullish.bind(this);
|
|
903
|
+
this.array = this.array.bind(this);
|
|
904
|
+
this.promise = this.promise.bind(this);
|
|
905
|
+
this.or = this.or.bind(this);
|
|
906
|
+
this.and = this.and.bind(this);
|
|
907
|
+
this.transform = this.transform.bind(this);
|
|
908
|
+
this.brand = this.brand.bind(this);
|
|
909
|
+
this.default = this.default.bind(this);
|
|
910
|
+
this.catch = this.catch.bind(this);
|
|
911
|
+
this.describe = this.describe.bind(this);
|
|
912
|
+
this.pipe = this.pipe.bind(this);
|
|
913
|
+
this.readonly = this.readonly.bind(this);
|
|
914
|
+
this.isNullable = this.isNullable.bind(this);
|
|
915
|
+
this.isOptional = this.isOptional.bind(this);
|
|
916
|
+
this["~standard"] = {
|
|
917
|
+
version: 1,
|
|
918
|
+
vendor: "zod",
|
|
919
|
+
validate: (data) => this["~validate"](data)
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
optional() {
|
|
923
|
+
return ZodOptional.create(this, this._def);
|
|
924
|
+
}
|
|
925
|
+
nullable() {
|
|
926
|
+
return ZodNullable.create(this, this._def);
|
|
927
|
+
}
|
|
928
|
+
nullish() {
|
|
929
|
+
return this.nullable().optional();
|
|
930
|
+
}
|
|
931
|
+
array() {
|
|
932
|
+
return ZodArray.create(this);
|
|
933
|
+
}
|
|
934
|
+
promise() {
|
|
935
|
+
return ZodPromise.create(this, this._def);
|
|
936
|
+
}
|
|
937
|
+
or(option) {
|
|
938
|
+
return ZodUnion.create([this, option], this._def);
|
|
939
|
+
}
|
|
940
|
+
and(incoming) {
|
|
941
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
942
|
+
}
|
|
943
|
+
transform(transform) {
|
|
944
|
+
return new ZodEffects({
|
|
945
|
+
...processCreateParams(this._def),
|
|
946
|
+
schema: this,
|
|
947
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
948
|
+
effect: { type: "transform", transform }
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
default(def) {
|
|
952
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
953
|
+
return new ZodDefault({
|
|
954
|
+
...processCreateParams(this._def),
|
|
955
|
+
innerType: this,
|
|
956
|
+
defaultValue: defaultValueFunc,
|
|
957
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
brand() {
|
|
961
|
+
return new ZodBranded({
|
|
962
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
963
|
+
type: this,
|
|
964
|
+
...processCreateParams(this._def)
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
catch(def) {
|
|
968
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
969
|
+
return new ZodCatch({
|
|
970
|
+
...processCreateParams(this._def),
|
|
971
|
+
innerType: this,
|
|
972
|
+
catchValue: catchValueFunc,
|
|
973
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
describe(description) {
|
|
977
|
+
const This = this.constructor;
|
|
978
|
+
return new This({
|
|
979
|
+
...this._def,
|
|
980
|
+
description
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
pipe(target) {
|
|
984
|
+
return ZodPipeline.create(this, target);
|
|
985
|
+
}
|
|
986
|
+
readonly() {
|
|
987
|
+
return ZodReadonly.create(this);
|
|
988
|
+
}
|
|
989
|
+
isOptional() {
|
|
990
|
+
return this.safeParse(void 0).success;
|
|
991
|
+
}
|
|
992
|
+
isNullable() {
|
|
993
|
+
return this.safeParse(null).success;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
997
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
998
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
999
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
1000
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1001
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1002
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1003
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1004
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1005
|
+
var emojiRegex;
|
|
1006
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1007
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
1008
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1009
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1010
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1011
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1012
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1013
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1014
|
+
function timeRegexSource(args) {
|
|
1015
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1016
|
+
if (args.precision) {
|
|
1017
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1018
|
+
} else if (args.precision == null) {
|
|
1019
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1020
|
+
}
|
|
1021
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1022
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1023
|
+
}
|
|
1024
|
+
function timeRegex(args) {
|
|
1025
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1026
|
+
}
|
|
1027
|
+
function datetimeRegex(args) {
|
|
1028
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1029
|
+
const opts = [];
|
|
1030
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1031
|
+
if (args.offset)
|
|
1032
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1033
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1034
|
+
return new RegExp(`^${regex}$`);
|
|
1035
|
+
}
|
|
1036
|
+
function isValidIP(ip, version) {
|
|
1037
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1041
|
+
return true;
|
|
1042
|
+
}
|
|
1043
|
+
return false;
|
|
1044
|
+
}
|
|
1045
|
+
function isValidJWT(jwt, alg) {
|
|
1046
|
+
if (!jwtRegex.test(jwt))
|
|
1047
|
+
return false;
|
|
1048
|
+
try {
|
|
1049
|
+
const [header] = jwt.split(".");
|
|
1050
|
+
if (!header)
|
|
1051
|
+
return false;
|
|
1052
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1053
|
+
const decoded = JSON.parse(atob(base64));
|
|
1054
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1055
|
+
return false;
|
|
1056
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1057
|
+
return false;
|
|
1058
|
+
if (!decoded.alg)
|
|
1059
|
+
return false;
|
|
1060
|
+
if (alg && decoded.alg !== alg)
|
|
1061
|
+
return false;
|
|
1062
|
+
return true;
|
|
1063
|
+
} catch {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
function isValidCidr(ip, version) {
|
|
1068
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1069
|
+
return true;
|
|
1070
|
+
}
|
|
1071
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1072
|
+
return true;
|
|
1073
|
+
}
|
|
1074
|
+
return false;
|
|
1075
|
+
}
|
|
1076
|
+
var ZodString = class _ZodString extends ZodType {
|
|
1077
|
+
_parse(input) {
|
|
1078
|
+
if (this._def.coerce) {
|
|
1079
|
+
input.data = String(input.data);
|
|
1080
|
+
}
|
|
1081
|
+
const parsedType = this._getType(input);
|
|
1082
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1083
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1084
|
+
addIssueToContext(ctx2, {
|
|
1085
|
+
code: ZodIssueCode.invalid_type,
|
|
1086
|
+
expected: ZodParsedType.string,
|
|
1087
|
+
received: ctx2.parsedType
|
|
1088
|
+
});
|
|
1089
|
+
return INVALID;
|
|
1090
|
+
}
|
|
1091
|
+
const status = new ParseStatus();
|
|
1092
|
+
let ctx = void 0;
|
|
1093
|
+
for (const check of this._def.checks) {
|
|
1094
|
+
if (check.kind === "min") {
|
|
1095
|
+
if (input.data.length < check.value) {
|
|
1096
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1097
|
+
addIssueToContext(ctx, {
|
|
1098
|
+
code: ZodIssueCode.too_small,
|
|
1099
|
+
minimum: check.value,
|
|
1100
|
+
type: "string",
|
|
1101
|
+
inclusive: true,
|
|
1102
|
+
exact: false,
|
|
1103
|
+
message: check.message
|
|
1104
|
+
});
|
|
1105
|
+
status.dirty();
|
|
1106
|
+
}
|
|
1107
|
+
} else if (check.kind === "max") {
|
|
1108
|
+
if (input.data.length > check.value) {
|
|
1109
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1110
|
+
addIssueToContext(ctx, {
|
|
1111
|
+
code: ZodIssueCode.too_big,
|
|
1112
|
+
maximum: check.value,
|
|
1113
|
+
type: "string",
|
|
1114
|
+
inclusive: true,
|
|
1115
|
+
exact: false,
|
|
1116
|
+
message: check.message
|
|
1117
|
+
});
|
|
1118
|
+
status.dirty();
|
|
1119
|
+
}
|
|
1120
|
+
} else if (check.kind === "length") {
|
|
1121
|
+
const tooBig = input.data.length > check.value;
|
|
1122
|
+
const tooSmall = input.data.length < check.value;
|
|
1123
|
+
if (tooBig || tooSmall) {
|
|
1124
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1125
|
+
if (tooBig) {
|
|
1126
|
+
addIssueToContext(ctx, {
|
|
1127
|
+
code: ZodIssueCode.too_big,
|
|
1128
|
+
maximum: check.value,
|
|
1129
|
+
type: "string",
|
|
1130
|
+
inclusive: true,
|
|
1131
|
+
exact: true,
|
|
1132
|
+
message: check.message
|
|
1133
|
+
});
|
|
1134
|
+
} else if (tooSmall) {
|
|
1135
|
+
addIssueToContext(ctx, {
|
|
1136
|
+
code: ZodIssueCode.too_small,
|
|
1137
|
+
minimum: check.value,
|
|
1138
|
+
type: "string",
|
|
1139
|
+
inclusive: true,
|
|
1140
|
+
exact: true,
|
|
1141
|
+
message: check.message
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
status.dirty();
|
|
1145
|
+
}
|
|
1146
|
+
} else if (check.kind === "email") {
|
|
1147
|
+
if (!emailRegex.test(input.data)) {
|
|
1148
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1149
|
+
addIssueToContext(ctx, {
|
|
1150
|
+
validation: "email",
|
|
1151
|
+
code: ZodIssueCode.invalid_string,
|
|
1152
|
+
message: check.message
|
|
1153
|
+
});
|
|
1154
|
+
status.dirty();
|
|
1155
|
+
}
|
|
1156
|
+
} else if (check.kind === "emoji") {
|
|
1157
|
+
if (!emojiRegex) {
|
|
1158
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1159
|
+
}
|
|
1160
|
+
if (!emojiRegex.test(input.data)) {
|
|
1161
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1162
|
+
addIssueToContext(ctx, {
|
|
1163
|
+
validation: "emoji",
|
|
1164
|
+
code: ZodIssueCode.invalid_string,
|
|
1165
|
+
message: check.message
|
|
1166
|
+
});
|
|
1167
|
+
status.dirty();
|
|
1168
|
+
}
|
|
1169
|
+
} else if (check.kind === "uuid") {
|
|
1170
|
+
if (!uuidRegex.test(input.data)) {
|
|
1171
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1172
|
+
addIssueToContext(ctx, {
|
|
1173
|
+
validation: "uuid",
|
|
1174
|
+
code: ZodIssueCode.invalid_string,
|
|
1175
|
+
message: check.message
|
|
1176
|
+
});
|
|
1177
|
+
status.dirty();
|
|
1178
|
+
}
|
|
1179
|
+
} else if (check.kind === "nanoid") {
|
|
1180
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1181
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1182
|
+
addIssueToContext(ctx, {
|
|
1183
|
+
validation: "nanoid",
|
|
1184
|
+
code: ZodIssueCode.invalid_string,
|
|
1185
|
+
message: check.message
|
|
1186
|
+
});
|
|
1187
|
+
status.dirty();
|
|
1188
|
+
}
|
|
1189
|
+
} else if (check.kind === "cuid") {
|
|
1190
|
+
if (!cuidRegex.test(input.data)) {
|
|
1191
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1192
|
+
addIssueToContext(ctx, {
|
|
1193
|
+
validation: "cuid",
|
|
1194
|
+
code: ZodIssueCode.invalid_string,
|
|
1195
|
+
message: check.message
|
|
1196
|
+
});
|
|
1197
|
+
status.dirty();
|
|
1198
|
+
}
|
|
1199
|
+
} else if (check.kind === "cuid2") {
|
|
1200
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1201
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1202
|
+
addIssueToContext(ctx, {
|
|
1203
|
+
validation: "cuid2",
|
|
1204
|
+
code: ZodIssueCode.invalid_string,
|
|
1205
|
+
message: check.message
|
|
1206
|
+
});
|
|
1207
|
+
status.dirty();
|
|
1208
|
+
}
|
|
1209
|
+
} else if (check.kind === "ulid") {
|
|
1210
|
+
if (!ulidRegex.test(input.data)) {
|
|
1211
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1212
|
+
addIssueToContext(ctx, {
|
|
1213
|
+
validation: "ulid",
|
|
1214
|
+
code: ZodIssueCode.invalid_string,
|
|
1215
|
+
message: check.message
|
|
1216
|
+
});
|
|
1217
|
+
status.dirty();
|
|
1218
|
+
}
|
|
1219
|
+
} else if (check.kind === "url") {
|
|
1220
|
+
try {
|
|
1221
|
+
new URL(input.data);
|
|
1222
|
+
} catch {
|
|
1223
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1224
|
+
addIssueToContext(ctx, {
|
|
1225
|
+
validation: "url",
|
|
1226
|
+
code: ZodIssueCode.invalid_string,
|
|
1227
|
+
message: check.message
|
|
1228
|
+
});
|
|
1229
|
+
status.dirty();
|
|
1230
|
+
}
|
|
1231
|
+
} else if (check.kind === "regex") {
|
|
1232
|
+
check.regex.lastIndex = 0;
|
|
1233
|
+
const testResult = check.regex.test(input.data);
|
|
1234
|
+
if (!testResult) {
|
|
1235
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1236
|
+
addIssueToContext(ctx, {
|
|
1237
|
+
validation: "regex",
|
|
1238
|
+
code: ZodIssueCode.invalid_string,
|
|
1239
|
+
message: check.message
|
|
1240
|
+
});
|
|
1241
|
+
status.dirty();
|
|
1242
|
+
}
|
|
1243
|
+
} else if (check.kind === "trim") {
|
|
1244
|
+
input.data = input.data.trim();
|
|
1245
|
+
} else if (check.kind === "includes") {
|
|
1246
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1247
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1248
|
+
addIssueToContext(ctx, {
|
|
1249
|
+
code: ZodIssueCode.invalid_string,
|
|
1250
|
+
validation: { includes: check.value, position: check.position },
|
|
1251
|
+
message: check.message
|
|
1252
|
+
});
|
|
1253
|
+
status.dirty();
|
|
1254
|
+
}
|
|
1255
|
+
} else if (check.kind === "toLowerCase") {
|
|
1256
|
+
input.data = input.data.toLowerCase();
|
|
1257
|
+
} else if (check.kind === "toUpperCase") {
|
|
1258
|
+
input.data = input.data.toUpperCase();
|
|
1259
|
+
} else if (check.kind === "startsWith") {
|
|
1260
|
+
if (!input.data.startsWith(check.value)) {
|
|
1261
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1262
|
+
addIssueToContext(ctx, {
|
|
1263
|
+
code: ZodIssueCode.invalid_string,
|
|
1264
|
+
validation: { startsWith: check.value },
|
|
1265
|
+
message: check.message
|
|
1266
|
+
});
|
|
1267
|
+
status.dirty();
|
|
1268
|
+
}
|
|
1269
|
+
} else if (check.kind === "endsWith") {
|
|
1270
|
+
if (!input.data.endsWith(check.value)) {
|
|
1271
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1272
|
+
addIssueToContext(ctx, {
|
|
1273
|
+
code: ZodIssueCode.invalid_string,
|
|
1274
|
+
validation: { endsWith: check.value },
|
|
1275
|
+
message: check.message
|
|
1276
|
+
});
|
|
1277
|
+
status.dirty();
|
|
1278
|
+
}
|
|
1279
|
+
} else if (check.kind === "datetime") {
|
|
1280
|
+
const regex = datetimeRegex(check);
|
|
1281
|
+
if (!regex.test(input.data)) {
|
|
1282
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1283
|
+
addIssueToContext(ctx, {
|
|
1284
|
+
code: ZodIssueCode.invalid_string,
|
|
1285
|
+
validation: "datetime",
|
|
1286
|
+
message: check.message
|
|
1287
|
+
});
|
|
1288
|
+
status.dirty();
|
|
1289
|
+
}
|
|
1290
|
+
} else if (check.kind === "date") {
|
|
1291
|
+
const regex = dateRegex;
|
|
1292
|
+
if (!regex.test(input.data)) {
|
|
1293
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1294
|
+
addIssueToContext(ctx, {
|
|
1295
|
+
code: ZodIssueCode.invalid_string,
|
|
1296
|
+
validation: "date",
|
|
1297
|
+
message: check.message
|
|
1298
|
+
});
|
|
1299
|
+
status.dirty();
|
|
1300
|
+
}
|
|
1301
|
+
} else if (check.kind === "time") {
|
|
1302
|
+
const regex = timeRegex(check);
|
|
1303
|
+
if (!regex.test(input.data)) {
|
|
1304
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1305
|
+
addIssueToContext(ctx, {
|
|
1306
|
+
code: ZodIssueCode.invalid_string,
|
|
1307
|
+
validation: "time",
|
|
1308
|
+
message: check.message
|
|
1309
|
+
});
|
|
1310
|
+
status.dirty();
|
|
1311
|
+
}
|
|
1312
|
+
} else if (check.kind === "duration") {
|
|
1313
|
+
if (!durationRegex.test(input.data)) {
|
|
1314
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1315
|
+
addIssueToContext(ctx, {
|
|
1316
|
+
validation: "duration",
|
|
1317
|
+
code: ZodIssueCode.invalid_string,
|
|
1318
|
+
message: check.message
|
|
1319
|
+
});
|
|
1320
|
+
status.dirty();
|
|
1321
|
+
}
|
|
1322
|
+
} else if (check.kind === "ip") {
|
|
1323
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1324
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1325
|
+
addIssueToContext(ctx, {
|
|
1326
|
+
validation: "ip",
|
|
1327
|
+
code: ZodIssueCode.invalid_string,
|
|
1328
|
+
message: check.message
|
|
1329
|
+
});
|
|
1330
|
+
status.dirty();
|
|
1331
|
+
}
|
|
1332
|
+
} else if (check.kind === "jwt") {
|
|
1333
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1334
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1335
|
+
addIssueToContext(ctx, {
|
|
1336
|
+
validation: "jwt",
|
|
1337
|
+
code: ZodIssueCode.invalid_string,
|
|
1338
|
+
message: check.message
|
|
1339
|
+
});
|
|
1340
|
+
status.dirty();
|
|
1341
|
+
}
|
|
1342
|
+
} else if (check.kind === "cidr") {
|
|
1343
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1344
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1345
|
+
addIssueToContext(ctx, {
|
|
1346
|
+
validation: "cidr",
|
|
1347
|
+
code: ZodIssueCode.invalid_string,
|
|
1348
|
+
message: check.message
|
|
1349
|
+
});
|
|
1350
|
+
status.dirty();
|
|
1351
|
+
}
|
|
1352
|
+
} else if (check.kind === "base64") {
|
|
1353
|
+
if (!base64Regex.test(input.data)) {
|
|
1354
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1355
|
+
addIssueToContext(ctx, {
|
|
1356
|
+
validation: "base64",
|
|
1357
|
+
code: ZodIssueCode.invalid_string,
|
|
1358
|
+
message: check.message
|
|
1359
|
+
});
|
|
1360
|
+
status.dirty();
|
|
1361
|
+
}
|
|
1362
|
+
} else if (check.kind === "base64url") {
|
|
1363
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1364
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1365
|
+
addIssueToContext(ctx, {
|
|
1366
|
+
validation: "base64url",
|
|
1367
|
+
code: ZodIssueCode.invalid_string,
|
|
1368
|
+
message: check.message
|
|
1369
|
+
});
|
|
1370
|
+
status.dirty();
|
|
1371
|
+
}
|
|
1372
|
+
} else {
|
|
1373
|
+
util.assertNever(check);
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return { status: status.value, value: input.data };
|
|
1377
|
+
}
|
|
1378
|
+
_regex(regex, validation, message) {
|
|
1379
|
+
return this.refinement((data) => regex.test(data), {
|
|
1380
|
+
validation,
|
|
1381
|
+
code: ZodIssueCode.invalid_string,
|
|
1382
|
+
...errorUtil.errToObj(message)
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
_addCheck(check) {
|
|
1386
|
+
return new _ZodString({
|
|
1387
|
+
...this._def,
|
|
1388
|
+
checks: [...this._def.checks, check]
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
email(message) {
|
|
1392
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1393
|
+
}
|
|
1394
|
+
url(message) {
|
|
1395
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1396
|
+
}
|
|
1397
|
+
emoji(message) {
|
|
1398
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1399
|
+
}
|
|
1400
|
+
uuid(message) {
|
|
1401
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1402
|
+
}
|
|
1403
|
+
nanoid(message) {
|
|
1404
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1405
|
+
}
|
|
1406
|
+
cuid(message) {
|
|
1407
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1408
|
+
}
|
|
1409
|
+
cuid2(message) {
|
|
1410
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1411
|
+
}
|
|
1412
|
+
ulid(message) {
|
|
1413
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1414
|
+
}
|
|
1415
|
+
base64(message) {
|
|
1416
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1417
|
+
}
|
|
1418
|
+
base64url(message) {
|
|
1419
|
+
return this._addCheck({
|
|
1420
|
+
kind: "base64url",
|
|
1421
|
+
...errorUtil.errToObj(message)
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
jwt(options) {
|
|
1425
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1426
|
+
}
|
|
1427
|
+
ip(options) {
|
|
1428
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1429
|
+
}
|
|
1430
|
+
cidr(options) {
|
|
1431
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1432
|
+
}
|
|
1433
|
+
datetime(options) {
|
|
1434
|
+
if (typeof options === "string") {
|
|
1435
|
+
return this._addCheck({
|
|
1436
|
+
kind: "datetime",
|
|
1437
|
+
precision: null,
|
|
1438
|
+
offset: false,
|
|
1439
|
+
local: false,
|
|
1440
|
+
message: options
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
return this._addCheck({
|
|
1444
|
+
kind: "datetime",
|
|
1445
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1446
|
+
offset: options?.offset ?? false,
|
|
1447
|
+
local: options?.local ?? false,
|
|
1448
|
+
...errorUtil.errToObj(options?.message)
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
date(message) {
|
|
1452
|
+
return this._addCheck({ kind: "date", message });
|
|
1453
|
+
}
|
|
1454
|
+
time(options) {
|
|
1455
|
+
if (typeof options === "string") {
|
|
1456
|
+
return this._addCheck({
|
|
1457
|
+
kind: "time",
|
|
1458
|
+
precision: null,
|
|
1459
|
+
message: options
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
return this._addCheck({
|
|
1463
|
+
kind: "time",
|
|
1464
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1465
|
+
...errorUtil.errToObj(options?.message)
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
duration(message) {
|
|
1469
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1470
|
+
}
|
|
1471
|
+
regex(regex, message) {
|
|
1472
|
+
return this._addCheck({
|
|
1473
|
+
kind: "regex",
|
|
1474
|
+
regex,
|
|
1475
|
+
...errorUtil.errToObj(message)
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
includes(value, options) {
|
|
1479
|
+
return this._addCheck({
|
|
1480
|
+
kind: "includes",
|
|
1481
|
+
value,
|
|
1482
|
+
position: options?.position,
|
|
1483
|
+
...errorUtil.errToObj(options?.message)
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
startsWith(value, message) {
|
|
1487
|
+
return this._addCheck({
|
|
1488
|
+
kind: "startsWith",
|
|
1489
|
+
value,
|
|
1490
|
+
...errorUtil.errToObj(message)
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
endsWith(value, message) {
|
|
1494
|
+
return this._addCheck({
|
|
1495
|
+
kind: "endsWith",
|
|
1496
|
+
value,
|
|
1497
|
+
...errorUtil.errToObj(message)
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
min(minLength, message) {
|
|
1501
|
+
return this._addCheck({
|
|
1502
|
+
kind: "min",
|
|
1503
|
+
value: minLength,
|
|
1504
|
+
...errorUtil.errToObj(message)
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
max(maxLength, message) {
|
|
1508
|
+
return this._addCheck({
|
|
1509
|
+
kind: "max",
|
|
1510
|
+
value: maxLength,
|
|
1511
|
+
...errorUtil.errToObj(message)
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
length(len, message) {
|
|
1515
|
+
return this._addCheck({
|
|
1516
|
+
kind: "length",
|
|
1517
|
+
value: len,
|
|
1518
|
+
...errorUtil.errToObj(message)
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Equivalent to `.min(1)`
|
|
1523
|
+
*/
|
|
1524
|
+
nonempty(message) {
|
|
1525
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1526
|
+
}
|
|
1527
|
+
trim() {
|
|
1528
|
+
return new _ZodString({
|
|
1529
|
+
...this._def,
|
|
1530
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
toLowerCase() {
|
|
1534
|
+
return new _ZodString({
|
|
1535
|
+
...this._def,
|
|
1536
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
toUpperCase() {
|
|
1540
|
+
return new _ZodString({
|
|
1541
|
+
...this._def,
|
|
1542
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
get isDatetime() {
|
|
1546
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1547
|
+
}
|
|
1548
|
+
get isDate() {
|
|
1549
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1550
|
+
}
|
|
1551
|
+
get isTime() {
|
|
1552
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1553
|
+
}
|
|
1554
|
+
get isDuration() {
|
|
1555
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1556
|
+
}
|
|
1557
|
+
get isEmail() {
|
|
1558
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1559
|
+
}
|
|
1560
|
+
get isURL() {
|
|
1561
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1562
|
+
}
|
|
1563
|
+
get isEmoji() {
|
|
1564
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1565
|
+
}
|
|
1566
|
+
get isUUID() {
|
|
1567
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1568
|
+
}
|
|
1569
|
+
get isNANOID() {
|
|
1570
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1571
|
+
}
|
|
1572
|
+
get isCUID() {
|
|
1573
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1574
|
+
}
|
|
1575
|
+
get isCUID2() {
|
|
1576
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1577
|
+
}
|
|
1578
|
+
get isULID() {
|
|
1579
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1580
|
+
}
|
|
1581
|
+
get isIP() {
|
|
1582
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1583
|
+
}
|
|
1584
|
+
get isCIDR() {
|
|
1585
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1586
|
+
}
|
|
1587
|
+
get isBase64() {
|
|
1588
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1589
|
+
}
|
|
1590
|
+
get isBase64url() {
|
|
1591
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1592
|
+
}
|
|
1593
|
+
get minLength() {
|
|
1594
|
+
let min = null;
|
|
1595
|
+
for (const ch of this._def.checks) {
|
|
1596
|
+
if (ch.kind === "min") {
|
|
1597
|
+
if (min === null || ch.value > min)
|
|
1598
|
+
min = ch.value;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return min;
|
|
1602
|
+
}
|
|
1603
|
+
get maxLength() {
|
|
1604
|
+
let max = null;
|
|
1605
|
+
for (const ch of this._def.checks) {
|
|
1606
|
+
if (ch.kind === "max") {
|
|
1607
|
+
if (max === null || ch.value < max)
|
|
1608
|
+
max = ch.value;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return max;
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
ZodString.create = (params) => {
|
|
1615
|
+
return new ZodString({
|
|
1616
|
+
checks: [],
|
|
1617
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1618
|
+
coerce: params?.coerce ?? false,
|
|
1619
|
+
...processCreateParams(params)
|
|
1620
|
+
});
|
|
1621
|
+
};
|
|
1622
|
+
function floatSafeRemainder(val, step) {
|
|
1623
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1624
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1625
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1626
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1627
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1628
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1629
|
+
}
|
|
1630
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1631
|
+
constructor() {
|
|
1632
|
+
super(...arguments);
|
|
1633
|
+
this.min = this.gte;
|
|
1634
|
+
this.max = this.lte;
|
|
1635
|
+
this.step = this.multipleOf;
|
|
1636
|
+
}
|
|
1637
|
+
_parse(input) {
|
|
1638
|
+
if (this._def.coerce) {
|
|
1639
|
+
input.data = Number(input.data);
|
|
1640
|
+
}
|
|
1641
|
+
const parsedType = this._getType(input);
|
|
1642
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1643
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1644
|
+
addIssueToContext(ctx2, {
|
|
1645
|
+
code: ZodIssueCode.invalid_type,
|
|
1646
|
+
expected: ZodParsedType.number,
|
|
1647
|
+
received: ctx2.parsedType
|
|
1648
|
+
});
|
|
1649
|
+
return INVALID;
|
|
1650
|
+
}
|
|
1651
|
+
let ctx = void 0;
|
|
1652
|
+
const status = new ParseStatus();
|
|
1653
|
+
for (const check of this._def.checks) {
|
|
1654
|
+
if (check.kind === "int") {
|
|
1655
|
+
if (!util.isInteger(input.data)) {
|
|
1656
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1657
|
+
addIssueToContext(ctx, {
|
|
1658
|
+
code: ZodIssueCode.invalid_type,
|
|
1659
|
+
expected: "integer",
|
|
1660
|
+
received: "float",
|
|
1661
|
+
message: check.message
|
|
1662
|
+
});
|
|
1663
|
+
status.dirty();
|
|
1664
|
+
}
|
|
1665
|
+
} else if (check.kind === "min") {
|
|
1666
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1667
|
+
if (tooSmall) {
|
|
1668
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1669
|
+
addIssueToContext(ctx, {
|
|
1670
|
+
code: ZodIssueCode.too_small,
|
|
1671
|
+
minimum: check.value,
|
|
1672
|
+
type: "number",
|
|
1673
|
+
inclusive: check.inclusive,
|
|
1674
|
+
exact: false,
|
|
1675
|
+
message: check.message
|
|
1676
|
+
});
|
|
1677
|
+
status.dirty();
|
|
1678
|
+
}
|
|
1679
|
+
} else if (check.kind === "max") {
|
|
1680
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1681
|
+
if (tooBig) {
|
|
1682
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1683
|
+
addIssueToContext(ctx, {
|
|
1684
|
+
code: ZodIssueCode.too_big,
|
|
1685
|
+
maximum: check.value,
|
|
1686
|
+
type: "number",
|
|
1687
|
+
inclusive: check.inclusive,
|
|
1688
|
+
exact: false,
|
|
1689
|
+
message: check.message
|
|
1690
|
+
});
|
|
1691
|
+
status.dirty();
|
|
1692
|
+
}
|
|
1693
|
+
} else if (check.kind === "multipleOf") {
|
|
1694
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1695
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1696
|
+
addIssueToContext(ctx, {
|
|
1697
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1698
|
+
multipleOf: check.value,
|
|
1699
|
+
message: check.message
|
|
1700
|
+
});
|
|
1701
|
+
status.dirty();
|
|
1702
|
+
}
|
|
1703
|
+
} else if (check.kind === "finite") {
|
|
1704
|
+
if (!Number.isFinite(input.data)) {
|
|
1705
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1706
|
+
addIssueToContext(ctx, {
|
|
1707
|
+
code: ZodIssueCode.not_finite,
|
|
1708
|
+
message: check.message
|
|
1709
|
+
});
|
|
1710
|
+
status.dirty();
|
|
1711
|
+
}
|
|
1712
|
+
} else {
|
|
1713
|
+
util.assertNever(check);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
return { status: status.value, value: input.data };
|
|
1717
|
+
}
|
|
1718
|
+
gte(value, message) {
|
|
1719
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1720
|
+
}
|
|
1721
|
+
gt(value, message) {
|
|
1722
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1723
|
+
}
|
|
1724
|
+
lte(value, message) {
|
|
1725
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1726
|
+
}
|
|
1727
|
+
lt(value, message) {
|
|
1728
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1729
|
+
}
|
|
1730
|
+
setLimit(kind, value, inclusive, message) {
|
|
1731
|
+
return new _ZodNumber({
|
|
1732
|
+
...this._def,
|
|
1733
|
+
checks: [
|
|
1734
|
+
...this._def.checks,
|
|
1735
|
+
{
|
|
1736
|
+
kind,
|
|
1737
|
+
value,
|
|
1738
|
+
inclusive,
|
|
1739
|
+
message: errorUtil.toString(message)
|
|
1740
|
+
}
|
|
1741
|
+
]
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
_addCheck(check) {
|
|
1745
|
+
return new _ZodNumber({
|
|
1746
|
+
...this._def,
|
|
1747
|
+
checks: [...this._def.checks, check]
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
int(message) {
|
|
1751
|
+
return this._addCheck({
|
|
1752
|
+
kind: "int",
|
|
1753
|
+
message: errorUtil.toString(message)
|
|
1754
|
+
});
|
|
1755
|
+
}
|
|
1756
|
+
positive(message) {
|
|
1757
|
+
return this._addCheck({
|
|
1758
|
+
kind: "min",
|
|
1759
|
+
value: 0,
|
|
1760
|
+
inclusive: false,
|
|
1761
|
+
message: errorUtil.toString(message)
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
negative(message) {
|
|
1765
|
+
return this._addCheck({
|
|
1766
|
+
kind: "max",
|
|
1767
|
+
value: 0,
|
|
1768
|
+
inclusive: false,
|
|
1769
|
+
message: errorUtil.toString(message)
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
nonpositive(message) {
|
|
1773
|
+
return this._addCheck({
|
|
1774
|
+
kind: "max",
|
|
1775
|
+
value: 0,
|
|
1776
|
+
inclusive: true,
|
|
1777
|
+
message: errorUtil.toString(message)
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
nonnegative(message) {
|
|
1781
|
+
return this._addCheck({
|
|
1782
|
+
kind: "min",
|
|
1783
|
+
value: 0,
|
|
1784
|
+
inclusive: true,
|
|
1785
|
+
message: errorUtil.toString(message)
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
multipleOf(value, message) {
|
|
1789
|
+
return this._addCheck({
|
|
1790
|
+
kind: "multipleOf",
|
|
1791
|
+
value,
|
|
1792
|
+
message: errorUtil.toString(message)
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
finite(message) {
|
|
1796
|
+
return this._addCheck({
|
|
1797
|
+
kind: "finite",
|
|
1798
|
+
message: errorUtil.toString(message)
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
safe(message) {
|
|
1802
|
+
return this._addCheck({
|
|
1803
|
+
kind: "min",
|
|
1804
|
+
inclusive: true,
|
|
1805
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1806
|
+
message: errorUtil.toString(message)
|
|
1807
|
+
})._addCheck({
|
|
1808
|
+
kind: "max",
|
|
1809
|
+
inclusive: true,
|
|
1810
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1811
|
+
message: errorUtil.toString(message)
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
get minValue() {
|
|
1815
|
+
let min = null;
|
|
1816
|
+
for (const ch of this._def.checks) {
|
|
1817
|
+
if (ch.kind === "min") {
|
|
1818
|
+
if (min === null || ch.value > min)
|
|
1819
|
+
min = ch.value;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return min;
|
|
1823
|
+
}
|
|
1824
|
+
get maxValue() {
|
|
1825
|
+
let max = null;
|
|
1826
|
+
for (const ch of this._def.checks) {
|
|
1827
|
+
if (ch.kind === "max") {
|
|
1828
|
+
if (max === null || ch.value < max)
|
|
1829
|
+
max = ch.value;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
return max;
|
|
1833
|
+
}
|
|
1834
|
+
get isInt() {
|
|
1835
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1836
|
+
}
|
|
1837
|
+
get isFinite() {
|
|
1838
|
+
let max = null;
|
|
1839
|
+
let min = null;
|
|
1840
|
+
for (const ch of this._def.checks) {
|
|
1841
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1842
|
+
return true;
|
|
1843
|
+
} else if (ch.kind === "min") {
|
|
1844
|
+
if (min === null || ch.value > min)
|
|
1845
|
+
min = ch.value;
|
|
1846
|
+
} else if (ch.kind === "max") {
|
|
1847
|
+
if (max === null || ch.value < max)
|
|
1848
|
+
max = ch.value;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
ZodNumber.create = (params) => {
|
|
1855
|
+
return new ZodNumber({
|
|
1856
|
+
checks: [],
|
|
1857
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1858
|
+
coerce: params?.coerce || false,
|
|
1859
|
+
...processCreateParams(params)
|
|
1860
|
+
});
|
|
1861
|
+
};
|
|
1862
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1863
|
+
constructor() {
|
|
1864
|
+
super(...arguments);
|
|
1865
|
+
this.min = this.gte;
|
|
1866
|
+
this.max = this.lte;
|
|
1867
|
+
}
|
|
1868
|
+
_parse(input) {
|
|
1869
|
+
if (this._def.coerce) {
|
|
1870
|
+
try {
|
|
1871
|
+
input.data = BigInt(input.data);
|
|
1872
|
+
} catch {
|
|
1873
|
+
return this._getInvalidInput(input);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
const parsedType = this._getType(input);
|
|
1877
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
1878
|
+
return this._getInvalidInput(input);
|
|
1879
|
+
}
|
|
1880
|
+
let ctx = void 0;
|
|
1881
|
+
const status = new ParseStatus();
|
|
1882
|
+
for (const check of this._def.checks) {
|
|
1883
|
+
if (check.kind === "min") {
|
|
1884
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1885
|
+
if (tooSmall) {
|
|
1886
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1887
|
+
addIssueToContext(ctx, {
|
|
1888
|
+
code: ZodIssueCode.too_small,
|
|
1889
|
+
type: "bigint",
|
|
1890
|
+
minimum: check.value,
|
|
1891
|
+
inclusive: check.inclusive,
|
|
1892
|
+
message: check.message
|
|
1893
|
+
});
|
|
1894
|
+
status.dirty();
|
|
1895
|
+
}
|
|
1896
|
+
} else if (check.kind === "max") {
|
|
1897
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1898
|
+
if (tooBig) {
|
|
1899
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1900
|
+
addIssueToContext(ctx, {
|
|
1901
|
+
code: ZodIssueCode.too_big,
|
|
1902
|
+
type: "bigint",
|
|
1903
|
+
maximum: check.value,
|
|
1904
|
+
inclusive: check.inclusive,
|
|
1905
|
+
message: check.message
|
|
1906
|
+
});
|
|
1907
|
+
status.dirty();
|
|
1908
|
+
}
|
|
1909
|
+
} else if (check.kind === "multipleOf") {
|
|
1910
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1911
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1912
|
+
addIssueToContext(ctx, {
|
|
1913
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1914
|
+
multipleOf: check.value,
|
|
1915
|
+
message: check.message
|
|
1916
|
+
});
|
|
1917
|
+
status.dirty();
|
|
1918
|
+
}
|
|
1919
|
+
} else {
|
|
1920
|
+
util.assertNever(check);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return { status: status.value, value: input.data };
|
|
1924
|
+
}
|
|
1925
|
+
_getInvalidInput(input) {
|
|
1926
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1927
|
+
addIssueToContext(ctx, {
|
|
1928
|
+
code: ZodIssueCode.invalid_type,
|
|
1929
|
+
expected: ZodParsedType.bigint,
|
|
1930
|
+
received: ctx.parsedType
|
|
1931
|
+
});
|
|
1932
|
+
return INVALID;
|
|
1933
|
+
}
|
|
1934
|
+
gte(value, message) {
|
|
1935
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1936
|
+
}
|
|
1937
|
+
gt(value, message) {
|
|
1938
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1939
|
+
}
|
|
1940
|
+
lte(value, message) {
|
|
1941
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1942
|
+
}
|
|
1943
|
+
lt(value, message) {
|
|
1944
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1945
|
+
}
|
|
1946
|
+
setLimit(kind, value, inclusive, message) {
|
|
1947
|
+
return new _ZodBigInt({
|
|
1948
|
+
...this._def,
|
|
1949
|
+
checks: [
|
|
1950
|
+
...this._def.checks,
|
|
1951
|
+
{
|
|
1952
|
+
kind,
|
|
1953
|
+
value,
|
|
1954
|
+
inclusive,
|
|
1955
|
+
message: errorUtil.toString(message)
|
|
1956
|
+
}
|
|
1957
|
+
]
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
_addCheck(check) {
|
|
1961
|
+
return new _ZodBigInt({
|
|
1962
|
+
...this._def,
|
|
1963
|
+
checks: [...this._def.checks, check]
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
positive(message) {
|
|
1967
|
+
return this._addCheck({
|
|
1968
|
+
kind: "min",
|
|
1969
|
+
value: BigInt(0),
|
|
1970
|
+
inclusive: false,
|
|
1971
|
+
message: errorUtil.toString(message)
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
negative(message) {
|
|
1975
|
+
return this._addCheck({
|
|
1976
|
+
kind: "max",
|
|
1977
|
+
value: BigInt(0),
|
|
1978
|
+
inclusive: false,
|
|
1979
|
+
message: errorUtil.toString(message)
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
nonpositive(message) {
|
|
1983
|
+
return this._addCheck({
|
|
1984
|
+
kind: "max",
|
|
1985
|
+
value: BigInt(0),
|
|
1986
|
+
inclusive: true,
|
|
1987
|
+
message: errorUtil.toString(message)
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
nonnegative(message) {
|
|
1991
|
+
return this._addCheck({
|
|
1992
|
+
kind: "min",
|
|
1993
|
+
value: BigInt(0),
|
|
1994
|
+
inclusive: true,
|
|
1995
|
+
message: errorUtil.toString(message)
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
multipleOf(value, message) {
|
|
1999
|
+
return this._addCheck({
|
|
2000
|
+
kind: "multipleOf",
|
|
2001
|
+
value,
|
|
2002
|
+
message: errorUtil.toString(message)
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
get minValue() {
|
|
2006
|
+
let min = null;
|
|
2007
|
+
for (const ch of this._def.checks) {
|
|
2008
|
+
if (ch.kind === "min") {
|
|
2009
|
+
if (min === null || ch.value > min)
|
|
2010
|
+
min = ch.value;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return min;
|
|
2014
|
+
}
|
|
2015
|
+
get maxValue() {
|
|
2016
|
+
let max = null;
|
|
2017
|
+
for (const ch of this._def.checks) {
|
|
2018
|
+
if (ch.kind === "max") {
|
|
2019
|
+
if (max === null || ch.value < max)
|
|
2020
|
+
max = ch.value;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
return max;
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
ZodBigInt.create = (params) => {
|
|
2027
|
+
return new ZodBigInt({
|
|
2028
|
+
checks: [],
|
|
2029
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2030
|
+
coerce: params?.coerce ?? false,
|
|
2031
|
+
...processCreateParams(params)
|
|
2032
|
+
});
|
|
2033
|
+
};
|
|
2034
|
+
var ZodBoolean = class extends ZodType {
|
|
2035
|
+
_parse(input) {
|
|
2036
|
+
if (this._def.coerce) {
|
|
2037
|
+
input.data = Boolean(input.data);
|
|
2038
|
+
}
|
|
2039
|
+
const parsedType = this._getType(input);
|
|
2040
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2041
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2042
|
+
addIssueToContext(ctx, {
|
|
2043
|
+
code: ZodIssueCode.invalid_type,
|
|
2044
|
+
expected: ZodParsedType.boolean,
|
|
2045
|
+
received: ctx.parsedType
|
|
2046
|
+
});
|
|
2047
|
+
return INVALID;
|
|
2048
|
+
}
|
|
2049
|
+
return OK(input.data);
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
ZodBoolean.create = (params) => {
|
|
2053
|
+
return new ZodBoolean({
|
|
2054
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2055
|
+
coerce: params?.coerce || false,
|
|
2056
|
+
...processCreateParams(params)
|
|
2057
|
+
});
|
|
2058
|
+
};
|
|
2059
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
2060
|
+
_parse(input) {
|
|
2061
|
+
if (this._def.coerce) {
|
|
2062
|
+
input.data = new Date(input.data);
|
|
2063
|
+
}
|
|
2064
|
+
const parsedType = this._getType(input);
|
|
2065
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2066
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2067
|
+
addIssueToContext(ctx2, {
|
|
2068
|
+
code: ZodIssueCode.invalid_type,
|
|
2069
|
+
expected: ZodParsedType.date,
|
|
2070
|
+
received: ctx2.parsedType
|
|
2071
|
+
});
|
|
2072
|
+
return INVALID;
|
|
2073
|
+
}
|
|
2074
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2075
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2076
|
+
addIssueToContext(ctx2, {
|
|
2077
|
+
code: ZodIssueCode.invalid_date
|
|
2078
|
+
});
|
|
2079
|
+
return INVALID;
|
|
2080
|
+
}
|
|
2081
|
+
const status = new ParseStatus();
|
|
2082
|
+
let ctx = void 0;
|
|
2083
|
+
for (const check of this._def.checks) {
|
|
2084
|
+
if (check.kind === "min") {
|
|
2085
|
+
if (input.data.getTime() < check.value) {
|
|
2086
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2087
|
+
addIssueToContext(ctx, {
|
|
2088
|
+
code: ZodIssueCode.too_small,
|
|
2089
|
+
message: check.message,
|
|
2090
|
+
inclusive: true,
|
|
2091
|
+
exact: false,
|
|
2092
|
+
minimum: check.value,
|
|
2093
|
+
type: "date"
|
|
2094
|
+
});
|
|
2095
|
+
status.dirty();
|
|
2096
|
+
}
|
|
2097
|
+
} else if (check.kind === "max") {
|
|
2098
|
+
if (input.data.getTime() > check.value) {
|
|
2099
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2100
|
+
addIssueToContext(ctx, {
|
|
2101
|
+
code: ZodIssueCode.too_big,
|
|
2102
|
+
message: check.message,
|
|
2103
|
+
inclusive: true,
|
|
2104
|
+
exact: false,
|
|
2105
|
+
maximum: check.value,
|
|
2106
|
+
type: "date"
|
|
2107
|
+
});
|
|
2108
|
+
status.dirty();
|
|
2109
|
+
}
|
|
2110
|
+
} else {
|
|
2111
|
+
util.assertNever(check);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
return {
|
|
2115
|
+
status: status.value,
|
|
2116
|
+
value: new Date(input.data.getTime())
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
_addCheck(check) {
|
|
2120
|
+
return new _ZodDate({
|
|
2121
|
+
...this._def,
|
|
2122
|
+
checks: [...this._def.checks, check]
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
min(minDate, message) {
|
|
2126
|
+
return this._addCheck({
|
|
2127
|
+
kind: "min",
|
|
2128
|
+
value: minDate.getTime(),
|
|
2129
|
+
message: errorUtil.toString(message)
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
max(maxDate, message) {
|
|
2133
|
+
return this._addCheck({
|
|
2134
|
+
kind: "max",
|
|
2135
|
+
value: maxDate.getTime(),
|
|
2136
|
+
message: errorUtil.toString(message)
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
get minDate() {
|
|
2140
|
+
let min = null;
|
|
2141
|
+
for (const ch of this._def.checks) {
|
|
2142
|
+
if (ch.kind === "min") {
|
|
2143
|
+
if (min === null || ch.value > min)
|
|
2144
|
+
min = ch.value;
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
return min != null ? new Date(min) : null;
|
|
2148
|
+
}
|
|
2149
|
+
get maxDate() {
|
|
2150
|
+
let max = null;
|
|
2151
|
+
for (const ch of this._def.checks) {
|
|
2152
|
+
if (ch.kind === "max") {
|
|
2153
|
+
if (max === null || ch.value < max)
|
|
2154
|
+
max = ch.value;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
return max != null ? new Date(max) : null;
|
|
2158
|
+
}
|
|
2159
|
+
};
|
|
2160
|
+
ZodDate.create = (params) => {
|
|
2161
|
+
return new ZodDate({
|
|
2162
|
+
checks: [],
|
|
2163
|
+
coerce: params?.coerce || false,
|
|
2164
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2165
|
+
...processCreateParams(params)
|
|
2166
|
+
});
|
|
2167
|
+
};
|
|
2168
|
+
var ZodSymbol = class extends ZodType {
|
|
2169
|
+
_parse(input) {
|
|
2170
|
+
const parsedType = this._getType(input);
|
|
2171
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2172
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2173
|
+
addIssueToContext(ctx, {
|
|
2174
|
+
code: ZodIssueCode.invalid_type,
|
|
2175
|
+
expected: ZodParsedType.symbol,
|
|
2176
|
+
received: ctx.parsedType
|
|
2177
|
+
});
|
|
2178
|
+
return INVALID;
|
|
2179
|
+
}
|
|
2180
|
+
return OK(input.data);
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
ZodSymbol.create = (params) => {
|
|
2184
|
+
return new ZodSymbol({
|
|
2185
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2186
|
+
...processCreateParams(params)
|
|
2187
|
+
});
|
|
2188
|
+
};
|
|
2189
|
+
var ZodUndefined = class extends ZodType {
|
|
2190
|
+
_parse(input) {
|
|
2191
|
+
const parsedType = this._getType(input);
|
|
2192
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2193
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2194
|
+
addIssueToContext(ctx, {
|
|
2195
|
+
code: ZodIssueCode.invalid_type,
|
|
2196
|
+
expected: ZodParsedType.undefined,
|
|
2197
|
+
received: ctx.parsedType
|
|
2198
|
+
});
|
|
2199
|
+
return INVALID;
|
|
2200
|
+
}
|
|
2201
|
+
return OK(input.data);
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
ZodUndefined.create = (params) => {
|
|
2205
|
+
return new ZodUndefined({
|
|
2206
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2207
|
+
...processCreateParams(params)
|
|
2208
|
+
});
|
|
2209
|
+
};
|
|
2210
|
+
var ZodNull = class extends ZodType {
|
|
2211
|
+
_parse(input) {
|
|
2212
|
+
const parsedType = this._getType(input);
|
|
2213
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2214
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2215
|
+
addIssueToContext(ctx, {
|
|
2216
|
+
code: ZodIssueCode.invalid_type,
|
|
2217
|
+
expected: ZodParsedType.null,
|
|
2218
|
+
received: ctx.parsedType
|
|
2219
|
+
});
|
|
2220
|
+
return INVALID;
|
|
2221
|
+
}
|
|
2222
|
+
return OK(input.data);
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
ZodNull.create = (params) => {
|
|
2226
|
+
return new ZodNull({
|
|
2227
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2228
|
+
...processCreateParams(params)
|
|
2229
|
+
});
|
|
2230
|
+
};
|
|
2231
|
+
var ZodAny = class extends ZodType {
|
|
2232
|
+
constructor() {
|
|
2233
|
+
super(...arguments);
|
|
2234
|
+
this._any = true;
|
|
2235
|
+
}
|
|
2236
|
+
_parse(input) {
|
|
2237
|
+
return OK(input.data);
|
|
2238
|
+
}
|
|
2239
|
+
};
|
|
2240
|
+
ZodAny.create = (params) => {
|
|
2241
|
+
return new ZodAny({
|
|
2242
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2243
|
+
...processCreateParams(params)
|
|
2244
|
+
});
|
|
2245
|
+
};
|
|
2246
|
+
var ZodUnknown = class extends ZodType {
|
|
2247
|
+
constructor() {
|
|
2248
|
+
super(...arguments);
|
|
2249
|
+
this._unknown = true;
|
|
2250
|
+
}
|
|
2251
|
+
_parse(input) {
|
|
2252
|
+
return OK(input.data);
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
ZodUnknown.create = (params) => {
|
|
2256
|
+
return new ZodUnknown({
|
|
2257
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2258
|
+
...processCreateParams(params)
|
|
2259
|
+
});
|
|
2260
|
+
};
|
|
2261
|
+
var ZodNever = class extends ZodType {
|
|
2262
|
+
_parse(input) {
|
|
2263
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2264
|
+
addIssueToContext(ctx, {
|
|
2265
|
+
code: ZodIssueCode.invalid_type,
|
|
2266
|
+
expected: ZodParsedType.never,
|
|
2267
|
+
received: ctx.parsedType
|
|
2268
|
+
});
|
|
2269
|
+
return INVALID;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
ZodNever.create = (params) => {
|
|
2273
|
+
return new ZodNever({
|
|
2274
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2275
|
+
...processCreateParams(params)
|
|
2276
|
+
});
|
|
2277
|
+
};
|
|
2278
|
+
var ZodVoid = class extends ZodType {
|
|
2279
|
+
_parse(input) {
|
|
2280
|
+
const parsedType = this._getType(input);
|
|
2281
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2282
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2283
|
+
addIssueToContext(ctx, {
|
|
2284
|
+
code: ZodIssueCode.invalid_type,
|
|
2285
|
+
expected: ZodParsedType.void,
|
|
2286
|
+
received: ctx.parsedType
|
|
2287
|
+
});
|
|
2288
|
+
return INVALID;
|
|
2289
|
+
}
|
|
2290
|
+
return OK(input.data);
|
|
2291
|
+
}
|
|
2292
|
+
};
|
|
2293
|
+
ZodVoid.create = (params) => {
|
|
2294
|
+
return new ZodVoid({
|
|
2295
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2296
|
+
...processCreateParams(params)
|
|
2297
|
+
});
|
|
2298
|
+
};
|
|
2299
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
2300
|
+
_parse(input) {
|
|
2301
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2302
|
+
const def = this._def;
|
|
2303
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2304
|
+
addIssueToContext(ctx, {
|
|
2305
|
+
code: ZodIssueCode.invalid_type,
|
|
2306
|
+
expected: ZodParsedType.array,
|
|
2307
|
+
received: ctx.parsedType
|
|
2308
|
+
});
|
|
2309
|
+
return INVALID;
|
|
2310
|
+
}
|
|
2311
|
+
if (def.exactLength !== null) {
|
|
2312
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2313
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2314
|
+
if (tooBig || tooSmall) {
|
|
2315
|
+
addIssueToContext(ctx, {
|
|
2316
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2317
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2318
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2319
|
+
type: "array",
|
|
2320
|
+
inclusive: true,
|
|
2321
|
+
exact: true,
|
|
2322
|
+
message: def.exactLength.message
|
|
2323
|
+
});
|
|
2324
|
+
status.dirty();
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
if (def.minLength !== null) {
|
|
2328
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2329
|
+
addIssueToContext(ctx, {
|
|
2330
|
+
code: ZodIssueCode.too_small,
|
|
2331
|
+
minimum: def.minLength.value,
|
|
2332
|
+
type: "array",
|
|
2333
|
+
inclusive: true,
|
|
2334
|
+
exact: false,
|
|
2335
|
+
message: def.minLength.message
|
|
2336
|
+
});
|
|
2337
|
+
status.dirty();
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
if (def.maxLength !== null) {
|
|
2341
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2342
|
+
addIssueToContext(ctx, {
|
|
2343
|
+
code: ZodIssueCode.too_big,
|
|
2344
|
+
maximum: def.maxLength.value,
|
|
2345
|
+
type: "array",
|
|
2346
|
+
inclusive: true,
|
|
2347
|
+
exact: false,
|
|
2348
|
+
message: def.maxLength.message
|
|
2349
|
+
});
|
|
2350
|
+
status.dirty();
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
if (ctx.common.async) {
|
|
2354
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
2355
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2356
|
+
})).then((result2) => {
|
|
2357
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
2360
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2361
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2362
|
+
});
|
|
2363
|
+
return ParseStatus.mergeArray(status, result);
|
|
2364
|
+
}
|
|
2365
|
+
get element() {
|
|
2366
|
+
return this._def.type;
|
|
2367
|
+
}
|
|
2368
|
+
min(minLength, message) {
|
|
2369
|
+
return new _ZodArray({
|
|
2370
|
+
...this._def,
|
|
2371
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
max(maxLength, message) {
|
|
2375
|
+
return new _ZodArray({
|
|
2376
|
+
...this._def,
|
|
2377
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2378
|
+
});
|
|
2379
|
+
}
|
|
2380
|
+
length(len, message) {
|
|
2381
|
+
return new _ZodArray({
|
|
2382
|
+
...this._def,
|
|
2383
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
nonempty(message) {
|
|
2387
|
+
return this.min(1, message);
|
|
2388
|
+
}
|
|
2389
|
+
};
|
|
2390
|
+
ZodArray.create = (schema, params) => {
|
|
2391
|
+
return new ZodArray({
|
|
2392
|
+
type: schema,
|
|
2393
|
+
minLength: null,
|
|
2394
|
+
maxLength: null,
|
|
2395
|
+
exactLength: null,
|
|
2396
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2397
|
+
...processCreateParams(params)
|
|
2398
|
+
});
|
|
2399
|
+
};
|
|
2400
|
+
function deepPartialify(schema) {
|
|
2401
|
+
if (schema instanceof ZodObject) {
|
|
2402
|
+
const newShape = {};
|
|
2403
|
+
for (const key in schema.shape) {
|
|
2404
|
+
const fieldSchema = schema.shape[key];
|
|
2405
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2406
|
+
}
|
|
2407
|
+
return new ZodObject({
|
|
2408
|
+
...schema._def,
|
|
2409
|
+
shape: () => newShape
|
|
2410
|
+
});
|
|
2411
|
+
} else if (schema instanceof ZodArray) {
|
|
2412
|
+
return new ZodArray({
|
|
2413
|
+
...schema._def,
|
|
2414
|
+
type: deepPartialify(schema.element)
|
|
2415
|
+
});
|
|
2416
|
+
} else if (schema instanceof ZodOptional) {
|
|
2417
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2418
|
+
} else if (schema instanceof ZodNullable) {
|
|
2419
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2420
|
+
} else if (schema instanceof ZodTuple) {
|
|
2421
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2422
|
+
} else {
|
|
2423
|
+
return schema;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
2427
|
+
constructor() {
|
|
2428
|
+
super(...arguments);
|
|
2429
|
+
this._cached = null;
|
|
2430
|
+
this.nonstrict = this.passthrough;
|
|
2431
|
+
this.augment = this.extend;
|
|
2432
|
+
}
|
|
2433
|
+
_getCached() {
|
|
2434
|
+
if (this._cached !== null)
|
|
2435
|
+
return this._cached;
|
|
2436
|
+
const shape = this._def.shape();
|
|
2437
|
+
const keys = util.objectKeys(shape);
|
|
2438
|
+
this._cached = { shape, keys };
|
|
2439
|
+
return this._cached;
|
|
2440
|
+
}
|
|
2441
|
+
_parse(input) {
|
|
2442
|
+
const parsedType = this._getType(input);
|
|
2443
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2444
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2445
|
+
addIssueToContext(ctx2, {
|
|
2446
|
+
code: ZodIssueCode.invalid_type,
|
|
2447
|
+
expected: ZodParsedType.object,
|
|
2448
|
+
received: ctx2.parsedType
|
|
2449
|
+
});
|
|
2450
|
+
return INVALID;
|
|
2451
|
+
}
|
|
2452
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2453
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2454
|
+
const extraKeys = [];
|
|
2455
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2456
|
+
for (const key in ctx.data) {
|
|
2457
|
+
if (!shapeKeys.includes(key)) {
|
|
2458
|
+
extraKeys.push(key);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
const pairs = [];
|
|
2463
|
+
for (const key of shapeKeys) {
|
|
2464
|
+
const keyValidator = shape[key];
|
|
2465
|
+
const value = ctx.data[key];
|
|
2466
|
+
pairs.push({
|
|
2467
|
+
key: { status: "valid", value: key },
|
|
2468
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2469
|
+
alwaysSet: key in ctx.data
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2473
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2474
|
+
if (unknownKeys === "passthrough") {
|
|
2475
|
+
for (const key of extraKeys) {
|
|
2476
|
+
pairs.push({
|
|
2477
|
+
key: { status: "valid", value: key },
|
|
2478
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
} else if (unknownKeys === "strict") {
|
|
2482
|
+
if (extraKeys.length > 0) {
|
|
2483
|
+
addIssueToContext(ctx, {
|
|
2484
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2485
|
+
keys: extraKeys
|
|
2486
|
+
});
|
|
2487
|
+
status.dirty();
|
|
2488
|
+
}
|
|
2489
|
+
} else if (unknownKeys === "strip") {
|
|
2490
|
+
} else {
|
|
2491
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2492
|
+
}
|
|
2493
|
+
} else {
|
|
2494
|
+
const catchall = this._def.catchall;
|
|
2495
|
+
for (const key of extraKeys) {
|
|
2496
|
+
const value = ctx.data[key];
|
|
2497
|
+
pairs.push({
|
|
2498
|
+
key: { status: "valid", value: key },
|
|
2499
|
+
value: catchall._parse(
|
|
2500
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2501
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2502
|
+
),
|
|
2503
|
+
alwaysSet: key in ctx.data
|
|
2504
|
+
});
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
if (ctx.common.async) {
|
|
2508
|
+
return Promise.resolve().then(async () => {
|
|
2509
|
+
const syncPairs = [];
|
|
2510
|
+
for (const pair of pairs) {
|
|
2511
|
+
const key = await pair.key;
|
|
2512
|
+
const value = await pair.value;
|
|
2513
|
+
syncPairs.push({
|
|
2514
|
+
key,
|
|
2515
|
+
value,
|
|
2516
|
+
alwaysSet: pair.alwaysSet
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
return syncPairs;
|
|
2520
|
+
}).then((syncPairs) => {
|
|
2521
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2522
|
+
});
|
|
2523
|
+
} else {
|
|
2524
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
get shape() {
|
|
2528
|
+
return this._def.shape();
|
|
2529
|
+
}
|
|
2530
|
+
strict(message) {
|
|
2531
|
+
errorUtil.errToObj;
|
|
2532
|
+
return new _ZodObject({
|
|
2533
|
+
...this._def,
|
|
2534
|
+
unknownKeys: "strict",
|
|
2535
|
+
...message !== void 0 ? {
|
|
2536
|
+
errorMap: (issue, ctx) => {
|
|
2537
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2538
|
+
if (issue.code === "unrecognized_keys")
|
|
2539
|
+
return {
|
|
2540
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2541
|
+
};
|
|
2542
|
+
return {
|
|
2543
|
+
message: defaultError
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
} : {}
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
strip() {
|
|
2550
|
+
return new _ZodObject({
|
|
2551
|
+
...this._def,
|
|
2552
|
+
unknownKeys: "strip"
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
passthrough() {
|
|
2556
|
+
return new _ZodObject({
|
|
2557
|
+
...this._def,
|
|
2558
|
+
unknownKeys: "passthrough"
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
// const AugmentFactory =
|
|
2562
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2563
|
+
// <Augmentation extends ZodRawShape>(
|
|
2564
|
+
// augmentation: Augmentation
|
|
2565
|
+
// ): ZodObject<
|
|
2566
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2567
|
+
// Def["unknownKeys"],
|
|
2568
|
+
// Def["catchall"]
|
|
2569
|
+
// > => {
|
|
2570
|
+
// return new ZodObject({
|
|
2571
|
+
// ...def,
|
|
2572
|
+
// shape: () => ({
|
|
2573
|
+
// ...def.shape(),
|
|
2574
|
+
// ...augmentation,
|
|
2575
|
+
// }),
|
|
2576
|
+
// }) as any;
|
|
2577
|
+
// };
|
|
2578
|
+
extend(augmentation) {
|
|
2579
|
+
return new _ZodObject({
|
|
2580
|
+
...this._def,
|
|
2581
|
+
shape: () => ({
|
|
2582
|
+
...this._def.shape(),
|
|
2583
|
+
...augmentation
|
|
2584
|
+
})
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2588
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2589
|
+
* inferred type of merged objects. Please
|
|
2590
|
+
* upgrade if you are experiencing issues.
|
|
2591
|
+
*/
|
|
2592
|
+
merge(merging) {
|
|
2593
|
+
const merged = new _ZodObject({
|
|
2594
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2595
|
+
catchall: merging._def.catchall,
|
|
2596
|
+
shape: () => ({
|
|
2597
|
+
...this._def.shape(),
|
|
2598
|
+
...merging._def.shape()
|
|
2599
|
+
}),
|
|
2600
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2601
|
+
});
|
|
2602
|
+
return merged;
|
|
2603
|
+
}
|
|
2604
|
+
// merge<
|
|
2605
|
+
// Incoming extends AnyZodObject,
|
|
2606
|
+
// Augmentation extends Incoming["shape"],
|
|
2607
|
+
// NewOutput extends {
|
|
2608
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2609
|
+
// ? Augmentation[k]["_output"]
|
|
2610
|
+
// : k extends keyof Output
|
|
2611
|
+
// ? Output[k]
|
|
2612
|
+
// : never;
|
|
2613
|
+
// },
|
|
2614
|
+
// NewInput extends {
|
|
2615
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2616
|
+
// ? Augmentation[k]["_input"]
|
|
2617
|
+
// : k extends keyof Input
|
|
2618
|
+
// ? Input[k]
|
|
2619
|
+
// : never;
|
|
2620
|
+
// }
|
|
2621
|
+
// >(
|
|
2622
|
+
// merging: Incoming
|
|
2623
|
+
// ): ZodObject<
|
|
2624
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2625
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2626
|
+
// Incoming["_def"]["catchall"],
|
|
2627
|
+
// NewOutput,
|
|
2628
|
+
// NewInput
|
|
2629
|
+
// > {
|
|
2630
|
+
// const merged: any = new ZodObject({
|
|
2631
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2632
|
+
// catchall: merging._def.catchall,
|
|
2633
|
+
// shape: () =>
|
|
2634
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2635
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2636
|
+
// }) as any;
|
|
2637
|
+
// return merged;
|
|
2638
|
+
// }
|
|
2639
|
+
setKey(key, schema) {
|
|
2640
|
+
return this.augment({ [key]: schema });
|
|
2641
|
+
}
|
|
2642
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2643
|
+
// merging: Incoming
|
|
2644
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2645
|
+
// ZodObject<
|
|
2646
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2647
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2648
|
+
// Incoming["_def"]["catchall"]
|
|
2649
|
+
// > {
|
|
2650
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2651
|
+
// // this._def.shape(),
|
|
2652
|
+
// // merging._def.shape()
|
|
2653
|
+
// // );
|
|
2654
|
+
// const merged: any = new ZodObject({
|
|
2655
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2656
|
+
// catchall: merging._def.catchall,
|
|
2657
|
+
// shape: () =>
|
|
2658
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2659
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2660
|
+
// }) as any;
|
|
2661
|
+
// return merged;
|
|
2662
|
+
// }
|
|
2663
|
+
catchall(index) {
|
|
2664
|
+
return new _ZodObject({
|
|
2665
|
+
...this._def,
|
|
2666
|
+
catchall: index
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
pick(mask) {
|
|
2670
|
+
const shape = {};
|
|
2671
|
+
for (const key of util.objectKeys(mask)) {
|
|
2672
|
+
if (mask[key] && this.shape[key]) {
|
|
2673
|
+
shape[key] = this.shape[key];
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
return new _ZodObject({
|
|
2677
|
+
...this._def,
|
|
2678
|
+
shape: () => shape
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
omit(mask) {
|
|
2682
|
+
const shape = {};
|
|
2683
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2684
|
+
if (!mask[key]) {
|
|
2685
|
+
shape[key] = this.shape[key];
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
return new _ZodObject({
|
|
2689
|
+
...this._def,
|
|
2690
|
+
shape: () => shape
|
|
2691
|
+
});
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* @deprecated
|
|
2695
|
+
*/
|
|
2696
|
+
deepPartial() {
|
|
2697
|
+
return deepPartialify(this);
|
|
2698
|
+
}
|
|
2699
|
+
partial(mask) {
|
|
2700
|
+
const newShape = {};
|
|
2701
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2702
|
+
const fieldSchema = this.shape[key];
|
|
2703
|
+
if (mask && !mask[key]) {
|
|
2704
|
+
newShape[key] = fieldSchema;
|
|
2705
|
+
} else {
|
|
2706
|
+
newShape[key] = fieldSchema.optional();
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
return new _ZodObject({
|
|
2710
|
+
...this._def,
|
|
2711
|
+
shape: () => newShape
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
required(mask) {
|
|
2715
|
+
const newShape = {};
|
|
2716
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2717
|
+
if (mask && !mask[key]) {
|
|
2718
|
+
newShape[key] = this.shape[key];
|
|
2719
|
+
} else {
|
|
2720
|
+
const fieldSchema = this.shape[key];
|
|
2721
|
+
let newField = fieldSchema;
|
|
2722
|
+
while (newField instanceof ZodOptional) {
|
|
2723
|
+
newField = newField._def.innerType;
|
|
2724
|
+
}
|
|
2725
|
+
newShape[key] = newField;
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
return new _ZodObject({
|
|
2729
|
+
...this._def,
|
|
2730
|
+
shape: () => newShape
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
keyof() {
|
|
2734
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2735
|
+
}
|
|
2736
|
+
};
|
|
2737
|
+
ZodObject.create = (shape, params) => {
|
|
2738
|
+
return new ZodObject({
|
|
2739
|
+
shape: () => shape,
|
|
2740
|
+
unknownKeys: "strip",
|
|
2741
|
+
catchall: ZodNever.create(),
|
|
2742
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2743
|
+
...processCreateParams(params)
|
|
2744
|
+
});
|
|
2745
|
+
};
|
|
2746
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2747
|
+
return new ZodObject({
|
|
2748
|
+
shape: () => shape,
|
|
2749
|
+
unknownKeys: "strict",
|
|
2750
|
+
catchall: ZodNever.create(),
|
|
2751
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2752
|
+
...processCreateParams(params)
|
|
2753
|
+
});
|
|
2754
|
+
};
|
|
2755
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2756
|
+
return new ZodObject({
|
|
2757
|
+
shape,
|
|
2758
|
+
unknownKeys: "strip",
|
|
2759
|
+
catchall: ZodNever.create(),
|
|
2760
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2761
|
+
...processCreateParams(params)
|
|
2762
|
+
});
|
|
2763
|
+
};
|
|
2764
|
+
var ZodUnion = class extends ZodType {
|
|
2765
|
+
_parse(input) {
|
|
2766
|
+
const { ctx } = this._processInputParams(input);
|
|
2767
|
+
const options = this._def.options;
|
|
2768
|
+
function handleResults(results) {
|
|
2769
|
+
for (const result of results) {
|
|
2770
|
+
if (result.result.status === "valid") {
|
|
2771
|
+
return result.result;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
for (const result of results) {
|
|
2775
|
+
if (result.result.status === "dirty") {
|
|
2776
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2777
|
+
return result.result;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2781
|
+
addIssueToContext(ctx, {
|
|
2782
|
+
code: ZodIssueCode.invalid_union,
|
|
2783
|
+
unionErrors
|
|
2784
|
+
});
|
|
2785
|
+
return INVALID;
|
|
2786
|
+
}
|
|
2787
|
+
if (ctx.common.async) {
|
|
2788
|
+
return Promise.all(options.map(async (option) => {
|
|
2789
|
+
const childCtx = {
|
|
2790
|
+
...ctx,
|
|
2791
|
+
common: {
|
|
2792
|
+
...ctx.common,
|
|
2793
|
+
issues: []
|
|
2794
|
+
},
|
|
2795
|
+
parent: null
|
|
2796
|
+
};
|
|
2797
|
+
return {
|
|
2798
|
+
result: await option._parseAsync({
|
|
2799
|
+
data: ctx.data,
|
|
2800
|
+
path: ctx.path,
|
|
2801
|
+
parent: childCtx
|
|
2802
|
+
}),
|
|
2803
|
+
ctx: childCtx
|
|
2804
|
+
};
|
|
2805
|
+
})).then(handleResults);
|
|
2806
|
+
} else {
|
|
2807
|
+
let dirty = void 0;
|
|
2808
|
+
const issues = [];
|
|
2809
|
+
for (const option of options) {
|
|
2810
|
+
const childCtx = {
|
|
2811
|
+
...ctx,
|
|
2812
|
+
common: {
|
|
2813
|
+
...ctx.common,
|
|
2814
|
+
issues: []
|
|
2815
|
+
},
|
|
2816
|
+
parent: null
|
|
2817
|
+
};
|
|
2818
|
+
const result = option._parseSync({
|
|
2819
|
+
data: ctx.data,
|
|
2820
|
+
path: ctx.path,
|
|
2821
|
+
parent: childCtx
|
|
2822
|
+
});
|
|
2823
|
+
if (result.status === "valid") {
|
|
2824
|
+
return result;
|
|
2825
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
2826
|
+
dirty = { result, ctx: childCtx };
|
|
2827
|
+
}
|
|
2828
|
+
if (childCtx.common.issues.length) {
|
|
2829
|
+
issues.push(childCtx.common.issues);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
if (dirty) {
|
|
2833
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2834
|
+
return dirty.result;
|
|
2835
|
+
}
|
|
2836
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
2837
|
+
addIssueToContext(ctx, {
|
|
2838
|
+
code: ZodIssueCode.invalid_union,
|
|
2839
|
+
unionErrors
|
|
2840
|
+
});
|
|
2841
|
+
return INVALID;
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
get options() {
|
|
2845
|
+
return this._def.options;
|
|
2846
|
+
}
|
|
2847
|
+
};
|
|
2848
|
+
ZodUnion.create = (types, params) => {
|
|
2849
|
+
return new ZodUnion({
|
|
2850
|
+
options: types,
|
|
2851
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2852
|
+
...processCreateParams(params)
|
|
2853
|
+
});
|
|
2854
|
+
};
|
|
2855
|
+
var getDiscriminator = (type) => {
|
|
2856
|
+
if (type instanceof ZodLazy) {
|
|
2857
|
+
return getDiscriminator(type.schema);
|
|
2858
|
+
} else if (type instanceof ZodEffects) {
|
|
2859
|
+
return getDiscriminator(type.innerType());
|
|
2860
|
+
} else if (type instanceof ZodLiteral) {
|
|
2861
|
+
return [type.value];
|
|
2862
|
+
} else if (type instanceof ZodEnum) {
|
|
2863
|
+
return type.options;
|
|
2864
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
2865
|
+
return util.objectValues(type.enum);
|
|
2866
|
+
} else if (type instanceof ZodDefault) {
|
|
2867
|
+
return getDiscriminator(type._def.innerType);
|
|
2868
|
+
} else if (type instanceof ZodUndefined) {
|
|
2869
|
+
return [void 0];
|
|
2870
|
+
} else if (type instanceof ZodNull) {
|
|
2871
|
+
return [null];
|
|
2872
|
+
} else if (type instanceof ZodOptional) {
|
|
2873
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2874
|
+
} else if (type instanceof ZodNullable) {
|
|
2875
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
2876
|
+
} else if (type instanceof ZodBranded) {
|
|
2877
|
+
return getDiscriminator(type.unwrap());
|
|
2878
|
+
} else if (type instanceof ZodReadonly) {
|
|
2879
|
+
return getDiscriminator(type.unwrap());
|
|
2880
|
+
} else if (type instanceof ZodCatch) {
|
|
2881
|
+
return getDiscriminator(type._def.innerType);
|
|
2882
|
+
} else {
|
|
2883
|
+
return [];
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2887
|
+
_parse(input) {
|
|
2888
|
+
const { ctx } = this._processInputParams(input);
|
|
2889
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2890
|
+
addIssueToContext(ctx, {
|
|
2891
|
+
code: ZodIssueCode.invalid_type,
|
|
2892
|
+
expected: ZodParsedType.object,
|
|
2893
|
+
received: ctx.parsedType
|
|
2894
|
+
});
|
|
2895
|
+
return INVALID;
|
|
2896
|
+
}
|
|
2897
|
+
const discriminator = this.discriminator;
|
|
2898
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
2899
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
2900
|
+
if (!option) {
|
|
2901
|
+
addIssueToContext(ctx, {
|
|
2902
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
2903
|
+
options: Array.from(this.optionsMap.keys()),
|
|
2904
|
+
path: [discriminator]
|
|
2905
|
+
});
|
|
2906
|
+
return INVALID;
|
|
2907
|
+
}
|
|
2908
|
+
if (ctx.common.async) {
|
|
2909
|
+
return option._parseAsync({
|
|
2910
|
+
data: ctx.data,
|
|
2911
|
+
path: ctx.path,
|
|
2912
|
+
parent: ctx
|
|
2913
|
+
});
|
|
2914
|
+
} else {
|
|
2915
|
+
return option._parseSync({
|
|
2916
|
+
data: ctx.data,
|
|
2917
|
+
path: ctx.path,
|
|
2918
|
+
parent: ctx
|
|
2919
|
+
});
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
get discriminator() {
|
|
2923
|
+
return this._def.discriminator;
|
|
2924
|
+
}
|
|
2925
|
+
get options() {
|
|
2926
|
+
return this._def.options;
|
|
2927
|
+
}
|
|
2928
|
+
get optionsMap() {
|
|
2929
|
+
return this._def.optionsMap;
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2933
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2934
|
+
* have a different value for each object in the union.
|
|
2935
|
+
* @param discriminator the name of the discriminator property
|
|
2936
|
+
* @param types an array of object schemas
|
|
2937
|
+
* @param params
|
|
2938
|
+
*/
|
|
2939
|
+
static create(discriminator, options, params) {
|
|
2940
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
2941
|
+
for (const type of options) {
|
|
2942
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2943
|
+
if (!discriminatorValues.length) {
|
|
2944
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2945
|
+
}
|
|
2946
|
+
for (const value of discriminatorValues) {
|
|
2947
|
+
if (optionsMap.has(value)) {
|
|
2948
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2949
|
+
}
|
|
2950
|
+
optionsMap.set(value, type);
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
return new _ZodDiscriminatedUnion({
|
|
2954
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2955
|
+
discriminator,
|
|
2956
|
+
options,
|
|
2957
|
+
optionsMap,
|
|
2958
|
+
...processCreateParams(params)
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
};
|
|
2962
|
+
function mergeValues(a, b) {
|
|
2963
|
+
const aType = getParsedType(a);
|
|
2964
|
+
const bType = getParsedType(b);
|
|
2965
|
+
if (a === b) {
|
|
2966
|
+
return { valid: true, data: a };
|
|
2967
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2968
|
+
const bKeys = util.objectKeys(b);
|
|
2969
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2970
|
+
const newObj = { ...a, ...b };
|
|
2971
|
+
for (const key of sharedKeys) {
|
|
2972
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
2973
|
+
if (!sharedValue.valid) {
|
|
2974
|
+
return { valid: false };
|
|
2975
|
+
}
|
|
2976
|
+
newObj[key] = sharedValue.data;
|
|
2977
|
+
}
|
|
2978
|
+
return { valid: true, data: newObj };
|
|
2979
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2980
|
+
if (a.length !== b.length) {
|
|
2981
|
+
return { valid: false };
|
|
2982
|
+
}
|
|
2983
|
+
const newArray = [];
|
|
2984
|
+
for (let index = 0; index < a.length; index++) {
|
|
2985
|
+
const itemA = a[index];
|
|
2986
|
+
const itemB = b[index];
|
|
2987
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2988
|
+
if (!sharedValue.valid) {
|
|
2989
|
+
return { valid: false };
|
|
2990
|
+
}
|
|
2991
|
+
newArray.push(sharedValue.data);
|
|
2992
|
+
}
|
|
2993
|
+
return { valid: true, data: newArray };
|
|
2994
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
2995
|
+
return { valid: true, data: a };
|
|
2996
|
+
} else {
|
|
2997
|
+
return { valid: false };
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
var ZodIntersection = class extends ZodType {
|
|
3001
|
+
_parse(input) {
|
|
3002
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3003
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3004
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3005
|
+
return INVALID;
|
|
3006
|
+
}
|
|
3007
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3008
|
+
if (!merged.valid) {
|
|
3009
|
+
addIssueToContext(ctx, {
|
|
3010
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
3011
|
+
});
|
|
3012
|
+
return INVALID;
|
|
3013
|
+
}
|
|
3014
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3015
|
+
status.dirty();
|
|
3016
|
+
}
|
|
3017
|
+
return { status: status.value, value: merged.data };
|
|
3018
|
+
};
|
|
3019
|
+
if (ctx.common.async) {
|
|
3020
|
+
return Promise.all([
|
|
3021
|
+
this._def.left._parseAsync({
|
|
3022
|
+
data: ctx.data,
|
|
3023
|
+
path: ctx.path,
|
|
3024
|
+
parent: ctx
|
|
3025
|
+
}),
|
|
3026
|
+
this._def.right._parseAsync({
|
|
3027
|
+
data: ctx.data,
|
|
3028
|
+
path: ctx.path,
|
|
3029
|
+
parent: ctx
|
|
3030
|
+
})
|
|
3031
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
3032
|
+
} else {
|
|
3033
|
+
return handleParsed(this._def.left._parseSync({
|
|
3034
|
+
data: ctx.data,
|
|
3035
|
+
path: ctx.path,
|
|
3036
|
+
parent: ctx
|
|
3037
|
+
}), this._def.right._parseSync({
|
|
3038
|
+
data: ctx.data,
|
|
3039
|
+
path: ctx.path,
|
|
3040
|
+
parent: ctx
|
|
3041
|
+
}));
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
};
|
|
3045
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3046
|
+
return new ZodIntersection({
|
|
3047
|
+
left,
|
|
3048
|
+
right,
|
|
3049
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3050
|
+
...processCreateParams(params)
|
|
3051
|
+
});
|
|
3052
|
+
};
|
|
3053
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3054
|
+
_parse(input) {
|
|
3055
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3056
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3057
|
+
addIssueToContext(ctx, {
|
|
3058
|
+
code: ZodIssueCode.invalid_type,
|
|
3059
|
+
expected: ZodParsedType.array,
|
|
3060
|
+
received: ctx.parsedType
|
|
3061
|
+
});
|
|
3062
|
+
return INVALID;
|
|
3063
|
+
}
|
|
3064
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3065
|
+
addIssueToContext(ctx, {
|
|
3066
|
+
code: ZodIssueCode.too_small,
|
|
3067
|
+
minimum: this._def.items.length,
|
|
3068
|
+
inclusive: true,
|
|
3069
|
+
exact: false,
|
|
3070
|
+
type: "array"
|
|
3071
|
+
});
|
|
3072
|
+
return INVALID;
|
|
3073
|
+
}
|
|
3074
|
+
const rest = this._def.rest;
|
|
3075
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3076
|
+
addIssueToContext(ctx, {
|
|
3077
|
+
code: ZodIssueCode.too_big,
|
|
3078
|
+
maximum: this._def.items.length,
|
|
3079
|
+
inclusive: true,
|
|
3080
|
+
exact: false,
|
|
3081
|
+
type: "array"
|
|
3082
|
+
});
|
|
3083
|
+
status.dirty();
|
|
3084
|
+
}
|
|
3085
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3086
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3087
|
+
if (!schema)
|
|
3088
|
+
return null;
|
|
3089
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3090
|
+
}).filter((x) => !!x);
|
|
3091
|
+
if (ctx.common.async) {
|
|
3092
|
+
return Promise.all(items).then((results) => {
|
|
3093
|
+
return ParseStatus.mergeArray(status, results);
|
|
3094
|
+
});
|
|
3095
|
+
} else {
|
|
3096
|
+
return ParseStatus.mergeArray(status, items);
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
get items() {
|
|
3100
|
+
return this._def.items;
|
|
3101
|
+
}
|
|
3102
|
+
rest(rest) {
|
|
3103
|
+
return new _ZodTuple({
|
|
3104
|
+
...this._def,
|
|
3105
|
+
rest
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
};
|
|
3109
|
+
ZodTuple.create = (schemas, params) => {
|
|
3110
|
+
if (!Array.isArray(schemas)) {
|
|
3111
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3112
|
+
}
|
|
3113
|
+
return new ZodTuple({
|
|
3114
|
+
items: schemas,
|
|
3115
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3116
|
+
rest: null,
|
|
3117
|
+
...processCreateParams(params)
|
|
3118
|
+
});
|
|
3119
|
+
};
|
|
3120
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3121
|
+
get keySchema() {
|
|
3122
|
+
return this._def.keyType;
|
|
3123
|
+
}
|
|
3124
|
+
get valueSchema() {
|
|
3125
|
+
return this._def.valueType;
|
|
3126
|
+
}
|
|
3127
|
+
_parse(input) {
|
|
3128
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3129
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3130
|
+
addIssueToContext(ctx, {
|
|
3131
|
+
code: ZodIssueCode.invalid_type,
|
|
3132
|
+
expected: ZodParsedType.object,
|
|
3133
|
+
received: ctx.parsedType
|
|
3134
|
+
});
|
|
3135
|
+
return INVALID;
|
|
3136
|
+
}
|
|
3137
|
+
const pairs = [];
|
|
3138
|
+
const keyType = this._def.keyType;
|
|
3139
|
+
const valueType = this._def.valueType;
|
|
3140
|
+
for (const key in ctx.data) {
|
|
3141
|
+
pairs.push({
|
|
3142
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3143
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3144
|
+
alwaysSet: key in ctx.data
|
|
3145
|
+
});
|
|
3146
|
+
}
|
|
3147
|
+
if (ctx.common.async) {
|
|
3148
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3149
|
+
} else {
|
|
3150
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
get element() {
|
|
3154
|
+
return this._def.valueType;
|
|
3155
|
+
}
|
|
3156
|
+
static create(first, second, third) {
|
|
3157
|
+
if (second instanceof ZodType) {
|
|
3158
|
+
return new _ZodRecord({
|
|
3159
|
+
keyType: first,
|
|
3160
|
+
valueType: second,
|
|
3161
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3162
|
+
...processCreateParams(third)
|
|
3163
|
+
});
|
|
3164
|
+
}
|
|
3165
|
+
return new _ZodRecord({
|
|
3166
|
+
keyType: ZodString.create(),
|
|
3167
|
+
valueType: first,
|
|
3168
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3169
|
+
...processCreateParams(second)
|
|
3170
|
+
});
|
|
3171
|
+
}
|
|
3172
|
+
};
|
|
3173
|
+
var ZodMap = class extends ZodType {
|
|
3174
|
+
get keySchema() {
|
|
3175
|
+
return this._def.keyType;
|
|
3176
|
+
}
|
|
3177
|
+
get valueSchema() {
|
|
3178
|
+
return this._def.valueType;
|
|
3179
|
+
}
|
|
3180
|
+
_parse(input) {
|
|
3181
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3182
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3183
|
+
addIssueToContext(ctx, {
|
|
3184
|
+
code: ZodIssueCode.invalid_type,
|
|
3185
|
+
expected: ZodParsedType.map,
|
|
3186
|
+
received: ctx.parsedType
|
|
3187
|
+
});
|
|
3188
|
+
return INVALID;
|
|
3189
|
+
}
|
|
3190
|
+
const keyType = this._def.keyType;
|
|
3191
|
+
const valueType = this._def.valueType;
|
|
3192
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3193
|
+
return {
|
|
3194
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3195
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3196
|
+
};
|
|
3197
|
+
});
|
|
3198
|
+
if (ctx.common.async) {
|
|
3199
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3200
|
+
return Promise.resolve().then(async () => {
|
|
3201
|
+
for (const pair of pairs) {
|
|
3202
|
+
const key = await pair.key;
|
|
3203
|
+
const value = await pair.value;
|
|
3204
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3205
|
+
return INVALID;
|
|
3206
|
+
}
|
|
3207
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3208
|
+
status.dirty();
|
|
3209
|
+
}
|
|
3210
|
+
finalMap.set(key.value, value.value);
|
|
3211
|
+
}
|
|
3212
|
+
return { status: status.value, value: finalMap };
|
|
3213
|
+
});
|
|
3214
|
+
} else {
|
|
3215
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3216
|
+
for (const pair of pairs) {
|
|
3217
|
+
const key = pair.key;
|
|
3218
|
+
const value = pair.value;
|
|
3219
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3220
|
+
return INVALID;
|
|
3221
|
+
}
|
|
3222
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3223
|
+
status.dirty();
|
|
3224
|
+
}
|
|
3225
|
+
finalMap.set(key.value, value.value);
|
|
3226
|
+
}
|
|
3227
|
+
return { status: status.value, value: finalMap };
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
};
|
|
3231
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3232
|
+
return new ZodMap({
|
|
3233
|
+
valueType,
|
|
3234
|
+
keyType,
|
|
3235
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3236
|
+
...processCreateParams(params)
|
|
3237
|
+
});
|
|
3238
|
+
};
|
|
3239
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
3240
|
+
_parse(input) {
|
|
3241
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3242
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3243
|
+
addIssueToContext(ctx, {
|
|
3244
|
+
code: ZodIssueCode.invalid_type,
|
|
3245
|
+
expected: ZodParsedType.set,
|
|
3246
|
+
received: ctx.parsedType
|
|
3247
|
+
});
|
|
3248
|
+
return INVALID;
|
|
3249
|
+
}
|
|
3250
|
+
const def = this._def;
|
|
3251
|
+
if (def.minSize !== null) {
|
|
3252
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3253
|
+
addIssueToContext(ctx, {
|
|
3254
|
+
code: ZodIssueCode.too_small,
|
|
3255
|
+
minimum: def.minSize.value,
|
|
3256
|
+
type: "set",
|
|
3257
|
+
inclusive: true,
|
|
3258
|
+
exact: false,
|
|
3259
|
+
message: def.minSize.message
|
|
3260
|
+
});
|
|
3261
|
+
status.dirty();
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
if (def.maxSize !== null) {
|
|
3265
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3266
|
+
addIssueToContext(ctx, {
|
|
3267
|
+
code: ZodIssueCode.too_big,
|
|
3268
|
+
maximum: def.maxSize.value,
|
|
3269
|
+
type: "set",
|
|
3270
|
+
inclusive: true,
|
|
3271
|
+
exact: false,
|
|
3272
|
+
message: def.maxSize.message
|
|
3273
|
+
});
|
|
3274
|
+
status.dirty();
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
const valueType = this._def.valueType;
|
|
3278
|
+
function finalizeSet(elements2) {
|
|
3279
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3280
|
+
for (const element of elements2) {
|
|
3281
|
+
if (element.status === "aborted")
|
|
3282
|
+
return INVALID;
|
|
3283
|
+
if (element.status === "dirty")
|
|
3284
|
+
status.dirty();
|
|
3285
|
+
parsedSet.add(element.value);
|
|
3286
|
+
}
|
|
3287
|
+
return { status: status.value, value: parsedSet };
|
|
3288
|
+
}
|
|
3289
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3290
|
+
if (ctx.common.async) {
|
|
3291
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3292
|
+
} else {
|
|
3293
|
+
return finalizeSet(elements);
|
|
3294
|
+
}
|
|
3295
|
+
}
|
|
3296
|
+
min(minSize, message) {
|
|
3297
|
+
return new _ZodSet({
|
|
3298
|
+
...this._def,
|
|
3299
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
max(maxSize, message) {
|
|
3303
|
+
return new _ZodSet({
|
|
3304
|
+
...this._def,
|
|
3305
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3306
|
+
});
|
|
3307
|
+
}
|
|
3308
|
+
size(size, message) {
|
|
3309
|
+
return this.min(size, message).max(size, message);
|
|
3310
|
+
}
|
|
3311
|
+
nonempty(message) {
|
|
3312
|
+
return this.min(1, message);
|
|
3313
|
+
}
|
|
3314
|
+
};
|
|
3315
|
+
ZodSet.create = (valueType, params) => {
|
|
3316
|
+
return new ZodSet({
|
|
3317
|
+
valueType,
|
|
3318
|
+
minSize: null,
|
|
3319
|
+
maxSize: null,
|
|
3320
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3321
|
+
...processCreateParams(params)
|
|
3322
|
+
});
|
|
3323
|
+
};
|
|
3324
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3325
|
+
constructor() {
|
|
3326
|
+
super(...arguments);
|
|
3327
|
+
this.validate = this.implement;
|
|
3328
|
+
}
|
|
3329
|
+
_parse(input) {
|
|
3330
|
+
const { ctx } = this._processInputParams(input);
|
|
3331
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3332
|
+
addIssueToContext(ctx, {
|
|
3333
|
+
code: ZodIssueCode.invalid_type,
|
|
3334
|
+
expected: ZodParsedType.function,
|
|
3335
|
+
received: ctx.parsedType
|
|
3336
|
+
});
|
|
3337
|
+
return INVALID;
|
|
3338
|
+
}
|
|
3339
|
+
function makeArgsIssue(args, error) {
|
|
3340
|
+
return makeIssue({
|
|
3341
|
+
data: args,
|
|
3342
|
+
path: ctx.path,
|
|
3343
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3344
|
+
issueData: {
|
|
3345
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3346
|
+
argumentsError: error
|
|
3347
|
+
}
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
function makeReturnsIssue(returns, error) {
|
|
3351
|
+
return makeIssue({
|
|
3352
|
+
data: returns,
|
|
3353
|
+
path: ctx.path,
|
|
3354
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3355
|
+
issueData: {
|
|
3356
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3357
|
+
returnTypeError: error
|
|
3358
|
+
}
|
|
3359
|
+
});
|
|
3360
|
+
}
|
|
3361
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3362
|
+
const fn = ctx.data;
|
|
3363
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3364
|
+
const me = this;
|
|
3365
|
+
return OK(async function(...args) {
|
|
3366
|
+
const error = new ZodError([]);
|
|
3367
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3368
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3369
|
+
throw error;
|
|
3370
|
+
});
|
|
3371
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3372
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3373
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3374
|
+
throw error;
|
|
3375
|
+
});
|
|
3376
|
+
return parsedReturns;
|
|
3377
|
+
});
|
|
3378
|
+
} else {
|
|
3379
|
+
const me = this;
|
|
3380
|
+
return OK(function(...args) {
|
|
3381
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3382
|
+
if (!parsedArgs.success) {
|
|
3383
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3384
|
+
}
|
|
3385
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3386
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3387
|
+
if (!parsedReturns.success) {
|
|
3388
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3389
|
+
}
|
|
3390
|
+
return parsedReturns.data;
|
|
3391
|
+
});
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
parameters() {
|
|
3395
|
+
return this._def.args;
|
|
3396
|
+
}
|
|
3397
|
+
returnType() {
|
|
3398
|
+
return this._def.returns;
|
|
3399
|
+
}
|
|
3400
|
+
args(...items) {
|
|
3401
|
+
return new _ZodFunction({
|
|
3402
|
+
...this._def,
|
|
3403
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
returns(returnType) {
|
|
3407
|
+
return new _ZodFunction({
|
|
3408
|
+
...this._def,
|
|
3409
|
+
returns: returnType
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
implement(func) {
|
|
3413
|
+
const validatedFunc = this.parse(func);
|
|
3414
|
+
return validatedFunc;
|
|
3415
|
+
}
|
|
3416
|
+
strictImplement(func) {
|
|
3417
|
+
const validatedFunc = this.parse(func);
|
|
3418
|
+
return validatedFunc;
|
|
3419
|
+
}
|
|
3420
|
+
static create(args, returns, params) {
|
|
3421
|
+
return new _ZodFunction({
|
|
3422
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3423
|
+
returns: returns || ZodUnknown.create(),
|
|
3424
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3425
|
+
...processCreateParams(params)
|
|
3426
|
+
});
|
|
3427
|
+
}
|
|
3428
|
+
};
|
|
3429
|
+
var ZodLazy = class extends ZodType {
|
|
3430
|
+
get schema() {
|
|
3431
|
+
return this._def.getter();
|
|
3432
|
+
}
|
|
3433
|
+
_parse(input) {
|
|
3434
|
+
const { ctx } = this._processInputParams(input);
|
|
3435
|
+
const lazySchema = this._def.getter();
|
|
3436
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
ZodLazy.create = (getter, params) => {
|
|
3440
|
+
return new ZodLazy({
|
|
3441
|
+
getter,
|
|
3442
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3443
|
+
...processCreateParams(params)
|
|
3444
|
+
});
|
|
3445
|
+
};
|
|
3446
|
+
var ZodLiteral = class extends ZodType {
|
|
3447
|
+
_parse(input) {
|
|
3448
|
+
if (input.data !== this._def.value) {
|
|
3449
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3450
|
+
addIssueToContext(ctx, {
|
|
3451
|
+
received: ctx.data,
|
|
3452
|
+
code: ZodIssueCode.invalid_literal,
|
|
3453
|
+
expected: this._def.value
|
|
3454
|
+
});
|
|
3455
|
+
return INVALID;
|
|
3456
|
+
}
|
|
3457
|
+
return { status: "valid", value: input.data };
|
|
3458
|
+
}
|
|
3459
|
+
get value() {
|
|
3460
|
+
return this._def.value;
|
|
3461
|
+
}
|
|
3462
|
+
};
|
|
3463
|
+
ZodLiteral.create = (value, params) => {
|
|
3464
|
+
return new ZodLiteral({
|
|
3465
|
+
value,
|
|
3466
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3467
|
+
...processCreateParams(params)
|
|
3468
|
+
});
|
|
3469
|
+
};
|
|
3470
|
+
function createZodEnum(values, params) {
|
|
3471
|
+
return new ZodEnum({
|
|
3472
|
+
values,
|
|
3473
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3474
|
+
...processCreateParams(params)
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3478
|
+
_parse(input) {
|
|
3479
|
+
if (typeof input.data !== "string") {
|
|
3480
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3481
|
+
const expectedValues = this._def.values;
|
|
3482
|
+
addIssueToContext(ctx, {
|
|
3483
|
+
expected: util.joinValues(expectedValues),
|
|
3484
|
+
received: ctx.parsedType,
|
|
3485
|
+
code: ZodIssueCode.invalid_type
|
|
3486
|
+
});
|
|
3487
|
+
return INVALID;
|
|
3488
|
+
}
|
|
3489
|
+
if (!this._cache) {
|
|
3490
|
+
this._cache = new Set(this._def.values);
|
|
3491
|
+
}
|
|
3492
|
+
if (!this._cache.has(input.data)) {
|
|
3493
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3494
|
+
const expectedValues = this._def.values;
|
|
3495
|
+
addIssueToContext(ctx, {
|
|
3496
|
+
received: ctx.data,
|
|
3497
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3498
|
+
options: expectedValues
|
|
3499
|
+
});
|
|
3500
|
+
return INVALID;
|
|
3501
|
+
}
|
|
3502
|
+
return OK(input.data);
|
|
3503
|
+
}
|
|
3504
|
+
get options() {
|
|
3505
|
+
return this._def.values;
|
|
3506
|
+
}
|
|
3507
|
+
get enum() {
|
|
3508
|
+
const enumValues = {};
|
|
3509
|
+
for (const val of this._def.values) {
|
|
3510
|
+
enumValues[val] = val;
|
|
3511
|
+
}
|
|
3512
|
+
return enumValues;
|
|
3513
|
+
}
|
|
3514
|
+
get Values() {
|
|
3515
|
+
const enumValues = {};
|
|
3516
|
+
for (const val of this._def.values) {
|
|
3517
|
+
enumValues[val] = val;
|
|
3518
|
+
}
|
|
3519
|
+
return enumValues;
|
|
3520
|
+
}
|
|
3521
|
+
get Enum() {
|
|
3522
|
+
const enumValues = {};
|
|
3523
|
+
for (const val of this._def.values) {
|
|
3524
|
+
enumValues[val] = val;
|
|
3525
|
+
}
|
|
3526
|
+
return enumValues;
|
|
3527
|
+
}
|
|
3528
|
+
extract(values, newDef = this._def) {
|
|
3529
|
+
return _ZodEnum.create(values, {
|
|
3530
|
+
...this._def,
|
|
3531
|
+
...newDef
|
|
3532
|
+
});
|
|
3533
|
+
}
|
|
3534
|
+
exclude(values, newDef = this._def) {
|
|
3535
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3536
|
+
...this._def,
|
|
3537
|
+
...newDef
|
|
3538
|
+
});
|
|
3539
|
+
}
|
|
3540
|
+
};
|
|
3541
|
+
ZodEnum.create = createZodEnum;
|
|
3542
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3543
|
+
_parse(input) {
|
|
3544
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3545
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3546
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3547
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3548
|
+
addIssueToContext(ctx, {
|
|
3549
|
+
expected: util.joinValues(expectedValues),
|
|
3550
|
+
received: ctx.parsedType,
|
|
3551
|
+
code: ZodIssueCode.invalid_type
|
|
3552
|
+
});
|
|
3553
|
+
return INVALID;
|
|
3554
|
+
}
|
|
3555
|
+
if (!this._cache) {
|
|
3556
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3557
|
+
}
|
|
3558
|
+
if (!this._cache.has(input.data)) {
|
|
3559
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3560
|
+
addIssueToContext(ctx, {
|
|
3561
|
+
received: ctx.data,
|
|
3562
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3563
|
+
options: expectedValues
|
|
3564
|
+
});
|
|
3565
|
+
return INVALID;
|
|
3566
|
+
}
|
|
3567
|
+
return OK(input.data);
|
|
3568
|
+
}
|
|
3569
|
+
get enum() {
|
|
3570
|
+
return this._def.values;
|
|
3571
|
+
}
|
|
3572
|
+
};
|
|
3573
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3574
|
+
return new ZodNativeEnum({
|
|
3575
|
+
values,
|
|
3576
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3577
|
+
...processCreateParams(params)
|
|
3578
|
+
});
|
|
3579
|
+
};
|
|
3580
|
+
var ZodPromise = class extends ZodType {
|
|
3581
|
+
unwrap() {
|
|
3582
|
+
return this._def.type;
|
|
3583
|
+
}
|
|
3584
|
+
_parse(input) {
|
|
3585
|
+
const { ctx } = this._processInputParams(input);
|
|
3586
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3587
|
+
addIssueToContext(ctx, {
|
|
3588
|
+
code: ZodIssueCode.invalid_type,
|
|
3589
|
+
expected: ZodParsedType.promise,
|
|
3590
|
+
received: ctx.parsedType
|
|
3591
|
+
});
|
|
3592
|
+
return INVALID;
|
|
3593
|
+
}
|
|
3594
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3595
|
+
return OK(promisified.then((data) => {
|
|
3596
|
+
return this._def.type.parseAsync(data, {
|
|
3597
|
+
path: ctx.path,
|
|
3598
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3599
|
+
});
|
|
3600
|
+
}));
|
|
3601
|
+
}
|
|
3602
|
+
};
|
|
3603
|
+
ZodPromise.create = (schema, params) => {
|
|
3604
|
+
return new ZodPromise({
|
|
3605
|
+
type: schema,
|
|
3606
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3607
|
+
...processCreateParams(params)
|
|
3608
|
+
});
|
|
3609
|
+
};
|
|
3610
|
+
var ZodEffects = class extends ZodType {
|
|
3611
|
+
innerType() {
|
|
3612
|
+
return this._def.schema;
|
|
3613
|
+
}
|
|
3614
|
+
sourceType() {
|
|
3615
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3616
|
+
}
|
|
3617
|
+
_parse(input) {
|
|
3618
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3619
|
+
const effect = this._def.effect || null;
|
|
3620
|
+
const checkCtx = {
|
|
3621
|
+
addIssue: (arg) => {
|
|
3622
|
+
addIssueToContext(ctx, arg);
|
|
3623
|
+
if (arg.fatal) {
|
|
3624
|
+
status.abort();
|
|
3625
|
+
} else {
|
|
3626
|
+
status.dirty();
|
|
3627
|
+
}
|
|
3628
|
+
},
|
|
3629
|
+
get path() {
|
|
3630
|
+
return ctx.path;
|
|
3631
|
+
}
|
|
3632
|
+
};
|
|
3633
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3634
|
+
if (effect.type === "preprocess") {
|
|
3635
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3636
|
+
if (ctx.common.async) {
|
|
3637
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3638
|
+
if (status.value === "aborted")
|
|
3639
|
+
return INVALID;
|
|
3640
|
+
const result = await this._def.schema._parseAsync({
|
|
3641
|
+
data: processed2,
|
|
3642
|
+
path: ctx.path,
|
|
3643
|
+
parent: ctx
|
|
3644
|
+
});
|
|
3645
|
+
if (result.status === "aborted")
|
|
3646
|
+
return INVALID;
|
|
3647
|
+
if (result.status === "dirty")
|
|
3648
|
+
return DIRTY(result.value);
|
|
3649
|
+
if (status.value === "dirty")
|
|
3650
|
+
return DIRTY(result.value);
|
|
3651
|
+
return result;
|
|
3652
|
+
});
|
|
3653
|
+
} else {
|
|
3654
|
+
if (status.value === "aborted")
|
|
3655
|
+
return INVALID;
|
|
3656
|
+
const result = this._def.schema._parseSync({
|
|
3657
|
+
data: processed,
|
|
3658
|
+
path: ctx.path,
|
|
3659
|
+
parent: ctx
|
|
3660
|
+
});
|
|
3661
|
+
if (result.status === "aborted")
|
|
3662
|
+
return INVALID;
|
|
3663
|
+
if (result.status === "dirty")
|
|
3664
|
+
return DIRTY(result.value);
|
|
3665
|
+
if (status.value === "dirty")
|
|
3666
|
+
return DIRTY(result.value);
|
|
3667
|
+
return result;
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
if (effect.type === "refinement") {
|
|
3671
|
+
const executeRefinement = (acc) => {
|
|
3672
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3673
|
+
if (ctx.common.async) {
|
|
3674
|
+
return Promise.resolve(result);
|
|
3675
|
+
}
|
|
3676
|
+
if (result instanceof Promise) {
|
|
3677
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3678
|
+
}
|
|
3679
|
+
return acc;
|
|
3680
|
+
};
|
|
3681
|
+
if (ctx.common.async === false) {
|
|
3682
|
+
const inner = this._def.schema._parseSync({
|
|
3683
|
+
data: ctx.data,
|
|
3684
|
+
path: ctx.path,
|
|
3685
|
+
parent: ctx
|
|
3686
|
+
});
|
|
3687
|
+
if (inner.status === "aborted")
|
|
3688
|
+
return INVALID;
|
|
3689
|
+
if (inner.status === "dirty")
|
|
3690
|
+
status.dirty();
|
|
3691
|
+
executeRefinement(inner.value);
|
|
3692
|
+
return { status: status.value, value: inner.value };
|
|
3693
|
+
} else {
|
|
3694
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3695
|
+
if (inner.status === "aborted")
|
|
3696
|
+
return INVALID;
|
|
3697
|
+
if (inner.status === "dirty")
|
|
3698
|
+
status.dirty();
|
|
3699
|
+
return executeRefinement(inner.value).then(() => {
|
|
3700
|
+
return { status: status.value, value: inner.value };
|
|
3701
|
+
});
|
|
3702
|
+
});
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
if (effect.type === "transform") {
|
|
3706
|
+
if (ctx.common.async === false) {
|
|
3707
|
+
const base = this._def.schema._parseSync({
|
|
3708
|
+
data: ctx.data,
|
|
3709
|
+
path: ctx.path,
|
|
3710
|
+
parent: ctx
|
|
3711
|
+
});
|
|
3712
|
+
if (!isValid(base))
|
|
3713
|
+
return INVALID;
|
|
3714
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3715
|
+
if (result instanceof Promise) {
|
|
3716
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3717
|
+
}
|
|
3718
|
+
return { status: status.value, value: result };
|
|
3719
|
+
} else {
|
|
3720
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3721
|
+
if (!isValid(base))
|
|
3722
|
+
return INVALID;
|
|
3723
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3724
|
+
status: status.value,
|
|
3725
|
+
value: result
|
|
3726
|
+
}));
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
}
|
|
3730
|
+
util.assertNever(effect);
|
|
3731
|
+
}
|
|
3732
|
+
};
|
|
3733
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3734
|
+
return new ZodEffects({
|
|
3735
|
+
schema,
|
|
3736
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3737
|
+
effect,
|
|
3738
|
+
...processCreateParams(params)
|
|
3739
|
+
});
|
|
3740
|
+
};
|
|
3741
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3742
|
+
return new ZodEffects({
|
|
3743
|
+
schema,
|
|
3744
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
3745
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3746
|
+
...processCreateParams(params)
|
|
3747
|
+
});
|
|
3748
|
+
};
|
|
3749
|
+
var ZodOptional = class extends ZodType {
|
|
3750
|
+
_parse(input) {
|
|
3751
|
+
const parsedType = this._getType(input);
|
|
3752
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
3753
|
+
return OK(void 0);
|
|
3754
|
+
}
|
|
3755
|
+
return this._def.innerType._parse(input);
|
|
3756
|
+
}
|
|
3757
|
+
unwrap() {
|
|
3758
|
+
return this._def.innerType;
|
|
3759
|
+
}
|
|
3760
|
+
};
|
|
3761
|
+
ZodOptional.create = (type, params) => {
|
|
3762
|
+
return new ZodOptional({
|
|
3763
|
+
innerType: type,
|
|
3764
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3765
|
+
...processCreateParams(params)
|
|
3766
|
+
});
|
|
3767
|
+
};
|
|
3768
|
+
var ZodNullable = class extends ZodType {
|
|
3769
|
+
_parse(input) {
|
|
3770
|
+
const parsedType = this._getType(input);
|
|
3771
|
+
if (parsedType === ZodParsedType.null) {
|
|
3772
|
+
return OK(null);
|
|
3773
|
+
}
|
|
3774
|
+
return this._def.innerType._parse(input);
|
|
3775
|
+
}
|
|
3776
|
+
unwrap() {
|
|
3777
|
+
return this._def.innerType;
|
|
3778
|
+
}
|
|
3779
|
+
};
|
|
3780
|
+
ZodNullable.create = (type, params) => {
|
|
3781
|
+
return new ZodNullable({
|
|
3782
|
+
innerType: type,
|
|
3783
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3784
|
+
...processCreateParams(params)
|
|
3785
|
+
});
|
|
3786
|
+
};
|
|
3787
|
+
var ZodDefault = class extends ZodType {
|
|
3788
|
+
_parse(input) {
|
|
3789
|
+
const { ctx } = this._processInputParams(input);
|
|
3790
|
+
let data = ctx.data;
|
|
3791
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3792
|
+
data = this._def.defaultValue();
|
|
3793
|
+
}
|
|
3794
|
+
return this._def.innerType._parse({
|
|
3795
|
+
data,
|
|
3796
|
+
path: ctx.path,
|
|
3797
|
+
parent: ctx
|
|
3798
|
+
});
|
|
3799
|
+
}
|
|
3800
|
+
removeDefault() {
|
|
3801
|
+
return this._def.innerType;
|
|
3802
|
+
}
|
|
3803
|
+
};
|
|
3804
|
+
ZodDefault.create = (type, params) => {
|
|
3805
|
+
return new ZodDefault({
|
|
3806
|
+
innerType: type,
|
|
3807
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3808
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3809
|
+
...processCreateParams(params)
|
|
3810
|
+
});
|
|
3811
|
+
};
|
|
3812
|
+
var ZodCatch = class extends ZodType {
|
|
3813
|
+
_parse(input) {
|
|
3814
|
+
const { ctx } = this._processInputParams(input);
|
|
3815
|
+
const newCtx = {
|
|
3816
|
+
...ctx,
|
|
3817
|
+
common: {
|
|
3818
|
+
...ctx.common,
|
|
3819
|
+
issues: []
|
|
3820
|
+
}
|
|
3821
|
+
};
|
|
3822
|
+
const result = this._def.innerType._parse({
|
|
3823
|
+
data: newCtx.data,
|
|
3824
|
+
path: newCtx.path,
|
|
3825
|
+
parent: {
|
|
3826
|
+
...newCtx
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
if (isAsync(result)) {
|
|
3830
|
+
return result.then((result2) => {
|
|
3831
|
+
return {
|
|
3832
|
+
status: "valid",
|
|
3833
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3834
|
+
get error() {
|
|
3835
|
+
return new ZodError(newCtx.common.issues);
|
|
3836
|
+
},
|
|
3837
|
+
input: newCtx.data
|
|
3838
|
+
})
|
|
3839
|
+
};
|
|
3840
|
+
});
|
|
3841
|
+
} else {
|
|
3842
|
+
return {
|
|
3843
|
+
status: "valid",
|
|
3844
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3845
|
+
get error() {
|
|
3846
|
+
return new ZodError(newCtx.common.issues);
|
|
3847
|
+
},
|
|
3848
|
+
input: newCtx.data
|
|
3849
|
+
})
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
removeCatch() {
|
|
3854
|
+
return this._def.innerType;
|
|
3855
|
+
}
|
|
3856
|
+
};
|
|
3857
|
+
ZodCatch.create = (type, params) => {
|
|
3858
|
+
return new ZodCatch({
|
|
3859
|
+
innerType: type,
|
|
3860
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3861
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3862
|
+
...processCreateParams(params)
|
|
3863
|
+
});
|
|
3864
|
+
};
|
|
3865
|
+
var ZodNaN = class extends ZodType {
|
|
3866
|
+
_parse(input) {
|
|
3867
|
+
const parsedType = this._getType(input);
|
|
3868
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
3869
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3870
|
+
addIssueToContext(ctx, {
|
|
3871
|
+
code: ZodIssueCode.invalid_type,
|
|
3872
|
+
expected: ZodParsedType.nan,
|
|
3873
|
+
received: ctx.parsedType
|
|
3874
|
+
});
|
|
3875
|
+
return INVALID;
|
|
3876
|
+
}
|
|
3877
|
+
return { status: "valid", value: input.data };
|
|
3878
|
+
}
|
|
3879
|
+
};
|
|
3880
|
+
ZodNaN.create = (params) => {
|
|
3881
|
+
return new ZodNaN({
|
|
3882
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3883
|
+
...processCreateParams(params)
|
|
3884
|
+
});
|
|
3885
|
+
};
|
|
3886
|
+
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
3887
|
+
var ZodBranded = class extends ZodType {
|
|
3888
|
+
_parse(input) {
|
|
3889
|
+
const { ctx } = this._processInputParams(input);
|
|
3890
|
+
const data = ctx.data;
|
|
3891
|
+
return this._def.type._parse({
|
|
3892
|
+
data,
|
|
3893
|
+
path: ctx.path,
|
|
3894
|
+
parent: ctx
|
|
3895
|
+
});
|
|
3896
|
+
}
|
|
3897
|
+
unwrap() {
|
|
3898
|
+
return this._def.type;
|
|
3899
|
+
}
|
|
3900
|
+
};
|
|
3901
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3902
|
+
_parse(input) {
|
|
3903
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3904
|
+
if (ctx.common.async) {
|
|
3905
|
+
const handleAsync = async () => {
|
|
3906
|
+
const inResult = await this._def.in._parseAsync({
|
|
3907
|
+
data: ctx.data,
|
|
3908
|
+
path: ctx.path,
|
|
3909
|
+
parent: ctx
|
|
3910
|
+
});
|
|
3911
|
+
if (inResult.status === "aborted")
|
|
3912
|
+
return INVALID;
|
|
3913
|
+
if (inResult.status === "dirty") {
|
|
3914
|
+
status.dirty();
|
|
3915
|
+
return DIRTY(inResult.value);
|
|
3916
|
+
} else {
|
|
3917
|
+
return this._def.out._parseAsync({
|
|
3918
|
+
data: inResult.value,
|
|
3919
|
+
path: ctx.path,
|
|
3920
|
+
parent: ctx
|
|
3921
|
+
});
|
|
3922
|
+
}
|
|
3923
|
+
};
|
|
3924
|
+
return handleAsync();
|
|
3925
|
+
} else {
|
|
3926
|
+
const inResult = this._def.in._parseSync({
|
|
3927
|
+
data: ctx.data,
|
|
3928
|
+
path: ctx.path,
|
|
3929
|
+
parent: ctx
|
|
3930
|
+
});
|
|
3931
|
+
if (inResult.status === "aborted")
|
|
3932
|
+
return INVALID;
|
|
3933
|
+
if (inResult.status === "dirty") {
|
|
3934
|
+
status.dirty();
|
|
3935
|
+
return {
|
|
3936
|
+
status: "dirty",
|
|
3937
|
+
value: inResult.value
|
|
3938
|
+
};
|
|
3939
|
+
} else {
|
|
3940
|
+
return this._def.out._parseSync({
|
|
3941
|
+
data: inResult.value,
|
|
3942
|
+
path: ctx.path,
|
|
3943
|
+
parent: ctx
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
static create(a, b) {
|
|
3949
|
+
return new _ZodPipeline({
|
|
3950
|
+
in: a,
|
|
3951
|
+
out: b,
|
|
3952
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3953
|
+
});
|
|
3954
|
+
}
|
|
3955
|
+
};
|
|
3956
|
+
var ZodReadonly = class extends ZodType {
|
|
3957
|
+
_parse(input) {
|
|
3958
|
+
const result = this._def.innerType._parse(input);
|
|
3959
|
+
const freeze = (data) => {
|
|
3960
|
+
if (isValid(data)) {
|
|
3961
|
+
data.value = Object.freeze(data.value);
|
|
3962
|
+
}
|
|
3963
|
+
return data;
|
|
3964
|
+
};
|
|
3965
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3966
|
+
}
|
|
3967
|
+
unwrap() {
|
|
3968
|
+
return this._def.innerType;
|
|
3969
|
+
}
|
|
3970
|
+
};
|
|
3971
|
+
ZodReadonly.create = (type, params) => {
|
|
3972
|
+
return new ZodReadonly({
|
|
3973
|
+
innerType: type,
|
|
3974
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3975
|
+
...processCreateParams(params)
|
|
3976
|
+
});
|
|
3977
|
+
};
|
|
3978
|
+
function cleanParams(params, data) {
|
|
3979
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3980
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3981
|
+
return p2;
|
|
3982
|
+
}
|
|
3983
|
+
function custom(check, _params = {}, fatal) {
|
|
3984
|
+
if (check)
|
|
3985
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
3986
|
+
const r = check(data);
|
|
3987
|
+
if (r instanceof Promise) {
|
|
3988
|
+
return r.then((r2) => {
|
|
3989
|
+
if (!r2) {
|
|
3990
|
+
const params = cleanParams(_params, data);
|
|
3991
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3992
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3993
|
+
}
|
|
3994
|
+
});
|
|
3995
|
+
}
|
|
3996
|
+
if (!r) {
|
|
3997
|
+
const params = cleanParams(_params, data);
|
|
3998
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
3999
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4000
|
+
}
|
|
4001
|
+
return;
|
|
4002
|
+
});
|
|
4003
|
+
return ZodAny.create();
|
|
4004
|
+
}
|
|
4005
|
+
var late = {
|
|
4006
|
+
object: ZodObject.lazycreate
|
|
4007
|
+
};
|
|
4008
|
+
var ZodFirstPartyTypeKind;
|
|
4009
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
4010
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4011
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4012
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4013
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4014
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4015
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4016
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4017
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4018
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4019
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4020
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4021
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4022
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4023
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4024
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4025
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4026
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4027
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4028
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4029
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4030
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4031
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4032
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4033
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4034
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4035
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4036
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4037
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4038
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4039
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4040
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4041
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4042
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4043
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4044
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4045
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4046
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4047
|
+
var instanceOfType = (cls, params = {
|
|
4048
|
+
message: `Input not instance of ${cls.name}`
|
|
4049
|
+
}) => custom((data) => data instanceof cls, params);
|
|
4050
|
+
var stringType = ZodString.create;
|
|
4051
|
+
var numberType = ZodNumber.create;
|
|
4052
|
+
var nanType = ZodNaN.create;
|
|
4053
|
+
var bigIntType = ZodBigInt.create;
|
|
4054
|
+
var booleanType = ZodBoolean.create;
|
|
4055
|
+
var dateType = ZodDate.create;
|
|
4056
|
+
var symbolType = ZodSymbol.create;
|
|
4057
|
+
var undefinedType = ZodUndefined.create;
|
|
4058
|
+
var nullType = ZodNull.create;
|
|
4059
|
+
var anyType = ZodAny.create;
|
|
4060
|
+
var unknownType = ZodUnknown.create;
|
|
4061
|
+
var neverType = ZodNever.create;
|
|
4062
|
+
var voidType = ZodVoid.create;
|
|
4063
|
+
var arrayType = ZodArray.create;
|
|
4064
|
+
var objectType = ZodObject.create;
|
|
4065
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4066
|
+
var unionType = ZodUnion.create;
|
|
4067
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4068
|
+
var intersectionType = ZodIntersection.create;
|
|
4069
|
+
var tupleType = ZodTuple.create;
|
|
4070
|
+
var recordType = ZodRecord.create;
|
|
4071
|
+
var mapType = ZodMap.create;
|
|
4072
|
+
var setType = ZodSet.create;
|
|
4073
|
+
var functionType = ZodFunction.create;
|
|
4074
|
+
var lazyType = ZodLazy.create;
|
|
4075
|
+
var literalType = ZodLiteral.create;
|
|
4076
|
+
var enumType = ZodEnum.create;
|
|
4077
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4078
|
+
var promiseType = ZodPromise.create;
|
|
4079
|
+
var effectsType = ZodEffects.create;
|
|
4080
|
+
var optionalType = ZodOptional.create;
|
|
4081
|
+
var nullableType = ZodNullable.create;
|
|
4082
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4083
|
+
var pipelineType = ZodPipeline.create;
|
|
4084
|
+
var ostring = () => stringType().optional();
|
|
4085
|
+
var onumber = () => numberType().optional();
|
|
4086
|
+
var oboolean = () => booleanType().optional();
|
|
4087
|
+
var coerce = {
|
|
4088
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4089
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4090
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
4091
|
+
...arg,
|
|
4092
|
+
coerce: true
|
|
4093
|
+
})),
|
|
4094
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4095
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4096
|
+
};
|
|
4097
|
+
var NEVER = INVALID;
|
|
4098
|
+
|
|
4099
|
+
// src/schema/match-defaults.ts
|
|
4100
|
+
function defaultMatchOpts() {
|
|
4101
|
+
return {
|
|
4102
|
+
tokenizer: { kind: "ngram", token_length: 3 },
|
|
4103
|
+
token_filters: [{ kind: "downcase" }],
|
|
4104
|
+
k: 6,
|
|
4105
|
+
m: 2048,
|
|
4106
|
+
include_original: true
|
|
4107
|
+
};
|
|
4108
|
+
}
|
|
4109
|
+
|
|
57
4110
|
// src/schema/index.ts
|
|
58
|
-
var
|
|
59
|
-
var eqlCastAsEnum = import_zod.z.enum([
|
|
4111
|
+
var eqlCastAsEnum = external_exports.enum([
|
|
60
4112
|
"text",
|
|
61
4113
|
"int",
|
|
62
4114
|
"small_int",
|
|
@@ -65,59 +4117,69 @@ var eqlCastAsEnum = import_zod.z.enum([
|
|
|
65
4117
|
"double",
|
|
66
4118
|
"boolean",
|
|
67
4119
|
"date",
|
|
4120
|
+
"timestamp",
|
|
68
4121
|
"jsonb"
|
|
69
4122
|
]).default("text");
|
|
70
|
-
var castAsEnum =
|
|
71
|
-
|
|
72
|
-
|
|
4123
|
+
var castAsEnum = external_exports.enum([
|
|
4124
|
+
"bigint",
|
|
4125
|
+
"boolean",
|
|
4126
|
+
"date",
|
|
4127
|
+
"timestamp",
|
|
4128
|
+
"number",
|
|
4129
|
+
"string",
|
|
4130
|
+
"json",
|
|
4131
|
+
"text"
|
|
4132
|
+
]).default("text");
|
|
4133
|
+
var tokenFilterSchema = external_exports.object({
|
|
4134
|
+
kind: external_exports.literal("downcase")
|
|
73
4135
|
});
|
|
74
|
-
var tokenizerSchema =
|
|
75
|
-
|
|
76
|
-
kind:
|
|
4136
|
+
var tokenizerSchema = external_exports.union([
|
|
4137
|
+
external_exports.object({
|
|
4138
|
+
kind: external_exports.literal("standard")
|
|
77
4139
|
}),
|
|
78
|
-
|
|
79
|
-
kind:
|
|
80
|
-
token_length:
|
|
4140
|
+
external_exports.object({
|
|
4141
|
+
kind: external_exports.literal("ngram"),
|
|
4142
|
+
token_length: external_exports.number()
|
|
81
4143
|
})
|
|
82
4144
|
]).default({ kind: "ngram", token_length: 3 }).optional();
|
|
83
|
-
var oreIndexOptsSchema =
|
|
84
|
-
var uniqueIndexOptsSchema =
|
|
85
|
-
token_filters:
|
|
4145
|
+
var oreIndexOptsSchema = external_exports.object({});
|
|
4146
|
+
var uniqueIndexOptsSchema = external_exports.object({
|
|
4147
|
+
token_filters: external_exports.array(tokenFilterSchema).default([]).optional()
|
|
86
4148
|
});
|
|
87
|
-
var matchIndexOptsSchema =
|
|
4149
|
+
var matchIndexOptsSchema = external_exports.object({
|
|
88
4150
|
tokenizer: tokenizerSchema,
|
|
89
|
-
token_filters:
|
|
90
|
-
k:
|
|
91
|
-
m:
|
|
92
|
-
include_original:
|
|
4151
|
+
token_filters: external_exports.array(tokenFilterSchema).default([]).optional(),
|
|
4152
|
+
k: external_exports.number().default(6).optional(),
|
|
4153
|
+
m: external_exports.number().default(2048).optional(),
|
|
4154
|
+
include_original: external_exports.boolean().default(false).optional()
|
|
93
4155
|
});
|
|
94
|
-
var arrayIndexModeSchema =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
item:
|
|
99
|
-
wildcard:
|
|
100
|
-
position:
|
|
4156
|
+
var arrayIndexModeSchema = external_exports.union([
|
|
4157
|
+
external_exports.literal("all"),
|
|
4158
|
+
external_exports.literal("none"),
|
|
4159
|
+
external_exports.object({
|
|
4160
|
+
item: external_exports.boolean().optional(),
|
|
4161
|
+
wildcard: external_exports.boolean().optional(),
|
|
4162
|
+
position: external_exports.boolean().optional()
|
|
101
4163
|
})
|
|
102
4164
|
]);
|
|
103
|
-
var steVecIndexOptsSchema =
|
|
104
|
-
prefix:
|
|
4165
|
+
var steVecIndexOptsSchema = external_exports.object({
|
|
4166
|
+
prefix: external_exports.string(),
|
|
105
4167
|
array_index_mode: arrayIndexModeSchema.optional()
|
|
106
4168
|
});
|
|
107
|
-
var indexesSchema =
|
|
4169
|
+
var indexesSchema = external_exports.object({
|
|
108
4170
|
ore: oreIndexOptsSchema.optional(),
|
|
109
4171
|
unique: uniqueIndexOptsSchema.optional(),
|
|
110
4172
|
match: matchIndexOptsSchema.optional(),
|
|
111
4173
|
ste_vec: steVecIndexOptsSchema.optional()
|
|
112
4174
|
}).default({});
|
|
113
|
-
var columnSchema =
|
|
4175
|
+
var columnSchema = external_exports.object({
|
|
114
4176
|
cast_as: castAsEnum,
|
|
115
4177
|
indexes: indexesSchema
|
|
116
4178
|
}).default({});
|
|
117
|
-
var tableSchema =
|
|
118
|
-
var tablesSchema =
|
|
119
|
-
var encryptConfigSchema =
|
|
120
|
-
v:
|
|
4179
|
+
var tableSchema = external_exports.record(columnSchema).default({});
|
|
4180
|
+
var tablesSchema = external_exports.record(tableSchema).default({});
|
|
4181
|
+
var encryptConfigSchema = external_exports.object({
|
|
4182
|
+
v: external_exports.number(),
|
|
121
4183
|
tables: tablesSchema
|
|
122
4184
|
});
|
|
123
4185
|
var EncryptedColumn = class {
|
|
@@ -224,16 +4286,13 @@ var EncryptedColumn = class {
|
|
|
224
4286
|
* ```
|
|
225
4287
|
*/
|
|
226
4288
|
freeTextSearch(opts) {
|
|
4289
|
+
const defaults = defaultMatchOpts();
|
|
227
4290
|
this.indexesValue.match = {
|
|
228
|
-
tokenizer: opts?.tokenizer ??
|
|
229
|
-
token_filters: opts?.token_filters ??
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
],
|
|
234
|
-
k: opts?.k ?? 6,
|
|
235
|
-
m: opts?.m ?? 2048,
|
|
236
|
-
include_original: opts?.include_original ?? true
|
|
4291
|
+
tokenizer: opts?.tokenizer ?? defaults.tokenizer,
|
|
4292
|
+
token_filters: opts?.token_filters ?? defaults.token_filters,
|
|
4293
|
+
k: opts?.k ?? defaults.k,
|
|
4294
|
+
m: opts?.m ?? defaults.m,
|
|
4295
|
+
include_original: opts?.include_original ?? defaults.include_original
|
|
237
4296
|
};
|
|
238
4297
|
return this;
|
|
239
4298
|
}
|
|
@@ -275,7 +4334,7 @@ var EncryptedColumn = class {
|
|
|
275
4334
|
}
|
|
276
4335
|
};
|
|
277
4336
|
|
|
278
|
-
// ../../node_modules/.pnpm/evlog@1.
|
|
4337
|
+
// ../../node_modules/.pnpm/evlog@1.11.0_next@15.5.18_react-dom@19.2.3_react@19.2.3__react@19.2.3__react@19.2.3/node_modules/evlog/dist/utils.mjs
|
|
279
4338
|
function formatDuration(ms) {
|
|
280
4339
|
if (ms < 1e3) return `${Math.round(ms)}ms`;
|
|
281
4340
|
return `${(ms / 1e3).toFixed(2)}s`;
|
|
@@ -331,7 +4390,7 @@ function matchesPattern(path, pattern) {
|
|
|
331
4390
|
return new RegExp(`^${regexPattern}$`).test(path);
|
|
332
4391
|
}
|
|
333
4392
|
|
|
334
|
-
// ../../node_modules/.pnpm/evlog@1.
|
|
4393
|
+
// ../../node_modules/.pnpm/evlog@1.11.0_next@15.5.18_react-dom@19.2.3_react@19.2.3__react@19.2.3__react@19.2.3/node_modules/evlog/dist/logger.mjs
|
|
335
4394
|
function isPlainObject(val) {
|
|
336
4395
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
337
4396
|
}
|
|
@@ -661,6 +4720,40 @@ function addJsonbCasts(columns, encryptedColumnNames) {
|
|
|
661
4720
|
return col;
|
|
662
4721
|
}).join(",");
|
|
663
4722
|
}
|
|
4723
|
+
function addJsonbCastsV3(columns, propToDb) {
|
|
4724
|
+
const dbNames = new Set(Object.values(propToDb));
|
|
4725
|
+
const keyToDb = {};
|
|
4726
|
+
const select = columns.split(",").map((col) => {
|
|
4727
|
+
const trimmed = col.trim();
|
|
4728
|
+
if (!trimmed) return col;
|
|
4729
|
+
if (trimmed.includes("::")) return col;
|
|
4730
|
+
if (trimmed.includes("(") || trimmed.includes(".")) return col;
|
|
4731
|
+
const leadingWhitespace = col.match(/^(\s*)/)?.[1] ?? "";
|
|
4732
|
+
const aliasMatch = trimmed.match(
|
|
4733
|
+
/^([A-Za-z_][A-Za-z0-9_]*):([A-Za-z_][A-Za-z0-9_]*)$/
|
|
4734
|
+
);
|
|
4735
|
+
if (aliasMatch) {
|
|
4736
|
+
const [, alias, name] = aliasMatch;
|
|
4737
|
+
const db2 = propToDb[name] ?? (dbNames.has(name) ? name : void 0);
|
|
4738
|
+
if (db2 !== void 0) {
|
|
4739
|
+
keyToDb[alias] = db2;
|
|
4740
|
+
return `${leadingWhitespace}${alias}:${db2}::jsonb`;
|
|
4741
|
+
}
|
|
4742
|
+
return col;
|
|
4743
|
+
}
|
|
4744
|
+
const db = propToDb[trimmed];
|
|
4745
|
+
if (db !== void 0) {
|
|
4746
|
+
keyToDb[trimmed] = db;
|
|
4747
|
+
return db === trimmed ? `${leadingWhitespace}${trimmed}::jsonb` : `${leadingWhitespace}${trimmed}:${db}::jsonb`;
|
|
4748
|
+
}
|
|
4749
|
+
if (dbNames.has(trimmed)) {
|
|
4750
|
+
keyToDb[trimmed] = trimmed;
|
|
4751
|
+
return `${leadingWhitespace}${trimmed}::jsonb`;
|
|
4752
|
+
}
|
|
4753
|
+
return col;
|
|
4754
|
+
}).join(",");
|
|
4755
|
+
return { select, keyToDb };
|
|
4756
|
+
}
|
|
664
4757
|
function mapFilterOpToQueryType(op) {
|
|
665
4758
|
switch (op) {
|
|
666
4759
|
case "eq":
|
|
@@ -1014,7 +5107,7 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1014
5107
|
result2.failure
|
|
1015
5108
|
);
|
|
1016
5109
|
}
|
|
1017
|
-
return
|
|
5110
|
+
return this.transformEncryptedMutationModels(result2.data);
|
|
1018
5111
|
}
|
|
1019
5112
|
const baseOp = this.encryptionClient.encryptModel(data, this.schema);
|
|
1020
5113
|
const op = this.lockContext ? baseOp.withLockContext(this.lockContext) : baseOp;
|
|
@@ -1029,7 +5122,20 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1029
5122
|
result.failure
|
|
1030
5123
|
);
|
|
1031
5124
|
}
|
|
1032
|
-
return
|
|
5125
|
+
return this.transformEncryptedMutationModel(result.data);
|
|
5126
|
+
}
|
|
5127
|
+
/**
|
|
5128
|
+
* Encode an encrypted model for the Supabase request body. v2 wraps each
|
|
5129
|
+
* encrypted value in the `{ data: ... }` object expected by the
|
|
5130
|
+
* `eql_v2_encrypted` composite type. The v3 dialect overrides this — native
|
|
5131
|
+
* `eql_v3.*` domains are plain jsonb, so the raw payload is sent instead
|
|
5132
|
+
* (keyed by DB column name).
|
|
5133
|
+
*/
|
|
5134
|
+
transformEncryptedMutationModel(model) {
|
|
5135
|
+
return modelToEncryptedPgComposites(model);
|
|
5136
|
+
}
|
|
5137
|
+
transformEncryptedMutationModels(models) {
|
|
5138
|
+
return bulkModelsToEncryptedPgComposites(models);
|
|
1033
5139
|
}
|
|
1034
5140
|
// ---------------------------------------------------------------------------
|
|
1035
5141
|
// Step 2: Build select string with casts
|
|
@@ -1062,7 +5168,6 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1062
5168
|
termMap.push({ source: "filter", filterIndex: i, inIndex: j });
|
|
1063
5169
|
}
|
|
1064
5170
|
} else if (f.op === "is") {
|
|
1065
|
-
continue;
|
|
1066
5171
|
} else {
|
|
1067
5172
|
terms.push({
|
|
1068
5173
|
value: f.value,
|
|
@@ -1162,6 +5267,17 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1162
5267
|
if (terms.length === 0) {
|
|
1163
5268
|
return { encryptedValues: [], termMap: [] };
|
|
1164
5269
|
}
|
|
5270
|
+
const encryptedValues = await this.encryptCollectedTerms(terms);
|
|
5271
|
+
return { encryptedValues, termMap };
|
|
5272
|
+
}
|
|
5273
|
+
/**
|
|
5274
|
+
* Encrypt the collected filter terms, returning one encoded value per term
|
|
5275
|
+
* (in order). v2 batch-encrypts via `encryptQuery` with the
|
|
5276
|
+
* `composite-literal` return type — the `("json")` string the
|
|
5277
|
+
* `eql_v2_encrypted` composite operators compare. The v3 dialect overrides
|
|
5278
|
+
* this to produce full-envelope jsonb operands instead.
|
|
5279
|
+
*/
|
|
5280
|
+
async encryptCollectedTerms(terms) {
|
|
1165
5281
|
const baseOp = this.encryptionClient.encryptQuery(terms);
|
|
1166
5282
|
const op = this.lockContext ? baseOp.withLockContext(this.lockContext) : baseOp;
|
|
1167
5283
|
if (this.auditConfig) op.audit(this.auditConfig);
|
|
@@ -1175,7 +5291,7 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1175
5291
|
result.failure
|
|
1176
5292
|
);
|
|
1177
5293
|
}
|
|
1178
|
-
return
|
|
5294
|
+
return result.data;
|
|
1179
5295
|
}
|
|
1180
5296
|
// ---------------------------------------------------------------------------
|
|
1181
5297
|
// Step 4: Build and execute real Supabase query
|
|
@@ -1295,36 +5411,36 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1295
5411
|
return filterInMap.has(key) ? filterInMap.get(key) : v;
|
|
1296
5412
|
});
|
|
1297
5413
|
}
|
|
5414
|
+
const column = this.filterColumnName(f.column);
|
|
5415
|
+
const wasEncrypted = filterValueMap.has(i);
|
|
1298
5416
|
switch (f.op) {
|
|
1299
5417
|
case "eq":
|
|
1300
|
-
q = q.eq(
|
|
5418
|
+
q = q.eq(column, value);
|
|
1301
5419
|
break;
|
|
1302
5420
|
case "neq":
|
|
1303
|
-
q = q.neq(
|
|
5421
|
+
q = q.neq(column, value);
|
|
1304
5422
|
break;
|
|
1305
5423
|
case "gt":
|
|
1306
|
-
q = q.gt(
|
|
5424
|
+
q = q.gt(column, value);
|
|
1307
5425
|
break;
|
|
1308
5426
|
case "gte":
|
|
1309
|
-
q = q.gte(
|
|
5427
|
+
q = q.gte(column, value);
|
|
1310
5428
|
break;
|
|
1311
5429
|
case "lt":
|
|
1312
|
-
q = q.lt(
|
|
5430
|
+
q = q.lt(column, value);
|
|
1313
5431
|
break;
|
|
1314
5432
|
case "lte":
|
|
1315
|
-
q = q.lte(
|
|
5433
|
+
q = q.lte(column, value);
|
|
1316
5434
|
break;
|
|
1317
5435
|
case "like":
|
|
1318
|
-
q = q.like(f.column, value);
|
|
1319
|
-
break;
|
|
1320
5436
|
case "ilike":
|
|
1321
|
-
q =
|
|
5437
|
+
q = this.applyPatternFilter(q, column, f.op, value, wasEncrypted);
|
|
1322
5438
|
break;
|
|
1323
5439
|
case "is":
|
|
1324
|
-
q = q.is(
|
|
5440
|
+
q = q.is(column, value);
|
|
1325
5441
|
break;
|
|
1326
5442
|
case "in":
|
|
1327
|
-
q = q.in(
|
|
5443
|
+
q = q.in(column, value);
|
|
1328
5444
|
break;
|
|
1329
5445
|
}
|
|
1330
5446
|
}
|
|
@@ -1333,53 +5449,113 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1333
5449
|
const resolvedQuery = {};
|
|
1334
5450
|
for (const [colName, originalValue] of Object.entries(mf.query)) {
|
|
1335
5451
|
const key = `${i}:${colName}`;
|
|
1336
|
-
resolvedQuery[colName] = matchValueMap.has(key) ? matchValueMap.get(key) : originalValue;
|
|
5452
|
+
resolvedQuery[this.filterColumnName(colName)] = matchValueMap.has(key) ? matchValueMap.get(key) : originalValue;
|
|
1337
5453
|
}
|
|
1338
5454
|
q = q.match(resolvedQuery);
|
|
1339
5455
|
}
|
|
1340
5456
|
for (let i = 0; i < this.notFilters.length; i++) {
|
|
1341
5457
|
const nf = this.notFilters[i];
|
|
1342
|
-
const
|
|
1343
|
-
|
|
5458
|
+
const wasEncrypted = notValueMap.has(i);
|
|
5459
|
+
const value = wasEncrypted ? notValueMap.get(i) : nf.value;
|
|
5460
|
+
q = q.not(
|
|
5461
|
+
this.filterColumnName(nf.column),
|
|
5462
|
+
this.notFilterOperator(nf.op, wasEncrypted),
|
|
5463
|
+
value
|
|
5464
|
+
);
|
|
1344
5465
|
}
|
|
1345
5466
|
for (let i = 0; i < this.orFilters.length; i++) {
|
|
1346
5467
|
const of_ = this.orFilters[i];
|
|
1347
5468
|
if (of_.kind === "string") {
|
|
1348
5469
|
const parsed = parseOrString(of_.value);
|
|
1349
|
-
|
|
5470
|
+
const encryptedIndexes = /* @__PURE__ */ new Set();
|
|
1350
5471
|
for (let j = 0; j < parsed.length; j++) {
|
|
1351
5472
|
const key = `${i}:${j}`;
|
|
1352
5473
|
if (orStringConditionMap.has(key)) {
|
|
1353
5474
|
parsed[j] = { ...parsed[j], value: orStringConditionMap.get(key) };
|
|
1354
|
-
|
|
5475
|
+
encryptedIndexes.add(j);
|
|
1355
5476
|
}
|
|
1356
5477
|
}
|
|
1357
|
-
if (
|
|
1358
|
-
q = q.or(
|
|
1359
|
-
|
|
1360
|
-
|
|
5478
|
+
if (encryptedIndexes.size > 0) {
|
|
5479
|
+
q = q.or(
|
|
5480
|
+
rebuildOrString(
|
|
5481
|
+
this.transformOrConditions(parsed, encryptedIndexes)
|
|
5482
|
+
),
|
|
5483
|
+
{
|
|
5484
|
+
referencedTable: of_.referencedTable
|
|
5485
|
+
}
|
|
5486
|
+
);
|
|
1361
5487
|
} else {
|
|
1362
5488
|
q = q.or(of_.value, { referencedTable: of_.referencedTable });
|
|
1363
5489
|
}
|
|
1364
5490
|
} else {
|
|
5491
|
+
const encryptedIndexes = /* @__PURE__ */ new Set();
|
|
1365
5492
|
const conditions = of_.conditions.map((cond, j) => {
|
|
1366
5493
|
const key = `${i}:${j}`;
|
|
1367
5494
|
if (orStructuredConditionMap.has(key)) {
|
|
5495
|
+
encryptedIndexes.add(j);
|
|
1368
5496
|
return { ...cond, value: orStructuredConditionMap.get(key) };
|
|
1369
5497
|
}
|
|
1370
5498
|
return cond;
|
|
1371
5499
|
});
|
|
1372
|
-
q = q.or(
|
|
5500
|
+
q = q.or(
|
|
5501
|
+
rebuildOrString(
|
|
5502
|
+
this.transformOrConditions(conditions, encryptedIndexes)
|
|
5503
|
+
)
|
|
5504
|
+
);
|
|
1373
5505
|
}
|
|
1374
5506
|
}
|
|
1375
5507
|
for (let i = 0; i < this.rawFilters.length; i++) {
|
|
1376
5508
|
const rf = this.rawFilters[i];
|
|
1377
5509
|
const value = rawValueMap.has(i) ? rawValueMap.get(i) : rf.value;
|
|
1378
|
-
q = q.filter(rf.column, rf.operator, value);
|
|
5510
|
+
q = q.filter(this.filterColumnName(rf.column), rf.operator, value);
|
|
1379
5511
|
}
|
|
1380
5512
|
return q;
|
|
1381
5513
|
}
|
|
1382
5514
|
// ---------------------------------------------------------------------------
|
|
5515
|
+
// Dialect seams — every default preserves the v2 behaviour byte-for-byte.
|
|
5516
|
+
// The v3 builder (see ./query-builder-v3) overrides these for native
|
|
5517
|
+
// `eql_v3.*` domain columns.
|
|
5518
|
+
// ---------------------------------------------------------------------------
|
|
5519
|
+
/**
|
|
5520
|
+
* Map a filter's column name to the DB column name PostgREST must see.
|
|
5521
|
+
* v2 schemas key columns by their DB name already, so this is the identity;
|
|
5522
|
+
* the v3 dialect resolves a JS property name to its DB name.
|
|
5523
|
+
*/
|
|
5524
|
+
filterColumnName(column) {
|
|
5525
|
+
return column;
|
|
5526
|
+
}
|
|
5527
|
+
/**
|
|
5528
|
+
* Apply a `like`/`ilike` filter. v2 relies on the `~~` operator defined on
|
|
5529
|
+
* `eql_v2_encrypted`; the v3 dialect overrides this for encrypted columns
|
|
5530
|
+
* because the `eql_v3.*` domains expose free-text match via `@>`
|
|
5531
|
+
* (PostgREST `cs`) rather than a LIKE operator.
|
|
5532
|
+
*/
|
|
5533
|
+
applyPatternFilter(q, column, op, value, _wasEncrypted) {
|
|
5534
|
+
return op === "like" ? q.like(column, value) : q.ilike(column, value);
|
|
5535
|
+
}
|
|
5536
|
+
/**
|
|
5537
|
+
* The PostgREST operator to use for a `.not()` filter. The v3 dialect maps
|
|
5538
|
+
* `like`/`ilike` on encrypted columns to `cs` (see applyPatternFilter).
|
|
5539
|
+
*/
|
|
5540
|
+
notFilterOperator(op, _wasEncrypted) {
|
|
5541
|
+
return op;
|
|
5542
|
+
}
|
|
5543
|
+
/**
|
|
5544
|
+
* Transform `.or()` conditions before the or-string is rebuilt. The v3
|
|
5545
|
+
* dialect maps property names to DB names and `like`/`ilike` on encrypted
|
|
5546
|
+
* conditions to `cs`.
|
|
5547
|
+
*/
|
|
5548
|
+
transformOrConditions(conditions, _encryptedIndexes) {
|
|
5549
|
+
return conditions;
|
|
5550
|
+
}
|
|
5551
|
+
/**
|
|
5552
|
+
* Post-process a decrypted result row. The v3 dialect reconstructs `Date`
|
|
5553
|
+
* values from the encrypt-config `cast_as`; v2 returns rows unchanged.
|
|
5554
|
+
*/
|
|
5555
|
+
postprocessDecryptedRow(row) {
|
|
5556
|
+
return row;
|
|
5557
|
+
}
|
|
5558
|
+
// ---------------------------------------------------------------------------
|
|
1383
5559
|
// Step 5: Decrypt results
|
|
1384
5560
|
// ---------------------------------------------------------------------------
|
|
1385
5561
|
async decryptResults(result) {
|
|
@@ -1443,7 +5619,9 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1443
5619
|
);
|
|
1444
5620
|
}
|
|
1445
5621
|
return {
|
|
1446
|
-
data:
|
|
5622
|
+
data: this.postprocessDecryptedRow(
|
|
5623
|
+
decrypted2.data
|
|
5624
|
+
),
|
|
1447
5625
|
error: null,
|
|
1448
5626
|
count: result.count ?? null,
|
|
1449
5627
|
status: result.status,
|
|
@@ -1474,7 +5652,9 @@ var EncryptedQueryBuilderImpl = class {
|
|
|
1474
5652
|
);
|
|
1475
5653
|
}
|
|
1476
5654
|
return {
|
|
1477
|
-
data: decrypted.data
|
|
5655
|
+
data: decrypted.data.map(
|
|
5656
|
+
(row) => this.postprocessDecryptedRow(row)
|
|
5657
|
+
),
|
|
1478
5658
|
error: null,
|
|
1479
5659
|
count: result.count ?? null,
|
|
1480
5660
|
status: result.status,
|
|
@@ -1505,6 +5685,237 @@ var EncryptionFailedError = class extends Error {
|
|
|
1505
5685
|
}
|
|
1506
5686
|
};
|
|
1507
5687
|
|
|
5688
|
+
// src/eql/v3/columns.ts
|
|
5689
|
+
function indexesForCapabilities(capabilities, castAs) {
|
|
5690
|
+
const indexes = {};
|
|
5691
|
+
if (capabilities.equality && (!capabilities.orderAndRange || castAs === "string")) {
|
|
5692
|
+
indexes.unique = { token_filters: [] };
|
|
5693
|
+
}
|
|
5694
|
+
if (capabilities.orderAndRange) {
|
|
5695
|
+
indexes.ore = {};
|
|
5696
|
+
}
|
|
5697
|
+
if (capabilities.freeTextSearch) {
|
|
5698
|
+
indexes.match = defaultMatchOpts();
|
|
5699
|
+
}
|
|
5700
|
+
return indexes;
|
|
5701
|
+
}
|
|
5702
|
+
function isQueryableCapabilities(capabilities) {
|
|
5703
|
+
return capabilities.equality || capabilities.orderAndRange || capabilities.freeTextSearch;
|
|
5704
|
+
}
|
|
5705
|
+
var EncryptedV3Column = class {
|
|
5706
|
+
constructor(columnName, definition) {
|
|
5707
|
+
this.columnName = columnName;
|
|
5708
|
+
this.definition = definition;
|
|
5709
|
+
}
|
|
5710
|
+
columnName;
|
|
5711
|
+
definition;
|
|
5712
|
+
getName() {
|
|
5713
|
+
return this.columnName;
|
|
5714
|
+
}
|
|
5715
|
+
/** The concrete EQL v3 domain name. Metadata only; not emitted by `build()`. */
|
|
5716
|
+
getEqlType() {
|
|
5717
|
+
return this.definition.eqlType;
|
|
5718
|
+
}
|
|
5719
|
+
/** The semantic query capabilities this domain exposes. Metadata only. */
|
|
5720
|
+
getQueryCapabilities() {
|
|
5721
|
+
return this.definition.capabilities;
|
|
5722
|
+
}
|
|
5723
|
+
/** `true` when this domain can produce at least one kind of query term. */
|
|
5724
|
+
isQueryable() {
|
|
5725
|
+
return isQueryableCapabilities(
|
|
5726
|
+
this.definition.capabilities
|
|
5727
|
+
);
|
|
5728
|
+
}
|
|
5729
|
+
/** Emit the encrypt-config column: `cast_as` plus capability-derived indexes. */
|
|
5730
|
+
build() {
|
|
5731
|
+
return {
|
|
5732
|
+
cast_as: this.definition.castAs,
|
|
5733
|
+
indexes: indexesForCapabilities(
|
|
5734
|
+
this.definition.capabilities,
|
|
5735
|
+
this.definition.castAs
|
|
5736
|
+
)
|
|
5737
|
+
};
|
|
5738
|
+
}
|
|
5739
|
+
};
|
|
5740
|
+
|
|
5741
|
+
// src/supabase/query-builder-v3.ts
|
|
5742
|
+
var EncryptedQueryBuilderV3Impl = class extends EncryptedQueryBuilderImpl {
|
|
5743
|
+
v3Table;
|
|
5744
|
+
/** JS property name → DB column name, for every encrypted column. */
|
|
5745
|
+
propToDb;
|
|
5746
|
+
/** Built column schemas keyed by DB column name (for `cast_as`). */
|
|
5747
|
+
columnSchemas;
|
|
5748
|
+
/** Column builders keyed by BOTH property name and DB name. */
|
|
5749
|
+
v3Columns;
|
|
5750
|
+
/**
|
|
5751
|
+
* Result-row key → DB column name for the columns the current select
|
|
5752
|
+
* produces, including user-chosen PostgREST aliases (`ts:created_at` keys
|
|
5753
|
+
* rows by `ts`). Populated by {@link buildSelectString}; consumed by
|
|
5754
|
+
* {@link postprocessDecryptedRow} so aliased date columns still get `Date`
|
|
5755
|
+
* reconstruction.
|
|
5756
|
+
*/
|
|
5757
|
+
selectKeyToDb = {};
|
|
5758
|
+
constructor(tableName, table, encryptionClient, supabaseClient) {
|
|
5759
|
+
super(
|
|
5760
|
+
tableName,
|
|
5761
|
+
// The base class only ever calls BuildableTable members on the schema
|
|
5762
|
+
// (build / encryptModel plumbing); every v2-specific behaviour is
|
|
5763
|
+
// overridden below.
|
|
5764
|
+
table,
|
|
5765
|
+
encryptionClient,
|
|
5766
|
+
supabaseClient
|
|
5767
|
+
);
|
|
5768
|
+
this.v3Table = table;
|
|
5769
|
+
this.propToDb = table.buildColumnKeyMap();
|
|
5770
|
+
this.columnSchemas = table.build().columns;
|
|
5771
|
+
this.v3Columns = {};
|
|
5772
|
+
for (const [property, builder] of Object.entries(table.columnBuilders)) {
|
|
5773
|
+
if (builder instanceof EncryptedV3Column) {
|
|
5774
|
+
const col = builder;
|
|
5775
|
+
this.v3Columns[property] = col;
|
|
5776
|
+
this.v3Columns[col.getName()] = col;
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5779
|
+
this.encryptedColumnNames = Object.keys(this.v3Columns);
|
|
5780
|
+
}
|
|
5781
|
+
// ---------------------------------------------------------------------------
|
|
5782
|
+
// Dialect overrides
|
|
5783
|
+
// ---------------------------------------------------------------------------
|
|
5784
|
+
getColumnMap() {
|
|
5785
|
+
return this.v3Columns;
|
|
5786
|
+
}
|
|
5787
|
+
filterColumnName(column) {
|
|
5788
|
+
return this.propToDb[column] ?? column;
|
|
5789
|
+
}
|
|
5790
|
+
buildSelectString() {
|
|
5791
|
+
if (this.selectColumns === null) return null;
|
|
5792
|
+
const { select, keyToDb } = addJsonbCastsV3(
|
|
5793
|
+
this.selectColumns,
|
|
5794
|
+
this.propToDb
|
|
5795
|
+
);
|
|
5796
|
+
this.selectKeyToDb = keyToDb;
|
|
5797
|
+
return select;
|
|
5798
|
+
}
|
|
5799
|
+
/** v3 domains are plain jsonb — send the raw payload, keyed by DB name. */
|
|
5800
|
+
transformEncryptedMutationModel(model) {
|
|
5801
|
+
const out = {};
|
|
5802
|
+
for (const [key, value] of Object.entries(model)) {
|
|
5803
|
+
out[this.propToDb[key] ?? key] = value;
|
|
5804
|
+
}
|
|
5805
|
+
return out;
|
|
5806
|
+
}
|
|
5807
|
+
transformEncryptedMutationModels(models) {
|
|
5808
|
+
return models.map((model) => this.transformEncryptedMutationModel(model));
|
|
5809
|
+
}
|
|
5810
|
+
/**
|
|
5811
|
+
* Encrypt every filter operand as a full storage envelope (see the class
|
|
5812
|
+
* doc for why `encryptQuery` terms cannot be used), serialized to jsonb
|
|
5813
|
+
* text for the PostgREST filter value.
|
|
5814
|
+
*
|
|
5815
|
+
* INTERIM + single swap point. The full-envelope operand is a tracked
|
|
5816
|
+
* workaround (Linear CIP-3402), not the design: it carries a real
|
|
5817
|
+
* decryptable ciphertext `c` plus ALL of the column's index terms, and
|
|
5818
|
+
* PostgREST filters travel in GET query strings — so operands can land in
|
|
5819
|
+
* URL logs, proxies, and Supabase request logs (query terms are meant to
|
|
5820
|
+
* be index-terms-only). When the EQL term-only scalar query envelope (the
|
|
5821
|
+
* scalar analog of `eql_v3.jsonb_query`) ships, swapping the encryption
|
|
5822
|
+
* call inside THIS method — and its `JSON.stringify` wire encoding — must
|
|
5823
|
+
* be the ONLY change needed: every consuming seam (filter application,
|
|
5824
|
+
* `or`/`not` transforms, the wire-operator remap) treats the returned
|
|
5825
|
+
* operand as an opaque, already-encoded string and is encoding-agnostic.
|
|
5826
|
+
* Do not let operand-encoding knowledge leak out of this method.
|
|
5827
|
+
*/
|
|
5828
|
+
async encryptCollectedTerms(terms) {
|
|
5829
|
+
return Promise.all(
|
|
5830
|
+
terms.map(async (term) => {
|
|
5831
|
+
const column = term.column;
|
|
5832
|
+
const queryType = term.queryType ?? "equality";
|
|
5833
|
+
const capabilities = column.getQueryCapabilities();
|
|
5834
|
+
if (term.value == null) {
|
|
5835
|
+
throw new Error(
|
|
5836
|
+
`[supabase v3]: cannot encrypt a null filter value for column "${column.getName()}" \u2014 use .is('${column.getName()}', null) for NULL checks`
|
|
5837
|
+
);
|
|
5838
|
+
}
|
|
5839
|
+
if (queryType !== "equality" && queryType !== "orderAndRange" && queryType !== "freeTextSearch") {
|
|
5840
|
+
throw new Error(
|
|
5841
|
+
`[supabase v3]: query type "${queryType}" is not supported on scalar eql_v3 columns`
|
|
5842
|
+
);
|
|
5843
|
+
}
|
|
5844
|
+
if (!capabilities[queryType]) {
|
|
5845
|
+
throw new Error(
|
|
5846
|
+
`[supabase v3]: column "${column.getName()}" (${column.getEqlType()}) does not support ${queryType} queries \u2014 declare the column with a domain that carries that capability`
|
|
5847
|
+
);
|
|
5848
|
+
}
|
|
5849
|
+
const baseOp = this.encryptionClient.encrypt(term.value, {
|
|
5850
|
+
column,
|
|
5851
|
+
table: this.v3Table
|
|
5852
|
+
});
|
|
5853
|
+
const op = this.lockContext ? baseOp.withLockContext(this.lockContext) : baseOp;
|
|
5854
|
+
if (this.auditConfig) op.audit(this.auditConfig);
|
|
5855
|
+
const result = await op;
|
|
5856
|
+
if (result.failure) {
|
|
5857
|
+
logger.error(
|
|
5858
|
+
`Supabase: failed to encrypt query terms for table "${this.tableName}"`
|
|
5859
|
+
);
|
|
5860
|
+
throw new EncryptionFailedError(
|
|
5861
|
+
`Failed to encrypt query terms: ${result.failure.message}`,
|
|
5862
|
+
result.failure
|
|
5863
|
+
);
|
|
5864
|
+
}
|
|
5865
|
+
return JSON.stringify(result.data);
|
|
5866
|
+
})
|
|
5867
|
+
);
|
|
5868
|
+
}
|
|
5869
|
+
/**
|
|
5870
|
+
* The single source of the encrypted wire-operator remap: `like`/`ilike`
|
|
5871
|
+
* on an encrypted column become PostgREST `cs` (bloom-filter `@>`) — the
|
|
5872
|
+
* `eql_v3.*` domains define no LIKE operator. Every pattern-bearing seam
|
|
5873
|
+
* (`applyPatternFilter`, `notFilterOperator`, `transformOrConditions`)
|
|
5874
|
+
* derives its operator here so they cannot drift apart.
|
|
5875
|
+
*/
|
|
5876
|
+
encryptedFilterOp(op, wasEncrypted) {
|
|
5877
|
+
return wasEncrypted && (op === "like" || op === "ilike") ? "cs" : op;
|
|
5878
|
+
}
|
|
5879
|
+
/** Encrypted pattern filters go through the bloom-filter `@>` (`cs`). */
|
|
5880
|
+
applyPatternFilter(q, column, op, value, wasEncrypted) {
|
|
5881
|
+
const wireOp = this.encryptedFilterOp(op, wasEncrypted);
|
|
5882
|
+
if (wireOp !== op) {
|
|
5883
|
+
return q.filter(column, wireOp, value);
|
|
5884
|
+
}
|
|
5885
|
+
return super.applyPatternFilter(q, column, op, value, wasEncrypted);
|
|
5886
|
+
}
|
|
5887
|
+
notFilterOperator(op, wasEncrypted) {
|
|
5888
|
+
return this.encryptedFilterOp(op, wasEncrypted);
|
|
5889
|
+
}
|
|
5890
|
+
transformOrConditions(conditions, encryptedIndexes) {
|
|
5891
|
+
return conditions.map((cond, j) => ({
|
|
5892
|
+
...cond,
|
|
5893
|
+
column: this.filterColumnName(cond.column),
|
|
5894
|
+
op: this.encryptedFilterOp(cond.op, encryptedIndexes.has(j))
|
|
5895
|
+
}));
|
|
5896
|
+
}
|
|
5897
|
+
/** Rebuild `Date` values from the encrypt-config `cast_as`, mirroring the
|
|
5898
|
+
* typed v3 client's decrypt-model path. */
|
|
5899
|
+
postprocessDecryptedRow(row) {
|
|
5900
|
+
const keyToDb = { ...this.selectKeyToDb };
|
|
5901
|
+
for (const [property, dbName] of Object.entries(this.propToDb)) {
|
|
5902
|
+
keyToDb[property] ??= dbName;
|
|
5903
|
+
keyToDb[dbName] ??= dbName;
|
|
5904
|
+
}
|
|
5905
|
+
const out = { ...row };
|
|
5906
|
+
for (const [key, dbName] of Object.entries(keyToDb)) {
|
|
5907
|
+
const castAs = this.columnSchemas[dbName]?.cast_as;
|
|
5908
|
+
if (castAs !== "date" && castAs !== "timestamp") continue;
|
|
5909
|
+
const value = out[key];
|
|
5910
|
+
if (value == null || value instanceof Date) continue;
|
|
5911
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
5912
|
+
out[key] = new Date(value);
|
|
5913
|
+
}
|
|
5914
|
+
}
|
|
5915
|
+
return out;
|
|
5916
|
+
}
|
|
5917
|
+
};
|
|
5918
|
+
|
|
1508
5919
|
// src/supabase/index.ts
|
|
1509
5920
|
function encryptedSupabase(config) {
|
|
1510
5921
|
const { encryptionClient, supabaseClient } = config;
|
|
@@ -1519,8 +5930,22 @@ function encryptedSupabase(config) {
|
|
|
1519
5930
|
}
|
|
1520
5931
|
};
|
|
1521
5932
|
}
|
|
5933
|
+
function encryptedSupabaseV3(config) {
|
|
5934
|
+
const { encryptionClient, supabaseClient } = config;
|
|
5935
|
+
return {
|
|
5936
|
+
from(tableName, table) {
|
|
5937
|
+
return new EncryptedQueryBuilderV3Impl(
|
|
5938
|
+
tableName,
|
|
5939
|
+
table,
|
|
5940
|
+
encryptionClient,
|
|
5941
|
+
supabaseClient
|
|
5942
|
+
);
|
|
5943
|
+
}
|
|
5944
|
+
};
|
|
5945
|
+
}
|
|
1522
5946
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1523
5947
|
0 && (module.exports = {
|
|
1524
|
-
encryptedSupabase
|
|
5948
|
+
encryptedSupabase,
|
|
5949
|
+
encryptedSupabaseV3
|
|
1525
5950
|
});
|
|
1526
5951
|
//# sourceMappingURL=index.cjs.map
|