linkque-cli-v2 1.6.27 → 1.6.28
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/linkquejs.js +4222 -1507
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-XUFLSZM4.js → chunk-33Q6KVN2.js} +60 -196
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-TX2XRFJ4.js → chunk-BMMEXZ52.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-PYP7WCXN.js → chunk-BQHLF2GE.js} +3979 -138
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-KQTRZ2SZ.js +19744 -0
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-GDCT36JV.js → chunk-NA35NOK4.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-2QJITP7G.js → chunk-RTUO3ZWI.js} +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-FC7MJHC3.js → chunk-TIXVMTXT.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{dist-6U5W3RLM.js → dist-JRQ7GIV4.js} +31 -46
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-generative-ai-RT2OOQDJ.js → google-generative-ai-5VYDRFFM.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{google-vertex-HVFMVQVY.js → google-vertex-JO4CT7NF.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{mistral-conversations-KIOTOF73.js → mistral-conversations-43TLMTO6.js} +4 -4
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{multipart-parser-TAD6XL3Q.js → multipart-parser-HCLTR6CW.js} +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{otel-LQR5KPZ3.js → otel-UCKXDLYZ.js} +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +340 -7477
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +4 -4
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +4 -4
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{src-JSJTYJV5.js → src-MFXPXO5F.js} +25 -25
- package/worker.js +226177 -220585
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/chunk-GAYNLDWK.js +0 -11166
package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-PYP7WCXN.js → chunk-BQHLF2GE.js}
RENAMED
|
@@ -1,118 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BRAND,
|
|
3
|
-
DIRTY,
|
|
4
|
-
EMPTY_PATH,
|
|
5
|
-
INVALID,
|
|
6
2
|
NEVER,
|
|
7
|
-
OK,
|
|
8
|
-
ParseStatus,
|
|
9
|
-
ZodAny,
|
|
10
|
-
ZodArray,
|
|
11
|
-
ZodBigInt,
|
|
12
|
-
ZodBoolean,
|
|
13
|
-
ZodBranded,
|
|
14
|
-
ZodCatch,
|
|
15
|
-
ZodDate,
|
|
16
|
-
ZodDefault,
|
|
17
|
-
ZodDiscriminatedUnion,
|
|
18
|
-
ZodEffects,
|
|
19
|
-
ZodEnum,
|
|
20
|
-
ZodError,
|
|
21
|
-
ZodFirstPartyTypeKind,
|
|
22
|
-
ZodFunction,
|
|
23
|
-
ZodIntersection,
|
|
24
3
|
ZodIssueCode,
|
|
25
|
-
ZodLazy,
|
|
26
|
-
ZodLiteral,
|
|
27
|
-
ZodMap,
|
|
28
|
-
ZodNaN,
|
|
29
|
-
ZodNativeEnum,
|
|
30
|
-
ZodNever,
|
|
31
|
-
ZodNull,
|
|
32
|
-
ZodNullable,
|
|
33
|
-
ZodNumber,
|
|
34
|
-
ZodObject,
|
|
35
|
-
ZodOptional,
|
|
36
|
-
ZodParsedType,
|
|
37
|
-
ZodPipeline,
|
|
38
|
-
ZodPromise,
|
|
39
|
-
ZodReadonly,
|
|
40
|
-
ZodRecord,
|
|
41
|
-
ZodSet,
|
|
42
|
-
ZodString,
|
|
43
|
-
ZodSymbol,
|
|
44
|
-
ZodTuple,
|
|
45
|
-
ZodType,
|
|
46
|
-
ZodUndefined,
|
|
47
|
-
ZodUnion,
|
|
48
|
-
ZodUnknown,
|
|
49
|
-
ZodVoid,
|
|
50
|
-
addIssueToContext,
|
|
51
|
-
anyType,
|
|
52
|
-
arrayType,
|
|
53
|
-
bigIntType,
|
|
54
|
-
booleanType,
|
|
55
|
-
coerce,
|
|
56
|
-
custom,
|
|
57
|
-
dateType,
|
|
58
|
-
datetimeRegex,
|
|
59
|
-
discriminatedUnionType,
|
|
60
|
-
effectsType,
|
|
61
|
-
en_default,
|
|
62
|
-
enumType,
|
|
63
|
-
functionType,
|
|
64
|
-
getErrorMap,
|
|
65
|
-
getParsedType,
|
|
66
|
-
instanceOfType,
|
|
67
|
-
intersectionType,
|
|
68
|
-
isAborted,
|
|
69
|
-
isAsync,
|
|
70
|
-
isDirty,
|
|
71
|
-
isValid,
|
|
72
|
-
late,
|
|
73
|
-
lazyType,
|
|
74
|
-
literalType,
|
|
75
|
-
makeIssue,
|
|
76
|
-
mapType,
|
|
77
|
-
nanType,
|
|
78
|
-
nativeEnumType,
|
|
79
|
-
neverType,
|
|
80
|
-
nullType,
|
|
81
|
-
nullableType,
|
|
82
|
-
numberType,
|
|
83
|
-
objectType,
|
|
84
|
-
objectUtil,
|
|
85
|
-
oboolean,
|
|
86
|
-
onumber,
|
|
87
|
-
optionalType,
|
|
88
|
-
ostring,
|
|
89
|
-
pipelineType,
|
|
90
|
-
preprocessType,
|
|
91
|
-
promiseType,
|
|
92
|
-
quotelessJson,
|
|
93
|
-
recordType,
|
|
94
|
-
setErrorMap,
|
|
95
|
-
setType,
|
|
96
|
-
strictObjectType,
|
|
97
|
-
stringType,
|
|
98
|
-
symbolType,
|
|
99
|
-
tupleType,
|
|
100
|
-
undefinedType,
|
|
101
|
-
unionType,
|
|
102
|
-
unknownType,
|
|
103
|
-
util,
|
|
104
|
-
voidType
|
|
105
|
-
} from "./chunk-XUFLSZM4.js";
|
|
106
|
-
import {
|
|
107
|
-
NEVER as NEVER2,
|
|
108
|
-
ZodIssueCode as ZodIssueCode2,
|
|
109
4
|
_enum,
|
|
110
5
|
_null,
|
|
111
6
|
any,
|
|
112
7
|
array,
|
|
113
8
|
boolean,
|
|
114
9
|
coerce_exports,
|
|
115
|
-
custom
|
|
10
|
+
custom,
|
|
116
11
|
discriminatedUnion,
|
|
117
12
|
intersection,
|
|
118
13
|
iso_exports,
|
|
@@ -128,7 +23,7 @@ import {
|
|
|
128
23
|
union,
|
|
129
24
|
unknown,
|
|
130
25
|
url
|
|
131
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-KQTRZ2SZ.js";
|
|
132
27
|
import {
|
|
133
28
|
ROOT_CONTEXT,
|
|
134
29
|
SpanKind,
|
|
@@ -1261,9 +1156,9 @@ var require_util = __commonJS({
|
|
|
1261
1156
|
}
|
|
1262
1157
|
}
|
|
1263
1158
|
exports.eachItem = eachItem;
|
|
1264
|
-
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName }) {
|
|
1159
|
+
function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues: mergeValues2, resultToName }) {
|
|
1265
1160
|
return (gen, from, to, toName) => {
|
|
1266
|
-
const res = to === void 0 ? from : to instanceof codegen_1.Name ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1.Name ? (mergeToName(gen, to, from), from) :
|
|
1161
|
+
const res = to === void 0 ? from : to instanceof codegen_1.Name ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to) : from instanceof codegen_1.Name ? (mergeToName(gen, to, from), from) : mergeValues2(from, to);
|
|
1267
1162
|
return toName === codegen_1.Name && !(res instanceof codegen_1.Name) ? resultToName(gen, res) : res;
|
|
1268
1163
|
};
|
|
1269
1164
|
}
|
|
@@ -1987,8 +1882,8 @@ var require_keyword = __commonJS({
|
|
|
1987
1882
|
var _a2;
|
|
1988
1883
|
const { gen, keyword, schema, parentSchema, $data, it } = cxt;
|
|
1989
1884
|
checkAsyncKeyword(it, def);
|
|
1990
|
-
const
|
|
1991
|
-
const validateRef = useKeyword(gen, keyword,
|
|
1885
|
+
const validate2 = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate;
|
|
1886
|
+
const validateRef = useKeyword(gen, keyword, validate2);
|
|
1992
1887
|
const valid = gen.let("valid");
|
|
1993
1888
|
cxt.block$data(valid, validateKeyword);
|
|
1994
1889
|
cxt.ok((_a2 = def.valid) !== null && _a2 !== void 0 ? _a2 : valid);
|
|
@@ -1999,13 +1894,13 @@ var require_keyword = __commonJS({
|
|
|
1999
1894
|
modifyData(cxt);
|
|
2000
1895
|
reportErrs(() => cxt.error());
|
|
2001
1896
|
} else {
|
|
2002
|
-
const ruleErrs = def.async ?
|
|
1897
|
+
const ruleErrs = def.async ? validateAsync2() : validateSync();
|
|
2003
1898
|
if (def.modifying)
|
|
2004
1899
|
modifyData(cxt);
|
|
2005
1900
|
reportErrs(() => addErrs(cxt, ruleErrs));
|
|
2006
1901
|
}
|
|
2007
1902
|
}
|
|
2008
|
-
function
|
|
1903
|
+
function validateAsync2() {
|
|
2009
1904
|
const ruleErrs = gen.let("ruleErrs", null);
|
|
2010
1905
|
gen.try(() => assignValid((0, codegen_1._)`await `), (e) => gen.assign(valid, false).if((0, codegen_1._)`${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._)`${e}.errors`), () => gen.throw(e)));
|
|
2011
1906
|
return ruleErrs;
|
|
@@ -3061,28 +2956,28 @@ var require_compile = __commonJS({
|
|
|
3061
2956
|
if (this.opts.code.process)
|
|
3062
2957
|
sourceCode = this.opts.code.process(sourceCode, sch);
|
|
3063
2958
|
const makeValidate = new Function(`${names_1.default.self}`, `${names_1.default.scope}`, sourceCode);
|
|
3064
|
-
const
|
|
3065
|
-
this.scope.value(validateName, { ref:
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
2959
|
+
const validate2 = makeValidate(this, this.scope.get());
|
|
2960
|
+
this.scope.value(validateName, { ref: validate2 });
|
|
2961
|
+
validate2.errors = null;
|
|
2962
|
+
validate2.schema = sch.schema;
|
|
2963
|
+
validate2.schemaEnv = sch;
|
|
3069
2964
|
if (sch.$async)
|
|
3070
|
-
|
|
2965
|
+
validate2.$async = true;
|
|
3071
2966
|
if (this.opts.code.source === true) {
|
|
3072
|
-
|
|
2967
|
+
validate2.source = { validateName, validateCode, scopeValues: gen._values };
|
|
3073
2968
|
}
|
|
3074
2969
|
if (this.opts.unevaluated) {
|
|
3075
2970
|
const { props, items } = schemaCxt;
|
|
3076
|
-
|
|
2971
|
+
validate2.evaluated = {
|
|
3077
2972
|
props: props instanceof codegen_1.Name ? void 0 : props,
|
|
3078
2973
|
items: items instanceof codegen_1.Name ? void 0 : items,
|
|
3079
2974
|
dynamicProps: props instanceof codegen_1.Name,
|
|
3080
2975
|
dynamicItems: items instanceof codegen_1.Name
|
|
3081
2976
|
};
|
|
3082
|
-
if (
|
|
3083
|
-
|
|
2977
|
+
if (validate2.source)
|
|
2978
|
+
validate2.source.evaluated = (0, codegen_1.stringify)(validate2.evaluated);
|
|
3084
2979
|
}
|
|
3085
|
-
sch.validate =
|
|
2980
|
+
sch.validate = validate2;
|
|
3086
2981
|
return sch;
|
|
3087
2982
|
} catch (e) {
|
|
3088
2983
|
delete sch.validate;
|
|
@@ -8570,8 +8465,8 @@ var require_formats = __commonJS({
|
|
|
8570
8465
|
"use strict";
|
|
8571
8466
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8572
8467
|
exports.formatNames = exports.fastFormats = exports.fullFormats = void 0;
|
|
8573
|
-
function fmtDef(
|
|
8574
|
-
return { validate, compare };
|
|
8468
|
+
function fmtDef(validate2, compare) {
|
|
8469
|
+
return { validate: validate2, compare };
|
|
8575
8470
|
}
|
|
8576
8471
|
exports.fullFormats = {
|
|
8577
8472
|
// date: http://tools.ietf.org/html/rfc3339#section-5.6
|
|
@@ -22522,7 +22417,7 @@ var require_util5 = __commonJS({
|
|
|
22522
22417
|
if (encoding === "failure") {
|
|
22523
22418
|
encoding = "UTF-8";
|
|
22524
22419
|
}
|
|
22525
|
-
return
|
|
22420
|
+
return decode2(bytes2, encoding);
|
|
22526
22421
|
}
|
|
22527
22422
|
case "ArrayBuffer": {
|
|
22528
22423
|
const sequence = combineByteSequences(bytes2);
|
|
@@ -22539,7 +22434,7 @@ var require_util5 = __commonJS({
|
|
|
22539
22434
|
}
|
|
22540
22435
|
}
|
|
22541
22436
|
}
|
|
22542
|
-
function
|
|
22437
|
+
function decode2(ioQueue, encoding) {
|
|
22543
22438
|
const bytes2 = combineByteSequences(ioQueue);
|
|
22544
22439
|
const BOMEncoding = BOMSniffing(bytes2);
|
|
22545
22440
|
let slice = 0;
|
|
@@ -41196,14 +41091,14 @@ function getRunEmbeddedQuery(request2) {
|
|
|
41196
41091
|
return value;
|
|
41197
41092
|
}
|
|
41198
41093
|
|
|
41199
|
-
// ../../node_modules/zod/v3/external.js
|
|
41094
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/external.js
|
|
41200
41095
|
var external_exports = {};
|
|
41201
41096
|
__export(external_exports, {
|
|
41202
41097
|
BRAND: () => BRAND,
|
|
41203
41098
|
DIRTY: () => DIRTY,
|
|
41204
41099
|
EMPTY_PATH: () => EMPTY_PATH,
|
|
41205
41100
|
INVALID: () => INVALID,
|
|
41206
|
-
NEVER: () =>
|
|
41101
|
+
NEVER: () => NEVER2,
|
|
41207
41102
|
OK: () => OK,
|
|
41208
41103
|
ParseStatus: () => ParseStatus,
|
|
41209
41104
|
Schema: () => ZodType,
|
|
@@ -41222,7 +41117,7 @@ __export(external_exports, {
|
|
|
41222
41117
|
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
41223
41118
|
ZodFunction: () => ZodFunction,
|
|
41224
41119
|
ZodIntersection: () => ZodIntersection,
|
|
41225
|
-
ZodIssueCode: () =>
|
|
41120
|
+
ZodIssueCode: () => ZodIssueCode2,
|
|
41226
41121
|
ZodLazy: () => ZodLazy,
|
|
41227
41122
|
ZodLiteral: () => ZodLiteral,
|
|
41228
41123
|
ZodMap: () => ZodMap,
|
|
@@ -41256,7 +41151,7 @@ __export(external_exports, {
|
|
|
41256
41151
|
bigint: () => bigIntType,
|
|
41257
41152
|
boolean: () => booleanType,
|
|
41258
41153
|
coerce: () => coerce,
|
|
41259
|
-
custom: () =>
|
|
41154
|
+
custom: () => custom2,
|
|
41260
41155
|
date: () => dateType,
|
|
41261
41156
|
datetimeRegex: () => datetimeRegex,
|
|
41262
41157
|
defaultErrorMap: () => en_default,
|
|
@@ -41308,6 +41203,3935 @@ __export(external_exports, {
|
|
|
41308
41203
|
void: () => voidType
|
|
41309
41204
|
});
|
|
41310
41205
|
|
|
41206
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/util.js
|
|
41207
|
+
var util;
|
|
41208
|
+
(function(util2) {
|
|
41209
|
+
util2.assertEqual = (_) => {
|
|
41210
|
+
};
|
|
41211
|
+
function assertIs(_arg) {
|
|
41212
|
+
}
|
|
41213
|
+
util2.assertIs = assertIs;
|
|
41214
|
+
function assertNever(_x) {
|
|
41215
|
+
throw new Error();
|
|
41216
|
+
}
|
|
41217
|
+
util2.assertNever = assertNever;
|
|
41218
|
+
util2.arrayToEnum = (items) => {
|
|
41219
|
+
const obj = {};
|
|
41220
|
+
for (const item of items) {
|
|
41221
|
+
obj[item] = item;
|
|
41222
|
+
}
|
|
41223
|
+
return obj;
|
|
41224
|
+
};
|
|
41225
|
+
util2.getValidEnumValues = (obj) => {
|
|
41226
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
41227
|
+
const filtered = {};
|
|
41228
|
+
for (const k of validKeys) {
|
|
41229
|
+
filtered[k] = obj[k];
|
|
41230
|
+
}
|
|
41231
|
+
return util2.objectValues(filtered);
|
|
41232
|
+
};
|
|
41233
|
+
util2.objectValues = (obj) => {
|
|
41234
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
41235
|
+
return obj[e];
|
|
41236
|
+
});
|
|
41237
|
+
};
|
|
41238
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object3) => {
|
|
41239
|
+
const keys2 = [];
|
|
41240
|
+
for (const key in object3) {
|
|
41241
|
+
if (Object.prototype.hasOwnProperty.call(object3, key)) {
|
|
41242
|
+
keys2.push(key);
|
|
41243
|
+
}
|
|
41244
|
+
}
|
|
41245
|
+
return keys2;
|
|
41246
|
+
};
|
|
41247
|
+
util2.find = (arr, checker) => {
|
|
41248
|
+
for (const item of arr) {
|
|
41249
|
+
if (checker(item))
|
|
41250
|
+
return item;
|
|
41251
|
+
}
|
|
41252
|
+
return void 0;
|
|
41253
|
+
};
|
|
41254
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
41255
|
+
function joinValues(array2, separator = " | ") {
|
|
41256
|
+
return array2.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
41257
|
+
}
|
|
41258
|
+
util2.joinValues = joinValues;
|
|
41259
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
41260
|
+
if (typeof value === "bigint") {
|
|
41261
|
+
return value.toString();
|
|
41262
|
+
}
|
|
41263
|
+
return value;
|
|
41264
|
+
};
|
|
41265
|
+
})(util || (util = {}));
|
|
41266
|
+
var objectUtil;
|
|
41267
|
+
(function(objectUtil2) {
|
|
41268
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
41269
|
+
return {
|
|
41270
|
+
...first,
|
|
41271
|
+
...second
|
|
41272
|
+
// second overwrites first
|
|
41273
|
+
};
|
|
41274
|
+
};
|
|
41275
|
+
})(objectUtil || (objectUtil = {}));
|
|
41276
|
+
var ZodParsedType = util.arrayToEnum([
|
|
41277
|
+
"string",
|
|
41278
|
+
"nan",
|
|
41279
|
+
"number",
|
|
41280
|
+
"integer",
|
|
41281
|
+
"float",
|
|
41282
|
+
"boolean",
|
|
41283
|
+
"date",
|
|
41284
|
+
"bigint",
|
|
41285
|
+
"symbol",
|
|
41286
|
+
"function",
|
|
41287
|
+
"undefined",
|
|
41288
|
+
"null",
|
|
41289
|
+
"array",
|
|
41290
|
+
"object",
|
|
41291
|
+
"unknown",
|
|
41292
|
+
"promise",
|
|
41293
|
+
"void",
|
|
41294
|
+
"never",
|
|
41295
|
+
"map",
|
|
41296
|
+
"set"
|
|
41297
|
+
]);
|
|
41298
|
+
var getParsedType = (data) => {
|
|
41299
|
+
const t = typeof data;
|
|
41300
|
+
switch (t) {
|
|
41301
|
+
case "undefined":
|
|
41302
|
+
return ZodParsedType.undefined;
|
|
41303
|
+
case "string":
|
|
41304
|
+
return ZodParsedType.string;
|
|
41305
|
+
case "number":
|
|
41306
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
41307
|
+
case "boolean":
|
|
41308
|
+
return ZodParsedType.boolean;
|
|
41309
|
+
case "function":
|
|
41310
|
+
return ZodParsedType.function;
|
|
41311
|
+
case "bigint":
|
|
41312
|
+
return ZodParsedType.bigint;
|
|
41313
|
+
case "symbol":
|
|
41314
|
+
return ZodParsedType.symbol;
|
|
41315
|
+
case "object":
|
|
41316
|
+
if (Array.isArray(data)) {
|
|
41317
|
+
return ZodParsedType.array;
|
|
41318
|
+
}
|
|
41319
|
+
if (data === null) {
|
|
41320
|
+
return ZodParsedType.null;
|
|
41321
|
+
}
|
|
41322
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
41323
|
+
return ZodParsedType.promise;
|
|
41324
|
+
}
|
|
41325
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
41326
|
+
return ZodParsedType.map;
|
|
41327
|
+
}
|
|
41328
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
41329
|
+
return ZodParsedType.set;
|
|
41330
|
+
}
|
|
41331
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
41332
|
+
return ZodParsedType.date;
|
|
41333
|
+
}
|
|
41334
|
+
return ZodParsedType.object;
|
|
41335
|
+
default:
|
|
41336
|
+
return ZodParsedType.unknown;
|
|
41337
|
+
}
|
|
41338
|
+
};
|
|
41339
|
+
|
|
41340
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/ZodError.js
|
|
41341
|
+
var ZodIssueCode2 = util.arrayToEnum([
|
|
41342
|
+
"invalid_type",
|
|
41343
|
+
"invalid_literal",
|
|
41344
|
+
"custom",
|
|
41345
|
+
"invalid_union",
|
|
41346
|
+
"invalid_union_discriminator",
|
|
41347
|
+
"invalid_enum_value",
|
|
41348
|
+
"unrecognized_keys",
|
|
41349
|
+
"invalid_arguments",
|
|
41350
|
+
"invalid_return_type",
|
|
41351
|
+
"invalid_date",
|
|
41352
|
+
"invalid_string",
|
|
41353
|
+
"too_small",
|
|
41354
|
+
"too_big",
|
|
41355
|
+
"invalid_intersection_types",
|
|
41356
|
+
"not_multiple_of",
|
|
41357
|
+
"not_finite"
|
|
41358
|
+
]);
|
|
41359
|
+
var quotelessJson = (obj) => {
|
|
41360
|
+
const json = JSON.stringify(obj, null, 2);
|
|
41361
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
41362
|
+
};
|
|
41363
|
+
var ZodError = class _ZodError extends Error {
|
|
41364
|
+
get errors() {
|
|
41365
|
+
return this.issues;
|
|
41366
|
+
}
|
|
41367
|
+
constructor(issues) {
|
|
41368
|
+
super();
|
|
41369
|
+
this.issues = [];
|
|
41370
|
+
this.addIssue = (sub) => {
|
|
41371
|
+
this.issues = [...this.issues, sub];
|
|
41372
|
+
};
|
|
41373
|
+
this.addIssues = (subs = []) => {
|
|
41374
|
+
this.issues = [...this.issues, ...subs];
|
|
41375
|
+
};
|
|
41376
|
+
const actualProto = new.target.prototype;
|
|
41377
|
+
if (Object.setPrototypeOf) {
|
|
41378
|
+
Object.setPrototypeOf(this, actualProto);
|
|
41379
|
+
} else {
|
|
41380
|
+
this.__proto__ = actualProto;
|
|
41381
|
+
}
|
|
41382
|
+
this.name = "ZodError";
|
|
41383
|
+
this.issues = issues;
|
|
41384
|
+
}
|
|
41385
|
+
format(_mapper) {
|
|
41386
|
+
const mapper = _mapper || function(issue3) {
|
|
41387
|
+
return issue3.message;
|
|
41388
|
+
};
|
|
41389
|
+
const fieldErrors = { _errors: [] };
|
|
41390
|
+
const processError = (error) => {
|
|
41391
|
+
for (const issue3 of error.issues) {
|
|
41392
|
+
if (issue3.code === "invalid_union") {
|
|
41393
|
+
issue3.unionErrors.map(processError);
|
|
41394
|
+
} else if (issue3.code === "invalid_return_type") {
|
|
41395
|
+
processError(issue3.returnTypeError);
|
|
41396
|
+
} else if (issue3.code === "invalid_arguments") {
|
|
41397
|
+
processError(issue3.argumentsError);
|
|
41398
|
+
} else if (issue3.path.length === 0) {
|
|
41399
|
+
fieldErrors._errors.push(mapper(issue3));
|
|
41400
|
+
} else {
|
|
41401
|
+
let curr = fieldErrors;
|
|
41402
|
+
let i = 0;
|
|
41403
|
+
while (i < issue3.path.length) {
|
|
41404
|
+
const el = issue3.path[i];
|
|
41405
|
+
const terminal = i === issue3.path.length - 1;
|
|
41406
|
+
if (!terminal) {
|
|
41407
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
41408
|
+
} else {
|
|
41409
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
41410
|
+
curr[el]._errors.push(mapper(issue3));
|
|
41411
|
+
}
|
|
41412
|
+
curr = curr[el];
|
|
41413
|
+
i++;
|
|
41414
|
+
}
|
|
41415
|
+
}
|
|
41416
|
+
}
|
|
41417
|
+
};
|
|
41418
|
+
processError(this);
|
|
41419
|
+
return fieldErrors;
|
|
41420
|
+
}
|
|
41421
|
+
static assert(value) {
|
|
41422
|
+
if (!(value instanceof _ZodError)) {
|
|
41423
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
41424
|
+
}
|
|
41425
|
+
}
|
|
41426
|
+
toString() {
|
|
41427
|
+
return this.message;
|
|
41428
|
+
}
|
|
41429
|
+
get message() {
|
|
41430
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
41431
|
+
}
|
|
41432
|
+
get isEmpty() {
|
|
41433
|
+
return this.issues.length === 0;
|
|
41434
|
+
}
|
|
41435
|
+
flatten(mapper = (issue3) => issue3.message) {
|
|
41436
|
+
const fieldErrors = {};
|
|
41437
|
+
const formErrors = [];
|
|
41438
|
+
for (const sub of this.issues) {
|
|
41439
|
+
if (sub.path.length > 0) {
|
|
41440
|
+
const firstEl = sub.path[0];
|
|
41441
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
41442
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
41443
|
+
} else {
|
|
41444
|
+
formErrors.push(mapper(sub));
|
|
41445
|
+
}
|
|
41446
|
+
}
|
|
41447
|
+
return { formErrors, fieldErrors };
|
|
41448
|
+
}
|
|
41449
|
+
get formErrors() {
|
|
41450
|
+
return this.flatten();
|
|
41451
|
+
}
|
|
41452
|
+
};
|
|
41453
|
+
ZodError.create = (issues) => {
|
|
41454
|
+
const error = new ZodError(issues);
|
|
41455
|
+
return error;
|
|
41456
|
+
};
|
|
41457
|
+
|
|
41458
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/locales/en.js
|
|
41459
|
+
var errorMap = (issue3, _ctx) => {
|
|
41460
|
+
let message;
|
|
41461
|
+
switch (issue3.code) {
|
|
41462
|
+
case ZodIssueCode2.invalid_type:
|
|
41463
|
+
if (issue3.received === ZodParsedType.undefined) {
|
|
41464
|
+
message = "Required";
|
|
41465
|
+
} else {
|
|
41466
|
+
message = `Expected ${issue3.expected}, received ${issue3.received}`;
|
|
41467
|
+
}
|
|
41468
|
+
break;
|
|
41469
|
+
case ZodIssueCode2.invalid_literal:
|
|
41470
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue3.expected, util.jsonStringifyReplacer)}`;
|
|
41471
|
+
break;
|
|
41472
|
+
case ZodIssueCode2.unrecognized_keys:
|
|
41473
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue3.keys, ", ")}`;
|
|
41474
|
+
break;
|
|
41475
|
+
case ZodIssueCode2.invalid_union:
|
|
41476
|
+
message = `Invalid input`;
|
|
41477
|
+
break;
|
|
41478
|
+
case ZodIssueCode2.invalid_union_discriminator:
|
|
41479
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue3.options)}`;
|
|
41480
|
+
break;
|
|
41481
|
+
case ZodIssueCode2.invalid_enum_value:
|
|
41482
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue3.options)}, received '${issue3.received}'`;
|
|
41483
|
+
break;
|
|
41484
|
+
case ZodIssueCode2.invalid_arguments:
|
|
41485
|
+
message = `Invalid function arguments`;
|
|
41486
|
+
break;
|
|
41487
|
+
case ZodIssueCode2.invalid_return_type:
|
|
41488
|
+
message = `Invalid function return type`;
|
|
41489
|
+
break;
|
|
41490
|
+
case ZodIssueCode2.invalid_date:
|
|
41491
|
+
message = `Invalid date`;
|
|
41492
|
+
break;
|
|
41493
|
+
case ZodIssueCode2.invalid_string:
|
|
41494
|
+
if (typeof issue3.validation === "object") {
|
|
41495
|
+
if ("includes" in issue3.validation) {
|
|
41496
|
+
message = `Invalid input: must include "${issue3.validation.includes}"`;
|
|
41497
|
+
if (typeof issue3.validation.position === "number") {
|
|
41498
|
+
message = `${message} at one or more positions greater than or equal to ${issue3.validation.position}`;
|
|
41499
|
+
}
|
|
41500
|
+
} else if ("startsWith" in issue3.validation) {
|
|
41501
|
+
message = `Invalid input: must start with "${issue3.validation.startsWith}"`;
|
|
41502
|
+
} else if ("endsWith" in issue3.validation) {
|
|
41503
|
+
message = `Invalid input: must end with "${issue3.validation.endsWith}"`;
|
|
41504
|
+
} else {
|
|
41505
|
+
util.assertNever(issue3.validation);
|
|
41506
|
+
}
|
|
41507
|
+
} else if (issue3.validation !== "regex") {
|
|
41508
|
+
message = `Invalid ${issue3.validation}`;
|
|
41509
|
+
} else {
|
|
41510
|
+
message = "Invalid";
|
|
41511
|
+
}
|
|
41512
|
+
break;
|
|
41513
|
+
case ZodIssueCode2.too_small:
|
|
41514
|
+
if (issue3.type === "array")
|
|
41515
|
+
message = `Array must contain ${issue3.exact ? "exactly" : issue3.inclusive ? `at least` : `more than`} ${issue3.minimum} element(s)`;
|
|
41516
|
+
else if (issue3.type === "string")
|
|
41517
|
+
message = `String must contain ${issue3.exact ? "exactly" : issue3.inclusive ? `at least` : `over`} ${issue3.minimum} character(s)`;
|
|
41518
|
+
else if (issue3.type === "number")
|
|
41519
|
+
message = `Number must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${issue3.minimum}`;
|
|
41520
|
+
else if (issue3.type === "bigint")
|
|
41521
|
+
message = `Number must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${issue3.minimum}`;
|
|
41522
|
+
else if (issue3.type === "date")
|
|
41523
|
+
message = `Date must be ${issue3.exact ? `exactly equal to ` : issue3.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue3.minimum))}`;
|
|
41524
|
+
else
|
|
41525
|
+
message = "Invalid input";
|
|
41526
|
+
break;
|
|
41527
|
+
case ZodIssueCode2.too_big:
|
|
41528
|
+
if (issue3.type === "array")
|
|
41529
|
+
message = `Array must contain ${issue3.exact ? `exactly` : issue3.inclusive ? `at most` : `less than`} ${issue3.maximum} element(s)`;
|
|
41530
|
+
else if (issue3.type === "string")
|
|
41531
|
+
message = `String must contain ${issue3.exact ? `exactly` : issue3.inclusive ? `at most` : `under`} ${issue3.maximum} character(s)`;
|
|
41532
|
+
else if (issue3.type === "number")
|
|
41533
|
+
message = `Number must be ${issue3.exact ? `exactly` : issue3.inclusive ? `less than or equal to` : `less than`} ${issue3.maximum}`;
|
|
41534
|
+
else if (issue3.type === "bigint")
|
|
41535
|
+
message = `BigInt must be ${issue3.exact ? `exactly` : issue3.inclusive ? `less than or equal to` : `less than`} ${issue3.maximum}`;
|
|
41536
|
+
else if (issue3.type === "date")
|
|
41537
|
+
message = `Date must be ${issue3.exact ? `exactly` : issue3.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue3.maximum))}`;
|
|
41538
|
+
else
|
|
41539
|
+
message = "Invalid input";
|
|
41540
|
+
break;
|
|
41541
|
+
case ZodIssueCode2.custom:
|
|
41542
|
+
message = `Invalid input`;
|
|
41543
|
+
break;
|
|
41544
|
+
case ZodIssueCode2.invalid_intersection_types:
|
|
41545
|
+
message = `Intersection results could not be merged`;
|
|
41546
|
+
break;
|
|
41547
|
+
case ZodIssueCode2.not_multiple_of:
|
|
41548
|
+
message = `Number must be a multiple of ${issue3.multipleOf}`;
|
|
41549
|
+
break;
|
|
41550
|
+
case ZodIssueCode2.not_finite:
|
|
41551
|
+
message = "Number must be finite";
|
|
41552
|
+
break;
|
|
41553
|
+
default:
|
|
41554
|
+
message = _ctx.defaultError;
|
|
41555
|
+
util.assertNever(issue3);
|
|
41556
|
+
}
|
|
41557
|
+
return { message };
|
|
41558
|
+
};
|
|
41559
|
+
var en_default = errorMap;
|
|
41560
|
+
|
|
41561
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/errors.js
|
|
41562
|
+
var overrideErrorMap = en_default;
|
|
41563
|
+
function setErrorMap(map) {
|
|
41564
|
+
overrideErrorMap = map;
|
|
41565
|
+
}
|
|
41566
|
+
function getErrorMap() {
|
|
41567
|
+
return overrideErrorMap;
|
|
41568
|
+
}
|
|
41569
|
+
|
|
41570
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/parseUtil.js
|
|
41571
|
+
var makeIssue = (params) => {
|
|
41572
|
+
const { data, path: path2, errorMaps, issueData } = params;
|
|
41573
|
+
const fullPath = [...path2, ...issueData.path || []];
|
|
41574
|
+
const fullIssue = {
|
|
41575
|
+
...issueData,
|
|
41576
|
+
path: fullPath
|
|
41577
|
+
};
|
|
41578
|
+
if (issueData.message !== void 0) {
|
|
41579
|
+
return {
|
|
41580
|
+
...issueData,
|
|
41581
|
+
path: fullPath,
|
|
41582
|
+
message: issueData.message
|
|
41583
|
+
};
|
|
41584
|
+
}
|
|
41585
|
+
let errorMessage2 = "";
|
|
41586
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
41587
|
+
for (const map of maps) {
|
|
41588
|
+
errorMessage2 = map(fullIssue, { data, defaultError: errorMessage2 }).message;
|
|
41589
|
+
}
|
|
41590
|
+
return {
|
|
41591
|
+
...issueData,
|
|
41592
|
+
path: fullPath,
|
|
41593
|
+
message: errorMessage2
|
|
41594
|
+
};
|
|
41595
|
+
};
|
|
41596
|
+
var EMPTY_PATH = [];
|
|
41597
|
+
function addIssueToContext(ctx, issueData) {
|
|
41598
|
+
const overrideMap = getErrorMap();
|
|
41599
|
+
const issue3 = makeIssue({
|
|
41600
|
+
issueData,
|
|
41601
|
+
data: ctx.data,
|
|
41602
|
+
path: ctx.path,
|
|
41603
|
+
errorMaps: [
|
|
41604
|
+
ctx.common.contextualErrorMap,
|
|
41605
|
+
// contextual error map is first priority
|
|
41606
|
+
ctx.schemaErrorMap,
|
|
41607
|
+
// then schema-bound map if available
|
|
41608
|
+
overrideMap,
|
|
41609
|
+
// then global override map
|
|
41610
|
+
overrideMap === en_default ? void 0 : en_default
|
|
41611
|
+
// then global default map
|
|
41612
|
+
].filter((x) => !!x)
|
|
41613
|
+
});
|
|
41614
|
+
ctx.common.issues.push(issue3);
|
|
41615
|
+
}
|
|
41616
|
+
var ParseStatus = class _ParseStatus {
|
|
41617
|
+
constructor() {
|
|
41618
|
+
this.value = "valid";
|
|
41619
|
+
}
|
|
41620
|
+
dirty() {
|
|
41621
|
+
if (this.value === "valid")
|
|
41622
|
+
this.value = "dirty";
|
|
41623
|
+
}
|
|
41624
|
+
abort() {
|
|
41625
|
+
if (this.value !== "aborted")
|
|
41626
|
+
this.value = "aborted";
|
|
41627
|
+
}
|
|
41628
|
+
static mergeArray(status, results) {
|
|
41629
|
+
const arrayValue = [];
|
|
41630
|
+
for (const s of results) {
|
|
41631
|
+
if (s.status === "aborted")
|
|
41632
|
+
return INVALID;
|
|
41633
|
+
if (s.status === "dirty")
|
|
41634
|
+
status.dirty();
|
|
41635
|
+
arrayValue.push(s.value);
|
|
41636
|
+
}
|
|
41637
|
+
return { status: status.value, value: arrayValue };
|
|
41638
|
+
}
|
|
41639
|
+
static async mergeObjectAsync(status, pairs) {
|
|
41640
|
+
const syncPairs = [];
|
|
41641
|
+
for (const pair of pairs) {
|
|
41642
|
+
const key = await pair.key;
|
|
41643
|
+
const value = await pair.value;
|
|
41644
|
+
syncPairs.push({
|
|
41645
|
+
key,
|
|
41646
|
+
value
|
|
41647
|
+
});
|
|
41648
|
+
}
|
|
41649
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
41650
|
+
}
|
|
41651
|
+
static mergeObjectSync(status, pairs) {
|
|
41652
|
+
const finalObject = {};
|
|
41653
|
+
for (const pair of pairs) {
|
|
41654
|
+
const { key, value } = pair;
|
|
41655
|
+
if (key.status === "aborted")
|
|
41656
|
+
return INVALID;
|
|
41657
|
+
if (value.status === "aborted")
|
|
41658
|
+
return INVALID;
|
|
41659
|
+
if (key.status === "dirty")
|
|
41660
|
+
status.dirty();
|
|
41661
|
+
if (value.status === "dirty")
|
|
41662
|
+
status.dirty();
|
|
41663
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
41664
|
+
finalObject[key.value] = value.value;
|
|
41665
|
+
}
|
|
41666
|
+
}
|
|
41667
|
+
return { status: status.value, value: finalObject };
|
|
41668
|
+
}
|
|
41669
|
+
};
|
|
41670
|
+
var INVALID = Object.freeze({
|
|
41671
|
+
status: "aborted"
|
|
41672
|
+
});
|
|
41673
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
41674
|
+
var OK = (value) => ({ status: "valid", value });
|
|
41675
|
+
var isAborted = (x) => x.status === "aborted";
|
|
41676
|
+
var isDirty = (x) => x.status === "dirty";
|
|
41677
|
+
var isValid = (x) => x.status === "valid";
|
|
41678
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
41679
|
+
|
|
41680
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/helpers/errorUtil.js
|
|
41681
|
+
var errorUtil;
|
|
41682
|
+
(function(errorUtil2) {
|
|
41683
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
41684
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
41685
|
+
})(errorUtil || (errorUtil = {}));
|
|
41686
|
+
|
|
41687
|
+
// ../../node_modules/@ag-ui/core/node_modules/zod/v3/types.js
|
|
41688
|
+
var ParseInputLazyPath = class {
|
|
41689
|
+
constructor(parent, value, path2, key) {
|
|
41690
|
+
this._cachedPath = [];
|
|
41691
|
+
this.parent = parent;
|
|
41692
|
+
this.data = value;
|
|
41693
|
+
this._path = path2;
|
|
41694
|
+
this._key = key;
|
|
41695
|
+
}
|
|
41696
|
+
get path() {
|
|
41697
|
+
if (!this._cachedPath.length) {
|
|
41698
|
+
if (Array.isArray(this._key)) {
|
|
41699
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
41700
|
+
} else {
|
|
41701
|
+
this._cachedPath.push(...this._path, this._key);
|
|
41702
|
+
}
|
|
41703
|
+
}
|
|
41704
|
+
return this._cachedPath;
|
|
41705
|
+
}
|
|
41706
|
+
};
|
|
41707
|
+
var handleResult = (ctx, result) => {
|
|
41708
|
+
if (isValid(result)) {
|
|
41709
|
+
return { success: true, data: result.value };
|
|
41710
|
+
} else {
|
|
41711
|
+
if (!ctx.common.issues.length) {
|
|
41712
|
+
throw new Error("Validation failed but no issues detected.");
|
|
41713
|
+
}
|
|
41714
|
+
return {
|
|
41715
|
+
success: false,
|
|
41716
|
+
get error() {
|
|
41717
|
+
if (this._error)
|
|
41718
|
+
return this._error;
|
|
41719
|
+
const error = new ZodError(ctx.common.issues);
|
|
41720
|
+
this._error = error;
|
|
41721
|
+
return this._error;
|
|
41722
|
+
}
|
|
41723
|
+
};
|
|
41724
|
+
}
|
|
41725
|
+
};
|
|
41726
|
+
function processCreateParams(params) {
|
|
41727
|
+
if (!params)
|
|
41728
|
+
return {};
|
|
41729
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
41730
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
41731
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
41732
|
+
}
|
|
41733
|
+
if (errorMap2)
|
|
41734
|
+
return { errorMap: errorMap2, description };
|
|
41735
|
+
const customMap = (iss, ctx) => {
|
|
41736
|
+
const { message } = params;
|
|
41737
|
+
if (iss.code === "invalid_enum_value") {
|
|
41738
|
+
return { message: message ?? ctx.defaultError };
|
|
41739
|
+
}
|
|
41740
|
+
if (typeof ctx.data === "undefined") {
|
|
41741
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
41742
|
+
}
|
|
41743
|
+
if (iss.code !== "invalid_type")
|
|
41744
|
+
return { message: ctx.defaultError };
|
|
41745
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
41746
|
+
};
|
|
41747
|
+
return { errorMap: customMap, description };
|
|
41748
|
+
}
|
|
41749
|
+
var ZodType = class {
|
|
41750
|
+
get description() {
|
|
41751
|
+
return this._def.description;
|
|
41752
|
+
}
|
|
41753
|
+
_getType(input) {
|
|
41754
|
+
return getParsedType(input.data);
|
|
41755
|
+
}
|
|
41756
|
+
_getOrReturnCtx(input, ctx) {
|
|
41757
|
+
return ctx || {
|
|
41758
|
+
common: input.parent.common,
|
|
41759
|
+
data: input.data,
|
|
41760
|
+
parsedType: getParsedType(input.data),
|
|
41761
|
+
schemaErrorMap: this._def.errorMap,
|
|
41762
|
+
path: input.path,
|
|
41763
|
+
parent: input.parent
|
|
41764
|
+
};
|
|
41765
|
+
}
|
|
41766
|
+
_processInputParams(input) {
|
|
41767
|
+
return {
|
|
41768
|
+
status: new ParseStatus(),
|
|
41769
|
+
ctx: {
|
|
41770
|
+
common: input.parent.common,
|
|
41771
|
+
data: input.data,
|
|
41772
|
+
parsedType: getParsedType(input.data),
|
|
41773
|
+
schemaErrorMap: this._def.errorMap,
|
|
41774
|
+
path: input.path,
|
|
41775
|
+
parent: input.parent
|
|
41776
|
+
}
|
|
41777
|
+
};
|
|
41778
|
+
}
|
|
41779
|
+
_parseSync(input) {
|
|
41780
|
+
const result = this._parse(input);
|
|
41781
|
+
if (isAsync(result)) {
|
|
41782
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
41783
|
+
}
|
|
41784
|
+
return result;
|
|
41785
|
+
}
|
|
41786
|
+
_parseAsync(input) {
|
|
41787
|
+
const result = this._parse(input);
|
|
41788
|
+
return Promise.resolve(result);
|
|
41789
|
+
}
|
|
41790
|
+
parse(data, params) {
|
|
41791
|
+
const result = this.safeParse(data, params);
|
|
41792
|
+
if (result.success)
|
|
41793
|
+
return result.data;
|
|
41794
|
+
throw result.error;
|
|
41795
|
+
}
|
|
41796
|
+
safeParse(data, params) {
|
|
41797
|
+
const ctx = {
|
|
41798
|
+
common: {
|
|
41799
|
+
issues: [],
|
|
41800
|
+
async: params?.async ?? false,
|
|
41801
|
+
contextualErrorMap: params?.errorMap
|
|
41802
|
+
},
|
|
41803
|
+
path: params?.path || [],
|
|
41804
|
+
schemaErrorMap: this._def.errorMap,
|
|
41805
|
+
parent: null,
|
|
41806
|
+
data,
|
|
41807
|
+
parsedType: getParsedType(data)
|
|
41808
|
+
};
|
|
41809
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
41810
|
+
return handleResult(ctx, result);
|
|
41811
|
+
}
|
|
41812
|
+
"~validate"(data) {
|
|
41813
|
+
const ctx = {
|
|
41814
|
+
common: {
|
|
41815
|
+
issues: [],
|
|
41816
|
+
async: !!this["~standard"].async
|
|
41817
|
+
},
|
|
41818
|
+
path: [],
|
|
41819
|
+
schemaErrorMap: this._def.errorMap,
|
|
41820
|
+
parent: null,
|
|
41821
|
+
data,
|
|
41822
|
+
parsedType: getParsedType(data)
|
|
41823
|
+
};
|
|
41824
|
+
if (!this["~standard"].async) {
|
|
41825
|
+
try {
|
|
41826
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
41827
|
+
return isValid(result) ? {
|
|
41828
|
+
value: result.value
|
|
41829
|
+
} : {
|
|
41830
|
+
issues: ctx.common.issues
|
|
41831
|
+
};
|
|
41832
|
+
} catch (err2) {
|
|
41833
|
+
if (err2?.message?.toLowerCase()?.includes("encountered")) {
|
|
41834
|
+
this["~standard"].async = true;
|
|
41835
|
+
}
|
|
41836
|
+
ctx.common = {
|
|
41837
|
+
issues: [],
|
|
41838
|
+
async: true
|
|
41839
|
+
};
|
|
41840
|
+
}
|
|
41841
|
+
}
|
|
41842
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
41843
|
+
value: result.value
|
|
41844
|
+
} : {
|
|
41845
|
+
issues: ctx.common.issues
|
|
41846
|
+
});
|
|
41847
|
+
}
|
|
41848
|
+
async parseAsync(data, params) {
|
|
41849
|
+
const result = await this.safeParseAsync(data, params);
|
|
41850
|
+
if (result.success)
|
|
41851
|
+
return result.data;
|
|
41852
|
+
throw result.error;
|
|
41853
|
+
}
|
|
41854
|
+
async safeParseAsync(data, params) {
|
|
41855
|
+
const ctx = {
|
|
41856
|
+
common: {
|
|
41857
|
+
issues: [],
|
|
41858
|
+
contextualErrorMap: params?.errorMap,
|
|
41859
|
+
async: true
|
|
41860
|
+
},
|
|
41861
|
+
path: params?.path || [],
|
|
41862
|
+
schemaErrorMap: this._def.errorMap,
|
|
41863
|
+
parent: null,
|
|
41864
|
+
data,
|
|
41865
|
+
parsedType: getParsedType(data)
|
|
41866
|
+
};
|
|
41867
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
41868
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
41869
|
+
return handleResult(ctx, result);
|
|
41870
|
+
}
|
|
41871
|
+
refine(check, message) {
|
|
41872
|
+
const getIssueProperties = (val) => {
|
|
41873
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
41874
|
+
return { message };
|
|
41875
|
+
} else if (typeof message === "function") {
|
|
41876
|
+
return message(val);
|
|
41877
|
+
} else {
|
|
41878
|
+
return message;
|
|
41879
|
+
}
|
|
41880
|
+
};
|
|
41881
|
+
return this._refinement((val, ctx) => {
|
|
41882
|
+
const result = check(val);
|
|
41883
|
+
const setError = () => ctx.addIssue({
|
|
41884
|
+
code: ZodIssueCode2.custom,
|
|
41885
|
+
...getIssueProperties(val)
|
|
41886
|
+
});
|
|
41887
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
41888
|
+
return result.then((data) => {
|
|
41889
|
+
if (!data) {
|
|
41890
|
+
setError();
|
|
41891
|
+
return false;
|
|
41892
|
+
} else {
|
|
41893
|
+
return true;
|
|
41894
|
+
}
|
|
41895
|
+
});
|
|
41896
|
+
}
|
|
41897
|
+
if (!result) {
|
|
41898
|
+
setError();
|
|
41899
|
+
return false;
|
|
41900
|
+
} else {
|
|
41901
|
+
return true;
|
|
41902
|
+
}
|
|
41903
|
+
});
|
|
41904
|
+
}
|
|
41905
|
+
refinement(check, refinementData) {
|
|
41906
|
+
return this._refinement((val, ctx) => {
|
|
41907
|
+
if (!check(val)) {
|
|
41908
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
41909
|
+
return false;
|
|
41910
|
+
} else {
|
|
41911
|
+
return true;
|
|
41912
|
+
}
|
|
41913
|
+
});
|
|
41914
|
+
}
|
|
41915
|
+
_refinement(refinement) {
|
|
41916
|
+
return new ZodEffects({
|
|
41917
|
+
schema: this,
|
|
41918
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
41919
|
+
effect: { type: "refinement", refinement }
|
|
41920
|
+
});
|
|
41921
|
+
}
|
|
41922
|
+
superRefine(refinement) {
|
|
41923
|
+
return this._refinement(refinement);
|
|
41924
|
+
}
|
|
41925
|
+
constructor(def) {
|
|
41926
|
+
this.spa = this.safeParseAsync;
|
|
41927
|
+
this._def = def;
|
|
41928
|
+
this.parse = this.parse.bind(this);
|
|
41929
|
+
this.safeParse = this.safeParse.bind(this);
|
|
41930
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
41931
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
41932
|
+
this.spa = this.spa.bind(this);
|
|
41933
|
+
this.refine = this.refine.bind(this);
|
|
41934
|
+
this.refinement = this.refinement.bind(this);
|
|
41935
|
+
this.superRefine = this.superRefine.bind(this);
|
|
41936
|
+
this.optional = this.optional.bind(this);
|
|
41937
|
+
this.nullable = this.nullable.bind(this);
|
|
41938
|
+
this.nullish = this.nullish.bind(this);
|
|
41939
|
+
this.array = this.array.bind(this);
|
|
41940
|
+
this.promise = this.promise.bind(this);
|
|
41941
|
+
this.or = this.or.bind(this);
|
|
41942
|
+
this.and = this.and.bind(this);
|
|
41943
|
+
this.transform = this.transform.bind(this);
|
|
41944
|
+
this.brand = this.brand.bind(this);
|
|
41945
|
+
this.default = this.default.bind(this);
|
|
41946
|
+
this.catch = this.catch.bind(this);
|
|
41947
|
+
this.describe = this.describe.bind(this);
|
|
41948
|
+
this.pipe = this.pipe.bind(this);
|
|
41949
|
+
this.readonly = this.readonly.bind(this);
|
|
41950
|
+
this.isNullable = this.isNullable.bind(this);
|
|
41951
|
+
this.isOptional = this.isOptional.bind(this);
|
|
41952
|
+
this["~standard"] = {
|
|
41953
|
+
version: 1,
|
|
41954
|
+
vendor: "zod",
|
|
41955
|
+
validate: (data) => this["~validate"](data)
|
|
41956
|
+
};
|
|
41957
|
+
}
|
|
41958
|
+
optional() {
|
|
41959
|
+
return ZodOptional.create(this, this._def);
|
|
41960
|
+
}
|
|
41961
|
+
nullable() {
|
|
41962
|
+
return ZodNullable.create(this, this._def);
|
|
41963
|
+
}
|
|
41964
|
+
nullish() {
|
|
41965
|
+
return this.nullable().optional();
|
|
41966
|
+
}
|
|
41967
|
+
array() {
|
|
41968
|
+
return ZodArray.create(this);
|
|
41969
|
+
}
|
|
41970
|
+
promise() {
|
|
41971
|
+
return ZodPromise.create(this, this._def);
|
|
41972
|
+
}
|
|
41973
|
+
or(option) {
|
|
41974
|
+
return ZodUnion.create([this, option], this._def);
|
|
41975
|
+
}
|
|
41976
|
+
and(incoming) {
|
|
41977
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
41978
|
+
}
|
|
41979
|
+
transform(transform) {
|
|
41980
|
+
return new ZodEffects({
|
|
41981
|
+
...processCreateParams(this._def),
|
|
41982
|
+
schema: this,
|
|
41983
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
41984
|
+
effect: { type: "transform", transform }
|
|
41985
|
+
});
|
|
41986
|
+
}
|
|
41987
|
+
default(def) {
|
|
41988
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
41989
|
+
return new ZodDefault({
|
|
41990
|
+
...processCreateParams(this._def),
|
|
41991
|
+
innerType: this,
|
|
41992
|
+
defaultValue: defaultValueFunc,
|
|
41993
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
41994
|
+
});
|
|
41995
|
+
}
|
|
41996
|
+
brand() {
|
|
41997
|
+
return new ZodBranded({
|
|
41998
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
41999
|
+
type: this,
|
|
42000
|
+
...processCreateParams(this._def)
|
|
42001
|
+
});
|
|
42002
|
+
}
|
|
42003
|
+
catch(def) {
|
|
42004
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
42005
|
+
return new ZodCatch({
|
|
42006
|
+
...processCreateParams(this._def),
|
|
42007
|
+
innerType: this,
|
|
42008
|
+
catchValue: catchValueFunc,
|
|
42009
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
42010
|
+
});
|
|
42011
|
+
}
|
|
42012
|
+
describe(description) {
|
|
42013
|
+
const This = this.constructor;
|
|
42014
|
+
return new This({
|
|
42015
|
+
...this._def,
|
|
42016
|
+
description
|
|
42017
|
+
});
|
|
42018
|
+
}
|
|
42019
|
+
pipe(target) {
|
|
42020
|
+
return ZodPipeline.create(this, target);
|
|
42021
|
+
}
|
|
42022
|
+
readonly() {
|
|
42023
|
+
return ZodReadonly.create(this);
|
|
42024
|
+
}
|
|
42025
|
+
isOptional() {
|
|
42026
|
+
return this.safeParse(void 0).success;
|
|
42027
|
+
}
|
|
42028
|
+
isNullable() {
|
|
42029
|
+
return this.safeParse(null).success;
|
|
42030
|
+
}
|
|
42031
|
+
};
|
|
42032
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
42033
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
42034
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
42035
|
+
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;
|
|
42036
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
42037
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
42038
|
+
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)?)??$/;
|
|
42039
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
42040
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
42041
|
+
var emojiRegex;
|
|
42042
|
+
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])$/;
|
|
42043
|
+
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])$/;
|
|
42044
|
+
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]))$/;
|
|
42045
|
+
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])$/;
|
|
42046
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
42047
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
42048
|
+
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])))`;
|
|
42049
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
42050
|
+
function timeRegexSource(args) {
|
|
42051
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
42052
|
+
if (args.precision) {
|
|
42053
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
42054
|
+
} else if (args.precision == null) {
|
|
42055
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
42056
|
+
}
|
|
42057
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
42058
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
42059
|
+
}
|
|
42060
|
+
function timeRegex(args) {
|
|
42061
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
42062
|
+
}
|
|
42063
|
+
function datetimeRegex(args) {
|
|
42064
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
42065
|
+
const opts = [];
|
|
42066
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
42067
|
+
if (args.offset)
|
|
42068
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
42069
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
42070
|
+
return new RegExp(`^${regex}$`);
|
|
42071
|
+
}
|
|
42072
|
+
function isValidIP(ip, version) {
|
|
42073
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
42074
|
+
return true;
|
|
42075
|
+
}
|
|
42076
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
42077
|
+
return true;
|
|
42078
|
+
}
|
|
42079
|
+
return false;
|
|
42080
|
+
}
|
|
42081
|
+
function isValidJWT(jwt, alg) {
|
|
42082
|
+
if (!jwtRegex.test(jwt))
|
|
42083
|
+
return false;
|
|
42084
|
+
try {
|
|
42085
|
+
const [header] = jwt.split(".");
|
|
42086
|
+
if (!header)
|
|
42087
|
+
return false;
|
|
42088
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
42089
|
+
const decoded = JSON.parse(atob(base64));
|
|
42090
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
42091
|
+
return false;
|
|
42092
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
42093
|
+
return false;
|
|
42094
|
+
if (!decoded.alg)
|
|
42095
|
+
return false;
|
|
42096
|
+
if (alg && decoded.alg !== alg)
|
|
42097
|
+
return false;
|
|
42098
|
+
return true;
|
|
42099
|
+
} catch {
|
|
42100
|
+
return false;
|
|
42101
|
+
}
|
|
42102
|
+
}
|
|
42103
|
+
function isValidCidr(ip, version) {
|
|
42104
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
42105
|
+
return true;
|
|
42106
|
+
}
|
|
42107
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
42108
|
+
return true;
|
|
42109
|
+
}
|
|
42110
|
+
return false;
|
|
42111
|
+
}
|
|
42112
|
+
var ZodString = class _ZodString extends ZodType {
|
|
42113
|
+
_parse(input) {
|
|
42114
|
+
if (this._def.coerce) {
|
|
42115
|
+
input.data = String(input.data);
|
|
42116
|
+
}
|
|
42117
|
+
const parsedType = this._getType(input);
|
|
42118
|
+
if (parsedType !== ZodParsedType.string) {
|
|
42119
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
42120
|
+
addIssueToContext(ctx2, {
|
|
42121
|
+
code: ZodIssueCode2.invalid_type,
|
|
42122
|
+
expected: ZodParsedType.string,
|
|
42123
|
+
received: ctx2.parsedType
|
|
42124
|
+
});
|
|
42125
|
+
return INVALID;
|
|
42126
|
+
}
|
|
42127
|
+
const status = new ParseStatus();
|
|
42128
|
+
let ctx = void 0;
|
|
42129
|
+
for (const check of this._def.checks) {
|
|
42130
|
+
if (check.kind === "min") {
|
|
42131
|
+
if (input.data.length < check.value) {
|
|
42132
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42133
|
+
addIssueToContext(ctx, {
|
|
42134
|
+
code: ZodIssueCode2.too_small,
|
|
42135
|
+
minimum: check.value,
|
|
42136
|
+
type: "string",
|
|
42137
|
+
inclusive: true,
|
|
42138
|
+
exact: false,
|
|
42139
|
+
message: check.message
|
|
42140
|
+
});
|
|
42141
|
+
status.dirty();
|
|
42142
|
+
}
|
|
42143
|
+
} else if (check.kind === "max") {
|
|
42144
|
+
if (input.data.length > check.value) {
|
|
42145
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42146
|
+
addIssueToContext(ctx, {
|
|
42147
|
+
code: ZodIssueCode2.too_big,
|
|
42148
|
+
maximum: check.value,
|
|
42149
|
+
type: "string",
|
|
42150
|
+
inclusive: true,
|
|
42151
|
+
exact: false,
|
|
42152
|
+
message: check.message
|
|
42153
|
+
});
|
|
42154
|
+
status.dirty();
|
|
42155
|
+
}
|
|
42156
|
+
} else if (check.kind === "length") {
|
|
42157
|
+
const tooBig = input.data.length > check.value;
|
|
42158
|
+
const tooSmall = input.data.length < check.value;
|
|
42159
|
+
if (tooBig || tooSmall) {
|
|
42160
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42161
|
+
if (tooBig) {
|
|
42162
|
+
addIssueToContext(ctx, {
|
|
42163
|
+
code: ZodIssueCode2.too_big,
|
|
42164
|
+
maximum: check.value,
|
|
42165
|
+
type: "string",
|
|
42166
|
+
inclusive: true,
|
|
42167
|
+
exact: true,
|
|
42168
|
+
message: check.message
|
|
42169
|
+
});
|
|
42170
|
+
} else if (tooSmall) {
|
|
42171
|
+
addIssueToContext(ctx, {
|
|
42172
|
+
code: ZodIssueCode2.too_small,
|
|
42173
|
+
minimum: check.value,
|
|
42174
|
+
type: "string",
|
|
42175
|
+
inclusive: true,
|
|
42176
|
+
exact: true,
|
|
42177
|
+
message: check.message
|
|
42178
|
+
});
|
|
42179
|
+
}
|
|
42180
|
+
status.dirty();
|
|
42181
|
+
}
|
|
42182
|
+
} else if (check.kind === "email") {
|
|
42183
|
+
if (!emailRegex.test(input.data)) {
|
|
42184
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42185
|
+
addIssueToContext(ctx, {
|
|
42186
|
+
validation: "email",
|
|
42187
|
+
code: ZodIssueCode2.invalid_string,
|
|
42188
|
+
message: check.message
|
|
42189
|
+
});
|
|
42190
|
+
status.dirty();
|
|
42191
|
+
}
|
|
42192
|
+
} else if (check.kind === "emoji") {
|
|
42193
|
+
if (!emojiRegex) {
|
|
42194
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
42195
|
+
}
|
|
42196
|
+
if (!emojiRegex.test(input.data)) {
|
|
42197
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42198
|
+
addIssueToContext(ctx, {
|
|
42199
|
+
validation: "emoji",
|
|
42200
|
+
code: ZodIssueCode2.invalid_string,
|
|
42201
|
+
message: check.message
|
|
42202
|
+
});
|
|
42203
|
+
status.dirty();
|
|
42204
|
+
}
|
|
42205
|
+
} else if (check.kind === "uuid") {
|
|
42206
|
+
if (!uuidRegex.test(input.data)) {
|
|
42207
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42208
|
+
addIssueToContext(ctx, {
|
|
42209
|
+
validation: "uuid",
|
|
42210
|
+
code: ZodIssueCode2.invalid_string,
|
|
42211
|
+
message: check.message
|
|
42212
|
+
});
|
|
42213
|
+
status.dirty();
|
|
42214
|
+
}
|
|
42215
|
+
} else if (check.kind === "nanoid") {
|
|
42216
|
+
if (!nanoidRegex.test(input.data)) {
|
|
42217
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42218
|
+
addIssueToContext(ctx, {
|
|
42219
|
+
validation: "nanoid",
|
|
42220
|
+
code: ZodIssueCode2.invalid_string,
|
|
42221
|
+
message: check.message
|
|
42222
|
+
});
|
|
42223
|
+
status.dirty();
|
|
42224
|
+
}
|
|
42225
|
+
} else if (check.kind === "cuid") {
|
|
42226
|
+
if (!cuidRegex.test(input.data)) {
|
|
42227
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42228
|
+
addIssueToContext(ctx, {
|
|
42229
|
+
validation: "cuid",
|
|
42230
|
+
code: ZodIssueCode2.invalid_string,
|
|
42231
|
+
message: check.message
|
|
42232
|
+
});
|
|
42233
|
+
status.dirty();
|
|
42234
|
+
}
|
|
42235
|
+
} else if (check.kind === "cuid2") {
|
|
42236
|
+
if (!cuid2Regex.test(input.data)) {
|
|
42237
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42238
|
+
addIssueToContext(ctx, {
|
|
42239
|
+
validation: "cuid2",
|
|
42240
|
+
code: ZodIssueCode2.invalid_string,
|
|
42241
|
+
message: check.message
|
|
42242
|
+
});
|
|
42243
|
+
status.dirty();
|
|
42244
|
+
}
|
|
42245
|
+
} else if (check.kind === "ulid") {
|
|
42246
|
+
if (!ulidRegex.test(input.data)) {
|
|
42247
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42248
|
+
addIssueToContext(ctx, {
|
|
42249
|
+
validation: "ulid",
|
|
42250
|
+
code: ZodIssueCode2.invalid_string,
|
|
42251
|
+
message: check.message
|
|
42252
|
+
});
|
|
42253
|
+
status.dirty();
|
|
42254
|
+
}
|
|
42255
|
+
} else if (check.kind === "url") {
|
|
42256
|
+
try {
|
|
42257
|
+
new URL(input.data);
|
|
42258
|
+
} catch {
|
|
42259
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42260
|
+
addIssueToContext(ctx, {
|
|
42261
|
+
validation: "url",
|
|
42262
|
+
code: ZodIssueCode2.invalid_string,
|
|
42263
|
+
message: check.message
|
|
42264
|
+
});
|
|
42265
|
+
status.dirty();
|
|
42266
|
+
}
|
|
42267
|
+
} else if (check.kind === "regex") {
|
|
42268
|
+
check.regex.lastIndex = 0;
|
|
42269
|
+
const testResult = check.regex.test(input.data);
|
|
42270
|
+
if (!testResult) {
|
|
42271
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42272
|
+
addIssueToContext(ctx, {
|
|
42273
|
+
validation: "regex",
|
|
42274
|
+
code: ZodIssueCode2.invalid_string,
|
|
42275
|
+
message: check.message
|
|
42276
|
+
});
|
|
42277
|
+
status.dirty();
|
|
42278
|
+
}
|
|
42279
|
+
} else if (check.kind === "trim") {
|
|
42280
|
+
input.data = input.data.trim();
|
|
42281
|
+
} else if (check.kind === "includes") {
|
|
42282
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
42283
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42284
|
+
addIssueToContext(ctx, {
|
|
42285
|
+
code: ZodIssueCode2.invalid_string,
|
|
42286
|
+
validation: { includes: check.value, position: check.position },
|
|
42287
|
+
message: check.message
|
|
42288
|
+
});
|
|
42289
|
+
status.dirty();
|
|
42290
|
+
}
|
|
42291
|
+
} else if (check.kind === "toLowerCase") {
|
|
42292
|
+
input.data = input.data.toLowerCase();
|
|
42293
|
+
} else if (check.kind === "toUpperCase") {
|
|
42294
|
+
input.data = input.data.toUpperCase();
|
|
42295
|
+
} else if (check.kind === "startsWith") {
|
|
42296
|
+
if (!input.data.startsWith(check.value)) {
|
|
42297
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42298
|
+
addIssueToContext(ctx, {
|
|
42299
|
+
code: ZodIssueCode2.invalid_string,
|
|
42300
|
+
validation: { startsWith: check.value },
|
|
42301
|
+
message: check.message
|
|
42302
|
+
});
|
|
42303
|
+
status.dirty();
|
|
42304
|
+
}
|
|
42305
|
+
} else if (check.kind === "endsWith") {
|
|
42306
|
+
if (!input.data.endsWith(check.value)) {
|
|
42307
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42308
|
+
addIssueToContext(ctx, {
|
|
42309
|
+
code: ZodIssueCode2.invalid_string,
|
|
42310
|
+
validation: { endsWith: check.value },
|
|
42311
|
+
message: check.message
|
|
42312
|
+
});
|
|
42313
|
+
status.dirty();
|
|
42314
|
+
}
|
|
42315
|
+
} else if (check.kind === "datetime") {
|
|
42316
|
+
const regex = datetimeRegex(check);
|
|
42317
|
+
if (!regex.test(input.data)) {
|
|
42318
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42319
|
+
addIssueToContext(ctx, {
|
|
42320
|
+
code: ZodIssueCode2.invalid_string,
|
|
42321
|
+
validation: "datetime",
|
|
42322
|
+
message: check.message
|
|
42323
|
+
});
|
|
42324
|
+
status.dirty();
|
|
42325
|
+
}
|
|
42326
|
+
} else if (check.kind === "date") {
|
|
42327
|
+
const regex = dateRegex;
|
|
42328
|
+
if (!regex.test(input.data)) {
|
|
42329
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42330
|
+
addIssueToContext(ctx, {
|
|
42331
|
+
code: ZodIssueCode2.invalid_string,
|
|
42332
|
+
validation: "date",
|
|
42333
|
+
message: check.message
|
|
42334
|
+
});
|
|
42335
|
+
status.dirty();
|
|
42336
|
+
}
|
|
42337
|
+
} else if (check.kind === "time") {
|
|
42338
|
+
const regex = timeRegex(check);
|
|
42339
|
+
if (!regex.test(input.data)) {
|
|
42340
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42341
|
+
addIssueToContext(ctx, {
|
|
42342
|
+
code: ZodIssueCode2.invalid_string,
|
|
42343
|
+
validation: "time",
|
|
42344
|
+
message: check.message
|
|
42345
|
+
});
|
|
42346
|
+
status.dirty();
|
|
42347
|
+
}
|
|
42348
|
+
} else if (check.kind === "duration") {
|
|
42349
|
+
if (!durationRegex.test(input.data)) {
|
|
42350
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42351
|
+
addIssueToContext(ctx, {
|
|
42352
|
+
validation: "duration",
|
|
42353
|
+
code: ZodIssueCode2.invalid_string,
|
|
42354
|
+
message: check.message
|
|
42355
|
+
});
|
|
42356
|
+
status.dirty();
|
|
42357
|
+
}
|
|
42358
|
+
} else if (check.kind === "ip") {
|
|
42359
|
+
if (!isValidIP(input.data, check.version)) {
|
|
42360
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42361
|
+
addIssueToContext(ctx, {
|
|
42362
|
+
validation: "ip",
|
|
42363
|
+
code: ZodIssueCode2.invalid_string,
|
|
42364
|
+
message: check.message
|
|
42365
|
+
});
|
|
42366
|
+
status.dirty();
|
|
42367
|
+
}
|
|
42368
|
+
} else if (check.kind === "jwt") {
|
|
42369
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
42370
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42371
|
+
addIssueToContext(ctx, {
|
|
42372
|
+
validation: "jwt",
|
|
42373
|
+
code: ZodIssueCode2.invalid_string,
|
|
42374
|
+
message: check.message
|
|
42375
|
+
});
|
|
42376
|
+
status.dirty();
|
|
42377
|
+
}
|
|
42378
|
+
} else if (check.kind === "cidr") {
|
|
42379
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
42380
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42381
|
+
addIssueToContext(ctx, {
|
|
42382
|
+
validation: "cidr",
|
|
42383
|
+
code: ZodIssueCode2.invalid_string,
|
|
42384
|
+
message: check.message
|
|
42385
|
+
});
|
|
42386
|
+
status.dirty();
|
|
42387
|
+
}
|
|
42388
|
+
} else if (check.kind === "base64") {
|
|
42389
|
+
if (!base64Regex.test(input.data)) {
|
|
42390
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42391
|
+
addIssueToContext(ctx, {
|
|
42392
|
+
validation: "base64",
|
|
42393
|
+
code: ZodIssueCode2.invalid_string,
|
|
42394
|
+
message: check.message
|
|
42395
|
+
});
|
|
42396
|
+
status.dirty();
|
|
42397
|
+
}
|
|
42398
|
+
} else if (check.kind === "base64url") {
|
|
42399
|
+
if (!base64urlRegex.test(input.data)) {
|
|
42400
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42401
|
+
addIssueToContext(ctx, {
|
|
42402
|
+
validation: "base64url",
|
|
42403
|
+
code: ZodIssueCode2.invalid_string,
|
|
42404
|
+
message: check.message
|
|
42405
|
+
});
|
|
42406
|
+
status.dirty();
|
|
42407
|
+
}
|
|
42408
|
+
} else {
|
|
42409
|
+
util.assertNever(check);
|
|
42410
|
+
}
|
|
42411
|
+
}
|
|
42412
|
+
return { status: status.value, value: input.data };
|
|
42413
|
+
}
|
|
42414
|
+
_regex(regex, validation, message) {
|
|
42415
|
+
return this.refinement((data) => regex.test(data), {
|
|
42416
|
+
validation,
|
|
42417
|
+
code: ZodIssueCode2.invalid_string,
|
|
42418
|
+
...errorUtil.errToObj(message)
|
|
42419
|
+
});
|
|
42420
|
+
}
|
|
42421
|
+
_addCheck(check) {
|
|
42422
|
+
return new _ZodString({
|
|
42423
|
+
...this._def,
|
|
42424
|
+
checks: [...this._def.checks, check]
|
|
42425
|
+
});
|
|
42426
|
+
}
|
|
42427
|
+
email(message) {
|
|
42428
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
42429
|
+
}
|
|
42430
|
+
url(message) {
|
|
42431
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
42432
|
+
}
|
|
42433
|
+
emoji(message) {
|
|
42434
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
42435
|
+
}
|
|
42436
|
+
uuid(message) {
|
|
42437
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
42438
|
+
}
|
|
42439
|
+
nanoid(message) {
|
|
42440
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
42441
|
+
}
|
|
42442
|
+
cuid(message) {
|
|
42443
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
42444
|
+
}
|
|
42445
|
+
cuid2(message) {
|
|
42446
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
42447
|
+
}
|
|
42448
|
+
ulid(message) {
|
|
42449
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
42450
|
+
}
|
|
42451
|
+
base64(message) {
|
|
42452
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
42453
|
+
}
|
|
42454
|
+
base64url(message) {
|
|
42455
|
+
return this._addCheck({
|
|
42456
|
+
kind: "base64url",
|
|
42457
|
+
...errorUtil.errToObj(message)
|
|
42458
|
+
});
|
|
42459
|
+
}
|
|
42460
|
+
jwt(options) {
|
|
42461
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
42462
|
+
}
|
|
42463
|
+
ip(options) {
|
|
42464
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
42465
|
+
}
|
|
42466
|
+
cidr(options) {
|
|
42467
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
42468
|
+
}
|
|
42469
|
+
datetime(options) {
|
|
42470
|
+
if (typeof options === "string") {
|
|
42471
|
+
return this._addCheck({
|
|
42472
|
+
kind: "datetime",
|
|
42473
|
+
precision: null,
|
|
42474
|
+
offset: false,
|
|
42475
|
+
local: false,
|
|
42476
|
+
message: options
|
|
42477
|
+
});
|
|
42478
|
+
}
|
|
42479
|
+
return this._addCheck({
|
|
42480
|
+
kind: "datetime",
|
|
42481
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
42482
|
+
offset: options?.offset ?? false,
|
|
42483
|
+
local: options?.local ?? false,
|
|
42484
|
+
...errorUtil.errToObj(options?.message)
|
|
42485
|
+
});
|
|
42486
|
+
}
|
|
42487
|
+
date(message) {
|
|
42488
|
+
return this._addCheck({ kind: "date", message });
|
|
42489
|
+
}
|
|
42490
|
+
time(options) {
|
|
42491
|
+
if (typeof options === "string") {
|
|
42492
|
+
return this._addCheck({
|
|
42493
|
+
kind: "time",
|
|
42494
|
+
precision: null,
|
|
42495
|
+
message: options
|
|
42496
|
+
});
|
|
42497
|
+
}
|
|
42498
|
+
return this._addCheck({
|
|
42499
|
+
kind: "time",
|
|
42500
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
42501
|
+
...errorUtil.errToObj(options?.message)
|
|
42502
|
+
});
|
|
42503
|
+
}
|
|
42504
|
+
duration(message) {
|
|
42505
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
42506
|
+
}
|
|
42507
|
+
regex(regex, message) {
|
|
42508
|
+
return this._addCheck({
|
|
42509
|
+
kind: "regex",
|
|
42510
|
+
regex,
|
|
42511
|
+
...errorUtil.errToObj(message)
|
|
42512
|
+
});
|
|
42513
|
+
}
|
|
42514
|
+
includes(value, options) {
|
|
42515
|
+
return this._addCheck({
|
|
42516
|
+
kind: "includes",
|
|
42517
|
+
value,
|
|
42518
|
+
position: options?.position,
|
|
42519
|
+
...errorUtil.errToObj(options?.message)
|
|
42520
|
+
});
|
|
42521
|
+
}
|
|
42522
|
+
startsWith(value, message) {
|
|
42523
|
+
return this._addCheck({
|
|
42524
|
+
kind: "startsWith",
|
|
42525
|
+
value,
|
|
42526
|
+
...errorUtil.errToObj(message)
|
|
42527
|
+
});
|
|
42528
|
+
}
|
|
42529
|
+
endsWith(value, message) {
|
|
42530
|
+
return this._addCheck({
|
|
42531
|
+
kind: "endsWith",
|
|
42532
|
+
value,
|
|
42533
|
+
...errorUtil.errToObj(message)
|
|
42534
|
+
});
|
|
42535
|
+
}
|
|
42536
|
+
min(minLength, message) {
|
|
42537
|
+
return this._addCheck({
|
|
42538
|
+
kind: "min",
|
|
42539
|
+
value: minLength,
|
|
42540
|
+
...errorUtil.errToObj(message)
|
|
42541
|
+
});
|
|
42542
|
+
}
|
|
42543
|
+
max(maxLength, message) {
|
|
42544
|
+
return this._addCheck({
|
|
42545
|
+
kind: "max",
|
|
42546
|
+
value: maxLength,
|
|
42547
|
+
...errorUtil.errToObj(message)
|
|
42548
|
+
});
|
|
42549
|
+
}
|
|
42550
|
+
length(len, message) {
|
|
42551
|
+
return this._addCheck({
|
|
42552
|
+
kind: "length",
|
|
42553
|
+
value: len,
|
|
42554
|
+
...errorUtil.errToObj(message)
|
|
42555
|
+
});
|
|
42556
|
+
}
|
|
42557
|
+
/**
|
|
42558
|
+
* Equivalent to `.min(1)`
|
|
42559
|
+
*/
|
|
42560
|
+
nonempty(message) {
|
|
42561
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
42562
|
+
}
|
|
42563
|
+
trim() {
|
|
42564
|
+
return new _ZodString({
|
|
42565
|
+
...this._def,
|
|
42566
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
42567
|
+
});
|
|
42568
|
+
}
|
|
42569
|
+
toLowerCase() {
|
|
42570
|
+
return new _ZodString({
|
|
42571
|
+
...this._def,
|
|
42572
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
42573
|
+
});
|
|
42574
|
+
}
|
|
42575
|
+
toUpperCase() {
|
|
42576
|
+
return new _ZodString({
|
|
42577
|
+
...this._def,
|
|
42578
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
42579
|
+
});
|
|
42580
|
+
}
|
|
42581
|
+
get isDatetime() {
|
|
42582
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "datetime");
|
|
42583
|
+
}
|
|
42584
|
+
get isDate() {
|
|
42585
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "date");
|
|
42586
|
+
}
|
|
42587
|
+
get isTime() {
|
|
42588
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "time");
|
|
42589
|
+
}
|
|
42590
|
+
get isDuration() {
|
|
42591
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "duration");
|
|
42592
|
+
}
|
|
42593
|
+
get isEmail() {
|
|
42594
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "email");
|
|
42595
|
+
}
|
|
42596
|
+
get isURL() {
|
|
42597
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "url");
|
|
42598
|
+
}
|
|
42599
|
+
get isEmoji() {
|
|
42600
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "emoji");
|
|
42601
|
+
}
|
|
42602
|
+
get isUUID() {
|
|
42603
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "uuid");
|
|
42604
|
+
}
|
|
42605
|
+
get isNANOID() {
|
|
42606
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "nanoid");
|
|
42607
|
+
}
|
|
42608
|
+
get isCUID() {
|
|
42609
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "cuid");
|
|
42610
|
+
}
|
|
42611
|
+
get isCUID2() {
|
|
42612
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "cuid2");
|
|
42613
|
+
}
|
|
42614
|
+
get isULID() {
|
|
42615
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "ulid");
|
|
42616
|
+
}
|
|
42617
|
+
get isIP() {
|
|
42618
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "ip");
|
|
42619
|
+
}
|
|
42620
|
+
get isCIDR() {
|
|
42621
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "cidr");
|
|
42622
|
+
}
|
|
42623
|
+
get isBase64() {
|
|
42624
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "base64");
|
|
42625
|
+
}
|
|
42626
|
+
get isBase64url() {
|
|
42627
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "base64url");
|
|
42628
|
+
}
|
|
42629
|
+
get minLength() {
|
|
42630
|
+
let min = null;
|
|
42631
|
+
for (const ch2 of this._def.checks) {
|
|
42632
|
+
if (ch2.kind === "min") {
|
|
42633
|
+
if (min === null || ch2.value > min)
|
|
42634
|
+
min = ch2.value;
|
|
42635
|
+
}
|
|
42636
|
+
}
|
|
42637
|
+
return min;
|
|
42638
|
+
}
|
|
42639
|
+
get maxLength() {
|
|
42640
|
+
let max2 = null;
|
|
42641
|
+
for (const ch2 of this._def.checks) {
|
|
42642
|
+
if (ch2.kind === "max") {
|
|
42643
|
+
if (max2 === null || ch2.value < max2)
|
|
42644
|
+
max2 = ch2.value;
|
|
42645
|
+
}
|
|
42646
|
+
}
|
|
42647
|
+
return max2;
|
|
42648
|
+
}
|
|
42649
|
+
};
|
|
42650
|
+
ZodString.create = (params) => {
|
|
42651
|
+
return new ZodString({
|
|
42652
|
+
checks: [],
|
|
42653
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
42654
|
+
coerce: params?.coerce ?? false,
|
|
42655
|
+
...processCreateParams(params)
|
|
42656
|
+
});
|
|
42657
|
+
};
|
|
42658
|
+
function floatSafeRemainder(val, step) {
|
|
42659
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
42660
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
42661
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
42662
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
42663
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
42664
|
+
return valInt % stepInt / 10 ** decCount;
|
|
42665
|
+
}
|
|
42666
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
42667
|
+
constructor() {
|
|
42668
|
+
super(...arguments);
|
|
42669
|
+
this.min = this.gte;
|
|
42670
|
+
this.max = this.lte;
|
|
42671
|
+
this.step = this.multipleOf;
|
|
42672
|
+
}
|
|
42673
|
+
_parse(input) {
|
|
42674
|
+
if (this._def.coerce) {
|
|
42675
|
+
input.data = Number(input.data);
|
|
42676
|
+
}
|
|
42677
|
+
const parsedType = this._getType(input);
|
|
42678
|
+
if (parsedType !== ZodParsedType.number) {
|
|
42679
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
42680
|
+
addIssueToContext(ctx2, {
|
|
42681
|
+
code: ZodIssueCode2.invalid_type,
|
|
42682
|
+
expected: ZodParsedType.number,
|
|
42683
|
+
received: ctx2.parsedType
|
|
42684
|
+
});
|
|
42685
|
+
return INVALID;
|
|
42686
|
+
}
|
|
42687
|
+
let ctx = void 0;
|
|
42688
|
+
const status = new ParseStatus();
|
|
42689
|
+
for (const check of this._def.checks) {
|
|
42690
|
+
if (check.kind === "int") {
|
|
42691
|
+
if (!util.isInteger(input.data)) {
|
|
42692
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42693
|
+
addIssueToContext(ctx, {
|
|
42694
|
+
code: ZodIssueCode2.invalid_type,
|
|
42695
|
+
expected: "integer",
|
|
42696
|
+
received: "float",
|
|
42697
|
+
message: check.message
|
|
42698
|
+
});
|
|
42699
|
+
status.dirty();
|
|
42700
|
+
}
|
|
42701
|
+
} else if (check.kind === "min") {
|
|
42702
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
42703
|
+
if (tooSmall) {
|
|
42704
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42705
|
+
addIssueToContext(ctx, {
|
|
42706
|
+
code: ZodIssueCode2.too_small,
|
|
42707
|
+
minimum: check.value,
|
|
42708
|
+
type: "number",
|
|
42709
|
+
inclusive: check.inclusive,
|
|
42710
|
+
exact: false,
|
|
42711
|
+
message: check.message
|
|
42712
|
+
});
|
|
42713
|
+
status.dirty();
|
|
42714
|
+
}
|
|
42715
|
+
} else if (check.kind === "max") {
|
|
42716
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
42717
|
+
if (tooBig) {
|
|
42718
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42719
|
+
addIssueToContext(ctx, {
|
|
42720
|
+
code: ZodIssueCode2.too_big,
|
|
42721
|
+
maximum: check.value,
|
|
42722
|
+
type: "number",
|
|
42723
|
+
inclusive: check.inclusive,
|
|
42724
|
+
exact: false,
|
|
42725
|
+
message: check.message
|
|
42726
|
+
});
|
|
42727
|
+
status.dirty();
|
|
42728
|
+
}
|
|
42729
|
+
} else if (check.kind === "multipleOf") {
|
|
42730
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
42731
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42732
|
+
addIssueToContext(ctx, {
|
|
42733
|
+
code: ZodIssueCode2.not_multiple_of,
|
|
42734
|
+
multipleOf: check.value,
|
|
42735
|
+
message: check.message
|
|
42736
|
+
});
|
|
42737
|
+
status.dirty();
|
|
42738
|
+
}
|
|
42739
|
+
} else if (check.kind === "finite") {
|
|
42740
|
+
if (!Number.isFinite(input.data)) {
|
|
42741
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42742
|
+
addIssueToContext(ctx, {
|
|
42743
|
+
code: ZodIssueCode2.not_finite,
|
|
42744
|
+
message: check.message
|
|
42745
|
+
});
|
|
42746
|
+
status.dirty();
|
|
42747
|
+
}
|
|
42748
|
+
} else {
|
|
42749
|
+
util.assertNever(check);
|
|
42750
|
+
}
|
|
42751
|
+
}
|
|
42752
|
+
return { status: status.value, value: input.data };
|
|
42753
|
+
}
|
|
42754
|
+
gte(value, message) {
|
|
42755
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
42756
|
+
}
|
|
42757
|
+
gt(value, message) {
|
|
42758
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
42759
|
+
}
|
|
42760
|
+
lte(value, message) {
|
|
42761
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
42762
|
+
}
|
|
42763
|
+
lt(value, message) {
|
|
42764
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
42765
|
+
}
|
|
42766
|
+
setLimit(kind, value, inclusive, message) {
|
|
42767
|
+
return new _ZodNumber({
|
|
42768
|
+
...this._def,
|
|
42769
|
+
checks: [
|
|
42770
|
+
...this._def.checks,
|
|
42771
|
+
{
|
|
42772
|
+
kind,
|
|
42773
|
+
value,
|
|
42774
|
+
inclusive,
|
|
42775
|
+
message: errorUtil.toString(message)
|
|
42776
|
+
}
|
|
42777
|
+
]
|
|
42778
|
+
});
|
|
42779
|
+
}
|
|
42780
|
+
_addCheck(check) {
|
|
42781
|
+
return new _ZodNumber({
|
|
42782
|
+
...this._def,
|
|
42783
|
+
checks: [...this._def.checks, check]
|
|
42784
|
+
});
|
|
42785
|
+
}
|
|
42786
|
+
int(message) {
|
|
42787
|
+
return this._addCheck({
|
|
42788
|
+
kind: "int",
|
|
42789
|
+
message: errorUtil.toString(message)
|
|
42790
|
+
});
|
|
42791
|
+
}
|
|
42792
|
+
positive(message) {
|
|
42793
|
+
return this._addCheck({
|
|
42794
|
+
kind: "min",
|
|
42795
|
+
value: 0,
|
|
42796
|
+
inclusive: false,
|
|
42797
|
+
message: errorUtil.toString(message)
|
|
42798
|
+
});
|
|
42799
|
+
}
|
|
42800
|
+
negative(message) {
|
|
42801
|
+
return this._addCheck({
|
|
42802
|
+
kind: "max",
|
|
42803
|
+
value: 0,
|
|
42804
|
+
inclusive: false,
|
|
42805
|
+
message: errorUtil.toString(message)
|
|
42806
|
+
});
|
|
42807
|
+
}
|
|
42808
|
+
nonpositive(message) {
|
|
42809
|
+
return this._addCheck({
|
|
42810
|
+
kind: "max",
|
|
42811
|
+
value: 0,
|
|
42812
|
+
inclusive: true,
|
|
42813
|
+
message: errorUtil.toString(message)
|
|
42814
|
+
});
|
|
42815
|
+
}
|
|
42816
|
+
nonnegative(message) {
|
|
42817
|
+
return this._addCheck({
|
|
42818
|
+
kind: "min",
|
|
42819
|
+
value: 0,
|
|
42820
|
+
inclusive: true,
|
|
42821
|
+
message: errorUtil.toString(message)
|
|
42822
|
+
});
|
|
42823
|
+
}
|
|
42824
|
+
multipleOf(value, message) {
|
|
42825
|
+
return this._addCheck({
|
|
42826
|
+
kind: "multipleOf",
|
|
42827
|
+
value,
|
|
42828
|
+
message: errorUtil.toString(message)
|
|
42829
|
+
});
|
|
42830
|
+
}
|
|
42831
|
+
finite(message) {
|
|
42832
|
+
return this._addCheck({
|
|
42833
|
+
kind: "finite",
|
|
42834
|
+
message: errorUtil.toString(message)
|
|
42835
|
+
});
|
|
42836
|
+
}
|
|
42837
|
+
safe(message) {
|
|
42838
|
+
return this._addCheck({
|
|
42839
|
+
kind: "min",
|
|
42840
|
+
inclusive: true,
|
|
42841
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
42842
|
+
message: errorUtil.toString(message)
|
|
42843
|
+
})._addCheck({
|
|
42844
|
+
kind: "max",
|
|
42845
|
+
inclusive: true,
|
|
42846
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
42847
|
+
message: errorUtil.toString(message)
|
|
42848
|
+
});
|
|
42849
|
+
}
|
|
42850
|
+
get minValue() {
|
|
42851
|
+
let min = null;
|
|
42852
|
+
for (const ch2 of this._def.checks) {
|
|
42853
|
+
if (ch2.kind === "min") {
|
|
42854
|
+
if (min === null || ch2.value > min)
|
|
42855
|
+
min = ch2.value;
|
|
42856
|
+
}
|
|
42857
|
+
}
|
|
42858
|
+
return min;
|
|
42859
|
+
}
|
|
42860
|
+
get maxValue() {
|
|
42861
|
+
let max2 = null;
|
|
42862
|
+
for (const ch2 of this._def.checks) {
|
|
42863
|
+
if (ch2.kind === "max") {
|
|
42864
|
+
if (max2 === null || ch2.value < max2)
|
|
42865
|
+
max2 = ch2.value;
|
|
42866
|
+
}
|
|
42867
|
+
}
|
|
42868
|
+
return max2;
|
|
42869
|
+
}
|
|
42870
|
+
get isInt() {
|
|
42871
|
+
return !!this._def.checks.find((ch2) => ch2.kind === "int" || ch2.kind === "multipleOf" && util.isInteger(ch2.value));
|
|
42872
|
+
}
|
|
42873
|
+
get isFinite() {
|
|
42874
|
+
let max2 = null;
|
|
42875
|
+
let min = null;
|
|
42876
|
+
for (const ch2 of this._def.checks) {
|
|
42877
|
+
if (ch2.kind === "finite" || ch2.kind === "int" || ch2.kind === "multipleOf") {
|
|
42878
|
+
return true;
|
|
42879
|
+
} else if (ch2.kind === "min") {
|
|
42880
|
+
if (min === null || ch2.value > min)
|
|
42881
|
+
min = ch2.value;
|
|
42882
|
+
} else if (ch2.kind === "max") {
|
|
42883
|
+
if (max2 === null || ch2.value < max2)
|
|
42884
|
+
max2 = ch2.value;
|
|
42885
|
+
}
|
|
42886
|
+
}
|
|
42887
|
+
return Number.isFinite(min) && Number.isFinite(max2);
|
|
42888
|
+
}
|
|
42889
|
+
};
|
|
42890
|
+
ZodNumber.create = (params) => {
|
|
42891
|
+
return new ZodNumber({
|
|
42892
|
+
checks: [],
|
|
42893
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
42894
|
+
coerce: params?.coerce || false,
|
|
42895
|
+
...processCreateParams(params)
|
|
42896
|
+
});
|
|
42897
|
+
};
|
|
42898
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
42899
|
+
constructor() {
|
|
42900
|
+
super(...arguments);
|
|
42901
|
+
this.min = this.gte;
|
|
42902
|
+
this.max = this.lte;
|
|
42903
|
+
}
|
|
42904
|
+
_parse(input) {
|
|
42905
|
+
if (this._def.coerce) {
|
|
42906
|
+
try {
|
|
42907
|
+
input.data = BigInt(input.data);
|
|
42908
|
+
} catch {
|
|
42909
|
+
return this._getInvalidInput(input);
|
|
42910
|
+
}
|
|
42911
|
+
}
|
|
42912
|
+
const parsedType = this._getType(input);
|
|
42913
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
42914
|
+
return this._getInvalidInput(input);
|
|
42915
|
+
}
|
|
42916
|
+
let ctx = void 0;
|
|
42917
|
+
const status = new ParseStatus();
|
|
42918
|
+
for (const check of this._def.checks) {
|
|
42919
|
+
if (check.kind === "min") {
|
|
42920
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
42921
|
+
if (tooSmall) {
|
|
42922
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42923
|
+
addIssueToContext(ctx, {
|
|
42924
|
+
code: ZodIssueCode2.too_small,
|
|
42925
|
+
type: "bigint",
|
|
42926
|
+
minimum: check.value,
|
|
42927
|
+
inclusive: check.inclusive,
|
|
42928
|
+
message: check.message
|
|
42929
|
+
});
|
|
42930
|
+
status.dirty();
|
|
42931
|
+
}
|
|
42932
|
+
} else if (check.kind === "max") {
|
|
42933
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
42934
|
+
if (tooBig) {
|
|
42935
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42936
|
+
addIssueToContext(ctx, {
|
|
42937
|
+
code: ZodIssueCode2.too_big,
|
|
42938
|
+
type: "bigint",
|
|
42939
|
+
maximum: check.value,
|
|
42940
|
+
inclusive: check.inclusive,
|
|
42941
|
+
message: check.message
|
|
42942
|
+
});
|
|
42943
|
+
status.dirty();
|
|
42944
|
+
}
|
|
42945
|
+
} else if (check.kind === "multipleOf") {
|
|
42946
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
42947
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
42948
|
+
addIssueToContext(ctx, {
|
|
42949
|
+
code: ZodIssueCode2.not_multiple_of,
|
|
42950
|
+
multipleOf: check.value,
|
|
42951
|
+
message: check.message
|
|
42952
|
+
});
|
|
42953
|
+
status.dirty();
|
|
42954
|
+
}
|
|
42955
|
+
} else {
|
|
42956
|
+
util.assertNever(check);
|
|
42957
|
+
}
|
|
42958
|
+
}
|
|
42959
|
+
return { status: status.value, value: input.data };
|
|
42960
|
+
}
|
|
42961
|
+
_getInvalidInput(input) {
|
|
42962
|
+
const ctx = this._getOrReturnCtx(input);
|
|
42963
|
+
addIssueToContext(ctx, {
|
|
42964
|
+
code: ZodIssueCode2.invalid_type,
|
|
42965
|
+
expected: ZodParsedType.bigint,
|
|
42966
|
+
received: ctx.parsedType
|
|
42967
|
+
});
|
|
42968
|
+
return INVALID;
|
|
42969
|
+
}
|
|
42970
|
+
gte(value, message) {
|
|
42971
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
42972
|
+
}
|
|
42973
|
+
gt(value, message) {
|
|
42974
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
42975
|
+
}
|
|
42976
|
+
lte(value, message) {
|
|
42977
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
42978
|
+
}
|
|
42979
|
+
lt(value, message) {
|
|
42980
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
42981
|
+
}
|
|
42982
|
+
setLimit(kind, value, inclusive, message) {
|
|
42983
|
+
return new _ZodBigInt({
|
|
42984
|
+
...this._def,
|
|
42985
|
+
checks: [
|
|
42986
|
+
...this._def.checks,
|
|
42987
|
+
{
|
|
42988
|
+
kind,
|
|
42989
|
+
value,
|
|
42990
|
+
inclusive,
|
|
42991
|
+
message: errorUtil.toString(message)
|
|
42992
|
+
}
|
|
42993
|
+
]
|
|
42994
|
+
});
|
|
42995
|
+
}
|
|
42996
|
+
_addCheck(check) {
|
|
42997
|
+
return new _ZodBigInt({
|
|
42998
|
+
...this._def,
|
|
42999
|
+
checks: [...this._def.checks, check]
|
|
43000
|
+
});
|
|
43001
|
+
}
|
|
43002
|
+
positive(message) {
|
|
43003
|
+
return this._addCheck({
|
|
43004
|
+
kind: "min",
|
|
43005
|
+
value: BigInt(0),
|
|
43006
|
+
inclusive: false,
|
|
43007
|
+
message: errorUtil.toString(message)
|
|
43008
|
+
});
|
|
43009
|
+
}
|
|
43010
|
+
negative(message) {
|
|
43011
|
+
return this._addCheck({
|
|
43012
|
+
kind: "max",
|
|
43013
|
+
value: BigInt(0),
|
|
43014
|
+
inclusive: false,
|
|
43015
|
+
message: errorUtil.toString(message)
|
|
43016
|
+
});
|
|
43017
|
+
}
|
|
43018
|
+
nonpositive(message) {
|
|
43019
|
+
return this._addCheck({
|
|
43020
|
+
kind: "max",
|
|
43021
|
+
value: BigInt(0),
|
|
43022
|
+
inclusive: true,
|
|
43023
|
+
message: errorUtil.toString(message)
|
|
43024
|
+
});
|
|
43025
|
+
}
|
|
43026
|
+
nonnegative(message) {
|
|
43027
|
+
return this._addCheck({
|
|
43028
|
+
kind: "min",
|
|
43029
|
+
value: BigInt(0),
|
|
43030
|
+
inclusive: true,
|
|
43031
|
+
message: errorUtil.toString(message)
|
|
43032
|
+
});
|
|
43033
|
+
}
|
|
43034
|
+
multipleOf(value, message) {
|
|
43035
|
+
return this._addCheck({
|
|
43036
|
+
kind: "multipleOf",
|
|
43037
|
+
value,
|
|
43038
|
+
message: errorUtil.toString(message)
|
|
43039
|
+
});
|
|
43040
|
+
}
|
|
43041
|
+
get minValue() {
|
|
43042
|
+
let min = null;
|
|
43043
|
+
for (const ch2 of this._def.checks) {
|
|
43044
|
+
if (ch2.kind === "min") {
|
|
43045
|
+
if (min === null || ch2.value > min)
|
|
43046
|
+
min = ch2.value;
|
|
43047
|
+
}
|
|
43048
|
+
}
|
|
43049
|
+
return min;
|
|
43050
|
+
}
|
|
43051
|
+
get maxValue() {
|
|
43052
|
+
let max2 = null;
|
|
43053
|
+
for (const ch2 of this._def.checks) {
|
|
43054
|
+
if (ch2.kind === "max") {
|
|
43055
|
+
if (max2 === null || ch2.value < max2)
|
|
43056
|
+
max2 = ch2.value;
|
|
43057
|
+
}
|
|
43058
|
+
}
|
|
43059
|
+
return max2;
|
|
43060
|
+
}
|
|
43061
|
+
};
|
|
43062
|
+
ZodBigInt.create = (params) => {
|
|
43063
|
+
return new ZodBigInt({
|
|
43064
|
+
checks: [],
|
|
43065
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
43066
|
+
coerce: params?.coerce ?? false,
|
|
43067
|
+
...processCreateParams(params)
|
|
43068
|
+
});
|
|
43069
|
+
};
|
|
43070
|
+
var ZodBoolean = class extends ZodType {
|
|
43071
|
+
_parse(input) {
|
|
43072
|
+
if (this._def.coerce) {
|
|
43073
|
+
input.data = Boolean(input.data);
|
|
43074
|
+
}
|
|
43075
|
+
const parsedType = this._getType(input);
|
|
43076
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
43077
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43078
|
+
addIssueToContext(ctx, {
|
|
43079
|
+
code: ZodIssueCode2.invalid_type,
|
|
43080
|
+
expected: ZodParsedType.boolean,
|
|
43081
|
+
received: ctx.parsedType
|
|
43082
|
+
});
|
|
43083
|
+
return INVALID;
|
|
43084
|
+
}
|
|
43085
|
+
return OK(input.data);
|
|
43086
|
+
}
|
|
43087
|
+
};
|
|
43088
|
+
ZodBoolean.create = (params) => {
|
|
43089
|
+
return new ZodBoolean({
|
|
43090
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
43091
|
+
coerce: params?.coerce || false,
|
|
43092
|
+
...processCreateParams(params)
|
|
43093
|
+
});
|
|
43094
|
+
};
|
|
43095
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
43096
|
+
_parse(input) {
|
|
43097
|
+
if (this._def.coerce) {
|
|
43098
|
+
input.data = new Date(input.data);
|
|
43099
|
+
}
|
|
43100
|
+
const parsedType = this._getType(input);
|
|
43101
|
+
if (parsedType !== ZodParsedType.date) {
|
|
43102
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
43103
|
+
addIssueToContext(ctx2, {
|
|
43104
|
+
code: ZodIssueCode2.invalid_type,
|
|
43105
|
+
expected: ZodParsedType.date,
|
|
43106
|
+
received: ctx2.parsedType
|
|
43107
|
+
});
|
|
43108
|
+
return INVALID;
|
|
43109
|
+
}
|
|
43110
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
43111
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
43112
|
+
addIssueToContext(ctx2, {
|
|
43113
|
+
code: ZodIssueCode2.invalid_date
|
|
43114
|
+
});
|
|
43115
|
+
return INVALID;
|
|
43116
|
+
}
|
|
43117
|
+
const status = new ParseStatus();
|
|
43118
|
+
let ctx = void 0;
|
|
43119
|
+
for (const check of this._def.checks) {
|
|
43120
|
+
if (check.kind === "min") {
|
|
43121
|
+
if (input.data.getTime() < check.value) {
|
|
43122
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
43123
|
+
addIssueToContext(ctx, {
|
|
43124
|
+
code: ZodIssueCode2.too_small,
|
|
43125
|
+
message: check.message,
|
|
43126
|
+
inclusive: true,
|
|
43127
|
+
exact: false,
|
|
43128
|
+
minimum: check.value,
|
|
43129
|
+
type: "date"
|
|
43130
|
+
});
|
|
43131
|
+
status.dirty();
|
|
43132
|
+
}
|
|
43133
|
+
} else if (check.kind === "max") {
|
|
43134
|
+
if (input.data.getTime() > check.value) {
|
|
43135
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
43136
|
+
addIssueToContext(ctx, {
|
|
43137
|
+
code: ZodIssueCode2.too_big,
|
|
43138
|
+
message: check.message,
|
|
43139
|
+
inclusive: true,
|
|
43140
|
+
exact: false,
|
|
43141
|
+
maximum: check.value,
|
|
43142
|
+
type: "date"
|
|
43143
|
+
});
|
|
43144
|
+
status.dirty();
|
|
43145
|
+
}
|
|
43146
|
+
} else {
|
|
43147
|
+
util.assertNever(check);
|
|
43148
|
+
}
|
|
43149
|
+
}
|
|
43150
|
+
return {
|
|
43151
|
+
status: status.value,
|
|
43152
|
+
value: new Date(input.data.getTime())
|
|
43153
|
+
};
|
|
43154
|
+
}
|
|
43155
|
+
_addCheck(check) {
|
|
43156
|
+
return new _ZodDate({
|
|
43157
|
+
...this._def,
|
|
43158
|
+
checks: [...this._def.checks, check]
|
|
43159
|
+
});
|
|
43160
|
+
}
|
|
43161
|
+
min(minDate, message) {
|
|
43162
|
+
return this._addCheck({
|
|
43163
|
+
kind: "min",
|
|
43164
|
+
value: minDate.getTime(),
|
|
43165
|
+
message: errorUtil.toString(message)
|
|
43166
|
+
});
|
|
43167
|
+
}
|
|
43168
|
+
max(maxDate, message) {
|
|
43169
|
+
return this._addCheck({
|
|
43170
|
+
kind: "max",
|
|
43171
|
+
value: maxDate.getTime(),
|
|
43172
|
+
message: errorUtil.toString(message)
|
|
43173
|
+
});
|
|
43174
|
+
}
|
|
43175
|
+
get minDate() {
|
|
43176
|
+
let min = null;
|
|
43177
|
+
for (const ch2 of this._def.checks) {
|
|
43178
|
+
if (ch2.kind === "min") {
|
|
43179
|
+
if (min === null || ch2.value > min)
|
|
43180
|
+
min = ch2.value;
|
|
43181
|
+
}
|
|
43182
|
+
}
|
|
43183
|
+
return min != null ? new Date(min) : null;
|
|
43184
|
+
}
|
|
43185
|
+
get maxDate() {
|
|
43186
|
+
let max2 = null;
|
|
43187
|
+
for (const ch2 of this._def.checks) {
|
|
43188
|
+
if (ch2.kind === "max") {
|
|
43189
|
+
if (max2 === null || ch2.value < max2)
|
|
43190
|
+
max2 = ch2.value;
|
|
43191
|
+
}
|
|
43192
|
+
}
|
|
43193
|
+
return max2 != null ? new Date(max2) : null;
|
|
43194
|
+
}
|
|
43195
|
+
};
|
|
43196
|
+
ZodDate.create = (params) => {
|
|
43197
|
+
return new ZodDate({
|
|
43198
|
+
checks: [],
|
|
43199
|
+
coerce: params?.coerce || false,
|
|
43200
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
43201
|
+
...processCreateParams(params)
|
|
43202
|
+
});
|
|
43203
|
+
};
|
|
43204
|
+
var ZodSymbol = class extends ZodType {
|
|
43205
|
+
_parse(input) {
|
|
43206
|
+
const parsedType = this._getType(input);
|
|
43207
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
43208
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43209
|
+
addIssueToContext(ctx, {
|
|
43210
|
+
code: ZodIssueCode2.invalid_type,
|
|
43211
|
+
expected: ZodParsedType.symbol,
|
|
43212
|
+
received: ctx.parsedType
|
|
43213
|
+
});
|
|
43214
|
+
return INVALID;
|
|
43215
|
+
}
|
|
43216
|
+
return OK(input.data);
|
|
43217
|
+
}
|
|
43218
|
+
};
|
|
43219
|
+
ZodSymbol.create = (params) => {
|
|
43220
|
+
return new ZodSymbol({
|
|
43221
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
43222
|
+
...processCreateParams(params)
|
|
43223
|
+
});
|
|
43224
|
+
};
|
|
43225
|
+
var ZodUndefined = class extends ZodType {
|
|
43226
|
+
_parse(input) {
|
|
43227
|
+
const parsedType = this._getType(input);
|
|
43228
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
43229
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43230
|
+
addIssueToContext(ctx, {
|
|
43231
|
+
code: ZodIssueCode2.invalid_type,
|
|
43232
|
+
expected: ZodParsedType.undefined,
|
|
43233
|
+
received: ctx.parsedType
|
|
43234
|
+
});
|
|
43235
|
+
return INVALID;
|
|
43236
|
+
}
|
|
43237
|
+
return OK(input.data);
|
|
43238
|
+
}
|
|
43239
|
+
};
|
|
43240
|
+
ZodUndefined.create = (params) => {
|
|
43241
|
+
return new ZodUndefined({
|
|
43242
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
43243
|
+
...processCreateParams(params)
|
|
43244
|
+
});
|
|
43245
|
+
};
|
|
43246
|
+
var ZodNull = class extends ZodType {
|
|
43247
|
+
_parse(input) {
|
|
43248
|
+
const parsedType = this._getType(input);
|
|
43249
|
+
if (parsedType !== ZodParsedType.null) {
|
|
43250
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43251
|
+
addIssueToContext(ctx, {
|
|
43252
|
+
code: ZodIssueCode2.invalid_type,
|
|
43253
|
+
expected: ZodParsedType.null,
|
|
43254
|
+
received: ctx.parsedType
|
|
43255
|
+
});
|
|
43256
|
+
return INVALID;
|
|
43257
|
+
}
|
|
43258
|
+
return OK(input.data);
|
|
43259
|
+
}
|
|
43260
|
+
};
|
|
43261
|
+
ZodNull.create = (params) => {
|
|
43262
|
+
return new ZodNull({
|
|
43263
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
43264
|
+
...processCreateParams(params)
|
|
43265
|
+
});
|
|
43266
|
+
};
|
|
43267
|
+
var ZodAny = class extends ZodType {
|
|
43268
|
+
constructor() {
|
|
43269
|
+
super(...arguments);
|
|
43270
|
+
this._any = true;
|
|
43271
|
+
}
|
|
43272
|
+
_parse(input) {
|
|
43273
|
+
return OK(input.data);
|
|
43274
|
+
}
|
|
43275
|
+
};
|
|
43276
|
+
ZodAny.create = (params) => {
|
|
43277
|
+
return new ZodAny({
|
|
43278
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
43279
|
+
...processCreateParams(params)
|
|
43280
|
+
});
|
|
43281
|
+
};
|
|
43282
|
+
var ZodUnknown = class extends ZodType {
|
|
43283
|
+
constructor() {
|
|
43284
|
+
super(...arguments);
|
|
43285
|
+
this._unknown = true;
|
|
43286
|
+
}
|
|
43287
|
+
_parse(input) {
|
|
43288
|
+
return OK(input.data);
|
|
43289
|
+
}
|
|
43290
|
+
};
|
|
43291
|
+
ZodUnknown.create = (params) => {
|
|
43292
|
+
return new ZodUnknown({
|
|
43293
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
43294
|
+
...processCreateParams(params)
|
|
43295
|
+
});
|
|
43296
|
+
};
|
|
43297
|
+
var ZodNever = class extends ZodType {
|
|
43298
|
+
_parse(input) {
|
|
43299
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43300
|
+
addIssueToContext(ctx, {
|
|
43301
|
+
code: ZodIssueCode2.invalid_type,
|
|
43302
|
+
expected: ZodParsedType.never,
|
|
43303
|
+
received: ctx.parsedType
|
|
43304
|
+
});
|
|
43305
|
+
return INVALID;
|
|
43306
|
+
}
|
|
43307
|
+
};
|
|
43308
|
+
ZodNever.create = (params) => {
|
|
43309
|
+
return new ZodNever({
|
|
43310
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
43311
|
+
...processCreateParams(params)
|
|
43312
|
+
});
|
|
43313
|
+
};
|
|
43314
|
+
var ZodVoid = class extends ZodType {
|
|
43315
|
+
_parse(input) {
|
|
43316
|
+
const parsedType = this._getType(input);
|
|
43317
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
43318
|
+
const ctx = this._getOrReturnCtx(input);
|
|
43319
|
+
addIssueToContext(ctx, {
|
|
43320
|
+
code: ZodIssueCode2.invalid_type,
|
|
43321
|
+
expected: ZodParsedType.void,
|
|
43322
|
+
received: ctx.parsedType
|
|
43323
|
+
});
|
|
43324
|
+
return INVALID;
|
|
43325
|
+
}
|
|
43326
|
+
return OK(input.data);
|
|
43327
|
+
}
|
|
43328
|
+
};
|
|
43329
|
+
ZodVoid.create = (params) => {
|
|
43330
|
+
return new ZodVoid({
|
|
43331
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
43332
|
+
...processCreateParams(params)
|
|
43333
|
+
});
|
|
43334
|
+
};
|
|
43335
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
43336
|
+
_parse(input) {
|
|
43337
|
+
const { ctx, status } = this._processInputParams(input);
|
|
43338
|
+
const def = this._def;
|
|
43339
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
43340
|
+
addIssueToContext(ctx, {
|
|
43341
|
+
code: ZodIssueCode2.invalid_type,
|
|
43342
|
+
expected: ZodParsedType.array,
|
|
43343
|
+
received: ctx.parsedType
|
|
43344
|
+
});
|
|
43345
|
+
return INVALID;
|
|
43346
|
+
}
|
|
43347
|
+
if (def.exactLength !== null) {
|
|
43348
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
43349
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
43350
|
+
if (tooBig || tooSmall) {
|
|
43351
|
+
addIssueToContext(ctx, {
|
|
43352
|
+
code: tooBig ? ZodIssueCode2.too_big : ZodIssueCode2.too_small,
|
|
43353
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
43354
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
43355
|
+
type: "array",
|
|
43356
|
+
inclusive: true,
|
|
43357
|
+
exact: true,
|
|
43358
|
+
message: def.exactLength.message
|
|
43359
|
+
});
|
|
43360
|
+
status.dirty();
|
|
43361
|
+
}
|
|
43362
|
+
}
|
|
43363
|
+
if (def.minLength !== null) {
|
|
43364
|
+
if (ctx.data.length < def.minLength.value) {
|
|
43365
|
+
addIssueToContext(ctx, {
|
|
43366
|
+
code: ZodIssueCode2.too_small,
|
|
43367
|
+
minimum: def.minLength.value,
|
|
43368
|
+
type: "array",
|
|
43369
|
+
inclusive: true,
|
|
43370
|
+
exact: false,
|
|
43371
|
+
message: def.minLength.message
|
|
43372
|
+
});
|
|
43373
|
+
status.dirty();
|
|
43374
|
+
}
|
|
43375
|
+
}
|
|
43376
|
+
if (def.maxLength !== null) {
|
|
43377
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
43378
|
+
addIssueToContext(ctx, {
|
|
43379
|
+
code: ZodIssueCode2.too_big,
|
|
43380
|
+
maximum: def.maxLength.value,
|
|
43381
|
+
type: "array",
|
|
43382
|
+
inclusive: true,
|
|
43383
|
+
exact: false,
|
|
43384
|
+
message: def.maxLength.message
|
|
43385
|
+
});
|
|
43386
|
+
status.dirty();
|
|
43387
|
+
}
|
|
43388
|
+
}
|
|
43389
|
+
if (ctx.common.async) {
|
|
43390
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
43391
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
43392
|
+
})).then((result2) => {
|
|
43393
|
+
return ParseStatus.mergeArray(status, result2);
|
|
43394
|
+
});
|
|
43395
|
+
}
|
|
43396
|
+
const result = [...ctx.data].map((item, i) => {
|
|
43397
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
43398
|
+
});
|
|
43399
|
+
return ParseStatus.mergeArray(status, result);
|
|
43400
|
+
}
|
|
43401
|
+
get element() {
|
|
43402
|
+
return this._def.type;
|
|
43403
|
+
}
|
|
43404
|
+
min(minLength, message) {
|
|
43405
|
+
return new _ZodArray({
|
|
43406
|
+
...this._def,
|
|
43407
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
43408
|
+
});
|
|
43409
|
+
}
|
|
43410
|
+
max(maxLength, message) {
|
|
43411
|
+
return new _ZodArray({
|
|
43412
|
+
...this._def,
|
|
43413
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
43414
|
+
});
|
|
43415
|
+
}
|
|
43416
|
+
length(len, message) {
|
|
43417
|
+
return new _ZodArray({
|
|
43418
|
+
...this._def,
|
|
43419
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
43420
|
+
});
|
|
43421
|
+
}
|
|
43422
|
+
nonempty(message) {
|
|
43423
|
+
return this.min(1, message);
|
|
43424
|
+
}
|
|
43425
|
+
};
|
|
43426
|
+
ZodArray.create = (schema, params) => {
|
|
43427
|
+
return new ZodArray({
|
|
43428
|
+
type: schema,
|
|
43429
|
+
minLength: null,
|
|
43430
|
+
maxLength: null,
|
|
43431
|
+
exactLength: null,
|
|
43432
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
43433
|
+
...processCreateParams(params)
|
|
43434
|
+
});
|
|
43435
|
+
};
|
|
43436
|
+
function deepPartialify(schema) {
|
|
43437
|
+
if (schema instanceof ZodObject) {
|
|
43438
|
+
const newShape = {};
|
|
43439
|
+
for (const key in schema.shape) {
|
|
43440
|
+
const fieldSchema = schema.shape[key];
|
|
43441
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
43442
|
+
}
|
|
43443
|
+
return new ZodObject({
|
|
43444
|
+
...schema._def,
|
|
43445
|
+
shape: () => newShape
|
|
43446
|
+
});
|
|
43447
|
+
} else if (schema instanceof ZodArray) {
|
|
43448
|
+
return new ZodArray({
|
|
43449
|
+
...schema._def,
|
|
43450
|
+
type: deepPartialify(schema.element)
|
|
43451
|
+
});
|
|
43452
|
+
} else if (schema instanceof ZodOptional) {
|
|
43453
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
43454
|
+
} else if (schema instanceof ZodNullable) {
|
|
43455
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
43456
|
+
} else if (schema instanceof ZodTuple) {
|
|
43457
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
43458
|
+
} else {
|
|
43459
|
+
return schema;
|
|
43460
|
+
}
|
|
43461
|
+
}
|
|
43462
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
43463
|
+
constructor() {
|
|
43464
|
+
super(...arguments);
|
|
43465
|
+
this._cached = null;
|
|
43466
|
+
this.nonstrict = this.passthrough;
|
|
43467
|
+
this.augment = this.extend;
|
|
43468
|
+
}
|
|
43469
|
+
_getCached() {
|
|
43470
|
+
if (this._cached !== null)
|
|
43471
|
+
return this._cached;
|
|
43472
|
+
const shape = this._def.shape();
|
|
43473
|
+
const keys2 = util.objectKeys(shape);
|
|
43474
|
+
this._cached = { shape, keys: keys2 };
|
|
43475
|
+
return this._cached;
|
|
43476
|
+
}
|
|
43477
|
+
_parse(input) {
|
|
43478
|
+
const parsedType = this._getType(input);
|
|
43479
|
+
if (parsedType !== ZodParsedType.object) {
|
|
43480
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
43481
|
+
addIssueToContext(ctx2, {
|
|
43482
|
+
code: ZodIssueCode2.invalid_type,
|
|
43483
|
+
expected: ZodParsedType.object,
|
|
43484
|
+
received: ctx2.parsedType
|
|
43485
|
+
});
|
|
43486
|
+
return INVALID;
|
|
43487
|
+
}
|
|
43488
|
+
const { status, ctx } = this._processInputParams(input);
|
|
43489
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
43490
|
+
const extraKeys = [];
|
|
43491
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
43492
|
+
for (const key in ctx.data) {
|
|
43493
|
+
if (!shapeKeys.includes(key)) {
|
|
43494
|
+
extraKeys.push(key);
|
|
43495
|
+
}
|
|
43496
|
+
}
|
|
43497
|
+
}
|
|
43498
|
+
const pairs = [];
|
|
43499
|
+
for (const key of shapeKeys) {
|
|
43500
|
+
const keyValidator = shape[key];
|
|
43501
|
+
const value = ctx.data[key];
|
|
43502
|
+
pairs.push({
|
|
43503
|
+
key: { status: "valid", value: key },
|
|
43504
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
43505
|
+
alwaysSet: key in ctx.data
|
|
43506
|
+
});
|
|
43507
|
+
}
|
|
43508
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
43509
|
+
const unknownKeys = this._def.unknownKeys;
|
|
43510
|
+
if (unknownKeys === "passthrough") {
|
|
43511
|
+
for (const key of extraKeys) {
|
|
43512
|
+
pairs.push({
|
|
43513
|
+
key: { status: "valid", value: key },
|
|
43514
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
43515
|
+
});
|
|
43516
|
+
}
|
|
43517
|
+
} else if (unknownKeys === "strict") {
|
|
43518
|
+
if (extraKeys.length > 0) {
|
|
43519
|
+
addIssueToContext(ctx, {
|
|
43520
|
+
code: ZodIssueCode2.unrecognized_keys,
|
|
43521
|
+
keys: extraKeys
|
|
43522
|
+
});
|
|
43523
|
+
status.dirty();
|
|
43524
|
+
}
|
|
43525
|
+
} else if (unknownKeys === "strip") {
|
|
43526
|
+
} else {
|
|
43527
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
43528
|
+
}
|
|
43529
|
+
} else {
|
|
43530
|
+
const catchall = this._def.catchall;
|
|
43531
|
+
for (const key of extraKeys) {
|
|
43532
|
+
const value = ctx.data[key];
|
|
43533
|
+
pairs.push({
|
|
43534
|
+
key: { status: "valid", value: key },
|
|
43535
|
+
value: catchall._parse(
|
|
43536
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
43537
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
43538
|
+
),
|
|
43539
|
+
alwaysSet: key in ctx.data
|
|
43540
|
+
});
|
|
43541
|
+
}
|
|
43542
|
+
}
|
|
43543
|
+
if (ctx.common.async) {
|
|
43544
|
+
return Promise.resolve().then(async () => {
|
|
43545
|
+
const syncPairs = [];
|
|
43546
|
+
for (const pair of pairs) {
|
|
43547
|
+
const key = await pair.key;
|
|
43548
|
+
const value = await pair.value;
|
|
43549
|
+
syncPairs.push({
|
|
43550
|
+
key,
|
|
43551
|
+
value,
|
|
43552
|
+
alwaysSet: pair.alwaysSet
|
|
43553
|
+
});
|
|
43554
|
+
}
|
|
43555
|
+
return syncPairs;
|
|
43556
|
+
}).then((syncPairs) => {
|
|
43557
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
43558
|
+
});
|
|
43559
|
+
} else {
|
|
43560
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
43561
|
+
}
|
|
43562
|
+
}
|
|
43563
|
+
get shape() {
|
|
43564
|
+
return this._def.shape();
|
|
43565
|
+
}
|
|
43566
|
+
strict(message) {
|
|
43567
|
+
errorUtil.errToObj;
|
|
43568
|
+
return new _ZodObject({
|
|
43569
|
+
...this._def,
|
|
43570
|
+
unknownKeys: "strict",
|
|
43571
|
+
...message !== void 0 ? {
|
|
43572
|
+
errorMap: (issue3, ctx) => {
|
|
43573
|
+
const defaultError = this._def.errorMap?.(issue3, ctx).message ?? ctx.defaultError;
|
|
43574
|
+
if (issue3.code === "unrecognized_keys")
|
|
43575
|
+
return {
|
|
43576
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
43577
|
+
};
|
|
43578
|
+
return {
|
|
43579
|
+
message: defaultError
|
|
43580
|
+
};
|
|
43581
|
+
}
|
|
43582
|
+
} : {}
|
|
43583
|
+
});
|
|
43584
|
+
}
|
|
43585
|
+
strip() {
|
|
43586
|
+
return new _ZodObject({
|
|
43587
|
+
...this._def,
|
|
43588
|
+
unknownKeys: "strip"
|
|
43589
|
+
});
|
|
43590
|
+
}
|
|
43591
|
+
passthrough() {
|
|
43592
|
+
return new _ZodObject({
|
|
43593
|
+
...this._def,
|
|
43594
|
+
unknownKeys: "passthrough"
|
|
43595
|
+
});
|
|
43596
|
+
}
|
|
43597
|
+
// const AugmentFactory =
|
|
43598
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
43599
|
+
// <Augmentation extends ZodRawShape>(
|
|
43600
|
+
// augmentation: Augmentation
|
|
43601
|
+
// ): ZodObject<
|
|
43602
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
43603
|
+
// Def["unknownKeys"],
|
|
43604
|
+
// Def["catchall"]
|
|
43605
|
+
// > => {
|
|
43606
|
+
// return new ZodObject({
|
|
43607
|
+
// ...def,
|
|
43608
|
+
// shape: () => ({
|
|
43609
|
+
// ...def.shape(),
|
|
43610
|
+
// ...augmentation,
|
|
43611
|
+
// }),
|
|
43612
|
+
// }) as any;
|
|
43613
|
+
// };
|
|
43614
|
+
extend(augmentation) {
|
|
43615
|
+
return new _ZodObject({
|
|
43616
|
+
...this._def,
|
|
43617
|
+
shape: () => ({
|
|
43618
|
+
...this._def.shape(),
|
|
43619
|
+
...augmentation
|
|
43620
|
+
})
|
|
43621
|
+
});
|
|
43622
|
+
}
|
|
43623
|
+
/**
|
|
43624
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
43625
|
+
* inferred type of merged objects. Please
|
|
43626
|
+
* upgrade if you are experiencing issues.
|
|
43627
|
+
*/
|
|
43628
|
+
merge(merging) {
|
|
43629
|
+
const merged = new _ZodObject({
|
|
43630
|
+
unknownKeys: merging._def.unknownKeys,
|
|
43631
|
+
catchall: merging._def.catchall,
|
|
43632
|
+
shape: () => ({
|
|
43633
|
+
...this._def.shape(),
|
|
43634
|
+
...merging._def.shape()
|
|
43635
|
+
}),
|
|
43636
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
43637
|
+
});
|
|
43638
|
+
return merged;
|
|
43639
|
+
}
|
|
43640
|
+
// merge<
|
|
43641
|
+
// Incoming extends AnyZodObject,
|
|
43642
|
+
// Augmentation extends Incoming["shape"],
|
|
43643
|
+
// NewOutput extends {
|
|
43644
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
43645
|
+
// ? Augmentation[k]["_output"]
|
|
43646
|
+
// : k extends keyof Output
|
|
43647
|
+
// ? Output[k]
|
|
43648
|
+
// : never;
|
|
43649
|
+
// },
|
|
43650
|
+
// NewInput extends {
|
|
43651
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
43652
|
+
// ? Augmentation[k]["_input"]
|
|
43653
|
+
// : k extends keyof Input
|
|
43654
|
+
// ? Input[k]
|
|
43655
|
+
// : never;
|
|
43656
|
+
// }
|
|
43657
|
+
// >(
|
|
43658
|
+
// merging: Incoming
|
|
43659
|
+
// ): ZodObject<
|
|
43660
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
43661
|
+
// Incoming["_def"]["unknownKeys"],
|
|
43662
|
+
// Incoming["_def"]["catchall"],
|
|
43663
|
+
// NewOutput,
|
|
43664
|
+
// NewInput
|
|
43665
|
+
// > {
|
|
43666
|
+
// const merged: any = new ZodObject({
|
|
43667
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
43668
|
+
// catchall: merging._def.catchall,
|
|
43669
|
+
// shape: () =>
|
|
43670
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
43671
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
43672
|
+
// }) as any;
|
|
43673
|
+
// return merged;
|
|
43674
|
+
// }
|
|
43675
|
+
setKey(key, schema) {
|
|
43676
|
+
return this.augment({ [key]: schema });
|
|
43677
|
+
}
|
|
43678
|
+
// merge<Incoming extends AnyZodObject>(
|
|
43679
|
+
// merging: Incoming
|
|
43680
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
43681
|
+
// ZodObject<
|
|
43682
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
43683
|
+
// Incoming["_def"]["unknownKeys"],
|
|
43684
|
+
// Incoming["_def"]["catchall"]
|
|
43685
|
+
// > {
|
|
43686
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
43687
|
+
// // this._def.shape(),
|
|
43688
|
+
// // merging._def.shape()
|
|
43689
|
+
// // );
|
|
43690
|
+
// const merged: any = new ZodObject({
|
|
43691
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
43692
|
+
// catchall: merging._def.catchall,
|
|
43693
|
+
// shape: () =>
|
|
43694
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
43695
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
43696
|
+
// }) as any;
|
|
43697
|
+
// return merged;
|
|
43698
|
+
// }
|
|
43699
|
+
catchall(index) {
|
|
43700
|
+
return new _ZodObject({
|
|
43701
|
+
...this._def,
|
|
43702
|
+
catchall: index
|
|
43703
|
+
});
|
|
43704
|
+
}
|
|
43705
|
+
pick(mask) {
|
|
43706
|
+
const shape = {};
|
|
43707
|
+
for (const key of util.objectKeys(mask)) {
|
|
43708
|
+
if (mask[key] && this.shape[key]) {
|
|
43709
|
+
shape[key] = this.shape[key];
|
|
43710
|
+
}
|
|
43711
|
+
}
|
|
43712
|
+
return new _ZodObject({
|
|
43713
|
+
...this._def,
|
|
43714
|
+
shape: () => shape
|
|
43715
|
+
});
|
|
43716
|
+
}
|
|
43717
|
+
omit(mask) {
|
|
43718
|
+
const shape = {};
|
|
43719
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
43720
|
+
if (!mask[key]) {
|
|
43721
|
+
shape[key] = this.shape[key];
|
|
43722
|
+
}
|
|
43723
|
+
}
|
|
43724
|
+
return new _ZodObject({
|
|
43725
|
+
...this._def,
|
|
43726
|
+
shape: () => shape
|
|
43727
|
+
});
|
|
43728
|
+
}
|
|
43729
|
+
/**
|
|
43730
|
+
* @deprecated
|
|
43731
|
+
*/
|
|
43732
|
+
deepPartial() {
|
|
43733
|
+
return deepPartialify(this);
|
|
43734
|
+
}
|
|
43735
|
+
partial(mask) {
|
|
43736
|
+
const newShape = {};
|
|
43737
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
43738
|
+
const fieldSchema = this.shape[key];
|
|
43739
|
+
if (mask && !mask[key]) {
|
|
43740
|
+
newShape[key] = fieldSchema;
|
|
43741
|
+
} else {
|
|
43742
|
+
newShape[key] = fieldSchema.optional();
|
|
43743
|
+
}
|
|
43744
|
+
}
|
|
43745
|
+
return new _ZodObject({
|
|
43746
|
+
...this._def,
|
|
43747
|
+
shape: () => newShape
|
|
43748
|
+
});
|
|
43749
|
+
}
|
|
43750
|
+
required(mask) {
|
|
43751
|
+
const newShape = {};
|
|
43752
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
43753
|
+
if (mask && !mask[key]) {
|
|
43754
|
+
newShape[key] = this.shape[key];
|
|
43755
|
+
} else {
|
|
43756
|
+
const fieldSchema = this.shape[key];
|
|
43757
|
+
let newField = fieldSchema;
|
|
43758
|
+
while (newField instanceof ZodOptional) {
|
|
43759
|
+
newField = newField._def.innerType;
|
|
43760
|
+
}
|
|
43761
|
+
newShape[key] = newField;
|
|
43762
|
+
}
|
|
43763
|
+
}
|
|
43764
|
+
return new _ZodObject({
|
|
43765
|
+
...this._def,
|
|
43766
|
+
shape: () => newShape
|
|
43767
|
+
});
|
|
43768
|
+
}
|
|
43769
|
+
keyof() {
|
|
43770
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
43771
|
+
}
|
|
43772
|
+
};
|
|
43773
|
+
ZodObject.create = (shape, params) => {
|
|
43774
|
+
return new ZodObject({
|
|
43775
|
+
shape: () => shape,
|
|
43776
|
+
unknownKeys: "strip",
|
|
43777
|
+
catchall: ZodNever.create(),
|
|
43778
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
43779
|
+
...processCreateParams(params)
|
|
43780
|
+
});
|
|
43781
|
+
};
|
|
43782
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
43783
|
+
return new ZodObject({
|
|
43784
|
+
shape: () => shape,
|
|
43785
|
+
unknownKeys: "strict",
|
|
43786
|
+
catchall: ZodNever.create(),
|
|
43787
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
43788
|
+
...processCreateParams(params)
|
|
43789
|
+
});
|
|
43790
|
+
};
|
|
43791
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
43792
|
+
return new ZodObject({
|
|
43793
|
+
shape,
|
|
43794
|
+
unknownKeys: "strip",
|
|
43795
|
+
catchall: ZodNever.create(),
|
|
43796
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
43797
|
+
...processCreateParams(params)
|
|
43798
|
+
});
|
|
43799
|
+
};
|
|
43800
|
+
var ZodUnion = class extends ZodType {
|
|
43801
|
+
_parse(input) {
|
|
43802
|
+
const { ctx } = this._processInputParams(input);
|
|
43803
|
+
const options = this._def.options;
|
|
43804
|
+
function handleResults(results) {
|
|
43805
|
+
for (const result of results) {
|
|
43806
|
+
if (result.result.status === "valid") {
|
|
43807
|
+
return result.result;
|
|
43808
|
+
}
|
|
43809
|
+
}
|
|
43810
|
+
for (const result of results) {
|
|
43811
|
+
if (result.result.status === "dirty") {
|
|
43812
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
43813
|
+
return result.result;
|
|
43814
|
+
}
|
|
43815
|
+
}
|
|
43816
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
43817
|
+
addIssueToContext(ctx, {
|
|
43818
|
+
code: ZodIssueCode2.invalid_union,
|
|
43819
|
+
unionErrors
|
|
43820
|
+
});
|
|
43821
|
+
return INVALID;
|
|
43822
|
+
}
|
|
43823
|
+
if (ctx.common.async) {
|
|
43824
|
+
return Promise.all(options.map(async (option) => {
|
|
43825
|
+
const childCtx = {
|
|
43826
|
+
...ctx,
|
|
43827
|
+
common: {
|
|
43828
|
+
...ctx.common,
|
|
43829
|
+
issues: []
|
|
43830
|
+
},
|
|
43831
|
+
parent: null
|
|
43832
|
+
};
|
|
43833
|
+
return {
|
|
43834
|
+
result: await option._parseAsync({
|
|
43835
|
+
data: ctx.data,
|
|
43836
|
+
path: ctx.path,
|
|
43837
|
+
parent: childCtx
|
|
43838
|
+
}),
|
|
43839
|
+
ctx: childCtx
|
|
43840
|
+
};
|
|
43841
|
+
})).then(handleResults);
|
|
43842
|
+
} else {
|
|
43843
|
+
let dirty = void 0;
|
|
43844
|
+
const issues = [];
|
|
43845
|
+
for (const option of options) {
|
|
43846
|
+
const childCtx = {
|
|
43847
|
+
...ctx,
|
|
43848
|
+
common: {
|
|
43849
|
+
...ctx.common,
|
|
43850
|
+
issues: []
|
|
43851
|
+
},
|
|
43852
|
+
parent: null
|
|
43853
|
+
};
|
|
43854
|
+
const result = option._parseSync({
|
|
43855
|
+
data: ctx.data,
|
|
43856
|
+
path: ctx.path,
|
|
43857
|
+
parent: childCtx
|
|
43858
|
+
});
|
|
43859
|
+
if (result.status === "valid") {
|
|
43860
|
+
return result;
|
|
43861
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
43862
|
+
dirty = { result, ctx: childCtx };
|
|
43863
|
+
}
|
|
43864
|
+
if (childCtx.common.issues.length) {
|
|
43865
|
+
issues.push(childCtx.common.issues);
|
|
43866
|
+
}
|
|
43867
|
+
}
|
|
43868
|
+
if (dirty) {
|
|
43869
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
43870
|
+
return dirty.result;
|
|
43871
|
+
}
|
|
43872
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
43873
|
+
addIssueToContext(ctx, {
|
|
43874
|
+
code: ZodIssueCode2.invalid_union,
|
|
43875
|
+
unionErrors
|
|
43876
|
+
});
|
|
43877
|
+
return INVALID;
|
|
43878
|
+
}
|
|
43879
|
+
}
|
|
43880
|
+
get options() {
|
|
43881
|
+
return this._def.options;
|
|
43882
|
+
}
|
|
43883
|
+
};
|
|
43884
|
+
ZodUnion.create = (types, params) => {
|
|
43885
|
+
return new ZodUnion({
|
|
43886
|
+
options: types,
|
|
43887
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
43888
|
+
...processCreateParams(params)
|
|
43889
|
+
});
|
|
43890
|
+
};
|
|
43891
|
+
var getDiscriminator = (type) => {
|
|
43892
|
+
if (type instanceof ZodLazy) {
|
|
43893
|
+
return getDiscriminator(type.schema);
|
|
43894
|
+
} else if (type instanceof ZodEffects) {
|
|
43895
|
+
return getDiscriminator(type.innerType());
|
|
43896
|
+
} else if (type instanceof ZodLiteral) {
|
|
43897
|
+
return [type.value];
|
|
43898
|
+
} else if (type instanceof ZodEnum) {
|
|
43899
|
+
return type.options;
|
|
43900
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
43901
|
+
return util.objectValues(type.enum);
|
|
43902
|
+
} else if (type instanceof ZodDefault) {
|
|
43903
|
+
return getDiscriminator(type._def.innerType);
|
|
43904
|
+
} else if (type instanceof ZodUndefined) {
|
|
43905
|
+
return [void 0];
|
|
43906
|
+
} else if (type instanceof ZodNull) {
|
|
43907
|
+
return [null];
|
|
43908
|
+
} else if (type instanceof ZodOptional) {
|
|
43909
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
43910
|
+
} else if (type instanceof ZodNullable) {
|
|
43911
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
43912
|
+
} else if (type instanceof ZodBranded) {
|
|
43913
|
+
return getDiscriminator(type.unwrap());
|
|
43914
|
+
} else if (type instanceof ZodReadonly) {
|
|
43915
|
+
return getDiscriminator(type.unwrap());
|
|
43916
|
+
} else if (type instanceof ZodCatch) {
|
|
43917
|
+
return getDiscriminator(type._def.innerType);
|
|
43918
|
+
} else {
|
|
43919
|
+
return [];
|
|
43920
|
+
}
|
|
43921
|
+
};
|
|
43922
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
43923
|
+
_parse(input) {
|
|
43924
|
+
const { ctx } = this._processInputParams(input);
|
|
43925
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
43926
|
+
addIssueToContext(ctx, {
|
|
43927
|
+
code: ZodIssueCode2.invalid_type,
|
|
43928
|
+
expected: ZodParsedType.object,
|
|
43929
|
+
received: ctx.parsedType
|
|
43930
|
+
});
|
|
43931
|
+
return INVALID;
|
|
43932
|
+
}
|
|
43933
|
+
const discriminator = this.discriminator;
|
|
43934
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
43935
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
43936
|
+
if (!option) {
|
|
43937
|
+
addIssueToContext(ctx, {
|
|
43938
|
+
code: ZodIssueCode2.invalid_union_discriminator,
|
|
43939
|
+
options: Array.from(this.optionsMap.keys()),
|
|
43940
|
+
path: [discriminator]
|
|
43941
|
+
});
|
|
43942
|
+
return INVALID;
|
|
43943
|
+
}
|
|
43944
|
+
if (ctx.common.async) {
|
|
43945
|
+
return option._parseAsync({
|
|
43946
|
+
data: ctx.data,
|
|
43947
|
+
path: ctx.path,
|
|
43948
|
+
parent: ctx
|
|
43949
|
+
});
|
|
43950
|
+
} else {
|
|
43951
|
+
return option._parseSync({
|
|
43952
|
+
data: ctx.data,
|
|
43953
|
+
path: ctx.path,
|
|
43954
|
+
parent: ctx
|
|
43955
|
+
});
|
|
43956
|
+
}
|
|
43957
|
+
}
|
|
43958
|
+
get discriminator() {
|
|
43959
|
+
return this._def.discriminator;
|
|
43960
|
+
}
|
|
43961
|
+
get options() {
|
|
43962
|
+
return this._def.options;
|
|
43963
|
+
}
|
|
43964
|
+
get optionsMap() {
|
|
43965
|
+
return this._def.optionsMap;
|
|
43966
|
+
}
|
|
43967
|
+
/**
|
|
43968
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
43969
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
43970
|
+
* have a different value for each object in the union.
|
|
43971
|
+
* @param discriminator the name of the discriminator property
|
|
43972
|
+
* @param types an array of object schemas
|
|
43973
|
+
* @param params
|
|
43974
|
+
*/
|
|
43975
|
+
static create(discriminator, options, params) {
|
|
43976
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
43977
|
+
for (const type of options) {
|
|
43978
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
43979
|
+
if (!discriminatorValues.length) {
|
|
43980
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
43981
|
+
}
|
|
43982
|
+
for (const value of discriminatorValues) {
|
|
43983
|
+
if (optionsMap.has(value)) {
|
|
43984
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
43985
|
+
}
|
|
43986
|
+
optionsMap.set(value, type);
|
|
43987
|
+
}
|
|
43988
|
+
}
|
|
43989
|
+
return new _ZodDiscriminatedUnion({
|
|
43990
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
43991
|
+
discriminator,
|
|
43992
|
+
options,
|
|
43993
|
+
optionsMap,
|
|
43994
|
+
...processCreateParams(params)
|
|
43995
|
+
});
|
|
43996
|
+
}
|
|
43997
|
+
};
|
|
43998
|
+
function mergeValues(a, b) {
|
|
43999
|
+
const aType = getParsedType(a);
|
|
44000
|
+
const bType = getParsedType(b);
|
|
44001
|
+
if (a === b) {
|
|
44002
|
+
return { valid: true, data: a };
|
|
44003
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
44004
|
+
const bKeys = util.objectKeys(b);
|
|
44005
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
44006
|
+
const newObj = { ...a, ...b };
|
|
44007
|
+
for (const key of sharedKeys) {
|
|
44008
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
44009
|
+
if (!sharedValue.valid) {
|
|
44010
|
+
return { valid: false };
|
|
44011
|
+
}
|
|
44012
|
+
newObj[key] = sharedValue.data;
|
|
44013
|
+
}
|
|
44014
|
+
return { valid: true, data: newObj };
|
|
44015
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
44016
|
+
if (a.length !== b.length) {
|
|
44017
|
+
return { valid: false };
|
|
44018
|
+
}
|
|
44019
|
+
const newArray = [];
|
|
44020
|
+
for (let index = 0; index < a.length; index++) {
|
|
44021
|
+
const itemA = a[index];
|
|
44022
|
+
const itemB = b[index];
|
|
44023
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
44024
|
+
if (!sharedValue.valid) {
|
|
44025
|
+
return { valid: false };
|
|
44026
|
+
}
|
|
44027
|
+
newArray.push(sharedValue.data);
|
|
44028
|
+
}
|
|
44029
|
+
return { valid: true, data: newArray };
|
|
44030
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
44031
|
+
return { valid: true, data: a };
|
|
44032
|
+
} else {
|
|
44033
|
+
return { valid: false };
|
|
44034
|
+
}
|
|
44035
|
+
}
|
|
44036
|
+
var ZodIntersection = class extends ZodType {
|
|
44037
|
+
_parse(input) {
|
|
44038
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44039
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
44040
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
44041
|
+
return INVALID;
|
|
44042
|
+
}
|
|
44043
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
44044
|
+
if (!merged.valid) {
|
|
44045
|
+
addIssueToContext(ctx, {
|
|
44046
|
+
code: ZodIssueCode2.invalid_intersection_types
|
|
44047
|
+
});
|
|
44048
|
+
return INVALID;
|
|
44049
|
+
}
|
|
44050
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
44051
|
+
status.dirty();
|
|
44052
|
+
}
|
|
44053
|
+
return { status: status.value, value: merged.data };
|
|
44054
|
+
};
|
|
44055
|
+
if (ctx.common.async) {
|
|
44056
|
+
return Promise.all([
|
|
44057
|
+
this._def.left._parseAsync({
|
|
44058
|
+
data: ctx.data,
|
|
44059
|
+
path: ctx.path,
|
|
44060
|
+
parent: ctx
|
|
44061
|
+
}),
|
|
44062
|
+
this._def.right._parseAsync({
|
|
44063
|
+
data: ctx.data,
|
|
44064
|
+
path: ctx.path,
|
|
44065
|
+
parent: ctx
|
|
44066
|
+
})
|
|
44067
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
44068
|
+
} else {
|
|
44069
|
+
return handleParsed(this._def.left._parseSync({
|
|
44070
|
+
data: ctx.data,
|
|
44071
|
+
path: ctx.path,
|
|
44072
|
+
parent: ctx
|
|
44073
|
+
}), this._def.right._parseSync({
|
|
44074
|
+
data: ctx.data,
|
|
44075
|
+
path: ctx.path,
|
|
44076
|
+
parent: ctx
|
|
44077
|
+
}));
|
|
44078
|
+
}
|
|
44079
|
+
}
|
|
44080
|
+
};
|
|
44081
|
+
ZodIntersection.create = (left, right, params) => {
|
|
44082
|
+
return new ZodIntersection({
|
|
44083
|
+
left,
|
|
44084
|
+
right,
|
|
44085
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
44086
|
+
...processCreateParams(params)
|
|
44087
|
+
});
|
|
44088
|
+
};
|
|
44089
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
44090
|
+
_parse(input) {
|
|
44091
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44092
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
44093
|
+
addIssueToContext(ctx, {
|
|
44094
|
+
code: ZodIssueCode2.invalid_type,
|
|
44095
|
+
expected: ZodParsedType.array,
|
|
44096
|
+
received: ctx.parsedType
|
|
44097
|
+
});
|
|
44098
|
+
return INVALID;
|
|
44099
|
+
}
|
|
44100
|
+
if (ctx.data.length < this._def.items.length) {
|
|
44101
|
+
addIssueToContext(ctx, {
|
|
44102
|
+
code: ZodIssueCode2.too_small,
|
|
44103
|
+
minimum: this._def.items.length,
|
|
44104
|
+
inclusive: true,
|
|
44105
|
+
exact: false,
|
|
44106
|
+
type: "array"
|
|
44107
|
+
});
|
|
44108
|
+
return INVALID;
|
|
44109
|
+
}
|
|
44110
|
+
const rest = this._def.rest;
|
|
44111
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
44112
|
+
addIssueToContext(ctx, {
|
|
44113
|
+
code: ZodIssueCode2.too_big,
|
|
44114
|
+
maximum: this._def.items.length,
|
|
44115
|
+
inclusive: true,
|
|
44116
|
+
exact: false,
|
|
44117
|
+
type: "array"
|
|
44118
|
+
});
|
|
44119
|
+
status.dirty();
|
|
44120
|
+
}
|
|
44121
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
44122
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
44123
|
+
if (!schema)
|
|
44124
|
+
return null;
|
|
44125
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
44126
|
+
}).filter((x) => !!x);
|
|
44127
|
+
if (ctx.common.async) {
|
|
44128
|
+
return Promise.all(items).then((results) => {
|
|
44129
|
+
return ParseStatus.mergeArray(status, results);
|
|
44130
|
+
});
|
|
44131
|
+
} else {
|
|
44132
|
+
return ParseStatus.mergeArray(status, items);
|
|
44133
|
+
}
|
|
44134
|
+
}
|
|
44135
|
+
get items() {
|
|
44136
|
+
return this._def.items;
|
|
44137
|
+
}
|
|
44138
|
+
rest(rest) {
|
|
44139
|
+
return new _ZodTuple({
|
|
44140
|
+
...this._def,
|
|
44141
|
+
rest
|
|
44142
|
+
});
|
|
44143
|
+
}
|
|
44144
|
+
};
|
|
44145
|
+
ZodTuple.create = (schemas, params) => {
|
|
44146
|
+
if (!Array.isArray(schemas)) {
|
|
44147
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
44148
|
+
}
|
|
44149
|
+
return new ZodTuple({
|
|
44150
|
+
items: schemas,
|
|
44151
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
44152
|
+
rest: null,
|
|
44153
|
+
...processCreateParams(params)
|
|
44154
|
+
});
|
|
44155
|
+
};
|
|
44156
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
44157
|
+
get keySchema() {
|
|
44158
|
+
return this._def.keyType;
|
|
44159
|
+
}
|
|
44160
|
+
get valueSchema() {
|
|
44161
|
+
return this._def.valueType;
|
|
44162
|
+
}
|
|
44163
|
+
_parse(input) {
|
|
44164
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44165
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
44166
|
+
addIssueToContext(ctx, {
|
|
44167
|
+
code: ZodIssueCode2.invalid_type,
|
|
44168
|
+
expected: ZodParsedType.object,
|
|
44169
|
+
received: ctx.parsedType
|
|
44170
|
+
});
|
|
44171
|
+
return INVALID;
|
|
44172
|
+
}
|
|
44173
|
+
const pairs = [];
|
|
44174
|
+
const keyType = this._def.keyType;
|
|
44175
|
+
const valueType3 = this._def.valueType;
|
|
44176
|
+
for (const key in ctx.data) {
|
|
44177
|
+
pairs.push({
|
|
44178
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
44179
|
+
value: valueType3._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
44180
|
+
alwaysSet: key in ctx.data
|
|
44181
|
+
});
|
|
44182
|
+
}
|
|
44183
|
+
if (ctx.common.async) {
|
|
44184
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
44185
|
+
} else {
|
|
44186
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
44187
|
+
}
|
|
44188
|
+
}
|
|
44189
|
+
get element() {
|
|
44190
|
+
return this._def.valueType;
|
|
44191
|
+
}
|
|
44192
|
+
static create(first, second, third) {
|
|
44193
|
+
if (second instanceof ZodType) {
|
|
44194
|
+
return new _ZodRecord({
|
|
44195
|
+
keyType: first,
|
|
44196
|
+
valueType: second,
|
|
44197
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
44198
|
+
...processCreateParams(third)
|
|
44199
|
+
});
|
|
44200
|
+
}
|
|
44201
|
+
return new _ZodRecord({
|
|
44202
|
+
keyType: ZodString.create(),
|
|
44203
|
+
valueType: first,
|
|
44204
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
44205
|
+
...processCreateParams(second)
|
|
44206
|
+
});
|
|
44207
|
+
}
|
|
44208
|
+
};
|
|
44209
|
+
var ZodMap = class extends ZodType {
|
|
44210
|
+
get keySchema() {
|
|
44211
|
+
return this._def.keyType;
|
|
44212
|
+
}
|
|
44213
|
+
get valueSchema() {
|
|
44214
|
+
return this._def.valueType;
|
|
44215
|
+
}
|
|
44216
|
+
_parse(input) {
|
|
44217
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44218
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
44219
|
+
addIssueToContext(ctx, {
|
|
44220
|
+
code: ZodIssueCode2.invalid_type,
|
|
44221
|
+
expected: ZodParsedType.map,
|
|
44222
|
+
received: ctx.parsedType
|
|
44223
|
+
});
|
|
44224
|
+
return INVALID;
|
|
44225
|
+
}
|
|
44226
|
+
const keyType = this._def.keyType;
|
|
44227
|
+
const valueType3 = this._def.valueType;
|
|
44228
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
44229
|
+
return {
|
|
44230
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
44231
|
+
value: valueType3._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
44232
|
+
};
|
|
44233
|
+
});
|
|
44234
|
+
if (ctx.common.async) {
|
|
44235
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
44236
|
+
return Promise.resolve().then(async () => {
|
|
44237
|
+
for (const pair of pairs) {
|
|
44238
|
+
const key = await pair.key;
|
|
44239
|
+
const value = await pair.value;
|
|
44240
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
44241
|
+
return INVALID;
|
|
44242
|
+
}
|
|
44243
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
44244
|
+
status.dirty();
|
|
44245
|
+
}
|
|
44246
|
+
finalMap.set(key.value, value.value);
|
|
44247
|
+
}
|
|
44248
|
+
return { status: status.value, value: finalMap };
|
|
44249
|
+
});
|
|
44250
|
+
} else {
|
|
44251
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
44252
|
+
for (const pair of pairs) {
|
|
44253
|
+
const key = pair.key;
|
|
44254
|
+
const value = pair.value;
|
|
44255
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
44256
|
+
return INVALID;
|
|
44257
|
+
}
|
|
44258
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
44259
|
+
status.dirty();
|
|
44260
|
+
}
|
|
44261
|
+
finalMap.set(key.value, value.value);
|
|
44262
|
+
}
|
|
44263
|
+
return { status: status.value, value: finalMap };
|
|
44264
|
+
}
|
|
44265
|
+
}
|
|
44266
|
+
};
|
|
44267
|
+
ZodMap.create = (keyType, valueType3, params) => {
|
|
44268
|
+
return new ZodMap({
|
|
44269
|
+
valueType: valueType3,
|
|
44270
|
+
keyType,
|
|
44271
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
44272
|
+
...processCreateParams(params)
|
|
44273
|
+
});
|
|
44274
|
+
};
|
|
44275
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
44276
|
+
_parse(input) {
|
|
44277
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44278
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
44279
|
+
addIssueToContext(ctx, {
|
|
44280
|
+
code: ZodIssueCode2.invalid_type,
|
|
44281
|
+
expected: ZodParsedType.set,
|
|
44282
|
+
received: ctx.parsedType
|
|
44283
|
+
});
|
|
44284
|
+
return INVALID;
|
|
44285
|
+
}
|
|
44286
|
+
const def = this._def;
|
|
44287
|
+
if (def.minSize !== null) {
|
|
44288
|
+
if (ctx.data.size < def.minSize.value) {
|
|
44289
|
+
addIssueToContext(ctx, {
|
|
44290
|
+
code: ZodIssueCode2.too_small,
|
|
44291
|
+
minimum: def.minSize.value,
|
|
44292
|
+
type: "set",
|
|
44293
|
+
inclusive: true,
|
|
44294
|
+
exact: false,
|
|
44295
|
+
message: def.minSize.message
|
|
44296
|
+
});
|
|
44297
|
+
status.dirty();
|
|
44298
|
+
}
|
|
44299
|
+
}
|
|
44300
|
+
if (def.maxSize !== null) {
|
|
44301
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
44302
|
+
addIssueToContext(ctx, {
|
|
44303
|
+
code: ZodIssueCode2.too_big,
|
|
44304
|
+
maximum: def.maxSize.value,
|
|
44305
|
+
type: "set",
|
|
44306
|
+
inclusive: true,
|
|
44307
|
+
exact: false,
|
|
44308
|
+
message: def.maxSize.message
|
|
44309
|
+
});
|
|
44310
|
+
status.dirty();
|
|
44311
|
+
}
|
|
44312
|
+
}
|
|
44313
|
+
const valueType3 = this._def.valueType;
|
|
44314
|
+
function finalizeSet(elements2) {
|
|
44315
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
44316
|
+
for (const element of elements2) {
|
|
44317
|
+
if (element.status === "aborted")
|
|
44318
|
+
return INVALID;
|
|
44319
|
+
if (element.status === "dirty")
|
|
44320
|
+
status.dirty();
|
|
44321
|
+
parsedSet.add(element.value);
|
|
44322
|
+
}
|
|
44323
|
+
return { status: status.value, value: parsedSet };
|
|
44324
|
+
}
|
|
44325
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType3._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
44326
|
+
if (ctx.common.async) {
|
|
44327
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
44328
|
+
} else {
|
|
44329
|
+
return finalizeSet(elements);
|
|
44330
|
+
}
|
|
44331
|
+
}
|
|
44332
|
+
min(minSize, message) {
|
|
44333
|
+
return new _ZodSet({
|
|
44334
|
+
...this._def,
|
|
44335
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
44336
|
+
});
|
|
44337
|
+
}
|
|
44338
|
+
max(maxSize, message) {
|
|
44339
|
+
return new _ZodSet({
|
|
44340
|
+
...this._def,
|
|
44341
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
44342
|
+
});
|
|
44343
|
+
}
|
|
44344
|
+
size(size, message) {
|
|
44345
|
+
return this.min(size, message).max(size, message);
|
|
44346
|
+
}
|
|
44347
|
+
nonempty(message) {
|
|
44348
|
+
return this.min(1, message);
|
|
44349
|
+
}
|
|
44350
|
+
};
|
|
44351
|
+
ZodSet.create = (valueType3, params) => {
|
|
44352
|
+
return new ZodSet({
|
|
44353
|
+
valueType: valueType3,
|
|
44354
|
+
minSize: null,
|
|
44355
|
+
maxSize: null,
|
|
44356
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
44357
|
+
...processCreateParams(params)
|
|
44358
|
+
});
|
|
44359
|
+
};
|
|
44360
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
44361
|
+
constructor() {
|
|
44362
|
+
super(...arguments);
|
|
44363
|
+
this.validate = this.implement;
|
|
44364
|
+
}
|
|
44365
|
+
_parse(input) {
|
|
44366
|
+
const { ctx } = this._processInputParams(input);
|
|
44367
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
44368
|
+
addIssueToContext(ctx, {
|
|
44369
|
+
code: ZodIssueCode2.invalid_type,
|
|
44370
|
+
expected: ZodParsedType.function,
|
|
44371
|
+
received: ctx.parsedType
|
|
44372
|
+
});
|
|
44373
|
+
return INVALID;
|
|
44374
|
+
}
|
|
44375
|
+
function makeArgsIssue(args, error) {
|
|
44376
|
+
return makeIssue({
|
|
44377
|
+
data: args,
|
|
44378
|
+
path: ctx.path,
|
|
44379
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
44380
|
+
issueData: {
|
|
44381
|
+
code: ZodIssueCode2.invalid_arguments,
|
|
44382
|
+
argumentsError: error
|
|
44383
|
+
}
|
|
44384
|
+
});
|
|
44385
|
+
}
|
|
44386
|
+
function makeReturnsIssue(returns, error) {
|
|
44387
|
+
return makeIssue({
|
|
44388
|
+
data: returns,
|
|
44389
|
+
path: ctx.path,
|
|
44390
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
44391
|
+
issueData: {
|
|
44392
|
+
code: ZodIssueCode2.invalid_return_type,
|
|
44393
|
+
returnTypeError: error
|
|
44394
|
+
}
|
|
44395
|
+
});
|
|
44396
|
+
}
|
|
44397
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
44398
|
+
const fn = ctx.data;
|
|
44399
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
44400
|
+
const me = this;
|
|
44401
|
+
return OK(async function(...args) {
|
|
44402
|
+
const error = new ZodError([]);
|
|
44403
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
44404
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
44405
|
+
throw error;
|
|
44406
|
+
});
|
|
44407
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
44408
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
44409
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
44410
|
+
throw error;
|
|
44411
|
+
});
|
|
44412
|
+
return parsedReturns;
|
|
44413
|
+
});
|
|
44414
|
+
} else {
|
|
44415
|
+
const me = this;
|
|
44416
|
+
return OK(function(...args) {
|
|
44417
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
44418
|
+
if (!parsedArgs.success) {
|
|
44419
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
44420
|
+
}
|
|
44421
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
44422
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
44423
|
+
if (!parsedReturns.success) {
|
|
44424
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
44425
|
+
}
|
|
44426
|
+
return parsedReturns.data;
|
|
44427
|
+
});
|
|
44428
|
+
}
|
|
44429
|
+
}
|
|
44430
|
+
parameters() {
|
|
44431
|
+
return this._def.args;
|
|
44432
|
+
}
|
|
44433
|
+
returnType() {
|
|
44434
|
+
return this._def.returns;
|
|
44435
|
+
}
|
|
44436
|
+
args(...items) {
|
|
44437
|
+
return new _ZodFunction({
|
|
44438
|
+
...this._def,
|
|
44439
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
44440
|
+
});
|
|
44441
|
+
}
|
|
44442
|
+
returns(returnType) {
|
|
44443
|
+
return new _ZodFunction({
|
|
44444
|
+
...this._def,
|
|
44445
|
+
returns: returnType
|
|
44446
|
+
});
|
|
44447
|
+
}
|
|
44448
|
+
implement(func) {
|
|
44449
|
+
const validatedFunc = this.parse(func);
|
|
44450
|
+
return validatedFunc;
|
|
44451
|
+
}
|
|
44452
|
+
strictImplement(func) {
|
|
44453
|
+
const validatedFunc = this.parse(func);
|
|
44454
|
+
return validatedFunc;
|
|
44455
|
+
}
|
|
44456
|
+
static create(args, returns, params) {
|
|
44457
|
+
return new _ZodFunction({
|
|
44458
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
44459
|
+
returns: returns || ZodUnknown.create(),
|
|
44460
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
44461
|
+
...processCreateParams(params)
|
|
44462
|
+
});
|
|
44463
|
+
}
|
|
44464
|
+
};
|
|
44465
|
+
var ZodLazy = class extends ZodType {
|
|
44466
|
+
get schema() {
|
|
44467
|
+
return this._def.getter();
|
|
44468
|
+
}
|
|
44469
|
+
_parse(input) {
|
|
44470
|
+
const { ctx } = this._processInputParams(input);
|
|
44471
|
+
const lazySchema = this._def.getter();
|
|
44472
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
44473
|
+
}
|
|
44474
|
+
};
|
|
44475
|
+
ZodLazy.create = (getter, params) => {
|
|
44476
|
+
return new ZodLazy({
|
|
44477
|
+
getter,
|
|
44478
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
44479
|
+
...processCreateParams(params)
|
|
44480
|
+
});
|
|
44481
|
+
};
|
|
44482
|
+
var ZodLiteral = class extends ZodType {
|
|
44483
|
+
_parse(input) {
|
|
44484
|
+
if (input.data !== this._def.value) {
|
|
44485
|
+
const ctx = this._getOrReturnCtx(input);
|
|
44486
|
+
addIssueToContext(ctx, {
|
|
44487
|
+
received: ctx.data,
|
|
44488
|
+
code: ZodIssueCode2.invalid_literal,
|
|
44489
|
+
expected: this._def.value
|
|
44490
|
+
});
|
|
44491
|
+
return INVALID;
|
|
44492
|
+
}
|
|
44493
|
+
return { status: "valid", value: input.data };
|
|
44494
|
+
}
|
|
44495
|
+
get value() {
|
|
44496
|
+
return this._def.value;
|
|
44497
|
+
}
|
|
44498
|
+
};
|
|
44499
|
+
ZodLiteral.create = (value, params) => {
|
|
44500
|
+
return new ZodLiteral({
|
|
44501
|
+
value,
|
|
44502
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
44503
|
+
...processCreateParams(params)
|
|
44504
|
+
});
|
|
44505
|
+
};
|
|
44506
|
+
function createZodEnum(values, params) {
|
|
44507
|
+
return new ZodEnum({
|
|
44508
|
+
values,
|
|
44509
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
44510
|
+
...processCreateParams(params)
|
|
44511
|
+
});
|
|
44512
|
+
}
|
|
44513
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
44514
|
+
_parse(input) {
|
|
44515
|
+
if (typeof input.data !== "string") {
|
|
44516
|
+
const ctx = this._getOrReturnCtx(input);
|
|
44517
|
+
const expectedValues = this._def.values;
|
|
44518
|
+
addIssueToContext(ctx, {
|
|
44519
|
+
expected: util.joinValues(expectedValues),
|
|
44520
|
+
received: ctx.parsedType,
|
|
44521
|
+
code: ZodIssueCode2.invalid_type
|
|
44522
|
+
});
|
|
44523
|
+
return INVALID;
|
|
44524
|
+
}
|
|
44525
|
+
if (!this._cache) {
|
|
44526
|
+
this._cache = new Set(this._def.values);
|
|
44527
|
+
}
|
|
44528
|
+
if (!this._cache.has(input.data)) {
|
|
44529
|
+
const ctx = this._getOrReturnCtx(input);
|
|
44530
|
+
const expectedValues = this._def.values;
|
|
44531
|
+
addIssueToContext(ctx, {
|
|
44532
|
+
received: ctx.data,
|
|
44533
|
+
code: ZodIssueCode2.invalid_enum_value,
|
|
44534
|
+
options: expectedValues
|
|
44535
|
+
});
|
|
44536
|
+
return INVALID;
|
|
44537
|
+
}
|
|
44538
|
+
return OK(input.data);
|
|
44539
|
+
}
|
|
44540
|
+
get options() {
|
|
44541
|
+
return this._def.values;
|
|
44542
|
+
}
|
|
44543
|
+
get enum() {
|
|
44544
|
+
const enumValues = {};
|
|
44545
|
+
for (const val of this._def.values) {
|
|
44546
|
+
enumValues[val] = val;
|
|
44547
|
+
}
|
|
44548
|
+
return enumValues;
|
|
44549
|
+
}
|
|
44550
|
+
get Values() {
|
|
44551
|
+
const enumValues = {};
|
|
44552
|
+
for (const val of this._def.values) {
|
|
44553
|
+
enumValues[val] = val;
|
|
44554
|
+
}
|
|
44555
|
+
return enumValues;
|
|
44556
|
+
}
|
|
44557
|
+
get Enum() {
|
|
44558
|
+
const enumValues = {};
|
|
44559
|
+
for (const val of this._def.values) {
|
|
44560
|
+
enumValues[val] = val;
|
|
44561
|
+
}
|
|
44562
|
+
return enumValues;
|
|
44563
|
+
}
|
|
44564
|
+
extract(values, newDef = this._def) {
|
|
44565
|
+
return _ZodEnum.create(values, {
|
|
44566
|
+
...this._def,
|
|
44567
|
+
...newDef
|
|
44568
|
+
});
|
|
44569
|
+
}
|
|
44570
|
+
exclude(values, newDef = this._def) {
|
|
44571
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
44572
|
+
...this._def,
|
|
44573
|
+
...newDef
|
|
44574
|
+
});
|
|
44575
|
+
}
|
|
44576
|
+
};
|
|
44577
|
+
ZodEnum.create = createZodEnum;
|
|
44578
|
+
var ZodNativeEnum = class extends ZodType {
|
|
44579
|
+
_parse(input) {
|
|
44580
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
44581
|
+
const ctx = this._getOrReturnCtx(input);
|
|
44582
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
44583
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
44584
|
+
addIssueToContext(ctx, {
|
|
44585
|
+
expected: util.joinValues(expectedValues),
|
|
44586
|
+
received: ctx.parsedType,
|
|
44587
|
+
code: ZodIssueCode2.invalid_type
|
|
44588
|
+
});
|
|
44589
|
+
return INVALID;
|
|
44590
|
+
}
|
|
44591
|
+
if (!this._cache) {
|
|
44592
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
44593
|
+
}
|
|
44594
|
+
if (!this._cache.has(input.data)) {
|
|
44595
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
44596
|
+
addIssueToContext(ctx, {
|
|
44597
|
+
received: ctx.data,
|
|
44598
|
+
code: ZodIssueCode2.invalid_enum_value,
|
|
44599
|
+
options: expectedValues
|
|
44600
|
+
});
|
|
44601
|
+
return INVALID;
|
|
44602
|
+
}
|
|
44603
|
+
return OK(input.data);
|
|
44604
|
+
}
|
|
44605
|
+
get enum() {
|
|
44606
|
+
return this._def.values;
|
|
44607
|
+
}
|
|
44608
|
+
};
|
|
44609
|
+
ZodNativeEnum.create = (values, params) => {
|
|
44610
|
+
return new ZodNativeEnum({
|
|
44611
|
+
values,
|
|
44612
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
44613
|
+
...processCreateParams(params)
|
|
44614
|
+
});
|
|
44615
|
+
};
|
|
44616
|
+
var ZodPromise = class extends ZodType {
|
|
44617
|
+
unwrap() {
|
|
44618
|
+
return this._def.type;
|
|
44619
|
+
}
|
|
44620
|
+
_parse(input) {
|
|
44621
|
+
const { ctx } = this._processInputParams(input);
|
|
44622
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
44623
|
+
addIssueToContext(ctx, {
|
|
44624
|
+
code: ZodIssueCode2.invalid_type,
|
|
44625
|
+
expected: ZodParsedType.promise,
|
|
44626
|
+
received: ctx.parsedType
|
|
44627
|
+
});
|
|
44628
|
+
return INVALID;
|
|
44629
|
+
}
|
|
44630
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
44631
|
+
return OK(promisified.then((data) => {
|
|
44632
|
+
return this._def.type.parseAsync(data, {
|
|
44633
|
+
path: ctx.path,
|
|
44634
|
+
errorMap: ctx.common.contextualErrorMap
|
|
44635
|
+
});
|
|
44636
|
+
}));
|
|
44637
|
+
}
|
|
44638
|
+
};
|
|
44639
|
+
ZodPromise.create = (schema, params) => {
|
|
44640
|
+
return new ZodPromise({
|
|
44641
|
+
type: schema,
|
|
44642
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
44643
|
+
...processCreateParams(params)
|
|
44644
|
+
});
|
|
44645
|
+
};
|
|
44646
|
+
var ZodEffects = class extends ZodType {
|
|
44647
|
+
innerType() {
|
|
44648
|
+
return this._def.schema;
|
|
44649
|
+
}
|
|
44650
|
+
sourceType() {
|
|
44651
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
44652
|
+
}
|
|
44653
|
+
_parse(input) {
|
|
44654
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44655
|
+
const effect = this._def.effect || null;
|
|
44656
|
+
const checkCtx = {
|
|
44657
|
+
addIssue: (arg) => {
|
|
44658
|
+
addIssueToContext(ctx, arg);
|
|
44659
|
+
if (arg.fatal) {
|
|
44660
|
+
status.abort();
|
|
44661
|
+
} else {
|
|
44662
|
+
status.dirty();
|
|
44663
|
+
}
|
|
44664
|
+
},
|
|
44665
|
+
get path() {
|
|
44666
|
+
return ctx.path;
|
|
44667
|
+
}
|
|
44668
|
+
};
|
|
44669
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
44670
|
+
if (effect.type === "preprocess") {
|
|
44671
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
44672
|
+
if (ctx.common.async) {
|
|
44673
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
44674
|
+
if (status.value === "aborted")
|
|
44675
|
+
return INVALID;
|
|
44676
|
+
const result = await this._def.schema._parseAsync({
|
|
44677
|
+
data: processed2,
|
|
44678
|
+
path: ctx.path,
|
|
44679
|
+
parent: ctx
|
|
44680
|
+
});
|
|
44681
|
+
if (result.status === "aborted")
|
|
44682
|
+
return INVALID;
|
|
44683
|
+
if (result.status === "dirty")
|
|
44684
|
+
return DIRTY(result.value);
|
|
44685
|
+
if (status.value === "dirty")
|
|
44686
|
+
return DIRTY(result.value);
|
|
44687
|
+
return result;
|
|
44688
|
+
});
|
|
44689
|
+
} else {
|
|
44690
|
+
if (status.value === "aborted")
|
|
44691
|
+
return INVALID;
|
|
44692
|
+
const result = this._def.schema._parseSync({
|
|
44693
|
+
data: processed,
|
|
44694
|
+
path: ctx.path,
|
|
44695
|
+
parent: ctx
|
|
44696
|
+
});
|
|
44697
|
+
if (result.status === "aborted")
|
|
44698
|
+
return INVALID;
|
|
44699
|
+
if (result.status === "dirty")
|
|
44700
|
+
return DIRTY(result.value);
|
|
44701
|
+
if (status.value === "dirty")
|
|
44702
|
+
return DIRTY(result.value);
|
|
44703
|
+
return result;
|
|
44704
|
+
}
|
|
44705
|
+
}
|
|
44706
|
+
if (effect.type === "refinement") {
|
|
44707
|
+
const executeRefinement = (acc) => {
|
|
44708
|
+
const result = effect.refinement(acc, checkCtx);
|
|
44709
|
+
if (ctx.common.async) {
|
|
44710
|
+
return Promise.resolve(result);
|
|
44711
|
+
}
|
|
44712
|
+
if (result instanceof Promise) {
|
|
44713
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
44714
|
+
}
|
|
44715
|
+
return acc;
|
|
44716
|
+
};
|
|
44717
|
+
if (ctx.common.async === false) {
|
|
44718
|
+
const inner = this._def.schema._parseSync({
|
|
44719
|
+
data: ctx.data,
|
|
44720
|
+
path: ctx.path,
|
|
44721
|
+
parent: ctx
|
|
44722
|
+
});
|
|
44723
|
+
if (inner.status === "aborted")
|
|
44724
|
+
return INVALID;
|
|
44725
|
+
if (inner.status === "dirty")
|
|
44726
|
+
status.dirty();
|
|
44727
|
+
executeRefinement(inner.value);
|
|
44728
|
+
return { status: status.value, value: inner.value };
|
|
44729
|
+
} else {
|
|
44730
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
44731
|
+
if (inner.status === "aborted")
|
|
44732
|
+
return INVALID;
|
|
44733
|
+
if (inner.status === "dirty")
|
|
44734
|
+
status.dirty();
|
|
44735
|
+
return executeRefinement(inner.value).then(() => {
|
|
44736
|
+
return { status: status.value, value: inner.value };
|
|
44737
|
+
});
|
|
44738
|
+
});
|
|
44739
|
+
}
|
|
44740
|
+
}
|
|
44741
|
+
if (effect.type === "transform") {
|
|
44742
|
+
if (ctx.common.async === false) {
|
|
44743
|
+
const base = this._def.schema._parseSync({
|
|
44744
|
+
data: ctx.data,
|
|
44745
|
+
path: ctx.path,
|
|
44746
|
+
parent: ctx
|
|
44747
|
+
});
|
|
44748
|
+
if (!isValid(base))
|
|
44749
|
+
return INVALID;
|
|
44750
|
+
const result = effect.transform(base.value, checkCtx);
|
|
44751
|
+
if (result instanceof Promise) {
|
|
44752
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
44753
|
+
}
|
|
44754
|
+
return { status: status.value, value: result };
|
|
44755
|
+
} else {
|
|
44756
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
44757
|
+
if (!isValid(base))
|
|
44758
|
+
return INVALID;
|
|
44759
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
44760
|
+
status: status.value,
|
|
44761
|
+
value: result
|
|
44762
|
+
}));
|
|
44763
|
+
});
|
|
44764
|
+
}
|
|
44765
|
+
}
|
|
44766
|
+
util.assertNever(effect);
|
|
44767
|
+
}
|
|
44768
|
+
};
|
|
44769
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
44770
|
+
return new ZodEffects({
|
|
44771
|
+
schema,
|
|
44772
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
44773
|
+
effect,
|
|
44774
|
+
...processCreateParams(params)
|
|
44775
|
+
});
|
|
44776
|
+
};
|
|
44777
|
+
ZodEffects.createWithPreprocess = (preprocess2, schema, params) => {
|
|
44778
|
+
return new ZodEffects({
|
|
44779
|
+
schema,
|
|
44780
|
+
effect: { type: "preprocess", transform: preprocess2 },
|
|
44781
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
44782
|
+
...processCreateParams(params)
|
|
44783
|
+
});
|
|
44784
|
+
};
|
|
44785
|
+
var ZodOptional = class extends ZodType {
|
|
44786
|
+
_parse(input) {
|
|
44787
|
+
const parsedType = this._getType(input);
|
|
44788
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
44789
|
+
return OK(void 0);
|
|
44790
|
+
}
|
|
44791
|
+
return this._def.innerType._parse(input);
|
|
44792
|
+
}
|
|
44793
|
+
unwrap() {
|
|
44794
|
+
return this._def.innerType;
|
|
44795
|
+
}
|
|
44796
|
+
};
|
|
44797
|
+
ZodOptional.create = (type, params) => {
|
|
44798
|
+
return new ZodOptional({
|
|
44799
|
+
innerType: type,
|
|
44800
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
44801
|
+
...processCreateParams(params)
|
|
44802
|
+
});
|
|
44803
|
+
};
|
|
44804
|
+
var ZodNullable = class extends ZodType {
|
|
44805
|
+
_parse(input) {
|
|
44806
|
+
const parsedType = this._getType(input);
|
|
44807
|
+
if (parsedType === ZodParsedType.null) {
|
|
44808
|
+
return OK(null);
|
|
44809
|
+
}
|
|
44810
|
+
return this._def.innerType._parse(input);
|
|
44811
|
+
}
|
|
44812
|
+
unwrap() {
|
|
44813
|
+
return this._def.innerType;
|
|
44814
|
+
}
|
|
44815
|
+
};
|
|
44816
|
+
ZodNullable.create = (type, params) => {
|
|
44817
|
+
return new ZodNullable({
|
|
44818
|
+
innerType: type,
|
|
44819
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
44820
|
+
...processCreateParams(params)
|
|
44821
|
+
});
|
|
44822
|
+
};
|
|
44823
|
+
var ZodDefault = class extends ZodType {
|
|
44824
|
+
_parse(input) {
|
|
44825
|
+
const { ctx } = this._processInputParams(input);
|
|
44826
|
+
let data = ctx.data;
|
|
44827
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
44828
|
+
data = this._def.defaultValue();
|
|
44829
|
+
}
|
|
44830
|
+
return this._def.innerType._parse({
|
|
44831
|
+
data,
|
|
44832
|
+
path: ctx.path,
|
|
44833
|
+
parent: ctx
|
|
44834
|
+
});
|
|
44835
|
+
}
|
|
44836
|
+
removeDefault() {
|
|
44837
|
+
return this._def.innerType;
|
|
44838
|
+
}
|
|
44839
|
+
};
|
|
44840
|
+
ZodDefault.create = (type, params) => {
|
|
44841
|
+
return new ZodDefault({
|
|
44842
|
+
innerType: type,
|
|
44843
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
44844
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
44845
|
+
...processCreateParams(params)
|
|
44846
|
+
});
|
|
44847
|
+
};
|
|
44848
|
+
var ZodCatch = class extends ZodType {
|
|
44849
|
+
_parse(input) {
|
|
44850
|
+
const { ctx } = this._processInputParams(input);
|
|
44851
|
+
const newCtx = {
|
|
44852
|
+
...ctx,
|
|
44853
|
+
common: {
|
|
44854
|
+
...ctx.common,
|
|
44855
|
+
issues: []
|
|
44856
|
+
}
|
|
44857
|
+
};
|
|
44858
|
+
const result = this._def.innerType._parse({
|
|
44859
|
+
data: newCtx.data,
|
|
44860
|
+
path: newCtx.path,
|
|
44861
|
+
parent: {
|
|
44862
|
+
...newCtx
|
|
44863
|
+
}
|
|
44864
|
+
});
|
|
44865
|
+
if (isAsync(result)) {
|
|
44866
|
+
return result.then((result2) => {
|
|
44867
|
+
return {
|
|
44868
|
+
status: "valid",
|
|
44869
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
44870
|
+
get error() {
|
|
44871
|
+
return new ZodError(newCtx.common.issues);
|
|
44872
|
+
},
|
|
44873
|
+
input: newCtx.data
|
|
44874
|
+
})
|
|
44875
|
+
};
|
|
44876
|
+
});
|
|
44877
|
+
} else {
|
|
44878
|
+
return {
|
|
44879
|
+
status: "valid",
|
|
44880
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
44881
|
+
get error() {
|
|
44882
|
+
return new ZodError(newCtx.common.issues);
|
|
44883
|
+
},
|
|
44884
|
+
input: newCtx.data
|
|
44885
|
+
})
|
|
44886
|
+
};
|
|
44887
|
+
}
|
|
44888
|
+
}
|
|
44889
|
+
removeCatch() {
|
|
44890
|
+
return this._def.innerType;
|
|
44891
|
+
}
|
|
44892
|
+
};
|
|
44893
|
+
ZodCatch.create = (type, params) => {
|
|
44894
|
+
return new ZodCatch({
|
|
44895
|
+
innerType: type,
|
|
44896
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
44897
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
44898
|
+
...processCreateParams(params)
|
|
44899
|
+
});
|
|
44900
|
+
};
|
|
44901
|
+
var ZodNaN = class extends ZodType {
|
|
44902
|
+
_parse(input) {
|
|
44903
|
+
const parsedType = this._getType(input);
|
|
44904
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
44905
|
+
const ctx = this._getOrReturnCtx(input);
|
|
44906
|
+
addIssueToContext(ctx, {
|
|
44907
|
+
code: ZodIssueCode2.invalid_type,
|
|
44908
|
+
expected: ZodParsedType.nan,
|
|
44909
|
+
received: ctx.parsedType
|
|
44910
|
+
});
|
|
44911
|
+
return INVALID;
|
|
44912
|
+
}
|
|
44913
|
+
return { status: "valid", value: input.data };
|
|
44914
|
+
}
|
|
44915
|
+
};
|
|
44916
|
+
ZodNaN.create = (params) => {
|
|
44917
|
+
return new ZodNaN({
|
|
44918
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
44919
|
+
...processCreateParams(params)
|
|
44920
|
+
});
|
|
44921
|
+
};
|
|
44922
|
+
var BRAND = Symbol("zod_brand");
|
|
44923
|
+
var ZodBranded = class extends ZodType {
|
|
44924
|
+
_parse(input) {
|
|
44925
|
+
const { ctx } = this._processInputParams(input);
|
|
44926
|
+
const data = ctx.data;
|
|
44927
|
+
return this._def.type._parse({
|
|
44928
|
+
data,
|
|
44929
|
+
path: ctx.path,
|
|
44930
|
+
parent: ctx
|
|
44931
|
+
});
|
|
44932
|
+
}
|
|
44933
|
+
unwrap() {
|
|
44934
|
+
return this._def.type;
|
|
44935
|
+
}
|
|
44936
|
+
};
|
|
44937
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
44938
|
+
_parse(input) {
|
|
44939
|
+
const { status, ctx } = this._processInputParams(input);
|
|
44940
|
+
if (ctx.common.async) {
|
|
44941
|
+
const handleAsync = async () => {
|
|
44942
|
+
const inResult = await this._def.in._parseAsync({
|
|
44943
|
+
data: ctx.data,
|
|
44944
|
+
path: ctx.path,
|
|
44945
|
+
parent: ctx
|
|
44946
|
+
});
|
|
44947
|
+
if (inResult.status === "aborted")
|
|
44948
|
+
return INVALID;
|
|
44949
|
+
if (inResult.status === "dirty") {
|
|
44950
|
+
status.dirty();
|
|
44951
|
+
return DIRTY(inResult.value);
|
|
44952
|
+
} else {
|
|
44953
|
+
return this._def.out._parseAsync({
|
|
44954
|
+
data: inResult.value,
|
|
44955
|
+
path: ctx.path,
|
|
44956
|
+
parent: ctx
|
|
44957
|
+
});
|
|
44958
|
+
}
|
|
44959
|
+
};
|
|
44960
|
+
return handleAsync();
|
|
44961
|
+
} else {
|
|
44962
|
+
const inResult = this._def.in._parseSync({
|
|
44963
|
+
data: ctx.data,
|
|
44964
|
+
path: ctx.path,
|
|
44965
|
+
parent: ctx
|
|
44966
|
+
});
|
|
44967
|
+
if (inResult.status === "aborted")
|
|
44968
|
+
return INVALID;
|
|
44969
|
+
if (inResult.status === "dirty") {
|
|
44970
|
+
status.dirty();
|
|
44971
|
+
return {
|
|
44972
|
+
status: "dirty",
|
|
44973
|
+
value: inResult.value
|
|
44974
|
+
};
|
|
44975
|
+
} else {
|
|
44976
|
+
return this._def.out._parseSync({
|
|
44977
|
+
data: inResult.value,
|
|
44978
|
+
path: ctx.path,
|
|
44979
|
+
parent: ctx
|
|
44980
|
+
});
|
|
44981
|
+
}
|
|
44982
|
+
}
|
|
44983
|
+
}
|
|
44984
|
+
static create(a, b) {
|
|
44985
|
+
return new _ZodPipeline({
|
|
44986
|
+
in: a,
|
|
44987
|
+
out: b,
|
|
44988
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
44989
|
+
});
|
|
44990
|
+
}
|
|
44991
|
+
};
|
|
44992
|
+
var ZodReadonly = class extends ZodType {
|
|
44993
|
+
_parse(input) {
|
|
44994
|
+
const result = this._def.innerType._parse(input);
|
|
44995
|
+
const freeze = (data) => {
|
|
44996
|
+
if (isValid(data)) {
|
|
44997
|
+
data.value = Object.freeze(data.value);
|
|
44998
|
+
}
|
|
44999
|
+
return data;
|
|
45000
|
+
};
|
|
45001
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
45002
|
+
}
|
|
45003
|
+
unwrap() {
|
|
45004
|
+
return this._def.innerType;
|
|
45005
|
+
}
|
|
45006
|
+
};
|
|
45007
|
+
ZodReadonly.create = (type, params) => {
|
|
45008
|
+
return new ZodReadonly({
|
|
45009
|
+
innerType: type,
|
|
45010
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
45011
|
+
...processCreateParams(params)
|
|
45012
|
+
});
|
|
45013
|
+
};
|
|
45014
|
+
function cleanParams(params, data) {
|
|
45015
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
45016
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
45017
|
+
return p2;
|
|
45018
|
+
}
|
|
45019
|
+
function custom2(check, _params = {}, fatal) {
|
|
45020
|
+
if (check)
|
|
45021
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
45022
|
+
const r = check(data);
|
|
45023
|
+
if (r instanceof Promise) {
|
|
45024
|
+
return r.then((r2) => {
|
|
45025
|
+
if (!r2) {
|
|
45026
|
+
const params = cleanParams(_params, data);
|
|
45027
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
45028
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
45029
|
+
}
|
|
45030
|
+
});
|
|
45031
|
+
}
|
|
45032
|
+
if (!r) {
|
|
45033
|
+
const params = cleanParams(_params, data);
|
|
45034
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
45035
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
45036
|
+
}
|
|
45037
|
+
return;
|
|
45038
|
+
});
|
|
45039
|
+
return ZodAny.create();
|
|
45040
|
+
}
|
|
45041
|
+
var late = {
|
|
45042
|
+
object: ZodObject.lazycreate
|
|
45043
|
+
};
|
|
45044
|
+
var ZodFirstPartyTypeKind;
|
|
45045
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
45046
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
45047
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
45048
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
45049
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
45050
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
45051
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
45052
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
45053
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
45054
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
45055
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
45056
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
45057
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
45058
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
45059
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
45060
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
45061
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
45062
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
45063
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
45064
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
45065
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
45066
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
45067
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
45068
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
45069
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
45070
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
45071
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
45072
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
45073
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
45074
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
45075
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
45076
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
45077
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
45078
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
45079
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
45080
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
45081
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
45082
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
45083
|
+
var instanceOfType = (cls, params = {
|
|
45084
|
+
message: `Input not instance of ${cls.name}`
|
|
45085
|
+
}) => custom2((data) => data instanceof cls, params);
|
|
45086
|
+
var stringType = ZodString.create;
|
|
45087
|
+
var numberType = ZodNumber.create;
|
|
45088
|
+
var nanType = ZodNaN.create;
|
|
45089
|
+
var bigIntType = ZodBigInt.create;
|
|
45090
|
+
var booleanType = ZodBoolean.create;
|
|
45091
|
+
var dateType = ZodDate.create;
|
|
45092
|
+
var symbolType = ZodSymbol.create;
|
|
45093
|
+
var undefinedType = ZodUndefined.create;
|
|
45094
|
+
var nullType = ZodNull.create;
|
|
45095
|
+
var anyType = ZodAny.create;
|
|
45096
|
+
var unknownType = ZodUnknown.create;
|
|
45097
|
+
var neverType = ZodNever.create;
|
|
45098
|
+
var voidType = ZodVoid.create;
|
|
45099
|
+
var arrayType = ZodArray.create;
|
|
45100
|
+
var objectType = ZodObject.create;
|
|
45101
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
45102
|
+
var unionType = ZodUnion.create;
|
|
45103
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
45104
|
+
var intersectionType = ZodIntersection.create;
|
|
45105
|
+
var tupleType = ZodTuple.create;
|
|
45106
|
+
var recordType = ZodRecord.create;
|
|
45107
|
+
var mapType = ZodMap.create;
|
|
45108
|
+
var setType = ZodSet.create;
|
|
45109
|
+
var functionType = ZodFunction.create;
|
|
45110
|
+
var lazyType = ZodLazy.create;
|
|
45111
|
+
var literalType = ZodLiteral.create;
|
|
45112
|
+
var enumType = ZodEnum.create;
|
|
45113
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
45114
|
+
var promiseType = ZodPromise.create;
|
|
45115
|
+
var effectsType = ZodEffects.create;
|
|
45116
|
+
var optionalType = ZodOptional.create;
|
|
45117
|
+
var nullableType = ZodNullable.create;
|
|
45118
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
45119
|
+
var pipelineType = ZodPipeline.create;
|
|
45120
|
+
var ostring = () => stringType().optional();
|
|
45121
|
+
var onumber = () => numberType().optional();
|
|
45122
|
+
var oboolean = () => booleanType().optional();
|
|
45123
|
+
var coerce = {
|
|
45124
|
+
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
45125
|
+
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
45126
|
+
boolean: (arg) => ZodBoolean.create({
|
|
45127
|
+
...arg,
|
|
45128
|
+
coerce: true
|
|
45129
|
+
}),
|
|
45130
|
+
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
45131
|
+
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
45132
|
+
};
|
|
45133
|
+
var NEVER2 = INVALID;
|
|
45134
|
+
|
|
41311
45135
|
// ../../node_modules/@ag-ui/core/dist/index.mjs
|
|
41312
45136
|
var FunctionCallSchema = external_exports.object({
|
|
41313
45137
|
name: external_exports.string(),
|
|
@@ -43367,15 +47191,15 @@ function isObjectJsonSchema(value) {
|
|
|
43367
47191
|
return isPlainRecord(value) && value.type === "object" && getJsonSchemaIssues(value).length === 0;
|
|
43368
47192
|
}
|
|
43369
47193
|
function validateJsonSchemaValue(schema, value, path2 = "$") {
|
|
43370
|
-
let
|
|
47194
|
+
let validate2;
|
|
43371
47195
|
try {
|
|
43372
|
-
|
|
47196
|
+
validate2 = ajv.compile(schema);
|
|
43373
47197
|
} catch (error) {
|
|
43374
47198
|
return [
|
|
43375
47199
|
issue(path2, "INVALID_JSON_SCHEMA", error instanceof Error ? error.message : "schema is invalid")
|
|
43376
47200
|
];
|
|
43377
47201
|
}
|
|
43378
|
-
return
|
|
47202
|
+
return validate2(value) ? [] : (validate2.errors ?? []).map(errorToIssue.bind(null, path2));
|
|
43379
47203
|
}
|
|
43380
47204
|
function errorToIssue(root, error) {
|
|
43381
47205
|
const suffix = error.instancePath.split("/").filter(Boolean).map((segment) => segment.replace(/~1/gu, "/").replace(/~0/gu, "~")).map((segment) => `[${JSON.stringify(segment)}]`).join("");
|
|
@@ -51594,7 +55418,7 @@ var LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
|
51594
55418
|
var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
51595
55419
|
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
51596
55420
|
var JSONRPC_VERSION = "2.0";
|
|
51597
|
-
var AssertObjectSchema =
|
|
55421
|
+
var AssertObjectSchema = custom((v) => v !== null && (typeof v === "object" || typeof v === "function"));
|
|
51598
55422
|
var ProgressTokenSchema = union([string(), number().int()]);
|
|
51599
55423
|
var CursorSchema = string();
|
|
51600
55424
|
var TaskCreationParamsSchema = looseObject({
|
|
@@ -55379,11 +59203,11 @@ async function pkceChallenge(length) {
|
|
|
55379
59203
|
var SafeUrlSchema = url().superRefine((val, ctx) => {
|
|
55380
59204
|
if (!URL.canParse(val)) {
|
|
55381
59205
|
ctx.addIssue({
|
|
55382
|
-
code:
|
|
59206
|
+
code: ZodIssueCode.custom,
|
|
55383
59207
|
message: "URL must be parseable",
|
|
55384
59208
|
fatal: true
|
|
55385
59209
|
});
|
|
55386
|
-
return
|
|
59210
|
+
return NEVER;
|
|
55387
59211
|
}
|
|
55388
59212
|
}).refine((url2) => {
|
|
55389
59213
|
const u = new URL(url2);
|
|
@@ -59836,6 +63660,22 @@ export {
|
|
|
59836
63660
|
isSafeJsonPointer,
|
|
59837
63661
|
readJsonPointer,
|
|
59838
63662
|
writeJsonPointer,
|
|
63663
|
+
require_codegen,
|
|
63664
|
+
require_util,
|
|
63665
|
+
require_names,
|
|
63666
|
+
require_validate,
|
|
63667
|
+
require_validation_error,
|
|
63668
|
+
require_ref_error,
|
|
63669
|
+
require_compile,
|
|
63670
|
+
require_core,
|
|
63671
|
+
require_ref,
|
|
63672
|
+
require_core2,
|
|
63673
|
+
require_validation,
|
|
63674
|
+
require_dependencies,
|
|
63675
|
+
require_applicator,
|
|
63676
|
+
require_format2 as require_format,
|
|
63677
|
+
require_metadata,
|
|
63678
|
+
require_discriminator,
|
|
59839
63679
|
validateJsonSchemaValue2 as validateJsonSchemaValue,
|
|
59840
63680
|
projectCardData,
|
|
59841
63681
|
normalizeCardDataValue,
|
|
@@ -59995,6 +63835,7 @@ export {
|
|
|
59995
63835
|
normalizeScenarioRunErrorCode,
|
|
59996
63836
|
authorizeAgentRun,
|
|
59997
63837
|
createGatewayRunAuthorization,
|
|
63838
|
+
require_dist,
|
|
59998
63839
|
abortableDelay,
|
|
59999
63840
|
RemoteGatewayMcpServerProvider,
|
|
60000
63841
|
LinkqueKnowledgeSearchPort,
|