@learncard/react 2.4.0 → 2.5.1
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/base.css +1 -1
- package/dist/base.js +1 -1
- package/dist/cjs/BoostSmallCard-c5b7cb24.js +110 -0
- package/dist/cjs/BoostSmallCard-c5b7cb24.js.map +1 -0
- package/dist/cjs/CaretRightFilled.svg +3 -0
- package/dist/cjs/{FlippyCard-2cbe2dbe.js → FlippyCard-209549c5.js} +2 -2
- package/dist/cjs/FlippyCard-209549c5.js.map +1 -0
- package/dist/cjs/{GenericCard-346b55ab.js → GenericCard-c3a42a6c.js} +2 -2
- package/dist/cjs/GenericCard-c3a42a6c.js.map +1 -0
- package/dist/cjs/{Notification-10b40c07.js → Notification-28ace54f.js} +50 -16
- package/dist/cjs/Notification-28ace54f.js.map +1 -0
- package/dist/cjs/SchoolIDCard-1baf77e8.js.map +1 -1
- package/dist/cjs/{VCCard-32c759a8.js → VCCard-8515516c.js} +3 -3
- package/dist/cjs/{VCCard-32c759a8.js.map → VCCard-8515516c.js.map} +1 -1
- package/dist/cjs/{VCDisplayBackFace-128b5cb2.js → VCDisplayBackFace-8c10fe7d.js} +3 -3
- package/dist/cjs/{VCDisplayBackFace-128b5cb2.js.map → VCDisplayBackFace-8c10fe7d.js.map} +1 -1
- package/dist/cjs/{VCDisplayCard-77133b71.js → VCDisplayCard-2356076d.js} +5 -5
- package/dist/cjs/VCDisplayCard-2356076d.js.map +1 -0
- package/dist/cjs/{VCDisplayCard2-a0a66aa6.js → VCDisplayCard2-721684cf.js} +55 -18
- package/dist/cjs/VCDisplayCard2-721684cf.js.map +1 -0
- package/dist/cjs/{VCVerificationPill-66e2a90f.js → VCVerificationPill-3ef39509.js} +2 -2
- package/dist/cjs/{VCVerificationPill-66e2a90f.js.map → VCVerificationPill-3ef39509.js.map} +1 -1
- package/dist/cjs/addawardlight.svg +8 -0
- package/dist/cjs/badge.png +0 -0
- package/dist/cjs/{constants-82581ffe.js → constants-00935dd2.js} +9 -4
- package/dist/cjs/constants-00935dd2.js.map +1 -0
- package/dist/cjs/{credential.helpers-7f7b9b02.js → credential.helpers-80101c51.js} +2 -2
- package/dist/cjs/{credential.helpers-7f7b9b02.js.map → credential.helpers-80101c51.js.map} +1 -1
- package/dist/cjs/index-6b34c190.js.map +1 -1
- package/dist/cjs/index.js +17 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index10.js +4 -108
- package/dist/cjs/index10.js.map +1 -1
- package/dist/cjs/index11.js +134 -1
- package/dist/cjs/index11.js.map +1 -1
- package/dist/cjs/index12.js +3 -15
- package/dist/cjs/index12.js.map +1 -1
- package/dist/cjs/index13.js +15 -3
- package/dist/cjs/index13.js.map +1 -1
- package/dist/cjs/index14.js +3 -5
- package/dist/cjs/index14.js.map +1 -1
- package/dist/cjs/index15.js +5 -14
- package/dist/cjs/index15.js.map +1 -1
- package/dist/cjs/index16.js +14 -2
- package/dist/cjs/index16.js.map +1 -1
- package/dist/cjs/index17.js +2 -3
- package/dist/cjs/index17.js.map +1 -1
- package/dist/cjs/index18.js +3 -5
- package/dist/cjs/index18.js.map +1 -1
- package/dist/cjs/index19.js +6 -3
- package/dist/cjs/index19.js.map +1 -1
- package/dist/cjs/index20.js +3 -15
- package/dist/cjs/index20.js.map +1 -1
- package/dist/cjs/index21.js +4 -19
- package/dist/cjs/index21.js.map +1 -1
- package/dist/cjs/index22.js +31 -2
- package/dist/cjs/index22.js.map +1 -1
- package/dist/cjs/index23.js +2 -3
- package/dist/cjs/index23.js.map +1 -1
- package/dist/cjs/index24.js +3 -3
- package/dist/cjs/index25.js +3 -16
- package/dist/cjs/index25.js.map +1 -1
- package/dist/cjs/index26.js +16 -3
- package/dist/cjs/index26.js.map +1 -1
- package/dist/cjs/index27.js +3 -3
- package/dist/cjs/index28.js +3 -13
- package/dist/cjs/index28.js.map +1 -1
- package/dist/cjs/index29.js +13 -21
- package/dist/cjs/index29.js.map +1 -1
- package/dist/cjs/index3.js +30 -2
- package/dist/cjs/index3.js.map +1 -1
- package/dist/cjs/index30.js +14 -6
- package/dist/cjs/index30.js.map +1 -1
- package/dist/cjs/index31.js +6 -10
- package/dist/cjs/index31.js.map +1 -1
- package/dist/cjs/index32.js +13 -6
- package/dist/cjs/index32.js.map +1 -1
- package/dist/cjs/index33.js +12 -3
- package/dist/cjs/index33.js.map +1 -1
- package/dist/cjs/index34.js +4 -7
- package/dist/cjs/index34.js.map +1 -1
- package/dist/cjs/index35.js +4 -6
- package/dist/cjs/index35.js.map +1 -1
- package/dist/cjs/index36.js +6 -6
- package/dist/cjs/index37.js +15 -0
- package/dist/cjs/index37.js.map +1 -0
- package/dist/cjs/index4.js +2 -15
- package/dist/cjs/index4.js.map +1 -1
- package/dist/cjs/index5.js +4 -4
- package/dist/cjs/index6.js +14 -5
- package/dist/cjs/index6.js.map +1 -1
- package/dist/cjs/index7.js +2 -14
- package/dist/cjs/index7.js.map +1 -1
- package/dist/cjs/index8.js +18 -2
- package/dist/cjs/index8.js.map +1 -1
- package/dist/cjs/index9.js +2 -27
- package/dist/cjs/index9.js.map +1 -1
- package/dist/cjs/{types.esm-034454a2.js → types.esm-fa693b17.js} +695 -107
- package/dist/cjs/types.esm-fa693b17.js.map +1 -0
- package/dist/esm/BoostSmallCard-0f4fec3b.js +101 -0
- package/dist/esm/BoostSmallCard-0f4fec3b.js.map +1 -0
- package/dist/esm/CaretRightFilled.svg +3 -0
- package/dist/esm/{FlippyCard-f4f0b3f8.js → FlippyCard-a2de5cf1.js} +2 -2
- package/dist/esm/FlippyCard-a2de5cf1.js.map +1 -0
- package/dist/esm/{GenericCard-446f46e0.js → GenericCard-c2d91e3c.js} +3 -3
- package/dist/esm/GenericCard-c2d91e3c.js.map +1 -0
- package/dist/esm/{Notification-ac50790d.js → Notification-60c43061.js} +51 -17
- package/dist/esm/Notification-60c43061.js.map +1 -0
- package/dist/esm/SchoolIDCard-3b746226.js.map +1 -1
- package/dist/esm/{VCCard-c4096573.js → VCCard-c71cfd7f.js} +3 -3
- package/dist/esm/{VCCard-c4096573.js.map → VCCard-c71cfd7f.js.map} +1 -1
- package/dist/esm/{VCDisplayBackFace-853b8fdf.js → VCDisplayBackFace-2949e56d.js} +3 -3
- package/dist/esm/{VCDisplayBackFace-853b8fdf.js.map → VCDisplayBackFace-2949e56d.js.map} +1 -1
- package/dist/esm/{VCDisplayCard-be496708.js → VCDisplayCard-c23f431e.js} +5 -5
- package/dist/esm/VCDisplayCard-c23f431e.js.map +1 -0
- package/dist/esm/{VCDisplayCard2-c8e96ce8.js → VCDisplayCard2-33a1dc1d.js} +55 -18
- package/dist/esm/VCDisplayCard2-33a1dc1d.js.map +1 -0
- package/dist/esm/{VCVerificationPill-fc7b53d0.js → VCVerificationPill-8e2a3850.js} +2 -2
- package/dist/esm/{VCVerificationPill-fc7b53d0.js.map → VCVerificationPill-8e2a3850.js.map} +1 -1
- package/dist/esm/addawardlight.svg +8 -0
- package/dist/esm/badge.png +0 -0
- package/dist/esm/{constants-c0a08298.js → constants-6bb0dc94.js} +8 -4
- package/dist/esm/constants-6bb0dc94.js.map +1 -0
- package/dist/esm/{credential.helpers-78d3c24a.js → credential.helpers-5929133d.js} +2 -2
- package/dist/esm/{credential.helpers-78d3c24a.js.map → credential.helpers-5929133d.js.map} +1 -1
- package/dist/esm/index-52cf2d17.js.map +1 -1
- package/dist/esm/index.js +16 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +4 -57
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +82 -1
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +2 -13
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +13 -2
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +2 -4
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +4 -13
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +13 -1
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +1 -2
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +2 -3
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +4 -2
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +2 -13
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +2 -14
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +26 -1
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +1 -1
- package/dist/esm/index24.js +1 -2
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +2 -15
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +15 -2
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +2 -2
- package/dist/esm/index28.js +2 -4
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +4 -20
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index3.js +29 -1
- package/dist/esm/index3.js.map +1 -1
- package/dist/esm/index30.js +13 -5
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +5 -9
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +12 -5
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +7 -3
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +4 -2
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +3 -3
- package/dist/esm/index36.js +3 -5
- package/dist/esm/index36.js.map +1 -1
- package/dist/esm/index37.js +7 -0
- package/dist/esm/index37.js.map +1 -0
- package/dist/esm/index4.js +1 -14
- package/dist/esm/index4.js.map +1 -1
- package/dist/esm/index5.js +3 -2
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +12 -4
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +1 -13
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +17 -1
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +1 -26
- package/dist/esm/index9.js.map +1 -1
- package/dist/esm/{types.esm-9db3d858.js → types.esm-877355bb.js} +695 -107
- package/dist/esm/types.esm-877355bb.js.map +1 -0
- package/dist/index.d.ts +153 -171
- package/dist/main.css +1 -1
- package/dist/main.js +1 -1
- package/package.json +6 -6
- package/dist/cjs/FlippyCard-2cbe2dbe.js.map +0 -1
- package/dist/cjs/GenericCard-346b55ab.js.map +0 -1
- package/dist/cjs/Notification-10b40c07.js.map +0 -1
- package/dist/cjs/VCDisplayCard-77133b71.js.map +0 -1
- package/dist/cjs/VCDisplayCard2-a0a66aa6.js.map +0 -1
- package/dist/cjs/constants-82581ffe.js.map +0 -1
- package/dist/cjs/types.esm-034454a2.js.map +0 -1
- package/dist/esm/FlippyCard-f4f0b3f8.js.map +0 -1
- package/dist/esm/GenericCard-446f46e0.js.map +0 -1
- package/dist/esm/Notification-ac50790d.js.map +0 -1
- package/dist/esm/VCDisplayCard-be496708.js.map +0 -1
- package/dist/esm/VCDisplayCard2-c8e96ce8.js.map +0 -1
- package/dist/esm/constants-c0a08298.js.map +0 -1
- package/dist/esm/types.esm-9db3d858.js.map +0 -1
|
@@ -100,6 +100,8 @@ const getParsedType = (data) => {
|
|
|
100
100
|
return ZodParsedType.function;
|
|
101
101
|
case "bigint":
|
|
102
102
|
return ZodParsedType.bigint;
|
|
103
|
+
case "symbol":
|
|
104
|
+
return ZodParsedType.symbol;
|
|
103
105
|
case "object":
|
|
104
106
|
if (Array.isArray(data)) {
|
|
105
107
|
return ZodParsedType.array;
|
|
@@ -144,6 +146,7 @@ const ZodIssueCode = util.arrayToEnum([
|
|
|
144
146
|
"too_big",
|
|
145
147
|
"invalid_intersection_types",
|
|
146
148
|
"not_multiple_of",
|
|
149
|
+
"not_finite",
|
|
147
150
|
]);
|
|
148
151
|
const quotelessJson = (obj) => {
|
|
149
152
|
const json = JSON.stringify(obj, null, 2);
|
|
@@ -310,25 +313,41 @@ const errorMap = (issue, _ctx) => {
|
|
|
310
313
|
break;
|
|
311
314
|
case ZodIssueCode.too_small:
|
|
312
315
|
if (issue.type === "array")
|
|
313
|
-
message = `Array must contain ${issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
316
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
314
317
|
else if (issue.type === "string")
|
|
315
|
-
message = `String must contain ${issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
318
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
316
319
|
else if (issue.type === "number")
|
|
317
|
-
message = `Number must be
|
|
320
|
+
message = `Number must be ${issue.exact
|
|
321
|
+
? `exactly equal to `
|
|
322
|
+
: issue.inclusive
|
|
323
|
+
? `greater than or equal to `
|
|
324
|
+
: `greater than `}${issue.minimum}`;
|
|
318
325
|
else if (issue.type === "date")
|
|
319
|
-
message = `Date must be
|
|
326
|
+
message = `Date must be ${issue.exact
|
|
327
|
+
? `exactly equal to `
|
|
328
|
+
: issue.inclusive
|
|
329
|
+
? `greater than or equal to `
|
|
330
|
+
: `greater than `}${new Date(issue.minimum)}`;
|
|
320
331
|
else
|
|
321
332
|
message = "Invalid input";
|
|
322
333
|
break;
|
|
323
334
|
case ZodIssueCode.too_big:
|
|
324
335
|
if (issue.type === "array")
|
|
325
|
-
message = `Array must contain ${issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
336
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
326
337
|
else if (issue.type === "string")
|
|
327
|
-
message = `String must contain ${issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
338
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
328
339
|
else if (issue.type === "number")
|
|
329
|
-
message = `Number must be
|
|
340
|
+
message = `Number must be ${issue.exact
|
|
341
|
+
? `exactly`
|
|
342
|
+
: issue.inclusive
|
|
343
|
+
? `less than or equal to`
|
|
344
|
+
: `less than`} ${issue.maximum}`;
|
|
330
345
|
else if (issue.type === "date")
|
|
331
|
-
message = `Date must be
|
|
346
|
+
message = `Date must be ${issue.exact
|
|
347
|
+
? `exactly`
|
|
348
|
+
: issue.inclusive
|
|
349
|
+
? `smaller than or equal to`
|
|
350
|
+
: `smaller than`} ${new Date(issue.maximum)}`;
|
|
332
351
|
else
|
|
333
352
|
message = "Invalid input";
|
|
334
353
|
break;
|
|
@@ -341,6 +360,9 @@ const errorMap = (issue, _ctx) => {
|
|
|
341
360
|
case ZodIssueCode.not_multiple_of:
|
|
342
361
|
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
343
362
|
break;
|
|
363
|
+
case ZodIssueCode.not_finite:
|
|
364
|
+
message = "Number must be finite";
|
|
365
|
+
break;
|
|
344
366
|
default:
|
|
345
367
|
message = _ctx.defaultError;
|
|
346
368
|
util.assertNever(issue);
|
|
@@ -387,7 +409,7 @@ function addIssueToContext(ctx, issueData) {
|
|
|
387
409
|
ctx.common.contextualErrorMap,
|
|
388
410
|
ctx.schemaErrorMap,
|
|
389
411
|
getErrorMap(),
|
|
390
|
-
errorMap,
|
|
412
|
+
errorMap, // then global default map
|
|
391
413
|
].filter((x) => !!x),
|
|
392
414
|
});
|
|
393
415
|
ctx.common.issues.push(issue);
|
|
@@ -452,7 +474,7 @@ const OK = (value) => ({ status: "valid", value });
|
|
|
452
474
|
const isAborted = (x) => x.status === "aborted";
|
|
453
475
|
const isDirty = (x) => x.status === "dirty";
|
|
454
476
|
const isValid = (x) => x.status === "valid";
|
|
455
|
-
const isAsync = (x) => typeof Promise !== undefined && x instanceof Promise;
|
|
477
|
+
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
456
478
|
|
|
457
479
|
var errorUtil;
|
|
458
480
|
(function (errorUtil) {
|
|
@@ -506,7 +528,6 @@ class ZodType {
|
|
|
506
528
|
constructor(def) {
|
|
507
529
|
/** Alias of safeParseAsync */
|
|
508
530
|
this.spa = this.safeParseAsync;
|
|
509
|
-
this.superRefine = this._refinement;
|
|
510
531
|
this._def = def;
|
|
511
532
|
this.parse = this.parse.bind(this);
|
|
512
533
|
this.safeParse = this.safeParse.bind(this);
|
|
@@ -524,8 +545,11 @@ class ZodType {
|
|
|
524
545
|
this.or = this.or.bind(this);
|
|
525
546
|
this.and = this.and.bind(this);
|
|
526
547
|
this.transform = this.transform.bind(this);
|
|
548
|
+
this.brand = this.brand.bind(this);
|
|
527
549
|
this.default = this.default.bind(this);
|
|
550
|
+
this.catch = this.catch.bind(this);
|
|
528
551
|
this.describe = this.describe.bind(this);
|
|
552
|
+
this.pipe = this.pipe.bind(this);
|
|
529
553
|
this.isNullable = this.isNullable.bind(this);
|
|
530
554
|
this.isOptional = this.isOptional.bind(this);
|
|
531
555
|
}
|
|
@@ -611,7 +635,7 @@ class ZodType {
|
|
|
611
635
|
data,
|
|
612
636
|
parsedType: getParsedType(data),
|
|
613
637
|
};
|
|
614
|
-
const maybeAsyncResult = this._parse({ data, path:
|
|
638
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
615
639
|
const result = await (isAsync(maybeAsyncResult)
|
|
616
640
|
? maybeAsyncResult
|
|
617
641
|
: Promise.resolve(maybeAsyncResult));
|
|
@@ -675,29 +699,33 @@ class ZodType {
|
|
|
675
699
|
effect: { type: "refinement", refinement },
|
|
676
700
|
});
|
|
677
701
|
}
|
|
702
|
+
superRefine(refinement) {
|
|
703
|
+
return this._refinement(refinement);
|
|
704
|
+
}
|
|
678
705
|
optional() {
|
|
679
|
-
return ZodOptional.create(this);
|
|
706
|
+
return ZodOptional.create(this, this._def);
|
|
680
707
|
}
|
|
681
708
|
nullable() {
|
|
682
|
-
return ZodNullable.create(this);
|
|
709
|
+
return ZodNullable.create(this, this._def);
|
|
683
710
|
}
|
|
684
711
|
nullish() {
|
|
685
|
-
return this.
|
|
712
|
+
return this.nullable().optional();
|
|
686
713
|
}
|
|
687
714
|
array() {
|
|
688
|
-
return ZodArray.create(this);
|
|
715
|
+
return ZodArray.create(this, this._def);
|
|
689
716
|
}
|
|
690
717
|
promise() {
|
|
691
|
-
return ZodPromise.create(this);
|
|
718
|
+
return ZodPromise.create(this, this._def);
|
|
692
719
|
}
|
|
693
720
|
or(option) {
|
|
694
|
-
return ZodUnion.create([this, option]);
|
|
721
|
+
return ZodUnion.create([this, option], this._def);
|
|
695
722
|
}
|
|
696
723
|
and(incoming) {
|
|
697
|
-
return ZodIntersection.create(this, incoming);
|
|
724
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
698
725
|
}
|
|
699
726
|
transform(transform) {
|
|
700
727
|
return new ZodEffects({
|
|
728
|
+
...processCreateParams(this._def),
|
|
701
729
|
schema: this,
|
|
702
730
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
703
731
|
effect: { type: "transform", transform },
|
|
@@ -706,6 +734,7 @@ class ZodType {
|
|
|
706
734
|
default(def) {
|
|
707
735
|
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
708
736
|
return new ZodDefault({
|
|
737
|
+
...processCreateParams(this._def),
|
|
709
738
|
innerType: this,
|
|
710
739
|
defaultValue: defaultValueFunc,
|
|
711
740
|
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
@@ -715,7 +744,16 @@ class ZodType {
|
|
|
715
744
|
return new ZodBranded({
|
|
716
745
|
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
717
746
|
type: this,
|
|
718
|
-
...processCreateParams(
|
|
747
|
+
...processCreateParams(this._def),
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
catch(def) {
|
|
751
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
752
|
+
return new ZodCatch({
|
|
753
|
+
...processCreateParams(this._def),
|
|
754
|
+
innerType: this,
|
|
755
|
+
catchValue: catchValueFunc,
|
|
756
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
719
757
|
});
|
|
720
758
|
}
|
|
721
759
|
describe(description) {
|
|
@@ -725,6 +763,9 @@ class ZodType {
|
|
|
725
763
|
description,
|
|
726
764
|
});
|
|
727
765
|
}
|
|
766
|
+
pipe(target) {
|
|
767
|
+
return ZodPipeline.create(this, target);
|
|
768
|
+
}
|
|
728
769
|
isOptional() {
|
|
729
770
|
return this.safeParse(undefined).success;
|
|
730
771
|
}
|
|
@@ -733,12 +774,48 @@ class ZodType {
|
|
|
733
774
|
}
|
|
734
775
|
}
|
|
735
776
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
777
|
+
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
736
778
|
const uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
737
779
|
// from https://stackoverflow.com/a/46181/1550155
|
|
738
780
|
// old version: too slow, didn't support unicode
|
|
739
781
|
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
782
|
+
//old email regex
|
|
783
|
+
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
|
740
784
|
// eslint-disable-next-line
|
|
741
|
-
const emailRegex = /^(([^<>()[\]
|
|
785
|
+
const emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|([^-]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}))$/;
|
|
786
|
+
// interface IsDateStringOptions extends StringDateOptions {
|
|
787
|
+
/**
|
|
788
|
+
* Match any configuration
|
|
789
|
+
*/
|
|
790
|
+
// any?: boolean;
|
|
791
|
+
// }
|
|
792
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
|
793
|
+
const datetimeRegex = (args) => {
|
|
794
|
+
if (args.precision) {
|
|
795
|
+
if (args.offset) {
|
|
796
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
797
|
+
}
|
|
798
|
+
else {
|
|
799
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
else if (args.precision === 0) {
|
|
803
|
+
if (args.offset) {
|
|
804
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
805
|
+
}
|
|
806
|
+
else {
|
|
807
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
if (args.offset) {
|
|
812
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
};
|
|
742
819
|
class ZodString extends ZodType {
|
|
743
820
|
constructor() {
|
|
744
821
|
super(...arguments);
|
|
@@ -758,6 +835,9 @@ class ZodString extends ZodType {
|
|
|
758
835
|
});
|
|
759
836
|
}
|
|
760
837
|
_parse(input) {
|
|
838
|
+
if (this._def.coerce) {
|
|
839
|
+
input.data = String(input.data);
|
|
840
|
+
}
|
|
761
841
|
const parsedType = this._getType(input);
|
|
762
842
|
if (parsedType !== ZodParsedType.string) {
|
|
763
843
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -781,6 +861,7 @@ class ZodString extends ZodType {
|
|
|
781
861
|
minimum: check.value,
|
|
782
862
|
type: "string",
|
|
783
863
|
inclusive: true,
|
|
864
|
+
exact: false,
|
|
784
865
|
message: check.message,
|
|
785
866
|
});
|
|
786
867
|
status.dirty();
|
|
@@ -794,11 +875,40 @@ class ZodString extends ZodType {
|
|
|
794
875
|
maximum: check.value,
|
|
795
876
|
type: "string",
|
|
796
877
|
inclusive: true,
|
|
878
|
+
exact: false,
|
|
797
879
|
message: check.message,
|
|
798
880
|
});
|
|
799
881
|
status.dirty();
|
|
800
882
|
}
|
|
801
883
|
}
|
|
884
|
+
else if (check.kind === "length") {
|
|
885
|
+
const tooBig = input.data.length > check.value;
|
|
886
|
+
const tooSmall = input.data.length < check.value;
|
|
887
|
+
if (tooBig || tooSmall) {
|
|
888
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
889
|
+
if (tooBig) {
|
|
890
|
+
addIssueToContext(ctx, {
|
|
891
|
+
code: ZodIssueCode.too_big,
|
|
892
|
+
maximum: check.value,
|
|
893
|
+
type: "string",
|
|
894
|
+
inclusive: true,
|
|
895
|
+
exact: true,
|
|
896
|
+
message: check.message,
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
else if (tooSmall) {
|
|
900
|
+
addIssueToContext(ctx, {
|
|
901
|
+
code: ZodIssueCode.too_small,
|
|
902
|
+
minimum: check.value,
|
|
903
|
+
type: "string",
|
|
904
|
+
inclusive: true,
|
|
905
|
+
exact: true,
|
|
906
|
+
message: check.message,
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
status.dirty();
|
|
910
|
+
}
|
|
911
|
+
}
|
|
802
912
|
else if (check.kind === "email") {
|
|
803
913
|
if (!emailRegex.test(input.data)) {
|
|
804
914
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -832,6 +942,17 @@ class ZodString extends ZodType {
|
|
|
832
942
|
status.dirty();
|
|
833
943
|
}
|
|
834
944
|
}
|
|
945
|
+
else if (check.kind === "cuid2") {
|
|
946
|
+
if (!cuid2Regex.test(input.data)) {
|
|
947
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
948
|
+
addIssueToContext(ctx, {
|
|
949
|
+
validation: "cuid2",
|
|
950
|
+
code: ZodIssueCode.invalid_string,
|
|
951
|
+
message: check.message,
|
|
952
|
+
});
|
|
953
|
+
status.dirty();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
835
956
|
else if (check.kind === "url") {
|
|
836
957
|
try {
|
|
837
958
|
new URL(input.data);
|
|
@@ -884,6 +1005,18 @@ class ZodString extends ZodType {
|
|
|
884
1005
|
status.dirty();
|
|
885
1006
|
}
|
|
886
1007
|
}
|
|
1008
|
+
else if (check.kind === "datetime") {
|
|
1009
|
+
const regex = datetimeRegex(check);
|
|
1010
|
+
if (!regex.test(input.data)) {
|
|
1011
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1012
|
+
addIssueToContext(ctx, {
|
|
1013
|
+
code: ZodIssueCode.invalid_string,
|
|
1014
|
+
validation: "datetime",
|
|
1015
|
+
message: check.message,
|
|
1016
|
+
});
|
|
1017
|
+
status.dirty();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
887
1020
|
else {
|
|
888
1021
|
util.assertNever(check);
|
|
889
1022
|
}
|
|
@@ -908,6 +1041,26 @@ class ZodString extends ZodType {
|
|
|
908
1041
|
cuid(message) {
|
|
909
1042
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
910
1043
|
}
|
|
1044
|
+
cuid2(message) {
|
|
1045
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1046
|
+
}
|
|
1047
|
+
datetime(options) {
|
|
1048
|
+
var _a;
|
|
1049
|
+
if (typeof options === "string") {
|
|
1050
|
+
return this._addCheck({
|
|
1051
|
+
kind: "datetime",
|
|
1052
|
+
precision: null,
|
|
1053
|
+
offset: false,
|
|
1054
|
+
message: options,
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
return this._addCheck({
|
|
1058
|
+
kind: "datetime",
|
|
1059
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1060
|
+
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1061
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
911
1064
|
regex(regex, message) {
|
|
912
1065
|
return this._addCheck({
|
|
913
1066
|
kind: "regex",
|
|
@@ -944,7 +1097,14 @@ class ZodString extends ZodType {
|
|
|
944
1097
|
});
|
|
945
1098
|
}
|
|
946
1099
|
length(len, message) {
|
|
947
|
-
return this.
|
|
1100
|
+
return this._addCheck({
|
|
1101
|
+
kind: "length",
|
|
1102
|
+
value: len,
|
|
1103
|
+
...errorUtil.errToObj(message),
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
get isDatetime() {
|
|
1107
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
948
1108
|
}
|
|
949
1109
|
get isEmail() {
|
|
950
1110
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
@@ -958,6 +1118,9 @@ class ZodString extends ZodType {
|
|
|
958
1118
|
get isCUID() {
|
|
959
1119
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
960
1120
|
}
|
|
1121
|
+
get isCUID2() {
|
|
1122
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1123
|
+
}
|
|
961
1124
|
get minLength() {
|
|
962
1125
|
let min = null;
|
|
963
1126
|
for (const ch of this._def.checks) {
|
|
@@ -980,9 +1143,11 @@ class ZodString extends ZodType {
|
|
|
980
1143
|
}
|
|
981
1144
|
}
|
|
982
1145
|
ZodString.create = (params) => {
|
|
1146
|
+
var _a;
|
|
983
1147
|
return new ZodString({
|
|
984
1148
|
checks: [],
|
|
985
1149
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1150
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
986
1151
|
...processCreateParams(params),
|
|
987
1152
|
});
|
|
988
1153
|
};
|
|
@@ -1003,6 +1168,9 @@ class ZodNumber extends ZodType {
|
|
|
1003
1168
|
this.step = this.multipleOf;
|
|
1004
1169
|
}
|
|
1005
1170
|
_parse(input) {
|
|
1171
|
+
if (this._def.coerce) {
|
|
1172
|
+
input.data = Number(input.data);
|
|
1173
|
+
}
|
|
1006
1174
|
const parsedType = this._getType(input);
|
|
1007
1175
|
if (parsedType !== ZodParsedType.number) {
|
|
1008
1176
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -1039,6 +1207,7 @@ class ZodNumber extends ZodType {
|
|
|
1039
1207
|
minimum: check.value,
|
|
1040
1208
|
type: "number",
|
|
1041
1209
|
inclusive: check.inclusive,
|
|
1210
|
+
exact: false,
|
|
1042
1211
|
message: check.message,
|
|
1043
1212
|
});
|
|
1044
1213
|
status.dirty();
|
|
@@ -1055,6 +1224,7 @@ class ZodNumber extends ZodType {
|
|
|
1055
1224
|
maximum: check.value,
|
|
1056
1225
|
type: "number",
|
|
1057
1226
|
inclusive: check.inclusive,
|
|
1227
|
+
exact: false,
|
|
1058
1228
|
message: check.message,
|
|
1059
1229
|
});
|
|
1060
1230
|
status.dirty();
|
|
@@ -1071,6 +1241,16 @@ class ZodNumber extends ZodType {
|
|
|
1071
1241
|
status.dirty();
|
|
1072
1242
|
}
|
|
1073
1243
|
}
|
|
1244
|
+
else if (check.kind === "finite") {
|
|
1245
|
+
if (!Number.isFinite(input.data)) {
|
|
1246
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1247
|
+
addIssueToContext(ctx, {
|
|
1248
|
+
code: ZodIssueCode.not_finite,
|
|
1249
|
+
message: check.message,
|
|
1250
|
+
});
|
|
1251
|
+
status.dirty();
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1074
1254
|
else {
|
|
1075
1255
|
util.assertNever(check);
|
|
1076
1256
|
}
|
|
@@ -1154,6 +1334,12 @@ class ZodNumber extends ZodType {
|
|
|
1154
1334
|
message: errorUtil.toString(message),
|
|
1155
1335
|
});
|
|
1156
1336
|
}
|
|
1337
|
+
finite(message) {
|
|
1338
|
+
return this._addCheck({
|
|
1339
|
+
kind: "finite",
|
|
1340
|
+
message: errorUtil.toString(message),
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1157
1343
|
get minValue() {
|
|
1158
1344
|
let min = null;
|
|
1159
1345
|
for (const ch of this._def.checks) {
|
|
@@ -1175,18 +1361,42 @@ class ZodNumber extends ZodType {
|
|
|
1175
1361
|
return max;
|
|
1176
1362
|
}
|
|
1177
1363
|
get isInt() {
|
|
1178
|
-
return !!this._def.checks.find((ch) => ch.kind === "int"
|
|
1364
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" ||
|
|
1365
|
+
(ch.kind === "multipleOf" && util.isInteger(ch.value)));
|
|
1366
|
+
}
|
|
1367
|
+
get isFinite() {
|
|
1368
|
+
let max = null, min = null;
|
|
1369
|
+
for (const ch of this._def.checks) {
|
|
1370
|
+
if (ch.kind === "finite" ||
|
|
1371
|
+
ch.kind === "int" ||
|
|
1372
|
+
ch.kind === "multipleOf") {
|
|
1373
|
+
return true;
|
|
1374
|
+
}
|
|
1375
|
+
else if (ch.kind === "min") {
|
|
1376
|
+
if (min === null || ch.value > min)
|
|
1377
|
+
min = ch.value;
|
|
1378
|
+
}
|
|
1379
|
+
else if (ch.kind === "max") {
|
|
1380
|
+
if (max === null || ch.value < max)
|
|
1381
|
+
max = ch.value;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1179
1385
|
}
|
|
1180
1386
|
}
|
|
1181
1387
|
ZodNumber.create = (params) => {
|
|
1182
1388
|
return new ZodNumber({
|
|
1183
1389
|
checks: [],
|
|
1184
1390
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1391
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1185
1392
|
...processCreateParams(params),
|
|
1186
1393
|
});
|
|
1187
1394
|
};
|
|
1188
1395
|
class ZodBigInt extends ZodType {
|
|
1189
1396
|
_parse(input) {
|
|
1397
|
+
if (this._def.coerce) {
|
|
1398
|
+
input.data = BigInt(input.data);
|
|
1399
|
+
}
|
|
1190
1400
|
const parsedType = this._getType(input);
|
|
1191
1401
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1192
1402
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -1201,13 +1411,18 @@ class ZodBigInt extends ZodType {
|
|
|
1201
1411
|
}
|
|
1202
1412
|
}
|
|
1203
1413
|
ZodBigInt.create = (params) => {
|
|
1414
|
+
var _a;
|
|
1204
1415
|
return new ZodBigInt({
|
|
1205
1416
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1417
|
+
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1206
1418
|
...processCreateParams(params),
|
|
1207
1419
|
});
|
|
1208
1420
|
};
|
|
1209
1421
|
class ZodBoolean extends ZodType {
|
|
1210
1422
|
_parse(input) {
|
|
1423
|
+
if (this._def.coerce) {
|
|
1424
|
+
input.data = Boolean(input.data);
|
|
1425
|
+
}
|
|
1211
1426
|
const parsedType = this._getType(input);
|
|
1212
1427
|
if (parsedType !== ZodParsedType.boolean) {
|
|
1213
1428
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -1224,11 +1439,15 @@ class ZodBoolean extends ZodType {
|
|
|
1224
1439
|
ZodBoolean.create = (params) => {
|
|
1225
1440
|
return new ZodBoolean({
|
|
1226
1441
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1442
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1227
1443
|
...processCreateParams(params),
|
|
1228
1444
|
});
|
|
1229
1445
|
};
|
|
1230
1446
|
class ZodDate extends ZodType {
|
|
1231
1447
|
_parse(input) {
|
|
1448
|
+
if (this._def.coerce) {
|
|
1449
|
+
input.data = new Date(input.data);
|
|
1450
|
+
}
|
|
1232
1451
|
const parsedType = this._getType(input);
|
|
1233
1452
|
if (parsedType !== ZodParsedType.date) {
|
|
1234
1453
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -1256,6 +1475,7 @@ class ZodDate extends ZodType {
|
|
|
1256
1475
|
code: ZodIssueCode.too_small,
|
|
1257
1476
|
message: check.message,
|
|
1258
1477
|
inclusive: true,
|
|
1478
|
+
exact: false,
|
|
1259
1479
|
minimum: check.value,
|
|
1260
1480
|
type: "date",
|
|
1261
1481
|
});
|
|
@@ -1269,6 +1489,7 @@ class ZodDate extends ZodType {
|
|
|
1269
1489
|
code: ZodIssueCode.too_big,
|
|
1270
1490
|
message: check.message,
|
|
1271
1491
|
inclusive: true,
|
|
1492
|
+
exact: false,
|
|
1272
1493
|
maximum: check.value,
|
|
1273
1494
|
type: "date",
|
|
1274
1495
|
});
|
|
@@ -1328,10 +1549,32 @@ class ZodDate extends ZodType {
|
|
|
1328
1549
|
ZodDate.create = (params) => {
|
|
1329
1550
|
return new ZodDate({
|
|
1330
1551
|
checks: [],
|
|
1552
|
+
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1331
1553
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1332
1554
|
...processCreateParams(params),
|
|
1333
1555
|
});
|
|
1334
1556
|
};
|
|
1557
|
+
class ZodSymbol extends ZodType {
|
|
1558
|
+
_parse(input) {
|
|
1559
|
+
const parsedType = this._getType(input);
|
|
1560
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
1561
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1562
|
+
addIssueToContext(ctx, {
|
|
1563
|
+
code: ZodIssueCode.invalid_type,
|
|
1564
|
+
expected: ZodParsedType.symbol,
|
|
1565
|
+
received: ctx.parsedType,
|
|
1566
|
+
});
|
|
1567
|
+
return INVALID;
|
|
1568
|
+
}
|
|
1569
|
+
return OK(input.data);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
ZodSymbol.create = (params) => {
|
|
1573
|
+
return new ZodSymbol({
|
|
1574
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
1575
|
+
...processCreateParams(params),
|
|
1576
|
+
});
|
|
1577
|
+
};
|
|
1335
1578
|
class ZodUndefined extends ZodType {
|
|
1336
1579
|
_parse(input) {
|
|
1337
1580
|
const parsedType = this._getType(input);
|
|
@@ -1456,6 +1699,22 @@ class ZodArray extends ZodType {
|
|
|
1456
1699
|
});
|
|
1457
1700
|
return INVALID;
|
|
1458
1701
|
}
|
|
1702
|
+
if (def.exactLength !== null) {
|
|
1703
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
1704
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
1705
|
+
if (tooBig || tooSmall) {
|
|
1706
|
+
addIssueToContext(ctx, {
|
|
1707
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
1708
|
+
minimum: (tooSmall ? def.exactLength.value : undefined),
|
|
1709
|
+
maximum: (tooBig ? def.exactLength.value : undefined),
|
|
1710
|
+
type: "array",
|
|
1711
|
+
inclusive: true,
|
|
1712
|
+
exact: true,
|
|
1713
|
+
message: def.exactLength.message,
|
|
1714
|
+
});
|
|
1715
|
+
status.dirty();
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1459
1718
|
if (def.minLength !== null) {
|
|
1460
1719
|
if (ctx.data.length < def.minLength.value) {
|
|
1461
1720
|
addIssueToContext(ctx, {
|
|
@@ -1463,6 +1722,7 @@ class ZodArray extends ZodType {
|
|
|
1463
1722
|
minimum: def.minLength.value,
|
|
1464
1723
|
type: "array",
|
|
1465
1724
|
inclusive: true,
|
|
1725
|
+
exact: false,
|
|
1466
1726
|
message: def.minLength.message,
|
|
1467
1727
|
});
|
|
1468
1728
|
status.dirty();
|
|
@@ -1475,19 +1735,20 @@ class ZodArray extends ZodType {
|
|
|
1475
1735
|
maximum: def.maxLength.value,
|
|
1476
1736
|
type: "array",
|
|
1477
1737
|
inclusive: true,
|
|
1738
|
+
exact: false,
|
|
1478
1739
|
message: def.maxLength.message,
|
|
1479
1740
|
});
|
|
1480
1741
|
status.dirty();
|
|
1481
1742
|
}
|
|
1482
1743
|
}
|
|
1483
1744
|
if (ctx.common.async) {
|
|
1484
|
-
return Promise.all(ctx.data.map((item, i) => {
|
|
1745
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
1485
1746
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1486
1747
|
})).then((result) => {
|
|
1487
1748
|
return ParseStatus.mergeArray(status, result);
|
|
1488
1749
|
});
|
|
1489
1750
|
}
|
|
1490
|
-
const result = ctx.data.map((item, i) => {
|
|
1751
|
+
const result = [...ctx.data].map((item, i) => {
|
|
1491
1752
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1492
1753
|
});
|
|
1493
1754
|
return ParseStatus.mergeArray(status, result);
|
|
@@ -1508,7 +1769,10 @@ class ZodArray extends ZodType {
|
|
|
1508
1769
|
});
|
|
1509
1770
|
}
|
|
1510
1771
|
length(len, message) {
|
|
1511
|
-
return
|
|
1772
|
+
return new ZodArray({
|
|
1773
|
+
...this._def,
|
|
1774
|
+
exactLength: { value: len, message: errorUtil.toString(message) },
|
|
1775
|
+
});
|
|
1512
1776
|
}
|
|
1513
1777
|
nonempty(message) {
|
|
1514
1778
|
return this.min(1, message);
|
|
@@ -1519,6 +1783,7 @@ ZodArray.create = (schema, params) => {
|
|
|
1519
1783
|
type: schema,
|
|
1520
1784
|
minLength: null,
|
|
1521
1785
|
maxLength: null,
|
|
1786
|
+
exactLength: null,
|
|
1522
1787
|
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
1523
1788
|
...processCreateParams(params),
|
|
1524
1789
|
});
|
|
@@ -1535,19 +1800,10 @@ var objectUtil;
|
|
|
1535
1800
|
objectUtil.mergeShapes = (first, second) => {
|
|
1536
1801
|
return {
|
|
1537
1802
|
...first,
|
|
1538
|
-
...second,
|
|
1803
|
+
...second, // second overwrites first
|
|
1539
1804
|
};
|
|
1540
1805
|
};
|
|
1541
1806
|
})(objectUtil || (objectUtil = {}));
|
|
1542
|
-
const AugmentFactory = (def) => (augmentation) => {
|
|
1543
|
-
return new ZodObject({
|
|
1544
|
-
...def,
|
|
1545
|
-
shape: () => ({
|
|
1546
|
-
...def.shape(),
|
|
1547
|
-
...augmentation,
|
|
1548
|
-
}),
|
|
1549
|
-
});
|
|
1550
|
-
};
|
|
1551
1807
|
function deepPartialify(schema) {
|
|
1552
1808
|
if (schema instanceof ZodObject) {
|
|
1553
1809
|
const newShape = {};
|
|
@@ -1585,8 +1841,43 @@ class ZodObject extends ZodType {
|
|
|
1585
1841
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1586
1842
|
*/
|
|
1587
1843
|
this.nonstrict = this.passthrough;
|
|
1588
|
-
|
|
1589
|
-
|
|
1844
|
+
// extend<
|
|
1845
|
+
// Augmentation extends ZodRawShape,
|
|
1846
|
+
// NewOutput extends util.flatten<{
|
|
1847
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
1848
|
+
// ? Augmentation[k]["_output"]
|
|
1849
|
+
// : k extends keyof Output
|
|
1850
|
+
// ? Output[k]
|
|
1851
|
+
// : never;
|
|
1852
|
+
// }>,
|
|
1853
|
+
// NewInput extends util.flatten<{
|
|
1854
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
1855
|
+
// ? Augmentation[k]["_input"]
|
|
1856
|
+
// : k extends keyof Input
|
|
1857
|
+
// ? Input[k]
|
|
1858
|
+
// : never;
|
|
1859
|
+
// }>
|
|
1860
|
+
// >(
|
|
1861
|
+
// augmentation: Augmentation
|
|
1862
|
+
// ): ZodObject<
|
|
1863
|
+
// extendShape<T, Augmentation>,
|
|
1864
|
+
// UnknownKeys,
|
|
1865
|
+
// Catchall,
|
|
1866
|
+
// NewOutput,
|
|
1867
|
+
// NewInput
|
|
1868
|
+
// > {
|
|
1869
|
+
// return new ZodObject({
|
|
1870
|
+
// ...this._def,
|
|
1871
|
+
// shape: () => ({
|
|
1872
|
+
// ...this._def.shape(),
|
|
1873
|
+
// ...augmentation,
|
|
1874
|
+
// }),
|
|
1875
|
+
// }) as any;
|
|
1876
|
+
// }
|
|
1877
|
+
/**
|
|
1878
|
+
* @deprecated Use `.extend` instead
|
|
1879
|
+
* */
|
|
1880
|
+
this.augment = this.extend;
|
|
1590
1881
|
}
|
|
1591
1882
|
_getCached() {
|
|
1592
1883
|
if (this._cached !== null)
|
|
@@ -1723,8 +2014,31 @@ class ZodObject extends ZodType {
|
|
|
1723
2014
|
unknownKeys: "passthrough",
|
|
1724
2015
|
});
|
|
1725
2016
|
}
|
|
1726
|
-
|
|
1727
|
-
|
|
2017
|
+
// const AugmentFactory =
|
|
2018
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2019
|
+
// <Augmentation extends ZodRawShape>(
|
|
2020
|
+
// augmentation: Augmentation
|
|
2021
|
+
// ): ZodObject<
|
|
2022
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2023
|
+
// Def["unknownKeys"],
|
|
2024
|
+
// Def["catchall"]
|
|
2025
|
+
// > => {
|
|
2026
|
+
// return new ZodObject({
|
|
2027
|
+
// ...def,
|
|
2028
|
+
// shape: () => ({
|
|
2029
|
+
// ...def.shape(),
|
|
2030
|
+
// ...augmentation,
|
|
2031
|
+
// }),
|
|
2032
|
+
// }) as any;
|
|
2033
|
+
// };
|
|
2034
|
+
extend(augmentation) {
|
|
2035
|
+
return new ZodObject({
|
|
2036
|
+
...this._def,
|
|
2037
|
+
shape: () => ({
|
|
2038
|
+
...this._def.shape(),
|
|
2039
|
+
...augmentation,
|
|
2040
|
+
}),
|
|
2041
|
+
});
|
|
1728
2042
|
}
|
|
1729
2043
|
/**
|
|
1730
2044
|
* Prior to zod@1.0.12 there was a bug in the
|
|
@@ -1732,10 +2046,6 @@ class ZodObject extends ZodType {
|
|
|
1732
2046
|
* upgrade if you are experiencing issues.
|
|
1733
2047
|
*/
|
|
1734
2048
|
merge(merging) {
|
|
1735
|
-
// const mergedShape = objectUtil.mergeShapes(
|
|
1736
|
-
// this._def.shape(),
|
|
1737
|
-
// merging._def.shape()
|
|
1738
|
-
// );
|
|
1739
2049
|
const merged = new ZodObject({
|
|
1740
2050
|
unknownKeys: merging._def.unknownKeys,
|
|
1741
2051
|
catchall: merging._def.catchall,
|
|
@@ -1744,6 +2054,65 @@ class ZodObject extends ZodType {
|
|
|
1744
2054
|
});
|
|
1745
2055
|
return merged;
|
|
1746
2056
|
}
|
|
2057
|
+
// merge<
|
|
2058
|
+
// Incoming extends AnyZodObject,
|
|
2059
|
+
// Augmentation extends Incoming["shape"],
|
|
2060
|
+
// NewOutput extends {
|
|
2061
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2062
|
+
// ? Augmentation[k]["_output"]
|
|
2063
|
+
// : k extends keyof Output
|
|
2064
|
+
// ? Output[k]
|
|
2065
|
+
// : never;
|
|
2066
|
+
// },
|
|
2067
|
+
// NewInput extends {
|
|
2068
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2069
|
+
// ? Augmentation[k]["_input"]
|
|
2070
|
+
// : k extends keyof Input
|
|
2071
|
+
// ? Input[k]
|
|
2072
|
+
// : never;
|
|
2073
|
+
// }
|
|
2074
|
+
// >(
|
|
2075
|
+
// merging: Incoming
|
|
2076
|
+
// ): ZodObject<
|
|
2077
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2078
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2079
|
+
// Incoming["_def"]["catchall"],
|
|
2080
|
+
// NewOutput,
|
|
2081
|
+
// NewInput
|
|
2082
|
+
// > {
|
|
2083
|
+
// const merged: any = new ZodObject({
|
|
2084
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2085
|
+
// catchall: merging._def.catchall,
|
|
2086
|
+
// shape: () =>
|
|
2087
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2088
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2089
|
+
// }) as any;
|
|
2090
|
+
// return merged;
|
|
2091
|
+
// }
|
|
2092
|
+
setKey(key, schema) {
|
|
2093
|
+
return this.augment({ [key]: schema });
|
|
2094
|
+
}
|
|
2095
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2096
|
+
// merging: Incoming
|
|
2097
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2098
|
+
// ZodObject<
|
|
2099
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2100
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2101
|
+
// Incoming["_def"]["catchall"]
|
|
2102
|
+
// > {
|
|
2103
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2104
|
+
// // this._def.shape(),
|
|
2105
|
+
// // merging._def.shape()
|
|
2106
|
+
// // );
|
|
2107
|
+
// const merged: any = new ZodObject({
|
|
2108
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2109
|
+
// catchall: merging._def.catchall,
|
|
2110
|
+
// shape: () =>
|
|
2111
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2112
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2113
|
+
// }) as any;
|
|
2114
|
+
// return merged;
|
|
2115
|
+
// }
|
|
1747
2116
|
catchall(index) {
|
|
1748
2117
|
return new ZodObject({
|
|
1749
2118
|
...this._def,
|
|
@@ -1752,10 +2121,10 @@ class ZodObject extends ZodType {
|
|
|
1752
2121
|
}
|
|
1753
2122
|
pick(mask) {
|
|
1754
2123
|
const shape = {};
|
|
1755
|
-
util.objectKeys(mask).
|
|
1756
|
-
|
|
1757
|
-
if (this.shape[key])
|
|
2124
|
+
util.objectKeys(mask).forEach((key) => {
|
|
2125
|
+
if (mask[key] && this.shape[key]) {
|
|
1758
2126
|
shape[key] = this.shape[key];
|
|
2127
|
+
}
|
|
1759
2128
|
});
|
|
1760
2129
|
return new ZodObject({
|
|
1761
2130
|
...this._def,
|
|
@@ -1764,8 +2133,8 @@ class ZodObject extends ZodType {
|
|
|
1764
2133
|
}
|
|
1765
2134
|
omit(mask) {
|
|
1766
2135
|
const shape = {};
|
|
1767
|
-
util.objectKeys(this.shape).
|
|
1768
|
-
if (
|
|
2136
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2137
|
+
if (!mask[key]) {
|
|
1769
2138
|
shape[key] = this.shape[key];
|
|
1770
2139
|
}
|
|
1771
2140
|
});
|
|
@@ -1779,41 +2148,35 @@ class ZodObject extends ZodType {
|
|
|
1779
2148
|
}
|
|
1780
2149
|
partial(mask) {
|
|
1781
2150
|
const newShape = {};
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
newShape[key] = this.shape[key].optional();
|
|
1789
|
-
}
|
|
1790
|
-
});
|
|
1791
|
-
return new ZodObject({
|
|
1792
|
-
...this._def,
|
|
1793
|
-
shape: () => newShape,
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
else {
|
|
1797
|
-
for (const key in this.shape) {
|
|
1798
|
-
const fieldSchema = this.shape[key];
|
|
2151
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2152
|
+
const fieldSchema = this.shape[key];
|
|
2153
|
+
if (mask && !mask[key]) {
|
|
2154
|
+
newShape[key] = fieldSchema;
|
|
2155
|
+
}
|
|
2156
|
+
else {
|
|
1799
2157
|
newShape[key] = fieldSchema.optional();
|
|
1800
2158
|
}
|
|
1801
|
-
}
|
|
2159
|
+
});
|
|
1802
2160
|
return new ZodObject({
|
|
1803
2161
|
...this._def,
|
|
1804
2162
|
shape: () => newShape,
|
|
1805
2163
|
});
|
|
1806
2164
|
}
|
|
1807
|
-
required() {
|
|
2165
|
+
required(mask) {
|
|
1808
2166
|
const newShape = {};
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
while (newField instanceof ZodOptional) {
|
|
1813
|
-
newField = newField._def.innerType;
|
|
2167
|
+
util.objectKeys(this.shape).forEach((key) => {
|
|
2168
|
+
if (mask && !mask[key]) {
|
|
2169
|
+
newShape[key] = this.shape[key];
|
|
1814
2170
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
2171
|
+
else {
|
|
2172
|
+
const fieldSchema = this.shape[key];
|
|
2173
|
+
let newField = fieldSchema;
|
|
2174
|
+
while (newField instanceof ZodOptional) {
|
|
2175
|
+
newField = newField._def.innerType;
|
|
2176
|
+
}
|
|
2177
|
+
newShape[key] = newField;
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
1817
2180
|
return new ZodObject({
|
|
1818
2181
|
...this._def,
|
|
1819
2182
|
shape: () => newShape,
|
|
@@ -1946,6 +2309,43 @@ ZodUnion.create = (types, params) => {
|
|
|
1946
2309
|
...processCreateParams(params),
|
|
1947
2310
|
});
|
|
1948
2311
|
};
|
|
2312
|
+
/////////////////////////////////////////////////////
|
|
2313
|
+
/////////////////////////////////////////////////////
|
|
2314
|
+
////////// //////////
|
|
2315
|
+
////////// ZodDiscriminatedUnion //////////
|
|
2316
|
+
////////// //////////
|
|
2317
|
+
/////////////////////////////////////////////////////
|
|
2318
|
+
/////////////////////////////////////////////////////
|
|
2319
|
+
const getDiscriminator = (type) => {
|
|
2320
|
+
if (type instanceof ZodLazy) {
|
|
2321
|
+
return getDiscriminator(type.schema);
|
|
2322
|
+
}
|
|
2323
|
+
else if (type instanceof ZodEffects) {
|
|
2324
|
+
return getDiscriminator(type.innerType());
|
|
2325
|
+
}
|
|
2326
|
+
else if (type instanceof ZodLiteral) {
|
|
2327
|
+
return [type.value];
|
|
2328
|
+
}
|
|
2329
|
+
else if (type instanceof ZodEnum) {
|
|
2330
|
+
return type.options;
|
|
2331
|
+
}
|
|
2332
|
+
else if (type instanceof ZodNativeEnum) {
|
|
2333
|
+
// eslint-disable-next-line ban/ban
|
|
2334
|
+
return Object.keys(type.enum);
|
|
2335
|
+
}
|
|
2336
|
+
else if (type instanceof ZodDefault) {
|
|
2337
|
+
return getDiscriminator(type._def.innerType);
|
|
2338
|
+
}
|
|
2339
|
+
else if (type instanceof ZodUndefined) {
|
|
2340
|
+
return [undefined];
|
|
2341
|
+
}
|
|
2342
|
+
else if (type instanceof ZodNull) {
|
|
2343
|
+
return [null];
|
|
2344
|
+
}
|
|
2345
|
+
else {
|
|
2346
|
+
return null;
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
1949
2349
|
class ZodDiscriminatedUnion extends ZodType {
|
|
1950
2350
|
_parse(input) {
|
|
1951
2351
|
const { ctx } = this._processInputParams(input);
|
|
@@ -1959,11 +2359,11 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1959
2359
|
}
|
|
1960
2360
|
const discriminator = this.discriminator;
|
|
1961
2361
|
const discriminatorValue = ctx.data[discriminator];
|
|
1962
|
-
const option = this.
|
|
2362
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
1963
2363
|
if (!option) {
|
|
1964
2364
|
addIssueToContext(ctx, {
|
|
1965
2365
|
code: ZodIssueCode.invalid_union_discriminator,
|
|
1966
|
-
options: this.
|
|
2366
|
+
options: Array.from(this.optionsMap.keys()),
|
|
1967
2367
|
path: [discriminator],
|
|
1968
2368
|
});
|
|
1969
2369
|
return INVALID;
|
|
@@ -1986,12 +2386,12 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
1986
2386
|
get discriminator() {
|
|
1987
2387
|
return this._def.discriminator;
|
|
1988
2388
|
}
|
|
1989
|
-
get validDiscriminatorValues() {
|
|
1990
|
-
return Array.from(this.options.keys());
|
|
1991
|
-
}
|
|
1992
2389
|
get options() {
|
|
1993
2390
|
return this._def.options;
|
|
1994
2391
|
}
|
|
2392
|
+
get optionsMap() {
|
|
2393
|
+
return this._def.optionsMap;
|
|
2394
|
+
}
|
|
1995
2395
|
/**
|
|
1996
2396
|
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
1997
2397
|
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
@@ -2000,26 +2400,27 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
2000
2400
|
* @param types an array of object schemas
|
|
2001
2401
|
* @param params
|
|
2002
2402
|
*/
|
|
2003
|
-
static create(discriminator,
|
|
2403
|
+
static create(discriminator, options, params) {
|
|
2004
2404
|
// Get all the valid discriminator values
|
|
2005
|
-
const
|
|
2006
|
-
try {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2405
|
+
const optionsMap = new Map();
|
|
2406
|
+
// try {
|
|
2407
|
+
for (const type of options) {
|
|
2408
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2409
|
+
if (!discriminatorValues) {
|
|
2410
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2411
|
+
}
|
|
2412
|
+
for (const value of discriminatorValues) {
|
|
2413
|
+
if (optionsMap.has(value)) {
|
|
2414
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2415
|
+
}
|
|
2416
|
+
optionsMap.set(value, type);
|
|
2417
|
+
}
|
|
2018
2418
|
}
|
|
2019
2419
|
return new ZodDiscriminatedUnion({
|
|
2020
2420
|
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2021
2421
|
discriminator,
|
|
2022
2422
|
options,
|
|
2423
|
+
optionsMap,
|
|
2023
2424
|
...processCreateParams(params),
|
|
2024
2425
|
});
|
|
2025
2426
|
}
|
|
@@ -2140,6 +2541,7 @@ class ZodTuple extends ZodType {
|
|
|
2140
2541
|
code: ZodIssueCode.too_small,
|
|
2141
2542
|
minimum: this._def.items.length,
|
|
2142
2543
|
inclusive: true,
|
|
2544
|
+
exact: false,
|
|
2143
2545
|
type: "array",
|
|
2144
2546
|
});
|
|
2145
2547
|
return INVALID;
|
|
@@ -2150,11 +2552,12 @@ class ZodTuple extends ZodType {
|
|
|
2150
2552
|
code: ZodIssueCode.too_big,
|
|
2151
2553
|
maximum: this._def.items.length,
|
|
2152
2554
|
inclusive: true,
|
|
2555
|
+
exact: false,
|
|
2153
2556
|
type: "array",
|
|
2154
2557
|
});
|
|
2155
2558
|
status.dirty();
|
|
2156
2559
|
}
|
|
2157
|
-
const items = ctx.data
|
|
2560
|
+
const items = [...ctx.data]
|
|
2158
2561
|
.map((item, itemIndex) => {
|
|
2159
2562
|
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2160
2563
|
if (!schema)
|
|
@@ -2325,6 +2728,7 @@ class ZodSet extends ZodType {
|
|
|
2325
2728
|
minimum: def.minSize.value,
|
|
2326
2729
|
type: "set",
|
|
2327
2730
|
inclusive: true,
|
|
2731
|
+
exact: false,
|
|
2328
2732
|
message: def.minSize.message,
|
|
2329
2733
|
});
|
|
2330
2734
|
status.dirty();
|
|
@@ -2337,6 +2741,7 @@ class ZodSet extends ZodType {
|
|
|
2337
2741
|
maximum: def.maxSize.value,
|
|
2338
2742
|
type: "set",
|
|
2339
2743
|
inclusive: true,
|
|
2744
|
+
exact: false,
|
|
2340
2745
|
message: def.maxSize.message,
|
|
2341
2746
|
});
|
|
2342
2747
|
status.dirty();
|
|
@@ -2532,6 +2937,7 @@ class ZodLiteral extends ZodType {
|
|
|
2532
2937
|
if (input.data !== this._def.value) {
|
|
2533
2938
|
const ctx = this._getOrReturnCtx(input);
|
|
2534
2939
|
addIssueToContext(ctx, {
|
|
2940
|
+
received: ctx.data,
|
|
2535
2941
|
code: ZodIssueCode.invalid_literal,
|
|
2536
2942
|
expected: this._def.value,
|
|
2537
2943
|
});
|
|
@@ -2605,6 +3011,12 @@ class ZodEnum extends ZodType {
|
|
|
2605
3011
|
}
|
|
2606
3012
|
return enumValues;
|
|
2607
3013
|
}
|
|
3014
|
+
extract(values) {
|
|
3015
|
+
return ZodEnum.create(values);
|
|
3016
|
+
}
|
|
3017
|
+
exclude(values) {
|
|
3018
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
|
|
3019
|
+
}
|
|
2608
3020
|
}
|
|
2609
3021
|
ZodEnum.create = createZodEnum;
|
|
2610
3022
|
class ZodNativeEnum extends ZodType {
|
|
@@ -2644,6 +3056,9 @@ ZodNativeEnum.create = (values, params) => {
|
|
|
2644
3056
|
});
|
|
2645
3057
|
};
|
|
2646
3058
|
class ZodPromise extends ZodType {
|
|
3059
|
+
unwrap() {
|
|
3060
|
+
return this._def.type;
|
|
3061
|
+
}
|
|
2647
3062
|
_parse(input) {
|
|
2648
3063
|
const { ctx } = this._processInputParams(input);
|
|
2649
3064
|
if (ctx.parsedType !== ZodParsedType.promise &&
|
|
@@ -2677,6 +3092,11 @@ class ZodEffects extends ZodType {
|
|
|
2677
3092
|
innerType() {
|
|
2678
3093
|
return this._def.schema;
|
|
2679
3094
|
}
|
|
3095
|
+
sourceType() {
|
|
3096
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
|
|
3097
|
+
? this._def.schema.sourceType()
|
|
3098
|
+
: this._def.schema;
|
|
3099
|
+
}
|
|
2680
3100
|
_parse(input) {
|
|
2681
3101
|
const { status, ctx } = this._processInputParams(input);
|
|
2682
3102
|
const effect = this._def.effect || null;
|
|
@@ -2863,9 +3283,53 @@ class ZodDefault extends ZodType {
|
|
|
2863
3283
|
}
|
|
2864
3284
|
}
|
|
2865
3285
|
ZodDefault.create = (type, params) => {
|
|
2866
|
-
return new
|
|
3286
|
+
return new ZodDefault({
|
|
2867
3287
|
innerType: type,
|
|
2868
|
-
typeName: ZodFirstPartyTypeKind.
|
|
3288
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3289
|
+
defaultValue: typeof params.default === "function"
|
|
3290
|
+
? params.default
|
|
3291
|
+
: () => params.default,
|
|
3292
|
+
...processCreateParams(params),
|
|
3293
|
+
});
|
|
3294
|
+
};
|
|
3295
|
+
class ZodCatch extends ZodType {
|
|
3296
|
+
_parse(input) {
|
|
3297
|
+
const { ctx } = this._processInputParams(input);
|
|
3298
|
+
const result = this._def.innerType._parse({
|
|
3299
|
+
data: ctx.data,
|
|
3300
|
+
path: ctx.path,
|
|
3301
|
+
parent: {
|
|
3302
|
+
...ctx,
|
|
3303
|
+
common: {
|
|
3304
|
+
...ctx.common,
|
|
3305
|
+
issues: [], // don't collect issues from inner type
|
|
3306
|
+
},
|
|
3307
|
+
},
|
|
3308
|
+
});
|
|
3309
|
+
if (isAsync(result)) {
|
|
3310
|
+
return result.then((result) => {
|
|
3311
|
+
return {
|
|
3312
|
+
status: "valid",
|
|
3313
|
+
value: result.status === "valid" ? result.value : this._def.catchValue(),
|
|
3314
|
+
};
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
else {
|
|
3318
|
+
return {
|
|
3319
|
+
status: "valid",
|
|
3320
|
+
value: result.status === "valid" ? result.value : this._def.catchValue(),
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
removeCatch() {
|
|
3325
|
+
return this._def.innerType;
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
ZodCatch.create = (type, params) => {
|
|
3329
|
+
return new ZodCatch({
|
|
3330
|
+
innerType: type,
|
|
3331
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3332
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
2869
3333
|
...processCreateParams(params),
|
|
2870
3334
|
});
|
|
2871
3335
|
};
|
|
@@ -2905,6 +3369,64 @@ class ZodBranded extends ZodType {
|
|
|
2905
3369
|
return this._def.type;
|
|
2906
3370
|
}
|
|
2907
3371
|
}
|
|
3372
|
+
class ZodPipeline extends ZodType {
|
|
3373
|
+
_parse(input) {
|
|
3374
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3375
|
+
if (ctx.common.async) {
|
|
3376
|
+
const handleAsync = async () => {
|
|
3377
|
+
const inResult = await this._def.in._parseAsync({
|
|
3378
|
+
data: ctx.data,
|
|
3379
|
+
path: ctx.path,
|
|
3380
|
+
parent: ctx,
|
|
3381
|
+
});
|
|
3382
|
+
if (inResult.status === "aborted")
|
|
3383
|
+
return INVALID;
|
|
3384
|
+
if (inResult.status === "dirty") {
|
|
3385
|
+
status.dirty();
|
|
3386
|
+
return DIRTY(inResult.value);
|
|
3387
|
+
}
|
|
3388
|
+
else {
|
|
3389
|
+
return this._def.out._parseAsync({
|
|
3390
|
+
data: inResult.value,
|
|
3391
|
+
path: ctx.path,
|
|
3392
|
+
parent: ctx,
|
|
3393
|
+
});
|
|
3394
|
+
}
|
|
3395
|
+
};
|
|
3396
|
+
return handleAsync();
|
|
3397
|
+
}
|
|
3398
|
+
else {
|
|
3399
|
+
const inResult = this._def.in._parseSync({
|
|
3400
|
+
data: ctx.data,
|
|
3401
|
+
path: ctx.path,
|
|
3402
|
+
parent: ctx,
|
|
3403
|
+
});
|
|
3404
|
+
if (inResult.status === "aborted")
|
|
3405
|
+
return INVALID;
|
|
3406
|
+
if (inResult.status === "dirty") {
|
|
3407
|
+
status.dirty();
|
|
3408
|
+
return {
|
|
3409
|
+
status: "dirty",
|
|
3410
|
+
value: inResult.value,
|
|
3411
|
+
};
|
|
3412
|
+
}
|
|
3413
|
+
else {
|
|
3414
|
+
return this._def.out._parseSync({
|
|
3415
|
+
data: inResult.value,
|
|
3416
|
+
path: ctx.path,
|
|
3417
|
+
parent: ctx,
|
|
3418
|
+
});
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
static create(a, b) {
|
|
3423
|
+
return new ZodPipeline({
|
|
3424
|
+
in: a,
|
|
3425
|
+
out: b,
|
|
3426
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline,
|
|
3427
|
+
});
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
2908
3430
|
const custom = (check, params = {}, fatal) => {
|
|
2909
3431
|
if (check)
|
|
2910
3432
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
@@ -2927,6 +3449,7 @@ var ZodFirstPartyTypeKind;
|
|
|
2927
3449
|
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
2928
3450
|
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
2929
3451
|
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
3452
|
+
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
2930
3453
|
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
2931
3454
|
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
2932
3455
|
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
@@ -2951,16 +3474,14 @@ var ZodFirstPartyTypeKind;
|
|
|
2951
3474
|
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
2952
3475
|
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
2953
3476
|
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3477
|
+
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
2954
3478
|
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
2955
3479
|
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
3480
|
+
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
2956
3481
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
2957
|
-
|
|
2958
|
-
//
|
|
2959
|
-
|
|
2960
|
-
// constructor(..._: any[]) {}
|
|
2961
|
-
// }
|
|
2962
|
-
// const instanceOfType = <T extends typeof Class>(
|
|
2963
|
-
const instanceOfType = (cls, params = {
|
|
3482
|
+
const instanceOfType = (
|
|
3483
|
+
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
|
3484
|
+
cls, params = {
|
|
2964
3485
|
message: `Input not instance of ${cls.name}`,
|
|
2965
3486
|
}) => custom((data) => data instanceof cls, params, true);
|
|
2966
3487
|
const stringType = ZodString.create;
|
|
@@ -2969,6 +3490,7 @@ const nanType = ZodNaN.create;
|
|
|
2969
3490
|
const bigIntType = ZodBigInt.create;
|
|
2970
3491
|
const booleanType = ZodBoolean.create;
|
|
2971
3492
|
const dateType = ZodDate.create;
|
|
3493
|
+
const symbolType = ZodSymbol.create;
|
|
2972
3494
|
const undefinedType = ZodUndefined.create;
|
|
2973
3495
|
const nullType = ZodNull.create;
|
|
2974
3496
|
const anyType = ZodAny.create;
|
|
@@ -2995,15 +3517,24 @@ const effectsType = ZodEffects.create;
|
|
|
2995
3517
|
const optionalType = ZodOptional.create;
|
|
2996
3518
|
const nullableType = ZodNullable.create;
|
|
2997
3519
|
const preprocessType = ZodEffects.createWithPreprocess;
|
|
3520
|
+
const pipelineType = ZodPipeline.create;
|
|
2998
3521
|
const ostring = () => stringType().optional();
|
|
2999
3522
|
const onumber = () => numberType().optional();
|
|
3000
3523
|
const oboolean = () => booleanType().optional();
|
|
3524
|
+
const coerce = {
|
|
3525
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
3526
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
3527
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
3528
|
+
...arg,
|
|
3529
|
+
coerce: true,
|
|
3530
|
+
})),
|
|
3531
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
3532
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
|
|
3533
|
+
};
|
|
3001
3534
|
const NEVER = INVALID;
|
|
3002
3535
|
|
|
3003
3536
|
var mod = /*#__PURE__*/Object.freeze({
|
|
3004
3537
|
__proto__: null,
|
|
3005
|
-
getParsedType: getParsedType,
|
|
3006
|
-
ZodParsedType: ZodParsedType,
|
|
3007
3538
|
defaultErrorMap: errorMap,
|
|
3008
3539
|
setErrorMap: setErrorMap,
|
|
3009
3540
|
getErrorMap: getErrorMap,
|
|
@@ -3018,12 +3549,16 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3018
3549
|
isDirty: isDirty,
|
|
3019
3550
|
isValid: isValid,
|
|
3020
3551
|
isAsync: isAsync,
|
|
3552
|
+
get util () { return util; },
|
|
3553
|
+
ZodParsedType: ZodParsedType,
|
|
3554
|
+
getParsedType: getParsedType,
|
|
3021
3555
|
ZodType: ZodType,
|
|
3022
3556
|
ZodString: ZodString,
|
|
3023
3557
|
ZodNumber: ZodNumber,
|
|
3024
3558
|
ZodBigInt: ZodBigInt,
|
|
3025
3559
|
ZodBoolean: ZodBoolean,
|
|
3026
3560
|
ZodDate: ZodDate,
|
|
3561
|
+
ZodSymbol: ZodSymbol,
|
|
3027
3562
|
ZodUndefined: ZodUndefined,
|
|
3028
3563
|
ZodNull: ZodNull,
|
|
3029
3564
|
ZodAny: ZodAny,
|
|
@@ -3051,14 +3586,17 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3051
3586
|
ZodOptional: ZodOptional,
|
|
3052
3587
|
ZodNullable: ZodNullable,
|
|
3053
3588
|
ZodDefault: ZodDefault,
|
|
3589
|
+
ZodCatch: ZodCatch,
|
|
3054
3590
|
ZodNaN: ZodNaN,
|
|
3055
3591
|
BRAND: BRAND,
|
|
3056
3592
|
ZodBranded: ZodBranded,
|
|
3593
|
+
ZodPipeline: ZodPipeline,
|
|
3057
3594
|
custom: custom,
|
|
3058
3595
|
Schema: ZodType,
|
|
3059
3596
|
ZodSchema: ZodType,
|
|
3060
3597
|
late: late,
|
|
3061
3598
|
get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
|
|
3599
|
+
coerce: coerce,
|
|
3062
3600
|
any: anyType,
|
|
3063
3601
|
array: arrayType,
|
|
3064
3602
|
bigint: bigIntType,
|
|
@@ -3084,12 +3622,14 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3084
3622
|
onumber: onumber,
|
|
3085
3623
|
optional: optionalType,
|
|
3086
3624
|
ostring: ostring,
|
|
3625
|
+
pipeline: pipelineType,
|
|
3087
3626
|
preprocess: preprocessType,
|
|
3088
3627
|
promise: promiseType,
|
|
3089
3628
|
record: recordType,
|
|
3090
3629
|
set: setType,
|
|
3091
3630
|
strictObject: strictObjectType,
|
|
3092
3631
|
string: stringType,
|
|
3632
|
+
symbol: symbolType,
|
|
3093
3633
|
transformer: effectsType,
|
|
3094
3634
|
tuple: tupleType,
|
|
3095
3635
|
'undefined': undefinedType,
|
|
@@ -3424,13 +3964,61 @@ mod.object({
|
|
|
3424
3964
|
credentialSubject: CredentialSubjectValidator.optional()
|
|
3425
3965
|
});
|
|
3426
3966
|
mod.object({ id: mod.string(), uri: mod.string() }).catchall(mod.any());
|
|
3967
|
+
var LCNProfileValidator = mod.object({
|
|
3968
|
+
profileId: mod.string().min(3).max(40),
|
|
3969
|
+
displayName: mod.string().default(""),
|
|
3970
|
+
did: mod.string(),
|
|
3971
|
+
email: mod.string().optional(),
|
|
3972
|
+
image: mod.string().optional(),
|
|
3973
|
+
isServiceProfile: mod.boolean().default(false).optional()
|
|
3974
|
+
});
|
|
3427
3975
|
mod.object({
|
|
3976
|
+
uri: mod.string(),
|
|
3977
|
+
to: mod.string(),
|
|
3978
|
+
from: mod.string(),
|
|
3979
|
+
sent: mod.string().datetime(),
|
|
3980
|
+
received: mod.string().datetime().optional()
|
|
3981
|
+
});
|
|
3982
|
+
mod.object({
|
|
3983
|
+
uri: mod.string(),
|
|
3984
|
+
name: mod.string().optional(),
|
|
3985
|
+
type: mod.string().optional(),
|
|
3986
|
+
category: mod.string().optional()
|
|
3987
|
+
});
|
|
3988
|
+
mod.object({
|
|
3989
|
+
to: LCNProfileValidator,
|
|
3990
|
+
from: mod.string(),
|
|
3991
|
+
received: mod.string()
|
|
3992
|
+
});
|
|
3993
|
+
var JWKValidator = mod.object({
|
|
3428
3994
|
kty: mod.string(),
|
|
3429
3995
|
crv: mod.string(),
|
|
3430
3996
|
x: mod.string(),
|
|
3431
3997
|
y: mod.string().optional(),
|
|
3998
|
+
n: mod.string().optional(),
|
|
3432
3999
|
d: mod.string()
|
|
3433
4000
|
});
|
|
4001
|
+
var JWERecipientHeaderValidator = mod.object({
|
|
4002
|
+
alg: mod.string(),
|
|
4003
|
+
iv: mod.string(),
|
|
4004
|
+
tag: mod.string(),
|
|
4005
|
+
epk: JWKValidator.partial().optional(),
|
|
4006
|
+
kid: mod.string().optional(),
|
|
4007
|
+
apv: mod.string().optional(),
|
|
4008
|
+
apu: mod.string().optional()
|
|
4009
|
+
});
|
|
4010
|
+
var JWERecipientValidator = mod.object({
|
|
4011
|
+
header: JWERecipientHeaderValidator,
|
|
4012
|
+
encrypted_key: mod.string()
|
|
4013
|
+
});
|
|
4014
|
+
mod.object({
|
|
4015
|
+
protected: mod.string(),
|
|
4016
|
+
iv: mod.string(),
|
|
4017
|
+
ciphertext: mod.string(),
|
|
4018
|
+
tag: mod.string(),
|
|
4019
|
+
aad: mod.string().optional(),
|
|
4020
|
+
recipients: JWERecipientValidator.array().optional()
|
|
4021
|
+
});
|
|
3434
4022
|
|
|
3435
4023
|
exports.VerificationStatusEnum = VerificationStatusEnum;
|
|
3436
|
-
//# sourceMappingURL=types.esm-
|
|
4024
|
+
//# sourceMappingURL=types.esm-fa693b17.js.map
|