zod 3.13.4 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- 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/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 +1 -1
- package/lib/index.mjs +1527 -2101
- package/lib/types.d.ts +1 -1
- package/lib/types.js +1318 -1711
- package/package.json +2 -1
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
|
-
enumerable: false,
|
|
798
|
-
configurable: true
|
|
799
|
-
});
|
|
800
|
-
Object.defineProperty(ZodNumber.prototype, "isInt", {
|
|
801
|
-
get: function () {
|
|
802
|
-
return !!this._def.checks.find(function (ch) { return ch.kind === "int"; });
|
|
803
|
-
},
|
|
804
|
-
enumerable: false,
|
|
805
|
-
configurable: true
|
|
806
|
-
});
|
|
807
|
-
ZodNumber.create = function (params) {
|
|
808
|
-
return new ZodNumber(__assign({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber }, processCreateParams(params)));
|
|
809
|
-
};
|
|
810
|
-
return ZodNumber;
|
|
811
|
-
}(ZodType));
|
|
812
|
-
exports.ZodNumber = ZodNumber;
|
|
813
|
-
var ZodBigInt = /** @class */ (function (_super) {
|
|
814
|
-
__extends(ZodBigInt, _super);
|
|
815
|
-
function ZodBigInt() {
|
|
816
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
629
|
+
}
|
|
630
|
+
return max;
|
|
817
631
|
}
|
|
818
|
-
|
|
819
|
-
|
|
632
|
+
get isInt() {
|
|
633
|
+
return !!this._def.checks.find((ch) => ch.kind === "int");
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
exports.ZodNumber = ZodNumber;
|
|
637
|
+
ZodNumber.create = (params) => {
|
|
638
|
+
return new ZodNumber({
|
|
639
|
+
checks: [],
|
|
640
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
641
|
+
...processCreateParams(params),
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
class ZodBigInt extends ZodType {
|
|
645
|
+
_parse(input) {
|
|
646
|
+
const { ctx } = this._processInputParams(input);
|
|
820
647
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.bigint) {
|
|
821
648
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
822
649
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -826,20 +653,18 @@ var ZodBigInt = /** @class */ (function (_super) {
|
|
|
826
653
|
return parseUtil_1.INVALID;
|
|
827
654
|
}
|
|
828
655
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
829
|
-
};
|
|
830
|
-
ZodBigInt.create = function (params) {
|
|
831
|
-
return new ZodBigInt(__assign({ typeName: ZodFirstPartyTypeKind.ZodBigInt }, processCreateParams(params)));
|
|
832
|
-
};
|
|
833
|
-
return ZodBigInt;
|
|
834
|
-
}(ZodType));
|
|
835
|
-
exports.ZodBigInt = ZodBigInt;
|
|
836
|
-
var ZodBoolean = /** @class */ (function (_super) {
|
|
837
|
-
__extends(ZodBoolean, _super);
|
|
838
|
-
function ZodBoolean() {
|
|
839
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
840
656
|
}
|
|
841
|
-
|
|
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,23 +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
|
|
1116
|
-
|
|
1117
|
-
|
|
937
|
+
const AugmentFactory = (def) => (augmentation) => {
|
|
938
|
+
return new ZodObject({
|
|
939
|
+
...def,
|
|
940
|
+
shape: () => ({
|
|
941
|
+
...def.shape(),
|
|
942
|
+
...augmentation,
|
|
943
|
+
}),
|
|
944
|
+
});
|
|
1118
945
|
};
|
|
1119
946
|
function deepPartialify(schema) {
|
|
1120
947
|
if (schema instanceof ZodObject) {
|
|
1121
|
-
|
|
1122
|
-
for (
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
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
|
+
});
|
|
1127
957
|
}
|
|
1128
958
|
else if (schema instanceof ZodArray) {
|
|
1129
959
|
return ZodArray.create(deepPartialify(schema.element));
|
|
@@ -1135,37 +965,33 @@ function deepPartialify(schema) {
|
|
|
1135
965
|
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1136
966
|
}
|
|
1137
967
|
else if (schema instanceof ZodTuple) {
|
|
1138
|
-
return ZodTuple.create(schema.items.map(
|
|
968
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
1139
969
|
}
|
|
1140
970
|
else {
|
|
1141
971
|
return schema;
|
|
1142
972
|
}
|
|
1143
973
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
_this._cached = null;
|
|
974
|
+
class ZodObject extends ZodType {
|
|
975
|
+
constructor() {
|
|
976
|
+
super(...arguments);
|
|
977
|
+
this._cached = null;
|
|
1149
978
|
/**
|
|
1150
979
|
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
1151
980
|
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
1152
981
|
*/
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
return _this;
|
|
982
|
+
this.nonstrict = this.passthrough;
|
|
983
|
+
this.augment = AugmentFactory(this._def);
|
|
984
|
+
this.extend = AugmentFactory(this._def);
|
|
1157
985
|
}
|
|
1158
|
-
|
|
986
|
+
_getCached() {
|
|
1159
987
|
if (this._cached !== null)
|
|
1160
988
|
return this._cached;
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
return (this._cached = { shape
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
var _this = this;
|
|
1168
|
-
var _d = this._processInputParams(input), status = _d.status, ctx = _d.ctx;
|
|
989
|
+
const shape = this._def.shape();
|
|
990
|
+
const keys = util_1.util.objectKeys(shape);
|
|
991
|
+
return (this._cached = { shape, keys });
|
|
992
|
+
}
|
|
993
|
+
_parse(input) {
|
|
994
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1169
995
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1170
996
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1171
997
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1174,51 +1000,31 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1174
1000
|
});
|
|
1175
1001
|
return parseUtil_1.INVALID;
|
|
1176
1002
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
alwaysSet: key in ctx.data,
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1198
|
-
finally {
|
|
1199
|
-
try {
|
|
1200
|
-
if (shapeKeys_1_1 && !shapeKeys_1_1.done && (_a = shapeKeys_1.return)) _a.call(shapeKeys_1);
|
|
1201
|
-
}
|
|
1202
|
-
finally { if (e_5) throw e_5.error; }
|
|
1003
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
1004
|
+
const dataKeys = util_1.util.objectKeys(ctx.data);
|
|
1005
|
+
const extraKeys = dataKeys.filter((k) => !shapeKeys.includes(k));
|
|
1006
|
+
const pairs = [];
|
|
1007
|
+
for (const key of shapeKeys) {
|
|
1008
|
+
const keyValidator = shape[key];
|
|
1009
|
+
const value = ctx.data[key];
|
|
1010
|
+
pairs.push({
|
|
1011
|
+
key: { status: "valid", value: key },
|
|
1012
|
+
value: keyValidator._parse({
|
|
1013
|
+
parent: ctx,
|
|
1014
|
+
data: value,
|
|
1015
|
+
path: [...ctx.path, key],
|
|
1016
|
+
}),
|
|
1017
|
+
alwaysSet: key in ctx.data,
|
|
1018
|
+
});
|
|
1203
1019
|
}
|
|
1204
1020
|
if (this._def.catchall instanceof ZodNever) {
|
|
1205
|
-
|
|
1021
|
+
const unknownKeys = this._def.unknownKeys;
|
|
1206
1022
|
if (unknownKeys === "passthrough") {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
value: { status: "valid", value: ctx.data[key] },
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1217
|
-
finally {
|
|
1218
|
-
try {
|
|
1219
|
-
if (extraKeys_1_1 && !extraKeys_1_1.done && (_b = extraKeys_1.return)) _b.call(extraKeys_1);
|
|
1220
|
-
}
|
|
1221
|
-
finally { if (e_6) throw e_6.error; }
|
|
1023
|
+
for (const key of extraKeys) {
|
|
1024
|
+
pairs.push({
|
|
1025
|
+
key: { status: "valid", value: key },
|
|
1026
|
+
value: { status: "valid", value: ctx.data[key] },
|
|
1027
|
+
});
|
|
1222
1028
|
}
|
|
1223
1029
|
}
|
|
1224
1030
|
else if (unknownKeys === "strict") {
|
|
@@ -1233,323 +1039,298 @@ var ZodObject = /** @class */ (function (_super) {
|
|
|
1233
1039
|
else if (unknownKeys === "strip") {
|
|
1234
1040
|
}
|
|
1235
1041
|
else {
|
|
1236
|
-
throw new Error(
|
|
1042
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
1237
1043
|
}
|
|
1238
1044
|
}
|
|
1239
1045
|
else {
|
|
1240
1046
|
// run catchall validation
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
alwaysSet: key in ctx.data,
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
1255
|
-
finally {
|
|
1256
|
-
try {
|
|
1257
|
-
if (extraKeys_2_1 && !extraKeys_2_1.done && (_c = extraKeys_2.return)) _c.call(extraKeys_2);
|
|
1258
|
-
}
|
|
1259
|
-
finally { if (e_7) throw e_7.error; }
|
|
1047
|
+
const catchall = this._def.catchall;
|
|
1048
|
+
for (const key of extraKeys) {
|
|
1049
|
+
const value = ctx.data[key];
|
|
1050
|
+
pairs.push({
|
|
1051
|
+
key: { status: "valid", value: key },
|
|
1052
|
+
value: catchall._parse({ parent: ctx, path: [...ctx.path, key], data: value } //, ctx.child(key), value, getParsedType(value)
|
|
1053
|
+
),
|
|
1054
|
+
alwaysSet: key in ctx.data,
|
|
1055
|
+
});
|
|
1260
1056
|
}
|
|
1261
1057
|
}
|
|
1262
1058
|
if (ctx.async) {
|
|
1263
1059
|
return Promise.resolve()
|
|
1264
|
-
.then(
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
if (!!pairs_1_1.done) return [3 /*break*/, 6];
|
|
1278
|
-
pair = pairs_1_1.value;
|
|
1279
|
-
return [4 /*yield*/, pair.key];
|
|
1280
|
-
case 3:
|
|
1281
|
-
key = _e.sent();
|
|
1282
|
-
_b = (_a = syncPairs).push;
|
|
1283
|
-
_d = {
|
|
1284
|
-
key: key
|
|
1285
|
-
};
|
|
1286
|
-
return [4 /*yield*/, pair.value];
|
|
1287
|
-
case 4:
|
|
1288
|
-
_b.apply(_a, [(_d.value = _e.sent(),
|
|
1289
|
-
_d.alwaysSet = pair.alwaysSet,
|
|
1290
|
-
_d)]);
|
|
1291
|
-
_e.label = 5;
|
|
1292
|
-
case 5:
|
|
1293
|
-
pairs_1_1 = pairs_1.next();
|
|
1294
|
-
return [3 /*break*/, 2];
|
|
1295
|
-
case 6: return [3 /*break*/, 9];
|
|
1296
|
-
case 7:
|
|
1297
|
-
e_8_1 = _e.sent();
|
|
1298
|
-
e_8 = { error: e_8_1 };
|
|
1299
|
-
return [3 /*break*/, 9];
|
|
1300
|
-
case 8:
|
|
1301
|
-
try {
|
|
1302
|
-
if (pairs_1_1 && !pairs_1_1.done && (_c = pairs_1.return)) _c.call(pairs_1);
|
|
1303
|
-
}
|
|
1304
|
-
finally { if (e_8) throw e_8.error; }
|
|
1305
|
-
return [7 /*endfinally*/];
|
|
1306
|
-
case 9: return [2 /*return*/, syncPairs];
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
}); })
|
|
1310
|
-
.then(function (syncPairs) {
|
|
1060
|
+
.then(async () => {
|
|
1061
|
+
const syncPairs = [];
|
|
1062
|
+
for (const pair of pairs) {
|
|
1063
|
+
const key = await pair.key;
|
|
1064
|
+
syncPairs.push({
|
|
1065
|
+
key,
|
|
1066
|
+
value: await pair.value,
|
|
1067
|
+
alwaysSet: pair.alwaysSet,
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
return syncPairs;
|
|
1071
|
+
})
|
|
1072
|
+
.then((syncPairs) => {
|
|
1311
1073
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1312
1074
|
});
|
|
1313
1075
|
}
|
|
1314
1076
|
else {
|
|
1315
1077
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
1316
1078
|
}
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
enumerable: false,
|
|
1323
|
-
configurable: true
|
|
1324
|
-
});
|
|
1325
|
-
ZodObject.prototype.strict = function (message) {
|
|
1326
|
-
var _this = this;
|
|
1079
|
+
}
|
|
1080
|
+
get shape() {
|
|
1081
|
+
return this._def.shape();
|
|
1082
|
+
}
|
|
1083
|
+
strict(message) {
|
|
1327
1084
|
errorUtil_1.errorUtil.errToObj;
|
|
1328
|
-
return new ZodObject(
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1085
|
+
return new ZodObject({
|
|
1086
|
+
...this._def,
|
|
1087
|
+
unknownKeys: "strict",
|
|
1088
|
+
...(message !== undefined
|
|
1089
|
+
? {
|
|
1090
|
+
errorMap: (issue, ctx) => {
|
|
1091
|
+
var _a, _b, _c, _d;
|
|
1092
|
+
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
1093
|
+
if (issue.code === "unrecognized_keys")
|
|
1094
|
+
return {
|
|
1095
|
+
message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
|
|
1096
|
+
};
|
|
1334
1097
|
return {
|
|
1335
|
-
message:
|
|
1098
|
+
message: defaultError,
|
|
1336
1099
|
};
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
}
|
|
1100
|
+
},
|
|
1101
|
+
}
|
|
1102
|
+
: {}),
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
strip() {
|
|
1106
|
+
return new ZodObject({
|
|
1107
|
+
...this._def,
|
|
1108
|
+
unknownKeys: "strip",
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
passthrough() {
|
|
1112
|
+
return new ZodObject({
|
|
1113
|
+
...this._def,
|
|
1114
|
+
unknownKeys: "passthrough",
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
setKey(key, schema) {
|
|
1118
|
+
return this.augment({ [key]: schema });
|
|
1119
|
+
}
|
|
1354
1120
|
/**
|
|
1355
1121
|
* Prior to zod@1.0.12 there was a bug in the
|
|
1356
1122
|
* inferred type of merged objects. Please
|
|
1357
1123
|
* upgrade if you are experiencing issues.
|
|
1358
1124
|
*/
|
|
1359
|
-
|
|
1360
|
-
var _this = this;
|
|
1125
|
+
merge(merging) {
|
|
1361
1126
|
// const mergedShape = objectUtil.mergeShapes(
|
|
1362
1127
|
// this._def.shape(),
|
|
1363
1128
|
// merging._def.shape()
|
|
1364
1129
|
// );
|
|
1365
|
-
|
|
1130
|
+
const merged = new ZodObject({
|
|
1366
1131
|
unknownKeys: merging._def.unknownKeys,
|
|
1367
1132
|
catchall: merging._def.catchall,
|
|
1368
|
-
shape:
|
|
1369
|
-
return objectUtil.mergeShapes(_this._def.shape(), merging._def.shape());
|
|
1370
|
-
},
|
|
1133
|
+
shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1371
1134
|
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1372
1135
|
});
|
|
1373
1136
|
return merged;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
return new ZodObject(
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
var _this = this;
|
|
1380
|
-
var shape = {};
|
|
1381
|
-
util_1.util.objectKeys(mask).map(function (key) {
|
|
1382
|
-
shape[key] = _this.shape[key];
|
|
1137
|
+
}
|
|
1138
|
+
catchall(index) {
|
|
1139
|
+
return new ZodObject({
|
|
1140
|
+
...this._def,
|
|
1141
|
+
catchall: index,
|
|
1383
1142
|
});
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1143
|
+
}
|
|
1144
|
+
pick(mask) {
|
|
1145
|
+
const shape = {};
|
|
1146
|
+
util_1.util.objectKeys(mask).map((key) => {
|
|
1147
|
+
shape[key] = this.shape[key];
|
|
1148
|
+
});
|
|
1149
|
+
return new ZodObject({
|
|
1150
|
+
...this._def,
|
|
1151
|
+
shape: () => shape,
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
omit(mask) {
|
|
1155
|
+
const shape = {};
|
|
1156
|
+
util_1.util.objectKeys(this.shape).map((key) => {
|
|
1390
1157
|
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
|
1391
|
-
shape[key] =
|
|
1158
|
+
shape[key] = this.shape[key];
|
|
1392
1159
|
}
|
|
1393
1160
|
});
|
|
1394
|
-
return new ZodObject(
|
|
1395
|
-
|
|
1396
|
-
|
|
1161
|
+
return new ZodObject({
|
|
1162
|
+
...this._def,
|
|
1163
|
+
shape: () => shape,
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
deepPartial() {
|
|
1397
1167
|
return deepPartialify(this);
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
var newShape = {};
|
|
1168
|
+
}
|
|
1169
|
+
partial(mask) {
|
|
1170
|
+
const newShape = {};
|
|
1402
1171
|
if (mask) {
|
|
1403
|
-
util_1.util.objectKeys(this.shape).map(
|
|
1172
|
+
util_1.util.objectKeys(this.shape).map((key) => {
|
|
1404
1173
|
if (util_1.util.objectKeys(mask).indexOf(key) === -1) {
|
|
1405
|
-
newShape[key] =
|
|
1174
|
+
newShape[key] = this.shape[key];
|
|
1406
1175
|
}
|
|
1407
1176
|
else {
|
|
1408
|
-
newShape[key] =
|
|
1177
|
+
newShape[key] = this.shape[key].optional();
|
|
1409
1178
|
}
|
|
1410
1179
|
});
|
|
1411
|
-
return new ZodObject(
|
|
1180
|
+
return new ZodObject({
|
|
1181
|
+
...this._def,
|
|
1182
|
+
shape: () => newShape,
|
|
1183
|
+
});
|
|
1412
1184
|
}
|
|
1413
1185
|
else {
|
|
1414
|
-
for (
|
|
1415
|
-
|
|
1186
|
+
for (const key in this.shape) {
|
|
1187
|
+
const fieldSchema = this.shape[key];
|
|
1416
1188
|
newShape[key] = fieldSchema.optional();
|
|
1417
1189
|
}
|
|
1418
1190
|
}
|
|
1419
|
-
return new ZodObject(
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1191
|
+
return new ZodObject({
|
|
1192
|
+
...this._def,
|
|
1193
|
+
shape: () => newShape,
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
required() {
|
|
1197
|
+
const newShape = {};
|
|
1198
|
+
for (const key in this.shape) {
|
|
1199
|
+
const fieldSchema = this.shape[key];
|
|
1200
|
+
let newField = fieldSchema;
|
|
1426
1201
|
while (newField instanceof ZodOptional) {
|
|
1427
1202
|
newField = newField._def.innerType;
|
|
1428
1203
|
}
|
|
1429
1204
|
newShape[key] = newField;
|
|
1430
1205
|
}
|
|
1431
|
-
return new ZodObject(
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
return new ZodObject(__assign({ shape: function () { return shape; }, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
1438
|
-
};
|
|
1439
|
-
ZodObject.lazycreate = function (shape, params) {
|
|
1440
|
-
return new ZodObject(__assign({ shape: shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject }, processCreateParams(params)));
|
|
1441
|
-
};
|
|
1442
|
-
return ZodObject;
|
|
1443
|
-
}(ZodType));
|
|
1206
|
+
return new ZodObject({
|
|
1207
|
+
...this._def,
|
|
1208
|
+
shape: () => newShape,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1444
1212
|
exports.ZodObject = ZodObject;
|
|
1445
|
-
|
|
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
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1213
|
+
ZodObject.create = (shape, params) => {
|
|
1214
|
+
return new ZodObject({
|
|
1215
|
+
shape: () => shape,
|
|
1216
|
+
unknownKeys: "strip",
|
|
1217
|
+
catchall: ZodNever.create(),
|
|
1218
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1219
|
+
...processCreateParams(params),
|
|
1220
|
+
});
|
|
1221
|
+
};
|
|
1222
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
1223
|
+
return new ZodObject({
|
|
1224
|
+
shape: () => shape,
|
|
1225
|
+
unknownKeys: "strict",
|
|
1226
|
+
catchall: ZodNever.create(),
|
|
1227
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1228
|
+
...processCreateParams(params),
|
|
1229
|
+
});
|
|
1230
|
+
};
|
|
1231
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
1232
|
+
return new ZodObject({
|
|
1233
|
+
shape,
|
|
1234
|
+
unknownKeys: "strip",
|
|
1235
|
+
catchall: ZodNever.create(),
|
|
1236
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1237
|
+
...processCreateParams(params),
|
|
1238
|
+
});
|
|
1239
|
+
};
|
|
1240
|
+
class ZodUnion extends ZodType {
|
|
1241
|
+
_parse(input) {
|
|
1242
|
+
const { ctx } = this._processInputParams(input);
|
|
1243
|
+
const options = this._def.options;
|
|
1244
|
+
function handleResults(results) {
|
|
1245
|
+
// return first issue-free validation if it exists
|
|
1246
|
+
for (const result of results) {
|
|
1247
|
+
if (result.result.status === "valid") {
|
|
1248
|
+
return result.result;
|
|
1480
1249
|
}
|
|
1481
1250
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1251
|
+
for (const result of results) {
|
|
1252
|
+
if (result.result.status === "dirty") {
|
|
1253
|
+
// add issues from dirty option
|
|
1254
|
+
ctx.issues.push(...result.ctx.issues);
|
|
1255
|
+
return result.result;
|
|
1486
1256
|
}
|
|
1487
|
-
finally { if (e_10) throw e_10.error; }
|
|
1488
1257
|
}
|
|
1489
1258
|
// return invalid
|
|
1490
|
-
|
|
1259
|
+
const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.issues));
|
|
1491
1260
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1492
1261
|
code: ZodError_1.ZodIssueCode.invalid_union,
|
|
1493
|
-
unionErrors
|
|
1262
|
+
unionErrors,
|
|
1494
1263
|
});
|
|
1495
1264
|
return parseUtil_1.INVALID;
|
|
1496
1265
|
}
|
|
1497
1266
|
if (ctx.async) {
|
|
1498
|
-
return Promise.all(options.map(
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
1505
|
-
_a = {};
|
|
1506
|
-
return [4 /*yield*/, option._parseAsync({
|
|
1507
|
-
data: ctx.data,
|
|
1508
|
-
path: ctx.path,
|
|
1509
|
-
parent: childCtx,
|
|
1510
|
-
})];
|
|
1511
|
-
case 1: return [2 /*return*/, (_a.result = _b.sent(),
|
|
1512
|
-
_a.ctx = childCtx,
|
|
1513
|
-
_a)];
|
|
1514
|
-
}
|
|
1515
|
-
});
|
|
1516
|
-
}); })).then(handleResults);
|
|
1517
|
-
}
|
|
1518
|
-
else {
|
|
1519
|
-
var optionResults = options.map(function (option) {
|
|
1520
|
-
var childCtx = __assign(__assign({}, ctx), { issues: [], parent: null });
|
|
1267
|
+
return Promise.all(options.map(async (option) => {
|
|
1268
|
+
const childCtx = {
|
|
1269
|
+
...ctx,
|
|
1270
|
+
issues: [],
|
|
1271
|
+
parent: null,
|
|
1272
|
+
};
|
|
1521
1273
|
return {
|
|
1522
|
-
result: option.
|
|
1274
|
+
result: await option._parseAsync({
|
|
1523
1275
|
data: ctx.data,
|
|
1524
1276
|
path: ctx.path,
|
|
1525
1277
|
parent: childCtx,
|
|
1526
1278
|
}),
|
|
1527
1279
|
ctx: childCtx,
|
|
1528
1280
|
};
|
|
1281
|
+
})).then(handleResults);
|
|
1282
|
+
}
|
|
1283
|
+
else {
|
|
1284
|
+
let dirty = undefined;
|
|
1285
|
+
const issues = [];
|
|
1286
|
+
for (const option of options) {
|
|
1287
|
+
const childCtx = {
|
|
1288
|
+
...ctx,
|
|
1289
|
+
issues: [],
|
|
1290
|
+
parent: null,
|
|
1291
|
+
};
|
|
1292
|
+
const result = option._parseSync({
|
|
1293
|
+
data: ctx.data,
|
|
1294
|
+
path: ctx.path,
|
|
1295
|
+
parent: childCtx,
|
|
1296
|
+
});
|
|
1297
|
+
if (result.status === "valid") {
|
|
1298
|
+
return result;
|
|
1299
|
+
}
|
|
1300
|
+
else if (result.status === "dirty" && !dirty) {
|
|
1301
|
+
dirty = { result, ctx: childCtx };
|
|
1302
|
+
}
|
|
1303
|
+
if (childCtx.issues.length) {
|
|
1304
|
+
issues.push(childCtx.issues);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
if (dirty) {
|
|
1308
|
+
ctx.issues.push(...dirty.ctx.issues);
|
|
1309
|
+
return dirty.result;
|
|
1310
|
+
}
|
|
1311
|
+
const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
|
|
1312
|
+
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1313
|
+
code: ZodError_1.ZodIssueCode.invalid_union,
|
|
1314
|
+
unionErrors,
|
|
1529
1315
|
});
|
|
1530
|
-
return
|
|
1316
|
+
return parseUtil_1.INVALID;
|
|
1531
1317
|
}
|
|
1532
|
-
};
|
|
1533
|
-
Object.defineProperty(ZodUnion.prototype, "options", {
|
|
1534
|
-
get: function () {
|
|
1535
|
-
return this._def.options;
|
|
1536
|
-
},
|
|
1537
|
-
enumerable: false,
|
|
1538
|
-
configurable: true
|
|
1539
|
-
});
|
|
1540
|
-
ZodUnion.create = function (types, params) {
|
|
1541
|
-
return new ZodUnion(__assign({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion }, processCreateParams(params)));
|
|
1542
|
-
};
|
|
1543
|
-
return ZodUnion;
|
|
1544
|
-
}(ZodType));
|
|
1545
|
-
exports.ZodUnion = ZodUnion;
|
|
1546
|
-
var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
1547
|
-
__extends(ZodDiscriminatedUnion, _super);
|
|
1548
|
-
function ZodDiscriminatedUnion() {
|
|
1549
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1550
1318
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1319
|
+
get options() {
|
|
1320
|
+
return this._def.options;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
exports.ZodUnion = ZodUnion;
|
|
1324
|
+
ZodUnion.create = (types, params) => {
|
|
1325
|
+
return new ZodUnion({
|
|
1326
|
+
options: types,
|
|
1327
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
1328
|
+
...processCreateParams(params),
|
|
1329
|
+
});
|
|
1330
|
+
};
|
|
1331
|
+
class ZodDiscriminatedUnion extends ZodType {
|
|
1332
|
+
_parse(input) {
|
|
1333
|
+
const { ctx } = this._processInputParams(input);
|
|
1553
1334
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1554
1335
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1555
1336
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1558,9 +1339,9 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1558
1339
|
});
|
|
1559
1340
|
return parseUtil_1.INVALID;
|
|
1560
1341
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1342
|
+
const discriminator = this.discriminator;
|
|
1343
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
1344
|
+
const option = this.options.get(discriminatorValue);
|
|
1564
1345
|
if (!option) {
|
|
1565
1346
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1566
1347
|
code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
|
|
@@ -1583,28 +1364,16 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1583
1364
|
parent: ctx,
|
|
1584
1365
|
});
|
|
1585
1366
|
}
|
|
1586
|
-
}
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
return Array.from(this.options.keys());
|
|
1597
|
-
},
|
|
1598
|
-
enumerable: false,
|
|
1599
|
-
configurable: true
|
|
1600
|
-
});
|
|
1601
|
-
Object.defineProperty(ZodDiscriminatedUnion.prototype, "options", {
|
|
1602
|
-
get: function () {
|
|
1603
|
-
return this._def.options;
|
|
1604
|
-
},
|
|
1605
|
-
enumerable: false,
|
|
1606
|
-
configurable: true
|
|
1607
|
-
});
|
|
1367
|
+
}
|
|
1368
|
+
get discriminator() {
|
|
1369
|
+
return this._def.discriminator;
|
|
1370
|
+
}
|
|
1371
|
+
get validDiscriminatorValues() {
|
|
1372
|
+
return Array.from(this.options.keys());
|
|
1373
|
+
}
|
|
1374
|
+
get options() {
|
|
1375
|
+
return this._def.options;
|
|
1376
|
+
}
|
|
1608
1377
|
/**
|
|
1609
1378
|
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
1610
1379
|
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
@@ -1613,12 +1382,12 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1613
1382
|
* @param types an array of object schemas
|
|
1614
1383
|
* @param params
|
|
1615
1384
|
*/
|
|
1616
|
-
|
|
1385
|
+
static create(discriminator, types, params) {
|
|
1617
1386
|
// Get all the valid discriminator values
|
|
1618
|
-
|
|
1387
|
+
const options = new Map();
|
|
1619
1388
|
try {
|
|
1620
|
-
types.forEach(
|
|
1621
|
-
|
|
1389
|
+
types.forEach((type) => {
|
|
1390
|
+
const discriminatorValue = type.shape[discriminator].value;
|
|
1622
1391
|
options.set(discriminatorValue, type);
|
|
1623
1392
|
});
|
|
1624
1393
|
}
|
|
@@ -1629,40 +1398,33 @@ var ZodDiscriminatedUnion = /** @class */ (function (_super) {
|
|
|
1629
1398
|
if (options.size !== types.length) {
|
|
1630
1399
|
throw new Error("Some of the discriminator values are not unique");
|
|
1631
1400
|
}
|
|
1632
|
-
return new ZodDiscriminatedUnion(
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1401
|
+
return new ZodDiscriminatedUnion({
|
|
1402
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
1403
|
+
discriminator,
|
|
1404
|
+
options,
|
|
1405
|
+
...processCreateParams(params),
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1636
1409
|
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
|
1637
1410
|
function mergeValues(a, b) {
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
var bType = (0, parseUtil_1.getParsedType)(b);
|
|
1411
|
+
const aType = (0, parseUtil_1.getParsedType)(a);
|
|
1412
|
+
const bType = (0, parseUtil_1.getParsedType)(b);
|
|
1641
1413
|
if (a === b) {
|
|
1642
1414
|
return { valid: true, data: a };
|
|
1643
1415
|
}
|
|
1644
1416
|
else if (aType === parseUtil_1.ZodParsedType.object && bType === parseUtil_1.ZodParsedType.object) {
|
|
1645
|
-
|
|
1646
|
-
|
|
1417
|
+
const bKeys = util_1.util.objectKeys(b);
|
|
1418
|
+
const sharedKeys = util_1.util
|
|
1647
1419
|
.objectKeys(a)
|
|
1648
|
-
.filter(
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
if (!sharedValue.valid) {
|
|
1655
|
-
return { valid: false };
|
|
1656
|
-
}
|
|
1657
|
-
newObj[key] = sharedValue.data;
|
|
1658
|
-
}
|
|
1659
|
-
}
|
|
1660
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1661
|
-
finally {
|
|
1662
|
-
try {
|
|
1663
|
-
if (sharedKeys_1_1 && !sharedKeys_1_1.done && (_a = sharedKeys_1.return)) _a.call(sharedKeys_1);
|
|
1420
|
+
.filter((key) => bKeys.indexOf(key) !== -1);
|
|
1421
|
+
const newObj = { ...a, ...b };
|
|
1422
|
+
for (const key of sharedKeys) {
|
|
1423
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
1424
|
+
if (!sharedValue.valid) {
|
|
1425
|
+
return { valid: false };
|
|
1664
1426
|
}
|
|
1665
|
-
|
|
1427
|
+
newObj[key] = sharedValue.data;
|
|
1666
1428
|
}
|
|
1667
1429
|
return { valid: true, data: newObj };
|
|
1668
1430
|
}
|
|
@@ -1670,11 +1432,11 @@ function mergeValues(a, b) {
|
|
|
1670
1432
|
if (a.length !== b.length) {
|
|
1671
1433
|
return { valid: false };
|
|
1672
1434
|
}
|
|
1673
|
-
|
|
1674
|
-
for (
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1435
|
+
const newArray = [];
|
|
1436
|
+
for (let index = 0; index < a.length; index++) {
|
|
1437
|
+
const itemA = a[index];
|
|
1438
|
+
const itemB = b[index];
|
|
1439
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
1678
1440
|
if (!sharedValue.valid) {
|
|
1679
1441
|
return { valid: false };
|
|
1680
1442
|
}
|
|
@@ -1691,18 +1453,14 @@ function mergeValues(a, b) {
|
|
|
1691
1453
|
return { valid: false };
|
|
1692
1454
|
}
|
|
1693
1455
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
}
|
|
1699
|
-
ZodIntersection.prototype._parse = function (input) {
|
|
1700
|
-
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
1701
|
-
var handleParsed = function (parsedLeft, parsedRight) {
|
|
1456
|
+
class ZodIntersection extends ZodType {
|
|
1457
|
+
_parse(input) {
|
|
1458
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1459
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
1702
1460
|
if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
|
|
1703
1461
|
return parseUtil_1.INVALID;
|
|
1704
1462
|
}
|
|
1705
|
-
|
|
1463
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
1706
1464
|
if (!merged.valid) {
|
|
1707
1465
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1708
1466
|
code: ZodError_1.ZodIssueCode.invalid_intersection_types,
|
|
@@ -1726,10 +1484,7 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
1726
1484
|
path: ctx.path,
|
|
1727
1485
|
parent: ctx,
|
|
1728
1486
|
}),
|
|
1729
|
-
]).then(
|
|
1730
|
-
var _b = __read(_a, 2), left = _b[0], right = _b[1];
|
|
1731
|
-
return handleParsed(left, right);
|
|
1732
|
-
});
|
|
1487
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
1733
1488
|
}
|
|
1734
1489
|
else {
|
|
1735
1490
|
return handleParsed(this._def.left._parseSync({
|
|
@@ -1742,21 +1497,20 @@ var ZodIntersection = /** @class */ (function (_super) {
|
|
|
1742
1497
|
parent: ctx,
|
|
1743
1498
|
}));
|
|
1744
1499
|
}
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
return new ZodIntersection(__assign({ left: left, right: right, typeName: ZodFirstPartyTypeKind.ZodIntersection }, processCreateParams(params)));
|
|
1748
|
-
};
|
|
1749
|
-
return ZodIntersection;
|
|
1750
|
-
}(ZodType));
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1751
1502
|
exports.ZodIntersection = ZodIntersection;
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1503
|
+
ZodIntersection.create = (left, right, params) => {
|
|
1504
|
+
return new ZodIntersection({
|
|
1505
|
+
left: left,
|
|
1506
|
+
right: right,
|
|
1507
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
1508
|
+
...processCreateParams(params),
|
|
1509
|
+
});
|
|
1510
|
+
};
|
|
1511
|
+
class ZodTuple extends ZodType {
|
|
1512
|
+
_parse(input) {
|
|
1513
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1760
1514
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.array) {
|
|
1761
1515
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1762
1516
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1774,7 +1528,7 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
1774
1528
|
});
|
|
1775
1529
|
return parseUtil_1.INVALID;
|
|
1776
1530
|
}
|
|
1777
|
-
|
|
1531
|
+
const rest = this._def.rest;
|
|
1778
1532
|
if (!rest && ctx.data.length > this._def.items.length) {
|
|
1779
1533
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1780
1534
|
code: ZodError_1.ZodIssueCode.too_big,
|
|
@@ -1784,64 +1538,55 @@ var ZodTuple = /** @class */ (function (_super) {
|
|
|
1784
1538
|
});
|
|
1785
1539
|
status.dirty();
|
|
1786
1540
|
}
|
|
1787
|
-
|
|
1788
|
-
.map(
|
|
1789
|
-
|
|
1541
|
+
const items = ctx.data
|
|
1542
|
+
.map((item, itemIndex) => {
|
|
1543
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
1790
1544
|
if (!schema)
|
|
1791
1545
|
return null;
|
|
1792
1546
|
return schema._parse({
|
|
1793
1547
|
data: item,
|
|
1794
|
-
path:
|
|
1548
|
+
path: [...ctx.path, itemIndex],
|
|
1795
1549
|
parent: ctx,
|
|
1796
1550
|
});
|
|
1797
1551
|
})
|
|
1798
|
-
.filter(
|
|
1552
|
+
.filter((x) => !!x); // filter nulls
|
|
1799
1553
|
if (ctx.async) {
|
|
1800
|
-
return Promise.all(items).then(
|
|
1554
|
+
return Promise.all(items).then((results) => {
|
|
1801
1555
|
return parseUtil_1.ParseStatus.mergeArray(status, results);
|
|
1802
1556
|
});
|
|
1803
1557
|
}
|
|
1804
1558
|
else {
|
|
1805
1559
|
return parseUtil_1.ParseStatus.mergeArray(status, items);
|
|
1806
1560
|
}
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
ZodTuple.create = function (schemas, params) {
|
|
1819
|
-
return new ZodTuple(__assign({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null }, processCreateParams(params)));
|
|
1820
|
-
};
|
|
1821
|
-
return ZodTuple;
|
|
1822
|
-
}(ZodType));
|
|
1561
|
+
}
|
|
1562
|
+
get items() {
|
|
1563
|
+
return this._def.items;
|
|
1564
|
+
}
|
|
1565
|
+
rest(rest) {
|
|
1566
|
+
return new ZodTuple({
|
|
1567
|
+
...this._def,
|
|
1568
|
+
rest,
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1823
1572
|
exports.ZodTuple = ZodTuple;
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
get: function () {
|
|
1831
|
-
return this._def.keyType;
|
|
1832
|
-
},
|
|
1833
|
-
enumerable: false,
|
|
1834
|
-
configurable: true
|
|
1835
|
-
});
|
|
1836
|
-
Object.defineProperty(ZodRecord.prototype, "valueSchema", {
|
|
1837
|
-
get: function () {
|
|
1838
|
-
return this._def.valueType;
|
|
1839
|
-
},
|
|
1840
|
-
enumerable: false,
|
|
1841
|
-
configurable: true
|
|
1573
|
+
ZodTuple.create = (schemas, params) => {
|
|
1574
|
+
return new ZodTuple({
|
|
1575
|
+
items: schemas,
|
|
1576
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
1577
|
+
rest: null,
|
|
1578
|
+
...processCreateParams(params),
|
|
1842
1579
|
});
|
|
1843
|
-
|
|
1844
|
-
|
|
1580
|
+
};
|
|
1581
|
+
class ZodRecord extends ZodType {
|
|
1582
|
+
get keySchema() {
|
|
1583
|
+
return this._def.keyType;
|
|
1584
|
+
}
|
|
1585
|
+
get valueSchema() {
|
|
1586
|
+
return this._def.valueType;
|
|
1587
|
+
}
|
|
1588
|
+
_parse(input) {
|
|
1589
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1845
1590
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.object) {
|
|
1846
1591
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1847
1592
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1850,19 +1595,19 @@ var ZodRecord = /** @class */ (function (_super) {
|
|
|
1850
1595
|
});
|
|
1851
1596
|
return parseUtil_1.INVALID;
|
|
1852
1597
|
}
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
for (
|
|
1598
|
+
const pairs = [];
|
|
1599
|
+
const keyType = this._def.keyType;
|
|
1600
|
+
const valueType = this._def.valueType;
|
|
1601
|
+
for (const key in ctx.data) {
|
|
1857
1602
|
pairs.push({
|
|
1858
1603
|
key: keyType._parse({
|
|
1859
1604
|
data: key,
|
|
1860
|
-
path:
|
|
1605
|
+
path: [...ctx.path, key],
|
|
1861
1606
|
parent: ctx,
|
|
1862
1607
|
}),
|
|
1863
1608
|
value: valueType._parse({
|
|
1864
1609
|
data: ctx.data[key],
|
|
1865
|
-
path:
|
|
1610
|
+
path: [...ctx.path, key],
|
|
1866
1611
|
parent: ctx,
|
|
1867
1612
|
}),
|
|
1868
1613
|
});
|
|
@@ -1873,32 +1618,31 @@ var ZodRecord = /** @class */ (function (_super) {
|
|
|
1873
1618
|
else {
|
|
1874
1619
|
return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
|
|
1875
1620
|
}
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
enumerable: false,
|
|
1882
|
-
configurable: true
|
|
1883
|
-
});
|
|
1884
|
-
ZodRecord.create = function (first, second, third) {
|
|
1621
|
+
}
|
|
1622
|
+
get element() {
|
|
1623
|
+
return this._def.valueType;
|
|
1624
|
+
}
|
|
1625
|
+
static create(first, second, third) {
|
|
1885
1626
|
if (second instanceof ZodType) {
|
|
1886
|
-
return new ZodRecord(
|
|
1627
|
+
return new ZodRecord({
|
|
1628
|
+
keyType: first,
|
|
1629
|
+
valueType: second,
|
|
1630
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
1631
|
+
...processCreateParams(third),
|
|
1632
|
+
});
|
|
1887
1633
|
}
|
|
1888
|
-
return new ZodRecord(
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1634
|
+
return new ZodRecord({
|
|
1635
|
+
keyType: ZodString.create(),
|
|
1636
|
+
valueType: first,
|
|
1637
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
1638
|
+
...processCreateParams(second),
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1892
1642
|
exports.ZodRecord = ZodRecord;
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
1897
|
-
}
|
|
1898
|
-
ZodMap.prototype._parse = function (input) {
|
|
1899
|
-
var e_12, _a;
|
|
1900
|
-
var _this = this;
|
|
1901
|
-
var _b = this._processInputParams(input), status = _b.status, ctx = _b.ctx;
|
|
1643
|
+
class ZodMap extends ZodType {
|
|
1644
|
+
_parse(input) {
|
|
1645
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1902
1646
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.map) {
|
|
1903
1647
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
1904
1648
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -1907,77 +1651,28 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
1907
1651
|
});
|
|
1908
1652
|
return parseUtil_1.INVALID;
|
|
1909
1653
|
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1654
|
+
const keyType = this._def.keyType;
|
|
1655
|
+
const valueType = this._def.valueType;
|
|
1656
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
1914
1657
|
return {
|
|
1915
1658
|
key: keyType._parse({
|
|
1916
1659
|
data: key,
|
|
1917
|
-
path:
|
|
1660
|
+
path: [...ctx.path, index, "key"],
|
|
1918
1661
|
parent: ctx,
|
|
1919
1662
|
}),
|
|
1920
1663
|
value: valueType._parse({
|
|
1921
1664
|
data: value,
|
|
1922
|
-
path:
|
|
1665
|
+
path: [...ctx.path, index, "value"],
|
|
1923
1666
|
parent: ctx,
|
|
1924
1667
|
}),
|
|
1925
1668
|
};
|
|
1926
1669
|
});
|
|
1927
1670
|
if (ctx.async) {
|
|
1928
|
-
|
|
1929
|
-
return Promise.resolve().then(
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
switch (_b.label) {
|
|
1934
|
-
case 0:
|
|
1935
|
-
_b.trys.push([0, 6, 7, 8]);
|
|
1936
|
-
pairs_3 = __values(pairs), pairs_3_1 = pairs_3.next();
|
|
1937
|
-
_b.label = 1;
|
|
1938
|
-
case 1:
|
|
1939
|
-
if (!!pairs_3_1.done) return [3 /*break*/, 5];
|
|
1940
|
-
pair = pairs_3_1.value;
|
|
1941
|
-
return [4 /*yield*/, pair.key];
|
|
1942
|
-
case 2:
|
|
1943
|
-
key = _b.sent();
|
|
1944
|
-
return [4 /*yield*/, pair.value];
|
|
1945
|
-
case 3:
|
|
1946
|
-
value = _b.sent();
|
|
1947
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
1948
|
-
return [2 /*return*/, parseUtil_1.INVALID];
|
|
1949
|
-
}
|
|
1950
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
1951
|
-
status.dirty();
|
|
1952
|
-
}
|
|
1953
|
-
finalMap_1.set(key.value, value.value);
|
|
1954
|
-
_b.label = 4;
|
|
1955
|
-
case 4:
|
|
1956
|
-
pairs_3_1 = pairs_3.next();
|
|
1957
|
-
return [3 /*break*/, 1];
|
|
1958
|
-
case 5: return [3 /*break*/, 8];
|
|
1959
|
-
case 6:
|
|
1960
|
-
e_13_1 = _b.sent();
|
|
1961
|
-
e_13 = { error: e_13_1 };
|
|
1962
|
-
return [3 /*break*/, 8];
|
|
1963
|
-
case 7:
|
|
1964
|
-
try {
|
|
1965
|
-
if (pairs_3_1 && !pairs_3_1.done && (_a = pairs_3.return)) _a.call(pairs_3);
|
|
1966
|
-
}
|
|
1967
|
-
finally { if (e_13) throw e_13.error; }
|
|
1968
|
-
return [7 /*endfinally*/];
|
|
1969
|
-
case 8: return [2 /*return*/, { status: status.value, value: finalMap_1 }];
|
|
1970
|
-
}
|
|
1971
|
-
});
|
|
1972
|
-
}); });
|
|
1973
|
-
}
|
|
1974
|
-
else {
|
|
1975
|
-
var finalMap = new Map();
|
|
1976
|
-
try {
|
|
1977
|
-
for (var pairs_2 = __values(pairs), pairs_2_1 = pairs_2.next(); !pairs_2_1.done; pairs_2_1 = pairs_2.next()) {
|
|
1978
|
-
var pair = pairs_2_1.value;
|
|
1979
|
-
var key = pair.key;
|
|
1980
|
-
var value = pair.value;
|
|
1671
|
+
const finalMap = new Map();
|
|
1672
|
+
return Promise.resolve().then(async () => {
|
|
1673
|
+
for (const pair of pairs) {
|
|
1674
|
+
const key = await pair.key;
|
|
1675
|
+
const value = await pair.value;
|
|
1981
1676
|
if (key.status === "aborted" || value.status === "aborted") {
|
|
1982
1677
|
return parseUtil_1.INVALID;
|
|
1983
1678
|
}
|
|
@@ -1986,30 +1681,38 @@ var ZodMap = /** @class */ (function (_super) {
|
|
|
1986
1681
|
}
|
|
1987
1682
|
finalMap.set(key.value, value.value);
|
|
1988
1683
|
}
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1684
|
+
return { status: status.value, value: finalMap };
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
else {
|
|
1688
|
+
const finalMap = new Map();
|
|
1689
|
+
for (const pair of pairs) {
|
|
1690
|
+
const key = pair.key;
|
|
1691
|
+
const value = pair.value;
|
|
1692
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
1693
|
+
return parseUtil_1.INVALID;
|
|
1694
|
+
}
|
|
1695
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
1696
|
+
status.dirty();
|
|
1994
1697
|
}
|
|
1995
|
-
|
|
1698
|
+
finalMap.set(key.value, value.value);
|
|
1996
1699
|
}
|
|
1997
1700
|
return { status: status.value, value: finalMap };
|
|
1998
1701
|
}
|
|
1999
|
-
};
|
|
2000
|
-
ZodMap.create = function (keyType, valueType, params) {
|
|
2001
|
-
return new ZodMap(__assign({ valueType: valueType, keyType: keyType, typeName: ZodFirstPartyTypeKind.ZodMap }, processCreateParams(params)));
|
|
2002
|
-
};
|
|
2003
|
-
return ZodMap;
|
|
2004
|
-
}(ZodType));
|
|
2005
|
-
exports.ZodMap = ZodMap;
|
|
2006
|
-
var ZodSet = /** @class */ (function (_super) {
|
|
2007
|
-
__extends(ZodSet, _super);
|
|
2008
|
-
function ZodSet() {
|
|
2009
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2010
1702
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
1703
|
+
}
|
|
1704
|
+
exports.ZodMap = ZodMap;
|
|
1705
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
1706
|
+
return new ZodMap({
|
|
1707
|
+
valueType,
|
|
1708
|
+
keyType,
|
|
1709
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
1710
|
+
...processCreateParams(params),
|
|
1711
|
+
});
|
|
1712
|
+
};
|
|
1713
|
+
class ZodSet extends ZodType {
|
|
1714
|
+
_parse(input) {
|
|
1715
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2013
1716
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.set) {
|
|
2014
1717
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2015
1718
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2018,7 +1721,7 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2018
1721
|
});
|
|
2019
1722
|
return parseUtil_1.INVALID;
|
|
2020
1723
|
}
|
|
2021
|
-
|
|
1724
|
+
const def = this._def;
|
|
2022
1725
|
if (def.minSize !== null) {
|
|
2023
1726
|
if (ctx.data.size < def.minSize.value) {
|
|
2024
1727
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
@@ -2043,67 +1746,62 @@ var ZodSet = /** @class */ (function (_super) {
|
|
|
2043
1746
|
status.dirty();
|
|
2044
1747
|
}
|
|
2045
1748
|
}
|
|
2046
|
-
|
|
1749
|
+
const valueType = this._def.valueType;
|
|
2047
1750
|
function finalizeSet(elements) {
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
if (element.status === "dirty")
|
|
2056
|
-
status.dirty();
|
|
2057
|
-
parsedSet.add(element.value);
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
2061
|
-
finally {
|
|
2062
|
-
try {
|
|
2063
|
-
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
2064
|
-
}
|
|
2065
|
-
finally { if (e_14) throw e_14.error; }
|
|
1751
|
+
const parsedSet = new Set();
|
|
1752
|
+
for (const element of elements) {
|
|
1753
|
+
if (element.status === "aborted")
|
|
1754
|
+
return parseUtil_1.INVALID;
|
|
1755
|
+
if (element.status === "dirty")
|
|
1756
|
+
status.dirty();
|
|
1757
|
+
parsedSet.add(element.value);
|
|
2066
1758
|
}
|
|
2067
1759
|
return { status: status.value, value: parsedSet };
|
|
2068
1760
|
}
|
|
2069
|
-
|
|
2070
|
-
return valueType._parse({ data: item, path: __spreadArray(__spreadArray([], __read(ctx.path), false), [i], false), parent: ctx });
|
|
2071
|
-
});
|
|
1761
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse({ data: item, path: [...ctx.path, i], parent: ctx }));
|
|
2072
1762
|
if (ctx.async) {
|
|
2073
|
-
return Promise.all(elements).then(
|
|
1763
|
+
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
|
2074
1764
|
}
|
|
2075
1765
|
else {
|
|
2076
1766
|
return finalizeSet(elements);
|
|
2077
1767
|
}
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
return new ZodSet(
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
}
|
|
2085
|
-
|
|
1768
|
+
}
|
|
1769
|
+
min(minSize, message) {
|
|
1770
|
+
return new ZodSet({
|
|
1771
|
+
...this._def,
|
|
1772
|
+
minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) },
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
max(maxSize, message) {
|
|
1776
|
+
return new ZodSet({
|
|
1777
|
+
...this._def,
|
|
1778
|
+
maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) },
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
size(size, message) {
|
|
2086
1782
|
return this.min(size, message).max(size, message);
|
|
2087
|
-
}
|
|
2088
|
-
|
|
1783
|
+
}
|
|
1784
|
+
nonempty(message) {
|
|
2089
1785
|
return this.min(1, message);
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
return new ZodSet(__assign({ valueType: valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet }, processCreateParams(params)));
|
|
2093
|
-
};
|
|
2094
|
-
return ZodSet;
|
|
2095
|
-
}(ZodType));
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
2096
1788
|
exports.ZodSet = ZodSet;
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
1789
|
+
ZodSet.create = (valueType, params) => {
|
|
1790
|
+
return new ZodSet({
|
|
1791
|
+
valueType,
|
|
1792
|
+
minSize: null,
|
|
1793
|
+
maxSize: null,
|
|
1794
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
1795
|
+
...processCreateParams(params),
|
|
1796
|
+
});
|
|
1797
|
+
};
|
|
1798
|
+
class ZodFunction extends ZodType {
|
|
1799
|
+
constructor() {
|
|
1800
|
+
super(...arguments);
|
|
1801
|
+
this.validate = this.implement;
|
|
1802
|
+
}
|
|
1803
|
+
_parse(input) {
|
|
1804
|
+
const { ctx } = this._processInputParams(input);
|
|
2107
1805
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.function) {
|
|
2108
1806
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2109
1807
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2121,7 +1819,7 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2121
1819
|
ctx.schemaErrorMap,
|
|
2122
1820
|
ZodError_1.overrideErrorMap,
|
|
2123
1821
|
ZodError_1.defaultErrorMap,
|
|
2124
|
-
].filter(
|
|
1822
|
+
].filter((x) => !!x),
|
|
2125
1823
|
issueData: {
|
|
2126
1824
|
code: ZodError_1.ZodIssueCode.invalid_arguments,
|
|
2127
1825
|
argumentsError: error,
|
|
@@ -2137,133 +1835,108 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2137
1835
|
ctx.schemaErrorMap,
|
|
2138
1836
|
ZodError_1.overrideErrorMap,
|
|
2139
1837
|
ZodError_1.defaultErrorMap,
|
|
2140
|
-
].filter(
|
|
1838
|
+
].filter((x) => !!x),
|
|
2141
1839
|
issueData: {
|
|
2142
1840
|
code: ZodError_1.ZodIssueCode.invalid_return_type,
|
|
2143
1841
|
returnTypeError: error,
|
|
2144
1842
|
},
|
|
2145
1843
|
});
|
|
2146
1844
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
1845
|
+
const params = { errorMap: ctx.contextualErrorMap };
|
|
1846
|
+
const fn = ctx.data;
|
|
2149
1847
|
if (this._def.returns instanceof ZodPromise) {
|
|
2150
|
-
return (0, parseUtil_1.OK)(
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
args
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
2165
|
-
throw error;
|
|
2166
|
-
})];
|
|
2167
|
-
case 1:
|
|
2168
|
-
parsedArgs = _a.sent();
|
|
2169
|
-
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2170
|
-
case 2:
|
|
2171
|
-
result = _a.sent();
|
|
2172
|
-
return [4 /*yield*/, this._def.returns._def.type
|
|
2173
|
-
.parseAsync(result, params)
|
|
2174
|
-
.catch(function (e) {
|
|
2175
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
2176
|
-
throw error;
|
|
2177
|
-
})];
|
|
2178
|
-
case 3:
|
|
2179
|
-
parsedReturns = _a.sent();
|
|
2180
|
-
return [2 /*return*/, parsedReturns];
|
|
2181
|
-
}
|
|
2182
|
-
});
|
|
1848
|
+
return (0, parseUtil_1.OK)(async (...args) => {
|
|
1849
|
+
const error = new ZodError_1.ZodError([]);
|
|
1850
|
+
const parsedArgs = await this._def.args
|
|
1851
|
+
.parseAsync(args, params)
|
|
1852
|
+
.catch((e) => {
|
|
1853
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
1854
|
+
throw error;
|
|
1855
|
+
});
|
|
1856
|
+
const result = await fn(...parsedArgs);
|
|
1857
|
+
const parsedReturns = await this._def.returns._def.type
|
|
1858
|
+
.parseAsync(result, params)
|
|
1859
|
+
.catch((e) => {
|
|
1860
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
1861
|
+
throw error;
|
|
2183
1862
|
});
|
|
1863
|
+
return parsedReturns;
|
|
2184
1864
|
});
|
|
2185
1865
|
}
|
|
2186
1866
|
else {
|
|
2187
|
-
return (0, parseUtil_1.OK)(
|
|
2188
|
-
|
|
2189
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2190
|
-
args[_i] = arguments[_i];
|
|
2191
|
-
}
|
|
2192
|
-
var parsedArgs = _this._def.args.safeParse(args, params);
|
|
1867
|
+
return (0, parseUtil_1.OK)((...args) => {
|
|
1868
|
+
const parsedArgs = this._def.args.safeParse(args, params);
|
|
2193
1869
|
if (!parsedArgs.success) {
|
|
2194
1870
|
throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2195
1871
|
}
|
|
2196
|
-
|
|
2197
|
-
|
|
1872
|
+
const result = fn(...parsedArgs.data);
|
|
1873
|
+
const parsedReturns = this._def.returns.safeParse(result, params);
|
|
2198
1874
|
if (!parsedReturns.success) {
|
|
2199
1875
|
throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2200
1876
|
}
|
|
2201
1877
|
return parsedReturns.data;
|
|
2202
1878
|
});
|
|
2203
1879
|
}
|
|
2204
|
-
}
|
|
2205
|
-
|
|
1880
|
+
}
|
|
1881
|
+
parameters() {
|
|
2206
1882
|
return this._def.args;
|
|
2207
|
-
}
|
|
2208
|
-
|
|
1883
|
+
}
|
|
1884
|
+
returnType() {
|
|
2209
1885
|
return this._def.returns;
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
items
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
1886
|
+
}
|
|
1887
|
+
args(...items) {
|
|
1888
|
+
return new ZodFunction({
|
|
1889
|
+
...this._def,
|
|
1890
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create()),
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
returns(returnType) {
|
|
1894
|
+
return new ZodFunction({
|
|
1895
|
+
...this._def,
|
|
1896
|
+
returns: returnType,
|
|
1897
|
+
});
|
|
1898
|
+
}
|
|
1899
|
+
implement(func) {
|
|
1900
|
+
const validatedFunc = this.parse(func);
|
|
2223
1901
|
return validatedFunc;
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
|
|
1902
|
+
}
|
|
1903
|
+
strictImplement(func) {
|
|
1904
|
+
const validatedFunc = this.parse(func);
|
|
2227
1905
|
return validatedFunc;
|
|
2228
|
-
}
|
|
2229
|
-
|
|
2230
|
-
return new ZodFunction(__assign({ args: (args
|
|
2231
|
-
? args.rest(ZodUnknown.create())
|
|
2232
|
-
: ZodTuple.create([]).rest(ZodUnknown.create())), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction }, processCreateParams(params)));
|
|
2233
|
-
};
|
|
2234
|
-
return ZodFunction;
|
|
2235
|
-
}(ZodType));
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
2236
1908
|
exports.ZodFunction = ZodFunction;
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
},
|
|
2246
|
-
enumerable: false,
|
|
2247
|
-
configurable: true
|
|
1909
|
+
ZodFunction.create = (args, returns, params) => {
|
|
1910
|
+
return new ZodFunction({
|
|
1911
|
+
args: (args
|
|
1912
|
+
? args.rest(ZodUnknown.create())
|
|
1913
|
+
: ZodTuple.create([]).rest(ZodUnknown.create())),
|
|
1914
|
+
returns: returns || ZodUnknown.create(),
|
|
1915
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
1916
|
+
...processCreateParams(params),
|
|
2248
1917
|
});
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
1918
|
+
};
|
|
1919
|
+
class ZodLazy extends ZodType {
|
|
1920
|
+
get schema() {
|
|
1921
|
+
return this._def.getter();
|
|
1922
|
+
}
|
|
1923
|
+
_parse(input) {
|
|
1924
|
+
const { ctx } = this._processInputParams(input);
|
|
1925
|
+
const lazySchema = this._def.getter();
|
|
2252
1926
|
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2253
|
-
};
|
|
2254
|
-
ZodLazy.create = function (getter, params) {
|
|
2255
|
-
return new ZodLazy(__assign({ getter: getter, typeName: ZodFirstPartyTypeKind.ZodLazy }, processCreateParams(params)));
|
|
2256
|
-
};
|
|
2257
|
-
return ZodLazy;
|
|
2258
|
-
}(ZodType));
|
|
2259
|
-
exports.ZodLazy = ZodLazy;
|
|
2260
|
-
var ZodLiteral = /** @class */ (function (_super) {
|
|
2261
|
-
__extends(ZodLiteral, _super);
|
|
2262
|
-
function ZodLiteral() {
|
|
2263
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2264
1927
|
}
|
|
2265
|
-
|
|
2266
|
-
|
|
1928
|
+
}
|
|
1929
|
+
exports.ZodLazy = ZodLazy;
|
|
1930
|
+
ZodLazy.create = (getter, params) => {
|
|
1931
|
+
return new ZodLazy({
|
|
1932
|
+
getter: getter,
|
|
1933
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
1934
|
+
...processCreateParams(params),
|
|
1935
|
+
});
|
|
1936
|
+
};
|
|
1937
|
+
class ZodLiteral extends ZodType {
|
|
1938
|
+
_parse(input) {
|
|
1939
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2267
1940
|
if (ctx.data !== this._def.value) {
|
|
2268
1941
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2269
1942
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2273,33 +1946,28 @@ var ZodLiteral = /** @class */ (function (_super) {
|
|
|
2273
1946
|
return parseUtil_1.INVALID;
|
|
2274
1947
|
}
|
|
2275
1948
|
return { status: status.value, value: ctx.data };
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
enumerable: false,
|
|
2282
|
-
configurable: true
|
|
2283
|
-
});
|
|
2284
|
-
ZodLiteral.create = function (value, params) {
|
|
2285
|
-
return new ZodLiteral(__assign({ value: value, typeName: ZodFirstPartyTypeKind.ZodLiteral }, processCreateParams(params)));
|
|
2286
|
-
};
|
|
2287
|
-
return ZodLiteral;
|
|
2288
|
-
}(ZodType));
|
|
1949
|
+
}
|
|
1950
|
+
get value() {
|
|
1951
|
+
return this._def.value;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
2289
1954
|
exports.ZodLiteral = ZodLiteral;
|
|
1955
|
+
ZodLiteral.create = (value, params) => {
|
|
1956
|
+
return new ZodLiteral({
|
|
1957
|
+
value: value,
|
|
1958
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
1959
|
+
...processCreateParams(params),
|
|
1960
|
+
});
|
|
1961
|
+
};
|
|
2290
1962
|
function createZodEnum(values) {
|
|
2291
1963
|
return new ZodEnum({
|
|
2292
1964
|
values: values,
|
|
2293
1965
|
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
2294
1966
|
});
|
|
2295
1967
|
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2300
|
-
}
|
|
2301
|
-
ZodEnum.prototype._parse = function (input) {
|
|
2302
|
-
var ctx = this._processInputParams(input).ctx;
|
|
1968
|
+
class ZodEnum extends ZodType {
|
|
1969
|
+
_parse(input) {
|
|
1970
|
+
const { ctx } = this._processInputParams(input);
|
|
2303
1971
|
if (this._def.values.indexOf(ctx.data) === -1) {
|
|
2304
1972
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2305
1973
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
@@ -2308,92 +1976,38 @@ var ZodEnum = /** @class */ (function (_super) {
|
|
|
2308
1976
|
return parseUtil_1.INVALID;
|
|
2309
1977
|
}
|
|
2310
1978
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
2311
|
-
}
|
|
2312
|
-
|
|
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
|
-
},
|
|
2338
|
-
enumerable: false,
|
|
2339
|
-
configurable: true
|
|
2340
|
-
});
|
|
2341
|
-
Object.defineProperty(ZodEnum.prototype, "Values", {
|
|
2342
|
-
get: function () {
|
|
2343
|
-
var e_16, _a;
|
|
2344
|
-
var enumValues = {};
|
|
2345
|
-
try {
|
|
2346
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2347
|
-
var val = _c.value;
|
|
2348
|
-
enumValues[val] = val;
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
2352
|
-
finally {
|
|
2353
|
-
try {
|
|
2354
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2355
|
-
}
|
|
2356
|
-
finally { if (e_16) throw e_16.error; }
|
|
2357
|
-
}
|
|
2358
|
-
return enumValues;
|
|
2359
|
-
},
|
|
2360
|
-
enumerable: false,
|
|
2361
|
-
configurable: true
|
|
2362
|
-
});
|
|
2363
|
-
Object.defineProperty(ZodEnum.prototype, "Enum", {
|
|
2364
|
-
get: function () {
|
|
2365
|
-
var e_17, _a;
|
|
2366
|
-
var enumValues = {};
|
|
2367
|
-
try {
|
|
2368
|
-
for (var _b = __values(this._def.values), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2369
|
-
var val = _c.value;
|
|
2370
|
-
enumValues[val] = val;
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
2374
|
-
finally {
|
|
2375
|
-
try {
|
|
2376
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2377
|
-
}
|
|
2378
|
-
finally { if (e_17) throw e_17.error; }
|
|
2379
|
-
}
|
|
2380
|
-
return enumValues;
|
|
2381
|
-
},
|
|
2382
|
-
enumerable: false,
|
|
2383
|
-
configurable: true
|
|
2384
|
-
});
|
|
2385
|
-
ZodEnum.create = createZodEnum;
|
|
2386
|
-
return ZodEnum;
|
|
2387
|
-
}(ZodType));
|
|
1979
|
+
}
|
|
1980
|
+
get options() {
|
|
1981
|
+
return this._def.values;
|
|
1982
|
+
}
|
|
1983
|
+
get enum() {
|
|
1984
|
+
const enumValues = {};
|
|
1985
|
+
for (const val of this._def.values) {
|
|
1986
|
+
enumValues[val] = val;
|
|
1987
|
+
}
|
|
1988
|
+
return enumValues;
|
|
1989
|
+
}
|
|
1990
|
+
get Values() {
|
|
1991
|
+
const enumValues = {};
|
|
1992
|
+
for (const val of this._def.values) {
|
|
1993
|
+
enumValues[val] = val;
|
|
1994
|
+
}
|
|
1995
|
+
return enumValues;
|
|
1996
|
+
}
|
|
1997
|
+
get Enum() {
|
|
1998
|
+
const enumValues = {};
|
|
1999
|
+
for (const val of this._def.values) {
|
|
2000
|
+
enumValues[val] = val;
|
|
2001
|
+
}
|
|
2002
|
+
return enumValues;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2388
2005
|
exports.ZodEnum = ZodEnum;
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
ZodNativeEnum.prototype._parse = function (input) {
|
|
2395
|
-
var ctx = this._processInputParams(input).ctx;
|
|
2396
|
-
var nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
|
|
2006
|
+
ZodEnum.create = createZodEnum;
|
|
2007
|
+
class ZodNativeEnum extends ZodType {
|
|
2008
|
+
_parse(input) {
|
|
2009
|
+
const { ctx } = this._processInputParams(input);
|
|
2010
|
+
const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
|
|
2397
2011
|
if (nativeEnumValues.indexOf(ctx.data) === -1) {
|
|
2398
2012
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2399
2013
|
code: ZodError_1.ZodIssueCode.invalid_enum_value,
|
|
@@ -2402,28 +2016,22 @@ var ZodNativeEnum = /** @class */ (function (_super) {
|
|
|
2402
2016
|
return parseUtil_1.INVALID;
|
|
2403
2017
|
}
|
|
2404
2018
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
enumerable: false,
|
|
2411
|
-
configurable: true
|
|
2412
|
-
});
|
|
2413
|
-
ZodNativeEnum.create = function (values, params) {
|
|
2414
|
-
return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
|
|
2415
|
-
};
|
|
2416
|
-
return ZodNativeEnum;
|
|
2417
|
-
}(ZodType));
|
|
2019
|
+
}
|
|
2020
|
+
get enum() {
|
|
2021
|
+
return this._def.values;
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2418
2024
|
exports.ZodNativeEnum = ZodNativeEnum;
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2025
|
+
ZodNativeEnum.create = (values, params) => {
|
|
2026
|
+
return new ZodNativeEnum({
|
|
2027
|
+
values: values,
|
|
2028
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
2029
|
+
...processCreateParams(params),
|
|
2030
|
+
});
|
|
2031
|
+
};
|
|
2032
|
+
class ZodPromise extends ZodType {
|
|
2033
|
+
_parse(input) {
|
|
2034
|
+
const { ctx } = this._processInputParams(input);
|
|
2427
2035
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.promise && ctx.async === false) {
|
|
2428
2036
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2429
2037
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2432,39 +2040,37 @@ var ZodPromise = /** @class */ (function (_super) {
|
|
|
2432
2040
|
});
|
|
2433
2041
|
return parseUtil_1.INVALID;
|
|
2434
2042
|
}
|
|
2435
|
-
|
|
2043
|
+
const promisified = ctx.parsedType === parseUtil_1.ZodParsedType.promise
|
|
2436
2044
|
? ctx.data
|
|
2437
2045
|
: Promise.resolve(ctx.data);
|
|
2438
|
-
return (0, parseUtil_1.OK)(promisified.then(
|
|
2439
|
-
return
|
|
2046
|
+
return (0, parseUtil_1.OK)(promisified.then((data) => {
|
|
2047
|
+
return this._def.type.parseAsync(data, {
|
|
2440
2048
|
path: ctx.path,
|
|
2441
2049
|
errorMap: ctx.contextualErrorMap,
|
|
2442
2050
|
});
|
|
2443
2051
|
}));
|
|
2444
|
-
};
|
|
2445
|
-
ZodPromise.create = function (schema, params) {
|
|
2446
|
-
return new ZodPromise(__assign({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise }, processCreateParams(params)));
|
|
2447
|
-
};
|
|
2448
|
-
return ZodPromise;
|
|
2449
|
-
}(ZodType));
|
|
2450
|
-
exports.ZodPromise = ZodPromise;
|
|
2451
|
-
var ZodEffects = /** @class */ (function (_super) {
|
|
2452
|
-
__extends(ZodEffects, _super);
|
|
2453
|
-
function ZodEffects() {
|
|
2454
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2455
2052
|
}
|
|
2456
|
-
|
|
2053
|
+
}
|
|
2054
|
+
exports.ZodPromise = ZodPromise;
|
|
2055
|
+
ZodPromise.create = (schema, params) => {
|
|
2056
|
+
return new ZodPromise({
|
|
2057
|
+
type: schema,
|
|
2058
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
2059
|
+
...processCreateParams(params),
|
|
2060
|
+
});
|
|
2061
|
+
};
|
|
2062
|
+
class ZodEffects extends ZodType {
|
|
2063
|
+
innerType() {
|
|
2457
2064
|
return this._def.schema;
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
var effect = this._def.effect || null;
|
|
2065
|
+
}
|
|
2066
|
+
_parse(input) {
|
|
2067
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2068
|
+
const effect = this._def.effect || null;
|
|
2463
2069
|
if (effect.type === "preprocess") {
|
|
2464
|
-
|
|
2070
|
+
const processed = effect.transform(ctx.data);
|
|
2465
2071
|
if (ctx.async) {
|
|
2466
|
-
return Promise.resolve(processed).then(
|
|
2467
|
-
return
|
|
2072
|
+
return Promise.resolve(processed).then((processed) => {
|
|
2073
|
+
return this._def.schema._parseAsync({
|
|
2468
2074
|
data: processed,
|
|
2469
2075
|
path: ctx.path,
|
|
2470
2076
|
parent: ctx,
|
|
@@ -2480,8 +2086,8 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2480
2086
|
}
|
|
2481
2087
|
}
|
|
2482
2088
|
if (effect.type === "refinement") {
|
|
2483
|
-
|
|
2484
|
-
addIssue:
|
|
2089
|
+
const checkCtx = {
|
|
2090
|
+
addIssue: (arg) => {
|
|
2485
2091
|
(0, parseUtil_1.addIssueToContext)(ctx, arg);
|
|
2486
2092
|
if (arg.fatal) {
|
|
2487
2093
|
status.abort();
|
|
@@ -2494,11 +2100,11 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2494
2100
|
return ctx.path;
|
|
2495
2101
|
},
|
|
2496
2102
|
};
|
|
2497
|
-
|
|
2498
|
-
|
|
2103
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2104
|
+
const executeRefinement = (acc
|
|
2499
2105
|
// effect: RefinementEffect<any>
|
|
2500
|
-
) {
|
|
2501
|
-
|
|
2106
|
+
) => {
|
|
2107
|
+
const result = effect.refinement(acc, checkCtx);
|
|
2502
2108
|
if (ctx.async) {
|
|
2503
2109
|
return Promise.resolve(result);
|
|
2504
2110
|
}
|
|
@@ -2508,7 +2114,7 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2508
2114
|
return acc;
|
|
2509
2115
|
};
|
|
2510
2116
|
if (ctx.async === false) {
|
|
2511
|
-
|
|
2117
|
+
const inner = this._def.schema._parseSync({
|
|
2512
2118
|
data: ctx.data,
|
|
2513
2119
|
path: ctx.path,
|
|
2514
2120
|
parent: ctx,
|
|
@@ -2518,18 +2124,18 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2518
2124
|
if (inner.status === "dirty")
|
|
2519
2125
|
status.dirty();
|
|
2520
2126
|
// return value is ignored
|
|
2521
|
-
|
|
2127
|
+
executeRefinement(inner.value);
|
|
2522
2128
|
return { status: status.value, value: inner.value };
|
|
2523
2129
|
}
|
|
2524
2130
|
else {
|
|
2525
2131
|
return this._def.schema
|
|
2526
2132
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
2527
|
-
.then(
|
|
2133
|
+
.then((inner) => {
|
|
2528
2134
|
if (inner.status === "aborted")
|
|
2529
2135
|
return parseUtil_1.INVALID;
|
|
2530
2136
|
if (inner.status === "dirty")
|
|
2531
2137
|
status.dirty();
|
|
2532
|
-
return
|
|
2138
|
+
return executeRefinement(inner.value).then(() => {
|
|
2533
2139
|
return { status: status.value, value: inner.value };
|
|
2534
2140
|
});
|
|
2535
2141
|
});
|
|
@@ -2537,7 +2143,7 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2537
2143
|
}
|
|
2538
2144
|
if (effect.type === "transform") {
|
|
2539
2145
|
if (ctx.async === false) {
|
|
2540
|
-
|
|
2146
|
+
const base = this._def.schema._parseSync({
|
|
2541
2147
|
data: ctx.data,
|
|
2542
2148
|
path: ctx.path,
|
|
2543
2149
|
parent: ctx,
|
|
@@ -2548,16 +2154,16 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2548
2154
|
// }
|
|
2549
2155
|
if (!(0, parseUtil_1.isValid)(base))
|
|
2550
2156
|
return base;
|
|
2551
|
-
|
|
2157
|
+
const result = effect.transform(base.value);
|
|
2552
2158
|
if (result instanceof Promise) {
|
|
2553
|
-
throw new Error(
|
|
2159
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2554
2160
|
}
|
|
2555
2161
|
return (0, parseUtil_1.OK)(result);
|
|
2556
2162
|
}
|
|
2557
2163
|
else {
|
|
2558
2164
|
return this._def.schema
|
|
2559
2165
|
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
2560
|
-
.then(
|
|
2166
|
+
.then((base) => {
|
|
2561
2167
|
if (!(0, parseUtil_1.isValid)(base))
|
|
2562
2168
|
return base;
|
|
2563
2169
|
// if (base.status === "aborted") return INVALID;
|
|
@@ -2569,24 +2175,29 @@ var ZodEffects = /** @class */ (function (_super) {
|
|
|
2569
2175
|
}
|
|
2570
2176
|
}
|
|
2571
2177
|
util_1.util.assertNever(effect);
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
return new ZodEffects(__assign({ schema: schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: effect }, processCreateParams(params)));
|
|
2575
|
-
};
|
|
2576
|
-
ZodEffects.createWithPreprocess = function (preprocess, schema, params) {
|
|
2577
|
-
return new ZodEffects(__assign({ schema: schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects }, processCreateParams(params)));
|
|
2578
|
-
};
|
|
2579
|
-
return ZodEffects;
|
|
2580
|
-
}(ZodType));
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2581
2180
|
exports.ZodEffects = ZodEffects;
|
|
2582
2181
|
exports.ZodTransformer = ZodEffects;
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2182
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
2183
|
+
return new ZodEffects({
|
|
2184
|
+
schema,
|
|
2185
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2186
|
+
effect,
|
|
2187
|
+
...processCreateParams(params),
|
|
2188
|
+
});
|
|
2189
|
+
};
|
|
2190
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
2191
|
+
return new ZodEffects({
|
|
2192
|
+
schema,
|
|
2193
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
2194
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
2195
|
+
...processCreateParams(params),
|
|
2196
|
+
});
|
|
2197
|
+
};
|
|
2198
|
+
class ZodOptional extends ZodType {
|
|
2199
|
+
_parse(input) {
|
|
2200
|
+
const { ctx } = this._processInputParams(input);
|
|
2590
2201
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
|
|
2591
2202
|
return (0, parseUtil_1.OK)(undefined);
|
|
2592
2203
|
}
|
|
@@ -2595,23 +2206,22 @@ var ZodOptional = /** @class */ (function (_super) {
|
|
|
2595
2206
|
path: ctx.path,
|
|
2596
2207
|
parent: ctx,
|
|
2597
2208
|
});
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2209
|
+
}
|
|
2210
|
+
unwrap() {
|
|
2600
2211
|
return this._def.innerType;
|
|
2601
|
-
};
|
|
2602
|
-
ZodOptional.create = function (type, params) {
|
|
2603
|
-
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
2604
|
-
};
|
|
2605
|
-
return ZodOptional;
|
|
2606
|
-
}(ZodType));
|
|
2607
|
-
exports.ZodOptional = ZodOptional;
|
|
2608
|
-
var ZodNullable = /** @class */ (function (_super) {
|
|
2609
|
-
__extends(ZodNullable, _super);
|
|
2610
|
-
function ZodNullable() {
|
|
2611
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2612
2212
|
}
|
|
2613
|
-
|
|
2614
|
-
|
|
2213
|
+
}
|
|
2214
|
+
exports.ZodOptional = ZodOptional;
|
|
2215
|
+
ZodOptional.create = (type, params) => {
|
|
2216
|
+
return new ZodOptional({
|
|
2217
|
+
innerType: type,
|
|
2218
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
2219
|
+
...processCreateParams(params),
|
|
2220
|
+
});
|
|
2221
|
+
};
|
|
2222
|
+
class ZodNullable extends ZodType {
|
|
2223
|
+
_parse(input) {
|
|
2224
|
+
const { ctx } = this._processInputParams(input);
|
|
2615
2225
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.null) {
|
|
2616
2226
|
return (0, parseUtil_1.OK)(null);
|
|
2617
2227
|
}
|
|
@@ -2620,49 +2230,47 @@ var ZodNullable = /** @class */ (function (_super) {
|
|
|
2620
2230
|
path: ctx.path,
|
|
2621
2231
|
parent: ctx,
|
|
2622
2232
|
});
|
|
2623
|
-
}
|
|
2624
|
-
|
|
2233
|
+
}
|
|
2234
|
+
unwrap() {
|
|
2625
2235
|
return this._def.innerType;
|
|
2626
|
-
}
|
|
2627
|
-
|
|
2628
|
-
return new ZodNullable(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable }, processCreateParams(params)));
|
|
2629
|
-
};
|
|
2630
|
-
return ZodNullable;
|
|
2631
|
-
}(ZodType));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2632
2238
|
exports.ZodNullable = ZodNullable;
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2239
|
+
ZodNullable.create = (type, params) => {
|
|
2240
|
+
return new ZodNullable({
|
|
2241
|
+
innerType: type,
|
|
2242
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
2243
|
+
...processCreateParams(params),
|
|
2244
|
+
});
|
|
2245
|
+
};
|
|
2246
|
+
class ZodDefault extends ZodType {
|
|
2247
|
+
_parse(input) {
|
|
2248
|
+
const { ctx } = this._processInputParams(input);
|
|
2249
|
+
let data = ctx.data;
|
|
2641
2250
|
if (ctx.parsedType === parseUtil_1.ZodParsedType.undefined) {
|
|
2642
2251
|
data = this._def.defaultValue();
|
|
2643
2252
|
}
|
|
2644
2253
|
return this._def.innerType._parse({
|
|
2645
|
-
data
|
|
2254
|
+
data,
|
|
2646
2255
|
path: ctx.path,
|
|
2647
2256
|
parent: ctx,
|
|
2648
2257
|
});
|
|
2649
|
-
}
|
|
2650
|
-
|
|
2258
|
+
}
|
|
2259
|
+
removeDefault() {
|
|
2651
2260
|
return this._def.innerType;
|
|
2652
|
-
};
|
|
2653
|
-
ZodDefault.create = function (type, params) {
|
|
2654
|
-
return new ZodOptional(__assign({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional }, processCreateParams(params)));
|
|
2655
|
-
};
|
|
2656
|
-
return ZodDefault;
|
|
2657
|
-
}(ZodType));
|
|
2658
|
-
exports.ZodDefault = ZodDefault;
|
|
2659
|
-
var ZodNaN = /** @class */ (function (_super) {
|
|
2660
|
-
__extends(ZodNaN, _super);
|
|
2661
|
-
function ZodNaN() {
|
|
2662
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2663
2261
|
}
|
|
2664
|
-
|
|
2665
|
-
|
|
2262
|
+
}
|
|
2263
|
+
exports.ZodDefault = ZodDefault;
|
|
2264
|
+
ZodDefault.create = (type, params) => {
|
|
2265
|
+
return new ZodOptional({
|
|
2266
|
+
innerType: type,
|
|
2267
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
2268
|
+
...processCreateParams(params),
|
|
2269
|
+
});
|
|
2270
|
+
};
|
|
2271
|
+
class ZodNaN extends ZodType {
|
|
2272
|
+
_parse(input) {
|
|
2273
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2666
2274
|
if (ctx.parsedType !== parseUtil_1.ZodParsedType.nan) {
|
|
2667
2275
|
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2668
2276
|
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
@@ -2672,14 +2280,16 @@ var ZodNaN = /** @class */ (function (_super) {
|
|
|
2672
2280
|
return parseUtil_1.INVALID;
|
|
2673
2281
|
}
|
|
2674
2282
|
return { status: status.value, value: ctx.data };
|
|
2675
|
-
}
|
|
2676
|
-
|
|
2677
|
-
return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
|
|
2678
|
-
};
|
|
2679
|
-
return ZodNaN;
|
|
2680
|
-
}(ZodType));
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2681
2285
|
exports.ZodNaN = ZodNaN;
|
|
2682
|
-
|
|
2286
|
+
ZodNaN.create = (params) => {
|
|
2287
|
+
return new ZodNaN({
|
|
2288
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
2289
|
+
...processCreateParams(params),
|
|
2290
|
+
});
|
|
2291
|
+
};
|
|
2292
|
+
const custom = (check, params) => {
|
|
2683
2293
|
if (check)
|
|
2684
2294
|
return ZodAny.create().refine(check, params);
|
|
2685
2295
|
return ZodAny.create();
|
|
@@ -2722,81 +2332,78 @@ var ZodFirstPartyTypeKind;
|
|
|
2722
2332
|
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
2723
2333
|
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
2724
2334
|
})(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
}; }
|
|
2729
|
-
return (0, exports.custom)(function (data) { return data instanceof cls; }, params);
|
|
2730
|
-
};
|
|
2335
|
+
const instanceOfType = (cls, params = {
|
|
2336
|
+
message: `Input not instance of ${cls.name}`,
|
|
2337
|
+
}) => (0, exports.custom)((data) => data instanceof cls, params);
|
|
2731
2338
|
exports.instanceof = instanceOfType;
|
|
2732
|
-
|
|
2339
|
+
const stringType = ZodString.create;
|
|
2733
2340
|
exports.string = stringType;
|
|
2734
|
-
|
|
2341
|
+
const numberType = ZodNumber.create;
|
|
2735
2342
|
exports.number = numberType;
|
|
2736
|
-
|
|
2343
|
+
const nanType = ZodNaN.create;
|
|
2737
2344
|
exports.nan = nanType;
|
|
2738
|
-
|
|
2345
|
+
const bigIntType = ZodBigInt.create;
|
|
2739
2346
|
exports.bigint = bigIntType;
|
|
2740
|
-
|
|
2347
|
+
const booleanType = ZodBoolean.create;
|
|
2741
2348
|
exports.boolean = booleanType;
|
|
2742
|
-
|
|
2349
|
+
const dateType = ZodDate.create;
|
|
2743
2350
|
exports.date = dateType;
|
|
2744
|
-
|
|
2351
|
+
const undefinedType = ZodUndefined.create;
|
|
2745
2352
|
exports.undefined = undefinedType;
|
|
2746
|
-
|
|
2353
|
+
const nullType = ZodNull.create;
|
|
2747
2354
|
exports.null = nullType;
|
|
2748
|
-
|
|
2355
|
+
const anyType = ZodAny.create;
|
|
2749
2356
|
exports.any = anyType;
|
|
2750
|
-
|
|
2357
|
+
const unknownType = ZodUnknown.create;
|
|
2751
2358
|
exports.unknown = unknownType;
|
|
2752
|
-
|
|
2359
|
+
const neverType = ZodNever.create;
|
|
2753
2360
|
exports.never = neverType;
|
|
2754
|
-
|
|
2361
|
+
const voidType = ZodVoid.create;
|
|
2755
2362
|
exports.void = voidType;
|
|
2756
|
-
|
|
2363
|
+
const arrayType = ZodArray.create;
|
|
2757
2364
|
exports.array = arrayType;
|
|
2758
|
-
|
|
2365
|
+
const objectType = ZodObject.create;
|
|
2759
2366
|
exports.object = objectType;
|
|
2760
|
-
|
|
2367
|
+
const strictObjectType = ZodObject.strictCreate;
|
|
2761
2368
|
exports.strictObject = strictObjectType;
|
|
2762
|
-
|
|
2369
|
+
const unionType = ZodUnion.create;
|
|
2763
2370
|
exports.union = unionType;
|
|
2764
|
-
|
|
2371
|
+
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
2765
2372
|
exports.discriminatedUnion = discriminatedUnionType;
|
|
2766
|
-
|
|
2373
|
+
const intersectionType = ZodIntersection.create;
|
|
2767
2374
|
exports.intersection = intersectionType;
|
|
2768
|
-
|
|
2375
|
+
const tupleType = ZodTuple.create;
|
|
2769
2376
|
exports.tuple = tupleType;
|
|
2770
|
-
|
|
2377
|
+
const recordType = ZodRecord.create;
|
|
2771
2378
|
exports.record = recordType;
|
|
2772
|
-
|
|
2379
|
+
const mapType = ZodMap.create;
|
|
2773
2380
|
exports.map = mapType;
|
|
2774
|
-
|
|
2381
|
+
const setType = ZodSet.create;
|
|
2775
2382
|
exports.set = setType;
|
|
2776
|
-
|
|
2383
|
+
const functionType = ZodFunction.create;
|
|
2777
2384
|
exports.function = functionType;
|
|
2778
|
-
|
|
2385
|
+
const lazyType = ZodLazy.create;
|
|
2779
2386
|
exports.lazy = lazyType;
|
|
2780
|
-
|
|
2387
|
+
const literalType = ZodLiteral.create;
|
|
2781
2388
|
exports.literal = literalType;
|
|
2782
|
-
|
|
2389
|
+
const enumType = ZodEnum.create;
|
|
2783
2390
|
exports.enum = enumType;
|
|
2784
|
-
|
|
2391
|
+
const nativeEnumType = ZodNativeEnum.create;
|
|
2785
2392
|
exports.nativeEnum = nativeEnumType;
|
|
2786
|
-
|
|
2393
|
+
const promiseType = ZodPromise.create;
|
|
2787
2394
|
exports.promise = promiseType;
|
|
2788
|
-
|
|
2395
|
+
const effectsType = ZodEffects.create;
|
|
2789
2396
|
exports.effect = effectsType;
|
|
2790
2397
|
exports.transformer = effectsType;
|
|
2791
|
-
|
|
2398
|
+
const optionalType = ZodOptional.create;
|
|
2792
2399
|
exports.optional = optionalType;
|
|
2793
|
-
|
|
2400
|
+
const nullableType = ZodNullable.create;
|
|
2794
2401
|
exports.nullable = nullableType;
|
|
2795
|
-
|
|
2402
|
+
const preprocessType = ZodEffects.createWithPreprocess;
|
|
2796
2403
|
exports.preprocess = preprocessType;
|
|
2797
|
-
|
|
2404
|
+
const ostring = () => stringType().optional();
|
|
2798
2405
|
exports.ostring = ostring;
|
|
2799
|
-
|
|
2406
|
+
const onumber = () => numberType().optional();
|
|
2800
2407
|
exports.onumber = onumber;
|
|
2801
|
-
|
|
2408
|
+
const oboolean = () => booleanType().optional();
|
|
2802
2409
|
exports.oboolean = oboolean;
|