@rspack/core 1.4.0-beta.1 → 1.4.0-rc.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 +1 -1
- package/dist/Module.d.ts +0 -1
- package/dist/builtin-loader/swc/pluginImport.d.ts +4 -26
- package/dist/builtin-loader/swc/types.d.ts +147 -2009
- package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +2 -1
- package/dist/config/normalization.d.ts +2 -1
- package/dist/config/types.d.ts +14 -3
- package/dist/config/utils.d.ts +3 -17
- package/dist/config/zod.d.ts +682 -4538
- package/dist/exports.d.ts +2 -1
- package/dist/index.js +3707 -1144
- package/dist/util/validate.d.ts +1 -1
- package/package.json +4 -4
- package/compiled/enhanced-resolve/CachedInputFileSystem.d.ts +0 -0
- package/compiled/enhanced-resolve/CachedInputFileSystem.js +0 -664
- package/compiled/enhanced-resolve/index.d.ts +0 -1124
- package/compiled/enhanced-resolve/license +0 -20
- package/compiled/enhanced-resolve/package.json +0 -1
- package/compiled/zod/dist/types/index.d.ts +0 -3
- package/compiled/zod/dist/types/v3/ZodError.d.ts +0 -164
- package/compiled/zod/dist/types/v3/benchmarks/datetime.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/discriminatedUnion.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/index.d.ts +0 -1
- package/compiled/zod/dist/types/v3/benchmarks/ipv4.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/object.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/primitives.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/realworld.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/string.d.ts +0 -5
- package/compiled/zod/dist/types/v3/benchmarks/union.d.ts +0 -5
- package/compiled/zod/dist/types/v3/errors.d.ts +0 -5
- package/compiled/zod/dist/types/v3/external.d.ts +0 -6
- package/compiled/zod/dist/types/v3/helpers/enumUtil.d.ts +0 -8
- package/compiled/zod/dist/types/v3/helpers/errorUtil.d.ts +0 -9
- package/compiled/zod/dist/types/v3/helpers/parseUtil.d.ts +0 -78
- package/compiled/zod/dist/types/v3/helpers/partialUtil.d.ts +0 -8
- package/compiled/zod/dist/types/v3/helpers/typeAliases.d.ts +0 -2
- package/compiled/zod/dist/types/v3/helpers/util.d.ts +0 -85
- package/compiled/zod/dist/types/v3/index.d.ts +0 -4
- package/compiled/zod/dist/types/v3/locales/en.d.ts +0 -3
- package/compiled/zod/dist/types/v3/standard-schema.d.ts +0 -102
- package/compiled/zod/dist/types/v3/tests/Mocker.d.ts +0 -17
- package/compiled/zod/dist/types/v3/types.d.ts +0 -1031
- package/compiled/zod/dist/types/v4/classic/checks.d.ts +0 -1
- package/compiled/zod/dist/types/v4/classic/coerce.d.ts +0 -17
- package/compiled/zod/dist/types/v4/classic/compat.d.ts +0 -48
- package/compiled/zod/dist/types/v4/classic/errors.d.ts +0 -30
- package/compiled/zod/dist/types/v4/classic/external.d.ts +0 -13
- package/compiled/zod/dist/types/v4/classic/index.d.ts +0 -4
- package/compiled/zod/dist/types/v4/classic/iso.d.ts +0 -22
- package/compiled/zod/dist/types/v4/classic/parse.d.ts +0 -23
- package/compiled/zod/dist/types/v4/classic/schemas.d.ts +0 -624
- package/compiled/zod/dist/types/v4/core/api.d.ts +0 -274
- package/compiled/zod/dist/types/v4/core/checks.d.ts +0 -277
- package/compiled/zod/dist/types/v4/core/config.d.ts +0 -9
- package/compiled/zod/dist/types/v4/core/core.d.ts +0 -47
- package/compiled/zod/dist/types/v4/core/doc.d.ts +0 -14
- package/compiled/zod/dist/types/v4/core/errors.d.ts +0 -204
- package/compiled/zod/dist/types/v4/core/function.d.ts +0 -52
- package/compiled/zod/dist/types/v4/core/index.d.ts +0 -15
- package/compiled/zod/dist/types/v4/core/json-schema.d.ts +0 -100
- package/compiled/zod/dist/types/v4/core/parse.d.ts +0 -25
- package/compiled/zod/dist/types/v4/core/regexes.d.ts +0 -62
- package/compiled/zod/dist/types/v4/core/registries.d.ts +0 -39
- package/compiled/zod/dist/types/v4/core/schemas.d.ts +0 -1005
- package/compiled/zod/dist/types/v4/core/standard-schema.d.ts +0 -55
- package/compiled/zod/dist/types/v4/core/to-json-schema.d.ts +0 -84
- package/compiled/zod/dist/types/v4/core/util.d.ts +0 -182
- package/compiled/zod/dist/types/v4/core/versions.d.ts +0 -5
- package/compiled/zod/dist/types/v4/core/zsf.d.ts +0 -91
- package/compiled/zod/dist/types/v4/index.d.ts +0 -3
- package/compiled/zod/dist/types/v4/locales/ar.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/az.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/be.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ca.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/cs.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/de.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/en.d.ts +0 -5
- package/compiled/zod/dist/types/v4/locales/es.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/fa.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/fi.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/fr-CA.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/fr.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/he.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/hu.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/id.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/index.d.ts +0 -38
- package/compiled/zod/dist/types/v4/locales/it.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ja.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/kh.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ko.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/mk.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ms.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/nl.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/no.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ota.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/pl.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ps.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/pt.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ru.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/sl.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/sv.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ta.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/th.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/tr.d.ts +0 -5
- package/compiled/zod/dist/types/v4/locales/ua.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/ur.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/vi.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/zh-CN.d.ts +0 -4
- package/compiled/zod/dist/types/v4/locales/zh-TW.d.ts +0 -4
- package/compiled/zod/dist/types/v4/mini/checks.d.ts +0 -1
- package/compiled/zod/dist/types/v4/mini/coerce.d.ts +0 -7
- package/compiled/zod/dist/types/v4/mini/external.d.ts +0 -11
- package/compiled/zod/dist/types/v4/mini/index.d.ts +0 -3
- package/compiled/zod/dist/types/v4/mini/iso.d.ts +0 -22
- package/compiled/zod/dist/types/v4/mini/parse.d.ts +0 -1
- package/compiled/zod/dist/types/v4/mini/schemas.d.ts +0 -350
- package/compiled/zod/index.js +0 -4513
- package/compiled/zod/license +0 -21
- package/compiled/zod/package.json +0 -1
- package/compiled/zod/v3/index.d.ts +0 -3
- package/compiled/zod/v4/core/index.d.ts +0 -1
- package/compiled/zod/v4/index.d.ts +0 -3
- package/compiled/zod/v4/locales/en.d.ts +0 -2
- package/compiled/zod/v4/locales/index.d.ts +0 -1
- package/compiled/zod/v4-mini/index.d.ts +0 -1
package/compiled/zod/index.js
DELETED
@@ -1,4513 +0,0 @@
|
|
1
|
-
/******/ (() => { // webpackBootstrap
|
2
|
-
/******/ "use strict";
|
3
|
-
/******/ var __webpack_modules__ = ({
|
4
|
-
|
5
|
-
/***/ 684:
|
6
|
-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
7
|
-
|
8
|
-
|
9
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
12
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
13
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
14
|
-
}
|
15
|
-
Object.defineProperty(o, k2, desc);
|
16
|
-
}) : (function(o, m, k, k2) {
|
17
|
-
if (k2 === undefined) k2 = k;
|
18
|
-
o[k2] = m[k];
|
19
|
-
}));
|
20
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
21
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
22
|
-
};
|
23
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
25
|
-
};
|
26
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
27
|
-
const index_js_1 = __importDefault(__nccwpck_require__(750));
|
28
|
-
__exportStar(__nccwpck_require__(750), exports);
|
29
|
-
exports["default"] = index_js_1.default;
|
30
|
-
|
31
|
-
|
32
|
-
/***/ }),
|
33
|
-
|
34
|
-
/***/ 757:
|
35
|
-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
36
|
-
|
37
|
-
|
38
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
39
|
-
exports.ZodError = exports.quotelessJson = exports.ZodIssueCode = void 0;
|
40
|
-
const util_js_1 = __nccwpck_require__(426);
|
41
|
-
exports.ZodIssueCode = util_js_1.util.arrayToEnum([
|
42
|
-
"invalid_type",
|
43
|
-
"invalid_literal",
|
44
|
-
"custom",
|
45
|
-
"invalid_union",
|
46
|
-
"invalid_union_discriminator",
|
47
|
-
"invalid_enum_value",
|
48
|
-
"unrecognized_keys",
|
49
|
-
"invalid_arguments",
|
50
|
-
"invalid_return_type",
|
51
|
-
"invalid_date",
|
52
|
-
"invalid_string",
|
53
|
-
"too_small",
|
54
|
-
"too_big",
|
55
|
-
"invalid_intersection_types",
|
56
|
-
"not_multiple_of",
|
57
|
-
"not_finite",
|
58
|
-
]);
|
59
|
-
const quotelessJson = (obj) => {
|
60
|
-
const json = JSON.stringify(obj, null, 2);
|
61
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
62
|
-
};
|
63
|
-
exports.quotelessJson = quotelessJson;
|
64
|
-
class ZodError extends Error {
|
65
|
-
get errors() {
|
66
|
-
return this.issues;
|
67
|
-
}
|
68
|
-
constructor(issues) {
|
69
|
-
super();
|
70
|
-
this.issues = [];
|
71
|
-
this.addIssue = (sub) => {
|
72
|
-
this.issues = [...this.issues, sub];
|
73
|
-
};
|
74
|
-
this.addIssues = (subs = []) => {
|
75
|
-
this.issues = [...this.issues, ...subs];
|
76
|
-
};
|
77
|
-
const actualProto = new.target.prototype;
|
78
|
-
if (Object.setPrototypeOf) {
|
79
|
-
// eslint-disable-next-line ban/ban
|
80
|
-
Object.setPrototypeOf(this, actualProto);
|
81
|
-
}
|
82
|
-
else {
|
83
|
-
this.__proto__ = actualProto;
|
84
|
-
}
|
85
|
-
this.name = "ZodError";
|
86
|
-
this.issues = issues;
|
87
|
-
}
|
88
|
-
format(_mapper) {
|
89
|
-
const mapper = _mapper ||
|
90
|
-
function (issue) {
|
91
|
-
return issue.message;
|
92
|
-
};
|
93
|
-
const fieldErrors = { _errors: [] };
|
94
|
-
const processError = (error) => {
|
95
|
-
for (const issue of error.issues) {
|
96
|
-
if (issue.code === "invalid_union") {
|
97
|
-
issue.unionErrors.map(processError);
|
98
|
-
}
|
99
|
-
else if (issue.code === "invalid_return_type") {
|
100
|
-
processError(issue.returnTypeError);
|
101
|
-
}
|
102
|
-
else if (issue.code === "invalid_arguments") {
|
103
|
-
processError(issue.argumentsError);
|
104
|
-
}
|
105
|
-
else if (issue.path.length === 0) {
|
106
|
-
fieldErrors._errors.push(mapper(issue));
|
107
|
-
}
|
108
|
-
else {
|
109
|
-
let curr = fieldErrors;
|
110
|
-
let i = 0;
|
111
|
-
while (i < issue.path.length) {
|
112
|
-
const el = issue.path[i];
|
113
|
-
const terminal = i === issue.path.length - 1;
|
114
|
-
if (!terminal) {
|
115
|
-
curr[el] = curr[el] || { _errors: [] };
|
116
|
-
// if (typeof el === "string") {
|
117
|
-
// curr[el] = curr[el] || { _errors: [] };
|
118
|
-
// } else if (typeof el === "number") {
|
119
|
-
// const errorArray: any = [];
|
120
|
-
// errorArray._errors = [];
|
121
|
-
// curr[el] = curr[el] || errorArray;
|
122
|
-
// }
|
123
|
-
}
|
124
|
-
else {
|
125
|
-
curr[el] = curr[el] || { _errors: [] };
|
126
|
-
curr[el]._errors.push(mapper(issue));
|
127
|
-
}
|
128
|
-
curr = curr[el];
|
129
|
-
i++;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
};
|
134
|
-
processError(this);
|
135
|
-
return fieldErrors;
|
136
|
-
}
|
137
|
-
static assert(value) {
|
138
|
-
if (!(value instanceof ZodError)) {
|
139
|
-
throw new Error(`Not a ZodError: ${value}`);
|
140
|
-
}
|
141
|
-
}
|
142
|
-
toString() {
|
143
|
-
return this.message;
|
144
|
-
}
|
145
|
-
get message() {
|
146
|
-
return JSON.stringify(this.issues, util_js_1.util.jsonStringifyReplacer, 2);
|
147
|
-
}
|
148
|
-
get isEmpty() {
|
149
|
-
return this.issues.length === 0;
|
150
|
-
}
|
151
|
-
flatten(mapper = (issue) => issue.message) {
|
152
|
-
const fieldErrors = {};
|
153
|
-
const formErrors = [];
|
154
|
-
for (const sub of this.issues) {
|
155
|
-
if (sub.path.length > 0) {
|
156
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
157
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
158
|
-
}
|
159
|
-
else {
|
160
|
-
formErrors.push(mapper(sub));
|
161
|
-
}
|
162
|
-
}
|
163
|
-
return { formErrors, fieldErrors };
|
164
|
-
}
|
165
|
-
get formErrors() {
|
166
|
-
return this.flatten();
|
167
|
-
}
|
168
|
-
}
|
169
|
-
exports.ZodError = ZodError;
|
170
|
-
ZodError.create = (issues) => {
|
171
|
-
const error = new ZodError(issues);
|
172
|
-
return error;
|
173
|
-
};
|
174
|
-
|
175
|
-
|
176
|
-
/***/ }),
|
177
|
-
|
178
|
-
/***/ 995:
|
179
|
-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
180
|
-
|
181
|
-
|
182
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
183
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
184
|
-
};
|
185
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
186
|
-
exports.defaultErrorMap = void 0;
|
187
|
-
exports.setErrorMap = setErrorMap;
|
188
|
-
exports.getErrorMap = getErrorMap;
|
189
|
-
const en_js_1 = __importDefault(__nccwpck_require__(947));
|
190
|
-
exports.defaultErrorMap = en_js_1.default;
|
191
|
-
let overrideErrorMap = en_js_1.default;
|
192
|
-
function setErrorMap(map) {
|
193
|
-
overrideErrorMap = map;
|
194
|
-
}
|
195
|
-
function getErrorMap() {
|
196
|
-
return overrideErrorMap;
|
197
|
-
}
|
198
|
-
|
199
|
-
|
200
|
-
/***/ }),
|
201
|
-
|
202
|
-
/***/ 979:
|
203
|
-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
204
|
-
|
205
|
-
|
206
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
207
|
-
if (k2 === undefined) k2 = k;
|
208
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
209
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
210
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
211
|
-
}
|
212
|
-
Object.defineProperty(o, k2, desc);
|
213
|
-
}) : (function(o, m, k, k2) {
|
214
|
-
if (k2 === undefined) k2 = k;
|
215
|
-
o[k2] = m[k];
|
216
|
-
}));
|
217
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
218
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
219
|
-
};
|
220
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
221
|
-
__exportStar(__nccwpck_require__(995), exports);
|
222
|
-
__exportStar(__nccwpck_require__(335), exports);
|
223
|
-
__exportStar(__nccwpck_require__(404), exports);
|
224
|
-
__exportStar(__nccwpck_require__(426), exports);
|
225
|
-
__exportStar(__nccwpck_require__(227), exports);
|
226
|
-
__exportStar(__nccwpck_require__(757), exports);
|
227
|
-
|
228
|
-
|
229
|
-
/***/ }),
|
230
|
-
|
231
|
-
/***/ 54:
|
232
|
-
/***/ ((__unused_webpack_module, exports) => {
|
233
|
-
|
234
|
-
|
235
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
236
|
-
exports.errorUtil = void 0;
|
237
|
-
var errorUtil;
|
238
|
-
(function (errorUtil) {
|
239
|
-
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
240
|
-
// biome-ignore lint:
|
241
|
-
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
242
|
-
})(errorUtil || (exports.errorUtil = errorUtil = {}));
|
243
|
-
|
244
|
-
|
245
|
-
/***/ }),
|
246
|
-
|
247
|
-
/***/ 335:
|
248
|
-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
249
|
-
|
250
|
-
|
251
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
252
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
253
|
-
};
|
254
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
255
|
-
exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.EMPTY_PATH = exports.makeIssue = void 0;
|
256
|
-
exports.addIssueToContext = addIssueToContext;
|
257
|
-
const errors_js_1 = __nccwpck_require__(995);
|
258
|
-
const en_js_1 = __importDefault(__nccwpck_require__(947));
|
259
|
-
const makeIssue = (params) => {
|
260
|
-
const { data, path, errorMaps, issueData } = params;
|
261
|
-
const fullPath = [...path, ...(issueData.path || [])];
|
262
|
-
const fullIssue = {
|
263
|
-
...issueData,
|
264
|
-
path: fullPath,
|
265
|
-
};
|
266
|
-
if (issueData.message !== undefined) {
|
267
|
-
return {
|
268
|
-
...issueData,
|
269
|
-
path: fullPath,
|
270
|
-
message: issueData.message,
|
271
|
-
};
|
272
|
-
}
|
273
|
-
let errorMessage = "";
|
274
|
-
const maps = errorMaps
|
275
|
-
.filter((m) => !!m)
|
276
|
-
.slice()
|
277
|
-
.reverse();
|
278
|
-
for (const map of maps) {
|
279
|
-
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
280
|
-
}
|
281
|
-
return {
|
282
|
-
...issueData,
|
283
|
-
path: fullPath,
|
284
|
-
message: errorMessage,
|
285
|
-
};
|
286
|
-
};
|
287
|
-
exports.makeIssue = makeIssue;
|
288
|
-
exports.EMPTY_PATH = [];
|
289
|
-
function addIssueToContext(ctx, issueData) {
|
290
|
-
const overrideMap = (0, errors_js_1.getErrorMap)();
|
291
|
-
const issue = (0, exports.makeIssue)({
|
292
|
-
issueData: issueData,
|
293
|
-
data: ctx.data,
|
294
|
-
path: ctx.path,
|
295
|
-
errorMaps: [
|
296
|
-
ctx.common.contextualErrorMap, // contextual error map is first priority
|
297
|
-
ctx.schemaErrorMap, // then schema-bound map if available
|
298
|
-
overrideMap, // then global override map
|
299
|
-
overrideMap === en_js_1.default ? undefined : en_js_1.default, // then global default map
|
300
|
-
].filter((x) => !!x),
|
301
|
-
});
|
302
|
-
ctx.common.issues.push(issue);
|
303
|
-
}
|
304
|
-
class ParseStatus {
|
305
|
-
constructor() {
|
306
|
-
this.value = "valid";
|
307
|
-
}
|
308
|
-
dirty() {
|
309
|
-
if (this.value === "valid")
|
310
|
-
this.value = "dirty";
|
311
|
-
}
|
312
|
-
abort() {
|
313
|
-
if (this.value !== "aborted")
|
314
|
-
this.value = "aborted";
|
315
|
-
}
|
316
|
-
static mergeArray(status, results) {
|
317
|
-
const arrayValue = [];
|
318
|
-
for (const s of results) {
|
319
|
-
if (s.status === "aborted")
|
320
|
-
return exports.INVALID;
|
321
|
-
if (s.status === "dirty")
|
322
|
-
status.dirty();
|
323
|
-
arrayValue.push(s.value);
|
324
|
-
}
|
325
|
-
return { status: status.value, value: arrayValue };
|
326
|
-
}
|
327
|
-
static async mergeObjectAsync(status, pairs) {
|
328
|
-
const syncPairs = [];
|
329
|
-
for (const pair of pairs) {
|
330
|
-
const key = await pair.key;
|
331
|
-
const value = await pair.value;
|
332
|
-
syncPairs.push({
|
333
|
-
key,
|
334
|
-
value,
|
335
|
-
});
|
336
|
-
}
|
337
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
338
|
-
}
|
339
|
-
static mergeObjectSync(status, pairs) {
|
340
|
-
const finalObject = {};
|
341
|
-
for (const pair of pairs) {
|
342
|
-
const { key, value } = pair;
|
343
|
-
if (key.status === "aborted")
|
344
|
-
return exports.INVALID;
|
345
|
-
if (value.status === "aborted")
|
346
|
-
return exports.INVALID;
|
347
|
-
if (key.status === "dirty")
|
348
|
-
status.dirty();
|
349
|
-
if (value.status === "dirty")
|
350
|
-
status.dirty();
|
351
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
352
|
-
finalObject[key.value] = value.value;
|
353
|
-
}
|
354
|
-
}
|
355
|
-
return { status: status.value, value: finalObject };
|
356
|
-
}
|
357
|
-
}
|
358
|
-
exports.ParseStatus = ParseStatus;
|
359
|
-
exports.INVALID = Object.freeze({
|
360
|
-
status: "aborted",
|
361
|
-
});
|
362
|
-
const DIRTY = (value) => ({ status: "dirty", value });
|
363
|
-
exports.DIRTY = DIRTY;
|
364
|
-
const OK = (value) => ({ status: "valid", value });
|
365
|
-
exports.OK = OK;
|
366
|
-
const isAborted = (x) => x.status === "aborted";
|
367
|
-
exports.isAborted = isAborted;
|
368
|
-
const isDirty = (x) => x.status === "dirty";
|
369
|
-
exports.isDirty = isDirty;
|
370
|
-
const isValid = (x) => x.status === "valid";
|
371
|
-
exports.isValid = isValid;
|
372
|
-
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
373
|
-
exports.isAsync = isAsync;
|
374
|
-
|
375
|
-
|
376
|
-
/***/ }),
|
377
|
-
|
378
|
-
/***/ 404:
|
379
|
-
/***/ ((__unused_webpack_module, exports) => {
|
380
|
-
|
381
|
-
|
382
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
383
|
-
|
384
|
-
|
385
|
-
/***/ }),
|
386
|
-
|
387
|
-
/***/ 426:
|
388
|
-
/***/ ((__unused_webpack_module, exports) => {
|
389
|
-
|
390
|
-
|
391
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
392
|
-
exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
|
393
|
-
var util;
|
394
|
-
(function (util) {
|
395
|
-
util.assertEqual = (_) => { };
|
396
|
-
function assertIs(_arg) { }
|
397
|
-
util.assertIs = assertIs;
|
398
|
-
function assertNever(_x) {
|
399
|
-
throw new Error();
|
400
|
-
}
|
401
|
-
util.assertNever = assertNever;
|
402
|
-
util.arrayToEnum = (items) => {
|
403
|
-
const obj = {};
|
404
|
-
for (const item of items) {
|
405
|
-
obj[item] = item;
|
406
|
-
}
|
407
|
-
return obj;
|
408
|
-
};
|
409
|
-
util.getValidEnumValues = (obj) => {
|
410
|
-
const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
411
|
-
const filtered = {};
|
412
|
-
for (const k of validKeys) {
|
413
|
-
filtered[k] = obj[k];
|
414
|
-
}
|
415
|
-
return util.objectValues(filtered);
|
416
|
-
};
|
417
|
-
util.objectValues = (obj) => {
|
418
|
-
return util.objectKeys(obj).map(function (e) {
|
419
|
-
return obj[e];
|
420
|
-
});
|
421
|
-
};
|
422
|
-
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
423
|
-
? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
|
424
|
-
: (object) => {
|
425
|
-
const keys = [];
|
426
|
-
for (const key in object) {
|
427
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
428
|
-
keys.push(key);
|
429
|
-
}
|
430
|
-
}
|
431
|
-
return keys;
|
432
|
-
};
|
433
|
-
util.find = (arr, checker) => {
|
434
|
-
for (const item of arr) {
|
435
|
-
if (checker(item))
|
436
|
-
return item;
|
437
|
-
}
|
438
|
-
return undefined;
|
439
|
-
};
|
440
|
-
util.isInteger = typeof Number.isInteger === "function"
|
441
|
-
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
442
|
-
: (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
443
|
-
function joinValues(array, separator = " | ") {
|
444
|
-
return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
|
445
|
-
}
|
446
|
-
util.joinValues = joinValues;
|
447
|
-
util.jsonStringifyReplacer = (_, value) => {
|
448
|
-
if (typeof value === "bigint") {
|
449
|
-
return value.toString();
|
450
|
-
}
|
451
|
-
return value;
|
452
|
-
};
|
453
|
-
})(util || (exports.util = util = {}));
|
454
|
-
var objectUtil;
|
455
|
-
(function (objectUtil) {
|
456
|
-
objectUtil.mergeShapes = (first, second) => {
|
457
|
-
return {
|
458
|
-
...first,
|
459
|
-
...second, // second overwrites first
|
460
|
-
};
|
461
|
-
};
|
462
|
-
})(objectUtil || (exports.objectUtil = objectUtil = {}));
|
463
|
-
exports.ZodParsedType = util.arrayToEnum([
|
464
|
-
"string",
|
465
|
-
"nan",
|
466
|
-
"number",
|
467
|
-
"integer",
|
468
|
-
"float",
|
469
|
-
"boolean",
|
470
|
-
"date",
|
471
|
-
"bigint",
|
472
|
-
"symbol",
|
473
|
-
"function",
|
474
|
-
"undefined",
|
475
|
-
"null",
|
476
|
-
"array",
|
477
|
-
"object",
|
478
|
-
"unknown",
|
479
|
-
"promise",
|
480
|
-
"void",
|
481
|
-
"never",
|
482
|
-
"map",
|
483
|
-
"set",
|
484
|
-
]);
|
485
|
-
const getParsedType = (data) => {
|
486
|
-
const t = typeof data;
|
487
|
-
switch (t) {
|
488
|
-
case "undefined":
|
489
|
-
return exports.ZodParsedType.undefined;
|
490
|
-
case "string":
|
491
|
-
return exports.ZodParsedType.string;
|
492
|
-
case "number":
|
493
|
-
return Number.isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
|
494
|
-
case "boolean":
|
495
|
-
return exports.ZodParsedType.boolean;
|
496
|
-
case "function":
|
497
|
-
return exports.ZodParsedType.function;
|
498
|
-
case "bigint":
|
499
|
-
return exports.ZodParsedType.bigint;
|
500
|
-
case "symbol":
|
501
|
-
return exports.ZodParsedType.symbol;
|
502
|
-
case "object":
|
503
|
-
if (Array.isArray(data)) {
|
504
|
-
return exports.ZodParsedType.array;
|
505
|
-
}
|
506
|
-
if (data === null) {
|
507
|
-
return exports.ZodParsedType.null;
|
508
|
-
}
|
509
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
510
|
-
return exports.ZodParsedType.promise;
|
511
|
-
}
|
512
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
513
|
-
return exports.ZodParsedType.map;
|
514
|
-
}
|
515
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
516
|
-
return exports.ZodParsedType.set;
|
517
|
-
}
|
518
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
519
|
-
return exports.ZodParsedType.date;
|
520
|
-
}
|
521
|
-
return exports.ZodParsedType.object;
|
522
|
-
default:
|
523
|
-
return exports.ZodParsedType.unknown;
|
524
|
-
}
|
525
|
-
};
|
526
|
-
exports.getParsedType = getParsedType;
|
527
|
-
|
528
|
-
|
529
|
-
/***/ }),
|
530
|
-
|
531
|
-
/***/ 750:
|
532
|
-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
533
|
-
|
534
|
-
|
535
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
536
|
-
if (k2 === undefined) k2 = k;
|
537
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
538
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
539
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
540
|
-
}
|
541
|
-
Object.defineProperty(o, k2, desc);
|
542
|
-
}) : (function(o, m, k, k2) {
|
543
|
-
if (k2 === undefined) k2 = k;
|
544
|
-
o[k2] = m[k];
|
545
|
-
}));
|
546
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
547
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
548
|
-
}) : function(o, v) {
|
549
|
-
o["default"] = v;
|
550
|
-
});
|
551
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
552
|
-
if (mod && mod.__esModule) return mod;
|
553
|
-
var result = {};
|
554
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
555
|
-
__setModuleDefault(result, mod);
|
556
|
-
return result;
|
557
|
-
};
|
558
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
559
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
560
|
-
};
|
561
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
562
|
-
exports.z = void 0;
|
563
|
-
const z = __importStar(__nccwpck_require__(979));
|
564
|
-
exports.z = z;
|
565
|
-
__exportStar(__nccwpck_require__(979), exports);
|
566
|
-
exports["default"] = z;
|
567
|
-
|
568
|
-
|
569
|
-
/***/ }),
|
570
|
-
|
571
|
-
/***/ 947:
|
572
|
-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
573
|
-
|
574
|
-
|
575
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
576
|
-
const ZodError_js_1 = __nccwpck_require__(757);
|
577
|
-
const util_js_1 = __nccwpck_require__(426);
|
578
|
-
const errorMap = (issue, _ctx) => {
|
579
|
-
let message;
|
580
|
-
switch (issue.code) {
|
581
|
-
case ZodError_js_1.ZodIssueCode.invalid_type:
|
582
|
-
if (issue.received === util_js_1.ZodParsedType.undefined) {
|
583
|
-
message = "Required";
|
584
|
-
}
|
585
|
-
else {
|
586
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
587
|
-
}
|
588
|
-
break;
|
589
|
-
case ZodError_js_1.ZodIssueCode.invalid_literal:
|
590
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_js_1.util.jsonStringifyReplacer)}`;
|
591
|
-
break;
|
592
|
-
case ZodError_js_1.ZodIssueCode.unrecognized_keys:
|
593
|
-
message = `Unrecognized key(s) in object: ${util_js_1.util.joinValues(issue.keys, ", ")}`;
|
594
|
-
break;
|
595
|
-
case ZodError_js_1.ZodIssueCode.invalid_union:
|
596
|
-
message = `Invalid input`;
|
597
|
-
break;
|
598
|
-
case ZodError_js_1.ZodIssueCode.invalid_union_discriminator:
|
599
|
-
message = `Invalid discriminator value. Expected ${util_js_1.util.joinValues(issue.options)}`;
|
600
|
-
break;
|
601
|
-
case ZodError_js_1.ZodIssueCode.invalid_enum_value:
|
602
|
-
message = `Invalid enum value. Expected ${util_js_1.util.joinValues(issue.options)}, received '${issue.received}'`;
|
603
|
-
break;
|
604
|
-
case ZodError_js_1.ZodIssueCode.invalid_arguments:
|
605
|
-
message = `Invalid function arguments`;
|
606
|
-
break;
|
607
|
-
case ZodError_js_1.ZodIssueCode.invalid_return_type:
|
608
|
-
message = `Invalid function return type`;
|
609
|
-
break;
|
610
|
-
case ZodError_js_1.ZodIssueCode.invalid_date:
|
611
|
-
message = `Invalid date`;
|
612
|
-
break;
|
613
|
-
case ZodError_js_1.ZodIssueCode.invalid_string:
|
614
|
-
if (typeof issue.validation === "object") {
|
615
|
-
if ("includes" in issue.validation) {
|
616
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
617
|
-
if (typeof issue.validation.position === "number") {
|
618
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
619
|
-
}
|
620
|
-
}
|
621
|
-
else if ("startsWith" in issue.validation) {
|
622
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
623
|
-
}
|
624
|
-
else if ("endsWith" in issue.validation) {
|
625
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
626
|
-
}
|
627
|
-
else {
|
628
|
-
util_js_1.util.assertNever(issue.validation);
|
629
|
-
}
|
630
|
-
}
|
631
|
-
else if (issue.validation !== "regex") {
|
632
|
-
message = `Invalid ${issue.validation}`;
|
633
|
-
}
|
634
|
-
else {
|
635
|
-
message = "Invalid";
|
636
|
-
}
|
637
|
-
break;
|
638
|
-
case ZodError_js_1.ZodIssueCode.too_small:
|
639
|
-
if (issue.type === "array")
|
640
|
-
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
641
|
-
else if (issue.type === "string")
|
642
|
-
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
643
|
-
else if (issue.type === "number")
|
644
|
-
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
645
|
-
else if (issue.type === "date")
|
646
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
647
|
-
else
|
648
|
-
message = "Invalid input";
|
649
|
-
break;
|
650
|
-
case ZodError_js_1.ZodIssueCode.too_big:
|
651
|
-
if (issue.type === "array")
|
652
|
-
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
653
|
-
else if (issue.type === "string")
|
654
|
-
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
655
|
-
else if (issue.type === "number")
|
656
|
-
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
657
|
-
else if (issue.type === "bigint")
|
658
|
-
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
659
|
-
else if (issue.type === "date")
|
660
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
661
|
-
else
|
662
|
-
message = "Invalid input";
|
663
|
-
break;
|
664
|
-
case ZodError_js_1.ZodIssueCode.custom:
|
665
|
-
message = `Invalid input`;
|
666
|
-
break;
|
667
|
-
case ZodError_js_1.ZodIssueCode.invalid_intersection_types:
|
668
|
-
message = `Intersection results could not be merged`;
|
669
|
-
break;
|
670
|
-
case ZodError_js_1.ZodIssueCode.not_multiple_of:
|
671
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
672
|
-
break;
|
673
|
-
case ZodError_js_1.ZodIssueCode.not_finite:
|
674
|
-
message = "Number must be finite";
|
675
|
-
break;
|
676
|
-
default:
|
677
|
-
message = _ctx.defaultError;
|
678
|
-
util_js_1.util.assertNever(issue);
|
679
|
-
}
|
680
|
-
return { message };
|
681
|
-
};
|
682
|
-
exports["default"] = errorMap;
|
683
|
-
|
684
|
-
|
685
|
-
/***/ }),
|
686
|
-
|
687
|
-
/***/ 227:
|
688
|
-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
689
|
-
|
690
|
-
|
691
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
692
|
-
exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = 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.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
|
693
|
-
exports.NEVER = exports["void"] = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = 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 = exports.intersection = exports["instanceof"] = exports["function"] = exports["enum"] = exports.effect = void 0;
|
694
|
-
exports.datetimeRegex = datetimeRegex;
|
695
|
-
exports.custom = custom;
|
696
|
-
const ZodError_js_1 = __nccwpck_require__(757);
|
697
|
-
const errors_js_1 = __nccwpck_require__(995);
|
698
|
-
const errorUtil_js_1 = __nccwpck_require__(54);
|
699
|
-
const parseUtil_js_1 = __nccwpck_require__(335);
|
700
|
-
const util_js_1 = __nccwpck_require__(426);
|
701
|
-
class ParseInputLazyPath {
|
702
|
-
constructor(parent, value, path, key) {
|
703
|
-
this._cachedPath = [];
|
704
|
-
this.parent = parent;
|
705
|
-
this.data = value;
|
706
|
-
this._path = path;
|
707
|
-
this._key = key;
|
708
|
-
}
|
709
|
-
get path() {
|
710
|
-
if (!this._cachedPath.length) {
|
711
|
-
if (Array.isArray(this._key)) {
|
712
|
-
this._cachedPath.push(...this._path, ...this._key);
|
713
|
-
}
|
714
|
-
else {
|
715
|
-
this._cachedPath.push(...this._path, this._key);
|
716
|
-
}
|
717
|
-
}
|
718
|
-
return this._cachedPath;
|
719
|
-
}
|
720
|
-
}
|
721
|
-
const handleResult = (ctx, result) => {
|
722
|
-
if ((0, parseUtil_js_1.isValid)(result)) {
|
723
|
-
return { success: true, data: result.value };
|
724
|
-
}
|
725
|
-
else {
|
726
|
-
if (!ctx.common.issues.length) {
|
727
|
-
throw new Error("Validation failed but no issues detected.");
|
728
|
-
}
|
729
|
-
return {
|
730
|
-
success: false,
|
731
|
-
get error() {
|
732
|
-
if (this._error)
|
733
|
-
return this._error;
|
734
|
-
const error = new ZodError_js_1.ZodError(ctx.common.issues);
|
735
|
-
this._error = error;
|
736
|
-
return this._error;
|
737
|
-
},
|
738
|
-
};
|
739
|
-
}
|
740
|
-
};
|
741
|
-
function processCreateParams(params) {
|
742
|
-
if (!params)
|
743
|
-
return {};
|
744
|
-
const { errorMap, invalid_type_error, required_error, description } = params;
|
745
|
-
if (errorMap && (invalid_type_error || required_error)) {
|
746
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
747
|
-
}
|
748
|
-
if (errorMap)
|
749
|
-
return { errorMap: errorMap, description };
|
750
|
-
const customMap = (iss, ctx) => {
|
751
|
-
const { message } = params;
|
752
|
-
if (iss.code === "invalid_enum_value") {
|
753
|
-
return { message: message ?? ctx.defaultError };
|
754
|
-
}
|
755
|
-
if (typeof ctx.data === "undefined") {
|
756
|
-
return { message: message ?? required_error ?? ctx.defaultError };
|
757
|
-
}
|
758
|
-
if (iss.code !== "invalid_type")
|
759
|
-
return { message: ctx.defaultError };
|
760
|
-
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
761
|
-
};
|
762
|
-
return { errorMap: customMap, description };
|
763
|
-
}
|
764
|
-
class ZodType {
|
765
|
-
get description() {
|
766
|
-
return this._def.description;
|
767
|
-
}
|
768
|
-
_getType(input) {
|
769
|
-
return (0, util_js_1.getParsedType)(input.data);
|
770
|
-
}
|
771
|
-
_getOrReturnCtx(input, ctx) {
|
772
|
-
return (ctx || {
|
773
|
-
common: input.parent.common,
|
774
|
-
data: input.data,
|
775
|
-
parsedType: (0, util_js_1.getParsedType)(input.data),
|
776
|
-
schemaErrorMap: this._def.errorMap,
|
777
|
-
path: input.path,
|
778
|
-
parent: input.parent,
|
779
|
-
});
|
780
|
-
}
|
781
|
-
_processInputParams(input) {
|
782
|
-
return {
|
783
|
-
status: new parseUtil_js_1.ParseStatus(),
|
784
|
-
ctx: {
|
785
|
-
common: input.parent.common,
|
786
|
-
data: input.data,
|
787
|
-
parsedType: (0, util_js_1.getParsedType)(input.data),
|
788
|
-
schemaErrorMap: this._def.errorMap,
|
789
|
-
path: input.path,
|
790
|
-
parent: input.parent,
|
791
|
-
},
|
792
|
-
};
|
793
|
-
}
|
794
|
-
_parseSync(input) {
|
795
|
-
const result = this._parse(input);
|
796
|
-
if ((0, parseUtil_js_1.isAsync)(result)) {
|
797
|
-
throw new Error("Synchronous parse encountered promise.");
|
798
|
-
}
|
799
|
-
return result;
|
800
|
-
}
|
801
|
-
_parseAsync(input) {
|
802
|
-
const result = this._parse(input);
|
803
|
-
return Promise.resolve(result);
|
804
|
-
}
|
805
|
-
parse(data, params) {
|
806
|
-
const result = this.safeParse(data, params);
|
807
|
-
if (result.success)
|
808
|
-
return result.data;
|
809
|
-
throw result.error;
|
810
|
-
}
|
811
|
-
safeParse(data, params) {
|
812
|
-
const ctx = {
|
813
|
-
common: {
|
814
|
-
issues: [],
|
815
|
-
async: params?.async ?? false,
|
816
|
-
contextualErrorMap: params?.errorMap,
|
817
|
-
},
|
818
|
-
path: params?.path || [],
|
819
|
-
schemaErrorMap: this._def.errorMap,
|
820
|
-
parent: null,
|
821
|
-
data,
|
822
|
-
parsedType: (0, util_js_1.getParsedType)(data),
|
823
|
-
};
|
824
|
-
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
825
|
-
return handleResult(ctx, result);
|
826
|
-
}
|
827
|
-
"~validate"(data) {
|
828
|
-
const ctx = {
|
829
|
-
common: {
|
830
|
-
issues: [],
|
831
|
-
async: !!this["~standard"].async,
|
832
|
-
},
|
833
|
-
path: [],
|
834
|
-
schemaErrorMap: this._def.errorMap,
|
835
|
-
parent: null,
|
836
|
-
data,
|
837
|
-
parsedType: (0, util_js_1.getParsedType)(data),
|
838
|
-
};
|
839
|
-
if (!this["~standard"].async) {
|
840
|
-
try {
|
841
|
-
const result = this._parseSync({ data, path: [], parent: ctx });
|
842
|
-
return (0, parseUtil_js_1.isValid)(result)
|
843
|
-
? {
|
844
|
-
value: result.value,
|
845
|
-
}
|
846
|
-
: {
|
847
|
-
issues: ctx.common.issues,
|
848
|
-
};
|
849
|
-
}
|
850
|
-
catch (err) {
|
851
|
-
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
852
|
-
this["~standard"].async = true;
|
853
|
-
}
|
854
|
-
ctx.common = {
|
855
|
-
issues: [],
|
856
|
-
async: true,
|
857
|
-
};
|
858
|
-
}
|
859
|
-
}
|
860
|
-
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => (0, parseUtil_js_1.isValid)(result)
|
861
|
-
? {
|
862
|
-
value: result.value,
|
863
|
-
}
|
864
|
-
: {
|
865
|
-
issues: ctx.common.issues,
|
866
|
-
});
|
867
|
-
}
|
868
|
-
async parseAsync(data, params) {
|
869
|
-
const result = await this.safeParseAsync(data, params);
|
870
|
-
if (result.success)
|
871
|
-
return result.data;
|
872
|
-
throw result.error;
|
873
|
-
}
|
874
|
-
async safeParseAsync(data, params) {
|
875
|
-
const ctx = {
|
876
|
-
common: {
|
877
|
-
issues: [],
|
878
|
-
contextualErrorMap: params?.errorMap,
|
879
|
-
async: true,
|
880
|
-
},
|
881
|
-
path: params?.path || [],
|
882
|
-
schemaErrorMap: this._def.errorMap,
|
883
|
-
parent: null,
|
884
|
-
data,
|
885
|
-
parsedType: (0, util_js_1.getParsedType)(data),
|
886
|
-
};
|
887
|
-
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
888
|
-
const result = await ((0, parseUtil_js_1.isAsync)(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
889
|
-
return handleResult(ctx, result);
|
890
|
-
}
|
891
|
-
refine(check, message) {
|
892
|
-
const getIssueProperties = (val) => {
|
893
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
894
|
-
return { message };
|
895
|
-
}
|
896
|
-
else if (typeof message === "function") {
|
897
|
-
return message(val);
|
898
|
-
}
|
899
|
-
else {
|
900
|
-
return message;
|
901
|
-
}
|
902
|
-
};
|
903
|
-
return this._refinement((val, ctx) => {
|
904
|
-
const result = check(val);
|
905
|
-
const setError = () => ctx.addIssue({
|
906
|
-
code: ZodError_js_1.ZodIssueCode.custom,
|
907
|
-
...getIssueProperties(val),
|
908
|
-
});
|
909
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
910
|
-
return result.then((data) => {
|
911
|
-
if (!data) {
|
912
|
-
setError();
|
913
|
-
return false;
|
914
|
-
}
|
915
|
-
else {
|
916
|
-
return true;
|
917
|
-
}
|
918
|
-
});
|
919
|
-
}
|
920
|
-
if (!result) {
|
921
|
-
setError();
|
922
|
-
return false;
|
923
|
-
}
|
924
|
-
else {
|
925
|
-
return true;
|
926
|
-
}
|
927
|
-
});
|
928
|
-
}
|
929
|
-
refinement(check, refinementData) {
|
930
|
-
return this._refinement((val, ctx) => {
|
931
|
-
if (!check(val)) {
|
932
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
933
|
-
return false;
|
934
|
-
}
|
935
|
-
else {
|
936
|
-
return true;
|
937
|
-
}
|
938
|
-
});
|
939
|
-
}
|
940
|
-
_refinement(refinement) {
|
941
|
-
return new ZodEffects({
|
942
|
-
schema: this,
|
943
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
944
|
-
effect: { type: "refinement", refinement },
|
945
|
-
});
|
946
|
-
}
|
947
|
-
superRefine(refinement) {
|
948
|
-
return this._refinement(refinement);
|
949
|
-
}
|
950
|
-
constructor(def) {
|
951
|
-
/** Alias of safeParseAsync */
|
952
|
-
this.spa = this.safeParseAsync;
|
953
|
-
this._def = def;
|
954
|
-
this.parse = this.parse.bind(this);
|
955
|
-
this.safeParse = this.safeParse.bind(this);
|
956
|
-
this.parseAsync = this.parseAsync.bind(this);
|
957
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
958
|
-
this.spa = this.spa.bind(this);
|
959
|
-
this.refine = this.refine.bind(this);
|
960
|
-
this.refinement = this.refinement.bind(this);
|
961
|
-
this.superRefine = this.superRefine.bind(this);
|
962
|
-
this.optional = this.optional.bind(this);
|
963
|
-
this.nullable = this.nullable.bind(this);
|
964
|
-
this.nullish = this.nullish.bind(this);
|
965
|
-
this.array = this.array.bind(this);
|
966
|
-
this.promise = this.promise.bind(this);
|
967
|
-
this.or = this.or.bind(this);
|
968
|
-
this.and = this.and.bind(this);
|
969
|
-
this.transform = this.transform.bind(this);
|
970
|
-
this.brand = this.brand.bind(this);
|
971
|
-
this.default = this.default.bind(this);
|
972
|
-
this.catch = this.catch.bind(this);
|
973
|
-
this.describe = this.describe.bind(this);
|
974
|
-
this.pipe = this.pipe.bind(this);
|
975
|
-
this.readonly = this.readonly.bind(this);
|
976
|
-
this.isNullable = this.isNullable.bind(this);
|
977
|
-
this.isOptional = this.isOptional.bind(this);
|
978
|
-
this["~standard"] = {
|
979
|
-
version: 1,
|
980
|
-
vendor: "zod",
|
981
|
-
validate: (data) => this["~validate"](data),
|
982
|
-
};
|
983
|
-
}
|
984
|
-
optional() {
|
985
|
-
return ZodOptional.create(this, this._def);
|
986
|
-
}
|
987
|
-
nullable() {
|
988
|
-
return ZodNullable.create(this, this._def);
|
989
|
-
}
|
990
|
-
nullish() {
|
991
|
-
return this.nullable().optional();
|
992
|
-
}
|
993
|
-
array() {
|
994
|
-
return ZodArray.create(this);
|
995
|
-
}
|
996
|
-
promise() {
|
997
|
-
return ZodPromise.create(this, this._def);
|
998
|
-
}
|
999
|
-
or(option) {
|
1000
|
-
return ZodUnion.create([this, option], this._def);
|
1001
|
-
}
|
1002
|
-
and(incoming) {
|
1003
|
-
return ZodIntersection.create(this, incoming, this._def);
|
1004
|
-
}
|
1005
|
-
transform(transform) {
|
1006
|
-
return new ZodEffects({
|
1007
|
-
...processCreateParams(this._def),
|
1008
|
-
schema: this,
|
1009
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
1010
|
-
effect: { type: "transform", transform },
|
1011
|
-
});
|
1012
|
-
}
|
1013
|
-
default(def) {
|
1014
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
1015
|
-
return new ZodDefault({
|
1016
|
-
...processCreateParams(this._def),
|
1017
|
-
innerType: this,
|
1018
|
-
defaultValue: defaultValueFunc,
|
1019
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
1020
|
-
});
|
1021
|
-
}
|
1022
|
-
brand() {
|
1023
|
-
return new ZodBranded({
|
1024
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
1025
|
-
type: this,
|
1026
|
-
...processCreateParams(this._def),
|
1027
|
-
});
|
1028
|
-
}
|
1029
|
-
catch(def) {
|
1030
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
1031
|
-
return new ZodCatch({
|
1032
|
-
...processCreateParams(this._def),
|
1033
|
-
innerType: this,
|
1034
|
-
catchValue: catchValueFunc,
|
1035
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
1036
|
-
});
|
1037
|
-
}
|
1038
|
-
describe(description) {
|
1039
|
-
const This = this.constructor;
|
1040
|
-
return new This({
|
1041
|
-
...this._def,
|
1042
|
-
description,
|
1043
|
-
});
|
1044
|
-
}
|
1045
|
-
pipe(target) {
|
1046
|
-
return ZodPipeline.create(this, target);
|
1047
|
-
}
|
1048
|
-
readonly() {
|
1049
|
-
return ZodReadonly.create(this);
|
1050
|
-
}
|
1051
|
-
isOptional() {
|
1052
|
-
return this.safeParse(undefined).success;
|
1053
|
-
}
|
1054
|
-
isNullable() {
|
1055
|
-
return this.safeParse(null).success;
|
1056
|
-
}
|
1057
|
-
}
|
1058
|
-
exports.ZodType = ZodType;
|
1059
|
-
exports.Schema = ZodType;
|
1060
|
-
exports.ZodSchema = ZodType;
|
1061
|
-
const cuidRegex = /^c[^\s-]{8,}$/i;
|
1062
|
-
const cuid2Regex = /^[0-9a-z]+$/;
|
1063
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
1064
|
-
// const uuidRegex =
|
1065
|
-
// /^([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;
|
1066
|
-
const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
1067
|
-
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
1068
|
-
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
1069
|
-
const durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
1070
|
-
// from https://stackoverflow.com/a/46181/1550155
|
1071
|
-
// old version: too slow, didn't support unicode
|
1072
|
-
// 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;
|
1073
|
-
//old email regex
|
1074
|
-
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
1075
|
-
// eslint-disable-next-line
|
1076
|
-
// const emailRegex =
|
1077
|
-
// /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
|
1078
|
-
// const emailRegex =
|
1079
|
-
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
1080
|
-
// const emailRegex =
|
1081
|
-
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
1082
|
-
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
1083
|
-
// const emailRegex =
|
1084
|
-
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
1085
|
-
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
1086
|
-
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
1087
|
-
let emojiRegex;
|
1088
|
-
// faster, simpler, safer
|
1089
|
-
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
1090
|
-
const ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
1091
|
-
// const ipv6Regex =
|
1092
|
-
// /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
1093
|
-
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
1094
|
-
const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
1095
|
-
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
1096
|
-
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
1097
|
-
// https://base64.guru/standards/base64url
|
1098
|
-
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
1099
|
-
// simple
|
1100
|
-
// const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
|
1101
|
-
// no leap year validation
|
1102
|
-
// const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
|
1103
|
-
// with leap year validation
|
1104
|
-
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
1105
|
-
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
1106
|
-
function timeRegexSource(args) {
|
1107
|
-
let secondsRegexSource = `[0-5]\\d`;
|
1108
|
-
if (args.precision) {
|
1109
|
-
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
1110
|
-
}
|
1111
|
-
else if (args.precision == null) {
|
1112
|
-
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
1113
|
-
}
|
1114
|
-
const secondsQuantifier = args.precision ? "+" : "?"; // require seconds if precision is nonzero
|
1115
|
-
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
1116
|
-
}
|
1117
|
-
function timeRegex(args) {
|
1118
|
-
return new RegExp(`^${timeRegexSource(args)}$`);
|
1119
|
-
}
|
1120
|
-
// Adapted from https://stackoverflow.com/a/3143231
|
1121
|
-
function datetimeRegex(args) {
|
1122
|
-
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
1123
|
-
const opts = [];
|
1124
|
-
opts.push(args.local ? `Z?` : `Z`);
|
1125
|
-
if (args.offset)
|
1126
|
-
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
1127
|
-
regex = `${regex}(${opts.join("|")})`;
|
1128
|
-
return new RegExp(`^${regex}$`);
|
1129
|
-
}
|
1130
|
-
function isValidIP(ip, version) {
|
1131
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
1132
|
-
return true;
|
1133
|
-
}
|
1134
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
1135
|
-
return true;
|
1136
|
-
}
|
1137
|
-
return false;
|
1138
|
-
}
|
1139
|
-
function isValidJWT(jwt, alg) {
|
1140
|
-
if (!jwtRegex.test(jwt))
|
1141
|
-
return false;
|
1142
|
-
try {
|
1143
|
-
const [header] = jwt.split(".");
|
1144
|
-
// Convert base64url to base64
|
1145
|
-
const base64 = header
|
1146
|
-
.replace(/-/g, "+")
|
1147
|
-
.replace(/_/g, "/")
|
1148
|
-
.padEnd(header.length + ((4 - (header.length % 4)) % 4), "=");
|
1149
|
-
const decoded = JSON.parse(atob(base64));
|
1150
|
-
if (typeof decoded !== "object" || decoded === null)
|
1151
|
-
return false;
|
1152
|
-
if ("typ" in decoded && decoded?.typ !== "JWT")
|
1153
|
-
return false;
|
1154
|
-
if (!decoded.alg)
|
1155
|
-
return false;
|
1156
|
-
if (alg && decoded.alg !== alg)
|
1157
|
-
return false;
|
1158
|
-
return true;
|
1159
|
-
}
|
1160
|
-
catch {
|
1161
|
-
return false;
|
1162
|
-
}
|
1163
|
-
}
|
1164
|
-
function isValidCidr(ip, version) {
|
1165
|
-
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
1166
|
-
return true;
|
1167
|
-
}
|
1168
|
-
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
1169
|
-
return true;
|
1170
|
-
}
|
1171
|
-
return false;
|
1172
|
-
}
|
1173
|
-
class ZodString extends ZodType {
|
1174
|
-
_parse(input) {
|
1175
|
-
if (this._def.coerce) {
|
1176
|
-
input.data = String(input.data);
|
1177
|
-
}
|
1178
|
-
const parsedType = this._getType(input);
|
1179
|
-
if (parsedType !== util_js_1.ZodParsedType.string) {
|
1180
|
-
const ctx = this._getOrReturnCtx(input);
|
1181
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1182
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
1183
|
-
expected: util_js_1.ZodParsedType.string,
|
1184
|
-
received: ctx.parsedType,
|
1185
|
-
});
|
1186
|
-
return parseUtil_js_1.INVALID;
|
1187
|
-
}
|
1188
|
-
const status = new parseUtil_js_1.ParseStatus();
|
1189
|
-
let ctx = undefined;
|
1190
|
-
for (const check of this._def.checks) {
|
1191
|
-
if (check.kind === "min") {
|
1192
|
-
if (input.data.length < check.value) {
|
1193
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1194
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1195
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
1196
|
-
minimum: check.value,
|
1197
|
-
type: "string",
|
1198
|
-
inclusive: true,
|
1199
|
-
exact: false,
|
1200
|
-
message: check.message,
|
1201
|
-
});
|
1202
|
-
status.dirty();
|
1203
|
-
}
|
1204
|
-
}
|
1205
|
-
else if (check.kind === "max") {
|
1206
|
-
if (input.data.length > check.value) {
|
1207
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1208
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1209
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
1210
|
-
maximum: check.value,
|
1211
|
-
type: "string",
|
1212
|
-
inclusive: true,
|
1213
|
-
exact: false,
|
1214
|
-
message: check.message,
|
1215
|
-
});
|
1216
|
-
status.dirty();
|
1217
|
-
}
|
1218
|
-
}
|
1219
|
-
else if (check.kind === "length") {
|
1220
|
-
const tooBig = input.data.length > check.value;
|
1221
|
-
const tooSmall = input.data.length < check.value;
|
1222
|
-
if (tooBig || tooSmall) {
|
1223
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1224
|
-
if (tooBig) {
|
1225
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1226
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
1227
|
-
maximum: check.value,
|
1228
|
-
type: "string",
|
1229
|
-
inclusive: true,
|
1230
|
-
exact: true,
|
1231
|
-
message: check.message,
|
1232
|
-
});
|
1233
|
-
}
|
1234
|
-
else if (tooSmall) {
|
1235
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1236
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
1237
|
-
minimum: check.value,
|
1238
|
-
type: "string",
|
1239
|
-
inclusive: true,
|
1240
|
-
exact: true,
|
1241
|
-
message: check.message,
|
1242
|
-
});
|
1243
|
-
}
|
1244
|
-
status.dirty();
|
1245
|
-
}
|
1246
|
-
}
|
1247
|
-
else if (check.kind === "email") {
|
1248
|
-
if (!emailRegex.test(input.data)) {
|
1249
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1250
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1251
|
-
validation: "email",
|
1252
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1253
|
-
message: check.message,
|
1254
|
-
});
|
1255
|
-
status.dirty();
|
1256
|
-
}
|
1257
|
-
}
|
1258
|
-
else if (check.kind === "emoji") {
|
1259
|
-
if (!emojiRegex) {
|
1260
|
-
emojiRegex = new RegExp(_emojiRegex, "u");
|
1261
|
-
}
|
1262
|
-
if (!emojiRegex.test(input.data)) {
|
1263
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1264
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1265
|
-
validation: "emoji",
|
1266
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1267
|
-
message: check.message,
|
1268
|
-
});
|
1269
|
-
status.dirty();
|
1270
|
-
}
|
1271
|
-
}
|
1272
|
-
else if (check.kind === "uuid") {
|
1273
|
-
if (!uuidRegex.test(input.data)) {
|
1274
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1275
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1276
|
-
validation: "uuid",
|
1277
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1278
|
-
message: check.message,
|
1279
|
-
});
|
1280
|
-
status.dirty();
|
1281
|
-
}
|
1282
|
-
}
|
1283
|
-
else if (check.kind === "nanoid") {
|
1284
|
-
if (!nanoidRegex.test(input.data)) {
|
1285
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1286
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1287
|
-
validation: "nanoid",
|
1288
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1289
|
-
message: check.message,
|
1290
|
-
});
|
1291
|
-
status.dirty();
|
1292
|
-
}
|
1293
|
-
}
|
1294
|
-
else if (check.kind === "cuid") {
|
1295
|
-
if (!cuidRegex.test(input.data)) {
|
1296
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1297
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1298
|
-
validation: "cuid",
|
1299
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1300
|
-
message: check.message,
|
1301
|
-
});
|
1302
|
-
status.dirty();
|
1303
|
-
}
|
1304
|
-
}
|
1305
|
-
else if (check.kind === "cuid2") {
|
1306
|
-
if (!cuid2Regex.test(input.data)) {
|
1307
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1308
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1309
|
-
validation: "cuid2",
|
1310
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1311
|
-
message: check.message,
|
1312
|
-
});
|
1313
|
-
status.dirty();
|
1314
|
-
}
|
1315
|
-
}
|
1316
|
-
else if (check.kind === "ulid") {
|
1317
|
-
if (!ulidRegex.test(input.data)) {
|
1318
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1319
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1320
|
-
validation: "ulid",
|
1321
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1322
|
-
message: check.message,
|
1323
|
-
});
|
1324
|
-
status.dirty();
|
1325
|
-
}
|
1326
|
-
}
|
1327
|
-
else if (check.kind === "url") {
|
1328
|
-
try {
|
1329
|
-
new URL(input.data);
|
1330
|
-
}
|
1331
|
-
catch {
|
1332
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1333
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1334
|
-
validation: "url",
|
1335
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1336
|
-
message: check.message,
|
1337
|
-
});
|
1338
|
-
status.dirty();
|
1339
|
-
}
|
1340
|
-
}
|
1341
|
-
else if (check.kind === "regex") {
|
1342
|
-
check.regex.lastIndex = 0;
|
1343
|
-
const testResult = check.regex.test(input.data);
|
1344
|
-
if (!testResult) {
|
1345
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1346
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1347
|
-
validation: "regex",
|
1348
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1349
|
-
message: check.message,
|
1350
|
-
});
|
1351
|
-
status.dirty();
|
1352
|
-
}
|
1353
|
-
}
|
1354
|
-
else if (check.kind === "trim") {
|
1355
|
-
input.data = input.data.trim();
|
1356
|
-
}
|
1357
|
-
else if (check.kind === "includes") {
|
1358
|
-
if (!input.data.includes(check.value, check.position)) {
|
1359
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1360
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1361
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1362
|
-
validation: { includes: check.value, position: check.position },
|
1363
|
-
message: check.message,
|
1364
|
-
});
|
1365
|
-
status.dirty();
|
1366
|
-
}
|
1367
|
-
}
|
1368
|
-
else if (check.kind === "toLowerCase") {
|
1369
|
-
input.data = input.data.toLowerCase();
|
1370
|
-
}
|
1371
|
-
else if (check.kind === "toUpperCase") {
|
1372
|
-
input.data = input.data.toUpperCase();
|
1373
|
-
}
|
1374
|
-
else if (check.kind === "startsWith") {
|
1375
|
-
if (!input.data.startsWith(check.value)) {
|
1376
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1377
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1378
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1379
|
-
validation: { startsWith: check.value },
|
1380
|
-
message: check.message,
|
1381
|
-
});
|
1382
|
-
status.dirty();
|
1383
|
-
}
|
1384
|
-
}
|
1385
|
-
else if (check.kind === "endsWith") {
|
1386
|
-
if (!input.data.endsWith(check.value)) {
|
1387
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1388
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1389
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1390
|
-
validation: { endsWith: check.value },
|
1391
|
-
message: check.message,
|
1392
|
-
});
|
1393
|
-
status.dirty();
|
1394
|
-
}
|
1395
|
-
}
|
1396
|
-
else if (check.kind === "datetime") {
|
1397
|
-
const regex = datetimeRegex(check);
|
1398
|
-
if (!regex.test(input.data)) {
|
1399
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1400
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1401
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1402
|
-
validation: "datetime",
|
1403
|
-
message: check.message,
|
1404
|
-
});
|
1405
|
-
status.dirty();
|
1406
|
-
}
|
1407
|
-
}
|
1408
|
-
else if (check.kind === "date") {
|
1409
|
-
const regex = dateRegex;
|
1410
|
-
if (!regex.test(input.data)) {
|
1411
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1412
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1413
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1414
|
-
validation: "date",
|
1415
|
-
message: check.message,
|
1416
|
-
});
|
1417
|
-
status.dirty();
|
1418
|
-
}
|
1419
|
-
}
|
1420
|
-
else if (check.kind === "time") {
|
1421
|
-
const regex = timeRegex(check);
|
1422
|
-
if (!regex.test(input.data)) {
|
1423
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1424
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1425
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1426
|
-
validation: "time",
|
1427
|
-
message: check.message,
|
1428
|
-
});
|
1429
|
-
status.dirty();
|
1430
|
-
}
|
1431
|
-
}
|
1432
|
-
else if (check.kind === "duration") {
|
1433
|
-
if (!durationRegex.test(input.data)) {
|
1434
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1435
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1436
|
-
validation: "duration",
|
1437
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1438
|
-
message: check.message,
|
1439
|
-
});
|
1440
|
-
status.dirty();
|
1441
|
-
}
|
1442
|
-
}
|
1443
|
-
else if (check.kind === "ip") {
|
1444
|
-
if (!isValidIP(input.data, check.version)) {
|
1445
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1446
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1447
|
-
validation: "ip",
|
1448
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1449
|
-
message: check.message,
|
1450
|
-
});
|
1451
|
-
status.dirty();
|
1452
|
-
}
|
1453
|
-
}
|
1454
|
-
else if (check.kind === "jwt") {
|
1455
|
-
if (!isValidJWT(input.data, check.alg)) {
|
1456
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1457
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1458
|
-
validation: "jwt",
|
1459
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1460
|
-
message: check.message,
|
1461
|
-
});
|
1462
|
-
status.dirty();
|
1463
|
-
}
|
1464
|
-
}
|
1465
|
-
else if (check.kind === "cidr") {
|
1466
|
-
if (!isValidCidr(input.data, check.version)) {
|
1467
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1468
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1469
|
-
validation: "cidr",
|
1470
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1471
|
-
message: check.message,
|
1472
|
-
});
|
1473
|
-
status.dirty();
|
1474
|
-
}
|
1475
|
-
}
|
1476
|
-
else if (check.kind === "base64") {
|
1477
|
-
if (!base64Regex.test(input.data)) {
|
1478
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1479
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1480
|
-
validation: "base64",
|
1481
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1482
|
-
message: check.message,
|
1483
|
-
});
|
1484
|
-
status.dirty();
|
1485
|
-
}
|
1486
|
-
}
|
1487
|
-
else if (check.kind === "base64url") {
|
1488
|
-
if (!base64urlRegex.test(input.data)) {
|
1489
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1490
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1491
|
-
validation: "base64url",
|
1492
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1493
|
-
message: check.message,
|
1494
|
-
});
|
1495
|
-
status.dirty();
|
1496
|
-
}
|
1497
|
-
}
|
1498
|
-
else {
|
1499
|
-
util_js_1.util.assertNever(check);
|
1500
|
-
}
|
1501
|
-
}
|
1502
|
-
return { status: status.value, value: input.data };
|
1503
|
-
}
|
1504
|
-
_regex(regex, validation, message) {
|
1505
|
-
return this.refinement((data) => regex.test(data), {
|
1506
|
-
validation,
|
1507
|
-
code: ZodError_js_1.ZodIssueCode.invalid_string,
|
1508
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1509
|
-
});
|
1510
|
-
}
|
1511
|
-
_addCheck(check) {
|
1512
|
-
return new ZodString({
|
1513
|
-
...this._def,
|
1514
|
-
checks: [...this._def.checks, check],
|
1515
|
-
});
|
1516
|
-
}
|
1517
|
-
email(message) {
|
1518
|
-
return this._addCheck({ kind: "email", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1519
|
-
}
|
1520
|
-
url(message) {
|
1521
|
-
return this._addCheck({ kind: "url", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1522
|
-
}
|
1523
|
-
emoji(message) {
|
1524
|
-
return this._addCheck({ kind: "emoji", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1525
|
-
}
|
1526
|
-
uuid(message) {
|
1527
|
-
return this._addCheck({ kind: "uuid", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1528
|
-
}
|
1529
|
-
nanoid(message) {
|
1530
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1531
|
-
}
|
1532
|
-
cuid(message) {
|
1533
|
-
return this._addCheck({ kind: "cuid", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1534
|
-
}
|
1535
|
-
cuid2(message) {
|
1536
|
-
return this._addCheck({ kind: "cuid2", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1537
|
-
}
|
1538
|
-
ulid(message) {
|
1539
|
-
return this._addCheck({ kind: "ulid", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1540
|
-
}
|
1541
|
-
base64(message) {
|
1542
|
-
return this._addCheck({ kind: "base64", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1543
|
-
}
|
1544
|
-
base64url(message) {
|
1545
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
1546
|
-
return this._addCheck({
|
1547
|
-
kind: "base64url",
|
1548
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1549
|
-
});
|
1550
|
-
}
|
1551
|
-
jwt(options) {
|
1552
|
-
return this._addCheck({ kind: "jwt", ...errorUtil_js_1.errorUtil.errToObj(options) });
|
1553
|
-
}
|
1554
|
-
ip(options) {
|
1555
|
-
return this._addCheck({ kind: "ip", ...errorUtil_js_1.errorUtil.errToObj(options) });
|
1556
|
-
}
|
1557
|
-
cidr(options) {
|
1558
|
-
return this._addCheck({ kind: "cidr", ...errorUtil_js_1.errorUtil.errToObj(options) });
|
1559
|
-
}
|
1560
|
-
datetime(options) {
|
1561
|
-
if (typeof options === "string") {
|
1562
|
-
return this._addCheck({
|
1563
|
-
kind: "datetime",
|
1564
|
-
precision: null,
|
1565
|
-
offset: false,
|
1566
|
-
local: false,
|
1567
|
-
message: options,
|
1568
|
-
});
|
1569
|
-
}
|
1570
|
-
return this._addCheck({
|
1571
|
-
kind: "datetime",
|
1572
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
1573
|
-
offset: options?.offset ?? false,
|
1574
|
-
local: options?.local ?? false,
|
1575
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message),
|
1576
|
-
});
|
1577
|
-
}
|
1578
|
-
date(message) {
|
1579
|
-
return this._addCheck({ kind: "date", message });
|
1580
|
-
}
|
1581
|
-
time(options) {
|
1582
|
-
if (typeof options === "string") {
|
1583
|
-
return this._addCheck({
|
1584
|
-
kind: "time",
|
1585
|
-
precision: null,
|
1586
|
-
message: options,
|
1587
|
-
});
|
1588
|
-
}
|
1589
|
-
return this._addCheck({
|
1590
|
-
kind: "time",
|
1591
|
-
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
1592
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message),
|
1593
|
-
});
|
1594
|
-
}
|
1595
|
-
duration(message) {
|
1596
|
-
return this._addCheck({ kind: "duration", ...errorUtil_js_1.errorUtil.errToObj(message) });
|
1597
|
-
}
|
1598
|
-
regex(regex, message) {
|
1599
|
-
return this._addCheck({
|
1600
|
-
kind: "regex",
|
1601
|
-
regex: regex,
|
1602
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1603
|
-
});
|
1604
|
-
}
|
1605
|
-
includes(value, options) {
|
1606
|
-
return this._addCheck({
|
1607
|
-
kind: "includes",
|
1608
|
-
value: value,
|
1609
|
-
position: options?.position,
|
1610
|
-
...errorUtil_js_1.errorUtil.errToObj(options?.message),
|
1611
|
-
});
|
1612
|
-
}
|
1613
|
-
startsWith(value, message) {
|
1614
|
-
return this._addCheck({
|
1615
|
-
kind: "startsWith",
|
1616
|
-
value: value,
|
1617
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1618
|
-
});
|
1619
|
-
}
|
1620
|
-
endsWith(value, message) {
|
1621
|
-
return this._addCheck({
|
1622
|
-
kind: "endsWith",
|
1623
|
-
value: value,
|
1624
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1625
|
-
});
|
1626
|
-
}
|
1627
|
-
min(minLength, message) {
|
1628
|
-
return this._addCheck({
|
1629
|
-
kind: "min",
|
1630
|
-
value: minLength,
|
1631
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1632
|
-
});
|
1633
|
-
}
|
1634
|
-
max(maxLength, message) {
|
1635
|
-
return this._addCheck({
|
1636
|
-
kind: "max",
|
1637
|
-
value: maxLength,
|
1638
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1639
|
-
});
|
1640
|
-
}
|
1641
|
-
length(len, message) {
|
1642
|
-
return this._addCheck({
|
1643
|
-
kind: "length",
|
1644
|
-
value: len,
|
1645
|
-
...errorUtil_js_1.errorUtil.errToObj(message),
|
1646
|
-
});
|
1647
|
-
}
|
1648
|
-
/**
|
1649
|
-
* Equivalent to `.min(1)`
|
1650
|
-
*/
|
1651
|
-
nonempty(message) {
|
1652
|
-
return this.min(1, errorUtil_js_1.errorUtil.errToObj(message));
|
1653
|
-
}
|
1654
|
-
trim() {
|
1655
|
-
return new ZodString({
|
1656
|
-
...this._def,
|
1657
|
-
checks: [...this._def.checks, { kind: "trim" }],
|
1658
|
-
});
|
1659
|
-
}
|
1660
|
-
toLowerCase() {
|
1661
|
-
return new ZodString({
|
1662
|
-
...this._def,
|
1663
|
-
checks: [...this._def.checks, { kind: "toLowerCase" }],
|
1664
|
-
});
|
1665
|
-
}
|
1666
|
-
toUpperCase() {
|
1667
|
-
return new ZodString({
|
1668
|
-
...this._def,
|
1669
|
-
checks: [...this._def.checks, { kind: "toUpperCase" }],
|
1670
|
-
});
|
1671
|
-
}
|
1672
|
-
get isDatetime() {
|
1673
|
-
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
1674
|
-
}
|
1675
|
-
get isDate() {
|
1676
|
-
return !!this._def.checks.find((ch) => ch.kind === "date");
|
1677
|
-
}
|
1678
|
-
get isTime() {
|
1679
|
-
return !!this._def.checks.find((ch) => ch.kind === "time");
|
1680
|
-
}
|
1681
|
-
get isDuration() {
|
1682
|
-
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
1683
|
-
}
|
1684
|
-
get isEmail() {
|
1685
|
-
return !!this._def.checks.find((ch) => ch.kind === "email");
|
1686
|
-
}
|
1687
|
-
get isURL() {
|
1688
|
-
return !!this._def.checks.find((ch) => ch.kind === "url");
|
1689
|
-
}
|
1690
|
-
get isEmoji() {
|
1691
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
1692
|
-
}
|
1693
|
-
get isUUID() {
|
1694
|
-
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
1695
|
-
}
|
1696
|
-
get isNANOID() {
|
1697
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
1698
|
-
}
|
1699
|
-
get isCUID() {
|
1700
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
1701
|
-
}
|
1702
|
-
get isCUID2() {
|
1703
|
-
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
1704
|
-
}
|
1705
|
-
get isULID() {
|
1706
|
-
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
1707
|
-
}
|
1708
|
-
get isIP() {
|
1709
|
-
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
1710
|
-
}
|
1711
|
-
get isCIDR() {
|
1712
|
-
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
1713
|
-
}
|
1714
|
-
get isBase64() {
|
1715
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
1716
|
-
}
|
1717
|
-
get isBase64url() {
|
1718
|
-
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
1719
|
-
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
1720
|
-
}
|
1721
|
-
get minLength() {
|
1722
|
-
let min = null;
|
1723
|
-
for (const ch of this._def.checks) {
|
1724
|
-
if (ch.kind === "min") {
|
1725
|
-
if (min === null || ch.value > min)
|
1726
|
-
min = ch.value;
|
1727
|
-
}
|
1728
|
-
}
|
1729
|
-
return min;
|
1730
|
-
}
|
1731
|
-
get maxLength() {
|
1732
|
-
let max = null;
|
1733
|
-
for (const ch of this._def.checks) {
|
1734
|
-
if (ch.kind === "max") {
|
1735
|
-
if (max === null || ch.value < max)
|
1736
|
-
max = ch.value;
|
1737
|
-
}
|
1738
|
-
}
|
1739
|
-
return max;
|
1740
|
-
}
|
1741
|
-
}
|
1742
|
-
exports.ZodString = ZodString;
|
1743
|
-
ZodString.create = (params) => {
|
1744
|
-
return new ZodString({
|
1745
|
-
checks: [],
|
1746
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
1747
|
-
coerce: params?.coerce ?? false,
|
1748
|
-
...processCreateParams(params),
|
1749
|
-
});
|
1750
|
-
};
|
1751
|
-
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
1752
|
-
function floatSafeRemainder(val, step) {
|
1753
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
1754
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
1755
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
1756
|
-
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
1757
|
-
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
1758
|
-
return (valInt % stepInt) / 10 ** decCount;
|
1759
|
-
}
|
1760
|
-
class ZodNumber extends ZodType {
|
1761
|
-
constructor() {
|
1762
|
-
super(...arguments);
|
1763
|
-
this.min = this.gte;
|
1764
|
-
this.max = this.lte;
|
1765
|
-
this.step = this.multipleOf;
|
1766
|
-
}
|
1767
|
-
_parse(input) {
|
1768
|
-
if (this._def.coerce) {
|
1769
|
-
input.data = Number(input.data);
|
1770
|
-
}
|
1771
|
-
const parsedType = this._getType(input);
|
1772
|
-
if (parsedType !== util_js_1.ZodParsedType.number) {
|
1773
|
-
const ctx = this._getOrReturnCtx(input);
|
1774
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1775
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
1776
|
-
expected: util_js_1.ZodParsedType.number,
|
1777
|
-
received: ctx.parsedType,
|
1778
|
-
});
|
1779
|
-
return parseUtil_js_1.INVALID;
|
1780
|
-
}
|
1781
|
-
let ctx = undefined;
|
1782
|
-
const status = new parseUtil_js_1.ParseStatus();
|
1783
|
-
for (const check of this._def.checks) {
|
1784
|
-
if (check.kind === "int") {
|
1785
|
-
if (!util_js_1.util.isInteger(input.data)) {
|
1786
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1787
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1788
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
1789
|
-
expected: "integer",
|
1790
|
-
received: "float",
|
1791
|
-
message: check.message,
|
1792
|
-
});
|
1793
|
-
status.dirty();
|
1794
|
-
}
|
1795
|
-
}
|
1796
|
-
else if (check.kind === "min") {
|
1797
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
1798
|
-
if (tooSmall) {
|
1799
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1800
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1801
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
1802
|
-
minimum: check.value,
|
1803
|
-
type: "number",
|
1804
|
-
inclusive: check.inclusive,
|
1805
|
-
exact: false,
|
1806
|
-
message: check.message,
|
1807
|
-
});
|
1808
|
-
status.dirty();
|
1809
|
-
}
|
1810
|
-
}
|
1811
|
-
else if (check.kind === "max") {
|
1812
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
1813
|
-
if (tooBig) {
|
1814
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1815
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1816
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
1817
|
-
maximum: check.value,
|
1818
|
-
type: "number",
|
1819
|
-
inclusive: check.inclusive,
|
1820
|
-
exact: false,
|
1821
|
-
message: check.message,
|
1822
|
-
});
|
1823
|
-
status.dirty();
|
1824
|
-
}
|
1825
|
-
}
|
1826
|
-
else if (check.kind === "multipleOf") {
|
1827
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
1828
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1829
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1830
|
-
code: ZodError_js_1.ZodIssueCode.not_multiple_of,
|
1831
|
-
multipleOf: check.value,
|
1832
|
-
message: check.message,
|
1833
|
-
});
|
1834
|
-
status.dirty();
|
1835
|
-
}
|
1836
|
-
}
|
1837
|
-
else if (check.kind === "finite") {
|
1838
|
-
if (!Number.isFinite(input.data)) {
|
1839
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
1840
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
1841
|
-
code: ZodError_js_1.ZodIssueCode.not_finite,
|
1842
|
-
message: check.message,
|
1843
|
-
});
|
1844
|
-
status.dirty();
|
1845
|
-
}
|
1846
|
-
}
|
1847
|
-
else {
|
1848
|
-
util_js_1.util.assertNever(check);
|
1849
|
-
}
|
1850
|
-
}
|
1851
|
-
return { status: status.value, value: input.data };
|
1852
|
-
}
|
1853
|
-
gte(value, message) {
|
1854
|
-
return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
|
1855
|
-
}
|
1856
|
-
gt(value, message) {
|
1857
|
-
return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
|
1858
|
-
}
|
1859
|
-
lte(value, message) {
|
1860
|
-
return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
|
1861
|
-
}
|
1862
|
-
lt(value, message) {
|
1863
|
-
return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
|
1864
|
-
}
|
1865
|
-
setLimit(kind, value, inclusive, message) {
|
1866
|
-
return new ZodNumber({
|
1867
|
-
...this._def,
|
1868
|
-
checks: [
|
1869
|
-
...this._def.checks,
|
1870
|
-
{
|
1871
|
-
kind,
|
1872
|
-
value,
|
1873
|
-
inclusive,
|
1874
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1875
|
-
},
|
1876
|
-
],
|
1877
|
-
});
|
1878
|
-
}
|
1879
|
-
_addCheck(check) {
|
1880
|
-
return new ZodNumber({
|
1881
|
-
...this._def,
|
1882
|
-
checks: [...this._def.checks, check],
|
1883
|
-
});
|
1884
|
-
}
|
1885
|
-
int(message) {
|
1886
|
-
return this._addCheck({
|
1887
|
-
kind: "int",
|
1888
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1889
|
-
});
|
1890
|
-
}
|
1891
|
-
positive(message) {
|
1892
|
-
return this._addCheck({
|
1893
|
-
kind: "min",
|
1894
|
-
value: 0,
|
1895
|
-
inclusive: false,
|
1896
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1897
|
-
});
|
1898
|
-
}
|
1899
|
-
negative(message) {
|
1900
|
-
return this._addCheck({
|
1901
|
-
kind: "max",
|
1902
|
-
value: 0,
|
1903
|
-
inclusive: false,
|
1904
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1905
|
-
});
|
1906
|
-
}
|
1907
|
-
nonpositive(message) {
|
1908
|
-
return this._addCheck({
|
1909
|
-
kind: "max",
|
1910
|
-
value: 0,
|
1911
|
-
inclusive: true,
|
1912
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1913
|
-
});
|
1914
|
-
}
|
1915
|
-
nonnegative(message) {
|
1916
|
-
return this._addCheck({
|
1917
|
-
kind: "min",
|
1918
|
-
value: 0,
|
1919
|
-
inclusive: true,
|
1920
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1921
|
-
});
|
1922
|
-
}
|
1923
|
-
multipleOf(value, message) {
|
1924
|
-
return this._addCheck({
|
1925
|
-
kind: "multipleOf",
|
1926
|
-
value: value,
|
1927
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1928
|
-
});
|
1929
|
-
}
|
1930
|
-
finite(message) {
|
1931
|
-
return this._addCheck({
|
1932
|
-
kind: "finite",
|
1933
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1934
|
-
});
|
1935
|
-
}
|
1936
|
-
safe(message) {
|
1937
|
-
return this._addCheck({
|
1938
|
-
kind: "min",
|
1939
|
-
inclusive: true,
|
1940
|
-
value: Number.MIN_SAFE_INTEGER,
|
1941
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1942
|
-
})._addCheck({
|
1943
|
-
kind: "max",
|
1944
|
-
inclusive: true,
|
1945
|
-
value: Number.MAX_SAFE_INTEGER,
|
1946
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
1947
|
-
});
|
1948
|
-
}
|
1949
|
-
get minValue() {
|
1950
|
-
let min = null;
|
1951
|
-
for (const ch of this._def.checks) {
|
1952
|
-
if (ch.kind === "min") {
|
1953
|
-
if (min === null || ch.value > min)
|
1954
|
-
min = ch.value;
|
1955
|
-
}
|
1956
|
-
}
|
1957
|
-
return min;
|
1958
|
-
}
|
1959
|
-
get maxValue() {
|
1960
|
-
let max = null;
|
1961
|
-
for (const ch of this._def.checks) {
|
1962
|
-
if (ch.kind === "max") {
|
1963
|
-
if (max === null || ch.value < max)
|
1964
|
-
max = ch.value;
|
1965
|
-
}
|
1966
|
-
}
|
1967
|
-
return max;
|
1968
|
-
}
|
1969
|
-
get isInt() {
|
1970
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util_js_1.util.isInteger(ch.value)));
|
1971
|
-
}
|
1972
|
-
get isFinite() {
|
1973
|
-
let max = null;
|
1974
|
-
let min = null;
|
1975
|
-
for (const ch of this._def.checks) {
|
1976
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
1977
|
-
return true;
|
1978
|
-
}
|
1979
|
-
else if (ch.kind === "min") {
|
1980
|
-
if (min === null || ch.value > min)
|
1981
|
-
min = ch.value;
|
1982
|
-
}
|
1983
|
-
else if (ch.kind === "max") {
|
1984
|
-
if (max === null || ch.value < max)
|
1985
|
-
max = ch.value;
|
1986
|
-
}
|
1987
|
-
}
|
1988
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
1989
|
-
}
|
1990
|
-
}
|
1991
|
-
exports.ZodNumber = ZodNumber;
|
1992
|
-
ZodNumber.create = (params) => {
|
1993
|
-
return new ZodNumber({
|
1994
|
-
checks: [],
|
1995
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
1996
|
-
coerce: params?.coerce || false,
|
1997
|
-
...processCreateParams(params),
|
1998
|
-
});
|
1999
|
-
};
|
2000
|
-
class ZodBigInt extends ZodType {
|
2001
|
-
constructor() {
|
2002
|
-
super(...arguments);
|
2003
|
-
this.min = this.gte;
|
2004
|
-
this.max = this.lte;
|
2005
|
-
}
|
2006
|
-
_parse(input) {
|
2007
|
-
if (this._def.coerce) {
|
2008
|
-
try {
|
2009
|
-
input.data = BigInt(input.data);
|
2010
|
-
}
|
2011
|
-
catch {
|
2012
|
-
return this._getInvalidInput(input);
|
2013
|
-
}
|
2014
|
-
}
|
2015
|
-
const parsedType = this._getType(input);
|
2016
|
-
if (parsedType !== util_js_1.ZodParsedType.bigint) {
|
2017
|
-
return this._getInvalidInput(input);
|
2018
|
-
}
|
2019
|
-
let ctx = undefined;
|
2020
|
-
const status = new parseUtil_js_1.ParseStatus();
|
2021
|
-
for (const check of this._def.checks) {
|
2022
|
-
if (check.kind === "min") {
|
2023
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
2024
|
-
if (tooSmall) {
|
2025
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
2026
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2027
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
2028
|
-
type: "bigint",
|
2029
|
-
minimum: check.value,
|
2030
|
-
inclusive: check.inclusive,
|
2031
|
-
message: check.message,
|
2032
|
-
});
|
2033
|
-
status.dirty();
|
2034
|
-
}
|
2035
|
-
}
|
2036
|
-
else if (check.kind === "max") {
|
2037
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
2038
|
-
if (tooBig) {
|
2039
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
2040
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2041
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
2042
|
-
type: "bigint",
|
2043
|
-
maximum: check.value,
|
2044
|
-
inclusive: check.inclusive,
|
2045
|
-
message: check.message,
|
2046
|
-
});
|
2047
|
-
status.dirty();
|
2048
|
-
}
|
2049
|
-
}
|
2050
|
-
else if (check.kind === "multipleOf") {
|
2051
|
-
if (input.data % check.value !== BigInt(0)) {
|
2052
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
2053
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2054
|
-
code: ZodError_js_1.ZodIssueCode.not_multiple_of,
|
2055
|
-
multipleOf: check.value,
|
2056
|
-
message: check.message,
|
2057
|
-
});
|
2058
|
-
status.dirty();
|
2059
|
-
}
|
2060
|
-
}
|
2061
|
-
else {
|
2062
|
-
util_js_1.util.assertNever(check);
|
2063
|
-
}
|
2064
|
-
}
|
2065
|
-
return { status: status.value, value: input.data };
|
2066
|
-
}
|
2067
|
-
_getInvalidInput(input) {
|
2068
|
-
const ctx = this._getOrReturnCtx(input);
|
2069
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2070
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2071
|
-
expected: util_js_1.ZodParsedType.bigint,
|
2072
|
-
received: ctx.parsedType,
|
2073
|
-
});
|
2074
|
-
return parseUtil_js_1.INVALID;
|
2075
|
-
}
|
2076
|
-
gte(value, message) {
|
2077
|
-
return this.setLimit("min", value, true, errorUtil_js_1.errorUtil.toString(message));
|
2078
|
-
}
|
2079
|
-
gt(value, message) {
|
2080
|
-
return this.setLimit("min", value, false, errorUtil_js_1.errorUtil.toString(message));
|
2081
|
-
}
|
2082
|
-
lte(value, message) {
|
2083
|
-
return this.setLimit("max", value, true, errorUtil_js_1.errorUtil.toString(message));
|
2084
|
-
}
|
2085
|
-
lt(value, message) {
|
2086
|
-
return this.setLimit("max", value, false, errorUtil_js_1.errorUtil.toString(message));
|
2087
|
-
}
|
2088
|
-
setLimit(kind, value, inclusive, message) {
|
2089
|
-
return new ZodBigInt({
|
2090
|
-
...this._def,
|
2091
|
-
checks: [
|
2092
|
-
...this._def.checks,
|
2093
|
-
{
|
2094
|
-
kind,
|
2095
|
-
value,
|
2096
|
-
inclusive,
|
2097
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2098
|
-
},
|
2099
|
-
],
|
2100
|
-
});
|
2101
|
-
}
|
2102
|
-
_addCheck(check) {
|
2103
|
-
return new ZodBigInt({
|
2104
|
-
...this._def,
|
2105
|
-
checks: [...this._def.checks, check],
|
2106
|
-
});
|
2107
|
-
}
|
2108
|
-
positive(message) {
|
2109
|
-
return this._addCheck({
|
2110
|
-
kind: "min",
|
2111
|
-
value: BigInt(0),
|
2112
|
-
inclusive: false,
|
2113
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2114
|
-
});
|
2115
|
-
}
|
2116
|
-
negative(message) {
|
2117
|
-
return this._addCheck({
|
2118
|
-
kind: "max",
|
2119
|
-
value: BigInt(0),
|
2120
|
-
inclusive: false,
|
2121
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2122
|
-
});
|
2123
|
-
}
|
2124
|
-
nonpositive(message) {
|
2125
|
-
return this._addCheck({
|
2126
|
-
kind: "max",
|
2127
|
-
value: BigInt(0),
|
2128
|
-
inclusive: true,
|
2129
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2130
|
-
});
|
2131
|
-
}
|
2132
|
-
nonnegative(message) {
|
2133
|
-
return this._addCheck({
|
2134
|
-
kind: "min",
|
2135
|
-
value: BigInt(0),
|
2136
|
-
inclusive: true,
|
2137
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2138
|
-
});
|
2139
|
-
}
|
2140
|
-
multipleOf(value, message) {
|
2141
|
-
return this._addCheck({
|
2142
|
-
kind: "multipleOf",
|
2143
|
-
value,
|
2144
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2145
|
-
});
|
2146
|
-
}
|
2147
|
-
get minValue() {
|
2148
|
-
let min = null;
|
2149
|
-
for (const ch of this._def.checks) {
|
2150
|
-
if (ch.kind === "min") {
|
2151
|
-
if (min === null || ch.value > min)
|
2152
|
-
min = ch.value;
|
2153
|
-
}
|
2154
|
-
}
|
2155
|
-
return min;
|
2156
|
-
}
|
2157
|
-
get maxValue() {
|
2158
|
-
let max = null;
|
2159
|
-
for (const ch of this._def.checks) {
|
2160
|
-
if (ch.kind === "max") {
|
2161
|
-
if (max === null || ch.value < max)
|
2162
|
-
max = ch.value;
|
2163
|
-
}
|
2164
|
-
}
|
2165
|
-
return max;
|
2166
|
-
}
|
2167
|
-
}
|
2168
|
-
exports.ZodBigInt = ZodBigInt;
|
2169
|
-
ZodBigInt.create = (params) => {
|
2170
|
-
return new ZodBigInt({
|
2171
|
-
checks: [],
|
2172
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
2173
|
-
coerce: params?.coerce ?? false,
|
2174
|
-
...processCreateParams(params),
|
2175
|
-
});
|
2176
|
-
};
|
2177
|
-
class ZodBoolean extends ZodType {
|
2178
|
-
_parse(input) {
|
2179
|
-
if (this._def.coerce) {
|
2180
|
-
input.data = Boolean(input.data);
|
2181
|
-
}
|
2182
|
-
const parsedType = this._getType(input);
|
2183
|
-
if (parsedType !== util_js_1.ZodParsedType.boolean) {
|
2184
|
-
const ctx = this._getOrReturnCtx(input);
|
2185
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2186
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2187
|
-
expected: util_js_1.ZodParsedType.boolean,
|
2188
|
-
received: ctx.parsedType,
|
2189
|
-
});
|
2190
|
-
return parseUtil_js_1.INVALID;
|
2191
|
-
}
|
2192
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2193
|
-
}
|
2194
|
-
}
|
2195
|
-
exports.ZodBoolean = ZodBoolean;
|
2196
|
-
ZodBoolean.create = (params) => {
|
2197
|
-
return new ZodBoolean({
|
2198
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
2199
|
-
coerce: params?.coerce || false,
|
2200
|
-
...processCreateParams(params),
|
2201
|
-
});
|
2202
|
-
};
|
2203
|
-
class ZodDate extends ZodType {
|
2204
|
-
_parse(input) {
|
2205
|
-
if (this._def.coerce) {
|
2206
|
-
input.data = new Date(input.data);
|
2207
|
-
}
|
2208
|
-
const parsedType = this._getType(input);
|
2209
|
-
if (parsedType !== util_js_1.ZodParsedType.date) {
|
2210
|
-
const ctx = this._getOrReturnCtx(input);
|
2211
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2212
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2213
|
-
expected: util_js_1.ZodParsedType.date,
|
2214
|
-
received: ctx.parsedType,
|
2215
|
-
});
|
2216
|
-
return parseUtil_js_1.INVALID;
|
2217
|
-
}
|
2218
|
-
if (Number.isNaN(input.data.getTime())) {
|
2219
|
-
const ctx = this._getOrReturnCtx(input);
|
2220
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2221
|
-
code: ZodError_js_1.ZodIssueCode.invalid_date,
|
2222
|
-
});
|
2223
|
-
return parseUtil_js_1.INVALID;
|
2224
|
-
}
|
2225
|
-
const status = new parseUtil_js_1.ParseStatus();
|
2226
|
-
let ctx = undefined;
|
2227
|
-
for (const check of this._def.checks) {
|
2228
|
-
if (check.kind === "min") {
|
2229
|
-
if (input.data.getTime() < check.value) {
|
2230
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
2231
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2232
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
2233
|
-
message: check.message,
|
2234
|
-
inclusive: true,
|
2235
|
-
exact: false,
|
2236
|
-
minimum: check.value,
|
2237
|
-
type: "date",
|
2238
|
-
});
|
2239
|
-
status.dirty();
|
2240
|
-
}
|
2241
|
-
}
|
2242
|
-
else if (check.kind === "max") {
|
2243
|
-
if (input.data.getTime() > check.value) {
|
2244
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
2245
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2246
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
2247
|
-
message: check.message,
|
2248
|
-
inclusive: true,
|
2249
|
-
exact: false,
|
2250
|
-
maximum: check.value,
|
2251
|
-
type: "date",
|
2252
|
-
});
|
2253
|
-
status.dirty();
|
2254
|
-
}
|
2255
|
-
}
|
2256
|
-
else {
|
2257
|
-
util_js_1.util.assertNever(check);
|
2258
|
-
}
|
2259
|
-
}
|
2260
|
-
return {
|
2261
|
-
status: status.value,
|
2262
|
-
value: new Date(input.data.getTime()),
|
2263
|
-
};
|
2264
|
-
}
|
2265
|
-
_addCheck(check) {
|
2266
|
-
return new ZodDate({
|
2267
|
-
...this._def,
|
2268
|
-
checks: [...this._def.checks, check],
|
2269
|
-
});
|
2270
|
-
}
|
2271
|
-
min(minDate, message) {
|
2272
|
-
return this._addCheck({
|
2273
|
-
kind: "min",
|
2274
|
-
value: minDate.getTime(),
|
2275
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2276
|
-
});
|
2277
|
-
}
|
2278
|
-
max(maxDate, message) {
|
2279
|
-
return this._addCheck({
|
2280
|
-
kind: "max",
|
2281
|
-
value: maxDate.getTime(),
|
2282
|
-
message: errorUtil_js_1.errorUtil.toString(message),
|
2283
|
-
});
|
2284
|
-
}
|
2285
|
-
get minDate() {
|
2286
|
-
let min = null;
|
2287
|
-
for (const ch of this._def.checks) {
|
2288
|
-
if (ch.kind === "min") {
|
2289
|
-
if (min === null || ch.value > min)
|
2290
|
-
min = ch.value;
|
2291
|
-
}
|
2292
|
-
}
|
2293
|
-
return min != null ? new Date(min) : null;
|
2294
|
-
}
|
2295
|
-
get maxDate() {
|
2296
|
-
let max = null;
|
2297
|
-
for (const ch of this._def.checks) {
|
2298
|
-
if (ch.kind === "max") {
|
2299
|
-
if (max === null || ch.value < max)
|
2300
|
-
max = ch.value;
|
2301
|
-
}
|
2302
|
-
}
|
2303
|
-
return max != null ? new Date(max) : null;
|
2304
|
-
}
|
2305
|
-
}
|
2306
|
-
exports.ZodDate = ZodDate;
|
2307
|
-
ZodDate.create = (params) => {
|
2308
|
-
return new ZodDate({
|
2309
|
-
checks: [],
|
2310
|
-
coerce: params?.coerce || false,
|
2311
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
2312
|
-
...processCreateParams(params),
|
2313
|
-
});
|
2314
|
-
};
|
2315
|
-
class ZodSymbol extends ZodType {
|
2316
|
-
_parse(input) {
|
2317
|
-
const parsedType = this._getType(input);
|
2318
|
-
if (parsedType !== util_js_1.ZodParsedType.symbol) {
|
2319
|
-
const ctx = this._getOrReturnCtx(input);
|
2320
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2321
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2322
|
-
expected: util_js_1.ZodParsedType.symbol,
|
2323
|
-
received: ctx.parsedType,
|
2324
|
-
});
|
2325
|
-
return parseUtil_js_1.INVALID;
|
2326
|
-
}
|
2327
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2328
|
-
}
|
2329
|
-
}
|
2330
|
-
exports.ZodSymbol = ZodSymbol;
|
2331
|
-
ZodSymbol.create = (params) => {
|
2332
|
-
return new ZodSymbol({
|
2333
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
2334
|
-
...processCreateParams(params),
|
2335
|
-
});
|
2336
|
-
};
|
2337
|
-
class ZodUndefined extends ZodType {
|
2338
|
-
_parse(input) {
|
2339
|
-
const parsedType = this._getType(input);
|
2340
|
-
if (parsedType !== util_js_1.ZodParsedType.undefined) {
|
2341
|
-
const ctx = this._getOrReturnCtx(input);
|
2342
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2343
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2344
|
-
expected: util_js_1.ZodParsedType.undefined,
|
2345
|
-
received: ctx.parsedType,
|
2346
|
-
});
|
2347
|
-
return parseUtil_js_1.INVALID;
|
2348
|
-
}
|
2349
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2350
|
-
}
|
2351
|
-
}
|
2352
|
-
exports.ZodUndefined = ZodUndefined;
|
2353
|
-
ZodUndefined.create = (params) => {
|
2354
|
-
return new ZodUndefined({
|
2355
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
2356
|
-
...processCreateParams(params),
|
2357
|
-
});
|
2358
|
-
};
|
2359
|
-
class ZodNull extends ZodType {
|
2360
|
-
_parse(input) {
|
2361
|
-
const parsedType = this._getType(input);
|
2362
|
-
if (parsedType !== util_js_1.ZodParsedType.null) {
|
2363
|
-
const ctx = this._getOrReturnCtx(input);
|
2364
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2365
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2366
|
-
expected: util_js_1.ZodParsedType.null,
|
2367
|
-
received: ctx.parsedType,
|
2368
|
-
});
|
2369
|
-
return parseUtil_js_1.INVALID;
|
2370
|
-
}
|
2371
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2372
|
-
}
|
2373
|
-
}
|
2374
|
-
exports.ZodNull = ZodNull;
|
2375
|
-
ZodNull.create = (params) => {
|
2376
|
-
return new ZodNull({
|
2377
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
2378
|
-
...processCreateParams(params),
|
2379
|
-
});
|
2380
|
-
};
|
2381
|
-
class ZodAny extends ZodType {
|
2382
|
-
constructor() {
|
2383
|
-
super(...arguments);
|
2384
|
-
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
2385
|
-
this._any = true;
|
2386
|
-
}
|
2387
|
-
_parse(input) {
|
2388
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2389
|
-
}
|
2390
|
-
}
|
2391
|
-
exports.ZodAny = ZodAny;
|
2392
|
-
ZodAny.create = (params) => {
|
2393
|
-
return new ZodAny({
|
2394
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
2395
|
-
...processCreateParams(params),
|
2396
|
-
});
|
2397
|
-
};
|
2398
|
-
class ZodUnknown extends ZodType {
|
2399
|
-
constructor() {
|
2400
|
-
super(...arguments);
|
2401
|
-
// required
|
2402
|
-
this._unknown = true;
|
2403
|
-
}
|
2404
|
-
_parse(input) {
|
2405
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2406
|
-
}
|
2407
|
-
}
|
2408
|
-
exports.ZodUnknown = ZodUnknown;
|
2409
|
-
ZodUnknown.create = (params) => {
|
2410
|
-
return new ZodUnknown({
|
2411
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
2412
|
-
...processCreateParams(params),
|
2413
|
-
});
|
2414
|
-
};
|
2415
|
-
class ZodNever extends ZodType {
|
2416
|
-
_parse(input) {
|
2417
|
-
const ctx = this._getOrReturnCtx(input);
|
2418
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2419
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2420
|
-
expected: util_js_1.ZodParsedType.never,
|
2421
|
-
received: ctx.parsedType,
|
2422
|
-
});
|
2423
|
-
return parseUtil_js_1.INVALID;
|
2424
|
-
}
|
2425
|
-
}
|
2426
|
-
exports.ZodNever = ZodNever;
|
2427
|
-
ZodNever.create = (params) => {
|
2428
|
-
return new ZodNever({
|
2429
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
2430
|
-
...processCreateParams(params),
|
2431
|
-
});
|
2432
|
-
};
|
2433
|
-
class ZodVoid extends ZodType {
|
2434
|
-
_parse(input) {
|
2435
|
-
const parsedType = this._getType(input);
|
2436
|
-
if (parsedType !== util_js_1.ZodParsedType.undefined) {
|
2437
|
-
const ctx = this._getOrReturnCtx(input);
|
2438
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2439
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2440
|
-
expected: util_js_1.ZodParsedType.void,
|
2441
|
-
received: ctx.parsedType,
|
2442
|
-
});
|
2443
|
-
return parseUtil_js_1.INVALID;
|
2444
|
-
}
|
2445
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
2446
|
-
}
|
2447
|
-
}
|
2448
|
-
exports.ZodVoid = ZodVoid;
|
2449
|
-
ZodVoid.create = (params) => {
|
2450
|
-
return new ZodVoid({
|
2451
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
2452
|
-
...processCreateParams(params),
|
2453
|
-
});
|
2454
|
-
};
|
2455
|
-
class ZodArray extends ZodType {
|
2456
|
-
_parse(input) {
|
2457
|
-
const { ctx, status } = this._processInputParams(input);
|
2458
|
-
const def = this._def;
|
2459
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
|
2460
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2461
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2462
|
-
expected: util_js_1.ZodParsedType.array,
|
2463
|
-
received: ctx.parsedType,
|
2464
|
-
});
|
2465
|
-
return parseUtil_js_1.INVALID;
|
2466
|
-
}
|
2467
|
-
if (def.exactLength !== null) {
|
2468
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
2469
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
2470
|
-
if (tooBig || tooSmall) {
|
2471
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2472
|
-
code: tooBig ? ZodError_js_1.ZodIssueCode.too_big : ZodError_js_1.ZodIssueCode.too_small,
|
2473
|
-
minimum: (tooSmall ? def.exactLength.value : undefined),
|
2474
|
-
maximum: (tooBig ? def.exactLength.value : undefined),
|
2475
|
-
type: "array",
|
2476
|
-
inclusive: true,
|
2477
|
-
exact: true,
|
2478
|
-
message: def.exactLength.message,
|
2479
|
-
});
|
2480
|
-
status.dirty();
|
2481
|
-
}
|
2482
|
-
}
|
2483
|
-
if (def.minLength !== null) {
|
2484
|
-
if (ctx.data.length < def.minLength.value) {
|
2485
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2486
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
2487
|
-
minimum: def.minLength.value,
|
2488
|
-
type: "array",
|
2489
|
-
inclusive: true,
|
2490
|
-
exact: false,
|
2491
|
-
message: def.minLength.message,
|
2492
|
-
});
|
2493
|
-
status.dirty();
|
2494
|
-
}
|
2495
|
-
}
|
2496
|
-
if (def.maxLength !== null) {
|
2497
|
-
if (ctx.data.length > def.maxLength.value) {
|
2498
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2499
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
2500
|
-
maximum: def.maxLength.value,
|
2501
|
-
type: "array",
|
2502
|
-
inclusive: true,
|
2503
|
-
exact: false,
|
2504
|
-
message: def.maxLength.message,
|
2505
|
-
});
|
2506
|
-
status.dirty();
|
2507
|
-
}
|
2508
|
-
}
|
2509
|
-
if (ctx.common.async) {
|
2510
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
2511
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
2512
|
-
})).then((result) => {
|
2513
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, result);
|
2514
|
-
});
|
2515
|
-
}
|
2516
|
-
const result = [...ctx.data].map((item, i) => {
|
2517
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
2518
|
-
});
|
2519
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, result);
|
2520
|
-
}
|
2521
|
-
get element() {
|
2522
|
-
return this._def.type;
|
2523
|
-
}
|
2524
|
-
min(minLength, message) {
|
2525
|
-
return new ZodArray({
|
2526
|
-
...this._def,
|
2527
|
-
minLength: { value: minLength, message: errorUtil_js_1.errorUtil.toString(message) },
|
2528
|
-
});
|
2529
|
-
}
|
2530
|
-
max(maxLength, message) {
|
2531
|
-
return new ZodArray({
|
2532
|
-
...this._def,
|
2533
|
-
maxLength: { value: maxLength, message: errorUtil_js_1.errorUtil.toString(message) },
|
2534
|
-
});
|
2535
|
-
}
|
2536
|
-
length(len, message) {
|
2537
|
-
return new ZodArray({
|
2538
|
-
...this._def,
|
2539
|
-
exactLength: { value: len, message: errorUtil_js_1.errorUtil.toString(message) },
|
2540
|
-
});
|
2541
|
-
}
|
2542
|
-
nonempty(message) {
|
2543
|
-
return this.min(1, message);
|
2544
|
-
}
|
2545
|
-
}
|
2546
|
-
exports.ZodArray = ZodArray;
|
2547
|
-
ZodArray.create = (schema, params) => {
|
2548
|
-
return new ZodArray({
|
2549
|
-
type: schema,
|
2550
|
-
minLength: null,
|
2551
|
-
maxLength: null,
|
2552
|
-
exactLength: null,
|
2553
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
2554
|
-
...processCreateParams(params),
|
2555
|
-
});
|
2556
|
-
};
|
2557
|
-
function deepPartialify(schema) {
|
2558
|
-
if (schema instanceof ZodObject) {
|
2559
|
-
const newShape = {};
|
2560
|
-
for (const key in schema.shape) {
|
2561
|
-
const fieldSchema = schema.shape[key];
|
2562
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
2563
|
-
}
|
2564
|
-
return new ZodObject({
|
2565
|
-
...schema._def,
|
2566
|
-
shape: () => newShape,
|
2567
|
-
});
|
2568
|
-
}
|
2569
|
-
else if (schema instanceof ZodArray) {
|
2570
|
-
return new ZodArray({
|
2571
|
-
...schema._def,
|
2572
|
-
type: deepPartialify(schema.element),
|
2573
|
-
});
|
2574
|
-
}
|
2575
|
-
else if (schema instanceof ZodOptional) {
|
2576
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
2577
|
-
}
|
2578
|
-
else if (schema instanceof ZodNullable) {
|
2579
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
2580
|
-
}
|
2581
|
-
else if (schema instanceof ZodTuple) {
|
2582
|
-
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
2583
|
-
}
|
2584
|
-
else {
|
2585
|
-
return schema;
|
2586
|
-
}
|
2587
|
-
}
|
2588
|
-
class ZodObject extends ZodType {
|
2589
|
-
constructor() {
|
2590
|
-
super(...arguments);
|
2591
|
-
this._cached = null;
|
2592
|
-
/**
|
2593
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
2594
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
2595
|
-
*/
|
2596
|
-
this.nonstrict = this.passthrough;
|
2597
|
-
// extend<
|
2598
|
-
// Augmentation extends ZodRawShape,
|
2599
|
-
// NewOutput extends util.flatten<{
|
2600
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
2601
|
-
// ? Augmentation[k]["_output"]
|
2602
|
-
// : k extends keyof Output
|
2603
|
-
// ? Output[k]
|
2604
|
-
// : never;
|
2605
|
-
// }>,
|
2606
|
-
// NewInput extends util.flatten<{
|
2607
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
2608
|
-
// ? Augmentation[k]["_input"]
|
2609
|
-
// : k extends keyof Input
|
2610
|
-
// ? Input[k]
|
2611
|
-
// : never;
|
2612
|
-
// }>
|
2613
|
-
// >(
|
2614
|
-
// augmentation: Augmentation
|
2615
|
-
// ): ZodObject<
|
2616
|
-
// extendShape<T, Augmentation>,
|
2617
|
-
// UnknownKeys,
|
2618
|
-
// Catchall,
|
2619
|
-
// NewOutput,
|
2620
|
-
// NewInput
|
2621
|
-
// > {
|
2622
|
-
// return new ZodObject({
|
2623
|
-
// ...this._def,
|
2624
|
-
// shape: () => ({
|
2625
|
-
// ...this._def.shape(),
|
2626
|
-
// ...augmentation,
|
2627
|
-
// }),
|
2628
|
-
// }) as any;
|
2629
|
-
// }
|
2630
|
-
/**
|
2631
|
-
* @deprecated Use `.extend` instead
|
2632
|
-
* */
|
2633
|
-
this.augment = this.extend;
|
2634
|
-
}
|
2635
|
-
_getCached() {
|
2636
|
-
if (this._cached !== null)
|
2637
|
-
return this._cached;
|
2638
|
-
const shape = this._def.shape();
|
2639
|
-
const keys = util_js_1.util.objectKeys(shape);
|
2640
|
-
this._cached = { shape, keys };
|
2641
|
-
return this._cached;
|
2642
|
-
}
|
2643
|
-
_parse(input) {
|
2644
|
-
const parsedType = this._getType(input);
|
2645
|
-
if (parsedType !== util_js_1.ZodParsedType.object) {
|
2646
|
-
const ctx = this._getOrReturnCtx(input);
|
2647
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2648
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
2649
|
-
expected: util_js_1.ZodParsedType.object,
|
2650
|
-
received: ctx.parsedType,
|
2651
|
-
});
|
2652
|
-
return parseUtil_js_1.INVALID;
|
2653
|
-
}
|
2654
|
-
const { status, ctx } = this._processInputParams(input);
|
2655
|
-
const { shape, keys: shapeKeys } = this._getCached();
|
2656
|
-
const extraKeys = [];
|
2657
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
2658
|
-
for (const key in ctx.data) {
|
2659
|
-
if (!shapeKeys.includes(key)) {
|
2660
|
-
extraKeys.push(key);
|
2661
|
-
}
|
2662
|
-
}
|
2663
|
-
}
|
2664
|
-
const pairs = [];
|
2665
|
-
for (const key of shapeKeys) {
|
2666
|
-
const keyValidator = shape[key];
|
2667
|
-
const value = ctx.data[key];
|
2668
|
-
pairs.push({
|
2669
|
-
key: { status: "valid", value: key },
|
2670
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
2671
|
-
alwaysSet: key in ctx.data,
|
2672
|
-
});
|
2673
|
-
}
|
2674
|
-
if (this._def.catchall instanceof ZodNever) {
|
2675
|
-
const unknownKeys = this._def.unknownKeys;
|
2676
|
-
if (unknownKeys === "passthrough") {
|
2677
|
-
for (const key of extraKeys) {
|
2678
|
-
pairs.push({
|
2679
|
-
key: { status: "valid", value: key },
|
2680
|
-
value: { status: "valid", value: ctx.data[key] },
|
2681
|
-
});
|
2682
|
-
}
|
2683
|
-
}
|
2684
|
-
else if (unknownKeys === "strict") {
|
2685
|
-
if (extraKeys.length > 0) {
|
2686
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2687
|
-
code: ZodError_js_1.ZodIssueCode.unrecognized_keys,
|
2688
|
-
keys: extraKeys,
|
2689
|
-
});
|
2690
|
-
status.dirty();
|
2691
|
-
}
|
2692
|
-
}
|
2693
|
-
else if (unknownKeys === "strip") {
|
2694
|
-
}
|
2695
|
-
else {
|
2696
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
2697
|
-
}
|
2698
|
-
}
|
2699
|
-
else {
|
2700
|
-
// run catchall validation
|
2701
|
-
const catchall = this._def.catchall;
|
2702
|
-
for (const key of extraKeys) {
|
2703
|
-
const value = ctx.data[key];
|
2704
|
-
pairs.push({
|
2705
|
-
key: { status: "valid", value: key },
|
2706
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
2707
|
-
),
|
2708
|
-
alwaysSet: key in ctx.data,
|
2709
|
-
});
|
2710
|
-
}
|
2711
|
-
}
|
2712
|
-
if (ctx.common.async) {
|
2713
|
-
return Promise.resolve()
|
2714
|
-
.then(async () => {
|
2715
|
-
const syncPairs = [];
|
2716
|
-
for (const pair of pairs) {
|
2717
|
-
const key = await pair.key;
|
2718
|
-
const value = await pair.value;
|
2719
|
-
syncPairs.push({
|
2720
|
-
key,
|
2721
|
-
value,
|
2722
|
-
alwaysSet: pair.alwaysSet,
|
2723
|
-
});
|
2724
|
-
}
|
2725
|
-
return syncPairs;
|
2726
|
-
})
|
2727
|
-
.then((syncPairs) => {
|
2728
|
-
return parseUtil_js_1.ParseStatus.mergeObjectSync(status, syncPairs);
|
2729
|
-
});
|
2730
|
-
}
|
2731
|
-
else {
|
2732
|
-
return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
|
2733
|
-
}
|
2734
|
-
}
|
2735
|
-
get shape() {
|
2736
|
-
return this._def.shape();
|
2737
|
-
}
|
2738
|
-
strict(message) {
|
2739
|
-
errorUtil_js_1.errorUtil.errToObj;
|
2740
|
-
return new ZodObject({
|
2741
|
-
...this._def,
|
2742
|
-
unknownKeys: "strict",
|
2743
|
-
...(message !== undefined
|
2744
|
-
? {
|
2745
|
-
errorMap: (issue, ctx) => {
|
2746
|
-
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
2747
|
-
if (issue.code === "unrecognized_keys")
|
2748
|
-
return {
|
2749
|
-
message: errorUtil_js_1.errorUtil.errToObj(message).message ?? defaultError,
|
2750
|
-
};
|
2751
|
-
return {
|
2752
|
-
message: defaultError,
|
2753
|
-
};
|
2754
|
-
},
|
2755
|
-
}
|
2756
|
-
: {}),
|
2757
|
-
});
|
2758
|
-
}
|
2759
|
-
strip() {
|
2760
|
-
return new ZodObject({
|
2761
|
-
...this._def,
|
2762
|
-
unknownKeys: "strip",
|
2763
|
-
});
|
2764
|
-
}
|
2765
|
-
passthrough() {
|
2766
|
-
return new ZodObject({
|
2767
|
-
...this._def,
|
2768
|
-
unknownKeys: "passthrough",
|
2769
|
-
});
|
2770
|
-
}
|
2771
|
-
// const AugmentFactory =
|
2772
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
2773
|
-
// <Augmentation extends ZodRawShape>(
|
2774
|
-
// augmentation: Augmentation
|
2775
|
-
// ): ZodObject<
|
2776
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
2777
|
-
// Def["unknownKeys"],
|
2778
|
-
// Def["catchall"]
|
2779
|
-
// > => {
|
2780
|
-
// return new ZodObject({
|
2781
|
-
// ...def,
|
2782
|
-
// shape: () => ({
|
2783
|
-
// ...def.shape(),
|
2784
|
-
// ...augmentation,
|
2785
|
-
// }),
|
2786
|
-
// }) as any;
|
2787
|
-
// };
|
2788
|
-
extend(augmentation) {
|
2789
|
-
return new ZodObject({
|
2790
|
-
...this._def,
|
2791
|
-
shape: () => ({
|
2792
|
-
...this._def.shape(),
|
2793
|
-
...augmentation,
|
2794
|
-
}),
|
2795
|
-
});
|
2796
|
-
}
|
2797
|
-
/**
|
2798
|
-
* Prior to zod@1.0.12 there was a bug in the
|
2799
|
-
* inferred type of merged objects. Please
|
2800
|
-
* upgrade if you are experiencing issues.
|
2801
|
-
*/
|
2802
|
-
merge(merging) {
|
2803
|
-
const merged = new ZodObject({
|
2804
|
-
unknownKeys: merging._def.unknownKeys,
|
2805
|
-
catchall: merging._def.catchall,
|
2806
|
-
shape: () => ({
|
2807
|
-
...this._def.shape(),
|
2808
|
-
...merging._def.shape(),
|
2809
|
-
}),
|
2810
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
2811
|
-
});
|
2812
|
-
return merged;
|
2813
|
-
}
|
2814
|
-
// merge<
|
2815
|
-
// Incoming extends AnyZodObject,
|
2816
|
-
// Augmentation extends Incoming["shape"],
|
2817
|
-
// NewOutput extends {
|
2818
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
2819
|
-
// ? Augmentation[k]["_output"]
|
2820
|
-
// : k extends keyof Output
|
2821
|
-
// ? Output[k]
|
2822
|
-
// : never;
|
2823
|
-
// },
|
2824
|
-
// NewInput extends {
|
2825
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
2826
|
-
// ? Augmentation[k]["_input"]
|
2827
|
-
// : k extends keyof Input
|
2828
|
-
// ? Input[k]
|
2829
|
-
// : never;
|
2830
|
-
// }
|
2831
|
-
// >(
|
2832
|
-
// merging: Incoming
|
2833
|
-
// ): ZodObject<
|
2834
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
2835
|
-
// Incoming["_def"]["unknownKeys"],
|
2836
|
-
// Incoming["_def"]["catchall"],
|
2837
|
-
// NewOutput,
|
2838
|
-
// NewInput
|
2839
|
-
// > {
|
2840
|
-
// const merged: any = new ZodObject({
|
2841
|
-
// unknownKeys: merging._def.unknownKeys,
|
2842
|
-
// catchall: merging._def.catchall,
|
2843
|
-
// shape: () =>
|
2844
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
2845
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
2846
|
-
// }) as any;
|
2847
|
-
// return merged;
|
2848
|
-
// }
|
2849
|
-
setKey(key, schema) {
|
2850
|
-
return this.augment({ [key]: schema });
|
2851
|
-
}
|
2852
|
-
// merge<Incoming extends AnyZodObject>(
|
2853
|
-
// merging: Incoming
|
2854
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
2855
|
-
// ZodObject<
|
2856
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
2857
|
-
// Incoming["_def"]["unknownKeys"],
|
2858
|
-
// Incoming["_def"]["catchall"]
|
2859
|
-
// > {
|
2860
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
2861
|
-
// // this._def.shape(),
|
2862
|
-
// // merging._def.shape()
|
2863
|
-
// // );
|
2864
|
-
// const merged: any = new ZodObject({
|
2865
|
-
// unknownKeys: merging._def.unknownKeys,
|
2866
|
-
// catchall: merging._def.catchall,
|
2867
|
-
// shape: () =>
|
2868
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
2869
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
2870
|
-
// }) as any;
|
2871
|
-
// return merged;
|
2872
|
-
// }
|
2873
|
-
catchall(index) {
|
2874
|
-
return new ZodObject({
|
2875
|
-
...this._def,
|
2876
|
-
catchall: index,
|
2877
|
-
});
|
2878
|
-
}
|
2879
|
-
pick(mask) {
|
2880
|
-
const shape = {};
|
2881
|
-
for (const key of util_js_1.util.objectKeys(mask)) {
|
2882
|
-
if (mask[key] && this.shape[key]) {
|
2883
|
-
shape[key] = this.shape[key];
|
2884
|
-
}
|
2885
|
-
}
|
2886
|
-
return new ZodObject({
|
2887
|
-
...this._def,
|
2888
|
-
shape: () => shape,
|
2889
|
-
});
|
2890
|
-
}
|
2891
|
-
omit(mask) {
|
2892
|
-
const shape = {};
|
2893
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) {
|
2894
|
-
if (!mask[key]) {
|
2895
|
-
shape[key] = this.shape[key];
|
2896
|
-
}
|
2897
|
-
}
|
2898
|
-
return new ZodObject({
|
2899
|
-
...this._def,
|
2900
|
-
shape: () => shape,
|
2901
|
-
});
|
2902
|
-
}
|
2903
|
-
/**
|
2904
|
-
* @deprecated
|
2905
|
-
*/
|
2906
|
-
deepPartial() {
|
2907
|
-
return deepPartialify(this);
|
2908
|
-
}
|
2909
|
-
partial(mask) {
|
2910
|
-
const newShape = {};
|
2911
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) {
|
2912
|
-
const fieldSchema = this.shape[key];
|
2913
|
-
if (mask && !mask[key]) {
|
2914
|
-
newShape[key] = fieldSchema;
|
2915
|
-
}
|
2916
|
-
else {
|
2917
|
-
newShape[key] = fieldSchema.optional();
|
2918
|
-
}
|
2919
|
-
}
|
2920
|
-
return new ZodObject({
|
2921
|
-
...this._def,
|
2922
|
-
shape: () => newShape,
|
2923
|
-
});
|
2924
|
-
}
|
2925
|
-
required(mask) {
|
2926
|
-
const newShape = {};
|
2927
|
-
for (const key of util_js_1.util.objectKeys(this.shape)) {
|
2928
|
-
if (mask && !mask[key]) {
|
2929
|
-
newShape[key] = this.shape[key];
|
2930
|
-
}
|
2931
|
-
else {
|
2932
|
-
const fieldSchema = this.shape[key];
|
2933
|
-
let newField = fieldSchema;
|
2934
|
-
while (newField instanceof ZodOptional) {
|
2935
|
-
newField = newField._def.innerType;
|
2936
|
-
}
|
2937
|
-
newShape[key] = newField;
|
2938
|
-
}
|
2939
|
-
}
|
2940
|
-
return new ZodObject({
|
2941
|
-
...this._def,
|
2942
|
-
shape: () => newShape,
|
2943
|
-
});
|
2944
|
-
}
|
2945
|
-
keyof() {
|
2946
|
-
return createZodEnum(util_js_1.util.objectKeys(this.shape));
|
2947
|
-
}
|
2948
|
-
}
|
2949
|
-
exports.ZodObject = ZodObject;
|
2950
|
-
ZodObject.create = (shape, params) => {
|
2951
|
-
return new ZodObject({
|
2952
|
-
shape: () => shape,
|
2953
|
-
unknownKeys: "strip",
|
2954
|
-
catchall: ZodNever.create(),
|
2955
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
2956
|
-
...processCreateParams(params),
|
2957
|
-
});
|
2958
|
-
};
|
2959
|
-
ZodObject.strictCreate = (shape, params) => {
|
2960
|
-
return new ZodObject({
|
2961
|
-
shape: () => shape,
|
2962
|
-
unknownKeys: "strict",
|
2963
|
-
catchall: ZodNever.create(),
|
2964
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
2965
|
-
...processCreateParams(params),
|
2966
|
-
});
|
2967
|
-
};
|
2968
|
-
ZodObject.lazycreate = (shape, params) => {
|
2969
|
-
return new ZodObject({
|
2970
|
-
shape,
|
2971
|
-
unknownKeys: "strip",
|
2972
|
-
catchall: ZodNever.create(),
|
2973
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
2974
|
-
...processCreateParams(params),
|
2975
|
-
});
|
2976
|
-
};
|
2977
|
-
class ZodUnion extends ZodType {
|
2978
|
-
_parse(input) {
|
2979
|
-
const { ctx } = this._processInputParams(input);
|
2980
|
-
const options = this._def.options;
|
2981
|
-
function handleResults(results) {
|
2982
|
-
// return first issue-free validation if it exists
|
2983
|
-
for (const result of results) {
|
2984
|
-
if (result.result.status === "valid") {
|
2985
|
-
return result.result;
|
2986
|
-
}
|
2987
|
-
}
|
2988
|
-
for (const result of results) {
|
2989
|
-
if (result.result.status === "dirty") {
|
2990
|
-
// add issues from dirty option
|
2991
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
2992
|
-
return result.result;
|
2993
|
-
}
|
2994
|
-
}
|
2995
|
-
// return invalid
|
2996
|
-
const unionErrors = results.map((result) => new ZodError_js_1.ZodError(result.ctx.common.issues));
|
2997
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
2998
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union,
|
2999
|
-
unionErrors,
|
3000
|
-
});
|
3001
|
-
return parseUtil_js_1.INVALID;
|
3002
|
-
}
|
3003
|
-
if (ctx.common.async) {
|
3004
|
-
return Promise.all(options.map(async (option) => {
|
3005
|
-
const childCtx = {
|
3006
|
-
...ctx,
|
3007
|
-
common: {
|
3008
|
-
...ctx.common,
|
3009
|
-
issues: [],
|
3010
|
-
},
|
3011
|
-
parent: null,
|
3012
|
-
};
|
3013
|
-
return {
|
3014
|
-
result: await option._parseAsync({
|
3015
|
-
data: ctx.data,
|
3016
|
-
path: ctx.path,
|
3017
|
-
parent: childCtx,
|
3018
|
-
}),
|
3019
|
-
ctx: childCtx,
|
3020
|
-
};
|
3021
|
-
})).then(handleResults);
|
3022
|
-
}
|
3023
|
-
else {
|
3024
|
-
let dirty = undefined;
|
3025
|
-
const issues = [];
|
3026
|
-
for (const option of options) {
|
3027
|
-
const childCtx = {
|
3028
|
-
...ctx,
|
3029
|
-
common: {
|
3030
|
-
...ctx.common,
|
3031
|
-
issues: [],
|
3032
|
-
},
|
3033
|
-
parent: null,
|
3034
|
-
};
|
3035
|
-
const result = option._parseSync({
|
3036
|
-
data: ctx.data,
|
3037
|
-
path: ctx.path,
|
3038
|
-
parent: childCtx,
|
3039
|
-
});
|
3040
|
-
if (result.status === "valid") {
|
3041
|
-
return result;
|
3042
|
-
}
|
3043
|
-
else if (result.status === "dirty" && !dirty) {
|
3044
|
-
dirty = { result, ctx: childCtx };
|
3045
|
-
}
|
3046
|
-
if (childCtx.common.issues.length) {
|
3047
|
-
issues.push(childCtx.common.issues);
|
3048
|
-
}
|
3049
|
-
}
|
3050
|
-
if (dirty) {
|
3051
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
3052
|
-
return dirty.result;
|
3053
|
-
}
|
3054
|
-
const unionErrors = issues.map((issues) => new ZodError_js_1.ZodError(issues));
|
3055
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3056
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union,
|
3057
|
-
unionErrors,
|
3058
|
-
});
|
3059
|
-
return parseUtil_js_1.INVALID;
|
3060
|
-
}
|
3061
|
-
}
|
3062
|
-
get options() {
|
3063
|
-
return this._def.options;
|
3064
|
-
}
|
3065
|
-
}
|
3066
|
-
exports.ZodUnion = ZodUnion;
|
3067
|
-
ZodUnion.create = (types, params) => {
|
3068
|
-
return new ZodUnion({
|
3069
|
-
options: types,
|
3070
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
3071
|
-
...processCreateParams(params),
|
3072
|
-
});
|
3073
|
-
};
|
3074
|
-
/////////////////////////////////////////////////////
|
3075
|
-
/////////////////////////////////////////////////////
|
3076
|
-
////////// //////////
|
3077
|
-
////////// ZodDiscriminatedUnion //////////
|
3078
|
-
////////// //////////
|
3079
|
-
/////////////////////////////////////////////////////
|
3080
|
-
/////////////////////////////////////////////////////
|
3081
|
-
const getDiscriminator = (type) => {
|
3082
|
-
if (type instanceof ZodLazy) {
|
3083
|
-
return getDiscriminator(type.schema);
|
3084
|
-
}
|
3085
|
-
else if (type instanceof ZodEffects) {
|
3086
|
-
return getDiscriminator(type.innerType());
|
3087
|
-
}
|
3088
|
-
else if (type instanceof ZodLiteral) {
|
3089
|
-
return [type.value];
|
3090
|
-
}
|
3091
|
-
else if (type instanceof ZodEnum) {
|
3092
|
-
return type.options;
|
3093
|
-
}
|
3094
|
-
else if (type instanceof ZodNativeEnum) {
|
3095
|
-
// eslint-disable-next-line ban/ban
|
3096
|
-
return util_js_1.util.objectValues(type.enum);
|
3097
|
-
}
|
3098
|
-
else if (type instanceof ZodDefault) {
|
3099
|
-
return getDiscriminator(type._def.innerType);
|
3100
|
-
}
|
3101
|
-
else if (type instanceof ZodUndefined) {
|
3102
|
-
return [undefined];
|
3103
|
-
}
|
3104
|
-
else if (type instanceof ZodNull) {
|
3105
|
-
return [null];
|
3106
|
-
}
|
3107
|
-
else if (type instanceof ZodOptional) {
|
3108
|
-
return [undefined, ...getDiscriminator(type.unwrap())];
|
3109
|
-
}
|
3110
|
-
else if (type instanceof ZodNullable) {
|
3111
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
3112
|
-
}
|
3113
|
-
else if (type instanceof ZodBranded) {
|
3114
|
-
return getDiscriminator(type.unwrap());
|
3115
|
-
}
|
3116
|
-
else if (type instanceof ZodReadonly) {
|
3117
|
-
return getDiscriminator(type.unwrap());
|
3118
|
-
}
|
3119
|
-
else if (type instanceof ZodCatch) {
|
3120
|
-
return getDiscriminator(type._def.innerType);
|
3121
|
-
}
|
3122
|
-
else {
|
3123
|
-
return [];
|
3124
|
-
}
|
3125
|
-
};
|
3126
|
-
class ZodDiscriminatedUnion extends ZodType {
|
3127
|
-
_parse(input) {
|
3128
|
-
const { ctx } = this._processInputParams(input);
|
3129
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
|
3130
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3131
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3132
|
-
expected: util_js_1.ZodParsedType.object,
|
3133
|
-
received: ctx.parsedType,
|
3134
|
-
});
|
3135
|
-
return parseUtil_js_1.INVALID;
|
3136
|
-
}
|
3137
|
-
const discriminator = this.discriminator;
|
3138
|
-
const discriminatorValue = ctx.data[discriminator];
|
3139
|
-
const option = this.optionsMap.get(discriminatorValue);
|
3140
|
-
if (!option) {
|
3141
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3142
|
-
code: ZodError_js_1.ZodIssueCode.invalid_union_discriminator,
|
3143
|
-
options: Array.from(this.optionsMap.keys()),
|
3144
|
-
path: [discriminator],
|
3145
|
-
});
|
3146
|
-
return parseUtil_js_1.INVALID;
|
3147
|
-
}
|
3148
|
-
if (ctx.common.async) {
|
3149
|
-
return option._parseAsync({
|
3150
|
-
data: ctx.data,
|
3151
|
-
path: ctx.path,
|
3152
|
-
parent: ctx,
|
3153
|
-
});
|
3154
|
-
}
|
3155
|
-
else {
|
3156
|
-
return option._parseSync({
|
3157
|
-
data: ctx.data,
|
3158
|
-
path: ctx.path,
|
3159
|
-
parent: ctx,
|
3160
|
-
});
|
3161
|
-
}
|
3162
|
-
}
|
3163
|
-
get discriminator() {
|
3164
|
-
return this._def.discriminator;
|
3165
|
-
}
|
3166
|
-
get options() {
|
3167
|
-
return this._def.options;
|
3168
|
-
}
|
3169
|
-
get optionsMap() {
|
3170
|
-
return this._def.optionsMap;
|
3171
|
-
}
|
3172
|
-
/**
|
3173
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
3174
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
3175
|
-
* have a different value for each object in the union.
|
3176
|
-
* @param discriminator the name of the discriminator property
|
3177
|
-
* @param types an array of object schemas
|
3178
|
-
* @param params
|
3179
|
-
*/
|
3180
|
-
static create(discriminator, options, params) {
|
3181
|
-
// Get all the valid discriminator values
|
3182
|
-
const optionsMap = new Map();
|
3183
|
-
// try {
|
3184
|
-
for (const type of options) {
|
3185
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
3186
|
-
if (!discriminatorValues.length) {
|
3187
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
3188
|
-
}
|
3189
|
-
for (const value of discriminatorValues) {
|
3190
|
-
if (optionsMap.has(value)) {
|
3191
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
3192
|
-
}
|
3193
|
-
optionsMap.set(value, type);
|
3194
|
-
}
|
3195
|
-
}
|
3196
|
-
return new ZodDiscriminatedUnion({
|
3197
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
3198
|
-
discriminator,
|
3199
|
-
options,
|
3200
|
-
optionsMap,
|
3201
|
-
...processCreateParams(params),
|
3202
|
-
});
|
3203
|
-
}
|
3204
|
-
}
|
3205
|
-
exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
|
3206
|
-
function mergeValues(a, b) {
|
3207
|
-
const aType = (0, util_js_1.getParsedType)(a);
|
3208
|
-
const bType = (0, util_js_1.getParsedType)(b);
|
3209
|
-
if (a === b) {
|
3210
|
-
return { valid: true, data: a };
|
3211
|
-
}
|
3212
|
-
else if (aType === util_js_1.ZodParsedType.object && bType === util_js_1.ZodParsedType.object) {
|
3213
|
-
const bKeys = util_js_1.util.objectKeys(b);
|
3214
|
-
const sharedKeys = util_js_1.util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
3215
|
-
const newObj = { ...a, ...b };
|
3216
|
-
for (const key of sharedKeys) {
|
3217
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
3218
|
-
if (!sharedValue.valid) {
|
3219
|
-
return { valid: false };
|
3220
|
-
}
|
3221
|
-
newObj[key] = sharedValue.data;
|
3222
|
-
}
|
3223
|
-
return { valid: true, data: newObj };
|
3224
|
-
}
|
3225
|
-
else if (aType === util_js_1.ZodParsedType.array && bType === util_js_1.ZodParsedType.array) {
|
3226
|
-
if (a.length !== b.length) {
|
3227
|
-
return { valid: false };
|
3228
|
-
}
|
3229
|
-
const newArray = [];
|
3230
|
-
for (let index = 0; index < a.length; index++) {
|
3231
|
-
const itemA = a[index];
|
3232
|
-
const itemB = b[index];
|
3233
|
-
const sharedValue = mergeValues(itemA, itemB);
|
3234
|
-
if (!sharedValue.valid) {
|
3235
|
-
return { valid: false };
|
3236
|
-
}
|
3237
|
-
newArray.push(sharedValue.data);
|
3238
|
-
}
|
3239
|
-
return { valid: true, data: newArray };
|
3240
|
-
}
|
3241
|
-
else if (aType === util_js_1.ZodParsedType.date && bType === util_js_1.ZodParsedType.date && +a === +b) {
|
3242
|
-
return { valid: true, data: a };
|
3243
|
-
}
|
3244
|
-
else {
|
3245
|
-
return { valid: false };
|
3246
|
-
}
|
3247
|
-
}
|
3248
|
-
class ZodIntersection extends ZodType {
|
3249
|
-
_parse(input) {
|
3250
|
-
const { status, ctx } = this._processInputParams(input);
|
3251
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
3252
|
-
if ((0, parseUtil_js_1.isAborted)(parsedLeft) || (0, parseUtil_js_1.isAborted)(parsedRight)) {
|
3253
|
-
return parseUtil_js_1.INVALID;
|
3254
|
-
}
|
3255
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
3256
|
-
if (!merged.valid) {
|
3257
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3258
|
-
code: ZodError_js_1.ZodIssueCode.invalid_intersection_types,
|
3259
|
-
});
|
3260
|
-
return parseUtil_js_1.INVALID;
|
3261
|
-
}
|
3262
|
-
if ((0, parseUtil_js_1.isDirty)(parsedLeft) || (0, parseUtil_js_1.isDirty)(parsedRight)) {
|
3263
|
-
status.dirty();
|
3264
|
-
}
|
3265
|
-
return { status: status.value, value: merged.data };
|
3266
|
-
};
|
3267
|
-
if (ctx.common.async) {
|
3268
|
-
return Promise.all([
|
3269
|
-
this._def.left._parseAsync({
|
3270
|
-
data: ctx.data,
|
3271
|
-
path: ctx.path,
|
3272
|
-
parent: ctx,
|
3273
|
-
}),
|
3274
|
-
this._def.right._parseAsync({
|
3275
|
-
data: ctx.data,
|
3276
|
-
path: ctx.path,
|
3277
|
-
parent: ctx,
|
3278
|
-
}),
|
3279
|
-
]).then(([left, right]) => handleParsed(left, right));
|
3280
|
-
}
|
3281
|
-
else {
|
3282
|
-
return handleParsed(this._def.left._parseSync({
|
3283
|
-
data: ctx.data,
|
3284
|
-
path: ctx.path,
|
3285
|
-
parent: ctx,
|
3286
|
-
}), this._def.right._parseSync({
|
3287
|
-
data: ctx.data,
|
3288
|
-
path: ctx.path,
|
3289
|
-
parent: ctx,
|
3290
|
-
}));
|
3291
|
-
}
|
3292
|
-
}
|
3293
|
-
}
|
3294
|
-
exports.ZodIntersection = ZodIntersection;
|
3295
|
-
ZodIntersection.create = (left, right, params) => {
|
3296
|
-
return new ZodIntersection({
|
3297
|
-
left: left,
|
3298
|
-
right: right,
|
3299
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
3300
|
-
...processCreateParams(params),
|
3301
|
-
});
|
3302
|
-
};
|
3303
|
-
// type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
|
3304
|
-
class ZodTuple extends ZodType {
|
3305
|
-
_parse(input) {
|
3306
|
-
const { status, ctx } = this._processInputParams(input);
|
3307
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.array) {
|
3308
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3309
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3310
|
-
expected: util_js_1.ZodParsedType.array,
|
3311
|
-
received: ctx.parsedType,
|
3312
|
-
});
|
3313
|
-
return parseUtil_js_1.INVALID;
|
3314
|
-
}
|
3315
|
-
if (ctx.data.length < this._def.items.length) {
|
3316
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3317
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
3318
|
-
minimum: this._def.items.length,
|
3319
|
-
inclusive: true,
|
3320
|
-
exact: false,
|
3321
|
-
type: "array",
|
3322
|
-
});
|
3323
|
-
return parseUtil_js_1.INVALID;
|
3324
|
-
}
|
3325
|
-
const rest = this._def.rest;
|
3326
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
3327
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3328
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
3329
|
-
maximum: this._def.items.length,
|
3330
|
-
inclusive: true,
|
3331
|
-
exact: false,
|
3332
|
-
type: "array",
|
3333
|
-
});
|
3334
|
-
status.dirty();
|
3335
|
-
}
|
3336
|
-
const items = [...ctx.data]
|
3337
|
-
.map((item, itemIndex) => {
|
3338
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
3339
|
-
if (!schema)
|
3340
|
-
return null;
|
3341
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
3342
|
-
})
|
3343
|
-
.filter((x) => !!x); // filter nulls
|
3344
|
-
if (ctx.common.async) {
|
3345
|
-
return Promise.all(items).then((results) => {
|
3346
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, results);
|
3347
|
-
});
|
3348
|
-
}
|
3349
|
-
else {
|
3350
|
-
return parseUtil_js_1.ParseStatus.mergeArray(status, items);
|
3351
|
-
}
|
3352
|
-
}
|
3353
|
-
get items() {
|
3354
|
-
return this._def.items;
|
3355
|
-
}
|
3356
|
-
rest(rest) {
|
3357
|
-
return new ZodTuple({
|
3358
|
-
...this._def,
|
3359
|
-
rest,
|
3360
|
-
});
|
3361
|
-
}
|
3362
|
-
}
|
3363
|
-
exports.ZodTuple = ZodTuple;
|
3364
|
-
ZodTuple.create = (schemas, params) => {
|
3365
|
-
if (!Array.isArray(schemas)) {
|
3366
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
3367
|
-
}
|
3368
|
-
return new ZodTuple({
|
3369
|
-
items: schemas,
|
3370
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
3371
|
-
rest: null,
|
3372
|
-
...processCreateParams(params),
|
3373
|
-
});
|
3374
|
-
};
|
3375
|
-
class ZodRecord extends ZodType {
|
3376
|
-
get keySchema() {
|
3377
|
-
return this._def.keyType;
|
3378
|
-
}
|
3379
|
-
get valueSchema() {
|
3380
|
-
return this._def.valueType;
|
3381
|
-
}
|
3382
|
-
_parse(input) {
|
3383
|
-
const { status, ctx } = this._processInputParams(input);
|
3384
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.object) {
|
3385
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3386
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3387
|
-
expected: util_js_1.ZodParsedType.object,
|
3388
|
-
received: ctx.parsedType,
|
3389
|
-
});
|
3390
|
-
return parseUtil_js_1.INVALID;
|
3391
|
-
}
|
3392
|
-
const pairs = [];
|
3393
|
-
const keyType = this._def.keyType;
|
3394
|
-
const valueType = this._def.valueType;
|
3395
|
-
for (const key in ctx.data) {
|
3396
|
-
pairs.push({
|
3397
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
3398
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
3399
|
-
alwaysSet: key in ctx.data,
|
3400
|
-
});
|
3401
|
-
}
|
3402
|
-
if (ctx.common.async) {
|
3403
|
-
return parseUtil_js_1.ParseStatus.mergeObjectAsync(status, pairs);
|
3404
|
-
}
|
3405
|
-
else {
|
3406
|
-
return parseUtil_js_1.ParseStatus.mergeObjectSync(status, pairs);
|
3407
|
-
}
|
3408
|
-
}
|
3409
|
-
get element() {
|
3410
|
-
return this._def.valueType;
|
3411
|
-
}
|
3412
|
-
static create(first, second, third) {
|
3413
|
-
if (second instanceof ZodType) {
|
3414
|
-
return new ZodRecord({
|
3415
|
-
keyType: first,
|
3416
|
-
valueType: second,
|
3417
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
3418
|
-
...processCreateParams(third),
|
3419
|
-
});
|
3420
|
-
}
|
3421
|
-
return new ZodRecord({
|
3422
|
-
keyType: ZodString.create(),
|
3423
|
-
valueType: first,
|
3424
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
3425
|
-
...processCreateParams(second),
|
3426
|
-
});
|
3427
|
-
}
|
3428
|
-
}
|
3429
|
-
exports.ZodRecord = ZodRecord;
|
3430
|
-
class ZodMap extends ZodType {
|
3431
|
-
get keySchema() {
|
3432
|
-
return this._def.keyType;
|
3433
|
-
}
|
3434
|
-
get valueSchema() {
|
3435
|
-
return this._def.valueType;
|
3436
|
-
}
|
3437
|
-
_parse(input) {
|
3438
|
-
const { status, ctx } = this._processInputParams(input);
|
3439
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.map) {
|
3440
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3441
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3442
|
-
expected: util_js_1.ZodParsedType.map,
|
3443
|
-
received: ctx.parsedType,
|
3444
|
-
});
|
3445
|
-
return parseUtil_js_1.INVALID;
|
3446
|
-
}
|
3447
|
-
const keyType = this._def.keyType;
|
3448
|
-
const valueType = this._def.valueType;
|
3449
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
3450
|
-
return {
|
3451
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
3452
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
|
3453
|
-
};
|
3454
|
-
});
|
3455
|
-
if (ctx.common.async) {
|
3456
|
-
const finalMap = new Map();
|
3457
|
-
return Promise.resolve().then(async () => {
|
3458
|
-
for (const pair of pairs) {
|
3459
|
-
const key = await pair.key;
|
3460
|
-
const value = await pair.value;
|
3461
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
3462
|
-
return parseUtil_js_1.INVALID;
|
3463
|
-
}
|
3464
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
3465
|
-
status.dirty();
|
3466
|
-
}
|
3467
|
-
finalMap.set(key.value, value.value);
|
3468
|
-
}
|
3469
|
-
return { status: status.value, value: finalMap };
|
3470
|
-
});
|
3471
|
-
}
|
3472
|
-
else {
|
3473
|
-
const finalMap = new Map();
|
3474
|
-
for (const pair of pairs) {
|
3475
|
-
const key = pair.key;
|
3476
|
-
const value = pair.value;
|
3477
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
3478
|
-
return parseUtil_js_1.INVALID;
|
3479
|
-
}
|
3480
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
3481
|
-
status.dirty();
|
3482
|
-
}
|
3483
|
-
finalMap.set(key.value, value.value);
|
3484
|
-
}
|
3485
|
-
return { status: status.value, value: finalMap };
|
3486
|
-
}
|
3487
|
-
}
|
3488
|
-
}
|
3489
|
-
exports.ZodMap = ZodMap;
|
3490
|
-
ZodMap.create = (keyType, valueType, params) => {
|
3491
|
-
return new ZodMap({
|
3492
|
-
valueType,
|
3493
|
-
keyType,
|
3494
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
3495
|
-
...processCreateParams(params),
|
3496
|
-
});
|
3497
|
-
};
|
3498
|
-
class ZodSet extends ZodType {
|
3499
|
-
_parse(input) {
|
3500
|
-
const { status, ctx } = this._processInputParams(input);
|
3501
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.set) {
|
3502
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3503
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3504
|
-
expected: util_js_1.ZodParsedType.set,
|
3505
|
-
received: ctx.parsedType,
|
3506
|
-
});
|
3507
|
-
return parseUtil_js_1.INVALID;
|
3508
|
-
}
|
3509
|
-
const def = this._def;
|
3510
|
-
if (def.minSize !== null) {
|
3511
|
-
if (ctx.data.size < def.minSize.value) {
|
3512
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3513
|
-
code: ZodError_js_1.ZodIssueCode.too_small,
|
3514
|
-
minimum: def.minSize.value,
|
3515
|
-
type: "set",
|
3516
|
-
inclusive: true,
|
3517
|
-
exact: false,
|
3518
|
-
message: def.minSize.message,
|
3519
|
-
});
|
3520
|
-
status.dirty();
|
3521
|
-
}
|
3522
|
-
}
|
3523
|
-
if (def.maxSize !== null) {
|
3524
|
-
if (ctx.data.size > def.maxSize.value) {
|
3525
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3526
|
-
code: ZodError_js_1.ZodIssueCode.too_big,
|
3527
|
-
maximum: def.maxSize.value,
|
3528
|
-
type: "set",
|
3529
|
-
inclusive: true,
|
3530
|
-
exact: false,
|
3531
|
-
message: def.maxSize.message,
|
3532
|
-
});
|
3533
|
-
status.dirty();
|
3534
|
-
}
|
3535
|
-
}
|
3536
|
-
const valueType = this._def.valueType;
|
3537
|
-
function finalizeSet(elements) {
|
3538
|
-
const parsedSet = new Set();
|
3539
|
-
for (const element of elements) {
|
3540
|
-
if (element.status === "aborted")
|
3541
|
-
return parseUtil_js_1.INVALID;
|
3542
|
-
if (element.status === "dirty")
|
3543
|
-
status.dirty();
|
3544
|
-
parsedSet.add(element.value);
|
3545
|
-
}
|
3546
|
-
return { status: status.value, value: parsedSet };
|
3547
|
-
}
|
3548
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
3549
|
-
if (ctx.common.async) {
|
3550
|
-
return Promise.all(elements).then((elements) => finalizeSet(elements));
|
3551
|
-
}
|
3552
|
-
else {
|
3553
|
-
return finalizeSet(elements);
|
3554
|
-
}
|
3555
|
-
}
|
3556
|
-
min(minSize, message) {
|
3557
|
-
return new ZodSet({
|
3558
|
-
...this._def,
|
3559
|
-
minSize: { value: minSize, message: errorUtil_js_1.errorUtil.toString(message) },
|
3560
|
-
});
|
3561
|
-
}
|
3562
|
-
max(maxSize, message) {
|
3563
|
-
return new ZodSet({
|
3564
|
-
...this._def,
|
3565
|
-
maxSize: { value: maxSize, message: errorUtil_js_1.errorUtil.toString(message) },
|
3566
|
-
});
|
3567
|
-
}
|
3568
|
-
size(size, message) {
|
3569
|
-
return this.min(size, message).max(size, message);
|
3570
|
-
}
|
3571
|
-
nonempty(message) {
|
3572
|
-
return this.min(1, message);
|
3573
|
-
}
|
3574
|
-
}
|
3575
|
-
exports.ZodSet = ZodSet;
|
3576
|
-
ZodSet.create = (valueType, params) => {
|
3577
|
-
return new ZodSet({
|
3578
|
-
valueType,
|
3579
|
-
minSize: null,
|
3580
|
-
maxSize: null,
|
3581
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
3582
|
-
...processCreateParams(params),
|
3583
|
-
});
|
3584
|
-
};
|
3585
|
-
class ZodFunction extends ZodType {
|
3586
|
-
constructor() {
|
3587
|
-
super(...arguments);
|
3588
|
-
this.validate = this.implement;
|
3589
|
-
}
|
3590
|
-
_parse(input) {
|
3591
|
-
const { ctx } = this._processInputParams(input);
|
3592
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.function) {
|
3593
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3594
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3595
|
-
expected: util_js_1.ZodParsedType.function,
|
3596
|
-
received: ctx.parsedType,
|
3597
|
-
});
|
3598
|
-
return parseUtil_js_1.INVALID;
|
3599
|
-
}
|
3600
|
-
function makeArgsIssue(args, error) {
|
3601
|
-
return (0, parseUtil_js_1.makeIssue)({
|
3602
|
-
data: args,
|
3603
|
-
path: ctx.path,
|
3604
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, (0, errors_js_1.getErrorMap)(), errors_js_1.defaultErrorMap].filter((x) => !!x),
|
3605
|
-
issueData: {
|
3606
|
-
code: ZodError_js_1.ZodIssueCode.invalid_arguments,
|
3607
|
-
argumentsError: error,
|
3608
|
-
},
|
3609
|
-
});
|
3610
|
-
}
|
3611
|
-
function makeReturnsIssue(returns, error) {
|
3612
|
-
return (0, parseUtil_js_1.makeIssue)({
|
3613
|
-
data: returns,
|
3614
|
-
path: ctx.path,
|
3615
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, (0, errors_js_1.getErrorMap)(), errors_js_1.defaultErrorMap].filter((x) => !!x),
|
3616
|
-
issueData: {
|
3617
|
-
code: ZodError_js_1.ZodIssueCode.invalid_return_type,
|
3618
|
-
returnTypeError: error,
|
3619
|
-
},
|
3620
|
-
});
|
3621
|
-
}
|
3622
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
3623
|
-
const fn = ctx.data;
|
3624
|
-
if (this._def.returns instanceof ZodPromise) {
|
3625
|
-
// Would love a way to avoid disabling this rule, but we need
|
3626
|
-
// an alias (using an arrow function was what caused 2651).
|
3627
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
3628
|
-
const me = this;
|
3629
|
-
return (0, parseUtil_js_1.OK)(async function (...args) {
|
3630
|
-
const error = new ZodError_js_1.ZodError([]);
|
3631
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
3632
|
-
error.addIssue(makeArgsIssue(args, e));
|
3633
|
-
throw error;
|
3634
|
-
});
|
3635
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
3636
|
-
const parsedReturns = await me._def.returns._def.type
|
3637
|
-
.parseAsync(result, params)
|
3638
|
-
.catch((e) => {
|
3639
|
-
error.addIssue(makeReturnsIssue(result, e));
|
3640
|
-
throw error;
|
3641
|
-
});
|
3642
|
-
return parsedReturns;
|
3643
|
-
});
|
3644
|
-
}
|
3645
|
-
else {
|
3646
|
-
// Would love a way to avoid disabling this rule, but we need
|
3647
|
-
// an alias (using an arrow function was what caused 2651).
|
3648
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
3649
|
-
const me = this;
|
3650
|
-
return (0, parseUtil_js_1.OK)(function (...args) {
|
3651
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
3652
|
-
if (!parsedArgs.success) {
|
3653
|
-
throw new ZodError_js_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
3654
|
-
}
|
3655
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
3656
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
3657
|
-
if (!parsedReturns.success) {
|
3658
|
-
throw new ZodError_js_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
3659
|
-
}
|
3660
|
-
return parsedReturns.data;
|
3661
|
-
});
|
3662
|
-
}
|
3663
|
-
}
|
3664
|
-
parameters() {
|
3665
|
-
return this._def.args;
|
3666
|
-
}
|
3667
|
-
returnType() {
|
3668
|
-
return this._def.returns;
|
3669
|
-
}
|
3670
|
-
args(...items) {
|
3671
|
-
return new ZodFunction({
|
3672
|
-
...this._def,
|
3673
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create()),
|
3674
|
-
});
|
3675
|
-
}
|
3676
|
-
returns(returnType) {
|
3677
|
-
return new ZodFunction({
|
3678
|
-
...this._def,
|
3679
|
-
returns: returnType,
|
3680
|
-
});
|
3681
|
-
}
|
3682
|
-
implement(func) {
|
3683
|
-
const validatedFunc = this.parse(func);
|
3684
|
-
return validatedFunc;
|
3685
|
-
}
|
3686
|
-
strictImplement(func) {
|
3687
|
-
const validatedFunc = this.parse(func);
|
3688
|
-
return validatedFunc;
|
3689
|
-
}
|
3690
|
-
static create(args, returns, params) {
|
3691
|
-
return new ZodFunction({
|
3692
|
-
args: (args ? args : ZodTuple.create([]).rest(ZodUnknown.create())),
|
3693
|
-
returns: returns || ZodUnknown.create(),
|
3694
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
3695
|
-
...processCreateParams(params),
|
3696
|
-
});
|
3697
|
-
}
|
3698
|
-
}
|
3699
|
-
exports.ZodFunction = ZodFunction;
|
3700
|
-
class ZodLazy extends ZodType {
|
3701
|
-
get schema() {
|
3702
|
-
return this._def.getter();
|
3703
|
-
}
|
3704
|
-
_parse(input) {
|
3705
|
-
const { ctx } = this._processInputParams(input);
|
3706
|
-
const lazySchema = this._def.getter();
|
3707
|
-
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
3708
|
-
}
|
3709
|
-
}
|
3710
|
-
exports.ZodLazy = ZodLazy;
|
3711
|
-
ZodLazy.create = (getter, params) => {
|
3712
|
-
return new ZodLazy({
|
3713
|
-
getter: getter,
|
3714
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
3715
|
-
...processCreateParams(params),
|
3716
|
-
});
|
3717
|
-
};
|
3718
|
-
class ZodLiteral extends ZodType {
|
3719
|
-
_parse(input) {
|
3720
|
-
if (input.data !== this._def.value) {
|
3721
|
-
const ctx = this._getOrReturnCtx(input);
|
3722
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3723
|
-
received: ctx.data,
|
3724
|
-
code: ZodError_js_1.ZodIssueCode.invalid_literal,
|
3725
|
-
expected: this._def.value,
|
3726
|
-
});
|
3727
|
-
return parseUtil_js_1.INVALID;
|
3728
|
-
}
|
3729
|
-
return { status: "valid", value: input.data };
|
3730
|
-
}
|
3731
|
-
get value() {
|
3732
|
-
return this._def.value;
|
3733
|
-
}
|
3734
|
-
}
|
3735
|
-
exports.ZodLiteral = ZodLiteral;
|
3736
|
-
ZodLiteral.create = (value, params) => {
|
3737
|
-
return new ZodLiteral({
|
3738
|
-
value: value,
|
3739
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
3740
|
-
...processCreateParams(params),
|
3741
|
-
});
|
3742
|
-
};
|
3743
|
-
function createZodEnum(values, params) {
|
3744
|
-
return new ZodEnum({
|
3745
|
-
values,
|
3746
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
3747
|
-
...processCreateParams(params),
|
3748
|
-
});
|
3749
|
-
}
|
3750
|
-
class ZodEnum extends ZodType {
|
3751
|
-
_parse(input) {
|
3752
|
-
if (typeof input.data !== "string") {
|
3753
|
-
const ctx = this._getOrReturnCtx(input);
|
3754
|
-
const expectedValues = this._def.values;
|
3755
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3756
|
-
expected: util_js_1.util.joinValues(expectedValues),
|
3757
|
-
received: ctx.parsedType,
|
3758
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3759
|
-
});
|
3760
|
-
return parseUtil_js_1.INVALID;
|
3761
|
-
}
|
3762
|
-
if (!this._cache) {
|
3763
|
-
this._cache = new Set(this._def.values);
|
3764
|
-
}
|
3765
|
-
if (!this._cache.has(input.data)) {
|
3766
|
-
const ctx = this._getOrReturnCtx(input);
|
3767
|
-
const expectedValues = this._def.values;
|
3768
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3769
|
-
received: ctx.data,
|
3770
|
-
code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
|
3771
|
-
options: expectedValues,
|
3772
|
-
});
|
3773
|
-
return parseUtil_js_1.INVALID;
|
3774
|
-
}
|
3775
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
3776
|
-
}
|
3777
|
-
get options() {
|
3778
|
-
return this._def.values;
|
3779
|
-
}
|
3780
|
-
get enum() {
|
3781
|
-
const enumValues = {};
|
3782
|
-
for (const val of this._def.values) {
|
3783
|
-
enumValues[val] = val;
|
3784
|
-
}
|
3785
|
-
return enumValues;
|
3786
|
-
}
|
3787
|
-
get Values() {
|
3788
|
-
const enumValues = {};
|
3789
|
-
for (const val of this._def.values) {
|
3790
|
-
enumValues[val] = val;
|
3791
|
-
}
|
3792
|
-
return enumValues;
|
3793
|
-
}
|
3794
|
-
get Enum() {
|
3795
|
-
const enumValues = {};
|
3796
|
-
for (const val of this._def.values) {
|
3797
|
-
enumValues[val] = val;
|
3798
|
-
}
|
3799
|
-
return enumValues;
|
3800
|
-
}
|
3801
|
-
extract(values, newDef = this._def) {
|
3802
|
-
return ZodEnum.create(values, {
|
3803
|
-
...this._def,
|
3804
|
-
...newDef,
|
3805
|
-
});
|
3806
|
-
}
|
3807
|
-
exclude(values, newDef = this._def) {
|
3808
|
-
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
3809
|
-
...this._def,
|
3810
|
-
...newDef,
|
3811
|
-
});
|
3812
|
-
}
|
3813
|
-
}
|
3814
|
-
exports.ZodEnum = ZodEnum;
|
3815
|
-
ZodEnum.create = createZodEnum;
|
3816
|
-
class ZodNativeEnum extends ZodType {
|
3817
|
-
_parse(input) {
|
3818
|
-
const nativeEnumValues = util_js_1.util.getValidEnumValues(this._def.values);
|
3819
|
-
const ctx = this._getOrReturnCtx(input);
|
3820
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.string && ctx.parsedType !== util_js_1.ZodParsedType.number) {
|
3821
|
-
const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
|
3822
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3823
|
-
expected: util_js_1.util.joinValues(expectedValues),
|
3824
|
-
received: ctx.parsedType,
|
3825
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3826
|
-
});
|
3827
|
-
return parseUtil_js_1.INVALID;
|
3828
|
-
}
|
3829
|
-
if (!this._cache) {
|
3830
|
-
this._cache = new Set(util_js_1.util.getValidEnumValues(this._def.values));
|
3831
|
-
}
|
3832
|
-
if (!this._cache.has(input.data)) {
|
3833
|
-
const expectedValues = util_js_1.util.objectValues(nativeEnumValues);
|
3834
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3835
|
-
received: ctx.data,
|
3836
|
-
code: ZodError_js_1.ZodIssueCode.invalid_enum_value,
|
3837
|
-
options: expectedValues,
|
3838
|
-
});
|
3839
|
-
return parseUtil_js_1.INVALID;
|
3840
|
-
}
|
3841
|
-
return (0, parseUtil_js_1.OK)(input.data);
|
3842
|
-
}
|
3843
|
-
get enum() {
|
3844
|
-
return this._def.values;
|
3845
|
-
}
|
3846
|
-
}
|
3847
|
-
exports.ZodNativeEnum = ZodNativeEnum;
|
3848
|
-
ZodNativeEnum.create = (values, params) => {
|
3849
|
-
return new ZodNativeEnum({
|
3850
|
-
values: values,
|
3851
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
3852
|
-
...processCreateParams(params),
|
3853
|
-
});
|
3854
|
-
};
|
3855
|
-
class ZodPromise extends ZodType {
|
3856
|
-
unwrap() {
|
3857
|
-
return this._def.type;
|
3858
|
-
}
|
3859
|
-
_parse(input) {
|
3860
|
-
const { ctx } = this._processInputParams(input);
|
3861
|
-
if (ctx.parsedType !== util_js_1.ZodParsedType.promise && ctx.common.async === false) {
|
3862
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
3863
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
3864
|
-
expected: util_js_1.ZodParsedType.promise,
|
3865
|
-
received: ctx.parsedType,
|
3866
|
-
});
|
3867
|
-
return parseUtil_js_1.INVALID;
|
3868
|
-
}
|
3869
|
-
const promisified = ctx.parsedType === util_js_1.ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
3870
|
-
return (0, parseUtil_js_1.OK)(promisified.then((data) => {
|
3871
|
-
return this._def.type.parseAsync(data, {
|
3872
|
-
path: ctx.path,
|
3873
|
-
errorMap: ctx.common.contextualErrorMap,
|
3874
|
-
});
|
3875
|
-
}));
|
3876
|
-
}
|
3877
|
-
}
|
3878
|
-
exports.ZodPromise = ZodPromise;
|
3879
|
-
ZodPromise.create = (schema, params) => {
|
3880
|
-
return new ZodPromise({
|
3881
|
-
type: schema,
|
3882
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
3883
|
-
...processCreateParams(params),
|
3884
|
-
});
|
3885
|
-
};
|
3886
|
-
class ZodEffects extends ZodType {
|
3887
|
-
innerType() {
|
3888
|
-
return this._def.schema;
|
3889
|
-
}
|
3890
|
-
sourceType() {
|
3891
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
|
3892
|
-
? this._def.schema.sourceType()
|
3893
|
-
: this._def.schema;
|
3894
|
-
}
|
3895
|
-
_parse(input) {
|
3896
|
-
const { status, ctx } = this._processInputParams(input);
|
3897
|
-
const effect = this._def.effect || null;
|
3898
|
-
const checkCtx = {
|
3899
|
-
addIssue: (arg) => {
|
3900
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, arg);
|
3901
|
-
if (arg.fatal) {
|
3902
|
-
status.abort();
|
3903
|
-
}
|
3904
|
-
else {
|
3905
|
-
status.dirty();
|
3906
|
-
}
|
3907
|
-
},
|
3908
|
-
get path() {
|
3909
|
-
return ctx.path;
|
3910
|
-
},
|
3911
|
-
};
|
3912
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
3913
|
-
if (effect.type === "preprocess") {
|
3914
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
3915
|
-
if (ctx.common.async) {
|
3916
|
-
return Promise.resolve(processed).then(async (processed) => {
|
3917
|
-
if (status.value === "aborted")
|
3918
|
-
return parseUtil_js_1.INVALID;
|
3919
|
-
const result = await this._def.schema._parseAsync({
|
3920
|
-
data: processed,
|
3921
|
-
path: ctx.path,
|
3922
|
-
parent: ctx,
|
3923
|
-
});
|
3924
|
-
if (result.status === "aborted")
|
3925
|
-
return parseUtil_js_1.INVALID;
|
3926
|
-
if (result.status === "dirty")
|
3927
|
-
return (0, parseUtil_js_1.DIRTY)(result.value);
|
3928
|
-
if (status.value === "dirty")
|
3929
|
-
return (0, parseUtil_js_1.DIRTY)(result.value);
|
3930
|
-
return result;
|
3931
|
-
});
|
3932
|
-
}
|
3933
|
-
else {
|
3934
|
-
if (status.value === "aborted")
|
3935
|
-
return parseUtil_js_1.INVALID;
|
3936
|
-
const result = this._def.schema._parseSync({
|
3937
|
-
data: processed,
|
3938
|
-
path: ctx.path,
|
3939
|
-
parent: ctx,
|
3940
|
-
});
|
3941
|
-
if (result.status === "aborted")
|
3942
|
-
return parseUtil_js_1.INVALID;
|
3943
|
-
if (result.status === "dirty")
|
3944
|
-
return (0, parseUtil_js_1.DIRTY)(result.value);
|
3945
|
-
if (status.value === "dirty")
|
3946
|
-
return (0, parseUtil_js_1.DIRTY)(result.value);
|
3947
|
-
return result;
|
3948
|
-
}
|
3949
|
-
}
|
3950
|
-
if (effect.type === "refinement") {
|
3951
|
-
const executeRefinement = (acc) => {
|
3952
|
-
const result = effect.refinement(acc, checkCtx);
|
3953
|
-
if (ctx.common.async) {
|
3954
|
-
return Promise.resolve(result);
|
3955
|
-
}
|
3956
|
-
if (result instanceof Promise) {
|
3957
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
3958
|
-
}
|
3959
|
-
return acc;
|
3960
|
-
};
|
3961
|
-
if (ctx.common.async === false) {
|
3962
|
-
const inner = this._def.schema._parseSync({
|
3963
|
-
data: ctx.data,
|
3964
|
-
path: ctx.path,
|
3965
|
-
parent: ctx,
|
3966
|
-
});
|
3967
|
-
if (inner.status === "aborted")
|
3968
|
-
return parseUtil_js_1.INVALID;
|
3969
|
-
if (inner.status === "dirty")
|
3970
|
-
status.dirty();
|
3971
|
-
// return value is ignored
|
3972
|
-
executeRefinement(inner.value);
|
3973
|
-
return { status: status.value, value: inner.value };
|
3974
|
-
}
|
3975
|
-
else {
|
3976
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
3977
|
-
if (inner.status === "aborted")
|
3978
|
-
return parseUtil_js_1.INVALID;
|
3979
|
-
if (inner.status === "dirty")
|
3980
|
-
status.dirty();
|
3981
|
-
return executeRefinement(inner.value).then(() => {
|
3982
|
-
return { status: status.value, value: inner.value };
|
3983
|
-
});
|
3984
|
-
});
|
3985
|
-
}
|
3986
|
-
}
|
3987
|
-
if (effect.type === "transform") {
|
3988
|
-
if (ctx.common.async === false) {
|
3989
|
-
const base = this._def.schema._parseSync({
|
3990
|
-
data: ctx.data,
|
3991
|
-
path: ctx.path,
|
3992
|
-
parent: ctx,
|
3993
|
-
});
|
3994
|
-
if (!(0, parseUtil_js_1.isValid)(base))
|
3995
|
-
return parseUtil_js_1.INVALID;
|
3996
|
-
const result = effect.transform(base.value, checkCtx);
|
3997
|
-
if (result instanceof Promise) {
|
3998
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
3999
|
-
}
|
4000
|
-
return { status: status.value, value: result };
|
4001
|
-
}
|
4002
|
-
else {
|
4003
|
-
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
4004
|
-
if (!(0, parseUtil_js_1.isValid)(base))
|
4005
|
-
return parseUtil_js_1.INVALID;
|
4006
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
4007
|
-
status: status.value,
|
4008
|
-
value: result,
|
4009
|
-
}));
|
4010
|
-
});
|
4011
|
-
}
|
4012
|
-
}
|
4013
|
-
util_js_1.util.assertNever(effect);
|
4014
|
-
}
|
4015
|
-
}
|
4016
|
-
exports.ZodEffects = ZodEffects;
|
4017
|
-
exports.ZodTransformer = ZodEffects;
|
4018
|
-
ZodEffects.create = (schema, effect, params) => {
|
4019
|
-
return new ZodEffects({
|
4020
|
-
schema,
|
4021
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
4022
|
-
effect,
|
4023
|
-
...processCreateParams(params),
|
4024
|
-
});
|
4025
|
-
};
|
4026
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
4027
|
-
return new ZodEffects({
|
4028
|
-
schema,
|
4029
|
-
effect: { type: "preprocess", transform: preprocess },
|
4030
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
4031
|
-
...processCreateParams(params),
|
4032
|
-
});
|
4033
|
-
};
|
4034
|
-
class ZodOptional extends ZodType {
|
4035
|
-
_parse(input) {
|
4036
|
-
const parsedType = this._getType(input);
|
4037
|
-
if (parsedType === util_js_1.ZodParsedType.undefined) {
|
4038
|
-
return (0, parseUtil_js_1.OK)(undefined);
|
4039
|
-
}
|
4040
|
-
return this._def.innerType._parse(input);
|
4041
|
-
}
|
4042
|
-
unwrap() {
|
4043
|
-
return this._def.innerType;
|
4044
|
-
}
|
4045
|
-
}
|
4046
|
-
exports.ZodOptional = ZodOptional;
|
4047
|
-
ZodOptional.create = (type, params) => {
|
4048
|
-
return new ZodOptional({
|
4049
|
-
innerType: type,
|
4050
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
4051
|
-
...processCreateParams(params),
|
4052
|
-
});
|
4053
|
-
};
|
4054
|
-
class ZodNullable extends ZodType {
|
4055
|
-
_parse(input) {
|
4056
|
-
const parsedType = this._getType(input);
|
4057
|
-
if (parsedType === util_js_1.ZodParsedType.null) {
|
4058
|
-
return (0, parseUtil_js_1.OK)(null);
|
4059
|
-
}
|
4060
|
-
return this._def.innerType._parse(input);
|
4061
|
-
}
|
4062
|
-
unwrap() {
|
4063
|
-
return this._def.innerType;
|
4064
|
-
}
|
4065
|
-
}
|
4066
|
-
exports.ZodNullable = ZodNullable;
|
4067
|
-
ZodNullable.create = (type, params) => {
|
4068
|
-
return new ZodNullable({
|
4069
|
-
innerType: type,
|
4070
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
4071
|
-
...processCreateParams(params),
|
4072
|
-
});
|
4073
|
-
};
|
4074
|
-
class ZodDefault extends ZodType {
|
4075
|
-
_parse(input) {
|
4076
|
-
const { ctx } = this._processInputParams(input);
|
4077
|
-
let data = ctx.data;
|
4078
|
-
if (ctx.parsedType === util_js_1.ZodParsedType.undefined) {
|
4079
|
-
data = this._def.defaultValue();
|
4080
|
-
}
|
4081
|
-
return this._def.innerType._parse({
|
4082
|
-
data,
|
4083
|
-
path: ctx.path,
|
4084
|
-
parent: ctx,
|
4085
|
-
});
|
4086
|
-
}
|
4087
|
-
removeDefault() {
|
4088
|
-
return this._def.innerType;
|
4089
|
-
}
|
4090
|
-
}
|
4091
|
-
exports.ZodDefault = ZodDefault;
|
4092
|
-
ZodDefault.create = (type, params) => {
|
4093
|
-
return new ZodDefault({
|
4094
|
-
innerType: type,
|
4095
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
4096
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
4097
|
-
...processCreateParams(params),
|
4098
|
-
});
|
4099
|
-
};
|
4100
|
-
class ZodCatch extends ZodType {
|
4101
|
-
_parse(input) {
|
4102
|
-
const { ctx } = this._processInputParams(input);
|
4103
|
-
// newCtx is used to not collect issues from inner types in ctx
|
4104
|
-
const newCtx = {
|
4105
|
-
...ctx,
|
4106
|
-
common: {
|
4107
|
-
...ctx.common,
|
4108
|
-
issues: [],
|
4109
|
-
},
|
4110
|
-
};
|
4111
|
-
const result = this._def.innerType._parse({
|
4112
|
-
data: newCtx.data,
|
4113
|
-
path: newCtx.path,
|
4114
|
-
parent: {
|
4115
|
-
...newCtx,
|
4116
|
-
},
|
4117
|
-
});
|
4118
|
-
if ((0, parseUtil_js_1.isAsync)(result)) {
|
4119
|
-
return result.then((result) => {
|
4120
|
-
return {
|
4121
|
-
status: "valid",
|
4122
|
-
value: result.status === "valid"
|
4123
|
-
? result.value
|
4124
|
-
: this._def.catchValue({
|
4125
|
-
get error() {
|
4126
|
-
return new ZodError_js_1.ZodError(newCtx.common.issues);
|
4127
|
-
},
|
4128
|
-
input: newCtx.data,
|
4129
|
-
}),
|
4130
|
-
};
|
4131
|
-
});
|
4132
|
-
}
|
4133
|
-
else {
|
4134
|
-
return {
|
4135
|
-
status: "valid",
|
4136
|
-
value: result.status === "valid"
|
4137
|
-
? result.value
|
4138
|
-
: this._def.catchValue({
|
4139
|
-
get error() {
|
4140
|
-
return new ZodError_js_1.ZodError(newCtx.common.issues);
|
4141
|
-
},
|
4142
|
-
input: newCtx.data,
|
4143
|
-
}),
|
4144
|
-
};
|
4145
|
-
}
|
4146
|
-
}
|
4147
|
-
removeCatch() {
|
4148
|
-
return this._def.innerType;
|
4149
|
-
}
|
4150
|
-
}
|
4151
|
-
exports.ZodCatch = ZodCatch;
|
4152
|
-
ZodCatch.create = (type, params) => {
|
4153
|
-
return new ZodCatch({
|
4154
|
-
innerType: type,
|
4155
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
4156
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
4157
|
-
...processCreateParams(params),
|
4158
|
-
});
|
4159
|
-
};
|
4160
|
-
class ZodNaN extends ZodType {
|
4161
|
-
_parse(input) {
|
4162
|
-
const parsedType = this._getType(input);
|
4163
|
-
if (parsedType !== util_js_1.ZodParsedType.nan) {
|
4164
|
-
const ctx = this._getOrReturnCtx(input);
|
4165
|
-
(0, parseUtil_js_1.addIssueToContext)(ctx, {
|
4166
|
-
code: ZodError_js_1.ZodIssueCode.invalid_type,
|
4167
|
-
expected: util_js_1.ZodParsedType.nan,
|
4168
|
-
received: ctx.parsedType,
|
4169
|
-
});
|
4170
|
-
return parseUtil_js_1.INVALID;
|
4171
|
-
}
|
4172
|
-
return { status: "valid", value: input.data };
|
4173
|
-
}
|
4174
|
-
}
|
4175
|
-
exports.ZodNaN = ZodNaN;
|
4176
|
-
ZodNaN.create = (params) => {
|
4177
|
-
return new ZodNaN({
|
4178
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
4179
|
-
...processCreateParams(params),
|
4180
|
-
});
|
4181
|
-
};
|
4182
|
-
exports.BRAND = Symbol("zod_brand");
|
4183
|
-
class ZodBranded extends ZodType {
|
4184
|
-
_parse(input) {
|
4185
|
-
const { ctx } = this._processInputParams(input);
|
4186
|
-
const data = ctx.data;
|
4187
|
-
return this._def.type._parse({
|
4188
|
-
data,
|
4189
|
-
path: ctx.path,
|
4190
|
-
parent: ctx,
|
4191
|
-
});
|
4192
|
-
}
|
4193
|
-
unwrap() {
|
4194
|
-
return this._def.type;
|
4195
|
-
}
|
4196
|
-
}
|
4197
|
-
exports.ZodBranded = ZodBranded;
|
4198
|
-
class ZodPipeline extends ZodType {
|
4199
|
-
_parse(input) {
|
4200
|
-
const { status, ctx } = this._processInputParams(input);
|
4201
|
-
if (ctx.common.async) {
|
4202
|
-
const handleAsync = async () => {
|
4203
|
-
const inResult = await this._def.in._parseAsync({
|
4204
|
-
data: ctx.data,
|
4205
|
-
path: ctx.path,
|
4206
|
-
parent: ctx,
|
4207
|
-
});
|
4208
|
-
if (inResult.status === "aborted")
|
4209
|
-
return parseUtil_js_1.INVALID;
|
4210
|
-
if (inResult.status === "dirty") {
|
4211
|
-
status.dirty();
|
4212
|
-
return (0, parseUtil_js_1.DIRTY)(inResult.value);
|
4213
|
-
}
|
4214
|
-
else {
|
4215
|
-
return this._def.out._parseAsync({
|
4216
|
-
data: inResult.value,
|
4217
|
-
path: ctx.path,
|
4218
|
-
parent: ctx,
|
4219
|
-
});
|
4220
|
-
}
|
4221
|
-
};
|
4222
|
-
return handleAsync();
|
4223
|
-
}
|
4224
|
-
else {
|
4225
|
-
const inResult = this._def.in._parseSync({
|
4226
|
-
data: ctx.data,
|
4227
|
-
path: ctx.path,
|
4228
|
-
parent: ctx,
|
4229
|
-
});
|
4230
|
-
if (inResult.status === "aborted")
|
4231
|
-
return parseUtil_js_1.INVALID;
|
4232
|
-
if (inResult.status === "dirty") {
|
4233
|
-
status.dirty();
|
4234
|
-
return {
|
4235
|
-
status: "dirty",
|
4236
|
-
value: inResult.value,
|
4237
|
-
};
|
4238
|
-
}
|
4239
|
-
else {
|
4240
|
-
return this._def.out._parseSync({
|
4241
|
-
data: inResult.value,
|
4242
|
-
path: ctx.path,
|
4243
|
-
parent: ctx,
|
4244
|
-
});
|
4245
|
-
}
|
4246
|
-
}
|
4247
|
-
}
|
4248
|
-
static create(a, b) {
|
4249
|
-
return new ZodPipeline({
|
4250
|
-
in: a,
|
4251
|
-
out: b,
|
4252
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline,
|
4253
|
-
});
|
4254
|
-
}
|
4255
|
-
}
|
4256
|
-
exports.ZodPipeline = ZodPipeline;
|
4257
|
-
class ZodReadonly extends ZodType {
|
4258
|
-
_parse(input) {
|
4259
|
-
const result = this._def.innerType._parse(input);
|
4260
|
-
const freeze = (data) => {
|
4261
|
-
if ((0, parseUtil_js_1.isValid)(data)) {
|
4262
|
-
data.value = Object.freeze(data.value);
|
4263
|
-
}
|
4264
|
-
return data;
|
4265
|
-
};
|
4266
|
-
return (0, parseUtil_js_1.isAsync)(result) ? result.then((data) => freeze(data)) : freeze(result);
|
4267
|
-
}
|
4268
|
-
unwrap() {
|
4269
|
-
return this._def.innerType;
|
4270
|
-
}
|
4271
|
-
}
|
4272
|
-
exports.ZodReadonly = ZodReadonly;
|
4273
|
-
ZodReadonly.create = (type, params) => {
|
4274
|
-
return new ZodReadonly({
|
4275
|
-
innerType: type,
|
4276
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
4277
|
-
...processCreateParams(params),
|
4278
|
-
});
|
4279
|
-
};
|
4280
|
-
////////////////////////////////////////
|
4281
|
-
////////////////////////////////////////
|
4282
|
-
////////// //////////
|
4283
|
-
////////// z.custom //////////
|
4284
|
-
////////// //////////
|
4285
|
-
////////////////////////////////////////
|
4286
|
-
////////////////////////////////////////
|
4287
|
-
function cleanParams(params, data) {
|
4288
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
4289
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
4290
|
-
return p2;
|
4291
|
-
}
|
4292
|
-
function custom(check, _params = {},
|
4293
|
-
/**
|
4294
|
-
* @deprecated
|
4295
|
-
*
|
4296
|
-
* Pass `fatal` into the params object instead:
|
4297
|
-
*
|
4298
|
-
* ```ts
|
4299
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
4300
|
-
* ```
|
4301
|
-
*
|
4302
|
-
*/
|
4303
|
-
fatal) {
|
4304
|
-
if (check)
|
4305
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
4306
|
-
const r = check(data);
|
4307
|
-
if (r instanceof Promise) {
|
4308
|
-
return r.then((r) => {
|
4309
|
-
if (!r) {
|
4310
|
-
const params = cleanParams(_params, data);
|
4311
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
4312
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
4313
|
-
}
|
4314
|
-
});
|
4315
|
-
}
|
4316
|
-
if (!r) {
|
4317
|
-
const params = cleanParams(_params, data);
|
4318
|
-
const _fatal = params.fatal ?? fatal ?? true;
|
4319
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
4320
|
-
}
|
4321
|
-
return;
|
4322
|
-
});
|
4323
|
-
return ZodAny.create();
|
4324
|
-
}
|
4325
|
-
exports.late = {
|
4326
|
-
object: ZodObject.lazycreate,
|
4327
|
-
};
|
4328
|
-
var ZodFirstPartyTypeKind;
|
4329
|
-
(function (ZodFirstPartyTypeKind) {
|
4330
|
-
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
4331
|
-
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
4332
|
-
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
4333
|
-
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
4334
|
-
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
4335
|
-
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
4336
|
-
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
4337
|
-
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
4338
|
-
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
4339
|
-
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
4340
|
-
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
4341
|
-
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
4342
|
-
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
4343
|
-
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
4344
|
-
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
4345
|
-
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
4346
|
-
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
4347
|
-
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
4348
|
-
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
4349
|
-
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
4350
|
-
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
4351
|
-
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
4352
|
-
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
4353
|
-
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
4354
|
-
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
4355
|
-
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
4356
|
-
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
4357
|
-
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
4358
|
-
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
4359
|
-
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
4360
|
-
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
4361
|
-
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
4362
|
-
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
4363
|
-
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
4364
|
-
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
4365
|
-
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
4366
|
-
})(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
|
4367
|
-
// requires TS 4.4+
|
4368
|
-
class Class {
|
4369
|
-
constructor(..._) { }
|
4370
|
-
}
|
4371
|
-
const instanceOfType = (
|
4372
|
-
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
4373
|
-
cls, params = {
|
4374
|
-
message: `Input not instance of ${cls.name}`,
|
4375
|
-
}) => custom((data) => data instanceof cls, params);
|
4376
|
-
exports["instanceof"] = instanceOfType;
|
4377
|
-
const stringType = ZodString.create;
|
4378
|
-
exports.string = stringType;
|
4379
|
-
const numberType = ZodNumber.create;
|
4380
|
-
exports.number = numberType;
|
4381
|
-
const nanType = ZodNaN.create;
|
4382
|
-
exports.nan = nanType;
|
4383
|
-
const bigIntType = ZodBigInt.create;
|
4384
|
-
exports.bigint = bigIntType;
|
4385
|
-
const booleanType = ZodBoolean.create;
|
4386
|
-
exports.boolean = booleanType;
|
4387
|
-
const dateType = ZodDate.create;
|
4388
|
-
exports.date = dateType;
|
4389
|
-
const symbolType = ZodSymbol.create;
|
4390
|
-
exports.symbol = symbolType;
|
4391
|
-
const undefinedType = ZodUndefined.create;
|
4392
|
-
exports.undefined = undefinedType;
|
4393
|
-
const nullType = ZodNull.create;
|
4394
|
-
exports["null"] = nullType;
|
4395
|
-
const anyType = ZodAny.create;
|
4396
|
-
exports.any = anyType;
|
4397
|
-
const unknownType = ZodUnknown.create;
|
4398
|
-
exports.unknown = unknownType;
|
4399
|
-
const neverType = ZodNever.create;
|
4400
|
-
exports.never = neverType;
|
4401
|
-
const voidType = ZodVoid.create;
|
4402
|
-
exports["void"] = voidType;
|
4403
|
-
const arrayType = ZodArray.create;
|
4404
|
-
exports.array = arrayType;
|
4405
|
-
const objectType = ZodObject.create;
|
4406
|
-
exports.object = objectType;
|
4407
|
-
const strictObjectType = ZodObject.strictCreate;
|
4408
|
-
exports.strictObject = strictObjectType;
|
4409
|
-
const unionType = ZodUnion.create;
|
4410
|
-
exports.union = unionType;
|
4411
|
-
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
4412
|
-
exports.discriminatedUnion = discriminatedUnionType;
|
4413
|
-
const intersectionType = ZodIntersection.create;
|
4414
|
-
exports.intersection = intersectionType;
|
4415
|
-
const tupleType = ZodTuple.create;
|
4416
|
-
exports.tuple = tupleType;
|
4417
|
-
const recordType = ZodRecord.create;
|
4418
|
-
exports.record = recordType;
|
4419
|
-
const mapType = ZodMap.create;
|
4420
|
-
exports.map = mapType;
|
4421
|
-
const setType = ZodSet.create;
|
4422
|
-
exports.set = setType;
|
4423
|
-
const functionType = ZodFunction.create;
|
4424
|
-
exports["function"] = functionType;
|
4425
|
-
const lazyType = ZodLazy.create;
|
4426
|
-
exports.lazy = lazyType;
|
4427
|
-
const literalType = ZodLiteral.create;
|
4428
|
-
exports.literal = literalType;
|
4429
|
-
const enumType = ZodEnum.create;
|
4430
|
-
exports["enum"] = enumType;
|
4431
|
-
const nativeEnumType = ZodNativeEnum.create;
|
4432
|
-
exports.nativeEnum = nativeEnumType;
|
4433
|
-
const promiseType = ZodPromise.create;
|
4434
|
-
exports.promise = promiseType;
|
4435
|
-
const effectsType = ZodEffects.create;
|
4436
|
-
exports.effect = effectsType;
|
4437
|
-
exports.transformer = effectsType;
|
4438
|
-
const optionalType = ZodOptional.create;
|
4439
|
-
exports.optional = optionalType;
|
4440
|
-
const nullableType = ZodNullable.create;
|
4441
|
-
exports.nullable = nullableType;
|
4442
|
-
const preprocessType = ZodEffects.createWithPreprocess;
|
4443
|
-
exports.preprocess = preprocessType;
|
4444
|
-
const pipelineType = ZodPipeline.create;
|
4445
|
-
exports.pipeline = pipelineType;
|
4446
|
-
const ostring = () => stringType().optional();
|
4447
|
-
exports.ostring = ostring;
|
4448
|
-
const onumber = () => numberType().optional();
|
4449
|
-
exports.onumber = onumber;
|
4450
|
-
const oboolean = () => booleanType().optional();
|
4451
|
-
exports.oboolean = oboolean;
|
4452
|
-
exports.coerce = {
|
4453
|
-
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
4454
|
-
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
4455
|
-
boolean: ((arg) => ZodBoolean.create({
|
4456
|
-
...arg,
|
4457
|
-
coerce: true,
|
4458
|
-
})),
|
4459
|
-
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
4460
|
-
date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
|
4461
|
-
};
|
4462
|
-
exports.NEVER = parseUtil_js_1.INVALID;
|
4463
|
-
|
4464
|
-
|
4465
|
-
/***/ })
|
4466
|
-
|
4467
|
-
/******/ });
|
4468
|
-
/************************************************************************/
|
4469
|
-
/******/ // The module cache
|
4470
|
-
/******/ var __webpack_module_cache__ = {};
|
4471
|
-
/******/
|
4472
|
-
/******/ // The require function
|
4473
|
-
/******/ function __nccwpck_require__(moduleId) {
|
4474
|
-
/******/ // Check if module is in cache
|
4475
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
4476
|
-
/******/ if (cachedModule !== undefined) {
|
4477
|
-
/******/ return cachedModule.exports;
|
4478
|
-
/******/ }
|
4479
|
-
/******/ // Create a new module (and put it into the cache)
|
4480
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
4481
|
-
/******/ // no module.id needed
|
4482
|
-
/******/ // no module.loaded needed
|
4483
|
-
/******/ exports: {}
|
4484
|
-
/******/ };
|
4485
|
-
/******/
|
4486
|
-
/******/ // Execute the module function
|
4487
|
-
/******/ var threw = true;
|
4488
|
-
/******/ try {
|
4489
|
-
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nccwpck_require__);
|
4490
|
-
/******/ threw = false;
|
4491
|
-
/******/ } finally {
|
4492
|
-
/******/ if(threw) delete __webpack_module_cache__[moduleId];
|
4493
|
-
/******/ }
|
4494
|
-
/******/
|
4495
|
-
/******/ // Return the exports of the module
|
4496
|
-
/******/ return module.exports;
|
4497
|
-
/******/ }
|
4498
|
-
/******/
|
4499
|
-
/************************************************************************/
|
4500
|
-
/******/ /* webpack/runtime/compat */
|
4501
|
-
/******/
|
4502
|
-
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
|
4503
|
-
/******/
|
4504
|
-
/************************************************************************/
|
4505
|
-
/******/
|
4506
|
-
/******/ // startup
|
4507
|
-
/******/ // Load entry module and return exports
|
4508
|
-
/******/ // This entry module is referenced by other modules so it can't be inlined
|
4509
|
-
/******/ var __webpack_exports__ = __nccwpck_require__(684);
|
4510
|
-
/******/ module.exports = __webpack_exports__;
|
4511
|
-
/******/
|
4512
|
-
/******/ })()
|
4513
|
-
;
|