@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.
Files changed (102) hide show
  1. package/CHANGELOG.md +225 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-CY5B4LIF.js → chunk-36AA7IBJ.js} +303 -204
  4. package/dist/chunk-36AA7IBJ.js.map +1 -0
  5. package/dist/{chunk-MD6742R6.js → chunk-4AVL4VZD.js} +1 -1
  6. package/dist/chunk-4AVL4VZD.js.map +1 -0
  7. package/dist/{chunk-4RNBI3UH.js → chunk-BNO32ZMV.js} +1 -1
  8. package/dist/chunk-BNO32ZMV.js.map +1 -0
  9. package/dist/{chunk-6FD7OBGM.js → chunk-HQANMV7R.js} +3 -3
  10. package/dist/chunk-HQANMV7R.js.map +1 -0
  11. package/dist/chunk-IADZCZEA.js +23 -0
  12. package/dist/chunk-IADZCZEA.js.map +1 -0
  13. package/dist/chunk-IBSK6P33.js +209 -0
  14. package/dist/chunk-IBSK6P33.js.map +1 -0
  15. package/dist/chunk-JSG2AMDI.js +17 -0
  16. package/dist/chunk-JSG2AMDI.js.map +1 -0
  17. package/dist/chunk-MP3SSDNN.js +4439 -0
  18. package/dist/chunk-MP3SSDNN.js.map +1 -0
  19. package/dist/chunk-OFQ555AX.js +191 -0
  20. package/dist/chunk-OFQ555AX.js.map +1 -0
  21. package/dist/chunk-PZ5AY32C.js +10 -0
  22. package/dist/chunk-PZ5AY32C.js.map +1 -0
  23. package/dist/chunk-U66S7VIF.js +435 -0
  24. package/dist/chunk-U66S7VIF.js.map +1 -0
  25. package/dist/{client-C_7TF8EL.d.cts → client-DSGHBN-g.d.cts} +209 -72
  26. package/dist/{client-BLbA6aFD.d.ts → client-DfCrlHXh.d.ts} +209 -72
  27. package/dist/client.cjs +4103 -43
  28. package/dist/client.cjs.map +1 -1
  29. package/dist/client.d.cts +5 -5
  30. package/dist/client.d.ts +5 -5
  31. package/dist/client.js +3 -1
  32. package/dist/drizzle/index.cjs +4139 -77
  33. package/dist/drizzle/index.cjs.map +1 -1
  34. package/dist/drizzle/index.d.cts +33 -33
  35. package/dist/drizzle/index.d.ts +33 -33
  36. package/dist/drizzle/index.js +39 -33
  37. package/dist/drizzle/index.js.map +1 -1
  38. package/dist/dynamodb/index.cjs +31 -14
  39. package/dist/dynamodb/index.cjs.map +1 -1
  40. package/dist/dynamodb/index.d.cts +12 -12
  41. package/dist/dynamodb/index.d.ts +12 -12
  42. package/dist/dynamodb/index.js +16 -12
  43. package/dist/dynamodb/index.js.map +1 -1
  44. package/dist/encryption/index.cjs +4611 -257
  45. package/dist/encryption/index.cjs.map +1 -1
  46. package/dist/encryption/index.d.cts +3 -3
  47. package/dist/encryption/index.d.ts +3 -3
  48. package/dist/encryption/index.js +35 -7
  49. package/dist/encryption/v3.cjs +7791 -0
  50. package/dist/encryption/v3.cjs.map +1 -0
  51. package/dist/encryption/v3.d.cts +100 -0
  52. package/dist/encryption/v3.d.ts +100 -0
  53. package/dist/encryption/v3.js +161 -0
  54. package/dist/encryption/v3.js.map +1 -0
  55. package/dist/eql/v3/index.cjs +612 -0
  56. package/dist/eql/v3/index.cjs.map +1 -0
  57. package/dist/eql/v3/index.d.cts +71 -0
  58. package/dist/eql/v3/index.d.ts +71 -0
  59. package/dist/eql/v3/index.js +89 -0
  60. package/dist/eql/v3/index.js.map +1 -0
  61. package/dist/errors/index.js +1 -0
  62. package/dist/identity/index.cjs +55 -35
  63. package/dist/identity/index.cjs.map +1 -1
  64. package/dist/identity/index.d.cts +54 -30
  65. package/dist/identity/index.d.ts +54 -30
  66. package/dist/identity/index.js +9 -177
  67. package/dist/identity/index.js.map +1 -1
  68. package/dist/index.cjs +4625 -273
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.cts +18 -7
  71. package/dist/index.d.ts +18 -7
  72. package/dist/index.js +20 -5
  73. package/dist/index.js.map +1 -1
  74. package/dist/schema/index.cjs +4108 -44
  75. package/dist/schema/index.cjs.map +1 -1
  76. package/dist/schema/index.d.cts +1 -1
  77. package/dist/schema/index.d.ts +1 -1
  78. package/dist/schema/index.js +3 -1
  79. package/dist/supabase/index.cjs +4500 -75
  80. package/dist/supabase/index.cjs.map +1 -1
  81. package/dist/supabase/index.d.cts +113 -34
  82. package/dist/supabase/index.d.ts +113 -34
  83. package/dist/supabase/index.js +350 -32
  84. package/dist/supabase/index.js.map +1 -1
  85. package/dist/table-CIH7jZ2h.d.ts +603 -0
  86. package/dist/table-DihEAlxG.d.cts +603 -0
  87. package/dist/{types-public-Dv-r6Ik0.d.ts → types-public-CpS5KjwX.d.cts} +209 -36
  88. package/dist/{types-public-Dv-r6Ik0.d.cts → types-public-CpS5KjwX.d.ts} +209 -36
  89. package/dist/types-public.cjs.map +1 -1
  90. package/dist/types-public.d.cts +2 -2
  91. package/dist/types-public.d.ts +2 -2
  92. package/dist/types-public.js +2 -1
  93. package/dist/wasm-inline.d.ts +1269 -0
  94. package/dist/wasm-inline.js +4594 -0
  95. package/dist/wasm-inline.js.map +1 -0
  96. package/package.json +63 -13
  97. package/dist/chunk-4RNBI3UH.js.map +0 -1
  98. package/dist/chunk-6FD7OBGM.js.map +0 -1
  99. package/dist/chunk-CY5B4LIF.js.map +0 -1
  100. package/dist/chunk-JDZ2QUUF.js +0 -381
  101. package/dist/chunk-JDZ2QUUF.js.map +0 -1
  102. package/dist/chunk-MD6742R6.js.map +0 -1
@@ -0,0 +1,4594 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/wasm-inline.ts
8
+ import {
9
+ AccessKeyStrategy
10
+ } from "@cipherstash/auth/wasm-inline";
11
+ import {
12
+ decrypt as wasmDecrypt,
13
+ encrypt as wasmEncrypt,
14
+ isEncrypted as wasmIsEncrypted,
15
+ newClient as wasmNewClient
16
+ } from "@cipherstash/protect-ffi/wasm-inline";
17
+
18
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
19
+ var external_exports = {};
20
+ __export(external_exports, {
21
+ BRAND: () => BRAND,
22
+ DIRTY: () => DIRTY,
23
+ EMPTY_PATH: () => EMPTY_PATH,
24
+ INVALID: () => INVALID,
25
+ NEVER: () => NEVER,
26
+ OK: () => OK,
27
+ ParseStatus: () => ParseStatus,
28
+ Schema: () => ZodType,
29
+ ZodAny: () => ZodAny,
30
+ ZodArray: () => ZodArray,
31
+ ZodBigInt: () => ZodBigInt,
32
+ ZodBoolean: () => ZodBoolean,
33
+ ZodBranded: () => ZodBranded,
34
+ ZodCatch: () => ZodCatch,
35
+ ZodDate: () => ZodDate,
36
+ ZodDefault: () => ZodDefault,
37
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
38
+ ZodEffects: () => ZodEffects,
39
+ ZodEnum: () => ZodEnum,
40
+ ZodError: () => ZodError,
41
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
42
+ ZodFunction: () => ZodFunction,
43
+ ZodIntersection: () => ZodIntersection,
44
+ ZodIssueCode: () => ZodIssueCode,
45
+ ZodLazy: () => ZodLazy,
46
+ ZodLiteral: () => ZodLiteral,
47
+ ZodMap: () => ZodMap,
48
+ ZodNaN: () => ZodNaN,
49
+ ZodNativeEnum: () => ZodNativeEnum,
50
+ ZodNever: () => ZodNever,
51
+ ZodNull: () => ZodNull,
52
+ ZodNullable: () => ZodNullable,
53
+ ZodNumber: () => ZodNumber,
54
+ ZodObject: () => ZodObject,
55
+ ZodOptional: () => ZodOptional,
56
+ ZodParsedType: () => ZodParsedType,
57
+ ZodPipeline: () => ZodPipeline,
58
+ ZodPromise: () => ZodPromise,
59
+ ZodReadonly: () => ZodReadonly,
60
+ ZodRecord: () => ZodRecord,
61
+ ZodSchema: () => ZodType,
62
+ ZodSet: () => ZodSet,
63
+ ZodString: () => ZodString,
64
+ ZodSymbol: () => ZodSymbol,
65
+ ZodTransformer: () => ZodEffects,
66
+ ZodTuple: () => ZodTuple,
67
+ ZodType: () => ZodType,
68
+ ZodUndefined: () => ZodUndefined,
69
+ ZodUnion: () => ZodUnion,
70
+ ZodUnknown: () => ZodUnknown,
71
+ ZodVoid: () => ZodVoid,
72
+ addIssueToContext: () => addIssueToContext,
73
+ any: () => anyType,
74
+ array: () => arrayType,
75
+ bigint: () => bigIntType,
76
+ boolean: () => booleanType,
77
+ coerce: () => coerce,
78
+ custom: () => custom,
79
+ date: () => dateType,
80
+ datetimeRegex: () => datetimeRegex,
81
+ defaultErrorMap: () => en_default,
82
+ discriminatedUnion: () => discriminatedUnionType,
83
+ effect: () => effectsType,
84
+ enum: () => enumType,
85
+ function: () => functionType,
86
+ getErrorMap: () => getErrorMap,
87
+ getParsedType: () => getParsedType,
88
+ instanceof: () => instanceOfType,
89
+ intersection: () => intersectionType,
90
+ isAborted: () => isAborted,
91
+ isAsync: () => isAsync,
92
+ isDirty: () => isDirty,
93
+ isValid: () => isValid,
94
+ late: () => late,
95
+ lazy: () => lazyType,
96
+ literal: () => literalType,
97
+ makeIssue: () => makeIssue,
98
+ map: () => mapType,
99
+ nan: () => nanType,
100
+ nativeEnum: () => nativeEnumType,
101
+ never: () => neverType,
102
+ null: () => nullType,
103
+ nullable: () => nullableType,
104
+ number: () => numberType,
105
+ object: () => objectType,
106
+ objectUtil: () => objectUtil,
107
+ oboolean: () => oboolean,
108
+ onumber: () => onumber,
109
+ optional: () => optionalType,
110
+ ostring: () => ostring,
111
+ pipeline: () => pipelineType,
112
+ preprocess: () => preprocessType,
113
+ promise: () => promiseType,
114
+ quotelessJson: () => quotelessJson,
115
+ record: () => recordType,
116
+ set: () => setType,
117
+ setErrorMap: () => setErrorMap,
118
+ strictObject: () => strictObjectType,
119
+ string: () => stringType,
120
+ symbol: () => symbolType,
121
+ transformer: () => effectsType,
122
+ tuple: () => tupleType,
123
+ undefined: () => undefinedType,
124
+ union: () => unionType,
125
+ unknown: () => unknownType,
126
+ util: () => util,
127
+ void: () => voidType
128
+ });
129
+
130
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
131
+ var util;
132
+ (function(util2) {
133
+ util2.assertEqual = (_) => {
134
+ };
135
+ function assertIs(_arg) {
136
+ }
137
+ util2.assertIs = assertIs;
138
+ function assertNever(_x) {
139
+ throw new Error();
140
+ }
141
+ util2.assertNever = assertNever;
142
+ util2.arrayToEnum = (items) => {
143
+ const obj = {};
144
+ for (const item of items) {
145
+ obj[item] = item;
146
+ }
147
+ return obj;
148
+ };
149
+ util2.getValidEnumValues = (obj) => {
150
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
151
+ const filtered = {};
152
+ for (const k of validKeys) {
153
+ filtered[k] = obj[k];
154
+ }
155
+ return util2.objectValues(filtered);
156
+ };
157
+ util2.objectValues = (obj) => {
158
+ return util2.objectKeys(obj).map(function(e) {
159
+ return obj[e];
160
+ });
161
+ };
162
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
163
+ const keys = [];
164
+ for (const key in object) {
165
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
166
+ keys.push(key);
167
+ }
168
+ }
169
+ return keys;
170
+ };
171
+ util2.find = (arr, checker) => {
172
+ for (const item of arr) {
173
+ if (checker(item))
174
+ return item;
175
+ }
176
+ return void 0;
177
+ };
178
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
179
+ function joinValues(array, separator = " | ") {
180
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
181
+ }
182
+ util2.joinValues = joinValues;
183
+ util2.jsonStringifyReplacer = (_, value) => {
184
+ if (typeof value === "bigint") {
185
+ return value.toString();
186
+ }
187
+ return value;
188
+ };
189
+ })(util || (util = {}));
190
+ var objectUtil;
191
+ (function(objectUtil2) {
192
+ objectUtil2.mergeShapes = (first, second) => {
193
+ return {
194
+ ...first,
195
+ ...second
196
+ // second overwrites first
197
+ };
198
+ };
199
+ })(objectUtil || (objectUtil = {}));
200
+ var ZodParsedType = util.arrayToEnum([
201
+ "string",
202
+ "nan",
203
+ "number",
204
+ "integer",
205
+ "float",
206
+ "boolean",
207
+ "date",
208
+ "bigint",
209
+ "symbol",
210
+ "function",
211
+ "undefined",
212
+ "null",
213
+ "array",
214
+ "object",
215
+ "unknown",
216
+ "promise",
217
+ "void",
218
+ "never",
219
+ "map",
220
+ "set"
221
+ ]);
222
+ var getParsedType = (data) => {
223
+ const t = typeof data;
224
+ switch (t) {
225
+ case "undefined":
226
+ return ZodParsedType.undefined;
227
+ case "string":
228
+ return ZodParsedType.string;
229
+ case "number":
230
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
231
+ case "boolean":
232
+ return ZodParsedType.boolean;
233
+ case "function":
234
+ return ZodParsedType.function;
235
+ case "bigint":
236
+ return ZodParsedType.bigint;
237
+ case "symbol":
238
+ return ZodParsedType.symbol;
239
+ case "object":
240
+ if (Array.isArray(data)) {
241
+ return ZodParsedType.array;
242
+ }
243
+ if (data === null) {
244
+ return ZodParsedType.null;
245
+ }
246
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
247
+ return ZodParsedType.promise;
248
+ }
249
+ if (typeof Map !== "undefined" && data instanceof Map) {
250
+ return ZodParsedType.map;
251
+ }
252
+ if (typeof Set !== "undefined" && data instanceof Set) {
253
+ return ZodParsedType.set;
254
+ }
255
+ if (typeof Date !== "undefined" && data instanceof Date) {
256
+ return ZodParsedType.date;
257
+ }
258
+ return ZodParsedType.object;
259
+ default:
260
+ return ZodParsedType.unknown;
261
+ }
262
+ };
263
+
264
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
265
+ var ZodIssueCode = util.arrayToEnum([
266
+ "invalid_type",
267
+ "invalid_literal",
268
+ "custom",
269
+ "invalid_union",
270
+ "invalid_union_discriminator",
271
+ "invalid_enum_value",
272
+ "unrecognized_keys",
273
+ "invalid_arguments",
274
+ "invalid_return_type",
275
+ "invalid_date",
276
+ "invalid_string",
277
+ "too_small",
278
+ "too_big",
279
+ "invalid_intersection_types",
280
+ "not_multiple_of",
281
+ "not_finite"
282
+ ]);
283
+ var quotelessJson = (obj) => {
284
+ const json = JSON.stringify(obj, null, 2);
285
+ return json.replace(/"([^"]+)":/g, "$1:");
286
+ };
287
+ var ZodError = class _ZodError extends Error {
288
+ get errors() {
289
+ return this.issues;
290
+ }
291
+ constructor(issues) {
292
+ super();
293
+ this.issues = [];
294
+ this.addIssue = (sub) => {
295
+ this.issues = [...this.issues, sub];
296
+ };
297
+ this.addIssues = (subs = []) => {
298
+ this.issues = [...this.issues, ...subs];
299
+ };
300
+ const actualProto = new.target.prototype;
301
+ if (Object.setPrototypeOf) {
302
+ Object.setPrototypeOf(this, actualProto);
303
+ } else {
304
+ this.__proto__ = actualProto;
305
+ }
306
+ this.name = "ZodError";
307
+ this.issues = issues;
308
+ }
309
+ format(_mapper) {
310
+ const mapper = _mapper || function(issue) {
311
+ return issue.message;
312
+ };
313
+ const fieldErrors = { _errors: [] };
314
+ const processError = (error) => {
315
+ for (const issue of error.issues) {
316
+ if (issue.code === "invalid_union") {
317
+ issue.unionErrors.map(processError);
318
+ } else if (issue.code === "invalid_return_type") {
319
+ processError(issue.returnTypeError);
320
+ } else if (issue.code === "invalid_arguments") {
321
+ processError(issue.argumentsError);
322
+ } else if (issue.path.length === 0) {
323
+ fieldErrors._errors.push(mapper(issue));
324
+ } else {
325
+ let curr = fieldErrors;
326
+ let i = 0;
327
+ while (i < issue.path.length) {
328
+ const el = issue.path[i];
329
+ const terminal = i === issue.path.length - 1;
330
+ if (!terminal) {
331
+ curr[el] = curr[el] || { _errors: [] };
332
+ } else {
333
+ curr[el] = curr[el] || { _errors: [] };
334
+ curr[el]._errors.push(mapper(issue));
335
+ }
336
+ curr = curr[el];
337
+ i++;
338
+ }
339
+ }
340
+ }
341
+ };
342
+ processError(this);
343
+ return fieldErrors;
344
+ }
345
+ static assert(value) {
346
+ if (!(value instanceof _ZodError)) {
347
+ throw new Error(`Not a ZodError: ${value}`);
348
+ }
349
+ }
350
+ toString() {
351
+ return this.message;
352
+ }
353
+ get message() {
354
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
355
+ }
356
+ get isEmpty() {
357
+ return this.issues.length === 0;
358
+ }
359
+ flatten(mapper = (issue) => issue.message) {
360
+ const fieldErrors = {};
361
+ const formErrors = [];
362
+ for (const sub of this.issues) {
363
+ if (sub.path.length > 0) {
364
+ const firstEl = sub.path[0];
365
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
366
+ fieldErrors[firstEl].push(mapper(sub));
367
+ } else {
368
+ formErrors.push(mapper(sub));
369
+ }
370
+ }
371
+ return { formErrors, fieldErrors };
372
+ }
373
+ get formErrors() {
374
+ return this.flatten();
375
+ }
376
+ };
377
+ ZodError.create = (issues) => {
378
+ const error = new ZodError(issues);
379
+ return error;
380
+ };
381
+
382
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
383
+ var errorMap = (issue, _ctx) => {
384
+ let message;
385
+ switch (issue.code) {
386
+ case ZodIssueCode.invalid_type:
387
+ if (issue.received === ZodParsedType.undefined) {
388
+ message = "Required";
389
+ } else {
390
+ message = `Expected ${issue.expected}, received ${issue.received}`;
391
+ }
392
+ break;
393
+ case ZodIssueCode.invalid_literal:
394
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
395
+ break;
396
+ case ZodIssueCode.unrecognized_keys:
397
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
398
+ break;
399
+ case ZodIssueCode.invalid_union:
400
+ message = `Invalid input`;
401
+ break;
402
+ case ZodIssueCode.invalid_union_discriminator:
403
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
404
+ break;
405
+ case ZodIssueCode.invalid_enum_value:
406
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
407
+ break;
408
+ case ZodIssueCode.invalid_arguments:
409
+ message = `Invalid function arguments`;
410
+ break;
411
+ case ZodIssueCode.invalid_return_type:
412
+ message = `Invalid function return type`;
413
+ break;
414
+ case ZodIssueCode.invalid_date:
415
+ message = `Invalid date`;
416
+ break;
417
+ case ZodIssueCode.invalid_string:
418
+ if (typeof issue.validation === "object") {
419
+ if ("includes" in issue.validation) {
420
+ message = `Invalid input: must include "${issue.validation.includes}"`;
421
+ if (typeof issue.validation.position === "number") {
422
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
423
+ }
424
+ } else if ("startsWith" in issue.validation) {
425
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
426
+ } else if ("endsWith" in issue.validation) {
427
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
428
+ } else {
429
+ util.assertNever(issue.validation);
430
+ }
431
+ } else if (issue.validation !== "regex") {
432
+ message = `Invalid ${issue.validation}`;
433
+ } else {
434
+ message = "Invalid";
435
+ }
436
+ break;
437
+ case ZodIssueCode.too_small:
438
+ if (issue.type === "array")
439
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
440
+ else if (issue.type === "string")
441
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
442
+ else if (issue.type === "number")
443
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
444
+ else if (issue.type === "bigint")
445
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
446
+ else if (issue.type === "date")
447
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
448
+ else
449
+ message = "Invalid input";
450
+ break;
451
+ case ZodIssueCode.too_big:
452
+ if (issue.type === "array")
453
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
454
+ else if (issue.type === "string")
455
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
456
+ else if (issue.type === "number")
457
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
458
+ else if (issue.type === "bigint")
459
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
460
+ else if (issue.type === "date")
461
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
462
+ else
463
+ message = "Invalid input";
464
+ break;
465
+ case ZodIssueCode.custom:
466
+ message = `Invalid input`;
467
+ break;
468
+ case ZodIssueCode.invalid_intersection_types:
469
+ message = `Intersection results could not be merged`;
470
+ break;
471
+ case ZodIssueCode.not_multiple_of:
472
+ message = `Number must be a multiple of ${issue.multipleOf}`;
473
+ break;
474
+ case ZodIssueCode.not_finite:
475
+ message = "Number must be finite";
476
+ break;
477
+ default:
478
+ message = _ctx.defaultError;
479
+ util.assertNever(issue);
480
+ }
481
+ return { message };
482
+ };
483
+ var en_default = errorMap;
484
+
485
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
486
+ var overrideErrorMap = en_default;
487
+ function setErrorMap(map) {
488
+ overrideErrorMap = map;
489
+ }
490
+ function getErrorMap() {
491
+ return overrideErrorMap;
492
+ }
493
+
494
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
495
+ var makeIssue = (params) => {
496
+ const { data, path, errorMaps, issueData } = params;
497
+ const fullPath = [...path, ...issueData.path || []];
498
+ const fullIssue = {
499
+ ...issueData,
500
+ path: fullPath
501
+ };
502
+ if (issueData.message !== void 0) {
503
+ return {
504
+ ...issueData,
505
+ path: fullPath,
506
+ message: issueData.message
507
+ };
508
+ }
509
+ let errorMessage = "";
510
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
511
+ for (const map of maps) {
512
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
513
+ }
514
+ return {
515
+ ...issueData,
516
+ path: fullPath,
517
+ message: errorMessage
518
+ };
519
+ };
520
+ var EMPTY_PATH = [];
521
+ function addIssueToContext(ctx, issueData) {
522
+ const overrideMap = getErrorMap();
523
+ const issue = makeIssue({
524
+ issueData,
525
+ data: ctx.data,
526
+ path: ctx.path,
527
+ errorMaps: [
528
+ ctx.common.contextualErrorMap,
529
+ // contextual error map is first priority
530
+ ctx.schemaErrorMap,
531
+ // then schema-bound map if available
532
+ overrideMap,
533
+ // then global override map
534
+ overrideMap === en_default ? void 0 : en_default
535
+ // then global default map
536
+ ].filter((x) => !!x)
537
+ });
538
+ ctx.common.issues.push(issue);
539
+ }
540
+ var ParseStatus = class _ParseStatus {
541
+ constructor() {
542
+ this.value = "valid";
543
+ }
544
+ dirty() {
545
+ if (this.value === "valid")
546
+ this.value = "dirty";
547
+ }
548
+ abort() {
549
+ if (this.value !== "aborted")
550
+ this.value = "aborted";
551
+ }
552
+ static mergeArray(status, results) {
553
+ const arrayValue = [];
554
+ for (const s of results) {
555
+ if (s.status === "aborted")
556
+ return INVALID;
557
+ if (s.status === "dirty")
558
+ status.dirty();
559
+ arrayValue.push(s.value);
560
+ }
561
+ return { status: status.value, value: arrayValue };
562
+ }
563
+ static async mergeObjectAsync(status, pairs) {
564
+ const syncPairs = [];
565
+ for (const pair of pairs) {
566
+ const key = await pair.key;
567
+ const value = await pair.value;
568
+ syncPairs.push({
569
+ key,
570
+ value
571
+ });
572
+ }
573
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
574
+ }
575
+ static mergeObjectSync(status, pairs) {
576
+ const finalObject = {};
577
+ for (const pair of pairs) {
578
+ const { key, value } = pair;
579
+ if (key.status === "aborted")
580
+ return INVALID;
581
+ if (value.status === "aborted")
582
+ return INVALID;
583
+ if (key.status === "dirty")
584
+ status.dirty();
585
+ if (value.status === "dirty")
586
+ status.dirty();
587
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
588
+ finalObject[key.value] = value.value;
589
+ }
590
+ }
591
+ return { status: status.value, value: finalObject };
592
+ }
593
+ };
594
+ var INVALID = Object.freeze({
595
+ status: "aborted"
596
+ });
597
+ var DIRTY = (value) => ({ status: "dirty", value });
598
+ var OK = (value) => ({ status: "valid", value });
599
+ var isAborted = (x) => x.status === "aborted";
600
+ var isDirty = (x) => x.status === "dirty";
601
+ var isValid = (x) => x.status === "valid";
602
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
603
+
604
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
605
+ var errorUtil;
606
+ (function(errorUtil2) {
607
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
608
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
609
+ })(errorUtil || (errorUtil = {}));
610
+
611
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
612
+ var ParseInputLazyPath = class {
613
+ constructor(parent, value, path, key) {
614
+ this._cachedPath = [];
615
+ this.parent = parent;
616
+ this.data = value;
617
+ this._path = path;
618
+ this._key = key;
619
+ }
620
+ get path() {
621
+ if (!this._cachedPath.length) {
622
+ if (Array.isArray(this._key)) {
623
+ this._cachedPath.push(...this._path, ...this._key);
624
+ } else {
625
+ this._cachedPath.push(...this._path, this._key);
626
+ }
627
+ }
628
+ return this._cachedPath;
629
+ }
630
+ };
631
+ var handleResult = (ctx, result) => {
632
+ if (isValid(result)) {
633
+ return { success: true, data: result.value };
634
+ } else {
635
+ if (!ctx.common.issues.length) {
636
+ throw new Error("Validation failed but no issues detected.");
637
+ }
638
+ return {
639
+ success: false,
640
+ get error() {
641
+ if (this._error)
642
+ return this._error;
643
+ const error = new ZodError(ctx.common.issues);
644
+ this._error = error;
645
+ return this._error;
646
+ }
647
+ };
648
+ }
649
+ };
650
+ function processCreateParams(params) {
651
+ if (!params)
652
+ return {};
653
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
654
+ if (errorMap2 && (invalid_type_error || required_error)) {
655
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
656
+ }
657
+ if (errorMap2)
658
+ return { errorMap: errorMap2, description };
659
+ const customMap = (iss, ctx) => {
660
+ const { message } = params;
661
+ if (iss.code === "invalid_enum_value") {
662
+ return { message: message ?? ctx.defaultError };
663
+ }
664
+ if (typeof ctx.data === "undefined") {
665
+ return { message: message ?? required_error ?? ctx.defaultError };
666
+ }
667
+ if (iss.code !== "invalid_type")
668
+ return { message: ctx.defaultError };
669
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
670
+ };
671
+ return { errorMap: customMap, description };
672
+ }
673
+ var ZodType = class {
674
+ get description() {
675
+ return this._def.description;
676
+ }
677
+ _getType(input) {
678
+ return getParsedType(input.data);
679
+ }
680
+ _getOrReturnCtx(input, ctx) {
681
+ return ctx || {
682
+ common: input.parent.common,
683
+ data: input.data,
684
+ parsedType: getParsedType(input.data),
685
+ schemaErrorMap: this._def.errorMap,
686
+ path: input.path,
687
+ parent: input.parent
688
+ };
689
+ }
690
+ _processInputParams(input) {
691
+ return {
692
+ status: new ParseStatus(),
693
+ ctx: {
694
+ common: input.parent.common,
695
+ data: input.data,
696
+ parsedType: getParsedType(input.data),
697
+ schemaErrorMap: this._def.errorMap,
698
+ path: input.path,
699
+ parent: input.parent
700
+ }
701
+ };
702
+ }
703
+ _parseSync(input) {
704
+ const result = this._parse(input);
705
+ if (isAsync(result)) {
706
+ throw new Error("Synchronous parse encountered promise.");
707
+ }
708
+ return result;
709
+ }
710
+ _parseAsync(input) {
711
+ const result = this._parse(input);
712
+ return Promise.resolve(result);
713
+ }
714
+ parse(data, params) {
715
+ const result = this.safeParse(data, params);
716
+ if (result.success)
717
+ return result.data;
718
+ throw result.error;
719
+ }
720
+ safeParse(data, params) {
721
+ const ctx = {
722
+ common: {
723
+ issues: [],
724
+ async: params?.async ?? false,
725
+ contextualErrorMap: params?.errorMap
726
+ },
727
+ path: params?.path || [],
728
+ schemaErrorMap: this._def.errorMap,
729
+ parent: null,
730
+ data,
731
+ parsedType: getParsedType(data)
732
+ };
733
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
734
+ return handleResult(ctx, result);
735
+ }
736
+ "~validate"(data) {
737
+ const ctx = {
738
+ common: {
739
+ issues: [],
740
+ async: !!this["~standard"].async
741
+ },
742
+ path: [],
743
+ schemaErrorMap: this._def.errorMap,
744
+ parent: null,
745
+ data,
746
+ parsedType: getParsedType(data)
747
+ };
748
+ if (!this["~standard"].async) {
749
+ try {
750
+ const result = this._parseSync({ data, path: [], parent: ctx });
751
+ return isValid(result) ? {
752
+ value: result.value
753
+ } : {
754
+ issues: ctx.common.issues
755
+ };
756
+ } catch (err) {
757
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
758
+ this["~standard"].async = true;
759
+ }
760
+ ctx.common = {
761
+ issues: [],
762
+ async: true
763
+ };
764
+ }
765
+ }
766
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
767
+ value: result.value
768
+ } : {
769
+ issues: ctx.common.issues
770
+ });
771
+ }
772
+ async parseAsync(data, params) {
773
+ const result = await this.safeParseAsync(data, params);
774
+ if (result.success)
775
+ return result.data;
776
+ throw result.error;
777
+ }
778
+ async safeParseAsync(data, params) {
779
+ const ctx = {
780
+ common: {
781
+ issues: [],
782
+ contextualErrorMap: params?.errorMap,
783
+ async: true
784
+ },
785
+ path: params?.path || [],
786
+ schemaErrorMap: this._def.errorMap,
787
+ parent: null,
788
+ data,
789
+ parsedType: getParsedType(data)
790
+ };
791
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
792
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
793
+ return handleResult(ctx, result);
794
+ }
795
+ refine(check, message) {
796
+ const getIssueProperties = (val) => {
797
+ if (typeof message === "string" || typeof message === "undefined") {
798
+ return { message };
799
+ } else if (typeof message === "function") {
800
+ return message(val);
801
+ } else {
802
+ return message;
803
+ }
804
+ };
805
+ return this._refinement((val, ctx) => {
806
+ const result = check(val);
807
+ const setError = () => ctx.addIssue({
808
+ code: ZodIssueCode.custom,
809
+ ...getIssueProperties(val)
810
+ });
811
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
812
+ return result.then((data) => {
813
+ if (!data) {
814
+ setError();
815
+ return false;
816
+ } else {
817
+ return true;
818
+ }
819
+ });
820
+ }
821
+ if (!result) {
822
+ setError();
823
+ return false;
824
+ } else {
825
+ return true;
826
+ }
827
+ });
828
+ }
829
+ refinement(check, refinementData) {
830
+ return this._refinement((val, ctx) => {
831
+ if (!check(val)) {
832
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
833
+ return false;
834
+ } else {
835
+ return true;
836
+ }
837
+ });
838
+ }
839
+ _refinement(refinement) {
840
+ return new ZodEffects({
841
+ schema: this,
842
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
843
+ effect: { type: "refinement", refinement }
844
+ });
845
+ }
846
+ superRefine(refinement) {
847
+ return this._refinement(refinement);
848
+ }
849
+ constructor(def) {
850
+ this.spa = this.safeParseAsync;
851
+ this._def = def;
852
+ this.parse = this.parse.bind(this);
853
+ this.safeParse = this.safeParse.bind(this);
854
+ this.parseAsync = this.parseAsync.bind(this);
855
+ this.safeParseAsync = this.safeParseAsync.bind(this);
856
+ this.spa = this.spa.bind(this);
857
+ this.refine = this.refine.bind(this);
858
+ this.refinement = this.refinement.bind(this);
859
+ this.superRefine = this.superRefine.bind(this);
860
+ this.optional = this.optional.bind(this);
861
+ this.nullable = this.nullable.bind(this);
862
+ this.nullish = this.nullish.bind(this);
863
+ this.array = this.array.bind(this);
864
+ this.promise = this.promise.bind(this);
865
+ this.or = this.or.bind(this);
866
+ this.and = this.and.bind(this);
867
+ this.transform = this.transform.bind(this);
868
+ this.brand = this.brand.bind(this);
869
+ this.default = this.default.bind(this);
870
+ this.catch = this.catch.bind(this);
871
+ this.describe = this.describe.bind(this);
872
+ this.pipe = this.pipe.bind(this);
873
+ this.readonly = this.readonly.bind(this);
874
+ this.isNullable = this.isNullable.bind(this);
875
+ this.isOptional = this.isOptional.bind(this);
876
+ this["~standard"] = {
877
+ version: 1,
878
+ vendor: "zod",
879
+ validate: (data) => this["~validate"](data)
880
+ };
881
+ }
882
+ optional() {
883
+ return ZodOptional.create(this, this._def);
884
+ }
885
+ nullable() {
886
+ return ZodNullable.create(this, this._def);
887
+ }
888
+ nullish() {
889
+ return this.nullable().optional();
890
+ }
891
+ array() {
892
+ return ZodArray.create(this);
893
+ }
894
+ promise() {
895
+ return ZodPromise.create(this, this._def);
896
+ }
897
+ or(option) {
898
+ return ZodUnion.create([this, option], this._def);
899
+ }
900
+ and(incoming) {
901
+ return ZodIntersection.create(this, incoming, this._def);
902
+ }
903
+ transform(transform) {
904
+ return new ZodEffects({
905
+ ...processCreateParams(this._def),
906
+ schema: this,
907
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
908
+ effect: { type: "transform", transform }
909
+ });
910
+ }
911
+ default(def) {
912
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
913
+ return new ZodDefault({
914
+ ...processCreateParams(this._def),
915
+ innerType: this,
916
+ defaultValue: defaultValueFunc,
917
+ typeName: ZodFirstPartyTypeKind.ZodDefault
918
+ });
919
+ }
920
+ brand() {
921
+ return new ZodBranded({
922
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
923
+ type: this,
924
+ ...processCreateParams(this._def)
925
+ });
926
+ }
927
+ catch(def) {
928
+ const catchValueFunc = typeof def === "function" ? def : () => def;
929
+ return new ZodCatch({
930
+ ...processCreateParams(this._def),
931
+ innerType: this,
932
+ catchValue: catchValueFunc,
933
+ typeName: ZodFirstPartyTypeKind.ZodCatch
934
+ });
935
+ }
936
+ describe(description) {
937
+ const This = this.constructor;
938
+ return new This({
939
+ ...this._def,
940
+ description
941
+ });
942
+ }
943
+ pipe(target) {
944
+ return ZodPipeline.create(this, target);
945
+ }
946
+ readonly() {
947
+ return ZodReadonly.create(this);
948
+ }
949
+ isOptional() {
950
+ return this.safeParse(void 0).success;
951
+ }
952
+ isNullable() {
953
+ return this.safeParse(null).success;
954
+ }
955
+ };
956
+ var cuidRegex = /^c[^\s-]{8,}$/i;
957
+ var cuid2Regex = /^[0-9a-z]+$/;
958
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
959
+ 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;
960
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
961
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
962
+ 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)?)??$/;
963
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
964
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
965
+ var emojiRegex;
966
+ 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])$/;
967
+ 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])$/;
968
+ 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]))$/;
969
+ 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])$/;
970
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
971
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
972
+ 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])))`;
973
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
974
+ function timeRegexSource(args) {
975
+ let secondsRegexSource = `[0-5]\\d`;
976
+ if (args.precision) {
977
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
978
+ } else if (args.precision == null) {
979
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
980
+ }
981
+ const secondsQuantifier = args.precision ? "+" : "?";
982
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
983
+ }
984
+ function timeRegex(args) {
985
+ return new RegExp(`^${timeRegexSource(args)}$`);
986
+ }
987
+ function datetimeRegex(args) {
988
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
989
+ const opts = [];
990
+ opts.push(args.local ? `Z?` : `Z`);
991
+ if (args.offset)
992
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
993
+ regex = `${regex}(${opts.join("|")})`;
994
+ return new RegExp(`^${regex}$`);
995
+ }
996
+ function isValidIP(ip, version) {
997
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
998
+ return true;
999
+ }
1000
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1001
+ return true;
1002
+ }
1003
+ return false;
1004
+ }
1005
+ function isValidJWT(jwt, alg) {
1006
+ if (!jwtRegex.test(jwt))
1007
+ return false;
1008
+ try {
1009
+ const [header] = jwt.split(".");
1010
+ if (!header)
1011
+ return false;
1012
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
1013
+ const decoded = JSON.parse(atob(base64));
1014
+ if (typeof decoded !== "object" || decoded === null)
1015
+ return false;
1016
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1017
+ return false;
1018
+ if (!decoded.alg)
1019
+ return false;
1020
+ if (alg && decoded.alg !== alg)
1021
+ return false;
1022
+ return true;
1023
+ } catch {
1024
+ return false;
1025
+ }
1026
+ }
1027
+ function isValidCidr(ip, version) {
1028
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
1029
+ return true;
1030
+ }
1031
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
1032
+ return true;
1033
+ }
1034
+ return false;
1035
+ }
1036
+ var ZodString = class _ZodString extends ZodType {
1037
+ _parse(input) {
1038
+ if (this._def.coerce) {
1039
+ input.data = String(input.data);
1040
+ }
1041
+ const parsedType = this._getType(input);
1042
+ if (parsedType !== ZodParsedType.string) {
1043
+ const ctx2 = this._getOrReturnCtx(input);
1044
+ addIssueToContext(ctx2, {
1045
+ code: ZodIssueCode.invalid_type,
1046
+ expected: ZodParsedType.string,
1047
+ received: ctx2.parsedType
1048
+ });
1049
+ return INVALID;
1050
+ }
1051
+ const status = new ParseStatus();
1052
+ let ctx = void 0;
1053
+ for (const check of this._def.checks) {
1054
+ if (check.kind === "min") {
1055
+ if (input.data.length < check.value) {
1056
+ ctx = this._getOrReturnCtx(input, ctx);
1057
+ addIssueToContext(ctx, {
1058
+ code: ZodIssueCode.too_small,
1059
+ minimum: check.value,
1060
+ type: "string",
1061
+ inclusive: true,
1062
+ exact: false,
1063
+ message: check.message
1064
+ });
1065
+ status.dirty();
1066
+ }
1067
+ } else if (check.kind === "max") {
1068
+ if (input.data.length > check.value) {
1069
+ ctx = this._getOrReturnCtx(input, ctx);
1070
+ addIssueToContext(ctx, {
1071
+ code: ZodIssueCode.too_big,
1072
+ maximum: check.value,
1073
+ type: "string",
1074
+ inclusive: true,
1075
+ exact: false,
1076
+ message: check.message
1077
+ });
1078
+ status.dirty();
1079
+ }
1080
+ } else if (check.kind === "length") {
1081
+ const tooBig = input.data.length > check.value;
1082
+ const tooSmall = input.data.length < check.value;
1083
+ if (tooBig || tooSmall) {
1084
+ ctx = this._getOrReturnCtx(input, ctx);
1085
+ if (tooBig) {
1086
+ addIssueToContext(ctx, {
1087
+ code: ZodIssueCode.too_big,
1088
+ maximum: check.value,
1089
+ type: "string",
1090
+ inclusive: true,
1091
+ exact: true,
1092
+ message: check.message
1093
+ });
1094
+ } else if (tooSmall) {
1095
+ addIssueToContext(ctx, {
1096
+ code: ZodIssueCode.too_small,
1097
+ minimum: check.value,
1098
+ type: "string",
1099
+ inclusive: true,
1100
+ exact: true,
1101
+ message: check.message
1102
+ });
1103
+ }
1104
+ status.dirty();
1105
+ }
1106
+ } else if (check.kind === "email") {
1107
+ if (!emailRegex.test(input.data)) {
1108
+ ctx = this._getOrReturnCtx(input, ctx);
1109
+ addIssueToContext(ctx, {
1110
+ validation: "email",
1111
+ code: ZodIssueCode.invalid_string,
1112
+ message: check.message
1113
+ });
1114
+ status.dirty();
1115
+ }
1116
+ } else if (check.kind === "emoji") {
1117
+ if (!emojiRegex) {
1118
+ emojiRegex = new RegExp(_emojiRegex, "u");
1119
+ }
1120
+ if (!emojiRegex.test(input.data)) {
1121
+ ctx = this._getOrReturnCtx(input, ctx);
1122
+ addIssueToContext(ctx, {
1123
+ validation: "emoji",
1124
+ code: ZodIssueCode.invalid_string,
1125
+ message: check.message
1126
+ });
1127
+ status.dirty();
1128
+ }
1129
+ } else if (check.kind === "uuid") {
1130
+ if (!uuidRegex.test(input.data)) {
1131
+ ctx = this._getOrReturnCtx(input, ctx);
1132
+ addIssueToContext(ctx, {
1133
+ validation: "uuid",
1134
+ code: ZodIssueCode.invalid_string,
1135
+ message: check.message
1136
+ });
1137
+ status.dirty();
1138
+ }
1139
+ } else if (check.kind === "nanoid") {
1140
+ if (!nanoidRegex.test(input.data)) {
1141
+ ctx = this._getOrReturnCtx(input, ctx);
1142
+ addIssueToContext(ctx, {
1143
+ validation: "nanoid",
1144
+ code: ZodIssueCode.invalid_string,
1145
+ message: check.message
1146
+ });
1147
+ status.dirty();
1148
+ }
1149
+ } else if (check.kind === "cuid") {
1150
+ if (!cuidRegex.test(input.data)) {
1151
+ ctx = this._getOrReturnCtx(input, ctx);
1152
+ addIssueToContext(ctx, {
1153
+ validation: "cuid",
1154
+ code: ZodIssueCode.invalid_string,
1155
+ message: check.message
1156
+ });
1157
+ status.dirty();
1158
+ }
1159
+ } else if (check.kind === "cuid2") {
1160
+ if (!cuid2Regex.test(input.data)) {
1161
+ ctx = this._getOrReturnCtx(input, ctx);
1162
+ addIssueToContext(ctx, {
1163
+ validation: "cuid2",
1164
+ code: ZodIssueCode.invalid_string,
1165
+ message: check.message
1166
+ });
1167
+ status.dirty();
1168
+ }
1169
+ } else if (check.kind === "ulid") {
1170
+ if (!ulidRegex.test(input.data)) {
1171
+ ctx = this._getOrReturnCtx(input, ctx);
1172
+ addIssueToContext(ctx, {
1173
+ validation: "ulid",
1174
+ code: ZodIssueCode.invalid_string,
1175
+ message: check.message
1176
+ });
1177
+ status.dirty();
1178
+ }
1179
+ } else if (check.kind === "url") {
1180
+ try {
1181
+ new URL(input.data);
1182
+ } catch {
1183
+ ctx = this._getOrReturnCtx(input, ctx);
1184
+ addIssueToContext(ctx, {
1185
+ validation: "url",
1186
+ code: ZodIssueCode.invalid_string,
1187
+ message: check.message
1188
+ });
1189
+ status.dirty();
1190
+ }
1191
+ } else if (check.kind === "regex") {
1192
+ check.regex.lastIndex = 0;
1193
+ const testResult = check.regex.test(input.data);
1194
+ if (!testResult) {
1195
+ ctx = this._getOrReturnCtx(input, ctx);
1196
+ addIssueToContext(ctx, {
1197
+ validation: "regex",
1198
+ code: ZodIssueCode.invalid_string,
1199
+ message: check.message
1200
+ });
1201
+ status.dirty();
1202
+ }
1203
+ } else if (check.kind === "trim") {
1204
+ input.data = input.data.trim();
1205
+ } else if (check.kind === "includes") {
1206
+ if (!input.data.includes(check.value, check.position)) {
1207
+ ctx = this._getOrReturnCtx(input, ctx);
1208
+ addIssueToContext(ctx, {
1209
+ code: ZodIssueCode.invalid_string,
1210
+ validation: { includes: check.value, position: check.position },
1211
+ message: check.message
1212
+ });
1213
+ status.dirty();
1214
+ }
1215
+ } else if (check.kind === "toLowerCase") {
1216
+ input.data = input.data.toLowerCase();
1217
+ } else if (check.kind === "toUpperCase") {
1218
+ input.data = input.data.toUpperCase();
1219
+ } else if (check.kind === "startsWith") {
1220
+ if (!input.data.startsWith(check.value)) {
1221
+ ctx = this._getOrReturnCtx(input, ctx);
1222
+ addIssueToContext(ctx, {
1223
+ code: ZodIssueCode.invalid_string,
1224
+ validation: { startsWith: check.value },
1225
+ message: check.message
1226
+ });
1227
+ status.dirty();
1228
+ }
1229
+ } else if (check.kind === "endsWith") {
1230
+ if (!input.data.endsWith(check.value)) {
1231
+ ctx = this._getOrReturnCtx(input, ctx);
1232
+ addIssueToContext(ctx, {
1233
+ code: ZodIssueCode.invalid_string,
1234
+ validation: { endsWith: check.value },
1235
+ message: check.message
1236
+ });
1237
+ status.dirty();
1238
+ }
1239
+ } else if (check.kind === "datetime") {
1240
+ const regex = datetimeRegex(check);
1241
+ if (!regex.test(input.data)) {
1242
+ ctx = this._getOrReturnCtx(input, ctx);
1243
+ addIssueToContext(ctx, {
1244
+ code: ZodIssueCode.invalid_string,
1245
+ validation: "datetime",
1246
+ message: check.message
1247
+ });
1248
+ status.dirty();
1249
+ }
1250
+ } else if (check.kind === "date") {
1251
+ const regex = dateRegex;
1252
+ if (!regex.test(input.data)) {
1253
+ ctx = this._getOrReturnCtx(input, ctx);
1254
+ addIssueToContext(ctx, {
1255
+ code: ZodIssueCode.invalid_string,
1256
+ validation: "date",
1257
+ message: check.message
1258
+ });
1259
+ status.dirty();
1260
+ }
1261
+ } else if (check.kind === "time") {
1262
+ const regex = timeRegex(check);
1263
+ if (!regex.test(input.data)) {
1264
+ ctx = this._getOrReturnCtx(input, ctx);
1265
+ addIssueToContext(ctx, {
1266
+ code: ZodIssueCode.invalid_string,
1267
+ validation: "time",
1268
+ message: check.message
1269
+ });
1270
+ status.dirty();
1271
+ }
1272
+ } else if (check.kind === "duration") {
1273
+ if (!durationRegex.test(input.data)) {
1274
+ ctx = this._getOrReturnCtx(input, ctx);
1275
+ addIssueToContext(ctx, {
1276
+ validation: "duration",
1277
+ code: ZodIssueCode.invalid_string,
1278
+ message: check.message
1279
+ });
1280
+ status.dirty();
1281
+ }
1282
+ } else if (check.kind === "ip") {
1283
+ if (!isValidIP(input.data, check.version)) {
1284
+ ctx = this._getOrReturnCtx(input, ctx);
1285
+ addIssueToContext(ctx, {
1286
+ validation: "ip",
1287
+ code: ZodIssueCode.invalid_string,
1288
+ message: check.message
1289
+ });
1290
+ status.dirty();
1291
+ }
1292
+ } else if (check.kind === "jwt") {
1293
+ if (!isValidJWT(input.data, check.alg)) {
1294
+ ctx = this._getOrReturnCtx(input, ctx);
1295
+ addIssueToContext(ctx, {
1296
+ validation: "jwt",
1297
+ code: ZodIssueCode.invalid_string,
1298
+ message: check.message
1299
+ });
1300
+ status.dirty();
1301
+ }
1302
+ } else if (check.kind === "cidr") {
1303
+ if (!isValidCidr(input.data, check.version)) {
1304
+ ctx = this._getOrReturnCtx(input, ctx);
1305
+ addIssueToContext(ctx, {
1306
+ validation: "cidr",
1307
+ code: ZodIssueCode.invalid_string,
1308
+ message: check.message
1309
+ });
1310
+ status.dirty();
1311
+ }
1312
+ } else if (check.kind === "base64") {
1313
+ if (!base64Regex.test(input.data)) {
1314
+ ctx = this._getOrReturnCtx(input, ctx);
1315
+ addIssueToContext(ctx, {
1316
+ validation: "base64",
1317
+ code: ZodIssueCode.invalid_string,
1318
+ message: check.message
1319
+ });
1320
+ status.dirty();
1321
+ }
1322
+ } else if (check.kind === "base64url") {
1323
+ if (!base64urlRegex.test(input.data)) {
1324
+ ctx = this._getOrReturnCtx(input, ctx);
1325
+ addIssueToContext(ctx, {
1326
+ validation: "base64url",
1327
+ code: ZodIssueCode.invalid_string,
1328
+ message: check.message
1329
+ });
1330
+ status.dirty();
1331
+ }
1332
+ } else {
1333
+ util.assertNever(check);
1334
+ }
1335
+ }
1336
+ return { status: status.value, value: input.data };
1337
+ }
1338
+ _regex(regex, validation, message) {
1339
+ return this.refinement((data) => regex.test(data), {
1340
+ validation,
1341
+ code: ZodIssueCode.invalid_string,
1342
+ ...errorUtil.errToObj(message)
1343
+ });
1344
+ }
1345
+ _addCheck(check) {
1346
+ return new _ZodString({
1347
+ ...this._def,
1348
+ checks: [...this._def.checks, check]
1349
+ });
1350
+ }
1351
+ email(message) {
1352
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1353
+ }
1354
+ url(message) {
1355
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1356
+ }
1357
+ emoji(message) {
1358
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1359
+ }
1360
+ uuid(message) {
1361
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1362
+ }
1363
+ nanoid(message) {
1364
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1365
+ }
1366
+ cuid(message) {
1367
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1368
+ }
1369
+ cuid2(message) {
1370
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1371
+ }
1372
+ ulid(message) {
1373
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1374
+ }
1375
+ base64(message) {
1376
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1377
+ }
1378
+ base64url(message) {
1379
+ return this._addCheck({
1380
+ kind: "base64url",
1381
+ ...errorUtil.errToObj(message)
1382
+ });
1383
+ }
1384
+ jwt(options) {
1385
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1386
+ }
1387
+ ip(options) {
1388
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1389
+ }
1390
+ cidr(options) {
1391
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1392
+ }
1393
+ datetime(options) {
1394
+ if (typeof options === "string") {
1395
+ return this._addCheck({
1396
+ kind: "datetime",
1397
+ precision: null,
1398
+ offset: false,
1399
+ local: false,
1400
+ message: options
1401
+ });
1402
+ }
1403
+ return this._addCheck({
1404
+ kind: "datetime",
1405
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1406
+ offset: options?.offset ?? false,
1407
+ local: options?.local ?? false,
1408
+ ...errorUtil.errToObj(options?.message)
1409
+ });
1410
+ }
1411
+ date(message) {
1412
+ return this._addCheck({ kind: "date", message });
1413
+ }
1414
+ time(options) {
1415
+ if (typeof options === "string") {
1416
+ return this._addCheck({
1417
+ kind: "time",
1418
+ precision: null,
1419
+ message: options
1420
+ });
1421
+ }
1422
+ return this._addCheck({
1423
+ kind: "time",
1424
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1425
+ ...errorUtil.errToObj(options?.message)
1426
+ });
1427
+ }
1428
+ duration(message) {
1429
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1430
+ }
1431
+ regex(regex, message) {
1432
+ return this._addCheck({
1433
+ kind: "regex",
1434
+ regex,
1435
+ ...errorUtil.errToObj(message)
1436
+ });
1437
+ }
1438
+ includes(value, options) {
1439
+ return this._addCheck({
1440
+ kind: "includes",
1441
+ value,
1442
+ position: options?.position,
1443
+ ...errorUtil.errToObj(options?.message)
1444
+ });
1445
+ }
1446
+ startsWith(value, message) {
1447
+ return this._addCheck({
1448
+ kind: "startsWith",
1449
+ value,
1450
+ ...errorUtil.errToObj(message)
1451
+ });
1452
+ }
1453
+ endsWith(value, message) {
1454
+ return this._addCheck({
1455
+ kind: "endsWith",
1456
+ value,
1457
+ ...errorUtil.errToObj(message)
1458
+ });
1459
+ }
1460
+ min(minLength, message) {
1461
+ return this._addCheck({
1462
+ kind: "min",
1463
+ value: minLength,
1464
+ ...errorUtil.errToObj(message)
1465
+ });
1466
+ }
1467
+ max(maxLength, message) {
1468
+ return this._addCheck({
1469
+ kind: "max",
1470
+ value: maxLength,
1471
+ ...errorUtil.errToObj(message)
1472
+ });
1473
+ }
1474
+ length(len, message) {
1475
+ return this._addCheck({
1476
+ kind: "length",
1477
+ value: len,
1478
+ ...errorUtil.errToObj(message)
1479
+ });
1480
+ }
1481
+ /**
1482
+ * Equivalent to `.min(1)`
1483
+ */
1484
+ nonempty(message) {
1485
+ return this.min(1, errorUtil.errToObj(message));
1486
+ }
1487
+ trim() {
1488
+ return new _ZodString({
1489
+ ...this._def,
1490
+ checks: [...this._def.checks, { kind: "trim" }]
1491
+ });
1492
+ }
1493
+ toLowerCase() {
1494
+ return new _ZodString({
1495
+ ...this._def,
1496
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1497
+ });
1498
+ }
1499
+ toUpperCase() {
1500
+ return new _ZodString({
1501
+ ...this._def,
1502
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1503
+ });
1504
+ }
1505
+ get isDatetime() {
1506
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1507
+ }
1508
+ get isDate() {
1509
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1510
+ }
1511
+ get isTime() {
1512
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1513
+ }
1514
+ get isDuration() {
1515
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1516
+ }
1517
+ get isEmail() {
1518
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1519
+ }
1520
+ get isURL() {
1521
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1522
+ }
1523
+ get isEmoji() {
1524
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1525
+ }
1526
+ get isUUID() {
1527
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1528
+ }
1529
+ get isNANOID() {
1530
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1531
+ }
1532
+ get isCUID() {
1533
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1534
+ }
1535
+ get isCUID2() {
1536
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1537
+ }
1538
+ get isULID() {
1539
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1540
+ }
1541
+ get isIP() {
1542
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1543
+ }
1544
+ get isCIDR() {
1545
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1546
+ }
1547
+ get isBase64() {
1548
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1549
+ }
1550
+ get isBase64url() {
1551
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1552
+ }
1553
+ get minLength() {
1554
+ let min = null;
1555
+ for (const ch of this._def.checks) {
1556
+ if (ch.kind === "min") {
1557
+ if (min === null || ch.value > min)
1558
+ min = ch.value;
1559
+ }
1560
+ }
1561
+ return min;
1562
+ }
1563
+ get maxLength() {
1564
+ let max = null;
1565
+ for (const ch of this._def.checks) {
1566
+ if (ch.kind === "max") {
1567
+ if (max === null || ch.value < max)
1568
+ max = ch.value;
1569
+ }
1570
+ }
1571
+ return max;
1572
+ }
1573
+ };
1574
+ ZodString.create = (params) => {
1575
+ return new ZodString({
1576
+ checks: [],
1577
+ typeName: ZodFirstPartyTypeKind.ZodString,
1578
+ coerce: params?.coerce ?? false,
1579
+ ...processCreateParams(params)
1580
+ });
1581
+ };
1582
+ function floatSafeRemainder(val, step) {
1583
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1584
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1585
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1586
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1587
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1588
+ return valInt % stepInt / 10 ** decCount;
1589
+ }
1590
+ var ZodNumber = class _ZodNumber extends ZodType {
1591
+ constructor() {
1592
+ super(...arguments);
1593
+ this.min = this.gte;
1594
+ this.max = this.lte;
1595
+ this.step = this.multipleOf;
1596
+ }
1597
+ _parse(input) {
1598
+ if (this._def.coerce) {
1599
+ input.data = Number(input.data);
1600
+ }
1601
+ const parsedType = this._getType(input);
1602
+ if (parsedType !== ZodParsedType.number) {
1603
+ const ctx2 = this._getOrReturnCtx(input);
1604
+ addIssueToContext(ctx2, {
1605
+ code: ZodIssueCode.invalid_type,
1606
+ expected: ZodParsedType.number,
1607
+ received: ctx2.parsedType
1608
+ });
1609
+ return INVALID;
1610
+ }
1611
+ let ctx = void 0;
1612
+ const status = new ParseStatus();
1613
+ for (const check of this._def.checks) {
1614
+ if (check.kind === "int") {
1615
+ if (!util.isInteger(input.data)) {
1616
+ ctx = this._getOrReturnCtx(input, ctx);
1617
+ addIssueToContext(ctx, {
1618
+ code: ZodIssueCode.invalid_type,
1619
+ expected: "integer",
1620
+ received: "float",
1621
+ message: check.message
1622
+ });
1623
+ status.dirty();
1624
+ }
1625
+ } else if (check.kind === "min") {
1626
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1627
+ if (tooSmall) {
1628
+ ctx = this._getOrReturnCtx(input, ctx);
1629
+ addIssueToContext(ctx, {
1630
+ code: ZodIssueCode.too_small,
1631
+ minimum: check.value,
1632
+ type: "number",
1633
+ inclusive: check.inclusive,
1634
+ exact: false,
1635
+ message: check.message
1636
+ });
1637
+ status.dirty();
1638
+ }
1639
+ } else if (check.kind === "max") {
1640
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1641
+ if (tooBig) {
1642
+ ctx = this._getOrReturnCtx(input, ctx);
1643
+ addIssueToContext(ctx, {
1644
+ code: ZodIssueCode.too_big,
1645
+ maximum: check.value,
1646
+ type: "number",
1647
+ inclusive: check.inclusive,
1648
+ exact: false,
1649
+ message: check.message
1650
+ });
1651
+ status.dirty();
1652
+ }
1653
+ } else if (check.kind === "multipleOf") {
1654
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1655
+ ctx = this._getOrReturnCtx(input, ctx);
1656
+ addIssueToContext(ctx, {
1657
+ code: ZodIssueCode.not_multiple_of,
1658
+ multipleOf: check.value,
1659
+ message: check.message
1660
+ });
1661
+ status.dirty();
1662
+ }
1663
+ } else if (check.kind === "finite") {
1664
+ if (!Number.isFinite(input.data)) {
1665
+ ctx = this._getOrReturnCtx(input, ctx);
1666
+ addIssueToContext(ctx, {
1667
+ code: ZodIssueCode.not_finite,
1668
+ message: check.message
1669
+ });
1670
+ status.dirty();
1671
+ }
1672
+ } else {
1673
+ util.assertNever(check);
1674
+ }
1675
+ }
1676
+ return { status: status.value, value: input.data };
1677
+ }
1678
+ gte(value, message) {
1679
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1680
+ }
1681
+ gt(value, message) {
1682
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1683
+ }
1684
+ lte(value, message) {
1685
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1686
+ }
1687
+ lt(value, message) {
1688
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1689
+ }
1690
+ setLimit(kind, value, inclusive, message) {
1691
+ return new _ZodNumber({
1692
+ ...this._def,
1693
+ checks: [
1694
+ ...this._def.checks,
1695
+ {
1696
+ kind,
1697
+ value,
1698
+ inclusive,
1699
+ message: errorUtil.toString(message)
1700
+ }
1701
+ ]
1702
+ });
1703
+ }
1704
+ _addCheck(check) {
1705
+ return new _ZodNumber({
1706
+ ...this._def,
1707
+ checks: [...this._def.checks, check]
1708
+ });
1709
+ }
1710
+ int(message) {
1711
+ return this._addCheck({
1712
+ kind: "int",
1713
+ message: errorUtil.toString(message)
1714
+ });
1715
+ }
1716
+ positive(message) {
1717
+ return this._addCheck({
1718
+ kind: "min",
1719
+ value: 0,
1720
+ inclusive: false,
1721
+ message: errorUtil.toString(message)
1722
+ });
1723
+ }
1724
+ negative(message) {
1725
+ return this._addCheck({
1726
+ kind: "max",
1727
+ value: 0,
1728
+ inclusive: false,
1729
+ message: errorUtil.toString(message)
1730
+ });
1731
+ }
1732
+ nonpositive(message) {
1733
+ return this._addCheck({
1734
+ kind: "max",
1735
+ value: 0,
1736
+ inclusive: true,
1737
+ message: errorUtil.toString(message)
1738
+ });
1739
+ }
1740
+ nonnegative(message) {
1741
+ return this._addCheck({
1742
+ kind: "min",
1743
+ value: 0,
1744
+ inclusive: true,
1745
+ message: errorUtil.toString(message)
1746
+ });
1747
+ }
1748
+ multipleOf(value, message) {
1749
+ return this._addCheck({
1750
+ kind: "multipleOf",
1751
+ value,
1752
+ message: errorUtil.toString(message)
1753
+ });
1754
+ }
1755
+ finite(message) {
1756
+ return this._addCheck({
1757
+ kind: "finite",
1758
+ message: errorUtil.toString(message)
1759
+ });
1760
+ }
1761
+ safe(message) {
1762
+ return this._addCheck({
1763
+ kind: "min",
1764
+ inclusive: true,
1765
+ value: Number.MIN_SAFE_INTEGER,
1766
+ message: errorUtil.toString(message)
1767
+ })._addCheck({
1768
+ kind: "max",
1769
+ inclusive: true,
1770
+ value: Number.MAX_SAFE_INTEGER,
1771
+ message: errorUtil.toString(message)
1772
+ });
1773
+ }
1774
+ get minValue() {
1775
+ let min = null;
1776
+ for (const ch of this._def.checks) {
1777
+ if (ch.kind === "min") {
1778
+ if (min === null || ch.value > min)
1779
+ min = ch.value;
1780
+ }
1781
+ }
1782
+ return min;
1783
+ }
1784
+ get maxValue() {
1785
+ let max = null;
1786
+ for (const ch of this._def.checks) {
1787
+ if (ch.kind === "max") {
1788
+ if (max === null || ch.value < max)
1789
+ max = ch.value;
1790
+ }
1791
+ }
1792
+ return max;
1793
+ }
1794
+ get isInt() {
1795
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1796
+ }
1797
+ get isFinite() {
1798
+ let max = null;
1799
+ let min = null;
1800
+ for (const ch of this._def.checks) {
1801
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1802
+ return true;
1803
+ } else if (ch.kind === "min") {
1804
+ if (min === null || ch.value > min)
1805
+ min = ch.value;
1806
+ } else if (ch.kind === "max") {
1807
+ if (max === null || ch.value < max)
1808
+ max = ch.value;
1809
+ }
1810
+ }
1811
+ return Number.isFinite(min) && Number.isFinite(max);
1812
+ }
1813
+ };
1814
+ ZodNumber.create = (params) => {
1815
+ return new ZodNumber({
1816
+ checks: [],
1817
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1818
+ coerce: params?.coerce || false,
1819
+ ...processCreateParams(params)
1820
+ });
1821
+ };
1822
+ var ZodBigInt = class _ZodBigInt extends ZodType {
1823
+ constructor() {
1824
+ super(...arguments);
1825
+ this.min = this.gte;
1826
+ this.max = this.lte;
1827
+ }
1828
+ _parse(input) {
1829
+ if (this._def.coerce) {
1830
+ try {
1831
+ input.data = BigInt(input.data);
1832
+ } catch {
1833
+ return this._getInvalidInput(input);
1834
+ }
1835
+ }
1836
+ const parsedType = this._getType(input);
1837
+ if (parsedType !== ZodParsedType.bigint) {
1838
+ return this._getInvalidInput(input);
1839
+ }
1840
+ let ctx = void 0;
1841
+ const status = new ParseStatus();
1842
+ for (const check of this._def.checks) {
1843
+ if (check.kind === "min") {
1844
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1845
+ if (tooSmall) {
1846
+ ctx = this._getOrReturnCtx(input, ctx);
1847
+ addIssueToContext(ctx, {
1848
+ code: ZodIssueCode.too_small,
1849
+ type: "bigint",
1850
+ minimum: check.value,
1851
+ inclusive: check.inclusive,
1852
+ message: check.message
1853
+ });
1854
+ status.dirty();
1855
+ }
1856
+ } else if (check.kind === "max") {
1857
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1858
+ if (tooBig) {
1859
+ ctx = this._getOrReturnCtx(input, ctx);
1860
+ addIssueToContext(ctx, {
1861
+ code: ZodIssueCode.too_big,
1862
+ type: "bigint",
1863
+ maximum: check.value,
1864
+ inclusive: check.inclusive,
1865
+ message: check.message
1866
+ });
1867
+ status.dirty();
1868
+ }
1869
+ } else if (check.kind === "multipleOf") {
1870
+ if (input.data % check.value !== BigInt(0)) {
1871
+ ctx = this._getOrReturnCtx(input, ctx);
1872
+ addIssueToContext(ctx, {
1873
+ code: ZodIssueCode.not_multiple_of,
1874
+ multipleOf: check.value,
1875
+ message: check.message
1876
+ });
1877
+ status.dirty();
1878
+ }
1879
+ } else {
1880
+ util.assertNever(check);
1881
+ }
1882
+ }
1883
+ return { status: status.value, value: input.data };
1884
+ }
1885
+ _getInvalidInput(input) {
1886
+ const ctx = this._getOrReturnCtx(input);
1887
+ addIssueToContext(ctx, {
1888
+ code: ZodIssueCode.invalid_type,
1889
+ expected: ZodParsedType.bigint,
1890
+ received: ctx.parsedType
1891
+ });
1892
+ return INVALID;
1893
+ }
1894
+ gte(value, message) {
1895
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1896
+ }
1897
+ gt(value, message) {
1898
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1899
+ }
1900
+ lte(value, message) {
1901
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1902
+ }
1903
+ lt(value, message) {
1904
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1905
+ }
1906
+ setLimit(kind, value, inclusive, message) {
1907
+ return new _ZodBigInt({
1908
+ ...this._def,
1909
+ checks: [
1910
+ ...this._def.checks,
1911
+ {
1912
+ kind,
1913
+ value,
1914
+ inclusive,
1915
+ message: errorUtil.toString(message)
1916
+ }
1917
+ ]
1918
+ });
1919
+ }
1920
+ _addCheck(check) {
1921
+ return new _ZodBigInt({
1922
+ ...this._def,
1923
+ checks: [...this._def.checks, check]
1924
+ });
1925
+ }
1926
+ positive(message) {
1927
+ return this._addCheck({
1928
+ kind: "min",
1929
+ value: BigInt(0),
1930
+ inclusive: false,
1931
+ message: errorUtil.toString(message)
1932
+ });
1933
+ }
1934
+ negative(message) {
1935
+ return this._addCheck({
1936
+ kind: "max",
1937
+ value: BigInt(0),
1938
+ inclusive: false,
1939
+ message: errorUtil.toString(message)
1940
+ });
1941
+ }
1942
+ nonpositive(message) {
1943
+ return this._addCheck({
1944
+ kind: "max",
1945
+ value: BigInt(0),
1946
+ inclusive: true,
1947
+ message: errorUtil.toString(message)
1948
+ });
1949
+ }
1950
+ nonnegative(message) {
1951
+ return this._addCheck({
1952
+ kind: "min",
1953
+ value: BigInt(0),
1954
+ inclusive: true,
1955
+ message: errorUtil.toString(message)
1956
+ });
1957
+ }
1958
+ multipleOf(value, message) {
1959
+ return this._addCheck({
1960
+ kind: "multipleOf",
1961
+ value,
1962
+ message: errorUtil.toString(message)
1963
+ });
1964
+ }
1965
+ get minValue() {
1966
+ let min = null;
1967
+ for (const ch of this._def.checks) {
1968
+ if (ch.kind === "min") {
1969
+ if (min === null || ch.value > min)
1970
+ min = ch.value;
1971
+ }
1972
+ }
1973
+ return min;
1974
+ }
1975
+ get maxValue() {
1976
+ let max = null;
1977
+ for (const ch of this._def.checks) {
1978
+ if (ch.kind === "max") {
1979
+ if (max === null || ch.value < max)
1980
+ max = ch.value;
1981
+ }
1982
+ }
1983
+ return max;
1984
+ }
1985
+ };
1986
+ ZodBigInt.create = (params) => {
1987
+ return new ZodBigInt({
1988
+ checks: [],
1989
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1990
+ coerce: params?.coerce ?? false,
1991
+ ...processCreateParams(params)
1992
+ });
1993
+ };
1994
+ var ZodBoolean = class extends ZodType {
1995
+ _parse(input) {
1996
+ if (this._def.coerce) {
1997
+ input.data = Boolean(input.data);
1998
+ }
1999
+ const parsedType = this._getType(input);
2000
+ if (parsedType !== ZodParsedType.boolean) {
2001
+ const ctx = this._getOrReturnCtx(input);
2002
+ addIssueToContext(ctx, {
2003
+ code: ZodIssueCode.invalid_type,
2004
+ expected: ZodParsedType.boolean,
2005
+ received: ctx.parsedType
2006
+ });
2007
+ return INVALID;
2008
+ }
2009
+ return OK(input.data);
2010
+ }
2011
+ };
2012
+ ZodBoolean.create = (params) => {
2013
+ return new ZodBoolean({
2014
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
2015
+ coerce: params?.coerce || false,
2016
+ ...processCreateParams(params)
2017
+ });
2018
+ };
2019
+ var ZodDate = class _ZodDate extends ZodType {
2020
+ _parse(input) {
2021
+ if (this._def.coerce) {
2022
+ input.data = new Date(input.data);
2023
+ }
2024
+ const parsedType = this._getType(input);
2025
+ if (parsedType !== ZodParsedType.date) {
2026
+ const ctx2 = this._getOrReturnCtx(input);
2027
+ addIssueToContext(ctx2, {
2028
+ code: ZodIssueCode.invalid_type,
2029
+ expected: ZodParsedType.date,
2030
+ received: ctx2.parsedType
2031
+ });
2032
+ return INVALID;
2033
+ }
2034
+ if (Number.isNaN(input.data.getTime())) {
2035
+ const ctx2 = this._getOrReturnCtx(input);
2036
+ addIssueToContext(ctx2, {
2037
+ code: ZodIssueCode.invalid_date
2038
+ });
2039
+ return INVALID;
2040
+ }
2041
+ const status = new ParseStatus();
2042
+ let ctx = void 0;
2043
+ for (const check of this._def.checks) {
2044
+ if (check.kind === "min") {
2045
+ if (input.data.getTime() < check.value) {
2046
+ ctx = this._getOrReturnCtx(input, ctx);
2047
+ addIssueToContext(ctx, {
2048
+ code: ZodIssueCode.too_small,
2049
+ message: check.message,
2050
+ inclusive: true,
2051
+ exact: false,
2052
+ minimum: check.value,
2053
+ type: "date"
2054
+ });
2055
+ status.dirty();
2056
+ }
2057
+ } else if (check.kind === "max") {
2058
+ if (input.data.getTime() > check.value) {
2059
+ ctx = this._getOrReturnCtx(input, ctx);
2060
+ addIssueToContext(ctx, {
2061
+ code: ZodIssueCode.too_big,
2062
+ message: check.message,
2063
+ inclusive: true,
2064
+ exact: false,
2065
+ maximum: check.value,
2066
+ type: "date"
2067
+ });
2068
+ status.dirty();
2069
+ }
2070
+ } else {
2071
+ util.assertNever(check);
2072
+ }
2073
+ }
2074
+ return {
2075
+ status: status.value,
2076
+ value: new Date(input.data.getTime())
2077
+ };
2078
+ }
2079
+ _addCheck(check) {
2080
+ return new _ZodDate({
2081
+ ...this._def,
2082
+ checks: [...this._def.checks, check]
2083
+ });
2084
+ }
2085
+ min(minDate, message) {
2086
+ return this._addCheck({
2087
+ kind: "min",
2088
+ value: minDate.getTime(),
2089
+ message: errorUtil.toString(message)
2090
+ });
2091
+ }
2092
+ max(maxDate, message) {
2093
+ return this._addCheck({
2094
+ kind: "max",
2095
+ value: maxDate.getTime(),
2096
+ message: errorUtil.toString(message)
2097
+ });
2098
+ }
2099
+ get minDate() {
2100
+ let min = null;
2101
+ for (const ch of this._def.checks) {
2102
+ if (ch.kind === "min") {
2103
+ if (min === null || ch.value > min)
2104
+ min = ch.value;
2105
+ }
2106
+ }
2107
+ return min != null ? new Date(min) : null;
2108
+ }
2109
+ get maxDate() {
2110
+ let max = null;
2111
+ for (const ch of this._def.checks) {
2112
+ if (ch.kind === "max") {
2113
+ if (max === null || ch.value < max)
2114
+ max = ch.value;
2115
+ }
2116
+ }
2117
+ return max != null ? new Date(max) : null;
2118
+ }
2119
+ };
2120
+ ZodDate.create = (params) => {
2121
+ return new ZodDate({
2122
+ checks: [],
2123
+ coerce: params?.coerce || false,
2124
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2125
+ ...processCreateParams(params)
2126
+ });
2127
+ };
2128
+ var ZodSymbol = class extends ZodType {
2129
+ _parse(input) {
2130
+ const parsedType = this._getType(input);
2131
+ if (parsedType !== ZodParsedType.symbol) {
2132
+ const ctx = this._getOrReturnCtx(input);
2133
+ addIssueToContext(ctx, {
2134
+ code: ZodIssueCode.invalid_type,
2135
+ expected: ZodParsedType.symbol,
2136
+ received: ctx.parsedType
2137
+ });
2138
+ return INVALID;
2139
+ }
2140
+ return OK(input.data);
2141
+ }
2142
+ };
2143
+ ZodSymbol.create = (params) => {
2144
+ return new ZodSymbol({
2145
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2146
+ ...processCreateParams(params)
2147
+ });
2148
+ };
2149
+ var ZodUndefined = class extends ZodType {
2150
+ _parse(input) {
2151
+ const parsedType = this._getType(input);
2152
+ if (parsedType !== ZodParsedType.undefined) {
2153
+ const ctx = this._getOrReturnCtx(input);
2154
+ addIssueToContext(ctx, {
2155
+ code: ZodIssueCode.invalid_type,
2156
+ expected: ZodParsedType.undefined,
2157
+ received: ctx.parsedType
2158
+ });
2159
+ return INVALID;
2160
+ }
2161
+ return OK(input.data);
2162
+ }
2163
+ };
2164
+ ZodUndefined.create = (params) => {
2165
+ return new ZodUndefined({
2166
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2167
+ ...processCreateParams(params)
2168
+ });
2169
+ };
2170
+ var ZodNull = class extends ZodType {
2171
+ _parse(input) {
2172
+ const parsedType = this._getType(input);
2173
+ if (parsedType !== ZodParsedType.null) {
2174
+ const ctx = this._getOrReturnCtx(input);
2175
+ addIssueToContext(ctx, {
2176
+ code: ZodIssueCode.invalid_type,
2177
+ expected: ZodParsedType.null,
2178
+ received: ctx.parsedType
2179
+ });
2180
+ return INVALID;
2181
+ }
2182
+ return OK(input.data);
2183
+ }
2184
+ };
2185
+ ZodNull.create = (params) => {
2186
+ return new ZodNull({
2187
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2188
+ ...processCreateParams(params)
2189
+ });
2190
+ };
2191
+ var ZodAny = class extends ZodType {
2192
+ constructor() {
2193
+ super(...arguments);
2194
+ this._any = true;
2195
+ }
2196
+ _parse(input) {
2197
+ return OK(input.data);
2198
+ }
2199
+ };
2200
+ ZodAny.create = (params) => {
2201
+ return new ZodAny({
2202
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2203
+ ...processCreateParams(params)
2204
+ });
2205
+ };
2206
+ var ZodUnknown = class extends ZodType {
2207
+ constructor() {
2208
+ super(...arguments);
2209
+ this._unknown = true;
2210
+ }
2211
+ _parse(input) {
2212
+ return OK(input.data);
2213
+ }
2214
+ };
2215
+ ZodUnknown.create = (params) => {
2216
+ return new ZodUnknown({
2217
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2218
+ ...processCreateParams(params)
2219
+ });
2220
+ };
2221
+ var ZodNever = class extends ZodType {
2222
+ _parse(input) {
2223
+ const ctx = this._getOrReturnCtx(input);
2224
+ addIssueToContext(ctx, {
2225
+ code: ZodIssueCode.invalid_type,
2226
+ expected: ZodParsedType.never,
2227
+ received: ctx.parsedType
2228
+ });
2229
+ return INVALID;
2230
+ }
2231
+ };
2232
+ ZodNever.create = (params) => {
2233
+ return new ZodNever({
2234
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2235
+ ...processCreateParams(params)
2236
+ });
2237
+ };
2238
+ var ZodVoid = class extends ZodType {
2239
+ _parse(input) {
2240
+ const parsedType = this._getType(input);
2241
+ if (parsedType !== ZodParsedType.undefined) {
2242
+ const ctx = this._getOrReturnCtx(input);
2243
+ addIssueToContext(ctx, {
2244
+ code: ZodIssueCode.invalid_type,
2245
+ expected: ZodParsedType.void,
2246
+ received: ctx.parsedType
2247
+ });
2248
+ return INVALID;
2249
+ }
2250
+ return OK(input.data);
2251
+ }
2252
+ };
2253
+ ZodVoid.create = (params) => {
2254
+ return new ZodVoid({
2255
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2256
+ ...processCreateParams(params)
2257
+ });
2258
+ };
2259
+ var ZodArray = class _ZodArray extends ZodType {
2260
+ _parse(input) {
2261
+ const { ctx, status } = this._processInputParams(input);
2262
+ const def = this._def;
2263
+ if (ctx.parsedType !== ZodParsedType.array) {
2264
+ addIssueToContext(ctx, {
2265
+ code: ZodIssueCode.invalid_type,
2266
+ expected: ZodParsedType.array,
2267
+ received: ctx.parsedType
2268
+ });
2269
+ return INVALID;
2270
+ }
2271
+ if (def.exactLength !== null) {
2272
+ const tooBig = ctx.data.length > def.exactLength.value;
2273
+ const tooSmall = ctx.data.length < def.exactLength.value;
2274
+ if (tooBig || tooSmall) {
2275
+ addIssueToContext(ctx, {
2276
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2277
+ minimum: tooSmall ? def.exactLength.value : void 0,
2278
+ maximum: tooBig ? def.exactLength.value : void 0,
2279
+ type: "array",
2280
+ inclusive: true,
2281
+ exact: true,
2282
+ message: def.exactLength.message
2283
+ });
2284
+ status.dirty();
2285
+ }
2286
+ }
2287
+ if (def.minLength !== null) {
2288
+ if (ctx.data.length < def.minLength.value) {
2289
+ addIssueToContext(ctx, {
2290
+ code: ZodIssueCode.too_small,
2291
+ minimum: def.minLength.value,
2292
+ type: "array",
2293
+ inclusive: true,
2294
+ exact: false,
2295
+ message: def.minLength.message
2296
+ });
2297
+ status.dirty();
2298
+ }
2299
+ }
2300
+ if (def.maxLength !== null) {
2301
+ if (ctx.data.length > def.maxLength.value) {
2302
+ addIssueToContext(ctx, {
2303
+ code: ZodIssueCode.too_big,
2304
+ maximum: def.maxLength.value,
2305
+ type: "array",
2306
+ inclusive: true,
2307
+ exact: false,
2308
+ message: def.maxLength.message
2309
+ });
2310
+ status.dirty();
2311
+ }
2312
+ }
2313
+ if (ctx.common.async) {
2314
+ return Promise.all([...ctx.data].map((item, i) => {
2315
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2316
+ })).then((result2) => {
2317
+ return ParseStatus.mergeArray(status, result2);
2318
+ });
2319
+ }
2320
+ const result = [...ctx.data].map((item, i) => {
2321
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2322
+ });
2323
+ return ParseStatus.mergeArray(status, result);
2324
+ }
2325
+ get element() {
2326
+ return this._def.type;
2327
+ }
2328
+ min(minLength, message) {
2329
+ return new _ZodArray({
2330
+ ...this._def,
2331
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2332
+ });
2333
+ }
2334
+ max(maxLength, message) {
2335
+ return new _ZodArray({
2336
+ ...this._def,
2337
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2338
+ });
2339
+ }
2340
+ length(len, message) {
2341
+ return new _ZodArray({
2342
+ ...this._def,
2343
+ exactLength: { value: len, message: errorUtil.toString(message) }
2344
+ });
2345
+ }
2346
+ nonempty(message) {
2347
+ return this.min(1, message);
2348
+ }
2349
+ };
2350
+ ZodArray.create = (schema, params) => {
2351
+ return new ZodArray({
2352
+ type: schema,
2353
+ minLength: null,
2354
+ maxLength: null,
2355
+ exactLength: null,
2356
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2357
+ ...processCreateParams(params)
2358
+ });
2359
+ };
2360
+ function deepPartialify(schema) {
2361
+ if (schema instanceof ZodObject) {
2362
+ const newShape = {};
2363
+ for (const key in schema.shape) {
2364
+ const fieldSchema = schema.shape[key];
2365
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2366
+ }
2367
+ return new ZodObject({
2368
+ ...schema._def,
2369
+ shape: () => newShape
2370
+ });
2371
+ } else if (schema instanceof ZodArray) {
2372
+ return new ZodArray({
2373
+ ...schema._def,
2374
+ type: deepPartialify(schema.element)
2375
+ });
2376
+ } else if (schema instanceof ZodOptional) {
2377
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2378
+ } else if (schema instanceof ZodNullable) {
2379
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2380
+ } else if (schema instanceof ZodTuple) {
2381
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2382
+ } else {
2383
+ return schema;
2384
+ }
2385
+ }
2386
+ var ZodObject = class _ZodObject extends ZodType {
2387
+ constructor() {
2388
+ super(...arguments);
2389
+ this._cached = null;
2390
+ this.nonstrict = this.passthrough;
2391
+ this.augment = this.extend;
2392
+ }
2393
+ _getCached() {
2394
+ if (this._cached !== null)
2395
+ return this._cached;
2396
+ const shape = this._def.shape();
2397
+ const keys = util.objectKeys(shape);
2398
+ this._cached = { shape, keys };
2399
+ return this._cached;
2400
+ }
2401
+ _parse(input) {
2402
+ const parsedType = this._getType(input);
2403
+ if (parsedType !== ZodParsedType.object) {
2404
+ const ctx2 = this._getOrReturnCtx(input);
2405
+ addIssueToContext(ctx2, {
2406
+ code: ZodIssueCode.invalid_type,
2407
+ expected: ZodParsedType.object,
2408
+ received: ctx2.parsedType
2409
+ });
2410
+ return INVALID;
2411
+ }
2412
+ const { status, ctx } = this._processInputParams(input);
2413
+ const { shape, keys: shapeKeys } = this._getCached();
2414
+ const extraKeys = [];
2415
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2416
+ for (const key in ctx.data) {
2417
+ if (!shapeKeys.includes(key)) {
2418
+ extraKeys.push(key);
2419
+ }
2420
+ }
2421
+ }
2422
+ const pairs = [];
2423
+ for (const key of shapeKeys) {
2424
+ const keyValidator = shape[key];
2425
+ const value = ctx.data[key];
2426
+ pairs.push({
2427
+ key: { status: "valid", value: key },
2428
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2429
+ alwaysSet: key in ctx.data
2430
+ });
2431
+ }
2432
+ if (this._def.catchall instanceof ZodNever) {
2433
+ const unknownKeys = this._def.unknownKeys;
2434
+ if (unknownKeys === "passthrough") {
2435
+ for (const key of extraKeys) {
2436
+ pairs.push({
2437
+ key: { status: "valid", value: key },
2438
+ value: { status: "valid", value: ctx.data[key] }
2439
+ });
2440
+ }
2441
+ } else if (unknownKeys === "strict") {
2442
+ if (extraKeys.length > 0) {
2443
+ addIssueToContext(ctx, {
2444
+ code: ZodIssueCode.unrecognized_keys,
2445
+ keys: extraKeys
2446
+ });
2447
+ status.dirty();
2448
+ }
2449
+ } else if (unknownKeys === "strip") {
2450
+ } else {
2451
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2452
+ }
2453
+ } else {
2454
+ const catchall = this._def.catchall;
2455
+ for (const key of extraKeys) {
2456
+ const value = ctx.data[key];
2457
+ pairs.push({
2458
+ key: { status: "valid", value: key },
2459
+ value: catchall._parse(
2460
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2461
+ //, ctx.child(key), value, getParsedType(value)
2462
+ ),
2463
+ alwaysSet: key in ctx.data
2464
+ });
2465
+ }
2466
+ }
2467
+ if (ctx.common.async) {
2468
+ return Promise.resolve().then(async () => {
2469
+ const syncPairs = [];
2470
+ for (const pair of pairs) {
2471
+ const key = await pair.key;
2472
+ const value = await pair.value;
2473
+ syncPairs.push({
2474
+ key,
2475
+ value,
2476
+ alwaysSet: pair.alwaysSet
2477
+ });
2478
+ }
2479
+ return syncPairs;
2480
+ }).then((syncPairs) => {
2481
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2482
+ });
2483
+ } else {
2484
+ return ParseStatus.mergeObjectSync(status, pairs);
2485
+ }
2486
+ }
2487
+ get shape() {
2488
+ return this._def.shape();
2489
+ }
2490
+ strict(message) {
2491
+ errorUtil.errToObj;
2492
+ return new _ZodObject({
2493
+ ...this._def,
2494
+ unknownKeys: "strict",
2495
+ ...message !== void 0 ? {
2496
+ errorMap: (issue, ctx) => {
2497
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2498
+ if (issue.code === "unrecognized_keys")
2499
+ return {
2500
+ message: errorUtil.errToObj(message).message ?? defaultError
2501
+ };
2502
+ return {
2503
+ message: defaultError
2504
+ };
2505
+ }
2506
+ } : {}
2507
+ });
2508
+ }
2509
+ strip() {
2510
+ return new _ZodObject({
2511
+ ...this._def,
2512
+ unknownKeys: "strip"
2513
+ });
2514
+ }
2515
+ passthrough() {
2516
+ return new _ZodObject({
2517
+ ...this._def,
2518
+ unknownKeys: "passthrough"
2519
+ });
2520
+ }
2521
+ // const AugmentFactory =
2522
+ // <Def extends ZodObjectDef>(def: Def) =>
2523
+ // <Augmentation extends ZodRawShape>(
2524
+ // augmentation: Augmentation
2525
+ // ): ZodObject<
2526
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2527
+ // Def["unknownKeys"],
2528
+ // Def["catchall"]
2529
+ // > => {
2530
+ // return new ZodObject({
2531
+ // ...def,
2532
+ // shape: () => ({
2533
+ // ...def.shape(),
2534
+ // ...augmentation,
2535
+ // }),
2536
+ // }) as any;
2537
+ // };
2538
+ extend(augmentation) {
2539
+ return new _ZodObject({
2540
+ ...this._def,
2541
+ shape: () => ({
2542
+ ...this._def.shape(),
2543
+ ...augmentation
2544
+ })
2545
+ });
2546
+ }
2547
+ /**
2548
+ * Prior to zod@1.0.12 there was a bug in the
2549
+ * inferred type of merged objects. Please
2550
+ * upgrade if you are experiencing issues.
2551
+ */
2552
+ merge(merging) {
2553
+ const merged = new _ZodObject({
2554
+ unknownKeys: merging._def.unknownKeys,
2555
+ catchall: merging._def.catchall,
2556
+ shape: () => ({
2557
+ ...this._def.shape(),
2558
+ ...merging._def.shape()
2559
+ }),
2560
+ typeName: ZodFirstPartyTypeKind.ZodObject
2561
+ });
2562
+ return merged;
2563
+ }
2564
+ // merge<
2565
+ // Incoming extends AnyZodObject,
2566
+ // Augmentation extends Incoming["shape"],
2567
+ // NewOutput extends {
2568
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2569
+ // ? Augmentation[k]["_output"]
2570
+ // : k extends keyof Output
2571
+ // ? Output[k]
2572
+ // : never;
2573
+ // },
2574
+ // NewInput extends {
2575
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2576
+ // ? Augmentation[k]["_input"]
2577
+ // : k extends keyof Input
2578
+ // ? Input[k]
2579
+ // : never;
2580
+ // }
2581
+ // >(
2582
+ // merging: Incoming
2583
+ // ): ZodObject<
2584
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2585
+ // Incoming["_def"]["unknownKeys"],
2586
+ // Incoming["_def"]["catchall"],
2587
+ // NewOutput,
2588
+ // NewInput
2589
+ // > {
2590
+ // const merged: any = new ZodObject({
2591
+ // unknownKeys: merging._def.unknownKeys,
2592
+ // catchall: merging._def.catchall,
2593
+ // shape: () =>
2594
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2595
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2596
+ // }) as any;
2597
+ // return merged;
2598
+ // }
2599
+ setKey(key, schema) {
2600
+ return this.augment({ [key]: schema });
2601
+ }
2602
+ // merge<Incoming extends AnyZodObject>(
2603
+ // merging: Incoming
2604
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2605
+ // ZodObject<
2606
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2607
+ // Incoming["_def"]["unknownKeys"],
2608
+ // Incoming["_def"]["catchall"]
2609
+ // > {
2610
+ // // const mergedShape = objectUtil.mergeShapes(
2611
+ // // this._def.shape(),
2612
+ // // merging._def.shape()
2613
+ // // );
2614
+ // const merged: any = new ZodObject({
2615
+ // unknownKeys: merging._def.unknownKeys,
2616
+ // catchall: merging._def.catchall,
2617
+ // shape: () =>
2618
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2619
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2620
+ // }) as any;
2621
+ // return merged;
2622
+ // }
2623
+ catchall(index) {
2624
+ return new _ZodObject({
2625
+ ...this._def,
2626
+ catchall: index
2627
+ });
2628
+ }
2629
+ pick(mask) {
2630
+ const shape = {};
2631
+ for (const key of util.objectKeys(mask)) {
2632
+ if (mask[key] && this.shape[key]) {
2633
+ shape[key] = this.shape[key];
2634
+ }
2635
+ }
2636
+ return new _ZodObject({
2637
+ ...this._def,
2638
+ shape: () => shape
2639
+ });
2640
+ }
2641
+ omit(mask) {
2642
+ const shape = {};
2643
+ for (const key of util.objectKeys(this.shape)) {
2644
+ if (!mask[key]) {
2645
+ shape[key] = this.shape[key];
2646
+ }
2647
+ }
2648
+ return new _ZodObject({
2649
+ ...this._def,
2650
+ shape: () => shape
2651
+ });
2652
+ }
2653
+ /**
2654
+ * @deprecated
2655
+ */
2656
+ deepPartial() {
2657
+ return deepPartialify(this);
2658
+ }
2659
+ partial(mask) {
2660
+ const newShape = {};
2661
+ for (const key of util.objectKeys(this.shape)) {
2662
+ const fieldSchema = this.shape[key];
2663
+ if (mask && !mask[key]) {
2664
+ newShape[key] = fieldSchema;
2665
+ } else {
2666
+ newShape[key] = fieldSchema.optional();
2667
+ }
2668
+ }
2669
+ return new _ZodObject({
2670
+ ...this._def,
2671
+ shape: () => newShape
2672
+ });
2673
+ }
2674
+ required(mask) {
2675
+ const newShape = {};
2676
+ for (const key of util.objectKeys(this.shape)) {
2677
+ if (mask && !mask[key]) {
2678
+ newShape[key] = this.shape[key];
2679
+ } else {
2680
+ const fieldSchema = this.shape[key];
2681
+ let newField = fieldSchema;
2682
+ while (newField instanceof ZodOptional) {
2683
+ newField = newField._def.innerType;
2684
+ }
2685
+ newShape[key] = newField;
2686
+ }
2687
+ }
2688
+ return new _ZodObject({
2689
+ ...this._def,
2690
+ shape: () => newShape
2691
+ });
2692
+ }
2693
+ keyof() {
2694
+ return createZodEnum(util.objectKeys(this.shape));
2695
+ }
2696
+ };
2697
+ ZodObject.create = (shape, params) => {
2698
+ return new ZodObject({
2699
+ shape: () => shape,
2700
+ unknownKeys: "strip",
2701
+ catchall: ZodNever.create(),
2702
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2703
+ ...processCreateParams(params)
2704
+ });
2705
+ };
2706
+ ZodObject.strictCreate = (shape, params) => {
2707
+ return new ZodObject({
2708
+ shape: () => shape,
2709
+ unknownKeys: "strict",
2710
+ catchall: ZodNever.create(),
2711
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2712
+ ...processCreateParams(params)
2713
+ });
2714
+ };
2715
+ ZodObject.lazycreate = (shape, params) => {
2716
+ return new ZodObject({
2717
+ shape,
2718
+ unknownKeys: "strip",
2719
+ catchall: ZodNever.create(),
2720
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2721
+ ...processCreateParams(params)
2722
+ });
2723
+ };
2724
+ var ZodUnion = class extends ZodType {
2725
+ _parse(input) {
2726
+ const { ctx } = this._processInputParams(input);
2727
+ const options = this._def.options;
2728
+ function handleResults(results) {
2729
+ for (const result of results) {
2730
+ if (result.result.status === "valid") {
2731
+ return result.result;
2732
+ }
2733
+ }
2734
+ for (const result of results) {
2735
+ if (result.result.status === "dirty") {
2736
+ ctx.common.issues.push(...result.ctx.common.issues);
2737
+ return result.result;
2738
+ }
2739
+ }
2740
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2741
+ addIssueToContext(ctx, {
2742
+ code: ZodIssueCode.invalid_union,
2743
+ unionErrors
2744
+ });
2745
+ return INVALID;
2746
+ }
2747
+ if (ctx.common.async) {
2748
+ return Promise.all(options.map(async (option) => {
2749
+ const childCtx = {
2750
+ ...ctx,
2751
+ common: {
2752
+ ...ctx.common,
2753
+ issues: []
2754
+ },
2755
+ parent: null
2756
+ };
2757
+ return {
2758
+ result: await option._parseAsync({
2759
+ data: ctx.data,
2760
+ path: ctx.path,
2761
+ parent: childCtx
2762
+ }),
2763
+ ctx: childCtx
2764
+ };
2765
+ })).then(handleResults);
2766
+ } else {
2767
+ let dirty = void 0;
2768
+ const issues = [];
2769
+ for (const option of options) {
2770
+ const childCtx = {
2771
+ ...ctx,
2772
+ common: {
2773
+ ...ctx.common,
2774
+ issues: []
2775
+ },
2776
+ parent: null
2777
+ };
2778
+ const result = option._parseSync({
2779
+ data: ctx.data,
2780
+ path: ctx.path,
2781
+ parent: childCtx
2782
+ });
2783
+ if (result.status === "valid") {
2784
+ return result;
2785
+ } else if (result.status === "dirty" && !dirty) {
2786
+ dirty = { result, ctx: childCtx };
2787
+ }
2788
+ if (childCtx.common.issues.length) {
2789
+ issues.push(childCtx.common.issues);
2790
+ }
2791
+ }
2792
+ if (dirty) {
2793
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2794
+ return dirty.result;
2795
+ }
2796
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
2797
+ addIssueToContext(ctx, {
2798
+ code: ZodIssueCode.invalid_union,
2799
+ unionErrors
2800
+ });
2801
+ return INVALID;
2802
+ }
2803
+ }
2804
+ get options() {
2805
+ return this._def.options;
2806
+ }
2807
+ };
2808
+ ZodUnion.create = (types, params) => {
2809
+ return new ZodUnion({
2810
+ options: types,
2811
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2812
+ ...processCreateParams(params)
2813
+ });
2814
+ };
2815
+ var getDiscriminator = (type) => {
2816
+ if (type instanceof ZodLazy) {
2817
+ return getDiscriminator(type.schema);
2818
+ } else if (type instanceof ZodEffects) {
2819
+ return getDiscriminator(type.innerType());
2820
+ } else if (type instanceof ZodLiteral) {
2821
+ return [type.value];
2822
+ } else if (type instanceof ZodEnum) {
2823
+ return type.options;
2824
+ } else if (type instanceof ZodNativeEnum) {
2825
+ return util.objectValues(type.enum);
2826
+ } else if (type instanceof ZodDefault) {
2827
+ return getDiscriminator(type._def.innerType);
2828
+ } else if (type instanceof ZodUndefined) {
2829
+ return [void 0];
2830
+ } else if (type instanceof ZodNull) {
2831
+ return [null];
2832
+ } else if (type instanceof ZodOptional) {
2833
+ return [void 0, ...getDiscriminator(type.unwrap())];
2834
+ } else if (type instanceof ZodNullable) {
2835
+ return [null, ...getDiscriminator(type.unwrap())];
2836
+ } else if (type instanceof ZodBranded) {
2837
+ return getDiscriminator(type.unwrap());
2838
+ } else if (type instanceof ZodReadonly) {
2839
+ return getDiscriminator(type.unwrap());
2840
+ } else if (type instanceof ZodCatch) {
2841
+ return getDiscriminator(type._def.innerType);
2842
+ } else {
2843
+ return [];
2844
+ }
2845
+ };
2846
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
2847
+ _parse(input) {
2848
+ const { ctx } = this._processInputParams(input);
2849
+ if (ctx.parsedType !== ZodParsedType.object) {
2850
+ addIssueToContext(ctx, {
2851
+ code: ZodIssueCode.invalid_type,
2852
+ expected: ZodParsedType.object,
2853
+ received: ctx.parsedType
2854
+ });
2855
+ return INVALID;
2856
+ }
2857
+ const discriminator = this.discriminator;
2858
+ const discriminatorValue = ctx.data[discriminator];
2859
+ const option = this.optionsMap.get(discriminatorValue);
2860
+ if (!option) {
2861
+ addIssueToContext(ctx, {
2862
+ code: ZodIssueCode.invalid_union_discriminator,
2863
+ options: Array.from(this.optionsMap.keys()),
2864
+ path: [discriminator]
2865
+ });
2866
+ return INVALID;
2867
+ }
2868
+ if (ctx.common.async) {
2869
+ return option._parseAsync({
2870
+ data: ctx.data,
2871
+ path: ctx.path,
2872
+ parent: ctx
2873
+ });
2874
+ } else {
2875
+ return option._parseSync({
2876
+ data: ctx.data,
2877
+ path: ctx.path,
2878
+ parent: ctx
2879
+ });
2880
+ }
2881
+ }
2882
+ get discriminator() {
2883
+ return this._def.discriminator;
2884
+ }
2885
+ get options() {
2886
+ return this._def.options;
2887
+ }
2888
+ get optionsMap() {
2889
+ return this._def.optionsMap;
2890
+ }
2891
+ /**
2892
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2893
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2894
+ * have a different value for each object in the union.
2895
+ * @param discriminator the name of the discriminator property
2896
+ * @param types an array of object schemas
2897
+ * @param params
2898
+ */
2899
+ static create(discriminator, options, params) {
2900
+ const optionsMap = /* @__PURE__ */ new Map();
2901
+ for (const type of options) {
2902
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2903
+ if (!discriminatorValues.length) {
2904
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2905
+ }
2906
+ for (const value of discriminatorValues) {
2907
+ if (optionsMap.has(value)) {
2908
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2909
+ }
2910
+ optionsMap.set(value, type);
2911
+ }
2912
+ }
2913
+ return new _ZodDiscriminatedUnion({
2914
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2915
+ discriminator,
2916
+ options,
2917
+ optionsMap,
2918
+ ...processCreateParams(params)
2919
+ });
2920
+ }
2921
+ };
2922
+ function mergeValues(a, b) {
2923
+ const aType = getParsedType(a);
2924
+ const bType = getParsedType(b);
2925
+ if (a === b) {
2926
+ return { valid: true, data: a };
2927
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2928
+ const bKeys = util.objectKeys(b);
2929
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2930
+ const newObj = { ...a, ...b };
2931
+ for (const key of sharedKeys) {
2932
+ const sharedValue = mergeValues(a[key], b[key]);
2933
+ if (!sharedValue.valid) {
2934
+ return { valid: false };
2935
+ }
2936
+ newObj[key] = sharedValue.data;
2937
+ }
2938
+ return { valid: true, data: newObj };
2939
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2940
+ if (a.length !== b.length) {
2941
+ return { valid: false };
2942
+ }
2943
+ const newArray = [];
2944
+ for (let index = 0; index < a.length; index++) {
2945
+ const itemA = a[index];
2946
+ const itemB = b[index];
2947
+ const sharedValue = mergeValues(itemA, itemB);
2948
+ if (!sharedValue.valid) {
2949
+ return { valid: false };
2950
+ }
2951
+ newArray.push(sharedValue.data);
2952
+ }
2953
+ return { valid: true, data: newArray };
2954
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
2955
+ return { valid: true, data: a };
2956
+ } else {
2957
+ return { valid: false };
2958
+ }
2959
+ }
2960
+ var ZodIntersection = class extends ZodType {
2961
+ _parse(input) {
2962
+ const { status, ctx } = this._processInputParams(input);
2963
+ const handleParsed = (parsedLeft, parsedRight) => {
2964
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2965
+ return INVALID;
2966
+ }
2967
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2968
+ if (!merged.valid) {
2969
+ addIssueToContext(ctx, {
2970
+ code: ZodIssueCode.invalid_intersection_types
2971
+ });
2972
+ return INVALID;
2973
+ }
2974
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2975
+ status.dirty();
2976
+ }
2977
+ return { status: status.value, value: merged.data };
2978
+ };
2979
+ if (ctx.common.async) {
2980
+ return Promise.all([
2981
+ this._def.left._parseAsync({
2982
+ data: ctx.data,
2983
+ path: ctx.path,
2984
+ parent: ctx
2985
+ }),
2986
+ this._def.right._parseAsync({
2987
+ data: ctx.data,
2988
+ path: ctx.path,
2989
+ parent: ctx
2990
+ })
2991
+ ]).then(([left, right]) => handleParsed(left, right));
2992
+ } else {
2993
+ return handleParsed(this._def.left._parseSync({
2994
+ data: ctx.data,
2995
+ path: ctx.path,
2996
+ parent: ctx
2997
+ }), this._def.right._parseSync({
2998
+ data: ctx.data,
2999
+ path: ctx.path,
3000
+ parent: ctx
3001
+ }));
3002
+ }
3003
+ }
3004
+ };
3005
+ ZodIntersection.create = (left, right, params) => {
3006
+ return new ZodIntersection({
3007
+ left,
3008
+ right,
3009
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
3010
+ ...processCreateParams(params)
3011
+ });
3012
+ };
3013
+ var ZodTuple = class _ZodTuple extends ZodType {
3014
+ _parse(input) {
3015
+ const { status, ctx } = this._processInputParams(input);
3016
+ if (ctx.parsedType !== ZodParsedType.array) {
3017
+ addIssueToContext(ctx, {
3018
+ code: ZodIssueCode.invalid_type,
3019
+ expected: ZodParsedType.array,
3020
+ received: ctx.parsedType
3021
+ });
3022
+ return INVALID;
3023
+ }
3024
+ if (ctx.data.length < this._def.items.length) {
3025
+ addIssueToContext(ctx, {
3026
+ code: ZodIssueCode.too_small,
3027
+ minimum: this._def.items.length,
3028
+ inclusive: true,
3029
+ exact: false,
3030
+ type: "array"
3031
+ });
3032
+ return INVALID;
3033
+ }
3034
+ const rest = this._def.rest;
3035
+ if (!rest && ctx.data.length > this._def.items.length) {
3036
+ addIssueToContext(ctx, {
3037
+ code: ZodIssueCode.too_big,
3038
+ maximum: this._def.items.length,
3039
+ inclusive: true,
3040
+ exact: false,
3041
+ type: "array"
3042
+ });
3043
+ status.dirty();
3044
+ }
3045
+ const items = [...ctx.data].map((item, itemIndex) => {
3046
+ const schema = this._def.items[itemIndex] || this._def.rest;
3047
+ if (!schema)
3048
+ return null;
3049
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3050
+ }).filter((x) => !!x);
3051
+ if (ctx.common.async) {
3052
+ return Promise.all(items).then((results) => {
3053
+ return ParseStatus.mergeArray(status, results);
3054
+ });
3055
+ } else {
3056
+ return ParseStatus.mergeArray(status, items);
3057
+ }
3058
+ }
3059
+ get items() {
3060
+ return this._def.items;
3061
+ }
3062
+ rest(rest) {
3063
+ return new _ZodTuple({
3064
+ ...this._def,
3065
+ rest
3066
+ });
3067
+ }
3068
+ };
3069
+ ZodTuple.create = (schemas, params) => {
3070
+ if (!Array.isArray(schemas)) {
3071
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3072
+ }
3073
+ return new ZodTuple({
3074
+ items: schemas,
3075
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
3076
+ rest: null,
3077
+ ...processCreateParams(params)
3078
+ });
3079
+ };
3080
+ var ZodRecord = class _ZodRecord extends ZodType {
3081
+ get keySchema() {
3082
+ return this._def.keyType;
3083
+ }
3084
+ get valueSchema() {
3085
+ return this._def.valueType;
3086
+ }
3087
+ _parse(input) {
3088
+ const { status, ctx } = this._processInputParams(input);
3089
+ if (ctx.parsedType !== ZodParsedType.object) {
3090
+ addIssueToContext(ctx, {
3091
+ code: ZodIssueCode.invalid_type,
3092
+ expected: ZodParsedType.object,
3093
+ received: ctx.parsedType
3094
+ });
3095
+ return INVALID;
3096
+ }
3097
+ const pairs = [];
3098
+ const keyType = this._def.keyType;
3099
+ const valueType = this._def.valueType;
3100
+ for (const key in ctx.data) {
3101
+ pairs.push({
3102
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3103
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3104
+ alwaysSet: key in ctx.data
3105
+ });
3106
+ }
3107
+ if (ctx.common.async) {
3108
+ return ParseStatus.mergeObjectAsync(status, pairs);
3109
+ } else {
3110
+ return ParseStatus.mergeObjectSync(status, pairs);
3111
+ }
3112
+ }
3113
+ get element() {
3114
+ return this._def.valueType;
3115
+ }
3116
+ static create(first, second, third) {
3117
+ if (second instanceof ZodType) {
3118
+ return new _ZodRecord({
3119
+ keyType: first,
3120
+ valueType: second,
3121
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3122
+ ...processCreateParams(third)
3123
+ });
3124
+ }
3125
+ return new _ZodRecord({
3126
+ keyType: ZodString.create(),
3127
+ valueType: first,
3128
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3129
+ ...processCreateParams(second)
3130
+ });
3131
+ }
3132
+ };
3133
+ var ZodMap = class extends ZodType {
3134
+ get keySchema() {
3135
+ return this._def.keyType;
3136
+ }
3137
+ get valueSchema() {
3138
+ return this._def.valueType;
3139
+ }
3140
+ _parse(input) {
3141
+ const { status, ctx } = this._processInputParams(input);
3142
+ if (ctx.parsedType !== ZodParsedType.map) {
3143
+ addIssueToContext(ctx, {
3144
+ code: ZodIssueCode.invalid_type,
3145
+ expected: ZodParsedType.map,
3146
+ received: ctx.parsedType
3147
+ });
3148
+ return INVALID;
3149
+ }
3150
+ const keyType = this._def.keyType;
3151
+ const valueType = this._def.valueType;
3152
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3153
+ return {
3154
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3155
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
3156
+ };
3157
+ });
3158
+ if (ctx.common.async) {
3159
+ const finalMap = /* @__PURE__ */ new Map();
3160
+ return Promise.resolve().then(async () => {
3161
+ for (const pair of pairs) {
3162
+ const key = await pair.key;
3163
+ const value = await pair.value;
3164
+ if (key.status === "aborted" || value.status === "aborted") {
3165
+ return INVALID;
3166
+ }
3167
+ if (key.status === "dirty" || value.status === "dirty") {
3168
+ status.dirty();
3169
+ }
3170
+ finalMap.set(key.value, value.value);
3171
+ }
3172
+ return { status: status.value, value: finalMap };
3173
+ });
3174
+ } else {
3175
+ const finalMap = /* @__PURE__ */ new Map();
3176
+ for (const pair of pairs) {
3177
+ const key = pair.key;
3178
+ const value = pair.value;
3179
+ if (key.status === "aborted" || value.status === "aborted") {
3180
+ return INVALID;
3181
+ }
3182
+ if (key.status === "dirty" || value.status === "dirty") {
3183
+ status.dirty();
3184
+ }
3185
+ finalMap.set(key.value, value.value);
3186
+ }
3187
+ return { status: status.value, value: finalMap };
3188
+ }
3189
+ }
3190
+ };
3191
+ ZodMap.create = (keyType, valueType, params) => {
3192
+ return new ZodMap({
3193
+ valueType,
3194
+ keyType,
3195
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3196
+ ...processCreateParams(params)
3197
+ });
3198
+ };
3199
+ var ZodSet = class _ZodSet extends ZodType {
3200
+ _parse(input) {
3201
+ const { status, ctx } = this._processInputParams(input);
3202
+ if (ctx.parsedType !== ZodParsedType.set) {
3203
+ addIssueToContext(ctx, {
3204
+ code: ZodIssueCode.invalid_type,
3205
+ expected: ZodParsedType.set,
3206
+ received: ctx.parsedType
3207
+ });
3208
+ return INVALID;
3209
+ }
3210
+ const def = this._def;
3211
+ if (def.minSize !== null) {
3212
+ if (ctx.data.size < def.minSize.value) {
3213
+ addIssueToContext(ctx, {
3214
+ code: ZodIssueCode.too_small,
3215
+ minimum: def.minSize.value,
3216
+ type: "set",
3217
+ inclusive: true,
3218
+ exact: false,
3219
+ message: def.minSize.message
3220
+ });
3221
+ status.dirty();
3222
+ }
3223
+ }
3224
+ if (def.maxSize !== null) {
3225
+ if (ctx.data.size > def.maxSize.value) {
3226
+ addIssueToContext(ctx, {
3227
+ code: ZodIssueCode.too_big,
3228
+ maximum: def.maxSize.value,
3229
+ type: "set",
3230
+ inclusive: true,
3231
+ exact: false,
3232
+ message: def.maxSize.message
3233
+ });
3234
+ status.dirty();
3235
+ }
3236
+ }
3237
+ const valueType = this._def.valueType;
3238
+ function finalizeSet(elements2) {
3239
+ const parsedSet = /* @__PURE__ */ new Set();
3240
+ for (const element of elements2) {
3241
+ if (element.status === "aborted")
3242
+ return INVALID;
3243
+ if (element.status === "dirty")
3244
+ status.dirty();
3245
+ parsedSet.add(element.value);
3246
+ }
3247
+ return { status: status.value, value: parsedSet };
3248
+ }
3249
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3250
+ if (ctx.common.async) {
3251
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3252
+ } else {
3253
+ return finalizeSet(elements);
3254
+ }
3255
+ }
3256
+ min(minSize, message) {
3257
+ return new _ZodSet({
3258
+ ...this._def,
3259
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3260
+ });
3261
+ }
3262
+ max(maxSize, message) {
3263
+ return new _ZodSet({
3264
+ ...this._def,
3265
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3266
+ });
3267
+ }
3268
+ size(size, message) {
3269
+ return this.min(size, message).max(size, message);
3270
+ }
3271
+ nonempty(message) {
3272
+ return this.min(1, message);
3273
+ }
3274
+ };
3275
+ ZodSet.create = (valueType, params) => {
3276
+ return new ZodSet({
3277
+ valueType,
3278
+ minSize: null,
3279
+ maxSize: null,
3280
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3281
+ ...processCreateParams(params)
3282
+ });
3283
+ };
3284
+ var ZodFunction = class _ZodFunction extends ZodType {
3285
+ constructor() {
3286
+ super(...arguments);
3287
+ this.validate = this.implement;
3288
+ }
3289
+ _parse(input) {
3290
+ const { ctx } = this._processInputParams(input);
3291
+ if (ctx.parsedType !== ZodParsedType.function) {
3292
+ addIssueToContext(ctx, {
3293
+ code: ZodIssueCode.invalid_type,
3294
+ expected: ZodParsedType.function,
3295
+ received: ctx.parsedType
3296
+ });
3297
+ return INVALID;
3298
+ }
3299
+ function makeArgsIssue(args, error) {
3300
+ return makeIssue({
3301
+ data: args,
3302
+ path: ctx.path,
3303
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3304
+ issueData: {
3305
+ code: ZodIssueCode.invalid_arguments,
3306
+ argumentsError: error
3307
+ }
3308
+ });
3309
+ }
3310
+ function makeReturnsIssue(returns, error) {
3311
+ return makeIssue({
3312
+ data: returns,
3313
+ path: ctx.path,
3314
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
3315
+ issueData: {
3316
+ code: ZodIssueCode.invalid_return_type,
3317
+ returnTypeError: error
3318
+ }
3319
+ });
3320
+ }
3321
+ const params = { errorMap: ctx.common.contextualErrorMap };
3322
+ const fn = ctx.data;
3323
+ if (this._def.returns instanceof ZodPromise) {
3324
+ const me = this;
3325
+ return OK(async function(...args) {
3326
+ const error = new ZodError([]);
3327
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3328
+ error.addIssue(makeArgsIssue(args, e));
3329
+ throw error;
3330
+ });
3331
+ const result = await Reflect.apply(fn, this, parsedArgs);
3332
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3333
+ error.addIssue(makeReturnsIssue(result, e));
3334
+ throw error;
3335
+ });
3336
+ return parsedReturns;
3337
+ });
3338
+ } else {
3339
+ const me = this;
3340
+ return OK(function(...args) {
3341
+ const parsedArgs = me._def.args.safeParse(args, params);
3342
+ if (!parsedArgs.success) {
3343
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3344
+ }
3345
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3346
+ const parsedReturns = me._def.returns.safeParse(result, params);
3347
+ if (!parsedReturns.success) {
3348
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3349
+ }
3350
+ return parsedReturns.data;
3351
+ });
3352
+ }
3353
+ }
3354
+ parameters() {
3355
+ return this._def.args;
3356
+ }
3357
+ returnType() {
3358
+ return this._def.returns;
3359
+ }
3360
+ args(...items) {
3361
+ return new _ZodFunction({
3362
+ ...this._def,
3363
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3364
+ });
3365
+ }
3366
+ returns(returnType) {
3367
+ return new _ZodFunction({
3368
+ ...this._def,
3369
+ returns: returnType
3370
+ });
3371
+ }
3372
+ implement(func) {
3373
+ const validatedFunc = this.parse(func);
3374
+ return validatedFunc;
3375
+ }
3376
+ strictImplement(func) {
3377
+ const validatedFunc = this.parse(func);
3378
+ return validatedFunc;
3379
+ }
3380
+ static create(args, returns, params) {
3381
+ return new _ZodFunction({
3382
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3383
+ returns: returns || ZodUnknown.create(),
3384
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3385
+ ...processCreateParams(params)
3386
+ });
3387
+ }
3388
+ };
3389
+ var ZodLazy = class extends ZodType {
3390
+ get schema() {
3391
+ return this._def.getter();
3392
+ }
3393
+ _parse(input) {
3394
+ const { ctx } = this._processInputParams(input);
3395
+ const lazySchema = this._def.getter();
3396
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3397
+ }
3398
+ };
3399
+ ZodLazy.create = (getter, params) => {
3400
+ return new ZodLazy({
3401
+ getter,
3402
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3403
+ ...processCreateParams(params)
3404
+ });
3405
+ };
3406
+ var ZodLiteral = class extends ZodType {
3407
+ _parse(input) {
3408
+ if (input.data !== this._def.value) {
3409
+ const ctx = this._getOrReturnCtx(input);
3410
+ addIssueToContext(ctx, {
3411
+ received: ctx.data,
3412
+ code: ZodIssueCode.invalid_literal,
3413
+ expected: this._def.value
3414
+ });
3415
+ return INVALID;
3416
+ }
3417
+ return { status: "valid", value: input.data };
3418
+ }
3419
+ get value() {
3420
+ return this._def.value;
3421
+ }
3422
+ };
3423
+ ZodLiteral.create = (value, params) => {
3424
+ return new ZodLiteral({
3425
+ value,
3426
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3427
+ ...processCreateParams(params)
3428
+ });
3429
+ };
3430
+ function createZodEnum(values, params) {
3431
+ return new ZodEnum({
3432
+ values,
3433
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3434
+ ...processCreateParams(params)
3435
+ });
3436
+ }
3437
+ var ZodEnum = class _ZodEnum extends ZodType {
3438
+ _parse(input) {
3439
+ if (typeof input.data !== "string") {
3440
+ const ctx = this._getOrReturnCtx(input);
3441
+ const expectedValues = this._def.values;
3442
+ addIssueToContext(ctx, {
3443
+ expected: util.joinValues(expectedValues),
3444
+ received: ctx.parsedType,
3445
+ code: ZodIssueCode.invalid_type
3446
+ });
3447
+ return INVALID;
3448
+ }
3449
+ if (!this._cache) {
3450
+ this._cache = new Set(this._def.values);
3451
+ }
3452
+ if (!this._cache.has(input.data)) {
3453
+ const ctx = this._getOrReturnCtx(input);
3454
+ const expectedValues = this._def.values;
3455
+ addIssueToContext(ctx, {
3456
+ received: ctx.data,
3457
+ code: ZodIssueCode.invalid_enum_value,
3458
+ options: expectedValues
3459
+ });
3460
+ return INVALID;
3461
+ }
3462
+ return OK(input.data);
3463
+ }
3464
+ get options() {
3465
+ return this._def.values;
3466
+ }
3467
+ get enum() {
3468
+ const enumValues = {};
3469
+ for (const val of this._def.values) {
3470
+ enumValues[val] = val;
3471
+ }
3472
+ return enumValues;
3473
+ }
3474
+ get Values() {
3475
+ const enumValues = {};
3476
+ for (const val of this._def.values) {
3477
+ enumValues[val] = val;
3478
+ }
3479
+ return enumValues;
3480
+ }
3481
+ get Enum() {
3482
+ const enumValues = {};
3483
+ for (const val of this._def.values) {
3484
+ enumValues[val] = val;
3485
+ }
3486
+ return enumValues;
3487
+ }
3488
+ extract(values, newDef = this._def) {
3489
+ return _ZodEnum.create(values, {
3490
+ ...this._def,
3491
+ ...newDef
3492
+ });
3493
+ }
3494
+ exclude(values, newDef = this._def) {
3495
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3496
+ ...this._def,
3497
+ ...newDef
3498
+ });
3499
+ }
3500
+ };
3501
+ ZodEnum.create = createZodEnum;
3502
+ var ZodNativeEnum = class extends ZodType {
3503
+ _parse(input) {
3504
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3505
+ const ctx = this._getOrReturnCtx(input);
3506
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3507
+ const expectedValues = util.objectValues(nativeEnumValues);
3508
+ addIssueToContext(ctx, {
3509
+ expected: util.joinValues(expectedValues),
3510
+ received: ctx.parsedType,
3511
+ code: ZodIssueCode.invalid_type
3512
+ });
3513
+ return INVALID;
3514
+ }
3515
+ if (!this._cache) {
3516
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
3517
+ }
3518
+ if (!this._cache.has(input.data)) {
3519
+ const expectedValues = util.objectValues(nativeEnumValues);
3520
+ addIssueToContext(ctx, {
3521
+ received: ctx.data,
3522
+ code: ZodIssueCode.invalid_enum_value,
3523
+ options: expectedValues
3524
+ });
3525
+ return INVALID;
3526
+ }
3527
+ return OK(input.data);
3528
+ }
3529
+ get enum() {
3530
+ return this._def.values;
3531
+ }
3532
+ };
3533
+ ZodNativeEnum.create = (values, params) => {
3534
+ return new ZodNativeEnum({
3535
+ values,
3536
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3537
+ ...processCreateParams(params)
3538
+ });
3539
+ };
3540
+ var ZodPromise = class extends ZodType {
3541
+ unwrap() {
3542
+ return this._def.type;
3543
+ }
3544
+ _parse(input) {
3545
+ const { ctx } = this._processInputParams(input);
3546
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3547
+ addIssueToContext(ctx, {
3548
+ code: ZodIssueCode.invalid_type,
3549
+ expected: ZodParsedType.promise,
3550
+ received: ctx.parsedType
3551
+ });
3552
+ return INVALID;
3553
+ }
3554
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3555
+ return OK(promisified.then((data) => {
3556
+ return this._def.type.parseAsync(data, {
3557
+ path: ctx.path,
3558
+ errorMap: ctx.common.contextualErrorMap
3559
+ });
3560
+ }));
3561
+ }
3562
+ };
3563
+ ZodPromise.create = (schema, params) => {
3564
+ return new ZodPromise({
3565
+ type: schema,
3566
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3567
+ ...processCreateParams(params)
3568
+ });
3569
+ };
3570
+ var ZodEffects = class extends ZodType {
3571
+ innerType() {
3572
+ return this._def.schema;
3573
+ }
3574
+ sourceType() {
3575
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3576
+ }
3577
+ _parse(input) {
3578
+ const { status, ctx } = this._processInputParams(input);
3579
+ const effect = this._def.effect || null;
3580
+ const checkCtx = {
3581
+ addIssue: (arg) => {
3582
+ addIssueToContext(ctx, arg);
3583
+ if (arg.fatal) {
3584
+ status.abort();
3585
+ } else {
3586
+ status.dirty();
3587
+ }
3588
+ },
3589
+ get path() {
3590
+ return ctx.path;
3591
+ }
3592
+ };
3593
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3594
+ if (effect.type === "preprocess") {
3595
+ const processed = effect.transform(ctx.data, checkCtx);
3596
+ if (ctx.common.async) {
3597
+ return Promise.resolve(processed).then(async (processed2) => {
3598
+ if (status.value === "aborted")
3599
+ return INVALID;
3600
+ const result = await this._def.schema._parseAsync({
3601
+ data: processed2,
3602
+ path: ctx.path,
3603
+ parent: ctx
3604
+ });
3605
+ if (result.status === "aborted")
3606
+ return INVALID;
3607
+ if (result.status === "dirty")
3608
+ return DIRTY(result.value);
3609
+ if (status.value === "dirty")
3610
+ return DIRTY(result.value);
3611
+ return result;
3612
+ });
3613
+ } else {
3614
+ if (status.value === "aborted")
3615
+ return INVALID;
3616
+ const result = this._def.schema._parseSync({
3617
+ data: processed,
3618
+ path: ctx.path,
3619
+ parent: ctx
3620
+ });
3621
+ if (result.status === "aborted")
3622
+ return INVALID;
3623
+ if (result.status === "dirty")
3624
+ return DIRTY(result.value);
3625
+ if (status.value === "dirty")
3626
+ return DIRTY(result.value);
3627
+ return result;
3628
+ }
3629
+ }
3630
+ if (effect.type === "refinement") {
3631
+ const executeRefinement = (acc) => {
3632
+ const result = effect.refinement(acc, checkCtx);
3633
+ if (ctx.common.async) {
3634
+ return Promise.resolve(result);
3635
+ }
3636
+ if (result instanceof Promise) {
3637
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3638
+ }
3639
+ return acc;
3640
+ };
3641
+ if (ctx.common.async === false) {
3642
+ const inner = this._def.schema._parseSync({
3643
+ data: ctx.data,
3644
+ path: ctx.path,
3645
+ parent: ctx
3646
+ });
3647
+ if (inner.status === "aborted")
3648
+ return INVALID;
3649
+ if (inner.status === "dirty")
3650
+ status.dirty();
3651
+ executeRefinement(inner.value);
3652
+ return { status: status.value, value: inner.value };
3653
+ } else {
3654
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3655
+ if (inner.status === "aborted")
3656
+ return INVALID;
3657
+ if (inner.status === "dirty")
3658
+ status.dirty();
3659
+ return executeRefinement(inner.value).then(() => {
3660
+ return { status: status.value, value: inner.value };
3661
+ });
3662
+ });
3663
+ }
3664
+ }
3665
+ if (effect.type === "transform") {
3666
+ if (ctx.common.async === false) {
3667
+ const base = this._def.schema._parseSync({
3668
+ data: ctx.data,
3669
+ path: ctx.path,
3670
+ parent: ctx
3671
+ });
3672
+ if (!isValid(base))
3673
+ return INVALID;
3674
+ const result = effect.transform(base.value, checkCtx);
3675
+ if (result instanceof Promise) {
3676
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3677
+ }
3678
+ return { status: status.value, value: result };
3679
+ } else {
3680
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3681
+ if (!isValid(base))
3682
+ return INVALID;
3683
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
3684
+ status: status.value,
3685
+ value: result
3686
+ }));
3687
+ });
3688
+ }
3689
+ }
3690
+ util.assertNever(effect);
3691
+ }
3692
+ };
3693
+ ZodEffects.create = (schema, effect, params) => {
3694
+ return new ZodEffects({
3695
+ schema,
3696
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3697
+ effect,
3698
+ ...processCreateParams(params)
3699
+ });
3700
+ };
3701
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3702
+ return new ZodEffects({
3703
+ schema,
3704
+ effect: { type: "preprocess", transform: preprocess },
3705
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3706
+ ...processCreateParams(params)
3707
+ });
3708
+ };
3709
+ var ZodOptional = class extends ZodType {
3710
+ _parse(input) {
3711
+ const parsedType = this._getType(input);
3712
+ if (parsedType === ZodParsedType.undefined) {
3713
+ return OK(void 0);
3714
+ }
3715
+ return this._def.innerType._parse(input);
3716
+ }
3717
+ unwrap() {
3718
+ return this._def.innerType;
3719
+ }
3720
+ };
3721
+ ZodOptional.create = (type, params) => {
3722
+ return new ZodOptional({
3723
+ innerType: type,
3724
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3725
+ ...processCreateParams(params)
3726
+ });
3727
+ };
3728
+ var ZodNullable = class extends ZodType {
3729
+ _parse(input) {
3730
+ const parsedType = this._getType(input);
3731
+ if (parsedType === ZodParsedType.null) {
3732
+ return OK(null);
3733
+ }
3734
+ return this._def.innerType._parse(input);
3735
+ }
3736
+ unwrap() {
3737
+ return this._def.innerType;
3738
+ }
3739
+ };
3740
+ ZodNullable.create = (type, params) => {
3741
+ return new ZodNullable({
3742
+ innerType: type,
3743
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3744
+ ...processCreateParams(params)
3745
+ });
3746
+ };
3747
+ var ZodDefault = class extends ZodType {
3748
+ _parse(input) {
3749
+ const { ctx } = this._processInputParams(input);
3750
+ let data = ctx.data;
3751
+ if (ctx.parsedType === ZodParsedType.undefined) {
3752
+ data = this._def.defaultValue();
3753
+ }
3754
+ return this._def.innerType._parse({
3755
+ data,
3756
+ path: ctx.path,
3757
+ parent: ctx
3758
+ });
3759
+ }
3760
+ removeDefault() {
3761
+ return this._def.innerType;
3762
+ }
3763
+ };
3764
+ ZodDefault.create = (type, params) => {
3765
+ return new ZodDefault({
3766
+ innerType: type,
3767
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3768
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3769
+ ...processCreateParams(params)
3770
+ });
3771
+ };
3772
+ var ZodCatch = class extends ZodType {
3773
+ _parse(input) {
3774
+ const { ctx } = this._processInputParams(input);
3775
+ const newCtx = {
3776
+ ...ctx,
3777
+ common: {
3778
+ ...ctx.common,
3779
+ issues: []
3780
+ }
3781
+ };
3782
+ const result = this._def.innerType._parse({
3783
+ data: newCtx.data,
3784
+ path: newCtx.path,
3785
+ parent: {
3786
+ ...newCtx
3787
+ }
3788
+ });
3789
+ if (isAsync(result)) {
3790
+ return result.then((result2) => {
3791
+ return {
3792
+ status: "valid",
3793
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
3794
+ get error() {
3795
+ return new ZodError(newCtx.common.issues);
3796
+ },
3797
+ input: newCtx.data
3798
+ })
3799
+ };
3800
+ });
3801
+ } else {
3802
+ return {
3803
+ status: "valid",
3804
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3805
+ get error() {
3806
+ return new ZodError(newCtx.common.issues);
3807
+ },
3808
+ input: newCtx.data
3809
+ })
3810
+ };
3811
+ }
3812
+ }
3813
+ removeCatch() {
3814
+ return this._def.innerType;
3815
+ }
3816
+ };
3817
+ ZodCatch.create = (type, params) => {
3818
+ return new ZodCatch({
3819
+ innerType: type,
3820
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3821
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3822
+ ...processCreateParams(params)
3823
+ });
3824
+ };
3825
+ var ZodNaN = class extends ZodType {
3826
+ _parse(input) {
3827
+ const parsedType = this._getType(input);
3828
+ if (parsedType !== ZodParsedType.nan) {
3829
+ const ctx = this._getOrReturnCtx(input);
3830
+ addIssueToContext(ctx, {
3831
+ code: ZodIssueCode.invalid_type,
3832
+ expected: ZodParsedType.nan,
3833
+ received: ctx.parsedType
3834
+ });
3835
+ return INVALID;
3836
+ }
3837
+ return { status: "valid", value: input.data };
3838
+ }
3839
+ };
3840
+ ZodNaN.create = (params) => {
3841
+ return new ZodNaN({
3842
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3843
+ ...processCreateParams(params)
3844
+ });
3845
+ };
3846
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
3847
+ var ZodBranded = class extends ZodType {
3848
+ _parse(input) {
3849
+ const { ctx } = this._processInputParams(input);
3850
+ const data = ctx.data;
3851
+ return this._def.type._parse({
3852
+ data,
3853
+ path: ctx.path,
3854
+ parent: ctx
3855
+ });
3856
+ }
3857
+ unwrap() {
3858
+ return this._def.type;
3859
+ }
3860
+ };
3861
+ var ZodPipeline = class _ZodPipeline extends ZodType {
3862
+ _parse(input) {
3863
+ const { status, ctx } = this._processInputParams(input);
3864
+ if (ctx.common.async) {
3865
+ const handleAsync = async () => {
3866
+ const inResult = await this._def.in._parseAsync({
3867
+ data: ctx.data,
3868
+ path: ctx.path,
3869
+ parent: ctx
3870
+ });
3871
+ if (inResult.status === "aborted")
3872
+ return INVALID;
3873
+ if (inResult.status === "dirty") {
3874
+ status.dirty();
3875
+ return DIRTY(inResult.value);
3876
+ } else {
3877
+ return this._def.out._parseAsync({
3878
+ data: inResult.value,
3879
+ path: ctx.path,
3880
+ parent: ctx
3881
+ });
3882
+ }
3883
+ };
3884
+ return handleAsync();
3885
+ } else {
3886
+ const inResult = this._def.in._parseSync({
3887
+ data: ctx.data,
3888
+ path: ctx.path,
3889
+ parent: ctx
3890
+ });
3891
+ if (inResult.status === "aborted")
3892
+ return INVALID;
3893
+ if (inResult.status === "dirty") {
3894
+ status.dirty();
3895
+ return {
3896
+ status: "dirty",
3897
+ value: inResult.value
3898
+ };
3899
+ } else {
3900
+ return this._def.out._parseSync({
3901
+ data: inResult.value,
3902
+ path: ctx.path,
3903
+ parent: ctx
3904
+ });
3905
+ }
3906
+ }
3907
+ }
3908
+ static create(a, b) {
3909
+ return new _ZodPipeline({
3910
+ in: a,
3911
+ out: b,
3912
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3913
+ });
3914
+ }
3915
+ };
3916
+ var ZodReadonly = class extends ZodType {
3917
+ _parse(input) {
3918
+ const result = this._def.innerType._parse(input);
3919
+ const freeze = (data) => {
3920
+ if (isValid(data)) {
3921
+ data.value = Object.freeze(data.value);
3922
+ }
3923
+ return data;
3924
+ };
3925
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3926
+ }
3927
+ unwrap() {
3928
+ return this._def.innerType;
3929
+ }
3930
+ };
3931
+ ZodReadonly.create = (type, params) => {
3932
+ return new ZodReadonly({
3933
+ innerType: type,
3934
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3935
+ ...processCreateParams(params)
3936
+ });
3937
+ };
3938
+ function cleanParams(params, data) {
3939
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3940
+ const p2 = typeof p === "string" ? { message: p } : p;
3941
+ return p2;
3942
+ }
3943
+ function custom(check, _params = {}, fatal) {
3944
+ if (check)
3945
+ return ZodAny.create().superRefine((data, ctx) => {
3946
+ const r = check(data);
3947
+ if (r instanceof Promise) {
3948
+ return r.then((r2) => {
3949
+ if (!r2) {
3950
+ const params = cleanParams(_params, data);
3951
+ const _fatal = params.fatal ?? fatal ?? true;
3952
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3953
+ }
3954
+ });
3955
+ }
3956
+ if (!r) {
3957
+ const params = cleanParams(_params, data);
3958
+ const _fatal = params.fatal ?? fatal ?? true;
3959
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3960
+ }
3961
+ return;
3962
+ });
3963
+ return ZodAny.create();
3964
+ }
3965
+ var late = {
3966
+ object: ZodObject.lazycreate
3967
+ };
3968
+ var ZodFirstPartyTypeKind;
3969
+ (function(ZodFirstPartyTypeKind2) {
3970
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3971
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3972
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3973
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3974
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3975
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3976
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3977
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3978
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3979
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3980
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3981
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3982
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3983
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3984
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3985
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3986
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3987
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3988
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3989
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3990
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3991
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3992
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3993
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3994
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3995
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3996
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3997
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3998
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3999
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4000
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4001
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4002
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4003
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4004
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4005
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4006
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4007
+ var instanceOfType = (cls, params = {
4008
+ message: `Input not instance of ${cls.name}`
4009
+ }) => custom((data) => data instanceof cls, params);
4010
+ var stringType = ZodString.create;
4011
+ var numberType = ZodNumber.create;
4012
+ var nanType = ZodNaN.create;
4013
+ var bigIntType = ZodBigInt.create;
4014
+ var booleanType = ZodBoolean.create;
4015
+ var dateType = ZodDate.create;
4016
+ var symbolType = ZodSymbol.create;
4017
+ var undefinedType = ZodUndefined.create;
4018
+ var nullType = ZodNull.create;
4019
+ var anyType = ZodAny.create;
4020
+ var unknownType = ZodUnknown.create;
4021
+ var neverType = ZodNever.create;
4022
+ var voidType = ZodVoid.create;
4023
+ var arrayType = ZodArray.create;
4024
+ var objectType = ZodObject.create;
4025
+ var strictObjectType = ZodObject.strictCreate;
4026
+ var unionType = ZodUnion.create;
4027
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
4028
+ var intersectionType = ZodIntersection.create;
4029
+ var tupleType = ZodTuple.create;
4030
+ var recordType = ZodRecord.create;
4031
+ var mapType = ZodMap.create;
4032
+ var setType = ZodSet.create;
4033
+ var functionType = ZodFunction.create;
4034
+ var lazyType = ZodLazy.create;
4035
+ var literalType = ZodLiteral.create;
4036
+ var enumType = ZodEnum.create;
4037
+ var nativeEnumType = ZodNativeEnum.create;
4038
+ var promiseType = ZodPromise.create;
4039
+ var effectsType = ZodEffects.create;
4040
+ var optionalType = ZodOptional.create;
4041
+ var nullableType = ZodNullable.create;
4042
+ var preprocessType = ZodEffects.createWithPreprocess;
4043
+ var pipelineType = ZodPipeline.create;
4044
+ var ostring = () => stringType().optional();
4045
+ var onumber = () => numberType().optional();
4046
+ var oboolean = () => booleanType().optional();
4047
+ var coerce = {
4048
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4049
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4050
+ boolean: ((arg) => ZodBoolean.create({
4051
+ ...arg,
4052
+ coerce: true
4053
+ })),
4054
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4055
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4056
+ };
4057
+ var NEVER = INVALID;
4058
+
4059
+ // src/schema/match-defaults.ts
4060
+ function defaultMatchOpts() {
4061
+ return {
4062
+ tokenizer: { kind: "ngram", token_length: 3 },
4063
+ token_filters: [{ kind: "downcase" }],
4064
+ k: 6,
4065
+ m: 2048,
4066
+ include_original: true
4067
+ };
4068
+ }
4069
+
4070
+ // src/schema/index.ts
4071
+ var eqlCastAsEnum = external_exports.enum([
4072
+ "text",
4073
+ "int",
4074
+ "small_int",
4075
+ "big_int",
4076
+ "real",
4077
+ "double",
4078
+ "boolean",
4079
+ "date",
4080
+ "timestamp",
4081
+ "jsonb"
4082
+ ]).default("text");
4083
+ var castAsEnum = external_exports.enum([
4084
+ "bigint",
4085
+ "boolean",
4086
+ "date",
4087
+ "timestamp",
4088
+ "number",
4089
+ "string",
4090
+ "json",
4091
+ "text"
4092
+ ]).default("text");
4093
+ function toEqlCastAs(value) {
4094
+ switch (value) {
4095
+ case "string":
4096
+ return "text";
4097
+ case "text":
4098
+ return "text";
4099
+ case "number":
4100
+ return "double";
4101
+ case "bigint":
4102
+ return "big_int";
4103
+ case "boolean":
4104
+ return "boolean";
4105
+ case "date":
4106
+ return "date";
4107
+ case "timestamp":
4108
+ return "timestamp";
4109
+ case "json":
4110
+ return "jsonb";
4111
+ }
4112
+ }
4113
+ var tokenFilterSchema = external_exports.object({
4114
+ kind: external_exports.literal("downcase")
4115
+ });
4116
+ var tokenizerSchema = external_exports.union([
4117
+ external_exports.object({
4118
+ kind: external_exports.literal("standard")
4119
+ }),
4120
+ external_exports.object({
4121
+ kind: external_exports.literal("ngram"),
4122
+ token_length: external_exports.number()
4123
+ })
4124
+ ]).default({ kind: "ngram", token_length: 3 }).optional();
4125
+ var oreIndexOptsSchema = external_exports.object({});
4126
+ var uniqueIndexOptsSchema = external_exports.object({
4127
+ token_filters: external_exports.array(tokenFilterSchema).default([]).optional()
4128
+ });
4129
+ var matchIndexOptsSchema = external_exports.object({
4130
+ tokenizer: tokenizerSchema,
4131
+ token_filters: external_exports.array(tokenFilterSchema).default([]).optional(),
4132
+ k: external_exports.number().default(6).optional(),
4133
+ m: external_exports.number().default(2048).optional(),
4134
+ include_original: external_exports.boolean().default(false).optional()
4135
+ });
4136
+ var arrayIndexModeSchema = external_exports.union([
4137
+ external_exports.literal("all"),
4138
+ external_exports.literal("none"),
4139
+ external_exports.object({
4140
+ item: external_exports.boolean().optional(),
4141
+ wildcard: external_exports.boolean().optional(),
4142
+ position: external_exports.boolean().optional()
4143
+ })
4144
+ ]);
4145
+ var steVecIndexOptsSchema = external_exports.object({
4146
+ prefix: external_exports.string(),
4147
+ array_index_mode: arrayIndexModeSchema.optional()
4148
+ });
4149
+ var indexesSchema = external_exports.object({
4150
+ ore: oreIndexOptsSchema.optional(),
4151
+ unique: uniqueIndexOptsSchema.optional(),
4152
+ match: matchIndexOptsSchema.optional(),
4153
+ ste_vec: steVecIndexOptsSchema.optional()
4154
+ }).default({});
4155
+ var columnSchema = external_exports.object({
4156
+ cast_as: castAsEnum,
4157
+ indexes: indexesSchema
4158
+ }).default({});
4159
+ var tableSchema = external_exports.record(columnSchema).default({});
4160
+ var tablesSchema = external_exports.record(tableSchema).default({});
4161
+ var encryptConfigSchema = external_exports.object({
4162
+ v: external_exports.number(),
4163
+ tables: tablesSchema
4164
+ });
4165
+ var EncryptedField = class {
4166
+ valueName;
4167
+ castAsValue;
4168
+ constructor(valueName) {
4169
+ this.valueName = valueName;
4170
+ this.castAsValue = "string";
4171
+ }
4172
+ /**
4173
+ * Set or override the plaintext data type for this field.
4174
+ *
4175
+ * By default all values are treated as `'string'`. Use this method to specify
4176
+ * a different type so the encryption layer knows how to encode the plaintext
4177
+ * before encrypting.
4178
+ *
4179
+ * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'text'`, `'bigint'`, or `'json'`.
4180
+ * @returns This `EncryptedField` instance for method chaining.
4181
+ *
4182
+ * @example
4183
+ * ```typescript
4184
+ * import { encryptedField } from "@cipherstash/stack/schema"
4185
+ *
4186
+ * const age = encryptedField("age").dataType("number")
4187
+ * ```
4188
+ */
4189
+ dataType(castAs) {
4190
+ this.castAsValue = castAs;
4191
+ return this;
4192
+ }
4193
+ build() {
4194
+ return {
4195
+ cast_as: this.castAsValue,
4196
+ indexes: {}
4197
+ };
4198
+ }
4199
+ getName() {
4200
+ return this.valueName;
4201
+ }
4202
+ };
4203
+ var EncryptedColumn = class {
4204
+ columnName;
4205
+ castAsValue;
4206
+ indexesValue = {};
4207
+ constructor(columnName) {
4208
+ this.columnName = columnName;
4209
+ this.castAsValue = "string";
4210
+ }
4211
+ /**
4212
+ * Set or override the plaintext data type for this column.
4213
+ *
4214
+ * By default all columns are treated as `'string'`. Use this method to specify
4215
+ * a different type so the encryption layer knows how to encode the plaintext
4216
+ * before encrypting.
4217
+ *
4218
+ * @param castAs - The plaintext data type: `'string'`, `'number'`, `'boolean'`, `'date'`, `'bigint'`, or `'json'`.
4219
+ * @returns This `EncryptedColumn` instance for method chaining.
4220
+ *
4221
+ * @example
4222
+ * ```typescript
4223
+ * import { encryptedColumn } from "@cipherstash/stack/schema"
4224
+ *
4225
+ * const dateOfBirth = encryptedColumn("date_of_birth").dataType("date")
4226
+ * ```
4227
+ */
4228
+ dataType(castAs) {
4229
+ this.castAsValue = castAs;
4230
+ return this;
4231
+ }
4232
+ /**
4233
+ * Enable Order-Revealing Encryption (ORE) indexing on this column.
4234
+ *
4235
+ * ORE allows sorting, comparison, and range queries on encrypted data.
4236
+ * Use with `encryptQuery` and `queryType: 'orderAndRange'`.
4237
+ *
4238
+ * @returns This `EncryptedColumn` instance for method chaining.
4239
+ *
4240
+ * @example
4241
+ * ```typescript
4242
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
4243
+ *
4244
+ * const users = encryptedTable("users", {
4245
+ * email: encryptedColumn("email").orderAndRange(),
4246
+ * })
4247
+ * ```
4248
+ */
4249
+ orderAndRange() {
4250
+ this.indexesValue.ore = {};
4251
+ return this;
4252
+ }
4253
+ /**
4254
+ * Enable an exact-match (unique) index on this column.
4255
+ *
4256
+ * Allows equality queries on encrypted data. Use with `encryptQuery`
4257
+ * and `queryType: 'equality'`.
4258
+ *
4259
+ * @param tokenFilters - Optional array of token filters (e.g. `[{ kind: 'downcase' }]`).
4260
+ * When omitted, no token filters are applied.
4261
+ * @returns This `EncryptedColumn` instance for method chaining.
4262
+ *
4263
+ * @example
4264
+ * ```typescript
4265
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
4266
+ *
4267
+ * const users = encryptedTable("users", {
4268
+ * email: encryptedColumn("email").equality(),
4269
+ * })
4270
+ * ```
4271
+ */
4272
+ equality(tokenFilters) {
4273
+ this.indexesValue.unique = {
4274
+ token_filters: tokenFilters ?? []
4275
+ };
4276
+ return this;
4277
+ }
4278
+ /**
4279
+ * Enable a full-text / fuzzy search (match) index on this column.
4280
+ *
4281
+ * Uses n-gram tokenization by default for substring and fuzzy matching.
4282
+ * Use with `encryptQuery` and `queryType: 'freeTextSearch'`.
4283
+ *
4284
+ * @param opts - Optional match index configuration. Defaults to 3-character ngram
4285
+ * tokenization with a downcase filter, `k=6`, `m=2048`, and `include_original=true`.
4286
+ * @returns This `EncryptedColumn` instance for method chaining.
4287
+ *
4288
+ * @example
4289
+ * ```typescript
4290
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
4291
+ *
4292
+ * const users = encryptedTable("users", {
4293
+ * email: encryptedColumn("email").freeTextSearch(),
4294
+ * })
4295
+ *
4296
+ * // With custom options
4297
+ * const posts = encryptedTable("posts", {
4298
+ * body: encryptedColumn("body").freeTextSearch({
4299
+ * tokenizer: { kind: "ngram", token_length: 4 },
4300
+ * k: 8,
4301
+ * m: 4096,
4302
+ * }),
4303
+ * })
4304
+ * ```
4305
+ */
4306
+ freeTextSearch(opts) {
4307
+ const defaults = defaultMatchOpts();
4308
+ this.indexesValue.match = {
4309
+ tokenizer: opts?.tokenizer ?? defaults.tokenizer,
4310
+ token_filters: opts?.token_filters ?? defaults.token_filters,
4311
+ k: opts?.k ?? defaults.k,
4312
+ m: opts?.m ?? defaults.m,
4313
+ include_original: opts?.include_original ?? defaults.include_original
4314
+ };
4315
+ return this;
4316
+ }
4317
+ /**
4318
+ * Configure this column for searchable encrypted JSON (STE-Vec).
4319
+ *
4320
+ * Enables encrypted JSONPath selector queries (e.g. `'$.user.email'`) and
4321
+ * containment queries (e.g. `{ role: 'admin' }`). Automatically sets the
4322
+ * data type to `'json'`.
4323
+ *
4324
+ * When used with `encryptQuery`, the query operation is auto-inferred from
4325
+ * the plaintext type: strings become selector queries, objects/arrays become
4326
+ * containment queries.
4327
+ *
4328
+ * @returns This `EncryptedColumn` instance for method chaining.
4329
+ *
4330
+ * @example
4331
+ * ```typescript
4332
+ * import { encryptedTable, encryptedColumn } from "@cipherstash/stack/schema"
4333
+ *
4334
+ * const documents = encryptedTable("documents", {
4335
+ * metadata: encryptedColumn("metadata").searchableJson(),
4336
+ * })
4337
+ * ```
4338
+ */
4339
+ searchableJson() {
4340
+ this.castAsValue = "json";
4341
+ this.indexesValue.ste_vec = { prefix: "enabled", array_index_mode: "all" };
4342
+ return this;
4343
+ }
4344
+ build() {
4345
+ return {
4346
+ cast_as: this.castAsValue,
4347
+ indexes: this.indexesValue
4348
+ };
4349
+ }
4350
+ getName() {
4351
+ return this.columnName;
4352
+ }
4353
+ };
4354
+ var EncryptedTable = class {
4355
+ constructor(tableName, columnBuilders) {
4356
+ this.tableName = tableName;
4357
+ this.columnBuilders = columnBuilders;
4358
+ }
4359
+ tableName;
4360
+ columnBuilders;
4361
+ /**
4362
+ * Compile this table schema into a `TableDefinition` used internally by the encryption client.
4363
+ *
4364
+ * Iterates over all column builders, calls `.build()` on each, and assembles
4365
+ * the final `{ tableName, columns }` structure. For `searchableJson()` columns,
4366
+ * the STE-Vec prefix is automatically set to `"<tableName>/<columnName>"`.
4367
+ *
4368
+ * @returns A `TableDefinition` containing the table name and built column configs.
4369
+ *
4370
+ * @example
4371
+ * ```typescript
4372
+ * const users = encryptedTable("users", {
4373
+ * email: encryptedColumn("email").equality(),
4374
+ * })
4375
+ *
4376
+ * const definition = users.build()
4377
+ * // { tableName: "users", columns: { email: { cast_as: "string", indexes: { unique: ... } } } }
4378
+ * ```
4379
+ */
4380
+ build() {
4381
+ const builtColumns = {};
4382
+ const processColumn = (builder, colName) => {
4383
+ if (builder instanceof EncryptedColumn) {
4384
+ const builtColumn = builder.build();
4385
+ if (builtColumn.cast_as === "json" && builtColumn.indexes.ste_vec?.prefix === "enabled") {
4386
+ builtColumns[colName] = {
4387
+ ...builtColumn,
4388
+ indexes: {
4389
+ ...builtColumn.indexes,
4390
+ ste_vec: {
4391
+ ...builtColumn.indexes.ste_vec,
4392
+ prefix: `${this.tableName}/${colName}`
4393
+ }
4394
+ }
4395
+ };
4396
+ } else {
4397
+ builtColumns[colName] = builtColumn;
4398
+ }
4399
+ } else {
4400
+ for (const [key, value] of Object.entries(builder)) {
4401
+ if (value instanceof EncryptedField) {
4402
+ builtColumns[value.getName()] = value.build();
4403
+ } else {
4404
+ processColumn(value, key);
4405
+ }
4406
+ }
4407
+ }
4408
+ };
4409
+ for (const [colName, builder] of Object.entries(this.columnBuilders)) {
4410
+ processColumn(builder, colName);
4411
+ }
4412
+ return {
4413
+ tableName: this.tableName,
4414
+ columns: builtColumns
4415
+ };
4416
+ }
4417
+ };
4418
+ function encryptedTable(tableName, columns) {
4419
+ const tableBuilder = new EncryptedTable(
4420
+ tableName,
4421
+ columns
4422
+ );
4423
+ for (const [colName, colBuilder] of Object.entries(columns)) {
4424
+ ;
4425
+ tableBuilder[colName] = colBuilder;
4426
+ }
4427
+ return tableBuilder;
4428
+ }
4429
+ function encryptedColumn(columnName) {
4430
+ return new EncryptedColumn(columnName);
4431
+ }
4432
+ function encryptedField(valueName) {
4433
+ return new EncryptedField(valueName);
4434
+ }
4435
+ function buildEncryptConfig(...protectTables) {
4436
+ const config = {
4437
+ v: 1,
4438
+ tables: {}
4439
+ };
4440
+ for (const tb of protectTables) {
4441
+ const tableDef = tb.build();
4442
+ config.tables[tableDef.tableName] = tableDef.columns;
4443
+ }
4444
+ return config;
4445
+ }
4446
+
4447
+ // src/wasm-inline.ts
4448
+ import {
4449
+ AccessKeyStrategy as AccessKeyStrategy2,
4450
+ OidcFederationStrategy
4451
+ } from "@cipherstash/auth/wasm-inline";
4452
+ function isEncrypted(value) {
4453
+ return wasmIsEncrypted(value);
4454
+ }
4455
+ var INTERNAL_CONSTRUCT = /* @__PURE__ */ Symbol("cs-wasm-client");
4456
+ var WasmEncryptionClient = class {
4457
+ /** @internal */
4458
+ client;
4459
+ /**
4460
+ * @internal Gated by the module-scoped {@link INTERNAL_CONSTRUCT}
4461
+ * symbol: external callers can't obtain it, so {@link Encryption} is
4462
+ * effectively the only constructor. (A `private` constructor would
4463
+ * block {@link Encryption} too, since it lives outside the class.)
4464
+ */
4465
+ constructor(token, client) {
4466
+ if (token !== INTERNAL_CONSTRUCT) {
4467
+ throw new Error(
4468
+ "[encryption]: WasmEncryptionClient cannot be constructed directly \u2014 use the Encryption() factory."
4469
+ );
4470
+ }
4471
+ this.client = client;
4472
+ }
4473
+ async encrypt(plaintext, opts) {
4474
+ const ffiOpts = {
4475
+ plaintext,
4476
+ table: opts.table.tableName,
4477
+ column: getColumnName(opts.column)
4478
+ };
4479
+ return await wasmEncrypt(
4480
+ this.client,
4481
+ ffiOpts
4482
+ );
4483
+ }
4484
+ async decrypt(encrypted) {
4485
+ return await wasmDecrypt(
4486
+ this.client,
4487
+ {
4488
+ ciphertext: encrypted
4489
+ }
4490
+ );
4491
+ }
4492
+ isEncrypted(value) {
4493
+ return wasmIsEncrypted(value);
4494
+ }
4495
+ };
4496
+ async function Encryption(config) {
4497
+ const { schemas, config: clientConfig } = config;
4498
+ if (!schemas.length) {
4499
+ throw new Error(
4500
+ "[encryption]: At least one encryptedTable must be provided to initialize the encryption client"
4501
+ );
4502
+ }
4503
+ const encryptConfig = encryptConfigSchema.parse(
4504
+ buildEncryptConfig(...schemas)
4505
+ );
4506
+ const strategy = resolveStrategy(clientConfig);
4507
+ const client = await wasmNewClient({
4508
+ strategy,
4509
+ encryptConfig: normalizeCastAs(encryptConfig),
4510
+ clientId: clientConfig.clientId,
4511
+ clientKey: clientConfig.clientKey
4512
+ });
4513
+ return new WasmEncryptionClient(INTERNAL_CONSTRUCT, client);
4514
+ }
4515
+ function normalizeCastAs(config) {
4516
+ const tables = {};
4517
+ for (const [tableName, columns] of Object.entries(config.tables)) {
4518
+ const normalised = {};
4519
+ for (const [colName, col] of Object.entries(columns)) {
4520
+ if (col.cast_as) {
4521
+ const eqlCastAs = toEqlCastAs(col.cast_as);
4522
+ if (eqlCastAs === void 0) {
4523
+ throw new Error(
4524
+ `[encryption]: unrecognised cast_as value "${col.cast_as}" on ${tableName}.${colName} \u2014 update toEqlCastAs() to map it to an EQL variant.`
4525
+ );
4526
+ }
4527
+ normalised[colName] = { ...col, cast_as: eqlCastAs };
4528
+ } else {
4529
+ normalised[colName] = col;
4530
+ }
4531
+ }
4532
+ tables[tableName] = normalised;
4533
+ }
4534
+ return { ...config, tables };
4535
+ }
4536
+ function getColumnName(col) {
4537
+ if (typeof col?.getName === "function") {
4538
+ return col.getName();
4539
+ }
4540
+ throw new Error(
4541
+ "[encryption]: opts.column must be a column builder exposing getName()"
4542
+ );
4543
+ }
4544
+ var warnedStrategyDeprecated = false;
4545
+ function warnStrategyDeprecated() {
4546
+ if (warnedStrategyDeprecated) return;
4547
+ warnedStrategyDeprecated = true;
4548
+ console.warn(
4549
+ "[encryption]: `config.strategy` is deprecated and will be removed in a future release \u2014 use `config.authStrategy` instead."
4550
+ );
4551
+ }
4552
+ function __resetStrategyDeprecationWarningForTests() {
4553
+ warnedStrategyDeprecated = false;
4554
+ }
4555
+ function resolveStrategy(cfg) {
4556
+ if (cfg.strategy) {
4557
+ warnStrategyDeprecated();
4558
+ }
4559
+ const authStrategy = cfg.authStrategy ?? cfg.strategy;
4560
+ if (authStrategy && cfg.accessKey) {
4561
+ const field = cfg.authStrategy ? "authStrategy" : "strategy";
4562
+ throw new Error(
4563
+ `[encryption]: \`config.${field}\` and \`config.accessKey\` are mutually exclusive \u2014 pass exactly one.`
4564
+ );
4565
+ }
4566
+ if (authStrategy) return authStrategy;
4567
+ if (!cfg.workspaceCrn || !cfg.accessKey) {
4568
+ throw new Error(
4569
+ "[encryption]: `config.workspaceCrn` and `config.accessKey` are required when no auth strategy is provided."
4570
+ );
4571
+ }
4572
+ const result = AccessKeyStrategy.create(cfg.workspaceCrn, cfg.accessKey);
4573
+ if (result.failure) {
4574
+ throw new Error(
4575
+ `[encryption]: failed to construct \`AccessKeyStrategy\` from \`config.workspaceCrn\` / \`config.accessKey\` (${result.failure.type}): ${result.failure.error.message}`
4576
+ );
4577
+ }
4578
+ return result.data;
4579
+ }
4580
+ export {
4581
+ AccessKeyStrategy2 as AccessKeyStrategy,
4582
+ Encryption,
4583
+ OidcFederationStrategy,
4584
+ WasmEncryptionClient,
4585
+ __resetStrategyDeprecationWarningForTests,
4586
+ encryptedColumn,
4587
+ encryptedField,
4588
+ encryptedTable,
4589
+ getColumnName,
4590
+ isEncrypted,
4591
+ normalizeCastAs,
4592
+ resolveStrategy
4593
+ };
4594
+ //# sourceMappingURL=wasm-inline.js.map