opencode-codebase-index 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +72 -4211
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +202 -4307
- package/dist/index.js.map +1 -1
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -14,10 +14,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
14
14
|
var __commonJS = (cb, mod) => function __require2() {
|
|
15
15
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
16
|
};
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
17
|
var __copyProps = (to, from, except, desc) => {
|
|
22
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
19
|
for (let key of __getOwnPropNames(from))
|
|
@@ -513,4250 +509,180 @@ var require_ignore = __commonJS({
|
|
|
513
509
|
matchedRule = negative ? UNDEFINED : rule;
|
|
514
510
|
});
|
|
515
511
|
const ret = {
|
|
516
|
-
ignored,
|
|
517
|
-
unignored
|
|
518
|
-
};
|
|
519
|
-
if (matchedRule) {
|
|
520
|
-
ret.rule = matchedRule;
|
|
521
|
-
}
|
|
522
|
-
return ret;
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
var throwError = (message, Ctor) => {
|
|
526
|
-
throw new Ctor(message);
|
|
527
|
-
};
|
|
528
|
-
var checkPath = (path9, originalPath, doThrow) => {
|
|
529
|
-
if (!isString(path9)) {
|
|
530
|
-
return doThrow(
|
|
531
|
-
`path must be a string, but got \`${originalPath}\``,
|
|
532
|
-
TypeError
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
if (!path9) {
|
|
536
|
-
return doThrow(`path must not be empty`, TypeError);
|
|
537
|
-
}
|
|
538
|
-
if (checkPath.isNotRelative(path9)) {
|
|
539
|
-
const r = "`path.relative()`d";
|
|
540
|
-
return doThrow(
|
|
541
|
-
`path should be a ${r} string, but got "${originalPath}"`,
|
|
542
|
-
RangeError
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
return true;
|
|
546
|
-
};
|
|
547
|
-
var isNotRelative = (path9) => REGEX_TEST_INVALID_PATH.test(path9);
|
|
548
|
-
checkPath.isNotRelative = isNotRelative;
|
|
549
|
-
checkPath.convert = (p) => p;
|
|
550
|
-
var Ignore2 = class {
|
|
551
|
-
constructor({
|
|
552
|
-
ignorecase = true,
|
|
553
|
-
ignoreCase = ignorecase,
|
|
554
|
-
allowRelativePaths = false
|
|
555
|
-
} = {}) {
|
|
556
|
-
define(this, KEY_IGNORE, true);
|
|
557
|
-
this._rules = new RuleManager(ignoreCase);
|
|
558
|
-
this._strictPathCheck = !allowRelativePaths;
|
|
559
|
-
this._initCache();
|
|
560
|
-
}
|
|
561
|
-
_initCache() {
|
|
562
|
-
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
563
|
-
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
564
|
-
}
|
|
565
|
-
add(pattern) {
|
|
566
|
-
if (this._rules.add(pattern)) {
|
|
567
|
-
this._initCache();
|
|
568
|
-
}
|
|
569
|
-
return this;
|
|
570
|
-
}
|
|
571
|
-
// legacy
|
|
572
|
-
addPattern(pattern) {
|
|
573
|
-
return this.add(pattern);
|
|
574
|
-
}
|
|
575
|
-
// @returns {TestResult}
|
|
576
|
-
_test(originalPath, cache, checkUnignored, slices) {
|
|
577
|
-
const path9 = originalPath && checkPath.convert(originalPath);
|
|
578
|
-
checkPath(
|
|
579
|
-
path9,
|
|
580
|
-
originalPath,
|
|
581
|
-
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
582
|
-
);
|
|
583
|
-
return this._t(path9, cache, checkUnignored, slices);
|
|
584
|
-
}
|
|
585
|
-
checkIgnore(path9) {
|
|
586
|
-
if (!REGEX_TEST_TRAILING_SLASH.test(path9)) {
|
|
587
|
-
return this.test(path9);
|
|
588
|
-
}
|
|
589
|
-
const slices = path9.split(SLASH2).filter(Boolean);
|
|
590
|
-
slices.pop();
|
|
591
|
-
if (slices.length) {
|
|
592
|
-
const parent = this._t(
|
|
593
|
-
slices.join(SLASH2) + SLASH2,
|
|
594
|
-
this._testCache,
|
|
595
|
-
true,
|
|
596
|
-
slices
|
|
597
|
-
);
|
|
598
|
-
if (parent.ignored) {
|
|
599
|
-
return parent;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return this._rules.test(path9, false, MODE_CHECK_IGNORE);
|
|
603
|
-
}
|
|
604
|
-
_t(path9, cache, checkUnignored, slices) {
|
|
605
|
-
if (path9 in cache) {
|
|
606
|
-
return cache[path9];
|
|
607
|
-
}
|
|
608
|
-
if (!slices) {
|
|
609
|
-
slices = path9.split(SLASH2).filter(Boolean);
|
|
610
|
-
}
|
|
611
|
-
slices.pop();
|
|
612
|
-
if (!slices.length) {
|
|
613
|
-
return cache[path9] = this._rules.test(path9, checkUnignored, MODE_IGNORE);
|
|
614
|
-
}
|
|
615
|
-
const parent = this._t(
|
|
616
|
-
slices.join(SLASH2) + SLASH2,
|
|
617
|
-
cache,
|
|
618
|
-
checkUnignored,
|
|
619
|
-
slices
|
|
620
|
-
);
|
|
621
|
-
return cache[path9] = parent.ignored ? parent : this._rules.test(path9, checkUnignored, MODE_IGNORE);
|
|
622
|
-
}
|
|
623
|
-
ignores(path9) {
|
|
624
|
-
return this._test(path9, this._ignoreCache, false).ignored;
|
|
625
|
-
}
|
|
626
|
-
createFilter() {
|
|
627
|
-
return (path9) => !this.ignores(path9);
|
|
628
|
-
}
|
|
629
|
-
filter(paths) {
|
|
630
|
-
return makeArray(paths).filter(this.createFilter());
|
|
631
|
-
}
|
|
632
|
-
// @returns {TestResult}
|
|
633
|
-
test(path9) {
|
|
634
|
-
return this._test(path9, this._testCache, true);
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
var factory = (options) => new Ignore2(options);
|
|
638
|
-
var isPathValid = (path9) => checkPath(path9 && checkPath.convert(path9), path9, RETURN_FALSE);
|
|
639
|
-
var setupWindows = () => {
|
|
640
|
-
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
641
|
-
checkPath.convert = makePosix;
|
|
642
|
-
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
643
|
-
checkPath.isNotRelative = (path9) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path9) || isNotRelative(path9);
|
|
644
|
-
};
|
|
645
|
-
if (
|
|
646
|
-
// Detect `process` so that it can run in browsers.
|
|
647
|
-
typeof process !== "undefined" && process.platform === "win32"
|
|
648
|
-
) {
|
|
649
|
-
setupWindows();
|
|
650
|
-
}
|
|
651
|
-
module.exports = factory;
|
|
652
|
-
factory.default = factory;
|
|
653
|
-
module.exports.isPathValid = isPathValid;
|
|
654
|
-
define(module.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
655
|
-
}
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
// src/index.ts
|
|
659
|
-
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
660
|
-
import * as path8 from "path";
|
|
661
|
-
|
|
662
|
-
// node_modules/zod/v3/external.js
|
|
663
|
-
var external_exports = {};
|
|
664
|
-
__export(external_exports, {
|
|
665
|
-
BRAND: () => BRAND,
|
|
666
|
-
DIRTY: () => DIRTY,
|
|
667
|
-
EMPTY_PATH: () => EMPTY_PATH,
|
|
668
|
-
INVALID: () => INVALID,
|
|
669
|
-
NEVER: () => NEVER,
|
|
670
|
-
OK: () => OK,
|
|
671
|
-
ParseStatus: () => ParseStatus,
|
|
672
|
-
Schema: () => ZodType,
|
|
673
|
-
ZodAny: () => ZodAny,
|
|
674
|
-
ZodArray: () => ZodArray,
|
|
675
|
-
ZodBigInt: () => ZodBigInt,
|
|
676
|
-
ZodBoolean: () => ZodBoolean,
|
|
677
|
-
ZodBranded: () => ZodBranded,
|
|
678
|
-
ZodCatch: () => ZodCatch,
|
|
679
|
-
ZodDate: () => ZodDate,
|
|
680
|
-
ZodDefault: () => ZodDefault,
|
|
681
|
-
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
682
|
-
ZodEffects: () => ZodEffects,
|
|
683
|
-
ZodEnum: () => ZodEnum,
|
|
684
|
-
ZodError: () => ZodError,
|
|
685
|
-
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
686
|
-
ZodFunction: () => ZodFunction,
|
|
687
|
-
ZodIntersection: () => ZodIntersection,
|
|
688
|
-
ZodIssueCode: () => ZodIssueCode,
|
|
689
|
-
ZodLazy: () => ZodLazy,
|
|
690
|
-
ZodLiteral: () => ZodLiteral,
|
|
691
|
-
ZodMap: () => ZodMap,
|
|
692
|
-
ZodNaN: () => ZodNaN,
|
|
693
|
-
ZodNativeEnum: () => ZodNativeEnum,
|
|
694
|
-
ZodNever: () => ZodNever,
|
|
695
|
-
ZodNull: () => ZodNull,
|
|
696
|
-
ZodNullable: () => ZodNullable,
|
|
697
|
-
ZodNumber: () => ZodNumber,
|
|
698
|
-
ZodObject: () => ZodObject,
|
|
699
|
-
ZodOptional: () => ZodOptional,
|
|
700
|
-
ZodParsedType: () => ZodParsedType,
|
|
701
|
-
ZodPipeline: () => ZodPipeline,
|
|
702
|
-
ZodPromise: () => ZodPromise,
|
|
703
|
-
ZodReadonly: () => ZodReadonly,
|
|
704
|
-
ZodRecord: () => ZodRecord,
|
|
705
|
-
ZodSchema: () => ZodType,
|
|
706
|
-
ZodSet: () => ZodSet,
|
|
707
|
-
ZodString: () => ZodString,
|
|
708
|
-
ZodSymbol: () => ZodSymbol,
|
|
709
|
-
ZodTransformer: () => ZodEffects,
|
|
710
|
-
ZodTuple: () => ZodTuple,
|
|
711
|
-
ZodType: () => ZodType,
|
|
712
|
-
ZodUndefined: () => ZodUndefined,
|
|
713
|
-
ZodUnion: () => ZodUnion,
|
|
714
|
-
ZodUnknown: () => ZodUnknown,
|
|
715
|
-
ZodVoid: () => ZodVoid,
|
|
716
|
-
addIssueToContext: () => addIssueToContext,
|
|
717
|
-
any: () => anyType,
|
|
718
|
-
array: () => arrayType,
|
|
719
|
-
bigint: () => bigIntType,
|
|
720
|
-
boolean: () => booleanType,
|
|
721
|
-
coerce: () => coerce,
|
|
722
|
-
custom: () => custom,
|
|
723
|
-
date: () => dateType,
|
|
724
|
-
datetimeRegex: () => datetimeRegex,
|
|
725
|
-
defaultErrorMap: () => en_default,
|
|
726
|
-
discriminatedUnion: () => discriminatedUnionType,
|
|
727
|
-
effect: () => effectsType,
|
|
728
|
-
enum: () => enumType,
|
|
729
|
-
function: () => functionType,
|
|
730
|
-
getErrorMap: () => getErrorMap,
|
|
731
|
-
getParsedType: () => getParsedType,
|
|
732
|
-
instanceof: () => instanceOfType,
|
|
733
|
-
intersection: () => intersectionType,
|
|
734
|
-
isAborted: () => isAborted,
|
|
735
|
-
isAsync: () => isAsync,
|
|
736
|
-
isDirty: () => isDirty,
|
|
737
|
-
isValid: () => isValid,
|
|
738
|
-
late: () => late,
|
|
739
|
-
lazy: () => lazyType,
|
|
740
|
-
literal: () => literalType,
|
|
741
|
-
makeIssue: () => makeIssue,
|
|
742
|
-
map: () => mapType,
|
|
743
|
-
nan: () => nanType,
|
|
744
|
-
nativeEnum: () => nativeEnumType,
|
|
745
|
-
never: () => neverType,
|
|
746
|
-
null: () => nullType,
|
|
747
|
-
nullable: () => nullableType,
|
|
748
|
-
number: () => numberType,
|
|
749
|
-
object: () => objectType,
|
|
750
|
-
objectUtil: () => objectUtil,
|
|
751
|
-
oboolean: () => oboolean,
|
|
752
|
-
onumber: () => onumber,
|
|
753
|
-
optional: () => optionalType,
|
|
754
|
-
ostring: () => ostring,
|
|
755
|
-
pipeline: () => pipelineType,
|
|
756
|
-
preprocess: () => preprocessType,
|
|
757
|
-
promise: () => promiseType,
|
|
758
|
-
quotelessJson: () => quotelessJson,
|
|
759
|
-
record: () => recordType,
|
|
760
|
-
set: () => setType,
|
|
761
|
-
setErrorMap: () => setErrorMap,
|
|
762
|
-
strictObject: () => strictObjectType,
|
|
763
|
-
string: () => stringType,
|
|
764
|
-
symbol: () => symbolType,
|
|
765
|
-
transformer: () => effectsType,
|
|
766
|
-
tuple: () => tupleType,
|
|
767
|
-
undefined: () => undefinedType,
|
|
768
|
-
union: () => unionType,
|
|
769
|
-
unknown: () => unknownType,
|
|
770
|
-
util: () => util,
|
|
771
|
-
void: () => voidType
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
// node_modules/zod/v3/helpers/util.js
|
|
775
|
-
var util;
|
|
776
|
-
(function(util2) {
|
|
777
|
-
util2.assertEqual = (_) => {
|
|
778
|
-
};
|
|
779
|
-
function assertIs(_arg) {
|
|
780
|
-
}
|
|
781
|
-
util2.assertIs = assertIs;
|
|
782
|
-
function assertNever(_x) {
|
|
783
|
-
throw new Error();
|
|
784
|
-
}
|
|
785
|
-
util2.assertNever = assertNever;
|
|
786
|
-
util2.arrayToEnum = (items) => {
|
|
787
|
-
const obj = {};
|
|
788
|
-
for (const item of items) {
|
|
789
|
-
obj[item] = item;
|
|
790
|
-
}
|
|
791
|
-
return obj;
|
|
792
|
-
};
|
|
793
|
-
util2.getValidEnumValues = (obj) => {
|
|
794
|
-
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
795
|
-
const filtered = {};
|
|
796
|
-
for (const k of validKeys) {
|
|
797
|
-
filtered[k] = obj[k];
|
|
798
|
-
}
|
|
799
|
-
return util2.objectValues(filtered);
|
|
800
|
-
};
|
|
801
|
-
util2.objectValues = (obj) => {
|
|
802
|
-
return util2.objectKeys(obj).map(function(e) {
|
|
803
|
-
return obj[e];
|
|
804
|
-
});
|
|
805
|
-
};
|
|
806
|
-
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
807
|
-
const keys = [];
|
|
808
|
-
for (const key in object) {
|
|
809
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
810
|
-
keys.push(key);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
return keys;
|
|
814
|
-
};
|
|
815
|
-
util2.find = (arr, checker) => {
|
|
816
|
-
for (const item of arr) {
|
|
817
|
-
if (checker(item))
|
|
818
|
-
return item;
|
|
819
|
-
}
|
|
820
|
-
return void 0;
|
|
821
|
-
};
|
|
822
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
823
|
-
function joinValues(array, separator = " | ") {
|
|
824
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
825
|
-
}
|
|
826
|
-
util2.joinValues = joinValues;
|
|
827
|
-
util2.jsonStringifyReplacer = (_, value) => {
|
|
828
|
-
if (typeof value === "bigint") {
|
|
829
|
-
return value.toString();
|
|
830
|
-
}
|
|
831
|
-
return value;
|
|
832
|
-
};
|
|
833
|
-
})(util || (util = {}));
|
|
834
|
-
var objectUtil;
|
|
835
|
-
(function(objectUtil2) {
|
|
836
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
837
|
-
return {
|
|
838
|
-
...first,
|
|
839
|
-
...second
|
|
840
|
-
// second overwrites first
|
|
841
|
-
};
|
|
842
|
-
};
|
|
843
|
-
})(objectUtil || (objectUtil = {}));
|
|
844
|
-
var ZodParsedType = util.arrayToEnum([
|
|
845
|
-
"string",
|
|
846
|
-
"nan",
|
|
847
|
-
"number",
|
|
848
|
-
"integer",
|
|
849
|
-
"float",
|
|
850
|
-
"boolean",
|
|
851
|
-
"date",
|
|
852
|
-
"bigint",
|
|
853
|
-
"symbol",
|
|
854
|
-
"function",
|
|
855
|
-
"undefined",
|
|
856
|
-
"null",
|
|
857
|
-
"array",
|
|
858
|
-
"object",
|
|
859
|
-
"unknown",
|
|
860
|
-
"promise",
|
|
861
|
-
"void",
|
|
862
|
-
"never",
|
|
863
|
-
"map",
|
|
864
|
-
"set"
|
|
865
|
-
]);
|
|
866
|
-
var getParsedType = (data) => {
|
|
867
|
-
const t = typeof data;
|
|
868
|
-
switch (t) {
|
|
869
|
-
case "undefined":
|
|
870
|
-
return ZodParsedType.undefined;
|
|
871
|
-
case "string":
|
|
872
|
-
return ZodParsedType.string;
|
|
873
|
-
case "number":
|
|
874
|
-
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
875
|
-
case "boolean":
|
|
876
|
-
return ZodParsedType.boolean;
|
|
877
|
-
case "function":
|
|
878
|
-
return ZodParsedType.function;
|
|
879
|
-
case "bigint":
|
|
880
|
-
return ZodParsedType.bigint;
|
|
881
|
-
case "symbol":
|
|
882
|
-
return ZodParsedType.symbol;
|
|
883
|
-
case "object":
|
|
884
|
-
if (Array.isArray(data)) {
|
|
885
|
-
return ZodParsedType.array;
|
|
886
|
-
}
|
|
887
|
-
if (data === null) {
|
|
888
|
-
return ZodParsedType.null;
|
|
889
|
-
}
|
|
890
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
891
|
-
return ZodParsedType.promise;
|
|
892
|
-
}
|
|
893
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
894
|
-
return ZodParsedType.map;
|
|
895
|
-
}
|
|
896
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
897
|
-
return ZodParsedType.set;
|
|
898
|
-
}
|
|
899
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
900
|
-
return ZodParsedType.date;
|
|
901
|
-
}
|
|
902
|
-
return ZodParsedType.object;
|
|
903
|
-
default:
|
|
904
|
-
return ZodParsedType.unknown;
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
// node_modules/zod/v3/ZodError.js
|
|
909
|
-
var ZodIssueCode = util.arrayToEnum([
|
|
910
|
-
"invalid_type",
|
|
911
|
-
"invalid_literal",
|
|
912
|
-
"custom",
|
|
913
|
-
"invalid_union",
|
|
914
|
-
"invalid_union_discriminator",
|
|
915
|
-
"invalid_enum_value",
|
|
916
|
-
"unrecognized_keys",
|
|
917
|
-
"invalid_arguments",
|
|
918
|
-
"invalid_return_type",
|
|
919
|
-
"invalid_date",
|
|
920
|
-
"invalid_string",
|
|
921
|
-
"too_small",
|
|
922
|
-
"too_big",
|
|
923
|
-
"invalid_intersection_types",
|
|
924
|
-
"not_multiple_of",
|
|
925
|
-
"not_finite"
|
|
926
|
-
]);
|
|
927
|
-
var quotelessJson = (obj) => {
|
|
928
|
-
const json = JSON.stringify(obj, null, 2);
|
|
929
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
930
|
-
};
|
|
931
|
-
var ZodError = class _ZodError extends Error {
|
|
932
|
-
get errors() {
|
|
933
|
-
return this.issues;
|
|
934
|
-
}
|
|
935
|
-
constructor(issues) {
|
|
936
|
-
super();
|
|
937
|
-
this.issues = [];
|
|
938
|
-
this.addIssue = (sub) => {
|
|
939
|
-
this.issues = [...this.issues, sub];
|
|
940
|
-
};
|
|
941
|
-
this.addIssues = (subs = []) => {
|
|
942
|
-
this.issues = [...this.issues, ...subs];
|
|
943
|
-
};
|
|
944
|
-
const actualProto = new.target.prototype;
|
|
945
|
-
if (Object.setPrototypeOf) {
|
|
946
|
-
Object.setPrototypeOf(this, actualProto);
|
|
947
|
-
} else {
|
|
948
|
-
this.__proto__ = actualProto;
|
|
949
|
-
}
|
|
950
|
-
this.name = "ZodError";
|
|
951
|
-
this.issues = issues;
|
|
952
|
-
}
|
|
953
|
-
format(_mapper) {
|
|
954
|
-
const mapper = _mapper || function(issue) {
|
|
955
|
-
return issue.message;
|
|
956
|
-
};
|
|
957
|
-
const fieldErrors = { _errors: [] };
|
|
958
|
-
const processError = (error) => {
|
|
959
|
-
for (const issue of error.issues) {
|
|
960
|
-
if (issue.code === "invalid_union") {
|
|
961
|
-
issue.unionErrors.map(processError);
|
|
962
|
-
} else if (issue.code === "invalid_return_type") {
|
|
963
|
-
processError(issue.returnTypeError);
|
|
964
|
-
} else if (issue.code === "invalid_arguments") {
|
|
965
|
-
processError(issue.argumentsError);
|
|
966
|
-
} else if (issue.path.length === 0) {
|
|
967
|
-
fieldErrors._errors.push(mapper(issue));
|
|
968
|
-
} else {
|
|
969
|
-
let curr = fieldErrors;
|
|
970
|
-
let i = 0;
|
|
971
|
-
while (i < issue.path.length) {
|
|
972
|
-
const el = issue.path[i];
|
|
973
|
-
const terminal = i === issue.path.length - 1;
|
|
974
|
-
if (!terminal) {
|
|
975
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
976
|
-
} else {
|
|
977
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
978
|
-
curr[el]._errors.push(mapper(issue));
|
|
979
|
-
}
|
|
980
|
-
curr = curr[el];
|
|
981
|
-
i++;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
processError(this);
|
|
987
|
-
return fieldErrors;
|
|
988
|
-
}
|
|
989
|
-
static assert(value) {
|
|
990
|
-
if (!(value instanceof _ZodError)) {
|
|
991
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
toString() {
|
|
995
|
-
return this.message;
|
|
996
|
-
}
|
|
997
|
-
get message() {
|
|
998
|
-
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
999
|
-
}
|
|
1000
|
-
get isEmpty() {
|
|
1001
|
-
return this.issues.length === 0;
|
|
1002
|
-
}
|
|
1003
|
-
flatten(mapper = (issue) => issue.message) {
|
|
1004
|
-
const fieldErrors = {};
|
|
1005
|
-
const formErrors = [];
|
|
1006
|
-
for (const sub of this.issues) {
|
|
1007
|
-
if (sub.path.length > 0) {
|
|
1008
|
-
const firstEl = sub.path[0];
|
|
1009
|
-
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
1010
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
1011
|
-
} else {
|
|
1012
|
-
formErrors.push(mapper(sub));
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
return { formErrors, fieldErrors };
|
|
1016
|
-
}
|
|
1017
|
-
get formErrors() {
|
|
1018
|
-
return this.flatten();
|
|
1019
|
-
}
|
|
1020
|
-
};
|
|
1021
|
-
ZodError.create = (issues) => {
|
|
1022
|
-
const error = new ZodError(issues);
|
|
1023
|
-
return error;
|
|
1024
|
-
};
|
|
1025
|
-
|
|
1026
|
-
// node_modules/zod/v3/locales/en.js
|
|
1027
|
-
var errorMap = (issue, _ctx) => {
|
|
1028
|
-
let message;
|
|
1029
|
-
switch (issue.code) {
|
|
1030
|
-
case ZodIssueCode.invalid_type:
|
|
1031
|
-
if (issue.received === ZodParsedType.undefined) {
|
|
1032
|
-
message = "Required";
|
|
1033
|
-
} else {
|
|
1034
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
1035
|
-
}
|
|
1036
|
-
break;
|
|
1037
|
-
case ZodIssueCode.invalid_literal:
|
|
1038
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
1039
|
-
break;
|
|
1040
|
-
case ZodIssueCode.unrecognized_keys:
|
|
1041
|
-
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
1042
|
-
break;
|
|
1043
|
-
case ZodIssueCode.invalid_union:
|
|
1044
|
-
message = `Invalid input`;
|
|
1045
|
-
break;
|
|
1046
|
-
case ZodIssueCode.invalid_union_discriminator:
|
|
1047
|
-
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
1048
|
-
break;
|
|
1049
|
-
case ZodIssueCode.invalid_enum_value:
|
|
1050
|
-
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
1051
|
-
break;
|
|
1052
|
-
case ZodIssueCode.invalid_arguments:
|
|
1053
|
-
message = `Invalid function arguments`;
|
|
1054
|
-
break;
|
|
1055
|
-
case ZodIssueCode.invalid_return_type:
|
|
1056
|
-
message = `Invalid function return type`;
|
|
1057
|
-
break;
|
|
1058
|
-
case ZodIssueCode.invalid_date:
|
|
1059
|
-
message = `Invalid date`;
|
|
1060
|
-
break;
|
|
1061
|
-
case ZodIssueCode.invalid_string:
|
|
1062
|
-
if (typeof issue.validation === "object") {
|
|
1063
|
-
if ("includes" in issue.validation) {
|
|
1064
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
1065
|
-
if (typeof issue.validation.position === "number") {
|
|
1066
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
1067
|
-
}
|
|
1068
|
-
} else if ("startsWith" in issue.validation) {
|
|
1069
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
1070
|
-
} else if ("endsWith" in issue.validation) {
|
|
1071
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
1072
|
-
} else {
|
|
1073
|
-
util.assertNever(issue.validation);
|
|
1074
|
-
}
|
|
1075
|
-
} else if (issue.validation !== "regex") {
|
|
1076
|
-
message = `Invalid ${issue.validation}`;
|
|
1077
|
-
} else {
|
|
1078
|
-
message = "Invalid";
|
|
1079
|
-
}
|
|
1080
|
-
break;
|
|
1081
|
-
case ZodIssueCode.too_small:
|
|
1082
|
-
if (issue.type === "array")
|
|
1083
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
1084
|
-
else if (issue.type === "string")
|
|
1085
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
1086
|
-
else if (issue.type === "number")
|
|
1087
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1088
|
-
else if (issue.type === "bigint")
|
|
1089
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
1090
|
-
else if (issue.type === "date")
|
|
1091
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
1092
|
-
else
|
|
1093
|
-
message = "Invalid input";
|
|
1094
|
-
break;
|
|
1095
|
-
case ZodIssueCode.too_big:
|
|
1096
|
-
if (issue.type === "array")
|
|
1097
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
1098
|
-
else if (issue.type === "string")
|
|
1099
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
1100
|
-
else if (issue.type === "number")
|
|
1101
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1102
|
-
else if (issue.type === "bigint")
|
|
1103
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
1104
|
-
else if (issue.type === "date")
|
|
1105
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
1106
|
-
else
|
|
1107
|
-
message = "Invalid input";
|
|
1108
|
-
break;
|
|
1109
|
-
case ZodIssueCode.custom:
|
|
1110
|
-
message = `Invalid input`;
|
|
1111
|
-
break;
|
|
1112
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
1113
|
-
message = `Intersection results could not be merged`;
|
|
1114
|
-
break;
|
|
1115
|
-
case ZodIssueCode.not_multiple_of:
|
|
1116
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
1117
|
-
break;
|
|
1118
|
-
case ZodIssueCode.not_finite:
|
|
1119
|
-
message = "Number must be finite";
|
|
1120
|
-
break;
|
|
1121
|
-
default:
|
|
1122
|
-
message = _ctx.defaultError;
|
|
1123
|
-
util.assertNever(issue);
|
|
1124
|
-
}
|
|
1125
|
-
return { message };
|
|
1126
|
-
};
|
|
1127
|
-
var en_default = errorMap;
|
|
1128
|
-
|
|
1129
|
-
// node_modules/zod/v3/errors.js
|
|
1130
|
-
var overrideErrorMap = en_default;
|
|
1131
|
-
function setErrorMap(map) {
|
|
1132
|
-
overrideErrorMap = map;
|
|
1133
|
-
}
|
|
1134
|
-
function getErrorMap() {
|
|
1135
|
-
return overrideErrorMap;
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
// node_modules/zod/v3/helpers/parseUtil.js
|
|
1139
|
-
var makeIssue = (params) => {
|
|
1140
|
-
const { data, path: path9, errorMaps, issueData } = params;
|
|
1141
|
-
const fullPath = [...path9, ...issueData.path || []];
|
|
1142
|
-
const fullIssue = {
|
|
1143
|
-
...issueData,
|
|
1144
|
-
path: fullPath
|
|
1145
|
-
};
|
|
1146
|
-
if (issueData.message !== void 0) {
|
|
1147
|
-
return {
|
|
1148
|
-
...issueData,
|
|
1149
|
-
path: fullPath,
|
|
1150
|
-
message: issueData.message
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
let errorMessage = "";
|
|
1154
|
-
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
1155
|
-
for (const map of maps) {
|
|
1156
|
-
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
1157
|
-
}
|
|
1158
|
-
return {
|
|
1159
|
-
...issueData,
|
|
1160
|
-
path: fullPath,
|
|
1161
|
-
message: errorMessage
|
|
1162
|
-
};
|
|
1163
|
-
};
|
|
1164
|
-
var EMPTY_PATH = [];
|
|
1165
|
-
function addIssueToContext(ctx, issueData) {
|
|
1166
|
-
const overrideMap = getErrorMap();
|
|
1167
|
-
const issue = makeIssue({
|
|
1168
|
-
issueData,
|
|
1169
|
-
data: ctx.data,
|
|
1170
|
-
path: ctx.path,
|
|
1171
|
-
errorMaps: [
|
|
1172
|
-
ctx.common.contextualErrorMap,
|
|
1173
|
-
// contextual error map is first priority
|
|
1174
|
-
ctx.schemaErrorMap,
|
|
1175
|
-
// then schema-bound map if available
|
|
1176
|
-
overrideMap,
|
|
1177
|
-
// then global override map
|
|
1178
|
-
overrideMap === en_default ? void 0 : en_default
|
|
1179
|
-
// then global default map
|
|
1180
|
-
].filter((x) => !!x)
|
|
1181
|
-
});
|
|
1182
|
-
ctx.common.issues.push(issue);
|
|
1183
|
-
}
|
|
1184
|
-
var ParseStatus = class _ParseStatus {
|
|
1185
|
-
constructor() {
|
|
1186
|
-
this.value = "valid";
|
|
1187
|
-
}
|
|
1188
|
-
dirty() {
|
|
1189
|
-
if (this.value === "valid")
|
|
1190
|
-
this.value = "dirty";
|
|
1191
|
-
}
|
|
1192
|
-
abort() {
|
|
1193
|
-
if (this.value !== "aborted")
|
|
1194
|
-
this.value = "aborted";
|
|
1195
|
-
}
|
|
1196
|
-
static mergeArray(status, results) {
|
|
1197
|
-
const arrayValue = [];
|
|
1198
|
-
for (const s of results) {
|
|
1199
|
-
if (s.status === "aborted")
|
|
1200
|
-
return INVALID;
|
|
1201
|
-
if (s.status === "dirty")
|
|
1202
|
-
status.dirty();
|
|
1203
|
-
arrayValue.push(s.value);
|
|
1204
|
-
}
|
|
1205
|
-
return { status: status.value, value: arrayValue };
|
|
1206
|
-
}
|
|
1207
|
-
static async mergeObjectAsync(status, pairs) {
|
|
1208
|
-
const syncPairs = [];
|
|
1209
|
-
for (const pair of pairs) {
|
|
1210
|
-
const key = await pair.key;
|
|
1211
|
-
const value = await pair.value;
|
|
1212
|
-
syncPairs.push({
|
|
1213
|
-
key,
|
|
1214
|
-
value
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
|
-
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1218
|
-
}
|
|
1219
|
-
static mergeObjectSync(status, pairs) {
|
|
1220
|
-
const finalObject = {};
|
|
1221
|
-
for (const pair of pairs) {
|
|
1222
|
-
const { key, value } = pair;
|
|
1223
|
-
if (key.status === "aborted")
|
|
1224
|
-
return INVALID;
|
|
1225
|
-
if (value.status === "aborted")
|
|
1226
|
-
return INVALID;
|
|
1227
|
-
if (key.status === "dirty")
|
|
1228
|
-
status.dirty();
|
|
1229
|
-
if (value.status === "dirty")
|
|
1230
|
-
status.dirty();
|
|
1231
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
1232
|
-
finalObject[key.value] = value.value;
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
return { status: status.value, value: finalObject };
|
|
1236
|
-
}
|
|
1237
|
-
};
|
|
1238
|
-
var INVALID = Object.freeze({
|
|
1239
|
-
status: "aborted"
|
|
1240
|
-
});
|
|
1241
|
-
var DIRTY = (value) => ({ status: "dirty", value });
|
|
1242
|
-
var OK = (value) => ({ status: "valid", value });
|
|
1243
|
-
var isAborted = (x) => x.status === "aborted";
|
|
1244
|
-
var isDirty = (x) => x.status === "dirty";
|
|
1245
|
-
var isValid = (x) => x.status === "valid";
|
|
1246
|
-
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
1247
|
-
|
|
1248
|
-
// node_modules/zod/v3/helpers/errorUtil.js
|
|
1249
|
-
var errorUtil;
|
|
1250
|
-
(function(errorUtil2) {
|
|
1251
|
-
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
1252
|
-
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
1253
|
-
})(errorUtil || (errorUtil = {}));
|
|
1254
|
-
|
|
1255
|
-
// node_modules/zod/v3/types.js
|
|
1256
|
-
var ParseInputLazyPath = class {
|
|
1257
|
-
constructor(parent, value, path9, key) {
|
|
1258
|
-
this._cachedPath = [];
|
|
1259
|
-
this.parent = parent;
|
|
1260
|
-
this.data = value;
|
|
1261
|
-
this._path = path9;
|
|
1262
|
-
this._key = key;
|
|
1263
|
-
}
|
|
1264
|
-
get path() {
|
|
1265
|
-
if (!this._cachedPath.length) {
|
|
1266
|
-
if (Array.isArray(this._key)) {
|
|
1267
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
1268
|
-
} else {
|
|
1269
|
-
this._cachedPath.push(...this._path, this._key);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
return this._cachedPath;
|
|
1273
|
-
}
|
|
1274
|
-
};
|
|
1275
|
-
var handleResult = (ctx, result) => {
|
|
1276
|
-
if (isValid(result)) {
|
|
1277
|
-
return { success: true, data: result.value };
|
|
1278
|
-
} else {
|
|
1279
|
-
if (!ctx.common.issues.length) {
|
|
1280
|
-
throw new Error("Validation failed but no issues detected.");
|
|
1281
|
-
}
|
|
1282
|
-
return {
|
|
1283
|
-
success: false,
|
|
1284
|
-
get error() {
|
|
1285
|
-
if (this._error)
|
|
1286
|
-
return this._error;
|
|
1287
|
-
const error = new ZodError(ctx.common.issues);
|
|
1288
|
-
this._error = error;
|
|
1289
|
-
return this._error;
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
};
|
|
1294
|
-
function processCreateParams(params) {
|
|
1295
|
-
if (!params)
|
|
1296
|
-
return {};
|
|
1297
|
-
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
1298
|
-
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
1299
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
1300
|
-
}
|
|
1301
|
-
if (errorMap2)
|
|
1302
|
-
return { errorMap: errorMap2, description };
|
|
1303
|
-
const customMap = (iss, ctx) => {
|
|
1304
|
-
const { message } = params;
|
|
1305
|
-
if (iss.code === "invalid_enum_value") {
|
|
1306
|
-
return { message: message ?? ctx.defaultError };
|
|
1307
|
-
}
|
|
1308
|
-
if (typeof ctx.data === "undefined") {
|
|
1309
|
-
return { message: message ?? required_error ?? ctx.defaultError };
|
|
1310
|
-
}
|
|
1311
|
-
if (iss.code !== "invalid_type")
|
|
1312
|
-
return { message: ctx.defaultError };
|
|
1313
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
1314
|
-
};
|
|
1315
|
-
return { errorMap: customMap, description };
|
|
1316
|
-
}
|
|
1317
|
-
var ZodType = class {
|
|
1318
|
-
get description() {
|
|
1319
|
-
return this._def.description;
|
|
1320
|
-
}
|
|
1321
|
-
_getType(input) {
|
|
1322
|
-
return getParsedType(input.data);
|
|
1323
|
-
}
|
|
1324
|
-
_getOrReturnCtx(input, ctx) {
|
|
1325
|
-
return ctx || {
|
|
1326
|
-
common: input.parent.common,
|
|
1327
|
-
data: input.data,
|
|
1328
|
-
parsedType: getParsedType(input.data),
|
|
1329
|
-
schemaErrorMap: this._def.errorMap,
|
|
1330
|
-
path: input.path,
|
|
1331
|
-
parent: input.parent
|
|
1332
|
-
};
|
|
1333
|
-
}
|
|
1334
|
-
_processInputParams(input) {
|
|
1335
|
-
return {
|
|
1336
|
-
status: new ParseStatus(),
|
|
1337
|
-
ctx: {
|
|
1338
|
-
common: input.parent.common,
|
|
1339
|
-
data: input.data,
|
|
1340
|
-
parsedType: getParsedType(input.data),
|
|
1341
|
-
schemaErrorMap: this._def.errorMap,
|
|
1342
|
-
path: input.path,
|
|
1343
|
-
parent: input.parent
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
}
|
|
1347
|
-
_parseSync(input) {
|
|
1348
|
-
const result = this._parse(input);
|
|
1349
|
-
if (isAsync(result)) {
|
|
1350
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
1351
|
-
}
|
|
1352
|
-
return result;
|
|
1353
|
-
}
|
|
1354
|
-
_parseAsync(input) {
|
|
1355
|
-
const result = this._parse(input);
|
|
1356
|
-
return Promise.resolve(result);
|
|
1357
|
-
}
|
|
1358
|
-
parse(data, params) {
|
|
1359
|
-
const result = this.safeParse(data, params);
|
|
1360
|
-
if (result.success)
|
|
1361
|
-
return result.data;
|
|
1362
|
-
throw result.error;
|
|
1363
|
-
}
|
|
1364
|
-
safeParse(data, params) {
|
|
1365
|
-
const ctx = {
|
|
1366
|
-
common: {
|
|
1367
|
-
issues: [],
|
|
1368
|
-
async: params?.async ?? false,
|
|
1369
|
-
contextualErrorMap: params?.errorMap
|
|
1370
|
-
},
|
|
1371
|
-
path: params?.path || [],
|
|
1372
|
-
schemaErrorMap: this._def.errorMap,
|
|
1373
|
-
parent: null,
|
|
1374
|
-
data,
|
|
1375
|
-
parsedType: getParsedType(data)
|
|
1376
|
-
};
|
|
1377
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
1378
|
-
return handleResult(ctx, result);
|
|
1379
|
-
}
|
|
1380
|
-
"~validate"(data) {
|
|
1381
|
-
const ctx = {
|
|
1382
|
-
common: {
|
|
1383
|
-
issues: [],
|
|
1384
|
-
async: !!this["~standard"].async
|
|
1385
|
-
},
|
|
1386
|
-
path: [],
|
|
1387
|
-
schemaErrorMap: this._def.errorMap,
|
|
1388
|
-
parent: null,
|
|
1389
|
-
data,
|
|
1390
|
-
parsedType: getParsedType(data)
|
|
1391
|
-
};
|
|
1392
|
-
if (!this["~standard"].async) {
|
|
1393
|
-
try {
|
|
1394
|
-
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
1395
|
-
return isValid(result) ? {
|
|
1396
|
-
value: result.value
|
|
1397
|
-
} : {
|
|
1398
|
-
issues: ctx.common.issues
|
|
1399
|
-
};
|
|
1400
|
-
} catch (err) {
|
|
1401
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
1402
|
-
this["~standard"].async = true;
|
|
1403
|
-
}
|
|
1404
|
-
ctx.common = {
|
|
1405
|
-
issues: [],
|
|
1406
|
-
async: true
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
1411
|
-
value: result.value
|
|
1412
|
-
} : {
|
|
1413
|
-
issues: ctx.common.issues
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
async parseAsync(data, params) {
|
|
1417
|
-
const result = await this.safeParseAsync(data, params);
|
|
1418
|
-
if (result.success)
|
|
1419
|
-
return result.data;
|
|
1420
|
-
throw result.error;
|
|
1421
|
-
}
|
|
1422
|
-
async safeParseAsync(data, params) {
|
|
1423
|
-
const ctx = {
|
|
1424
|
-
common: {
|
|
1425
|
-
issues: [],
|
|
1426
|
-
contextualErrorMap: params?.errorMap,
|
|
1427
|
-
async: true
|
|
1428
|
-
},
|
|
1429
|
-
path: params?.path || [],
|
|
1430
|
-
schemaErrorMap: this._def.errorMap,
|
|
1431
|
-
parent: null,
|
|
1432
|
-
data,
|
|
1433
|
-
parsedType: getParsedType(data)
|
|
1434
|
-
};
|
|
1435
|
-
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
1436
|
-
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
1437
|
-
return handleResult(ctx, result);
|
|
1438
|
-
}
|
|
1439
|
-
refine(check, message) {
|
|
1440
|
-
const getIssueProperties = (val) => {
|
|
1441
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
1442
|
-
return { message };
|
|
1443
|
-
} else if (typeof message === "function") {
|
|
1444
|
-
return message(val);
|
|
1445
|
-
} else {
|
|
1446
|
-
return message;
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
|
-
return this._refinement((val, ctx) => {
|
|
1450
|
-
const result = check(val);
|
|
1451
|
-
const setError = () => ctx.addIssue({
|
|
1452
|
-
code: ZodIssueCode.custom,
|
|
1453
|
-
...getIssueProperties(val)
|
|
1454
|
-
});
|
|
1455
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
1456
|
-
return result.then((data) => {
|
|
1457
|
-
if (!data) {
|
|
1458
|
-
setError();
|
|
1459
|
-
return false;
|
|
1460
|
-
} else {
|
|
1461
|
-
return true;
|
|
1462
|
-
}
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
if (!result) {
|
|
1466
|
-
setError();
|
|
1467
|
-
return false;
|
|
1468
|
-
} else {
|
|
1469
|
-
return true;
|
|
1470
|
-
}
|
|
1471
|
-
});
|
|
1472
|
-
}
|
|
1473
|
-
refinement(check, refinementData) {
|
|
1474
|
-
return this._refinement((val, ctx) => {
|
|
1475
|
-
if (!check(val)) {
|
|
1476
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
1477
|
-
return false;
|
|
1478
|
-
} else {
|
|
1479
|
-
return true;
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
}
|
|
1483
|
-
_refinement(refinement) {
|
|
1484
|
-
return new ZodEffects({
|
|
1485
|
-
schema: this,
|
|
1486
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1487
|
-
effect: { type: "refinement", refinement }
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
superRefine(refinement) {
|
|
1491
|
-
return this._refinement(refinement);
|
|
1492
|
-
}
|
|
1493
|
-
constructor(def) {
|
|
1494
|
-
this.spa = this.safeParseAsync;
|
|
1495
|
-
this._def = def;
|
|
1496
|
-
this.parse = this.parse.bind(this);
|
|
1497
|
-
this.safeParse = this.safeParse.bind(this);
|
|
1498
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
1499
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
1500
|
-
this.spa = this.spa.bind(this);
|
|
1501
|
-
this.refine = this.refine.bind(this);
|
|
1502
|
-
this.refinement = this.refinement.bind(this);
|
|
1503
|
-
this.superRefine = this.superRefine.bind(this);
|
|
1504
|
-
this.optional = this.optional.bind(this);
|
|
1505
|
-
this.nullable = this.nullable.bind(this);
|
|
1506
|
-
this.nullish = this.nullish.bind(this);
|
|
1507
|
-
this.array = this.array.bind(this);
|
|
1508
|
-
this.promise = this.promise.bind(this);
|
|
1509
|
-
this.or = this.or.bind(this);
|
|
1510
|
-
this.and = this.and.bind(this);
|
|
1511
|
-
this.transform = this.transform.bind(this);
|
|
1512
|
-
this.brand = this.brand.bind(this);
|
|
1513
|
-
this.default = this.default.bind(this);
|
|
1514
|
-
this.catch = this.catch.bind(this);
|
|
1515
|
-
this.describe = this.describe.bind(this);
|
|
1516
|
-
this.pipe = this.pipe.bind(this);
|
|
1517
|
-
this.readonly = this.readonly.bind(this);
|
|
1518
|
-
this.isNullable = this.isNullable.bind(this);
|
|
1519
|
-
this.isOptional = this.isOptional.bind(this);
|
|
1520
|
-
this["~standard"] = {
|
|
1521
|
-
version: 1,
|
|
1522
|
-
vendor: "zod",
|
|
1523
|
-
validate: (data) => this["~validate"](data)
|
|
1524
|
-
};
|
|
1525
|
-
}
|
|
1526
|
-
optional() {
|
|
1527
|
-
return ZodOptional.create(this, this._def);
|
|
1528
|
-
}
|
|
1529
|
-
nullable() {
|
|
1530
|
-
return ZodNullable.create(this, this._def);
|
|
1531
|
-
}
|
|
1532
|
-
nullish() {
|
|
1533
|
-
return this.nullable().optional();
|
|
1534
|
-
}
|
|
1535
|
-
array() {
|
|
1536
|
-
return ZodArray.create(this);
|
|
1537
|
-
}
|
|
1538
|
-
promise() {
|
|
1539
|
-
return ZodPromise.create(this, this._def);
|
|
1540
|
-
}
|
|
1541
|
-
or(option) {
|
|
1542
|
-
return ZodUnion.create([this, option], this._def);
|
|
1543
|
-
}
|
|
1544
|
-
and(incoming) {
|
|
1545
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
1546
|
-
}
|
|
1547
|
-
transform(transform) {
|
|
1548
|
-
return new ZodEffects({
|
|
1549
|
-
...processCreateParams(this._def),
|
|
1550
|
-
schema: this,
|
|
1551
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1552
|
-
effect: { type: "transform", transform }
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
default(def) {
|
|
1556
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1557
|
-
return new ZodDefault({
|
|
1558
|
-
...processCreateParams(this._def),
|
|
1559
|
-
innerType: this,
|
|
1560
|
-
defaultValue: defaultValueFunc,
|
|
1561
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1562
|
-
});
|
|
1563
|
-
}
|
|
1564
|
-
brand() {
|
|
1565
|
-
return new ZodBranded({
|
|
1566
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1567
|
-
type: this,
|
|
1568
|
-
...processCreateParams(this._def)
|
|
1569
|
-
});
|
|
1570
|
-
}
|
|
1571
|
-
catch(def) {
|
|
1572
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1573
|
-
return new ZodCatch({
|
|
1574
|
-
...processCreateParams(this._def),
|
|
1575
|
-
innerType: this,
|
|
1576
|
-
catchValue: catchValueFunc,
|
|
1577
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1578
|
-
});
|
|
1579
|
-
}
|
|
1580
|
-
describe(description) {
|
|
1581
|
-
const This = this.constructor;
|
|
1582
|
-
return new This({
|
|
1583
|
-
...this._def,
|
|
1584
|
-
description
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1587
|
-
pipe(target) {
|
|
1588
|
-
return ZodPipeline.create(this, target);
|
|
1589
|
-
}
|
|
1590
|
-
readonly() {
|
|
1591
|
-
return ZodReadonly.create(this);
|
|
1592
|
-
}
|
|
1593
|
-
isOptional() {
|
|
1594
|
-
return this.safeParse(void 0).success;
|
|
1595
|
-
}
|
|
1596
|
-
isNullable() {
|
|
1597
|
-
return this.safeParse(null).success;
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1601
|
-
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1602
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1603
|
-
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;
|
|
1604
|
-
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1605
|
-
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1606
|
-
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)?)??$/;
|
|
1607
|
-
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1608
|
-
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1609
|
-
var emojiRegex;
|
|
1610
|
-
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])$/;
|
|
1611
|
-
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])$/;
|
|
1612
|
-
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]))$/;
|
|
1613
|
-
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])$/;
|
|
1614
|
-
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1615
|
-
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1616
|
-
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])))`;
|
|
1617
|
-
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1618
|
-
function timeRegexSource(args) {
|
|
1619
|
-
let secondsRegexSource = `[0-5]\\d`;
|
|
1620
|
-
if (args.precision) {
|
|
1621
|
-
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1622
|
-
} else if (args.precision == null) {
|
|
1623
|
-
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1624
|
-
}
|
|
1625
|
-
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1626
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1627
|
-
}
|
|
1628
|
-
function timeRegex(args) {
|
|
1629
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1630
|
-
}
|
|
1631
|
-
function datetimeRegex(args) {
|
|
1632
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1633
|
-
const opts = [];
|
|
1634
|
-
opts.push(args.local ? `Z?` : `Z`);
|
|
1635
|
-
if (args.offset)
|
|
1636
|
-
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1637
|
-
regex = `${regex}(${opts.join("|")})`;
|
|
1638
|
-
return new RegExp(`^${regex}$`);
|
|
1639
|
-
}
|
|
1640
|
-
function isValidIP(ip, version) {
|
|
1641
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1642
|
-
return true;
|
|
1643
|
-
}
|
|
1644
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1645
|
-
return true;
|
|
1646
|
-
}
|
|
1647
|
-
return false;
|
|
1648
|
-
}
|
|
1649
|
-
function isValidJWT(jwt, alg) {
|
|
1650
|
-
if (!jwtRegex.test(jwt))
|
|
1651
|
-
return false;
|
|
1652
|
-
try {
|
|
1653
|
-
const [header] = jwt.split(".");
|
|
1654
|
-
if (!header)
|
|
1655
|
-
return false;
|
|
1656
|
-
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1657
|
-
const decoded = JSON.parse(atob(base64));
|
|
1658
|
-
if (typeof decoded !== "object" || decoded === null)
|
|
1659
|
-
return false;
|
|
1660
|
-
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1661
|
-
return false;
|
|
1662
|
-
if (!decoded.alg)
|
|
1663
|
-
return false;
|
|
1664
|
-
if (alg && decoded.alg !== alg)
|
|
1665
|
-
return false;
|
|
1666
|
-
return true;
|
|
1667
|
-
} catch {
|
|
1668
|
-
return false;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
function isValidCidr(ip, version) {
|
|
1672
|
-
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1673
|
-
return true;
|
|
1674
|
-
}
|
|
1675
|
-
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1676
|
-
return true;
|
|
1677
|
-
}
|
|
1678
|
-
return false;
|
|
1679
|
-
}
|
|
1680
|
-
var ZodString = class _ZodString extends ZodType {
|
|
1681
|
-
_parse(input) {
|
|
1682
|
-
if (this._def.coerce) {
|
|
1683
|
-
input.data = String(input.data);
|
|
1684
|
-
}
|
|
1685
|
-
const parsedType = this._getType(input);
|
|
1686
|
-
if (parsedType !== ZodParsedType.string) {
|
|
1687
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
1688
|
-
addIssueToContext(ctx2, {
|
|
1689
|
-
code: ZodIssueCode.invalid_type,
|
|
1690
|
-
expected: ZodParsedType.string,
|
|
1691
|
-
received: ctx2.parsedType
|
|
1692
|
-
});
|
|
1693
|
-
return INVALID;
|
|
1694
|
-
}
|
|
1695
|
-
const status = new ParseStatus();
|
|
1696
|
-
let ctx = void 0;
|
|
1697
|
-
for (const check of this._def.checks) {
|
|
1698
|
-
if (check.kind === "min") {
|
|
1699
|
-
if (input.data.length < check.value) {
|
|
1700
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1701
|
-
addIssueToContext(ctx, {
|
|
1702
|
-
code: ZodIssueCode.too_small,
|
|
1703
|
-
minimum: check.value,
|
|
1704
|
-
type: "string",
|
|
1705
|
-
inclusive: true,
|
|
1706
|
-
exact: false,
|
|
1707
|
-
message: check.message
|
|
1708
|
-
});
|
|
1709
|
-
status.dirty();
|
|
1710
|
-
}
|
|
1711
|
-
} else if (check.kind === "max") {
|
|
1712
|
-
if (input.data.length > check.value) {
|
|
1713
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1714
|
-
addIssueToContext(ctx, {
|
|
1715
|
-
code: ZodIssueCode.too_big,
|
|
1716
|
-
maximum: check.value,
|
|
1717
|
-
type: "string",
|
|
1718
|
-
inclusive: true,
|
|
1719
|
-
exact: false,
|
|
1720
|
-
message: check.message
|
|
1721
|
-
});
|
|
1722
|
-
status.dirty();
|
|
1723
|
-
}
|
|
1724
|
-
} else if (check.kind === "length") {
|
|
1725
|
-
const tooBig = input.data.length > check.value;
|
|
1726
|
-
const tooSmall = input.data.length < check.value;
|
|
1727
|
-
if (tooBig || tooSmall) {
|
|
1728
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1729
|
-
if (tooBig) {
|
|
1730
|
-
addIssueToContext(ctx, {
|
|
1731
|
-
code: ZodIssueCode.too_big,
|
|
1732
|
-
maximum: check.value,
|
|
1733
|
-
type: "string",
|
|
1734
|
-
inclusive: true,
|
|
1735
|
-
exact: true,
|
|
1736
|
-
message: check.message
|
|
1737
|
-
});
|
|
1738
|
-
} else if (tooSmall) {
|
|
1739
|
-
addIssueToContext(ctx, {
|
|
1740
|
-
code: ZodIssueCode.too_small,
|
|
1741
|
-
minimum: check.value,
|
|
1742
|
-
type: "string",
|
|
1743
|
-
inclusive: true,
|
|
1744
|
-
exact: true,
|
|
1745
|
-
message: check.message
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
status.dirty();
|
|
1749
|
-
}
|
|
1750
|
-
} else if (check.kind === "email") {
|
|
1751
|
-
if (!emailRegex.test(input.data)) {
|
|
1752
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1753
|
-
addIssueToContext(ctx, {
|
|
1754
|
-
validation: "email",
|
|
1755
|
-
code: ZodIssueCode.invalid_string,
|
|
1756
|
-
message: check.message
|
|
1757
|
-
});
|
|
1758
|
-
status.dirty();
|
|
1759
|
-
}
|
|
1760
|
-
} else if (check.kind === "emoji") {
|
|
1761
|
-
if (!emojiRegex) {
|
|
1762
|
-
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1763
|
-
}
|
|
1764
|
-
if (!emojiRegex.test(input.data)) {
|
|
1765
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1766
|
-
addIssueToContext(ctx, {
|
|
1767
|
-
validation: "emoji",
|
|
1768
|
-
code: ZodIssueCode.invalid_string,
|
|
1769
|
-
message: check.message
|
|
1770
|
-
});
|
|
1771
|
-
status.dirty();
|
|
1772
|
-
}
|
|
1773
|
-
} else if (check.kind === "uuid") {
|
|
1774
|
-
if (!uuidRegex.test(input.data)) {
|
|
1775
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1776
|
-
addIssueToContext(ctx, {
|
|
1777
|
-
validation: "uuid",
|
|
1778
|
-
code: ZodIssueCode.invalid_string,
|
|
1779
|
-
message: check.message
|
|
1780
|
-
});
|
|
1781
|
-
status.dirty();
|
|
1782
|
-
}
|
|
1783
|
-
} else if (check.kind === "nanoid") {
|
|
1784
|
-
if (!nanoidRegex.test(input.data)) {
|
|
1785
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1786
|
-
addIssueToContext(ctx, {
|
|
1787
|
-
validation: "nanoid",
|
|
1788
|
-
code: ZodIssueCode.invalid_string,
|
|
1789
|
-
message: check.message
|
|
1790
|
-
});
|
|
1791
|
-
status.dirty();
|
|
1792
|
-
}
|
|
1793
|
-
} else if (check.kind === "cuid") {
|
|
1794
|
-
if (!cuidRegex.test(input.data)) {
|
|
1795
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1796
|
-
addIssueToContext(ctx, {
|
|
1797
|
-
validation: "cuid",
|
|
1798
|
-
code: ZodIssueCode.invalid_string,
|
|
1799
|
-
message: check.message
|
|
1800
|
-
});
|
|
1801
|
-
status.dirty();
|
|
1802
|
-
}
|
|
1803
|
-
} else if (check.kind === "cuid2") {
|
|
1804
|
-
if (!cuid2Regex.test(input.data)) {
|
|
1805
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1806
|
-
addIssueToContext(ctx, {
|
|
1807
|
-
validation: "cuid2",
|
|
1808
|
-
code: ZodIssueCode.invalid_string,
|
|
1809
|
-
message: check.message
|
|
1810
|
-
});
|
|
1811
|
-
status.dirty();
|
|
1812
|
-
}
|
|
1813
|
-
} else if (check.kind === "ulid") {
|
|
1814
|
-
if (!ulidRegex.test(input.data)) {
|
|
1815
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1816
|
-
addIssueToContext(ctx, {
|
|
1817
|
-
validation: "ulid",
|
|
1818
|
-
code: ZodIssueCode.invalid_string,
|
|
1819
|
-
message: check.message
|
|
1820
|
-
});
|
|
1821
|
-
status.dirty();
|
|
1822
|
-
}
|
|
1823
|
-
} else if (check.kind === "url") {
|
|
1824
|
-
try {
|
|
1825
|
-
new URL(input.data);
|
|
1826
|
-
} catch {
|
|
1827
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1828
|
-
addIssueToContext(ctx, {
|
|
1829
|
-
validation: "url",
|
|
1830
|
-
code: ZodIssueCode.invalid_string,
|
|
1831
|
-
message: check.message
|
|
1832
|
-
});
|
|
1833
|
-
status.dirty();
|
|
1834
|
-
}
|
|
1835
|
-
} else if (check.kind === "regex") {
|
|
1836
|
-
check.regex.lastIndex = 0;
|
|
1837
|
-
const testResult = check.regex.test(input.data);
|
|
1838
|
-
if (!testResult) {
|
|
1839
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1840
|
-
addIssueToContext(ctx, {
|
|
1841
|
-
validation: "regex",
|
|
1842
|
-
code: ZodIssueCode.invalid_string,
|
|
1843
|
-
message: check.message
|
|
1844
|
-
});
|
|
1845
|
-
status.dirty();
|
|
1846
|
-
}
|
|
1847
|
-
} else if (check.kind === "trim") {
|
|
1848
|
-
input.data = input.data.trim();
|
|
1849
|
-
} else if (check.kind === "includes") {
|
|
1850
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
1851
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1852
|
-
addIssueToContext(ctx, {
|
|
1853
|
-
code: ZodIssueCode.invalid_string,
|
|
1854
|
-
validation: { includes: check.value, position: check.position },
|
|
1855
|
-
message: check.message
|
|
1856
|
-
});
|
|
1857
|
-
status.dirty();
|
|
1858
|
-
}
|
|
1859
|
-
} else if (check.kind === "toLowerCase") {
|
|
1860
|
-
input.data = input.data.toLowerCase();
|
|
1861
|
-
} else if (check.kind === "toUpperCase") {
|
|
1862
|
-
input.data = input.data.toUpperCase();
|
|
1863
|
-
} else if (check.kind === "startsWith") {
|
|
1864
|
-
if (!input.data.startsWith(check.value)) {
|
|
1865
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1866
|
-
addIssueToContext(ctx, {
|
|
1867
|
-
code: ZodIssueCode.invalid_string,
|
|
1868
|
-
validation: { startsWith: check.value },
|
|
1869
|
-
message: check.message
|
|
1870
|
-
});
|
|
1871
|
-
status.dirty();
|
|
1872
|
-
}
|
|
1873
|
-
} else if (check.kind === "endsWith") {
|
|
1874
|
-
if (!input.data.endsWith(check.value)) {
|
|
1875
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1876
|
-
addIssueToContext(ctx, {
|
|
1877
|
-
code: ZodIssueCode.invalid_string,
|
|
1878
|
-
validation: { endsWith: check.value },
|
|
1879
|
-
message: check.message
|
|
1880
|
-
});
|
|
1881
|
-
status.dirty();
|
|
1882
|
-
}
|
|
1883
|
-
} else if (check.kind === "datetime") {
|
|
1884
|
-
const regex = datetimeRegex(check);
|
|
1885
|
-
if (!regex.test(input.data)) {
|
|
1886
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1887
|
-
addIssueToContext(ctx, {
|
|
1888
|
-
code: ZodIssueCode.invalid_string,
|
|
1889
|
-
validation: "datetime",
|
|
1890
|
-
message: check.message
|
|
1891
|
-
});
|
|
1892
|
-
status.dirty();
|
|
1893
|
-
}
|
|
1894
|
-
} else if (check.kind === "date") {
|
|
1895
|
-
const regex = dateRegex;
|
|
1896
|
-
if (!regex.test(input.data)) {
|
|
1897
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1898
|
-
addIssueToContext(ctx, {
|
|
1899
|
-
code: ZodIssueCode.invalid_string,
|
|
1900
|
-
validation: "date",
|
|
1901
|
-
message: check.message
|
|
1902
|
-
});
|
|
1903
|
-
status.dirty();
|
|
1904
|
-
}
|
|
1905
|
-
} else if (check.kind === "time") {
|
|
1906
|
-
const regex = timeRegex(check);
|
|
1907
|
-
if (!regex.test(input.data)) {
|
|
1908
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1909
|
-
addIssueToContext(ctx, {
|
|
1910
|
-
code: ZodIssueCode.invalid_string,
|
|
1911
|
-
validation: "time",
|
|
1912
|
-
message: check.message
|
|
1913
|
-
});
|
|
1914
|
-
status.dirty();
|
|
1915
|
-
}
|
|
1916
|
-
} else if (check.kind === "duration") {
|
|
1917
|
-
if (!durationRegex.test(input.data)) {
|
|
1918
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1919
|
-
addIssueToContext(ctx, {
|
|
1920
|
-
validation: "duration",
|
|
1921
|
-
code: ZodIssueCode.invalid_string,
|
|
1922
|
-
message: check.message
|
|
1923
|
-
});
|
|
1924
|
-
status.dirty();
|
|
1925
|
-
}
|
|
1926
|
-
} else if (check.kind === "ip") {
|
|
1927
|
-
if (!isValidIP(input.data, check.version)) {
|
|
1928
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1929
|
-
addIssueToContext(ctx, {
|
|
1930
|
-
validation: "ip",
|
|
1931
|
-
code: ZodIssueCode.invalid_string,
|
|
1932
|
-
message: check.message
|
|
1933
|
-
});
|
|
1934
|
-
status.dirty();
|
|
1935
|
-
}
|
|
1936
|
-
} else if (check.kind === "jwt") {
|
|
1937
|
-
if (!isValidJWT(input.data, check.alg)) {
|
|
1938
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1939
|
-
addIssueToContext(ctx, {
|
|
1940
|
-
validation: "jwt",
|
|
1941
|
-
code: ZodIssueCode.invalid_string,
|
|
1942
|
-
message: check.message
|
|
1943
|
-
});
|
|
1944
|
-
status.dirty();
|
|
1945
|
-
}
|
|
1946
|
-
} else if (check.kind === "cidr") {
|
|
1947
|
-
if (!isValidCidr(input.data, check.version)) {
|
|
1948
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1949
|
-
addIssueToContext(ctx, {
|
|
1950
|
-
validation: "cidr",
|
|
1951
|
-
code: ZodIssueCode.invalid_string,
|
|
1952
|
-
message: check.message
|
|
1953
|
-
});
|
|
1954
|
-
status.dirty();
|
|
1955
|
-
}
|
|
1956
|
-
} else if (check.kind === "base64") {
|
|
1957
|
-
if (!base64Regex.test(input.data)) {
|
|
1958
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1959
|
-
addIssueToContext(ctx, {
|
|
1960
|
-
validation: "base64",
|
|
1961
|
-
code: ZodIssueCode.invalid_string,
|
|
1962
|
-
message: check.message
|
|
1963
|
-
});
|
|
1964
|
-
status.dirty();
|
|
1965
|
-
}
|
|
1966
|
-
} else if (check.kind === "base64url") {
|
|
1967
|
-
if (!base64urlRegex.test(input.data)) {
|
|
1968
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1969
|
-
addIssueToContext(ctx, {
|
|
1970
|
-
validation: "base64url",
|
|
1971
|
-
code: ZodIssueCode.invalid_string,
|
|
1972
|
-
message: check.message
|
|
1973
|
-
});
|
|
1974
|
-
status.dirty();
|
|
1975
|
-
}
|
|
1976
|
-
} else {
|
|
1977
|
-
util.assertNever(check);
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
return { status: status.value, value: input.data };
|
|
1981
|
-
}
|
|
1982
|
-
_regex(regex, validation, message) {
|
|
1983
|
-
return this.refinement((data) => regex.test(data), {
|
|
1984
|
-
validation,
|
|
1985
|
-
code: ZodIssueCode.invalid_string,
|
|
1986
|
-
...errorUtil.errToObj(message)
|
|
1987
|
-
});
|
|
1988
|
-
}
|
|
1989
|
-
_addCheck(check) {
|
|
1990
|
-
return new _ZodString({
|
|
1991
|
-
...this._def,
|
|
1992
|
-
checks: [...this._def.checks, check]
|
|
1993
|
-
});
|
|
1994
|
-
}
|
|
1995
|
-
email(message) {
|
|
1996
|
-
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1997
|
-
}
|
|
1998
|
-
url(message) {
|
|
1999
|
-
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
2000
|
-
}
|
|
2001
|
-
emoji(message) {
|
|
2002
|
-
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
2003
|
-
}
|
|
2004
|
-
uuid(message) {
|
|
2005
|
-
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
2006
|
-
}
|
|
2007
|
-
nanoid(message) {
|
|
2008
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
2009
|
-
}
|
|
2010
|
-
cuid(message) {
|
|
2011
|
-
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
2012
|
-
}
|
|
2013
|
-
cuid2(message) {
|
|
2014
|
-
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
2015
|
-
}
|
|
2016
|
-
ulid(message) {
|
|
2017
|
-
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
2018
|
-
}
|
|
2019
|
-
base64(message) {
|
|
2020
|
-
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
2021
|
-
}
|
|
2022
|
-
base64url(message) {
|
|
2023
|
-
return this._addCheck({
|
|
2024
|
-
kind: "base64url",
|
|
2025
|
-
...errorUtil.errToObj(message)
|
|
2026
|
-
});
|
|
2027
|
-
}
|
|
2028
|
-
jwt(options) {
|
|
2029
|
-
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
2030
|
-
}
|
|
2031
|
-
ip(options) {
|
|
2032
|
-
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
2033
|
-
}
|
|
2034
|
-
cidr(options) {
|
|
2035
|
-
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
2036
|
-
}
|
|
2037
|
-
datetime(options) {
|
|
2038
|
-
if (typeof options === "string") {
|
|
2039
|
-
return this._addCheck({
|
|
2040
|
-
kind: "datetime",
|
|
2041
|
-
precision: null,
|
|
2042
|
-
offset: false,
|
|
2043
|
-
local: false,
|
|
2044
|
-
message: options
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
return this._addCheck({
|
|
2048
|
-
kind: "datetime",
|
|
2049
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
2050
|
-
offset: options?.offset ?? false,
|
|
2051
|
-
local: options?.local ?? false,
|
|
2052
|
-
...errorUtil.errToObj(options?.message)
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
date(message) {
|
|
2056
|
-
return this._addCheck({ kind: "date", message });
|
|
2057
|
-
}
|
|
2058
|
-
time(options) {
|
|
2059
|
-
if (typeof options === "string") {
|
|
2060
|
-
return this._addCheck({
|
|
2061
|
-
kind: "time",
|
|
2062
|
-
precision: null,
|
|
2063
|
-
message: options
|
|
2064
|
-
});
|
|
2065
|
-
}
|
|
2066
|
-
return this._addCheck({
|
|
2067
|
-
kind: "time",
|
|
2068
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
2069
|
-
...errorUtil.errToObj(options?.message)
|
|
2070
|
-
});
|
|
2071
|
-
}
|
|
2072
|
-
duration(message) {
|
|
2073
|
-
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
2074
|
-
}
|
|
2075
|
-
regex(regex, message) {
|
|
2076
|
-
return this._addCheck({
|
|
2077
|
-
kind: "regex",
|
|
2078
|
-
regex,
|
|
2079
|
-
...errorUtil.errToObj(message)
|
|
2080
|
-
});
|
|
2081
|
-
}
|
|
2082
|
-
includes(value, options) {
|
|
2083
|
-
return this._addCheck({
|
|
2084
|
-
kind: "includes",
|
|
2085
|
-
value,
|
|
2086
|
-
position: options?.position,
|
|
2087
|
-
...errorUtil.errToObj(options?.message)
|
|
2088
|
-
});
|
|
2089
|
-
}
|
|
2090
|
-
startsWith(value, message) {
|
|
2091
|
-
return this._addCheck({
|
|
2092
|
-
kind: "startsWith",
|
|
2093
|
-
value,
|
|
2094
|
-
...errorUtil.errToObj(message)
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
endsWith(value, message) {
|
|
2098
|
-
return this._addCheck({
|
|
2099
|
-
kind: "endsWith",
|
|
2100
|
-
value,
|
|
2101
|
-
...errorUtil.errToObj(message)
|
|
2102
|
-
});
|
|
2103
|
-
}
|
|
2104
|
-
min(minLength, message) {
|
|
2105
|
-
return this._addCheck({
|
|
2106
|
-
kind: "min",
|
|
2107
|
-
value: minLength,
|
|
2108
|
-
...errorUtil.errToObj(message)
|
|
2109
|
-
});
|
|
2110
|
-
}
|
|
2111
|
-
max(maxLength, message) {
|
|
2112
|
-
return this._addCheck({
|
|
2113
|
-
kind: "max",
|
|
2114
|
-
value: maxLength,
|
|
2115
|
-
...errorUtil.errToObj(message)
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
length(len, message) {
|
|
2119
|
-
return this._addCheck({
|
|
2120
|
-
kind: "length",
|
|
2121
|
-
value: len,
|
|
2122
|
-
...errorUtil.errToObj(message)
|
|
2123
|
-
});
|
|
2124
|
-
}
|
|
2125
|
-
/**
|
|
2126
|
-
* Equivalent to `.min(1)`
|
|
2127
|
-
*/
|
|
2128
|
-
nonempty(message) {
|
|
2129
|
-
return this.min(1, errorUtil.errToObj(message));
|
|
2130
|
-
}
|
|
2131
|
-
trim() {
|
|
2132
|
-
return new _ZodString({
|
|
2133
|
-
...this._def,
|
|
2134
|
-
checks: [...this._def.checks, { kind: "trim" }]
|
|
2135
|
-
});
|
|
2136
|
-
}
|
|
2137
|
-
toLowerCase() {
|
|
2138
|
-
return new _ZodString({
|
|
2139
|
-
...this._def,
|
|
2140
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
2141
|
-
});
|
|
2142
|
-
}
|
|
2143
|
-
toUpperCase() {
|
|
2144
|
-
return new _ZodString({
|
|
2145
|
-
...this._def,
|
|
2146
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
2147
|
-
});
|
|
2148
|
-
}
|
|
2149
|
-
get isDatetime() {
|
|
2150
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
2151
|
-
}
|
|
2152
|
-
get isDate() {
|
|
2153
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
2154
|
-
}
|
|
2155
|
-
get isTime() {
|
|
2156
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
2157
|
-
}
|
|
2158
|
-
get isDuration() {
|
|
2159
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
2160
|
-
}
|
|
2161
|
-
get isEmail() {
|
|
2162
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
2163
|
-
}
|
|
2164
|
-
get isURL() {
|
|
2165
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
2166
|
-
}
|
|
2167
|
-
get isEmoji() {
|
|
2168
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
2169
|
-
}
|
|
2170
|
-
get isUUID() {
|
|
2171
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
2172
|
-
}
|
|
2173
|
-
get isNANOID() {
|
|
2174
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
2175
|
-
}
|
|
2176
|
-
get isCUID() {
|
|
2177
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
2178
|
-
}
|
|
2179
|
-
get isCUID2() {
|
|
2180
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
2181
|
-
}
|
|
2182
|
-
get isULID() {
|
|
2183
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
2184
|
-
}
|
|
2185
|
-
get isIP() {
|
|
2186
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
2187
|
-
}
|
|
2188
|
-
get isCIDR() {
|
|
2189
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
2190
|
-
}
|
|
2191
|
-
get isBase64() {
|
|
2192
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
2193
|
-
}
|
|
2194
|
-
get isBase64url() {
|
|
2195
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
2196
|
-
}
|
|
2197
|
-
get minLength() {
|
|
2198
|
-
let min = null;
|
|
2199
|
-
for (const ch of this._def.checks) {
|
|
2200
|
-
if (ch.kind === "min") {
|
|
2201
|
-
if (min === null || ch.value > min)
|
|
2202
|
-
min = ch.value;
|
|
2203
|
-
}
|
|
2204
|
-
}
|
|
2205
|
-
return min;
|
|
2206
|
-
}
|
|
2207
|
-
get maxLength() {
|
|
2208
|
-
let max = null;
|
|
2209
|
-
for (const ch of this._def.checks) {
|
|
2210
|
-
if (ch.kind === "max") {
|
|
2211
|
-
if (max === null || ch.value < max)
|
|
2212
|
-
max = ch.value;
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
return max;
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
ZodString.create = (params) => {
|
|
2219
|
-
return new ZodString({
|
|
2220
|
-
checks: [],
|
|
2221
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
2222
|
-
coerce: params?.coerce ?? false,
|
|
2223
|
-
...processCreateParams(params)
|
|
2224
|
-
});
|
|
2225
|
-
};
|
|
2226
|
-
function floatSafeRemainder(val, step) {
|
|
2227
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
2228
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
2229
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
2230
|
-
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
2231
|
-
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
2232
|
-
return valInt % stepInt / 10 ** decCount;
|
|
2233
|
-
}
|
|
2234
|
-
var ZodNumber = class _ZodNumber extends ZodType {
|
|
2235
|
-
constructor() {
|
|
2236
|
-
super(...arguments);
|
|
2237
|
-
this.min = this.gte;
|
|
2238
|
-
this.max = this.lte;
|
|
2239
|
-
this.step = this.multipleOf;
|
|
2240
|
-
}
|
|
2241
|
-
_parse(input) {
|
|
2242
|
-
if (this._def.coerce) {
|
|
2243
|
-
input.data = Number(input.data);
|
|
2244
|
-
}
|
|
2245
|
-
const parsedType = this._getType(input);
|
|
2246
|
-
if (parsedType !== ZodParsedType.number) {
|
|
2247
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2248
|
-
addIssueToContext(ctx2, {
|
|
2249
|
-
code: ZodIssueCode.invalid_type,
|
|
2250
|
-
expected: ZodParsedType.number,
|
|
2251
|
-
received: ctx2.parsedType
|
|
2252
|
-
});
|
|
2253
|
-
return INVALID;
|
|
2254
|
-
}
|
|
2255
|
-
let ctx = void 0;
|
|
2256
|
-
const status = new ParseStatus();
|
|
2257
|
-
for (const check of this._def.checks) {
|
|
2258
|
-
if (check.kind === "int") {
|
|
2259
|
-
if (!util.isInteger(input.data)) {
|
|
2260
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2261
|
-
addIssueToContext(ctx, {
|
|
2262
|
-
code: ZodIssueCode.invalid_type,
|
|
2263
|
-
expected: "integer",
|
|
2264
|
-
received: "float",
|
|
2265
|
-
message: check.message
|
|
2266
|
-
});
|
|
2267
|
-
status.dirty();
|
|
2268
|
-
}
|
|
2269
|
-
} else if (check.kind === "min") {
|
|
2270
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2271
|
-
if (tooSmall) {
|
|
2272
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2273
|
-
addIssueToContext(ctx, {
|
|
2274
|
-
code: ZodIssueCode.too_small,
|
|
2275
|
-
minimum: check.value,
|
|
2276
|
-
type: "number",
|
|
2277
|
-
inclusive: check.inclusive,
|
|
2278
|
-
exact: false,
|
|
2279
|
-
message: check.message
|
|
2280
|
-
});
|
|
2281
|
-
status.dirty();
|
|
2282
|
-
}
|
|
2283
|
-
} else if (check.kind === "max") {
|
|
2284
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2285
|
-
if (tooBig) {
|
|
2286
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2287
|
-
addIssueToContext(ctx, {
|
|
2288
|
-
code: ZodIssueCode.too_big,
|
|
2289
|
-
maximum: check.value,
|
|
2290
|
-
type: "number",
|
|
2291
|
-
inclusive: check.inclusive,
|
|
2292
|
-
exact: false,
|
|
2293
|
-
message: check.message
|
|
2294
|
-
});
|
|
2295
|
-
status.dirty();
|
|
2296
|
-
}
|
|
2297
|
-
} else if (check.kind === "multipleOf") {
|
|
2298
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
2299
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2300
|
-
addIssueToContext(ctx, {
|
|
2301
|
-
code: ZodIssueCode.not_multiple_of,
|
|
2302
|
-
multipleOf: check.value,
|
|
2303
|
-
message: check.message
|
|
2304
|
-
});
|
|
2305
|
-
status.dirty();
|
|
2306
|
-
}
|
|
2307
|
-
} else if (check.kind === "finite") {
|
|
2308
|
-
if (!Number.isFinite(input.data)) {
|
|
2309
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2310
|
-
addIssueToContext(ctx, {
|
|
2311
|
-
code: ZodIssueCode.not_finite,
|
|
2312
|
-
message: check.message
|
|
2313
|
-
});
|
|
2314
|
-
status.dirty();
|
|
2315
|
-
}
|
|
2316
|
-
} else {
|
|
2317
|
-
util.assertNever(check);
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
return { status: status.value, value: input.data };
|
|
2321
|
-
}
|
|
2322
|
-
gte(value, message) {
|
|
2323
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2324
|
-
}
|
|
2325
|
-
gt(value, message) {
|
|
2326
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2327
|
-
}
|
|
2328
|
-
lte(value, message) {
|
|
2329
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2330
|
-
}
|
|
2331
|
-
lt(value, message) {
|
|
2332
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2333
|
-
}
|
|
2334
|
-
setLimit(kind, value, inclusive, message) {
|
|
2335
|
-
return new _ZodNumber({
|
|
2336
|
-
...this._def,
|
|
2337
|
-
checks: [
|
|
2338
|
-
...this._def.checks,
|
|
2339
|
-
{
|
|
2340
|
-
kind,
|
|
2341
|
-
value,
|
|
2342
|
-
inclusive,
|
|
2343
|
-
message: errorUtil.toString(message)
|
|
2344
|
-
}
|
|
2345
|
-
]
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
_addCheck(check) {
|
|
2349
|
-
return new _ZodNumber({
|
|
2350
|
-
...this._def,
|
|
2351
|
-
checks: [...this._def.checks, check]
|
|
2352
|
-
});
|
|
2353
|
-
}
|
|
2354
|
-
int(message) {
|
|
2355
|
-
return this._addCheck({
|
|
2356
|
-
kind: "int",
|
|
2357
|
-
message: errorUtil.toString(message)
|
|
2358
|
-
});
|
|
2359
|
-
}
|
|
2360
|
-
positive(message) {
|
|
2361
|
-
return this._addCheck({
|
|
2362
|
-
kind: "min",
|
|
2363
|
-
value: 0,
|
|
2364
|
-
inclusive: false,
|
|
2365
|
-
message: errorUtil.toString(message)
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
|
-
negative(message) {
|
|
2369
|
-
return this._addCheck({
|
|
2370
|
-
kind: "max",
|
|
2371
|
-
value: 0,
|
|
2372
|
-
inclusive: false,
|
|
2373
|
-
message: errorUtil.toString(message)
|
|
2374
|
-
});
|
|
2375
|
-
}
|
|
2376
|
-
nonpositive(message) {
|
|
2377
|
-
return this._addCheck({
|
|
2378
|
-
kind: "max",
|
|
2379
|
-
value: 0,
|
|
2380
|
-
inclusive: true,
|
|
2381
|
-
message: errorUtil.toString(message)
|
|
2382
|
-
});
|
|
2383
|
-
}
|
|
2384
|
-
nonnegative(message) {
|
|
2385
|
-
return this._addCheck({
|
|
2386
|
-
kind: "min",
|
|
2387
|
-
value: 0,
|
|
2388
|
-
inclusive: true,
|
|
2389
|
-
message: errorUtil.toString(message)
|
|
2390
|
-
});
|
|
2391
|
-
}
|
|
2392
|
-
multipleOf(value, message) {
|
|
2393
|
-
return this._addCheck({
|
|
2394
|
-
kind: "multipleOf",
|
|
2395
|
-
value,
|
|
2396
|
-
message: errorUtil.toString(message)
|
|
2397
|
-
});
|
|
2398
|
-
}
|
|
2399
|
-
finite(message) {
|
|
2400
|
-
return this._addCheck({
|
|
2401
|
-
kind: "finite",
|
|
2402
|
-
message: errorUtil.toString(message)
|
|
2403
|
-
});
|
|
2404
|
-
}
|
|
2405
|
-
safe(message) {
|
|
2406
|
-
return this._addCheck({
|
|
2407
|
-
kind: "min",
|
|
2408
|
-
inclusive: true,
|
|
2409
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
2410
|
-
message: errorUtil.toString(message)
|
|
2411
|
-
})._addCheck({
|
|
2412
|
-
kind: "max",
|
|
2413
|
-
inclusive: true,
|
|
2414
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
2415
|
-
message: errorUtil.toString(message)
|
|
2416
|
-
});
|
|
2417
|
-
}
|
|
2418
|
-
get minValue() {
|
|
2419
|
-
let min = null;
|
|
2420
|
-
for (const ch of this._def.checks) {
|
|
2421
|
-
if (ch.kind === "min") {
|
|
2422
|
-
if (min === null || ch.value > min)
|
|
2423
|
-
min = ch.value;
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
return min;
|
|
2427
|
-
}
|
|
2428
|
-
get maxValue() {
|
|
2429
|
-
let max = null;
|
|
2430
|
-
for (const ch of this._def.checks) {
|
|
2431
|
-
if (ch.kind === "max") {
|
|
2432
|
-
if (max === null || ch.value < max)
|
|
2433
|
-
max = ch.value;
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
return max;
|
|
2437
|
-
}
|
|
2438
|
-
get isInt() {
|
|
2439
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
2440
|
-
}
|
|
2441
|
-
get isFinite() {
|
|
2442
|
-
let max = null;
|
|
2443
|
-
let min = null;
|
|
2444
|
-
for (const ch of this._def.checks) {
|
|
2445
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
2446
|
-
return true;
|
|
2447
|
-
} else if (ch.kind === "min") {
|
|
2448
|
-
if (min === null || ch.value > min)
|
|
2449
|
-
min = ch.value;
|
|
2450
|
-
} else if (ch.kind === "max") {
|
|
2451
|
-
if (max === null || ch.value < max)
|
|
2452
|
-
max = ch.value;
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2455
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
2456
|
-
}
|
|
2457
|
-
};
|
|
2458
|
-
ZodNumber.create = (params) => {
|
|
2459
|
-
return new ZodNumber({
|
|
2460
|
-
checks: [],
|
|
2461
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2462
|
-
coerce: params?.coerce || false,
|
|
2463
|
-
...processCreateParams(params)
|
|
2464
|
-
});
|
|
2465
|
-
};
|
|
2466
|
-
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
2467
|
-
constructor() {
|
|
2468
|
-
super(...arguments);
|
|
2469
|
-
this.min = this.gte;
|
|
2470
|
-
this.max = this.lte;
|
|
2471
|
-
}
|
|
2472
|
-
_parse(input) {
|
|
2473
|
-
if (this._def.coerce) {
|
|
2474
|
-
try {
|
|
2475
|
-
input.data = BigInt(input.data);
|
|
2476
|
-
} catch {
|
|
2477
|
-
return this._getInvalidInput(input);
|
|
2478
|
-
}
|
|
2479
|
-
}
|
|
2480
|
-
const parsedType = this._getType(input);
|
|
2481
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
2482
|
-
return this._getInvalidInput(input);
|
|
2483
|
-
}
|
|
2484
|
-
let ctx = void 0;
|
|
2485
|
-
const status = new ParseStatus();
|
|
2486
|
-
for (const check of this._def.checks) {
|
|
2487
|
-
if (check.kind === "min") {
|
|
2488
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2489
|
-
if (tooSmall) {
|
|
2490
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2491
|
-
addIssueToContext(ctx, {
|
|
2492
|
-
code: ZodIssueCode.too_small,
|
|
2493
|
-
type: "bigint",
|
|
2494
|
-
minimum: check.value,
|
|
2495
|
-
inclusive: check.inclusive,
|
|
2496
|
-
message: check.message
|
|
2497
|
-
});
|
|
2498
|
-
status.dirty();
|
|
2499
|
-
}
|
|
2500
|
-
} else if (check.kind === "max") {
|
|
2501
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2502
|
-
if (tooBig) {
|
|
2503
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2504
|
-
addIssueToContext(ctx, {
|
|
2505
|
-
code: ZodIssueCode.too_big,
|
|
2506
|
-
type: "bigint",
|
|
2507
|
-
maximum: check.value,
|
|
2508
|
-
inclusive: check.inclusive,
|
|
2509
|
-
message: check.message
|
|
2510
|
-
});
|
|
2511
|
-
status.dirty();
|
|
2512
|
-
}
|
|
2513
|
-
} else if (check.kind === "multipleOf") {
|
|
2514
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
2515
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2516
|
-
addIssueToContext(ctx, {
|
|
2517
|
-
code: ZodIssueCode.not_multiple_of,
|
|
2518
|
-
multipleOf: check.value,
|
|
2519
|
-
message: check.message
|
|
2520
|
-
});
|
|
2521
|
-
status.dirty();
|
|
2522
|
-
}
|
|
2523
|
-
} else {
|
|
2524
|
-
util.assertNever(check);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
return { status: status.value, value: input.data };
|
|
2528
|
-
}
|
|
2529
|
-
_getInvalidInput(input) {
|
|
2530
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2531
|
-
addIssueToContext(ctx, {
|
|
2532
|
-
code: ZodIssueCode.invalid_type,
|
|
2533
|
-
expected: ZodParsedType.bigint,
|
|
2534
|
-
received: ctx.parsedType
|
|
2535
|
-
});
|
|
2536
|
-
return INVALID;
|
|
2537
|
-
}
|
|
2538
|
-
gte(value, message) {
|
|
2539
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2540
|
-
}
|
|
2541
|
-
gt(value, message) {
|
|
2542
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2543
|
-
}
|
|
2544
|
-
lte(value, message) {
|
|
2545
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2546
|
-
}
|
|
2547
|
-
lt(value, message) {
|
|
2548
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2549
|
-
}
|
|
2550
|
-
setLimit(kind, value, inclusive, message) {
|
|
2551
|
-
return new _ZodBigInt({
|
|
2552
|
-
...this._def,
|
|
2553
|
-
checks: [
|
|
2554
|
-
...this._def.checks,
|
|
2555
|
-
{
|
|
2556
|
-
kind,
|
|
2557
|
-
value,
|
|
2558
|
-
inclusive,
|
|
2559
|
-
message: errorUtil.toString(message)
|
|
2560
|
-
}
|
|
2561
|
-
]
|
|
2562
|
-
});
|
|
2563
|
-
}
|
|
2564
|
-
_addCheck(check) {
|
|
2565
|
-
return new _ZodBigInt({
|
|
2566
|
-
...this._def,
|
|
2567
|
-
checks: [...this._def.checks, check]
|
|
2568
|
-
});
|
|
2569
|
-
}
|
|
2570
|
-
positive(message) {
|
|
2571
|
-
return this._addCheck({
|
|
2572
|
-
kind: "min",
|
|
2573
|
-
value: BigInt(0),
|
|
2574
|
-
inclusive: false,
|
|
2575
|
-
message: errorUtil.toString(message)
|
|
2576
|
-
});
|
|
2577
|
-
}
|
|
2578
|
-
negative(message) {
|
|
2579
|
-
return this._addCheck({
|
|
2580
|
-
kind: "max",
|
|
2581
|
-
value: BigInt(0),
|
|
2582
|
-
inclusive: false,
|
|
2583
|
-
message: errorUtil.toString(message)
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
nonpositive(message) {
|
|
2587
|
-
return this._addCheck({
|
|
2588
|
-
kind: "max",
|
|
2589
|
-
value: BigInt(0),
|
|
2590
|
-
inclusive: true,
|
|
2591
|
-
message: errorUtil.toString(message)
|
|
2592
|
-
});
|
|
2593
|
-
}
|
|
2594
|
-
nonnegative(message) {
|
|
2595
|
-
return this._addCheck({
|
|
2596
|
-
kind: "min",
|
|
2597
|
-
value: BigInt(0),
|
|
2598
|
-
inclusive: true,
|
|
2599
|
-
message: errorUtil.toString(message)
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
multipleOf(value, message) {
|
|
2603
|
-
return this._addCheck({
|
|
2604
|
-
kind: "multipleOf",
|
|
2605
|
-
value,
|
|
2606
|
-
message: errorUtil.toString(message)
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2609
|
-
get minValue() {
|
|
2610
|
-
let min = null;
|
|
2611
|
-
for (const ch of this._def.checks) {
|
|
2612
|
-
if (ch.kind === "min") {
|
|
2613
|
-
if (min === null || ch.value > min)
|
|
2614
|
-
min = ch.value;
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
return min;
|
|
2618
|
-
}
|
|
2619
|
-
get maxValue() {
|
|
2620
|
-
let max = null;
|
|
2621
|
-
for (const ch of this._def.checks) {
|
|
2622
|
-
if (ch.kind === "max") {
|
|
2623
|
-
if (max === null || ch.value < max)
|
|
2624
|
-
max = ch.value;
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
return max;
|
|
2628
|
-
}
|
|
2629
|
-
};
|
|
2630
|
-
ZodBigInt.create = (params) => {
|
|
2631
|
-
return new ZodBigInt({
|
|
2632
|
-
checks: [],
|
|
2633
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2634
|
-
coerce: params?.coerce ?? false,
|
|
2635
|
-
...processCreateParams(params)
|
|
2636
|
-
});
|
|
2637
|
-
};
|
|
2638
|
-
var ZodBoolean = class extends ZodType {
|
|
2639
|
-
_parse(input) {
|
|
2640
|
-
if (this._def.coerce) {
|
|
2641
|
-
input.data = Boolean(input.data);
|
|
2642
|
-
}
|
|
2643
|
-
const parsedType = this._getType(input);
|
|
2644
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
2645
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2646
|
-
addIssueToContext(ctx, {
|
|
2647
|
-
code: ZodIssueCode.invalid_type,
|
|
2648
|
-
expected: ZodParsedType.boolean,
|
|
2649
|
-
received: ctx.parsedType
|
|
2650
|
-
});
|
|
2651
|
-
return INVALID;
|
|
2652
|
-
}
|
|
2653
|
-
return OK(input.data);
|
|
2654
|
-
}
|
|
2655
|
-
};
|
|
2656
|
-
ZodBoolean.create = (params) => {
|
|
2657
|
-
return new ZodBoolean({
|
|
2658
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2659
|
-
coerce: params?.coerce || false,
|
|
2660
|
-
...processCreateParams(params)
|
|
2661
|
-
});
|
|
2662
|
-
};
|
|
2663
|
-
var ZodDate = class _ZodDate extends ZodType {
|
|
2664
|
-
_parse(input) {
|
|
2665
|
-
if (this._def.coerce) {
|
|
2666
|
-
input.data = new Date(input.data);
|
|
2667
|
-
}
|
|
2668
|
-
const parsedType = this._getType(input);
|
|
2669
|
-
if (parsedType !== ZodParsedType.date) {
|
|
2670
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2671
|
-
addIssueToContext(ctx2, {
|
|
2672
|
-
code: ZodIssueCode.invalid_type,
|
|
2673
|
-
expected: ZodParsedType.date,
|
|
2674
|
-
received: ctx2.parsedType
|
|
2675
|
-
});
|
|
2676
|
-
return INVALID;
|
|
2677
|
-
}
|
|
2678
|
-
if (Number.isNaN(input.data.getTime())) {
|
|
2679
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
2680
|
-
addIssueToContext(ctx2, {
|
|
2681
|
-
code: ZodIssueCode.invalid_date
|
|
2682
|
-
});
|
|
2683
|
-
return INVALID;
|
|
2684
|
-
}
|
|
2685
|
-
const status = new ParseStatus();
|
|
2686
|
-
let ctx = void 0;
|
|
2687
|
-
for (const check of this._def.checks) {
|
|
2688
|
-
if (check.kind === "min") {
|
|
2689
|
-
if (input.data.getTime() < check.value) {
|
|
2690
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2691
|
-
addIssueToContext(ctx, {
|
|
2692
|
-
code: ZodIssueCode.too_small,
|
|
2693
|
-
message: check.message,
|
|
2694
|
-
inclusive: true,
|
|
2695
|
-
exact: false,
|
|
2696
|
-
minimum: check.value,
|
|
2697
|
-
type: "date"
|
|
2698
|
-
});
|
|
2699
|
-
status.dirty();
|
|
2700
|
-
}
|
|
2701
|
-
} else if (check.kind === "max") {
|
|
2702
|
-
if (input.data.getTime() > check.value) {
|
|
2703
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
2704
|
-
addIssueToContext(ctx, {
|
|
2705
|
-
code: ZodIssueCode.too_big,
|
|
2706
|
-
message: check.message,
|
|
2707
|
-
inclusive: true,
|
|
2708
|
-
exact: false,
|
|
2709
|
-
maximum: check.value,
|
|
2710
|
-
type: "date"
|
|
2711
|
-
});
|
|
2712
|
-
status.dirty();
|
|
2713
|
-
}
|
|
2714
|
-
} else {
|
|
2715
|
-
util.assertNever(check);
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
return {
|
|
2719
|
-
status: status.value,
|
|
2720
|
-
value: new Date(input.data.getTime())
|
|
2721
|
-
};
|
|
2722
|
-
}
|
|
2723
|
-
_addCheck(check) {
|
|
2724
|
-
return new _ZodDate({
|
|
2725
|
-
...this._def,
|
|
2726
|
-
checks: [...this._def.checks, check]
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
|
-
min(minDate, message) {
|
|
2730
|
-
return this._addCheck({
|
|
2731
|
-
kind: "min",
|
|
2732
|
-
value: minDate.getTime(),
|
|
2733
|
-
message: errorUtil.toString(message)
|
|
2734
|
-
});
|
|
2735
|
-
}
|
|
2736
|
-
max(maxDate, message) {
|
|
2737
|
-
return this._addCheck({
|
|
2738
|
-
kind: "max",
|
|
2739
|
-
value: maxDate.getTime(),
|
|
2740
|
-
message: errorUtil.toString(message)
|
|
2741
|
-
});
|
|
2742
|
-
}
|
|
2743
|
-
get minDate() {
|
|
2744
|
-
let min = null;
|
|
2745
|
-
for (const ch of this._def.checks) {
|
|
2746
|
-
if (ch.kind === "min") {
|
|
2747
|
-
if (min === null || ch.value > min)
|
|
2748
|
-
min = ch.value;
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
return min != null ? new Date(min) : null;
|
|
2752
|
-
}
|
|
2753
|
-
get maxDate() {
|
|
2754
|
-
let max = null;
|
|
2755
|
-
for (const ch of this._def.checks) {
|
|
2756
|
-
if (ch.kind === "max") {
|
|
2757
|
-
if (max === null || ch.value < max)
|
|
2758
|
-
max = ch.value;
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
return max != null ? new Date(max) : null;
|
|
2762
|
-
}
|
|
2763
|
-
};
|
|
2764
|
-
ZodDate.create = (params) => {
|
|
2765
|
-
return new ZodDate({
|
|
2766
|
-
checks: [],
|
|
2767
|
-
coerce: params?.coerce || false,
|
|
2768
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2769
|
-
...processCreateParams(params)
|
|
2770
|
-
});
|
|
2771
|
-
};
|
|
2772
|
-
var ZodSymbol = class extends ZodType {
|
|
2773
|
-
_parse(input) {
|
|
2774
|
-
const parsedType = this._getType(input);
|
|
2775
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
2776
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2777
|
-
addIssueToContext(ctx, {
|
|
2778
|
-
code: ZodIssueCode.invalid_type,
|
|
2779
|
-
expected: ZodParsedType.symbol,
|
|
2780
|
-
received: ctx.parsedType
|
|
2781
|
-
});
|
|
2782
|
-
return INVALID;
|
|
2783
|
-
}
|
|
2784
|
-
return OK(input.data);
|
|
2785
|
-
}
|
|
2786
|
-
};
|
|
2787
|
-
ZodSymbol.create = (params) => {
|
|
2788
|
-
return new ZodSymbol({
|
|
2789
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2790
|
-
...processCreateParams(params)
|
|
2791
|
-
});
|
|
2792
|
-
};
|
|
2793
|
-
var ZodUndefined = class extends ZodType {
|
|
2794
|
-
_parse(input) {
|
|
2795
|
-
const parsedType = this._getType(input);
|
|
2796
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2797
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2798
|
-
addIssueToContext(ctx, {
|
|
2799
|
-
code: ZodIssueCode.invalid_type,
|
|
2800
|
-
expected: ZodParsedType.undefined,
|
|
2801
|
-
received: ctx.parsedType
|
|
2802
|
-
});
|
|
2803
|
-
return INVALID;
|
|
2804
|
-
}
|
|
2805
|
-
return OK(input.data);
|
|
2806
|
-
}
|
|
2807
|
-
};
|
|
2808
|
-
ZodUndefined.create = (params) => {
|
|
2809
|
-
return new ZodUndefined({
|
|
2810
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2811
|
-
...processCreateParams(params)
|
|
2812
|
-
});
|
|
2813
|
-
};
|
|
2814
|
-
var ZodNull = class extends ZodType {
|
|
2815
|
-
_parse(input) {
|
|
2816
|
-
const parsedType = this._getType(input);
|
|
2817
|
-
if (parsedType !== ZodParsedType.null) {
|
|
2818
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2819
|
-
addIssueToContext(ctx, {
|
|
2820
|
-
code: ZodIssueCode.invalid_type,
|
|
2821
|
-
expected: ZodParsedType.null,
|
|
2822
|
-
received: ctx.parsedType
|
|
2823
|
-
});
|
|
2824
|
-
return INVALID;
|
|
2825
|
-
}
|
|
2826
|
-
return OK(input.data);
|
|
2827
|
-
}
|
|
2828
|
-
};
|
|
2829
|
-
ZodNull.create = (params) => {
|
|
2830
|
-
return new ZodNull({
|
|
2831
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2832
|
-
...processCreateParams(params)
|
|
2833
|
-
});
|
|
2834
|
-
};
|
|
2835
|
-
var ZodAny = class extends ZodType {
|
|
2836
|
-
constructor() {
|
|
2837
|
-
super(...arguments);
|
|
2838
|
-
this._any = true;
|
|
2839
|
-
}
|
|
2840
|
-
_parse(input) {
|
|
2841
|
-
return OK(input.data);
|
|
2842
|
-
}
|
|
2843
|
-
};
|
|
2844
|
-
ZodAny.create = (params) => {
|
|
2845
|
-
return new ZodAny({
|
|
2846
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2847
|
-
...processCreateParams(params)
|
|
2848
|
-
});
|
|
2849
|
-
};
|
|
2850
|
-
var ZodUnknown = class extends ZodType {
|
|
2851
|
-
constructor() {
|
|
2852
|
-
super(...arguments);
|
|
2853
|
-
this._unknown = true;
|
|
2854
|
-
}
|
|
2855
|
-
_parse(input) {
|
|
2856
|
-
return OK(input.data);
|
|
2857
|
-
}
|
|
2858
|
-
};
|
|
2859
|
-
ZodUnknown.create = (params) => {
|
|
2860
|
-
return new ZodUnknown({
|
|
2861
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2862
|
-
...processCreateParams(params)
|
|
2863
|
-
});
|
|
2864
|
-
};
|
|
2865
|
-
var ZodNever = class extends ZodType {
|
|
2866
|
-
_parse(input) {
|
|
2867
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2868
|
-
addIssueToContext(ctx, {
|
|
2869
|
-
code: ZodIssueCode.invalid_type,
|
|
2870
|
-
expected: ZodParsedType.never,
|
|
2871
|
-
received: ctx.parsedType
|
|
2872
|
-
});
|
|
2873
|
-
return INVALID;
|
|
2874
|
-
}
|
|
2875
|
-
};
|
|
2876
|
-
ZodNever.create = (params) => {
|
|
2877
|
-
return new ZodNever({
|
|
2878
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2879
|
-
...processCreateParams(params)
|
|
2880
|
-
});
|
|
2881
|
-
};
|
|
2882
|
-
var ZodVoid = class extends ZodType {
|
|
2883
|
-
_parse(input) {
|
|
2884
|
-
const parsedType = this._getType(input);
|
|
2885
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2886
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2887
|
-
addIssueToContext(ctx, {
|
|
2888
|
-
code: ZodIssueCode.invalid_type,
|
|
2889
|
-
expected: ZodParsedType.void,
|
|
2890
|
-
received: ctx.parsedType
|
|
2891
|
-
});
|
|
2892
|
-
return INVALID;
|
|
2893
|
-
}
|
|
2894
|
-
return OK(input.data);
|
|
2895
|
-
}
|
|
2896
|
-
};
|
|
2897
|
-
ZodVoid.create = (params) => {
|
|
2898
|
-
return new ZodVoid({
|
|
2899
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2900
|
-
...processCreateParams(params)
|
|
2901
|
-
});
|
|
2902
|
-
};
|
|
2903
|
-
var ZodArray = class _ZodArray extends ZodType {
|
|
2904
|
-
_parse(input) {
|
|
2905
|
-
const { ctx, status } = this._processInputParams(input);
|
|
2906
|
-
const def = this._def;
|
|
2907
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2908
|
-
addIssueToContext(ctx, {
|
|
2909
|
-
code: ZodIssueCode.invalid_type,
|
|
2910
|
-
expected: ZodParsedType.array,
|
|
2911
|
-
received: ctx.parsedType
|
|
2912
|
-
});
|
|
2913
|
-
return INVALID;
|
|
2914
|
-
}
|
|
2915
|
-
if (def.exactLength !== null) {
|
|
2916
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2917
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2918
|
-
if (tooBig || tooSmall) {
|
|
2919
|
-
addIssueToContext(ctx, {
|
|
2920
|
-
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2921
|
-
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2922
|
-
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2923
|
-
type: "array",
|
|
2924
|
-
inclusive: true,
|
|
2925
|
-
exact: true,
|
|
2926
|
-
message: def.exactLength.message
|
|
2927
|
-
});
|
|
2928
|
-
status.dirty();
|
|
2929
|
-
}
|
|
2930
|
-
}
|
|
2931
|
-
if (def.minLength !== null) {
|
|
2932
|
-
if (ctx.data.length < def.minLength.value) {
|
|
2933
|
-
addIssueToContext(ctx, {
|
|
2934
|
-
code: ZodIssueCode.too_small,
|
|
2935
|
-
minimum: def.minLength.value,
|
|
2936
|
-
type: "array",
|
|
2937
|
-
inclusive: true,
|
|
2938
|
-
exact: false,
|
|
2939
|
-
message: def.minLength.message
|
|
2940
|
-
});
|
|
2941
|
-
status.dirty();
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
if (def.maxLength !== null) {
|
|
2945
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
2946
|
-
addIssueToContext(ctx, {
|
|
2947
|
-
code: ZodIssueCode.too_big,
|
|
2948
|
-
maximum: def.maxLength.value,
|
|
2949
|
-
type: "array",
|
|
2950
|
-
inclusive: true,
|
|
2951
|
-
exact: false,
|
|
2952
|
-
message: def.maxLength.message
|
|
2953
|
-
});
|
|
2954
|
-
status.dirty();
|
|
2955
|
-
}
|
|
2956
|
-
}
|
|
2957
|
-
if (ctx.common.async) {
|
|
2958
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
|
2959
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2960
|
-
})).then((result2) => {
|
|
2961
|
-
return ParseStatus.mergeArray(status, result2);
|
|
2962
|
-
});
|
|
2963
|
-
}
|
|
2964
|
-
const result = [...ctx.data].map((item, i) => {
|
|
2965
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2966
|
-
});
|
|
2967
|
-
return ParseStatus.mergeArray(status, result);
|
|
2968
|
-
}
|
|
2969
|
-
get element() {
|
|
2970
|
-
return this._def.type;
|
|
2971
|
-
}
|
|
2972
|
-
min(minLength, message) {
|
|
2973
|
-
return new _ZodArray({
|
|
2974
|
-
...this._def,
|
|
2975
|
-
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2976
|
-
});
|
|
2977
|
-
}
|
|
2978
|
-
max(maxLength, message) {
|
|
2979
|
-
return new _ZodArray({
|
|
2980
|
-
...this._def,
|
|
2981
|
-
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2982
|
-
});
|
|
2983
|
-
}
|
|
2984
|
-
length(len, message) {
|
|
2985
|
-
return new _ZodArray({
|
|
2986
|
-
...this._def,
|
|
2987
|
-
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2988
|
-
});
|
|
2989
|
-
}
|
|
2990
|
-
nonempty(message) {
|
|
2991
|
-
return this.min(1, message);
|
|
2992
|
-
}
|
|
2993
|
-
};
|
|
2994
|
-
ZodArray.create = (schema, params) => {
|
|
2995
|
-
return new ZodArray({
|
|
2996
|
-
type: schema,
|
|
2997
|
-
minLength: null,
|
|
2998
|
-
maxLength: null,
|
|
2999
|
-
exactLength: null,
|
|
3000
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
3001
|
-
...processCreateParams(params)
|
|
3002
|
-
});
|
|
3003
|
-
};
|
|
3004
|
-
function deepPartialify(schema) {
|
|
3005
|
-
if (schema instanceof ZodObject) {
|
|
3006
|
-
const newShape = {};
|
|
3007
|
-
for (const key in schema.shape) {
|
|
3008
|
-
const fieldSchema = schema.shape[key];
|
|
3009
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
3010
|
-
}
|
|
3011
|
-
return new ZodObject({
|
|
3012
|
-
...schema._def,
|
|
3013
|
-
shape: () => newShape
|
|
3014
|
-
});
|
|
3015
|
-
} else if (schema instanceof ZodArray) {
|
|
3016
|
-
return new ZodArray({
|
|
3017
|
-
...schema._def,
|
|
3018
|
-
type: deepPartialify(schema.element)
|
|
3019
|
-
});
|
|
3020
|
-
} else if (schema instanceof ZodOptional) {
|
|
3021
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
3022
|
-
} else if (schema instanceof ZodNullable) {
|
|
3023
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
3024
|
-
} else if (schema instanceof ZodTuple) {
|
|
3025
|
-
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
3026
|
-
} else {
|
|
3027
|
-
return schema;
|
|
3028
|
-
}
|
|
3029
|
-
}
|
|
3030
|
-
var ZodObject = class _ZodObject extends ZodType {
|
|
3031
|
-
constructor() {
|
|
3032
|
-
super(...arguments);
|
|
3033
|
-
this._cached = null;
|
|
3034
|
-
this.nonstrict = this.passthrough;
|
|
3035
|
-
this.augment = this.extend;
|
|
3036
|
-
}
|
|
3037
|
-
_getCached() {
|
|
3038
|
-
if (this._cached !== null)
|
|
3039
|
-
return this._cached;
|
|
3040
|
-
const shape = this._def.shape();
|
|
3041
|
-
const keys = util.objectKeys(shape);
|
|
3042
|
-
this._cached = { shape, keys };
|
|
3043
|
-
return this._cached;
|
|
3044
|
-
}
|
|
3045
|
-
_parse(input) {
|
|
3046
|
-
const parsedType = this._getType(input);
|
|
3047
|
-
if (parsedType !== ZodParsedType.object) {
|
|
3048
|
-
const ctx2 = this._getOrReturnCtx(input);
|
|
3049
|
-
addIssueToContext(ctx2, {
|
|
3050
|
-
code: ZodIssueCode.invalid_type,
|
|
3051
|
-
expected: ZodParsedType.object,
|
|
3052
|
-
received: ctx2.parsedType
|
|
3053
|
-
});
|
|
3054
|
-
return INVALID;
|
|
3055
|
-
}
|
|
3056
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3057
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
|
3058
|
-
const extraKeys = [];
|
|
3059
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
3060
|
-
for (const key in ctx.data) {
|
|
3061
|
-
if (!shapeKeys.includes(key)) {
|
|
3062
|
-
extraKeys.push(key);
|
|
3063
|
-
}
|
|
3064
|
-
}
|
|
3065
|
-
}
|
|
3066
|
-
const pairs = [];
|
|
3067
|
-
for (const key of shapeKeys) {
|
|
3068
|
-
const keyValidator = shape[key];
|
|
3069
|
-
const value = ctx.data[key];
|
|
3070
|
-
pairs.push({
|
|
3071
|
-
key: { status: "valid", value: key },
|
|
3072
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
3073
|
-
alwaysSet: key in ctx.data
|
|
3074
|
-
});
|
|
3075
|
-
}
|
|
3076
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
3077
|
-
const unknownKeys = this._def.unknownKeys;
|
|
3078
|
-
if (unknownKeys === "passthrough") {
|
|
3079
|
-
for (const key of extraKeys) {
|
|
3080
|
-
pairs.push({
|
|
3081
|
-
key: { status: "valid", value: key },
|
|
3082
|
-
value: { status: "valid", value: ctx.data[key] }
|
|
3083
|
-
});
|
|
3084
|
-
}
|
|
3085
|
-
} else if (unknownKeys === "strict") {
|
|
3086
|
-
if (extraKeys.length > 0) {
|
|
3087
|
-
addIssueToContext(ctx, {
|
|
3088
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
3089
|
-
keys: extraKeys
|
|
3090
|
-
});
|
|
3091
|
-
status.dirty();
|
|
3092
|
-
}
|
|
3093
|
-
} else if (unknownKeys === "strip") {
|
|
3094
|
-
} else {
|
|
3095
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
3096
|
-
}
|
|
3097
|
-
} else {
|
|
3098
|
-
const catchall = this._def.catchall;
|
|
3099
|
-
for (const key of extraKeys) {
|
|
3100
|
-
const value = ctx.data[key];
|
|
3101
|
-
pairs.push({
|
|
3102
|
-
key: { status: "valid", value: key },
|
|
3103
|
-
value: catchall._parse(
|
|
3104
|
-
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
3105
|
-
//, ctx.child(key), value, getParsedType(value)
|
|
3106
|
-
),
|
|
3107
|
-
alwaysSet: key in ctx.data
|
|
3108
|
-
});
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
if (ctx.common.async) {
|
|
3112
|
-
return Promise.resolve().then(async () => {
|
|
3113
|
-
const syncPairs = [];
|
|
3114
|
-
for (const pair of pairs) {
|
|
3115
|
-
const key = await pair.key;
|
|
3116
|
-
const value = await pair.value;
|
|
3117
|
-
syncPairs.push({
|
|
3118
|
-
key,
|
|
3119
|
-
value,
|
|
3120
|
-
alwaysSet: pair.alwaysSet
|
|
3121
|
-
});
|
|
3122
|
-
}
|
|
3123
|
-
return syncPairs;
|
|
3124
|
-
}).then((syncPairs) => {
|
|
3125
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
3126
|
-
});
|
|
3127
|
-
} else {
|
|
3128
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3129
|
-
}
|
|
3130
|
-
}
|
|
3131
|
-
get shape() {
|
|
3132
|
-
return this._def.shape();
|
|
3133
|
-
}
|
|
3134
|
-
strict(message) {
|
|
3135
|
-
errorUtil.errToObj;
|
|
3136
|
-
return new _ZodObject({
|
|
3137
|
-
...this._def,
|
|
3138
|
-
unknownKeys: "strict",
|
|
3139
|
-
...message !== void 0 ? {
|
|
3140
|
-
errorMap: (issue, ctx) => {
|
|
3141
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
3142
|
-
if (issue.code === "unrecognized_keys")
|
|
3143
|
-
return {
|
|
3144
|
-
message: errorUtil.errToObj(message).message ?? defaultError
|
|
3145
|
-
};
|
|
3146
|
-
return {
|
|
3147
|
-
message: defaultError
|
|
3148
|
-
};
|
|
3149
|
-
}
|
|
3150
|
-
} : {}
|
|
3151
|
-
});
|
|
3152
|
-
}
|
|
3153
|
-
strip() {
|
|
3154
|
-
return new _ZodObject({
|
|
3155
|
-
...this._def,
|
|
3156
|
-
unknownKeys: "strip"
|
|
3157
|
-
});
|
|
3158
|
-
}
|
|
3159
|
-
passthrough() {
|
|
3160
|
-
return new _ZodObject({
|
|
3161
|
-
...this._def,
|
|
3162
|
-
unknownKeys: "passthrough"
|
|
3163
|
-
});
|
|
3164
|
-
}
|
|
3165
|
-
// const AugmentFactory =
|
|
3166
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
3167
|
-
// <Augmentation extends ZodRawShape>(
|
|
3168
|
-
// augmentation: Augmentation
|
|
3169
|
-
// ): ZodObject<
|
|
3170
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
3171
|
-
// Def["unknownKeys"],
|
|
3172
|
-
// Def["catchall"]
|
|
3173
|
-
// > => {
|
|
3174
|
-
// return new ZodObject({
|
|
3175
|
-
// ...def,
|
|
3176
|
-
// shape: () => ({
|
|
3177
|
-
// ...def.shape(),
|
|
3178
|
-
// ...augmentation,
|
|
3179
|
-
// }),
|
|
3180
|
-
// }) as any;
|
|
3181
|
-
// };
|
|
3182
|
-
extend(augmentation) {
|
|
3183
|
-
return new _ZodObject({
|
|
3184
|
-
...this._def,
|
|
3185
|
-
shape: () => ({
|
|
3186
|
-
...this._def.shape(),
|
|
3187
|
-
...augmentation
|
|
3188
|
-
})
|
|
3189
|
-
});
|
|
3190
|
-
}
|
|
3191
|
-
/**
|
|
3192
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
3193
|
-
* inferred type of merged objects. Please
|
|
3194
|
-
* upgrade if you are experiencing issues.
|
|
3195
|
-
*/
|
|
3196
|
-
merge(merging) {
|
|
3197
|
-
const merged = new _ZodObject({
|
|
3198
|
-
unknownKeys: merging._def.unknownKeys,
|
|
3199
|
-
catchall: merging._def.catchall,
|
|
3200
|
-
shape: () => ({
|
|
3201
|
-
...this._def.shape(),
|
|
3202
|
-
...merging._def.shape()
|
|
3203
|
-
}),
|
|
3204
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
3205
|
-
});
|
|
3206
|
-
return merged;
|
|
3207
|
-
}
|
|
3208
|
-
// merge<
|
|
3209
|
-
// Incoming extends AnyZodObject,
|
|
3210
|
-
// Augmentation extends Incoming["shape"],
|
|
3211
|
-
// NewOutput extends {
|
|
3212
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
3213
|
-
// ? Augmentation[k]["_output"]
|
|
3214
|
-
// : k extends keyof Output
|
|
3215
|
-
// ? Output[k]
|
|
3216
|
-
// : never;
|
|
3217
|
-
// },
|
|
3218
|
-
// NewInput extends {
|
|
3219
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
3220
|
-
// ? Augmentation[k]["_input"]
|
|
3221
|
-
// : k extends keyof Input
|
|
3222
|
-
// ? Input[k]
|
|
3223
|
-
// : never;
|
|
3224
|
-
// }
|
|
3225
|
-
// >(
|
|
3226
|
-
// merging: Incoming
|
|
3227
|
-
// ): ZodObject<
|
|
3228
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3229
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3230
|
-
// Incoming["_def"]["catchall"],
|
|
3231
|
-
// NewOutput,
|
|
3232
|
-
// NewInput
|
|
3233
|
-
// > {
|
|
3234
|
-
// const merged: any = new ZodObject({
|
|
3235
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3236
|
-
// catchall: merging._def.catchall,
|
|
3237
|
-
// shape: () =>
|
|
3238
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3239
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3240
|
-
// }) as any;
|
|
3241
|
-
// return merged;
|
|
3242
|
-
// }
|
|
3243
|
-
setKey(key, schema) {
|
|
3244
|
-
return this.augment({ [key]: schema });
|
|
3245
|
-
}
|
|
3246
|
-
// merge<Incoming extends AnyZodObject>(
|
|
3247
|
-
// merging: Incoming
|
|
3248
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
3249
|
-
// ZodObject<
|
|
3250
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
3251
|
-
// Incoming["_def"]["unknownKeys"],
|
|
3252
|
-
// Incoming["_def"]["catchall"]
|
|
3253
|
-
// > {
|
|
3254
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
3255
|
-
// // this._def.shape(),
|
|
3256
|
-
// // merging._def.shape()
|
|
3257
|
-
// // );
|
|
3258
|
-
// const merged: any = new ZodObject({
|
|
3259
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
3260
|
-
// catchall: merging._def.catchall,
|
|
3261
|
-
// shape: () =>
|
|
3262
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
3263
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3264
|
-
// }) as any;
|
|
3265
|
-
// return merged;
|
|
3266
|
-
// }
|
|
3267
|
-
catchall(index) {
|
|
3268
|
-
return new _ZodObject({
|
|
3269
|
-
...this._def,
|
|
3270
|
-
catchall: index
|
|
3271
|
-
});
|
|
3272
|
-
}
|
|
3273
|
-
pick(mask) {
|
|
3274
|
-
const shape = {};
|
|
3275
|
-
for (const key of util.objectKeys(mask)) {
|
|
3276
|
-
if (mask[key] && this.shape[key]) {
|
|
3277
|
-
shape[key] = this.shape[key];
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
return new _ZodObject({
|
|
3281
|
-
...this._def,
|
|
3282
|
-
shape: () => shape
|
|
3283
|
-
});
|
|
3284
|
-
}
|
|
3285
|
-
omit(mask) {
|
|
3286
|
-
const shape = {};
|
|
3287
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3288
|
-
if (!mask[key]) {
|
|
3289
|
-
shape[key] = this.shape[key];
|
|
3290
|
-
}
|
|
3291
|
-
}
|
|
3292
|
-
return new _ZodObject({
|
|
3293
|
-
...this._def,
|
|
3294
|
-
shape: () => shape
|
|
3295
|
-
});
|
|
3296
|
-
}
|
|
3297
|
-
/**
|
|
3298
|
-
* @deprecated
|
|
3299
|
-
*/
|
|
3300
|
-
deepPartial() {
|
|
3301
|
-
return deepPartialify(this);
|
|
3302
|
-
}
|
|
3303
|
-
partial(mask) {
|
|
3304
|
-
const newShape = {};
|
|
3305
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3306
|
-
const fieldSchema = this.shape[key];
|
|
3307
|
-
if (mask && !mask[key]) {
|
|
3308
|
-
newShape[key] = fieldSchema;
|
|
3309
|
-
} else {
|
|
3310
|
-
newShape[key] = fieldSchema.optional();
|
|
3311
|
-
}
|
|
3312
|
-
}
|
|
3313
|
-
return new _ZodObject({
|
|
3314
|
-
...this._def,
|
|
3315
|
-
shape: () => newShape
|
|
3316
|
-
});
|
|
3317
|
-
}
|
|
3318
|
-
required(mask) {
|
|
3319
|
-
const newShape = {};
|
|
3320
|
-
for (const key of util.objectKeys(this.shape)) {
|
|
3321
|
-
if (mask && !mask[key]) {
|
|
3322
|
-
newShape[key] = this.shape[key];
|
|
3323
|
-
} else {
|
|
3324
|
-
const fieldSchema = this.shape[key];
|
|
3325
|
-
let newField = fieldSchema;
|
|
3326
|
-
while (newField instanceof ZodOptional) {
|
|
3327
|
-
newField = newField._def.innerType;
|
|
3328
|
-
}
|
|
3329
|
-
newShape[key] = newField;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
return new _ZodObject({
|
|
3333
|
-
...this._def,
|
|
3334
|
-
shape: () => newShape
|
|
3335
|
-
});
|
|
3336
|
-
}
|
|
3337
|
-
keyof() {
|
|
3338
|
-
return createZodEnum(util.objectKeys(this.shape));
|
|
3339
|
-
}
|
|
3340
|
-
};
|
|
3341
|
-
ZodObject.create = (shape, params) => {
|
|
3342
|
-
return new ZodObject({
|
|
3343
|
-
shape: () => shape,
|
|
3344
|
-
unknownKeys: "strip",
|
|
3345
|
-
catchall: ZodNever.create(),
|
|
3346
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3347
|
-
...processCreateParams(params)
|
|
3348
|
-
});
|
|
3349
|
-
};
|
|
3350
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
3351
|
-
return new ZodObject({
|
|
3352
|
-
shape: () => shape,
|
|
3353
|
-
unknownKeys: "strict",
|
|
3354
|
-
catchall: ZodNever.create(),
|
|
3355
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3356
|
-
...processCreateParams(params)
|
|
3357
|
-
});
|
|
3358
|
-
};
|
|
3359
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
3360
|
-
return new ZodObject({
|
|
3361
|
-
shape,
|
|
3362
|
-
unknownKeys: "strip",
|
|
3363
|
-
catchall: ZodNever.create(),
|
|
3364
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3365
|
-
...processCreateParams(params)
|
|
3366
|
-
});
|
|
3367
|
-
};
|
|
3368
|
-
var ZodUnion = class extends ZodType {
|
|
3369
|
-
_parse(input) {
|
|
3370
|
-
const { ctx } = this._processInputParams(input);
|
|
3371
|
-
const options = this._def.options;
|
|
3372
|
-
function handleResults(results) {
|
|
3373
|
-
for (const result of results) {
|
|
3374
|
-
if (result.result.status === "valid") {
|
|
3375
|
-
return result.result;
|
|
3376
|
-
}
|
|
3377
|
-
}
|
|
3378
|
-
for (const result of results) {
|
|
3379
|
-
if (result.result.status === "dirty") {
|
|
3380
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
3381
|
-
return result.result;
|
|
3382
|
-
}
|
|
3383
|
-
}
|
|
3384
|
-
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
3385
|
-
addIssueToContext(ctx, {
|
|
3386
|
-
code: ZodIssueCode.invalid_union,
|
|
3387
|
-
unionErrors
|
|
3388
|
-
});
|
|
3389
|
-
return INVALID;
|
|
3390
|
-
}
|
|
3391
|
-
if (ctx.common.async) {
|
|
3392
|
-
return Promise.all(options.map(async (option) => {
|
|
3393
|
-
const childCtx = {
|
|
3394
|
-
...ctx,
|
|
3395
|
-
common: {
|
|
3396
|
-
...ctx.common,
|
|
3397
|
-
issues: []
|
|
3398
|
-
},
|
|
3399
|
-
parent: null
|
|
3400
|
-
};
|
|
3401
|
-
return {
|
|
3402
|
-
result: await option._parseAsync({
|
|
3403
|
-
data: ctx.data,
|
|
3404
|
-
path: ctx.path,
|
|
3405
|
-
parent: childCtx
|
|
3406
|
-
}),
|
|
3407
|
-
ctx: childCtx
|
|
3408
|
-
};
|
|
3409
|
-
})).then(handleResults);
|
|
3410
|
-
} else {
|
|
3411
|
-
let dirty = void 0;
|
|
3412
|
-
const issues = [];
|
|
3413
|
-
for (const option of options) {
|
|
3414
|
-
const childCtx = {
|
|
3415
|
-
...ctx,
|
|
3416
|
-
common: {
|
|
3417
|
-
...ctx.common,
|
|
3418
|
-
issues: []
|
|
3419
|
-
},
|
|
3420
|
-
parent: null
|
|
3421
|
-
};
|
|
3422
|
-
const result = option._parseSync({
|
|
3423
|
-
data: ctx.data,
|
|
3424
|
-
path: ctx.path,
|
|
3425
|
-
parent: childCtx
|
|
3426
|
-
});
|
|
3427
|
-
if (result.status === "valid") {
|
|
3428
|
-
return result;
|
|
3429
|
-
} else if (result.status === "dirty" && !dirty) {
|
|
3430
|
-
dirty = { result, ctx: childCtx };
|
|
3431
|
-
}
|
|
3432
|
-
if (childCtx.common.issues.length) {
|
|
3433
|
-
issues.push(childCtx.common.issues);
|
|
3434
|
-
}
|
|
3435
|
-
}
|
|
3436
|
-
if (dirty) {
|
|
3437
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
3438
|
-
return dirty.result;
|
|
3439
|
-
}
|
|
3440
|
-
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
3441
|
-
addIssueToContext(ctx, {
|
|
3442
|
-
code: ZodIssueCode.invalid_union,
|
|
3443
|
-
unionErrors
|
|
3444
|
-
});
|
|
3445
|
-
return INVALID;
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
get options() {
|
|
3449
|
-
return this._def.options;
|
|
3450
|
-
}
|
|
3451
|
-
};
|
|
3452
|
-
ZodUnion.create = (types, params) => {
|
|
3453
|
-
return new ZodUnion({
|
|
3454
|
-
options: types,
|
|
3455
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
3456
|
-
...processCreateParams(params)
|
|
3457
|
-
});
|
|
3458
|
-
};
|
|
3459
|
-
var getDiscriminator = (type) => {
|
|
3460
|
-
if (type instanceof ZodLazy) {
|
|
3461
|
-
return getDiscriminator(type.schema);
|
|
3462
|
-
} else if (type instanceof ZodEffects) {
|
|
3463
|
-
return getDiscriminator(type.innerType());
|
|
3464
|
-
} else if (type instanceof ZodLiteral) {
|
|
3465
|
-
return [type.value];
|
|
3466
|
-
} else if (type instanceof ZodEnum) {
|
|
3467
|
-
return type.options;
|
|
3468
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
3469
|
-
return util.objectValues(type.enum);
|
|
3470
|
-
} else if (type instanceof ZodDefault) {
|
|
3471
|
-
return getDiscriminator(type._def.innerType);
|
|
3472
|
-
} else if (type instanceof ZodUndefined) {
|
|
3473
|
-
return [void 0];
|
|
3474
|
-
} else if (type instanceof ZodNull) {
|
|
3475
|
-
return [null];
|
|
3476
|
-
} else if (type instanceof ZodOptional) {
|
|
3477
|
-
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
3478
|
-
} else if (type instanceof ZodNullable) {
|
|
3479
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
|
3480
|
-
} else if (type instanceof ZodBranded) {
|
|
3481
|
-
return getDiscriminator(type.unwrap());
|
|
3482
|
-
} else if (type instanceof ZodReadonly) {
|
|
3483
|
-
return getDiscriminator(type.unwrap());
|
|
3484
|
-
} else if (type instanceof ZodCatch) {
|
|
3485
|
-
return getDiscriminator(type._def.innerType);
|
|
3486
|
-
} else {
|
|
3487
|
-
return [];
|
|
3488
|
-
}
|
|
3489
|
-
};
|
|
3490
|
-
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3491
|
-
_parse(input) {
|
|
3492
|
-
const { ctx } = this._processInputParams(input);
|
|
3493
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3494
|
-
addIssueToContext(ctx, {
|
|
3495
|
-
code: ZodIssueCode.invalid_type,
|
|
3496
|
-
expected: ZodParsedType.object,
|
|
3497
|
-
received: ctx.parsedType
|
|
3498
|
-
});
|
|
3499
|
-
return INVALID;
|
|
3500
|
-
}
|
|
3501
|
-
const discriminator = this.discriminator;
|
|
3502
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
3503
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
3504
|
-
if (!option) {
|
|
3505
|
-
addIssueToContext(ctx, {
|
|
3506
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
3507
|
-
options: Array.from(this.optionsMap.keys()),
|
|
3508
|
-
path: [discriminator]
|
|
3509
|
-
});
|
|
3510
|
-
return INVALID;
|
|
3511
|
-
}
|
|
3512
|
-
if (ctx.common.async) {
|
|
3513
|
-
return option._parseAsync({
|
|
3514
|
-
data: ctx.data,
|
|
3515
|
-
path: ctx.path,
|
|
3516
|
-
parent: ctx
|
|
3517
|
-
});
|
|
3518
|
-
} else {
|
|
3519
|
-
return option._parseSync({
|
|
3520
|
-
data: ctx.data,
|
|
3521
|
-
path: ctx.path,
|
|
3522
|
-
parent: ctx
|
|
3523
|
-
});
|
|
3524
|
-
}
|
|
3525
|
-
}
|
|
3526
|
-
get discriminator() {
|
|
3527
|
-
return this._def.discriminator;
|
|
3528
|
-
}
|
|
3529
|
-
get options() {
|
|
3530
|
-
return this._def.options;
|
|
3531
|
-
}
|
|
3532
|
-
get optionsMap() {
|
|
3533
|
-
return this._def.optionsMap;
|
|
3534
|
-
}
|
|
3535
|
-
/**
|
|
3536
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3537
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3538
|
-
* have a different value for each object in the union.
|
|
3539
|
-
* @param discriminator the name of the discriminator property
|
|
3540
|
-
* @param types an array of object schemas
|
|
3541
|
-
* @param params
|
|
3542
|
-
*/
|
|
3543
|
-
static create(discriminator, options, params) {
|
|
3544
|
-
const optionsMap = /* @__PURE__ */ new Map();
|
|
3545
|
-
for (const type of options) {
|
|
3546
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3547
|
-
if (!discriminatorValues.length) {
|
|
3548
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3549
|
-
}
|
|
3550
|
-
for (const value of discriminatorValues) {
|
|
3551
|
-
if (optionsMap.has(value)) {
|
|
3552
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3553
|
-
}
|
|
3554
|
-
optionsMap.set(value, type);
|
|
3555
|
-
}
|
|
3556
|
-
}
|
|
3557
|
-
return new _ZodDiscriminatedUnion({
|
|
3558
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3559
|
-
discriminator,
|
|
3560
|
-
options,
|
|
3561
|
-
optionsMap,
|
|
3562
|
-
...processCreateParams(params)
|
|
3563
|
-
});
|
|
3564
|
-
}
|
|
3565
|
-
};
|
|
3566
|
-
function mergeValues(a, b) {
|
|
3567
|
-
const aType = getParsedType(a);
|
|
3568
|
-
const bType = getParsedType(b);
|
|
3569
|
-
if (a === b) {
|
|
3570
|
-
return { valid: true, data: a };
|
|
3571
|
-
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3572
|
-
const bKeys = util.objectKeys(b);
|
|
3573
|
-
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3574
|
-
const newObj = { ...a, ...b };
|
|
3575
|
-
for (const key of sharedKeys) {
|
|
3576
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
3577
|
-
if (!sharedValue.valid) {
|
|
3578
|
-
return { valid: false };
|
|
3579
|
-
}
|
|
3580
|
-
newObj[key] = sharedValue.data;
|
|
3581
|
-
}
|
|
3582
|
-
return { valid: true, data: newObj };
|
|
3583
|
-
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
3584
|
-
if (a.length !== b.length) {
|
|
3585
|
-
return { valid: false };
|
|
3586
|
-
}
|
|
3587
|
-
const newArray = [];
|
|
3588
|
-
for (let index = 0; index < a.length; index++) {
|
|
3589
|
-
const itemA = a[index];
|
|
3590
|
-
const itemB = b[index];
|
|
3591
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
3592
|
-
if (!sharedValue.valid) {
|
|
3593
|
-
return { valid: false };
|
|
3594
|
-
}
|
|
3595
|
-
newArray.push(sharedValue.data);
|
|
3596
|
-
}
|
|
3597
|
-
return { valid: true, data: newArray };
|
|
3598
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3599
|
-
return { valid: true, data: a };
|
|
3600
|
-
} else {
|
|
3601
|
-
return { valid: false };
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
var ZodIntersection = class extends ZodType {
|
|
3605
|
-
_parse(input) {
|
|
3606
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3607
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3608
|
-
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3609
|
-
return INVALID;
|
|
3610
|
-
}
|
|
3611
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3612
|
-
if (!merged.valid) {
|
|
3613
|
-
addIssueToContext(ctx, {
|
|
3614
|
-
code: ZodIssueCode.invalid_intersection_types
|
|
3615
|
-
});
|
|
3616
|
-
return INVALID;
|
|
3617
|
-
}
|
|
3618
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3619
|
-
status.dirty();
|
|
3620
|
-
}
|
|
3621
|
-
return { status: status.value, value: merged.data };
|
|
3622
|
-
};
|
|
3623
|
-
if (ctx.common.async) {
|
|
3624
|
-
return Promise.all([
|
|
3625
|
-
this._def.left._parseAsync({
|
|
3626
|
-
data: ctx.data,
|
|
3627
|
-
path: ctx.path,
|
|
3628
|
-
parent: ctx
|
|
3629
|
-
}),
|
|
3630
|
-
this._def.right._parseAsync({
|
|
3631
|
-
data: ctx.data,
|
|
3632
|
-
path: ctx.path,
|
|
3633
|
-
parent: ctx
|
|
3634
|
-
})
|
|
3635
|
-
]).then(([left, right]) => handleParsed(left, right));
|
|
3636
|
-
} else {
|
|
3637
|
-
return handleParsed(this._def.left._parseSync({
|
|
3638
|
-
data: ctx.data,
|
|
3639
|
-
path: ctx.path,
|
|
3640
|
-
parent: ctx
|
|
3641
|
-
}), this._def.right._parseSync({
|
|
3642
|
-
data: ctx.data,
|
|
3643
|
-
path: ctx.path,
|
|
3644
|
-
parent: ctx
|
|
3645
|
-
}));
|
|
3646
|
-
}
|
|
3647
|
-
}
|
|
3648
|
-
};
|
|
3649
|
-
ZodIntersection.create = (left, right, params) => {
|
|
3650
|
-
return new ZodIntersection({
|
|
3651
|
-
left,
|
|
3652
|
-
right,
|
|
3653
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3654
|
-
...processCreateParams(params)
|
|
3655
|
-
});
|
|
3656
|
-
};
|
|
3657
|
-
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3658
|
-
_parse(input) {
|
|
3659
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3660
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3661
|
-
addIssueToContext(ctx, {
|
|
3662
|
-
code: ZodIssueCode.invalid_type,
|
|
3663
|
-
expected: ZodParsedType.array,
|
|
3664
|
-
received: ctx.parsedType
|
|
3665
|
-
});
|
|
3666
|
-
return INVALID;
|
|
3667
|
-
}
|
|
3668
|
-
if (ctx.data.length < this._def.items.length) {
|
|
3669
|
-
addIssueToContext(ctx, {
|
|
3670
|
-
code: ZodIssueCode.too_small,
|
|
3671
|
-
minimum: this._def.items.length,
|
|
3672
|
-
inclusive: true,
|
|
3673
|
-
exact: false,
|
|
3674
|
-
type: "array"
|
|
3675
|
-
});
|
|
3676
|
-
return INVALID;
|
|
3677
|
-
}
|
|
3678
|
-
const rest = this._def.rest;
|
|
3679
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3680
|
-
addIssueToContext(ctx, {
|
|
3681
|
-
code: ZodIssueCode.too_big,
|
|
3682
|
-
maximum: this._def.items.length,
|
|
3683
|
-
inclusive: true,
|
|
3684
|
-
exact: false,
|
|
3685
|
-
type: "array"
|
|
3686
|
-
});
|
|
3687
|
-
status.dirty();
|
|
3688
|
-
}
|
|
3689
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3690
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3691
|
-
if (!schema)
|
|
3692
|
-
return null;
|
|
3693
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3694
|
-
}).filter((x) => !!x);
|
|
3695
|
-
if (ctx.common.async) {
|
|
3696
|
-
return Promise.all(items).then((results) => {
|
|
3697
|
-
return ParseStatus.mergeArray(status, results);
|
|
3698
|
-
});
|
|
3699
|
-
} else {
|
|
3700
|
-
return ParseStatus.mergeArray(status, items);
|
|
3701
|
-
}
|
|
3702
|
-
}
|
|
3703
|
-
get items() {
|
|
3704
|
-
return this._def.items;
|
|
3705
|
-
}
|
|
3706
|
-
rest(rest) {
|
|
3707
|
-
return new _ZodTuple({
|
|
3708
|
-
...this._def,
|
|
3709
|
-
rest
|
|
3710
|
-
});
|
|
3711
|
-
}
|
|
3712
|
-
};
|
|
3713
|
-
ZodTuple.create = (schemas, params) => {
|
|
3714
|
-
if (!Array.isArray(schemas)) {
|
|
3715
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3716
|
-
}
|
|
3717
|
-
return new ZodTuple({
|
|
3718
|
-
items: schemas,
|
|
3719
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3720
|
-
rest: null,
|
|
3721
|
-
...processCreateParams(params)
|
|
3722
|
-
});
|
|
3723
|
-
};
|
|
3724
|
-
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3725
|
-
get keySchema() {
|
|
3726
|
-
return this._def.keyType;
|
|
3727
|
-
}
|
|
3728
|
-
get valueSchema() {
|
|
3729
|
-
return this._def.valueType;
|
|
3730
|
-
}
|
|
3731
|
-
_parse(input) {
|
|
3732
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3733
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3734
|
-
addIssueToContext(ctx, {
|
|
3735
|
-
code: ZodIssueCode.invalid_type,
|
|
3736
|
-
expected: ZodParsedType.object,
|
|
3737
|
-
received: ctx.parsedType
|
|
3738
|
-
});
|
|
3739
|
-
return INVALID;
|
|
3740
|
-
}
|
|
3741
|
-
const pairs = [];
|
|
3742
|
-
const keyType = this._def.keyType;
|
|
3743
|
-
const valueType = this._def.valueType;
|
|
3744
|
-
for (const key in ctx.data) {
|
|
3745
|
-
pairs.push({
|
|
3746
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3747
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3748
|
-
alwaysSet: key in ctx.data
|
|
3749
|
-
});
|
|
3750
|
-
}
|
|
3751
|
-
if (ctx.common.async) {
|
|
3752
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3753
|
-
} else {
|
|
3754
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3755
|
-
}
|
|
3756
|
-
}
|
|
3757
|
-
get element() {
|
|
3758
|
-
return this._def.valueType;
|
|
3759
|
-
}
|
|
3760
|
-
static create(first, second, third) {
|
|
3761
|
-
if (second instanceof ZodType) {
|
|
3762
|
-
return new _ZodRecord({
|
|
3763
|
-
keyType: first,
|
|
3764
|
-
valueType: second,
|
|
3765
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3766
|
-
...processCreateParams(third)
|
|
3767
|
-
});
|
|
3768
|
-
}
|
|
3769
|
-
return new _ZodRecord({
|
|
3770
|
-
keyType: ZodString.create(),
|
|
3771
|
-
valueType: first,
|
|
3772
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3773
|
-
...processCreateParams(second)
|
|
3774
|
-
});
|
|
3775
|
-
}
|
|
3776
|
-
};
|
|
3777
|
-
var ZodMap = class extends ZodType {
|
|
3778
|
-
get keySchema() {
|
|
3779
|
-
return this._def.keyType;
|
|
3780
|
-
}
|
|
3781
|
-
get valueSchema() {
|
|
3782
|
-
return this._def.valueType;
|
|
3783
|
-
}
|
|
3784
|
-
_parse(input) {
|
|
3785
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3786
|
-
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3787
|
-
addIssueToContext(ctx, {
|
|
3788
|
-
code: ZodIssueCode.invalid_type,
|
|
3789
|
-
expected: ZodParsedType.map,
|
|
3790
|
-
received: ctx.parsedType
|
|
3791
|
-
});
|
|
3792
|
-
return INVALID;
|
|
3793
|
-
}
|
|
3794
|
-
const keyType = this._def.keyType;
|
|
3795
|
-
const valueType = this._def.valueType;
|
|
3796
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3797
|
-
return {
|
|
3798
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3799
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3800
|
-
};
|
|
3801
|
-
});
|
|
3802
|
-
if (ctx.common.async) {
|
|
3803
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3804
|
-
return Promise.resolve().then(async () => {
|
|
3805
|
-
for (const pair of pairs) {
|
|
3806
|
-
const key = await pair.key;
|
|
3807
|
-
const value = await pair.value;
|
|
3808
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3809
|
-
return INVALID;
|
|
3810
|
-
}
|
|
3811
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3812
|
-
status.dirty();
|
|
3813
|
-
}
|
|
3814
|
-
finalMap.set(key.value, value.value);
|
|
3815
|
-
}
|
|
3816
|
-
return { status: status.value, value: finalMap };
|
|
3817
|
-
});
|
|
3818
|
-
} else {
|
|
3819
|
-
const finalMap = /* @__PURE__ */ new Map();
|
|
3820
|
-
for (const pair of pairs) {
|
|
3821
|
-
const key = pair.key;
|
|
3822
|
-
const value = pair.value;
|
|
3823
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3824
|
-
return INVALID;
|
|
3825
|
-
}
|
|
3826
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3827
|
-
status.dirty();
|
|
3828
|
-
}
|
|
3829
|
-
finalMap.set(key.value, value.value);
|
|
3830
|
-
}
|
|
3831
|
-
return { status: status.value, value: finalMap };
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
|
-
};
|
|
3835
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
3836
|
-
return new ZodMap({
|
|
3837
|
-
valueType,
|
|
3838
|
-
keyType,
|
|
3839
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3840
|
-
...processCreateParams(params)
|
|
3841
|
-
});
|
|
3842
|
-
};
|
|
3843
|
-
var ZodSet = class _ZodSet extends ZodType {
|
|
3844
|
-
_parse(input) {
|
|
3845
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3846
|
-
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3847
|
-
addIssueToContext(ctx, {
|
|
3848
|
-
code: ZodIssueCode.invalid_type,
|
|
3849
|
-
expected: ZodParsedType.set,
|
|
3850
|
-
received: ctx.parsedType
|
|
3851
|
-
});
|
|
3852
|
-
return INVALID;
|
|
3853
|
-
}
|
|
3854
|
-
const def = this._def;
|
|
3855
|
-
if (def.minSize !== null) {
|
|
3856
|
-
if (ctx.data.size < def.minSize.value) {
|
|
3857
|
-
addIssueToContext(ctx, {
|
|
3858
|
-
code: ZodIssueCode.too_small,
|
|
3859
|
-
minimum: def.minSize.value,
|
|
3860
|
-
type: "set",
|
|
3861
|
-
inclusive: true,
|
|
3862
|
-
exact: false,
|
|
3863
|
-
message: def.minSize.message
|
|
3864
|
-
});
|
|
3865
|
-
status.dirty();
|
|
3866
|
-
}
|
|
3867
|
-
}
|
|
3868
|
-
if (def.maxSize !== null) {
|
|
3869
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
3870
|
-
addIssueToContext(ctx, {
|
|
3871
|
-
code: ZodIssueCode.too_big,
|
|
3872
|
-
maximum: def.maxSize.value,
|
|
3873
|
-
type: "set",
|
|
3874
|
-
inclusive: true,
|
|
3875
|
-
exact: false,
|
|
3876
|
-
message: def.maxSize.message
|
|
3877
|
-
});
|
|
3878
|
-
status.dirty();
|
|
3879
|
-
}
|
|
3880
|
-
}
|
|
3881
|
-
const valueType = this._def.valueType;
|
|
3882
|
-
function finalizeSet(elements2) {
|
|
3883
|
-
const parsedSet = /* @__PURE__ */ new Set();
|
|
3884
|
-
for (const element of elements2) {
|
|
3885
|
-
if (element.status === "aborted")
|
|
3886
|
-
return INVALID;
|
|
3887
|
-
if (element.status === "dirty")
|
|
3888
|
-
status.dirty();
|
|
3889
|
-
parsedSet.add(element.value);
|
|
3890
|
-
}
|
|
3891
|
-
return { status: status.value, value: parsedSet };
|
|
3892
|
-
}
|
|
3893
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3894
|
-
if (ctx.common.async) {
|
|
3895
|
-
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3896
|
-
} else {
|
|
3897
|
-
return finalizeSet(elements);
|
|
3898
|
-
}
|
|
3899
|
-
}
|
|
3900
|
-
min(minSize, message) {
|
|
3901
|
-
return new _ZodSet({
|
|
3902
|
-
...this._def,
|
|
3903
|
-
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3904
|
-
});
|
|
3905
|
-
}
|
|
3906
|
-
max(maxSize, message) {
|
|
3907
|
-
return new _ZodSet({
|
|
3908
|
-
...this._def,
|
|
3909
|
-
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3910
|
-
});
|
|
3911
|
-
}
|
|
3912
|
-
size(size, message) {
|
|
3913
|
-
return this.min(size, message).max(size, message);
|
|
3914
|
-
}
|
|
3915
|
-
nonempty(message) {
|
|
3916
|
-
return this.min(1, message);
|
|
3917
|
-
}
|
|
3918
|
-
};
|
|
3919
|
-
ZodSet.create = (valueType, params) => {
|
|
3920
|
-
return new ZodSet({
|
|
3921
|
-
valueType,
|
|
3922
|
-
minSize: null,
|
|
3923
|
-
maxSize: null,
|
|
3924
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3925
|
-
...processCreateParams(params)
|
|
3926
|
-
});
|
|
3927
|
-
};
|
|
3928
|
-
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3929
|
-
constructor() {
|
|
3930
|
-
super(...arguments);
|
|
3931
|
-
this.validate = this.implement;
|
|
3932
|
-
}
|
|
3933
|
-
_parse(input) {
|
|
3934
|
-
const { ctx } = this._processInputParams(input);
|
|
3935
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3936
|
-
addIssueToContext(ctx, {
|
|
3937
|
-
code: ZodIssueCode.invalid_type,
|
|
3938
|
-
expected: ZodParsedType.function,
|
|
3939
|
-
received: ctx.parsedType
|
|
3940
|
-
});
|
|
3941
|
-
return INVALID;
|
|
3942
|
-
}
|
|
3943
|
-
function makeArgsIssue(args, error) {
|
|
3944
|
-
return makeIssue({
|
|
3945
|
-
data: args,
|
|
3946
|
-
path: ctx.path,
|
|
3947
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3948
|
-
issueData: {
|
|
3949
|
-
code: ZodIssueCode.invalid_arguments,
|
|
3950
|
-
argumentsError: error
|
|
3951
|
-
}
|
|
3952
|
-
});
|
|
3953
|
-
}
|
|
3954
|
-
function makeReturnsIssue(returns, error) {
|
|
3955
|
-
return makeIssue({
|
|
3956
|
-
data: returns,
|
|
3957
|
-
path: ctx.path,
|
|
3958
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3959
|
-
issueData: {
|
|
3960
|
-
code: ZodIssueCode.invalid_return_type,
|
|
3961
|
-
returnTypeError: error
|
|
3962
|
-
}
|
|
3963
|
-
});
|
|
3964
|
-
}
|
|
3965
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3966
|
-
const fn = ctx.data;
|
|
3967
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3968
|
-
const me = this;
|
|
3969
|
-
return OK(async function(...args) {
|
|
3970
|
-
const error = new ZodError([]);
|
|
3971
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3972
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3973
|
-
throw error;
|
|
3974
|
-
});
|
|
3975
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3976
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3977
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3978
|
-
throw error;
|
|
3979
|
-
});
|
|
3980
|
-
return parsedReturns;
|
|
3981
|
-
});
|
|
3982
|
-
} else {
|
|
3983
|
-
const me = this;
|
|
3984
|
-
return OK(function(...args) {
|
|
3985
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3986
|
-
if (!parsedArgs.success) {
|
|
3987
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3988
|
-
}
|
|
3989
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3990
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3991
|
-
if (!parsedReturns.success) {
|
|
3992
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3993
|
-
}
|
|
3994
|
-
return parsedReturns.data;
|
|
3995
|
-
});
|
|
3996
|
-
}
|
|
3997
|
-
}
|
|
3998
|
-
parameters() {
|
|
3999
|
-
return this._def.args;
|
|
4000
|
-
}
|
|
4001
|
-
returnType() {
|
|
4002
|
-
return this._def.returns;
|
|
4003
|
-
}
|
|
4004
|
-
args(...items) {
|
|
4005
|
-
return new _ZodFunction({
|
|
4006
|
-
...this._def,
|
|
4007
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
4008
|
-
});
|
|
4009
|
-
}
|
|
4010
|
-
returns(returnType) {
|
|
4011
|
-
return new _ZodFunction({
|
|
4012
|
-
...this._def,
|
|
4013
|
-
returns: returnType
|
|
4014
|
-
});
|
|
4015
|
-
}
|
|
4016
|
-
implement(func) {
|
|
4017
|
-
const validatedFunc = this.parse(func);
|
|
4018
|
-
return validatedFunc;
|
|
4019
|
-
}
|
|
4020
|
-
strictImplement(func) {
|
|
4021
|
-
const validatedFunc = this.parse(func);
|
|
4022
|
-
return validatedFunc;
|
|
4023
|
-
}
|
|
4024
|
-
static create(args, returns, params) {
|
|
4025
|
-
return new _ZodFunction({
|
|
4026
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
4027
|
-
returns: returns || ZodUnknown.create(),
|
|
4028
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
4029
|
-
...processCreateParams(params)
|
|
4030
|
-
});
|
|
4031
|
-
}
|
|
4032
|
-
};
|
|
4033
|
-
var ZodLazy = class extends ZodType {
|
|
4034
|
-
get schema() {
|
|
4035
|
-
return this._def.getter();
|
|
4036
|
-
}
|
|
4037
|
-
_parse(input) {
|
|
4038
|
-
const { ctx } = this._processInputParams(input);
|
|
4039
|
-
const lazySchema = this._def.getter();
|
|
4040
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
4041
|
-
}
|
|
4042
|
-
};
|
|
4043
|
-
ZodLazy.create = (getter, params) => {
|
|
4044
|
-
return new ZodLazy({
|
|
4045
|
-
getter,
|
|
4046
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
4047
|
-
...processCreateParams(params)
|
|
4048
|
-
});
|
|
4049
|
-
};
|
|
4050
|
-
var ZodLiteral = class extends ZodType {
|
|
4051
|
-
_parse(input) {
|
|
4052
|
-
if (input.data !== this._def.value) {
|
|
4053
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4054
|
-
addIssueToContext(ctx, {
|
|
4055
|
-
received: ctx.data,
|
|
4056
|
-
code: ZodIssueCode.invalid_literal,
|
|
4057
|
-
expected: this._def.value
|
|
4058
|
-
});
|
|
4059
|
-
return INVALID;
|
|
4060
|
-
}
|
|
4061
|
-
return { status: "valid", value: input.data };
|
|
4062
|
-
}
|
|
4063
|
-
get value() {
|
|
4064
|
-
return this._def.value;
|
|
4065
|
-
}
|
|
4066
|
-
};
|
|
4067
|
-
ZodLiteral.create = (value, params) => {
|
|
4068
|
-
return new ZodLiteral({
|
|
4069
|
-
value,
|
|
4070
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
4071
|
-
...processCreateParams(params)
|
|
4072
|
-
});
|
|
4073
|
-
};
|
|
4074
|
-
function createZodEnum(values, params) {
|
|
4075
|
-
return new ZodEnum({
|
|
4076
|
-
values,
|
|
4077
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
4078
|
-
...processCreateParams(params)
|
|
4079
|
-
});
|
|
4080
|
-
}
|
|
4081
|
-
var ZodEnum = class _ZodEnum extends ZodType {
|
|
4082
|
-
_parse(input) {
|
|
4083
|
-
if (typeof input.data !== "string") {
|
|
4084
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4085
|
-
const expectedValues = this._def.values;
|
|
4086
|
-
addIssueToContext(ctx, {
|
|
4087
|
-
expected: util.joinValues(expectedValues),
|
|
4088
|
-
received: ctx.parsedType,
|
|
4089
|
-
code: ZodIssueCode.invalid_type
|
|
4090
|
-
});
|
|
4091
|
-
return INVALID;
|
|
4092
|
-
}
|
|
4093
|
-
if (!this._cache) {
|
|
4094
|
-
this._cache = new Set(this._def.values);
|
|
4095
|
-
}
|
|
4096
|
-
if (!this._cache.has(input.data)) {
|
|
4097
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4098
|
-
const expectedValues = this._def.values;
|
|
4099
|
-
addIssueToContext(ctx, {
|
|
4100
|
-
received: ctx.data,
|
|
4101
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
4102
|
-
options: expectedValues
|
|
4103
|
-
});
|
|
4104
|
-
return INVALID;
|
|
4105
|
-
}
|
|
4106
|
-
return OK(input.data);
|
|
4107
|
-
}
|
|
4108
|
-
get options() {
|
|
4109
|
-
return this._def.values;
|
|
4110
|
-
}
|
|
4111
|
-
get enum() {
|
|
4112
|
-
const enumValues = {};
|
|
4113
|
-
for (const val of this._def.values) {
|
|
4114
|
-
enumValues[val] = val;
|
|
4115
|
-
}
|
|
4116
|
-
return enumValues;
|
|
4117
|
-
}
|
|
4118
|
-
get Values() {
|
|
4119
|
-
const enumValues = {};
|
|
4120
|
-
for (const val of this._def.values) {
|
|
4121
|
-
enumValues[val] = val;
|
|
4122
|
-
}
|
|
4123
|
-
return enumValues;
|
|
4124
|
-
}
|
|
4125
|
-
get Enum() {
|
|
4126
|
-
const enumValues = {};
|
|
4127
|
-
for (const val of this._def.values) {
|
|
4128
|
-
enumValues[val] = val;
|
|
4129
|
-
}
|
|
4130
|
-
return enumValues;
|
|
4131
|
-
}
|
|
4132
|
-
extract(values, newDef = this._def) {
|
|
4133
|
-
return _ZodEnum.create(values, {
|
|
4134
|
-
...this._def,
|
|
4135
|
-
...newDef
|
|
4136
|
-
});
|
|
4137
|
-
}
|
|
4138
|
-
exclude(values, newDef = this._def) {
|
|
4139
|
-
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
4140
|
-
...this._def,
|
|
4141
|
-
...newDef
|
|
4142
|
-
});
|
|
4143
|
-
}
|
|
4144
|
-
};
|
|
4145
|
-
ZodEnum.create = createZodEnum;
|
|
4146
|
-
var ZodNativeEnum = class extends ZodType {
|
|
4147
|
-
_parse(input) {
|
|
4148
|
-
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
4149
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4150
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
4151
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
4152
|
-
addIssueToContext(ctx, {
|
|
4153
|
-
expected: util.joinValues(expectedValues),
|
|
4154
|
-
received: ctx.parsedType,
|
|
4155
|
-
code: ZodIssueCode.invalid_type
|
|
4156
|
-
});
|
|
4157
|
-
return INVALID;
|
|
4158
|
-
}
|
|
4159
|
-
if (!this._cache) {
|
|
4160
|
-
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
4161
|
-
}
|
|
4162
|
-
if (!this._cache.has(input.data)) {
|
|
4163
|
-
const expectedValues = util.objectValues(nativeEnumValues);
|
|
4164
|
-
addIssueToContext(ctx, {
|
|
4165
|
-
received: ctx.data,
|
|
4166
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
4167
|
-
options: expectedValues
|
|
4168
|
-
});
|
|
4169
|
-
return INVALID;
|
|
4170
|
-
}
|
|
4171
|
-
return OK(input.data);
|
|
4172
|
-
}
|
|
4173
|
-
get enum() {
|
|
4174
|
-
return this._def.values;
|
|
4175
|
-
}
|
|
4176
|
-
};
|
|
4177
|
-
ZodNativeEnum.create = (values, params) => {
|
|
4178
|
-
return new ZodNativeEnum({
|
|
4179
|
-
values,
|
|
4180
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
4181
|
-
...processCreateParams(params)
|
|
4182
|
-
});
|
|
4183
|
-
};
|
|
4184
|
-
var ZodPromise = class extends ZodType {
|
|
4185
|
-
unwrap() {
|
|
4186
|
-
return this._def.type;
|
|
4187
|
-
}
|
|
4188
|
-
_parse(input) {
|
|
4189
|
-
const { ctx } = this._processInputParams(input);
|
|
4190
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
4191
|
-
addIssueToContext(ctx, {
|
|
4192
|
-
code: ZodIssueCode.invalid_type,
|
|
4193
|
-
expected: ZodParsedType.promise,
|
|
4194
|
-
received: ctx.parsedType
|
|
4195
|
-
});
|
|
4196
|
-
return INVALID;
|
|
4197
|
-
}
|
|
4198
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
4199
|
-
return OK(promisified.then((data) => {
|
|
4200
|
-
return this._def.type.parseAsync(data, {
|
|
4201
|
-
path: ctx.path,
|
|
4202
|
-
errorMap: ctx.common.contextualErrorMap
|
|
4203
|
-
});
|
|
4204
|
-
}));
|
|
4205
|
-
}
|
|
4206
|
-
};
|
|
4207
|
-
ZodPromise.create = (schema, params) => {
|
|
4208
|
-
return new ZodPromise({
|
|
4209
|
-
type: schema,
|
|
4210
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
4211
|
-
...processCreateParams(params)
|
|
4212
|
-
});
|
|
4213
|
-
};
|
|
4214
|
-
var ZodEffects = class extends ZodType {
|
|
4215
|
-
innerType() {
|
|
4216
|
-
return this._def.schema;
|
|
4217
|
-
}
|
|
4218
|
-
sourceType() {
|
|
4219
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
4220
|
-
}
|
|
4221
|
-
_parse(input) {
|
|
4222
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4223
|
-
const effect = this._def.effect || null;
|
|
4224
|
-
const checkCtx = {
|
|
4225
|
-
addIssue: (arg) => {
|
|
4226
|
-
addIssueToContext(ctx, arg);
|
|
4227
|
-
if (arg.fatal) {
|
|
4228
|
-
status.abort();
|
|
4229
|
-
} else {
|
|
4230
|
-
status.dirty();
|
|
512
|
+
ignored,
|
|
513
|
+
unignored
|
|
514
|
+
};
|
|
515
|
+
if (matchedRule) {
|
|
516
|
+
ret.rule = matchedRule;
|
|
4231
517
|
}
|
|
4232
|
-
|
|
4233
|
-
get path() {
|
|
4234
|
-
return ctx.path;
|
|
518
|
+
return ret;
|
|
4235
519
|
}
|
|
4236
520
|
};
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
path: ctx.path,
|
|
4247
|
-
parent: ctx
|
|
4248
|
-
});
|
|
4249
|
-
if (result.status === "aborted")
|
|
4250
|
-
return INVALID;
|
|
4251
|
-
if (result.status === "dirty")
|
|
4252
|
-
return DIRTY(result.value);
|
|
4253
|
-
if (status.value === "dirty")
|
|
4254
|
-
return DIRTY(result.value);
|
|
4255
|
-
return result;
|
|
4256
|
-
});
|
|
4257
|
-
} else {
|
|
4258
|
-
if (status.value === "aborted")
|
|
4259
|
-
return INVALID;
|
|
4260
|
-
const result = this._def.schema._parseSync({
|
|
4261
|
-
data: processed,
|
|
4262
|
-
path: ctx.path,
|
|
4263
|
-
parent: ctx
|
|
4264
|
-
});
|
|
4265
|
-
if (result.status === "aborted")
|
|
4266
|
-
return INVALID;
|
|
4267
|
-
if (result.status === "dirty")
|
|
4268
|
-
return DIRTY(result.value);
|
|
4269
|
-
if (status.value === "dirty")
|
|
4270
|
-
return DIRTY(result.value);
|
|
4271
|
-
return result;
|
|
521
|
+
var throwError = (message, Ctor) => {
|
|
522
|
+
throw new Ctor(message);
|
|
523
|
+
};
|
|
524
|
+
var checkPath = (path9, originalPath, doThrow) => {
|
|
525
|
+
if (!isString(path9)) {
|
|
526
|
+
return doThrow(
|
|
527
|
+
`path must be a string, but got \`${originalPath}\``,
|
|
528
|
+
TypeError
|
|
529
|
+
);
|
|
4272
530
|
}
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
531
|
+
if (!path9) {
|
|
532
|
+
return doThrow(`path must not be empty`, TypeError);
|
|
533
|
+
}
|
|
534
|
+
if (checkPath.isNotRelative(path9)) {
|
|
535
|
+
const r = "`path.relative()`d";
|
|
536
|
+
return doThrow(
|
|
537
|
+
`path should be a ${r} string, but got "${originalPath}"`,
|
|
538
|
+
RangeError
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
return true;
|
|
542
|
+
};
|
|
543
|
+
var isNotRelative = (path9) => REGEX_TEST_INVALID_PATH.test(path9);
|
|
544
|
+
checkPath.isNotRelative = isNotRelative;
|
|
545
|
+
checkPath.convert = (p) => p;
|
|
546
|
+
var Ignore2 = class {
|
|
547
|
+
constructor({
|
|
548
|
+
ignorecase = true,
|
|
549
|
+
ignoreCase = ignorecase,
|
|
550
|
+
allowRelativePaths = false
|
|
551
|
+
} = {}) {
|
|
552
|
+
define(this, KEY_IGNORE, true);
|
|
553
|
+
this._rules = new RuleManager(ignoreCase);
|
|
554
|
+
this._strictPathCheck = !allowRelativePaths;
|
|
555
|
+
this._initCache();
|
|
556
|
+
}
|
|
557
|
+
_initCache() {
|
|
558
|
+
this._ignoreCache = /* @__PURE__ */ Object.create(null);
|
|
559
|
+
this._testCache = /* @__PURE__ */ Object.create(null);
|
|
560
|
+
}
|
|
561
|
+
add(pattern) {
|
|
562
|
+
if (this._rules.add(pattern)) {
|
|
563
|
+
this._initCache();
|
|
564
|
+
}
|
|
565
|
+
return this;
|
|
566
|
+
}
|
|
567
|
+
// legacy
|
|
568
|
+
addPattern(pattern) {
|
|
569
|
+
return this.add(pattern);
|
|
570
|
+
}
|
|
571
|
+
// @returns {TestResult}
|
|
572
|
+
_test(originalPath, cache, checkUnignored, slices) {
|
|
573
|
+
const path9 = originalPath && checkPath.convert(originalPath);
|
|
574
|
+
checkPath(
|
|
575
|
+
path9,
|
|
576
|
+
originalPath,
|
|
577
|
+
this._strictPathCheck ? throwError : RETURN_FALSE
|
|
578
|
+
);
|
|
579
|
+
return this._t(path9, cache, checkUnignored, slices);
|
|
580
|
+
}
|
|
581
|
+
checkIgnore(path9) {
|
|
582
|
+
if (!REGEX_TEST_TRAILING_SLASH.test(path9)) {
|
|
583
|
+
return this.test(path9);
|
|
4279
584
|
}
|
|
4280
|
-
|
|
4281
|
-
|
|
585
|
+
const slices = path9.split(SLASH2).filter(Boolean);
|
|
586
|
+
slices.pop();
|
|
587
|
+
if (slices.length) {
|
|
588
|
+
const parent = this._t(
|
|
589
|
+
slices.join(SLASH2) + SLASH2,
|
|
590
|
+
this._testCache,
|
|
591
|
+
true,
|
|
592
|
+
slices
|
|
593
|
+
);
|
|
594
|
+
if (parent.ignored) {
|
|
595
|
+
return parent;
|
|
596
|
+
}
|
|
4282
597
|
}
|
|
4283
|
-
return
|
|
4284
|
-
};
|
|
4285
|
-
if (ctx.common.async === false) {
|
|
4286
|
-
const inner = this._def.schema._parseSync({
|
|
4287
|
-
data: ctx.data,
|
|
4288
|
-
path: ctx.path,
|
|
4289
|
-
parent: ctx
|
|
4290
|
-
});
|
|
4291
|
-
if (inner.status === "aborted")
|
|
4292
|
-
return INVALID;
|
|
4293
|
-
if (inner.status === "dirty")
|
|
4294
|
-
status.dirty();
|
|
4295
|
-
executeRefinement(inner.value);
|
|
4296
|
-
return { status: status.value, value: inner.value };
|
|
4297
|
-
} else {
|
|
4298
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
4299
|
-
if (inner.status === "aborted")
|
|
4300
|
-
return INVALID;
|
|
4301
|
-
if (inner.status === "dirty")
|
|
4302
|
-
status.dirty();
|
|
4303
|
-
return executeRefinement(inner.value).then(() => {
|
|
4304
|
-
return { status: status.value, value: inner.value };
|
|
4305
|
-
});
|
|
4306
|
-
});
|
|
598
|
+
return this._rules.test(path9, false, MODE_CHECK_IGNORE);
|
|
4307
599
|
}
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
const base = this._def.schema._parseSync({
|
|
4312
|
-
data: ctx.data,
|
|
4313
|
-
path: ctx.path,
|
|
4314
|
-
parent: ctx
|
|
4315
|
-
});
|
|
4316
|
-
if (!isValid(base))
|
|
4317
|
-
return INVALID;
|
|
4318
|
-
const result = effect.transform(base.value, checkCtx);
|
|
4319
|
-
if (result instanceof Promise) {
|
|
4320
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
600
|
+
_t(path9, cache, checkUnignored, slices) {
|
|
601
|
+
if (path9 in cache) {
|
|
602
|
+
return cache[path9];
|
|
4321
603
|
}
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
return
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
604
|
+
if (!slices) {
|
|
605
|
+
slices = path9.split(SLASH2).filter(Boolean);
|
|
606
|
+
}
|
|
607
|
+
slices.pop();
|
|
608
|
+
if (!slices.length) {
|
|
609
|
+
return cache[path9] = this._rules.test(path9, checkUnignored, MODE_IGNORE);
|
|
610
|
+
}
|
|
611
|
+
const parent = this._t(
|
|
612
|
+
slices.join(SLASH2) + SLASH2,
|
|
613
|
+
cache,
|
|
614
|
+
checkUnignored,
|
|
615
|
+
slices
|
|
616
|
+
);
|
|
617
|
+
return cache[path9] = parent.ignored ? parent : this._rules.test(path9, checkUnignored, MODE_IGNORE);
|
|
4332
618
|
}
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
}
|
|
4336
|
-
};
|
|
4337
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
4338
|
-
return new ZodEffects({
|
|
4339
|
-
schema,
|
|
4340
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4341
|
-
effect,
|
|
4342
|
-
...processCreateParams(params)
|
|
4343
|
-
});
|
|
4344
|
-
};
|
|
4345
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
4346
|
-
return new ZodEffects({
|
|
4347
|
-
schema,
|
|
4348
|
-
effect: { type: "preprocess", transform: preprocess },
|
|
4349
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4350
|
-
...processCreateParams(params)
|
|
4351
|
-
});
|
|
4352
|
-
};
|
|
4353
|
-
var ZodOptional = class extends ZodType {
|
|
4354
|
-
_parse(input) {
|
|
4355
|
-
const parsedType = this._getType(input);
|
|
4356
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
4357
|
-
return OK(void 0);
|
|
4358
|
-
}
|
|
4359
|
-
return this._def.innerType._parse(input);
|
|
4360
|
-
}
|
|
4361
|
-
unwrap() {
|
|
4362
|
-
return this._def.innerType;
|
|
4363
|
-
}
|
|
4364
|
-
};
|
|
4365
|
-
ZodOptional.create = (type, params) => {
|
|
4366
|
-
return new ZodOptional({
|
|
4367
|
-
innerType: type,
|
|
4368
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
4369
|
-
...processCreateParams(params)
|
|
4370
|
-
});
|
|
4371
|
-
};
|
|
4372
|
-
var ZodNullable = class extends ZodType {
|
|
4373
|
-
_parse(input) {
|
|
4374
|
-
const parsedType = this._getType(input);
|
|
4375
|
-
if (parsedType === ZodParsedType.null) {
|
|
4376
|
-
return OK(null);
|
|
4377
|
-
}
|
|
4378
|
-
return this._def.innerType._parse(input);
|
|
4379
|
-
}
|
|
4380
|
-
unwrap() {
|
|
4381
|
-
return this._def.innerType;
|
|
4382
|
-
}
|
|
4383
|
-
};
|
|
4384
|
-
ZodNullable.create = (type, params) => {
|
|
4385
|
-
return new ZodNullable({
|
|
4386
|
-
innerType: type,
|
|
4387
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
4388
|
-
...processCreateParams(params)
|
|
4389
|
-
});
|
|
4390
|
-
};
|
|
4391
|
-
var ZodDefault = class extends ZodType {
|
|
4392
|
-
_parse(input) {
|
|
4393
|
-
const { ctx } = this._processInputParams(input);
|
|
4394
|
-
let data = ctx.data;
|
|
4395
|
-
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
4396
|
-
data = this._def.defaultValue();
|
|
4397
|
-
}
|
|
4398
|
-
return this._def.innerType._parse({
|
|
4399
|
-
data,
|
|
4400
|
-
path: ctx.path,
|
|
4401
|
-
parent: ctx
|
|
4402
|
-
});
|
|
4403
|
-
}
|
|
4404
|
-
removeDefault() {
|
|
4405
|
-
return this._def.innerType;
|
|
4406
|
-
}
|
|
4407
|
-
};
|
|
4408
|
-
ZodDefault.create = (type, params) => {
|
|
4409
|
-
return new ZodDefault({
|
|
4410
|
-
innerType: type,
|
|
4411
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4412
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4413
|
-
...processCreateParams(params)
|
|
4414
|
-
});
|
|
4415
|
-
};
|
|
4416
|
-
var ZodCatch = class extends ZodType {
|
|
4417
|
-
_parse(input) {
|
|
4418
|
-
const { ctx } = this._processInputParams(input);
|
|
4419
|
-
const newCtx = {
|
|
4420
|
-
...ctx,
|
|
4421
|
-
common: {
|
|
4422
|
-
...ctx.common,
|
|
4423
|
-
issues: []
|
|
619
|
+
ignores(path9) {
|
|
620
|
+
return this._test(path9, this._ignoreCache, false).ignored;
|
|
4424
621
|
}
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
data: newCtx.data,
|
|
4428
|
-
path: newCtx.path,
|
|
4429
|
-
parent: {
|
|
4430
|
-
...newCtx
|
|
622
|
+
createFilter() {
|
|
623
|
+
return (path9) => !this.ignores(path9);
|
|
4431
624
|
}
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
return result.then((result2) => {
|
|
4435
|
-
return {
|
|
4436
|
-
status: "valid",
|
|
4437
|
-
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
4438
|
-
get error() {
|
|
4439
|
-
return new ZodError(newCtx.common.issues);
|
|
4440
|
-
},
|
|
4441
|
-
input: newCtx.data
|
|
4442
|
-
})
|
|
4443
|
-
};
|
|
4444
|
-
});
|
|
4445
|
-
} else {
|
|
4446
|
-
return {
|
|
4447
|
-
status: "valid",
|
|
4448
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
4449
|
-
get error() {
|
|
4450
|
-
return new ZodError(newCtx.common.issues);
|
|
4451
|
-
},
|
|
4452
|
-
input: newCtx.data
|
|
4453
|
-
})
|
|
4454
|
-
};
|
|
4455
|
-
}
|
|
4456
|
-
}
|
|
4457
|
-
removeCatch() {
|
|
4458
|
-
return this._def.innerType;
|
|
4459
|
-
}
|
|
4460
|
-
};
|
|
4461
|
-
ZodCatch.create = (type, params) => {
|
|
4462
|
-
return new ZodCatch({
|
|
4463
|
-
innerType: type,
|
|
4464
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
4465
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
4466
|
-
...processCreateParams(params)
|
|
4467
|
-
});
|
|
4468
|
-
};
|
|
4469
|
-
var ZodNaN = class extends ZodType {
|
|
4470
|
-
_parse(input) {
|
|
4471
|
-
const parsedType = this._getType(input);
|
|
4472
|
-
if (parsedType !== ZodParsedType.nan) {
|
|
4473
|
-
const ctx = this._getOrReturnCtx(input);
|
|
4474
|
-
addIssueToContext(ctx, {
|
|
4475
|
-
code: ZodIssueCode.invalid_type,
|
|
4476
|
-
expected: ZodParsedType.nan,
|
|
4477
|
-
received: ctx.parsedType
|
|
4478
|
-
});
|
|
4479
|
-
return INVALID;
|
|
4480
|
-
}
|
|
4481
|
-
return { status: "valid", value: input.data };
|
|
4482
|
-
}
|
|
4483
|
-
};
|
|
4484
|
-
ZodNaN.create = (params) => {
|
|
4485
|
-
return new ZodNaN({
|
|
4486
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
4487
|
-
...processCreateParams(params)
|
|
4488
|
-
});
|
|
4489
|
-
};
|
|
4490
|
-
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
4491
|
-
var ZodBranded = class extends ZodType {
|
|
4492
|
-
_parse(input) {
|
|
4493
|
-
const { ctx } = this._processInputParams(input);
|
|
4494
|
-
const data = ctx.data;
|
|
4495
|
-
return this._def.type._parse({
|
|
4496
|
-
data,
|
|
4497
|
-
path: ctx.path,
|
|
4498
|
-
parent: ctx
|
|
4499
|
-
});
|
|
4500
|
-
}
|
|
4501
|
-
unwrap() {
|
|
4502
|
-
return this._def.type;
|
|
4503
|
-
}
|
|
4504
|
-
};
|
|
4505
|
-
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4506
|
-
_parse(input) {
|
|
4507
|
-
const { status, ctx } = this._processInputParams(input);
|
|
4508
|
-
if (ctx.common.async) {
|
|
4509
|
-
const handleAsync = async () => {
|
|
4510
|
-
const inResult = await this._def.in._parseAsync({
|
|
4511
|
-
data: ctx.data,
|
|
4512
|
-
path: ctx.path,
|
|
4513
|
-
parent: ctx
|
|
4514
|
-
});
|
|
4515
|
-
if (inResult.status === "aborted")
|
|
4516
|
-
return INVALID;
|
|
4517
|
-
if (inResult.status === "dirty") {
|
|
4518
|
-
status.dirty();
|
|
4519
|
-
return DIRTY(inResult.value);
|
|
4520
|
-
} else {
|
|
4521
|
-
return this._def.out._parseAsync({
|
|
4522
|
-
data: inResult.value,
|
|
4523
|
-
path: ctx.path,
|
|
4524
|
-
parent: ctx
|
|
4525
|
-
});
|
|
4526
|
-
}
|
|
4527
|
-
};
|
|
4528
|
-
return handleAsync();
|
|
4529
|
-
} else {
|
|
4530
|
-
const inResult = this._def.in._parseSync({
|
|
4531
|
-
data: ctx.data,
|
|
4532
|
-
path: ctx.path,
|
|
4533
|
-
parent: ctx
|
|
4534
|
-
});
|
|
4535
|
-
if (inResult.status === "aborted")
|
|
4536
|
-
return INVALID;
|
|
4537
|
-
if (inResult.status === "dirty") {
|
|
4538
|
-
status.dirty();
|
|
4539
|
-
return {
|
|
4540
|
-
status: "dirty",
|
|
4541
|
-
value: inResult.value
|
|
4542
|
-
};
|
|
4543
|
-
} else {
|
|
4544
|
-
return this._def.out._parseSync({
|
|
4545
|
-
data: inResult.value,
|
|
4546
|
-
path: ctx.path,
|
|
4547
|
-
parent: ctx
|
|
4548
|
-
});
|
|
625
|
+
filter(paths) {
|
|
626
|
+
return makeArray(paths).filter(this.createFilter());
|
|
4549
627
|
}
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
return new _ZodPipeline({
|
|
4554
|
-
in: a,
|
|
4555
|
-
out: b,
|
|
4556
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4557
|
-
});
|
|
4558
|
-
}
|
|
4559
|
-
};
|
|
4560
|
-
var ZodReadonly = class extends ZodType {
|
|
4561
|
-
_parse(input) {
|
|
4562
|
-
const result = this._def.innerType._parse(input);
|
|
4563
|
-
const freeze = (data) => {
|
|
4564
|
-
if (isValid(data)) {
|
|
4565
|
-
data.value = Object.freeze(data.value);
|
|
628
|
+
// @returns {TestResult}
|
|
629
|
+
test(path9) {
|
|
630
|
+
return this._test(path9, this._testCache, true);
|
|
4566
631
|
}
|
|
4567
|
-
return data;
|
|
4568
632
|
};
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
633
|
+
var factory = (options) => new Ignore2(options);
|
|
634
|
+
var isPathValid = (path9) => checkPath(path9 && checkPath.convert(path9), path9, RETURN_FALSE);
|
|
635
|
+
var setupWindows = () => {
|
|
636
|
+
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
637
|
+
checkPath.convert = makePosix;
|
|
638
|
+
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
639
|
+
checkPath.isNotRelative = (path9) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path9) || isNotRelative(path9);
|
|
640
|
+
};
|
|
641
|
+
if (
|
|
642
|
+
// Detect `process` so that it can run in browsers.
|
|
643
|
+
typeof process !== "undefined" && process.platform === "win32"
|
|
644
|
+
) {
|
|
645
|
+
setupWindows();
|
|
646
|
+
}
|
|
647
|
+
module.exports = factory;
|
|
648
|
+
factory.default = factory;
|
|
649
|
+
module.exports.isPathValid = isPathValid;
|
|
650
|
+
define(module.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
|
|
4573
651
|
}
|
|
4574
|
-
};
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
...processCreateParams(params)
|
|
4580
|
-
});
|
|
4581
|
-
};
|
|
4582
|
-
function cleanParams(params, data) {
|
|
4583
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
4584
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4585
|
-
return p2;
|
|
4586
|
-
}
|
|
4587
|
-
function custom(check, _params = {}, fatal) {
|
|
4588
|
-
if (check)
|
|
4589
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
4590
|
-
const r = check(data);
|
|
4591
|
-
if (r instanceof Promise) {
|
|
4592
|
-
return r.then((r2) => {
|
|
4593
|
-
if (!r2) {
|
|
4594
|
-
const params = cleanParams(_params, data);
|
|
4595
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
4596
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4597
|
-
}
|
|
4598
|
-
});
|
|
4599
|
-
}
|
|
4600
|
-
if (!r) {
|
|
4601
|
-
const params = cleanParams(_params, data);
|
|
4602
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
|
4603
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4604
|
-
}
|
|
4605
|
-
return;
|
|
4606
|
-
});
|
|
4607
|
-
return ZodAny.create();
|
|
4608
|
-
}
|
|
4609
|
-
var late = {
|
|
4610
|
-
object: ZodObject.lazycreate
|
|
4611
|
-
};
|
|
4612
|
-
var ZodFirstPartyTypeKind;
|
|
4613
|
-
(function(ZodFirstPartyTypeKind2) {
|
|
4614
|
-
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4615
|
-
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4616
|
-
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4617
|
-
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4618
|
-
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4619
|
-
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4620
|
-
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4621
|
-
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4622
|
-
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4623
|
-
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4624
|
-
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4625
|
-
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4626
|
-
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4627
|
-
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4628
|
-
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4629
|
-
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4630
|
-
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4631
|
-
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4632
|
-
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4633
|
-
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4634
|
-
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4635
|
-
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4636
|
-
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4637
|
-
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4638
|
-
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4639
|
-
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4640
|
-
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4641
|
-
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4642
|
-
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4643
|
-
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4644
|
-
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4645
|
-
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4646
|
-
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4647
|
-
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4648
|
-
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4649
|
-
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4650
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4651
|
-
var instanceOfType = (cls, params = {
|
|
4652
|
-
message: `Input not instance of ${cls.name}`
|
|
4653
|
-
}) => custom((data) => data instanceof cls, params);
|
|
4654
|
-
var stringType = ZodString.create;
|
|
4655
|
-
var numberType = ZodNumber.create;
|
|
4656
|
-
var nanType = ZodNaN.create;
|
|
4657
|
-
var bigIntType = ZodBigInt.create;
|
|
4658
|
-
var booleanType = ZodBoolean.create;
|
|
4659
|
-
var dateType = ZodDate.create;
|
|
4660
|
-
var symbolType = ZodSymbol.create;
|
|
4661
|
-
var undefinedType = ZodUndefined.create;
|
|
4662
|
-
var nullType = ZodNull.create;
|
|
4663
|
-
var anyType = ZodAny.create;
|
|
4664
|
-
var unknownType = ZodUnknown.create;
|
|
4665
|
-
var neverType = ZodNever.create;
|
|
4666
|
-
var voidType = ZodVoid.create;
|
|
4667
|
-
var arrayType = ZodArray.create;
|
|
4668
|
-
var objectType = ZodObject.create;
|
|
4669
|
-
var strictObjectType = ZodObject.strictCreate;
|
|
4670
|
-
var unionType = ZodUnion.create;
|
|
4671
|
-
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4672
|
-
var intersectionType = ZodIntersection.create;
|
|
4673
|
-
var tupleType = ZodTuple.create;
|
|
4674
|
-
var recordType = ZodRecord.create;
|
|
4675
|
-
var mapType = ZodMap.create;
|
|
4676
|
-
var setType = ZodSet.create;
|
|
4677
|
-
var functionType = ZodFunction.create;
|
|
4678
|
-
var lazyType = ZodLazy.create;
|
|
4679
|
-
var literalType = ZodLiteral.create;
|
|
4680
|
-
var enumType = ZodEnum.create;
|
|
4681
|
-
var nativeEnumType = ZodNativeEnum.create;
|
|
4682
|
-
var promiseType = ZodPromise.create;
|
|
4683
|
-
var effectsType = ZodEffects.create;
|
|
4684
|
-
var optionalType = ZodOptional.create;
|
|
4685
|
-
var nullableType = ZodNullable.create;
|
|
4686
|
-
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4687
|
-
var pipelineType = ZodPipeline.create;
|
|
4688
|
-
var ostring = () => stringType().optional();
|
|
4689
|
-
var onumber = () => numberType().optional();
|
|
4690
|
-
var oboolean = () => booleanType().optional();
|
|
4691
|
-
var coerce = {
|
|
4692
|
-
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4693
|
-
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4694
|
-
boolean: ((arg) => ZodBoolean.create({
|
|
4695
|
-
...arg,
|
|
4696
|
-
coerce: true
|
|
4697
|
-
})),
|
|
4698
|
-
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4699
|
-
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4700
|
-
};
|
|
4701
|
-
var NEVER = INVALID;
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// src/index.ts
|
|
655
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
656
|
+
import * as path8 from "path";
|
|
4702
657
|
|
|
4703
658
|
// src/config/schema.ts
|
|
4704
|
-
var
|
|
4705
|
-
"
|
|
4706
|
-
"
|
|
4707
|
-
"
|
|
4708
|
-
"
|
|
4709
|
-
"
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
search: SearchConfigSchema.optional(),
|
|
4732
|
-
include: external_exports.array(external_exports.string()).default([
|
|
4733
|
-
"**/*.{ts,tsx,js,jsx,mjs,cjs}",
|
|
4734
|
-
"**/*.{py,pyi}",
|
|
4735
|
-
"**/*.{go,rs,java,kt,scala}",
|
|
4736
|
-
"**/*.{c,cpp,cc,h,hpp}",
|
|
4737
|
-
"**/*.{rb,php,swift}",
|
|
4738
|
-
"**/*.{vue,svelte,astro}",
|
|
4739
|
-
"**/*.{sql,graphql,proto}",
|
|
4740
|
-
"**/*.{yaml,yml,toml}",
|
|
4741
|
-
"**/*.{md,mdx}",
|
|
4742
|
-
"**/*.{sh,bash,zsh}"
|
|
4743
|
-
]),
|
|
4744
|
-
exclude: external_exports.array(external_exports.string()).default([
|
|
4745
|
-
"**/node_modules/**",
|
|
4746
|
-
"**/.git/**",
|
|
4747
|
-
"**/dist/**",
|
|
4748
|
-
"**/build/**",
|
|
4749
|
-
"**/*.min.js",
|
|
4750
|
-
"**/*.bundle.js",
|
|
4751
|
-
"**/vendor/**",
|
|
4752
|
-
"**/__pycache__/**",
|
|
4753
|
-
"**/target/**",
|
|
4754
|
-
"**/coverage/**",
|
|
4755
|
-
"**/.next/**",
|
|
4756
|
-
"**/.nuxt/**",
|
|
4757
|
-
"**/.opencode/**"
|
|
4758
|
-
])
|
|
4759
|
-
});
|
|
659
|
+
var DEFAULT_INCLUDE = [
|
|
660
|
+
"**/*.{ts,tsx,js,jsx,mjs,cjs}",
|
|
661
|
+
"**/*.{py,pyi}",
|
|
662
|
+
"**/*.{go,rs,java,kt,scala}",
|
|
663
|
+
"**/*.{c,cpp,cc,h,hpp}",
|
|
664
|
+
"**/*.{rb,php,swift}",
|
|
665
|
+
"**/*.{vue,svelte,astro}",
|
|
666
|
+
"**/*.{sql,graphql,proto}",
|
|
667
|
+
"**/*.{yaml,yml,toml}",
|
|
668
|
+
"**/*.{md,mdx}",
|
|
669
|
+
"**/*.{sh,bash,zsh}"
|
|
670
|
+
];
|
|
671
|
+
var DEFAULT_EXCLUDE = [
|
|
672
|
+
"**/node_modules/**",
|
|
673
|
+
"**/.git/**",
|
|
674
|
+
"**/dist/**",
|
|
675
|
+
"**/build/**",
|
|
676
|
+
"**/*.min.js",
|
|
677
|
+
"**/*.bundle.js",
|
|
678
|
+
"**/vendor/**",
|
|
679
|
+
"**/__pycache__/**",
|
|
680
|
+
"**/target/**",
|
|
681
|
+
"**/coverage/**",
|
|
682
|
+
"**/.next/**",
|
|
683
|
+
"**/.nuxt/**",
|
|
684
|
+
"**/.opencode/**"
|
|
685
|
+
];
|
|
4760
686
|
function getDefaultIndexingConfig() {
|
|
4761
687
|
return {
|
|
4762
688
|
autoIndex: false,
|
|
@@ -4775,17 +701,47 @@ function getDefaultSearchConfig() {
|
|
|
4775
701
|
contextLines: 0
|
|
4776
702
|
};
|
|
4777
703
|
}
|
|
704
|
+
var VALID_PROVIDERS = ["auto", "github-copilot", "openai", "google", "ollama"];
|
|
705
|
+
var VALID_SCOPES = ["project", "global"];
|
|
706
|
+
function isValidProvider(value) {
|
|
707
|
+
return typeof value === "string" && VALID_PROVIDERS.includes(value);
|
|
708
|
+
}
|
|
709
|
+
function isValidScope(value) {
|
|
710
|
+
return typeof value === "string" && VALID_SCOPES.includes(value);
|
|
711
|
+
}
|
|
712
|
+
function isStringArray(value) {
|
|
713
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
714
|
+
}
|
|
4778
715
|
function parseConfig(raw) {
|
|
4779
|
-
const
|
|
716
|
+
const input = raw && typeof raw === "object" ? raw : {};
|
|
717
|
+
const defaultIndexing = getDefaultIndexingConfig();
|
|
718
|
+
const defaultSearch = getDefaultSearchConfig();
|
|
719
|
+
const rawIndexing = input.indexing && typeof input.indexing === "object" ? input.indexing : {};
|
|
720
|
+
const indexing = {
|
|
721
|
+
autoIndex: typeof rawIndexing.autoIndex === "boolean" ? rawIndexing.autoIndex : defaultIndexing.autoIndex,
|
|
722
|
+
watchFiles: typeof rawIndexing.watchFiles === "boolean" ? rawIndexing.watchFiles : defaultIndexing.watchFiles,
|
|
723
|
+
maxFileSize: typeof rawIndexing.maxFileSize === "number" ? rawIndexing.maxFileSize : defaultIndexing.maxFileSize,
|
|
724
|
+
retries: typeof rawIndexing.retries === "number" ? rawIndexing.retries : defaultIndexing.retries,
|
|
725
|
+
retryDelayMs: typeof rawIndexing.retryDelayMs === "number" ? rawIndexing.retryDelayMs : defaultIndexing.retryDelayMs
|
|
726
|
+
};
|
|
727
|
+
const rawSearch = input.search && typeof input.search === "object" ? input.search : {};
|
|
728
|
+
const search = {
|
|
729
|
+
maxResults: typeof rawSearch.maxResults === "number" ? rawSearch.maxResults : defaultSearch.maxResults,
|
|
730
|
+
minScore: typeof rawSearch.minScore === "number" ? rawSearch.minScore : defaultSearch.minScore,
|
|
731
|
+
includeContext: typeof rawSearch.includeContext === "boolean" ? rawSearch.includeContext : defaultSearch.includeContext,
|
|
732
|
+
hybridWeight: typeof rawSearch.hybridWeight === "number" ? Math.min(1, Math.max(0, rawSearch.hybridWeight)) : defaultSearch.hybridWeight,
|
|
733
|
+
contextLines: typeof rawSearch.contextLines === "number" ? Math.min(50, Math.max(0, rawSearch.contextLines)) : defaultSearch.contextLines
|
|
734
|
+
};
|
|
4780
735
|
return {
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
736
|
+
embeddingProvider: isValidProvider(input.embeddingProvider) ? input.embeddingProvider : "auto",
|
|
737
|
+
embeddingModel: typeof input.embeddingModel === "string" ? input.embeddingModel : "auto",
|
|
738
|
+
scope: isValidScope(input.scope) ? input.scope : "project",
|
|
739
|
+
include: isStringArray(input.include) ? input.include : DEFAULT_INCLUDE,
|
|
740
|
+
exclude: isStringArray(input.exclude) ? input.exclude : DEFAULT_EXCLUDE,
|
|
741
|
+
indexing,
|
|
742
|
+
search
|
|
4784
743
|
};
|
|
4785
744
|
}
|
|
4786
|
-
function getDefaultConfig() {
|
|
4787
|
-
return CodebaseIndexConfigSchema.parse({});
|
|
4788
|
-
}
|
|
4789
745
|
var EMBEDDING_MODELS = {
|
|
4790
746
|
"github-copilot/text-embedding-3-small": {
|
|
4791
747
|
provider: "github-copilot",
|
|
@@ -4841,7 +797,7 @@ function getDefaultModelForProvider(provider) {
|
|
|
4841
797
|
case "ollama":
|
|
4842
798
|
return EMBEDDING_MODELS["ollama/nomic-embed-text"];
|
|
4843
799
|
default:
|
|
4844
|
-
return EMBEDDING_MODELS["github/text-embedding-3-small"];
|
|
800
|
+
return EMBEDDING_MODELS["github-copilot/text-embedding-3-small"];
|
|
4845
801
|
}
|
|
4846
802
|
}
|
|
4847
803
|
|
|
@@ -5671,8 +1627,8 @@ var errorMessages = /* @__PURE__ */ new Set([
|
|
|
5671
1627
|
// Cloudflare Workers (fetch)
|
|
5672
1628
|
]);
|
|
5673
1629
|
function isNetworkError(error) {
|
|
5674
|
-
const
|
|
5675
|
-
if (!
|
|
1630
|
+
const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
|
|
1631
|
+
if (!isValid) {
|
|
5676
1632
|
return false;
|
|
5677
1633
|
}
|
|
5678
1634
|
const { message, stack } = error;
|
|
@@ -6339,9 +2295,6 @@ async function collectFiles(projectRoot, includePatterns, excludePatterns, maxFi
|
|
|
6339
2295
|
}
|
|
6340
2296
|
|
|
6341
2297
|
// src/utils/cost.ts
|
|
6342
|
-
function estimateTokens(text) {
|
|
6343
|
-
return Math.ceil(text.length / 4);
|
|
6344
|
-
}
|
|
6345
2298
|
function estimateChunksFromFiles(files) {
|
|
6346
2299
|
let totalChunks = 0;
|
|
6347
2300
|
for (const file of files) {
|
|
@@ -6402,25 +2355,6 @@ function formatBytes(bytes) {
|
|
|
6402
2355
|
function padRight(str, length) {
|
|
6403
2356
|
return str.padEnd(length);
|
|
6404
2357
|
}
|
|
6405
|
-
function formatConfirmationPrompt() {
|
|
6406
|
-
return `
|
|
6407
|
-
Proceed with indexing? [Y/n/always]
|
|
6408
|
-
|
|
6409
|
-
Y - Index now
|
|
6410
|
-
n - Cancel
|
|
6411
|
-
always - Index now and don't ask again for this project
|
|
6412
|
-
`;
|
|
6413
|
-
}
|
|
6414
|
-
function parseConfirmationResponse(response) {
|
|
6415
|
-
const normalized = response.toLowerCase().trim();
|
|
6416
|
-
if (normalized === "" || normalized === "y" || normalized === "yes") {
|
|
6417
|
-
return { confirmed: true, rememberChoice: false };
|
|
6418
|
-
}
|
|
6419
|
-
if (normalized === "always" || normalized === "a") {
|
|
6420
|
-
return { confirmed: true, rememberChoice: true };
|
|
6421
|
-
}
|
|
6422
|
-
return { confirmed: false, rememberChoice: false };
|
|
6423
|
-
}
|
|
6424
2358
|
|
|
6425
2359
|
// src/native/index.ts
|
|
6426
2360
|
import * as path4 from "path";
|
|
@@ -6457,10 +2391,6 @@ function getNativeBinding() {
|
|
|
6457
2391
|
return __require(nativePath);
|
|
6458
2392
|
}
|
|
6459
2393
|
var native = getNativeBinding();
|
|
6460
|
-
function parseFile(filePath, content) {
|
|
6461
|
-
const result = native.parseFile(filePath, content);
|
|
6462
|
-
return result.map(mapChunk);
|
|
6463
|
-
}
|
|
6464
2394
|
function parseFiles(files) {
|
|
6465
2395
|
const result = native.parseFiles(files);
|
|
6466
2396
|
return result.map((f) => ({
|
|
@@ -6558,7 +2488,7 @@ var VectorStore = class {
|
|
|
6558
2488
|
var CHARS_PER_TOKEN = 4;
|
|
6559
2489
|
var MAX_BATCH_TOKENS = 7500;
|
|
6560
2490
|
var MAX_SINGLE_CHUNK_TOKENS = 2e3;
|
|
6561
|
-
function
|
|
2491
|
+
function estimateTokens(text) {
|
|
6562
2492
|
return Math.ceil(text.length / CHARS_PER_TOKEN);
|
|
6563
2493
|
}
|
|
6564
2494
|
function createEmbeddingText(chunk, filePath) {
|
|
@@ -6623,7 +2553,7 @@ function createDynamicBatches(chunks) {
|
|
|
6623
2553
|
let currentBatch = [];
|
|
6624
2554
|
let currentTokens = 0;
|
|
6625
2555
|
for (const chunk of chunks) {
|
|
6626
|
-
const chunkTokens =
|
|
2556
|
+
const chunkTokens = estimateTokens(chunk.text);
|
|
6627
2557
|
if (currentBatch.length > 0 && currentTokens + chunkTokens > MAX_BATCH_TOKENS) {
|
|
6628
2558
|
batches.push(currentBatch);
|
|
6629
2559
|
currentBatch = [];
|
|
@@ -9179,7 +5109,7 @@ var codebase_search = tool({
|
|
|
9179
5109
|
},
|
|
9180
5110
|
async execute(args) {
|
|
9181
5111
|
const indexer = getIndexer();
|
|
9182
|
-
const results = await indexer.search(args.query, args.limit, {
|
|
5112
|
+
const results = await indexer.search(args.query, args.limit ?? 10, {
|
|
9183
5113
|
fileType: args.fileType,
|
|
9184
5114
|
directory: args.directory,
|
|
9185
5115
|
chunkType: args.chunkType,
|
|
@@ -9217,7 +5147,7 @@ var index_codebase = tool({
|
|
|
9217
5147
|
await indexer.clearIndex();
|
|
9218
5148
|
}
|
|
9219
5149
|
const stats = await indexer.index();
|
|
9220
|
-
return formatIndexStats(stats, args.verbose);
|
|
5150
|
+
return formatIndexStats(stats, args.verbose ?? false);
|
|
9221
5151
|
}
|
|
9222
5152
|
});
|
|
9223
5153
|
var index_status = tool({
|
|
@@ -9344,42 +5274,7 @@ var plugin = async ({ directory }) => {
|
|
|
9344
5274
|
};
|
|
9345
5275
|
var index_default = plugin;
|
|
9346
5276
|
export {
|
|
9347
|
-
|
|
9348
|
-
EMBEDDING_MODELS,
|
|
9349
|
-
EmbeddingProviderSchema,
|
|
9350
|
-
FileWatcher,
|
|
9351
|
-
IndexScopeSchema,
|
|
9352
|
-
Indexer,
|
|
9353
|
-
IndexingConfigSchema,
|
|
9354
|
-
SearchConfigSchema,
|
|
9355
|
-
VectorStore,
|
|
9356
|
-
collectFiles,
|
|
9357
|
-
createCostEstimate,
|
|
9358
|
-
createDynamicBatches,
|
|
9359
|
-
createEmbeddingProvider,
|
|
9360
|
-
createEmbeddingText,
|
|
9361
|
-
createIgnoreFilter,
|
|
9362
|
-
index_default as default,
|
|
9363
|
-
detectEmbeddingProvider,
|
|
9364
|
-
estimateChunksFromFiles,
|
|
9365
|
-
estimateCost,
|
|
9366
|
-
estimateTokens,
|
|
9367
|
-
formatBytes,
|
|
9368
|
-
formatConfirmationPrompt,
|
|
9369
|
-
formatCostEstimate,
|
|
9370
|
-
generateChunkHash,
|
|
9371
|
-
generateChunkId,
|
|
9372
|
-
getDefaultConfig,
|
|
9373
|
-
getDefaultModelForProvider,
|
|
9374
|
-
getProviderDisplayName,
|
|
9375
|
-
hashContent,
|
|
9376
|
-
hashFile,
|
|
9377
|
-
parseConfig,
|
|
9378
|
-
parseConfirmationResponse,
|
|
9379
|
-
parseFile,
|
|
9380
|
-
parseFiles,
|
|
9381
|
-
shouldIncludeFile,
|
|
9382
|
-
walkDirectory
|
|
5277
|
+
index_default as default
|
|
9383
5278
|
};
|
|
9384
5279
|
/*! Bundled license information:
|
|
9385
5280
|
|