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