@rspack/core 1.0.0-alpha.5 → 1.0.0-beta.0

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.
Files changed (89) hide show
  1. package/compiled/zod/index.d.ts +138 -52
  2. package/compiled/zod/index.js +300 -103
  3. package/compiled/zod/package.json +1 -1
  4. package/compiled/zod-validation-error/index.js +6 -6
  5. package/dist/Compilation.d.ts +21 -3
  6. package/dist/Compilation.js +64 -49
  7. package/dist/Compiler.js +28 -28
  8. package/dist/ErrorHelpers.js +2 -4
  9. package/dist/Module.js +2 -6
  10. package/dist/ModuleTypeConstants.d.ts +45 -69
  11. package/dist/ModuleTypeConstants.js +24 -77
  12. package/dist/Stats.js +4 -6
  13. package/dist/Template.d.ts +31 -147
  14. package/dist/Template.js +40 -236
  15. package/dist/builtin-loader/lightningcss/index.d.ts +89 -0
  16. package/dist/builtin-loader/lightningcss/index.js +175 -0
  17. package/dist/builtin-plugin/BannerPlugin.d.ts +24 -48
  18. package/dist/builtin-plugin/DefinePlugin.js +9 -13
  19. package/dist/builtin-plugin/EntryPlugin.d.ts +2 -2
  20. package/dist/builtin-plugin/ExternalsPlugin.d.ts +24 -0
  21. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +8 -8
  22. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +2 -2
  23. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.d.ts +10 -3
  24. package/dist/builtin-plugin/LightningCssMiminizerRspackPlugin.js +4 -1
  25. package/dist/builtin-plugin/SplitChunksPlugin.js +5 -15
  26. package/dist/builtin-plugin/SwcJsMinimizerPlugin.js +15 -23
  27. package/dist/builtin-plugin/base.js +1 -3
  28. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.d.ts +3 -3
  29. package/dist/builtin-plugin/css-extract/hmr/hotModuleReplacement.js +17 -66
  30. package/dist/builtin-plugin/css-extract/hmr/normalizeUrl.d.ts +2 -0
  31. package/dist/builtin-plugin/css-extract/hmr/{normalize-url.js → normalizeUrl.js} +15 -24
  32. package/dist/builtin-plugin/css-extract/loader.js +5 -5
  33. package/dist/config/adapter.d.ts +1 -1
  34. package/dist/config/adapter.js +24 -23
  35. package/dist/config/adapterRuleUse.d.ts +5 -5
  36. package/dist/config/adapterRuleUse.js +23 -1
  37. package/dist/config/browserslistTargetHandler.d.ts +17 -15
  38. package/dist/config/browserslistTargetHandler.js +27 -33
  39. package/dist/config/defaults.js +20 -21
  40. package/dist/config/normalization.d.ts +2 -0
  41. package/dist/config/normalization.js +5 -5
  42. package/dist/config/target.d.ts +48 -109
  43. package/dist/config/target.js +50 -86
  44. package/dist/config/zod.d.ts +2391 -2205
  45. package/dist/config/zod.js +28 -18
  46. package/dist/container/ContainerPlugin.d.ts +7 -7
  47. package/dist/container/options.js +1 -1
  48. package/dist/exports.d.ts +4 -4
  49. package/dist/exports.js +2 -2
  50. package/dist/lib/CacheFacade.js +1 -0
  51. package/dist/lib/ModuleFilenameHelpers.js +1 -3
  52. package/dist/lib/cache/mergeEtags.js +5 -11
  53. package/dist/lib/formatLocation.js +3 -5
  54. package/dist/loader-runner/LoaderLoadingError.d.ts +11 -1
  55. package/dist/loader-runner/LoaderLoadingError.js +3 -5
  56. package/dist/loader-runner/index.js +7 -9
  57. package/dist/loader-runner/loadLoader.d.ts +11 -2
  58. package/dist/loader-runner/loadLoader.js +17 -19
  59. package/dist/logging/createConsoleLogger.js +2 -6
  60. package/dist/logging/truncateArgs.js +5 -9
  61. package/dist/node/nodeConsole.js +1 -3
  62. package/dist/stats/DefaultStatsFactoryPlugin.js +17 -7
  63. package/dist/stats/DefaultStatsPresetPlugin.js +4 -4
  64. package/dist/stats/DefaultStatsPrinterPlugin.js +11 -16
  65. package/dist/stats/StatsFactory.js +13 -17
  66. package/dist/stats/StatsPrinter.js +7 -9
  67. package/dist/util/AssetInfo.js +11 -7
  68. package/dist/util/SplitChunkSize.js +1 -1
  69. package/dist/util/cleverMerge.d.ts +33 -57
  70. package/dist/util/cleverMerge.js +89 -145
  71. package/dist/util/comparators.js +3 -5
  72. package/dist/util/createHash.d.ts +4 -3
  73. package/dist/util/createHash.js +31 -45
  74. package/dist/util/fs.js +9 -13
  75. package/dist/util/hash/BatchedHash.d.ts +24 -9
  76. package/dist/util/hash/BatchedHash.js +16 -13
  77. package/dist/util/hash/index.d.ts +9 -9
  78. package/dist/util/hash/index.js +14 -11
  79. package/dist/util/hash/md4.d.ts +29 -2
  80. package/dist/util/hash/md4.js +7 -3
  81. package/dist/util/hash/wasm-hash.d.ts +52 -5
  82. package/dist/util/hash/wasm-hash.js +19 -22
  83. package/dist/util/hash/xxhash64.d.ts +29 -2
  84. package/dist/util/hash/xxhash64.js +7 -3
  85. package/dist/util/identifier.js +9 -15
  86. package/dist/util/index.js +1 -1
  87. package/dist/util/memoize.js +7 -9
  88. package/package.json +9 -8
  89. package/dist/builtin-plugin/css-extract/hmr/normalize-url.d.ts +0 -2
@@ -2,13 +2,13 @@
2
2
  /******/ "use strict";
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
5
- /***/ 533:
5
+ /***/ 690:
6
6
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10
10
  exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
11
- const util_1 = __nccwpck_require__(276);
11
+ const util_1 = __nccwpck_require__(168);
12
12
  exports.ZodIssueCode = util_1.util.arrayToEnum([
13
13
  "invalid_type",
14
14
  "invalid_literal",
@@ -105,6 +105,11 @@ class ZodError extends Error {
105
105
  processError(this);
106
106
  return fieldErrors;
107
107
  }
108
+ static assert(value) {
109
+ if (!(value instanceof ZodError)) {
110
+ throw new Error(`Not a ZodError: ${value}`);
111
+ }
112
+ }
108
113
  toString() {
109
114
  return this.message;
110
115
  }
@@ -141,7 +146,7 @@ ZodError.create = (issues) => {
141
146
 
142
147
  /***/ }),
143
148
 
144
- /***/ 347:
149
+ /***/ 155:
145
150
  /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
146
151
 
147
152
 
@@ -150,7 +155,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
150
155
  };
151
156
  Object.defineProperty(exports, "__esModule", ({ value: true }));
152
157
  exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0;
153
- const en_1 = __importDefault(__nccwpck_require__(56));
158
+ const en_1 = __importDefault(__nccwpck_require__(806));
154
159
  exports.defaultErrorMap = en_1.default;
155
160
  let overrideErrorMap = en_1.default;
156
161
  function setErrorMap(map) {
@@ -165,7 +170,7 @@ exports.getErrorMap = getErrorMap;
165
170
 
166
171
  /***/ }),
167
172
 
168
- /***/ 961:
173
+ /***/ 359:
169
174
  /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
170
175
 
171
176
 
@@ -180,17 +185,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
180
185
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
181
186
  };
182
187
  Object.defineProperty(exports, "__esModule", ({ value: true }));
183
- __exportStar(__nccwpck_require__(347), exports);
184
- __exportStar(__nccwpck_require__(825), exports);
185
- __exportStar(__nccwpck_require__(764), exports);
186
- __exportStar(__nccwpck_require__(276), exports);
187
- __exportStar(__nccwpck_require__(355), exports);
188
- __exportStar(__nccwpck_require__(533), exports);
188
+ __exportStar(__nccwpck_require__(155), exports);
189
+ __exportStar(__nccwpck_require__(802), exports);
190
+ __exportStar(__nccwpck_require__(245), exports);
191
+ __exportStar(__nccwpck_require__(168), exports);
192
+ __exportStar(__nccwpck_require__(233), exports);
193
+ __exportStar(__nccwpck_require__(690), exports);
189
194
 
190
195
 
191
196
  /***/ }),
192
197
 
193
- /***/ 429:
198
+ /***/ 344:
194
199
  /***/ ((__unused_webpack_module, exports) => {
195
200
 
196
201
 
@@ -205,7 +210,7 @@ var errorUtil;
205
210
 
206
211
  /***/ }),
207
212
 
208
- /***/ 825:
213
+ /***/ 802:
209
214
  /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
210
215
 
211
216
 
@@ -214,8 +219,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
214
219
  };
215
220
  Object.defineProperty(exports, "__esModule", ({ value: true }));
216
221
  exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
217
- const errors_1 = __nccwpck_require__(347);
218
- const en_1 = __importDefault(__nccwpck_require__(56));
222
+ const errors_1 = __nccwpck_require__(155);
223
+ const en_1 = __importDefault(__nccwpck_require__(806));
219
224
  const makeIssue = (params) => {
220
225
  const { data, path, errorMaps, issueData } = params;
221
226
  const fullPath = [...path, ...(issueData.path || [])];
@@ -223,6 +228,13 @@ const makeIssue = (params) => {
223
228
  ...issueData,
224
229
  path: fullPath,
225
230
  };
231
+ if (issueData.message !== undefined) {
232
+ return {
233
+ ...issueData,
234
+ path: fullPath,
235
+ message: issueData.message,
236
+ };
237
+ }
226
238
  let errorMessage = "";
227
239
  const maps = errorMaps
228
240
  .filter((m) => !!m)
@@ -234,12 +246,13 @@ const makeIssue = (params) => {
234
246
  return {
235
247
  ...issueData,
236
248
  path: fullPath,
237
- message: issueData.message || errorMessage,
249
+ message: errorMessage,
238
250
  };
239
251
  };
240
252
  exports.makeIssue = makeIssue;
241
253
  exports.EMPTY_PATH = [];
242
254
  function addIssueToContext(ctx, issueData) {
255
+ const overrideMap = (0, errors_1.getErrorMap)();
243
256
  const issue = (0, exports.makeIssue)({
244
257
  issueData: issueData,
245
258
  data: ctx.data,
@@ -247,8 +260,8 @@ function addIssueToContext(ctx, issueData) {
247
260
  errorMaps: [
248
261
  ctx.common.contextualErrorMap,
249
262
  ctx.schemaErrorMap,
250
- (0, errors_1.getErrorMap)(),
251
- en_1.default, // then global default map
263
+ overrideMap,
264
+ overrideMap === en_1.default ? undefined : en_1.default, // then global default map
252
265
  ].filter((x) => !!x),
253
266
  });
254
267
  ctx.common.issues.push(issue);
@@ -280,9 +293,11 @@ class ParseStatus {
280
293
  static async mergeObjectAsync(status, pairs) {
281
294
  const syncPairs = [];
282
295
  for (const pair of pairs) {
296
+ const key = await pair.key;
297
+ const value = await pair.value;
283
298
  syncPairs.push({
284
- key: await pair.key,
285
- value: await pair.value,
299
+ key,
300
+ value,
286
301
  });
287
302
  }
288
303
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -327,7 +342,7 @@ exports.isAsync = isAsync;
327
342
 
328
343
  /***/ }),
329
344
 
330
- /***/ 764:
345
+ /***/ 245:
331
346
  /***/ ((__unused_webpack_module, exports) => {
332
347
 
333
348
 
@@ -336,7 +351,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
336
351
 
337
352
  /***/ }),
338
353
 
339
- /***/ 276:
354
+ /***/ 168:
340
355
  /***/ ((__unused_webpack_module, exports) => {
341
356
 
342
357
 
@@ -485,7 +500,7 @@ exports.getParsedType = getParsedType;
485
500
 
486
501
  /***/ }),
487
502
 
488
- /***/ 353:
503
+ /***/ 847:
489
504
  /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
490
505
 
491
506
 
@@ -513,21 +528,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
513
528
  };
514
529
  Object.defineProperty(exports, "__esModule", ({ value: true }));
515
530
  exports.z = void 0;
516
- const z = __importStar(__nccwpck_require__(961));
531
+ const z = __importStar(__nccwpck_require__(359));
517
532
  exports.z = z;
518
- __exportStar(__nccwpck_require__(961), exports);
533
+ __exportStar(__nccwpck_require__(359), exports);
519
534
  exports["default"] = z;
520
535
 
521
536
 
522
537
  /***/ }),
523
538
 
524
- /***/ 56:
539
+ /***/ 806:
525
540
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
526
541
 
527
542
 
528
543
  Object.defineProperty(exports, "__esModule", ({ value: true }));
529
- const util_1 = __nccwpck_require__(276);
530
- const ZodError_1 = __nccwpck_require__(533);
544
+ const util_1 = __nccwpck_require__(168);
545
+ const ZodError_1 = __nccwpck_require__(690);
531
546
  const errorMap = (issue, _ctx) => {
532
547
  let message;
533
548
  switch (issue.code) {
@@ -657,18 +672,30 @@ exports["default"] = errorMap;
657
672
 
658
673
  /***/ }),
659
674
 
660
- /***/ 355:
661
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
675
+ /***/ 233:
676
+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
662
677
 
663
678
 
679
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
680
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
681
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
682
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
683
+ };
684
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
685
+ if (kind === "m") throw new TypeError("Private method is not writable");
686
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
687
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
688
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
689
+ };
690
+ var _ZodEnum_cache, _ZodNativeEnum_cache;
664
691
  Object.defineProperty(exports, "__esModule", ({ value: true }));
665
- 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;
666
- 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;
667
- const errors_1 = __nccwpck_require__(347);
668
- const errorUtil_1 = __nccwpck_require__(429);
669
- const parseUtil_1 = __nccwpck_require__(825);
670
- const util_1 = __nccwpck_require__(276);
671
- const ZodError_1 = __nccwpck_require__(533);
692
+ 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.datetimeRegex = exports.ZodType = void 0;
693
+ 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 = exports.date = void 0;
694
+ const errors_1 = __nccwpck_require__(155);
695
+ const errorUtil_1 = __nccwpck_require__(344);
696
+ const parseUtil_1 = __nccwpck_require__(802);
697
+ const util_1 = __nccwpck_require__(168);
698
+ const ZodError_1 = __nccwpck_require__(690);
672
699
  class ParseInputLazyPath {
673
700
  constructor(parent, value, path, key) {
674
701
  this._cachedPath = [];
@@ -719,12 +746,17 @@ function processCreateParams(params) {
719
746
  if (errorMap)
720
747
  return { errorMap: errorMap, description };
721
748
  const customMap = (iss, ctx) => {
722
- if (iss.code !== "invalid_type")
723
- return { message: ctx.defaultError };
749
+ var _a, _b;
750
+ const { message } = params;
751
+ if (iss.code === "invalid_enum_value") {
752
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
753
+ }
724
754
  if (typeof ctx.data === "undefined") {
725
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
755
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
726
756
  }
727
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
757
+ if (iss.code !== "invalid_type")
758
+ return { message: ctx.defaultError };
759
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
728
760
  };
729
761
  return { errorMap: customMap, description };
730
762
  }
@@ -985,11 +1017,13 @@ exports.ZodType = ZodType;
985
1017
  exports.Schema = ZodType;
986
1018
  exports.ZodSchema = ZodType;
987
1019
  const cuidRegex = /^c[^\s-]{8,}$/i;
988
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
1020
+ const cuid2Regex = /^[0-9a-z]+$/;
989
1021
  const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
990
1022
  // const uuidRegex =
991
1023
  // /^([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;
992
1024
  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;
1025
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
1026
+ const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
993
1027
  // from https://stackoverflow.com/a/46181/1550155
994
1028
  // old version: too slow, didn't support unicode
995
1029
  // 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;
@@ -1002,41 +1036,49 @@ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-
1002
1036
  // /^[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])?)*$/;
1003
1037
  // const emailRegex =
1004
1038
  // /^(?:[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;
1005
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1039
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1006
1040
  // const emailRegex =
1007
1041
  // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
1008
1042
  // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
1009
1043
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1010
1044
  let emojiRegex;
1011
- 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}))$/;
1045
+ // faster, simpler, safer
1046
+ const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
1012
1047
  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})))$/;
1013
- // Adapted from https://stackoverflow.com/a/3143231
1014
- const datetimeRegex = (args) => {
1048
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
1049
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1050
+ // simple
1051
+ // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
1052
+ // no leap year validation
1053
+ // const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
1054
+ // with leap year validation
1055
+ const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1056
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
1057
+ function timeRegexSource(args) {
1058
+ // let regex = `\\d{2}:\\d{2}:\\d{2}`;
1059
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
1015
1060
  if (args.precision) {
1016
- if (args.offset) {
1017
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1018
- }
1019
- else {
1020
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
1021
- }
1022
- }
1023
- else if (args.precision === 0) {
1024
- if (args.offset) {
1025
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1026
- }
1027
- else {
1028
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
1029
- }
1061
+ regex = `${regex}\\.\\d{${args.precision}}`;
1030
1062
  }
1031
- else {
1032
- if (args.offset) {
1033
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1034
- }
1035
- else {
1036
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
1037
- }
1063
+ else if (args.precision == null) {
1064
+ regex = `${regex}(\\.\\d+)?`;
1038
1065
  }
1039
- };
1066
+ return regex;
1067
+ }
1068
+ function timeRegex(args) {
1069
+ return new RegExp(`^${timeRegexSource(args)}$`);
1070
+ }
1071
+ // Adapted from https://stackoverflow.com/a/3143231
1072
+ function datetimeRegex(args) {
1073
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1074
+ const opts = [];
1075
+ opts.push(args.local ? `Z?` : `Z`);
1076
+ if (args.offset)
1077
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1078
+ regex = `${regex}(${opts.join("|")})`;
1079
+ return new RegExp(`^${regex}$`);
1080
+ }
1081
+ exports.datetimeRegex = datetimeRegex;
1040
1082
  function isValidIP(ip, version) {
1041
1083
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1042
1084
  return true;
@@ -1058,9 +1100,7 @@ class ZodString extends ZodType {
1058
1100
  code: ZodError_1.ZodIssueCode.invalid_type,
1059
1101
  expected: util_1.ZodParsedType.string,
1060
1102
  received: ctx.parsedType,
1061
- }
1062
- //
1063
- );
1103
+ });
1064
1104
  return parseUtil_1.INVALID;
1065
1105
  }
1066
1106
  const status = new parseUtil_1.ParseStatus();
@@ -1158,6 +1198,17 @@ class ZodString extends ZodType {
1158
1198
  status.dirty();
1159
1199
  }
1160
1200
  }
1201
+ else if (check.kind === "nanoid") {
1202
+ if (!nanoidRegex.test(input.data)) {
1203
+ ctx = this._getOrReturnCtx(input, ctx);
1204
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1205
+ validation: "nanoid",
1206
+ code: ZodError_1.ZodIssueCode.invalid_string,
1207
+ message: check.message,
1208
+ });
1209
+ status.dirty();
1210
+ }
1211
+ }
1161
1212
  else if (check.kind === "cuid") {
1162
1213
  if (!cuidRegex.test(input.data)) {
1163
1214
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1272,6 +1323,41 @@ class ZodString extends ZodType {
1272
1323
  status.dirty();
1273
1324
  }
1274
1325
  }
1326
+ else if (check.kind === "date") {
1327
+ const regex = dateRegex;
1328
+ if (!regex.test(input.data)) {
1329
+ ctx = this._getOrReturnCtx(input, ctx);
1330
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1331
+ code: ZodError_1.ZodIssueCode.invalid_string,
1332
+ validation: "date",
1333
+ message: check.message,
1334
+ });
1335
+ status.dirty();
1336
+ }
1337
+ }
1338
+ else if (check.kind === "time") {
1339
+ const regex = timeRegex(check);
1340
+ if (!regex.test(input.data)) {
1341
+ ctx = this._getOrReturnCtx(input, ctx);
1342
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1343
+ code: ZodError_1.ZodIssueCode.invalid_string,
1344
+ validation: "time",
1345
+ message: check.message,
1346
+ });
1347
+ status.dirty();
1348
+ }
1349
+ }
1350
+ else if (check.kind === "duration") {
1351
+ if (!durationRegex.test(input.data)) {
1352
+ ctx = this._getOrReturnCtx(input, ctx);
1353
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1354
+ validation: "duration",
1355
+ code: ZodError_1.ZodIssueCode.invalid_string,
1356
+ message: check.message,
1357
+ });
1358
+ status.dirty();
1359
+ }
1360
+ }
1275
1361
  else if (check.kind === "ip") {
1276
1362
  if (!isValidIP(input.data, check.version)) {
1277
1363
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1283,6 +1369,17 @@ class ZodString extends ZodType {
1283
1369
  status.dirty();
1284
1370
  }
1285
1371
  }
1372
+ else if (check.kind === "base64") {
1373
+ if (!base64Regex.test(input.data)) {
1374
+ ctx = this._getOrReturnCtx(input, ctx);
1375
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1376
+ validation: "base64",
1377
+ code: ZodError_1.ZodIssueCode.invalid_string,
1378
+ message: check.message,
1379
+ });
1380
+ status.dirty();
1381
+ }
1382
+ }
1286
1383
  else {
1287
1384
  util_1.util.assertNever(check);
1288
1385
  }
@@ -1314,6 +1411,9 @@ class ZodString extends ZodType {
1314
1411
  uuid(message) {
1315
1412
  return this._addCheck({ kind: "uuid", ...errorUtil_1.errorUtil.errToObj(message) });
1316
1413
  }
1414
+ nanoid(message) {
1415
+ return this._addCheck({ kind: "nanoid", ...errorUtil_1.errorUtil.errToObj(message) });
1416
+ }
1317
1417
  cuid(message) {
1318
1418
  return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
1319
1419
  }
@@ -1323,16 +1423,20 @@ class ZodString extends ZodType {
1323
1423
  ulid(message) {
1324
1424
  return this._addCheck({ kind: "ulid", ...errorUtil_1.errorUtil.errToObj(message) });
1325
1425
  }
1426
+ base64(message) {
1427
+ return this._addCheck({ kind: "base64", ...errorUtil_1.errorUtil.errToObj(message) });
1428
+ }
1326
1429
  ip(options) {
1327
1430
  return this._addCheck({ kind: "ip", ...errorUtil_1.errorUtil.errToObj(options) });
1328
1431
  }
1329
1432
  datetime(options) {
1330
- var _a;
1433
+ var _a, _b;
1331
1434
  if (typeof options === "string") {
1332
1435
  return this._addCheck({
1333
1436
  kind: "datetime",
1334
1437
  precision: null,
1335
1438
  offset: false,
1439
+ local: false,
1336
1440
  message: options,
1337
1441
  });
1338
1442
  }
@@ -1340,9 +1444,30 @@ class ZodString extends ZodType {
1340
1444
  kind: "datetime",
1341
1445
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1342
1446
  offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1447
+ local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1448
+ ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1449
+ });
1450
+ }
1451
+ date(message) {
1452
+ return this._addCheck({ kind: "date", message });
1453
+ }
1454
+ time(options) {
1455
+ if (typeof options === "string") {
1456
+ return this._addCheck({
1457
+ kind: "time",
1458
+ precision: null,
1459
+ message: options,
1460
+ });
1461
+ }
1462
+ return this._addCheck({
1463
+ kind: "time",
1464
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1343
1465
  ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1344
1466
  });
1345
1467
  }
1468
+ duration(message) {
1469
+ return this._addCheck({ kind: "duration", ...errorUtil_1.errorUtil.errToObj(message) });
1470
+ }
1346
1471
  regex(regex, message) {
1347
1472
  return this._addCheck({
1348
1473
  kind: "regex",
@@ -1421,6 +1546,15 @@ class ZodString extends ZodType {
1421
1546
  get isDatetime() {
1422
1547
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
1423
1548
  }
1549
+ get isDate() {
1550
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1551
+ }
1552
+ get isTime() {
1553
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1554
+ }
1555
+ get isDuration() {
1556
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1557
+ }
1424
1558
  get isEmail() {
1425
1559
  return !!this._def.checks.find((ch) => ch.kind === "email");
1426
1560
  }
@@ -1433,6 +1567,9 @@ class ZodString extends ZodType {
1433
1567
  get isUUID() {
1434
1568
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
1435
1569
  }
1570
+ get isNANOID() {
1571
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1572
+ }
1436
1573
  get isCUID() {
1437
1574
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
1438
1575
  }
@@ -1445,6 +1582,9 @@ class ZodString extends ZodType {
1445
1582
  get isIP() {
1446
1583
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1447
1584
  }
1585
+ get isBase64() {
1586
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1587
+ }
1448
1588
  get minLength() {
1449
1589
  let min = null;
1450
1590
  for (const ch of this._def.checks) {
@@ -2446,9 +2586,10 @@ class ZodObject extends ZodType {
2446
2586
  const syncPairs = [];
2447
2587
  for (const pair of pairs) {
2448
2588
  const key = await pair.key;
2589
+ const value = await pair.value;
2449
2590
  syncPairs.push({
2450
2591
  key,
2451
- value: await pair.value,
2592
+ value,
2452
2593
  alwaysSet: pair.alwaysSet,
2453
2594
  });
2454
2595
  }
@@ -2824,7 +2965,7 @@ const getDiscriminator = (type) => {
2824
2965
  }
2825
2966
  else if (type instanceof ZodNativeEnum) {
2826
2967
  // eslint-disable-next-line ban/ban
2827
- return Object.keys(type.enum);
2968
+ return util_1.util.objectValues(type.enum);
2828
2969
  }
2829
2970
  else if (type instanceof ZodDefault) {
2830
2971
  return getDiscriminator(type._def.innerType);
@@ -2835,8 +2976,23 @@ const getDiscriminator = (type) => {
2835
2976
  else if (type instanceof ZodNull) {
2836
2977
  return [null];
2837
2978
  }
2979
+ else if (type instanceof ZodOptional) {
2980
+ return [undefined, ...getDiscriminator(type.unwrap())];
2981
+ }
2982
+ else if (type instanceof ZodNullable) {
2983
+ return [null, ...getDiscriminator(type.unwrap())];
2984
+ }
2985
+ else if (type instanceof ZodBranded) {
2986
+ return getDiscriminator(type.unwrap());
2987
+ }
2988
+ else if (type instanceof ZodReadonly) {
2989
+ return getDiscriminator(type.unwrap());
2990
+ }
2991
+ else if (type instanceof ZodCatch) {
2992
+ return getDiscriminator(type._def.innerType);
2993
+ }
2838
2994
  else {
2839
- return null;
2995
+ return [];
2840
2996
  }
2841
2997
  };
2842
2998
  class ZodDiscriminatedUnion extends ZodType {
@@ -2899,7 +3055,7 @@ class ZodDiscriminatedUnion extends ZodType {
2899
3055
  // try {
2900
3056
  for (const type of options) {
2901
3057
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2902
- if (!discriminatorValues) {
3058
+ if (!discriminatorValues.length) {
2903
3059
  throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2904
3060
  }
2905
3061
  for (const value of discriminatorValues) {
@@ -3115,6 +3271,7 @@ class ZodRecord extends ZodType {
3115
3271
  pairs.push({
3116
3272
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3117
3273
  value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3274
+ alwaysSet: key in ctx.data,
3118
3275
  });
3119
3276
  }
3120
3277
  if (ctx.common.async) {
@@ -3480,6 +3637,10 @@ function createZodEnum(values, params) {
3480
3637
  });
3481
3638
  }
3482
3639
  class ZodEnum extends ZodType {
3640
+ constructor() {
3641
+ super(...arguments);
3642
+ _ZodEnum_cache.set(this, void 0);
3643
+ }
3483
3644
  _parse(input) {
3484
3645
  if (typeof input.data !== "string") {
3485
3646
  const ctx = this._getOrReturnCtx(input);
@@ -3491,7 +3652,10 @@ class ZodEnum extends ZodType {
3491
3652
  });
3492
3653
  return parseUtil_1.INVALID;
3493
3654
  }
3494
- if (this._def.values.indexOf(input.data) === -1) {
3655
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
3656
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
3657
+ }
3658
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3495
3659
  const ctx = this._getOrReturnCtx(input);
3496
3660
  const expectedValues = this._def.values;
3497
3661
  (0, parseUtil_1.addIssueToContext)(ctx, {
@@ -3527,16 +3691,27 @@ class ZodEnum extends ZodType {
3527
3691
  }
3528
3692
  return enumValues;
3529
3693
  }
3530
- extract(values) {
3531
- return ZodEnum.create(values);
3694
+ extract(values, newDef = this._def) {
3695
+ return ZodEnum.create(values, {
3696
+ ...this._def,
3697
+ ...newDef,
3698
+ });
3532
3699
  }
3533
- exclude(values) {
3534
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
3700
+ exclude(values, newDef = this._def) {
3701
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3702
+ ...this._def,
3703
+ ...newDef,
3704
+ });
3535
3705
  }
3536
3706
  }
3537
3707
  exports.ZodEnum = ZodEnum;
3708
+ _ZodEnum_cache = new WeakMap();
3538
3709
  ZodEnum.create = createZodEnum;
3539
3710
  class ZodNativeEnum extends ZodType {
3711
+ constructor() {
3712
+ super(...arguments);
3713
+ _ZodNativeEnum_cache.set(this, void 0);
3714
+ }
3540
3715
  _parse(input) {
3541
3716
  const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
3542
3717
  const ctx = this._getOrReturnCtx(input);
@@ -3550,7 +3725,10 @@ class ZodNativeEnum extends ZodType {
3550
3725
  });
3551
3726
  return parseUtil_1.INVALID;
3552
3727
  }
3553
- if (nativeEnumValues.indexOf(input.data) === -1) {
3728
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
3729
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util_1.util.getValidEnumValues(this._def.values)), "f");
3730
+ }
3731
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3554
3732
  const expectedValues = util_1.util.objectValues(nativeEnumValues);
3555
3733
  (0, parseUtil_1.addIssueToContext)(ctx, {
3556
3734
  received: ctx.data,
@@ -3566,6 +3744,7 @@ class ZodNativeEnum extends ZodType {
3566
3744
  }
3567
3745
  }
3568
3746
  exports.ZodNativeEnum = ZodNativeEnum;
3747
+ _ZodNativeEnum_cache = new WeakMap();
3569
3748
  ZodNativeEnum.create = (values, params) => {
3570
3749
  return new ZodNativeEnum({
3571
3750
  values: values,
@@ -3636,33 +3815,43 @@ class ZodEffects extends ZodType {
3636
3815
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3637
3816
  if (effect.type === "preprocess") {
3638
3817
  const processed = effect.transform(ctx.data, checkCtx);
3639
- if (ctx.common.issues.length) {
3640
- return {
3641
- status: "dirty",
3642
- value: ctx.data,
3643
- };
3644
- }
3645
3818
  if (ctx.common.async) {
3646
- return Promise.resolve(processed).then((processed) => {
3647
- return this._def.schema._parseAsync({
3819
+ return Promise.resolve(processed).then(async (processed) => {
3820
+ if (status.value === "aborted")
3821
+ return parseUtil_1.INVALID;
3822
+ const result = await this._def.schema._parseAsync({
3648
3823
  data: processed,
3649
3824
  path: ctx.path,
3650
3825
  parent: ctx,
3651
3826
  });
3827
+ if (result.status === "aborted")
3828
+ return parseUtil_1.INVALID;
3829
+ if (result.status === "dirty")
3830
+ return (0, parseUtil_1.DIRTY)(result.value);
3831
+ if (status.value === "dirty")
3832
+ return (0, parseUtil_1.DIRTY)(result.value);
3833
+ return result;
3652
3834
  });
3653
3835
  }
3654
3836
  else {
3655
- return this._def.schema._parseSync({
3837
+ if (status.value === "aborted")
3838
+ return parseUtil_1.INVALID;
3839
+ const result = this._def.schema._parseSync({
3656
3840
  data: processed,
3657
3841
  path: ctx.path,
3658
3842
  parent: ctx,
3659
3843
  });
3844
+ if (result.status === "aborted")
3845
+ return parseUtil_1.INVALID;
3846
+ if (result.status === "dirty")
3847
+ return (0, parseUtil_1.DIRTY)(result.value);
3848
+ if (status.value === "dirty")
3849
+ return (0, parseUtil_1.DIRTY)(result.value);
3850
+ return result;
3660
3851
  }
3661
3852
  }
3662
3853
  if (effect.type === "refinement") {
3663
- const executeRefinement = (acc
3664
- // effect: RefinementEffect<any>
3665
- ) => {
3854
+ const executeRefinement = (acc) => {
3666
3855
  const result = effect.refinement(acc, checkCtx);
3667
3856
  if (ctx.common.async) {
3668
3857
  return Promise.resolve(result);
@@ -3974,10 +4163,18 @@ exports.ZodPipeline = ZodPipeline;
3974
4163
  class ZodReadonly extends ZodType {
3975
4164
  _parse(input) {
3976
4165
  const result = this._def.innerType._parse(input);
3977
- if ((0, parseUtil_1.isValid)(result)) {
3978
- result.value = Object.freeze(result.value);
3979
- }
3980
- return result;
4166
+ const freeze = (data) => {
4167
+ if ((0, parseUtil_1.isValid)(data)) {
4168
+ data.value = Object.freeze(data.value);
4169
+ }
4170
+ return data;
4171
+ };
4172
+ return (0, parseUtil_1.isAsync)(result)
4173
+ ? result.then((data) => freeze(data))
4174
+ : freeze(result);
4175
+ }
4176
+ unwrap() {
4177
+ return this._def.innerType;
3981
4178
  }
3982
4179
  }
3983
4180
  exports.ZodReadonly = ZodReadonly;
@@ -3988,7 +4185,7 @@ ZodReadonly.create = (type, params) => {
3988
4185
  ...processCreateParams(params),
3989
4186
  });
3990
4187
  };
3991
- const custom = (check, params = {},
4188
+ function custom(check, params = {},
3992
4189
  /**
3993
4190
  * @deprecated
3994
4191
  *
@@ -3999,7 +4196,7 @@ const custom = (check, params = {},
3999
4196
  * ```
4000
4197
  *
4001
4198
  */
4002
- fatal) => {
4199
+ fatal) {
4003
4200
  if (check)
4004
4201
  return ZodAny.create().superRefine((data, ctx) => {
4005
4202
  var _a, _b;
@@ -4015,7 +4212,7 @@ fatal) => {
4015
4212
  }
4016
4213
  });
4017
4214
  return ZodAny.create();
4018
- };
4215
+ }
4019
4216
  exports.custom = custom;
4020
4217
  exports.late = {
4021
4218
  object: ZodObject.lazycreate,
@@ -4067,7 +4264,7 @@ const instanceOfType = (
4067
4264
  // const instanceOfType = <T extends new (...args: any[]) => any>(
4068
4265
  cls, params = {
4069
4266
  message: `Input not instance of ${cls.name}`,
4070
- }) => (0, exports.custom)((data) => data instanceof cls, params);
4267
+ }) => custom((data) => data instanceof cls, params);
4071
4268
  exports["instanceof"] = instanceOfType;
4072
4269
  const stringType = ZodString.create;
4073
4270
  exports.string = stringType;
@@ -4201,7 +4398,7 @@ exports.NEVER = parseUtil_1.INVALID;
4201
4398
  /******/ // startup
4202
4399
  /******/ // Load entry module and return exports
4203
4400
  /******/ // This entry module is referenced by other modules so it can't be inlined
4204
- /******/ var __webpack_exports__ = __nccwpck_require__(353);
4401
+ /******/ var __webpack_exports__ = __nccwpck_require__(847);
4205
4402
  /******/ module.exports = __webpack_exports__;
4206
4403
  /******/
4207
4404
  /******/ })()