@claude-sync/cli 0.1.1 → 0.1.3

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