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