zod 3.13.4 → 3.14.0

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