zod 4.0.0-beta.1 → 4.0.0-beta.20250409T222615

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +1 -1
  2. package/dist/commonjs/checks.d.ts +1 -0
  3. package/dist/commonjs/checks.js +32 -0
  4. package/dist/commonjs/coerce.d.ts +17 -0
  5. package/dist/commonjs/coerce.js +57 -0
  6. package/dist/commonjs/compat.d.ts +47 -0
  7. package/dist/commonjs/compat.js +73 -0
  8. package/dist/commonjs/errors.d.ts +28 -0
  9. package/dist/commonjs/errors.js +60 -0
  10. package/dist/commonjs/external.d.ts +8 -0
  11. package/dist/commonjs/external.js +67 -0
  12. package/dist/commonjs/index.d.ts +4 -0
  13. package/dist/commonjs/index.js +43 -0
  14. package/dist/commonjs/iso.d.ts +22 -0
  15. package/dist/commonjs/iso.js +70 -0
  16. package/dist/commonjs/package.json +3 -0
  17. package/dist/commonjs/parse.d.ts +17 -0
  18. package/dist/commonjs/parse.js +44 -0
  19. package/dist/commonjs/schemas.d.ts +738 -0
  20. package/dist/commonjs/schemas.js +1171 -0
  21. package/dist/esm/checks.d.ts +1 -0
  22. package/dist/esm/checks.js +1 -0
  23. package/dist/esm/coerce.d.ts +17 -0
  24. package/dist/esm/coerce.js +17 -0
  25. package/dist/esm/compat.d.ts +47 -0
  26. package/dist/esm/compat.js +33 -0
  27. package/dist/esm/errors.d.ts +28 -0
  28. package/dist/esm/errors.js +23 -0
  29. package/dist/esm/external.d.ts +8 -0
  30. package/dist/esm/external.js +14 -0
  31. package/dist/esm/index.d.ts +4 -0
  32. package/dist/esm/index.js +4 -0
  33. package/dist/esm/iso.d.ts +22 -0
  34. package/dist/esm/iso.js +30 -0
  35. package/dist/esm/package.json +3 -0
  36. package/dist/esm/parse.d.ts +17 -0
  37. package/dist/esm/parse.js +8 -0
  38. package/dist/esm/schemas.d.ts +738 -0
  39. package/dist/esm/schemas.js +1057 -0
  40. package/package.json +66 -82
  41. package/src/checks.ts +30 -0
  42. package/src/coerce.ts +27 -0
  43. package/src/compat.ts +74 -0
  44. package/src/errors.ts +52 -0
  45. package/src/external.ts +29 -0
  46. package/src/index.ts +5 -0
  47. package/src/iso.ts +90 -0
  48. package/src/parse.ts +32 -0
  49. package/src/schemas.ts +2324 -0
  50. package/CHANGELOG.md +0 -160
  51. package/README.md +0 -1730
  52. package/lib/.DS_Store +0 -0
  53. package/lib/PseudoPromise.d.ts +0 -7
  54. package/lib/PseudoPromise.d.ts.map +0 -1
  55. package/lib/PseudoPromise.js +0 -17
  56. package/lib/PseudoPromise.js.map +0 -1
  57. package/lib/ZodError.d.ts +0 -137
  58. package/lib/ZodError.d.ts.map +0 -1
  59. package/lib/ZodError.js +0 -301
  60. package/lib/ZodError.js.map +0 -1
  61. package/lib/benchmarks/index.d.ts +0 -2
  62. package/lib/benchmarks/index.d.ts.map +0 -1
  63. package/lib/benchmarks/index.js +0 -54
  64. package/lib/benchmarks/index.js.map +0 -1
  65. package/lib/benchmarks/object.d.ts +0 -6
  66. package/lib/benchmarks/object.d.ts.map +0 -1
  67. package/lib/benchmarks/object.js +0 -71
  68. package/lib/benchmarks/object.js.map +0 -1
  69. package/lib/benchmarks/string.d.ts +0 -6
  70. package/lib/benchmarks/string.d.ts.map +0 -1
  71. package/lib/benchmarks/string.js +0 -45
  72. package/lib/benchmarks/string.js.map +0 -1
  73. package/lib/external.d.ts +0 -4
  74. package/lib/external.d.ts.map +0 -1
  75. package/lib/external.js +0 -16
  76. package/lib/external.js.map +0 -1
  77. package/lib/helpers/errorUtil.d.ts +0 -10
  78. package/lib/helpers/errorUtil.d.ts.map +0 -1
  79. package/lib/helpers/errorUtil.js +0 -13
  80. package/lib/helpers/errorUtil.js.map +0 -1
  81. package/lib/helpers/parseUtil.d.ts +0 -74
  82. package/lib/helpers/parseUtil.d.ts.map +0 -1
  83. package/lib/helpers/parseUtil.js +0 -179
  84. package/lib/helpers/parseUtil.js.map +0 -1
  85. package/lib/helpers/partialUtil.d.ts +0 -18
  86. package/lib/helpers/partialUtil.d.ts.map +0 -1
  87. package/lib/helpers/partialUtil.js +0 -3
  88. package/lib/helpers/partialUtil.js.map +0 -1
  89. package/lib/helpers/util.d.ts +0 -18
  90. package/lib/helpers/util.d.ts.map +0 -1
  91. package/lib/helpers/util.js +0 -87
  92. package/lib/helpers/util.js.map +0 -1
  93. package/lib/index.d.ts +0 -4
  94. package/lib/index.d.ts.map +0 -1
  95. package/lib/index.js +0 -29
  96. package/lib/index.js.map +0 -1
  97. package/lib/index.mjs +0 -2808
  98. package/lib/index.mjs.map +0 -1
  99. package/lib/types.d.ts +0 -541
  100. package/lib/types.d.ts.map +0 -1
  101. package/lib/types.js +0 -2282
  102. package/lib/types.js.map +0 -1
package/lib/types.js DELETED
@@ -1,2282 +0,0 @@
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 __read = (this && this.__read) || function (o, n) {
65
- var m = typeof Symbol === "function" && o[Symbol.iterator];
66
- if (!m) return o;
67
- var i = m.call(o), r, ar = [], e;
68
- try {
69
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
70
- }
71
- catch (error) { e = { error: error }; }
72
- finally {
73
- try {
74
- if (r && !r.done && (m = i["return"])) m.call(i);
75
- }
76
- finally { if (e) throw e.error; }
77
- }
78
- return ar;
79
- };
80
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
81
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
82
- to[j] = from[i];
83
- return to;
84
- };
85
- var __values = (this && this.__values) || function(o) {
86
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
87
- if (m) return m.call(o);
88
- if (o && typeof o.length === "number") return {
89
- next: function () {
90
- if (o && i >= o.length) o = void 0;
91
- return { value: o && o[i++], done: !o };
92
- }
93
- };
94
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
95
- };
96
- Object.defineProperty(exports, "__esModule", { value: true });
97
- exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.late = exports.ZodSchema = exports.Schema = exports.custom = 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.ZodUnion = exports.ZodObject = exports.mergeObjects = exports.objectUtil = exports.ZodNonEmptyArray = 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;
98
- exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.map = void 0;
99
- var errorUtil_1 = require("./helpers/errorUtil");
100
- var parseUtil_1 = require("./helpers/parseUtil");
101
- var util_1 = require("./helpers/util");
102
- var PseudoPromise_1 = require("./PseudoPromise");
103
- var ZodError_1 = require("./ZodError");
104
- var createTasks = function (ctx) {
105
- return ctx.params.async ? [] : null;
106
- };
107
- var createRootContext = function (params) {
108
- var _a;
109
- return new parseUtil_1.ParseContext(parseUtil_1.pathFromArray(params.path || []), [], {
110
- async: (_a = params.async) !== null && _a !== void 0 ? _a : false,
111
- errorMap: params.errorMap || ZodError_1.overrideErrorMap,
112
- });
113
- };
114
- var handleResult = function (ctx, result, parentError) {
115
- if (parseUtil_1.isOk(result)) {
116
- return { success: true, data: result.value };
117
- }
118
- else {
119
- parentError === null || parentError === void 0 ? void 0 : parentError.addIssues(ctx.issues);
120
- var error = new ZodError_1.ZodError(ctx.issues);
121
- return { success: false, error: error };
122
- }
123
- };
124
- var ZodType = /** @class */ (function () {
125
- function ZodType(def) {
126
- var _this = this;
127
- this.parse = function (data, params) {
128
- var result = _this.safeParse(data, params);
129
- if (result.success)
130
- return result.data;
131
- throw result.error;
132
- };
133
- this.safeParse = function (data, params) {
134
- var ctx = createRootContext(__assign(__assign({}, params), { async: false }));
135
- var result = _this._parseSync(ctx, data, parseUtil_1.getParsedType(data));
136
- return handleResult(ctx, result, params === null || params === void 0 ? void 0 : params.parentError);
137
- };
138
- this.parseAsync = function (data, params) { return __awaiter(_this, void 0, void 0, function () {
139
- var result;
140
- return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0: return [4 /*yield*/, this.safeParseAsync(data, params)];
143
- case 1:
144
- result = _a.sent();
145
- if (result.success)
146
- return [2 /*return*/, result.data];
147
- throw result.error;
148
- }
149
- });
150
- }); };
151
- this.safeParseAsync = function (data, params) { return __awaiter(_this, void 0, void 0, function () {
152
- var ctx, maybeAsyncResult, result;
153
- return __generator(this, function (_a) {
154
- switch (_a.label) {
155
- case 0:
156
- ctx = createRootContext(__assign(__assign({}, params), { async: true }));
157
- maybeAsyncResult = this._parse(ctx, data, parseUtil_1.getParsedType(data));
158
- return [4 /*yield*/, (parseUtil_1.isAsync(maybeAsyncResult)
159
- ? maybeAsyncResult.promise
160
- : Promise.resolve(maybeAsyncResult))];
161
- case 1:
162
- result = _a.sent();
163
- return [2 /*return*/, handleResult(ctx, result, params === null || params === void 0 ? void 0 : params.parentError)];
164
- }
165
- });
166
- }); };
167
- /** Alias of safeParseAsync */
168
- this.spa = this.safeParseAsync;
169
- this.refine = function (check, message) {
170
- var getIssueProperties = function (val) {
171
- if (typeof message === "string" || typeof message === "undefined") {
172
- return { message: message };
173
- }
174
- else if (typeof message === "function") {
175
- return message(val);
176
- }
177
- else {
178
- return message;
179
- }
180
- };
181
- return _this._refinement(function (val, ctx) {
182
- var result = check(val);
183
- var setError = function () {
184
- return ctx.addIssue(__assign({ code: ZodError_1.ZodIssueCode.custom }, getIssueProperties(val)));
185
- };
186
- if (result instanceof Promise) {
187
- return result.then(function (data) {
188
- if (!data) {
189
- setError();
190
- return false;
191
- }
192
- else {
193
- return true;
194
- }
195
- });
196
- }
197
- if (!result) {
198
- setError();
199
- return false;
200
- }
201
- else {
202
- return true;
203
- }
204
- });
205
- };
206
- this.refinement = function (check, refinementData) {
207
- return _this._refinement(function (val, ctx) {
208
- if (!check(val)) {
209
- ctx.addIssue(typeof refinementData === "function"
210
- ? refinementData(val, ctx)
211
- : refinementData);
212
- return false;
213
- }
214
- else {
215
- return true;
216
- }
217
- });
218
- };
219
- this.superRefine = this._refinement;
220
- this.optional = function () {
221
- return ZodOptional.create(_this);
222
- };
223
- this.nullable = function () {
224
- return ZodNullable.create(_this);
225
- };
226
- this.nullish = function () { return _this.optional().nullable(); };
227
- this.array = function () { return ZodArray.create(_this); };
228
- this.isOptional = function () { return _this.safeParse(undefined).success; };
229
- this.isNullable = function () { return _this.safeParse(null).success; };
230
- this._def = def;
231
- this.transform = this.transform.bind(this);
232
- this.default = this.default.bind(this);
233
- }
234
- ZodType.prototype._parseSync = function (_ctx, _data, _parsedType) {
235
- var result = this._parse(_ctx, _data, _parsedType);
236
- if (parseUtil_1.isAsync(result)) {
237
- throw new Error("Synchronous parse encountered promise.");
238
- }
239
- return result;
240
- };
241
- ZodType.prototype._refinement = function (refinement) {
242
- var returnType;
243
- if (this instanceof ZodEffects) {
244
- returnType = new ZodEffects(__assign(__assign({}, this._def), { effects: __spreadArray(__spreadArray([], __read((this._def.effects || []))), [
245
- { type: "refinement", refinement: refinement },
246
- ]) }));
247
- }
248
- else {
249
- returnType = new ZodEffects({
250
- schema: this,
251
- effects: [{ type: "refinement", refinement: refinement }],
252
- });
253
- }
254
- return returnType;
255
- };
256
- ZodType.prototype.or = function (option) {
257
- return ZodUnion.create([this, option]);
258
- };
259
- ZodType.prototype.and = function (incoming) {
260
- return ZodIntersection.create(this, incoming);
261
- };
262
- ZodType.prototype.transform = function (transform) {
263
- return new ZodEffects({
264
- schema: this,
265
- effects: [{ type: "transform", transform: transform }],
266
- });
267
- };
268
- ZodType.prototype.default = function (def) {
269
- var defaultValueFunc = typeof def === "function" ? def : function () { return def; };
270
- // if (this instanceof ZodOptional) {
271
- // return new ZodOptional({
272
- // ...this._def,
273
- // defaultValue: defaultValueFunc,
274
- // }) as any;
275
- // }
276
- return new ZodDefault({
277
- innerType: this,
278
- defaultValue: defaultValueFunc,
279
- });
280
- };
281
- return ZodType;
282
- }());
283
- exports.ZodType = ZodType;
284
- exports.Schema = ZodType;
285
- exports.ZodSchema = ZodType;
286
- var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
287
- // from https://stackoverflow.com/a/46181/1550155
288
- // old version: too slow, didn't support unicode
289
- // 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;
290
- // eslint-disable-next-line
291
- var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
292
- var ZodString = /** @class */ (function (_super) {
293
- __extends(ZodString, _super);
294
- function ZodString() {
295
- var _this = _super !== null && _super.apply(this, arguments) || this;
296
- _this._regex = function (regex, validation, message) {
297
- return _this.refinement(function (data) { return regex.test(data); }, __assign({ validation: validation, code: ZodError_1.ZodIssueCode.invalid_string }, errorUtil_1.errorUtil.errToObj(message)));
298
- };
299
- _this.email = function (message) {
300
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
301
- __assign({ kind: "email" }, errorUtil_1.errorUtil.errToObj(message)),
302
- ]) }));
303
- };
304
- _this.url = function (message) {
305
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
306
- __assign({ kind: "url" }, errorUtil_1.errorUtil.errToObj(message)),
307
- ]) }));
308
- };
309
- _this.uuid = function (message) {
310
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
311
- __assign({ kind: "uuid" }, errorUtil_1.errorUtil.errToObj(message)),
312
- ]) }));
313
- };
314
- _this.regex = function (regex, message) {
315
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
316
- __assign({ kind: "regex", regex: regex }, errorUtil_1.errorUtil.errToObj(message)),
317
- ]) }));
318
- };
319
- _this.min = function (minLength, message) {
320
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
321
- __assign({ kind: "min", value: minLength }, errorUtil_1.errorUtil.errToObj(message)),
322
- ]) }));
323
- };
324
- _this.max = function (maxLength, message) {
325
- return new ZodString(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
326
- __assign({ kind: "max", value: maxLength }, errorUtil_1.errorUtil.errToObj(message)),
327
- ]) }));
328
- };
329
- /**
330
- * Deprecated.
331
- * Use z.string().min(1) instead.
332
- */
333
- _this.nonempty = function (message) {
334
- return _this.min(1, errorUtil_1.errorUtil.errToObj(message));
335
- };
336
- return _this;
337
- }
338
- ZodString.prototype._parse = function (ctx, data, parsedType) {
339
- var e_1, _a;
340
- if (parsedType !== parseUtil_1.ZodParsedType.string) {
341
- ctx.addIssue(data, {
342
- code: ZodError_1.ZodIssueCode.invalid_type,
343
- expected: parseUtil_1.ZodParsedType.string,
344
- received: parsedType,
345
- });
346
- return parseUtil_1.INVALID;
347
- }
348
- var invalid = false;
349
- try {
350
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
351
- var check = _c.value;
352
- if (check.kind === "min") {
353
- if (data.length < check.value) {
354
- invalid = true;
355
- ctx.addIssue(data, {
356
- code: ZodError_1.ZodIssueCode.too_small,
357
- minimum: check.value,
358
- type: "string",
359
- inclusive: true,
360
- message: check.message,
361
- });
362
- }
363
- }
364
- else if (check.kind === "max") {
365
- if (data.length > check.value) {
366
- invalid = true;
367
- ctx.addIssue(data, {
368
- code: ZodError_1.ZodIssueCode.too_big,
369
- maximum: check.value,
370
- type: "string",
371
- inclusive: true,
372
- message: check.message,
373
- // ...errorUtil.errToObj(this._def.maxLength.message),
374
- });
375
- }
376
- }
377
- else if (check.kind === "email") {
378
- if (!emailRegex.test(data)) {
379
- invalid = true;
380
- ctx.addIssue(data, {
381
- validation: "email",
382
- code: ZodError_1.ZodIssueCode.invalid_string,
383
- message: check.message,
384
- });
385
- }
386
- }
387
- else if (check.kind === "uuid") {
388
- if (!uuidRegex.test(data)) {
389
- invalid = true;
390
- ctx.addIssue(data, {
391
- validation: "uuid",
392
- code: ZodError_1.ZodIssueCode.invalid_string,
393
- message: check.message,
394
- });
395
- }
396
- }
397
- else if (check.kind === "url") {
398
- try {
399
- new URL(data);
400
- }
401
- catch (_d) {
402
- invalid = true;
403
- ctx.addIssue(data, {
404
- validation: "url",
405
- code: ZodError_1.ZodIssueCode.invalid_string,
406
- message: check.message,
407
- });
408
- }
409
- }
410
- else if (check.kind === "regex") {
411
- if (!check.regex.test(data)) {
412
- invalid = true;
413
- ctx.addIssue(data, {
414
- validation: "regex",
415
- code: ZodError_1.ZodIssueCode.invalid_string,
416
- message: check.message,
417
- });
418
- }
419
- }
420
- }
421
- }
422
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
423
- finally {
424
- try {
425
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
426
- }
427
- finally { if (e_1) throw e_1.error; }
428
- }
429
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(data);
430
- };
431
- ZodString.prototype.length = function (len, message) {
432
- return this.min(len, message).max(len, message);
433
- };
434
- Object.defineProperty(ZodString.prototype, "isEmail", {
435
- get: function () {
436
- return !!this._def.checks.find(function (ch) { return ch.kind === "email"; });
437
- },
438
- enumerable: false,
439
- configurable: true
440
- });
441
- Object.defineProperty(ZodString.prototype, "isURL", {
442
- get: function () {
443
- return !!this._def.checks.find(function (ch) { return ch.kind === "url"; });
444
- },
445
- enumerable: false,
446
- configurable: true
447
- });
448
- Object.defineProperty(ZodString.prototype, "isUUID", {
449
- get: function () {
450
- return !!this._def.checks.find(function (ch) { return ch.kind === "uuid"; });
451
- },
452
- enumerable: false,
453
- configurable: true
454
- });
455
- Object.defineProperty(ZodString.prototype, "minLength", {
456
- get: function () {
457
- var min = -Infinity;
458
- this._def.checks.map(function (ch) {
459
- if (ch.kind === "min") {
460
- if (min === null || ch.value > min) {
461
- min = ch.value;
462
- }
463
- }
464
- });
465
- return min;
466
- },
467
- enumerable: false,
468
- configurable: true
469
- });
470
- Object.defineProperty(ZodString.prototype, "maxLength", {
471
- get: function () {
472
- var max = null;
473
- this._def.checks.map(function (ch) {
474
- if (ch.kind === "min") {
475
- if (max === null || ch.value < max) {
476
- max = ch.value;
477
- }
478
- }
479
- });
480
- return max;
481
- },
482
- enumerable: false,
483
- configurable: true
484
- });
485
- ZodString.create = function () {
486
- return new ZodString({
487
- checks: [],
488
- });
489
- };
490
- return ZodString;
491
- }(ZodType));
492
- exports.ZodString = ZodString;
493
- var ZodNumber = /** @class */ (function (_super) {
494
- __extends(ZodNumber, _super);
495
- function ZodNumber() {
496
- var _this = _super !== null && _super.apply(this, arguments) || this;
497
- _this.min = function (value, message) {
498
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
499
- {
500
- kind: "min",
501
- value: value,
502
- inclusive: true,
503
- message: errorUtil_1.errorUtil.toString(message),
504
- },
505
- ]) }));
506
- };
507
- _this.max = function (value, message) {
508
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
509
- {
510
- kind: "max",
511
- value: value,
512
- inclusive: true,
513
- message: errorUtil_1.errorUtil.toString(message),
514
- },
515
- ]) }));
516
- };
517
- _this.int = function (message) {
518
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
519
- {
520
- kind: "int",
521
- message: errorUtil_1.errorUtil.toString(message),
522
- },
523
- ]) }));
524
- };
525
- _this.positive = function (message) {
526
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
527
- {
528
- kind: "min",
529
- value: 0,
530
- inclusive: false,
531
- message: errorUtil_1.errorUtil.toString(message),
532
- },
533
- ]) }));
534
- };
535
- _this.negative = function (message) {
536
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
537
- {
538
- kind: "max",
539
- value: 0,
540
- inclusive: false,
541
- message: errorUtil_1.errorUtil.toString(message),
542
- },
543
- ]) }));
544
- };
545
- _this.nonpositive = function (message) {
546
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
547
- {
548
- kind: "max",
549
- value: 0,
550
- inclusive: true,
551
- message: errorUtil_1.errorUtil.toString(message),
552
- },
553
- ]) }));
554
- };
555
- _this.nonnegative = function (message) {
556
- return new ZodNumber(__assign(__assign({}, _this._def), { checks: __spreadArray(__spreadArray([], __read(_this._def.checks)), [
557
- {
558
- kind: "min",
559
- value: 0,
560
- inclusive: true,
561
- message: errorUtil_1.errorUtil.toString(message),
562
- },
563
- ]) }));
564
- };
565
- return _this;
566
- }
567
- ZodNumber.prototype._parse = function (ctx, data, parsedType) {
568
- var e_2, _a;
569
- if (parsedType !== parseUtil_1.ZodParsedType.number) {
570
- ctx.addIssue(data, {
571
- code: ZodError_1.ZodIssueCode.invalid_type,
572
- expected: parseUtil_1.ZodParsedType.number,
573
- received: parsedType,
574
- });
575
- return parseUtil_1.INVALID;
576
- }
577
- var invalid = false;
578
- try {
579
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
580
- var check = _c.value;
581
- if (check.kind === "int") {
582
- if (!Number.isInteger(data)) {
583
- invalid = true;
584
- ctx.addIssue(data, {
585
- code: ZodError_1.ZodIssueCode.invalid_type,
586
- expected: "integer",
587
- received: "float",
588
- message: check.message,
589
- });
590
- }
591
- }
592
- else if (check.kind === "min") {
593
- // const MIN = check.value;
594
- var tooSmall = check.inclusive
595
- ? data < check.value
596
- : data <= check.value;
597
- if (tooSmall) {
598
- invalid = true;
599
- ctx.addIssue(data, {
600
- code: ZodError_1.ZodIssueCode.too_small,
601
- minimum: check.value,
602
- type: "number",
603
- inclusive: check.inclusive,
604
- message: check.message,
605
- });
606
- }
607
- }
608
- else if (check.kind === "max") {
609
- var tooBig = check.inclusive
610
- ? data > check.value
611
- : data >= check.value;
612
- if (tooBig) {
613
- invalid = true;
614
- ctx.addIssue(data, {
615
- code: ZodError_1.ZodIssueCode.too_big,
616
- maximum: check.value,
617
- type: "number",
618
- inclusive: check.inclusive,
619
- message: check.message,
620
- });
621
- }
622
- }
623
- }
624
- }
625
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
626
- finally {
627
- try {
628
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
629
- }
630
- finally { if (e_2) throw e_2.error; }
631
- }
632
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(data);
633
- };
634
- Object.defineProperty(ZodNumber.prototype, "minValue", {
635
- get: function () {
636
- var e_3, _a;
637
- var min = null;
638
- try {
639
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
640
- var ch = _c.value;
641
- if (ch.kind === "min") {
642
- if (min === null || ch.value > min)
643
- min = ch.value;
644
- }
645
- }
646
- }
647
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
648
- finally {
649
- try {
650
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
651
- }
652
- finally { if (e_3) throw e_3.error; }
653
- }
654
- return min;
655
- },
656
- enumerable: false,
657
- configurable: true
658
- });
659
- Object.defineProperty(ZodNumber.prototype, "maxValue", {
660
- get: function () {
661
- var e_4, _a;
662
- var max = null;
663
- try {
664
- for (var _b = __values(this._def.checks), _c = _b.next(); !_c.done; _c = _b.next()) {
665
- var ch = _c.value;
666
- if (ch.kind === "max") {
667
- if (max === null || ch.value < max)
668
- max = ch.value;
669
- }
670
- }
671
- }
672
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
673
- finally {
674
- try {
675
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
676
- }
677
- finally { if (e_4) throw e_4.error; }
678
- }
679
- return max;
680
- },
681
- enumerable: false,
682
- configurable: true
683
- });
684
- Object.defineProperty(ZodNumber.prototype, "isInt", {
685
- get: function () {
686
- return !!this._def.checks.find(function (ch) { return ch.kind === "int"; });
687
- },
688
- enumerable: false,
689
- configurable: true
690
- });
691
- ZodNumber.create = function () {
692
- return new ZodNumber({
693
- checks: [],
694
- });
695
- };
696
- return ZodNumber;
697
- }(ZodType));
698
- exports.ZodNumber = ZodNumber;
699
- var ZodBigInt = /** @class */ (function (_super) {
700
- __extends(ZodBigInt, _super);
701
- function ZodBigInt() {
702
- return _super !== null && _super.apply(this, arguments) || this;
703
- }
704
- ZodBigInt.prototype._parse = function (ctx, data, parsedType) {
705
- if (parsedType !== parseUtil_1.ZodParsedType.bigint) {
706
- ctx.addIssue(data, {
707
- code: ZodError_1.ZodIssueCode.invalid_type,
708
- expected: parseUtil_1.ZodParsedType.bigint,
709
- received: parsedType,
710
- });
711
- return parseUtil_1.INVALID;
712
- }
713
- return parseUtil_1.OK(data);
714
- };
715
- ZodBigInt.create = function () {
716
- return new ZodBigInt({});
717
- };
718
- return ZodBigInt;
719
- }(ZodType));
720
- exports.ZodBigInt = ZodBigInt;
721
- var ZodBoolean = /** @class */ (function (_super) {
722
- __extends(ZodBoolean, _super);
723
- function ZodBoolean() {
724
- return _super !== null && _super.apply(this, arguments) || this;
725
- }
726
- ZodBoolean.prototype._parse = function (ctx, data, parsedType) {
727
- if (parsedType !== parseUtil_1.ZodParsedType.boolean) {
728
- ctx.addIssue(data, {
729
- code: ZodError_1.ZodIssueCode.invalid_type,
730
- expected: parseUtil_1.ZodParsedType.boolean,
731
- received: parsedType,
732
- });
733
- return parseUtil_1.INVALID;
734
- }
735
- return parseUtil_1.OK(data);
736
- };
737
- ZodBoolean.create = function () {
738
- return new ZodBoolean({});
739
- };
740
- return ZodBoolean;
741
- }(ZodType));
742
- exports.ZodBoolean = ZodBoolean;
743
- var ZodDate = /** @class */ (function (_super) {
744
- __extends(ZodDate, _super);
745
- function ZodDate() {
746
- return _super !== null && _super.apply(this, arguments) || this;
747
- }
748
- ZodDate.prototype._parse = function (ctx, data, parsedType) {
749
- if (parsedType !== parseUtil_1.ZodParsedType.date) {
750
- ctx.addIssue(data, {
751
- code: ZodError_1.ZodIssueCode.invalid_type,
752
- expected: parseUtil_1.ZodParsedType.date,
753
- received: parsedType,
754
- });
755
- return parseUtil_1.INVALID;
756
- }
757
- if (isNaN(data.getTime())) {
758
- ctx.addIssue(data, {
759
- code: ZodError_1.ZodIssueCode.invalid_date,
760
- });
761
- return parseUtil_1.INVALID;
762
- }
763
- return parseUtil_1.OK(new Date(data.getTime()));
764
- };
765
- ZodDate.create = function () {
766
- return new ZodDate({});
767
- };
768
- return ZodDate;
769
- }(ZodType));
770
- exports.ZodDate = ZodDate;
771
- var ZodUndefined = /** @class */ (function (_super) {
772
- __extends(ZodUndefined, _super);
773
- function ZodUndefined() {
774
- return _super !== null && _super.apply(this, arguments) || this;
775
- }
776
- ZodUndefined.prototype._parse = function (ctx, data, parsedType) {
777
- if (parsedType !== parseUtil_1.ZodParsedType.undefined) {
778
- ctx.addIssue(data, {
779
- code: ZodError_1.ZodIssueCode.invalid_type,
780
- expected: parseUtil_1.ZodParsedType.undefined,
781
- received: parsedType,
782
- });
783
- return parseUtil_1.INVALID;
784
- }
785
- return parseUtil_1.OK(data);
786
- };
787
- ZodUndefined.create = function () {
788
- return new ZodUndefined({});
789
- };
790
- return ZodUndefined;
791
- }(ZodType));
792
- exports.ZodUndefined = ZodUndefined;
793
- var ZodNull = /** @class */ (function (_super) {
794
- __extends(ZodNull, _super);
795
- function ZodNull() {
796
- return _super !== null && _super.apply(this, arguments) || this;
797
- }
798
- ZodNull.prototype._parse = function (ctx, data, parsedType) {
799
- if (parsedType !== parseUtil_1.ZodParsedType.null) {
800
- ctx.addIssue(data, {
801
- code: ZodError_1.ZodIssueCode.invalid_type,
802
- expected: parseUtil_1.ZodParsedType.null,
803
- received: parsedType,
804
- });
805
- return parseUtil_1.INVALID;
806
- }
807
- return parseUtil_1.OK(data);
808
- };
809
- ZodNull.create = function () {
810
- return new ZodNull({});
811
- };
812
- return ZodNull;
813
- }(ZodType));
814
- exports.ZodNull = ZodNull;
815
- var ZodAny = /** @class */ (function (_super) {
816
- __extends(ZodAny, _super);
817
- function ZodAny() {
818
- return _super !== null && _super.apply(this, arguments) || this;
819
- }
820
- ZodAny.prototype._parse = function (_ctx, data, _parsedType) {
821
- return parseUtil_1.OK(data);
822
- };
823
- ZodAny.create = function () {
824
- return new ZodAny({});
825
- };
826
- return ZodAny;
827
- }(ZodType));
828
- exports.ZodAny = ZodAny;
829
- var ZodUnknown = /** @class */ (function (_super) {
830
- __extends(ZodUnknown, _super);
831
- function ZodUnknown() {
832
- return _super !== null && _super.apply(this, arguments) || this;
833
- }
834
- ZodUnknown.prototype._parse = function (_ctx, data, _parsedType) {
835
- return parseUtil_1.OK(data);
836
- };
837
- ZodUnknown.create = function () {
838
- return new ZodUnknown({});
839
- };
840
- return ZodUnknown;
841
- }(ZodType));
842
- exports.ZodUnknown = ZodUnknown;
843
- var ZodNever = /** @class */ (function (_super) {
844
- __extends(ZodNever, _super);
845
- function ZodNever() {
846
- return _super !== null && _super.apply(this, arguments) || this;
847
- }
848
- ZodNever.prototype._parse = function (ctx, data, parsedType) {
849
- ctx.addIssue(data, {
850
- code: ZodError_1.ZodIssueCode.invalid_type,
851
- expected: parseUtil_1.ZodParsedType.never,
852
- received: parsedType,
853
- });
854
- return parseUtil_1.INVALID;
855
- };
856
- ZodNever.create = function () {
857
- return new ZodNever({});
858
- };
859
- return ZodNever;
860
- }(ZodType));
861
- exports.ZodNever = ZodNever;
862
- var ZodVoid = /** @class */ (function (_super) {
863
- __extends(ZodVoid, _super);
864
- function ZodVoid() {
865
- return _super !== null && _super.apply(this, arguments) || this;
866
- }
867
- ZodVoid.prototype._parse = function (ctx, data, parsedType) {
868
- if (parsedType !== parseUtil_1.ZodParsedType.undefined &&
869
- parsedType !== parseUtil_1.ZodParsedType.null) {
870
- ctx.addIssue(data, {
871
- code: ZodError_1.ZodIssueCode.invalid_type,
872
- expected: parseUtil_1.ZodParsedType.void,
873
- received: parsedType,
874
- });
875
- return parseUtil_1.INVALID;
876
- }
877
- return parseUtil_1.OK(data);
878
- };
879
- ZodVoid.create = function () {
880
- return new ZodVoid({});
881
- };
882
- return ZodVoid;
883
- }(ZodType));
884
- exports.ZodVoid = ZodVoid;
885
- var parseArray = function (ctx, data, parsedType, def, nonEmpty) {
886
- if (parsedType !== parseUtil_1.ZodParsedType.array) {
887
- ctx.addIssue(data, {
888
- code: ZodError_1.ZodIssueCode.invalid_type,
889
- expected: parseUtil_1.ZodParsedType.array,
890
- received: parsedType,
891
- });
892
- return parseUtil_1.INVALID;
893
- }
894
- var invalid = false;
895
- if (def.minLength !== null) {
896
- if (data.length < def.minLength.value) {
897
- invalid = true;
898
- ctx.addIssue(data, {
899
- code: ZodError_1.ZodIssueCode.too_small,
900
- minimum: def.minLength.value,
901
- type: "array",
902
- inclusive: true,
903
- message: def.minLength.message,
904
- });
905
- }
906
- }
907
- if (def.maxLength !== null) {
908
- if (data.length > def.maxLength.value) {
909
- invalid = true;
910
- ctx.addIssue(data, {
911
- code: ZodError_1.ZodIssueCode.too_big,
912
- maximum: def.maxLength.value,
913
- type: "array",
914
- inclusive: true,
915
- message: def.maxLength.message,
916
- });
917
- }
918
- }
919
- if (nonEmpty && data.length < 1) {
920
- invalid = true;
921
- ctx.addIssue(data, {
922
- code: ZodError_1.ZodIssueCode.too_small,
923
- minimum: 1,
924
- type: "array",
925
- inclusive: true,
926
- // message: this._def.minLength.message,
927
- // ...errorUtil.errToObj(this._def.minLength.message),
928
- });
929
- }
930
- if (invalid) {
931
- return parseUtil_1.INVALID;
932
- }
933
- var tasks = createTasks(ctx);
934
- var result = new Array(data.length);
935
- var type = def.type;
936
- var handleParsed = function (index, parsedItem) {
937
- if (parseUtil_1.isOk(parsedItem)) {
938
- result[index] = parsedItem.value;
939
- }
940
- else if (parseUtil_1.isInvalid(parsedItem)) {
941
- invalid = true;
942
- }
943
- else {
944
- tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(index, parsed); }));
945
- }
946
- };
947
- data.forEach(function (item, index) {
948
- handleParsed(index, type._parse(ctx.stepInto(index), item, parseUtil_1.getParsedType(item)));
949
- });
950
- if (tasks !== null && tasks.length > 0) {
951
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(result)); }));
952
- }
953
- else {
954
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(result);
955
- }
956
- };
957
- var ZodArray = /** @class */ (function (_super) {
958
- __extends(ZodArray, _super);
959
- function ZodArray() {
960
- var _this = _super !== null && _super.apply(this, arguments) || this;
961
- _this.min = function (minLength, message) {
962
- return new ZodArray(__assign(__assign({}, _this._def), { minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) } }));
963
- };
964
- _this.max = function (maxLength, message) {
965
- return new ZodArray(__assign(__assign({}, _this._def), { maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) } }));
966
- };
967
- _this.length = function (len, message) {
968
- return _this.min(len, message).max(len, message);
969
- };
970
- _this.nonempty = function () {
971
- return new ZodNonEmptyArray(__assign({}, _this._def));
972
- };
973
- return _this;
974
- }
975
- ZodArray.prototype._parse = function (ctx, data, parsedType) {
976
- var nonEmpty = false;
977
- return parseArray(ctx, data, parsedType, this._def, nonEmpty);
978
- };
979
- Object.defineProperty(ZodArray.prototype, "element", {
980
- get: function () {
981
- return this._def.type;
982
- },
983
- enumerable: false,
984
- configurable: true
985
- });
986
- ZodArray.create = function (schema) {
987
- return new ZodArray({
988
- type: schema,
989
- minLength: null,
990
- maxLength: null,
991
- });
992
- };
993
- return ZodArray;
994
- }(ZodType));
995
- exports.ZodArray = ZodArray;
996
- var ZodNonEmptyArray = /** @class */ (function (_super) {
997
- __extends(ZodNonEmptyArray, _super);
998
- function ZodNonEmptyArray() {
999
- var _this = _super !== null && _super.apply(this, arguments) || this;
1000
- _this.min = function (minLength, message) {
1001
- return new ZodNonEmptyArray(__assign(__assign({}, _this._def), { minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) } }));
1002
- };
1003
- _this.max = function (maxLength, message) {
1004
- return new ZodNonEmptyArray(__assign(__assign({}, _this._def), { maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) } }));
1005
- };
1006
- _this.length = function (len, message) {
1007
- return _this.min(len, message).max(len, message);
1008
- };
1009
- return _this;
1010
- }
1011
- ZodNonEmptyArray.prototype._parse = function (ctx, data, parsedType) {
1012
- var nonEmpty = true;
1013
- return parseArray(ctx, data, parsedType, this._def, nonEmpty);
1014
- };
1015
- ZodNonEmptyArray.create = function (schema) {
1016
- return new ZodNonEmptyArray({
1017
- type: schema,
1018
- minLength: null,
1019
- maxLength: null,
1020
- });
1021
- };
1022
- return ZodNonEmptyArray;
1023
- }(ZodType));
1024
- exports.ZodNonEmptyArray = ZodNonEmptyArray;
1025
- /////////////////////////////////////////
1026
- /////////////////////////////////////////
1027
- ////////// //////////
1028
- ////////// ZodObject //////////
1029
- ////////// //////////
1030
- /////////////////////////////////////////
1031
- /////////////////////////////////////////
1032
- var objectUtil;
1033
- (function (objectUtil) {
1034
- objectUtil.mergeShapes = function (first, second) {
1035
- return __assign(__assign({}, first), second);
1036
- };
1037
- objectUtil.intersectShapes = function (first, second) {
1038
- var e_5, _a;
1039
- var firstKeys = Object.keys(first);
1040
- var secondKeys = Object.keys(second);
1041
- var sharedKeys = firstKeys.filter(function (k) { return secondKeys.indexOf(k) !== -1; });
1042
- var sharedShape = {};
1043
- try {
1044
- for (var sharedKeys_1 = __values(sharedKeys), sharedKeys_1_1 = sharedKeys_1.next(); !sharedKeys_1_1.done; sharedKeys_1_1 = sharedKeys_1.next()) {
1045
- var k = sharedKeys_1_1.value;
1046
- sharedShape[k] = ZodIntersection.create(first[k], second[k]);
1047
- }
1048
- }
1049
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
1050
- finally {
1051
- try {
1052
- if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
1053
- }
1054
- finally { if (e_5) throw e_5.error; }
1055
- }
1056
- return __assign(__assign(__assign({}, first), second), sharedShape);
1057
- };
1058
- })(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
1059
- var mergeObjects = function (first) { return function (second) {
1060
- var mergedShape = objectUtil.mergeShapes(first._def.shape(), second._def.shape());
1061
- var merged = new ZodObject({
1062
- // effects: [...(first._def.effects || []), ...(second._def.effects || [])],
1063
- unknownKeys: first._def.unknownKeys,
1064
- catchall: first._def.catchall,
1065
- shape: function () { return mergedShape; },
1066
- });
1067
- return merged;
1068
- }; };
1069
- exports.mergeObjects = mergeObjects;
1070
- var AugmentFactory = function (def) { return function (augmentation) {
1071
- return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
1072
- }; };
1073
- var ZodObject = /** @class */ (function (_super) {
1074
- __extends(ZodObject, _super);
1075
- function ZodObject() {
1076
- var _this = _super !== null && _super.apply(this, arguments) || this;
1077
- _this._cached = null;
1078
- _this.strict = function () {
1079
- return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "strict" }));
1080
- };
1081
- _this.strip = function () {
1082
- return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "strip" }));
1083
- };
1084
- _this.passthrough = function () {
1085
- return new ZodObject(__assign(__assign({}, _this._def), { unknownKeys: "passthrough" }));
1086
- };
1087
- /**
1088
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
1089
- * If you want to pass through unknown properies, use `.passthrough()` instead.
1090
- */
1091
- _this.nonstrict = _this.passthrough;
1092
- _this.augment = AugmentFactory(_this._def);
1093
- _this.extend = AugmentFactory(_this._def);
1094
- _this.setKey = function (key, schema) {
1095
- var _a;
1096
- return _this.augment((_a = {}, _a[key] = schema, _a));
1097
- };
1098
- /**
1099
- * Prior to zod@1.0.12 there was a bug in the
1100
- * inferred type of merged objects. Please
1101
- * upgrade if you are experiencing issues.
1102
- */
1103
- _this.merge = function (merging) {
1104
- var mergedShape = objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
1105
- var merged = new ZodObject({
1106
- // effects: [], // wipe all refinements
1107
- unknownKeys: merging._def.unknownKeys,
1108
- catchall: merging._def.catchall,
1109
- shape: function () { return mergedShape; },
1110
- });
1111
- return merged;
1112
- };
1113
- _this.catchall = function (index) {
1114
- return new ZodObject(__assign(__assign({}, _this._def), { catchall: index }));
1115
- };
1116
- _this.pick = function (mask) {
1117
- var shape = {};
1118
- Object.keys(mask).map(function (key) {
1119
- shape[key] = _this.shape[key];
1120
- });
1121
- return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
1122
- };
1123
- _this.omit = function (mask) {
1124
- var shape = {};
1125
- Object.keys(_this.shape).map(function (key) {
1126
- if (Object.keys(mask).indexOf(key) === -1) {
1127
- shape[key] = _this.shape[key];
1128
- }
1129
- });
1130
- return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return shape; } }));
1131
- };
1132
- _this.partial = function () {
1133
- var newShape = {};
1134
- for (var key in _this.shape) {
1135
- var fieldSchema = _this.shape[key];
1136
- newShape[key] = fieldSchema.isOptional()
1137
- ? fieldSchema
1138
- : fieldSchema.optional();
1139
- }
1140
- return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
1141
- };
1142
- _this.deepPartial = function () {
1143
- var newShape = {};
1144
- for (var key in _this.shape) {
1145
- var fieldSchema = _this.shape[key];
1146
- if (fieldSchema instanceof ZodObject) {
1147
- newShape[key] = fieldSchema.isOptional()
1148
- ? fieldSchema
1149
- : fieldSchema.deepPartial().optional();
1150
- }
1151
- else {
1152
- newShape[key] = fieldSchema.isOptional()
1153
- ? fieldSchema
1154
- : fieldSchema.optional();
1155
- }
1156
- }
1157
- return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
1158
- };
1159
- _this.required = function () {
1160
- var newShape = {};
1161
- for (var key in _this.shape) {
1162
- var fieldSchema = _this.shape[key];
1163
- var newField = fieldSchema;
1164
- while (newField instanceof ZodOptional) {
1165
- newField = newField._def.innerType;
1166
- }
1167
- newShape[key] = newField;
1168
- }
1169
- return new ZodObject(__assign(__assign({}, _this._def), { shape: function () { return newShape; } }));
1170
- };
1171
- return _this;
1172
- }
1173
- ZodObject.prototype._getCached = function () {
1174
- if (this._cached !== null)
1175
- return this._cached;
1176
- var shape = this._def.shape();
1177
- var keys = Object.keys(shape);
1178
- return (this._cached = { shape: shape, keys: keys });
1179
- };
1180
- ZodObject.prototype._parse = function (ctx, data, parsedType) {
1181
- var e_6, _a, e_7, _b, e_8, _c;
1182
- if (parsedType !== parseUtil_1.ZodParsedType.object) {
1183
- ctx.addIssue(data, {
1184
- code: ZodError_1.ZodIssueCode.invalid_type,
1185
- expected: parseUtil_1.ZodParsedType.object,
1186
- received: parsedType,
1187
- });
1188
- return parseUtil_1.INVALID;
1189
- }
1190
- var _d = this._getCached(), shape = _d.shape, shapeKeys = _d.keys;
1191
- var invalid = false;
1192
- var tasks = createTasks(ctx);
1193
- var resultObject = {};
1194
- var handleParsed = function (key, parsedValue) {
1195
- if (parseUtil_1.isOk(parsedValue)) {
1196
- var value = parsedValue.value;
1197
- if (typeof value !== "undefined" || key in data) {
1198
- // key was valid but result was undefined: add it to the result object
1199
- // only if key was in the input data object - if it wasn't, then it's
1200
- // an optional key that should not be added
1201
- resultObject[key] = value;
1202
- }
1203
- }
1204
- else if (parseUtil_1.isInvalid(parsedValue)) {
1205
- invalid = true;
1206
- }
1207
- else {
1208
- tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedValue.promise.then(function (parsed) { return handleParsed(key, parsed); }));
1209
- }
1210
- };
1211
- try {
1212
- for (var shapeKeys_1 = __values(shapeKeys), shapeKeys_1_1 = shapeKeys_1.next(); !shapeKeys_1_1.done; shapeKeys_1_1 = shapeKeys_1.next()) {
1213
- var key = shapeKeys_1_1.value;
1214
- var keyValidator = shape[key];
1215
- var value = data[key];
1216
- handleParsed(key, keyValidator._parse(ctx.stepInto(key), value, parseUtil_1.getParsedType(value)));
1217
- }
1218
- }
1219
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
1220
- finally {
1221
- try {
1222
- if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
1223
- }
1224
- finally { if (e_6) throw e_6.error; }
1225
- }
1226
- if (this._def.catchall instanceof ZodNever) {
1227
- var unknownKeys = this._def.unknownKeys;
1228
- if (unknownKeys === "passthrough") {
1229
- var dataKeys = Object.keys(data);
1230
- var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
1231
- try {
1232
- for (var extraKeys_1 = __values(extraKeys), extraKeys_1_1 = extraKeys_1.next(); !extraKeys_1_1.done; extraKeys_1_1 = extraKeys_1.next()) {
1233
- var key = extraKeys_1_1.value;
1234
- resultObject[key] = data[key];
1235
- }
1236
- }
1237
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
1238
- finally {
1239
- try {
1240
- if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
1241
- }
1242
- finally { if (e_7) throw e_7.error; }
1243
- }
1244
- }
1245
- else if (unknownKeys === "strict") {
1246
- var dataKeys = Object.keys(data);
1247
- var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
1248
- if (extraKeys.length > 0) {
1249
- invalid = true;
1250
- ctx.addIssue(data, {
1251
- code: ZodError_1.ZodIssueCode.unrecognized_keys,
1252
- keys: extraKeys,
1253
- });
1254
- }
1255
- }
1256
- else if (unknownKeys === "strip") {
1257
- }
1258
- else {
1259
- throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1260
- }
1261
- }
1262
- else {
1263
- // run catchall validation
1264
- var catchall = this._def.catchall;
1265
- var dataKeys = Object.keys(data);
1266
- var extraKeys = dataKeys.filter(function (k) { return !(k in shape); });
1267
- try {
1268
- for (var extraKeys_2 = __values(extraKeys), extraKeys_2_1 = extraKeys_2.next(); !extraKeys_2_1.done; extraKeys_2_1 = extraKeys_2.next()) {
1269
- var key = extraKeys_2_1.value;
1270
- var value = data[key];
1271
- handleParsed(key, catchall._parse(ctx.stepInto(key), value, parseUtil_1.getParsedType(value)));
1272
- }
1273
- }
1274
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
1275
- finally {
1276
- try {
1277
- if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
1278
- }
1279
- finally { if (e_8) throw e_8.error; }
1280
- }
1281
- }
1282
- if (tasks !== null && tasks.length > 0) {
1283
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () {
1284
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(resultObject);
1285
- }));
1286
- }
1287
- else {
1288
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(resultObject);
1289
- }
1290
- };
1291
- Object.defineProperty(ZodObject.prototype, "shape", {
1292
- get: function () {
1293
- return this._def.shape();
1294
- },
1295
- enumerable: false,
1296
- configurable: true
1297
- });
1298
- ZodObject.create = function (shape) {
1299
- return new ZodObject({
1300
- shape: function () { return shape; },
1301
- unknownKeys: "strip",
1302
- catchall: ZodNever.create(),
1303
- });
1304
- };
1305
- ZodObject.strictCreate = function (shape) {
1306
- return new ZodObject({
1307
- shape: function () { return shape; },
1308
- unknownKeys: "strict",
1309
- catchall: ZodNever.create(),
1310
- });
1311
- };
1312
- ZodObject.lazycreate = function (shape) {
1313
- return new ZodObject({
1314
- shape: shape,
1315
- unknownKeys: "strip",
1316
- catchall: ZodNever.create(),
1317
- });
1318
- };
1319
- return ZodObject;
1320
- }(ZodType));
1321
- exports.ZodObject = ZodObject;
1322
- // export type toOpts<T> = T extends ZodUnionOptions ? T : never;
1323
- // export type ZodUnionType<
1324
- // A extends ZodTypeAny,
1325
- // B extends ZodTypeAny
1326
- // > = A extends ZodUnion<infer AOpts>
1327
- // ? B extends ZodUnion<infer BOpts>
1328
- // ? ZodUnion<toOpts<[...AOpts, ...BOpts]>>
1329
- // : ZodUnion<toOpts<[...AOpts, B]>>
1330
- // : B extends ZodUnion<infer BOpts>
1331
- // ? ZodUnion<toOpts<[A, ...BOpts]>>
1332
- // : ZodUnion<toOpts<[A, B]>>;
1333
- var ZodUnion = /** @class */ (function (_super) {
1334
- __extends(ZodUnion, _super);
1335
- function ZodUnion() {
1336
- return _super !== null && _super.apply(this, arguments) || this;
1337
- }
1338
- ZodUnion.prototype._parse = function (ctx, data, parsedType) {
1339
- var e_9, _a;
1340
- var options = this._def.options;
1341
- var noMatch = function (allIssues) {
1342
- var unionErrors = allIssues.map(function (issues) { return new ZodError_1.ZodError(issues); });
1343
- var nonTypeErrors = unionErrors.filter(function (err) {
1344
- return err.issues[0].code !== "invalid_type";
1345
- });
1346
- if (nonTypeErrors.length === 1) {
1347
- // TODO encapsulate
1348
- nonTypeErrors[0].issues.forEach(function (issue) { return ctx.issues.push(issue); });
1349
- }
1350
- else {
1351
- ctx.addIssue(data, {
1352
- code: ZodError_1.ZodIssueCode.invalid_union,
1353
- unionErrors: unionErrors,
1354
- });
1355
- }
1356
- return parseUtil_1.INVALID;
1357
- };
1358
- if (ctx.params.async) {
1359
- var contexts_1 = options.map(function () { return new parseUtil_1.ParseContext(ctx.path, [], ctx.params); });
1360
- return PseudoPromise_1.PseudoPromise.all(options.map(function (option, index) {
1361
- return option._parse(contexts_1[index], data, parsedType);
1362
- })).then(function (parsedOptions) {
1363
- var e_10, _a;
1364
- try {
1365
- for (var parsedOptions_1 = __values(parsedOptions), parsedOptions_1_1 = parsedOptions_1.next(); !parsedOptions_1_1.done; parsedOptions_1_1 = parsedOptions_1.next()) {
1366
- var parsedOption = parsedOptions_1_1.value;
1367
- if (parseUtil_1.isOk(parsedOption)) {
1368
- return parsedOption;
1369
- }
1370
- }
1371
- }
1372
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
1373
- finally {
1374
- try {
1375
- if (parsedOptions_1_1 && !parsedOptions_1_1.done && (_a = parsedOptions_1.return)) _a.call(parsedOptions_1);
1376
- }
1377
- finally { if (e_10) throw e_10.error; }
1378
- }
1379
- return noMatch(contexts_1.map(function (ctx) { return ctx.issues; }));
1380
- });
1381
- }
1382
- else {
1383
- var allIssues = [];
1384
- try {
1385
- for (var options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
1386
- var option = options_1_1.value;
1387
- var optionCtx = new parseUtil_1.ParseContext(ctx.path, [], ctx.params);
1388
- var parsedOption = option._parseSync(optionCtx, data, parsedType);
1389
- if (parseUtil_1.isInvalid(parsedOption)) {
1390
- allIssues.push(optionCtx.issues);
1391
- }
1392
- else {
1393
- return parsedOption;
1394
- }
1395
- }
1396
- }
1397
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
1398
- finally {
1399
- try {
1400
- if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
1401
- }
1402
- finally { if (e_9) throw e_9.error; }
1403
- }
1404
- return noMatch(allIssues);
1405
- }
1406
- };
1407
- Object.defineProperty(ZodUnion.prototype, "options", {
1408
- get: function () {
1409
- return this._def.options;
1410
- },
1411
- enumerable: false,
1412
- configurable: true
1413
- });
1414
- ZodUnion.create = function (types) {
1415
- return new ZodUnion({
1416
- options: types,
1417
- });
1418
- };
1419
- return ZodUnion;
1420
- }(ZodType));
1421
- exports.ZodUnion = ZodUnion;
1422
- function mergeValues(a, b) {
1423
- var e_11, _a;
1424
- var aType = parseUtil_1.getParsedType(a);
1425
- var bType = parseUtil_1.getParsedType(b);
1426
- if (a === b) {
1427
- return { valid: true, data: a };
1428
- }
1429
- else if (aType === parseUtil_1.ZodParsedType.object && bType === parseUtil_1.ZodParsedType.object) {
1430
- var bKeysSet_1 = new Set(Object.keys(b));
1431
- var sharedKeys = Object.keys(a).filter(function (key) { return bKeysSet_1.has(key); });
1432
- var newObj = __assign(__assign({}, a), b);
1433
- try {
1434
- for (var sharedKeys_2 = __values(sharedKeys), sharedKeys_2_1 = sharedKeys_2.next(); !sharedKeys_2_1.done; sharedKeys_2_1 = sharedKeys_2.next()) {
1435
- var key = sharedKeys_2_1.value;
1436
- var sharedValue = mergeValues(a[key], b[key]);
1437
- if (!sharedValue.valid) {
1438
- return { valid: false };
1439
- }
1440
- newObj[key] = sharedValue.data;
1441
- }
1442
- }
1443
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1444
- finally {
1445
- try {
1446
- if (sharedKeys_2_1 && !sharedKeys_2_1.done && (_a = sharedKeys_2.return)) _a.call(sharedKeys_2);
1447
- }
1448
- finally { if (e_11) throw e_11.error; }
1449
- }
1450
- return { valid: true, data: newObj };
1451
- }
1452
- else {
1453
- return { valid: false };
1454
- }
1455
- }
1456
- var ZodIntersection = /** @class */ (function (_super) {
1457
- __extends(ZodIntersection, _super);
1458
- function ZodIntersection() {
1459
- return _super !== null && _super.apply(this, arguments) || this;
1460
- }
1461
- ZodIntersection.prototype._parse = function (ctx, data, parsedType) {
1462
- var handleParsed = function (parsedLeft, parsedRight) {
1463
- if (parseUtil_1.isInvalid(parsedLeft) || parseUtil_1.isInvalid(parsedRight)) {
1464
- return parseUtil_1.INVALID;
1465
- }
1466
- var merged = mergeValues(parsedLeft.value, parsedRight.value);
1467
- if (!merged.valid) {
1468
- ctx.addIssue(data, {
1469
- code: ZodError_1.ZodIssueCode.invalid_intersection_types,
1470
- });
1471
- return parseUtil_1.INVALID;
1472
- }
1473
- return parseUtil_1.OK(merged.data);
1474
- };
1475
- if (ctx.params.async) {
1476
- return PseudoPromise_1.PseudoPromise.all([
1477
- this._def.left._parse(ctx, data, parsedType),
1478
- this._def.right._parse(ctx, data, parsedType),
1479
- ]).then(function (_a) {
1480
- var _b = __read(_a, 2), left = _b[0], right = _b[1];
1481
- return handleParsed(left, right);
1482
- });
1483
- }
1484
- else {
1485
- return handleParsed(this._def.left._parseSync(ctx, data, parsedType), this._def.right._parseSync(ctx, data, parsedType));
1486
- }
1487
- };
1488
- ZodIntersection.create = function (left, right) {
1489
- return new ZodIntersection({
1490
- left: left,
1491
- right: right,
1492
- });
1493
- };
1494
- return ZodIntersection;
1495
- }(ZodType));
1496
- exports.ZodIntersection = ZodIntersection;
1497
- var ZodTuple = /** @class */ (function (_super) {
1498
- __extends(ZodTuple, _super);
1499
- function ZodTuple() {
1500
- return _super !== null && _super.apply(this, arguments) || this;
1501
- }
1502
- ZodTuple.prototype._parse = function (ctx, data, parsedType) {
1503
- if (parsedType !== parseUtil_1.ZodParsedType.array) {
1504
- ctx.addIssue(data, {
1505
- code: ZodError_1.ZodIssueCode.invalid_type,
1506
- expected: parseUtil_1.ZodParsedType.array,
1507
- received: parsedType,
1508
- });
1509
- return parseUtil_1.INVALID;
1510
- }
1511
- if (data.length > this._def.items.length) {
1512
- ctx.addIssue(data, {
1513
- code: ZodError_1.ZodIssueCode.too_big,
1514
- maximum: this._def.items.length,
1515
- inclusive: true,
1516
- type: "array",
1517
- });
1518
- return parseUtil_1.INVALID;
1519
- }
1520
- else if (data.length < this._def.items.length) {
1521
- ctx.addIssue(data, {
1522
- code: ZodError_1.ZodIssueCode.too_small,
1523
- minimum: this._def.items.length,
1524
- inclusive: true,
1525
- type: "array",
1526
- });
1527
- return parseUtil_1.INVALID;
1528
- }
1529
- var tasks = createTasks(ctx);
1530
- var items = this._def.items;
1531
- var parseResult = new Array(items.length);
1532
- var invalid = false;
1533
- var handleParsed = function (index, parsedItem) {
1534
- if (parseUtil_1.isOk(parsedItem)) {
1535
- parseResult[index] = parsedItem.value;
1536
- }
1537
- else if (parseUtil_1.isInvalid(parsedItem)) {
1538
- invalid = true;
1539
- }
1540
- else {
1541
- tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(index, parsed); }));
1542
- }
1543
- };
1544
- items.forEach(function (item, index) {
1545
- handleParsed(index, item._parse(ctx.stepInto(index), data[index], parseUtil_1.getParsedType(data[index])));
1546
- });
1547
- if (tasks !== null && tasks.length > 0) {
1548
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult)); }));
1549
- }
1550
- else {
1551
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult);
1552
- }
1553
- };
1554
- Object.defineProperty(ZodTuple.prototype, "items", {
1555
- get: function () {
1556
- return this._def.items;
1557
- },
1558
- enumerable: false,
1559
- configurable: true
1560
- });
1561
- ZodTuple.create = function (schemas) {
1562
- return new ZodTuple({
1563
- items: schemas,
1564
- });
1565
- };
1566
- return ZodTuple;
1567
- }(ZodType));
1568
- exports.ZodTuple = ZodTuple;
1569
- var ZodRecord = /** @class */ (function (_super) {
1570
- __extends(ZodRecord, _super);
1571
- function ZodRecord() {
1572
- return _super !== null && _super.apply(this, arguments) || this;
1573
- }
1574
- ZodRecord.prototype._parse = function (ctx, data, parsedType) {
1575
- if (parsedType !== parseUtil_1.ZodParsedType.object) {
1576
- ctx.addIssue(data, {
1577
- code: ZodError_1.ZodIssueCode.invalid_type,
1578
- expected: parseUtil_1.ZodParsedType.object,
1579
- received: parsedType,
1580
- });
1581
- return parseUtil_1.INVALID;
1582
- }
1583
- var tasks = createTasks(ctx);
1584
- var valueType = this._def.valueType;
1585
- var parseResult = {};
1586
- var invalid = false;
1587
- var handleParsed = function (key, parsedKey) {
1588
- if (parseUtil_1.isOk(parsedKey)) {
1589
- parseResult[key] = parsedKey.value;
1590
- }
1591
- else if (parseUtil_1.isInvalid(parsedKey)) {
1592
- invalid = true;
1593
- }
1594
- else {
1595
- tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedKey.promise.then(function (parsed) { return handleParsed(key, parsed); }));
1596
- }
1597
- };
1598
- for (var key in data) {
1599
- handleParsed(key, valueType._parse(ctx.stepInto(key), data[key], parseUtil_1.getParsedType(data[key])));
1600
- }
1601
- if (tasks !== null && tasks.length > 0) {
1602
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult)); }));
1603
- }
1604
- else {
1605
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult);
1606
- }
1607
- };
1608
- ZodRecord.create = function (valueType) {
1609
- return new ZodRecord({
1610
- valueType: valueType,
1611
- });
1612
- };
1613
- return ZodRecord;
1614
- }(ZodType));
1615
- exports.ZodRecord = ZodRecord;
1616
- var ZodMap = /** @class */ (function (_super) {
1617
- __extends(ZodMap, _super);
1618
- function ZodMap() {
1619
- return _super !== null && _super.apply(this, arguments) || this;
1620
- }
1621
- ZodMap.prototype._parse = function (ctx, data, parsedType) {
1622
- if (parsedType !== parseUtil_1.ZodParsedType.map) {
1623
- ctx.addIssue(data, {
1624
- code: ZodError_1.ZodIssueCode.invalid_type,
1625
- expected: parseUtil_1.ZodParsedType.map,
1626
- received: parsedType,
1627
- });
1628
- return parseUtil_1.INVALID;
1629
- }
1630
- var keyType = this._def.keyType;
1631
- var valueType = this._def.valueType;
1632
- var dataMap = data;
1633
- var parseResult = new Map();
1634
- var tasks = createTasks(ctx);
1635
- var invalid = false;
1636
- var handleParsed = function (parsedKey, parsedValue) {
1637
- if (parseUtil_1.isAsync(parsedKey) || parseUtil_1.isAsync(parsedValue)) {
1638
- tasks === null || tasks === void 0 ? void 0 : tasks.push(PseudoPromise_1.PseudoPromise.all([parsedKey, parsedValue]).promise.then(function (_a) {
1639
- var _b = __read(_a, 2), k = _b[0], v = _b[1];
1640
- return handleParsed(k, v);
1641
- }));
1642
- }
1643
- else if (parseUtil_1.isInvalid(parsedKey) || parseUtil_1.isInvalid(parsedValue)) {
1644
- invalid = true;
1645
- }
1646
- else {
1647
- parseResult.set(parsedKey.value, parsedValue.value);
1648
- }
1649
- };
1650
- __spreadArray([], __read(dataMap.entries())).forEach(function (_a, index) {
1651
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
1652
- var entryCtx = ctx.stepInto(index);
1653
- var parsedKey = keyType._parse(entryCtx.stepInto("key"), key, parseUtil_1.getParsedType(key));
1654
- var parsedValue = valueType._parse(entryCtx.stepInto("value"), value, parseUtil_1.getParsedType(value));
1655
- handleParsed(parsedKey, parsedValue);
1656
- });
1657
- if (tasks !== null && tasks.length > 0) {
1658
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult)); }));
1659
- }
1660
- else {
1661
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parseResult);
1662
- }
1663
- };
1664
- ZodMap.create = function (keyType, valueType) {
1665
- return new ZodMap({
1666
- valueType: valueType,
1667
- keyType: keyType,
1668
- });
1669
- };
1670
- return ZodMap;
1671
- }(ZodType));
1672
- exports.ZodMap = ZodMap;
1673
- var ZodSet = /** @class */ (function (_super) {
1674
- __extends(ZodSet, _super);
1675
- function ZodSet() {
1676
- return _super !== null && _super.apply(this, arguments) || this;
1677
- }
1678
- ZodSet.prototype._parse = function (ctx, data, parsedType) {
1679
- if (parsedType !== parseUtil_1.ZodParsedType.set) {
1680
- ctx.addIssue(data, {
1681
- code: ZodError_1.ZodIssueCode.invalid_type,
1682
- expected: parseUtil_1.ZodParsedType.set,
1683
- received: parsedType,
1684
- });
1685
- return parseUtil_1.INVALID;
1686
- }
1687
- var dataSet = data;
1688
- var valueType = this._def.valueType;
1689
- var parsedSet = new Set();
1690
- var tasks = createTasks(ctx);
1691
- var invalid = false;
1692
- var handleParsed = function (parsedItem) {
1693
- if (parseUtil_1.isOk(parsedItem)) {
1694
- parsedSet.add(parsedItem.value);
1695
- }
1696
- else if (parseUtil_1.isInvalid(parsedItem)) {
1697
- invalid = true;
1698
- }
1699
- else {
1700
- tasks === null || tasks === void 0 ? void 0 : tasks.push(parsedItem.promise.then(function (parsed) { return handleParsed(parsed); }));
1701
- }
1702
- };
1703
- __spreadArray([], __read(dataSet.values())).forEach(function (item, i) {
1704
- return handleParsed(valueType._parse(ctx.stepInto(i), item, parseUtil_1.getParsedType(item)));
1705
- });
1706
- if (tasks !== null && tasks.length > 0) {
1707
- return parseUtil_1.ASYNC(Promise.all(tasks).then(function () { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parsedSet)); }));
1708
- }
1709
- else {
1710
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(parsedSet);
1711
- }
1712
- };
1713
- ZodSet.create = function (valueType) {
1714
- return new ZodSet({
1715
- valueType: valueType,
1716
- });
1717
- };
1718
- return ZodSet;
1719
- }(ZodType));
1720
- exports.ZodSet = ZodSet;
1721
- var ZodFunction = /** @class */ (function (_super) {
1722
- __extends(ZodFunction, _super);
1723
- function ZodFunction() {
1724
- var _this = _super !== null && _super.apply(this, arguments) || this;
1725
- _this.args = function () {
1726
- var items = [];
1727
- for (var _i = 0; _i < arguments.length; _i++) {
1728
- items[_i] = arguments[_i];
1729
- }
1730
- return new ZodFunction(__assign(__assign({}, _this._def), { args: ZodTuple.create(items) }));
1731
- };
1732
- _this.returns = function (returnType) {
1733
- return new ZodFunction(__assign(__assign({}, _this._def), { returns: returnType }));
1734
- };
1735
- _this.implement = function (func) {
1736
- var validatedFunc = _this.parse(func);
1737
- return validatedFunc;
1738
- };
1739
- _this.strictImplement = function (func) {
1740
- var validatedFunc = _this.parse(func);
1741
- return validatedFunc;
1742
- };
1743
- _this.validate = _this.implement;
1744
- return _this;
1745
- }
1746
- ZodFunction.prototype._parse = function (ctx, data, parsedType) {
1747
- var _this = this;
1748
- if (parsedType !== parseUtil_1.ZodParsedType.function) {
1749
- ctx.addIssue(data, {
1750
- code: ZodError_1.ZodIssueCode.invalid_type,
1751
- expected: parseUtil_1.ZodParsedType.function,
1752
- received: parsedType,
1753
- });
1754
- return parseUtil_1.INVALID;
1755
- }
1756
- var handleArgs = function (args, parsedArgs) {
1757
- if (!parsedArgs.success) {
1758
- var issue = parseUtil_1.makeIssue(args, parseUtil_1.pathToArray(ctx.path), ctx.params.errorMap, {
1759
- code: ZodError_1.ZodIssueCode.invalid_arguments,
1760
- argumentsError: parsedArgs.error,
1761
- });
1762
- throw new ZodError_1.ZodError([issue]);
1763
- }
1764
- return parsedArgs.data;
1765
- };
1766
- var handleReturns = function (returns, parsedReturns) {
1767
- if (!parsedReturns.success) {
1768
- var issue = parseUtil_1.makeIssue(returns, parseUtil_1.pathToArray(ctx.path), ctx.params.errorMap, {
1769
- code: ZodError_1.ZodIssueCode.invalid_return_type,
1770
- returnTypeError: parsedReturns.error,
1771
- });
1772
- throw new ZodError_1.ZodError([issue]);
1773
- }
1774
- return parsedReturns.data;
1775
- };
1776
- var params = { errorMap: ctx.params.errorMap };
1777
- var fn = data;
1778
- if (this._def.returns instanceof ZodPromise) {
1779
- return parseUtil_1.OK(function () {
1780
- var args = [];
1781
- for (var _i = 0; _i < arguments.length; _i++) {
1782
- args[_i] = arguments[_i];
1783
- }
1784
- return __awaiter(_this, void 0, void 0, function () {
1785
- var parsedArgs, _a, _b, result, _c, _d;
1786
- return __generator(this, function (_e) {
1787
- switch (_e.label) {
1788
- case 0:
1789
- _a = handleArgs;
1790
- _b = [args];
1791
- return [4 /*yield*/, this._def.args.spa(args, params)];
1792
- case 1:
1793
- parsedArgs = _a.apply(void 0, _b.concat([_e.sent()]));
1794
- return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs)))];
1795
- case 2:
1796
- result = _e.sent();
1797
- _c = handleReturns;
1798
- _d = [result];
1799
- return [4 /*yield*/, this._def.returns.spa(result, params)];
1800
- case 3: return [2 /*return*/, _c.apply(void 0, _d.concat([_e.sent()]))];
1801
- }
1802
- });
1803
- });
1804
- });
1805
- }
1806
- else {
1807
- return parseUtil_1.OK(function () {
1808
- var args = [];
1809
- for (var _i = 0; _i < arguments.length; _i++) {
1810
- args[_i] = arguments[_i];
1811
- }
1812
- var parsedArgs = handleArgs(args, _this._def.args.safeParse(args, params));
1813
- var result = fn.apply(void 0, __spreadArray([], __read(parsedArgs)));
1814
- return handleReturns(result, _this._def.returns.safeParse(result, params));
1815
- });
1816
- }
1817
- };
1818
- ZodFunction.prototype.parameters = function () {
1819
- return this._def.args;
1820
- };
1821
- ZodFunction.prototype.returnType = function () {
1822
- return this._def.returns;
1823
- };
1824
- ZodFunction.create = function (args, returns) {
1825
- return new ZodFunction({
1826
- args: args || ZodTuple.create([]),
1827
- returns: returns || ZodUnknown.create(),
1828
- });
1829
- };
1830
- return ZodFunction;
1831
- }(ZodType));
1832
- exports.ZodFunction = ZodFunction;
1833
- var ZodLazy = /** @class */ (function (_super) {
1834
- __extends(ZodLazy, _super);
1835
- function ZodLazy() {
1836
- return _super !== null && _super.apply(this, arguments) || this;
1837
- }
1838
- Object.defineProperty(ZodLazy.prototype, "schema", {
1839
- get: function () {
1840
- return this._def.getter();
1841
- },
1842
- enumerable: false,
1843
- configurable: true
1844
- });
1845
- ZodLazy.prototype._parse = function (ctx, data, parsedType) {
1846
- var lazySchema = this._def.getter();
1847
- return lazySchema._parse(ctx, data, parsedType);
1848
- };
1849
- ZodLazy.create = function (getter) {
1850
- return new ZodLazy({
1851
- getter: getter,
1852
- });
1853
- };
1854
- return ZodLazy;
1855
- }(ZodType));
1856
- exports.ZodLazy = ZodLazy;
1857
- var ZodLiteral = /** @class */ (function (_super) {
1858
- __extends(ZodLiteral, _super);
1859
- function ZodLiteral() {
1860
- return _super !== null && _super.apply(this, arguments) || this;
1861
- }
1862
- ZodLiteral.prototype._parse = function (ctx, data, _parsedType) {
1863
- if (data !== this._def.value) {
1864
- ctx.addIssue(data, {
1865
- code: ZodError_1.ZodIssueCode.invalid_type,
1866
- expected: this._def.value,
1867
- received: data,
1868
- });
1869
- return parseUtil_1.INVALID;
1870
- }
1871
- return parseUtil_1.OK(data);
1872
- };
1873
- ZodLiteral.create = function (value) {
1874
- return new ZodLiteral({
1875
- value: value,
1876
- });
1877
- };
1878
- return ZodLiteral;
1879
- }(ZodType));
1880
- exports.ZodLiteral = ZodLiteral;
1881
- var ZodEnum = /** @class */ (function (_super) {
1882
- __extends(ZodEnum, _super);
1883
- function ZodEnum() {
1884
- return _super !== null && _super.apply(this, arguments) || this;
1885
- }
1886
- ZodEnum.prototype._parse = function (ctx, data, _parsedType) {
1887
- if (this._def.values.indexOf(data) === -1) {
1888
- ctx.addIssue(data, {
1889
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
1890
- options: this._def.values,
1891
- });
1892
- return parseUtil_1.INVALID;
1893
- }
1894
- return parseUtil_1.OK(data);
1895
- };
1896
- Object.defineProperty(ZodEnum.prototype, "options", {
1897
- get: function () {
1898
- return this._def.values;
1899
- },
1900
- enumerable: false,
1901
- configurable: true
1902
- });
1903
- Object.defineProperty(ZodEnum.prototype, "enum", {
1904
- get: function () {
1905
- var e_12, _a;
1906
- var enumValues = {};
1907
- try {
1908
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
1909
- var val = _c.value;
1910
- enumValues[val] = val;
1911
- }
1912
- }
1913
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
1914
- finally {
1915
- try {
1916
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1917
- }
1918
- finally { if (e_12) throw e_12.error; }
1919
- }
1920
- return enumValues;
1921
- },
1922
- enumerable: false,
1923
- configurable: true
1924
- });
1925
- Object.defineProperty(ZodEnum.prototype, "Values", {
1926
- get: function () {
1927
- var e_13, _a;
1928
- var enumValues = {};
1929
- try {
1930
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
1931
- var val = _c.value;
1932
- enumValues[val] = val;
1933
- }
1934
- }
1935
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
1936
- finally {
1937
- try {
1938
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1939
- }
1940
- finally { if (e_13) throw e_13.error; }
1941
- }
1942
- return enumValues;
1943
- },
1944
- enumerable: false,
1945
- configurable: true
1946
- });
1947
- Object.defineProperty(ZodEnum.prototype, "Enum", {
1948
- get: function () {
1949
- var e_14, _a;
1950
- var enumValues = {};
1951
- try {
1952
- for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
1953
- var val = _c.value;
1954
- enumValues[val] = val;
1955
- }
1956
- }
1957
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
1958
- finally {
1959
- try {
1960
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1961
- }
1962
- finally { if (e_14) throw e_14.error; }
1963
- }
1964
- return enumValues;
1965
- },
1966
- enumerable: false,
1967
- configurable: true
1968
- });
1969
- ZodEnum.create = function (values) {
1970
- return new ZodEnum({
1971
- values: values,
1972
- });
1973
- };
1974
- return ZodEnum;
1975
- }(ZodType));
1976
- exports.ZodEnum = ZodEnum;
1977
- var ZodNativeEnum = /** @class */ (function (_super) {
1978
- __extends(ZodNativeEnum, _super);
1979
- function ZodNativeEnum() {
1980
- return _super !== null && _super.apply(this, arguments) || this;
1981
- }
1982
- ZodNativeEnum.prototype._parse = function (ctx, data, _parsedType) {
1983
- var nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
1984
- if (nativeEnumValues.indexOf(data) === -1) {
1985
- ctx.addIssue(data, {
1986
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
1987
- options: util_1.util.objectValues(nativeEnumValues),
1988
- });
1989
- return parseUtil_1.INVALID;
1990
- }
1991
- return parseUtil_1.OK(data);
1992
- };
1993
- ZodNativeEnum.create = function (values) {
1994
- return new ZodNativeEnum({
1995
- values: values,
1996
- });
1997
- };
1998
- return ZodNativeEnum;
1999
- }(ZodType));
2000
- exports.ZodNativeEnum = ZodNativeEnum;
2001
- var ZodPromise = /** @class */ (function (_super) {
2002
- __extends(ZodPromise, _super);
2003
- function ZodPromise() {
2004
- return _super !== null && _super.apply(this, arguments) || this;
2005
- }
2006
- ZodPromise.prototype._parse = function (ctx, data, parsedType) {
2007
- var _this = this;
2008
- if (parsedType !== parseUtil_1.ZodParsedType.promise && ctx.params.async === false) {
2009
- ctx.addIssue(data, {
2010
- code: ZodError_1.ZodIssueCode.invalid_type,
2011
- expected: parseUtil_1.ZodParsedType.promise,
2012
- received: parsedType,
2013
- });
2014
- return parseUtil_1.INVALID;
2015
- }
2016
- var promisified = parsedType === parseUtil_1.ZodParsedType.promise ? data : Promise.resolve(data);
2017
- return parseUtil_1.OK(promisified.then(function (data) {
2018
- return _this._def.type.parseAsync(data, {
2019
- path: parseUtil_1.pathToArray(ctx.path),
2020
- errorMap: ctx.params.errorMap,
2021
- });
2022
- }));
2023
- };
2024
- ZodPromise.create = function (schema) {
2025
- return new ZodPromise({
2026
- type: schema,
2027
- });
2028
- };
2029
- return ZodPromise;
2030
- }(ZodType));
2031
- exports.ZodPromise = ZodPromise;
2032
- var ZodEffects = /** @class */ (function (_super) {
2033
- __extends(ZodEffects, _super);
2034
- function ZodEffects(def) {
2035
- return _super.call(this, def) || this;
2036
- // if (def.schema instanceof ZodEffects) {
2037
- // throw new Error("ZodEffects cannot be nested.");
2038
- // }
2039
- }
2040
- ZodEffects.prototype.innerType = function () {
2041
- return this._def.schema;
2042
- };
2043
- ZodEffects.prototype._parse = function (ctx, data, parsedType) {
2044
- var isSync = ctx.params.async === false;
2045
- var effects = this._def.effects || [];
2046
- var checkCtx = {
2047
- addIssue: function (arg) {
2048
- ctx.addIssue(data, arg);
2049
- },
2050
- get path() {
2051
- return parseUtil_1.pathToArray(ctx.path);
2052
- },
2053
- };
2054
- var invalid = false;
2055
- var applyEffect = function (acc, effect) {
2056
- switch (effect.type) {
2057
- case "refinement":
2058
- var result = effect.refinement(acc, checkCtx);
2059
- if (result instanceof Promise) {
2060
- if (isSync) {
2061
- throw new Error("You can't use .parse() on a schema containing async refinements. Use .parseAsync instead.");
2062
- }
2063
- else {
2064
- return result.then(function (res) {
2065
- invalid = invalid || !res;
2066
- return acc;
2067
- });
2068
- }
2069
- }
2070
- else {
2071
- invalid = invalid || !result;
2072
- return acc;
2073
- }
2074
- case "transform":
2075
- var transformed = effect.transform(acc);
2076
- if (transformed instanceof Promise && isSync) {
2077
- throw new Error("You can't use .parse() on a schema containing async transformations. Use .parseAsync instead.");
2078
- }
2079
- return transformed;
2080
- default:
2081
- throw new Error("Invalid effect type.");
2082
- }
2083
- };
2084
- if (isSync) {
2085
- var base = this._def.schema._parseSync(ctx, data, parsedType);
2086
- if (parseUtil_1.isOk(base)) {
2087
- var result = effects.reduce(applyEffect, base.value);
2088
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(result);
2089
- }
2090
- else {
2091
- return parseUtil_1.INVALID;
2092
- }
2093
- }
2094
- else {
2095
- var applyAsyncEffects_1 = function (base) {
2096
- var result = effects.reduce(function (acc, eff) {
2097
- return acc instanceof Promise
2098
- ? acc.then(function (val) { return applyEffect(val, eff); })
2099
- : applyEffect(acc, eff);
2100
- }, base);
2101
- if (result instanceof Promise) {
2102
- return parseUtil_1.ASYNC(result.then(function (val) { return (invalid ? parseUtil_1.INVALID : parseUtil_1.OK(val)); }));
2103
- }
2104
- else {
2105
- return invalid ? parseUtil_1.INVALID : parseUtil_1.OK(result);
2106
- }
2107
- };
2108
- var baseResult = this._def.schema._parse(ctx, data, parsedType);
2109
- if (parseUtil_1.isOk(baseResult)) {
2110
- return applyAsyncEffects_1(baseResult.value);
2111
- }
2112
- else if (parseUtil_1.isInvalid(baseResult)) {
2113
- return parseUtil_1.INVALID;
2114
- }
2115
- else {
2116
- return parseUtil_1.ASYNC(baseResult.promise.then(function (base) {
2117
- if (parseUtil_1.isInvalid(base))
2118
- return parseUtil_1.INVALID;
2119
- var result = applyAsyncEffects_1(base.value);
2120
- return parseUtil_1.isAsync(result) ? result.promise : result;
2121
- }));
2122
- }
2123
- }
2124
- };
2125
- ZodEffects.create = function (schema) {
2126
- var newTx = new ZodEffects({
2127
- schema: schema,
2128
- });
2129
- return newTx;
2130
- };
2131
- return ZodEffects;
2132
- }(ZodType));
2133
- exports.ZodEffects = ZodEffects;
2134
- exports.ZodTransformer = ZodEffects;
2135
- var ZodOptional = /** @class */ (function (_super) {
2136
- __extends(ZodOptional, _super);
2137
- function ZodOptional() {
2138
- return _super !== null && _super.apply(this, arguments) || this;
2139
- }
2140
- ZodOptional.prototype._parse = function (ctx, data, parsedType) {
2141
- if (parsedType === parseUtil_1.ZodParsedType.undefined) {
2142
- return parseUtil_1.OK(undefined);
2143
- }
2144
- return this._def.innerType._parse(ctx, data, parsedType);
2145
- };
2146
- ZodOptional.prototype.unwrap = function () {
2147
- return this._def.innerType;
2148
- };
2149
- ZodOptional.create = function (type) {
2150
- return new ZodOptional({
2151
- innerType: type,
2152
- });
2153
- };
2154
- return ZodOptional;
2155
- }(ZodType));
2156
- exports.ZodOptional = ZodOptional;
2157
- var ZodNullable = /** @class */ (function (_super) {
2158
- __extends(ZodNullable, _super);
2159
- function ZodNullable() {
2160
- return _super !== null && _super.apply(this, arguments) || this;
2161
- }
2162
- ZodNullable.prototype._parse = function (ctx, data, parsedType) {
2163
- if (parsedType === parseUtil_1.ZodParsedType.null) {
2164
- return parseUtil_1.OK(null);
2165
- }
2166
- return this._def.innerType._parse(ctx, data, parsedType);
2167
- };
2168
- ZodNullable.prototype.unwrap = function () {
2169
- return this._def.innerType;
2170
- };
2171
- ZodNullable.create = function (type) {
2172
- return new ZodNullable({
2173
- innerType: type,
2174
- });
2175
- };
2176
- return ZodNullable;
2177
- }(ZodType));
2178
- exports.ZodNullable = ZodNullable;
2179
- var ZodDefault = /** @class */ (function (_super) {
2180
- __extends(ZodDefault, _super);
2181
- function ZodDefault() {
2182
- return _super !== null && _super.apply(this, arguments) || this;
2183
- }
2184
- ZodDefault.prototype._parse = function (ctx, data, parsedType) {
2185
- if (parsedType === parseUtil_1.ZodParsedType.undefined) {
2186
- data = this._def.defaultValue();
2187
- }
2188
- return this._def.innerType._parse(ctx, data, parseUtil_1.getParsedType(data));
2189
- };
2190
- ZodDefault.prototype.removeDefault = function () {
2191
- return this._def.innerType;
2192
- };
2193
- ZodDefault.create = function (type) {
2194
- return new ZodOptional({
2195
- innerType: type,
2196
- });
2197
- };
2198
- return ZodDefault;
2199
- }(ZodType));
2200
- exports.ZodDefault = ZodDefault;
2201
- var custom = function (check, params) {
2202
- if (check)
2203
- return ZodAny.create().refine(check, params);
2204
- return ZodAny.create();
2205
- };
2206
- exports.custom = custom;
2207
- exports.late = {
2208
- object: ZodObject.lazycreate,
2209
- };
2210
- var instanceOfType = function (cls, params) {
2211
- if (params === void 0) { params = {
2212
- message: "Input not instance of " + cls.name,
2213
- }; }
2214
- return exports.custom(function (data) { return data instanceof cls; }, params);
2215
- };
2216
- exports.instanceof = instanceOfType;
2217
- var stringType = ZodString.create;
2218
- exports.string = stringType;
2219
- var numberType = ZodNumber.create;
2220
- exports.number = numberType;
2221
- var bigIntType = ZodBigInt.create;
2222
- exports.bigint = bigIntType;
2223
- var booleanType = ZodBoolean.create;
2224
- exports.boolean = booleanType;
2225
- var dateType = ZodDate.create;
2226
- exports.date = dateType;
2227
- var undefinedType = ZodUndefined.create;
2228
- exports.undefined = undefinedType;
2229
- var nullType = ZodNull.create;
2230
- exports.null = nullType;
2231
- var anyType = ZodAny.create;
2232
- exports.any = anyType;
2233
- var unknownType = ZodUnknown.create;
2234
- exports.unknown = unknownType;
2235
- var neverType = ZodNever.create;
2236
- exports.never = neverType;
2237
- var voidType = ZodVoid.create;
2238
- exports.void = voidType;
2239
- var arrayType = ZodArray.create;
2240
- exports.array = arrayType;
2241
- var objectType = ZodObject.create;
2242
- exports.object = objectType;
2243
- var strictObjectType = ZodObject.strictCreate;
2244
- exports.strictObject = strictObjectType;
2245
- var unionType = ZodUnion.create;
2246
- exports.union = unionType;
2247
- var intersectionType = ZodIntersection.create;
2248
- exports.intersection = intersectionType;
2249
- var tupleType = ZodTuple.create;
2250
- exports.tuple = tupleType;
2251
- var recordType = ZodRecord.create;
2252
- exports.record = recordType;
2253
- var mapType = ZodMap.create;
2254
- exports.map = mapType;
2255
- var setType = ZodSet.create;
2256
- exports.set = setType;
2257
- var functionType = ZodFunction.create;
2258
- exports.function = functionType;
2259
- var lazyType = ZodLazy.create;
2260
- exports.lazy = lazyType;
2261
- var literalType = ZodLiteral.create;
2262
- exports.literal = literalType;
2263
- var enumType = ZodEnum.create;
2264
- exports.enum = enumType;
2265
- var nativeEnumType = ZodNativeEnum.create;
2266
- exports.nativeEnum = nativeEnumType;
2267
- var promiseType = ZodPromise.create;
2268
- exports.promise = promiseType;
2269
- var effectsType = ZodEffects.create;
2270
- exports.effect = effectsType;
2271
- exports.transformer = effectsType;
2272
- var optionalType = ZodOptional.create;
2273
- exports.optional = optionalType;
2274
- var nullableType = ZodNullable.create;
2275
- exports.nullable = nullableType;
2276
- var ostring = function () { return stringType().optional(); };
2277
- exports.ostring = ostring;
2278
- var onumber = function () { return numberType().optional(); };
2279
- exports.onumber = onumber;
2280
- var oboolean = function () { return booleanType().optional(); };
2281
- exports.oboolean = oboolean;
2282
- //# sourceMappingURL=types.js.map