@learncard/simple-signing-plugin 1.0.12 → 1.0.14
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/simple-signing-plugin.cjs.development.cjs +760 -196
- package/dist/simple-signing-plugin.cjs.development.cjs.map +4 -4
- package/dist/simple-signing-plugin.cjs.production.min.cjs +2 -2
- package/dist/simple-signing-plugin.cjs.production.min.cjs.map +4 -4
- package/dist/simple-signing-plugin.esm.js +759 -195
- package/dist/simple-signing-plugin.esm.js.map +4 -4
- package/dist/types.d.ts +3 -3
- package/package.json +2 -3
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toCommonJS = (
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var src_exports = {};
|
|
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
|
|
29
|
-
// ../../../node_modules/.pnpm/zod@3.
|
|
29
|
+
// ../../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
|
|
30
30
|
var util;
|
|
31
31
|
(function(util2) {
|
|
32
32
|
util2.assertEqual = (val) => val;
|
|
@@ -88,6 +88,15 @@ var util;
|
|
|
88
88
|
return value;
|
|
89
89
|
};
|
|
90
90
|
})(util || (util = {}));
|
|
91
|
+
var objectUtil;
|
|
92
|
+
(function(objectUtil2) {
|
|
93
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
94
|
+
return {
|
|
95
|
+
...first,
|
|
96
|
+
...second
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
})(objectUtil || (objectUtil = {}));
|
|
91
100
|
var ZodParsedType = util.arrayToEnum([
|
|
92
101
|
"string",
|
|
93
102
|
"nan",
|
|
@@ -231,6 +240,11 @@ var ZodError = class extends Error {
|
|
|
231
240
|
processError(this);
|
|
232
241
|
return fieldErrors;
|
|
233
242
|
}
|
|
243
|
+
static assert(value) {
|
|
244
|
+
if (!(value instanceof ZodError)) {
|
|
245
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
234
248
|
toString() {
|
|
235
249
|
return this.message;
|
|
236
250
|
}
|
|
@@ -298,7 +312,12 @@ var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
|
298
312
|
break;
|
|
299
313
|
case ZodIssueCode.invalid_string:
|
|
300
314
|
if (typeof issue.validation === "object") {
|
|
301
|
-
if ("
|
|
315
|
+
if ("includes" in issue.validation) {
|
|
316
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
317
|
+
if (typeof issue.validation.position === "number") {
|
|
318
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
319
|
+
}
|
|
320
|
+
} else if ("startsWith" in issue.validation) {
|
|
302
321
|
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
303
322
|
} else if ("endsWith" in issue.validation) {
|
|
304
323
|
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
@@ -319,7 +338,7 @@ var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
|
319
338
|
else if (issue.type === "number")
|
|
320
339
|
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
321
340
|
else if (issue.type === "date")
|
|
322
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(issue.minimum)}`;
|
|
341
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
323
342
|
else
|
|
324
343
|
message = "Invalid input";
|
|
325
344
|
break;
|
|
@@ -330,8 +349,10 @@ var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
|
330
349
|
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
331
350
|
else if (issue.type === "number")
|
|
332
351
|
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
352
|
+
else if (issue.type === "bigint")
|
|
353
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
333
354
|
else if (issue.type === "date")
|
|
334
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(issue.maximum)}`;
|
|
355
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
335
356
|
else
|
|
336
357
|
message = "Invalid input";
|
|
337
358
|
break;
|
|
@@ -369,6 +390,13 @@ var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
|
369
390
|
...issueData,
|
|
370
391
|
path: fullPath
|
|
371
392
|
};
|
|
393
|
+
if (issueData.message !== void 0) {
|
|
394
|
+
return {
|
|
395
|
+
...issueData,
|
|
396
|
+
path: fullPath,
|
|
397
|
+
message: issueData.message
|
|
398
|
+
};
|
|
399
|
+
}
|
|
372
400
|
let errorMessage = "";
|
|
373
401
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
374
402
|
for (const map of maps) {
|
|
@@ -377,11 +405,12 @@ var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
|
377
405
|
return {
|
|
378
406
|
...issueData,
|
|
379
407
|
path: fullPath,
|
|
380
|
-
message:
|
|
408
|
+
message: errorMessage
|
|
381
409
|
};
|
|
382
410
|
}, "makeIssue");
|
|
383
411
|
var EMPTY_PATH = [];
|
|
384
412
|
function addIssueToContext(ctx, issueData) {
|
|
413
|
+
const overrideMap = getErrorMap();
|
|
385
414
|
const issue = makeIssue({
|
|
386
415
|
issueData,
|
|
387
416
|
data: ctx.data,
|
|
@@ -389,8 +418,8 @@ function addIssueToContext(ctx, issueData) {
|
|
|
389
418
|
errorMaps: [
|
|
390
419
|
ctx.common.contextualErrorMap,
|
|
391
420
|
ctx.schemaErrorMap,
|
|
392
|
-
|
|
393
|
-
errorMap
|
|
421
|
+
overrideMap,
|
|
422
|
+
overrideMap === errorMap ? void 0 : errorMap
|
|
394
423
|
].filter((x) => !!x)
|
|
395
424
|
});
|
|
396
425
|
ctx.common.issues.push(issue);
|
|
@@ -422,9 +451,11 @@ var ParseStatus = class {
|
|
|
422
451
|
static async mergeObjectAsync(status, pairs) {
|
|
423
452
|
const syncPairs = [];
|
|
424
453
|
for (const pair of pairs) {
|
|
454
|
+
const key = await pair.key;
|
|
455
|
+
const value = await pair.value;
|
|
425
456
|
syncPairs.push({
|
|
426
|
-
key
|
|
427
|
-
value
|
|
457
|
+
key,
|
|
458
|
+
value
|
|
428
459
|
});
|
|
429
460
|
}
|
|
430
461
|
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
@@ -441,7 +472,7 @@ var ParseStatus = class {
|
|
|
441
472
|
status.dirty();
|
|
442
473
|
if (value.status === "dirty")
|
|
443
474
|
status.dirty();
|
|
444
|
-
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
|
475
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
445
476
|
finalObject[key.value] = value.value;
|
|
446
477
|
}
|
|
447
478
|
}
|
|
@@ -457,21 +488,49 @@ var OK = /* @__PURE__ */ __name((value) => ({ status: "valid", value }), "OK");
|
|
|
457
488
|
var isAborted = /* @__PURE__ */ __name((x) => x.status === "aborted", "isAborted");
|
|
458
489
|
var isDirty = /* @__PURE__ */ __name((x) => x.status === "dirty", "isDirty");
|
|
459
490
|
var isValid = /* @__PURE__ */ __name((x) => x.status === "valid", "isValid");
|
|
460
|
-
var isAsync = /* @__PURE__ */ __name((x) => typeof Promise !==
|
|
491
|
+
var isAsync = /* @__PURE__ */ __name((x) => typeof Promise !== "undefined" && x instanceof Promise, "isAsync");
|
|
492
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
493
|
+
if (kind === "a" && !f)
|
|
494
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
495
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
496
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
497
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
498
|
+
}
|
|
499
|
+
__name(__classPrivateFieldGet, "__classPrivateFieldGet");
|
|
500
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
501
|
+
if (kind === "m")
|
|
502
|
+
throw new TypeError("Private method is not writable");
|
|
503
|
+
if (kind === "a" && !f)
|
|
504
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
505
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
506
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
507
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
508
|
+
}
|
|
509
|
+
__name(__classPrivateFieldSet, "__classPrivateFieldSet");
|
|
461
510
|
var errorUtil;
|
|
462
511
|
(function(errorUtil2) {
|
|
463
512
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
464
513
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
465
514
|
})(errorUtil || (errorUtil = {}));
|
|
515
|
+
var _ZodEnum_cache;
|
|
516
|
+
var _ZodNativeEnum_cache;
|
|
466
517
|
var ParseInputLazyPath = class {
|
|
467
518
|
constructor(parent, value, path, key) {
|
|
519
|
+
this._cachedPath = [];
|
|
468
520
|
this.parent = parent;
|
|
469
521
|
this.data = value;
|
|
470
522
|
this._path = path;
|
|
471
523
|
this._key = key;
|
|
472
524
|
}
|
|
473
525
|
get path() {
|
|
474
|
-
|
|
526
|
+
if (!this._cachedPath.length) {
|
|
527
|
+
if (this._key instanceof Array) {
|
|
528
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
529
|
+
} else {
|
|
530
|
+
this._cachedPath.push(...this._path, this._key);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return this._cachedPath;
|
|
475
534
|
}
|
|
476
535
|
};
|
|
477
536
|
__name(ParseInputLazyPath, "ParseInputLazyPath");
|
|
@@ -482,8 +541,16 @@ var handleResult = /* @__PURE__ */ __name((ctx, result) => {
|
|
|
482
541
|
if (!ctx.common.issues.length) {
|
|
483
542
|
throw new Error("Validation failed but no issues detected.");
|
|
484
543
|
}
|
|
485
|
-
|
|
486
|
-
|
|
544
|
+
return {
|
|
545
|
+
success: false,
|
|
546
|
+
get error() {
|
|
547
|
+
if (this._error)
|
|
548
|
+
return this._error;
|
|
549
|
+
const error = new ZodError(ctx.common.issues);
|
|
550
|
+
this._error = error;
|
|
551
|
+
return this._error;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
487
554
|
}
|
|
488
555
|
}, "handleResult");
|
|
489
556
|
function processCreateParams(params) {
|
|
@@ -496,12 +563,17 @@ function processCreateParams(params) {
|
|
|
496
563
|
if (errorMap2)
|
|
497
564
|
return { errorMap: errorMap2, description };
|
|
498
565
|
const customMap = /* @__PURE__ */ __name((iss, ctx) => {
|
|
499
|
-
|
|
500
|
-
|
|
566
|
+
var _a, _b;
|
|
567
|
+
const { message } = params;
|
|
568
|
+
if (iss.code === "invalid_enum_value") {
|
|
569
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
570
|
+
}
|
|
501
571
|
if (typeof ctx.data === "undefined") {
|
|
502
|
-
return { message:
|
|
572
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
503
573
|
}
|
|
504
|
-
|
|
574
|
+
if (iss.code !== "invalid_type")
|
|
575
|
+
return { message: ctx.defaultError };
|
|
576
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
505
577
|
}, "customMap");
|
|
506
578
|
return { errorMap: customMap, description };
|
|
507
579
|
}
|
|
@@ -531,6 +603,7 @@ var ZodType = class {
|
|
|
531
603
|
this.catch = this.catch.bind(this);
|
|
532
604
|
this.describe = this.describe.bind(this);
|
|
533
605
|
this.pipe = this.pipe.bind(this);
|
|
606
|
+
this.readonly = this.readonly.bind(this);
|
|
534
607
|
this.isNullable = this.isNullable.bind(this);
|
|
535
608
|
this.isOptional = this.isOptional.bind(this);
|
|
536
609
|
}
|
|
@@ -675,28 +748,29 @@ var ZodType = class {
|
|
|
675
748
|
return this._refinement(refinement);
|
|
676
749
|
}
|
|
677
750
|
optional() {
|
|
678
|
-
return ZodOptional.create(this);
|
|
751
|
+
return ZodOptional.create(this, this._def);
|
|
679
752
|
}
|
|
680
753
|
nullable() {
|
|
681
|
-
return ZodNullable.create(this);
|
|
754
|
+
return ZodNullable.create(this, this._def);
|
|
682
755
|
}
|
|
683
756
|
nullish() {
|
|
684
|
-
return this.
|
|
757
|
+
return this.nullable().optional();
|
|
685
758
|
}
|
|
686
759
|
array() {
|
|
687
|
-
return ZodArray.create(this);
|
|
760
|
+
return ZodArray.create(this, this._def);
|
|
688
761
|
}
|
|
689
762
|
promise() {
|
|
690
|
-
return ZodPromise.create(this);
|
|
763
|
+
return ZodPromise.create(this, this._def);
|
|
691
764
|
}
|
|
692
765
|
or(option) {
|
|
693
|
-
return ZodUnion.create([this, option]);
|
|
766
|
+
return ZodUnion.create([this, option], this._def);
|
|
694
767
|
}
|
|
695
768
|
and(incoming) {
|
|
696
|
-
return ZodIntersection.create(this, incoming);
|
|
769
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
697
770
|
}
|
|
698
771
|
transform(transform) {
|
|
699
772
|
return new ZodEffects({
|
|
773
|
+
...processCreateParams(this._def),
|
|
700
774
|
schema: this,
|
|
701
775
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
702
776
|
effect: { type: "transform", transform }
|
|
@@ -705,6 +779,7 @@ var ZodType = class {
|
|
|
705
779
|
default(def) {
|
|
706
780
|
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
707
781
|
return new ZodDefault({
|
|
782
|
+
...processCreateParams(this._def),
|
|
708
783
|
innerType: this,
|
|
709
784
|
defaultValue: defaultValueFunc,
|
|
710
785
|
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
@@ -714,14 +789,15 @@ var ZodType = class {
|
|
|
714
789
|
return new ZodBranded({
|
|
715
790
|
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
716
791
|
type: this,
|
|
717
|
-
...processCreateParams(
|
|
792
|
+
...processCreateParams(this._def)
|
|
718
793
|
});
|
|
719
794
|
}
|
|
720
795
|
catch(def) {
|
|
721
|
-
const
|
|
796
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
722
797
|
return new ZodCatch({
|
|
798
|
+
...processCreateParams(this._def),
|
|
723
799
|
innerType: this,
|
|
724
|
-
|
|
800
|
+
catchValue: catchValueFunc,
|
|
725
801
|
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
726
802
|
});
|
|
727
803
|
}
|
|
@@ -735,6 +811,9 @@ var ZodType = class {
|
|
|
735
811
|
pipe(target) {
|
|
736
812
|
return ZodPipeline.create(this, target);
|
|
737
813
|
}
|
|
814
|
+
readonly() {
|
|
815
|
+
return ZodReadonly.create(this);
|
|
816
|
+
}
|
|
738
817
|
isOptional() {
|
|
739
818
|
return this.safeParse(void 0).success;
|
|
740
819
|
}
|
|
@@ -744,43 +823,54 @@ var ZodType = class {
|
|
|
744
823
|
};
|
|
745
824
|
__name(ZodType, "ZodType");
|
|
746
825
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
747
|
-
var
|
|
748
|
-
var
|
|
749
|
-
var
|
|
826
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
827
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
828
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
829
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
830
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
831
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
832
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
833
|
+
var emojiRegex;
|
|
834
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
835
|
+
var 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})))$/;
|
|
836
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
837
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
838
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
839
|
+
function timeRegexSource(args) {
|
|
840
|
+
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
750
841
|
if (args.precision) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
755
|
-
}
|
|
756
|
-
} else if (args.precision === 0) {
|
|
757
|
-
if (args.offset) {
|
|
758
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$`);
|
|
759
|
-
} else {
|
|
760
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
761
|
-
}
|
|
762
|
-
} else {
|
|
763
|
-
if (args.offset) {
|
|
764
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$`);
|
|
765
|
-
} else {
|
|
766
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
767
|
-
}
|
|
842
|
+
regex = `${regex}\\.\\d{${args.precision}}`;
|
|
843
|
+
} else if (args.precision == null) {
|
|
844
|
+
regex = `${regex}(\\.\\d+)?`;
|
|
768
845
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
846
|
+
return regex;
|
|
847
|
+
}
|
|
848
|
+
__name(timeRegexSource, "timeRegexSource");
|
|
849
|
+
function timeRegex(args) {
|
|
850
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
851
|
+
}
|
|
852
|
+
__name(timeRegex, "timeRegex");
|
|
853
|
+
function datetimeRegex(args) {
|
|
854
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
855
|
+
const opts = [];
|
|
856
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
857
|
+
if (args.offset)
|
|
858
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
859
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
860
|
+
return new RegExp(`^${regex}$`);
|
|
861
|
+
}
|
|
862
|
+
__name(datetimeRegex, "datetimeRegex");
|
|
863
|
+
function isValidIP(ip, version) {
|
|
864
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
865
|
+
return true;
|
|
866
|
+
}
|
|
867
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
868
|
+
return true;
|
|
783
869
|
}
|
|
870
|
+
return false;
|
|
871
|
+
}
|
|
872
|
+
__name(isValidIP, "isValidIP");
|
|
873
|
+
var ZodString = class extends ZodType {
|
|
784
874
|
_parse(input) {
|
|
785
875
|
if (this._def.coerce) {
|
|
786
876
|
input.data = String(input.data);
|
|
@@ -788,14 +878,11 @@ var ZodString = class extends ZodType {
|
|
|
788
878
|
const parsedType = this._getType(input);
|
|
789
879
|
if (parsedType !== ZodParsedType.string) {
|
|
790
880
|
const ctx2 = this._getOrReturnCtx(input);
|
|
791
|
-
addIssueToContext(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
received: ctx2.parsedType
|
|
797
|
-
}
|
|
798
|
-
);
|
|
881
|
+
addIssueToContext(ctx2, {
|
|
882
|
+
code: ZodIssueCode.invalid_type,
|
|
883
|
+
expected: ZodParsedType.string,
|
|
884
|
+
received: ctx2.parsedType
|
|
885
|
+
});
|
|
799
886
|
return INVALID;
|
|
800
887
|
}
|
|
801
888
|
const status = new ParseStatus();
|
|
@@ -863,6 +950,19 @@ var ZodString = class extends ZodType {
|
|
|
863
950
|
});
|
|
864
951
|
status.dirty();
|
|
865
952
|
}
|
|
953
|
+
} else if (check.kind === "emoji") {
|
|
954
|
+
if (!emojiRegex) {
|
|
955
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
956
|
+
}
|
|
957
|
+
if (!emojiRegex.test(input.data)) {
|
|
958
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
959
|
+
addIssueToContext(ctx, {
|
|
960
|
+
validation: "emoji",
|
|
961
|
+
code: ZodIssueCode.invalid_string,
|
|
962
|
+
message: check.message
|
|
963
|
+
});
|
|
964
|
+
status.dirty();
|
|
965
|
+
}
|
|
866
966
|
} else if (check.kind === "uuid") {
|
|
867
967
|
if (!uuidRegex.test(input.data)) {
|
|
868
968
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -873,6 +973,16 @@ var ZodString = class extends ZodType {
|
|
|
873
973
|
});
|
|
874
974
|
status.dirty();
|
|
875
975
|
}
|
|
976
|
+
} else if (check.kind === "nanoid") {
|
|
977
|
+
if (!nanoidRegex.test(input.data)) {
|
|
978
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
979
|
+
addIssueToContext(ctx, {
|
|
980
|
+
validation: "nanoid",
|
|
981
|
+
code: ZodIssueCode.invalid_string,
|
|
982
|
+
message: check.message
|
|
983
|
+
});
|
|
984
|
+
status.dirty();
|
|
985
|
+
}
|
|
876
986
|
} else if (check.kind === "cuid") {
|
|
877
987
|
if (!cuidRegex.test(input.data)) {
|
|
878
988
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -883,6 +993,26 @@ var ZodString = class extends ZodType {
|
|
|
883
993
|
});
|
|
884
994
|
status.dirty();
|
|
885
995
|
}
|
|
996
|
+
} else if (check.kind === "cuid2") {
|
|
997
|
+
if (!cuid2Regex.test(input.data)) {
|
|
998
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
999
|
+
addIssueToContext(ctx, {
|
|
1000
|
+
validation: "cuid2",
|
|
1001
|
+
code: ZodIssueCode.invalid_string,
|
|
1002
|
+
message: check.message
|
|
1003
|
+
});
|
|
1004
|
+
status.dirty();
|
|
1005
|
+
}
|
|
1006
|
+
} else if (check.kind === "ulid") {
|
|
1007
|
+
if (!ulidRegex.test(input.data)) {
|
|
1008
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1009
|
+
addIssueToContext(ctx, {
|
|
1010
|
+
validation: "ulid",
|
|
1011
|
+
code: ZodIssueCode.invalid_string,
|
|
1012
|
+
message: check.message
|
|
1013
|
+
});
|
|
1014
|
+
status.dirty();
|
|
1015
|
+
}
|
|
886
1016
|
} else if (check.kind === "url") {
|
|
887
1017
|
try {
|
|
888
1018
|
new URL(input.data);
|
|
@@ -909,6 +1039,20 @@ var ZodString = class extends ZodType {
|
|
|
909
1039
|
}
|
|
910
1040
|
} else if (check.kind === "trim") {
|
|
911
1041
|
input.data = input.data.trim();
|
|
1042
|
+
} else if (check.kind === "includes") {
|
|
1043
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1044
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1045
|
+
addIssueToContext(ctx, {
|
|
1046
|
+
code: ZodIssueCode.invalid_string,
|
|
1047
|
+
validation: { includes: check.value, position: check.position },
|
|
1048
|
+
message: check.message
|
|
1049
|
+
});
|
|
1050
|
+
status.dirty();
|
|
1051
|
+
}
|
|
1052
|
+
} else if (check.kind === "toLowerCase") {
|
|
1053
|
+
input.data = input.data.toLowerCase();
|
|
1054
|
+
} else if (check.kind === "toUpperCase") {
|
|
1055
|
+
input.data = input.data.toUpperCase();
|
|
912
1056
|
} else if (check.kind === "startsWith") {
|
|
913
1057
|
if (!input.data.startsWith(check.value)) {
|
|
914
1058
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -940,12 +1084,71 @@ var ZodString = class extends ZodType {
|
|
|
940
1084
|
});
|
|
941
1085
|
status.dirty();
|
|
942
1086
|
}
|
|
1087
|
+
} else if (check.kind === "date") {
|
|
1088
|
+
const regex = dateRegex;
|
|
1089
|
+
if (!regex.test(input.data)) {
|
|
1090
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1091
|
+
addIssueToContext(ctx, {
|
|
1092
|
+
code: ZodIssueCode.invalid_string,
|
|
1093
|
+
validation: "date",
|
|
1094
|
+
message: check.message
|
|
1095
|
+
});
|
|
1096
|
+
status.dirty();
|
|
1097
|
+
}
|
|
1098
|
+
} else if (check.kind === "time") {
|
|
1099
|
+
const regex = timeRegex(check);
|
|
1100
|
+
if (!regex.test(input.data)) {
|
|
1101
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1102
|
+
addIssueToContext(ctx, {
|
|
1103
|
+
code: ZodIssueCode.invalid_string,
|
|
1104
|
+
validation: "time",
|
|
1105
|
+
message: check.message
|
|
1106
|
+
});
|
|
1107
|
+
status.dirty();
|
|
1108
|
+
}
|
|
1109
|
+
} else if (check.kind === "duration") {
|
|
1110
|
+
if (!durationRegex.test(input.data)) {
|
|
1111
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1112
|
+
addIssueToContext(ctx, {
|
|
1113
|
+
validation: "duration",
|
|
1114
|
+
code: ZodIssueCode.invalid_string,
|
|
1115
|
+
message: check.message
|
|
1116
|
+
});
|
|
1117
|
+
status.dirty();
|
|
1118
|
+
}
|
|
1119
|
+
} else if (check.kind === "ip") {
|
|
1120
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1121
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1122
|
+
addIssueToContext(ctx, {
|
|
1123
|
+
validation: "ip",
|
|
1124
|
+
code: ZodIssueCode.invalid_string,
|
|
1125
|
+
message: check.message
|
|
1126
|
+
});
|
|
1127
|
+
status.dirty();
|
|
1128
|
+
}
|
|
1129
|
+
} else if (check.kind === "base64") {
|
|
1130
|
+
if (!base64Regex.test(input.data)) {
|
|
1131
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1132
|
+
addIssueToContext(ctx, {
|
|
1133
|
+
validation: "base64",
|
|
1134
|
+
code: ZodIssueCode.invalid_string,
|
|
1135
|
+
message: check.message
|
|
1136
|
+
});
|
|
1137
|
+
status.dirty();
|
|
1138
|
+
}
|
|
943
1139
|
} else {
|
|
944
1140
|
util.assertNever(check);
|
|
945
1141
|
}
|
|
946
1142
|
}
|
|
947
1143
|
return { status: status.value, value: input.data };
|
|
948
1144
|
}
|
|
1145
|
+
_regex(regex, validation, message) {
|
|
1146
|
+
return this.refinement((data) => regex.test(data), {
|
|
1147
|
+
validation,
|
|
1148
|
+
code: ZodIssueCode.invalid_string,
|
|
1149
|
+
...errorUtil.errToObj(message)
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
949
1152
|
_addCheck(check) {
|
|
950
1153
|
return new ZodString({
|
|
951
1154
|
...this._def,
|
|
@@ -958,19 +1161,38 @@ var ZodString = class extends ZodType {
|
|
|
958
1161
|
url(message) {
|
|
959
1162
|
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
960
1163
|
}
|
|
1164
|
+
emoji(message) {
|
|
1165
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1166
|
+
}
|
|
961
1167
|
uuid(message) {
|
|
962
1168
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
963
1169
|
}
|
|
1170
|
+
nanoid(message) {
|
|
1171
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1172
|
+
}
|
|
964
1173
|
cuid(message) {
|
|
965
1174
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
966
1175
|
}
|
|
1176
|
+
cuid2(message) {
|
|
1177
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1178
|
+
}
|
|
1179
|
+
ulid(message) {
|
|
1180
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1181
|
+
}
|
|
1182
|
+
base64(message) {
|
|
1183
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1184
|
+
}
|
|
1185
|
+
ip(options) {
|
|
1186
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1187
|
+
}
|
|
967
1188
|
datetime(options) {
|
|
968
|
-
var _a;
|
|
1189
|
+
var _a, _b;
|
|
969
1190
|
if (typeof options === "string") {
|
|
970
1191
|
return this._addCheck({
|
|
971
1192
|
kind: "datetime",
|
|
972
1193
|
precision: null,
|
|
973
1194
|
offset: false,
|
|
1195
|
+
local: false,
|
|
974
1196
|
message: options
|
|
975
1197
|
});
|
|
976
1198
|
}
|
|
@@ -978,9 +1200,30 @@ var ZodString = class extends ZodType {
|
|
|
978
1200
|
kind: "datetime",
|
|
979
1201
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
980
1202
|
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1203
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
|
1204
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
date(message) {
|
|
1208
|
+
return this._addCheck({ kind: "date", message });
|
|
1209
|
+
}
|
|
1210
|
+
time(options) {
|
|
1211
|
+
if (typeof options === "string") {
|
|
1212
|
+
return this._addCheck({
|
|
1213
|
+
kind: "time",
|
|
1214
|
+
precision: null,
|
|
1215
|
+
message: options
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
return this._addCheck({
|
|
1219
|
+
kind: "time",
|
|
1220
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
981
1221
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
982
1222
|
});
|
|
983
1223
|
}
|
|
1224
|
+
duration(message) {
|
|
1225
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1226
|
+
}
|
|
984
1227
|
regex(regex, message) {
|
|
985
1228
|
return this._addCheck({
|
|
986
1229
|
kind: "regex",
|
|
@@ -988,6 +1231,14 @@ var ZodString = class extends ZodType {
|
|
|
988
1231
|
...errorUtil.errToObj(message)
|
|
989
1232
|
});
|
|
990
1233
|
}
|
|
1234
|
+
includes(value, options) {
|
|
1235
|
+
return this._addCheck({
|
|
1236
|
+
kind: "includes",
|
|
1237
|
+
value,
|
|
1238
|
+
position: options === null || options === void 0 ? void 0 : options.position,
|
|
1239
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
991
1242
|
startsWith(value, message) {
|
|
992
1243
|
return this._addCheck({
|
|
993
1244
|
kind: "startsWith",
|
|
@@ -1023,21 +1274,69 @@ var ZodString = class extends ZodType {
|
|
|
1023
1274
|
...errorUtil.errToObj(message)
|
|
1024
1275
|
});
|
|
1025
1276
|
}
|
|
1277
|
+
nonempty(message) {
|
|
1278
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1279
|
+
}
|
|
1280
|
+
trim() {
|
|
1281
|
+
return new ZodString({
|
|
1282
|
+
...this._def,
|
|
1283
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
toLowerCase() {
|
|
1287
|
+
return new ZodString({
|
|
1288
|
+
...this._def,
|
|
1289
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
toUpperCase() {
|
|
1293
|
+
return new ZodString({
|
|
1294
|
+
...this._def,
|
|
1295
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1026
1298
|
get isDatetime() {
|
|
1027
1299
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1028
1300
|
}
|
|
1301
|
+
get isDate() {
|
|
1302
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1303
|
+
}
|
|
1304
|
+
get isTime() {
|
|
1305
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1306
|
+
}
|
|
1307
|
+
get isDuration() {
|
|
1308
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1309
|
+
}
|
|
1029
1310
|
get isEmail() {
|
|
1030
1311
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1031
1312
|
}
|
|
1032
1313
|
get isURL() {
|
|
1033
1314
|
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1034
1315
|
}
|
|
1316
|
+
get isEmoji() {
|
|
1317
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1318
|
+
}
|
|
1035
1319
|
get isUUID() {
|
|
1036
1320
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1037
1321
|
}
|
|
1322
|
+
get isNANOID() {
|
|
1323
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1324
|
+
}
|
|
1038
1325
|
get isCUID() {
|
|
1039
1326
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1040
1327
|
}
|
|
1328
|
+
get isCUID2() {
|
|
1329
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1330
|
+
}
|
|
1331
|
+
get isULID() {
|
|
1332
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1333
|
+
}
|
|
1334
|
+
get isIP() {
|
|
1335
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1336
|
+
}
|
|
1337
|
+
get isBase64() {
|
|
1338
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1339
|
+
}
|
|
1041
1340
|
get minLength() {
|
|
1042
1341
|
let min = null;
|
|
1043
1342
|
for (const ch of this._def.checks) {
|
|
@@ -1249,6 +1548,19 @@ var ZodNumber = class extends ZodType {
|
|
|
1249
1548
|
message: errorUtil.toString(message)
|
|
1250
1549
|
});
|
|
1251
1550
|
}
|
|
1551
|
+
safe(message) {
|
|
1552
|
+
return this._addCheck({
|
|
1553
|
+
kind: "min",
|
|
1554
|
+
inclusive: true,
|
|
1555
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1556
|
+
message: errorUtil.toString(message)
|
|
1557
|
+
})._addCheck({
|
|
1558
|
+
kind: "max",
|
|
1559
|
+
inclusive: true,
|
|
1560
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1561
|
+
message: errorUtil.toString(message)
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1252
1564
|
get minValue() {
|
|
1253
1565
|
let min = null;
|
|
1254
1566
|
for (const ch of this._def.checks) {
|
|
@@ -1270,7 +1582,22 @@ var ZodNumber = class extends ZodType {
|
|
|
1270
1582
|
return max;
|
|
1271
1583
|
}
|
|
1272
1584
|
get isInt() {
|
|
1273
|
-
return !!this._def.checks.find((ch) => ch.kind === "int");
|
|
1585
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1586
|
+
}
|
|
1587
|
+
get isFinite() {
|
|
1588
|
+
let max = null, min = null;
|
|
1589
|
+
for (const ch of this._def.checks) {
|
|
1590
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1591
|
+
return true;
|
|
1592
|
+
} else if (ch.kind === "min") {
|
|
1593
|
+
if (min === null || ch.value > min)
|
|
1594
|
+
min = ch.value;
|
|
1595
|
+
} else if (ch.kind === "max") {
|
|
1596
|
+
if (max === null || ch.value < max)
|
|
1597
|
+
max = ch.value;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1274
1601
|
}
|
|
1275
1602
|
};
|
|
1276
1603
|
__name(ZodNumber, "ZodNumber");
|
|
@@ -1283,27 +1610,167 @@ ZodNumber.create = (params) => {
|
|
|
1283
1610
|
});
|
|
1284
1611
|
};
|
|
1285
1612
|
var ZodBigInt = class extends ZodType {
|
|
1613
|
+
constructor() {
|
|
1614
|
+
super(...arguments);
|
|
1615
|
+
this.min = this.gte;
|
|
1616
|
+
this.max = this.lte;
|
|
1617
|
+
}
|
|
1286
1618
|
_parse(input) {
|
|
1287
1619
|
if (this._def.coerce) {
|
|
1288
1620
|
input.data = BigInt(input.data);
|
|
1289
1621
|
}
|
|
1290
1622
|
const parsedType = this._getType(input);
|
|
1291
1623
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1292
|
-
const
|
|
1293
|
-
addIssueToContext(
|
|
1624
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1625
|
+
addIssueToContext(ctx2, {
|
|
1294
1626
|
code: ZodIssueCode.invalid_type,
|
|
1295
1627
|
expected: ZodParsedType.bigint,
|
|
1296
|
-
received:
|
|
1628
|
+
received: ctx2.parsedType
|
|
1297
1629
|
});
|
|
1298
1630
|
return INVALID;
|
|
1299
1631
|
}
|
|
1300
|
-
|
|
1632
|
+
let ctx = void 0;
|
|
1633
|
+
const status = new ParseStatus();
|
|
1634
|
+
for (const check of this._def.checks) {
|
|
1635
|
+
if (check.kind === "min") {
|
|
1636
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1637
|
+
if (tooSmall) {
|
|
1638
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1639
|
+
addIssueToContext(ctx, {
|
|
1640
|
+
code: ZodIssueCode.too_small,
|
|
1641
|
+
type: "bigint",
|
|
1642
|
+
minimum: check.value,
|
|
1643
|
+
inclusive: check.inclusive,
|
|
1644
|
+
message: check.message
|
|
1645
|
+
});
|
|
1646
|
+
status.dirty();
|
|
1647
|
+
}
|
|
1648
|
+
} else if (check.kind === "max") {
|
|
1649
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1650
|
+
if (tooBig) {
|
|
1651
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1652
|
+
addIssueToContext(ctx, {
|
|
1653
|
+
code: ZodIssueCode.too_big,
|
|
1654
|
+
type: "bigint",
|
|
1655
|
+
maximum: check.value,
|
|
1656
|
+
inclusive: check.inclusive,
|
|
1657
|
+
message: check.message
|
|
1658
|
+
});
|
|
1659
|
+
status.dirty();
|
|
1660
|
+
}
|
|
1661
|
+
} else if (check.kind === "multipleOf") {
|
|
1662
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1663
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1664
|
+
addIssueToContext(ctx, {
|
|
1665
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1666
|
+
multipleOf: check.value,
|
|
1667
|
+
message: check.message
|
|
1668
|
+
});
|
|
1669
|
+
status.dirty();
|
|
1670
|
+
}
|
|
1671
|
+
} else {
|
|
1672
|
+
util.assertNever(check);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return { status: status.value, value: input.data };
|
|
1676
|
+
}
|
|
1677
|
+
gte(value, message) {
|
|
1678
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1679
|
+
}
|
|
1680
|
+
gt(value, message) {
|
|
1681
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1682
|
+
}
|
|
1683
|
+
lte(value, message) {
|
|
1684
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1685
|
+
}
|
|
1686
|
+
lt(value, message) {
|
|
1687
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1688
|
+
}
|
|
1689
|
+
setLimit(kind, value, inclusive, message) {
|
|
1690
|
+
return new ZodBigInt({
|
|
1691
|
+
...this._def,
|
|
1692
|
+
checks: [
|
|
1693
|
+
...this._def.checks,
|
|
1694
|
+
{
|
|
1695
|
+
kind,
|
|
1696
|
+
value,
|
|
1697
|
+
inclusive,
|
|
1698
|
+
message: errorUtil.toString(message)
|
|
1699
|
+
}
|
|
1700
|
+
]
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
_addCheck(check) {
|
|
1704
|
+
return new ZodBigInt({
|
|
1705
|
+
...this._def,
|
|
1706
|
+
checks: [...this._def.checks, check]
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
positive(message) {
|
|
1710
|
+
return this._addCheck({
|
|
1711
|
+
kind: "min",
|
|
1712
|
+
value: BigInt(0),
|
|
1713
|
+
inclusive: false,
|
|
1714
|
+
message: errorUtil.toString(message)
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
negative(message) {
|
|
1718
|
+
return this._addCheck({
|
|
1719
|
+
kind: "max",
|
|
1720
|
+
value: BigInt(0),
|
|
1721
|
+
inclusive: false,
|
|
1722
|
+
message: errorUtil.toString(message)
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
nonpositive(message) {
|
|
1726
|
+
return this._addCheck({
|
|
1727
|
+
kind: "max",
|
|
1728
|
+
value: BigInt(0),
|
|
1729
|
+
inclusive: true,
|
|
1730
|
+
message: errorUtil.toString(message)
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
nonnegative(message) {
|
|
1734
|
+
return this._addCheck({
|
|
1735
|
+
kind: "min",
|
|
1736
|
+
value: BigInt(0),
|
|
1737
|
+
inclusive: true,
|
|
1738
|
+
message: errorUtil.toString(message)
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
multipleOf(value, message) {
|
|
1742
|
+
return this._addCheck({
|
|
1743
|
+
kind: "multipleOf",
|
|
1744
|
+
value,
|
|
1745
|
+
message: errorUtil.toString(message)
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
get minValue() {
|
|
1749
|
+
let min = null;
|
|
1750
|
+
for (const ch of this._def.checks) {
|
|
1751
|
+
if (ch.kind === "min") {
|
|
1752
|
+
if (min === null || ch.value > min)
|
|
1753
|
+
min = ch.value;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return min;
|
|
1757
|
+
}
|
|
1758
|
+
get maxValue() {
|
|
1759
|
+
let max = null;
|
|
1760
|
+
for (const ch of this._def.checks) {
|
|
1761
|
+
if (ch.kind === "max") {
|
|
1762
|
+
if (max === null || ch.value < max)
|
|
1763
|
+
max = ch.value;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
return max;
|
|
1301
1767
|
}
|
|
1302
1768
|
};
|
|
1303
1769
|
__name(ZodBigInt, "ZodBigInt");
|
|
1304
1770
|
ZodBigInt.create = (params) => {
|
|
1305
1771
|
var _a;
|
|
1306
1772
|
return new ZodBigInt({
|
|
1773
|
+
checks: [],
|
|
1307
1774
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1308
1775
|
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1309
1776
|
...processCreateParams(params)
|
|
@@ -1638,13 +2105,13 @@ var ZodArray = class extends ZodType {
|
|
|
1638
2105
|
}
|
|
1639
2106
|
}
|
|
1640
2107
|
if (ctx.common.async) {
|
|
1641
|
-
return Promise.all(ctx.data.map((item, i) => {
|
|
2108
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
1642
2109
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1643
2110
|
})).then((result2) => {
|
|
1644
2111
|
return ParseStatus.mergeArray(status, result2);
|
|
1645
2112
|
});
|
|
1646
2113
|
}
|
|
1647
|
-
const result = ctx.data.map((item, i) => {
|
|
2114
|
+
const result = [...ctx.data].map((item, i) => {
|
|
1648
2115
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1649
2116
|
});
|
|
1650
2117
|
return ParseStatus.mergeArray(status, result);
|
|
@@ -1685,24 +2152,6 @@ ZodArray.create = (schema, params) => {
|
|
|
1685
2152
|
...processCreateParams(params)
|
|
1686
2153
|
});
|
|
1687
2154
|
};
|
|
1688
|
-
var objectUtil;
|
|
1689
|
-
(function(objectUtil2) {
|
|
1690
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
1691
|
-
return {
|
|
1692
|
-
...first,
|
|
1693
|
-
...second
|
|
1694
|
-
};
|
|
1695
|
-
};
|
|
1696
|
-
})(objectUtil || (objectUtil = {}));
|
|
1697
|
-
var AugmentFactory = /* @__PURE__ */ __name((def) => (augmentation) => {
|
|
1698
|
-
return new ZodObject({
|
|
1699
|
-
...def,
|
|
1700
|
-
shape: () => ({
|
|
1701
|
-
...def.shape(),
|
|
1702
|
-
...augmentation
|
|
1703
|
-
})
|
|
1704
|
-
});
|
|
1705
|
-
}, "AugmentFactory");
|
|
1706
2155
|
function deepPartialify(schema) {
|
|
1707
2156
|
if (schema instanceof ZodObject) {
|
|
1708
2157
|
const newShape = {};
|
|
@@ -1715,7 +2164,10 @@ function deepPartialify(schema) {
|
|
|
1715
2164
|
shape: () => newShape
|
|
1716
2165
|
});
|
|
1717
2166
|
} else if (schema instanceof ZodArray) {
|
|
1718
|
-
return ZodArray
|
|
2167
|
+
return new ZodArray({
|
|
2168
|
+
...schema._def,
|
|
2169
|
+
type: deepPartialify(schema.element)
|
|
2170
|
+
});
|
|
1719
2171
|
} else if (schema instanceof ZodOptional) {
|
|
1720
2172
|
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
1721
2173
|
} else if (schema instanceof ZodNullable) {
|
|
@@ -1732,8 +2184,7 @@ var ZodObject = class extends ZodType {
|
|
|
1732
2184
|
super(...arguments);
|
|
1733
2185
|
this._cached = null;
|
|
1734
2186
|
this.nonstrict = this.passthrough;
|
|
1735
|
-
this.augment =
|
|
1736
|
-
this.extend = AugmentFactory(this._def);
|
|
2187
|
+
this.augment = this.extend;
|
|
1737
2188
|
}
|
|
1738
2189
|
_getCached() {
|
|
1739
2190
|
if (this._cached !== null)
|
|
@@ -1813,9 +2264,10 @@ var ZodObject = class extends ZodType {
|
|
|
1813
2264
|
const syncPairs = [];
|
|
1814
2265
|
for (const pair of pairs) {
|
|
1815
2266
|
const key = await pair.key;
|
|
2267
|
+
const value = await pair.value;
|
|
1816
2268
|
syncPairs.push({
|
|
1817
2269
|
key,
|
|
1818
|
-
value
|
|
2270
|
+
value,
|
|
1819
2271
|
alwaysSet: pair.alwaysSet
|
|
1820
2272
|
});
|
|
1821
2273
|
}
|
|
@@ -1862,18 +2314,30 @@ var ZodObject = class extends ZodType {
|
|
|
1862
2314
|
unknownKeys: "passthrough"
|
|
1863
2315
|
});
|
|
1864
2316
|
}
|
|
1865
|
-
|
|
1866
|
-
return
|
|
2317
|
+
extend(augmentation) {
|
|
2318
|
+
return new ZodObject({
|
|
2319
|
+
...this._def,
|
|
2320
|
+
shape: () => ({
|
|
2321
|
+
...this._def.shape(),
|
|
2322
|
+
...augmentation
|
|
2323
|
+
})
|
|
2324
|
+
});
|
|
1867
2325
|
}
|
|
1868
2326
|
merge(merging) {
|
|
1869
2327
|
const merged = new ZodObject({
|
|
1870
2328
|
unknownKeys: merging._def.unknownKeys,
|
|
1871
2329
|
catchall: merging._def.catchall,
|
|
1872
|
-
shape: () =>
|
|
2330
|
+
shape: () => ({
|
|
2331
|
+
...this._def.shape(),
|
|
2332
|
+
...merging._def.shape()
|
|
2333
|
+
}),
|
|
1873
2334
|
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
1874
2335
|
});
|
|
1875
2336
|
return merged;
|
|
1876
2337
|
}
|
|
2338
|
+
setKey(key, schema) {
|
|
2339
|
+
return this.augment({ [key]: schema });
|
|
2340
|
+
}
|
|
1877
2341
|
catchall(index) {
|
|
1878
2342
|
return new ZodObject({
|
|
1879
2343
|
...this._def,
|
|
@@ -1882,9 +2346,10 @@ var ZodObject = class extends ZodType {
|
|
|
1882
2346
|
}
|
|
1883
2347
|
pick(mask) {
|
|
1884
2348
|
const shape = {};
|
|
1885
|
-
util.objectKeys(mask).
|
|
1886
|
-
if (this.shape[key])
|
|
2349
|
+
util.objectKeys(mask).forEach((key) => {
|
|
2350
|
+
if (mask[key] && this.shape[key]) {
|
|
1887
2351
|
shape[key] = this.shape[key];
|
|
2352
|
+
}
|
|
1888
2353
|
});
|
|
1889
2354
|
return new ZodObject({
|
|
1890
2355
|
...this._def,
|
|
@@ -1893,8 +2358,8 @@ var ZodObject = class extends ZodType {
|
|
|
1893
2358
|
}
|
|
1894
2359
|
omit(mask) {
|
|
1895
2360
|
const shape = {};
|
|
1896
|
-
util.objectKeys(this.shape).
|
|
1897
|
-
if (
|
|
2361
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2362
|
+
if (!mask[key]) {
|
|
1898
2363
|
shape[key] = this.shape[key];
|
|
1899
2364
|
}
|
|
1900
2365
|
});
|
|
@@ -1908,24 +2373,14 @@ var ZodObject = class extends ZodType {
|
|
|
1908
2373
|
}
|
|
1909
2374
|
partial(mask) {
|
|
1910
2375
|
const newShape = {};
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
newShape[key] = this.shape[key].optional();
|
|
1917
|
-
}
|
|
1918
|
-
});
|
|
1919
|
-
return new ZodObject({
|
|
1920
|
-
...this._def,
|
|
1921
|
-
shape: () => newShape
|
|
1922
|
-
});
|
|
1923
|
-
} else {
|
|
1924
|
-
for (const key in this.shape) {
|
|
1925
|
-
const fieldSchema = this.shape[key];
|
|
2376
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2377
|
+
const fieldSchema = this.shape[key];
|
|
2378
|
+
if (mask && !mask[key]) {
|
|
2379
|
+
newShape[key] = fieldSchema;
|
|
2380
|
+
} else {
|
|
1926
2381
|
newShape[key] = fieldSchema.optional();
|
|
1927
2382
|
}
|
|
1928
|
-
}
|
|
2383
|
+
});
|
|
1929
2384
|
return new ZodObject({
|
|
1930
2385
|
...this._def,
|
|
1931
2386
|
shape: () => newShape
|
|
@@ -1933,21 +2388,10 @@ var ZodObject = class extends ZodType {
|
|
|
1933
2388
|
}
|
|
1934
2389
|
required(mask) {
|
|
1935
2390
|
const newShape = {};
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
} else {
|
|
1941
|
-
const fieldSchema = this.shape[key];
|
|
1942
|
-
let newField = fieldSchema;
|
|
1943
|
-
while (newField instanceof ZodOptional) {
|
|
1944
|
-
newField = newField._def.innerType;
|
|
1945
|
-
}
|
|
1946
|
-
newShape[key] = newField;
|
|
1947
|
-
}
|
|
1948
|
-
});
|
|
1949
|
-
} else {
|
|
1950
|
-
for (const key in this.shape) {
|
|
2391
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2392
|
+
if (mask && !mask[key]) {
|
|
2393
|
+
newShape[key] = this.shape[key];
|
|
2394
|
+
} else {
|
|
1951
2395
|
const fieldSchema = this.shape[key];
|
|
1952
2396
|
let newField = fieldSchema;
|
|
1953
2397
|
while (newField instanceof ZodOptional) {
|
|
@@ -1955,7 +2399,7 @@ var ZodObject = class extends ZodType {
|
|
|
1955
2399
|
}
|
|
1956
2400
|
newShape[key] = newField;
|
|
1957
2401
|
}
|
|
1958
|
-
}
|
|
2402
|
+
});
|
|
1959
2403
|
return new ZodObject({
|
|
1960
2404
|
...this._def,
|
|
1961
2405
|
shape: () => newShape
|
|
@@ -2096,15 +2540,25 @@ var getDiscriminator = /* @__PURE__ */ __name((type) => {
|
|
|
2096
2540
|
} else if (type instanceof ZodEnum) {
|
|
2097
2541
|
return type.options;
|
|
2098
2542
|
} else if (type instanceof ZodNativeEnum) {
|
|
2099
|
-
return
|
|
2543
|
+
return util.objectValues(type.enum);
|
|
2100
2544
|
} else if (type instanceof ZodDefault) {
|
|
2101
2545
|
return getDiscriminator(type._def.innerType);
|
|
2102
2546
|
} else if (type instanceof ZodUndefined) {
|
|
2103
2547
|
return [void 0];
|
|
2104
2548
|
} else if (type instanceof ZodNull) {
|
|
2105
2549
|
return [null];
|
|
2550
|
+
} else if (type instanceof ZodOptional) {
|
|
2551
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
2552
|
+
} else if (type instanceof ZodNullable) {
|
|
2553
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
2554
|
+
} else if (type instanceof ZodBranded) {
|
|
2555
|
+
return getDiscriminator(type.unwrap());
|
|
2556
|
+
} else if (type instanceof ZodReadonly) {
|
|
2557
|
+
return getDiscriminator(type.unwrap());
|
|
2558
|
+
} else if (type instanceof ZodCatch) {
|
|
2559
|
+
return getDiscriminator(type._def.innerType);
|
|
2106
2560
|
} else {
|
|
2107
|
-
return
|
|
2561
|
+
return [];
|
|
2108
2562
|
}
|
|
2109
2563
|
}, "getDiscriminator");
|
|
2110
2564
|
var ZodDiscriminatedUnion = class extends ZodType {
|
|
@@ -2156,7 +2610,7 @@ var ZodDiscriminatedUnion = class extends ZodType {
|
|
|
2156
2610
|
const optionsMap = /* @__PURE__ */ new Map();
|
|
2157
2611
|
for (const type of options) {
|
|
2158
2612
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2159
|
-
if (!discriminatorValues) {
|
|
2613
|
+
if (!discriminatorValues.length) {
|
|
2160
2614
|
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2161
2615
|
}
|
|
2162
2616
|
for (const value of discriminatorValues) {
|
|
@@ -2301,7 +2755,7 @@ var ZodTuple = class extends ZodType {
|
|
|
2301
2755
|
});
|
|
2302
2756
|
status.dirty();
|
|
2303
2757
|
}
|
|
2304
|
-
const items = ctx.data.map((item, itemIndex) => {
|
|
2758
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
2305
2759
|
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2306
2760
|
if (!schema)
|
|
2307
2761
|
return null;
|
|
@@ -2360,7 +2814,8 @@ var ZodRecord = class extends ZodType {
|
|
|
2360
2814
|
for (const key in ctx.data) {
|
|
2361
2815
|
pairs.push({
|
|
2362
2816
|
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2363
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
|
2817
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2818
|
+
alwaysSet: key in ctx.data
|
|
2364
2819
|
});
|
|
2365
2820
|
}
|
|
2366
2821
|
if (ctx.common.async) {
|
|
@@ -2391,6 +2846,12 @@ var ZodRecord = class extends ZodType {
|
|
|
2391
2846
|
};
|
|
2392
2847
|
__name(ZodRecord, "ZodRecord");
|
|
2393
2848
|
var ZodMap = class extends ZodType {
|
|
2849
|
+
get keySchema() {
|
|
2850
|
+
return this._def.keyType;
|
|
2851
|
+
}
|
|
2852
|
+
get valueSchema() {
|
|
2853
|
+
return this._def.valueType;
|
|
2854
|
+
}
|
|
2394
2855
|
_parse(input) {
|
|
2395
2856
|
const { status, ctx } = this._processInputParams(input);
|
|
2396
2857
|
if (ctx.parsedType !== ZodParsedType.map) {
|
|
@@ -2590,27 +3051,29 @@ var ZodFunction = class extends ZodType {
|
|
|
2590
3051
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
2591
3052
|
const fn = ctx.data;
|
|
2592
3053
|
if (this._def.returns instanceof ZodPromise) {
|
|
2593
|
-
|
|
3054
|
+
const me = this;
|
|
3055
|
+
return OK(async function(...args) {
|
|
2594
3056
|
const error = new ZodError([]);
|
|
2595
|
-
const parsedArgs = await
|
|
3057
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
2596
3058
|
error.addIssue(makeArgsIssue(args, e));
|
|
2597
3059
|
throw error;
|
|
2598
3060
|
});
|
|
2599
|
-
const result = await fn
|
|
2600
|
-
const parsedReturns = await
|
|
3061
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3062
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
2601
3063
|
error.addIssue(makeReturnsIssue(result, e));
|
|
2602
3064
|
throw error;
|
|
2603
3065
|
});
|
|
2604
3066
|
return parsedReturns;
|
|
2605
3067
|
});
|
|
2606
3068
|
} else {
|
|
2607
|
-
|
|
2608
|
-
|
|
3069
|
+
const me = this;
|
|
3070
|
+
return OK(function(...args) {
|
|
3071
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
2609
3072
|
if (!parsedArgs.success) {
|
|
2610
3073
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2611
3074
|
}
|
|
2612
|
-
const result = fn
|
|
2613
|
-
const parsedReturns =
|
|
3075
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3076
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
2614
3077
|
if (!parsedReturns.success) {
|
|
2615
3078
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2616
3079
|
}
|
|
@@ -2677,6 +3140,7 @@ var ZodLiteral = class extends ZodType {
|
|
|
2677
3140
|
if (input.data !== this._def.value) {
|
|
2678
3141
|
const ctx = this._getOrReturnCtx(input);
|
|
2679
3142
|
addIssueToContext(ctx, {
|
|
3143
|
+
received: ctx.data,
|
|
2680
3144
|
code: ZodIssueCode.invalid_literal,
|
|
2681
3145
|
expected: this._def.value
|
|
2682
3146
|
});
|
|
@@ -2705,6 +3169,10 @@ function createZodEnum(values, params) {
|
|
|
2705
3169
|
}
|
|
2706
3170
|
__name(createZodEnum, "createZodEnum");
|
|
2707
3171
|
var ZodEnum = class extends ZodType {
|
|
3172
|
+
constructor() {
|
|
3173
|
+
super(...arguments);
|
|
3174
|
+
_ZodEnum_cache.set(this, void 0);
|
|
3175
|
+
}
|
|
2708
3176
|
_parse(input) {
|
|
2709
3177
|
if (typeof input.data !== "string") {
|
|
2710
3178
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -2716,7 +3184,10 @@ var ZodEnum = class extends ZodType {
|
|
|
2716
3184
|
});
|
|
2717
3185
|
return INVALID;
|
|
2718
3186
|
}
|
|
2719
|
-
if (this
|
|
3187
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
|
3188
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
|
3189
|
+
}
|
|
3190
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
|
2720
3191
|
const ctx = this._getOrReturnCtx(input);
|
|
2721
3192
|
const expectedValues = this._def.values;
|
|
2722
3193
|
addIssueToContext(ctx, {
|
|
@@ -2752,10 +3223,27 @@ var ZodEnum = class extends ZodType {
|
|
|
2752
3223
|
}
|
|
2753
3224
|
return enumValues;
|
|
2754
3225
|
}
|
|
3226
|
+
extract(values, newDef = this._def) {
|
|
3227
|
+
return ZodEnum.create(values, {
|
|
3228
|
+
...this._def,
|
|
3229
|
+
...newDef
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3232
|
+
exclude(values, newDef = this._def) {
|
|
3233
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3234
|
+
...this._def,
|
|
3235
|
+
...newDef
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
2755
3238
|
};
|
|
2756
3239
|
__name(ZodEnum, "ZodEnum");
|
|
3240
|
+
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
|
2757
3241
|
ZodEnum.create = createZodEnum;
|
|
2758
3242
|
var ZodNativeEnum = class extends ZodType {
|
|
3243
|
+
constructor() {
|
|
3244
|
+
super(...arguments);
|
|
3245
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
|
3246
|
+
}
|
|
2759
3247
|
_parse(input) {
|
|
2760
3248
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
2761
3249
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -2768,7 +3256,10 @@ var ZodNativeEnum = class extends ZodType {
|
|
|
2768
3256
|
});
|
|
2769
3257
|
return INVALID;
|
|
2770
3258
|
}
|
|
2771
|
-
if (
|
|
3259
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
|
3260
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
|
3261
|
+
}
|
|
3262
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
|
2772
3263
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
2773
3264
|
addIssueToContext(ctx, {
|
|
2774
3265
|
received: ctx.data,
|
|
@@ -2784,6 +3275,7 @@ var ZodNativeEnum = class extends ZodType {
|
|
|
2784
3275
|
}
|
|
2785
3276
|
};
|
|
2786
3277
|
__name(ZodNativeEnum, "ZodNativeEnum");
|
|
3278
|
+
_ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
|
|
2787
3279
|
ZodNativeEnum.create = (values, params) => {
|
|
2788
3280
|
return new ZodNativeEnum({
|
|
2789
3281
|
values,
|
|
@@ -2792,6 +3284,9 @@ ZodNativeEnum.create = (values, params) => {
|
|
|
2792
3284
|
});
|
|
2793
3285
|
};
|
|
2794
3286
|
var ZodPromise = class extends ZodType {
|
|
3287
|
+
unwrap() {
|
|
3288
|
+
return this._def.type;
|
|
3289
|
+
}
|
|
2795
3290
|
_parse(input) {
|
|
2796
3291
|
const { ctx } = this._processInputParams(input);
|
|
2797
3292
|
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
@@ -2829,24 +3324,6 @@ var ZodEffects = class extends ZodType {
|
|
|
2829
3324
|
_parse(input) {
|
|
2830
3325
|
const { status, ctx } = this._processInputParams(input);
|
|
2831
3326
|
const effect = this._def.effect || null;
|
|
2832
|
-
if (effect.type === "preprocess") {
|
|
2833
|
-
const processed = effect.transform(ctx.data);
|
|
2834
|
-
if (ctx.common.async) {
|
|
2835
|
-
return Promise.resolve(processed).then((processed2) => {
|
|
2836
|
-
return this._def.schema._parseAsync({
|
|
2837
|
-
data: processed2,
|
|
2838
|
-
path: ctx.path,
|
|
2839
|
-
parent: ctx
|
|
2840
|
-
});
|
|
2841
|
-
});
|
|
2842
|
-
} else {
|
|
2843
|
-
return this._def.schema._parseSync({
|
|
2844
|
-
data: processed,
|
|
2845
|
-
path: ctx.path,
|
|
2846
|
-
parent: ctx
|
|
2847
|
-
});
|
|
2848
|
-
}
|
|
2849
|
-
}
|
|
2850
3327
|
const checkCtx = {
|
|
2851
3328
|
addIssue: (arg) => {
|
|
2852
3329
|
addIssueToContext(ctx, arg);
|
|
@@ -2861,6 +3338,42 @@ var ZodEffects = class extends ZodType {
|
|
|
2861
3338
|
}
|
|
2862
3339
|
};
|
|
2863
3340
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3341
|
+
if (effect.type === "preprocess") {
|
|
3342
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3343
|
+
if (ctx.common.async) {
|
|
3344
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3345
|
+
if (status.value === "aborted")
|
|
3346
|
+
return INVALID;
|
|
3347
|
+
const result = await this._def.schema._parseAsync({
|
|
3348
|
+
data: processed2,
|
|
3349
|
+
path: ctx.path,
|
|
3350
|
+
parent: ctx
|
|
3351
|
+
});
|
|
3352
|
+
if (result.status === "aborted")
|
|
3353
|
+
return INVALID;
|
|
3354
|
+
if (result.status === "dirty")
|
|
3355
|
+
return DIRTY(result.value);
|
|
3356
|
+
if (status.value === "dirty")
|
|
3357
|
+
return DIRTY(result.value);
|
|
3358
|
+
return result;
|
|
3359
|
+
});
|
|
3360
|
+
} else {
|
|
3361
|
+
if (status.value === "aborted")
|
|
3362
|
+
return INVALID;
|
|
3363
|
+
const result = this._def.schema._parseSync({
|
|
3364
|
+
data: processed,
|
|
3365
|
+
path: ctx.path,
|
|
3366
|
+
parent: ctx
|
|
3367
|
+
});
|
|
3368
|
+
if (result.status === "aborted")
|
|
3369
|
+
return INVALID;
|
|
3370
|
+
if (result.status === "dirty")
|
|
3371
|
+
return DIRTY(result.value);
|
|
3372
|
+
if (status.value === "dirty")
|
|
3373
|
+
return DIRTY(result.value);
|
|
3374
|
+
return result;
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
2864
3377
|
if (effect.type === "refinement") {
|
|
2865
3378
|
const executeRefinement = /* @__PURE__ */ __name((acc) => {
|
|
2866
3379
|
const result = effect.refinement(acc, checkCtx);
|
|
@@ -3007,26 +3520,45 @@ ZodDefault.create = (type, params) => {
|
|
|
3007
3520
|
var ZodCatch = class extends ZodType {
|
|
3008
3521
|
_parse(input) {
|
|
3009
3522
|
const { ctx } = this._processInputParams(input);
|
|
3523
|
+
const newCtx = {
|
|
3524
|
+
...ctx,
|
|
3525
|
+
common: {
|
|
3526
|
+
...ctx.common,
|
|
3527
|
+
issues: []
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3010
3530
|
const result = this._def.innerType._parse({
|
|
3011
|
-
data:
|
|
3012
|
-
path:
|
|
3013
|
-
parent:
|
|
3531
|
+
data: newCtx.data,
|
|
3532
|
+
path: newCtx.path,
|
|
3533
|
+
parent: {
|
|
3534
|
+
...newCtx
|
|
3535
|
+
}
|
|
3014
3536
|
});
|
|
3015
3537
|
if (isAsync(result)) {
|
|
3016
3538
|
return result.then((result2) => {
|
|
3017
3539
|
return {
|
|
3018
3540
|
status: "valid",
|
|
3019
|
-
value: result2.status === "valid" ? result2.value : this._def.
|
|
3541
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
3542
|
+
get error() {
|
|
3543
|
+
return new ZodError(newCtx.common.issues);
|
|
3544
|
+
},
|
|
3545
|
+
input: newCtx.data
|
|
3546
|
+
})
|
|
3020
3547
|
};
|
|
3021
3548
|
});
|
|
3022
3549
|
} else {
|
|
3023
3550
|
return {
|
|
3024
3551
|
status: "valid",
|
|
3025
|
-
value: result.status === "valid" ? result.value : this._def.
|
|
3552
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3553
|
+
get error() {
|
|
3554
|
+
return new ZodError(newCtx.common.issues);
|
|
3555
|
+
},
|
|
3556
|
+
input: newCtx.data
|
|
3557
|
+
})
|
|
3026
3558
|
};
|
|
3027
3559
|
}
|
|
3028
3560
|
}
|
|
3029
|
-
|
|
3561
|
+
removeCatch() {
|
|
3030
3562
|
return this._def.innerType;
|
|
3031
3563
|
}
|
|
3032
3564
|
};
|
|
@@ -3035,7 +3567,7 @@ ZodCatch.create = (type, params) => {
|
|
|
3035
3567
|
return new ZodCatch({
|
|
3036
3568
|
innerType: type,
|
|
3037
3569
|
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3038
|
-
|
|
3570
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3039
3571
|
...processCreateParams(params)
|
|
3040
3572
|
});
|
|
3041
3573
|
};
|
|
@@ -3133,17 +3665,43 @@ var ZodPipeline = class extends ZodType {
|
|
|
3133
3665
|
}
|
|
3134
3666
|
};
|
|
3135
3667
|
__name(ZodPipeline, "ZodPipeline");
|
|
3136
|
-
var
|
|
3668
|
+
var ZodReadonly = class extends ZodType {
|
|
3669
|
+
_parse(input) {
|
|
3670
|
+
const result = this._def.innerType._parse(input);
|
|
3671
|
+
const freeze = /* @__PURE__ */ __name((data) => {
|
|
3672
|
+
if (isValid(data)) {
|
|
3673
|
+
data.value = Object.freeze(data.value);
|
|
3674
|
+
}
|
|
3675
|
+
return data;
|
|
3676
|
+
}, "freeze");
|
|
3677
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3678
|
+
}
|
|
3679
|
+
unwrap() {
|
|
3680
|
+
return this._def.innerType;
|
|
3681
|
+
}
|
|
3682
|
+
};
|
|
3683
|
+
__name(ZodReadonly, "ZodReadonly");
|
|
3684
|
+
ZodReadonly.create = (type, params) => {
|
|
3685
|
+
return new ZodReadonly({
|
|
3686
|
+
innerType: type,
|
|
3687
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3688
|
+
...processCreateParams(params)
|
|
3689
|
+
});
|
|
3690
|
+
};
|
|
3691
|
+
function custom(check, params = {}, fatal) {
|
|
3137
3692
|
if (check)
|
|
3138
3693
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
3694
|
+
var _a, _b;
|
|
3139
3695
|
if (!check(data)) {
|
|
3140
|
-
const p = typeof params === "function" ? params(data) : params;
|
|
3696
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
3697
|
+
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3141
3698
|
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3142
|
-
ctx.addIssue({ code: "custom", ...p2, fatal });
|
|
3699
|
+
ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
|
|
3143
3700
|
}
|
|
3144
3701
|
});
|
|
3145
3702
|
return ZodAny.create();
|
|
3146
|
-
}
|
|
3703
|
+
}
|
|
3704
|
+
__name(custom, "custom");
|
|
3147
3705
|
var late = {
|
|
3148
3706
|
object: ZodObject.lazycreate
|
|
3149
3707
|
};
|
|
@@ -3184,10 +3742,11 @@ var ZodFirstPartyTypeKind;
|
|
|
3184
3742
|
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
3185
3743
|
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
3186
3744
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
3745
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
3187
3746
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3188
3747
|
var instanceOfType = /* @__PURE__ */ __name((cls, params = {
|
|
3189
3748
|
message: `Input not instance of ${cls.name}`
|
|
3190
|
-
}) => custom((data) => data instanceof cls, params
|
|
3749
|
+
}) => custom((data) => data instanceof cls, params), "instanceOfType");
|
|
3191
3750
|
var stringType = ZodString.create;
|
|
3192
3751
|
var numberType = ZodNumber.create;
|
|
3193
3752
|
var nanType = ZodNaN.create;
|
|
@@ -3228,12 +3787,15 @@ var oboolean = /* @__PURE__ */ __name(() => booleanType().optional(), "oboolean"
|
|
|
3228
3787
|
var coerce = {
|
|
3229
3788
|
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
3230
3789
|
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
3231
|
-
boolean: (arg) => ZodBoolean.create({
|
|
3790
|
+
boolean: (arg) => ZodBoolean.create({
|
|
3791
|
+
...arg,
|
|
3792
|
+
coerce: true
|
|
3793
|
+
}),
|
|
3232
3794
|
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
3233
3795
|
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
3234
3796
|
};
|
|
3235
3797
|
var NEVER = INVALID;
|
|
3236
|
-
var
|
|
3798
|
+
var z = /* @__PURE__ */ Object.freeze({
|
|
3237
3799
|
__proto__: null,
|
|
3238
3800
|
defaultErrorMap: errorMap,
|
|
3239
3801
|
setErrorMap,
|
|
@@ -3252,9 +3814,13 @@ var mod = /* @__PURE__ */ Object.freeze({
|
|
|
3252
3814
|
get util() {
|
|
3253
3815
|
return util;
|
|
3254
3816
|
},
|
|
3817
|
+
get objectUtil() {
|
|
3818
|
+
return objectUtil;
|
|
3819
|
+
},
|
|
3255
3820
|
ZodParsedType,
|
|
3256
3821
|
getParsedType,
|
|
3257
3822
|
ZodType,
|
|
3823
|
+
datetimeRegex,
|
|
3258
3824
|
ZodString,
|
|
3259
3825
|
ZodNumber,
|
|
3260
3826
|
ZodBigInt,
|
|
@@ -3268,9 +3834,6 @@ var mod = /* @__PURE__ */ Object.freeze({
|
|
|
3268
3834
|
ZodNever,
|
|
3269
3835
|
ZodVoid,
|
|
3270
3836
|
ZodArray,
|
|
3271
|
-
get objectUtil() {
|
|
3272
|
-
return objectUtil;
|
|
3273
|
-
},
|
|
3274
3837
|
ZodObject,
|
|
3275
3838
|
ZodUnion,
|
|
3276
3839
|
ZodDiscriminatedUnion,
|
|
@@ -3295,6 +3858,7 @@ var mod = /* @__PURE__ */ Object.freeze({
|
|
|
3295
3858
|
BRAND,
|
|
3296
3859
|
ZodBranded,
|
|
3297
3860
|
ZodPipeline,
|
|
3861
|
+
ZodReadonly,
|
|
3298
3862
|
custom,
|
|
3299
3863
|
Schema: ZodType,
|
|
3300
3864
|
ZodSchema: ZodType,
|
|
@@ -3349,12 +3913,12 @@ var mod = /* @__PURE__ */ Object.freeze({
|
|
|
3349
3913
|
});
|
|
3350
3914
|
|
|
3351
3915
|
// src/types.ts
|
|
3352
|
-
var SigningAuthorityValidator =
|
|
3353
|
-
_id:
|
|
3354
|
-
ownerDid:
|
|
3355
|
-
name:
|
|
3356
|
-
did:
|
|
3357
|
-
endpoint:
|
|
3916
|
+
var SigningAuthorityValidator = z.object({
|
|
3917
|
+
_id: z.string().optional(),
|
|
3918
|
+
ownerDid: z.string(),
|
|
3919
|
+
name: z.string(),
|
|
3920
|
+
did: z.string().optional(),
|
|
3921
|
+
endpoint: z.string().optional()
|
|
3358
3922
|
});
|
|
3359
3923
|
|
|
3360
3924
|
// ../../../node_modules/.pnpm/@trpc+server@10.45.2/node_modules/@trpc/server/dist/observable-ade1bad8.mjs
|