@aws-amplify/graphql-api-construct 1.1.3 → 1.1.4
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/.jsii +34 -34
- package/CHANGELOG.md +8 -0
- package/README.md +9 -3
- package/lib/amplify-graphql-api.d.ts +9 -3
- package/lib/amplify-graphql-api.js +11 -5
- package/lib/amplify-graphql-definition.js +1 -1
- package/lib/internal/codegen-assets.js +6 -1
- package/node_modules/@aws-amplify/graphql-auth-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-auth-transformer/package.json +8 -8
- package/node_modules/@aws-amplify/graphql-default-value-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-default-value-transformer/package.json +5 -5
- package/node_modules/@aws-amplify/graphql-function-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-function-transformer/package.json +4 -4
- package/node_modules/@aws-amplify/graphql-http-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-http-transformer/package.json +4 -4
- package/node_modules/@aws-amplify/graphql-index-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-index-transformer/package.json +5 -5
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/assets/mapping-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/package.json +8 -8
- package/node_modules/@aws-amplify/graphql-model-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-notification-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-patching-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/package.json +4 -4
- package/node_modules/@aws-amplify/graphql-predictions-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-predictions-transformer/lib/predictionsLambdaFunction.zip +0 -0
- package/node_modules/@aws-amplify/graphql-predictions-transformer/package.json +4 -4
- package/node_modules/@aws-amplify/graphql-relational-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-relational-transformer/package.json +6 -6
- package/node_modules/@aws-amplify/graphql-searchable-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/streaming-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-searchable-transformer/package.json +5 -5
- package/node_modules/@aws-amplify/graphql-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-transformer/package.json +13 -13
- package/node_modules/@aws-amplify/graphql-transformer-core/API.md +1 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.d.ts +8 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.js +60 -23
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.d.ts +4 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.js +35 -36
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/package.json +2 -2
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/package.json +1 -2
- package/node_modules/zod/README.md +215 -120
- package/node_modules/zod/lib/ZodError.js +8 -0
- package/node_modules/zod/lib/helpers/parseUtil.js +3 -2
- package/node_modules/zod/lib/helpers/util.js +4 -4
- package/node_modules/zod/lib/index.mjs +121 -57
- package/node_modules/zod/lib/index.umd.js +121 -56
- package/node_modules/zod/lib/types.d.ts +55 -10
- package/node_modules/zod/lib/types.js +301 -58
- package/node_modules/zod/package.json +29 -15
- package/package.json +15 -15
- package/src/amplify-graphql-api.ts +9 -3
- package/src/internal/codegen-assets.ts +5 -0
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/LICENSE +0 -201
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = void 0;
|
3
|
+
exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
|
4
|
+
exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = void 0;
|
5
5
|
const errors_1 = require("./errors");
|
6
6
|
const errorUtil_1 = require("./helpers/errorUtil");
|
7
7
|
const parseUtil_1 = require("./helpers/parseUtil");
|
@@ -68,6 +68,7 @@ function processCreateParams(params) {
|
|
68
68
|
}
|
69
69
|
class ZodType {
|
70
70
|
constructor(def) {
|
71
|
+
/** Alias of safeParseAsync */
|
71
72
|
this.spa = this.safeParseAsync;
|
72
73
|
this._def = def;
|
73
74
|
this.parse = this.parse.bind(this);
|
@@ -91,6 +92,7 @@ class ZodType {
|
|
91
92
|
this.catch = this.catch.bind(this);
|
92
93
|
this.describe = this.describe.bind(this);
|
93
94
|
this.pipe = this.pipe.bind(this);
|
95
|
+
this.readonly = this.readonly.bind(this);
|
94
96
|
this.isNullable = this.isNullable.bind(this);
|
95
97
|
this.isOptional = this.isOptional.bind(this);
|
96
98
|
}
|
@@ -307,6 +309,9 @@ class ZodType {
|
|
307
309
|
pipe(target) {
|
308
310
|
return ZodPipeline.create(this, target);
|
309
311
|
}
|
312
|
+
readonly() {
|
313
|
+
return ZodReadonly.create(this);
|
314
|
+
}
|
310
315
|
isOptional() {
|
311
316
|
return this.safeParse(undefined).success;
|
312
317
|
}
|
@@ -319,12 +324,31 @@ exports.Schema = ZodType;
|
|
319
324
|
exports.ZodSchema = ZodType;
|
320
325
|
const cuidRegex = /^c[^\s-]{8,}$/i;
|
321
326
|
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
322
|
-
const ulidRegex =
|
323
|
-
const uuidRegex =
|
324
|
-
|
325
|
-
const
|
327
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
328
|
+
// const uuidRegex =
|
329
|
+
// /^([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;
|
330
|
+
const 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;
|
331
|
+
// from https://stackoverflow.com/a/46181/1550155
|
332
|
+
// old version: too slow, didn't support unicode
|
333
|
+
// 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;
|
334
|
+
//old email regex
|
335
|
+
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
336
|
+
// eslint-disable-next-line
|
337
|
+
// const emailRegex =
|
338
|
+
// /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((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}))\])|(\[IPv6:(([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})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
|
339
|
+
// const emailRegex =
|
340
|
+
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
341
|
+
// const emailRegex =
|
342
|
+
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
343
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
344
|
+
// const emailRegex =
|
345
|
+
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
346
|
+
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
347
|
+
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
348
|
+
let emojiRegex;
|
326
349
|
const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
327
350
|
const 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})))$/;
|
351
|
+
// Adapted from https://stackoverflow.com/a/3143231
|
328
352
|
const datetimeRegex = (args) => {
|
329
353
|
if (args.precision) {
|
330
354
|
if (args.offset) {
|
@@ -361,27 +385,6 @@ function isValidIP(ip, version) {
|
|
361
385
|
return false;
|
362
386
|
}
|
363
387
|
class ZodString extends ZodType {
|
364
|
-
constructor() {
|
365
|
-
super(...arguments);
|
366
|
-
this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
|
367
|
-
validation,
|
368
|
-
code: ZodError_1.ZodIssueCode.invalid_string,
|
369
|
-
...errorUtil_1.errorUtil.errToObj(message),
|
370
|
-
});
|
371
|
-
this.nonempty = (message) => this.min(1, errorUtil_1.errorUtil.errToObj(message));
|
372
|
-
this.trim = () => new ZodString({
|
373
|
-
...this._def,
|
374
|
-
checks: [...this._def.checks, { kind: "trim" }],
|
375
|
-
});
|
376
|
-
this.toLowerCase = () => new ZodString({
|
377
|
-
...this._def,
|
378
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }],
|
379
|
-
});
|
380
|
-
this.toUpperCase = () => new ZodString({
|
381
|
-
...this._def,
|
382
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }],
|
383
|
-
});
|
384
|
-
}
|
385
388
|
_parse(input) {
|
386
389
|
if (this._def.coerce) {
|
387
390
|
input.data = String(input.data);
|
@@ -393,7 +396,9 @@ class ZodString extends ZodType {
|
|
393
396
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
394
397
|
expected: util_1.ZodParsedType.string,
|
395
398
|
received: ctx.parsedType,
|
396
|
-
}
|
399
|
+
}
|
400
|
+
//
|
401
|
+
);
|
397
402
|
return parseUtil_1.INVALID;
|
398
403
|
}
|
399
404
|
const status = new parseUtil_1.ParseStatus();
|
@@ -467,6 +472,9 @@ class ZodString extends ZodType {
|
|
467
472
|
}
|
468
473
|
}
|
469
474
|
else if (check.kind === "emoji") {
|
475
|
+
if (!emojiRegex) {
|
476
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
477
|
+
}
|
470
478
|
if (!emojiRegex.test(input.data)) {
|
471
479
|
ctx = this._getOrReturnCtx(input, ctx);
|
472
480
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
@@ -619,6 +627,13 @@ class ZodString extends ZodType {
|
|
619
627
|
}
|
620
628
|
return { status: status.value, value: input.data };
|
621
629
|
}
|
630
|
+
_regex(regex, validation, message) {
|
631
|
+
return this.refinement((data) => regex.test(data), {
|
632
|
+
validation,
|
633
|
+
code: ZodError_1.ZodIssueCode.invalid_string,
|
634
|
+
...errorUtil_1.errorUtil.errToObj(message),
|
635
|
+
});
|
636
|
+
}
|
622
637
|
_addCheck(check) {
|
623
638
|
return new ZodString({
|
624
639
|
...this._def,
|
@@ -716,6 +731,31 @@ class ZodString extends ZodType {
|
|
716
731
|
...errorUtil_1.errorUtil.errToObj(message),
|
717
732
|
});
|
718
733
|
}
|
734
|
+
/**
|
735
|
+
* @deprecated Use z.string().min(1) instead.
|
736
|
+
* @see {@link ZodString.min}
|
737
|
+
*/
|
738
|
+
nonempty(message) {
|
739
|
+
return this.min(1, errorUtil_1.errorUtil.errToObj(message));
|
740
|
+
}
|
741
|
+
trim() {
|
742
|
+
return new ZodString({
|
743
|
+
...this._def,
|
744
|
+
checks: [...this._def.checks, { kind: "trim" }],
|
745
|
+
});
|
746
|
+
}
|
747
|
+
toLowerCase() {
|
748
|
+
return new ZodString({
|
749
|
+
...this._def,
|
750
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }],
|
751
|
+
});
|
752
|
+
}
|
753
|
+
toUpperCase() {
|
754
|
+
return new ZodString({
|
755
|
+
...this._def,
|
756
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }],
|
757
|
+
});
|
758
|
+
}
|
719
759
|
get isDatetime() {
|
720
760
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
721
761
|
}
|
@@ -774,6 +814,7 @@ ZodString.create = (params) => {
|
|
774
814
|
...processCreateParams(params),
|
775
815
|
});
|
776
816
|
};
|
817
|
+
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
777
818
|
function floatSafeRemainder(val, step) {
|
778
819
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
779
820
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
@@ -1409,6 +1450,7 @@ ZodNull.create = (params) => {
|
|
1409
1450
|
class ZodAny extends ZodType {
|
1410
1451
|
constructor() {
|
1411
1452
|
super(...arguments);
|
1453
|
+
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
1412
1454
|
this._any = true;
|
1413
1455
|
}
|
1414
1456
|
_parse(input) {
|
@@ -1425,6 +1467,7 @@ ZodAny.create = (params) => {
|
|
1425
1467
|
class ZodUnknown extends ZodType {
|
1426
1468
|
constructor() {
|
1427
1469
|
super(...arguments);
|
1470
|
+
// required
|
1428
1471
|
this._unknown = true;
|
1429
1472
|
}
|
1430
1473
|
_parse(input) {
|
@@ -1615,7 +1658,47 @@ class ZodObject extends ZodType {
|
|
1615
1658
|
constructor() {
|
1616
1659
|
super(...arguments);
|
1617
1660
|
this._cached = null;
|
1661
|
+
/**
|
1662
|
+
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
1663
|
+
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
1664
|
+
*/
|
1618
1665
|
this.nonstrict = this.passthrough;
|
1666
|
+
// extend<
|
1667
|
+
// Augmentation extends ZodRawShape,
|
1668
|
+
// NewOutput extends util.flatten<{
|
1669
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
1670
|
+
// ? Augmentation[k]["_output"]
|
1671
|
+
// : k extends keyof Output
|
1672
|
+
// ? Output[k]
|
1673
|
+
// : never;
|
1674
|
+
// }>,
|
1675
|
+
// NewInput extends util.flatten<{
|
1676
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
1677
|
+
// ? Augmentation[k]["_input"]
|
1678
|
+
// : k extends keyof Input
|
1679
|
+
// ? Input[k]
|
1680
|
+
// : never;
|
1681
|
+
// }>
|
1682
|
+
// >(
|
1683
|
+
// augmentation: Augmentation
|
1684
|
+
// ): ZodObject<
|
1685
|
+
// extendShape<T, Augmentation>,
|
1686
|
+
// UnknownKeys,
|
1687
|
+
// Catchall,
|
1688
|
+
// NewOutput,
|
1689
|
+
// NewInput
|
1690
|
+
// > {
|
1691
|
+
// return new ZodObject({
|
1692
|
+
// ...this._def,
|
1693
|
+
// shape: () => ({
|
1694
|
+
// ...this._def.shape(),
|
1695
|
+
// ...augmentation,
|
1696
|
+
// }),
|
1697
|
+
// }) as any;
|
1698
|
+
// }
|
1699
|
+
/**
|
1700
|
+
* @deprecated Use `.extend` instead
|
1701
|
+
* */
|
1619
1702
|
this.augment = this.extend;
|
1620
1703
|
}
|
1621
1704
|
_getCached() {
|
@@ -1683,12 +1766,14 @@ class ZodObject extends ZodType {
|
|
1683
1766
|
}
|
1684
1767
|
}
|
1685
1768
|
else {
|
1769
|
+
// run catchall validation
|
1686
1770
|
const catchall = this._def.catchall;
|
1687
1771
|
for (const key of extraKeys) {
|
1688
1772
|
const value = ctx.data[key];
|
1689
1773
|
pairs.push({
|
1690
1774
|
key: { status: "valid", value: key },
|
1691
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
1775
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
1776
|
+
),
|
1692
1777
|
alwaysSet: key in ctx.data,
|
1693
1778
|
});
|
1694
1779
|
}
|
@@ -1752,6 +1837,23 @@ class ZodObject extends ZodType {
|
|
1752
1837
|
unknownKeys: "passthrough",
|
1753
1838
|
});
|
1754
1839
|
}
|
1840
|
+
// const AugmentFactory =
|
1841
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
1842
|
+
// <Augmentation extends ZodRawShape>(
|
1843
|
+
// augmentation: Augmentation
|
1844
|
+
// ): ZodObject<
|
1845
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
1846
|
+
// Def["unknownKeys"],
|
1847
|
+
// Def["catchall"]
|
1848
|
+
// > => {
|
1849
|
+
// return new ZodObject({
|
1850
|
+
// ...def,
|
1851
|
+
// shape: () => ({
|
1852
|
+
// ...def.shape(),
|
1853
|
+
// ...augmentation,
|
1854
|
+
// }),
|
1855
|
+
// }) as any;
|
1856
|
+
// };
|
1755
1857
|
extend(augmentation) {
|
1756
1858
|
return new ZodObject({
|
1757
1859
|
...this._def,
|
@@ -1761,6 +1863,11 @@ class ZodObject extends ZodType {
|
|
1761
1863
|
}),
|
1762
1864
|
});
|
1763
1865
|
}
|
1866
|
+
/**
|
1867
|
+
* Prior to zod@1.0.12 there was a bug in the
|
1868
|
+
* inferred type of merged objects. Please
|
1869
|
+
* upgrade if you are experiencing issues.
|
1870
|
+
*/
|
1764
1871
|
merge(merging) {
|
1765
1872
|
const merged = new ZodObject({
|
1766
1873
|
unknownKeys: merging._def.unknownKeys,
|
@@ -1773,9 +1880,65 @@ class ZodObject extends ZodType {
|
|
1773
1880
|
});
|
1774
1881
|
return merged;
|
1775
1882
|
}
|
1883
|
+
// merge<
|
1884
|
+
// Incoming extends AnyZodObject,
|
1885
|
+
// Augmentation extends Incoming["shape"],
|
1886
|
+
// NewOutput extends {
|
1887
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
1888
|
+
// ? Augmentation[k]["_output"]
|
1889
|
+
// : k extends keyof Output
|
1890
|
+
// ? Output[k]
|
1891
|
+
// : never;
|
1892
|
+
// },
|
1893
|
+
// NewInput extends {
|
1894
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
1895
|
+
// ? Augmentation[k]["_input"]
|
1896
|
+
// : k extends keyof Input
|
1897
|
+
// ? Input[k]
|
1898
|
+
// : never;
|
1899
|
+
// }
|
1900
|
+
// >(
|
1901
|
+
// merging: Incoming
|
1902
|
+
// ): ZodObject<
|
1903
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
1904
|
+
// Incoming["_def"]["unknownKeys"],
|
1905
|
+
// Incoming["_def"]["catchall"],
|
1906
|
+
// NewOutput,
|
1907
|
+
// NewInput
|
1908
|
+
// > {
|
1909
|
+
// const merged: any = new ZodObject({
|
1910
|
+
// unknownKeys: merging._def.unknownKeys,
|
1911
|
+
// catchall: merging._def.catchall,
|
1912
|
+
// shape: () =>
|
1913
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
1914
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
1915
|
+
// }) as any;
|
1916
|
+
// return merged;
|
1917
|
+
// }
|
1776
1918
|
setKey(key, schema) {
|
1777
1919
|
return this.augment({ [key]: schema });
|
1778
1920
|
}
|
1921
|
+
// merge<Incoming extends AnyZodObject>(
|
1922
|
+
// merging: Incoming
|
1923
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
1924
|
+
// ZodObject<
|
1925
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
1926
|
+
// Incoming["_def"]["unknownKeys"],
|
1927
|
+
// Incoming["_def"]["catchall"]
|
1928
|
+
// > {
|
1929
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
1930
|
+
// // this._def.shape(),
|
1931
|
+
// // merging._def.shape()
|
1932
|
+
// // );
|
1933
|
+
// const merged: any = new ZodObject({
|
1934
|
+
// unknownKeys: merging._def.unknownKeys,
|
1935
|
+
// catchall: merging._def.catchall,
|
1936
|
+
// shape: () =>
|
1937
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
1938
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
1939
|
+
// }) as any;
|
1940
|
+
// return merged;
|
1941
|
+
// }
|
1779
1942
|
catchall(index) {
|
1780
1943
|
return new ZodObject({
|
1781
1944
|
...this._def,
|
@@ -1806,6 +1969,9 @@ class ZodObject extends ZodType {
|
|
1806
1969
|
shape: () => shape,
|
1807
1970
|
});
|
1808
1971
|
}
|
1972
|
+
/**
|
1973
|
+
* @deprecated
|
1974
|
+
*/
|
1809
1975
|
deepPartial() {
|
1810
1976
|
return deepPartialify(this);
|
1811
1977
|
}
|
@@ -1882,6 +2048,7 @@ class ZodUnion extends ZodType {
|
|
1882
2048
|
const { ctx } = this._processInputParams(input);
|
1883
2049
|
const options = this._def.options;
|
1884
2050
|
function handleResults(results) {
|
2051
|
+
// return first issue-free validation if it exists
|
1885
2052
|
for (const result of results) {
|
1886
2053
|
if (result.result.status === "valid") {
|
1887
2054
|
return result.result;
|
@@ -1889,10 +2056,12 @@ class ZodUnion extends ZodType {
|
|
1889
2056
|
}
|
1890
2057
|
for (const result of results) {
|
1891
2058
|
if (result.result.status === "dirty") {
|
2059
|
+
// add issues from dirty option
|
1892
2060
|
ctx.common.issues.push(...result.ctx.common.issues);
|
1893
2061
|
return result.result;
|
1894
2062
|
}
|
1895
2063
|
}
|
2064
|
+
// return invalid
|
1896
2065
|
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
|
1897
2066
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
1898
2067
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
@@ -1971,6 +2140,13 @@ ZodUnion.create = (types, params) => {
|
|
1971
2140
|
...processCreateParams(params),
|
1972
2141
|
});
|
1973
2142
|
};
|
2143
|
+
/////////////////////////////////////////////////////
|
2144
|
+
/////////////////////////////////////////////////////
|
2145
|
+
////////// //////////
|
2146
|
+
////////// ZodDiscriminatedUnion //////////
|
2147
|
+
////////// //////////
|
2148
|
+
/////////////////////////////////////////////////////
|
2149
|
+
/////////////////////////////////////////////////////
|
1974
2150
|
const getDiscriminator = (type) => {
|
1975
2151
|
if (type instanceof ZodLazy) {
|
1976
2152
|
return getDiscriminator(type.schema);
|
@@ -1985,6 +2161,7 @@ const getDiscriminator = (type) => {
|
|
1985
2161
|
return type.options;
|
1986
2162
|
}
|
1987
2163
|
else if (type instanceof ZodNativeEnum) {
|
2164
|
+
// eslint-disable-next-line ban/ban
|
1988
2165
|
return Object.keys(type.enum);
|
1989
2166
|
}
|
1990
2167
|
else if (type instanceof ZodDefault) {
|
@@ -2046,8 +2223,18 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
2046
2223
|
get optionsMap() {
|
2047
2224
|
return this._def.optionsMap;
|
2048
2225
|
}
|
2226
|
+
/**
|
2227
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
2228
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
2229
|
+
* have a different value for each object in the union.
|
2230
|
+
* @param discriminator the name of the discriminator property
|
2231
|
+
* @param types an array of object schemas
|
2232
|
+
* @param params
|
2233
|
+
*/
|
2049
2234
|
static create(discriminator, options, params) {
|
2235
|
+
// Get all the valid discriminator values
|
2050
2236
|
const optionsMap = new Map();
|
2237
|
+
// try {
|
2051
2238
|
for (const type of options) {
|
2052
2239
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
2053
2240
|
if (!discriminatorValues) {
|
@@ -2210,7 +2397,7 @@ class ZodTuple extends ZodType {
|
|
2210
2397
|
return null;
|
2211
2398
|
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
2212
2399
|
})
|
2213
|
-
.filter((x) => !!x);
|
2400
|
+
.filter((x) => !!x); // filter nulls
|
2214
2401
|
if (ctx.common.async) {
|
2215
2402
|
return Promise.all(items).then((results) => {
|
2216
2403
|
return parseUtil_1.ParseStatus.mergeArray(status, results);
|
@@ -2297,6 +2484,12 @@ class ZodRecord extends ZodType {
|
|
2297
2484
|
}
|
2298
2485
|
exports.ZodRecord = ZodRecord;
|
2299
2486
|
class ZodMap extends ZodType {
|
2487
|
+
get keySchema() {
|
2488
|
+
return this._def.keyType;
|
2489
|
+
}
|
2490
|
+
get valueSchema() {
|
2491
|
+
return this._def.valueType;
|
2492
|
+
}
|
2300
2493
|
_parse(input) {
|
2301
2494
|
const { status, ctx } = this._processInputParams(input);
|
2302
2495
|
if (ctx.parsedType !== util_1.ZodParsedType.map) {
|
@@ -2495,16 +2688,20 @@ class ZodFunction extends ZodType {
|
|
2495
2688
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
2496
2689
|
const fn = ctx.data;
|
2497
2690
|
if (this._def.returns instanceof ZodPromise) {
|
2498
|
-
|
2691
|
+
// Would love a way to avoid disabling this rule, but we need
|
2692
|
+
// an alias (using an arrow function was what caused 2651).
|
2693
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
2694
|
+
const me = this;
|
2695
|
+
return (0, parseUtil_1.OK)(async function (...args) {
|
2499
2696
|
const error = new ZodError_1.ZodError([]);
|
2500
|
-
const parsedArgs = await
|
2697
|
+
const parsedArgs = await me._def.args
|
2501
2698
|
.parseAsync(args, params)
|
2502
2699
|
.catch((e) => {
|
2503
2700
|
error.addIssue(makeArgsIssue(args, e));
|
2504
2701
|
throw error;
|
2505
2702
|
});
|
2506
|
-
const result = await fn
|
2507
|
-
const parsedReturns = await
|
2703
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
2704
|
+
const parsedReturns = await me._def.returns._def.type
|
2508
2705
|
.parseAsync(result, params)
|
2509
2706
|
.catch((e) => {
|
2510
2707
|
error.addIssue(makeReturnsIssue(result, e));
|
@@ -2514,13 +2711,17 @@ class ZodFunction extends ZodType {
|
|
2514
2711
|
});
|
2515
2712
|
}
|
2516
2713
|
else {
|
2517
|
-
|
2518
|
-
|
2714
|
+
// Would love a way to avoid disabling this rule, but we need
|
2715
|
+
// an alias (using an arrow function was what caused 2651).
|
2716
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
2717
|
+
const me = this;
|
2718
|
+
return (0, parseUtil_1.OK)(function (...args) {
|
2719
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
2519
2720
|
if (!parsedArgs.success) {
|
2520
2721
|
throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
2521
2722
|
}
|
2522
|
-
const result = fn
|
2523
|
-
const parsedReturns =
|
2723
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
2724
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
2524
2725
|
if (!parsedReturns.success) {
|
2525
2726
|
throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
2526
2727
|
}
|
@@ -2611,7 +2812,7 @@ ZodLiteral.create = (value, params) => {
|
|
2611
2812
|
};
|
2612
2813
|
function createZodEnum(values, params) {
|
2613
2814
|
return new ZodEnum({
|
2614
|
-
values
|
2815
|
+
values,
|
2615
2816
|
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
2616
2817
|
...processCreateParams(params),
|
2617
2818
|
});
|
@@ -2756,8 +2957,29 @@ class ZodEffects extends ZodType {
|
|
2756
2957
|
_parse(input) {
|
2757
2958
|
const { status, ctx } = this._processInputParams(input);
|
2758
2959
|
const effect = this._def.effect || null;
|
2960
|
+
const checkCtx = {
|
2961
|
+
addIssue: (arg) => {
|
2962
|
+
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
2963
|
+
if (arg.fatal) {
|
2964
|
+
status.abort();
|
2965
|
+
}
|
2966
|
+
else {
|
2967
|
+
status.dirty();
|
2968
|
+
}
|
2969
|
+
},
|
2970
|
+
get path() {
|
2971
|
+
return ctx.path;
|
2972
|
+
},
|
2973
|
+
};
|
2974
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
2759
2975
|
if (effect.type === "preprocess") {
|
2760
|
-
const processed = effect.transform(ctx.data);
|
2976
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
2977
|
+
if (ctx.common.issues.length) {
|
2978
|
+
return {
|
2979
|
+
status: "dirty",
|
2980
|
+
value: ctx.data,
|
2981
|
+
};
|
2982
|
+
}
|
2761
2983
|
if (ctx.common.async) {
|
2762
2984
|
return Promise.resolve(processed).then((processed) => {
|
2763
2985
|
return this._def.schema._parseAsync({
|
@@ -2775,23 +2997,10 @@ class ZodEffects extends ZodType {
|
|
2775
2997
|
});
|
2776
2998
|
}
|
2777
2999
|
}
|
2778
|
-
const checkCtx = {
|
2779
|
-
addIssue: (arg) => {
|
2780
|
-
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
2781
|
-
if (arg.fatal) {
|
2782
|
-
status.abort();
|
2783
|
-
}
|
2784
|
-
else {
|
2785
|
-
status.dirty();
|
2786
|
-
}
|
2787
|
-
},
|
2788
|
-
get path() {
|
2789
|
-
return ctx.path;
|
2790
|
-
},
|
2791
|
-
};
|
2792
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
2793
3000
|
if (effect.type === "refinement") {
|
2794
|
-
const executeRefinement = (acc
|
3001
|
+
const executeRefinement = (acc
|
3002
|
+
// effect: RefinementEffect<any>
|
3003
|
+
) => {
|
2795
3004
|
const result = effect.refinement(acc, checkCtx);
|
2796
3005
|
if (ctx.common.async) {
|
2797
3006
|
return Promise.resolve(result);
|
@@ -2811,6 +3020,7 @@ class ZodEffects extends ZodType {
|
|
2811
3020
|
return parseUtil_1.INVALID;
|
2812
3021
|
if (inner.status === "dirty")
|
2813
3022
|
status.dirty();
|
3023
|
+
// return value is ignored
|
2814
3024
|
executeRefinement(inner.value);
|
2815
3025
|
return { status: status.value, value: inner.value };
|
2816
3026
|
}
|
@@ -2945,6 +3155,7 @@ ZodDefault.create = (type, params) => {
|
|
2945
3155
|
class ZodCatch extends ZodType {
|
2946
3156
|
_parse(input) {
|
2947
3157
|
const { ctx } = this._processInputParams(input);
|
3158
|
+
// newCtx is used to not collect issues from inner types in ctx
|
2948
3159
|
const newCtx = {
|
2949
3160
|
...ctx,
|
2950
3161
|
common: {
|
@@ -3098,7 +3309,35 @@ class ZodPipeline extends ZodType {
|
|
3098
3309
|
}
|
3099
3310
|
}
|
3100
3311
|
exports.ZodPipeline = ZodPipeline;
|
3101
|
-
|
3312
|
+
class ZodReadonly extends ZodType {
|
3313
|
+
_parse(input) {
|
3314
|
+
const result = this._def.innerType._parse(input);
|
3315
|
+
if ((0, parseUtil_1.isValid)(result)) {
|
3316
|
+
result.value = Object.freeze(result.value);
|
3317
|
+
}
|
3318
|
+
return result;
|
3319
|
+
}
|
3320
|
+
}
|
3321
|
+
exports.ZodReadonly = ZodReadonly;
|
3322
|
+
ZodReadonly.create = (type, params) => {
|
3323
|
+
return new ZodReadonly({
|
3324
|
+
innerType: type,
|
3325
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
3326
|
+
...processCreateParams(params),
|
3327
|
+
});
|
3328
|
+
};
|
3329
|
+
const custom = (check, params = {},
|
3330
|
+
/**
|
3331
|
+
* @deprecated
|
3332
|
+
*
|
3333
|
+
* Pass `fatal` into the params object instead:
|
3334
|
+
*
|
3335
|
+
* ```ts
|
3336
|
+
* z.string().custom((val) => val.length > 5, { fatal: false })
|
3337
|
+
* ```
|
3338
|
+
*
|
3339
|
+
*/
|
3340
|
+
fatal) => {
|
3102
3341
|
if (check)
|
3103
3342
|
return ZodAny.create().superRefine((data, ctx) => {
|
3104
3343
|
var _a, _b;
|
@@ -3156,11 +3395,15 @@ var ZodFirstPartyTypeKind;
|
|
3156
3395
|
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
3157
3396
|
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
3158
3397
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
3398
|
+
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
3159
3399
|
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
3400
|
+
// requires TS 4.4+
|
3160
3401
|
class Class {
|
3161
3402
|
constructor(..._) { }
|
3162
3403
|
}
|
3163
|
-
const instanceOfType = (
|
3404
|
+
const instanceOfType = (
|
3405
|
+
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
3406
|
+
cls, params = {
|
3164
3407
|
message: `Input not instance of ${cls.name}`,
|
3165
3408
|
}) => (0, exports.custom)((data) => data instanceof cls, params);
|
3166
3409
|
exports.instanceof = instanceOfType;
|