zod 3.13.2 → 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/README.md +35 -29
- package/lib/ZodError.js +110 -205
- package/lib/benchmarks/discriminatedUnion.js +25 -25
- package/lib/benchmarks/index.js +13 -53
- package/lib/benchmarks/object.js +23 -23
- package/lib/benchmarks/realworld.d.ts +5 -0
- package/lib/benchmarks/realworld.js +56 -0
- package/lib/benchmarks/string.js +16 -16
- package/lib/benchmarks/union.js +25 -25
- package/lib/external.js +5 -1
- package/lib/helpers/errorUtil.js +2 -6
- package/lib/helpers/parseUtil.d.ts +1 -2
- package/lib/helpers/parseUtil.js +82 -242
- package/lib/helpers/util.js +20 -66
- package/lib/index.js +6 -2
- package/lib/index.mjs +1530 -2097
- package/lib/types.d.ts +4 -2
- package/lib/types.js +1319 -1704
- package/package.json +3 -3
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
116
|
-
return { success: false, 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
|
-
|
|
24
|
+
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
123
25
|
if (errorMap && (invalid_type_error || required_error)) {
|
|
124
|
-
throw new Error(
|
|
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
|
|
128
|
-
|
|
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
|
|
39
|
+
return { errorMap: customMap, description };
|
|
138
40
|
}
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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:
|
|
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
|
-
|
|
180
|
-
|
|
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
|
-
|
|
187
|
-
|
|
90
|
+
}
|
|
91
|
+
_parseAsync(input) {
|
|
92
|
+
const result = this._parse(input);
|
|
188
93
|
return Promise.resolve(result);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
100
|
+
}
|
|
101
|
+
safeParse(data, params) {
|
|
197
102
|
var _a;
|
|
198
|
-
|
|
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
|
|
110
|
+
data,
|
|
207
111
|
parsedType: (0, parseUtil_1.getParsedType)(data),
|
|
208
112
|
};
|
|
209
|
-
|
|
113
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
210
114
|
return handleResult(ctx, result);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
|
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(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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(
|
|
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
|
-
|
|
293
|
-
return this._refinement(
|
|
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
|
-
|
|
189
|
+
}
|
|
190
|
+
_refinement(refinement) {
|
|
306
191
|
return new ZodEffects({
|
|
307
192
|
schema: this,
|
|
308
193
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
309
|
-
effect: { type: "refinement", refinement
|
|
194
|
+
effect: { type: "refinement", refinement },
|
|
310
195
|
});
|
|
311
|
-
}
|
|
312
|
-
|
|
196
|
+
}
|
|
197
|
+
optional() {
|
|
313
198
|
return ZodOptional.create(this);
|
|
314
|
-
}
|
|
315
|
-
|
|
199
|
+
}
|
|
200
|
+
nullable() {
|
|
316
201
|
return ZodNullable.create(this);
|
|
317
|
-
}
|
|
318
|
-
|
|
202
|
+
}
|
|
203
|
+
nullish() {
|
|
319
204
|
return this.optional().nullable();
|
|
320
|
-
}
|
|
321
|
-
|
|
205
|
+
}
|
|
206
|
+
array() {
|
|
322
207
|
return ZodArray.create(this);
|
|
323
|
-
}
|
|
324
|
-
|
|
208
|
+
}
|
|
209
|
+
promise() {
|
|
325
210
|
return ZodPromise.create(this);
|
|
326
|
-
}
|
|
327
|
-
|
|
211
|
+
}
|
|
212
|
+
or(option) {
|
|
328
213
|
return ZodUnion.create([this, option]);
|
|
329
|
-
}
|
|
330
|
-
|
|
214
|
+
}
|
|
215
|
+
and(incoming) {
|
|
331
216
|
return ZodIntersection.create(this, incoming);
|
|
332
|
-
}
|
|
333
|
-
|
|
217
|
+
}
|
|
218
|
+
transform(transform) {
|
|
334
219
|
return new ZodEffects({
|
|
335
220
|
schema: this,
|
|
336
221
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
337
|
-
effect: { type: "transform", transform
|
|
222
|
+
effect: { type: "transform", transform },
|
|
338
223
|
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
return new This(
|
|
351
|
-
|
|
352
|
-
|
|
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
|
-
|
|
242
|
+
}
|
|
243
|
+
isNullable() {
|
|
356
244
|
return this.safeParse(null).success;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
}());
|
|
245
|
+
}
|
|
246
|
+
}
|
|
360
247
|
exports.ZodType = ZodType;
|
|
361
248
|
exports.Schema = ZodType;
|
|
362
249
|
exports.ZodSchema = ZodType;
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
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
|
-
|
|
387
|
-
|
|
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
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
-
|
|
493
|
-
return new ZodString(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
return this._addCheck(
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return this._addCheck(
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
return this._addCheck(
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
return this._addCheck(
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return this._addCheck(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
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
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
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
|
-
|
|
667
|
-
|
|
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
|
-
|
|
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
|
-
|
|
534
|
+
}
|
|
535
|
+
gte(value, message) {
|
|
681
536
|
return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
|
|
682
|
-
}
|
|
683
|
-
|
|
537
|
+
}
|
|
538
|
+
gt(value, message) {
|
|
684
539
|
return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
|
|
685
|
-
}
|
|
686
|
-
|
|
540
|
+
}
|
|
541
|
+
lte(value, message) {
|
|
687
542
|
return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
|
|
688
|
-
}
|
|
689
|
-
|
|
543
|
+
}
|
|
544
|
+
lt(value, message) {
|
|
690
545
|
return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
return new ZodNumber(
|
|
546
|
+
}
|
|
547
|
+
setLimit(kind, value, inclusive, message) {
|
|
548
|
+
return new ZodNumber({
|
|
549
|
+
...this._def,
|
|
550
|
+
checks: [
|
|
551
|
+
...this._def.checks,
|
|
694
552
|
{
|
|
695
|
-
kind
|
|
696
|
-
value
|
|
697
|
-
inclusive
|
|
553
|
+
kind,
|
|
554
|
+
value,
|
|
555
|
+
inclusive,
|
|
698
556
|
message: errorUtil_1.errorUtil.toString(message),
|
|
699
557
|
},
|
|
700
|
-
],
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
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
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
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
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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;
|
|
631
|
+
}
|
|
632
|
+
get isInt() {
|
|
633
|
+
return !!this._def.checks.find((ch) => ch.kind === "int");
|
|
817
634
|
}
|
|
818
|
-
|
|
819
|
-
|
|
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
|
-
|
|
842
|
-
|
|
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
|
-
|
|
865
|
-
|
|
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
|
-
|
|
897
|
-
|
|
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
|
-
|
|
920
|
-
|
|
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
|
-
|
|
932
|
-
return new ZodNull(__assign({ typeName: ZodFirstPartyTypeKind.ZodNull }, processCreateParams(params)));
|
|
933
|
-
};
|
|
934
|
-
return ZodNull;
|
|
935
|
-
}(ZodType));
|
|
749
|
+
}
|
|
750
|
+
}
|
|
936
751
|
exports.ZodNull = ZodNull;
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
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
|
-
|
|
943
|
-
return _this;
|
|
762
|
+
this._any = true;
|
|
944
763
|
}
|
|
945
|
-
|
|
946
|
-
|
|
764
|
+
_parse(input) {
|
|
765
|
+
const { ctx } = this._processInputParams(input);
|
|
947
766
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
return new ZodAny(__assign({ typeName: ZodFirstPartyTypeKind.ZodAny }, processCreateParams(params)));
|
|
951
|
-
};
|
|
952
|
-
return ZodAny;
|
|
953
|
-
}(ZodType));
|
|
767
|
+
}
|
|
768
|
+
}
|
|
954
769
|
exports.ZodAny = ZodAny;
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
|
|
961
|
-
return _this;
|
|
780
|
+
this._unknown = true;
|
|
962
781
|
}
|
|
963
|
-
|
|
964
|
-
|
|
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
|
-
|
|
979
|
-
|
|
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
|
-
|
|
999
|
-
|
|
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
|
-
|
|
1011
|
-
return new ZodVoid(__assign({ typeName: ZodFirstPartyTypeKind.ZodVoid }, processCreateParams(params)));
|
|
1012
|
-
};
|
|
1013
|
-
return ZodVoid;
|
|
1014
|
-
}(ZodType));
|
|
824
|
+
}
|
|
825
|
+
}
|
|
1015
826
|
exports.ZodVoid = ZodVoid;
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
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(
|
|
870
|
+
return Promise.all(ctx.data.map((item, i) => {
|
|
1058
871
|
return def.type._parseAsync({
|
|
1059
872
|
parent: ctx,
|
|
1060
|
-
path:
|
|
873
|
+
path: [...ctx.path, i],
|
|
1061
874
|
data: item,
|
|
1062
875
|
});
|
|
1063
|
-
})).then(
|
|
876
|
+
})).then((result) => {
|
|
1064
877
|
return parseUtil_1.ParseStatus.mergeArray(status, result);
|
|
1065
878
|
});
|
|
1066
879
|
}
|
|
1067
|
-
|
|
880
|
+
const result = ctx.data.map((item, i) => {
|
|
1068
881
|
return def.type._parseSync({
|
|
1069
882
|
parent: ctx,
|
|
1070
|
-
path:
|
|
883
|
+
path: [...ctx.path, i],
|
|
1071
884
|
data: item,
|
|
1072
885
|
});
|
|
1073
886
|
});
|
|
1074
887
|
return parseUtil_1.ParseStatus.mergeArray(status, result);
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
-
|
|
906
|
+
}
|
|
907
|
+
nonempty(message) {
|
|
1093
908
|
return this.min(1, message);
|
|
1094
|
-
}
|
|
1095
|
-
|
|
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,21 +927,33 @@ exports.ZodArray = ZodArray;
|
|
|
1107
927
|
/////////////////////////////////////////
|
|
1108
928
|
var objectUtil;
|
|
1109
929
|
(function (objectUtil) {
|
|
1110
|
-
objectUtil.mergeShapes =
|
|
1111
|
-
return
|
|
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
|
-
|
|
1115
|
-
return new ZodObject(
|
|
1116
|
-
|
|
937
|
+
const AugmentFactory = (def) => (augmentation) => {
|
|
938
|
+
return new ZodObject({
|
|
939
|
+
...def,
|
|
940
|
+
shape: () => ({
|
|
941
|
+
...def.shape(),
|
|
942
|
+
...augmentation,
|
|
943
|
+
}),
|
|
944
|
+
});
|
|
945
|
+
};
|
|
1117
946
|
function deepPartialify(schema) {
|
|
1118
947
|
if (schema instanceof ZodObject) {
|
|
1119
|
-
|
|
1120
|
-
for (
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
return new ZodObject(
|
|
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
|
+
});
|
|
1125
957
|
}
|
|
1126
958
|
else if (schema instanceof ZodArray) {
|
|
1127
959
|
return ZodArray.create(deepPartialify(schema.element));
|
|
@@ -1133,37 +965,33 @@ function deepPartialify(schema) {
|
|
|
1133
965
|
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1134
966
|
}
|
|
1135
967
|
else if (schema instanceof ZodTuple) {
|
|
1136
|
-
return ZodTuple.create(schema.items.map(
|
|
968
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
1137
969
|
}
|
|
1138
970
|
else {
|
|
1139
971
|
return schema;
|
|
1140
972
|
}
|
|
1141
973
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
_this._cached = null;
|
|
974
|
+
class ZodObject extends ZodType {
|
|
975
|
+
constructor() {
|
|
976
|
+
super(...arguments);
|
|
977
|
+
this._cached = null;
|
|
1147
978
|
/**
|
|
1148
979
|
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
1149
980
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1150
981
|
*/
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
return _this;
|
|
982
|
+
this.nonstrict = this.passthrough;
|
|
983
|
+
this.augment = AugmentFactory(this._def);
|
|
984
|
+
this.extend = AugmentFactory(this._def);
|
|
1155
985
|
}
|
|
1156
|
-
|
|
986
|
+
_getCached() {
|
|
1157
987
|
if (this._cached !== null)
|
|
1158
988
|
return this._cached;
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
return (this._cached = { shape
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
var _this = this;
|
|
1166
|
-
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);
|
|
1167
995
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1168
996
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1169
997
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1172,51 +1000,31 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1172
1000
|
});
|
|
1173
1001
|
return parseUtil_1.INVALID;
|
|
1174
1002
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
alwaysSet: key in ctx.data,
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1196
|
-
finally {
|
|
1197
|
-
try {
|
|
1198
|
-
if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
|
|
1199
|
-
}
|
|
1200
|
-
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
|
+
});
|
|
1201
1019
|
}
|
|
1202
1020
|
if (this._def.catchall instanceof ZodNever) {
|
|
1203
|
-
|
|
1021
|
+
const unknownKeys = this._def.unknownKeys;
|
|
1204
1022
|
if (unknownKeys === "passthrough") {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
value: { status: "valid", value: ctx.data[key] },
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1215
|
-
finally {
|
|
1216
|
-
try {
|
|
1217
|
-
if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
|
|
1218
|
-
}
|
|
1219
|
-
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
|
+
});
|
|
1220
1028
|
}
|
|
1221
1029
|
}
|
|
1222
1030
|
else if (unknownKeys === "strict") {
|
|
@@ -1231,323 +1039,298 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1231
1039
|
else if (unknownKeys === "strip") {
|
|
1232
1040
|
}
|
|
1233
1041
|
else {
|
|
1234
|
-
throw new Error(
|
|
1042
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
1235
1043
|
}
|
|
1236
1044
|
}
|
|
1237
1045
|
else {
|
|
1238
1046
|
// run catchall validation
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
alwaysSet: key in ctx.data,
|
|
1249
|
-
});
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1253
|
-
finally {
|
|
1254
|
-
try {
|
|
1255
|
-
if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
|
|
1256
|
-
}
|
|
1257
|
-
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
|
+
});
|
|
1258
1056
|
}
|
|
1259
1057
|
}
|
|
1260
1058
|
if (ctx.async) {
|
|
1261
1059
|
return Promise.resolve()
|
|
1262
|
-
.then(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
1276
|
-
pair = pairs_1_1.value;
|
|
1277
|
-
return [4 /*yield*/, pair.key];
|
|
1278
|
-
case 3:
|
|
1279
|
-
key = _e.sent();
|
|
1280
|
-
_b = (_a = syncPairs).push;
|
|
1281
|
-
_d = {
|
|
1282
|
-
key: key
|
|
1283
|
-
};
|
|
1284
|
-
return [4 /*yield*/, pair.value];
|
|
1285
|
-
case 4:
|
|
1286
|
-
_b.apply(_a, [(_d.value = _e.sent(),
|
|
1287
|
-
_d.alwaysSet = pair.alwaysSet,
|
|
1288
|
-
_d)]);
|
|
1289
|
-
_e.label = 5;
|
|
1290
|
-
case 5:
|
|
1291
|
-
pairs_1_1 = pairs_1.next();
|
|
1292
|
-
return [3 /*break*/, 2];
|
|
1293
|
-
case 6: return [3 /*break*/, 9];
|
|
1294
|
-
case 7:
|
|
1295
|
-
e_8_1 = _e.sent();
|
|
1296
|
-
e_8 = { error: e_8_1 };
|
|
1297
|
-
return [3 /*break*/, 9];
|
|
1298
|
-
case 8:
|
|
1299
|
-
try {
|
|
1300
|
-
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
1301
|
-
}
|
|
1302
|
-
finally { if (e_8) throw e_8.error; }
|
|
1303
|
-
return [7 /*endfinally*/];
|
|
1304
|
-
case 9: return [2 /*return*/, syncPairs];
|
|
1305
|
-
}
|
|
1306
|
-
});
|
|
1307
|
-
}); })
|
|
1308
|
-
.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) => {
|
|
1309
1073
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1310
1074
|
});
|
|
1311
1075
|
}
|
|
1312
1076
|
else {
|
|
1313
1077
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
1314
1078
|
}
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
enumerable: false,
|
|
1321
|
-
configurable: true
|
|
1322
|
-
});
|
|
1323
|
-
ZodObject.prototype.strict = function (message) {
|
|
1324
|
-
var _this = this;
|
|
1079
|
+
}
|
|
1080
|
+
get shape() {
|
|
1081
|
+
return this._def.shape();
|
|
1082
|
+
}
|
|
1083
|
+
strict(message) {
|
|
1325
1084
|
errorUtil_1.errorUtil.errToObj;
|
|
1326
|
-
return new ZodObject(
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
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
|
+
};
|
|
1332
1097
|
return {
|
|
1333
|
-
message:
|
|
1098
|
+
message: defaultError,
|
|
1334
1099
|
};
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
}
|
|
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
|
+
}
|
|
1352
1120
|
/**
|
|
1353
1121
|
* Prior to zod@1.0.12 there was a bug in the
|
|
1354
1122
|
* inferred type of merged objects. Please
|
|
1355
1123
|
* upgrade if you are experiencing issues.
|
|
1356
1124
|
*/
|
|
1357
|
-
|
|
1358
|
-
var _this = this;
|
|
1125
|
+
merge(merging) {
|
|
1359
1126
|
// const mergedShape = objectUtil.mergeShapes(
|
|
1360
1127
|
// this._def.shape(),
|
|
1361
1128
|
// merging._def.shape()
|
|
1362
1129
|
// );
|
|
1363
|
-
|
|
1130
|
+
const merged = new ZodObject({
|
|
1364
1131
|
unknownKeys: merging._def.unknownKeys,
|
|
1365
1132
|
catchall: merging._def.catchall,
|
|
1366
|
-
shape:
|
|
1367
|
-
return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
|
|
1368
|
-
},
|
|
1133
|
+
shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1369
1134
|
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1370
1135
|
});
|
|
1371
1136
|
return merged;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
return new ZodObject(
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
var _this = this;
|
|
1378
|
-
var shape = {};
|
|
1379
|
-
util_1.util.objectKeys(mask).map(function (key) {
|
|
1380
|
-
shape[key] = _this.shape[key];
|
|
1137
|
+
}
|
|
1138
|
+
catchall(index) {
|
|
1139
|
+
return new ZodObject({
|
|
1140
|
+
...this._def,
|
|
1141
|
+
catchall: index,
|
|
1381
1142
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
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) => {
|
|
1388
1157
|
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
|
1389
|
-
shape[key] =
|
|
1158
|
+
shape[key] = this.shape[key];
|
|
1390
1159
|
}
|
|
1391
1160
|
});
|
|
1392
|
-
return new ZodObject(
|
|
1393
|
-
|
|
1394
|
-
|
|
1161
|
+
return new ZodObject({
|
|
1162
|
+
...this._def,
|
|
1163
|
+
shape: () => shape,
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
deepPartial() {
|
|
1395
1167
|
return deepPartialify(this);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
var newShape = {};
|
|
1168
|
+
}
|
|
1169
|
+
partial(mask) {
|
|
1170
|
+
const newShape = {};
|
|
1400
1171
|
if (mask) {
|
|
1401
|
-
util_1.util.objectKeys(this.shape).map(
|
|
1172
|
+
util_1.util.objectKeys(this.shape).map((key) => {
|
|
1402
1173
|
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
|
1403
|
-
newShape[key] =
|
|
1174
|
+
newShape[key] = this.shape[key];
|
|
1404
1175
|
}
|
|
1405
1176
|
else {
|
|
1406
|
-
newShape[key] =
|
|
1177
|
+
newShape[key] = this.shape[key].optional();
|
|
1407
1178
|
}
|
|
1408
1179
|
});
|
|
1409
|
-
return new ZodObject(
|
|
1180
|
+
return new ZodObject({
|
|
1181
|
+
...this._def,
|
|
1182
|
+
shape: () => newShape,
|
|
1183
|
+
});
|
|
1410
1184
|
}
|
|
1411
1185
|
else {
|
|
1412
|
-
for (
|
|
1413
|
-
|
|
1186
|
+
for (const key in this.shape) {
|
|
1187
|
+
const fieldSchema = this.shape[key];
|
|
1414
1188
|
newShape[key] = fieldSchema.optional();
|
|
1415
1189
|
}
|
|
1416
1190
|
}
|
|
1417
|
-
return new ZodObject(
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
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;
|
|
1424
1201
|
while (newField instanceof ZodOptional) {
|
|
1425
1202
|
newField = newField._def.innerType;
|
|
1426
1203
|
}
|
|
1427
1204
|
newShape[key] = newField;
|
|
1428
1205
|
}
|
|
1429
|
-
return new ZodObject(
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
1436
|
-
};
|
|
1437
|
-
ZodObject.lazycreate = function (shape, params) {
|
|
1438
|
-
return new ZodObject(__assign({ shape: shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
1439
|
-
};
|
|
1440
|
-
return ZodObject;
|
|
1441
|
-
}(ZodType));
|
|
1206
|
+
return new ZodObject({
|
|
1207
|
+
...this._def,
|
|
1208
|
+
shape: () => newShape,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1442
1212
|
exports.ZodObject = ZodObject;
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
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;
|
|
1478
1249
|
}
|
|
1479
1250
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
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;
|
|
1484
1256
|
}
|
|
1485
|
-
finally { if (e_10) throw e_10.error; }
|
|
1486
1257
|
}
|
|
1487
1258
|
// return invalid
|
|
1488
|
-
|
|
1259
|
+
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.issues));
|
|
1489
1260
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1490
1261
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
|
1491
|
-
unionErrors
|
|
1262
|
+
unionErrors,
|
|
1492
1263
|
});
|
|
1493
1264
|
return parseUtil_1.INVALID;
|
|
1494
1265
|
}
|
|
1495
1266
|
if (ctx.async) {
|
|
1496
|
-
return Promise.all(options.map(
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
1503
|
-
_a = {};
|
|
1504
|
-
return [4 /*yield*/, option._parseAsync({
|
|
1505
|
-
data: ctx.data,
|
|
1506
|
-
path: ctx.path,
|
|
1507
|
-
parent: childCtx,
|
|
1508
|
-
})];
|
|
1509
|
-
case 1: return [2 /*return*/, (_a.result = _b.sent(),
|
|
1510
|
-
_a.ctx = childCtx,
|
|
1511
|
-
_a)];
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
}); })).then(handleResults);
|
|
1515
|
-
}
|
|
1516
|
-
else {
|
|
1517
|
-
var optionResults = options.map(function (option) {
|
|
1518
|
-
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
|
+
};
|
|
1519
1273
|
return {
|
|
1520
|
-
result: option.
|
|
1274
|
+
result: await option._parseAsync({
|
|
1521
1275
|
data: ctx.data,
|
|
1522
1276
|
path: ctx.path,
|
|
1523
1277
|
parent: childCtx,
|
|
1524
1278
|
}),
|
|
1525
1279
|
ctx: childCtx,
|
|
1526
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,
|
|
1527
1315
|
});
|
|
1528
|
-
return
|
|
1316
|
+
return parseUtil_1.INVALID;
|
|
1529
1317
|
}
|
|
1530
|
-
};
|
|
1531
|
-
Object.defineProperty(ZodUnion.prototype, "options", {
|
|
1532
|
-
get: function () {
|
|
1533
|
-
return this._def.options;
|
|
1534
|
-
},
|
|
1535
|
-
enumerable: false,
|
|
1536
|
-
configurable: true
|
|
1537
|
-
});
|
|
1538
|
-
ZodUnion.create = function (types, params) {
|
|
1539
|
-
return new ZodUnion(__assign({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion }, processCreateParams(params)));
|
|
1540
|
-
};
|
|
1541
|
-
return ZodUnion;
|
|
1542
|
-
}(ZodType));
|
|
1543
|
-
exports.ZodUnion = ZodUnion;
|
|
1544
|
-
var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
1545
|
-
__extends(ZodDiscriminatedUnion, _super);
|
|
1546
|
-
function ZodDiscriminatedUnion() {
|
|
1547
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1548
1318
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
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);
|
|
1551
1334
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1552
1335
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1553
1336
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1556,9 +1339,9 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1556
1339
|
});
|
|
1557
1340
|
return parseUtil_1.INVALID;
|
|
1558
1341
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1342
|
+
const discriminator = this.discriminator;
|
|
1343
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
1344
|
+
const option = this.options.get(discriminatorValue);
|
|
1562
1345
|
if (!option) {
|
|
1563
1346
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1564
1347
|
code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
|
|
@@ -1581,28 +1364,16 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1581
1364
|
parent: ctx,
|
|
1582
1365
|
});
|
|
1583
1366
|
}
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
return Array.from(this.options.keys());
|
|
1595
|
-
},
|
|
1596
|
-
enumerable: false,
|
|
1597
|
-
configurable: true
|
|
1598
|
-
});
|
|
1599
|
-
Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
|
|
1600
|
-
get: function () {
|
|
1601
|
-
return this._def.options;
|
|
1602
|
-
},
|
|
1603
|
-
enumerable: false,
|
|
1604
|
-
configurable: true
|
|
1605
|
-
});
|
|
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
|
+
}
|
|
1606
1377
|
/**
|
|
1607
1378
|
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
1608
1379
|
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
@@ -1611,12 +1382,12 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1611
1382
|
* @param types an array of object schemas
|
|
1612
1383
|
* @param params
|
|
1613
1384
|
*/
|
|
1614
|
-
|
|
1385
|
+
static create(discriminator, types, params) {
|
|
1615
1386
|
// Get all the valid discriminator values
|
|
1616
|
-
|
|
1387
|
+
const options = new Map();
|
|
1617
1388
|
try {
|
|
1618
|
-
types.forEach(
|
|
1619
|
-
|
|
1389
|
+
types.forEach((type) => {
|
|
1390
|
+
const discriminatorValue = type.shape[discriminator].value;
|
|
1620
1391
|
options.set(discriminatorValue, type);
|
|
1621
1392
|
});
|
|
1622
1393
|
}
|
|
@@ -1627,40 +1398,33 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1627
1398
|
if (options.size !== types.length) {
|
|
1628
1399
|
throw new Error("Some of the discriminator values are not unique");
|
|
1629
1400
|
}
|
|
1630
|
-
return new ZodDiscriminatedUnion(
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1401
|
+
return new ZodDiscriminatedUnion({
|
|
1402
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
1403
|
+
discriminator,
|
|
1404
|
+
options,
|
|
1405
|
+
...processCreateParams(params),
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1634
1409
|
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
|
1635
1410
|
function mergeValues(a, b) {
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
var bType = (0, parseUtil_1.getParsedType)(b);
|
|
1411
|
+
const aType = (0, parseUtil_1.getParsedType)(a);
|
|
1412
|
+
const bType = (0, parseUtil_1.getParsedType)(b);
|
|
1639
1413
|
if (a === b) {
|
|
1640
1414
|
return { valid: true, data: a };
|
|
1641
1415
|
}
|
|
1642
1416
|
else if (aType === parseUtil_1.ZodParsedType.object && bType === parseUtil_1.ZodParsedType.object) {
|
|
1643
|
-
|
|
1644
|
-
|
|
1417
|
+
const bKeys = util_1.util.objectKeys(b);
|
|
1418
|
+
const sharedKeys = util_1.util
|
|
1645
1419
|
.objectKeys(a)
|
|
1646
|
-
.filter(
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (!sharedValue.valid) {
|
|
1653
|
-
return { valid: false };
|
|
1654
|
-
}
|
|
1655
|
-
newObj[key] = sharedValue.data;
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1659
|
-
finally {
|
|
1660
|
-
try {
|
|
1661
|
-
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 };
|
|
1662
1426
|
}
|
|
1663
|
-
|
|
1427
|
+
newObj[key] = sharedValue.data;
|
|
1664
1428
|
}
|
|
1665
1429
|
return { valid: true, data: newObj };
|
|
1666
1430
|
}
|
|
@@ -1668,11 +1432,11 @@ function mergeValues(a, b) {
|
|
|
1668
1432
|
if (a.length !== b.length) {
|
|
1669
1433
|
return { valid: false };
|
|
1670
1434
|
}
|
|
1671
|
-
|
|
1672
|
-
for (
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
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);
|
|
1676
1440
|
if (!sharedValue.valid) {
|
|
1677
1441
|
return { valid: false };
|
|
1678
1442
|
}
|
|
@@ -1689,18 +1453,14 @@ function mergeValues(a, b) {
|
|
|
1689
1453
|
return { valid: false };
|
|
1690
1454
|
}
|
|
1691
1455
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
}
|
|
1697
|
-
ZodIntersection.prototype._parse = function (input) {
|
|
1698
|
-
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1699
|
-
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) => {
|
|
1700
1460
|
if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
|
|
1701
1461
|
return parseUtil_1.INVALID;
|
|
1702
1462
|
}
|
|
1703
|
-
|
|
1463
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
1704
1464
|
if (!merged.valid) {
|
|
1705
1465
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1706
1466
|
code: ZodError_1.ZodIssueCode.invalid_intersection_types,
|
|
@@ -1724,10 +1484,7 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
1724
1484
|
path: ctx.path,
|
|
1725
1485
|
parent: ctx,
|
|
1726
1486
|
}),
|
|
1727
|
-
]).then(
|
|
1728
|
-
var _b = __read(_a, 2), left = _b[0], right = _b[1];
|
|
1729
|
-
return handleParsed(left, right);
|
|
1730
|
-
});
|
|
1487
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
1731
1488
|
}
|
|
1732
1489
|
else {
|
|
1733
1490
|
return handleParsed(this._def.left._parseSync({
|
|
@@ -1740,21 +1497,20 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
1740
1497
|
parent: ctx,
|
|
1741
1498
|
}));
|
|
1742
1499
|
}
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
return new ZodIntersection(__assign({ left: left, right: right, typeName: ZodFirstPartyTypeKind.ZodIntersection }, processCreateParams(params)));
|
|
1746
|
-
};
|
|
1747
|
-
return ZodIntersection;
|
|
1748
|
-
}(ZodType));
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1749
1502
|
exports.ZodIntersection = ZodIntersection;
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
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);
|
|
1758
1514
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.array) {
|
|
1759
1515
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1760
1516
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1772,7 +1528,7 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
1772
1528
|
});
|
|
1773
1529
|
return parseUtil_1.INVALID;
|
|
1774
1530
|
}
|
|
1775
|
-
|
|
1531
|
+
const rest = this._def.rest;
|
|
1776
1532
|
if (!rest && ctx.data.length > this._def.items.length) {
|
|
1777
1533
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1778
1534
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
@@ -1782,64 +1538,55 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
1782
1538
|
});
|
|
1783
1539
|
status.dirty();
|
|
1784
1540
|
}
|
|
1785
|
-
|
|
1786
|
-
.map(
|
|
1787
|
-
|
|
1541
|
+
const items = ctx.data
|
|
1542
|
+
.map((item, itemIndex) => {
|
|
1543
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
1788
1544
|
if (!schema)
|
|
1789
1545
|
return null;
|
|
1790
1546
|
return schema._parse({
|
|
1791
1547
|
data: item,
|
|
1792
|
-
path:
|
|
1548
|
+
path: [...ctx.path, itemIndex],
|
|
1793
1549
|
parent: ctx,
|
|
1794
1550
|
});
|
|
1795
1551
|
})
|
|
1796
|
-
.filter(
|
|
1552
|
+
.filter((x) => !!x); // filter nulls
|
|
1797
1553
|
if (ctx.async) {
|
|
1798
|
-
return Promise.all(items).then(
|
|
1554
|
+
return Promise.all(items).then((results) => {
|
|
1799
1555
|
return parseUtil_1.ParseStatus.mergeArray(status, results);
|
|
1800
1556
|
});
|
|
1801
1557
|
}
|
|
1802
1558
|
else {
|
|
1803
1559
|
return parseUtil_1.ParseStatus.mergeArray(status, items);
|
|
1804
1560
|
}
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
ZodTuple.create = function (schemas, params) {
|
|
1817
|
-
return new ZodTuple(__assign({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null }, processCreateParams(params)));
|
|
1818
|
-
};
|
|
1819
|
-
return ZodTuple;
|
|
1820
|
-
}(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
|
+
}
|
|
1821
1572
|
exports.ZodTuple = ZodTuple;
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
get: function () {
|
|
1829
|
-
return this._def.keyType;
|
|
1830
|
-
},
|
|
1831
|
-
enumerable: false,
|
|
1832
|
-
configurable: true
|
|
1573
|
+
ZodTuple.create = (schemas, params) => {
|
|
1574
|
+
return new ZodTuple({
|
|
1575
|
+
items: schemas,
|
|
1576
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
1577
|
+
rest: null,
|
|
1578
|
+
...processCreateParams(params),
|
|
1833
1579
|
});
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
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);
|
|
1843
1590
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1844
1591
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1845
1592
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1848,19 +1595,19 @@ var ZodRecord = /** @class */ (function (_super) {
|
|
|
1848
1595
|
});
|
|
1849
1596
|
return parseUtil_1.INVALID;
|
|
1850
1597
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
for (
|
|
1598
|
+
const pairs = [];
|
|
1599
|
+
const keyType = this._def.keyType;
|
|
1600
|
+
const valueType = this._def.valueType;
|
|
1601
|
+
for (const key in ctx.data) {
|
|
1855
1602
|
pairs.push({
|
|
1856
1603
|
key: keyType._parse({
|
|
1857
1604
|
data: key,
|
|
1858
|
-
path:
|
|
1605
|
+
path: [...ctx.path, key],
|
|
1859
1606
|
parent: ctx,
|
|
1860
1607
|
}),
|
|
1861
1608
|
value: valueType._parse({
|
|
1862
1609
|
data: ctx.data[key],
|
|
1863
|
-
path:
|
|
1610
|
+
path: [...ctx.path, key],
|
|
1864
1611
|
parent: ctx,
|
|
1865
1612
|
}),
|
|
1866
1613
|
});
|
|
@@ -1871,32 +1618,31 @@ var ZodRecord = /** @class */ (function (_super) {
|
|
|
1871
1618
|
else {
|
|
1872
1619
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
1873
1620
|
}
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
enumerable: false,
|
|
1880
|
-
configurable: true
|
|
1881
|
-
});
|
|
1882
|
-
ZodRecord.create = function (first, second, third) {
|
|
1621
|
+
}
|
|
1622
|
+
get element() {
|
|
1623
|
+
return this._def.valueType;
|
|
1624
|
+
}
|
|
1625
|
+
static create(first, second, third) {
|
|
1883
1626
|
if (second instanceof ZodType) {
|
|
1884
|
-
return new ZodRecord(
|
|
1627
|
+
return new ZodRecord({
|
|
1628
|
+
keyType: first,
|
|
1629
|
+
valueType: second,
|
|
1630
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
1631
|
+
...processCreateParams(third),
|
|
1632
|
+
});
|
|
1885
1633
|
}
|
|
1886
|
-
return new ZodRecord(
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1634
|
+
return new ZodRecord({
|
|
1635
|
+
keyType: ZodString.create(),
|
|
1636
|
+
valueType: first,
|
|
1637
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
1638
|
+
...processCreateParams(second),
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1890
1642
|
exports.ZodRecord = ZodRecord;
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1895
|
-
}
|
|
1896
|
-
ZodMap.prototype._parse = function (input) {
|
|
1897
|
-
var e_12, _a;
|
|
1898
|
-
var _this = this;
|
|
1899
|
-
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);
|
|
1900
1646
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.map) {
|
|
1901
1647
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1902
1648
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1905,77 +1651,28 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
1905
1651
|
});
|
|
1906
1652
|
return parseUtil_1.INVALID;
|
|
1907
1653
|
}
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
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) => {
|
|
1912
1657
|
return {
|
|
1913
1658
|
key: keyType._parse({
|
|
1914
1659
|
data: key,
|
|
1915
|
-
path:
|
|
1660
|
+
path: [...ctx.path, index, "key"],
|
|
1916
1661
|
parent: ctx,
|
|
1917
1662
|
}),
|
|
1918
1663
|
value: valueType._parse({
|
|
1919
1664
|
data: value,
|
|
1920
|
-
path:
|
|
1665
|
+
path: [...ctx.path, index, "value"],
|
|
1921
1666
|
parent: ctx,
|
|
1922
1667
|
}),
|
|
1923
1668
|
};
|
|
1924
1669
|
});
|
|
1925
1670
|
if (ctx.async) {
|
|
1926
|
-
|
|
1927
|
-
return Promise.resolve().then(
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
switch (_b.label) {
|
|
1932
|
-
case 0:
|
|
1933
|
-
_b.trys.push([0, 6, 7, 8]);
|
|
1934
|
-
pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
|
|
1935
|
-
_b.label = 1;
|
|
1936
|
-
case 1:
|
|
1937
|
-
if (!!pairs_3_1.done) return [3 /*break*/, 5];
|
|
1938
|
-
pair = pairs_3_1.value;
|
|
1939
|
-
return [4 /*yield*/, pair.key];
|
|
1940
|
-
case 2:
|
|
1941
|
-
key = _b.sent();
|
|
1942
|
-
return [4 /*yield*/, pair.value];
|
|
1943
|
-
case 3:
|
|
1944
|
-
value = _b.sent();
|
|
1945
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
1946
|
-
return [2 /*return*/, parseUtil_1.INVALID];
|
|
1947
|
-
}
|
|
1948
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
1949
|
-
status.dirty();
|
|
1950
|
-
}
|
|
1951
|
-
finalMap_1.set(key.value, value.value);
|
|
1952
|
-
_b.label = 4;
|
|
1953
|
-
case 4:
|
|
1954
|
-
pairs_3_1 = pairs_3.next();
|
|
1955
|
-
return [3 /*break*/, 1];
|
|
1956
|
-
case 5: return [3 /*break*/, 8];
|
|
1957
|
-
case 6:
|
|
1958
|
-
e_13_1 = _b.sent();
|
|
1959
|
-
e_13 = { error: e_13_1 };
|
|
1960
|
-
return [3 /*break*/, 8];
|
|
1961
|
-
case 7:
|
|
1962
|
-
try {
|
|
1963
|
-
if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
|
|
1964
|
-
}
|
|
1965
|
-
finally { if (e_13) throw e_13.error; }
|
|
1966
|
-
return [7 /*endfinally*/];
|
|
1967
|
-
case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
|
|
1968
|
-
}
|
|
1969
|
-
});
|
|
1970
|
-
}); });
|
|
1971
|
-
}
|
|
1972
|
-
else {
|
|
1973
|
-
var finalMap = new Map();
|
|
1974
|
-
try {
|
|
1975
|
-
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
1976
|
-
var pair = pairs_2_1.value;
|
|
1977
|
-
var key = pair.key;
|
|
1978
|
-
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;
|
|
1979
1676
|
if (key.status === "aborted" || value.status === "aborted") {
|
|
1980
1677
|
return parseUtil_1.INVALID;
|
|
1981
1678
|
}
|
|
@@ -1984,30 +1681,38 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
1984
1681
|
}
|
|
1985
1682
|
finalMap.set(key.value, value.value);
|
|
1986
1683
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
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();
|
|
1992
1697
|
}
|
|
1993
|
-
|
|
1698
|
+
finalMap.set(key.value, value.value);
|
|
1994
1699
|
}
|
|
1995
1700
|
return { status: status.value, value: finalMap };
|
|
1996
1701
|
}
|
|
1997
|
-
};
|
|
1998
|
-
ZodMap.create = function (keyType, valueType, params) {
|
|
1999
|
-
return new ZodMap(__assign({ valueType: valueType, keyType: keyType, typeName: ZodFirstPartyTypeKind.ZodMap }, processCreateParams(params)));
|
|
2000
|
-
};
|
|
2001
|
-
return ZodMap;
|
|
2002
|
-
}(ZodType));
|
|
2003
|
-
exports.ZodMap = ZodMap;
|
|
2004
|
-
var ZodSet = /** @class */ (function (_super) {
|
|
2005
|
-
__extends(ZodSet, _super);
|
|
2006
|
-
function ZodSet() {
|
|
2007
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2008
1702
|
}
|
|
2009
|
-
|
|
2010
|
-
|
|
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);
|
|
2011
1716
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.set) {
|
|
2012
1717
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2013
1718
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2016,7 +1721,7 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2016
1721
|
});
|
|
2017
1722
|
return parseUtil_1.INVALID;
|
|
2018
1723
|
}
|
|
2019
|
-
|
|
1724
|
+
const def = this._def;
|
|
2020
1725
|
if (def.minSize !== null) {
|
|
2021
1726
|
if (ctx.data.size < def.minSize.value) {
|
|
2022
1727
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
@@ -2041,67 +1746,62 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2041
1746
|
status.dirty();
|
|
2042
1747
|
}
|
|
2043
1748
|
}
|
|
2044
|
-
|
|
1749
|
+
const valueType = this._def.valueType;
|
|
2045
1750
|
function finalizeSet(elements) {
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
if (element.status === "dirty")
|
|
2054
|
-
status.dirty();
|
|
2055
|
-
parsedSet.add(element.value);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2059
|
-
finally {
|
|
2060
|
-
try {
|
|
2061
|
-
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
2062
|
-
}
|
|
2063
|
-
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);
|
|
2064
1758
|
}
|
|
2065
1759
|
return { status: status.value, value: parsedSet };
|
|
2066
1760
|
}
|
|
2067
|
-
|
|
2068
|
-
return valueType._parse({ data: item, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false), parent: ctx });
|
|
2069
|
-
});
|
|
1761
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx }));
|
|
2070
1762
|
if (ctx.async) {
|
|
2071
|
-
return Promise.all(elements).then(
|
|
1763
|
+
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
2072
1764
|
}
|
|
2073
1765
|
else {
|
|
2074
1766
|
return finalizeSet(elements);
|
|
2075
1767
|
}
|
|
2076
|
-
}
|
|
2077
|
-
|
|
2078
|
-
return new ZodSet(
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
}
|
|
2083
|
-
|
|
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) {
|
|
2084
1782
|
return this.min(size, message).max(size, message);
|
|
2085
|
-
}
|
|
2086
|
-
|
|
1783
|
+
}
|
|
1784
|
+
nonempty(message) {
|
|
2087
1785
|
return this.min(1, message);
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
return new ZodSet(__assign({ valueType: valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet }, processCreateParams(params)));
|
|
2091
|
-
};
|
|
2092
|
-
return ZodSet;
|
|
2093
|
-
}(ZodType));
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
2094
1788
|
exports.ZodSet = ZodSet;
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
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);
|
|
2105
1805
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.function) {
|
|
2106
1806
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2107
1807
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2119,7 +1819,7 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2119
1819
|
ctx.schemaErrorMap,
|
|
2120
1820
|
ZodError_1.overrideErrorMap,
|
|
2121
1821
|
ZodError_1.defaultErrorMap,
|
|
2122
|
-
].filter(
|
|
1822
|
+
].filter((x) => !!x),
|
|
2123
1823
|
issueData: {
|
|
2124
1824
|
code: ZodError_1.ZodIssueCode.invalid_arguments,
|
|
2125
1825
|
argumentsError: error,
|
|
@@ -2135,134 +1835,108 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2135
1835
|
ctx.schemaErrorMap,
|
|
2136
1836
|
ZodError_1.overrideErrorMap,
|
|
2137
1837
|
ZodError_1.defaultErrorMap,
|
|
2138
|
-
].filter(
|
|
1838
|
+
].filter((x) => !!x),
|
|
2139
1839
|
issueData: {
|
|
2140
1840
|
code: ZodError_1.ZodIssueCode.invalid_return_type,
|
|
2141
1841
|
returnTypeError: error,
|
|
2142
1842
|
},
|
|
2143
1843
|
});
|
|
2144
1844
|
}
|
|
2145
|
-
|
|
2146
|
-
|
|
1845
|
+
const params = { errorMap: ctx.contextualErrorMap };
|
|
1846
|
+
const fn = ctx.data;
|
|
2147
1847
|
if (this._def.returns instanceof ZodPromise) {
|
|
2148
|
-
return (0, parseUtil_1.OK)(
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
args
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
return __generator(this, function (_a) {
|
|
2156
|
-
switch (_a.label) {
|
|
2157
|
-
case 0:
|
|
2158
|
-
error = new ZodError_1.ZodError([]);
|
|
2159
|
-
return [4 /*yield*/, this._def.args
|
|
2160
|
-
.parseAsync(args, params)
|
|
2161
|
-
.catch(function (e) {
|
|
2162
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
2163
|
-
throw error;
|
|
2164
|
-
})];
|
|
2165
|
-
case 1:
|
|
2166
|
-
parsedArgs = _a.sent();
|
|
2167
|
-
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2168
|
-
case 2:
|
|
2169
|
-
result = _a.sent();
|
|
2170
|
-
return [4 /*yield*/, this._def
|
|
2171
|
-
.returns._def.type
|
|
2172
|
-
.parseAsync(result, params)
|
|
2173
|
-
.catch(function (e) {
|
|
2174
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
2175
|
-
throw error;
|
|
2176
|
-
})];
|
|
2177
|
-
case 3:
|
|
2178
|
-
parsedReturns = _a.sent();
|
|
2179
|
-
return [2 /*return*/, parsedReturns];
|
|
2180
|
-
}
|
|
2181
|
-
});
|
|
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;
|
|
2182
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;
|
|
1862
|
+
});
|
|
1863
|
+
return parsedReturns;
|
|
2183
1864
|
});
|
|
2184
1865
|
}
|
|
2185
1866
|
else {
|
|
2186
|
-
return (0, parseUtil_1.OK)(
|
|
2187
|
-
|
|
2188
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2189
|
-
args[_i] = arguments[_i];
|
|
2190
|
-
}
|
|
2191
|
-
var parsedArgs = _this._def.args.safeParse(args, params);
|
|
1867
|
+
return (0, parseUtil_1.OK)((...args) => {
|
|
1868
|
+
const parsedArgs = this._def.args.safeParse(args, params);
|
|
2192
1869
|
if (!parsedArgs.success) {
|
|
2193
1870
|
throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2194
1871
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
1872
|
+
const result = fn(...parsedArgs.data);
|
|
1873
|
+
const parsedReturns = this._def.returns.safeParse(result, params);
|
|
2197
1874
|
if (!parsedReturns.success) {
|
|
2198
1875
|
throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2199
1876
|
}
|
|
2200
1877
|
return parsedReturns.data;
|
|
2201
1878
|
});
|
|
2202
1879
|
}
|
|
2203
|
-
}
|
|
2204
|
-
|
|
1880
|
+
}
|
|
1881
|
+
parameters() {
|
|
2205
1882
|
return this._def.args;
|
|
2206
|
-
}
|
|
2207
|
-
|
|
1883
|
+
}
|
|
1884
|
+
returnType() {
|
|
2208
1885
|
return this._def.returns;
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
items
|
|
2214
|
-
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
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);
|
|
2222
1901
|
return validatedFunc;
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
|
|
1902
|
+
}
|
|
1903
|
+
strictImplement(func) {
|
|
1904
|
+
const validatedFunc = this.parse(func);
|
|
2226
1905
|
return validatedFunc;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
return new ZodFunction(__assign({ args: (args
|
|
2230
|
-
? args.rest(ZodUnknown.create())
|
|
2231
|
-
: ZodTuple.create([]).rest(ZodUnknown.create())), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction }, processCreateParams(params)));
|
|
2232
|
-
};
|
|
2233
|
-
return ZodFunction;
|
|
2234
|
-
}(ZodType));
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
2235
1908
|
exports.ZodFunction = ZodFunction;
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
},
|
|
2245
|
-
enumerable: false,
|
|
2246
|
-
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),
|
|
2247
1917
|
});
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
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();
|
|
2251
1926
|
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2252
|
-
};
|
|
2253
|
-
ZodLazy.create = function (getter, params) {
|
|
2254
|
-
return new ZodLazy(__assign({ getter: getter, typeName: ZodFirstPartyTypeKind.ZodLazy }, processCreateParams(params)));
|
|
2255
|
-
};
|
|
2256
|
-
return ZodLazy;
|
|
2257
|
-
}(ZodType));
|
|
2258
|
-
exports.ZodLazy = ZodLazy;
|
|
2259
|
-
var ZodLiteral = /** @class */ (function (_super) {
|
|
2260
|
-
__extends(ZodLiteral, _super);
|
|
2261
|
-
function ZodLiteral() {
|
|
2262
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2263
1927
|
}
|
|
2264
|
-
|
|
2265
|
-
|
|
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);
|
|
2266
1940
|
if (ctx.data !== this._def.value) {
|
|
2267
1941
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2268
1942
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2272,33 +1946,28 @@ var ZodLiteral = /** @class */ (function (_super) {
|
|
|
2272
1946
|
return parseUtil_1.INVALID;
|
|
2273
1947
|
}
|
|
2274
1948
|
return { status: status.value, value: ctx.data };
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
enumerable: false,
|
|
2281
|
-
configurable: true
|
|
2282
|
-
});
|
|
2283
|
-
ZodLiteral.create = function (value, params) {
|
|
2284
|
-
return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
|
|
2285
|
-
};
|
|
2286
|
-
return ZodLiteral;
|
|
2287
|
-
}(ZodType));
|
|
1949
|
+
}
|
|
1950
|
+
get value() {
|
|
1951
|
+
return this._def.value;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
2288
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
|
+
};
|
|
2289
1962
|
function createZodEnum(values) {
|
|
2290
1963
|
return new ZodEnum({
|
|
2291
1964
|
values: values,
|
|
2292
1965
|
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
2293
1966
|
});
|
|
2294
1967
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2299
|
-
}
|
|
2300
|
-
ZodEnum.prototype._parse = function (input) {
|
|
2301
|
-
var ctx = this._processInputParams(input).ctx;
|
|
1968
|
+
class ZodEnum extends ZodType {
|
|
1969
|
+
_parse(input) {
|
|
1970
|
+
const { ctx } = this._processInputParams(input);
|
|
2302
1971
|
if (this._def.values.indexOf(ctx.data) === -1) {
|
|
2303
1972
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2304
1973
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
@@ -2307,92 +1976,38 @@ var ZodEnum = /** @class */ (function (_super) {
|
|
|
2307
1976
|
return parseUtil_1.INVALID;
|
|
2308
1977
|
}
|
|
2309
1978
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
},
|
|
2337
|
-
enumerable: false,
|
|
2338
|
-
configurable: true
|
|
2339
|
-
});
|
|
2340
|
-
Object.defineProperty(ZodEnum.prototype, "Values", {
|
|
2341
|
-
get: function () {
|
|
2342
|
-
var e_16, _a;
|
|
2343
|
-
var enumValues = {};
|
|
2344
|
-
try {
|
|
2345
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2346
|
-
var val = _c.value;
|
|
2347
|
-
enumValues[val] = val;
|
|
2348
|
-
}
|
|
2349
|
-
}
|
|
2350
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
2351
|
-
finally {
|
|
2352
|
-
try {
|
|
2353
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2354
|
-
}
|
|
2355
|
-
finally { if (e_16) throw e_16.error; }
|
|
2356
|
-
}
|
|
2357
|
-
return enumValues;
|
|
2358
|
-
},
|
|
2359
|
-
enumerable: false,
|
|
2360
|
-
configurable: true
|
|
2361
|
-
});
|
|
2362
|
-
Object.defineProperty(ZodEnum.prototype, "Enum", {
|
|
2363
|
-
get: function () {
|
|
2364
|
-
var e_17, _a;
|
|
2365
|
-
var enumValues = {};
|
|
2366
|
-
try {
|
|
2367
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2368
|
-
var val = _c.value;
|
|
2369
|
-
enumValues[val] = val;
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
2373
|
-
finally {
|
|
2374
|
-
try {
|
|
2375
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2376
|
-
}
|
|
2377
|
-
finally { if (e_17) throw e_17.error; }
|
|
2378
|
-
}
|
|
2379
|
-
return enumValues;
|
|
2380
|
-
},
|
|
2381
|
-
enumerable: false,
|
|
2382
|
-
configurable: true
|
|
2383
|
-
});
|
|
2384
|
-
ZodEnum.create = createZodEnum;
|
|
2385
|
-
return ZodEnum;
|
|
2386
|
-
}(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
|
+
}
|
|
2387
2005
|
exports.ZodEnum = ZodEnum;
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
ZodNativeEnum.prototype._parse = function (input) {
|
|
2394
|
-
var ctx = this._processInputParams(input).ctx;
|
|
2395
|
-
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);
|
|
2396
2011
|
if (nativeEnumValues.indexOf(ctx.data) === -1) {
|
|
2397
2012
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2398
2013
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
@@ -2401,21 +2016,22 @@ var ZodNativeEnum = /** @class */ (function (_super) {
|
|
|
2401
2016
|
return parseUtil_1.INVALID;
|
|
2402
2017
|
}
|
|
2403
2018
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
return
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2409
|
-
}(ZodType));
|
|
2019
|
+
}
|
|
2020
|
+
get enum() {
|
|
2021
|
+
return this._def.values;
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2410
2024
|
exports.ZodNativeEnum = ZodNativeEnum;
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
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);
|
|
2419
2035
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.promise && ctx.async === false) {
|
|
2420
2036
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2421
2037
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2424,39 +2040,37 @@ var ZodPromise = /** @class */ (function (_super) {
|
|
|
2424
2040
|
});
|
|
2425
2041
|
return parseUtil_1.INVALID;
|
|
2426
2042
|
}
|
|
2427
|
-
|
|
2043
|
+
const promisified = ctx.parsedType === parseUtil_1.ZodParsedType.promise
|
|
2428
2044
|
? ctx.data
|
|
2429
2045
|
: Promise.resolve(ctx.data);
|
|
2430
|
-
return (0, parseUtil_1.OK)(promisified.then(
|
|
2431
|
-
return
|
|
2046
|
+
return (0, parseUtil_1.OK)(promisified.then((data) => {
|
|
2047
|
+
return this._def.type.parseAsync(data, {
|
|
2432
2048
|
path: ctx.path,
|
|
2433
2049
|
errorMap: ctx.contextualErrorMap,
|
|
2434
2050
|
});
|
|
2435
2051
|
}));
|
|
2436
|
-
};
|
|
2437
|
-
ZodPromise.create = function (schema, params) {
|
|
2438
|
-
return new ZodPromise(__assign({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise }, processCreateParams(params)));
|
|
2439
|
-
};
|
|
2440
|
-
return ZodPromise;
|
|
2441
|
-
}(ZodType));
|
|
2442
|
-
exports.ZodPromise = ZodPromise;
|
|
2443
|
-
var ZodEffects = /** @class */ (function (_super) {
|
|
2444
|
-
__extends(ZodEffects, _super);
|
|
2445
|
-
function ZodEffects() {
|
|
2446
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2447
2052
|
}
|
|
2448
|
-
|
|
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() {
|
|
2449
2064
|
return this._def.schema;
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
var effect = this._def.effect || null;
|
|
2065
|
+
}
|
|
2066
|
+
_parse(input) {
|
|
2067
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2068
|
+
const effect = this._def.effect || null;
|
|
2455
2069
|
if (effect.type === "preprocess") {
|
|
2456
|
-
|
|
2070
|
+
const processed = effect.transform(ctx.data);
|
|
2457
2071
|
if (ctx.async) {
|
|
2458
|
-
return Promise.resolve(processed).then(
|
|
2459
|
-
return
|
|
2072
|
+
return Promise.resolve(processed).then((processed) => {
|
|
2073
|
+
return this._def.schema._parseAsync({
|
|
2460
2074
|
data: processed,
|
|
2461
2075
|
path: ctx.path,
|
|
2462
2076
|
parent: ctx,
|
|
@@ -2472,8 +2086,8 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2472
2086
|
}
|
|
2473
2087
|
}
|
|
2474
2088
|
if (effect.type === "refinement") {
|
|
2475
|
-
|
|
2476
|
-
addIssue:
|
|
2089
|
+
const checkCtx = {
|
|
2090
|
+
addIssue: (arg) => {
|
|
2477
2091
|
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
|
2478
2092
|
if (arg.fatal) {
|
|
2479
2093
|
status.abort();
|
|
@@ -2486,11 +2100,11 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2486
2100
|
return ctx.path;
|
|
2487
2101
|
},
|
|
2488
2102
|
};
|
|
2489
|
-
|
|
2490
|
-
|
|
2103
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2104
|
+
const executeRefinement = (acc
|
|
2491
2105
|
// effect: RefinementEffect<any>
|
|
2492
|
-
) {
|
|
2493
|
-
|
|
2106
|
+
) => {
|
|
2107
|
+
const result = effect.refinement(acc, checkCtx);
|
|
2494
2108
|
if (ctx.async) {
|
|
2495
2109
|
return Promise.resolve(result);
|
|
2496
2110
|
}
|
|
@@ -2500,7 +2114,7 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2500
2114
|
return acc;
|
|
2501
2115
|
};
|
|
2502
2116
|
if (ctx.async === false) {
|
|
2503
|
-
|
|
2117
|
+
const inner = this._def.schema._parseSync({
|
|
2504
2118
|
data: ctx.data,
|
|
2505
2119
|
path: ctx.path,
|
|
2506
2120
|
parent: ctx,
|
|
@@ -2510,18 +2124,18 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2510
2124
|
if (inner.status === "dirty")
|
|
2511
2125
|
status.dirty();
|
|
2512
2126
|
// return value is ignored
|
|
2513
|
-
|
|
2127
|
+
executeRefinement(inner.value);
|
|
2514
2128
|
return { status: status.value, value: inner.value };
|
|
2515
2129
|
}
|
|
2516
2130
|
else {
|
|
2517
2131
|
return this._def.schema
|
|
2518
2132
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
2519
|
-
.then(
|
|
2133
|
+
.then((inner) => {
|
|
2520
2134
|
if (inner.status === "aborted")
|
|
2521
2135
|
return parseUtil_1.INVALID;
|
|
2522
2136
|
if (inner.status === "dirty")
|
|
2523
2137
|
status.dirty();
|
|
2524
|
-
return
|
|
2138
|
+
return executeRefinement(inner.value).then(() => {
|
|
2525
2139
|
return { status: status.value, value: inner.value };
|
|
2526
2140
|
});
|
|
2527
2141
|
});
|
|
@@ -2529,7 +2143,7 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2529
2143
|
}
|
|
2530
2144
|
if (effect.type === "transform") {
|
|
2531
2145
|
if (ctx.async === false) {
|
|
2532
|
-
|
|
2146
|
+
const base = this._def.schema._parseSync({
|
|
2533
2147
|
data: ctx.data,
|
|
2534
2148
|
path: ctx.path,
|
|
2535
2149
|
parent: ctx,
|
|
@@ -2540,16 +2154,16 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2540
2154
|
// }
|
|
2541
2155
|
if (!(0, parseUtil_1.isValid)(base))
|
|
2542
2156
|
return base;
|
|
2543
|
-
|
|
2157
|
+
const result = effect.transform(base.value);
|
|
2544
2158
|
if (result instanceof Promise) {
|
|
2545
|
-
throw new Error(
|
|
2159
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2546
2160
|
}
|
|
2547
2161
|
return (0, parseUtil_1.OK)(result);
|
|
2548
2162
|
}
|
|
2549
2163
|
else {
|
|
2550
2164
|
return this._def.schema
|
|
2551
2165
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
2552
|
-
.then(
|
|
2166
|
+
.then((base) => {
|
|
2553
2167
|
if (!(0, parseUtil_1.isValid)(base))
|
|
2554
2168
|
return base;
|
|
2555
2169
|
// if (base.status === "aborted") return INVALID;
|
|
@@ -2561,24 +2175,29 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2561
2175
|
}
|
|
2562
2176
|
}
|
|
2563
2177
|
util_1.util.assertNever(effect);
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
return new ZodEffects(__assign({ schema: schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: effect }, processCreateParams(params)));
|
|
2567
|
-
};
|
|
2568
|
-
ZodEffects.createWithPreprocess = function (preprocess, schema, params) {
|
|
2569
|
-
return new ZodEffects(__assign({ schema: schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects }, processCreateParams(params)));
|
|
2570
|
-
};
|
|
2571
|
-
return ZodEffects;
|
|
2572
|
-
}(ZodType));
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2573
2180
|
exports.ZodEffects = ZodEffects;
|
|
2574
2181
|
exports.ZodTransformer = ZodEffects;
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
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);
|
|
2582
2201
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
|
|
2583
2202
|
return (0, parseUtil_1.OK)(undefined);
|
|
2584
2203
|
}
|
|
@@ -2587,23 +2206,22 @@ var ZodOptional = /** @class */ (function (_super) {
|
|
|
2587
2206
|
path: ctx.path,
|
|
2588
2207
|
parent: ctx,
|
|
2589
2208
|
});
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2209
|
+
}
|
|
2210
|
+
unwrap() {
|
|
2592
2211
|
return this._def.innerType;
|
|
2593
|
-
};
|
|
2594
|
-
ZodOptional.create = function (type, params) {
|
|
2595
|
-
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
2596
|
-
};
|
|
2597
|
-
return ZodOptional;
|
|
2598
|
-
}(ZodType));
|
|
2599
|
-
exports.ZodOptional = ZodOptional;
|
|
2600
|
-
var ZodNullable = /** @class */ (function (_super) {
|
|
2601
|
-
__extends(ZodNullable, _super);
|
|
2602
|
-
function ZodNullable() {
|
|
2603
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2604
2212
|
}
|
|
2605
|
-
|
|
2606
|
-
|
|
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);
|
|
2607
2225
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.null) {
|
|
2608
2226
|
return (0, parseUtil_1.OK)(null);
|
|
2609
2227
|
}
|
|
@@ -2612,49 +2230,47 @@ var ZodNullable = /** @class */ (function (_super) {
|
|
|
2612
2230
|
path: ctx.path,
|
|
2613
2231
|
parent: ctx,
|
|
2614
2232
|
});
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2233
|
+
}
|
|
2234
|
+
unwrap() {
|
|
2617
2235
|
return this._def.innerType;
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
return new ZodNullable(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable }, processCreateParams(params)));
|
|
2621
|
-
};
|
|
2622
|
-
return ZodNullable;
|
|
2623
|
-
}(ZodType));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2624
2238
|
exports.ZodNullable = ZodNullable;
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
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;
|
|
2633
2250
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
|
|
2634
2251
|
data = this._def.defaultValue();
|
|
2635
2252
|
}
|
|
2636
2253
|
return this._def.innerType._parse({
|
|
2637
|
-
data
|
|
2254
|
+
data,
|
|
2638
2255
|
path: ctx.path,
|
|
2639
2256
|
parent: ctx,
|
|
2640
2257
|
});
|
|
2641
|
-
}
|
|
2642
|
-
|
|
2258
|
+
}
|
|
2259
|
+
removeDefault() {
|
|
2643
2260
|
return this._def.innerType;
|
|
2644
|
-
};
|
|
2645
|
-
ZodDefault.create = function (type, params) {
|
|
2646
|
-
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
2647
|
-
};
|
|
2648
|
-
return ZodDefault;
|
|
2649
|
-
}(ZodType));
|
|
2650
|
-
exports.ZodDefault = ZodDefault;
|
|
2651
|
-
var ZodNaN = /** @class */ (function (_super) {
|
|
2652
|
-
__extends(ZodNaN, _super);
|
|
2653
|
-
function ZodNaN() {
|
|
2654
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2655
2261
|
}
|
|
2656
|
-
|
|
2657
|
-
|
|
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);
|
|
2658
2274
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.nan) {
|
|
2659
2275
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2660
2276
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2664,14 +2280,16 @@ var ZodNaN = /** @class */ (function (_super) {
|
|
|
2664
2280
|
return parseUtil_1.INVALID;
|
|
2665
2281
|
}
|
|
2666
2282
|
return { status: status.value, value: ctx.data };
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
|
|
2670
|
-
};
|
|
2671
|
-
return ZodNaN;
|
|
2672
|
-
}(ZodType));
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2673
2285
|
exports.ZodNaN = ZodNaN;
|
|
2674
|
-
|
|
2286
|
+
ZodNaN.create = (params) => {
|
|
2287
|
+
return new ZodNaN({
|
|
2288
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
2289
|
+
...processCreateParams(params),
|
|
2290
|
+
});
|
|
2291
|
+
};
|
|
2292
|
+
const custom = (check, params) => {
|
|
2675
2293
|
if (check)
|
|
2676
2294
|
return ZodAny.create().refine(check, params);
|
|
2677
2295
|
return ZodAny.create();
|
|
@@ -2714,81 +2332,78 @@ var ZodFirstPartyTypeKind;
|
|
|
2714
2332
|
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
2715
2333
|
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
2716
2334
|
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
}; }
|
|
2721
|
-
return (0, exports.custom)(function (data) { return data instanceof cls; }, params);
|
|
2722
|
-
};
|
|
2335
|
+
const instanceOfType = (cls, params = {
|
|
2336
|
+
message: `Input not instance of ${cls.name}`,
|
|
2337
|
+
}) => (0, exports.custom)((data) => data instanceof cls, params);
|
|
2723
2338
|
exports.instanceof = instanceOfType;
|
|
2724
|
-
|
|
2339
|
+
const stringType = ZodString.create;
|
|
2725
2340
|
exports.string = stringType;
|
|
2726
|
-
|
|
2341
|
+
const numberType = ZodNumber.create;
|
|
2727
2342
|
exports.number = numberType;
|
|
2728
|
-
|
|
2343
|
+
const nanType = ZodNaN.create;
|
|
2729
2344
|
exports.nan = nanType;
|
|
2730
|
-
|
|
2345
|
+
const bigIntType = ZodBigInt.create;
|
|
2731
2346
|
exports.bigint = bigIntType;
|
|
2732
|
-
|
|
2347
|
+
const booleanType = ZodBoolean.create;
|
|
2733
2348
|
exports.boolean = booleanType;
|
|
2734
|
-
|
|
2349
|
+
const dateType = ZodDate.create;
|
|
2735
2350
|
exports.date = dateType;
|
|
2736
|
-
|
|
2351
|
+
const undefinedType = ZodUndefined.create;
|
|
2737
2352
|
exports.undefined = undefinedType;
|
|
2738
|
-
|
|
2353
|
+
const nullType = ZodNull.create;
|
|
2739
2354
|
exports.null = nullType;
|
|
2740
|
-
|
|
2355
|
+
const anyType = ZodAny.create;
|
|
2741
2356
|
exports.any = anyType;
|
|
2742
|
-
|
|
2357
|
+
const unknownType = ZodUnknown.create;
|
|
2743
2358
|
exports.unknown = unknownType;
|
|
2744
|
-
|
|
2359
|
+
const neverType = ZodNever.create;
|
|
2745
2360
|
exports.never = neverType;
|
|
2746
|
-
|
|
2361
|
+
const voidType = ZodVoid.create;
|
|
2747
2362
|
exports.void = voidType;
|
|
2748
|
-
|
|
2363
|
+
const arrayType = ZodArray.create;
|
|
2749
2364
|
exports.array = arrayType;
|
|
2750
|
-
|
|
2365
|
+
const objectType = ZodObject.create;
|
|
2751
2366
|
exports.object = objectType;
|
|
2752
|
-
|
|
2367
|
+
const strictObjectType = ZodObject.strictCreate;
|
|
2753
2368
|
exports.strictObject = strictObjectType;
|
|
2754
|
-
|
|
2369
|
+
const unionType = ZodUnion.create;
|
|
2755
2370
|
exports.union = unionType;
|
|
2756
|
-
|
|
2371
|
+
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
2757
2372
|
exports.discriminatedUnion = discriminatedUnionType;
|
|
2758
|
-
|
|
2373
|
+
const intersectionType = ZodIntersection.create;
|
|
2759
2374
|
exports.intersection = intersectionType;
|
|
2760
|
-
|
|
2375
|
+
const tupleType = ZodTuple.create;
|
|
2761
2376
|
exports.tuple = tupleType;
|
|
2762
|
-
|
|
2377
|
+
const recordType = ZodRecord.create;
|
|
2763
2378
|
exports.record = recordType;
|
|
2764
|
-
|
|
2379
|
+
const mapType = ZodMap.create;
|
|
2765
2380
|
exports.map = mapType;
|
|
2766
|
-
|
|
2381
|
+
const setType = ZodSet.create;
|
|
2767
2382
|
exports.set = setType;
|
|
2768
|
-
|
|
2383
|
+
const functionType = ZodFunction.create;
|
|
2769
2384
|
exports.function = functionType;
|
|
2770
|
-
|
|
2385
|
+
const lazyType = ZodLazy.create;
|
|
2771
2386
|
exports.lazy = lazyType;
|
|
2772
|
-
|
|
2387
|
+
const literalType = ZodLiteral.create;
|
|
2773
2388
|
exports.literal = literalType;
|
|
2774
|
-
|
|
2389
|
+
const enumType = ZodEnum.create;
|
|
2775
2390
|
exports.enum = enumType;
|
|
2776
|
-
|
|
2391
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
2777
2392
|
exports.nativeEnum = nativeEnumType;
|
|
2778
|
-
|
|
2393
|
+
const promiseType = ZodPromise.create;
|
|
2779
2394
|
exports.promise = promiseType;
|
|
2780
|
-
|
|
2395
|
+
const effectsType = ZodEffects.create;
|
|
2781
2396
|
exports.effect = effectsType;
|
|
2782
2397
|
exports.transformer = effectsType;
|
|
2783
|
-
|
|
2398
|
+
const optionalType = ZodOptional.create;
|
|
2784
2399
|
exports.optional = optionalType;
|
|
2785
|
-
|
|
2400
|
+
const nullableType = ZodNullable.create;
|
|
2786
2401
|
exports.nullable = nullableType;
|
|
2787
|
-
|
|
2402
|
+
const preprocessType = ZodEffects.createWithPreprocess;
|
|
2788
2403
|
exports.preprocess = preprocessType;
|
|
2789
|
-
|
|
2404
|
+
const ostring = () => stringType().optional();
|
|
2790
2405
|
exports.ostring = ostring;
|
|
2791
|
-
|
|
2406
|
+
const onumber = () => numberType().optional();
|
|
2792
2407
|
exports.onumber = onumber;
|
|
2793
|
-
|
|
2408
|
+
const oboolean = () => booleanType().optional();
|
|
2794
2409
|
exports.oboolean = oboolean;
|