@aws-amplify/graphql-api-construct 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/.jsii +34 -34
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +9 -3
  4. package/lib/amplify-graphql-api.d.ts +9 -3
  5. package/lib/amplify-graphql-api.js +11 -5
  6. package/lib/amplify-graphql-definition.js +1 -1
  7. package/lib/internal/codegen-assets.js +6 -1
  8. package/node_modules/@aws-amplify/graphql-auth-transformer/CHANGELOG.md +4 -0
  9. package/node_modules/@aws-amplify/graphql-auth-transformer/package.json +8 -8
  10. package/node_modules/@aws-amplify/graphql-default-value-transformer/CHANGELOG.md +4 -0
  11. package/node_modules/@aws-amplify/graphql-default-value-transformer/package.json +5 -5
  12. package/node_modules/@aws-amplify/graphql-function-transformer/CHANGELOG.md +4 -0
  13. package/node_modules/@aws-amplify/graphql-function-transformer/package.json +4 -4
  14. package/node_modules/@aws-amplify/graphql-http-transformer/CHANGELOG.md +4 -0
  15. package/node_modules/@aws-amplify/graphql-http-transformer/package.json +4 -4
  16. package/node_modules/@aws-amplify/graphql-index-transformer/CHANGELOG.md +4 -0
  17. package/node_modules/@aws-amplify/graphql-index-transformer/package.json +5 -5
  18. package/node_modules/@aws-amplify/graphql-maps-to-transformer/CHANGELOG.md +4 -0
  19. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/assets/mapping-lambda.zip +0 -0
  20. package/node_modules/@aws-amplify/graphql-maps-to-transformer/package.json +8 -8
  21. package/node_modules/@aws-amplify/graphql-model-transformer/CHANGELOG.md +4 -0
  22. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-lambda.zip +0 -0
  23. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-notification-lambda.zip +0 -0
  24. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-patching-lambda.zip +0 -0
  25. package/node_modules/@aws-amplify/graphql-model-transformer/package.json +4 -4
  26. package/node_modules/@aws-amplify/graphql-predictions-transformer/CHANGELOG.md +4 -0
  27. package/node_modules/@aws-amplify/graphql-predictions-transformer/lib/predictionsLambdaFunction.zip +0 -0
  28. package/node_modules/@aws-amplify/graphql-predictions-transformer/package.json +4 -4
  29. package/node_modules/@aws-amplify/graphql-relational-transformer/CHANGELOG.md +4 -0
  30. package/node_modules/@aws-amplify/graphql-relational-transformer/package.json +6 -6
  31. package/node_modules/@aws-amplify/graphql-searchable-transformer/CHANGELOG.md +4 -0
  32. package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/streaming-lambda.zip +0 -0
  33. package/node_modules/@aws-amplify/graphql-searchable-transformer/package.json +5 -5
  34. package/node_modules/@aws-amplify/graphql-transformer/CHANGELOG.md +4 -0
  35. package/node_modules/@aws-amplify/graphql-transformer/package.json +13 -13
  36. package/node_modules/@aws-amplify/graphql-transformer-core/API.md +1 -0
  37. package/node_modules/@aws-amplify/graphql-transformer-core/CHANGELOG.md +6 -0
  38. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.d.ts +8 -1
  39. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.d.ts.map +1 -1
  40. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.js +60 -23
  41. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/output.js.map +1 -1
  42. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.d.ts +4 -1
  43. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.d.ts.map +1 -1
  44. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.js +35 -36
  45. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/defaultSchema.js.map +1 -1
  46. package/node_modules/@aws-amplify/graphql-transformer-core/package.json +2 -2
  47. package/node_modules/@aws-amplify/graphql-transformer-interfaces/package.json +1 -2
  48. package/node_modules/zod/README.md +215 -120
  49. package/node_modules/zod/lib/ZodError.js +8 -0
  50. package/node_modules/zod/lib/helpers/parseUtil.js +3 -2
  51. package/node_modules/zod/lib/helpers/util.js +4 -4
  52. package/node_modules/zod/lib/index.mjs +121 -57
  53. package/node_modules/zod/lib/index.umd.js +121 -56
  54. package/node_modules/zod/lib/types.d.ts +55 -10
  55. package/node_modules/zod/lib/types.js +301 -58
  56. package/node_modules/zod/package.json +29 -15
  57. package/package.json +15 -15
  58. package/src/amplify-graphql-api.ts +9 -3
  59. package/src/internal/codegen-assets.ts +5 -0
  60. package/node_modules/@aws-amplify/graphql-transformer-interfaces/LICENSE +0 -201
@@ -484,7 +484,8 @@
484
484
  status.dirty();
485
485
  if (value.status === "dirty")
486
486
  status.dirty();
487
- if (typeof value.value !== "undefined" || pair.alwaysSet) {
487
+ if (key.value !== "__proto__" &&
488
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
488
489
  finalObject[key.value] = value.value;
489
490
  }
490
491
  }
@@ -592,6 +593,7 @@
592
593
  this.catch = this.catch.bind(this);
593
594
  this.describe = this.describe.bind(this);
594
595
  this.pipe = this.pipe.bind(this);
596
+ this.readonly = this.readonly.bind(this);
595
597
  this.isNullable = this.isNullable.bind(this);
596
598
  this.isOptional = this.isOptional.bind(this);
597
599
  }
@@ -808,6 +810,9 @@
808
810
  pipe(target) {
809
811
  return ZodPipeline.create(this, target);
810
812
  }
813
+ readonly() {
814
+ return ZodReadonly.create(this);
815
+ }
811
816
  isOptional() {
812
817
  return this.safeParse(undefined).success;
813
818
  }
@@ -817,17 +822,28 @@
817
822
  }
818
823
  const cuidRegex = /^c[^\s-]{8,}$/i;
819
824
  const cuid2Regex = /^[a-z][a-z0-9]*$/;
820
- const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
821
- 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;
825
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
826
+ // const uuidRegex =
827
+ // /^([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;
828
+ 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;
822
829
  // from https://stackoverflow.com/a/46181/1550155
823
830
  // old version: too slow, didn't support unicode
824
831
  // 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;
825
832
  //old email regex
826
833
  // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
827
834
  // eslint-disable-next-line
828
- const emailRegex = /^(([^<>()[\]\\.,;:\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,})+))$/;
835
+ // const emailRegex =
836
+ // /^(([^<>()[\]\\.,;:\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,})+))$/;
837
+ // const emailRegex =
838
+ // /^[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])?)*$/;
839
+ // const emailRegex =
840
+ // /^(?:[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;
841
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
842
+ // const emailRegex =
843
+ // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
829
844
  // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
830
- const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
845
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
846
+ let emojiRegex;
831
847
  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}))$/;
832
848
  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})))$/;
833
849
  // Adapted from https://stackoverflow.com/a/3143231
@@ -867,31 +883,6 @@
867
883
  return false;
868
884
  }
869
885
  class ZodString extends ZodType {
870
- constructor() {
871
- super(...arguments);
872
- this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
873
- validation,
874
- code: ZodIssueCode.invalid_string,
875
- ...errorUtil.errToObj(message),
876
- });
877
- /**
878
- * @deprecated Use z.string().min(1) instead.
879
- * @see {@link ZodString.min}
880
- */
881
- this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
882
- this.trim = () => new ZodString({
883
- ...this._def,
884
- checks: [...this._def.checks, { kind: "trim" }],
885
- });
886
- this.toLowerCase = () => new ZodString({
887
- ...this._def,
888
- checks: [...this._def.checks, { kind: "toLowerCase" }],
889
- });
890
- this.toUpperCase = () => new ZodString({
891
- ...this._def,
892
- checks: [...this._def.checks, { kind: "toUpperCase" }],
893
- });
894
- }
895
886
  _parse(input) {
896
887
  if (this._def.coerce) {
897
888
  input.data = String(input.data);
@@ -979,6 +970,9 @@
979
970
  }
980
971
  }
981
972
  else if (check.kind === "emoji") {
973
+ if (!emojiRegex) {
974
+ emojiRegex = new RegExp(_emojiRegex, "u");
975
+ }
982
976
  if (!emojiRegex.test(input.data)) {
983
977
  ctx = this._getOrReturnCtx(input, ctx);
984
978
  addIssueToContext(ctx, {
@@ -1131,6 +1125,13 @@
1131
1125
  }
1132
1126
  return { status: status.value, value: input.data };
1133
1127
  }
1128
+ _regex(regex, validation, message) {
1129
+ return this.refinement((data) => regex.test(data), {
1130
+ validation,
1131
+ code: ZodIssueCode.invalid_string,
1132
+ ...errorUtil.errToObj(message),
1133
+ });
1134
+ }
1134
1135
  _addCheck(check) {
1135
1136
  return new ZodString({
1136
1137
  ...this._def,
@@ -1228,6 +1229,31 @@
1228
1229
  ...errorUtil.errToObj(message),
1229
1230
  });
1230
1231
  }
1232
+ /**
1233
+ * @deprecated Use z.string().min(1) instead.
1234
+ * @see {@link ZodString.min}
1235
+ */
1236
+ nonempty(message) {
1237
+ return this.min(1, errorUtil.errToObj(message));
1238
+ }
1239
+ trim() {
1240
+ return new ZodString({
1241
+ ...this._def,
1242
+ checks: [...this._def.checks, { kind: "trim" }],
1243
+ });
1244
+ }
1245
+ toLowerCase() {
1246
+ return new ZodString({
1247
+ ...this._def,
1248
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
1249
+ });
1250
+ }
1251
+ toUpperCase() {
1252
+ return new ZodString({
1253
+ ...this._def,
1254
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
1255
+ });
1256
+ }
1231
1257
  get isDatetime() {
1232
1258
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
1233
1259
  }
@@ -2936,6 +2962,12 @@
2936
2962
  }
2937
2963
  }
2938
2964
  class ZodMap extends ZodType {
2965
+ get keySchema() {
2966
+ return this._def.keyType;
2967
+ }
2968
+ get valueSchema() {
2969
+ return this._def.valueType;
2970
+ }
2939
2971
  _parse(input) {
2940
2972
  const { status, ctx } = this._processInputParams(input);
2941
2973
  if (ctx.parsedType !== ZodParsedType.map) {
@@ -3132,16 +3164,20 @@
3132
3164
  const params = { errorMap: ctx.common.contextualErrorMap };
3133
3165
  const fn = ctx.data;
3134
3166
  if (this._def.returns instanceof ZodPromise) {
3135
- return OK(async (...args) => {
3167
+ // Would love a way to avoid disabling this rule, but we need
3168
+ // an alias (using an arrow function was what caused 2651).
3169
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3170
+ const me = this;
3171
+ return OK(async function (...args) {
3136
3172
  const error = new ZodError([]);
3137
- const parsedArgs = await this._def.args
3173
+ const parsedArgs = await me._def.args
3138
3174
  .parseAsync(args, params)
3139
3175
  .catch((e) => {
3140
3176
  error.addIssue(makeArgsIssue(args, e));
3141
3177
  throw error;
3142
3178
  });
3143
- const result = await fn(...parsedArgs);
3144
- const parsedReturns = await this._def.returns._def.type
3179
+ const result = await Reflect.apply(fn, this, parsedArgs);
3180
+ const parsedReturns = await me._def.returns._def.type
3145
3181
  .parseAsync(result, params)
3146
3182
  .catch((e) => {
3147
3183
  error.addIssue(makeReturnsIssue(result, e));
@@ -3151,13 +3187,17 @@
3151
3187
  });
3152
3188
  }
3153
3189
  else {
3154
- return OK((...args) => {
3155
- const parsedArgs = this._def.args.safeParse(args, params);
3190
+ // Would love a way to avoid disabling this rule, but we need
3191
+ // an alias (using an arrow function was what caused 2651).
3192
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3193
+ const me = this;
3194
+ return OK(function (...args) {
3195
+ const parsedArgs = me._def.args.safeParse(args, params);
3156
3196
  if (!parsedArgs.success) {
3157
3197
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3158
3198
  }
3159
- const result = fn(...parsedArgs.data);
3160
- const parsedReturns = this._def.returns.safeParse(result, params);
3199
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3200
+ const parsedReturns = me._def.returns.safeParse(result, params);
3161
3201
  if (!parsedReturns.success) {
3162
3202
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3163
3203
  }
@@ -3245,7 +3285,7 @@
3245
3285
  };
3246
3286
  function createZodEnum(values, params) {
3247
3287
  return new ZodEnum({
3248
- values: values,
3288
+ values,
3249
3289
  typeName: exports.ZodFirstPartyTypeKind.ZodEnum,
3250
3290
  ...processCreateParams(params),
3251
3291
  });
@@ -3387,8 +3427,29 @@
3387
3427
  _parse(input) {
3388
3428
  const { status, ctx } = this._processInputParams(input);
3389
3429
  const effect = this._def.effect || null;
3430
+ const checkCtx = {
3431
+ addIssue: (arg) => {
3432
+ addIssueToContext(ctx, arg);
3433
+ if (arg.fatal) {
3434
+ status.abort();
3435
+ }
3436
+ else {
3437
+ status.dirty();
3438
+ }
3439
+ },
3440
+ get path() {
3441
+ return ctx.path;
3442
+ },
3443
+ };
3444
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3390
3445
  if (effect.type === "preprocess") {
3391
- const processed = effect.transform(ctx.data);
3446
+ const processed = effect.transform(ctx.data, checkCtx);
3447
+ if (ctx.common.issues.length) {
3448
+ return {
3449
+ status: "dirty",
3450
+ value: ctx.data,
3451
+ };
3452
+ }
3392
3453
  if (ctx.common.async) {
3393
3454
  return Promise.resolve(processed).then((processed) => {
3394
3455
  return this._def.schema._parseAsync({
@@ -3406,21 +3467,6 @@
3406
3467
  });
3407
3468
  }
3408
3469
  }
3409
- const checkCtx = {
3410
- addIssue: (arg) => {
3411
- addIssueToContext(ctx, arg);
3412
- if (arg.fatal) {
3413
- status.abort();
3414
- }
3415
- else {
3416
- status.dirty();
3417
- }
3418
- },
3419
- get path() {
3420
- return ctx.path;
3421
- },
3422
- };
3423
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3424
3470
  if (effect.type === "refinement") {
3425
3471
  const executeRefinement = (acc
3426
3472
  // effect: RefinementEffect<any>
@@ -3724,8 +3770,24 @@
3724
3770
  });
3725
3771
  }
3726
3772
  }
3773
+ class ZodReadonly extends ZodType {
3774
+ _parse(input) {
3775
+ const result = this._def.innerType._parse(input);
3776
+ if (isValid(result)) {
3777
+ result.value = Object.freeze(result.value);
3778
+ }
3779
+ return result;
3780
+ }
3781
+ }
3782
+ ZodReadonly.create = (type, params) => {
3783
+ return new ZodReadonly({
3784
+ innerType: type,
3785
+ typeName: exports.ZodFirstPartyTypeKind.ZodReadonly,
3786
+ ...processCreateParams(params),
3787
+ });
3788
+ };
3727
3789
  const custom = (check, params = {},
3728
- /*
3790
+ /**
3729
3791
  * @deprecated
3730
3792
  *
3731
3793
  * Pass `fatal` into the params object instead:
@@ -3792,6 +3854,7 @@
3792
3854
  ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3793
3855
  ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
3794
3856
  ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
3857
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
3795
3858
  })(exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
3796
3859
  const instanceOfType = (
3797
3860
  // const instanceOfType = <T extends new (...args: any[]) => any>(
@@ -3905,6 +3968,7 @@
3905
3968
  BRAND: BRAND,
3906
3969
  ZodBranded: ZodBranded,
3907
3970
  ZodPipeline: ZodPipeline,
3971
+ ZodReadonly: ZodReadonly,
3908
3972
  custom: custom,
3909
3973
  Schema: ZodType,
3910
3974
  ZodSchema: ZodType,
@@ -3993,6 +4057,7 @@
3993
4057
  exports.ZodParsedType = ZodParsedType;
3994
4058
  exports.ZodPipeline = ZodPipeline;
3995
4059
  exports.ZodPromise = ZodPromise;
4060
+ exports.ZodReadonly = ZodReadonly;
3996
4061
  exports.ZodRecord = ZodRecord;
3997
4062
  exports.ZodSchema = ZodType;
3998
4063
  exports.ZodSet = ZodSet;
@@ -60,6 +60,7 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
60
60
  safeParse(data: unknown, params?: Partial<ParseParams>): SafeParseReturnType<Input, Output>;
61
61
  parseAsync(data: unknown, params?: Partial<ParseParams>): Promise<Output>;
62
62
  safeParseAsync(data: unknown, params?: Partial<ParseParams>): Promise<SafeParseReturnType<Input, Output>>;
63
+ /** Alias of safeParseAsync */
63
64
  spa: (data: unknown, params?: Partial<ParseParams> | undefined) => Promise<SafeParseReturnType<Input, Output>>;
64
65
  refine<RefinedOutput extends Output>(check: (arg: Output) => arg is RefinedOutput, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, RefinedOutput, Input>;
65
66
  refine(check: (arg: Output) => unknown | Promise<unknown>, message?: string | CustomErrorParams | ((arg: Output) => CustomErrorParams)): ZodEffects<this, Output, Input>;
@@ -68,6 +69,7 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
68
69
  _refinement(refinement: RefinementEffect<Output>["refinement"]): ZodEffects<this, Output, Input>;
69
70
  superRefine<RefinedOutput extends Output>(refinement: (arg: Output, ctx: RefinementCtx) => arg is RefinedOutput): ZodEffects<this, RefinedOutput, Input>;
70
71
  superRefine(refinement: (arg: Output, ctx: RefinementCtx) => void): ZodEffects<this, Output, Input>;
72
+ superRefine(refinement: (arg: Output, ctx: RefinementCtx) => Promise<void>): ZodEffects<this, Output, Input>;
71
73
  constructor(def: Def);
72
74
  optional(): ZodOptional<this>;
73
75
  nullable(): ZodNullable<this>;
@@ -87,6 +89,7 @@ export declare abstract class ZodType<Output = any, Def extends ZodTypeDef = Zod
87
89
  }) => Output): ZodCatch<this>;
88
90
  describe(description: string): this;
89
91
  pipe<T extends ZodTypeAny>(target: T): ZodPipeline<this, T>;
92
+ readonly(): ZodReadonly<this>;
90
93
  isOptional(): boolean;
91
94
  isNullable(): boolean;
92
95
  }
@@ -167,7 +170,7 @@ export interface ZodStringDef extends ZodTypeDef {
167
170
  }
168
171
  export declare class ZodString extends ZodType<string, ZodStringDef> {
169
172
  _parse(input: ParseInput): ParseReturnType<string>;
170
- protected _regex: (regex: RegExp, validation: StringValidation, message?: errorUtil.ErrMessage | undefined) => ZodEffects<this, string, string>;
173
+ protected _regex(regex: RegExp, validation: StringValidation, message?: errorUtil.ErrMessage): ZodEffects<this, string, string>;
171
174
  _addCheck(check: ZodStringCheck): ZodString;
172
175
  email(message?: errorUtil.ErrMessage): ZodString;
173
176
  url(message?: errorUtil.ErrMessage): ZodString;
@@ -195,10 +198,14 @@ export declare class ZodString extends ZodType<string, ZodStringDef> {
195
198
  min(minLength: number, message?: errorUtil.ErrMessage): ZodString;
196
199
  max(maxLength: number, message?: errorUtil.ErrMessage): ZodString;
197
200
  length(len: number, message?: errorUtil.ErrMessage): ZodString;
198
- nonempty: (message?: errorUtil.ErrMessage | undefined) => ZodString;
199
- trim: () => ZodString;
200
- toLowerCase: () => ZodString;
201
- toUpperCase: () => ZodString;
201
+ /**
202
+ * @deprecated Use z.string().min(1) instead.
203
+ * @see {@link ZodString.min}
204
+ */
205
+ nonempty(message?: errorUtil.ErrMessage): ZodString;
206
+ trim(): ZodString;
207
+ toLowerCase(): ZodString;
208
+ toUpperCase(): ZodString;
202
209
  get isDatetime(): boolean;
203
210
  get isEmail(): boolean;
204
211
  get isURL(): boolean;
@@ -491,9 +498,21 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
491
498
  strict(message?: errorUtil.ErrMessage): ZodObject<T, "strict", Catchall>;
492
499
  strip(): ZodObject<T, "strip", Catchall>;
493
500
  passthrough(): ZodObject<T, "passthrough", Catchall>;
501
+ /**
502
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
503
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
504
+ */
494
505
  nonstrict: () => ZodObject<T, "passthrough", Catchall>;
495
506
  extend<Augmentation extends ZodRawShape>(augmentation: Augmentation): ZodObject<objectUtil.extendShape<T, Augmentation>, UnknownKeys, Catchall>;
507
+ /**
508
+ * @deprecated Use `.extend` instead
509
+ * */
496
510
  augment: <Augmentation extends ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, UnknownKeys, Catchall, objectOutputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall, UnknownKeys>, objectInputType<{ [k in keyof (Omit<T, keyof Augmentation> & Augmentation)]: (Omit<T, keyof Augmentation> & Augmentation)[k]; }, Catchall, UnknownKeys>>;
511
+ /**
512
+ * Prior to zod@1.0.12 there was a bug in the
513
+ * inferred type of merged objects. Please
514
+ * upgrade if you are experiencing issues.
515
+ */
497
516
  merge<Incoming extends AnyZodObject, Augmentation extends Incoming["shape"]>(merging: Incoming): ZodObject<objectUtil.extendShape<T, Augmentation>, Incoming["_def"]["unknownKeys"], Incoming["_def"]["catchall"]>;
498
517
  setKey<Key extends string, Schema extends ZodTypeAny>(key: Key, schema: Schema): ZodObject<T & {
499
518
  [k in Key]: Schema;
@@ -505,6 +524,9 @@ export declare class ZodObject<T extends ZodRawShape, UnknownKeys extends Unknow
505
524
  omit<Mask extends {
506
525
  [k in keyof T]?: true;
507
526
  }>(mask: Mask): ZodObject<Omit<T, keyof Mask>, UnknownKeys, Catchall>;
527
+ /**
528
+ * @deprecated
529
+ */
508
530
  deepPartial(): partialUtil.DeepPartial<this>;
509
531
  partial(): ZodObject<{
510
532
  [k in keyof T]: ZodOptional<T[k]>;
@@ -556,6 +578,14 @@ export declare class ZodDiscriminatedUnion<Discriminator extends string, Options
556
578
  get discriminator(): Discriminator;
557
579
  get options(): Options;
558
580
  get optionsMap(): Map<Primitive, ZodDiscriminatedUnionOption<any>>;
581
+ /**
582
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
583
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
584
+ * have a different value for each object in the union.
585
+ * @param discriminator the name of the discriminator property
586
+ * @param types an array of object schemas
587
+ * @param params
588
+ */
559
589
  static create<Discriminator extends string, Types extends [
560
590
  ZodDiscriminatedUnionOption<Discriminator>,
561
591
  ...ZodDiscriminatedUnionOption<Discriminator>[]
@@ -618,6 +648,8 @@ export interface ZodMapDef<Key extends ZodTypeAny = ZodTypeAny, Value extends Zo
618
648
  typeName: ZodFirstPartyTypeKind.ZodMap;
619
649
  }
620
650
  export declare class ZodMap<Key extends ZodTypeAny = ZodTypeAny, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<Map<Key["_output"], Value["_output"]>, ZodMapDef<Key, Value>, Map<Key["_input"], Value["_input"]>> {
651
+ get keySchema(): Key;
652
+ get valueSchema(): Value;
621
653
  _parse(input: ParseInput): ParseReturnType<this["_output"]>;
622
654
  static create: <Key_1 extends ZodTypeAny = ZodTypeAny, Value_1 extends ZodTypeAny = ZodTypeAny>(keyType: Key_1, valueType: Value_1, params?: RawCreateParams) => ZodMap<Key_1, Value_1>;
623
655
  }
@@ -730,7 +762,7 @@ export declare class ZodPromise<T extends ZodTypeAny> extends ZodType<Promise<T[
730
762
  static create: <T_1 extends ZodTypeAny>(schema: T_1, params?: RawCreateParams) => ZodPromise<T_1>;
731
763
  }
732
764
  export declare type Refinement<T> = (arg: T, ctx: RefinementCtx) => any;
733
- export declare type SuperRefinement<T> = (arg: T, ctx: RefinementCtx) => void;
765
+ export declare type SuperRefinement<T> = (arg: T, ctx: RefinementCtx) => void | Promise<void>;
734
766
  export declare type RefinementEffect<T> = {
735
767
  type: "refinement";
736
768
  refinement: (arg: T, ctx: RefinementCtx) => any;
@@ -741,7 +773,7 @@ export declare type TransformEffect<T> = {
741
773
  };
742
774
  export declare type PreprocessEffect<T> = {
743
775
  type: "preprocess";
744
- transform: (arg: T) => any;
776
+ transform: (arg: T, ctx: RefinementCtx) => any;
745
777
  };
746
778
  export declare type Effect<T> = RefinementEffect<T> | TransformEffect<T> | PreprocessEffect<T>;
747
779
  export interface ZodEffectsDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
@@ -754,7 +786,7 @@ export declare class ZodEffects<T extends ZodTypeAny, Output = output<T>, Input
754
786
  sourceType(): T;
755
787
  _parse(input: ParseInput): ParseReturnType<this["_output"]>;
756
788
  static create: <I extends ZodTypeAny>(schema: I, effect: Effect<I["_output"]>, params?: RawCreateParams) => ZodEffects<I, I["_output"], input<I>>;
757
- static createWithPreprocess: <I extends ZodTypeAny>(preprocess: (arg: unknown) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
789
+ static createWithPreprocess: <I extends ZodTypeAny>(preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
758
790
  }
759
791
  export { ZodEffects as ZodTransformer };
760
792
  export interface ZodOptionalDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
@@ -844,6 +876,18 @@ export declare class ZodPipeline<A extends ZodTypeAny, B extends ZodTypeAny> ext
844
876
  _parse(input: ParseInput): ParseReturnType<any>;
845
877
  static create<A extends ZodTypeAny, B extends ZodTypeAny>(a: A, b: B): ZodPipeline<A, B>;
846
878
  }
879
+ declare type BuiltIn = (((...args: any[]) => any) | (new (...args: any[]) => any)) | {
880
+ readonly [Symbol.toStringTag]: string;
881
+ } | Date | Error | Generator | Promise<unknown> | RegExp;
882
+ declare type MakeReadonly<T> = T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : T extends Set<infer V> ? ReadonlySet<V> : T extends [infer Head, ...infer Tail] ? readonly [Head, ...Tail] : T extends Array<infer V> ? ReadonlyArray<V> : T extends BuiltIn ? T : Readonly<T>;
883
+ export interface ZodReadonlyDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
884
+ innerType: T;
885
+ typeName: ZodFirstPartyTypeKind.ZodReadonly;
886
+ }
887
+ export declare class ZodReadonly<T extends ZodTypeAny> extends ZodType<MakeReadonly<T["_output"]>, ZodReadonlyDef<T>, T["_input"]> {
888
+ _parse(input: ParseInput): ParseReturnType<this["_output"]>;
889
+ static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodReadonly<T_1>;
890
+ }
847
891
  declare type CustomParams = CustomErrorParams & {
848
892
  fatal?: boolean;
849
893
  };
@@ -887,7 +931,8 @@ export declare enum ZodFirstPartyTypeKind {
887
931
  ZodCatch = "ZodCatch",
888
932
  ZodPromise = "ZodPromise",
889
933
  ZodBranded = "ZodBranded",
890
- ZodPipeline = "ZodPipeline"
934
+ ZodPipeline = "ZodPipeline",
935
+ ZodReadonly = "ZodReadonly"
891
936
  }
892
937
  export declare type ZodFirstPartySchemaTypes = ZodString | ZodNumber | ZodNaN | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid | ZodArray<any, any> | ZodObject<any, any, any> | ZodUnion<any> | ZodDiscriminatedUnion<any, any> | ZodIntersection<any, any> | ZodTuple<any, any> | ZodRecord<any, any> | ZodMap<any> | ZodSet<any> | ZodFunction<any, any> | ZodLazy<any> | ZodLiteral<any> | ZodEnum<any> | ZodEffects<any, any, any> | ZodNativeEnum<any> | ZodOptional<any> | ZodNullable<any> | ZodDefault<any> | ZodCatch<any> | ZodPromise<any> | ZodBranded<any, any> | ZodPipeline<any, any>;
893
938
  declare abstract class Class {
@@ -961,7 +1006,7 @@ declare const promiseType: <T extends ZodTypeAny>(schema: T, params?: RawCreateP
961
1006
  declare const effectsType: <I extends ZodTypeAny>(schema: I, effect: Effect<I["_output"]>, params?: RawCreateParams) => ZodEffects<I, I["_output"], input<I>>;
962
1007
  declare const optionalType: <T extends ZodTypeAny>(type: T, params?: RawCreateParams) => ZodOptional<T>;
963
1008
  declare const nullableType: <T extends ZodTypeAny>(type: T, params?: RawCreateParams) => ZodNullable<T>;
964
- declare const preprocessType: <I extends ZodTypeAny>(preprocess: (arg: unknown) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
1009
+ declare const preprocessType: <I extends ZodTypeAny>(preprocess: (arg: unknown, ctx: RefinementCtx) => unknown, schema: I, params?: RawCreateParams) => ZodEffects<I, I["_output"], unknown>;
965
1010
  declare const pipelineType: typeof ZodPipeline.create;
966
1011
  declare const ostring: () => ZodOptional<ZodString>;
967
1012
  declare const onumber: () => ZodOptional<ZodNumber>;