zod 3.13.4 → 3.14.2

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/lib/types.js CHANGED
@@ -1,131 +1,33 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __values = (this && this.__values) || function(o) {
65
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
66
- if (m) return m.call(o);
67
- if (o && typeof o.length === "number") return {
68
- next: function () {
69
- if (o && i >= o.length) o = void 0;
70
- return { value: o && o[i++], done: !o };
71
- }
72
- };
73
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
74
- };
75
- var __read = (this && this.__read) || function (o, n) {
76
- var m = typeof Symbol === "function" && o[Symbol.iterator];
77
- if (!m) return o;
78
- var i = m.call(o), r, ar = [], e;
79
- try {
80
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
- }
82
- catch (error) { e = { error: error }; }
83
- finally {
84
- try {
85
- if (r && !r.done && (m = i["return"])) m.call(i);
86
- }
87
- finally { if (e) throw e.error; }
88
- }
89
- return ar;
90
- };
91
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
- if (ar || !(i in from)) {
94
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
- ar[i] = from[i];
96
- }
97
- }
98
- return to.concat(ar || Array.prototype.slice.call(from));
99
- };
100
2
  Object.defineProperty(exports, "__esModule", { value: true });
101
3
  exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodNaN = 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.objectUtil = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
102
4
  exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = 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 = void 0;
103
- var errorUtil_1 = require("./helpers/errorUtil");
104
- var parseUtil_1 = require("./helpers/parseUtil");
105
- var util_1 = require("./helpers/util");
106
- var ZodError_1 = require("./ZodError");
107
- var handleResult = function (ctx, result) {
5
+ const errorUtil_1 = require("./helpers/errorUtil");
6
+ const parseUtil_1 = require("./helpers/parseUtil");
7
+ const util_1 = require("./helpers/util");
8
+ const ZodError_1 = require("./ZodError");
9
+ const handleResult = (ctx, result) => {
108
10
  if ((0, parseUtil_1.isValid)(result)) {
109
11
  return { success: true, data: result.value };
110
12
  }
111
13
  else {
112
- if (!ctx.issues.length) {
14
+ if (!ctx.common.issues.length) {
113
15
  throw new Error("Validation failed but no issues detected.");
114
16
  }
115
- var error = new ZodError_1.ZodError(ctx.issues);
116
- return { success: false, error: error };
17
+ const error = new ZodError_1.ZodError(ctx.common.issues);
18
+ return { success: false, error };
117
19
  }
118
20
  };
119
21
  function processCreateParams(params) {
120
22
  if (!params)
121
23
  return {};
122
- var errorMap = params.errorMap, invalid_type_error = params.invalid_type_error, required_error = params.required_error, description = params.description;
24
+ const { errorMap, invalid_type_error, required_error, description } = params;
123
25
  if (errorMap && (invalid_type_error || required_error)) {
124
- throw new Error("Can't use \"invalid\" or \"required\" in conjunction with custom error map.");
26
+ throw new Error(`Can't use "invalid" or "required" in conjunction with custom error map.`);
125
27
  }
126
28
  if (errorMap)
127
- return { errorMap: errorMap, description: description };
128
- var customMap = function (iss, ctx) {
29
+ return { errorMap: errorMap, description };
30
+ const customMap = (iss, ctx) => {
129
31
  if (iss.code !== "invalid_type")
130
32
  return { message: ctx.defaultError };
131
33
  if (typeof ctx.data === "undefined" && required_error)
@@ -134,10 +36,10 @@ function processCreateParams(params) {
134
36
  return { message: params.invalid_type_error };
135
37
  return { message: ctx.defaultError };
136
38
  };
137
- return { errorMap: customMap, description: description };
39
+ return { errorMap: customMap, description };
138
40
  }
139
- var ZodType = /** @class */ (function () {
140
- function ZodType(def) {
41
+ class ZodType {
42
+ constructor(def) {
141
43
  /** Alias of safeParseAsync */
142
44
  this.spa = this.safeParseAsync;
143
45
  this.superRefine = this._refinement;
@@ -163,99 +65,100 @@ var ZodType = /** @class */ (function () {
163
65
  this.isOptional = this.isOptional.bind(this);
164
66
  this.isNullable = this.isNullable.bind(this);
165
67
  }
166
- Object.defineProperty(ZodType.prototype, "description", {
167
- get: function () {
168
- return this._def.description;
169
- },
170
- enumerable: false,
171
- configurable: true
172
- });
173
- ZodType.prototype._processInputParams = function (input) {
68
+ get description() {
69
+ return this._def.description;
70
+ }
71
+ _getType(input) {
72
+ return (0, parseUtil_1.getParsedType)(input.data);
73
+ }
74
+ _getOrReturnCtx(input, ctx) {
75
+ return (ctx || {
76
+ common: input.parent.common,
77
+ data: input.data,
78
+ parsedType: (0, parseUtil_1.getParsedType)(input.data),
79
+ schemaErrorMap: this._def.errorMap,
80
+ path: input.path,
81
+ parent: input.parent,
82
+ });
83
+ }
84
+ _processInputParams(input) {
174
85
  return {
175
86
  status: new parseUtil_1.ParseStatus(),
176
- ctx: __assign(__assign({}, input.parent), { data: input.data, parsedType: (0, parseUtil_1.getParsedType)(input.data, input.parent.typeCache), schemaErrorMap: this._def.errorMap, path: input.path, parent: input.parent }),
87
+ ctx: {
88
+ common: input.parent.common,
89
+ data: input.data,
90
+ parsedType: (0, parseUtil_1.getParsedType)(input.data),
91
+ schemaErrorMap: this._def.errorMap,
92
+ path: input.path,
93
+ parent: input.parent,
94
+ },
177
95
  };
178
- };
179
- ZodType.prototype._parseSync = function (input) {
180
- var result = this._parse(input);
96
+ }
97
+ _parseSync(input) {
98
+ const result = this._parse(input);
181
99
  if ((0, parseUtil_1.isAsync)(result)) {
182
100
  throw new Error("Synchronous parse encountered promise.");
183
101
  }
184
102
  return result;
185
- };
186
- ZodType.prototype._parseAsync = function (input) {
187
- var result = this._parse(input);
103
+ }
104
+ _parseAsync(input) {
105
+ const result = this._parse(input);
188
106
  return Promise.resolve(result);
189
- };
190
- ZodType.prototype.parse = function (data, params) {
191
- var result = this.safeParse(data, params);
107
+ }
108
+ parse(data, params) {
109
+ const result = this.safeParse(data, params);
192
110
  if (result.success)
193
111
  return result.data;
194
112
  throw result.error;
195
- };
196
- ZodType.prototype.safeParse = function (data, params) {
113
+ }
114
+ safeParse(data, params) {
197
115
  var _a;
198
- var ctx = {
116
+ const ctx = {
117
+ common: {
118
+ issues: [],
119
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
120
+ typeCache: typeof Map !== "undefined" ? new Map() : undefined,
121
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
122
+ },
199
123
  path: (params === null || params === void 0 ? void 0 : params.path) || [],
200
- issues: [],
201
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
202
124
  schemaErrorMap: this._def.errorMap,
203
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
204
- typeCache: typeof Map !== "undefined" ? new Map() : undefined,
205
125
  parent: null,
206
- data: data,
126
+ data,
207
127
  parsedType: (0, parseUtil_1.getParsedType)(data),
208
128
  };
209
- var result = this._parseSync({ data: data, path: ctx.path, parent: ctx });
129
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
210
130
  return handleResult(ctx, result);
211
- };
212
- ZodType.prototype.parseAsync = function (data, params) {
213
- return __awaiter(this, void 0, void 0, function () {
214
- var result;
215
- return __generator(this, function (_a) {
216
- switch (_a.label) {
217
- case 0: return [4 /*yield*/, this.safeParseAsync(data, params)];
218
- case 1:
219
- result = _a.sent();
220
- if (result.success)
221
- return [2 /*return*/, result.data];
222
- throw result.error;
223
- }
224
- });
225
- });
226
- };
227
- ZodType.prototype.safeParseAsync = function (data, params) {
228
- return __awaiter(this, void 0, void 0, function () {
229
- var ctx, maybeAsyncResult, result;
230
- return __generator(this, function (_a) {
231
- switch (_a.label) {
232
- case 0:
233
- ctx = {
234
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
235
- issues: [],
236
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
237
- schemaErrorMap: this._def.errorMap,
238
- async: true,
239
- typeCache: typeof Map !== "undefined" ? new Map() : undefined,
240
- parent: null,
241
- data: data,
242
- parsedType: (0, parseUtil_1.getParsedType)(data),
243
- };
244
- maybeAsyncResult = this._parse({ data: data, path: [], parent: ctx });
245
- return [4 /*yield*/, ((0, parseUtil_1.isAsync)(maybeAsyncResult)
246
- ? maybeAsyncResult
247
- : Promise.resolve(maybeAsyncResult))];
248
- case 1:
249
- result = _a.sent();
250
- return [2 /*return*/, handleResult(ctx, result)];
251
- }
252
- });
253
- });
254
- };
255
- ZodType.prototype.refine = function (check, message) {
256
- var getIssueProperties = function (val) {
131
+ }
132
+ async parseAsync(data, params) {
133
+ const result = await this.safeParseAsync(data, params);
134
+ if (result.success)
135
+ return result.data;
136
+ throw result.error;
137
+ }
138
+ async safeParseAsync(data, params) {
139
+ const ctx = {
140
+ common: {
141
+ issues: [],
142
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
143
+ async: true,
144
+ typeCache: typeof Map !== "undefined" ? new Map() : undefined,
145
+ },
146
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
147
+ schemaErrorMap: this._def.errorMap,
148
+ parent: null,
149
+ data,
150
+ parsedType: (0, parseUtil_1.getParsedType)(data),
151
+ };
152
+ const maybeAsyncResult = this._parse({ data, path: [], parent: ctx });
153
+ const result = await ((0, parseUtil_1.isAsync)(maybeAsyncResult)
154
+ ? maybeAsyncResult
155
+ : Promise.resolve(maybeAsyncResult));
156
+ return handleResult(ctx, result);
157
+ }
158
+ refine(check, message) {
159
+ const getIssueProperties = (val) => {
257
160
  if (typeof message === "string" || typeof message === "undefined") {
258
- return { message: message };
161
+ return { message };
259
162
  }
260
163
  else if (typeof message === "function") {
261
164
  return message(val);
@@ -264,13 +167,14 @@ var ZodType = /** @class */ (function () {
264
167
  return message;
265
168
  }
266
169
  };
267
- return this._refinement(function (val, ctx) {
268
- var result = check(val);
269
- var setError = function () {
270
- return ctx.addIssue(__assign({ code: ZodError_1.ZodIssueCode.custom }, getIssueProperties(val)));
271
- };
170
+ return this._refinement((val, ctx) => {
171
+ const result = check(val);
172
+ const setError = () => ctx.addIssue({
173
+ code: ZodError_1.ZodIssueCode.custom,
174
+ ...getIssueProperties(val),
175
+ });
272
176
  if (typeof Promise !== "undefined" && result instanceof Promise) {
273
- return result.then(function (data) {
177
+ return result.then((data) => {
274
178
  if (!data) {
275
179
  setError();
276
180
  return false;
@@ -288,9 +192,9 @@ var ZodType = /** @class */ (function () {
288
192
  return true;
289
193
  }
290
194
  });
291
- };
292
- ZodType.prototype.refinement = function (check, refinementData) {
293
- return this._refinement(function (val, ctx) {
195
+ }
196
+ refinement(check, refinementData) {
197
+ return this._refinement((val, ctx) => {
294
198
  if (!check(val)) {
295
199
  ctx.addIssue(typeof refinementData === "function"
296
200
  ? refinementData(val, ctx)
@@ -301,92 +205,92 @@ var ZodType = /** @class */ (function () {
301
205
  return true;
302
206
  }
303
207
  });
304
- };
305
- ZodType.prototype._refinement = function (refinement) {
208
+ }
209
+ _refinement(refinement) {
306
210
  return new ZodEffects({
307
211
  schema: this,
308
212
  typeName: ZodFirstPartyTypeKind.ZodEffects,
309
- effect: { type: "refinement", refinement: refinement },
213
+ effect: { type: "refinement", refinement },
310
214
  });
311
- };
312
- ZodType.prototype.optional = function () {
215
+ }
216
+ optional() {
313
217
  return ZodOptional.create(this);
314
- };
315
- ZodType.prototype.nullable = function () {
218
+ }
219
+ nullable() {
316
220
  return ZodNullable.create(this);
317
- };
318
- ZodType.prototype.nullish = function () {
221
+ }
222
+ nullish() {
319
223
  return this.optional().nullable();
320
- };
321
- ZodType.prototype.array = function () {
224
+ }
225
+ array() {
322
226
  return ZodArray.create(this);
323
- };
324
- ZodType.prototype.promise = function () {
227
+ }
228
+ promise() {
325
229
  return ZodPromise.create(this);
326
- };
327
- ZodType.prototype.or = function (option) {
230
+ }
231
+ or(option) {
328
232
  return ZodUnion.create([this, option]);
329
- };
330
- ZodType.prototype.and = function (incoming) {
233
+ }
234
+ and(incoming) {
331
235
  return ZodIntersection.create(this, incoming);
332
- };
333
- ZodType.prototype.transform = function (transform) {
236
+ }
237
+ transform(transform) {
334
238
  return new ZodEffects({
335
239
  schema: this,
336
240
  typeName: ZodFirstPartyTypeKind.ZodEffects,
337
- effect: { type: "transform", transform: transform },
241
+ effect: { type: "transform", transform },
338
242
  });
339
- };
340
- ZodType.prototype.default = function (def) {
341
- var defaultValueFunc = typeof def === "function" ? def : function () { return def; };
243
+ }
244
+ default(def) {
245
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
342
246
  return new ZodDefault({
343
247
  innerType: this,
344
248
  defaultValue: defaultValueFunc,
345
249
  typeName: ZodFirstPartyTypeKind.ZodDefault,
346
250
  });
347
- };
348
- ZodType.prototype.describe = function (description) {
349
- var This = this.constructor;
350
- return new This(__assign(__assign({}, this._def), { description: description }));
351
- };
352
- ZodType.prototype.isOptional = function () {
251
+ }
252
+ describe(description) {
253
+ const This = this.constructor;
254
+ return new This({
255
+ ...this._def,
256
+ description,
257
+ });
258
+ }
259
+ isOptional() {
353
260
  return this.safeParse(undefined).success;
354
- };
355
- ZodType.prototype.isNullable = function () {
261
+ }
262
+ isNullable() {
356
263
  return this.safeParse(null).success;
357
- };
358
- return ZodType;
359
- }());
264
+ }
265
+ }
360
266
  exports.ZodType = ZodType;
361
267
  exports.Schema = ZodType;
362
268
  exports.ZodSchema = ZodType;
363
- var cuidRegex = /^c[^\s-]{8,}$/i;
364
- var 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;
269
+ const cuidRegex = /^c[^\s-]{8,}$/i;
270
+ 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;
365
271
  // from https://stackoverflow.com/a/46181/1550155
366
272
  // old version: too slow, didn't support unicode
367
273
  // 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;
368
274
  // eslint-disable-next-line
369
- var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
370
- var ZodString = /** @class */ (function (_super) {
371
- __extends(ZodString, _super);
372
- function ZodString() {
373
- var _this = _super !== null && _super.apply(this, arguments) || this;
374
- _this._regex = function (regex, validation, message) {
375
- return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodError_1.ZodIssueCode.invalid_string }, errorUtil_1.errorUtil.errToObj(message)));
376
- };
275
+ const emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
276
+ class ZodString extends ZodType {
277
+ constructor() {
278
+ super(...arguments);
279
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
280
+ validation,
281
+ code: ZodError_1.ZodIssueCode.invalid_string,
282
+ ...errorUtil_1.errorUtil.errToObj(message),
283
+ });
377
284
  /**
378
285
  * Deprecated.
379
286
  * Use z.string().min(1) instead.
380
287
  */
381
- _this.nonempty = function (message) {
382
- return _this.min(1, errorUtil_1.errorUtil.errToObj(message));
383
- };
384
- return _this;
288
+ this.nonempty = (message) => this.min(1, errorUtil_1.errorUtil.errToObj(message));
385
289
  }
386
- ZodString.prototype._parse = function (input) {
387
- var e_1, _a;
388
- var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
389
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.string) {
290
+ _parse(input) {
291
+ const parsedType = this._getType(input);
292
+ if (parsedType !== parseUtil_1.ZodParsedType.string) {
293
+ const ctx = this._getOrReturnCtx(input);
390
294
  (0, parseUtil_1.addIssueToContext)(ctx, {
391
295
  code: ZodError_1.ZodIssueCode.invalid_type,
392
296
  expected: parseUtil_1.ZodParsedType.string,
@@ -396,212 +300,203 @@ var ZodString = /** @class */ (function (_super) {
396
300
  );
397
301
  return parseUtil_1.INVALID;
398
302
  }
399
- try {
400
- for (var _c = __values(this._def.checks), _d = _c.next(); !_d.done; _d = _c.next()) {
401
- var check = _d.value;
402
- if (check.kind === "min") {
403
- if (ctx.data.length < check.value) {
404
- (0, parseUtil_1.addIssueToContext)(ctx, {
405
- code: ZodError_1.ZodIssueCode.too_small,
406
- minimum: check.value,
407
- type: "string",
408
- inclusive: true,
409
- message: check.message,
410
- });
411
- status.dirty();
412
- }
303
+ const status = new parseUtil_1.ParseStatus();
304
+ let ctx = undefined;
305
+ for (const check of this._def.checks) {
306
+ if (check.kind === "min") {
307
+ if (input.data.length < check.value) {
308
+ ctx = this._getOrReturnCtx(input, ctx);
309
+ (0, parseUtil_1.addIssueToContext)(ctx, {
310
+ code: ZodError_1.ZodIssueCode.too_small,
311
+ minimum: check.value,
312
+ type: "string",
313
+ inclusive: true,
314
+ message: check.message,
315
+ });
316
+ status.dirty();
413
317
  }
414
- else if (check.kind === "max") {
415
- if (ctx.data.length > check.value) {
416
- (0, parseUtil_1.addIssueToContext)(ctx, {
417
- code: ZodError_1.ZodIssueCode.too_big,
418
- maximum: check.value,
419
- type: "string",
420
- inclusive: true,
421
- message: check.message,
422
- });
423
- status.dirty();
424
- }
318
+ }
319
+ else if (check.kind === "max") {
320
+ if (input.data.length > check.value) {
321
+ ctx = this._getOrReturnCtx(input, ctx);
322
+ (0, parseUtil_1.addIssueToContext)(ctx, {
323
+ code: ZodError_1.ZodIssueCode.too_big,
324
+ maximum: check.value,
325
+ type: "string",
326
+ inclusive: true,
327
+ message: check.message,
328
+ });
329
+ status.dirty();
425
330
  }
426
- else if (check.kind === "email") {
427
- if (!emailRegex.test(ctx.data)) {
428
- (0, parseUtil_1.addIssueToContext)(ctx, {
429
- validation: "email",
430
- code: ZodError_1.ZodIssueCode.invalid_string,
431
- message: check.message,
432
- });
433
- status.dirty();
434
- }
331
+ }
332
+ else if (check.kind === "email") {
333
+ if (!emailRegex.test(input.data)) {
334
+ ctx = this._getOrReturnCtx(input, ctx);
335
+ (0, parseUtil_1.addIssueToContext)(ctx, {
336
+ validation: "email",
337
+ code: ZodError_1.ZodIssueCode.invalid_string,
338
+ message: check.message,
339
+ });
340
+ status.dirty();
435
341
  }
436
- else if (check.kind === "uuid") {
437
- if (!uuidRegex.test(ctx.data)) {
438
- (0, parseUtil_1.addIssueToContext)(ctx, {
439
- validation: "uuid",
440
- code: ZodError_1.ZodIssueCode.invalid_string,
441
- message: check.message,
442
- });
443
- status.dirty();
444
- }
342
+ }
343
+ else if (check.kind === "uuid") {
344
+ if (!uuidRegex.test(input.data)) {
345
+ ctx = this._getOrReturnCtx(input, ctx);
346
+ (0, parseUtil_1.addIssueToContext)(ctx, {
347
+ validation: "uuid",
348
+ code: ZodError_1.ZodIssueCode.invalid_string,
349
+ message: check.message,
350
+ });
351
+ status.dirty();
445
352
  }
446
- else if (check.kind === "cuid") {
447
- if (!cuidRegex.test(ctx.data)) {
448
- (0, parseUtil_1.addIssueToContext)(ctx, {
449
- validation: "cuid",
450
- code: ZodError_1.ZodIssueCode.invalid_string,
451
- message: check.message,
452
- });
453
- status.dirty();
454
- }
353
+ }
354
+ else if (check.kind === "cuid") {
355
+ if (!cuidRegex.test(input.data)) {
356
+ ctx = this._getOrReturnCtx(input, ctx);
357
+ (0, parseUtil_1.addIssueToContext)(ctx, {
358
+ validation: "cuid",
359
+ code: ZodError_1.ZodIssueCode.invalid_string,
360
+ message: check.message,
361
+ });
362
+ status.dirty();
455
363
  }
456
- else if (check.kind === "url") {
457
- try {
458
- new URL(ctx.data);
459
- }
460
- catch (_e) {
461
- (0, parseUtil_1.addIssueToContext)(ctx, {
462
- validation: "url",
463
- code: ZodError_1.ZodIssueCode.invalid_string,
464
- message: check.message,
465
- });
466
- status.dirty();
467
- }
364
+ }
365
+ else if (check.kind === "url") {
366
+ try {
367
+ new URL(input.data);
468
368
  }
469
- else if (check.kind === "regex") {
470
- check.regex.lastIndex = 0;
471
- var testResult = check.regex.test(ctx.data);
472
- if (!testResult) {
473
- (0, parseUtil_1.addIssueToContext)(ctx, {
474
- validation: "regex",
475
- code: ZodError_1.ZodIssueCode.invalid_string,
476
- message: check.message,
477
- });
478
- status.dirty();
479
- }
369
+ catch (_a) {
370
+ ctx = this._getOrReturnCtx(input, ctx);
371
+ (0, parseUtil_1.addIssueToContext)(ctx, {
372
+ validation: "url",
373
+ code: ZodError_1.ZodIssueCode.invalid_string,
374
+ message: check.message,
375
+ });
376
+ status.dirty();
480
377
  }
481
378
  }
482
- }
483
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
484
- finally {
485
- try {
486
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
379
+ else if (check.kind === "regex") {
380
+ check.regex.lastIndex = 0;
381
+ const testResult = check.regex.test(input.data);
382
+ if (!testResult) {
383
+ ctx = this._getOrReturnCtx(input, ctx);
384
+ (0, parseUtil_1.addIssueToContext)(ctx, {
385
+ validation: "regex",
386
+ code: ZodError_1.ZodIssueCode.invalid_string,
387
+ message: check.message,
388
+ });
389
+ status.dirty();
390
+ }
487
391
  }
488
- finally { if (e_1) throw e_1.error; }
489
392
  }
490
- return { status: status.value, value: ctx.data };
491
- };
492
- ZodString.prototype._addCheck = function (check) {
493
- return new ZodString(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [check], false) }));
494
- };
495
- ZodString.prototype.email = function (message) {
496
- return this._addCheck(__assign({ kind: "email" }, errorUtil_1.errorUtil.errToObj(message)));
497
- };
498
- ZodString.prototype.url = function (message) {
499
- return this._addCheck(__assign({ kind: "url" }, errorUtil_1.errorUtil.errToObj(message)));
500
- };
501
- ZodString.prototype.uuid = function (message) {
502
- return this._addCheck(__assign({ kind: "uuid" }, errorUtil_1.errorUtil.errToObj(message)));
503
- };
504
- ZodString.prototype.cuid = function (message) {
505
- return this._addCheck(__assign({ kind: "cuid" }, errorUtil_1.errorUtil.errToObj(message)));
506
- };
507
- ZodString.prototype.regex = function (regex, message) {
508
- return this._addCheck(__assign({ kind: "regex", regex: regex }, errorUtil_1.errorUtil.errToObj(message)));
509
- };
510
- ZodString.prototype.min = function (minLength, message) {
511
- return this._addCheck(__assign({ kind: "min", value: minLength }, errorUtil_1.errorUtil.errToObj(message)));
512
- };
513
- ZodString.prototype.max = function (maxLength, message) {
514
- return this._addCheck(__assign({ kind: "max", value: maxLength }, errorUtil_1.errorUtil.errToObj(message)));
515
- };
516
- ZodString.prototype.length = function (len, message) {
393
+ return { status: status.value, value: input.data };
394
+ }
395
+ _addCheck(check) {
396
+ return new ZodString({
397
+ ...this._def,
398
+ checks: [...this._def.checks, check],
399
+ });
400
+ }
401
+ email(message) {
402
+ return this._addCheck({ kind: "email", ...errorUtil_1.errorUtil.errToObj(message) });
403
+ }
404
+ url(message) {
405
+ return this._addCheck({ kind: "url", ...errorUtil_1.errorUtil.errToObj(message) });
406
+ }
407
+ uuid(message) {
408
+ return this._addCheck({ kind: "uuid", ...errorUtil_1.errorUtil.errToObj(message) });
409
+ }
410
+ cuid(message) {
411
+ return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
412
+ }
413
+ regex(regex, message) {
414
+ return this._addCheck({
415
+ kind: "regex",
416
+ regex: regex,
417
+ ...errorUtil_1.errorUtil.errToObj(message),
418
+ });
419
+ }
420
+ min(minLength, message) {
421
+ return this._addCheck({
422
+ kind: "min",
423
+ value: minLength,
424
+ ...errorUtil_1.errorUtil.errToObj(message),
425
+ });
426
+ }
427
+ max(maxLength, message) {
428
+ return this._addCheck({
429
+ kind: "max",
430
+ value: maxLength,
431
+ ...errorUtil_1.errorUtil.errToObj(message),
432
+ });
433
+ }
434
+ length(len, message) {
517
435
  return this.min(len, message).max(len, message);
518
- };
519
- Object.defineProperty(ZodString.prototype, "isEmail", {
520
- get: function () {
521
- return !!this._def.checks.find(function (ch) { return ch.kind === "email"; });
522
- },
523
- enumerable: false,
524
- configurable: true
525
- });
526
- Object.defineProperty(ZodString.prototype, "isURL", {
527
- get: function () {
528
- return !!this._def.checks.find(function (ch) { return ch.kind === "url"; });
529
- },
530
- enumerable: false,
531
- configurable: true
532
- });
533
- Object.defineProperty(ZodString.prototype, "isUUID", {
534
- get: function () {
535
- return !!this._def.checks.find(function (ch) { return ch.kind === "uuid"; });
536
- },
537
- enumerable: false,
538
- configurable: true
539
- });
540
- Object.defineProperty(ZodString.prototype, "isCUID", {
541
- get: function () {
542
- return !!this._def.checks.find(function (ch) { return ch.kind === "cuid"; });
543
- },
544
- enumerable: false,
545
- configurable: true
546
- });
547
- Object.defineProperty(ZodString.prototype, "minLength", {
548
- get: function () {
549
- var min = -Infinity;
550
- this._def.checks.map(function (ch) {
551
- if (ch.kind === "min") {
552
- if (min === null || ch.value > min) {
553
- min = ch.value;
554
- }
436
+ }
437
+ get isEmail() {
438
+ return !!this._def.checks.find((ch) => ch.kind === "email");
439
+ }
440
+ get isURL() {
441
+ return !!this._def.checks.find((ch) => ch.kind === "url");
442
+ }
443
+ get isUUID() {
444
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
445
+ }
446
+ get isCUID() {
447
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
448
+ }
449
+ get minLength() {
450
+ let min = -Infinity;
451
+ this._def.checks.map((ch) => {
452
+ if (ch.kind === "min") {
453
+ if (min === null || ch.value > min) {
454
+ min = ch.value;
555
455
  }
556
- });
557
- return min;
558
- },
559
- enumerable: false,
560
- configurable: true
561
- });
562
- Object.defineProperty(ZodString.prototype, "maxLength", {
563
- get: function () {
564
- var max = null;
565
- this._def.checks.map(function (ch) {
566
- if (ch.kind === "max") {
567
- if (max === null || ch.value < max) {
568
- max = ch.value;
569
- }
456
+ }
457
+ });
458
+ return min;
459
+ }
460
+ get maxLength() {
461
+ let max = null;
462
+ this._def.checks.map((ch) => {
463
+ if (ch.kind === "max") {
464
+ if (max === null || ch.value < max) {
465
+ max = ch.value;
570
466
  }
571
- });
572
- return max;
573
- },
574
- enumerable: false,
575
- configurable: true
576
- });
577
- ZodString.create = function (params) {
578
- return new ZodString(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString }, processCreateParams(params)));
579
- };
580
- return ZodString;
581
- }(ZodType));
467
+ }
468
+ });
469
+ return max;
470
+ }
471
+ }
582
472
  exports.ZodString = ZodString;
473
+ ZodString.create = (params) => {
474
+ return new ZodString({
475
+ checks: [],
476
+ typeName: ZodFirstPartyTypeKind.ZodString,
477
+ ...processCreateParams(params),
478
+ });
479
+ };
583
480
  // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
584
481
  function floatSafeRemainder(val, step) {
585
- var valDecCount = (val.toString().split(".")[1] || "").length;
586
- var stepDecCount = (step.toString().split(".")[1] || "").length;
587
- var decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
588
- var valInt = parseInt(val.toFixed(decCount).replace(".", ""));
589
- var stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
482
+ const valDecCount = (val.toString().split(".")[1] || "").length;
483
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
484
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
485
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
486
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
590
487
  return (valInt % stepInt) / Math.pow(10, decCount);
591
488
  }
592
- var ZodNumber = /** @class */ (function (_super) {
593
- __extends(ZodNumber, _super);
594
- function ZodNumber() {
595
- var _this = _super !== null && _super.apply(this, arguments) || this;
596
- _this.min = _this.gte;
597
- _this.max = _this.lte;
598
- _this.step = _this.multipleOf;
599
- return _this;
600
- }
601
- ZodNumber.prototype._parse = function (input) {
602
- var e_2, _a;
603
- var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
604
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.number) {
489
+ class ZodNumber extends ZodType {
490
+ constructor() {
491
+ super(...arguments);
492
+ this.min = this.gte;
493
+ this.max = this.lte;
494
+ this.step = this.multipleOf;
495
+ }
496
+ _parse(input) {
497
+ const parsedType = this._getType(input);
498
+ if (parsedType !== parseUtil_1.ZodParsedType.number) {
499
+ const ctx = this._getOrReturnCtx(input);
605
500
  (0, parseUtil_1.addIssueToContext)(ctx, {
606
501
  code: ZodError_1.ZodIssueCode.invalid_type,
607
502
  expected: parseUtil_1.ZodParsedType.number,
@@ -609,215 +504,184 @@ var ZodNumber = /** @class */ (function (_super) {
609
504
  });
610
505
  return parseUtil_1.INVALID;
611
506
  }
612
- try {
613
- for (var _c = __values(this._def.checks), _d = _c.next(); !_d.done; _d = _c.next()) {
614
- var check = _d.value;
615
- if (check.kind === "int") {
616
- if (!util_1.util.isInteger(ctx.data)) {
617
- (0, parseUtil_1.addIssueToContext)(ctx, {
618
- code: ZodError_1.ZodIssueCode.invalid_type,
619
- expected: "integer",
620
- received: "float",
621
- message: check.message,
622
- });
623
- status.dirty();
624
- }
625
- }
626
- else if (check.kind === "min") {
627
- var tooSmall = check.inclusive
628
- ? ctx.data < check.value
629
- : ctx.data <= check.value;
630
- if (tooSmall) {
631
- (0, parseUtil_1.addIssueToContext)(ctx, {
632
- code: ZodError_1.ZodIssueCode.too_small,
633
- minimum: check.value,
634
- type: "number",
635
- inclusive: check.inclusive,
636
- message: check.message,
637
- });
638
- status.dirty();
639
- }
507
+ let ctx = undefined;
508
+ const status = new parseUtil_1.ParseStatus();
509
+ for (const check of this._def.checks) {
510
+ if (check.kind === "int") {
511
+ if (!util_1.util.isInteger(input.data)) {
512
+ ctx = this._getOrReturnCtx(input, ctx);
513
+ (0, parseUtil_1.addIssueToContext)(ctx, {
514
+ code: ZodError_1.ZodIssueCode.invalid_type,
515
+ expected: "integer",
516
+ received: "float",
517
+ message: check.message,
518
+ });
519
+ status.dirty();
640
520
  }
641
- else if (check.kind === "max") {
642
- var tooBig = check.inclusive
643
- ? ctx.data > check.value
644
- : ctx.data >= check.value;
645
- if (tooBig) {
646
- (0, parseUtil_1.addIssueToContext)(ctx, {
647
- code: ZodError_1.ZodIssueCode.too_big,
648
- maximum: check.value,
649
- type: "number",
650
- inclusive: check.inclusive,
651
- message: check.message,
652
- });
653
- status.dirty();
654
- }
521
+ }
522
+ else if (check.kind === "min") {
523
+ const tooSmall = check.inclusive
524
+ ? input.data < check.value
525
+ : input.data <= check.value;
526
+ if (tooSmall) {
527
+ ctx = this._getOrReturnCtx(input, ctx);
528
+ (0, parseUtil_1.addIssueToContext)(ctx, {
529
+ code: ZodError_1.ZodIssueCode.too_small,
530
+ minimum: check.value,
531
+ type: "number",
532
+ inclusive: check.inclusive,
533
+ message: check.message,
534
+ });
535
+ status.dirty();
655
536
  }
656
- else if (check.kind === "multipleOf") {
657
- if (floatSafeRemainder(ctx.data, check.value) !== 0) {
658
- (0, parseUtil_1.addIssueToContext)(ctx, {
659
- code: ZodError_1.ZodIssueCode.not_multiple_of,
660
- multipleOf: check.value,
661
- message: check.message,
662
- });
663
- status.dirty();
664
- }
537
+ }
538
+ else if (check.kind === "max") {
539
+ const tooBig = check.inclusive
540
+ ? input.data > check.value
541
+ : input.data >= check.value;
542
+ if (tooBig) {
543
+ ctx = this._getOrReturnCtx(input, ctx);
544
+ (0, parseUtil_1.addIssueToContext)(ctx, {
545
+ code: ZodError_1.ZodIssueCode.too_big,
546
+ maximum: check.value,
547
+ type: "number",
548
+ inclusive: check.inclusive,
549
+ message: check.message,
550
+ });
551
+ status.dirty();
665
552
  }
666
- else {
667
- util_1.util.assertNever(check);
553
+ }
554
+ else if (check.kind === "multipleOf") {
555
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
556
+ ctx = this._getOrReturnCtx(input, ctx);
557
+ (0, parseUtil_1.addIssueToContext)(ctx, {
558
+ code: ZodError_1.ZodIssueCode.not_multiple_of,
559
+ multipleOf: check.value,
560
+ message: check.message,
561
+ });
562
+ status.dirty();
668
563
  }
669
564
  }
670
- }
671
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
672
- finally {
673
- try {
674
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
565
+ else {
566
+ util_1.util.assertNever(check);
675
567
  }
676
- finally { if (e_2) throw e_2.error; }
677
568
  }
678
- return { status: status.value, value: ctx.data };
679
- };
680
- ZodNumber.prototype.gte = function (value, message) {
569
+ return { status: status.value, value: input.data };
570
+ }
571
+ gte(value, message) {
681
572
  return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
682
- };
683
- ZodNumber.prototype.gt = function (value, message) {
573
+ }
574
+ gt(value, message) {
684
575
  return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
685
- };
686
- ZodNumber.prototype.lte = function (value, message) {
576
+ }
577
+ lte(value, message) {
687
578
  return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
688
- };
689
- ZodNumber.prototype.lt = function (value, message) {
579
+ }
580
+ lt(value, message) {
690
581
  return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
691
- };
692
- ZodNumber.prototype.setLimit = function (kind, value, inclusive, message) {
693
- return new ZodNumber(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [
582
+ }
583
+ setLimit(kind, value, inclusive, message) {
584
+ return new ZodNumber({
585
+ ...this._def,
586
+ checks: [
587
+ ...this._def.checks,
694
588
  {
695
- kind: kind,
696
- value: value,
697
- inclusive: inclusive,
589
+ kind,
590
+ value,
591
+ inclusive,
698
592
  message: errorUtil_1.errorUtil.toString(message),
699
593
  },
700
- ], false) }));
701
- };
702
- ZodNumber.prototype._addCheck = function (check) {
703
- return new ZodNumber(__assign(__assign({}, this._def), { checks: __spreadArray(__spreadArray([], __read(this._def.checks), false), [check], false) }));
704
- };
705
- ZodNumber.prototype.int = function (message) {
594
+ ],
595
+ });
596
+ }
597
+ _addCheck(check) {
598
+ return new ZodNumber({
599
+ ...this._def,
600
+ checks: [...this._def.checks, check],
601
+ });
602
+ }
603
+ int(message) {
706
604
  return this._addCheck({
707
605
  kind: "int",
708
606
  message: errorUtil_1.errorUtil.toString(message),
709
607
  });
710
- };
711
- ZodNumber.prototype.positive = function (message) {
608
+ }
609
+ positive(message) {
712
610
  return this._addCheck({
713
611
  kind: "min",
714
612
  value: 0,
715
613
  inclusive: false,
716
614
  message: errorUtil_1.errorUtil.toString(message),
717
615
  });
718
- };
719
- ZodNumber.prototype.negative = function (message) {
616
+ }
617
+ negative(message) {
720
618
  return this._addCheck({
721
619
  kind: "max",
722
620
  value: 0,
723
621
  inclusive: false,
724
622
  message: errorUtil_1.errorUtil.toString(message),
725
623
  });
726
- };
727
- ZodNumber.prototype.nonpositive = function (message) {
624
+ }
625
+ nonpositive(message) {
728
626
  return this._addCheck({
729
627
  kind: "max",
730
628
  value: 0,
731
629
  inclusive: true,
732
630
  message: errorUtil_1.errorUtil.toString(message),
733
631
  });
734
- };
735
- ZodNumber.prototype.nonnegative = function (message) {
632
+ }
633
+ nonnegative(message) {
736
634
  return this._addCheck({
737
635
  kind: "min",
738
636
  value: 0,
739
637
  inclusive: true,
740
638
  message: errorUtil_1.errorUtil.toString(message),
741
639
  });
742
- };
743
- ZodNumber.prototype.multipleOf = function (value, message) {
640
+ }
641
+ multipleOf(value, message) {
744
642
  return this._addCheck({
745
643
  kind: "multipleOf",
746
644
  value: value,
747
645
  message: errorUtil_1.errorUtil.toString(message),
748
646
  });
749
- };
750
- Object.defineProperty(ZodNumber.prototype, "minValue", {
751
- get: function () {
752
- var e_3, _a;
753
- var min = null;
754
- try {
755
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
756
- var ch = _c.value;
757
- if (ch.kind === "min") {
758
- if (min === null || ch.value > min)
759
- min = ch.value;
760
- }
761
- }
762
- }
763
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
764
- finally {
765
- try {
766
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
767
- }
768
- finally { if (e_3) throw e_3.error; }
769
- }
770
- return min;
771
- },
772
- enumerable: false,
773
- configurable: true
774
- });
775
- Object.defineProperty(ZodNumber.prototype, "maxValue", {
776
- get: function () {
777
- var e_4, _a;
778
- var max = null;
779
- try {
780
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
781
- var ch = _c.value;
782
- if (ch.kind === "max") {
783
- if (max === null || ch.value < max)
784
- max = ch.value;
785
- }
786
- }
647
+ }
648
+ get minValue() {
649
+ let min = null;
650
+ for (const ch of this._def.checks) {
651
+ if (ch.kind === "min") {
652
+ if (min === null || ch.value > min)
653
+ min = ch.value;
787
654
  }
788
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
789
- finally {
790
- try {
791
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
792
- }
793
- finally { if (e_4) throw e_4.error; }
655
+ }
656
+ return min;
657
+ }
658
+ get maxValue() {
659
+ let max = null;
660
+ for (const ch of this._def.checks) {
661
+ if (ch.kind === "max") {
662
+ if (max === null || ch.value < max)
663
+ max = ch.value;
794
664
  }
795
- return max;
796
- },
797
- enumerable: false,
798
- configurable: true
799
- });
800
- Object.defineProperty(ZodNumber.prototype, "isInt", {
801
- get: function () {
802
- return !!this._def.checks.find(function (ch) { return ch.kind === "int"; });
803
- },
804
- enumerable: false,
805
- configurable: true
806
- });
807
- ZodNumber.create = function (params) {
808
- return new ZodNumber(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber }, processCreateParams(params)));
809
- };
810
- return ZodNumber;
811
- }(ZodType));
665
+ }
666
+ return max;
667
+ }
668
+ get isInt() {
669
+ return !!this._def.checks.find((ch) => ch.kind === "int");
670
+ }
671
+ }
812
672
  exports.ZodNumber = ZodNumber;
813
- var ZodBigInt = /** @class */ (function (_super) {
814
- __extends(ZodBigInt, _super);
815
- function ZodBigInt() {
816
- return _super !== null && _super.apply(this, arguments) || this;
817
- }
818
- ZodBigInt.prototype._parse = function (input) {
819
- var ctx = this._processInputParams(input).ctx;
820
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.bigint) {
673
+ ZodNumber.create = (params) => {
674
+ return new ZodNumber({
675
+ checks: [],
676
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
677
+ ...processCreateParams(params),
678
+ });
679
+ };
680
+ class ZodBigInt extends ZodType {
681
+ _parse(input) {
682
+ const parsedType = this._getType(input);
683
+ if (parsedType !== parseUtil_1.ZodParsedType.bigint) {
684
+ const ctx = this._getOrReturnCtx(input);
821
685
  (0, parseUtil_1.addIssueToContext)(ctx, {
822
686
  code: ZodError_1.ZodIssueCode.invalid_type,
823
687
  expected: parseUtil_1.ZodParsedType.bigint,
@@ -825,22 +689,21 @@ var ZodBigInt = /** @class */ (function (_super) {
825
689
  });
826
690
  return parseUtil_1.INVALID;
827
691
  }
828
- return (0, parseUtil_1.OK)(ctx.data);
829
- };
830
- ZodBigInt.create = function (params) {
831
- return new ZodBigInt(__assign({ typeName: ZodFirstPartyTypeKind.ZodBigInt }, processCreateParams(params)));
832
- };
833
- return ZodBigInt;
834
- }(ZodType));
692
+ return (0, parseUtil_1.OK)(input.data);
693
+ }
694
+ }
835
695
  exports.ZodBigInt = ZodBigInt;
836
- var ZodBoolean = /** @class */ (function (_super) {
837
- __extends(ZodBoolean, _super);
838
- function ZodBoolean() {
839
- return _super !== null && _super.apply(this, arguments) || this;
840
- }
841
- ZodBoolean.prototype._parse = function (input) {
842
- var ctx = this._processInputParams(input).ctx;
843
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.boolean) {
696
+ ZodBigInt.create = (params) => {
697
+ return new ZodBigInt({
698
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
699
+ ...processCreateParams(params),
700
+ });
701
+ };
702
+ class ZodBoolean extends ZodType {
703
+ _parse(input) {
704
+ const parsedType = this._getType(input);
705
+ if (parsedType !== parseUtil_1.ZodParsedType.boolean) {
706
+ const ctx = this._getOrReturnCtx(input);
844
707
  (0, parseUtil_1.addIssueToContext)(ctx, {
845
708
  code: ZodError_1.ZodIssueCode.invalid_type,
846
709
  expected: parseUtil_1.ZodParsedType.boolean,
@@ -848,22 +711,21 @@ var ZodBoolean = /** @class */ (function (_super) {
848
711
  });
849
712
  return parseUtil_1.INVALID;
850
713
  }
851
- return (0, parseUtil_1.OK)(ctx.data);
852
- };
853
- ZodBoolean.create = function (params) {
854
- return new ZodBoolean(__assign({ typeName: ZodFirstPartyTypeKind.ZodBoolean }, processCreateParams(params)));
855
- };
856
- return ZodBoolean;
857
- }(ZodType));
714
+ return (0, parseUtil_1.OK)(input.data);
715
+ }
716
+ }
858
717
  exports.ZodBoolean = ZodBoolean;
859
- var ZodDate = /** @class */ (function (_super) {
860
- __extends(ZodDate, _super);
861
- function ZodDate() {
862
- return _super !== null && _super.apply(this, arguments) || this;
863
- }
864
- ZodDate.prototype._parse = function (input) {
865
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
866
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.date) {
718
+ ZodBoolean.create = (params) => {
719
+ return new ZodBoolean({
720
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
721
+ ...processCreateParams(params),
722
+ });
723
+ };
724
+ class ZodDate extends ZodType {
725
+ _parse(input) {
726
+ const parsedType = this._getType(input);
727
+ if (parsedType !== parseUtil_1.ZodParsedType.date) {
728
+ const ctx = this._getOrReturnCtx(input);
867
729
  (0, parseUtil_1.addIssueToContext)(ctx, {
868
730
  code: ZodError_1.ZodIssueCode.invalid_type,
869
731
  expected: parseUtil_1.ZodParsedType.date,
@@ -871,31 +733,31 @@ var ZodDate = /** @class */ (function (_super) {
871
733
  });
872
734
  return parseUtil_1.INVALID;
873
735
  }
874
- if (isNaN(ctx.data.getTime())) {
736
+ if (isNaN(input.data.getTime())) {
737
+ const ctx = this._getOrReturnCtx(input);
875
738
  (0, parseUtil_1.addIssueToContext)(ctx, {
876
739
  code: ZodError_1.ZodIssueCode.invalid_date,
877
740
  });
878
741
  return parseUtil_1.INVALID;
879
742
  }
880
743
  return {
881
- status: status.value,
882
- value: new Date(ctx.data.getTime()),
744
+ status: "valid",
745
+ value: new Date(input.data.getTime()),
883
746
  };
884
- };
885
- ZodDate.create = function (params) {
886
- return new ZodDate(__assign({ typeName: ZodFirstPartyTypeKind.ZodDate }, processCreateParams(params)));
887
- };
888
- return ZodDate;
889
- }(ZodType));
747
+ }
748
+ }
890
749
  exports.ZodDate = ZodDate;
891
- var ZodUndefined = /** @class */ (function (_super) {
892
- __extends(ZodUndefined, _super);
893
- function ZodUndefined() {
894
- return _super !== null && _super.apply(this, arguments) || this;
895
- }
896
- ZodUndefined.prototype._parse = function (input) {
897
- var ctx = this._processInputParams(input).ctx;
898
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.undefined) {
750
+ ZodDate.create = (params) => {
751
+ return new ZodDate({
752
+ typeName: ZodFirstPartyTypeKind.ZodDate,
753
+ ...processCreateParams(params),
754
+ });
755
+ };
756
+ class ZodUndefined extends ZodType {
757
+ _parse(input) {
758
+ const parsedType = this._getType(input);
759
+ if (parsedType !== parseUtil_1.ZodParsedType.undefined) {
760
+ const ctx = this._getOrReturnCtx(input);
899
761
  (0, parseUtil_1.addIssueToContext)(ctx, {
900
762
  code: ZodError_1.ZodIssueCode.invalid_type,
901
763
  expected: parseUtil_1.ZodParsedType.undefined,
@@ -903,22 +765,21 @@ var ZodUndefined = /** @class */ (function (_super) {
903
765
  });
904
766
  return parseUtil_1.INVALID;
905
767
  }
906
- return (0, parseUtil_1.OK)(ctx.data);
907
- };
908
- ZodUndefined.create = function (params) {
909
- return new ZodUndefined(__assign({ typeName: ZodFirstPartyTypeKind.ZodUndefined }, processCreateParams(params)));
910
- };
911
- return ZodUndefined;
912
- }(ZodType));
768
+ return (0, parseUtil_1.OK)(input.data);
769
+ }
770
+ }
913
771
  exports.ZodUndefined = ZodUndefined;
914
- var ZodNull = /** @class */ (function (_super) {
915
- __extends(ZodNull, _super);
916
- function ZodNull() {
917
- return _super !== null && _super.apply(this, arguments) || this;
918
- }
919
- ZodNull.prototype._parse = function (input) {
920
- var ctx = this._processInputParams(input).ctx;
921
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.null) {
772
+ ZodUndefined.create = (params) => {
773
+ return new ZodUndefined({
774
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
775
+ ...processCreateParams(params),
776
+ });
777
+ };
778
+ class ZodNull extends ZodType {
779
+ _parse(input) {
780
+ const parsedType = this._getType(input);
781
+ if (parsedType !== parseUtil_1.ZodParsedType.null) {
782
+ const ctx = this._getOrReturnCtx(input);
922
783
  (0, parseUtil_1.addIssueToContext)(ctx, {
923
784
  code: ZodError_1.ZodIssueCode.invalid_type,
924
785
  expected: parseUtil_1.ZodParsedType.null,
@@ -926,78 +787,73 @@ var ZodNull = /** @class */ (function (_super) {
926
787
  });
927
788
  return parseUtil_1.INVALID;
928
789
  }
929
- return (0, parseUtil_1.OK)(ctx.data);
930
- };
931
- ZodNull.create = function (params) {
932
- return new ZodNull(__assign({ typeName: ZodFirstPartyTypeKind.ZodNull }, processCreateParams(params)));
933
- };
934
- return ZodNull;
935
- }(ZodType));
790
+ return (0, parseUtil_1.OK)(input.data);
791
+ }
792
+ }
936
793
  exports.ZodNull = ZodNull;
937
- var ZodAny = /** @class */ (function (_super) {
938
- __extends(ZodAny, _super);
939
- function ZodAny() {
940
- var _this = _super !== null && _super.apply(this, arguments) || this;
794
+ ZodNull.create = (params) => {
795
+ return new ZodNull({
796
+ typeName: ZodFirstPartyTypeKind.ZodNull,
797
+ ...processCreateParams(params),
798
+ });
799
+ };
800
+ class ZodAny extends ZodType {
801
+ constructor() {
802
+ super(...arguments);
941
803
  // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
942
- _this._any = true;
943
- return _this;
804
+ this._any = true;
944
805
  }
945
- ZodAny.prototype._parse = function (input) {
946
- var ctx = this._processInputParams(input).ctx;
947
- return (0, parseUtil_1.OK)(ctx.data);
948
- };
949
- ZodAny.create = function (params) {
950
- return new ZodAny(__assign({ typeName: ZodFirstPartyTypeKind.ZodAny }, processCreateParams(params)));
951
- };
952
- return ZodAny;
953
- }(ZodType));
806
+ _parse(input) {
807
+ return (0, parseUtil_1.OK)(input.data);
808
+ }
809
+ }
954
810
  exports.ZodAny = ZodAny;
955
- var ZodUnknown = /** @class */ (function (_super) {
956
- __extends(ZodUnknown, _super);
957
- function ZodUnknown() {
958
- var _this = _super !== null && _super.apply(this, arguments) || this;
811
+ ZodAny.create = (params) => {
812
+ return new ZodAny({
813
+ typeName: ZodFirstPartyTypeKind.ZodAny,
814
+ ...processCreateParams(params),
815
+ });
816
+ };
817
+ class ZodUnknown extends ZodType {
818
+ constructor() {
819
+ super(...arguments);
959
820
  // required
960
- _this._unknown = true;
961
- return _this;
821
+ this._unknown = true;
962
822
  }
963
- ZodUnknown.prototype._parse = function (input) {
964
- var ctx = this._processInputParams(input).ctx;
965
- return (0, parseUtil_1.OK)(ctx.data);
966
- };
967
- ZodUnknown.create = function (params) {
968
- return new ZodUnknown(__assign({ typeName: ZodFirstPartyTypeKind.ZodUnknown }, processCreateParams(params)));
969
- };
970
- return ZodUnknown;
971
- }(ZodType));
972
- exports.ZodUnknown = ZodUnknown;
973
- var ZodNever = /** @class */ (function (_super) {
974
- __extends(ZodNever, _super);
975
- function ZodNever() {
976
- return _super !== null && _super.apply(this, arguments) || this;
823
+ _parse(input) {
824
+ return (0, parseUtil_1.OK)(input.data);
977
825
  }
978
- ZodNever.prototype._parse = function (input) {
979
- var ctx = this._processInputParams(input).ctx;
826
+ }
827
+ exports.ZodUnknown = ZodUnknown;
828
+ ZodUnknown.create = (params) => {
829
+ return new ZodUnknown({
830
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
831
+ ...processCreateParams(params),
832
+ });
833
+ };
834
+ class ZodNever extends ZodType {
835
+ _parse(input) {
836
+ const ctx = this._getOrReturnCtx(input);
980
837
  (0, parseUtil_1.addIssueToContext)(ctx, {
981
838
  code: ZodError_1.ZodIssueCode.invalid_type,
982
839
  expected: parseUtil_1.ZodParsedType.never,
983
840
  received: ctx.parsedType,
984
841
  });
985
842
  return parseUtil_1.INVALID;
986
- };
987
- ZodNever.create = function (params) {
988
- return new ZodNever(__assign({ typeName: ZodFirstPartyTypeKind.ZodNever }, processCreateParams(params)));
989
- };
990
- return ZodNever;
991
- }(ZodType));
843
+ }
844
+ }
992
845
  exports.ZodNever = ZodNever;
993
- var ZodVoid = /** @class */ (function (_super) {
994
- __extends(ZodVoid, _super);
995
- function ZodVoid() {
996
- return _super !== null && _super.apply(this, arguments) || this;
997
- }
998
- ZodVoid.prototype._parse = function (input) {
999
- var ctx = this._processInputParams(input).ctx;
1000
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.undefined) {
846
+ ZodNever.create = (params) => {
847
+ return new ZodNever({
848
+ typeName: ZodFirstPartyTypeKind.ZodNever,
849
+ ...processCreateParams(params),
850
+ });
851
+ };
852
+ class ZodVoid extends ZodType {
853
+ _parse(input) {
854
+ const parsedType = this._getType(input);
855
+ if (parsedType !== parseUtil_1.ZodParsedType.undefined) {
856
+ const ctx = this._getOrReturnCtx(input);
1001
857
  (0, parseUtil_1.addIssueToContext)(ctx, {
1002
858
  code: ZodError_1.ZodIssueCode.invalid_type,
1003
859
  expected: parseUtil_1.ZodParsedType.void,
@@ -1005,22 +861,20 @@ var ZodVoid = /** @class */ (function (_super) {
1005
861
  });
1006
862
  return parseUtil_1.INVALID;
1007
863
  }
1008
- return (0, parseUtil_1.OK)(ctx.data);
1009
- };
1010
- ZodVoid.create = function (params) {
1011
- return new ZodVoid(__assign({ typeName: ZodFirstPartyTypeKind.ZodVoid }, processCreateParams(params)));
1012
- };
1013
- return ZodVoid;
1014
- }(ZodType));
864
+ return (0, parseUtil_1.OK)(input.data);
865
+ }
866
+ }
1015
867
  exports.ZodVoid = ZodVoid;
1016
- var ZodArray = /** @class */ (function (_super) {
1017
- __extends(ZodArray, _super);
1018
- function ZodArray() {
1019
- return _super !== null && _super.apply(this, arguments) || this;
1020
- }
1021
- ZodArray.prototype._parse = function (input) {
1022
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1023
- var def = this._def;
868
+ ZodVoid.create = (params) => {
869
+ return new ZodVoid({
870
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
871
+ ...processCreateParams(params),
872
+ });
873
+ };
874
+ class ZodArray extends ZodType {
875
+ _parse(input) {
876
+ const { ctx, status } = this._processInputParams(input);
877
+ const def = this._def;
1024
878
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.array) {
1025
879
  (0, parseUtil_1.addIssueToContext)(ctx, {
1026
880
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -1053,51 +907,58 @@ var ZodArray = /** @class */ (function (_super) {
1053
907
  status.dirty();
1054
908
  }
1055
909
  }
1056
- if (ctx.async) {
1057
- return Promise.all(ctx.data.map(function (item, i) {
910
+ if (ctx.common.async) {
911
+ return Promise.all(ctx.data.map((item, i) => {
1058
912
  return def.type._parseAsync({
1059
913
  parent: ctx,
1060
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
914
+ path: [...ctx.path, i],
1061
915
  data: item,
1062
916
  });
1063
- })).then(function (result) {
917
+ })).then((result) => {
1064
918
  return parseUtil_1.ParseStatus.mergeArray(status, result);
1065
919
  });
1066
920
  }
1067
- var result = ctx.data.map(function (item, i) {
921
+ const result = ctx.data.map((item, i) => {
1068
922
  return def.type._parseSync({
1069
923
  parent: ctx,
1070
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false),
924
+ path: [...ctx.path, i],
1071
925
  data: item,
1072
926
  });
1073
927
  });
1074
928
  return parseUtil_1.ParseStatus.mergeArray(status, result);
1075
- };
1076
- Object.defineProperty(ZodArray.prototype, "element", {
1077
- get: function () {
1078
- return this._def.type;
1079
- },
1080
- enumerable: false,
1081
- configurable: true
1082
- });
1083
- ZodArray.prototype.min = function (minLength, message) {
1084
- return new ZodArray(__assign(__assign({}, this._def), { minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) } }));
1085
- };
1086
- ZodArray.prototype.max = function (maxLength, message) {
1087
- return new ZodArray(__assign(__assign({}, this._def), { maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) } }));
1088
- };
1089
- ZodArray.prototype.length = function (len, message) {
929
+ }
930
+ get element() {
931
+ return this._def.type;
932
+ }
933
+ min(minLength, message) {
934
+ return new ZodArray({
935
+ ...this._def,
936
+ minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) },
937
+ });
938
+ }
939
+ max(maxLength, message) {
940
+ return new ZodArray({
941
+ ...this._def,
942
+ maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) },
943
+ });
944
+ }
945
+ length(len, message) {
1090
946
  return this.min(len, message).max(len, message);
1091
- };
1092
- ZodArray.prototype.nonempty = function (message) {
947
+ }
948
+ nonempty(message) {
1093
949
  return this.min(1, message);
1094
- };
1095
- ZodArray.create = function (schema, params) {
1096
- return new ZodArray(__assign({ type: schema, minLength: null, maxLength: null, typeName: ZodFirstPartyTypeKind.ZodArray }, processCreateParams(params)));
1097
- };
1098
- return ZodArray;
1099
- }(ZodType));
950
+ }
951
+ }
1100
952
  exports.ZodArray = ZodArray;
953
+ ZodArray.create = (schema, params) => {
954
+ return new ZodArray({
955
+ type: schema,
956
+ minLength: null,
957
+ maxLength: null,
958
+ typeName: ZodFirstPartyTypeKind.ZodArray,
959
+ ...processCreateParams(params),
960
+ });
961
+ };
1101
962
  /////////////////////////////////////////
1102
963
  /////////////////////////////////////////
1103
964
  ////////// //////////
@@ -1107,23 +968,33 @@ exports.ZodArray = ZodArray;
1107
968
  /////////////////////////////////////////
1108
969
  var objectUtil;
1109
970
  (function (objectUtil) {
1110
- objectUtil.mergeShapes = function (first, second) {
1111
- return __assign(__assign({}, first), second);
971
+ objectUtil.mergeShapes = (first, second) => {
972
+ return {
973
+ ...first,
974
+ ...second, // second overwrites first
975
+ };
1112
976
  };
1113
977
  })(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
1114
- var AugmentFactory = function (def) {
1115
- return function (augmentation) {
1116
- return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
1117
- };
978
+ const AugmentFactory = (def) => (augmentation) => {
979
+ return new ZodObject({
980
+ ...def,
981
+ shape: () => ({
982
+ ...def.shape(),
983
+ ...augmentation,
984
+ }),
985
+ });
1118
986
  };
1119
987
  function deepPartialify(schema) {
1120
988
  if (schema instanceof ZodObject) {
1121
- var newShape_1 = {};
1122
- for (var key in schema.shape) {
1123
- var fieldSchema = schema.shape[key];
1124
- newShape_1[key] = ZodOptional.create(deepPartialify(fieldSchema));
1125
- }
1126
- return new ZodObject(__assign(__assign({}, schema._def), { shape: function () { return newShape_1; } }));
989
+ const newShape = {};
990
+ for (const key in schema.shape) {
991
+ const fieldSchema = schema.shape[key];
992
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
993
+ }
994
+ return new ZodObject({
995
+ ...schema._def,
996
+ shape: () => newShape,
997
+ });
1127
998
  }
1128
999
  else if (schema instanceof ZodArray) {
1129
1000
  return ZodArray.create(deepPartialify(schema.element));
@@ -1135,38 +1006,35 @@ function deepPartialify(schema) {
1135
1006
  return ZodNullable.create(deepPartialify(schema.unwrap()));
1136
1007
  }
1137
1008
  else if (schema instanceof ZodTuple) {
1138
- return ZodTuple.create(schema.items.map(function (item) { return deepPartialify(item); }));
1009
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
1139
1010
  }
1140
1011
  else {
1141
1012
  return schema;
1142
1013
  }
1143
1014
  }
1144
- var ZodObject = /** @class */ (function (_super) {
1145
- __extends(ZodObject, _super);
1146
- function ZodObject() {
1147
- var _this = _super !== null && _super.apply(this, arguments) || this;
1148
- _this._cached = null;
1015
+ class ZodObject extends ZodType {
1016
+ constructor() {
1017
+ super(...arguments);
1018
+ this._cached = null;
1149
1019
  /**
1150
1020
  * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
1151
1021
  * If you want to pass through unknown properties, use `.passthrough()` instead.
1152
1022
  */
1153
- _this.nonstrict = _this.passthrough;
1154
- _this.augment = AugmentFactory(_this._def);
1155
- _this.extend = AugmentFactory(_this._def);
1156
- return _this;
1023
+ this.nonstrict = this.passthrough;
1024
+ this.augment = AugmentFactory(this._def);
1025
+ this.extend = AugmentFactory(this._def);
1157
1026
  }
1158
- ZodObject.prototype._getCached = function () {
1027
+ _getCached() {
1159
1028
  if (this._cached !== null)
1160
1029
  return this._cached;
1161
- var shape = this._def.shape();
1162
- var keys = util_1.util.objectKeys(shape);
1163
- return (this._cached = { shape: shape, keys: keys });
1164
- };
1165
- ZodObject.prototype._parse = function (input) {
1166
- var e_5, _a, e_6, _b, e_7, _c;
1167
- var _this = this;
1168
- var _d = this._processInputParams(input), status = _d.status, ctx = _d.ctx;
1169
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
1030
+ const shape = this._def.shape();
1031
+ const keys = util_1.util.objectKeys(shape);
1032
+ return (this._cached = { shape, keys });
1033
+ }
1034
+ _parse(input) {
1035
+ const parsedType = this._getType(input);
1036
+ if (parsedType !== parseUtil_1.ZodParsedType.object) {
1037
+ const ctx = this._getOrReturnCtx(input);
1170
1038
  (0, parseUtil_1.addIssueToContext)(ctx, {
1171
1039
  code: ZodError_1.ZodIssueCode.invalid_type,
1172
1040
  expected: parseUtil_1.ZodParsedType.object,
@@ -1174,51 +1042,32 @@ var ZodObject = /** @class */ (function (_super) {
1174
1042
  });
1175
1043
  return parseUtil_1.INVALID;
1176
1044
  }
1177
- var _e = this._getCached(), shape = _e.shape, shapeKeys = _e.keys;
1178
- var dataKeys = util_1.util.objectKeys(ctx.data);
1179
- var extraKeys = dataKeys.filter(function (k) { return !shapeKeys.includes(k); });
1180
- var pairs = [];
1181
- try {
1182
- for (var shapeKeys_1 = __values(shapeKeys), shapeKeys_1_1 = shapeKeys_1.next(); !shapeKeys_1_1.done; shapeKeys_1_1 = shapeKeys_1.next()) {
1183
- var key = shapeKeys_1_1.value;
1184
- var keyValidator = shape[key];
1185
- var value = ctx.data[key];
1186
- pairs.push({
1187
- key: { status: "valid", value: key },
1188
- value: keyValidator._parse({
1189
- parent: ctx,
1190
- data: value,
1191
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
1192
- }),
1193
- alwaysSet: key in ctx.data,
1194
- });
1195
- }
1196
- }
1197
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1198
- finally {
1199
- try {
1200
- if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
1201
- }
1202
- finally { if (e_5) throw e_5.error; }
1045
+ const { status, ctx } = this._processInputParams(input);
1046
+ const { shape, keys: shapeKeys } = this._getCached();
1047
+ const dataKeys = util_1.util.objectKeys(ctx.data);
1048
+ const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k));
1049
+ const pairs = [];
1050
+ for (const key of shapeKeys) {
1051
+ const keyValidator = shape[key];
1052
+ const value = ctx.data[key];
1053
+ pairs.push({
1054
+ key: { status: "valid", value: key },
1055
+ value: keyValidator._parse({
1056
+ parent: ctx,
1057
+ data: value,
1058
+ path: [...ctx.path, key],
1059
+ }),
1060
+ alwaysSet: key in ctx.data,
1061
+ });
1203
1062
  }
1204
1063
  if (this._def.catchall instanceof ZodNever) {
1205
- var unknownKeys = this._def.unknownKeys;
1064
+ const unknownKeys = this._def.unknownKeys;
1206
1065
  if (unknownKeys === "passthrough") {
1207
- try {
1208
- for (var extraKeys_1 = __values(extraKeys), extraKeys_1_1 = extraKeys_1.next(); !extraKeys_1_1.done; extraKeys_1_1 = extraKeys_1.next()) {
1209
- var key = extraKeys_1_1.value;
1210
- pairs.push({
1211
- key: { status: "valid", value: key },
1212
- value: { status: "valid", value: ctx.data[key] },
1213
- });
1214
- }
1215
- }
1216
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1217
- finally {
1218
- try {
1219
- if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
1220
- }
1221
- finally { if (e_6) throw e_6.error; }
1066
+ for (const key of extraKeys) {
1067
+ pairs.push({
1068
+ key: { status: "valid", value: key },
1069
+ value: { status: "valid", value: ctx.data[key] },
1070
+ });
1222
1071
  }
1223
1072
  }
1224
1073
  else if (unknownKeys === "strict") {
@@ -1233,323 +1082,304 @@ var ZodObject = /** @class */ (function (_super) {
1233
1082
  else if (unknownKeys === "strip") {
1234
1083
  }
1235
1084
  else {
1236
- throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1085
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
1237
1086
  }
1238
1087
  }
1239
1088
  else {
1240
1089
  // run catchall validation
1241
- var catchall = this._def.catchall;
1242
- try {
1243
- for (var extraKeys_2 = __values(extraKeys), extraKeys_2_1 = extraKeys_2.next(); !extraKeys_2_1.done; extraKeys_2_1 = extraKeys_2.next()) {
1244
- var key = extraKeys_2_1.value;
1245
- var value = ctx.data[key];
1246
- pairs.push({
1247
- key: { status: "valid", value: key },
1248
- value: catchall._parse({ parent: ctx, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false), data: value } //, ctx.child(key), value, getParsedType(value)
1249
- ),
1250
- alwaysSet: key in ctx.data,
1251
- });
1252
- }
1253
- }
1254
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1255
- finally {
1256
- try {
1257
- if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
1258
- }
1259
- finally { if (e_7) throw e_7.error; }
1090
+ const catchall = this._def.catchall;
1091
+ for (const key of extraKeys) {
1092
+ const value = ctx.data[key];
1093
+ pairs.push({
1094
+ key: { status: "valid", value: key },
1095
+ value: catchall._parse({ parent: ctx, path: [...ctx.path, key], data: value } //, ctx.child(key), value, getParsedType(value)
1096
+ ),
1097
+ alwaysSet: key in ctx.data,
1098
+ });
1260
1099
  }
1261
1100
  }
1262
- if (ctx.async) {
1101
+ if (ctx.common.async) {
1263
1102
  return Promise.resolve()
1264
- .then(function () { return __awaiter(_this, void 0, void 0, function () {
1265
- var syncPairs, pairs_1, pairs_1_1, pair, key, _a, _b, e_8_1;
1266
- var e_8, _c, _d;
1267
- return __generator(this, function (_e) {
1268
- switch (_e.label) {
1269
- case 0:
1270
- syncPairs = [];
1271
- _e.label = 1;
1272
- case 1:
1273
- _e.trys.push([1, 7, 8, 9]);
1274
- pairs_1 = __values(pairs), pairs_1_1 = pairs_1.next();
1275
- _e.label = 2;
1276
- case 2:
1277
- if (!!pairs_1_1.done) return [3 /*break*/, 6];
1278
- pair = pairs_1_1.value;
1279
- return [4 /*yield*/, pair.key];
1280
- case 3:
1281
- key = _e.sent();
1282
- _b = (_a = syncPairs).push;
1283
- _d = {
1284
- key: key
1285
- };
1286
- return [4 /*yield*/, pair.value];
1287
- case 4:
1288
- _b.apply(_a, [(_d.value = _e.sent(),
1289
- _d.alwaysSet = pair.alwaysSet,
1290
- _d)]);
1291
- _e.label = 5;
1292
- case 5:
1293
- pairs_1_1 = pairs_1.next();
1294
- return [3 /*break*/, 2];
1295
- case 6: return [3 /*break*/, 9];
1296
- case 7:
1297
- e_8_1 = _e.sent();
1298
- e_8 = { error: e_8_1 };
1299
- return [3 /*break*/, 9];
1300
- case 8:
1301
- try {
1302
- if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
1303
- }
1304
- finally { if (e_8) throw e_8.error; }
1305
- return [7 /*endfinally*/];
1306
- case 9: return [2 /*return*/, syncPairs];
1307
- }
1308
- });
1309
- }); })
1310
- .then(function (syncPairs) {
1103
+ .then(async () => {
1104
+ const syncPairs = [];
1105
+ for (const pair of pairs) {
1106
+ const key = await pair.key;
1107
+ syncPairs.push({
1108
+ key,
1109
+ value: await pair.value,
1110
+ alwaysSet: pair.alwaysSet,
1111
+ });
1112
+ }
1113
+ return syncPairs;
1114
+ })
1115
+ .then((syncPairs) => {
1311
1116
  return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
1312
1117
  });
1313
1118
  }
1314
1119
  else {
1315
1120
  return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
1316
1121
  }
1317
- };
1318
- Object.defineProperty(ZodObject.prototype, "shape", {
1319
- get: function () {
1320
- return this._def.shape();
1321
- },
1322
- enumerable: false,
1323
- configurable: true
1324
- });
1325
- ZodObject.prototype.strict = function (message) {
1326
- var _this = this;
1122
+ }
1123
+ get shape() {
1124
+ return this._def.shape();
1125
+ }
1126
+ strict(message) {
1327
1127
  errorUtil_1.errorUtil.errToObj;
1328
- return new ZodObject(__assign(__assign(__assign({}, this._def), { unknownKeys: "strict" }), (message !== undefined
1329
- ? {
1330
- errorMap: function (issue, ctx) {
1331
- var _a, _b, _c, _d;
1332
- var defaultError = (_c = (_b = (_a = _this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
1333
- if (issue.code === "unrecognized_keys")
1128
+ return new ZodObject({
1129
+ ...this._def,
1130
+ unknownKeys: "strict",
1131
+ ...(message !== undefined
1132
+ ? {
1133
+ errorMap: (issue, ctx) => {
1134
+ var _a, _b, _c, _d;
1135
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
1136
+ if (issue.code === "unrecognized_keys")
1137
+ return {
1138
+ message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
1139
+ };
1334
1140
  return {
1335
- message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
1141
+ message: defaultError,
1336
1142
  };
1337
- return {
1338
- message: defaultError,
1339
- };
1340
- },
1341
- }
1342
- : {})));
1343
- };
1344
- ZodObject.prototype.strip = function () {
1345
- return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "strip" }));
1346
- };
1347
- ZodObject.prototype.passthrough = function () {
1348
- return new ZodObject(__assign(__assign({}, this._def), { unknownKeys: "passthrough" }));
1349
- };
1350
- ZodObject.prototype.setKey = function (key, schema) {
1351
- var _a;
1352
- return this.augment((_a = {}, _a[key] = schema, _a));
1353
- };
1143
+ },
1144
+ }
1145
+ : {}),
1146
+ });
1147
+ }
1148
+ strip() {
1149
+ return new ZodObject({
1150
+ ...this._def,
1151
+ unknownKeys: "strip",
1152
+ });
1153
+ }
1154
+ passthrough() {
1155
+ return new ZodObject({
1156
+ ...this._def,
1157
+ unknownKeys: "passthrough",
1158
+ });
1159
+ }
1160
+ setKey(key, schema) {
1161
+ return this.augment({ [key]: schema });
1162
+ }
1354
1163
  /**
1355
1164
  * Prior to zod@1.0.12 there was a bug in the
1356
1165
  * inferred type of merged objects. Please
1357
1166
  * upgrade if you are experiencing issues.
1358
1167
  */
1359
- ZodObject.prototype.merge = function (merging) {
1360
- var _this = this;
1168
+ merge(merging) {
1361
1169
  // const mergedShape = objectUtil.mergeShapes(
1362
1170
  // this._def.shape(),
1363
1171
  // merging._def.shape()
1364
1172
  // );
1365
- var merged = new ZodObject({
1173
+ const merged = new ZodObject({
1366
1174
  unknownKeys: merging._def.unknownKeys,
1367
1175
  catchall: merging._def.catchall,
1368
- shape: function () {
1369
- return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
1370
- },
1176
+ shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1371
1177
  typeName: ZodFirstPartyTypeKind.ZodObject,
1372
1178
  });
1373
1179
  return merged;
1374
- };
1375
- ZodObject.prototype.catchall = function (index) {
1376
- return new ZodObject(__assign(__assign({}, this._def), { catchall: index }));
1377
- };
1378
- ZodObject.prototype.pick = function (mask) {
1379
- var _this = this;
1380
- var shape = {};
1381
- util_1.util.objectKeys(mask).map(function (key) {
1382
- shape[key] = _this.shape[key];
1180
+ }
1181
+ catchall(index) {
1182
+ return new ZodObject({
1183
+ ...this._def,
1184
+ catchall: index,
1383
1185
  });
1384
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
1385
- };
1386
- ZodObject.prototype.omit = function (mask) {
1387
- var _this = this;
1388
- var shape = {};
1389
- util_1.util.objectKeys(this.shape).map(function (key) {
1186
+ }
1187
+ pick(mask) {
1188
+ const shape = {};
1189
+ util_1.util.objectKeys(mask).map((key) => {
1190
+ shape[key] = this.shape[key];
1191
+ });
1192
+ return new ZodObject({
1193
+ ...this._def,
1194
+ shape: () => shape,
1195
+ });
1196
+ }
1197
+ omit(mask) {
1198
+ const shape = {};
1199
+ util_1.util.objectKeys(this.shape).map((key) => {
1390
1200
  if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
1391
- shape[key] = _this.shape[key];
1201
+ shape[key] = this.shape[key];
1392
1202
  }
1393
1203
  });
1394
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return shape; } }));
1395
- };
1396
- ZodObject.prototype.deepPartial = function () {
1204
+ return new ZodObject({
1205
+ ...this._def,
1206
+ shape: () => shape,
1207
+ });
1208
+ }
1209
+ deepPartial() {
1397
1210
  return deepPartialify(this);
1398
- };
1399
- ZodObject.prototype.partial = function (mask) {
1400
- var _this = this;
1401
- var newShape = {};
1211
+ }
1212
+ partial(mask) {
1213
+ const newShape = {};
1402
1214
  if (mask) {
1403
- util_1.util.objectKeys(this.shape).map(function (key) {
1215
+ util_1.util.objectKeys(this.shape).map((key) => {
1404
1216
  if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
1405
- newShape[key] = _this.shape[key];
1217
+ newShape[key] = this.shape[key];
1406
1218
  }
1407
1219
  else {
1408
- newShape[key] = _this.shape[key].optional();
1220
+ newShape[key] = this.shape[key].optional();
1409
1221
  }
1410
1222
  });
1411
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
1223
+ return new ZodObject({
1224
+ ...this._def,
1225
+ shape: () => newShape,
1226
+ });
1412
1227
  }
1413
1228
  else {
1414
- for (var key in this.shape) {
1415
- var fieldSchema = this.shape[key];
1229
+ for (const key in this.shape) {
1230
+ const fieldSchema = this.shape[key];
1416
1231
  newShape[key] = fieldSchema.optional();
1417
1232
  }
1418
1233
  }
1419
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
1420
- };
1421
- ZodObject.prototype.required = function () {
1422
- var newShape = {};
1423
- for (var key in this.shape) {
1424
- var fieldSchema = this.shape[key];
1425
- var newField = fieldSchema;
1234
+ return new ZodObject({
1235
+ ...this._def,
1236
+ shape: () => newShape,
1237
+ });
1238
+ }
1239
+ required() {
1240
+ const newShape = {};
1241
+ for (const key in this.shape) {
1242
+ const fieldSchema = this.shape[key];
1243
+ let newField = fieldSchema;
1426
1244
  while (newField instanceof ZodOptional) {
1427
1245
  newField = newField._def.innerType;
1428
1246
  }
1429
1247
  newShape[key] = newField;
1430
1248
  }
1431
- return new ZodObject(__assign(__assign({}, this._def), { shape: function () { return newShape; } }));
1432
- };
1433
- ZodObject.create = function (shape, params) {
1434
- return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
1435
- };
1436
- ZodObject.strictCreate = function (shape, params) {
1437
- return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
1438
- };
1439
- ZodObject.lazycreate = function (shape, params) {
1440
- return new ZodObject(__assign({ shape: shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
1441
- };
1442
- return ZodObject;
1443
- }(ZodType));
1249
+ return new ZodObject({
1250
+ ...this._def,
1251
+ shape: () => newShape,
1252
+ });
1253
+ }
1254
+ }
1444
1255
  exports.ZodObject = ZodObject;
1445
- var ZodUnion = /** @class */ (function (_super) {
1446
- __extends(ZodUnion, _super);
1447
- function ZodUnion() {
1448
- return _super !== null && _super.apply(this, arguments) || this;
1449
- }
1450
- ZodUnion.prototype._parse = function (input) {
1451
- var _this = this;
1452
- var ctx = this._processInputParams(input).ctx;
1453
- var options = this._def.options;
1256
+ ZodObject.create = (shape, params) => {
1257
+ return new ZodObject({
1258
+ shape: () => shape,
1259
+ unknownKeys: "strip",
1260
+ catchall: ZodNever.create(),
1261
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1262
+ ...processCreateParams(params),
1263
+ });
1264
+ };
1265
+ ZodObject.strictCreate = (shape, params) => {
1266
+ return new ZodObject({
1267
+ shape: () => shape,
1268
+ unknownKeys: "strict",
1269
+ catchall: ZodNever.create(),
1270
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1271
+ ...processCreateParams(params),
1272
+ });
1273
+ };
1274
+ ZodObject.lazycreate = (shape, params) => {
1275
+ return new ZodObject({
1276
+ shape,
1277
+ unknownKeys: "strip",
1278
+ catchall: ZodNever.create(),
1279
+ typeName: ZodFirstPartyTypeKind.ZodObject,
1280
+ ...processCreateParams(params),
1281
+ });
1282
+ };
1283
+ class ZodUnion extends ZodType {
1284
+ _parse(input) {
1285
+ const { ctx } = this._processInputParams(input);
1286
+ const options = this._def.options;
1454
1287
  function handleResults(results) {
1455
- var e_9, _a, e_10, _b, _c;
1456
- try {
1457
- // return first issue-free validation if it exists
1458
- for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
1459
- var result = results_1_1.value;
1460
- if (result.result.status === "valid") {
1461
- return result.result;
1462
- }
1288
+ // return first issue-free validation if it exists
1289
+ for (const result of results) {
1290
+ if (result.result.status === "valid") {
1291
+ return result.result;
1463
1292
  }
1464
1293
  }
1465
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1466
- finally {
1467
- try {
1468
- if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
1469
- }
1470
- finally { if (e_9) throw e_9.error; }
1471
- }
1472
- try {
1473
- for (var results_2 = __values(results), results_2_1 = results_2.next(); !results_2_1.done; results_2_1 = results_2.next()) {
1474
- var result = results_2_1.value;
1475
- if (result.result.status === "dirty") {
1476
- // add issues from dirty option
1477
- (_c = ctx.issues).push.apply(_c, __spreadArray([], __read(result.ctx.issues), false));
1478
- return result.result;
1479
- }
1480
- }
1481
- }
1482
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
1483
- finally {
1484
- try {
1485
- if (results_2_1 && !results_2_1.done && (_b = results_2.return)) _b.call(results_2);
1294
+ for (const result of results) {
1295
+ if (result.result.status === "dirty") {
1296
+ // add issues from dirty option
1297
+ ctx.common.issues.push(...result.ctx.common.issues);
1298
+ return result.result;
1486
1299
  }
1487
- finally { if (e_10) throw e_10.error; }
1488
1300
  }
1489
1301
  // return invalid
1490
- var unionErrors = results.map(function (result) { return new ZodError_1.ZodError(result.ctx.issues); });
1302
+ const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
1491
1303
  (0, parseUtil_1.addIssueToContext)(ctx, {
1492
1304
  code: ZodError_1.ZodIssueCode.invalid_union,
1493
- unionErrors: unionErrors,
1305
+ unionErrors,
1494
1306
  });
1495
1307
  return parseUtil_1.INVALID;
1496
1308
  }
1497
- if (ctx.async) {
1498
- return Promise.all(options.map(function (option) { return __awaiter(_this, void 0, void 0, function () {
1499
- var childCtx;
1500
- var _a;
1501
- return __generator(this, function (_b) {
1502
- switch (_b.label) {
1503
- case 0:
1504
- childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
1505
- _a = {};
1506
- return [4 /*yield*/, option._parseAsync({
1507
- data: ctx.data,
1508
- path: ctx.path,
1509
- parent: childCtx,
1510
- })];
1511
- case 1: return [2 /*return*/, (_a.result = _b.sent(),
1512
- _a.ctx = childCtx,
1513
- _a)];
1514
- }
1515
- });
1516
- }); })).then(handleResults);
1517
- }
1518
- else {
1519
- var optionResults = options.map(function (option) {
1520
- var childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
1309
+ if (ctx.common.async) {
1310
+ return Promise.all(options.map(async (option) => {
1311
+ const childCtx = {
1312
+ ...ctx,
1313
+ common: {
1314
+ ...ctx.common,
1315
+ issues: [],
1316
+ },
1317
+ parent: null,
1318
+ };
1521
1319
  return {
1522
- result: option._parseSync({
1320
+ result: await option._parseAsync({
1523
1321
  data: ctx.data,
1524
1322
  path: ctx.path,
1525
1323
  parent: childCtx,
1526
1324
  }),
1527
1325
  ctx: childCtx,
1528
1326
  };
1327
+ })).then(handleResults);
1328
+ }
1329
+ else {
1330
+ let dirty = undefined;
1331
+ const issues = [];
1332
+ for (const option of options) {
1333
+ const childCtx = {
1334
+ ...ctx,
1335
+ common: {
1336
+ ...ctx.common,
1337
+ issues: [],
1338
+ },
1339
+ parent: null,
1340
+ };
1341
+ const result = option._parseSync({
1342
+ data: ctx.data,
1343
+ path: ctx.path,
1344
+ parent: childCtx,
1345
+ });
1346
+ if (result.status === "valid") {
1347
+ return result;
1348
+ }
1349
+ else if (result.status === "dirty" && !dirty) {
1350
+ dirty = { result, ctx: childCtx };
1351
+ }
1352
+ if (childCtx.common.issues.length) {
1353
+ issues.push(childCtx.common.issues);
1354
+ }
1355
+ }
1356
+ if (dirty) {
1357
+ ctx.common.issues.push(...dirty.ctx.common.issues);
1358
+ return dirty.result;
1359
+ }
1360
+ const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
1361
+ (0, parseUtil_1.addIssueToContext)(ctx, {
1362
+ code: ZodError_1.ZodIssueCode.invalid_union,
1363
+ unionErrors,
1529
1364
  });
1530
- return handleResults(optionResults);
1365
+ return parseUtil_1.INVALID;
1531
1366
  }
1532
- };
1533
- Object.defineProperty(ZodUnion.prototype, "options", {
1534
- get: function () {
1535
- return this._def.options;
1536
- },
1537
- enumerable: false,
1538
- configurable: true
1539
- });
1540
- ZodUnion.create = function (types, params) {
1541
- return new ZodUnion(__assign({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion }, processCreateParams(params)));
1542
- };
1543
- return ZodUnion;
1544
- }(ZodType));
1545
- exports.ZodUnion = ZodUnion;
1546
- var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1547
- __extends(ZodDiscriminatedUnion, _super);
1548
- function ZodDiscriminatedUnion() {
1549
- return _super !== null && _super.apply(this, arguments) || this;
1550
1367
  }
1551
- ZodDiscriminatedUnion.prototype._parse = function (input) {
1552
- var ctx = this._processInputParams(input).ctx;
1368
+ get options() {
1369
+ return this._def.options;
1370
+ }
1371
+ }
1372
+ exports.ZodUnion = ZodUnion;
1373
+ ZodUnion.create = (types, params) => {
1374
+ return new ZodUnion({
1375
+ options: types,
1376
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
1377
+ ...processCreateParams(params),
1378
+ });
1379
+ };
1380
+ class ZodDiscriminatedUnion extends ZodType {
1381
+ _parse(input) {
1382
+ const { ctx } = this._processInputParams(input);
1553
1383
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
1554
1384
  (0, parseUtil_1.addIssueToContext)(ctx, {
1555
1385
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -1558,9 +1388,9 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1558
1388
  });
1559
1389
  return parseUtil_1.INVALID;
1560
1390
  }
1561
- var discriminator = this.discriminator;
1562
- var discriminatorValue = ctx.data[discriminator];
1563
- var option = this.options.get(discriminatorValue);
1391
+ const discriminator = this.discriminator;
1392
+ const discriminatorValue = ctx.data[discriminator];
1393
+ const option = this.options.get(discriminatorValue);
1564
1394
  if (!option) {
1565
1395
  (0, parseUtil_1.addIssueToContext)(ctx, {
1566
1396
  code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
@@ -1569,7 +1399,7 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1569
1399
  });
1570
1400
  return parseUtil_1.INVALID;
1571
1401
  }
1572
- if (ctx.async) {
1402
+ if (ctx.common.async) {
1573
1403
  return option._parseAsync({
1574
1404
  data: ctx.data,
1575
1405
  path: ctx.path,
@@ -1583,28 +1413,16 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1583
1413
  parent: ctx,
1584
1414
  });
1585
1415
  }
1586
- };
1587
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "discriminator", {
1588
- get: function () {
1589
- return this._def.discriminator;
1590
- },
1591
- enumerable: false,
1592
- configurable: true
1593
- });
1594
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "validDiscriminatorValues", {
1595
- get: function () {
1596
- return Array.from(this.options.keys());
1597
- },
1598
- enumerable: false,
1599
- configurable: true
1600
- });
1601
- Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
1602
- get: function () {
1603
- return this._def.options;
1604
- },
1605
- enumerable: false,
1606
- configurable: true
1607
- });
1416
+ }
1417
+ get discriminator() {
1418
+ return this._def.discriminator;
1419
+ }
1420
+ get validDiscriminatorValues() {
1421
+ return Array.from(this.options.keys());
1422
+ }
1423
+ get options() {
1424
+ return this._def.options;
1425
+ }
1608
1426
  /**
1609
1427
  * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
1610
1428
  * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
@@ -1613,12 +1431,12 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1613
1431
  * @param types an array of object schemas
1614
1432
  * @param params
1615
1433
  */
1616
- ZodDiscriminatedUnion.create = function (discriminator, types, params) {
1434
+ static create(discriminator, types, params) {
1617
1435
  // Get all the valid discriminator values
1618
- var options = new Map();
1436
+ const options = new Map();
1619
1437
  try {
1620
- types.forEach(function (type) {
1621
- var discriminatorValue = type.shape[discriminator].value;
1438
+ types.forEach((type) => {
1439
+ const discriminatorValue = type.shape[discriminator].value;
1622
1440
  options.set(discriminatorValue, type);
1623
1441
  });
1624
1442
  }
@@ -1629,40 +1447,33 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
1629
1447
  if (options.size !== types.length) {
1630
1448
  throw new Error("Some of the discriminator values are not unique");
1631
1449
  }
1632
- return new ZodDiscriminatedUnion(__assign({ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion, discriminator: discriminator, options: options }, processCreateParams(params)));
1633
- };
1634
- return ZodDiscriminatedUnion;
1635
- }(ZodType));
1450
+ return new ZodDiscriminatedUnion({
1451
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
1452
+ discriminator,
1453
+ options,
1454
+ ...processCreateParams(params),
1455
+ });
1456
+ }
1457
+ }
1636
1458
  exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
1637
1459
  function mergeValues(a, b) {
1638
- var e_11, _a;
1639
- var aType = (0, parseUtil_1.getParsedType)(a);
1640
- var bType = (0, parseUtil_1.getParsedType)(b);
1460
+ const aType = (0, parseUtil_1.getParsedType)(a);
1461
+ const bType = (0, parseUtil_1.getParsedType)(b);
1641
1462
  if (a === b) {
1642
1463
  return { valid: true, data: a };
1643
1464
  }
1644
1465
  else if (aType === parseUtil_1.ZodParsedType.object && bType === parseUtil_1.ZodParsedType.object) {
1645
- var bKeys_1 = util_1.util.objectKeys(b);
1646
- var sharedKeys = util_1.util
1466
+ const bKeys = util_1.util.objectKeys(b);
1467
+ const sharedKeys = util_1.util
1647
1468
  .objectKeys(a)
1648
- .filter(function (key) { return bKeys_1.indexOf(key) !== -1; });
1649
- var newObj = __assign(__assign({}, a), b);
1650
- try {
1651
- for (var sharedKeys_1 = __values(sharedKeys), sharedKeys_1_1 = sharedKeys_1.next(); !sharedKeys_1_1.done; sharedKeys_1_1 = sharedKeys_1.next()) {
1652
- var key = sharedKeys_1_1.value;
1653
- var sharedValue = mergeValues(a[key], b[key]);
1654
- if (!sharedValue.valid) {
1655
- return { valid: false };
1656
- }
1657
- newObj[key] = sharedValue.data;
1658
- }
1659
- }
1660
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1661
- finally {
1662
- try {
1663
- if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
1469
+ .filter((key) => bKeys.indexOf(key) !== -1);
1470
+ const newObj = { ...a, ...b };
1471
+ for (const key of sharedKeys) {
1472
+ const sharedValue = mergeValues(a[key], b[key]);
1473
+ if (!sharedValue.valid) {
1474
+ return { valid: false };
1664
1475
  }
1665
- finally { if (e_11) throw e_11.error; }
1476
+ newObj[key] = sharedValue.data;
1666
1477
  }
1667
1478
  return { valid: true, data: newObj };
1668
1479
  }
@@ -1670,11 +1481,11 @@ function mergeValues(a, b) {
1670
1481
  if (a.length !== b.length) {
1671
1482
  return { valid: false };
1672
1483
  }
1673
- var newArray = [];
1674
- for (var index = 0; index < a.length; index++) {
1675
- var itemA = a[index];
1676
- var itemB = b[index];
1677
- var sharedValue = mergeValues(itemA, itemB);
1484
+ const newArray = [];
1485
+ for (let index = 0; index < a.length; index++) {
1486
+ const itemA = a[index];
1487
+ const itemB = b[index];
1488
+ const sharedValue = mergeValues(itemA, itemB);
1678
1489
  if (!sharedValue.valid) {
1679
1490
  return { valid: false };
1680
1491
  }
@@ -1691,18 +1502,14 @@ function mergeValues(a, b) {
1691
1502
  return { valid: false };
1692
1503
  }
1693
1504
  }
1694
- var ZodIntersection = /** @class */ (function (_super) {
1695
- __extends(ZodIntersection, _super);
1696
- function ZodIntersection() {
1697
- return _super !== null && _super.apply(this, arguments) || this;
1698
- }
1699
- ZodIntersection.prototype._parse = function (input) {
1700
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1701
- var handleParsed = function (parsedLeft, parsedRight) {
1505
+ class ZodIntersection extends ZodType {
1506
+ _parse(input) {
1507
+ const { status, ctx } = this._processInputParams(input);
1508
+ const handleParsed = (parsedLeft, parsedRight) => {
1702
1509
  if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
1703
1510
  return parseUtil_1.INVALID;
1704
1511
  }
1705
- var merged = mergeValues(parsedLeft.value, parsedRight.value);
1512
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
1706
1513
  if (!merged.valid) {
1707
1514
  (0, parseUtil_1.addIssueToContext)(ctx, {
1708
1515
  code: ZodError_1.ZodIssueCode.invalid_intersection_types,
@@ -1714,7 +1521,7 @@ var ZodIntersection = /** @class */ (function (_super) {
1714
1521
  }
1715
1522
  return { status: status.value, value: merged.data };
1716
1523
  };
1717
- if (ctx.async) {
1524
+ if (ctx.common.async) {
1718
1525
  return Promise.all([
1719
1526
  this._def.left._parseAsync({
1720
1527
  data: ctx.data,
@@ -1726,10 +1533,7 @@ var ZodIntersection = /** @class */ (function (_super) {
1726
1533
  path: ctx.path,
1727
1534
  parent: ctx,
1728
1535
  }),
1729
- ]).then(function (_a) {
1730
- var _b = __read(_a, 2), left = _b[0], right = _b[1];
1731
- return handleParsed(left, right);
1732
- });
1536
+ ]).then(([left, right]) => handleParsed(left, right));
1733
1537
  }
1734
1538
  else {
1735
1539
  return handleParsed(this._def.left._parseSync({
@@ -1742,21 +1546,20 @@ var ZodIntersection = /** @class */ (function (_super) {
1742
1546
  parent: ctx,
1743
1547
  }));
1744
1548
  }
1745
- };
1746
- ZodIntersection.create = function (left, right, params) {
1747
- return new ZodIntersection(__assign({ left: left, right: right, typeName: ZodFirstPartyTypeKind.ZodIntersection }, processCreateParams(params)));
1748
- };
1749
- return ZodIntersection;
1750
- }(ZodType));
1549
+ }
1550
+ }
1751
1551
  exports.ZodIntersection = ZodIntersection;
1752
- var ZodTuple = /** @class */ (function (_super) {
1753
- __extends(ZodTuple, _super);
1754
- function ZodTuple() {
1755
- return _super !== null && _super.apply(this, arguments) || this;
1756
- }
1757
- ZodTuple.prototype._parse = function (input) {
1758
- var _this = this;
1759
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1552
+ ZodIntersection.create = (left, right, params) => {
1553
+ return new ZodIntersection({
1554
+ left: left,
1555
+ right: right,
1556
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
1557
+ ...processCreateParams(params),
1558
+ });
1559
+ };
1560
+ class ZodTuple extends ZodType {
1561
+ _parse(input) {
1562
+ const { status, ctx } = this._processInputParams(input);
1760
1563
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.array) {
1761
1564
  (0, parseUtil_1.addIssueToContext)(ctx, {
1762
1565
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -1774,7 +1577,7 @@ var ZodTuple = /** @class */ (function (_super) {
1774
1577
  });
1775
1578
  return parseUtil_1.INVALID;
1776
1579
  }
1777
- var rest = this._def.rest;
1580
+ const rest = this._def.rest;
1778
1581
  if (!rest && ctx.data.length > this._def.items.length) {
1779
1582
  (0, parseUtil_1.addIssueToContext)(ctx, {
1780
1583
  code: ZodError_1.ZodIssueCode.too_big,
@@ -1784,64 +1587,55 @@ var ZodTuple = /** @class */ (function (_super) {
1784
1587
  });
1785
1588
  status.dirty();
1786
1589
  }
1787
- var items = ctx.data
1788
- .map(function (item, itemIndex) {
1789
- var schema = _this._def.items[itemIndex] || _this._def.rest;
1590
+ const items = ctx.data
1591
+ .map((item, itemIndex) => {
1592
+ const schema = this._def.items[itemIndex] || this._def.rest;
1790
1593
  if (!schema)
1791
1594
  return null;
1792
1595
  return schema._parse({
1793
1596
  data: item,
1794
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [itemIndex], false),
1597
+ path: [...ctx.path, itemIndex],
1795
1598
  parent: ctx,
1796
1599
  });
1797
1600
  })
1798
- .filter(function (x) { return !!x; }); // filter nulls
1799
- if (ctx.async) {
1800
- return Promise.all(items).then(function (results) {
1601
+ .filter((x) => !!x); // filter nulls
1602
+ if (ctx.common.async) {
1603
+ return Promise.all(items).then((results) => {
1801
1604
  return parseUtil_1.ParseStatus.mergeArray(status, results);
1802
1605
  });
1803
1606
  }
1804
1607
  else {
1805
1608
  return parseUtil_1.ParseStatus.mergeArray(status, items);
1806
1609
  }
1807
- };
1808
- Object.defineProperty(ZodTuple.prototype, "items", {
1809
- get: function () {
1810
- return this._def.items;
1811
- },
1812
- enumerable: false,
1813
- configurable: true
1814
- });
1815
- ZodTuple.prototype.rest = function (rest) {
1816
- return new ZodTuple(__assign(__assign({}, this._def), { rest: rest }));
1817
- };
1818
- ZodTuple.create = function (schemas, params) {
1819
- return new ZodTuple(__assign({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null }, processCreateParams(params)));
1820
- };
1821
- return ZodTuple;
1822
- }(ZodType));
1610
+ }
1611
+ get items() {
1612
+ return this._def.items;
1613
+ }
1614
+ rest(rest) {
1615
+ return new ZodTuple({
1616
+ ...this._def,
1617
+ rest,
1618
+ });
1619
+ }
1620
+ }
1823
1621
  exports.ZodTuple = ZodTuple;
1824
- var ZodRecord = /** @class */ (function (_super) {
1825
- __extends(ZodRecord, _super);
1826
- function ZodRecord() {
1827
- return _super !== null && _super.apply(this, arguments) || this;
1828
- }
1829
- Object.defineProperty(ZodRecord.prototype, "keySchema", {
1830
- get: function () {
1831
- return this._def.keyType;
1832
- },
1833
- enumerable: false,
1834
- configurable: true
1622
+ ZodTuple.create = (schemas, params) => {
1623
+ return new ZodTuple({
1624
+ items: schemas,
1625
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
1626
+ rest: null,
1627
+ ...processCreateParams(params),
1835
1628
  });
1836
- Object.defineProperty(ZodRecord.prototype, "valueSchema", {
1837
- get: function () {
1838
- return this._def.valueType;
1839
- },
1840
- enumerable: false,
1841
- configurable: true
1842
- });
1843
- ZodRecord.prototype._parse = function (input) {
1844
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1629
+ };
1630
+ class ZodRecord extends ZodType {
1631
+ get keySchema() {
1632
+ return this._def.keyType;
1633
+ }
1634
+ get valueSchema() {
1635
+ return this._def.valueType;
1636
+ }
1637
+ _parse(input) {
1638
+ const { status, ctx } = this._processInputParams(input);
1845
1639
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
1846
1640
  (0, parseUtil_1.addIssueToContext)(ctx, {
1847
1641
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -1850,55 +1644,54 @@ var ZodRecord = /** @class */ (function (_super) {
1850
1644
  });
1851
1645
  return parseUtil_1.INVALID;
1852
1646
  }
1853
- var pairs = [];
1854
- var keyType = this._def.keyType;
1855
- var valueType = this._def.valueType;
1856
- for (var key in ctx.data) {
1647
+ const pairs = [];
1648
+ const keyType = this._def.keyType;
1649
+ const valueType = this._def.valueType;
1650
+ for (const key in ctx.data) {
1857
1651
  pairs.push({
1858
1652
  key: keyType._parse({
1859
1653
  data: key,
1860
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
1654
+ path: [...ctx.path, key],
1861
1655
  parent: ctx,
1862
1656
  }),
1863
1657
  value: valueType._parse({
1864
1658
  data: ctx.data[key],
1865
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [key], false),
1659
+ path: [...ctx.path, key],
1866
1660
  parent: ctx,
1867
1661
  }),
1868
1662
  });
1869
1663
  }
1870
- if (ctx.async) {
1664
+ if (ctx.common.async) {
1871
1665
  return parseUtil_1.ParseStatus.mergeObjectAsync(status, pairs);
1872
1666
  }
1873
1667
  else {
1874
1668
  return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
1875
1669
  }
1876
- };
1877
- Object.defineProperty(ZodRecord.prototype, "element", {
1878
- get: function () {
1879
- return this._def.valueType;
1880
- },
1881
- enumerable: false,
1882
- configurable: true
1883
- });
1884
- ZodRecord.create = function (first, second, third) {
1670
+ }
1671
+ get element() {
1672
+ return this._def.valueType;
1673
+ }
1674
+ static create(first, second, third) {
1885
1675
  if (second instanceof ZodType) {
1886
- return new ZodRecord(__assign({ keyType: first, valueType: second, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(third)));
1676
+ return new ZodRecord({
1677
+ keyType: first,
1678
+ valueType: second,
1679
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
1680
+ ...processCreateParams(third),
1681
+ });
1887
1682
  }
1888
- return new ZodRecord(__assign({ keyType: ZodString.create(), valueType: first, typeName: ZodFirstPartyTypeKind.ZodRecord }, processCreateParams(second)));
1889
- };
1890
- return ZodRecord;
1891
- }(ZodType));
1683
+ return new ZodRecord({
1684
+ keyType: ZodString.create(),
1685
+ valueType: first,
1686
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
1687
+ ...processCreateParams(second),
1688
+ });
1689
+ }
1690
+ }
1892
1691
  exports.ZodRecord = ZodRecord;
1893
- var ZodMap = /** @class */ (function (_super) {
1894
- __extends(ZodMap, _super);
1895
- function ZodMap() {
1896
- return _super !== null && _super.apply(this, arguments) || this;
1897
- }
1898
- ZodMap.prototype._parse = function (input) {
1899
- var e_12, _a;
1900
- var _this = this;
1901
- var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
1692
+ class ZodMap extends ZodType {
1693
+ _parse(input) {
1694
+ const { status, ctx } = this._processInputParams(input);
1902
1695
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.map) {
1903
1696
  (0, parseUtil_1.addIssueToContext)(ctx, {
1904
1697
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -1907,77 +1700,28 @@ var ZodMap = /** @class */ (function (_super) {
1907
1700
  });
1908
1701
  return parseUtil_1.INVALID;
1909
1702
  }
1910
- var keyType = this._def.keyType;
1911
- var valueType = this._def.valueType;
1912
- var pairs = __spreadArray([], __read(ctx.data.entries()), false).map(function (_a, index) {
1913
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
1703
+ const keyType = this._def.keyType;
1704
+ const valueType = this._def.valueType;
1705
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
1914
1706
  return {
1915
1707
  key: keyType._parse({
1916
1708
  data: key,
1917
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "key"], false),
1709
+ path: [...ctx.path, index, "key"],
1918
1710
  parent: ctx,
1919
1711
  }),
1920
1712
  value: valueType._parse({
1921
1713
  data: value,
1922
- path: __spreadArray(__spreadArray([], __read(ctx.path), false), [index, "value"], false),
1714
+ path: [...ctx.path, index, "value"],
1923
1715
  parent: ctx,
1924
1716
  }),
1925
1717
  };
1926
1718
  });
1927
- if (ctx.async) {
1928
- var finalMap_1 = new Map();
1929
- return Promise.resolve().then(function () { return __awaiter(_this, void 0, void 0, function () {
1930
- var pairs_3, pairs_3_1, pair, key, value, e_13_1;
1931
- var e_13, _a;
1932
- return __generator(this, function (_b) {
1933
- switch (_b.label) {
1934
- case 0:
1935
- _b.trys.push([0, 6, 7, 8]);
1936
- pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
1937
- _b.label = 1;
1938
- case 1:
1939
- if (!!pairs_3_1.done) return [3 /*break*/, 5];
1940
- pair = pairs_3_1.value;
1941
- return [4 /*yield*/, pair.key];
1942
- case 2:
1943
- key = _b.sent();
1944
- return [4 /*yield*/, pair.value];
1945
- case 3:
1946
- value = _b.sent();
1947
- if (key.status === "aborted" || value.status === "aborted") {
1948
- return [2 /*return*/, parseUtil_1.INVALID];
1949
- }
1950
- if (key.status === "dirty" || value.status === "dirty") {
1951
- status.dirty();
1952
- }
1953
- finalMap_1.set(key.value, value.value);
1954
- _b.label = 4;
1955
- case 4:
1956
- pairs_3_1 = pairs_3.next();
1957
- return [3 /*break*/, 1];
1958
- case 5: return [3 /*break*/, 8];
1959
- case 6:
1960
- e_13_1 = _b.sent();
1961
- e_13 = { error: e_13_1 };
1962
- return [3 /*break*/, 8];
1963
- case 7:
1964
- try {
1965
- if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
1966
- }
1967
- finally { if (e_13) throw e_13.error; }
1968
- return [7 /*endfinally*/];
1969
- case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
1970
- }
1971
- });
1972
- }); });
1973
- }
1974
- else {
1975
- var finalMap = new Map();
1976
- try {
1977
- for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
1978
- var pair = pairs_2_1.value;
1979
- var key = pair.key;
1980
- var value = pair.value;
1719
+ if (ctx.common.async) {
1720
+ const finalMap = new Map();
1721
+ return Promise.resolve().then(async () => {
1722
+ for (const pair of pairs) {
1723
+ const key = await pair.key;
1724
+ const value = await pair.value;
1981
1725
  if (key.status === "aborted" || value.status === "aborted") {
1982
1726
  return parseUtil_1.INVALID;
1983
1727
  }
@@ -1986,30 +1730,38 @@ var ZodMap = /** @class */ (function (_super) {
1986
1730
  }
1987
1731
  finalMap.set(key.value, value.value);
1988
1732
  }
1989
- }
1990
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1991
- finally {
1992
- try {
1993
- if (pairs_2_1 && !pairs_2_1.done && (_a = pairs_2.return)) _a.call(pairs_2);
1733
+ return { status: status.value, value: finalMap };
1734
+ });
1735
+ }
1736
+ else {
1737
+ const finalMap = new Map();
1738
+ for (const pair of pairs) {
1739
+ const key = pair.key;
1740
+ const value = pair.value;
1741
+ if (key.status === "aborted" || value.status === "aborted") {
1742
+ return parseUtil_1.INVALID;
1743
+ }
1744
+ if (key.status === "dirty" || value.status === "dirty") {
1745
+ status.dirty();
1994
1746
  }
1995
- finally { if (e_12) throw e_12.error; }
1747
+ finalMap.set(key.value, value.value);
1996
1748
  }
1997
1749
  return { status: status.value, value: finalMap };
1998
1750
  }
1999
- };
2000
- ZodMap.create = function (keyType, valueType, params) {
2001
- return new ZodMap(__assign({ valueType: valueType, keyType: keyType, typeName: ZodFirstPartyTypeKind.ZodMap }, processCreateParams(params)));
2002
- };
2003
- return ZodMap;
2004
- }(ZodType));
2005
- exports.ZodMap = ZodMap;
2006
- var ZodSet = /** @class */ (function (_super) {
2007
- __extends(ZodSet, _super);
2008
- function ZodSet() {
2009
- return _super !== null && _super.apply(this, arguments) || this;
2010
1751
  }
2011
- ZodSet.prototype._parse = function (input) {
2012
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
1752
+ }
1753
+ exports.ZodMap = ZodMap;
1754
+ ZodMap.create = (keyType, valueType, params) => {
1755
+ return new ZodMap({
1756
+ valueType,
1757
+ keyType,
1758
+ typeName: ZodFirstPartyTypeKind.ZodMap,
1759
+ ...processCreateParams(params),
1760
+ });
1761
+ };
1762
+ class ZodSet extends ZodType {
1763
+ _parse(input) {
1764
+ const { status, ctx } = this._processInputParams(input);
2013
1765
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.set) {
2014
1766
  (0, parseUtil_1.addIssueToContext)(ctx, {
2015
1767
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -2018,7 +1770,7 @@ var ZodSet = /** @class */ (function (_super) {
2018
1770
  });
2019
1771
  return parseUtil_1.INVALID;
2020
1772
  }
2021
- var def = this._def;
1773
+ const def = this._def;
2022
1774
  if (def.minSize !== null) {
2023
1775
  if (ctx.data.size < def.minSize.value) {
2024
1776
  (0, parseUtil_1.addIssueToContext)(ctx, {
@@ -2043,67 +1795,62 @@ var ZodSet = /** @class */ (function (_super) {
2043
1795
  status.dirty();
2044
1796
  }
2045
1797
  }
2046
- var valueType = this._def.valueType;
1798
+ const valueType = this._def.valueType;
2047
1799
  function finalizeSet(elements) {
2048
- var e_14, _a;
2049
- var parsedSet = new Set();
2050
- try {
2051
- for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
2052
- var element = elements_1_1.value;
2053
- if (element.status === "aborted")
2054
- return parseUtil_1.INVALID;
2055
- if (element.status === "dirty")
2056
- status.dirty();
2057
- parsedSet.add(element.value);
2058
- }
2059
- }
2060
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
2061
- finally {
2062
- try {
2063
- if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
2064
- }
2065
- finally { if (e_14) throw e_14.error; }
1800
+ const parsedSet = new Set();
1801
+ for (const element of elements) {
1802
+ if (element.status === "aborted")
1803
+ return parseUtil_1.INVALID;
1804
+ if (element.status === "dirty")
1805
+ status.dirty();
1806
+ parsedSet.add(element.value);
2066
1807
  }
2067
1808
  return { status: status.value, value: parsedSet };
2068
1809
  }
2069
- var elements = __spreadArray([], __read(ctx.data.values()), false).map(function (item, i) {
2070
- return valueType._parse({ data: item, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false), parent: ctx });
2071
- });
2072
- if (ctx.async) {
2073
- return Promise.all(elements).then(function (elements) { return finalizeSet(elements); });
1810
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx }));
1811
+ if (ctx.common.async) {
1812
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
2074
1813
  }
2075
1814
  else {
2076
1815
  return finalizeSet(elements);
2077
1816
  }
2078
- };
2079
- ZodSet.prototype.min = function (minSize, message) {
2080
- return new ZodSet(__assign(__assign({}, this._def), { minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) } }));
2081
- };
2082
- ZodSet.prototype.max = function (maxSize, message) {
2083
- return new ZodSet(__assign(__assign({}, this._def), { maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) } }));
2084
- };
2085
- ZodSet.prototype.size = function (size, message) {
1817
+ }
1818
+ min(minSize, message) {
1819
+ return new ZodSet({
1820
+ ...this._def,
1821
+ minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) },
1822
+ });
1823
+ }
1824
+ max(maxSize, message) {
1825
+ return new ZodSet({
1826
+ ...this._def,
1827
+ maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) },
1828
+ });
1829
+ }
1830
+ size(size, message) {
2086
1831
  return this.min(size, message).max(size, message);
2087
- };
2088
- ZodSet.prototype.nonempty = function (message) {
1832
+ }
1833
+ nonempty(message) {
2089
1834
  return this.min(1, message);
2090
- };
2091
- ZodSet.create = function (valueType, params) {
2092
- return new ZodSet(__assign({ valueType: valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet }, processCreateParams(params)));
2093
- };
2094
- return ZodSet;
2095
- }(ZodType));
1835
+ }
1836
+ }
2096
1837
  exports.ZodSet = ZodSet;
2097
- var ZodFunction = /** @class */ (function (_super) {
2098
- __extends(ZodFunction, _super);
2099
- function ZodFunction() {
2100
- var _this = _super !== null && _super.apply(this, arguments) || this;
2101
- _this.validate = _this.implement;
2102
- return _this;
2103
- }
2104
- ZodFunction.prototype._parse = function (input) {
2105
- var _this = this;
2106
- var ctx = this._processInputParams(input).ctx;
1838
+ ZodSet.create = (valueType, params) => {
1839
+ return new ZodSet({
1840
+ valueType,
1841
+ minSize: null,
1842
+ maxSize: null,
1843
+ typeName: ZodFirstPartyTypeKind.ZodSet,
1844
+ ...processCreateParams(params),
1845
+ });
1846
+ };
1847
+ class ZodFunction extends ZodType {
1848
+ constructor() {
1849
+ super(...arguments);
1850
+ this.validate = this.implement;
1851
+ }
1852
+ _parse(input) {
1853
+ const { ctx } = this._processInputParams(input);
2107
1854
  if (ctx.parsedType !== parseUtil_1.ZodParsedType.function) {
2108
1855
  (0, parseUtil_1.addIssueToContext)(ctx, {
2109
1856
  code: ZodError_1.ZodIssueCode.invalid_type,
@@ -2117,11 +1864,11 @@ var ZodFunction = /** @class */ (function (_super) {
2117
1864
  data: args,
2118
1865
  path: ctx.path,
2119
1866
  errorMaps: [
2120
- ctx.contextualErrorMap,
1867
+ ctx.common.contextualErrorMap,
2121
1868
  ctx.schemaErrorMap,
2122
1869
  ZodError_1.overrideErrorMap,
2123
1870
  ZodError_1.defaultErrorMap,
2124
- ].filter(function (x) { return !!x; }),
1871
+ ].filter((x) => !!x),
2125
1872
  issueData: {
2126
1873
  code: ZodError_1.ZodIssueCode.invalid_arguments,
2127
1874
  argumentsError: error,
@@ -2133,138 +1880,113 @@ var ZodFunction = /** @class */ (function (_super) {
2133
1880
  data: returns,
2134
1881
  path: ctx.path,
2135
1882
  errorMaps: [
2136
- ctx.contextualErrorMap,
1883
+ ctx.common.contextualErrorMap,
2137
1884
  ctx.schemaErrorMap,
2138
1885
  ZodError_1.overrideErrorMap,
2139
1886
  ZodError_1.defaultErrorMap,
2140
- ].filter(function (x) { return !!x; }),
1887
+ ].filter((x) => !!x),
2141
1888
  issueData: {
2142
1889
  code: ZodError_1.ZodIssueCode.invalid_return_type,
2143
1890
  returnTypeError: error,
2144
1891
  },
2145
1892
  });
2146
1893
  }
2147
- var params = { errorMap: ctx.contextualErrorMap };
2148
- var fn = ctx.data;
1894
+ const params = { errorMap: ctx.common.contextualErrorMap };
1895
+ const fn = ctx.data;
2149
1896
  if (this._def.returns instanceof ZodPromise) {
2150
- return (0, parseUtil_1.OK)(function () {
2151
- var args = [];
2152
- for (var _i = 0; _i < arguments.length; _i++) {
2153
- args[_i] = arguments[_i];
2154
- }
2155
- return __awaiter(_this, void 0, void 0, function () {
2156
- var error, parsedArgs, result, parsedReturns;
2157
- return __generator(this, function (_a) {
2158
- switch (_a.label) {
2159
- case 0:
2160
- error = new ZodError_1.ZodError([]);
2161
- return [4 /*yield*/, this._def.args
2162
- .parseAsync(args, params)
2163
- .catch(function (e) {
2164
- error.addIssue(makeArgsIssue(args, e));
2165
- throw error;
2166
- })];
2167
- case 1:
2168
- parsedArgs = _a.sent();
2169
- return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
2170
- case 2:
2171
- result = _a.sent();
2172
- return [4 /*yield*/, this._def.returns._def.type
2173
- .parseAsync(result, params)
2174
- .catch(function (e) {
2175
- error.addIssue(makeReturnsIssue(result, e));
2176
- throw error;
2177
- })];
2178
- case 3:
2179
- parsedReturns = _a.sent();
2180
- return [2 /*return*/, parsedReturns];
2181
- }
2182
- });
1897
+ return (0, parseUtil_1.OK)(async (...args) => {
1898
+ const error = new ZodError_1.ZodError([]);
1899
+ const parsedArgs = await this._def.args
1900
+ .parseAsync(args, params)
1901
+ .catch((e) => {
1902
+ error.addIssue(makeArgsIssue(args, e));
1903
+ throw error;
2183
1904
  });
1905
+ const result = await fn(...parsedArgs);
1906
+ const parsedReturns = await this._def.returns._def.type
1907
+ .parseAsync(result, params)
1908
+ .catch((e) => {
1909
+ error.addIssue(makeReturnsIssue(result, e));
1910
+ throw error;
1911
+ });
1912
+ return parsedReturns;
2184
1913
  });
2185
1914
  }
2186
1915
  else {
2187
- return (0, parseUtil_1.OK)(function () {
2188
- var args = [];
2189
- for (var _i = 0; _i < arguments.length; _i++) {
2190
- args[_i] = arguments[_i];
2191
- }
2192
- var parsedArgs = _this._def.args.safeParse(args, params);
1916
+ return (0, parseUtil_1.OK)((...args) => {
1917
+ const parsedArgs = this._def.args.safeParse(args, params);
2193
1918
  if (!parsedArgs.success) {
2194
1919
  throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
2195
1920
  }
2196
- var result = fn.apply(void 0, __spreadArray([], __read(parsedArgs.data), false));
2197
- var parsedReturns = _this._def.returns.safeParse(result, params);
1921
+ const result = fn(...parsedArgs.data);
1922
+ const parsedReturns = this._def.returns.safeParse(result, params);
2198
1923
  if (!parsedReturns.success) {
2199
1924
  throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
2200
1925
  }
2201
1926
  return parsedReturns.data;
2202
1927
  });
2203
1928
  }
2204
- };
2205
- ZodFunction.prototype.parameters = function () {
1929
+ }
1930
+ parameters() {
2206
1931
  return this._def.args;
2207
- };
2208
- ZodFunction.prototype.returnType = function () {
1932
+ }
1933
+ returnType() {
2209
1934
  return this._def.returns;
2210
- };
2211
- ZodFunction.prototype.args = function () {
2212
- var items = [];
2213
- for (var _i = 0; _i < arguments.length; _i++) {
2214
- items[_i] = arguments[_i];
2215
- }
2216
- return new ZodFunction(__assign(__assign({}, this._def), { args: ZodTuple.create(items).rest(ZodUnknown.create()) }));
2217
- };
2218
- ZodFunction.prototype.returns = function (returnType) {
2219
- return new ZodFunction(__assign(__assign({}, this._def), { returns: returnType }));
2220
- };
2221
- ZodFunction.prototype.implement = function (func) {
2222
- var validatedFunc = this.parse(func);
1935
+ }
1936
+ args(...items) {
1937
+ return new ZodFunction({
1938
+ ...this._def,
1939
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
1940
+ });
1941
+ }
1942
+ returns(returnType) {
1943
+ return new ZodFunction({
1944
+ ...this._def,
1945
+ returns: returnType,
1946
+ });
1947
+ }
1948
+ implement(func) {
1949
+ const validatedFunc = this.parse(func);
2223
1950
  return validatedFunc;
2224
- };
2225
- ZodFunction.prototype.strictImplement = function (func) {
2226
- var validatedFunc = this.parse(func);
1951
+ }
1952
+ strictImplement(func) {
1953
+ const validatedFunc = this.parse(func);
2227
1954
  return validatedFunc;
2228
- };
2229
- ZodFunction.create = function (args, returns, params) {
2230
- return new ZodFunction(__assign({ args: (args
2231
- ? args.rest(ZodUnknown.create())
2232
- : ZodTuple.create([]).rest(ZodUnknown.create())), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction }, processCreateParams(params)));
2233
- };
2234
- return ZodFunction;
2235
- }(ZodType));
1955
+ }
1956
+ }
2236
1957
  exports.ZodFunction = ZodFunction;
2237
- var ZodLazy = /** @class */ (function (_super) {
2238
- __extends(ZodLazy, _super);
2239
- function ZodLazy() {
2240
- return _super !== null && _super.apply(this, arguments) || this;
2241
- }
2242
- Object.defineProperty(ZodLazy.prototype, "schema", {
2243
- get: function () {
2244
- return this._def.getter();
2245
- },
2246
- enumerable: false,
2247
- configurable: true
1958
+ ZodFunction.create = (args, returns, params) => {
1959
+ return new ZodFunction({
1960
+ args: (args
1961
+ ? args.rest(ZodUnknown.create())
1962
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
1963
+ returns: returns || ZodUnknown.create(),
1964
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
1965
+ ...processCreateParams(params),
2248
1966
  });
2249
- ZodLazy.prototype._parse = function (input) {
2250
- var ctx = this._processInputParams(input).ctx;
2251
- var lazySchema = this._def.getter();
1967
+ };
1968
+ class ZodLazy extends ZodType {
1969
+ get schema() {
1970
+ return this._def.getter();
1971
+ }
1972
+ _parse(input) {
1973
+ const { ctx } = this._processInputParams(input);
1974
+ const lazySchema = this._def.getter();
2252
1975
  return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
2253
- };
2254
- ZodLazy.create = function (getter, params) {
2255
- return new ZodLazy(__assign({ getter: getter, typeName: ZodFirstPartyTypeKind.ZodLazy }, processCreateParams(params)));
2256
- };
2257
- return ZodLazy;
2258
- }(ZodType));
1976
+ }
1977
+ }
2259
1978
  exports.ZodLazy = ZodLazy;
2260
- var ZodLiteral = /** @class */ (function (_super) {
2261
- __extends(ZodLiteral, _super);
2262
- function ZodLiteral() {
2263
- return _super !== null && _super.apply(this, arguments) || this;
2264
- }
2265
- ZodLiteral.prototype._parse = function (input) {
2266
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2267
- if (ctx.data !== this._def.value) {
1979
+ ZodLazy.create = (getter, params) => {
1980
+ return new ZodLazy({
1981
+ getter: getter,
1982
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
1983
+ ...processCreateParams(params),
1984
+ });
1985
+ };
1986
+ class ZodLiteral extends ZodType {
1987
+ _parse(input) {
1988
+ if (input.data !== this._def.value) {
1989
+ const ctx = this._getOrReturnCtx(input);
2268
1990
  (0, parseUtil_1.addIssueToContext)(ctx, {
2269
1991
  code: ZodError_1.ZodIssueCode.invalid_type,
2270
1992
  expected: (0, parseUtil_1.getParsedType)(this._def.value),
@@ -2272,159 +1994,95 @@ var ZodLiteral = /** @class */ (function (_super) {
2272
1994
  });
2273
1995
  return parseUtil_1.INVALID;
2274
1996
  }
2275
- return { status: status.value, value: ctx.data };
2276
- };
2277
- Object.defineProperty(ZodLiteral.prototype, "value", {
2278
- get: function () {
2279
- return this._def.value;
2280
- },
2281
- enumerable: false,
2282
- configurable: true
2283
- });
2284
- ZodLiteral.create = function (value, params) {
2285
- return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
2286
- };
2287
- return ZodLiteral;
2288
- }(ZodType));
1997
+ return { status: "valid", value: input.data };
1998
+ }
1999
+ get value() {
2000
+ return this._def.value;
2001
+ }
2002
+ }
2289
2003
  exports.ZodLiteral = ZodLiteral;
2004
+ ZodLiteral.create = (value, params) => {
2005
+ return new ZodLiteral({
2006
+ value: value,
2007
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
2008
+ ...processCreateParams(params),
2009
+ });
2010
+ };
2290
2011
  function createZodEnum(values) {
2291
2012
  return new ZodEnum({
2292
2013
  values: values,
2293
2014
  typeName: ZodFirstPartyTypeKind.ZodEnum,
2294
2015
  });
2295
2016
  }
2296
- var ZodEnum = /** @class */ (function (_super) {
2297
- __extends(ZodEnum, _super);
2298
- function ZodEnum() {
2299
- return _super !== null && _super.apply(this, arguments) || this;
2300
- }
2301
- ZodEnum.prototype._parse = function (input) {
2302
- var ctx = this._processInputParams(input).ctx;
2303
- if (this._def.values.indexOf(ctx.data) === -1) {
2017
+ class ZodEnum extends ZodType {
2018
+ _parse(input) {
2019
+ if (this._def.values.indexOf(input.data) === -1) {
2020
+ const ctx = this._getOrReturnCtx(input);
2304
2021
  (0, parseUtil_1.addIssueToContext)(ctx, {
2305
2022
  code: ZodError_1.ZodIssueCode.invalid_enum_value,
2306
2023
  options: this._def.values,
2307
2024
  });
2308
2025
  return parseUtil_1.INVALID;
2309
2026
  }
2310
- return (0, parseUtil_1.OK)(ctx.data);
2311
- };
2312
- Object.defineProperty(ZodEnum.prototype, "options", {
2313
- get: function () {
2314
- return this._def.values;
2315
- },
2316
- enumerable: false,
2317
- configurable: true
2318
- });
2319
- Object.defineProperty(ZodEnum.prototype, "enum", {
2320
- get: function () {
2321
- var e_15, _a;
2322
- var enumValues = {};
2323
- try {
2324
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2325
- var val = _c.value;
2326
- enumValues[val] = val;
2327
- }
2328
- }
2329
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
2330
- finally {
2331
- try {
2332
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2333
- }
2334
- finally { if (e_15) throw e_15.error; }
2335
- }
2336
- return enumValues;
2337
- },
2338
- enumerable: false,
2339
- configurable: true
2340
- });
2341
- Object.defineProperty(ZodEnum.prototype, "Values", {
2342
- get: function () {
2343
- var e_16, _a;
2344
- var enumValues = {};
2345
- try {
2346
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2347
- var val = _c.value;
2348
- enumValues[val] = val;
2349
- }
2350
- }
2351
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
2352
- finally {
2353
- try {
2354
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2355
- }
2356
- finally { if (e_16) throw e_16.error; }
2357
- }
2358
- return enumValues;
2359
- },
2360
- enumerable: false,
2361
- configurable: true
2362
- });
2363
- Object.defineProperty(ZodEnum.prototype, "Enum", {
2364
- get: function () {
2365
- var e_17, _a;
2366
- var enumValues = {};
2367
- try {
2368
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
2369
- var val = _c.value;
2370
- enumValues[val] = val;
2371
- }
2372
- }
2373
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
2374
- finally {
2375
- try {
2376
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2377
- }
2378
- finally { if (e_17) throw e_17.error; }
2379
- }
2380
- return enumValues;
2381
- },
2382
- enumerable: false,
2383
- configurable: true
2384
- });
2385
- ZodEnum.create = createZodEnum;
2386
- return ZodEnum;
2387
- }(ZodType));
2027
+ return (0, parseUtil_1.OK)(input.data);
2028
+ }
2029
+ get options() {
2030
+ return this._def.values;
2031
+ }
2032
+ get enum() {
2033
+ const enumValues = {};
2034
+ for (const val of this._def.values) {
2035
+ enumValues[val] = val;
2036
+ }
2037
+ return enumValues;
2038
+ }
2039
+ get Values() {
2040
+ const enumValues = {};
2041
+ for (const val of this._def.values) {
2042
+ enumValues[val] = val;
2043
+ }
2044
+ return enumValues;
2045
+ }
2046
+ get Enum() {
2047
+ const enumValues = {};
2048
+ for (const val of this._def.values) {
2049
+ enumValues[val] = val;
2050
+ }
2051
+ return enumValues;
2052
+ }
2053
+ }
2388
2054
  exports.ZodEnum = ZodEnum;
2389
- var ZodNativeEnum = /** @class */ (function (_super) {
2390
- __extends(ZodNativeEnum, _super);
2391
- function ZodNativeEnum() {
2392
- return _super !== null && _super.apply(this, arguments) || this;
2393
- }
2394
- ZodNativeEnum.prototype._parse = function (input) {
2395
- var ctx = this._processInputParams(input).ctx;
2396
- var nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
2397
- if (nativeEnumValues.indexOf(ctx.data) === -1) {
2055
+ ZodEnum.create = createZodEnum;
2056
+ class ZodNativeEnum extends ZodType {
2057
+ _parse(input) {
2058
+ const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
2059
+ if (nativeEnumValues.indexOf(input.data) === -1) {
2060
+ const ctx = this._getOrReturnCtx(input);
2398
2061
  (0, parseUtil_1.addIssueToContext)(ctx, {
2399
2062
  code: ZodError_1.ZodIssueCode.invalid_enum_value,
2400
2063
  options: util_1.util.objectValues(nativeEnumValues),
2401
2064
  });
2402
2065
  return parseUtil_1.INVALID;
2403
2066
  }
2404
- return (0, parseUtil_1.OK)(ctx.data);
2405
- };
2406
- Object.defineProperty(ZodNativeEnum.prototype, "enum", {
2407
- get: function () {
2408
- return this._def.values;
2409
- },
2410
- enumerable: false,
2411
- configurable: true
2412
- });
2413
- ZodNativeEnum.create = function (values, params) {
2414
- return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
2415
- };
2416
- return ZodNativeEnum;
2417
- }(ZodType));
2067
+ return (0, parseUtil_1.OK)(input.data);
2068
+ }
2069
+ get enum() {
2070
+ return this._def.values;
2071
+ }
2072
+ }
2418
2073
  exports.ZodNativeEnum = ZodNativeEnum;
2419
- var ZodPromise = /** @class */ (function (_super) {
2420
- __extends(ZodPromise, _super);
2421
- function ZodPromise() {
2422
- return _super !== null && _super.apply(this, arguments) || this;
2423
- }
2424
- ZodPromise.prototype._parse = function (input) {
2425
- var _this = this;
2426
- var ctx = this._processInputParams(input).ctx;
2427
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.promise && ctx.async === false) {
2074
+ ZodNativeEnum.create = (values, params) => {
2075
+ return new ZodNativeEnum({
2076
+ values: values,
2077
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
2078
+ ...processCreateParams(params),
2079
+ });
2080
+ };
2081
+ class ZodPromise extends ZodType {
2082
+ _parse(input) {
2083
+ const { ctx } = this._processInputParams(input);
2084
+ if (ctx.parsedType !== parseUtil_1.ZodParsedType.promise &&
2085
+ ctx.common.async === false) {
2428
2086
  (0, parseUtil_1.addIssueToContext)(ctx, {
2429
2087
  code: ZodError_1.ZodIssueCode.invalid_type,
2430
2088
  expected: parseUtil_1.ZodParsedType.promise,
@@ -2432,39 +2090,37 @@ var ZodPromise = /** @class */ (function (_super) {
2432
2090
  });
2433
2091
  return parseUtil_1.INVALID;
2434
2092
  }
2435
- var promisified = ctx.parsedType === parseUtil_1.ZodParsedType.promise
2093
+ const promisified = ctx.parsedType === parseUtil_1.ZodParsedType.promise
2436
2094
  ? ctx.data
2437
2095
  : Promise.resolve(ctx.data);
2438
- return (0, parseUtil_1.OK)(promisified.then(function (data) {
2439
- return _this._def.type.parseAsync(data, {
2096
+ return (0, parseUtil_1.OK)(promisified.then((data) => {
2097
+ return this._def.type.parseAsync(data, {
2440
2098
  path: ctx.path,
2441
- errorMap: ctx.contextualErrorMap,
2099
+ errorMap: ctx.common.contextualErrorMap,
2442
2100
  });
2443
2101
  }));
2444
- };
2445
- ZodPromise.create = function (schema, params) {
2446
- return new ZodPromise(__assign({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise }, processCreateParams(params)));
2447
- };
2448
- return ZodPromise;
2449
- }(ZodType));
2450
- exports.ZodPromise = ZodPromise;
2451
- var ZodEffects = /** @class */ (function (_super) {
2452
- __extends(ZodEffects, _super);
2453
- function ZodEffects() {
2454
- return _super !== null && _super.apply(this, arguments) || this;
2455
2102
  }
2456
- ZodEffects.prototype.innerType = function () {
2103
+ }
2104
+ exports.ZodPromise = ZodPromise;
2105
+ ZodPromise.create = (schema, params) => {
2106
+ return new ZodPromise({
2107
+ type: schema,
2108
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
2109
+ ...processCreateParams(params),
2110
+ });
2111
+ };
2112
+ class ZodEffects extends ZodType {
2113
+ innerType() {
2457
2114
  return this._def.schema;
2458
- };
2459
- ZodEffects.prototype._parse = function (input) {
2460
- var _this = this;
2461
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2462
- var effect = this._def.effect || null;
2115
+ }
2116
+ _parse(input) {
2117
+ const { status, ctx } = this._processInputParams(input);
2118
+ const effect = this._def.effect || null;
2463
2119
  if (effect.type === "preprocess") {
2464
- var processed = effect.transform(ctx.data);
2465
- if (ctx.async) {
2466
- return Promise.resolve(processed).then(function (processed) {
2467
- return _this._def.schema._parseAsync({
2120
+ const processed = effect.transform(ctx.data);
2121
+ if (ctx.common.async) {
2122
+ return Promise.resolve(processed).then((processed) => {
2123
+ return this._def.schema._parseAsync({
2468
2124
  data: processed,
2469
2125
  path: ctx.path,
2470
2126
  parent: ctx,
@@ -2480,8 +2136,8 @@ var ZodEffects = /** @class */ (function (_super) {
2480
2136
  }
2481
2137
  }
2482
2138
  if (effect.type === "refinement") {
2483
- var checkCtx_1 = {
2484
- addIssue: function (arg) {
2139
+ const checkCtx = {
2140
+ addIssue: (arg) => {
2485
2141
  (0, parseUtil_1.addIssueToContext)(ctx, arg);
2486
2142
  if (arg.fatal) {
2487
2143
  status.abort();
@@ -2494,12 +2150,12 @@ var ZodEffects = /** @class */ (function (_super) {
2494
2150
  return ctx.path;
2495
2151
  },
2496
2152
  };
2497
- checkCtx_1.addIssue = checkCtx_1.addIssue.bind(checkCtx_1);
2498
- var executeRefinement_1 = function (acc
2153
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
2154
+ const executeRefinement = (acc
2499
2155
  // effect: RefinementEffect<any>
2500
- ) {
2501
- var result = effect.refinement(acc, checkCtx_1);
2502
- if (ctx.async) {
2156
+ ) => {
2157
+ const result = effect.refinement(acc, checkCtx);
2158
+ if (ctx.common.async) {
2503
2159
  return Promise.resolve(result);
2504
2160
  }
2505
2161
  if (result instanceof Promise) {
@@ -2507,8 +2163,8 @@ var ZodEffects = /** @class */ (function (_super) {
2507
2163
  }
2508
2164
  return acc;
2509
2165
  };
2510
- if (ctx.async === false) {
2511
- var inner = this._def.schema._parseSync({
2166
+ if (ctx.common.async === false) {
2167
+ const inner = this._def.schema._parseSync({
2512
2168
  data: ctx.data,
2513
2169
  path: ctx.path,
2514
2170
  parent: ctx,
@@ -2518,26 +2174,26 @@ var ZodEffects = /** @class */ (function (_super) {
2518
2174
  if (inner.status === "dirty")
2519
2175
  status.dirty();
2520
2176
  // return value is ignored
2521
- executeRefinement_1(inner.value);
2177
+ executeRefinement(inner.value);
2522
2178
  return { status: status.value, value: inner.value };
2523
2179
  }
2524
2180
  else {
2525
2181
  return this._def.schema
2526
2182
  ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
2527
- .then(function (inner) {
2183
+ .then((inner) => {
2528
2184
  if (inner.status === "aborted")
2529
2185
  return parseUtil_1.INVALID;
2530
2186
  if (inner.status === "dirty")
2531
2187
  status.dirty();
2532
- return executeRefinement_1(inner.value).then(function () {
2188
+ return executeRefinement(inner.value).then(() => {
2533
2189
  return { status: status.value, value: inner.value };
2534
2190
  });
2535
2191
  });
2536
2192
  }
2537
2193
  }
2538
2194
  if (effect.type === "transform") {
2539
- if (ctx.async === false) {
2540
- var base = this._def.schema._parseSync({
2195
+ if (ctx.common.async === false) {
2196
+ const base = this._def.schema._parseSync({
2541
2197
  data: ctx.data,
2542
2198
  path: ctx.path,
2543
2199
  parent: ctx,
@@ -2548,16 +2204,16 @@ var ZodEffects = /** @class */ (function (_super) {
2548
2204
  // }
2549
2205
  if (!(0, parseUtil_1.isValid)(base))
2550
2206
  return base;
2551
- var result = effect.transform(base.value);
2207
+ const result = effect.transform(base.value);
2552
2208
  if (result instanceof Promise) {
2553
- throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2209
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
2554
2210
  }
2555
2211
  return (0, parseUtil_1.OK)(result);
2556
2212
  }
2557
2213
  else {
2558
2214
  return this._def.schema
2559
2215
  ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
2560
- .then(function (base) {
2216
+ .then((base) => {
2561
2217
  if (!(0, parseUtil_1.isValid)(base))
2562
2218
  return base;
2563
2219
  // if (base.status === "aborted") return INVALID;
@@ -2569,101 +2225,96 @@ var ZodEffects = /** @class */ (function (_super) {
2569
2225
  }
2570
2226
  }
2571
2227
  util_1.util.assertNever(effect);
2572
- };
2573
- ZodEffects.create = function (schema, effect, params) {
2574
- return new ZodEffects(__assign({ schema: schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: effect }, processCreateParams(params)));
2575
- };
2576
- ZodEffects.createWithPreprocess = function (preprocess, schema, params) {
2577
- return new ZodEffects(__assign({ schema: schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects }, processCreateParams(params)));
2578
- };
2579
- return ZodEffects;
2580
- }(ZodType));
2228
+ }
2229
+ }
2581
2230
  exports.ZodEffects = ZodEffects;
2582
2231
  exports.ZodTransformer = ZodEffects;
2583
- var ZodOptional = /** @class */ (function (_super) {
2584
- __extends(ZodOptional, _super);
2585
- function ZodOptional() {
2586
- return _super !== null && _super.apply(this, arguments) || this;
2587
- }
2588
- ZodOptional.prototype._parse = function (input) {
2589
- var ctx = this._processInputParams(input).ctx;
2590
- if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
2232
+ ZodEffects.create = (schema, effect, params) => {
2233
+ return new ZodEffects({
2234
+ schema,
2235
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2236
+ effect,
2237
+ ...processCreateParams(params),
2238
+ });
2239
+ };
2240
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
2241
+ return new ZodEffects({
2242
+ schema,
2243
+ effect: { type: "preprocess", transform: preprocess },
2244
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2245
+ ...processCreateParams(params),
2246
+ });
2247
+ };
2248
+ class ZodOptional extends ZodType {
2249
+ _parse(input) {
2250
+ const parsedType = this._getType(input);
2251
+ if (parsedType === parseUtil_1.ZodParsedType.undefined) {
2591
2252
  return (0, parseUtil_1.OK)(undefined);
2592
2253
  }
2593
- return this._def.innerType._parse({
2594
- data: ctx.data,
2595
- path: ctx.path,
2596
- parent: ctx,
2597
- });
2598
- };
2599
- ZodOptional.prototype.unwrap = function () {
2254
+ return this._def.innerType._parse(input);
2255
+ }
2256
+ unwrap() {
2600
2257
  return this._def.innerType;
2601
- };
2602
- ZodOptional.create = function (type, params) {
2603
- return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
2604
- };
2605
- return ZodOptional;
2606
- }(ZodType));
2258
+ }
2259
+ }
2607
2260
  exports.ZodOptional = ZodOptional;
2608
- var ZodNullable = /** @class */ (function (_super) {
2609
- __extends(ZodNullable, _super);
2610
- function ZodNullable() {
2611
- return _super !== null && _super.apply(this, arguments) || this;
2612
- }
2613
- ZodNullable.prototype._parse = function (input) {
2614
- var ctx = this._processInputParams(input).ctx;
2615
- if (ctx.parsedType === parseUtil_1.ZodParsedType.null) {
2261
+ ZodOptional.create = (type, params) => {
2262
+ return new ZodOptional({
2263
+ innerType: type,
2264
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
2265
+ ...processCreateParams(params),
2266
+ });
2267
+ };
2268
+ class ZodNullable extends ZodType {
2269
+ _parse(input) {
2270
+ const parsedType = this._getType(input);
2271
+ if (parsedType === parseUtil_1.ZodParsedType.null) {
2616
2272
  return (0, parseUtil_1.OK)(null);
2617
2273
  }
2618
- return this._def.innerType._parse({
2619
- data: ctx.data,
2620
- path: ctx.path,
2621
- parent: ctx,
2622
- });
2623
- };
2624
- ZodNullable.prototype.unwrap = function () {
2274
+ return this._def.innerType._parse(input);
2275
+ }
2276
+ unwrap() {
2625
2277
  return this._def.innerType;
2626
- };
2627
- ZodNullable.create = function (type, params) {
2628
- return new ZodNullable(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable }, processCreateParams(params)));
2629
- };
2630
- return ZodNullable;
2631
- }(ZodType));
2278
+ }
2279
+ }
2632
2280
  exports.ZodNullable = ZodNullable;
2633
- var ZodDefault = /** @class */ (function (_super) {
2634
- __extends(ZodDefault, _super);
2635
- function ZodDefault() {
2636
- return _super !== null && _super.apply(this, arguments) || this;
2637
- }
2638
- ZodDefault.prototype._parse = function (input) {
2639
- var ctx = this._processInputParams(input).ctx;
2640
- var data = ctx.data;
2281
+ ZodNullable.create = (type, params) => {
2282
+ return new ZodNullable({
2283
+ innerType: type,
2284
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
2285
+ ...processCreateParams(params),
2286
+ });
2287
+ };
2288
+ class ZodDefault extends ZodType {
2289
+ _parse(input) {
2290
+ const { ctx } = this._processInputParams(input);
2291
+ let data = ctx.data;
2641
2292
  if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
2642
2293
  data = this._def.defaultValue();
2643
2294
  }
2644
2295
  return this._def.innerType._parse({
2645
- data: data,
2296
+ data,
2646
2297
  path: ctx.path,
2647
2298
  parent: ctx,
2648
2299
  });
2649
- };
2650
- ZodDefault.prototype.removeDefault = function () {
2300
+ }
2301
+ removeDefault() {
2651
2302
  return this._def.innerType;
2652
- };
2653
- ZodDefault.create = function (type, params) {
2654
- return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
2655
- };
2656
- return ZodDefault;
2657
- }(ZodType));
2303
+ }
2304
+ }
2658
2305
  exports.ZodDefault = ZodDefault;
2659
- var ZodNaN = /** @class */ (function (_super) {
2660
- __extends(ZodNaN, _super);
2661
- function ZodNaN() {
2662
- return _super !== null && _super.apply(this, arguments) || this;
2663
- }
2664
- ZodNaN.prototype._parse = function (input) {
2665
- var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2666
- if (ctx.parsedType !== parseUtil_1.ZodParsedType.nan) {
2306
+ ZodDefault.create = (type, params) => {
2307
+ return new ZodOptional({
2308
+ innerType: type,
2309
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
2310
+ ...processCreateParams(params),
2311
+ });
2312
+ };
2313
+ class ZodNaN extends ZodType {
2314
+ _parse(input) {
2315
+ const parsedType = this._getType(input);
2316
+ if (parsedType !== parseUtil_1.ZodParsedType.nan) {
2317
+ const ctx = this._getOrReturnCtx(input);
2667
2318
  (0, parseUtil_1.addIssueToContext)(ctx, {
2668
2319
  code: ZodError_1.ZodIssueCode.invalid_type,
2669
2320
  expected: parseUtil_1.ZodParsedType.nan,
@@ -2671,15 +2322,17 @@ var ZodNaN = /** @class */ (function (_super) {
2671
2322
  });
2672
2323
  return parseUtil_1.INVALID;
2673
2324
  }
2674
- return { status: status.value, value: ctx.data };
2675
- };
2676
- ZodNaN.create = function (params) {
2677
- return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
2678
- };
2679
- return ZodNaN;
2680
- }(ZodType));
2325
+ return { status: "valid", value: input.data };
2326
+ }
2327
+ }
2681
2328
  exports.ZodNaN = ZodNaN;
2682
- var custom = function (check, params) {
2329
+ ZodNaN.create = (params) => {
2330
+ return new ZodNaN({
2331
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
2332
+ ...processCreateParams(params),
2333
+ });
2334
+ };
2335
+ const custom = (check, params) => {
2683
2336
  if (check)
2684
2337
  return ZodAny.create().refine(check, params);
2685
2338
  return ZodAny.create();
@@ -2722,81 +2375,78 @@ var ZodFirstPartyTypeKind;
2722
2375
  ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
2723
2376
  ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
2724
2377
  })(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
2725
- var instanceOfType = function (cls, params) {
2726
- if (params === void 0) { params = {
2727
- message: "Input not instance of ".concat(cls.name),
2728
- }; }
2729
- return (0, exports.custom)(function (data) { return data instanceof cls; }, params);
2730
- };
2378
+ const instanceOfType = (cls, params = {
2379
+ message: `Input not instance of ${cls.name}`,
2380
+ }) => (0, exports.custom)((data) => data instanceof cls, params);
2731
2381
  exports.instanceof = instanceOfType;
2732
- var stringType = ZodString.create;
2382
+ const stringType = ZodString.create;
2733
2383
  exports.string = stringType;
2734
- var numberType = ZodNumber.create;
2384
+ const numberType = ZodNumber.create;
2735
2385
  exports.number = numberType;
2736
- var nanType = ZodNaN.create;
2386
+ const nanType = ZodNaN.create;
2737
2387
  exports.nan = nanType;
2738
- var bigIntType = ZodBigInt.create;
2388
+ const bigIntType = ZodBigInt.create;
2739
2389
  exports.bigint = bigIntType;
2740
- var booleanType = ZodBoolean.create;
2390
+ const booleanType = ZodBoolean.create;
2741
2391
  exports.boolean = booleanType;
2742
- var dateType = ZodDate.create;
2392
+ const dateType = ZodDate.create;
2743
2393
  exports.date = dateType;
2744
- var undefinedType = ZodUndefined.create;
2394
+ const undefinedType = ZodUndefined.create;
2745
2395
  exports.undefined = undefinedType;
2746
- var nullType = ZodNull.create;
2396
+ const nullType = ZodNull.create;
2747
2397
  exports.null = nullType;
2748
- var anyType = ZodAny.create;
2398
+ const anyType = ZodAny.create;
2749
2399
  exports.any = anyType;
2750
- var unknownType = ZodUnknown.create;
2400
+ const unknownType = ZodUnknown.create;
2751
2401
  exports.unknown = unknownType;
2752
- var neverType = ZodNever.create;
2402
+ const neverType = ZodNever.create;
2753
2403
  exports.never = neverType;
2754
- var voidType = ZodVoid.create;
2404
+ const voidType = ZodVoid.create;
2755
2405
  exports.void = voidType;
2756
- var arrayType = ZodArray.create;
2406
+ const arrayType = ZodArray.create;
2757
2407
  exports.array = arrayType;
2758
- var objectType = ZodObject.create;
2408
+ const objectType = ZodObject.create;
2759
2409
  exports.object = objectType;
2760
- var strictObjectType = ZodObject.strictCreate;
2410
+ const strictObjectType = ZodObject.strictCreate;
2761
2411
  exports.strictObject = strictObjectType;
2762
- var unionType = ZodUnion.create;
2412
+ const unionType = ZodUnion.create;
2763
2413
  exports.union = unionType;
2764
- var discriminatedUnionType = ZodDiscriminatedUnion.create;
2414
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
2765
2415
  exports.discriminatedUnion = discriminatedUnionType;
2766
- var intersectionType = ZodIntersection.create;
2416
+ const intersectionType = ZodIntersection.create;
2767
2417
  exports.intersection = intersectionType;
2768
- var tupleType = ZodTuple.create;
2418
+ const tupleType = ZodTuple.create;
2769
2419
  exports.tuple = tupleType;
2770
- var recordType = ZodRecord.create;
2420
+ const recordType = ZodRecord.create;
2771
2421
  exports.record = recordType;
2772
- var mapType = ZodMap.create;
2422
+ const mapType = ZodMap.create;
2773
2423
  exports.map = mapType;
2774
- var setType = ZodSet.create;
2424
+ const setType = ZodSet.create;
2775
2425
  exports.set = setType;
2776
- var functionType = ZodFunction.create;
2426
+ const functionType = ZodFunction.create;
2777
2427
  exports.function = functionType;
2778
- var lazyType = ZodLazy.create;
2428
+ const lazyType = ZodLazy.create;
2779
2429
  exports.lazy = lazyType;
2780
- var literalType = ZodLiteral.create;
2430
+ const literalType = ZodLiteral.create;
2781
2431
  exports.literal = literalType;
2782
- var enumType = ZodEnum.create;
2432
+ const enumType = ZodEnum.create;
2783
2433
  exports.enum = enumType;
2784
- var nativeEnumType = ZodNativeEnum.create;
2434
+ const nativeEnumType = ZodNativeEnum.create;
2785
2435
  exports.nativeEnum = nativeEnumType;
2786
- var promiseType = ZodPromise.create;
2436
+ const promiseType = ZodPromise.create;
2787
2437
  exports.promise = promiseType;
2788
- var effectsType = ZodEffects.create;
2438
+ const effectsType = ZodEffects.create;
2789
2439
  exports.effect = effectsType;
2790
2440
  exports.transformer = effectsType;
2791
- var optionalType = ZodOptional.create;
2441
+ const optionalType = ZodOptional.create;
2792
2442
  exports.optional = optionalType;
2793
- var nullableType = ZodNullable.create;
2443
+ const nullableType = ZodNullable.create;
2794
2444
  exports.nullable = nullableType;
2795
- var preprocessType = ZodEffects.createWithPreprocess;
2445
+ const preprocessType = ZodEffects.createWithPreprocess;
2796
2446
  exports.preprocess = preprocessType;
2797
- var ostring = function () { return stringType().optional(); };
2447
+ const ostring = () => stringType().optional();
2798
2448
  exports.ostring = ostring;
2799
- var onumber = function () { return numberType().optional(); };
2449
+ const onumber = () => numberType().optional();
2800
2450
  exports.onumber = onumber;
2801
- var oboolean = function () { return booleanType().optional(); };
2451
+ const oboolean = () => booleanType().optional();
2802
2452
  exports.oboolean = oboolean;