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