@seed-ship/mcp-ui-solid 5.4.0 → 5.5.1
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/CHANGELOG.md +81 -0
- package/dist/mcp-ui-spec/dist/schemas.cjs +493 -0
- package/dist/mcp-ui-spec/dist/schemas.cjs.map +1 -0
- package/dist/mcp-ui-spec/dist/schemas.js +493 -0
- package/dist/mcp-ui-spec/dist/schemas.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.cjs +118 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js +118 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.cjs +10 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js +10 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.cjs +8 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js +9 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.cjs +122 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js +122 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.cjs +137 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js +139 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.cjs +105 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js +106 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs +3229 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs.map +1 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +3230 -0
- package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -0
- package/dist/services/validation.cjs +73 -154
- package/dist/services/validation.cjs.map +1 -1
- package/dist/services/validation.d.ts.map +1 -1
- package/dist/services/validation.js +73 -154
- package/dist/services/validation.js.map +1 -1
- package/package.json +3 -2
- package/src/services/validation.spec-migration.test.ts +207 -0
- package/src/services/validation.test.ts +53 -3
- package/src/services/validation.ts +143 -181
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,3229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ZodError = require("./ZodError.cjs");
|
|
4
|
+
const errorUtil = require("./helpers/errorUtil.cjs");
|
|
5
|
+
const parseUtil = require("./helpers/parseUtil.cjs");
|
|
6
|
+
const util = require("./helpers/util.cjs");
|
|
7
|
+
class ParseInputLazyPath {
|
|
8
|
+
constructor(parent, value, path, key) {
|
|
9
|
+
this._cachedPath = [];
|
|
10
|
+
this.parent = parent;
|
|
11
|
+
this.data = value;
|
|
12
|
+
this._path = path;
|
|
13
|
+
this._key = key;
|
|
14
|
+
}
|
|
15
|
+
get path() {
|
|
16
|
+
if (!this._cachedPath.length) {
|
|
17
|
+
if (Array.isArray(this._key)) {
|
|
18
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
19
|
+
} else {
|
|
20
|
+
this._cachedPath.push(...this._path, this._key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return this._cachedPath;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const handleResult = (ctx, result) => {
|
|
27
|
+
if (parseUtil.isValid(result)) {
|
|
28
|
+
return { success: true, data: result.value };
|
|
29
|
+
} else {
|
|
30
|
+
if (!ctx.common.issues.length) {
|
|
31
|
+
throw new Error("Validation failed but no issues detected.");
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
get error() {
|
|
36
|
+
if (this._error)
|
|
37
|
+
return this._error;
|
|
38
|
+
const error = new ZodError.ZodError(ctx.common.issues);
|
|
39
|
+
this._error = error;
|
|
40
|
+
return this._error;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
function processCreateParams(params) {
|
|
46
|
+
if (!params)
|
|
47
|
+
return {};
|
|
48
|
+
const { errorMap, invalid_type_error, required_error, description } = params;
|
|
49
|
+
if (errorMap && (invalid_type_error || required_error)) {
|
|
50
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
51
|
+
}
|
|
52
|
+
if (errorMap)
|
|
53
|
+
return { errorMap, description };
|
|
54
|
+
const customMap = (iss, ctx) => {
|
|
55
|
+
const { message } = params;
|
|
56
|
+
if (iss.code === "invalid_enum_value") {
|
|
57
|
+
return { message: message ?? ctx.defaultError };
|
|
58
|
+
}
|
|
59
|
+
if (typeof ctx.data === "undefined") {
|
|
60
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
61
|
+
}
|
|
62
|
+
if (iss.code !== "invalid_type")
|
|
63
|
+
return { message: ctx.defaultError };
|
|
64
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
65
|
+
};
|
|
66
|
+
return { errorMap: customMap, description };
|
|
67
|
+
}
|
|
68
|
+
class ZodType {
|
|
69
|
+
get description() {
|
|
70
|
+
return this._def.description;
|
|
71
|
+
}
|
|
72
|
+
_getType(input) {
|
|
73
|
+
return util.getParsedType(input.data);
|
|
74
|
+
}
|
|
75
|
+
_getOrReturnCtx(input, ctx) {
|
|
76
|
+
return ctx || {
|
|
77
|
+
common: input.parent.common,
|
|
78
|
+
data: input.data,
|
|
79
|
+
parsedType: util.getParsedType(input.data),
|
|
80
|
+
schemaErrorMap: this._def.errorMap,
|
|
81
|
+
path: input.path,
|
|
82
|
+
parent: input.parent
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
_processInputParams(input) {
|
|
86
|
+
return {
|
|
87
|
+
status: new parseUtil.ParseStatus(),
|
|
88
|
+
ctx: {
|
|
89
|
+
common: input.parent.common,
|
|
90
|
+
data: input.data,
|
|
91
|
+
parsedType: util.getParsedType(input.data),
|
|
92
|
+
schemaErrorMap: this._def.errorMap,
|
|
93
|
+
path: input.path,
|
|
94
|
+
parent: input.parent
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
_parseSync(input) {
|
|
99
|
+
const result = this._parse(input);
|
|
100
|
+
if (parseUtil.isAsync(result)) {
|
|
101
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
_parseAsync(input) {
|
|
106
|
+
const result = this._parse(input);
|
|
107
|
+
return Promise.resolve(result);
|
|
108
|
+
}
|
|
109
|
+
parse(data, params) {
|
|
110
|
+
const result = this.safeParse(data, params);
|
|
111
|
+
if (result.success)
|
|
112
|
+
return result.data;
|
|
113
|
+
throw result.error;
|
|
114
|
+
}
|
|
115
|
+
safeParse(data, params) {
|
|
116
|
+
const ctx = {
|
|
117
|
+
common: {
|
|
118
|
+
issues: [],
|
|
119
|
+
async: (params == null ? void 0 : params.async) ?? false,
|
|
120
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap
|
|
121
|
+
},
|
|
122
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
123
|
+
schemaErrorMap: this._def.errorMap,
|
|
124
|
+
parent: null,
|
|
125
|
+
data,
|
|
126
|
+
parsedType: util.getParsedType(data)
|
|
127
|
+
};
|
|
128
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
129
|
+
return handleResult(ctx, result);
|
|
130
|
+
}
|
|
131
|
+
"~validate"(data) {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
const ctx = {
|
|
134
|
+
common: {
|
|
135
|
+
issues: [],
|
|
136
|
+
async: !!this["~standard"].async
|
|
137
|
+
},
|
|
138
|
+
path: [],
|
|
139
|
+
schemaErrorMap: this._def.errorMap,
|
|
140
|
+
parent: null,
|
|
141
|
+
data,
|
|
142
|
+
parsedType: util.getParsedType(data)
|
|
143
|
+
};
|
|
144
|
+
if (!this["~standard"].async) {
|
|
145
|
+
try {
|
|
146
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
147
|
+
return parseUtil.isValid(result) ? {
|
|
148
|
+
value: result.value
|
|
149
|
+
} : {
|
|
150
|
+
issues: ctx.common.issues
|
|
151
|
+
};
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
|
|
154
|
+
this["~standard"].async = true;
|
|
155
|
+
}
|
|
156
|
+
ctx.common = {
|
|
157
|
+
issues: [],
|
|
158
|
+
async: true
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => parseUtil.isValid(result) ? {
|
|
163
|
+
value: result.value
|
|
164
|
+
} : {
|
|
165
|
+
issues: ctx.common.issues
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async parseAsync(data, params) {
|
|
169
|
+
const result = await this.safeParseAsync(data, params);
|
|
170
|
+
if (result.success)
|
|
171
|
+
return result.data;
|
|
172
|
+
throw result.error;
|
|
173
|
+
}
|
|
174
|
+
async safeParseAsync(data, params) {
|
|
175
|
+
const ctx = {
|
|
176
|
+
common: {
|
|
177
|
+
issues: [],
|
|
178
|
+
contextualErrorMap: params == null ? void 0 : params.errorMap,
|
|
179
|
+
async: true
|
|
180
|
+
},
|
|
181
|
+
path: (params == null ? void 0 : params.path) || [],
|
|
182
|
+
schemaErrorMap: this._def.errorMap,
|
|
183
|
+
parent: null,
|
|
184
|
+
data,
|
|
185
|
+
parsedType: util.getParsedType(data)
|
|
186
|
+
};
|
|
187
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
188
|
+
const result = await (parseUtil.isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
189
|
+
return handleResult(ctx, result);
|
|
190
|
+
}
|
|
191
|
+
refine(check, message) {
|
|
192
|
+
const getIssueProperties = (val) => {
|
|
193
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
194
|
+
return { message };
|
|
195
|
+
} else if (typeof message === "function") {
|
|
196
|
+
return message(val);
|
|
197
|
+
} else {
|
|
198
|
+
return message;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
return this._refinement((val, ctx) => {
|
|
202
|
+
const result = check(val);
|
|
203
|
+
const setError = () => ctx.addIssue({
|
|
204
|
+
code: ZodError.ZodIssueCode.custom,
|
|
205
|
+
...getIssueProperties(val)
|
|
206
|
+
});
|
|
207
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
208
|
+
return result.then((data) => {
|
|
209
|
+
if (!data) {
|
|
210
|
+
setError();
|
|
211
|
+
return false;
|
|
212
|
+
} else {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (!result) {
|
|
218
|
+
setError();
|
|
219
|
+
return false;
|
|
220
|
+
} else {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
refinement(check, refinementData) {
|
|
226
|
+
return this._refinement((val, ctx) => {
|
|
227
|
+
if (!check(val)) {
|
|
228
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
229
|
+
return false;
|
|
230
|
+
} else {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
_refinement(refinement) {
|
|
236
|
+
return new ZodEffects({
|
|
237
|
+
schema: this,
|
|
238
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
|
|
239
|
+
effect: { type: "refinement", refinement }
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
superRefine(refinement) {
|
|
243
|
+
return this._refinement(refinement);
|
|
244
|
+
}
|
|
245
|
+
constructor(def) {
|
|
246
|
+
this.spa = this.safeParseAsync;
|
|
247
|
+
this._def = def;
|
|
248
|
+
this.parse = this.parse.bind(this);
|
|
249
|
+
this.safeParse = this.safeParse.bind(this);
|
|
250
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
251
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
252
|
+
this.spa = this.spa.bind(this);
|
|
253
|
+
this.refine = this.refine.bind(this);
|
|
254
|
+
this.refinement = this.refinement.bind(this);
|
|
255
|
+
this.superRefine = this.superRefine.bind(this);
|
|
256
|
+
this.optional = this.optional.bind(this);
|
|
257
|
+
this.nullable = this.nullable.bind(this);
|
|
258
|
+
this.nullish = this.nullish.bind(this);
|
|
259
|
+
this.array = this.array.bind(this);
|
|
260
|
+
this.promise = this.promise.bind(this);
|
|
261
|
+
this.or = this.or.bind(this);
|
|
262
|
+
this.and = this.and.bind(this);
|
|
263
|
+
this.transform = this.transform.bind(this);
|
|
264
|
+
this.brand = this.brand.bind(this);
|
|
265
|
+
this.default = this.default.bind(this);
|
|
266
|
+
this.catch = this.catch.bind(this);
|
|
267
|
+
this.describe = this.describe.bind(this);
|
|
268
|
+
this.pipe = this.pipe.bind(this);
|
|
269
|
+
this.readonly = this.readonly.bind(this);
|
|
270
|
+
this.isNullable = this.isNullable.bind(this);
|
|
271
|
+
this.isOptional = this.isOptional.bind(this);
|
|
272
|
+
this["~standard"] = {
|
|
273
|
+
version: 1,
|
|
274
|
+
vendor: "zod",
|
|
275
|
+
validate: (data) => this["~validate"](data)
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
optional() {
|
|
279
|
+
return ZodOptional.create(this, this._def);
|
|
280
|
+
}
|
|
281
|
+
nullable() {
|
|
282
|
+
return ZodNullable.create(this, this._def);
|
|
283
|
+
}
|
|
284
|
+
nullish() {
|
|
285
|
+
return this.nullable().optional();
|
|
286
|
+
}
|
|
287
|
+
array() {
|
|
288
|
+
return ZodArray.create(this);
|
|
289
|
+
}
|
|
290
|
+
promise() {
|
|
291
|
+
return ZodPromise.create(this, this._def);
|
|
292
|
+
}
|
|
293
|
+
or(option) {
|
|
294
|
+
return ZodUnion.create([this, option], this._def);
|
|
295
|
+
}
|
|
296
|
+
and(incoming) {
|
|
297
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
298
|
+
}
|
|
299
|
+
transform(transform) {
|
|
300
|
+
return new ZodEffects({
|
|
301
|
+
...processCreateParams(this._def),
|
|
302
|
+
schema: this,
|
|
303
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
|
|
304
|
+
effect: { type: "transform", transform }
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
default(def) {
|
|
308
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
309
|
+
return new ZodDefault({
|
|
310
|
+
...processCreateParams(this._def),
|
|
311
|
+
innerType: this,
|
|
312
|
+
defaultValue: defaultValueFunc,
|
|
313
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodDefault
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
brand() {
|
|
317
|
+
return new ZodBranded({
|
|
318
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodBranded,
|
|
319
|
+
type: this,
|
|
320
|
+
...processCreateParams(this._def)
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
catch(def) {
|
|
324
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
325
|
+
return new ZodCatch({
|
|
326
|
+
...processCreateParams(this._def),
|
|
327
|
+
innerType: this,
|
|
328
|
+
catchValue: catchValueFunc,
|
|
329
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodCatch
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
describe(description) {
|
|
333
|
+
const This = this.constructor;
|
|
334
|
+
return new This({
|
|
335
|
+
...this._def,
|
|
336
|
+
description
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
pipe(target) {
|
|
340
|
+
return ZodPipeline.create(this, target);
|
|
341
|
+
}
|
|
342
|
+
readonly() {
|
|
343
|
+
return ZodReadonly.create(this);
|
|
344
|
+
}
|
|
345
|
+
isOptional() {
|
|
346
|
+
return this.safeParse(void 0).success;
|
|
347
|
+
}
|
|
348
|
+
isNullable() {
|
|
349
|
+
return this.safeParse(null).success;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
353
|
+
const cuid2Regex = /^[0-9a-z]+$/;
|
|
354
|
+
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
355
|
+
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;
|
|
356
|
+
const nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
357
|
+
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
358
|
+
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)?)??$/;
|
|
359
|
+
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
360
|
+
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
361
|
+
let emojiRegex;
|
|
362
|
+
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])$/;
|
|
363
|
+
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])$/;
|
|
364
|
+
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]))$/;
|
|
365
|
+
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])$/;
|
|
366
|
+
const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
367
|
+
const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
368
|
+
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])))`;
|
|
369
|
+
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
370
|
+
function timeRegexSource(args) {
|
|
371
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
372
|
+
if (args.precision) {
|
|
373
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
374
|
+
} else if (args.precision == null) {
|
|
375
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
376
|
+
}
|
|
377
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
378
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
379
|
+
}
|
|
380
|
+
function timeRegex(args) {
|
|
381
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
382
|
+
}
|
|
383
|
+
function datetimeRegex(args) {
|
|
384
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
385
|
+
const opts = [];
|
|
386
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
387
|
+
if (args.offset)
|
|
388
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
389
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
390
|
+
return new RegExp(`^${regex}$`);
|
|
391
|
+
}
|
|
392
|
+
function isValidIP(ip, version) {
|
|
393
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
function isValidJWT(jwt, alg) {
|
|
402
|
+
if (!jwtRegex.test(jwt))
|
|
403
|
+
return false;
|
|
404
|
+
try {
|
|
405
|
+
const [header] = jwt.split(".");
|
|
406
|
+
if (!header)
|
|
407
|
+
return false;
|
|
408
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
409
|
+
const decoded = JSON.parse(atob(base64));
|
|
410
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
411
|
+
return false;
|
|
412
|
+
if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
|
|
413
|
+
return false;
|
|
414
|
+
if (!decoded.alg)
|
|
415
|
+
return false;
|
|
416
|
+
if (alg && decoded.alg !== alg)
|
|
417
|
+
return false;
|
|
418
|
+
return true;
|
|
419
|
+
} catch {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function isValidCidr(ip, version) {
|
|
424
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
class ZodString extends ZodType {
|
|
433
|
+
_parse(input) {
|
|
434
|
+
if (this._def.coerce) {
|
|
435
|
+
input.data = String(input.data);
|
|
436
|
+
}
|
|
437
|
+
const parsedType = this._getType(input);
|
|
438
|
+
if (parsedType !== util.ZodParsedType.string) {
|
|
439
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
440
|
+
parseUtil.addIssueToContext(ctx2, {
|
|
441
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
442
|
+
expected: util.ZodParsedType.string,
|
|
443
|
+
received: ctx2.parsedType
|
|
444
|
+
});
|
|
445
|
+
return parseUtil.INVALID;
|
|
446
|
+
}
|
|
447
|
+
const status = new parseUtil.ParseStatus();
|
|
448
|
+
let ctx = void 0;
|
|
449
|
+
for (const check of this._def.checks) {
|
|
450
|
+
if (check.kind === "min") {
|
|
451
|
+
if (input.data.length < check.value) {
|
|
452
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
453
|
+
parseUtil.addIssueToContext(ctx, {
|
|
454
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
455
|
+
minimum: check.value,
|
|
456
|
+
type: "string",
|
|
457
|
+
inclusive: true,
|
|
458
|
+
exact: false,
|
|
459
|
+
message: check.message
|
|
460
|
+
});
|
|
461
|
+
status.dirty();
|
|
462
|
+
}
|
|
463
|
+
} else if (check.kind === "max") {
|
|
464
|
+
if (input.data.length > check.value) {
|
|
465
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
466
|
+
parseUtil.addIssueToContext(ctx, {
|
|
467
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
468
|
+
maximum: check.value,
|
|
469
|
+
type: "string",
|
|
470
|
+
inclusive: true,
|
|
471
|
+
exact: false,
|
|
472
|
+
message: check.message
|
|
473
|
+
});
|
|
474
|
+
status.dirty();
|
|
475
|
+
}
|
|
476
|
+
} else if (check.kind === "length") {
|
|
477
|
+
const tooBig = input.data.length > check.value;
|
|
478
|
+
const tooSmall = input.data.length < check.value;
|
|
479
|
+
if (tooBig || tooSmall) {
|
|
480
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
481
|
+
if (tooBig) {
|
|
482
|
+
parseUtil.addIssueToContext(ctx, {
|
|
483
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
484
|
+
maximum: check.value,
|
|
485
|
+
type: "string",
|
|
486
|
+
inclusive: true,
|
|
487
|
+
exact: true,
|
|
488
|
+
message: check.message
|
|
489
|
+
});
|
|
490
|
+
} else if (tooSmall) {
|
|
491
|
+
parseUtil.addIssueToContext(ctx, {
|
|
492
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
493
|
+
minimum: check.value,
|
|
494
|
+
type: "string",
|
|
495
|
+
inclusive: true,
|
|
496
|
+
exact: true,
|
|
497
|
+
message: check.message
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
status.dirty();
|
|
501
|
+
}
|
|
502
|
+
} else if (check.kind === "email") {
|
|
503
|
+
if (!emailRegex.test(input.data)) {
|
|
504
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
505
|
+
parseUtil.addIssueToContext(ctx, {
|
|
506
|
+
validation: "email",
|
|
507
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
508
|
+
message: check.message
|
|
509
|
+
});
|
|
510
|
+
status.dirty();
|
|
511
|
+
}
|
|
512
|
+
} else if (check.kind === "emoji") {
|
|
513
|
+
if (!emojiRegex) {
|
|
514
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
515
|
+
}
|
|
516
|
+
if (!emojiRegex.test(input.data)) {
|
|
517
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
518
|
+
parseUtil.addIssueToContext(ctx, {
|
|
519
|
+
validation: "emoji",
|
|
520
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
521
|
+
message: check.message
|
|
522
|
+
});
|
|
523
|
+
status.dirty();
|
|
524
|
+
}
|
|
525
|
+
} else if (check.kind === "uuid") {
|
|
526
|
+
if (!uuidRegex.test(input.data)) {
|
|
527
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
528
|
+
parseUtil.addIssueToContext(ctx, {
|
|
529
|
+
validation: "uuid",
|
|
530
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
531
|
+
message: check.message
|
|
532
|
+
});
|
|
533
|
+
status.dirty();
|
|
534
|
+
}
|
|
535
|
+
} else if (check.kind === "nanoid") {
|
|
536
|
+
if (!nanoidRegex.test(input.data)) {
|
|
537
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
538
|
+
parseUtil.addIssueToContext(ctx, {
|
|
539
|
+
validation: "nanoid",
|
|
540
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
541
|
+
message: check.message
|
|
542
|
+
});
|
|
543
|
+
status.dirty();
|
|
544
|
+
}
|
|
545
|
+
} else if (check.kind === "cuid") {
|
|
546
|
+
if (!cuidRegex.test(input.data)) {
|
|
547
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
548
|
+
parseUtil.addIssueToContext(ctx, {
|
|
549
|
+
validation: "cuid",
|
|
550
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
551
|
+
message: check.message
|
|
552
|
+
});
|
|
553
|
+
status.dirty();
|
|
554
|
+
}
|
|
555
|
+
} else if (check.kind === "cuid2") {
|
|
556
|
+
if (!cuid2Regex.test(input.data)) {
|
|
557
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
558
|
+
parseUtil.addIssueToContext(ctx, {
|
|
559
|
+
validation: "cuid2",
|
|
560
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
561
|
+
message: check.message
|
|
562
|
+
});
|
|
563
|
+
status.dirty();
|
|
564
|
+
}
|
|
565
|
+
} else if (check.kind === "ulid") {
|
|
566
|
+
if (!ulidRegex.test(input.data)) {
|
|
567
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
568
|
+
parseUtil.addIssueToContext(ctx, {
|
|
569
|
+
validation: "ulid",
|
|
570
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
571
|
+
message: check.message
|
|
572
|
+
});
|
|
573
|
+
status.dirty();
|
|
574
|
+
}
|
|
575
|
+
} else if (check.kind === "url") {
|
|
576
|
+
try {
|
|
577
|
+
new URL(input.data);
|
|
578
|
+
} catch {
|
|
579
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
580
|
+
parseUtil.addIssueToContext(ctx, {
|
|
581
|
+
validation: "url",
|
|
582
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
583
|
+
message: check.message
|
|
584
|
+
});
|
|
585
|
+
status.dirty();
|
|
586
|
+
}
|
|
587
|
+
} else if (check.kind === "regex") {
|
|
588
|
+
check.regex.lastIndex = 0;
|
|
589
|
+
const testResult = check.regex.test(input.data);
|
|
590
|
+
if (!testResult) {
|
|
591
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
592
|
+
parseUtil.addIssueToContext(ctx, {
|
|
593
|
+
validation: "regex",
|
|
594
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
595
|
+
message: check.message
|
|
596
|
+
});
|
|
597
|
+
status.dirty();
|
|
598
|
+
}
|
|
599
|
+
} else if (check.kind === "trim") {
|
|
600
|
+
input.data = input.data.trim();
|
|
601
|
+
} else if (check.kind === "includes") {
|
|
602
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
603
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
604
|
+
parseUtil.addIssueToContext(ctx, {
|
|
605
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
606
|
+
validation: { includes: check.value, position: check.position },
|
|
607
|
+
message: check.message
|
|
608
|
+
});
|
|
609
|
+
status.dirty();
|
|
610
|
+
}
|
|
611
|
+
} else if (check.kind === "toLowerCase") {
|
|
612
|
+
input.data = input.data.toLowerCase();
|
|
613
|
+
} else if (check.kind === "toUpperCase") {
|
|
614
|
+
input.data = input.data.toUpperCase();
|
|
615
|
+
} else if (check.kind === "startsWith") {
|
|
616
|
+
if (!input.data.startsWith(check.value)) {
|
|
617
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
618
|
+
parseUtil.addIssueToContext(ctx, {
|
|
619
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
620
|
+
validation: { startsWith: check.value },
|
|
621
|
+
message: check.message
|
|
622
|
+
});
|
|
623
|
+
status.dirty();
|
|
624
|
+
}
|
|
625
|
+
} else if (check.kind === "endsWith") {
|
|
626
|
+
if (!input.data.endsWith(check.value)) {
|
|
627
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
628
|
+
parseUtil.addIssueToContext(ctx, {
|
|
629
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
630
|
+
validation: { endsWith: check.value },
|
|
631
|
+
message: check.message
|
|
632
|
+
});
|
|
633
|
+
status.dirty();
|
|
634
|
+
}
|
|
635
|
+
} else if (check.kind === "datetime") {
|
|
636
|
+
const regex = datetimeRegex(check);
|
|
637
|
+
if (!regex.test(input.data)) {
|
|
638
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
639
|
+
parseUtil.addIssueToContext(ctx, {
|
|
640
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
641
|
+
validation: "datetime",
|
|
642
|
+
message: check.message
|
|
643
|
+
});
|
|
644
|
+
status.dirty();
|
|
645
|
+
}
|
|
646
|
+
} else if (check.kind === "date") {
|
|
647
|
+
const regex = dateRegex;
|
|
648
|
+
if (!regex.test(input.data)) {
|
|
649
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
650
|
+
parseUtil.addIssueToContext(ctx, {
|
|
651
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
652
|
+
validation: "date",
|
|
653
|
+
message: check.message
|
|
654
|
+
});
|
|
655
|
+
status.dirty();
|
|
656
|
+
}
|
|
657
|
+
} else if (check.kind === "time") {
|
|
658
|
+
const regex = timeRegex(check);
|
|
659
|
+
if (!regex.test(input.data)) {
|
|
660
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
661
|
+
parseUtil.addIssueToContext(ctx, {
|
|
662
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
663
|
+
validation: "time",
|
|
664
|
+
message: check.message
|
|
665
|
+
});
|
|
666
|
+
status.dirty();
|
|
667
|
+
}
|
|
668
|
+
} else if (check.kind === "duration") {
|
|
669
|
+
if (!durationRegex.test(input.data)) {
|
|
670
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
671
|
+
parseUtil.addIssueToContext(ctx, {
|
|
672
|
+
validation: "duration",
|
|
673
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
674
|
+
message: check.message
|
|
675
|
+
});
|
|
676
|
+
status.dirty();
|
|
677
|
+
}
|
|
678
|
+
} else if (check.kind === "ip") {
|
|
679
|
+
if (!isValidIP(input.data, check.version)) {
|
|
680
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
681
|
+
parseUtil.addIssueToContext(ctx, {
|
|
682
|
+
validation: "ip",
|
|
683
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
684
|
+
message: check.message
|
|
685
|
+
});
|
|
686
|
+
status.dirty();
|
|
687
|
+
}
|
|
688
|
+
} else if (check.kind === "jwt") {
|
|
689
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
690
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
691
|
+
parseUtil.addIssueToContext(ctx, {
|
|
692
|
+
validation: "jwt",
|
|
693
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
694
|
+
message: check.message
|
|
695
|
+
});
|
|
696
|
+
status.dirty();
|
|
697
|
+
}
|
|
698
|
+
} else if (check.kind === "cidr") {
|
|
699
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
700
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
701
|
+
parseUtil.addIssueToContext(ctx, {
|
|
702
|
+
validation: "cidr",
|
|
703
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
704
|
+
message: check.message
|
|
705
|
+
});
|
|
706
|
+
status.dirty();
|
|
707
|
+
}
|
|
708
|
+
} else if (check.kind === "base64") {
|
|
709
|
+
if (!base64Regex.test(input.data)) {
|
|
710
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
711
|
+
parseUtil.addIssueToContext(ctx, {
|
|
712
|
+
validation: "base64",
|
|
713
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
714
|
+
message: check.message
|
|
715
|
+
});
|
|
716
|
+
status.dirty();
|
|
717
|
+
}
|
|
718
|
+
} else if (check.kind === "base64url") {
|
|
719
|
+
if (!base64urlRegex.test(input.data)) {
|
|
720
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
721
|
+
parseUtil.addIssueToContext(ctx, {
|
|
722
|
+
validation: "base64url",
|
|
723
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
724
|
+
message: check.message
|
|
725
|
+
});
|
|
726
|
+
status.dirty();
|
|
727
|
+
}
|
|
728
|
+
} else {
|
|
729
|
+
util.util.assertNever(check);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return { status: status.value, value: input.data };
|
|
733
|
+
}
|
|
734
|
+
_regex(regex, validation, message) {
|
|
735
|
+
return this.refinement((data) => regex.test(data), {
|
|
736
|
+
validation,
|
|
737
|
+
code: ZodError.ZodIssueCode.invalid_string,
|
|
738
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
_addCheck(check) {
|
|
742
|
+
return new ZodString({
|
|
743
|
+
...this._def,
|
|
744
|
+
checks: [...this._def.checks, check]
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
email(message) {
|
|
748
|
+
return this._addCheck({ kind: "email", ...errorUtil.errorUtil.errToObj(message) });
|
|
749
|
+
}
|
|
750
|
+
url(message) {
|
|
751
|
+
return this._addCheck({ kind: "url", ...errorUtil.errorUtil.errToObj(message) });
|
|
752
|
+
}
|
|
753
|
+
emoji(message) {
|
|
754
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errorUtil.errToObj(message) });
|
|
755
|
+
}
|
|
756
|
+
uuid(message) {
|
|
757
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errorUtil.errToObj(message) });
|
|
758
|
+
}
|
|
759
|
+
nanoid(message) {
|
|
760
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errorUtil.errToObj(message) });
|
|
761
|
+
}
|
|
762
|
+
cuid(message) {
|
|
763
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errorUtil.errToObj(message) });
|
|
764
|
+
}
|
|
765
|
+
cuid2(message) {
|
|
766
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errorUtil.errToObj(message) });
|
|
767
|
+
}
|
|
768
|
+
ulid(message) {
|
|
769
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errorUtil.errToObj(message) });
|
|
770
|
+
}
|
|
771
|
+
base64(message) {
|
|
772
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errorUtil.errToObj(message) });
|
|
773
|
+
}
|
|
774
|
+
base64url(message) {
|
|
775
|
+
return this._addCheck({
|
|
776
|
+
kind: "base64url",
|
|
777
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
jwt(options) {
|
|
781
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errorUtil.errToObj(options) });
|
|
782
|
+
}
|
|
783
|
+
ip(options) {
|
|
784
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errorUtil.errToObj(options) });
|
|
785
|
+
}
|
|
786
|
+
cidr(options) {
|
|
787
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errorUtil.errToObj(options) });
|
|
788
|
+
}
|
|
789
|
+
datetime(options) {
|
|
790
|
+
if (typeof options === "string") {
|
|
791
|
+
return this._addCheck({
|
|
792
|
+
kind: "datetime",
|
|
793
|
+
precision: null,
|
|
794
|
+
offset: false,
|
|
795
|
+
local: false,
|
|
796
|
+
message: options
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
return this._addCheck({
|
|
800
|
+
kind: "datetime",
|
|
801
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
802
|
+
offset: (options == null ? void 0 : options.offset) ?? false,
|
|
803
|
+
local: (options == null ? void 0 : options.local) ?? false,
|
|
804
|
+
...errorUtil.errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
date(message) {
|
|
808
|
+
return this._addCheck({ kind: "date", message });
|
|
809
|
+
}
|
|
810
|
+
time(options) {
|
|
811
|
+
if (typeof options === "string") {
|
|
812
|
+
return this._addCheck({
|
|
813
|
+
kind: "time",
|
|
814
|
+
precision: null,
|
|
815
|
+
message: options
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
return this._addCheck({
|
|
819
|
+
kind: "time",
|
|
820
|
+
precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
|
|
821
|
+
...errorUtil.errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
duration(message) {
|
|
825
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errorUtil.errToObj(message) });
|
|
826
|
+
}
|
|
827
|
+
regex(regex, message) {
|
|
828
|
+
return this._addCheck({
|
|
829
|
+
kind: "regex",
|
|
830
|
+
regex,
|
|
831
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
includes(value, options) {
|
|
835
|
+
return this._addCheck({
|
|
836
|
+
kind: "includes",
|
|
837
|
+
value,
|
|
838
|
+
position: options == null ? void 0 : options.position,
|
|
839
|
+
...errorUtil.errorUtil.errToObj(options == null ? void 0 : options.message)
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
startsWith(value, message) {
|
|
843
|
+
return this._addCheck({
|
|
844
|
+
kind: "startsWith",
|
|
845
|
+
value,
|
|
846
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
endsWith(value, message) {
|
|
850
|
+
return this._addCheck({
|
|
851
|
+
kind: "endsWith",
|
|
852
|
+
value,
|
|
853
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
min(minLength, message) {
|
|
857
|
+
return this._addCheck({
|
|
858
|
+
kind: "min",
|
|
859
|
+
value: minLength,
|
|
860
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
max(maxLength, message) {
|
|
864
|
+
return this._addCheck({
|
|
865
|
+
kind: "max",
|
|
866
|
+
value: maxLength,
|
|
867
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
length(len, message) {
|
|
871
|
+
return this._addCheck({
|
|
872
|
+
kind: "length",
|
|
873
|
+
value: len,
|
|
874
|
+
...errorUtil.errorUtil.errToObj(message)
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Equivalent to `.min(1)`
|
|
879
|
+
*/
|
|
880
|
+
nonempty(message) {
|
|
881
|
+
return this.min(1, errorUtil.errorUtil.errToObj(message));
|
|
882
|
+
}
|
|
883
|
+
trim() {
|
|
884
|
+
return new ZodString({
|
|
885
|
+
...this._def,
|
|
886
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
toLowerCase() {
|
|
890
|
+
return new ZodString({
|
|
891
|
+
...this._def,
|
|
892
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
toUpperCase() {
|
|
896
|
+
return new ZodString({
|
|
897
|
+
...this._def,
|
|
898
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
get isDatetime() {
|
|
902
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
903
|
+
}
|
|
904
|
+
get isDate() {
|
|
905
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
906
|
+
}
|
|
907
|
+
get isTime() {
|
|
908
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
909
|
+
}
|
|
910
|
+
get isDuration() {
|
|
911
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
912
|
+
}
|
|
913
|
+
get isEmail() {
|
|
914
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
915
|
+
}
|
|
916
|
+
get isURL() {
|
|
917
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
918
|
+
}
|
|
919
|
+
get isEmoji() {
|
|
920
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
921
|
+
}
|
|
922
|
+
get isUUID() {
|
|
923
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
924
|
+
}
|
|
925
|
+
get isNANOID() {
|
|
926
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
927
|
+
}
|
|
928
|
+
get isCUID() {
|
|
929
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
930
|
+
}
|
|
931
|
+
get isCUID2() {
|
|
932
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
933
|
+
}
|
|
934
|
+
get isULID() {
|
|
935
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
936
|
+
}
|
|
937
|
+
get isIP() {
|
|
938
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
939
|
+
}
|
|
940
|
+
get isCIDR() {
|
|
941
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
942
|
+
}
|
|
943
|
+
get isBase64() {
|
|
944
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
945
|
+
}
|
|
946
|
+
get isBase64url() {
|
|
947
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
948
|
+
}
|
|
949
|
+
get minLength() {
|
|
950
|
+
let min = null;
|
|
951
|
+
for (const ch of this._def.checks) {
|
|
952
|
+
if (ch.kind === "min") {
|
|
953
|
+
if (min === null || ch.value > min)
|
|
954
|
+
min = ch.value;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
return min;
|
|
958
|
+
}
|
|
959
|
+
get maxLength() {
|
|
960
|
+
let max = null;
|
|
961
|
+
for (const ch of this._def.checks) {
|
|
962
|
+
if (ch.kind === "max") {
|
|
963
|
+
if (max === null || ch.value < max)
|
|
964
|
+
max = ch.value;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return max;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
ZodString.create = (params) => {
|
|
971
|
+
return new ZodString({
|
|
972
|
+
checks: [],
|
|
973
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodString,
|
|
974
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
975
|
+
...processCreateParams(params)
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
function floatSafeRemainder(val, step) {
|
|
979
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
980
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
981
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
982
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
983
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
984
|
+
return valInt % stepInt / 10 ** decCount;
|
|
985
|
+
}
|
|
986
|
+
class ZodNumber extends ZodType {
|
|
987
|
+
constructor() {
|
|
988
|
+
super(...arguments);
|
|
989
|
+
this.min = this.gte;
|
|
990
|
+
this.max = this.lte;
|
|
991
|
+
this.step = this.multipleOf;
|
|
992
|
+
}
|
|
993
|
+
_parse(input) {
|
|
994
|
+
if (this._def.coerce) {
|
|
995
|
+
input.data = Number(input.data);
|
|
996
|
+
}
|
|
997
|
+
const parsedType = this._getType(input);
|
|
998
|
+
if (parsedType !== util.ZodParsedType.number) {
|
|
999
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1000
|
+
parseUtil.addIssueToContext(ctx2, {
|
|
1001
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1002
|
+
expected: util.ZodParsedType.number,
|
|
1003
|
+
received: ctx2.parsedType
|
|
1004
|
+
});
|
|
1005
|
+
return parseUtil.INVALID;
|
|
1006
|
+
}
|
|
1007
|
+
let ctx = void 0;
|
|
1008
|
+
const status = new parseUtil.ParseStatus();
|
|
1009
|
+
for (const check of this._def.checks) {
|
|
1010
|
+
if (check.kind === "int") {
|
|
1011
|
+
if (!util.util.isInteger(input.data)) {
|
|
1012
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1013
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1014
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1015
|
+
expected: "integer",
|
|
1016
|
+
received: "float",
|
|
1017
|
+
message: check.message
|
|
1018
|
+
});
|
|
1019
|
+
status.dirty();
|
|
1020
|
+
}
|
|
1021
|
+
} else if (check.kind === "min") {
|
|
1022
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1023
|
+
if (tooSmall) {
|
|
1024
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1025
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1026
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
1027
|
+
minimum: check.value,
|
|
1028
|
+
type: "number",
|
|
1029
|
+
inclusive: check.inclusive,
|
|
1030
|
+
exact: false,
|
|
1031
|
+
message: check.message
|
|
1032
|
+
});
|
|
1033
|
+
status.dirty();
|
|
1034
|
+
}
|
|
1035
|
+
} else if (check.kind === "max") {
|
|
1036
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1037
|
+
if (tooBig) {
|
|
1038
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1039
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1040
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
1041
|
+
maximum: check.value,
|
|
1042
|
+
type: "number",
|
|
1043
|
+
inclusive: check.inclusive,
|
|
1044
|
+
exact: false,
|
|
1045
|
+
message: check.message
|
|
1046
|
+
});
|
|
1047
|
+
status.dirty();
|
|
1048
|
+
}
|
|
1049
|
+
} else if (check.kind === "multipleOf") {
|
|
1050
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1051
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1052
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1053
|
+
code: ZodError.ZodIssueCode.not_multiple_of,
|
|
1054
|
+
multipleOf: check.value,
|
|
1055
|
+
message: check.message
|
|
1056
|
+
});
|
|
1057
|
+
status.dirty();
|
|
1058
|
+
}
|
|
1059
|
+
} else if (check.kind === "finite") {
|
|
1060
|
+
if (!Number.isFinite(input.data)) {
|
|
1061
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1062
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1063
|
+
code: ZodError.ZodIssueCode.not_finite,
|
|
1064
|
+
message: check.message
|
|
1065
|
+
});
|
|
1066
|
+
status.dirty();
|
|
1067
|
+
}
|
|
1068
|
+
} else {
|
|
1069
|
+
util.util.assertNever(check);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
return { status: status.value, value: input.data };
|
|
1073
|
+
}
|
|
1074
|
+
gte(value, message) {
|
|
1075
|
+
return this.setLimit("min", value, true, errorUtil.errorUtil.toString(message));
|
|
1076
|
+
}
|
|
1077
|
+
gt(value, message) {
|
|
1078
|
+
return this.setLimit("min", value, false, errorUtil.errorUtil.toString(message));
|
|
1079
|
+
}
|
|
1080
|
+
lte(value, message) {
|
|
1081
|
+
return this.setLimit("max", value, true, errorUtil.errorUtil.toString(message));
|
|
1082
|
+
}
|
|
1083
|
+
lt(value, message) {
|
|
1084
|
+
return this.setLimit("max", value, false, errorUtil.errorUtil.toString(message));
|
|
1085
|
+
}
|
|
1086
|
+
setLimit(kind, value, inclusive, message) {
|
|
1087
|
+
return new ZodNumber({
|
|
1088
|
+
...this._def,
|
|
1089
|
+
checks: [
|
|
1090
|
+
...this._def.checks,
|
|
1091
|
+
{
|
|
1092
|
+
kind,
|
|
1093
|
+
value,
|
|
1094
|
+
inclusive,
|
|
1095
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1096
|
+
}
|
|
1097
|
+
]
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
_addCheck(check) {
|
|
1101
|
+
return new ZodNumber({
|
|
1102
|
+
...this._def,
|
|
1103
|
+
checks: [...this._def.checks, check]
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
int(message) {
|
|
1107
|
+
return this._addCheck({
|
|
1108
|
+
kind: "int",
|
|
1109
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
positive(message) {
|
|
1113
|
+
return this._addCheck({
|
|
1114
|
+
kind: "min",
|
|
1115
|
+
value: 0,
|
|
1116
|
+
inclusive: false,
|
|
1117
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
negative(message) {
|
|
1121
|
+
return this._addCheck({
|
|
1122
|
+
kind: "max",
|
|
1123
|
+
value: 0,
|
|
1124
|
+
inclusive: false,
|
|
1125
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
nonpositive(message) {
|
|
1129
|
+
return this._addCheck({
|
|
1130
|
+
kind: "max",
|
|
1131
|
+
value: 0,
|
|
1132
|
+
inclusive: true,
|
|
1133
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
nonnegative(message) {
|
|
1137
|
+
return this._addCheck({
|
|
1138
|
+
kind: "min",
|
|
1139
|
+
value: 0,
|
|
1140
|
+
inclusive: true,
|
|
1141
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
multipleOf(value, message) {
|
|
1145
|
+
return this._addCheck({
|
|
1146
|
+
kind: "multipleOf",
|
|
1147
|
+
value,
|
|
1148
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
finite(message) {
|
|
1152
|
+
return this._addCheck({
|
|
1153
|
+
kind: "finite",
|
|
1154
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
safe(message) {
|
|
1158
|
+
return this._addCheck({
|
|
1159
|
+
kind: "min",
|
|
1160
|
+
inclusive: true,
|
|
1161
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1162
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1163
|
+
})._addCheck({
|
|
1164
|
+
kind: "max",
|
|
1165
|
+
inclusive: true,
|
|
1166
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1167
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
get minValue() {
|
|
1171
|
+
let min = null;
|
|
1172
|
+
for (const ch of this._def.checks) {
|
|
1173
|
+
if (ch.kind === "min") {
|
|
1174
|
+
if (min === null || ch.value > min)
|
|
1175
|
+
min = ch.value;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return min;
|
|
1179
|
+
}
|
|
1180
|
+
get maxValue() {
|
|
1181
|
+
let max = null;
|
|
1182
|
+
for (const ch of this._def.checks) {
|
|
1183
|
+
if (ch.kind === "max") {
|
|
1184
|
+
if (max === null || ch.value < max)
|
|
1185
|
+
max = ch.value;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return max;
|
|
1189
|
+
}
|
|
1190
|
+
get isInt() {
|
|
1191
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.util.isInteger(ch.value));
|
|
1192
|
+
}
|
|
1193
|
+
get isFinite() {
|
|
1194
|
+
let max = null;
|
|
1195
|
+
let min = null;
|
|
1196
|
+
for (const ch of this._def.checks) {
|
|
1197
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1198
|
+
return true;
|
|
1199
|
+
} else if (ch.kind === "min") {
|
|
1200
|
+
if (min === null || ch.value > min)
|
|
1201
|
+
min = ch.value;
|
|
1202
|
+
} else if (ch.kind === "max") {
|
|
1203
|
+
if (max === null || ch.value < max)
|
|
1204
|
+
max = ch.value;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
ZodNumber.create = (params) => {
|
|
1211
|
+
return new ZodNumber({
|
|
1212
|
+
checks: [],
|
|
1213
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNumber,
|
|
1214
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
1215
|
+
...processCreateParams(params)
|
|
1216
|
+
});
|
|
1217
|
+
};
|
|
1218
|
+
class ZodBigInt extends ZodType {
|
|
1219
|
+
constructor() {
|
|
1220
|
+
super(...arguments);
|
|
1221
|
+
this.min = this.gte;
|
|
1222
|
+
this.max = this.lte;
|
|
1223
|
+
}
|
|
1224
|
+
_parse(input) {
|
|
1225
|
+
if (this._def.coerce) {
|
|
1226
|
+
try {
|
|
1227
|
+
input.data = BigInt(input.data);
|
|
1228
|
+
} catch {
|
|
1229
|
+
return this._getInvalidInput(input);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
const parsedType = this._getType(input);
|
|
1233
|
+
if (parsedType !== util.ZodParsedType.bigint) {
|
|
1234
|
+
return this._getInvalidInput(input);
|
|
1235
|
+
}
|
|
1236
|
+
let ctx = void 0;
|
|
1237
|
+
const status = new parseUtil.ParseStatus();
|
|
1238
|
+
for (const check of this._def.checks) {
|
|
1239
|
+
if (check.kind === "min") {
|
|
1240
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1241
|
+
if (tooSmall) {
|
|
1242
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1243
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1244
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
1245
|
+
type: "bigint",
|
|
1246
|
+
minimum: check.value,
|
|
1247
|
+
inclusive: check.inclusive,
|
|
1248
|
+
message: check.message
|
|
1249
|
+
});
|
|
1250
|
+
status.dirty();
|
|
1251
|
+
}
|
|
1252
|
+
} else if (check.kind === "max") {
|
|
1253
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1254
|
+
if (tooBig) {
|
|
1255
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1256
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1257
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
1258
|
+
type: "bigint",
|
|
1259
|
+
maximum: check.value,
|
|
1260
|
+
inclusive: check.inclusive,
|
|
1261
|
+
message: check.message
|
|
1262
|
+
});
|
|
1263
|
+
status.dirty();
|
|
1264
|
+
}
|
|
1265
|
+
} else if (check.kind === "multipleOf") {
|
|
1266
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
1267
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1268
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1269
|
+
code: ZodError.ZodIssueCode.not_multiple_of,
|
|
1270
|
+
multipleOf: check.value,
|
|
1271
|
+
message: check.message
|
|
1272
|
+
});
|
|
1273
|
+
status.dirty();
|
|
1274
|
+
}
|
|
1275
|
+
} else {
|
|
1276
|
+
util.util.assertNever(check);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
return { status: status.value, value: input.data };
|
|
1280
|
+
}
|
|
1281
|
+
_getInvalidInput(input) {
|
|
1282
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1283
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1284
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1285
|
+
expected: util.ZodParsedType.bigint,
|
|
1286
|
+
received: ctx.parsedType
|
|
1287
|
+
});
|
|
1288
|
+
return parseUtil.INVALID;
|
|
1289
|
+
}
|
|
1290
|
+
gte(value, message) {
|
|
1291
|
+
return this.setLimit("min", value, true, errorUtil.errorUtil.toString(message));
|
|
1292
|
+
}
|
|
1293
|
+
gt(value, message) {
|
|
1294
|
+
return this.setLimit("min", value, false, errorUtil.errorUtil.toString(message));
|
|
1295
|
+
}
|
|
1296
|
+
lte(value, message) {
|
|
1297
|
+
return this.setLimit("max", value, true, errorUtil.errorUtil.toString(message));
|
|
1298
|
+
}
|
|
1299
|
+
lt(value, message) {
|
|
1300
|
+
return this.setLimit("max", value, false, errorUtil.errorUtil.toString(message));
|
|
1301
|
+
}
|
|
1302
|
+
setLimit(kind, value, inclusive, message) {
|
|
1303
|
+
return new ZodBigInt({
|
|
1304
|
+
...this._def,
|
|
1305
|
+
checks: [
|
|
1306
|
+
...this._def.checks,
|
|
1307
|
+
{
|
|
1308
|
+
kind,
|
|
1309
|
+
value,
|
|
1310
|
+
inclusive,
|
|
1311
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1312
|
+
}
|
|
1313
|
+
]
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
_addCheck(check) {
|
|
1317
|
+
return new ZodBigInt({
|
|
1318
|
+
...this._def,
|
|
1319
|
+
checks: [...this._def.checks, check]
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
positive(message) {
|
|
1323
|
+
return this._addCheck({
|
|
1324
|
+
kind: "min",
|
|
1325
|
+
value: BigInt(0),
|
|
1326
|
+
inclusive: false,
|
|
1327
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
negative(message) {
|
|
1331
|
+
return this._addCheck({
|
|
1332
|
+
kind: "max",
|
|
1333
|
+
value: BigInt(0),
|
|
1334
|
+
inclusive: false,
|
|
1335
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
nonpositive(message) {
|
|
1339
|
+
return this._addCheck({
|
|
1340
|
+
kind: "max",
|
|
1341
|
+
value: BigInt(0),
|
|
1342
|
+
inclusive: true,
|
|
1343
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
nonnegative(message) {
|
|
1347
|
+
return this._addCheck({
|
|
1348
|
+
kind: "min",
|
|
1349
|
+
value: BigInt(0),
|
|
1350
|
+
inclusive: true,
|
|
1351
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
multipleOf(value, message) {
|
|
1355
|
+
return this._addCheck({
|
|
1356
|
+
kind: "multipleOf",
|
|
1357
|
+
value,
|
|
1358
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
get minValue() {
|
|
1362
|
+
let min = null;
|
|
1363
|
+
for (const ch of this._def.checks) {
|
|
1364
|
+
if (ch.kind === "min") {
|
|
1365
|
+
if (min === null || ch.value > min)
|
|
1366
|
+
min = ch.value;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return min;
|
|
1370
|
+
}
|
|
1371
|
+
get maxValue() {
|
|
1372
|
+
let max = null;
|
|
1373
|
+
for (const ch of this._def.checks) {
|
|
1374
|
+
if (ch.kind === "max") {
|
|
1375
|
+
if (max === null || ch.value < max)
|
|
1376
|
+
max = ch.value;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return max;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
ZodBigInt.create = (params) => {
|
|
1383
|
+
return new ZodBigInt({
|
|
1384
|
+
checks: [],
|
|
1385
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodBigInt,
|
|
1386
|
+
coerce: (params == null ? void 0 : params.coerce) ?? false,
|
|
1387
|
+
...processCreateParams(params)
|
|
1388
|
+
});
|
|
1389
|
+
};
|
|
1390
|
+
class ZodBoolean extends ZodType {
|
|
1391
|
+
_parse(input) {
|
|
1392
|
+
if (this._def.coerce) {
|
|
1393
|
+
input.data = Boolean(input.data);
|
|
1394
|
+
}
|
|
1395
|
+
const parsedType = this._getType(input);
|
|
1396
|
+
if (parsedType !== util.ZodParsedType.boolean) {
|
|
1397
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1398
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1399
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1400
|
+
expected: util.ZodParsedType.boolean,
|
|
1401
|
+
received: ctx.parsedType
|
|
1402
|
+
});
|
|
1403
|
+
return parseUtil.INVALID;
|
|
1404
|
+
}
|
|
1405
|
+
return parseUtil.OK(input.data);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
ZodBoolean.create = (params) => {
|
|
1409
|
+
return new ZodBoolean({
|
|
1410
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodBoolean,
|
|
1411
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
1412
|
+
...processCreateParams(params)
|
|
1413
|
+
});
|
|
1414
|
+
};
|
|
1415
|
+
class ZodDate extends ZodType {
|
|
1416
|
+
_parse(input) {
|
|
1417
|
+
if (this._def.coerce) {
|
|
1418
|
+
input.data = new Date(input.data);
|
|
1419
|
+
}
|
|
1420
|
+
const parsedType = this._getType(input);
|
|
1421
|
+
if (parsedType !== util.ZodParsedType.date) {
|
|
1422
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1423
|
+
parseUtil.addIssueToContext(ctx2, {
|
|
1424
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1425
|
+
expected: util.ZodParsedType.date,
|
|
1426
|
+
received: ctx2.parsedType
|
|
1427
|
+
});
|
|
1428
|
+
return parseUtil.INVALID;
|
|
1429
|
+
}
|
|
1430
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
1431
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1432
|
+
parseUtil.addIssueToContext(ctx2, {
|
|
1433
|
+
code: ZodError.ZodIssueCode.invalid_date
|
|
1434
|
+
});
|
|
1435
|
+
return parseUtil.INVALID;
|
|
1436
|
+
}
|
|
1437
|
+
const status = new parseUtil.ParseStatus();
|
|
1438
|
+
let ctx = void 0;
|
|
1439
|
+
for (const check of this._def.checks) {
|
|
1440
|
+
if (check.kind === "min") {
|
|
1441
|
+
if (input.data.getTime() < check.value) {
|
|
1442
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1443
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1444
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
1445
|
+
message: check.message,
|
|
1446
|
+
inclusive: true,
|
|
1447
|
+
exact: false,
|
|
1448
|
+
minimum: check.value,
|
|
1449
|
+
type: "date"
|
|
1450
|
+
});
|
|
1451
|
+
status.dirty();
|
|
1452
|
+
}
|
|
1453
|
+
} else if (check.kind === "max") {
|
|
1454
|
+
if (input.data.getTime() > check.value) {
|
|
1455
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1456
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1457
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
1458
|
+
message: check.message,
|
|
1459
|
+
inclusive: true,
|
|
1460
|
+
exact: false,
|
|
1461
|
+
maximum: check.value,
|
|
1462
|
+
type: "date"
|
|
1463
|
+
});
|
|
1464
|
+
status.dirty();
|
|
1465
|
+
}
|
|
1466
|
+
} else {
|
|
1467
|
+
util.util.assertNever(check);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
status: status.value,
|
|
1472
|
+
value: new Date(input.data.getTime())
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
_addCheck(check) {
|
|
1476
|
+
return new ZodDate({
|
|
1477
|
+
...this._def,
|
|
1478
|
+
checks: [...this._def.checks, check]
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
min(minDate, message) {
|
|
1482
|
+
return this._addCheck({
|
|
1483
|
+
kind: "min",
|
|
1484
|
+
value: minDate.getTime(),
|
|
1485
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
max(maxDate, message) {
|
|
1489
|
+
return this._addCheck({
|
|
1490
|
+
kind: "max",
|
|
1491
|
+
value: maxDate.getTime(),
|
|
1492
|
+
message: errorUtil.errorUtil.toString(message)
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
get minDate() {
|
|
1496
|
+
let min = null;
|
|
1497
|
+
for (const ch of this._def.checks) {
|
|
1498
|
+
if (ch.kind === "min") {
|
|
1499
|
+
if (min === null || ch.value > min)
|
|
1500
|
+
min = ch.value;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return min != null ? new Date(min) : null;
|
|
1504
|
+
}
|
|
1505
|
+
get maxDate() {
|
|
1506
|
+
let max = null;
|
|
1507
|
+
for (const ch of this._def.checks) {
|
|
1508
|
+
if (ch.kind === "max") {
|
|
1509
|
+
if (max === null || ch.value < max)
|
|
1510
|
+
max = ch.value;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
return max != null ? new Date(max) : null;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
ZodDate.create = (params) => {
|
|
1517
|
+
return new ZodDate({
|
|
1518
|
+
checks: [],
|
|
1519
|
+
coerce: (params == null ? void 0 : params.coerce) || false,
|
|
1520
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodDate,
|
|
1521
|
+
...processCreateParams(params)
|
|
1522
|
+
});
|
|
1523
|
+
};
|
|
1524
|
+
class ZodSymbol extends ZodType {
|
|
1525
|
+
_parse(input) {
|
|
1526
|
+
const parsedType = this._getType(input);
|
|
1527
|
+
if (parsedType !== util.ZodParsedType.symbol) {
|
|
1528
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1529
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1530
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1531
|
+
expected: util.ZodParsedType.symbol,
|
|
1532
|
+
received: ctx.parsedType
|
|
1533
|
+
});
|
|
1534
|
+
return parseUtil.INVALID;
|
|
1535
|
+
}
|
|
1536
|
+
return parseUtil.OK(input.data);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
ZodSymbol.create = (params) => {
|
|
1540
|
+
return new ZodSymbol({
|
|
1541
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodSymbol,
|
|
1542
|
+
...processCreateParams(params)
|
|
1543
|
+
});
|
|
1544
|
+
};
|
|
1545
|
+
class ZodUndefined extends ZodType {
|
|
1546
|
+
_parse(input) {
|
|
1547
|
+
const parsedType = this._getType(input);
|
|
1548
|
+
if (parsedType !== util.ZodParsedType.undefined) {
|
|
1549
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1550
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1551
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1552
|
+
expected: util.ZodParsedType.undefined,
|
|
1553
|
+
received: ctx.parsedType
|
|
1554
|
+
});
|
|
1555
|
+
return parseUtil.INVALID;
|
|
1556
|
+
}
|
|
1557
|
+
return parseUtil.OK(input.data);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
ZodUndefined.create = (params) => {
|
|
1561
|
+
return new ZodUndefined({
|
|
1562
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodUndefined,
|
|
1563
|
+
...processCreateParams(params)
|
|
1564
|
+
});
|
|
1565
|
+
};
|
|
1566
|
+
class ZodNull extends ZodType {
|
|
1567
|
+
_parse(input) {
|
|
1568
|
+
const parsedType = this._getType(input);
|
|
1569
|
+
if (parsedType !== util.ZodParsedType.null) {
|
|
1570
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1571
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1572
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1573
|
+
expected: util.ZodParsedType.null,
|
|
1574
|
+
received: ctx.parsedType
|
|
1575
|
+
});
|
|
1576
|
+
return parseUtil.INVALID;
|
|
1577
|
+
}
|
|
1578
|
+
return parseUtil.OK(input.data);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
ZodNull.create = (params) => {
|
|
1582
|
+
return new ZodNull({
|
|
1583
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNull,
|
|
1584
|
+
...processCreateParams(params)
|
|
1585
|
+
});
|
|
1586
|
+
};
|
|
1587
|
+
class ZodAny extends ZodType {
|
|
1588
|
+
constructor() {
|
|
1589
|
+
super(...arguments);
|
|
1590
|
+
this._any = true;
|
|
1591
|
+
}
|
|
1592
|
+
_parse(input) {
|
|
1593
|
+
return parseUtil.OK(input.data);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
ZodAny.create = (params) => {
|
|
1597
|
+
return new ZodAny({
|
|
1598
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodAny,
|
|
1599
|
+
...processCreateParams(params)
|
|
1600
|
+
});
|
|
1601
|
+
};
|
|
1602
|
+
class ZodUnknown extends ZodType {
|
|
1603
|
+
constructor() {
|
|
1604
|
+
super(...arguments);
|
|
1605
|
+
this._unknown = true;
|
|
1606
|
+
}
|
|
1607
|
+
_parse(input) {
|
|
1608
|
+
return parseUtil.OK(input.data);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
ZodUnknown.create = (params) => {
|
|
1612
|
+
return new ZodUnknown({
|
|
1613
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodUnknown,
|
|
1614
|
+
...processCreateParams(params)
|
|
1615
|
+
});
|
|
1616
|
+
};
|
|
1617
|
+
class ZodNever extends ZodType {
|
|
1618
|
+
_parse(input) {
|
|
1619
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1620
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1621
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1622
|
+
expected: util.ZodParsedType.never,
|
|
1623
|
+
received: ctx.parsedType
|
|
1624
|
+
});
|
|
1625
|
+
return parseUtil.INVALID;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
ZodNever.create = (params) => {
|
|
1629
|
+
return new ZodNever({
|
|
1630
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNever,
|
|
1631
|
+
...processCreateParams(params)
|
|
1632
|
+
});
|
|
1633
|
+
};
|
|
1634
|
+
class ZodVoid extends ZodType {
|
|
1635
|
+
_parse(input) {
|
|
1636
|
+
const parsedType = this._getType(input);
|
|
1637
|
+
if (parsedType !== util.ZodParsedType.undefined) {
|
|
1638
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1639
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1640
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1641
|
+
expected: util.ZodParsedType.void,
|
|
1642
|
+
received: ctx.parsedType
|
|
1643
|
+
});
|
|
1644
|
+
return parseUtil.INVALID;
|
|
1645
|
+
}
|
|
1646
|
+
return parseUtil.OK(input.data);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
ZodVoid.create = (params) => {
|
|
1650
|
+
return new ZodVoid({
|
|
1651
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodVoid,
|
|
1652
|
+
...processCreateParams(params)
|
|
1653
|
+
});
|
|
1654
|
+
};
|
|
1655
|
+
class ZodArray extends ZodType {
|
|
1656
|
+
_parse(input) {
|
|
1657
|
+
const { ctx, status } = this._processInputParams(input);
|
|
1658
|
+
const def = this._def;
|
|
1659
|
+
if (ctx.parsedType !== util.ZodParsedType.array) {
|
|
1660
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1661
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1662
|
+
expected: util.ZodParsedType.array,
|
|
1663
|
+
received: ctx.parsedType
|
|
1664
|
+
});
|
|
1665
|
+
return parseUtil.INVALID;
|
|
1666
|
+
}
|
|
1667
|
+
if (def.exactLength !== null) {
|
|
1668
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
1669
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
1670
|
+
if (tooBig || tooSmall) {
|
|
1671
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1672
|
+
code: tooBig ? ZodError.ZodIssueCode.too_big : ZodError.ZodIssueCode.too_small,
|
|
1673
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
1674
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
1675
|
+
type: "array",
|
|
1676
|
+
inclusive: true,
|
|
1677
|
+
exact: true,
|
|
1678
|
+
message: def.exactLength.message
|
|
1679
|
+
});
|
|
1680
|
+
status.dirty();
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
if (def.minLength !== null) {
|
|
1684
|
+
if (ctx.data.length < def.minLength.value) {
|
|
1685
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1686
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
1687
|
+
minimum: def.minLength.value,
|
|
1688
|
+
type: "array",
|
|
1689
|
+
inclusive: true,
|
|
1690
|
+
exact: false,
|
|
1691
|
+
message: def.minLength.message
|
|
1692
|
+
});
|
|
1693
|
+
status.dirty();
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if (def.maxLength !== null) {
|
|
1697
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
1698
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1699
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
1700
|
+
maximum: def.maxLength.value,
|
|
1701
|
+
type: "array",
|
|
1702
|
+
inclusive: true,
|
|
1703
|
+
exact: false,
|
|
1704
|
+
message: def.maxLength.message
|
|
1705
|
+
});
|
|
1706
|
+
status.dirty();
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
if (ctx.common.async) {
|
|
1710
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
1711
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1712
|
+
})).then((result2) => {
|
|
1713
|
+
return parseUtil.ParseStatus.mergeArray(status, result2);
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
const result = [...ctx.data].map((item, i) => {
|
|
1717
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
1718
|
+
});
|
|
1719
|
+
return parseUtil.ParseStatus.mergeArray(status, result);
|
|
1720
|
+
}
|
|
1721
|
+
get element() {
|
|
1722
|
+
return this._def.type;
|
|
1723
|
+
}
|
|
1724
|
+
min(minLength, message) {
|
|
1725
|
+
return new ZodArray({
|
|
1726
|
+
...this._def,
|
|
1727
|
+
minLength: { value: minLength, message: errorUtil.errorUtil.toString(message) }
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
max(maxLength, message) {
|
|
1731
|
+
return new ZodArray({
|
|
1732
|
+
...this._def,
|
|
1733
|
+
maxLength: { value: maxLength, message: errorUtil.errorUtil.toString(message) }
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
length(len, message) {
|
|
1737
|
+
return new ZodArray({
|
|
1738
|
+
...this._def,
|
|
1739
|
+
exactLength: { value: len, message: errorUtil.errorUtil.toString(message) }
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
nonempty(message) {
|
|
1743
|
+
return this.min(1, message);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
ZodArray.create = (schema, params) => {
|
|
1747
|
+
return new ZodArray({
|
|
1748
|
+
type: schema,
|
|
1749
|
+
minLength: null,
|
|
1750
|
+
maxLength: null,
|
|
1751
|
+
exactLength: null,
|
|
1752
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodArray,
|
|
1753
|
+
...processCreateParams(params)
|
|
1754
|
+
});
|
|
1755
|
+
};
|
|
1756
|
+
function deepPartialify(schema) {
|
|
1757
|
+
if (schema instanceof ZodObject) {
|
|
1758
|
+
const newShape = {};
|
|
1759
|
+
for (const key in schema.shape) {
|
|
1760
|
+
const fieldSchema = schema.shape[key];
|
|
1761
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
1762
|
+
}
|
|
1763
|
+
return new ZodObject({
|
|
1764
|
+
...schema._def,
|
|
1765
|
+
shape: () => newShape
|
|
1766
|
+
});
|
|
1767
|
+
} else if (schema instanceof ZodArray) {
|
|
1768
|
+
return new ZodArray({
|
|
1769
|
+
...schema._def,
|
|
1770
|
+
type: deepPartialify(schema.element)
|
|
1771
|
+
});
|
|
1772
|
+
} else if (schema instanceof ZodOptional) {
|
|
1773
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
1774
|
+
} else if (schema instanceof ZodNullable) {
|
|
1775
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1776
|
+
} else if (schema instanceof ZodTuple) {
|
|
1777
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
1778
|
+
} else {
|
|
1779
|
+
return schema;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
class ZodObject extends ZodType {
|
|
1783
|
+
constructor() {
|
|
1784
|
+
super(...arguments);
|
|
1785
|
+
this._cached = null;
|
|
1786
|
+
this.nonstrict = this.passthrough;
|
|
1787
|
+
this.augment = this.extend;
|
|
1788
|
+
}
|
|
1789
|
+
_getCached() {
|
|
1790
|
+
if (this._cached !== null)
|
|
1791
|
+
return this._cached;
|
|
1792
|
+
const shape = this._def.shape();
|
|
1793
|
+
const keys = util.util.objectKeys(shape);
|
|
1794
|
+
this._cached = { shape, keys };
|
|
1795
|
+
return this._cached;
|
|
1796
|
+
}
|
|
1797
|
+
_parse(input) {
|
|
1798
|
+
const parsedType = this._getType(input);
|
|
1799
|
+
if (parsedType !== util.ZodParsedType.object) {
|
|
1800
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1801
|
+
parseUtil.addIssueToContext(ctx2, {
|
|
1802
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
1803
|
+
expected: util.ZodParsedType.object,
|
|
1804
|
+
received: ctx2.parsedType
|
|
1805
|
+
});
|
|
1806
|
+
return parseUtil.INVALID;
|
|
1807
|
+
}
|
|
1808
|
+
const { status, ctx } = this._processInputParams(input);
|
|
1809
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
1810
|
+
const extraKeys = [];
|
|
1811
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
1812
|
+
for (const key in ctx.data) {
|
|
1813
|
+
if (!shapeKeys.includes(key)) {
|
|
1814
|
+
extraKeys.push(key);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
const pairs = [];
|
|
1819
|
+
for (const key of shapeKeys) {
|
|
1820
|
+
const keyValidator = shape[key];
|
|
1821
|
+
const value = ctx.data[key];
|
|
1822
|
+
pairs.push({
|
|
1823
|
+
key: { status: "valid", value: key },
|
|
1824
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
1825
|
+
alwaysSet: key in ctx.data
|
|
1826
|
+
});
|
|
1827
|
+
}
|
|
1828
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
1829
|
+
const unknownKeys = this._def.unknownKeys;
|
|
1830
|
+
if (unknownKeys === "passthrough") {
|
|
1831
|
+
for (const key of extraKeys) {
|
|
1832
|
+
pairs.push({
|
|
1833
|
+
key: { status: "valid", value: key },
|
|
1834
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
} else if (unknownKeys === "strict") {
|
|
1838
|
+
if (extraKeys.length > 0) {
|
|
1839
|
+
parseUtil.addIssueToContext(ctx, {
|
|
1840
|
+
code: ZodError.ZodIssueCode.unrecognized_keys,
|
|
1841
|
+
keys: extraKeys
|
|
1842
|
+
});
|
|
1843
|
+
status.dirty();
|
|
1844
|
+
}
|
|
1845
|
+
} else if (unknownKeys === "strip") ;
|
|
1846
|
+
else {
|
|
1847
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
1848
|
+
}
|
|
1849
|
+
} else {
|
|
1850
|
+
const catchall = this._def.catchall;
|
|
1851
|
+
for (const key of extraKeys) {
|
|
1852
|
+
const value = ctx.data[key];
|
|
1853
|
+
pairs.push({
|
|
1854
|
+
key: { status: "valid", value: key },
|
|
1855
|
+
value: catchall._parse(
|
|
1856
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
1857
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
1858
|
+
),
|
|
1859
|
+
alwaysSet: key in ctx.data
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
if (ctx.common.async) {
|
|
1864
|
+
return Promise.resolve().then(async () => {
|
|
1865
|
+
const syncPairs = [];
|
|
1866
|
+
for (const pair of pairs) {
|
|
1867
|
+
const key = await pair.key;
|
|
1868
|
+
const value = await pair.value;
|
|
1869
|
+
syncPairs.push({
|
|
1870
|
+
key,
|
|
1871
|
+
value,
|
|
1872
|
+
alwaysSet: pair.alwaysSet
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
return syncPairs;
|
|
1876
|
+
}).then((syncPairs) => {
|
|
1877
|
+
return parseUtil.ParseStatus.mergeObjectSync(status, syncPairs);
|
|
1878
|
+
});
|
|
1879
|
+
} else {
|
|
1880
|
+
return parseUtil.ParseStatus.mergeObjectSync(status, pairs);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
get shape() {
|
|
1884
|
+
return this._def.shape();
|
|
1885
|
+
}
|
|
1886
|
+
strict(message) {
|
|
1887
|
+
errorUtil.errorUtil.errToObj;
|
|
1888
|
+
return new ZodObject({
|
|
1889
|
+
...this._def,
|
|
1890
|
+
unknownKeys: "strict",
|
|
1891
|
+
...message !== void 0 ? {
|
|
1892
|
+
errorMap: (issue, ctx) => {
|
|
1893
|
+
var _a, _b;
|
|
1894
|
+
const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) ?? ctx.defaultError;
|
|
1895
|
+
if (issue.code === "unrecognized_keys")
|
|
1896
|
+
return {
|
|
1897
|
+
message: errorUtil.errorUtil.errToObj(message).message ?? defaultError
|
|
1898
|
+
};
|
|
1899
|
+
return {
|
|
1900
|
+
message: defaultError
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
} : {}
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
strip() {
|
|
1907
|
+
return new ZodObject({
|
|
1908
|
+
...this._def,
|
|
1909
|
+
unknownKeys: "strip"
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
passthrough() {
|
|
1913
|
+
return new ZodObject({
|
|
1914
|
+
...this._def,
|
|
1915
|
+
unknownKeys: "passthrough"
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
// const AugmentFactory =
|
|
1919
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
1920
|
+
// <Augmentation extends ZodRawShape>(
|
|
1921
|
+
// augmentation: Augmentation
|
|
1922
|
+
// ): ZodObject<
|
|
1923
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
1924
|
+
// Def["unknownKeys"],
|
|
1925
|
+
// Def["catchall"]
|
|
1926
|
+
// > => {
|
|
1927
|
+
// return new ZodObject({
|
|
1928
|
+
// ...def,
|
|
1929
|
+
// shape: () => ({
|
|
1930
|
+
// ...def.shape(),
|
|
1931
|
+
// ...augmentation,
|
|
1932
|
+
// }),
|
|
1933
|
+
// }) as any;
|
|
1934
|
+
// };
|
|
1935
|
+
extend(augmentation) {
|
|
1936
|
+
return new ZodObject({
|
|
1937
|
+
...this._def,
|
|
1938
|
+
shape: () => ({
|
|
1939
|
+
...this._def.shape(),
|
|
1940
|
+
...augmentation
|
|
1941
|
+
})
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
1946
|
+
* inferred type of merged objects. Please
|
|
1947
|
+
* upgrade if you are experiencing issues.
|
|
1948
|
+
*/
|
|
1949
|
+
merge(merging) {
|
|
1950
|
+
const merged = new ZodObject({
|
|
1951
|
+
unknownKeys: merging._def.unknownKeys,
|
|
1952
|
+
catchall: merging._def.catchall,
|
|
1953
|
+
shape: () => ({
|
|
1954
|
+
...this._def.shape(),
|
|
1955
|
+
...merging._def.shape()
|
|
1956
|
+
}),
|
|
1957
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodObject
|
|
1958
|
+
});
|
|
1959
|
+
return merged;
|
|
1960
|
+
}
|
|
1961
|
+
// merge<
|
|
1962
|
+
// Incoming extends AnyZodObject,
|
|
1963
|
+
// Augmentation extends Incoming["shape"],
|
|
1964
|
+
// NewOutput extends {
|
|
1965
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
1966
|
+
// ? Augmentation[k]["_output"]
|
|
1967
|
+
// : k extends keyof Output
|
|
1968
|
+
// ? Output[k]
|
|
1969
|
+
// : never;
|
|
1970
|
+
// },
|
|
1971
|
+
// NewInput extends {
|
|
1972
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
1973
|
+
// ? Augmentation[k]["_input"]
|
|
1974
|
+
// : k extends keyof Input
|
|
1975
|
+
// ? Input[k]
|
|
1976
|
+
// : never;
|
|
1977
|
+
// }
|
|
1978
|
+
// >(
|
|
1979
|
+
// merging: Incoming
|
|
1980
|
+
// ): ZodObject<
|
|
1981
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
1982
|
+
// Incoming["_def"]["unknownKeys"],
|
|
1983
|
+
// Incoming["_def"]["catchall"],
|
|
1984
|
+
// NewOutput,
|
|
1985
|
+
// NewInput
|
|
1986
|
+
// > {
|
|
1987
|
+
// const merged: any = new ZodObject({
|
|
1988
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
1989
|
+
// catchall: merging._def.catchall,
|
|
1990
|
+
// shape: () =>
|
|
1991
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
1992
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
1993
|
+
// }) as any;
|
|
1994
|
+
// return merged;
|
|
1995
|
+
// }
|
|
1996
|
+
setKey(key, schema) {
|
|
1997
|
+
return this.augment({ [key]: schema });
|
|
1998
|
+
}
|
|
1999
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2000
|
+
// merging: Incoming
|
|
2001
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2002
|
+
// ZodObject<
|
|
2003
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2004
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2005
|
+
// Incoming["_def"]["catchall"]
|
|
2006
|
+
// > {
|
|
2007
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2008
|
+
// // this._def.shape(),
|
|
2009
|
+
// // merging._def.shape()
|
|
2010
|
+
// // );
|
|
2011
|
+
// const merged: any = new ZodObject({
|
|
2012
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2013
|
+
// catchall: merging._def.catchall,
|
|
2014
|
+
// shape: () =>
|
|
2015
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2016
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2017
|
+
// }) as any;
|
|
2018
|
+
// return merged;
|
|
2019
|
+
// }
|
|
2020
|
+
catchall(index) {
|
|
2021
|
+
return new ZodObject({
|
|
2022
|
+
...this._def,
|
|
2023
|
+
catchall: index
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
pick(mask) {
|
|
2027
|
+
const shape = {};
|
|
2028
|
+
for (const key of util.util.objectKeys(mask)) {
|
|
2029
|
+
if (mask[key] && this.shape[key]) {
|
|
2030
|
+
shape[key] = this.shape[key];
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
return new ZodObject({
|
|
2034
|
+
...this._def,
|
|
2035
|
+
shape: () => shape
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
omit(mask) {
|
|
2039
|
+
const shape = {};
|
|
2040
|
+
for (const key of util.util.objectKeys(this.shape)) {
|
|
2041
|
+
if (!mask[key]) {
|
|
2042
|
+
shape[key] = this.shape[key];
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
return new ZodObject({
|
|
2046
|
+
...this._def,
|
|
2047
|
+
shape: () => shape
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* @deprecated
|
|
2052
|
+
*/
|
|
2053
|
+
deepPartial() {
|
|
2054
|
+
return deepPartialify(this);
|
|
2055
|
+
}
|
|
2056
|
+
partial(mask) {
|
|
2057
|
+
const newShape = {};
|
|
2058
|
+
for (const key of util.util.objectKeys(this.shape)) {
|
|
2059
|
+
const fieldSchema = this.shape[key];
|
|
2060
|
+
if (mask && !mask[key]) {
|
|
2061
|
+
newShape[key] = fieldSchema;
|
|
2062
|
+
} else {
|
|
2063
|
+
newShape[key] = fieldSchema.optional();
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return new ZodObject({
|
|
2067
|
+
...this._def,
|
|
2068
|
+
shape: () => newShape
|
|
2069
|
+
});
|
|
2070
|
+
}
|
|
2071
|
+
required(mask) {
|
|
2072
|
+
const newShape = {};
|
|
2073
|
+
for (const key of util.util.objectKeys(this.shape)) {
|
|
2074
|
+
if (mask && !mask[key]) {
|
|
2075
|
+
newShape[key] = this.shape[key];
|
|
2076
|
+
} else {
|
|
2077
|
+
const fieldSchema = this.shape[key];
|
|
2078
|
+
let newField = fieldSchema;
|
|
2079
|
+
while (newField instanceof ZodOptional) {
|
|
2080
|
+
newField = newField._def.innerType;
|
|
2081
|
+
}
|
|
2082
|
+
newShape[key] = newField;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
return new ZodObject({
|
|
2086
|
+
...this._def,
|
|
2087
|
+
shape: () => newShape
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
keyof() {
|
|
2091
|
+
return createZodEnum(util.util.objectKeys(this.shape));
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
ZodObject.create = (shape, params) => {
|
|
2095
|
+
return new ZodObject({
|
|
2096
|
+
shape: () => shape,
|
|
2097
|
+
unknownKeys: "strip",
|
|
2098
|
+
catchall: ZodNever.create(),
|
|
2099
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodObject,
|
|
2100
|
+
...processCreateParams(params)
|
|
2101
|
+
});
|
|
2102
|
+
};
|
|
2103
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2104
|
+
return new ZodObject({
|
|
2105
|
+
shape: () => shape,
|
|
2106
|
+
unknownKeys: "strict",
|
|
2107
|
+
catchall: ZodNever.create(),
|
|
2108
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodObject,
|
|
2109
|
+
...processCreateParams(params)
|
|
2110
|
+
});
|
|
2111
|
+
};
|
|
2112
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2113
|
+
return new ZodObject({
|
|
2114
|
+
shape,
|
|
2115
|
+
unknownKeys: "strip",
|
|
2116
|
+
catchall: ZodNever.create(),
|
|
2117
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodObject,
|
|
2118
|
+
...processCreateParams(params)
|
|
2119
|
+
});
|
|
2120
|
+
};
|
|
2121
|
+
class ZodUnion extends ZodType {
|
|
2122
|
+
_parse(input) {
|
|
2123
|
+
const { ctx } = this._processInputParams(input);
|
|
2124
|
+
const options = this._def.options;
|
|
2125
|
+
function handleResults(results) {
|
|
2126
|
+
for (const result of results) {
|
|
2127
|
+
if (result.result.status === "valid") {
|
|
2128
|
+
return result.result;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
for (const result of results) {
|
|
2132
|
+
if (result.result.status === "dirty") {
|
|
2133
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2134
|
+
return result.result;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
const unionErrors = results.map((result) => new ZodError.ZodError(result.ctx.common.issues));
|
|
2138
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2139
|
+
code: ZodError.ZodIssueCode.invalid_union,
|
|
2140
|
+
unionErrors
|
|
2141
|
+
});
|
|
2142
|
+
return parseUtil.INVALID;
|
|
2143
|
+
}
|
|
2144
|
+
if (ctx.common.async) {
|
|
2145
|
+
return Promise.all(options.map(async (option) => {
|
|
2146
|
+
const childCtx = {
|
|
2147
|
+
...ctx,
|
|
2148
|
+
common: {
|
|
2149
|
+
...ctx.common,
|
|
2150
|
+
issues: []
|
|
2151
|
+
},
|
|
2152
|
+
parent: null
|
|
2153
|
+
};
|
|
2154
|
+
return {
|
|
2155
|
+
result: await option._parseAsync({
|
|
2156
|
+
data: ctx.data,
|
|
2157
|
+
path: ctx.path,
|
|
2158
|
+
parent: childCtx
|
|
2159
|
+
}),
|
|
2160
|
+
ctx: childCtx
|
|
2161
|
+
};
|
|
2162
|
+
})).then(handleResults);
|
|
2163
|
+
} else {
|
|
2164
|
+
let dirty = void 0;
|
|
2165
|
+
const issues = [];
|
|
2166
|
+
for (const option of options) {
|
|
2167
|
+
const childCtx = {
|
|
2168
|
+
...ctx,
|
|
2169
|
+
common: {
|
|
2170
|
+
...ctx.common,
|
|
2171
|
+
issues: []
|
|
2172
|
+
},
|
|
2173
|
+
parent: null
|
|
2174
|
+
};
|
|
2175
|
+
const result = option._parseSync({
|
|
2176
|
+
data: ctx.data,
|
|
2177
|
+
path: ctx.path,
|
|
2178
|
+
parent: childCtx
|
|
2179
|
+
});
|
|
2180
|
+
if (result.status === "valid") {
|
|
2181
|
+
return result;
|
|
2182
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
2183
|
+
dirty = { result, ctx: childCtx };
|
|
2184
|
+
}
|
|
2185
|
+
if (childCtx.common.issues.length) {
|
|
2186
|
+
issues.push(childCtx.common.issues);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
if (dirty) {
|
|
2190
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2191
|
+
return dirty.result;
|
|
2192
|
+
}
|
|
2193
|
+
const unionErrors = issues.map((issues2) => new ZodError.ZodError(issues2));
|
|
2194
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2195
|
+
code: ZodError.ZodIssueCode.invalid_union,
|
|
2196
|
+
unionErrors
|
|
2197
|
+
});
|
|
2198
|
+
return parseUtil.INVALID;
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
get options() {
|
|
2202
|
+
return this._def.options;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
ZodUnion.create = (types, params) => {
|
|
2206
|
+
return new ZodUnion({
|
|
2207
|
+
options: types,
|
|
2208
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodUnion,
|
|
2209
|
+
...processCreateParams(params)
|
|
2210
|
+
});
|
|
2211
|
+
};
|
|
2212
|
+
function mergeValues(a, b) {
|
|
2213
|
+
const aType = util.getParsedType(a);
|
|
2214
|
+
const bType = util.getParsedType(b);
|
|
2215
|
+
if (a === b) {
|
|
2216
|
+
return { valid: true, data: a };
|
|
2217
|
+
} else if (aType === util.ZodParsedType.object && bType === util.ZodParsedType.object) {
|
|
2218
|
+
const bKeys = util.util.objectKeys(b);
|
|
2219
|
+
const sharedKeys = util.util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
2220
|
+
const newObj = { ...a, ...b };
|
|
2221
|
+
for (const key of sharedKeys) {
|
|
2222
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
2223
|
+
if (!sharedValue.valid) {
|
|
2224
|
+
return { valid: false };
|
|
2225
|
+
}
|
|
2226
|
+
newObj[key] = sharedValue.data;
|
|
2227
|
+
}
|
|
2228
|
+
return { valid: true, data: newObj };
|
|
2229
|
+
} else if (aType === util.ZodParsedType.array && bType === util.ZodParsedType.array) {
|
|
2230
|
+
if (a.length !== b.length) {
|
|
2231
|
+
return { valid: false };
|
|
2232
|
+
}
|
|
2233
|
+
const newArray = [];
|
|
2234
|
+
for (let index = 0; index < a.length; index++) {
|
|
2235
|
+
const itemA = a[index];
|
|
2236
|
+
const itemB = b[index];
|
|
2237
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
2238
|
+
if (!sharedValue.valid) {
|
|
2239
|
+
return { valid: false };
|
|
2240
|
+
}
|
|
2241
|
+
newArray.push(sharedValue.data);
|
|
2242
|
+
}
|
|
2243
|
+
return { valid: true, data: newArray };
|
|
2244
|
+
} else if (aType === util.ZodParsedType.date && bType === util.ZodParsedType.date && +a === +b) {
|
|
2245
|
+
return { valid: true, data: a };
|
|
2246
|
+
} else {
|
|
2247
|
+
return { valid: false };
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
class ZodIntersection extends ZodType {
|
|
2251
|
+
_parse(input) {
|
|
2252
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2253
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2254
|
+
if (parseUtil.isAborted(parsedLeft) || parseUtil.isAborted(parsedRight)) {
|
|
2255
|
+
return parseUtil.INVALID;
|
|
2256
|
+
}
|
|
2257
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2258
|
+
if (!merged.valid) {
|
|
2259
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2260
|
+
code: ZodError.ZodIssueCode.invalid_intersection_types
|
|
2261
|
+
});
|
|
2262
|
+
return parseUtil.INVALID;
|
|
2263
|
+
}
|
|
2264
|
+
if (parseUtil.isDirty(parsedLeft) || parseUtil.isDirty(parsedRight)) {
|
|
2265
|
+
status.dirty();
|
|
2266
|
+
}
|
|
2267
|
+
return { status: status.value, value: merged.data };
|
|
2268
|
+
};
|
|
2269
|
+
if (ctx.common.async) {
|
|
2270
|
+
return Promise.all([
|
|
2271
|
+
this._def.left._parseAsync({
|
|
2272
|
+
data: ctx.data,
|
|
2273
|
+
path: ctx.path,
|
|
2274
|
+
parent: ctx
|
|
2275
|
+
}),
|
|
2276
|
+
this._def.right._parseAsync({
|
|
2277
|
+
data: ctx.data,
|
|
2278
|
+
path: ctx.path,
|
|
2279
|
+
parent: ctx
|
|
2280
|
+
})
|
|
2281
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
2282
|
+
} else {
|
|
2283
|
+
return handleParsed(this._def.left._parseSync({
|
|
2284
|
+
data: ctx.data,
|
|
2285
|
+
path: ctx.path,
|
|
2286
|
+
parent: ctx
|
|
2287
|
+
}), this._def.right._parseSync({
|
|
2288
|
+
data: ctx.data,
|
|
2289
|
+
path: ctx.path,
|
|
2290
|
+
parent: ctx
|
|
2291
|
+
}));
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
ZodIntersection.create = (left, right, params) => {
|
|
2296
|
+
return new ZodIntersection({
|
|
2297
|
+
left,
|
|
2298
|
+
right,
|
|
2299
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodIntersection,
|
|
2300
|
+
...processCreateParams(params)
|
|
2301
|
+
});
|
|
2302
|
+
};
|
|
2303
|
+
class ZodTuple extends ZodType {
|
|
2304
|
+
_parse(input) {
|
|
2305
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2306
|
+
if (ctx.parsedType !== util.ZodParsedType.array) {
|
|
2307
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2308
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
2309
|
+
expected: util.ZodParsedType.array,
|
|
2310
|
+
received: ctx.parsedType
|
|
2311
|
+
});
|
|
2312
|
+
return parseUtil.INVALID;
|
|
2313
|
+
}
|
|
2314
|
+
if (ctx.data.length < this._def.items.length) {
|
|
2315
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2316
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
2317
|
+
minimum: this._def.items.length,
|
|
2318
|
+
inclusive: true,
|
|
2319
|
+
exact: false,
|
|
2320
|
+
type: "array"
|
|
2321
|
+
});
|
|
2322
|
+
return parseUtil.INVALID;
|
|
2323
|
+
}
|
|
2324
|
+
const rest = this._def.rest;
|
|
2325
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
2326
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2327
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
2328
|
+
maximum: this._def.items.length,
|
|
2329
|
+
inclusive: true,
|
|
2330
|
+
exact: false,
|
|
2331
|
+
type: "array"
|
|
2332
|
+
});
|
|
2333
|
+
status.dirty();
|
|
2334
|
+
}
|
|
2335
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
2336
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2337
|
+
if (!schema)
|
|
2338
|
+
return null;
|
|
2339
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
2340
|
+
}).filter((x) => !!x);
|
|
2341
|
+
if (ctx.common.async) {
|
|
2342
|
+
return Promise.all(items).then((results) => {
|
|
2343
|
+
return parseUtil.ParseStatus.mergeArray(status, results);
|
|
2344
|
+
});
|
|
2345
|
+
} else {
|
|
2346
|
+
return parseUtil.ParseStatus.mergeArray(status, items);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
get items() {
|
|
2350
|
+
return this._def.items;
|
|
2351
|
+
}
|
|
2352
|
+
rest(rest) {
|
|
2353
|
+
return new ZodTuple({
|
|
2354
|
+
...this._def,
|
|
2355
|
+
rest
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
ZodTuple.create = (schemas, params) => {
|
|
2360
|
+
if (!Array.isArray(schemas)) {
|
|
2361
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
2362
|
+
}
|
|
2363
|
+
return new ZodTuple({
|
|
2364
|
+
items: schemas,
|
|
2365
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodTuple,
|
|
2366
|
+
rest: null,
|
|
2367
|
+
...processCreateParams(params)
|
|
2368
|
+
});
|
|
2369
|
+
};
|
|
2370
|
+
class ZodRecord extends ZodType {
|
|
2371
|
+
get keySchema() {
|
|
2372
|
+
return this._def.keyType;
|
|
2373
|
+
}
|
|
2374
|
+
get valueSchema() {
|
|
2375
|
+
return this._def.valueType;
|
|
2376
|
+
}
|
|
2377
|
+
_parse(input) {
|
|
2378
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2379
|
+
if (ctx.parsedType !== util.ZodParsedType.object) {
|
|
2380
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2381
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
2382
|
+
expected: util.ZodParsedType.object,
|
|
2383
|
+
received: ctx.parsedType
|
|
2384
|
+
});
|
|
2385
|
+
return parseUtil.INVALID;
|
|
2386
|
+
}
|
|
2387
|
+
const pairs = [];
|
|
2388
|
+
const keyType = this._def.keyType;
|
|
2389
|
+
const valueType = this._def.valueType;
|
|
2390
|
+
for (const key in ctx.data) {
|
|
2391
|
+
pairs.push({
|
|
2392
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
2393
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
2394
|
+
alwaysSet: key in ctx.data
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
if (ctx.common.async) {
|
|
2398
|
+
return parseUtil.ParseStatus.mergeObjectAsync(status, pairs);
|
|
2399
|
+
} else {
|
|
2400
|
+
return parseUtil.ParseStatus.mergeObjectSync(status, pairs);
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
get element() {
|
|
2404
|
+
return this._def.valueType;
|
|
2405
|
+
}
|
|
2406
|
+
static create(first, second, third) {
|
|
2407
|
+
if (second instanceof ZodType) {
|
|
2408
|
+
return new ZodRecord({
|
|
2409
|
+
keyType: first,
|
|
2410
|
+
valueType: second,
|
|
2411
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodRecord,
|
|
2412
|
+
...processCreateParams(third)
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
return new ZodRecord({
|
|
2416
|
+
keyType: ZodString.create(),
|
|
2417
|
+
valueType: first,
|
|
2418
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodRecord,
|
|
2419
|
+
...processCreateParams(second)
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
class ZodMap extends ZodType {
|
|
2424
|
+
get keySchema() {
|
|
2425
|
+
return this._def.keyType;
|
|
2426
|
+
}
|
|
2427
|
+
get valueSchema() {
|
|
2428
|
+
return this._def.valueType;
|
|
2429
|
+
}
|
|
2430
|
+
_parse(input) {
|
|
2431
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2432
|
+
if (ctx.parsedType !== util.ZodParsedType.map) {
|
|
2433
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2434
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
2435
|
+
expected: util.ZodParsedType.map,
|
|
2436
|
+
received: ctx.parsedType
|
|
2437
|
+
});
|
|
2438
|
+
return parseUtil.INVALID;
|
|
2439
|
+
}
|
|
2440
|
+
const keyType = this._def.keyType;
|
|
2441
|
+
const valueType = this._def.valueType;
|
|
2442
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
2443
|
+
return {
|
|
2444
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
2445
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
2446
|
+
};
|
|
2447
|
+
});
|
|
2448
|
+
if (ctx.common.async) {
|
|
2449
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
2450
|
+
return Promise.resolve().then(async () => {
|
|
2451
|
+
for (const pair of pairs) {
|
|
2452
|
+
const key = await pair.key;
|
|
2453
|
+
const value = await pair.value;
|
|
2454
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
2455
|
+
return parseUtil.INVALID;
|
|
2456
|
+
}
|
|
2457
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
2458
|
+
status.dirty();
|
|
2459
|
+
}
|
|
2460
|
+
finalMap.set(key.value, value.value);
|
|
2461
|
+
}
|
|
2462
|
+
return { status: status.value, value: finalMap };
|
|
2463
|
+
});
|
|
2464
|
+
} else {
|
|
2465
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
2466
|
+
for (const pair of pairs) {
|
|
2467
|
+
const key = pair.key;
|
|
2468
|
+
const value = pair.value;
|
|
2469
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
2470
|
+
return parseUtil.INVALID;
|
|
2471
|
+
}
|
|
2472
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
2473
|
+
status.dirty();
|
|
2474
|
+
}
|
|
2475
|
+
finalMap.set(key.value, value.value);
|
|
2476
|
+
}
|
|
2477
|
+
return { status: status.value, value: finalMap };
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
2482
|
+
return new ZodMap({
|
|
2483
|
+
valueType,
|
|
2484
|
+
keyType,
|
|
2485
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodMap,
|
|
2486
|
+
...processCreateParams(params)
|
|
2487
|
+
});
|
|
2488
|
+
};
|
|
2489
|
+
class ZodSet extends ZodType {
|
|
2490
|
+
_parse(input) {
|
|
2491
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2492
|
+
if (ctx.parsedType !== util.ZodParsedType.set) {
|
|
2493
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2494
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
2495
|
+
expected: util.ZodParsedType.set,
|
|
2496
|
+
received: ctx.parsedType
|
|
2497
|
+
});
|
|
2498
|
+
return parseUtil.INVALID;
|
|
2499
|
+
}
|
|
2500
|
+
const def = this._def;
|
|
2501
|
+
if (def.minSize !== null) {
|
|
2502
|
+
if (ctx.data.size < def.minSize.value) {
|
|
2503
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2504
|
+
code: ZodError.ZodIssueCode.too_small,
|
|
2505
|
+
minimum: def.minSize.value,
|
|
2506
|
+
type: "set",
|
|
2507
|
+
inclusive: true,
|
|
2508
|
+
exact: false,
|
|
2509
|
+
message: def.minSize.message
|
|
2510
|
+
});
|
|
2511
|
+
status.dirty();
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
if (def.maxSize !== null) {
|
|
2515
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
2516
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2517
|
+
code: ZodError.ZodIssueCode.too_big,
|
|
2518
|
+
maximum: def.maxSize.value,
|
|
2519
|
+
type: "set",
|
|
2520
|
+
inclusive: true,
|
|
2521
|
+
exact: false,
|
|
2522
|
+
message: def.maxSize.message
|
|
2523
|
+
});
|
|
2524
|
+
status.dirty();
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
const valueType = this._def.valueType;
|
|
2528
|
+
function finalizeSet(elements2) {
|
|
2529
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
2530
|
+
for (const element of elements2) {
|
|
2531
|
+
if (element.status === "aborted")
|
|
2532
|
+
return parseUtil.INVALID;
|
|
2533
|
+
if (element.status === "dirty")
|
|
2534
|
+
status.dirty();
|
|
2535
|
+
parsedSet.add(element.value);
|
|
2536
|
+
}
|
|
2537
|
+
return { status: status.value, value: parsedSet };
|
|
2538
|
+
}
|
|
2539
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
2540
|
+
if (ctx.common.async) {
|
|
2541
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
2542
|
+
} else {
|
|
2543
|
+
return finalizeSet(elements);
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
min(minSize, message) {
|
|
2547
|
+
return new ZodSet({
|
|
2548
|
+
...this._def,
|
|
2549
|
+
minSize: { value: minSize, message: errorUtil.errorUtil.toString(message) }
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
max(maxSize, message) {
|
|
2553
|
+
return new ZodSet({
|
|
2554
|
+
...this._def,
|
|
2555
|
+
maxSize: { value: maxSize, message: errorUtil.errorUtil.toString(message) }
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
size(size, message) {
|
|
2559
|
+
return this.min(size, message).max(size, message);
|
|
2560
|
+
}
|
|
2561
|
+
nonempty(message) {
|
|
2562
|
+
return this.min(1, message);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
ZodSet.create = (valueType, params) => {
|
|
2566
|
+
return new ZodSet({
|
|
2567
|
+
valueType,
|
|
2568
|
+
minSize: null,
|
|
2569
|
+
maxSize: null,
|
|
2570
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodSet,
|
|
2571
|
+
...processCreateParams(params)
|
|
2572
|
+
});
|
|
2573
|
+
};
|
|
2574
|
+
class ZodLazy extends ZodType {
|
|
2575
|
+
get schema() {
|
|
2576
|
+
return this._def.getter();
|
|
2577
|
+
}
|
|
2578
|
+
_parse(input) {
|
|
2579
|
+
const { ctx } = this._processInputParams(input);
|
|
2580
|
+
const lazySchema = this._def.getter();
|
|
2581
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
ZodLazy.create = (getter, params) => {
|
|
2585
|
+
return new ZodLazy({
|
|
2586
|
+
getter,
|
|
2587
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodLazy,
|
|
2588
|
+
...processCreateParams(params)
|
|
2589
|
+
});
|
|
2590
|
+
};
|
|
2591
|
+
class ZodLiteral extends ZodType {
|
|
2592
|
+
_parse(input) {
|
|
2593
|
+
if (input.data !== this._def.value) {
|
|
2594
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2595
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2596
|
+
received: ctx.data,
|
|
2597
|
+
code: ZodError.ZodIssueCode.invalid_literal,
|
|
2598
|
+
expected: this._def.value
|
|
2599
|
+
});
|
|
2600
|
+
return parseUtil.INVALID;
|
|
2601
|
+
}
|
|
2602
|
+
return { status: "valid", value: input.data };
|
|
2603
|
+
}
|
|
2604
|
+
get value() {
|
|
2605
|
+
return this._def.value;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
ZodLiteral.create = (value, params) => {
|
|
2609
|
+
return new ZodLiteral({
|
|
2610
|
+
value,
|
|
2611
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodLiteral,
|
|
2612
|
+
...processCreateParams(params)
|
|
2613
|
+
});
|
|
2614
|
+
};
|
|
2615
|
+
function createZodEnum(values, params) {
|
|
2616
|
+
return new ZodEnum({
|
|
2617
|
+
values,
|
|
2618
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodEnum,
|
|
2619
|
+
...processCreateParams(params)
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
class ZodEnum extends ZodType {
|
|
2623
|
+
_parse(input) {
|
|
2624
|
+
if (typeof input.data !== "string") {
|
|
2625
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2626
|
+
const expectedValues = this._def.values;
|
|
2627
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2628
|
+
expected: util.util.joinValues(expectedValues),
|
|
2629
|
+
received: ctx.parsedType,
|
|
2630
|
+
code: ZodError.ZodIssueCode.invalid_type
|
|
2631
|
+
});
|
|
2632
|
+
return parseUtil.INVALID;
|
|
2633
|
+
}
|
|
2634
|
+
if (!this._cache) {
|
|
2635
|
+
this._cache = new Set(this._def.values);
|
|
2636
|
+
}
|
|
2637
|
+
if (!this._cache.has(input.data)) {
|
|
2638
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2639
|
+
const expectedValues = this._def.values;
|
|
2640
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2641
|
+
received: ctx.data,
|
|
2642
|
+
code: ZodError.ZodIssueCode.invalid_enum_value,
|
|
2643
|
+
options: expectedValues
|
|
2644
|
+
});
|
|
2645
|
+
return parseUtil.INVALID;
|
|
2646
|
+
}
|
|
2647
|
+
return parseUtil.OK(input.data);
|
|
2648
|
+
}
|
|
2649
|
+
get options() {
|
|
2650
|
+
return this._def.values;
|
|
2651
|
+
}
|
|
2652
|
+
get enum() {
|
|
2653
|
+
const enumValues = {};
|
|
2654
|
+
for (const val of this._def.values) {
|
|
2655
|
+
enumValues[val] = val;
|
|
2656
|
+
}
|
|
2657
|
+
return enumValues;
|
|
2658
|
+
}
|
|
2659
|
+
get Values() {
|
|
2660
|
+
const enumValues = {};
|
|
2661
|
+
for (const val of this._def.values) {
|
|
2662
|
+
enumValues[val] = val;
|
|
2663
|
+
}
|
|
2664
|
+
return enumValues;
|
|
2665
|
+
}
|
|
2666
|
+
get Enum() {
|
|
2667
|
+
const enumValues = {};
|
|
2668
|
+
for (const val of this._def.values) {
|
|
2669
|
+
enumValues[val] = val;
|
|
2670
|
+
}
|
|
2671
|
+
return enumValues;
|
|
2672
|
+
}
|
|
2673
|
+
extract(values, newDef = this._def) {
|
|
2674
|
+
return ZodEnum.create(values, {
|
|
2675
|
+
...this._def,
|
|
2676
|
+
...newDef
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
exclude(values, newDef = this._def) {
|
|
2680
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
2681
|
+
...this._def,
|
|
2682
|
+
...newDef
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
ZodEnum.create = createZodEnum;
|
|
2687
|
+
class ZodNativeEnum extends ZodType {
|
|
2688
|
+
_parse(input) {
|
|
2689
|
+
const nativeEnumValues = util.util.getValidEnumValues(this._def.values);
|
|
2690
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2691
|
+
if (ctx.parsedType !== util.ZodParsedType.string && ctx.parsedType !== util.ZodParsedType.number) {
|
|
2692
|
+
const expectedValues = util.util.objectValues(nativeEnumValues);
|
|
2693
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2694
|
+
expected: util.util.joinValues(expectedValues),
|
|
2695
|
+
received: ctx.parsedType,
|
|
2696
|
+
code: ZodError.ZodIssueCode.invalid_type
|
|
2697
|
+
});
|
|
2698
|
+
return parseUtil.INVALID;
|
|
2699
|
+
}
|
|
2700
|
+
if (!this._cache) {
|
|
2701
|
+
this._cache = new Set(util.util.getValidEnumValues(this._def.values));
|
|
2702
|
+
}
|
|
2703
|
+
if (!this._cache.has(input.data)) {
|
|
2704
|
+
const expectedValues = util.util.objectValues(nativeEnumValues);
|
|
2705
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2706
|
+
received: ctx.data,
|
|
2707
|
+
code: ZodError.ZodIssueCode.invalid_enum_value,
|
|
2708
|
+
options: expectedValues
|
|
2709
|
+
});
|
|
2710
|
+
return parseUtil.INVALID;
|
|
2711
|
+
}
|
|
2712
|
+
return parseUtil.OK(input.data);
|
|
2713
|
+
}
|
|
2714
|
+
get enum() {
|
|
2715
|
+
return this._def.values;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
ZodNativeEnum.create = (values, params) => {
|
|
2719
|
+
return new ZodNativeEnum({
|
|
2720
|
+
values,
|
|
2721
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
2722
|
+
...processCreateParams(params)
|
|
2723
|
+
});
|
|
2724
|
+
};
|
|
2725
|
+
class ZodPromise extends ZodType {
|
|
2726
|
+
unwrap() {
|
|
2727
|
+
return this._def.type;
|
|
2728
|
+
}
|
|
2729
|
+
_parse(input) {
|
|
2730
|
+
const { ctx } = this._processInputParams(input);
|
|
2731
|
+
if (ctx.parsedType !== util.ZodParsedType.promise && ctx.common.async === false) {
|
|
2732
|
+
parseUtil.addIssueToContext(ctx, {
|
|
2733
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
2734
|
+
expected: util.ZodParsedType.promise,
|
|
2735
|
+
received: ctx.parsedType
|
|
2736
|
+
});
|
|
2737
|
+
return parseUtil.INVALID;
|
|
2738
|
+
}
|
|
2739
|
+
const promisified = ctx.parsedType === util.ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
2740
|
+
return parseUtil.OK(promisified.then((data) => {
|
|
2741
|
+
return this._def.type.parseAsync(data, {
|
|
2742
|
+
path: ctx.path,
|
|
2743
|
+
errorMap: ctx.common.contextualErrorMap
|
|
2744
|
+
});
|
|
2745
|
+
}));
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
ZodPromise.create = (schema, params) => {
|
|
2749
|
+
return new ZodPromise({
|
|
2750
|
+
type: schema,
|
|
2751
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodPromise,
|
|
2752
|
+
...processCreateParams(params)
|
|
2753
|
+
});
|
|
2754
|
+
};
|
|
2755
|
+
class ZodEffects extends ZodType {
|
|
2756
|
+
innerType() {
|
|
2757
|
+
return this._def.schema;
|
|
2758
|
+
}
|
|
2759
|
+
sourceType() {
|
|
2760
|
+
return this._def.schema._def.typeName === exports.ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
2761
|
+
}
|
|
2762
|
+
_parse(input) {
|
|
2763
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2764
|
+
const effect = this._def.effect || null;
|
|
2765
|
+
const checkCtx = {
|
|
2766
|
+
addIssue: (arg) => {
|
|
2767
|
+
parseUtil.addIssueToContext(ctx, arg);
|
|
2768
|
+
if (arg.fatal) {
|
|
2769
|
+
status.abort();
|
|
2770
|
+
} else {
|
|
2771
|
+
status.dirty();
|
|
2772
|
+
}
|
|
2773
|
+
},
|
|
2774
|
+
get path() {
|
|
2775
|
+
return ctx.path;
|
|
2776
|
+
}
|
|
2777
|
+
};
|
|
2778
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
2779
|
+
if (effect.type === "preprocess") {
|
|
2780
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
2781
|
+
if (ctx.common.async) {
|
|
2782
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
2783
|
+
if (status.value === "aborted")
|
|
2784
|
+
return parseUtil.INVALID;
|
|
2785
|
+
const result = await this._def.schema._parseAsync({
|
|
2786
|
+
data: processed2,
|
|
2787
|
+
path: ctx.path,
|
|
2788
|
+
parent: ctx
|
|
2789
|
+
});
|
|
2790
|
+
if (result.status === "aborted")
|
|
2791
|
+
return parseUtil.INVALID;
|
|
2792
|
+
if (result.status === "dirty")
|
|
2793
|
+
return parseUtil.DIRTY(result.value);
|
|
2794
|
+
if (status.value === "dirty")
|
|
2795
|
+
return parseUtil.DIRTY(result.value);
|
|
2796
|
+
return result;
|
|
2797
|
+
});
|
|
2798
|
+
} else {
|
|
2799
|
+
if (status.value === "aborted")
|
|
2800
|
+
return parseUtil.INVALID;
|
|
2801
|
+
const result = this._def.schema._parseSync({
|
|
2802
|
+
data: processed,
|
|
2803
|
+
path: ctx.path,
|
|
2804
|
+
parent: ctx
|
|
2805
|
+
});
|
|
2806
|
+
if (result.status === "aborted")
|
|
2807
|
+
return parseUtil.INVALID;
|
|
2808
|
+
if (result.status === "dirty")
|
|
2809
|
+
return parseUtil.DIRTY(result.value);
|
|
2810
|
+
if (status.value === "dirty")
|
|
2811
|
+
return parseUtil.DIRTY(result.value);
|
|
2812
|
+
return result;
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
if (effect.type === "refinement") {
|
|
2816
|
+
const executeRefinement = (acc) => {
|
|
2817
|
+
const result = effect.refinement(acc, checkCtx);
|
|
2818
|
+
if (ctx.common.async) {
|
|
2819
|
+
return Promise.resolve(result);
|
|
2820
|
+
}
|
|
2821
|
+
if (result instanceof Promise) {
|
|
2822
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
2823
|
+
}
|
|
2824
|
+
return acc;
|
|
2825
|
+
};
|
|
2826
|
+
if (ctx.common.async === false) {
|
|
2827
|
+
const inner = this._def.schema._parseSync({
|
|
2828
|
+
data: ctx.data,
|
|
2829
|
+
path: ctx.path,
|
|
2830
|
+
parent: ctx
|
|
2831
|
+
});
|
|
2832
|
+
if (inner.status === "aborted")
|
|
2833
|
+
return parseUtil.INVALID;
|
|
2834
|
+
if (inner.status === "dirty")
|
|
2835
|
+
status.dirty();
|
|
2836
|
+
executeRefinement(inner.value);
|
|
2837
|
+
return { status: status.value, value: inner.value };
|
|
2838
|
+
} else {
|
|
2839
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
2840
|
+
if (inner.status === "aborted")
|
|
2841
|
+
return parseUtil.INVALID;
|
|
2842
|
+
if (inner.status === "dirty")
|
|
2843
|
+
status.dirty();
|
|
2844
|
+
return executeRefinement(inner.value).then(() => {
|
|
2845
|
+
return { status: status.value, value: inner.value };
|
|
2846
|
+
});
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
if (effect.type === "transform") {
|
|
2851
|
+
if (ctx.common.async === false) {
|
|
2852
|
+
const base = this._def.schema._parseSync({
|
|
2853
|
+
data: ctx.data,
|
|
2854
|
+
path: ctx.path,
|
|
2855
|
+
parent: ctx
|
|
2856
|
+
});
|
|
2857
|
+
if (!parseUtil.isValid(base))
|
|
2858
|
+
return parseUtil.INVALID;
|
|
2859
|
+
const result = effect.transform(base.value, checkCtx);
|
|
2860
|
+
if (result instanceof Promise) {
|
|
2861
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
2862
|
+
}
|
|
2863
|
+
return { status: status.value, value: result };
|
|
2864
|
+
} else {
|
|
2865
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
2866
|
+
if (!parseUtil.isValid(base))
|
|
2867
|
+
return parseUtil.INVALID;
|
|
2868
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
2869
|
+
status: status.value,
|
|
2870
|
+
value: result
|
|
2871
|
+
}));
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
util.util.assertNever(effect);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
2879
|
+
return new ZodEffects({
|
|
2880
|
+
schema,
|
|
2881
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
|
|
2882
|
+
effect,
|
|
2883
|
+
...processCreateParams(params)
|
|
2884
|
+
});
|
|
2885
|
+
};
|
|
2886
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
2887
|
+
return new ZodEffects({
|
|
2888
|
+
schema,
|
|
2889
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
2890
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodEffects,
|
|
2891
|
+
...processCreateParams(params)
|
|
2892
|
+
});
|
|
2893
|
+
};
|
|
2894
|
+
class ZodOptional extends ZodType {
|
|
2895
|
+
_parse(input) {
|
|
2896
|
+
const parsedType = this._getType(input);
|
|
2897
|
+
if (parsedType === util.ZodParsedType.undefined) {
|
|
2898
|
+
return parseUtil.OK(void 0);
|
|
2899
|
+
}
|
|
2900
|
+
return this._def.innerType._parse(input);
|
|
2901
|
+
}
|
|
2902
|
+
unwrap() {
|
|
2903
|
+
return this._def.innerType;
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
ZodOptional.create = (type, params) => {
|
|
2907
|
+
return new ZodOptional({
|
|
2908
|
+
innerType: type,
|
|
2909
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodOptional,
|
|
2910
|
+
...processCreateParams(params)
|
|
2911
|
+
});
|
|
2912
|
+
};
|
|
2913
|
+
class ZodNullable extends ZodType {
|
|
2914
|
+
_parse(input) {
|
|
2915
|
+
const parsedType = this._getType(input);
|
|
2916
|
+
if (parsedType === util.ZodParsedType.null) {
|
|
2917
|
+
return parseUtil.OK(null);
|
|
2918
|
+
}
|
|
2919
|
+
return this._def.innerType._parse(input);
|
|
2920
|
+
}
|
|
2921
|
+
unwrap() {
|
|
2922
|
+
return this._def.innerType;
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
ZodNullable.create = (type, params) => {
|
|
2926
|
+
return new ZodNullable({
|
|
2927
|
+
innerType: type,
|
|
2928
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNullable,
|
|
2929
|
+
...processCreateParams(params)
|
|
2930
|
+
});
|
|
2931
|
+
};
|
|
2932
|
+
class ZodDefault extends ZodType {
|
|
2933
|
+
_parse(input) {
|
|
2934
|
+
const { ctx } = this._processInputParams(input);
|
|
2935
|
+
let data = ctx.data;
|
|
2936
|
+
if (ctx.parsedType === util.ZodParsedType.undefined) {
|
|
2937
|
+
data = this._def.defaultValue();
|
|
2938
|
+
}
|
|
2939
|
+
return this._def.innerType._parse({
|
|
2940
|
+
data,
|
|
2941
|
+
path: ctx.path,
|
|
2942
|
+
parent: ctx
|
|
2943
|
+
});
|
|
2944
|
+
}
|
|
2945
|
+
removeDefault() {
|
|
2946
|
+
return this._def.innerType;
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
ZodDefault.create = (type, params) => {
|
|
2950
|
+
return new ZodDefault({
|
|
2951
|
+
innerType: type,
|
|
2952
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodDefault,
|
|
2953
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
2954
|
+
...processCreateParams(params)
|
|
2955
|
+
});
|
|
2956
|
+
};
|
|
2957
|
+
class ZodCatch extends ZodType {
|
|
2958
|
+
_parse(input) {
|
|
2959
|
+
const { ctx } = this._processInputParams(input);
|
|
2960
|
+
const newCtx = {
|
|
2961
|
+
...ctx,
|
|
2962
|
+
common: {
|
|
2963
|
+
...ctx.common,
|
|
2964
|
+
issues: []
|
|
2965
|
+
}
|
|
2966
|
+
};
|
|
2967
|
+
const result = this._def.innerType._parse({
|
|
2968
|
+
data: newCtx.data,
|
|
2969
|
+
path: newCtx.path,
|
|
2970
|
+
parent: {
|
|
2971
|
+
...newCtx
|
|
2972
|
+
}
|
|
2973
|
+
});
|
|
2974
|
+
if (parseUtil.isAsync(result)) {
|
|
2975
|
+
return result.then((result2) => {
|
|
2976
|
+
return {
|
|
2977
|
+
status: "valid",
|
|
2978
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
2979
|
+
get error() {
|
|
2980
|
+
return new ZodError.ZodError(newCtx.common.issues);
|
|
2981
|
+
},
|
|
2982
|
+
input: newCtx.data
|
|
2983
|
+
})
|
|
2984
|
+
};
|
|
2985
|
+
});
|
|
2986
|
+
} else {
|
|
2987
|
+
return {
|
|
2988
|
+
status: "valid",
|
|
2989
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
2990
|
+
get error() {
|
|
2991
|
+
return new ZodError.ZodError(newCtx.common.issues);
|
|
2992
|
+
},
|
|
2993
|
+
input: newCtx.data
|
|
2994
|
+
})
|
|
2995
|
+
};
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
removeCatch() {
|
|
2999
|
+
return this._def.innerType;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
ZodCatch.create = (type, params) => {
|
|
3003
|
+
return new ZodCatch({
|
|
3004
|
+
innerType: type,
|
|
3005
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodCatch,
|
|
3006
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3007
|
+
...processCreateParams(params)
|
|
3008
|
+
});
|
|
3009
|
+
};
|
|
3010
|
+
class ZodNaN extends ZodType {
|
|
3011
|
+
_parse(input) {
|
|
3012
|
+
const parsedType = this._getType(input);
|
|
3013
|
+
if (parsedType !== util.ZodParsedType.nan) {
|
|
3014
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3015
|
+
parseUtil.addIssueToContext(ctx, {
|
|
3016
|
+
code: ZodError.ZodIssueCode.invalid_type,
|
|
3017
|
+
expected: util.ZodParsedType.nan,
|
|
3018
|
+
received: ctx.parsedType
|
|
3019
|
+
});
|
|
3020
|
+
return parseUtil.INVALID;
|
|
3021
|
+
}
|
|
3022
|
+
return { status: "valid", value: input.data };
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
ZodNaN.create = (params) => {
|
|
3026
|
+
return new ZodNaN({
|
|
3027
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodNaN,
|
|
3028
|
+
...processCreateParams(params)
|
|
3029
|
+
});
|
|
3030
|
+
};
|
|
3031
|
+
class ZodBranded extends ZodType {
|
|
3032
|
+
_parse(input) {
|
|
3033
|
+
const { ctx } = this._processInputParams(input);
|
|
3034
|
+
const data = ctx.data;
|
|
3035
|
+
return this._def.type._parse({
|
|
3036
|
+
data,
|
|
3037
|
+
path: ctx.path,
|
|
3038
|
+
parent: ctx
|
|
3039
|
+
});
|
|
3040
|
+
}
|
|
3041
|
+
unwrap() {
|
|
3042
|
+
return this._def.type;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
class ZodPipeline extends ZodType {
|
|
3046
|
+
_parse(input) {
|
|
3047
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3048
|
+
if (ctx.common.async) {
|
|
3049
|
+
const handleAsync = async () => {
|
|
3050
|
+
const inResult = await this._def.in._parseAsync({
|
|
3051
|
+
data: ctx.data,
|
|
3052
|
+
path: ctx.path,
|
|
3053
|
+
parent: ctx
|
|
3054
|
+
});
|
|
3055
|
+
if (inResult.status === "aborted")
|
|
3056
|
+
return parseUtil.INVALID;
|
|
3057
|
+
if (inResult.status === "dirty") {
|
|
3058
|
+
status.dirty();
|
|
3059
|
+
return parseUtil.DIRTY(inResult.value);
|
|
3060
|
+
} else {
|
|
3061
|
+
return this._def.out._parseAsync({
|
|
3062
|
+
data: inResult.value,
|
|
3063
|
+
path: ctx.path,
|
|
3064
|
+
parent: ctx
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
return handleAsync();
|
|
3069
|
+
} else {
|
|
3070
|
+
const inResult = this._def.in._parseSync({
|
|
3071
|
+
data: ctx.data,
|
|
3072
|
+
path: ctx.path,
|
|
3073
|
+
parent: ctx
|
|
3074
|
+
});
|
|
3075
|
+
if (inResult.status === "aborted")
|
|
3076
|
+
return parseUtil.INVALID;
|
|
3077
|
+
if (inResult.status === "dirty") {
|
|
3078
|
+
status.dirty();
|
|
3079
|
+
return {
|
|
3080
|
+
status: "dirty",
|
|
3081
|
+
value: inResult.value
|
|
3082
|
+
};
|
|
3083
|
+
} else {
|
|
3084
|
+
return this._def.out._parseSync({
|
|
3085
|
+
data: inResult.value,
|
|
3086
|
+
path: ctx.path,
|
|
3087
|
+
parent: ctx
|
|
3088
|
+
});
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
static create(a, b) {
|
|
3093
|
+
return new ZodPipeline({
|
|
3094
|
+
in: a,
|
|
3095
|
+
out: b,
|
|
3096
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodPipeline
|
|
3097
|
+
});
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
class ZodReadonly extends ZodType {
|
|
3101
|
+
_parse(input) {
|
|
3102
|
+
const result = this._def.innerType._parse(input);
|
|
3103
|
+
const freeze = (data) => {
|
|
3104
|
+
if (parseUtil.isValid(data)) {
|
|
3105
|
+
data.value = Object.freeze(data.value);
|
|
3106
|
+
}
|
|
3107
|
+
return data;
|
|
3108
|
+
};
|
|
3109
|
+
return parseUtil.isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3110
|
+
}
|
|
3111
|
+
unwrap() {
|
|
3112
|
+
return this._def.innerType;
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
ZodReadonly.create = (type, params) => {
|
|
3116
|
+
return new ZodReadonly({
|
|
3117
|
+
innerType: type,
|
|
3118
|
+
typeName: exports.ZodFirstPartyTypeKind.ZodReadonly,
|
|
3119
|
+
...processCreateParams(params)
|
|
3120
|
+
});
|
|
3121
|
+
};
|
|
3122
|
+
exports.ZodFirstPartyTypeKind = void 0;
|
|
3123
|
+
(function(ZodFirstPartyTypeKind) {
|
|
3124
|
+
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
3125
|
+
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
3126
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
3127
|
+
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
3128
|
+
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
3129
|
+
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
3130
|
+
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
3131
|
+
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
3132
|
+
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
3133
|
+
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
3134
|
+
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
3135
|
+
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
3136
|
+
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
3137
|
+
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
3138
|
+
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
3139
|
+
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
3140
|
+
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3141
|
+
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
3142
|
+
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
3143
|
+
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
3144
|
+
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
3145
|
+
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
3146
|
+
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
3147
|
+
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
3148
|
+
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
3149
|
+
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
3150
|
+
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
3151
|
+
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3152
|
+
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
3153
|
+
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
3154
|
+
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3155
|
+
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
3156
|
+
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
3157
|
+
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
3158
|
+
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
3159
|
+
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
3160
|
+
})(exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
|
|
3161
|
+
const stringType = ZodString.create;
|
|
3162
|
+
const numberType = ZodNumber.create;
|
|
3163
|
+
const booleanType = ZodBoolean.create;
|
|
3164
|
+
const anyType = ZodAny.create;
|
|
3165
|
+
const unknownType = ZodUnknown.create;
|
|
3166
|
+
ZodNever.create;
|
|
3167
|
+
const arrayType = ZodArray.create;
|
|
3168
|
+
const objectType = ZodObject.create;
|
|
3169
|
+
const unionType = ZodUnion.create;
|
|
3170
|
+
ZodIntersection.create;
|
|
3171
|
+
const tupleType = ZodTuple.create;
|
|
3172
|
+
const recordType = ZodRecord.create;
|
|
3173
|
+
const literalType = ZodLiteral.create;
|
|
3174
|
+
const enumType = ZodEnum.create;
|
|
3175
|
+
ZodPromise.create;
|
|
3176
|
+
ZodOptional.create;
|
|
3177
|
+
ZodNullable.create;
|
|
3178
|
+
exports.Schema = ZodType;
|
|
3179
|
+
exports.ZodAny = ZodAny;
|
|
3180
|
+
exports.ZodArray = ZodArray;
|
|
3181
|
+
exports.ZodBigInt = ZodBigInt;
|
|
3182
|
+
exports.ZodBoolean = ZodBoolean;
|
|
3183
|
+
exports.ZodBranded = ZodBranded;
|
|
3184
|
+
exports.ZodCatch = ZodCatch;
|
|
3185
|
+
exports.ZodDate = ZodDate;
|
|
3186
|
+
exports.ZodDefault = ZodDefault;
|
|
3187
|
+
exports.ZodEffects = ZodEffects;
|
|
3188
|
+
exports.ZodEnum = ZodEnum;
|
|
3189
|
+
exports.ZodIntersection = ZodIntersection;
|
|
3190
|
+
exports.ZodLazy = ZodLazy;
|
|
3191
|
+
exports.ZodLiteral = ZodLiteral;
|
|
3192
|
+
exports.ZodMap = ZodMap;
|
|
3193
|
+
exports.ZodNaN = ZodNaN;
|
|
3194
|
+
exports.ZodNativeEnum = ZodNativeEnum;
|
|
3195
|
+
exports.ZodNever = ZodNever;
|
|
3196
|
+
exports.ZodNull = ZodNull;
|
|
3197
|
+
exports.ZodNullable = ZodNullable;
|
|
3198
|
+
exports.ZodNumber = ZodNumber;
|
|
3199
|
+
exports.ZodObject = ZodObject;
|
|
3200
|
+
exports.ZodOptional = ZodOptional;
|
|
3201
|
+
exports.ZodPipeline = ZodPipeline;
|
|
3202
|
+
exports.ZodPromise = ZodPromise;
|
|
3203
|
+
exports.ZodReadonly = ZodReadonly;
|
|
3204
|
+
exports.ZodRecord = ZodRecord;
|
|
3205
|
+
exports.ZodSchema = ZodType;
|
|
3206
|
+
exports.ZodSet = ZodSet;
|
|
3207
|
+
exports.ZodString = ZodString;
|
|
3208
|
+
exports.ZodSymbol = ZodSymbol;
|
|
3209
|
+
exports.ZodTransformer = ZodEffects;
|
|
3210
|
+
exports.ZodTuple = ZodTuple;
|
|
3211
|
+
exports.ZodType = ZodType;
|
|
3212
|
+
exports.ZodUndefined = ZodUndefined;
|
|
3213
|
+
exports.ZodUnion = ZodUnion;
|
|
3214
|
+
exports.ZodUnknown = ZodUnknown;
|
|
3215
|
+
exports.ZodVoid = ZodVoid;
|
|
3216
|
+
exports.any = anyType;
|
|
3217
|
+
exports.array = arrayType;
|
|
3218
|
+
exports.boolean = booleanType;
|
|
3219
|
+
exports.datetimeRegex = datetimeRegex;
|
|
3220
|
+
exports.enum = enumType;
|
|
3221
|
+
exports.literal = literalType;
|
|
3222
|
+
exports.number = numberType;
|
|
3223
|
+
exports.object = objectType;
|
|
3224
|
+
exports.record = recordType;
|
|
3225
|
+
exports.string = stringType;
|
|
3226
|
+
exports.tuple = tupleType;
|
|
3227
|
+
exports.union = unionType;
|
|
3228
|
+
exports.unknown = unknownType;
|
|
3229
|
+
//# sourceMappingURL=types.cjs.map
|