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