@noodleseed/assistant 1.22.0 → 1.24.0

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