@stdout-design/cli 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +3506 -4
  2. package/package.json +11 -7
package/dist/index.mjs CHANGED
@@ -1,18 +1,3520 @@
1
1
  #!/usr/bin/env bun
2
+ import { createRequire } from "node:module";
2
3
  import { Command } from "commander";
4
+ import { AppError, ErrorCode, importTemplateForBatch, loadConfig, openCache, runBatch, zodToJsonSchemaShape } from "@stdout-design/core";
5
+ import path from "node:path";
6
+ import { execSync, spawnSync } from "node:child_process";
7
+ import { existsSync } from "node:fs";
8
+ import { resolveCommand } from "package-manager-detector/commands";
9
+ import { detect, getUserAgent } from "package-manager-detector/detect";
10
+ import { cp, mkdir, writeFile } from "node:fs/promises";
3
11
  //#region src/lib/display.ts
4
- const formatError = (error) => {
12
+ const formatBytes = (bytes) => {
13
+ if (bytes < 1024) return `${bytes} B`;
14
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
15
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
16
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
17
+ };
18
+ const formatCacheStats = (stats) => {
19
+ return [
20
+ "",
21
+ "Cache Statistics",
22
+ "━━━━━━━━━━━━━━━━",
23
+ ` Location: ${stats.cacheDir}`,
24
+ ` Compiled: ${stats.compiled.entries} entries (in-memory compile cache)`,
25
+ ` Pixel: ${stats.pixels.entries} entries`,
26
+ ` Disk used: ${formatBytes(stats.pixels.sizeBytes)}`,
27
+ ` Disk limit: ${formatBytes(stats.pixels.maxSizeBytes)}`,
28
+ ""
29
+ ].join("\n");
30
+ };
31
+ const formatManifestSummary = (manifest) => {
32
+ const { completedCount, totalCount, succeeded, failed } = manifest;
33
+ const cacheHits = succeeded.filter((s) => s.cacheHit).length;
34
+ const lines = [
35
+ "",
36
+ "Batch Render Complete",
37
+ "━━━━━━━━━━━━━━━━━━━━",
38
+ ` Status: ${manifest.status}`,
39
+ ` Total: ${totalCount}`,
40
+ ` Completed: ${completedCount}`,
41
+ ` Cache: ${cacheHits} hits, ${succeeded.length - cacheHits} renders`,
42
+ ` Failed: ${failed.length}`,
43
+ ""
44
+ ];
45
+ if (succeeded.length > 0 && succeeded.length <= 10) {
46
+ lines.push("Output files:");
47
+ for (const entry of succeeded) lines.push(` ${entry.outputPath}`);
48
+ lines.push("");
49
+ }
50
+ if (failed.length > 0) {
51
+ lines.push("Failures:");
52
+ for (const f of failed) lines.push(` Row ${f.rowIndex}, ${f.locale}, ${f.preset}: ${f.error}`);
53
+ lines.push("");
54
+ }
55
+ return lines.join("\n");
56
+ };
57
+ const formatError$1 = (error) => {
5
58
  if (error instanceof Error) return `Error: ${error.message}`;
6
59
  return `Error: ${String(error)}`;
7
60
  };
61
+ const formatCacheCleanResult = (freedBytes) => `Cache cleared. Freed ${formatBytes(freedBytes)}.`;
62
+ //#endregion
63
+ //#region src/commands/cache.ts
64
+ const cacheStats = async (rootDir, options) => {
65
+ const cache = await openCache(rootDir ?? process.cwd());
66
+ const stats = await cache.stats();
67
+ cache.close();
68
+ if (options.json) console.log(JSON.stringify(stats, null, 2));
69
+ else console.log(formatCacheStats(stats));
70
+ };
71
+ const cacheClean = async (rootDir, options) => {
72
+ const cache = await openCache(rootDir ?? process.cwd());
73
+ const result = await cache.clean();
74
+ cache.close();
75
+ if (options.json) console.log(JSON.stringify(result));
76
+ else console.log(formatCacheCleanResult(result.freedBytes));
77
+ };
78
+ //#endregion
79
+ //#region src/commands/dev.ts
80
+ const findWebUiDist = () => {
81
+ try {
82
+ const pkgJsonPath = createRequire(import.meta.url).resolve("@stdout-design/web-ui/package.json");
83
+ const pkgDir = path.dirname(pkgJsonPath);
84
+ return path.join(pkgDir, "dist");
85
+ } catch {}
86
+ };
87
+ const dev = async (rootDir, options) => {
88
+ const { startStandaloneServer } = await import("@stdout-design/dev-server").catch(() => {
89
+ throw new Error([
90
+ "studio dev requires a scaffolded project with @stdout-design/dev-server installed.",
91
+ "Run `studio init` to create one, or install it manually:",
92
+ "",
93
+ " bun add @stdout-design/dev-server",
94
+ "",
95
+ "See https://stdout.design/docs for more information."
96
+ ].join("\n"));
97
+ });
98
+ const resolvedRoot = rootDir ?? process.cwd();
99
+ const port = Number(options.port ?? "3000");
100
+ const webUiDist = findWebUiDist();
101
+ console.log(`Starting studio dev server for ${resolvedRoot}...`);
102
+ await startStandaloneServer({
103
+ port,
104
+ rootDir: resolvedRoot,
105
+ webUiDist
106
+ });
107
+ };
108
+ //#endregion
109
+ //#region src/commands/init/git.ts
110
+ const isInsideGitRepo = (dir) => {
111
+ let current = path.resolve(dir);
112
+ for (;;) {
113
+ if (existsSync(path.join(current, ".git"))) return true;
114
+ const parent = path.dirname(current);
115
+ if (parent === current) break;
116
+ current = parent;
117
+ }
118
+ return false;
119
+ };
120
+ const tryGitInit = (dir) => {
121
+ try {
122
+ execSync("git --version", { stdio: "ignore" });
123
+ } catch {
124
+ return false;
125
+ }
126
+ if (existsSync(path.join(dir, ".git")) || isInsideGitRepo(path.dirname(dir))) return false;
127
+ try {
128
+ execSync("git init", {
129
+ cwd: dir,
130
+ stdio: "ignore"
131
+ });
132
+ execSync("git checkout -b main", {
133
+ cwd: dir,
134
+ stdio: "ignore"
135
+ });
136
+ execSync("git add .", {
137
+ cwd: dir,
138
+ stdio: "ignore"
139
+ });
140
+ execSync("git commit -m \"Initial commit from stdout-design\"", {
141
+ cwd: dir,
142
+ stdio: "ignore"
143
+ });
144
+ return true;
145
+ } catch {
146
+ if (existsSync(path.join(dir, ".git"))) try {
147
+ execSync("rm -rf .git", {
148
+ cwd: dir,
149
+ stdio: "ignore"
150
+ });
151
+ } catch {}
152
+ return false;
153
+ }
154
+ };
155
+ //#endregion
156
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/core.js
157
+ var _a$1;
158
+ function $constructor(name, initializer, params) {
159
+ function init(inst, def) {
160
+ if (!inst._zod) Object.defineProperty(inst, "_zod", {
161
+ value: {
162
+ def,
163
+ constr: _,
164
+ traits: /* @__PURE__ */ new Set()
165
+ },
166
+ enumerable: false
167
+ });
168
+ if (inst._zod.traits.has(name)) return;
169
+ inst._zod.traits.add(name);
170
+ initializer(inst, def);
171
+ const proto = _.prototype;
172
+ const keys = Object.keys(proto);
173
+ for (let i = 0; i < keys.length; i++) {
174
+ const k = keys[i];
175
+ if (!(k in inst)) inst[k] = proto[k].bind(inst);
176
+ }
177
+ }
178
+ const Parent = params?.Parent ?? Object;
179
+ class Definition extends Parent {}
180
+ Object.defineProperty(Definition, "name", { value: name });
181
+ function _(def) {
182
+ var _a;
183
+ const inst = params?.Parent ? new Definition() : this;
184
+ init(inst, def);
185
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
186
+ for (const fn of inst._zod.deferred) fn();
187
+ return inst;
188
+ }
189
+ Object.defineProperty(_, "init", { value: init });
190
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
191
+ if (params?.Parent && inst instanceof params.Parent) return true;
192
+ return inst?._zod?.traits?.has(name);
193
+ } });
194
+ Object.defineProperty(_, "name", { value: name });
195
+ return _;
196
+ }
197
+ var $ZodAsyncError = class extends Error {
198
+ constructor() {
199
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
200
+ }
201
+ };
202
+ var $ZodEncodeError = class extends Error {
203
+ constructor(name) {
204
+ super(`Encountered unidirectional transform during encode: ${name}`);
205
+ this.name = "ZodEncodeError";
206
+ }
207
+ };
208
+ (_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
209
+ const globalConfig = globalThis.__zod_globalConfig;
210
+ function config(newConfig) {
211
+ if (newConfig) Object.assign(globalConfig, newConfig);
212
+ return globalConfig;
213
+ }
214
+ //#endregion
215
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/util.js
216
+ function jsonStringifyReplacer(_, value) {
217
+ if (typeof value === "bigint") return value.toString();
218
+ return value;
219
+ }
220
+ function nullish(input) {
221
+ return input === null || input === void 0;
222
+ }
223
+ function cleanRegex(source) {
224
+ const start = source.startsWith("^") ? 1 : 0;
225
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
226
+ return source.slice(start, end);
227
+ }
228
+ const EVALUATING = /* @__PURE__*/ Symbol("evaluating");
229
+ function defineLazy(object, key, getter) {
230
+ let value = void 0;
231
+ Object.defineProperty(object, key, {
232
+ get() {
233
+ if (value === EVALUATING) return;
234
+ if (value === void 0) {
235
+ value = EVALUATING;
236
+ value = getter();
237
+ }
238
+ return value;
239
+ },
240
+ set(v) {
241
+ Object.defineProperty(object, key, { value: v });
242
+ },
243
+ configurable: true
244
+ });
245
+ }
246
+ function mergeDefs(...defs) {
247
+ const mergedDescriptors = {};
248
+ for (const def of defs) {
249
+ const descriptors = Object.getOwnPropertyDescriptors(def);
250
+ Object.assign(mergedDescriptors, descriptors);
251
+ }
252
+ return Object.defineProperties({}, mergedDescriptors);
253
+ }
254
+ function slugify(input) {
255
+ return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
256
+ }
257
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
258
+ function isObject(data) {
259
+ return typeof data === "object" && data !== null && !Array.isArray(data);
260
+ }
261
+ function isPlainObject(o) {
262
+ if (isObject(o) === false) return false;
263
+ const ctor = o.constructor;
264
+ if (ctor === void 0) return true;
265
+ if (typeof ctor !== "function") return true;
266
+ const prot = ctor.prototype;
267
+ if (isObject(prot) === false) return false;
268
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
269
+ return true;
270
+ }
271
+ function shallowClone(o) {
272
+ if (isPlainObject(o)) return { ...o };
273
+ if (Array.isArray(o)) return [...o];
274
+ if (o instanceof Map) return new Map(o);
275
+ if (o instanceof Set) return new Set(o);
276
+ return o;
277
+ }
278
+ function escapeRegex(str) {
279
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
280
+ }
281
+ function clone(inst, def, params) {
282
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
283
+ if (!def || params?.parent) cl._zod.parent = inst;
284
+ return cl;
285
+ }
286
+ function normalizeParams(_params) {
287
+ const params = _params;
288
+ if (!params) return {};
289
+ if (typeof params === "string") return { error: () => params };
290
+ if (params?.message !== void 0) {
291
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
292
+ params.error = params.message;
293
+ }
294
+ delete params.message;
295
+ if (typeof params.error === "string") return {
296
+ ...params,
297
+ error: () => params.error
298
+ };
299
+ return params;
300
+ }
301
+ Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, -Number.MAX_VALUE, Number.MAX_VALUE;
302
+ function aborted(x, startIndex = 0) {
303
+ if (x.aborted === true) return true;
304
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
305
+ return false;
306
+ }
307
+ function explicitlyAborted(x, startIndex = 0) {
308
+ if (x.aborted === true) return true;
309
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue === false) return true;
310
+ return false;
311
+ }
312
+ function prefixIssues(path, issues) {
313
+ return issues.map((iss) => {
314
+ var _a;
315
+ (_a = iss).path ?? (_a.path = []);
316
+ iss.path.unshift(path);
317
+ return iss;
318
+ });
319
+ }
320
+ function unwrapMessage(message) {
321
+ return typeof message === "string" ? message : message?.message;
322
+ }
323
+ function finalizeIssue(iss, ctx, config) {
324
+ const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
325
+ const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
326
+ rest.path ?? (rest.path = []);
327
+ rest.message = message;
328
+ if (ctx?.reportInput) rest.input = _input;
329
+ return rest;
330
+ }
331
+ function getLengthableOrigin(input) {
332
+ if (Array.isArray(input)) return "array";
333
+ if (typeof input === "string") return "string";
334
+ return "unknown";
335
+ }
336
+ function issue(...args) {
337
+ const [iss, input, inst] = args;
338
+ if (typeof iss === "string") return {
339
+ message: iss,
340
+ code: "custom",
341
+ input,
342
+ inst
343
+ };
344
+ return { ...iss };
345
+ }
346
+ //#endregion
347
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/errors.js
348
+ const initializer$1 = (inst, def) => {
349
+ inst.name = "$ZodError";
350
+ Object.defineProperty(inst, "_zod", {
351
+ value: inst._zod,
352
+ enumerable: false
353
+ });
354
+ Object.defineProperty(inst, "issues", {
355
+ value: def,
356
+ enumerable: false
357
+ });
358
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
359
+ Object.defineProperty(inst, "toString", {
360
+ value: () => inst.message,
361
+ enumerable: false
362
+ });
363
+ };
364
+ const $ZodError = $constructor("$ZodError", initializer$1);
365
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
366
+ function flattenError(error, mapper = (issue) => issue.message) {
367
+ const fieldErrors = {};
368
+ const formErrors = [];
369
+ for (const sub of error.issues) if (sub.path.length > 0) {
370
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
371
+ fieldErrors[sub.path[0]].push(mapper(sub));
372
+ } else formErrors.push(mapper(sub));
373
+ return {
374
+ formErrors,
375
+ fieldErrors
376
+ };
377
+ }
378
+ function formatError(error, mapper = (issue) => issue.message) {
379
+ const fieldErrors = { _errors: [] };
380
+ const processError = (error, path = []) => {
381
+ for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
382
+ else if (issue.code === "invalid_key") processError({ issues: issue.issues }, [...path, ...issue.path]);
383
+ else if (issue.code === "invalid_element") processError({ issues: issue.issues }, [...path, ...issue.path]);
384
+ else {
385
+ const fullpath = [...path, ...issue.path];
386
+ if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
387
+ else {
388
+ let curr = fieldErrors;
389
+ let i = 0;
390
+ while (i < fullpath.length) {
391
+ const el = fullpath[i];
392
+ if (!(i === fullpath.length - 1)) curr[el] = curr[el] || { _errors: [] };
393
+ else {
394
+ curr[el] = curr[el] || { _errors: [] };
395
+ curr[el]._errors.push(mapper(issue));
396
+ }
397
+ curr = curr[el];
398
+ i++;
399
+ }
400
+ }
401
+ }
402
+ };
403
+ processError(error);
404
+ return fieldErrors;
405
+ }
406
+ //#endregion
407
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/parse.js
408
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
409
+ const ctx = _ctx ? {
410
+ ..._ctx,
411
+ async: false
412
+ } : { async: false };
413
+ const result = schema._zod.run({
414
+ value,
415
+ issues: []
416
+ }, ctx);
417
+ if (result instanceof Promise) throw new $ZodAsyncError();
418
+ if (result.issues.length) {
419
+ const e = new ((_params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
420
+ captureStackTrace(e, _params?.callee);
421
+ throw e;
422
+ }
423
+ return result.value;
424
+ };
425
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
426
+ const ctx = _ctx ? {
427
+ ..._ctx,
428
+ async: true
429
+ } : { async: true };
430
+ let result = schema._zod.run({
431
+ value,
432
+ issues: []
433
+ }, ctx);
434
+ if (result instanceof Promise) result = await result;
435
+ if (result.issues.length) {
436
+ const e = new ((params?.Err) ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
437
+ captureStackTrace(e, params?.callee);
438
+ throw e;
439
+ }
440
+ return result.value;
441
+ };
442
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
443
+ const ctx = _ctx ? {
444
+ ..._ctx,
445
+ async: false
446
+ } : { async: false };
447
+ const result = schema._zod.run({
448
+ value,
449
+ issues: []
450
+ }, ctx);
451
+ if (result instanceof Promise) throw new $ZodAsyncError();
452
+ return result.issues.length ? {
453
+ success: false,
454
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
455
+ } : {
456
+ success: true,
457
+ data: result.value
458
+ };
459
+ };
460
+ const safeParse$1 = /* @__PURE__*/ _safeParse($ZodRealError);
461
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
462
+ const ctx = _ctx ? {
463
+ ..._ctx,
464
+ async: true
465
+ } : { async: true };
466
+ let result = schema._zod.run({
467
+ value,
468
+ issues: []
469
+ }, ctx);
470
+ if (result instanceof Promise) result = await result;
471
+ return result.issues.length ? {
472
+ success: false,
473
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
474
+ } : {
475
+ success: true,
476
+ data: result.value
477
+ };
478
+ };
479
+ const safeParseAsync$1 = /* @__PURE__*/ _safeParseAsync($ZodRealError);
480
+ const _encode = (_Err) => (schema, value, _ctx) => {
481
+ const ctx = _ctx ? {
482
+ ..._ctx,
483
+ direction: "backward"
484
+ } : { direction: "backward" };
485
+ return _parse(_Err)(schema, value, ctx);
486
+ };
487
+ const _decode = (_Err) => (schema, value, _ctx) => {
488
+ return _parse(_Err)(schema, value, _ctx);
489
+ };
490
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
491
+ const ctx = _ctx ? {
492
+ ..._ctx,
493
+ direction: "backward"
494
+ } : { direction: "backward" };
495
+ return _parseAsync(_Err)(schema, value, ctx);
496
+ };
497
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
498
+ return _parseAsync(_Err)(schema, value, _ctx);
499
+ };
500
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
501
+ const ctx = _ctx ? {
502
+ ..._ctx,
503
+ direction: "backward"
504
+ } : { direction: "backward" };
505
+ return _safeParse(_Err)(schema, value, ctx);
506
+ };
507
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
508
+ return _safeParse(_Err)(schema, value, _ctx);
509
+ };
510
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
511
+ const ctx = _ctx ? {
512
+ ..._ctx,
513
+ direction: "backward"
514
+ } : { direction: "backward" };
515
+ return _safeParseAsync(_Err)(schema, value, ctx);
516
+ };
517
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
518
+ return _safeParseAsync(_Err)(schema, value, _ctx);
519
+ };
520
+ //#endregion
521
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/regexes.js
522
+ /**
523
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
524
+ * (timestamps embedded in the id). Use {@link cuid2} instead.
525
+ * See https://github.com/paralleldrive/cuid.
526
+ */
527
+ const cuid = /^[cC][0-9a-z]{6,}$/;
528
+ const cuid2 = /^[0-9a-z]+$/;
529
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
530
+ const xid = /^[0-9a-vA-V]{20}$/;
531
+ const ksuid = /^[A-Za-z0-9]{27}$/;
532
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
533
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
534
+ const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
535
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
536
+ const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
537
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
538
+ *
539
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
540
+ const uuid = (version) => {
541
+ if (!version) return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
542
+ return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
543
+ };
544
+ /** Practical email validation */
545
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
546
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
547
+ function emoji() {
548
+ return new RegExp(_emoji$1, "u");
549
+ }
550
+ const ipv4 = /^(?:(?: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])$/;
551
+ const ipv6 = /^(([0-9a-fA-F]{1,4}:){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}|:))$/;
552
+ const cidrv4 = /^((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])\/([0-9]|[1-2][0-9]|3[0-2])$/;
553
+ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
554
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
555
+ const base64url = /^[A-Za-z0-9_-]*$/;
556
+ const httpProtocol = /^https?$/;
557
+ const e164 = /^\+[1-9]\d{6,14}$/;
558
+ const dateSource = `(?:(?:\\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])))`;
559
+ const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
560
+ function timeSource(args) {
561
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
562
+ return typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
563
+ }
564
+ function time$1(args) {
565
+ return new RegExp(`^${timeSource(args)}$`);
566
+ }
567
+ function datetime$1(args) {
568
+ const time = timeSource({ precision: args.precision });
569
+ const opts = ["Z"];
570
+ if (args.local) opts.push("");
571
+ if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
572
+ const timeRegex = `${time}(?:${opts.join("|")})`;
573
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
574
+ }
575
+ const string$1 = (params) => {
576
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
577
+ return new RegExp(`^${regex}$`);
578
+ };
579
+ const lowercase = /^[^A-Z]*$/;
580
+ const uppercase = /^[^a-z]*$/;
581
+ //#endregion
582
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/checks.js
583
+ const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
584
+ var _a;
585
+ inst._zod ?? (inst._zod = {});
586
+ inst._zod.def = def;
587
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
588
+ });
589
+ const $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst, def) => {
590
+ var _a;
591
+ $ZodCheck.init(inst, def);
592
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
593
+ const val = payload.value;
594
+ return !nullish(val) && val.length !== void 0;
595
+ });
596
+ inst._zod.onattach.push((inst) => {
597
+ const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
598
+ if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
599
+ });
600
+ inst._zod.check = (payload) => {
601
+ const input = payload.value;
602
+ if (input.length <= def.maximum) return;
603
+ const origin = getLengthableOrigin(input);
604
+ payload.issues.push({
605
+ origin,
606
+ code: "too_big",
607
+ maximum: def.maximum,
608
+ inclusive: true,
609
+ input,
610
+ inst,
611
+ continue: !def.abort
612
+ });
613
+ };
614
+ });
615
+ const $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst, def) => {
616
+ var _a;
617
+ $ZodCheck.init(inst, def);
618
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
619
+ const val = payload.value;
620
+ return !nullish(val) && val.length !== void 0;
621
+ });
622
+ inst._zod.onattach.push((inst) => {
623
+ const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
624
+ if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
625
+ });
626
+ inst._zod.check = (payload) => {
627
+ const input = payload.value;
628
+ if (input.length >= def.minimum) return;
629
+ const origin = getLengthableOrigin(input);
630
+ payload.issues.push({
631
+ origin,
632
+ code: "too_small",
633
+ minimum: def.minimum,
634
+ inclusive: true,
635
+ input,
636
+ inst,
637
+ continue: !def.abort
638
+ });
639
+ };
640
+ });
641
+ const $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals", (inst, def) => {
642
+ var _a;
643
+ $ZodCheck.init(inst, def);
644
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
645
+ const val = payload.value;
646
+ return !nullish(val) && val.length !== void 0;
647
+ });
648
+ inst._zod.onattach.push((inst) => {
649
+ const bag = inst._zod.bag;
650
+ bag.minimum = def.length;
651
+ bag.maximum = def.length;
652
+ bag.length = def.length;
653
+ });
654
+ inst._zod.check = (payload) => {
655
+ const input = payload.value;
656
+ const length = input.length;
657
+ if (length === def.length) return;
658
+ const origin = getLengthableOrigin(input);
659
+ const tooBig = length > def.length;
660
+ payload.issues.push({
661
+ origin,
662
+ ...tooBig ? {
663
+ code: "too_big",
664
+ maximum: def.length
665
+ } : {
666
+ code: "too_small",
667
+ minimum: def.length
668
+ },
669
+ inclusive: true,
670
+ exact: true,
671
+ input: payload.value,
672
+ inst,
673
+ continue: !def.abort
674
+ });
675
+ };
676
+ });
677
+ const $ZodCheckStringFormat = /*@__PURE__*/ $constructor("$ZodCheckStringFormat", (inst, def) => {
678
+ var _a, _b;
679
+ $ZodCheck.init(inst, def);
680
+ inst._zod.onattach.push((inst) => {
681
+ const bag = inst._zod.bag;
682
+ bag.format = def.format;
683
+ if (def.pattern) {
684
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
685
+ bag.patterns.add(def.pattern);
686
+ }
687
+ });
688
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
689
+ def.pattern.lastIndex = 0;
690
+ if (def.pattern.test(payload.value)) return;
691
+ payload.issues.push({
692
+ origin: "string",
693
+ code: "invalid_format",
694
+ format: def.format,
695
+ input: payload.value,
696
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
697
+ inst,
698
+ continue: !def.abort
699
+ });
700
+ });
701
+ else (_b = inst._zod).check ?? (_b.check = () => {});
702
+ });
703
+ const $ZodCheckRegex = /*@__PURE__*/ $constructor("$ZodCheckRegex", (inst, def) => {
704
+ $ZodCheckStringFormat.init(inst, def);
705
+ inst._zod.check = (payload) => {
706
+ def.pattern.lastIndex = 0;
707
+ if (def.pattern.test(payload.value)) return;
708
+ payload.issues.push({
709
+ origin: "string",
710
+ code: "invalid_format",
711
+ format: "regex",
712
+ input: payload.value,
713
+ pattern: def.pattern.toString(),
714
+ inst,
715
+ continue: !def.abort
716
+ });
717
+ };
718
+ });
719
+ const $ZodCheckLowerCase = /*@__PURE__*/ $constructor("$ZodCheckLowerCase", (inst, def) => {
720
+ def.pattern ?? (def.pattern = lowercase);
721
+ $ZodCheckStringFormat.init(inst, def);
722
+ });
723
+ const $ZodCheckUpperCase = /*@__PURE__*/ $constructor("$ZodCheckUpperCase", (inst, def) => {
724
+ def.pattern ?? (def.pattern = uppercase);
725
+ $ZodCheckStringFormat.init(inst, def);
726
+ });
727
+ const $ZodCheckIncludes = /*@__PURE__*/ $constructor("$ZodCheckIncludes", (inst, def) => {
728
+ $ZodCheck.init(inst, def);
729
+ const escapedRegex = escapeRegex(def.includes);
730
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
731
+ def.pattern = pattern;
732
+ inst._zod.onattach.push((inst) => {
733
+ const bag = inst._zod.bag;
734
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
735
+ bag.patterns.add(pattern);
736
+ });
737
+ inst._zod.check = (payload) => {
738
+ if (payload.value.includes(def.includes, def.position)) return;
739
+ payload.issues.push({
740
+ origin: "string",
741
+ code: "invalid_format",
742
+ format: "includes",
743
+ includes: def.includes,
744
+ input: payload.value,
745
+ inst,
746
+ continue: !def.abort
747
+ });
748
+ };
749
+ });
750
+ const $ZodCheckStartsWith = /*@__PURE__*/ $constructor("$ZodCheckStartsWith", (inst, def) => {
751
+ $ZodCheck.init(inst, def);
752
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
753
+ def.pattern ?? (def.pattern = pattern);
754
+ inst._zod.onattach.push((inst) => {
755
+ const bag = inst._zod.bag;
756
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
757
+ bag.patterns.add(pattern);
758
+ });
759
+ inst._zod.check = (payload) => {
760
+ if (payload.value.startsWith(def.prefix)) return;
761
+ payload.issues.push({
762
+ origin: "string",
763
+ code: "invalid_format",
764
+ format: "starts_with",
765
+ prefix: def.prefix,
766
+ input: payload.value,
767
+ inst,
768
+ continue: !def.abort
769
+ });
770
+ };
771
+ });
772
+ const $ZodCheckEndsWith = /*@__PURE__*/ $constructor("$ZodCheckEndsWith", (inst, def) => {
773
+ $ZodCheck.init(inst, def);
774
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
775
+ def.pattern ?? (def.pattern = pattern);
776
+ inst._zod.onattach.push((inst) => {
777
+ const bag = inst._zod.bag;
778
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
779
+ bag.patterns.add(pattern);
780
+ });
781
+ inst._zod.check = (payload) => {
782
+ if (payload.value.endsWith(def.suffix)) return;
783
+ payload.issues.push({
784
+ origin: "string",
785
+ code: "invalid_format",
786
+ format: "ends_with",
787
+ suffix: def.suffix,
788
+ input: payload.value,
789
+ inst,
790
+ continue: !def.abort
791
+ });
792
+ };
793
+ });
794
+ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (inst, def) => {
795
+ $ZodCheck.init(inst, def);
796
+ inst._zod.check = (payload) => {
797
+ payload.value = def.tx(payload.value);
798
+ };
799
+ });
800
+ //#endregion
801
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/versions.js
802
+ const version = {
803
+ major: 4,
804
+ minor: 4,
805
+ patch: 3
806
+ };
807
+ //#endregion
808
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/schemas.js
809
+ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
810
+ var _a;
811
+ inst ?? (inst = {});
812
+ inst._zod.def = def;
813
+ inst._zod.bag = inst._zod.bag || {};
814
+ inst._zod.version = version;
815
+ const checks = [...inst._zod.def.checks ?? []];
816
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
817
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
818
+ if (checks.length === 0) {
819
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
820
+ inst._zod.deferred?.push(() => {
821
+ inst._zod.run = inst._zod.parse;
822
+ });
823
+ } else {
824
+ const runChecks = (payload, checks, ctx) => {
825
+ let isAborted = aborted(payload);
826
+ let asyncResult;
827
+ for (const ch of checks) {
828
+ if (ch._zod.def.when) {
829
+ if (explicitlyAborted(payload)) continue;
830
+ if (!ch._zod.def.when(payload)) continue;
831
+ } else if (isAborted) continue;
832
+ const currLen = payload.issues.length;
833
+ const _ = ch._zod.check(payload);
834
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
835
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
836
+ await _;
837
+ if (payload.issues.length === currLen) return;
838
+ if (!isAborted) isAborted = aborted(payload, currLen);
839
+ });
840
+ else {
841
+ if (payload.issues.length === currLen) continue;
842
+ if (!isAborted) isAborted = aborted(payload, currLen);
843
+ }
844
+ }
845
+ if (asyncResult) return asyncResult.then(() => {
846
+ return payload;
847
+ });
848
+ return payload;
849
+ };
850
+ const handleCanaryResult = (canary, payload, ctx) => {
851
+ if (aborted(canary)) {
852
+ canary.aborted = true;
853
+ return canary;
854
+ }
855
+ const checkResult = runChecks(payload, checks, ctx);
856
+ if (checkResult instanceof Promise) {
857
+ if (ctx.async === false) throw new $ZodAsyncError();
858
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
859
+ }
860
+ return inst._zod.parse(checkResult, ctx);
861
+ };
862
+ inst._zod.run = (payload, ctx) => {
863
+ if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
864
+ if (ctx.direction === "backward") {
865
+ const canary = inst._zod.parse({
866
+ value: payload.value,
867
+ issues: []
868
+ }, {
869
+ ...ctx,
870
+ skipChecks: true
871
+ });
872
+ if (canary instanceof Promise) return canary.then((canary) => {
873
+ return handleCanaryResult(canary, payload, ctx);
874
+ });
875
+ return handleCanaryResult(canary, payload, ctx);
876
+ }
877
+ const result = inst._zod.parse(payload, ctx);
878
+ if (result instanceof Promise) {
879
+ if (ctx.async === false) throw new $ZodAsyncError();
880
+ return result.then((result) => runChecks(result, checks, ctx));
881
+ }
882
+ return runChecks(result, checks, ctx);
883
+ };
884
+ }
885
+ defineLazy(inst, "~standard", () => ({
886
+ validate: (value) => {
887
+ try {
888
+ const r = safeParse$1(inst, value);
889
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
890
+ } catch (_) {
891
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
892
+ }
893
+ },
894
+ vendor: "zod",
895
+ version: 1
896
+ }));
897
+ });
898
+ const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
899
+ $ZodType.init(inst, def);
900
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
901
+ inst._zod.parse = (payload, _) => {
902
+ if (def.coerce) try {
903
+ payload.value = String(payload.value);
904
+ } catch (_) {}
905
+ if (typeof payload.value === "string") return payload;
906
+ payload.issues.push({
907
+ expected: "string",
908
+ code: "invalid_type",
909
+ input: payload.value,
910
+ inst
911
+ });
912
+ return payload;
913
+ };
914
+ });
915
+ const $ZodStringFormat = /*@__PURE__*/ $constructor("$ZodStringFormat", (inst, def) => {
916
+ $ZodCheckStringFormat.init(inst, def);
917
+ $ZodString.init(inst, def);
918
+ });
919
+ const $ZodGUID = /*@__PURE__*/ $constructor("$ZodGUID", (inst, def) => {
920
+ def.pattern ?? (def.pattern = guid);
921
+ $ZodStringFormat.init(inst, def);
922
+ });
923
+ const $ZodUUID = /*@__PURE__*/ $constructor("$ZodUUID", (inst, def) => {
924
+ if (def.version) {
925
+ const v = {
926
+ v1: 1,
927
+ v2: 2,
928
+ v3: 3,
929
+ v4: 4,
930
+ v5: 5,
931
+ v6: 6,
932
+ v7: 7,
933
+ v8: 8
934
+ }[def.version];
935
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
936
+ def.pattern ?? (def.pattern = uuid(v));
937
+ } else def.pattern ?? (def.pattern = uuid());
938
+ $ZodStringFormat.init(inst, def);
939
+ });
940
+ const $ZodEmail = /*@__PURE__*/ $constructor("$ZodEmail", (inst, def) => {
941
+ def.pattern ?? (def.pattern = email);
942
+ $ZodStringFormat.init(inst, def);
943
+ });
944
+ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
945
+ $ZodStringFormat.init(inst, def);
946
+ inst._zod.check = (payload) => {
947
+ try {
948
+ const trimmed = payload.value.trim();
949
+ if (!def.normalize && def.protocol?.source === httpProtocol.source) {
950
+ if (!/^https?:\/\//i.test(trimmed)) {
951
+ payload.issues.push({
952
+ code: "invalid_format",
953
+ format: "url",
954
+ note: "Invalid URL format",
955
+ input: payload.value,
956
+ inst,
957
+ continue: !def.abort
958
+ });
959
+ return;
960
+ }
961
+ }
962
+ const url = new URL(trimmed);
963
+ if (def.hostname) {
964
+ def.hostname.lastIndex = 0;
965
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
966
+ code: "invalid_format",
967
+ format: "url",
968
+ note: "Invalid hostname",
969
+ pattern: def.hostname.source,
970
+ input: payload.value,
971
+ inst,
972
+ continue: !def.abort
973
+ });
974
+ }
975
+ if (def.protocol) {
976
+ def.protocol.lastIndex = 0;
977
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
978
+ code: "invalid_format",
979
+ format: "url",
980
+ note: "Invalid protocol",
981
+ pattern: def.protocol.source,
982
+ input: payload.value,
983
+ inst,
984
+ continue: !def.abort
985
+ });
986
+ }
987
+ if (def.normalize) payload.value = url.href;
988
+ else payload.value = trimmed;
989
+ return;
990
+ } catch (_) {
991
+ payload.issues.push({
992
+ code: "invalid_format",
993
+ format: "url",
994
+ input: payload.value,
995
+ inst,
996
+ continue: !def.abort
997
+ });
998
+ }
999
+ };
1000
+ });
1001
+ const $ZodEmoji = /*@__PURE__*/ $constructor("$ZodEmoji", (inst, def) => {
1002
+ def.pattern ?? (def.pattern = emoji());
1003
+ $ZodStringFormat.init(inst, def);
1004
+ });
1005
+ const $ZodNanoID = /*@__PURE__*/ $constructor("$ZodNanoID", (inst, def) => {
1006
+ def.pattern ?? (def.pattern = nanoid);
1007
+ $ZodStringFormat.init(inst, def);
1008
+ });
1009
+ /**
1010
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1011
+ * (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
1012
+ * See https://github.com/paralleldrive/cuid.
1013
+ */
1014
+ const $ZodCUID = /*@__PURE__*/ $constructor("$ZodCUID", (inst, def) => {
1015
+ def.pattern ?? (def.pattern = cuid);
1016
+ $ZodStringFormat.init(inst, def);
1017
+ });
1018
+ const $ZodCUID2 = /*@__PURE__*/ $constructor("$ZodCUID2", (inst, def) => {
1019
+ def.pattern ?? (def.pattern = cuid2);
1020
+ $ZodStringFormat.init(inst, def);
1021
+ });
1022
+ const $ZodULID = /*@__PURE__*/ $constructor("$ZodULID", (inst, def) => {
1023
+ def.pattern ?? (def.pattern = ulid);
1024
+ $ZodStringFormat.init(inst, def);
1025
+ });
1026
+ const $ZodXID = /*@__PURE__*/ $constructor("$ZodXID", (inst, def) => {
1027
+ def.pattern ?? (def.pattern = xid);
1028
+ $ZodStringFormat.init(inst, def);
1029
+ });
1030
+ const $ZodKSUID = /*@__PURE__*/ $constructor("$ZodKSUID", (inst, def) => {
1031
+ def.pattern ?? (def.pattern = ksuid);
1032
+ $ZodStringFormat.init(inst, def);
1033
+ });
1034
+ const $ZodISODateTime = /*@__PURE__*/ $constructor("$ZodISODateTime", (inst, def) => {
1035
+ def.pattern ?? (def.pattern = datetime$1(def));
1036
+ $ZodStringFormat.init(inst, def);
1037
+ });
1038
+ const $ZodISODate = /*@__PURE__*/ $constructor("$ZodISODate", (inst, def) => {
1039
+ def.pattern ?? (def.pattern = date$1);
1040
+ $ZodStringFormat.init(inst, def);
1041
+ });
1042
+ const $ZodISOTime = /*@__PURE__*/ $constructor("$ZodISOTime", (inst, def) => {
1043
+ def.pattern ?? (def.pattern = time$1(def));
1044
+ $ZodStringFormat.init(inst, def);
1045
+ });
1046
+ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def) => {
1047
+ def.pattern ?? (def.pattern = duration$1);
1048
+ $ZodStringFormat.init(inst, def);
1049
+ });
1050
+ const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1051
+ def.pattern ?? (def.pattern = ipv4);
1052
+ $ZodStringFormat.init(inst, def);
1053
+ inst._zod.bag.format = `ipv4`;
1054
+ });
1055
+ const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1056
+ def.pattern ?? (def.pattern = ipv6);
1057
+ $ZodStringFormat.init(inst, def);
1058
+ inst._zod.bag.format = `ipv6`;
1059
+ inst._zod.check = (payload) => {
1060
+ try {
1061
+ new URL(`http://[${payload.value}]`);
1062
+ } catch {
1063
+ payload.issues.push({
1064
+ code: "invalid_format",
1065
+ format: "ipv6",
1066
+ input: payload.value,
1067
+ inst,
1068
+ continue: !def.abort
1069
+ });
1070
+ }
1071
+ };
1072
+ });
1073
+ const $ZodCIDRv4 = /*@__PURE__*/ $constructor("$ZodCIDRv4", (inst, def) => {
1074
+ def.pattern ?? (def.pattern = cidrv4);
1075
+ $ZodStringFormat.init(inst, def);
1076
+ });
1077
+ const $ZodCIDRv6 = /*@__PURE__*/ $constructor("$ZodCIDRv6", (inst, def) => {
1078
+ def.pattern ?? (def.pattern = cidrv6);
1079
+ $ZodStringFormat.init(inst, def);
1080
+ inst._zod.check = (payload) => {
1081
+ const parts = payload.value.split("/");
1082
+ try {
1083
+ if (parts.length !== 2) throw new Error();
1084
+ const [address, prefix] = parts;
1085
+ if (!prefix) throw new Error();
1086
+ const prefixNum = Number(prefix);
1087
+ if (`${prefixNum}` !== prefix) throw new Error();
1088
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1089
+ new URL(`http://[${address}]`);
1090
+ } catch {
1091
+ payload.issues.push({
1092
+ code: "invalid_format",
1093
+ format: "cidrv6",
1094
+ input: payload.value,
1095
+ inst,
1096
+ continue: !def.abort
1097
+ });
1098
+ }
1099
+ };
1100
+ });
1101
+ function isValidBase64(data) {
1102
+ if (data === "") return true;
1103
+ if (/\s/.test(data)) return false;
1104
+ if (data.length % 4 !== 0) return false;
1105
+ try {
1106
+ atob(data);
1107
+ return true;
1108
+ } catch {
1109
+ return false;
1110
+ }
1111
+ }
1112
+ const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1113
+ def.pattern ?? (def.pattern = base64);
1114
+ $ZodStringFormat.init(inst, def);
1115
+ inst._zod.bag.contentEncoding = "base64";
1116
+ inst._zod.check = (payload) => {
1117
+ if (isValidBase64(payload.value)) return;
1118
+ payload.issues.push({
1119
+ code: "invalid_format",
1120
+ format: "base64",
1121
+ input: payload.value,
1122
+ inst,
1123
+ continue: !def.abort
1124
+ });
1125
+ };
1126
+ });
1127
+ function isValidBase64URL(data) {
1128
+ if (!base64url.test(data)) return false;
1129
+ const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1130
+ return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
1131
+ }
1132
+ const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1133
+ def.pattern ?? (def.pattern = base64url);
1134
+ $ZodStringFormat.init(inst, def);
1135
+ inst._zod.bag.contentEncoding = "base64url";
1136
+ inst._zod.check = (payload) => {
1137
+ if (isValidBase64URL(payload.value)) return;
1138
+ payload.issues.push({
1139
+ code: "invalid_format",
1140
+ format: "base64url",
1141
+ input: payload.value,
1142
+ inst,
1143
+ continue: !def.abort
1144
+ });
1145
+ };
1146
+ });
1147
+ const $ZodE164 = /*@__PURE__*/ $constructor("$ZodE164", (inst, def) => {
1148
+ def.pattern ?? (def.pattern = e164);
1149
+ $ZodStringFormat.init(inst, def);
1150
+ });
1151
+ function isValidJWT(token, algorithm = null) {
1152
+ try {
1153
+ const tokensParts = token.split(".");
1154
+ if (tokensParts.length !== 3) return false;
1155
+ const [header] = tokensParts;
1156
+ if (!header) return false;
1157
+ const parsedHeader = JSON.parse(atob(header));
1158
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1159
+ if (!parsedHeader.alg) return false;
1160
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1161
+ return true;
1162
+ } catch {
1163
+ return false;
1164
+ }
1165
+ }
1166
+ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
1167
+ $ZodStringFormat.init(inst, def);
1168
+ inst._zod.check = (payload) => {
1169
+ if (isValidJWT(payload.value, def.alg)) return;
1170
+ payload.issues.push({
1171
+ code: "invalid_format",
1172
+ format: "jwt",
1173
+ input: payload.value,
1174
+ inst,
1175
+ continue: !def.abort
1176
+ });
1177
+ };
1178
+ });
1179
+ function handleArrayResult(result, final, index) {
1180
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1181
+ final.value[index] = result.value;
1182
+ }
1183
+ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
1184
+ $ZodType.init(inst, def);
1185
+ inst._zod.parse = (payload, ctx) => {
1186
+ const input = payload.value;
1187
+ if (!Array.isArray(input)) {
1188
+ payload.issues.push({
1189
+ expected: "array",
1190
+ code: "invalid_type",
1191
+ input,
1192
+ inst
1193
+ });
1194
+ return payload;
1195
+ }
1196
+ payload.value = Array(input.length);
1197
+ const proms = [];
1198
+ for (let i = 0; i < input.length; i++) {
1199
+ const item = input[i];
1200
+ const result = def.element._zod.run({
1201
+ value: item,
1202
+ issues: []
1203
+ }, ctx);
1204
+ if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1205
+ else handleArrayResult(result, payload, i);
1206
+ }
1207
+ if (proms.length) return Promise.all(proms).then(() => payload);
1208
+ return payload;
1209
+ };
1210
+ });
1211
+ function handleUnionResults(results, final, inst, ctx) {
1212
+ for (const result of results) if (result.issues.length === 0) {
1213
+ final.value = result.value;
1214
+ return final;
1215
+ }
1216
+ const nonaborted = results.filter((r) => !aborted(r));
1217
+ if (nonaborted.length === 1) {
1218
+ final.value = nonaborted[0].value;
1219
+ return nonaborted[0];
1220
+ }
1221
+ final.issues.push({
1222
+ code: "invalid_union",
1223
+ input: final.value,
1224
+ inst,
1225
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1226
+ });
1227
+ return final;
1228
+ }
1229
+ const $ZodUnion = /*@__PURE__*/ $constructor("$ZodUnion", (inst, def) => {
1230
+ $ZodType.init(inst, def);
1231
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1232
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1233
+ defineLazy(inst._zod, "values", () => {
1234
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1235
+ });
1236
+ defineLazy(inst._zod, "pattern", () => {
1237
+ if (def.options.every((o) => o._zod.pattern)) {
1238
+ const patterns = def.options.map((o) => o._zod.pattern);
1239
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1240
+ }
1241
+ });
1242
+ const first = def.options.length === 1 ? def.options[0]._zod.run : null;
1243
+ inst._zod.parse = (payload, ctx) => {
1244
+ if (first) return first(payload, ctx);
1245
+ let async = false;
1246
+ const results = [];
1247
+ for (const option of def.options) {
1248
+ const result = option._zod.run({
1249
+ value: payload.value,
1250
+ issues: []
1251
+ }, ctx);
1252
+ if (result instanceof Promise) {
1253
+ results.push(result);
1254
+ async = true;
1255
+ } else {
1256
+ if (result.issues.length === 0) return result;
1257
+ results.push(result);
1258
+ }
1259
+ }
1260
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1261
+ return Promise.all(results).then((results) => {
1262
+ return handleUnionResults(results, payload, inst, ctx);
1263
+ });
1264
+ };
1265
+ });
1266
+ const $ZodIntersection = /*@__PURE__*/ $constructor("$ZodIntersection", (inst, def) => {
1267
+ $ZodType.init(inst, def);
1268
+ inst._zod.parse = (payload, ctx) => {
1269
+ const input = payload.value;
1270
+ const left = def.left._zod.run({
1271
+ value: input,
1272
+ issues: []
1273
+ }, ctx);
1274
+ const right = def.right._zod.run({
1275
+ value: input,
1276
+ issues: []
1277
+ }, ctx);
1278
+ if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
1279
+ return handleIntersectionResults(payload, left, right);
1280
+ });
1281
+ return handleIntersectionResults(payload, left, right);
1282
+ };
1283
+ });
1284
+ function mergeValues(a, b) {
1285
+ if (a === b) return {
1286
+ valid: true,
1287
+ data: a
1288
+ };
1289
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
1290
+ valid: true,
1291
+ data: a
1292
+ };
1293
+ if (isPlainObject(a) && isPlainObject(b)) {
1294
+ const bKeys = Object.keys(b);
1295
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1296
+ const newObj = {
1297
+ ...a,
1298
+ ...b
1299
+ };
1300
+ for (const key of sharedKeys) {
1301
+ const sharedValue = mergeValues(a[key], b[key]);
1302
+ if (!sharedValue.valid) return {
1303
+ valid: false,
1304
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1305
+ };
1306
+ newObj[key] = sharedValue.data;
1307
+ }
1308
+ return {
1309
+ valid: true,
1310
+ data: newObj
1311
+ };
1312
+ }
1313
+ if (Array.isArray(a) && Array.isArray(b)) {
1314
+ if (a.length !== b.length) return {
1315
+ valid: false,
1316
+ mergeErrorPath: []
1317
+ };
1318
+ const newArray = [];
1319
+ for (let index = 0; index < a.length; index++) {
1320
+ const itemA = a[index];
1321
+ const itemB = b[index];
1322
+ const sharedValue = mergeValues(itemA, itemB);
1323
+ if (!sharedValue.valid) return {
1324
+ valid: false,
1325
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1326
+ };
1327
+ newArray.push(sharedValue.data);
1328
+ }
1329
+ return {
1330
+ valid: true,
1331
+ data: newArray
1332
+ };
1333
+ }
1334
+ return {
1335
+ valid: false,
1336
+ mergeErrorPath: []
1337
+ };
1338
+ }
1339
+ function handleIntersectionResults(result, left, right) {
1340
+ const unrecKeys = /* @__PURE__ */ new Map();
1341
+ let unrecIssue;
1342
+ for (const iss of left.issues) if (iss.code === "unrecognized_keys") {
1343
+ unrecIssue ?? (unrecIssue = iss);
1344
+ for (const k of iss.keys) {
1345
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1346
+ unrecKeys.get(k).l = true;
1347
+ }
1348
+ } else result.issues.push(iss);
1349
+ for (const iss of right.issues) if (iss.code === "unrecognized_keys") for (const k of iss.keys) {
1350
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1351
+ unrecKeys.get(k).r = true;
1352
+ }
1353
+ else result.issues.push(iss);
1354
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1355
+ if (bothKeys.length && unrecIssue) result.issues.push({
1356
+ ...unrecIssue,
1357
+ keys: bothKeys
1358
+ });
1359
+ if (aborted(result)) return result;
1360
+ const merged = mergeValues(left.value, right.value);
1361
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1362
+ result.value = merged.data;
1363
+ return result;
1364
+ }
1365
+ const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
1366
+ $ZodType.init(inst, def);
1367
+ inst._zod.optin = "optional";
1368
+ inst._zod.parse = (payload, ctx) => {
1369
+ if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
1370
+ const _out = def.transform(payload.value, payload);
1371
+ if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1372
+ payload.value = output;
1373
+ payload.fallback = true;
1374
+ return payload;
1375
+ });
1376
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1377
+ payload.value = _out;
1378
+ payload.fallback = true;
1379
+ return payload;
1380
+ };
1381
+ });
1382
+ function handleOptionalResult(result, input) {
1383
+ if (input === void 0 && (result.issues.length || result.fallback)) return {
1384
+ issues: [],
1385
+ value: void 0
1386
+ };
1387
+ return result;
1388
+ }
1389
+ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
1390
+ $ZodType.init(inst, def);
1391
+ inst._zod.optin = "optional";
1392
+ inst._zod.optout = "optional";
1393
+ defineLazy(inst._zod, "values", () => {
1394
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
1395
+ });
1396
+ defineLazy(inst._zod, "pattern", () => {
1397
+ const pattern = def.innerType._zod.pattern;
1398
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1399
+ });
1400
+ inst._zod.parse = (payload, ctx) => {
1401
+ if (def.innerType._zod.optin === "optional") {
1402
+ const input = payload.value;
1403
+ const result = def.innerType._zod.run(payload, ctx);
1404
+ if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, input));
1405
+ return handleOptionalResult(result, input);
1406
+ }
1407
+ if (payload.value === void 0) return payload;
1408
+ return def.innerType._zod.run(payload, ctx);
1409
+ };
1410
+ });
1411
+ const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
1412
+ $ZodOptional.init(inst, def);
1413
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1414
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
1415
+ inst._zod.parse = (payload, ctx) => {
1416
+ return def.innerType._zod.run(payload, ctx);
1417
+ };
1418
+ });
1419
+ const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
1420
+ $ZodType.init(inst, def);
1421
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1422
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1423
+ defineLazy(inst._zod, "pattern", () => {
1424
+ const pattern = def.innerType._zod.pattern;
1425
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1426
+ });
1427
+ defineLazy(inst._zod, "values", () => {
1428
+ return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
1429
+ });
1430
+ inst._zod.parse = (payload, ctx) => {
1431
+ if (payload.value === null) return payload;
1432
+ return def.innerType._zod.run(payload, ctx);
1433
+ };
1434
+ });
1435
+ const $ZodDefault = /*@__PURE__*/ $constructor("$ZodDefault", (inst, def) => {
1436
+ $ZodType.init(inst, def);
1437
+ inst._zod.optin = "optional";
1438
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1439
+ inst._zod.parse = (payload, ctx) => {
1440
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1441
+ if (payload.value === void 0) {
1442
+ payload.value = def.defaultValue;
1443
+ /**
1444
+ * $ZodDefault returns the default value immediately in forward direction.
1445
+ * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1446
+ return payload;
1447
+ }
1448
+ const result = def.innerType._zod.run(payload, ctx);
1449
+ if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
1450
+ return handleDefaultResult(result, def);
1451
+ };
1452
+ });
1453
+ function handleDefaultResult(payload, def) {
1454
+ if (payload.value === void 0) payload.value = def.defaultValue;
1455
+ return payload;
1456
+ }
1457
+ const $ZodPrefault = /*@__PURE__*/ $constructor("$ZodPrefault", (inst, def) => {
1458
+ $ZodType.init(inst, def);
1459
+ inst._zod.optin = "optional";
1460
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1461
+ inst._zod.parse = (payload, ctx) => {
1462
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1463
+ if (payload.value === void 0) payload.value = def.defaultValue;
1464
+ return def.innerType._zod.run(payload, ctx);
1465
+ };
1466
+ });
1467
+ const $ZodNonOptional = /*@__PURE__*/ $constructor("$ZodNonOptional", (inst, def) => {
1468
+ $ZodType.init(inst, def);
1469
+ defineLazy(inst._zod, "values", () => {
1470
+ const v = def.innerType._zod.values;
1471
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1472
+ });
1473
+ inst._zod.parse = (payload, ctx) => {
1474
+ const result = def.innerType._zod.run(payload, ctx);
1475
+ if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
1476
+ return handleNonOptionalResult(result, inst);
1477
+ };
1478
+ });
1479
+ function handleNonOptionalResult(payload, inst) {
1480
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1481
+ code: "invalid_type",
1482
+ expected: "nonoptional",
1483
+ input: payload.value,
1484
+ inst
1485
+ });
1486
+ return payload;
1487
+ }
1488
+ const $ZodCatch = /*@__PURE__*/ $constructor("$ZodCatch", (inst, def) => {
1489
+ $ZodType.init(inst, def);
1490
+ inst._zod.optin = "optional";
1491
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1492
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1493
+ inst._zod.parse = (payload, ctx) => {
1494
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1495
+ const result = def.innerType._zod.run(payload, ctx);
1496
+ if (result instanceof Promise) return result.then((result) => {
1497
+ payload.value = result.value;
1498
+ if (result.issues.length) {
1499
+ payload.value = def.catchValue({
1500
+ ...payload,
1501
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1502
+ input: payload.value
1503
+ });
1504
+ payload.issues = [];
1505
+ payload.fallback = true;
1506
+ }
1507
+ return payload;
1508
+ });
1509
+ payload.value = result.value;
1510
+ if (result.issues.length) {
1511
+ payload.value = def.catchValue({
1512
+ ...payload,
1513
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1514
+ input: payload.value
1515
+ });
1516
+ payload.issues = [];
1517
+ payload.fallback = true;
1518
+ }
1519
+ return payload;
1520
+ };
1521
+ });
1522
+ const $ZodPipe = /*@__PURE__*/ $constructor("$ZodPipe", (inst, def) => {
1523
+ $ZodType.init(inst, def);
1524
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
1525
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1526
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1527
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1528
+ inst._zod.parse = (payload, ctx) => {
1529
+ if (ctx.direction === "backward") {
1530
+ const right = def.out._zod.run(payload, ctx);
1531
+ if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
1532
+ return handlePipeResult(right, def.in, ctx);
1533
+ }
1534
+ const left = def.in._zod.run(payload, ctx);
1535
+ if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
1536
+ return handlePipeResult(left, def.out, ctx);
1537
+ };
1538
+ });
1539
+ function handlePipeResult(left, next, ctx) {
1540
+ if (left.issues.length) {
1541
+ left.aborted = true;
1542
+ return left;
1543
+ }
1544
+ return next._zod.run({
1545
+ value: left.value,
1546
+ issues: left.issues,
1547
+ fallback: left.fallback
1548
+ }, ctx);
1549
+ }
1550
+ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
1551
+ $ZodType.init(inst, def);
1552
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1553
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1554
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1555
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1556
+ inst._zod.parse = (payload, ctx) => {
1557
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1558
+ const result = def.innerType._zod.run(payload, ctx);
1559
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
1560
+ return handleReadonlyResult(result);
1561
+ };
1562
+ });
1563
+ function handleReadonlyResult(payload) {
1564
+ payload.value = Object.freeze(payload.value);
1565
+ return payload;
1566
+ }
1567
+ const $ZodCustom = /*@__PURE__*/ $constructor("$ZodCustom", (inst, def) => {
1568
+ $ZodCheck.init(inst, def);
1569
+ $ZodType.init(inst, def);
1570
+ inst._zod.parse = (payload, _) => {
1571
+ return payload;
1572
+ };
1573
+ inst._zod.check = (payload) => {
1574
+ const input = payload.value;
1575
+ const r = def.fn(input);
1576
+ if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
1577
+ handleRefineResult(r, payload, input, inst);
1578
+ };
1579
+ });
1580
+ function handleRefineResult(result, payload, input, inst) {
1581
+ if (!result) {
1582
+ const _iss = {
1583
+ code: "custom",
1584
+ input,
1585
+ inst,
1586
+ path: [...inst._zod.def.path ?? []],
1587
+ continue: !inst._zod.def.abort
1588
+ };
1589
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
1590
+ payload.issues.push(issue(_iss));
1591
+ }
1592
+ }
1593
+ //#endregion
1594
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/registries.js
1595
+ var _a;
1596
+ var $ZodRegistry = class {
1597
+ constructor() {
1598
+ this._map = /* @__PURE__ */ new WeakMap();
1599
+ this._idmap = /* @__PURE__ */ new Map();
1600
+ }
1601
+ add(schema, ..._meta) {
1602
+ const meta = _meta[0];
1603
+ this._map.set(schema, meta);
1604
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
1605
+ return this;
1606
+ }
1607
+ clear() {
1608
+ this._map = /* @__PURE__ */ new WeakMap();
1609
+ this._idmap = /* @__PURE__ */ new Map();
1610
+ return this;
1611
+ }
1612
+ remove(schema) {
1613
+ const meta = this._map.get(schema);
1614
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
1615
+ this._map.delete(schema);
1616
+ return this;
1617
+ }
1618
+ get(schema) {
1619
+ const p = schema._zod.parent;
1620
+ if (p) {
1621
+ const pm = { ...this.get(p) ?? {} };
1622
+ delete pm.id;
1623
+ const f = {
1624
+ ...pm,
1625
+ ...this._map.get(schema)
1626
+ };
1627
+ return Object.keys(f).length ? f : void 0;
1628
+ }
1629
+ return this._map.get(schema);
1630
+ }
1631
+ has(schema) {
1632
+ return this._map.has(schema);
1633
+ }
1634
+ };
1635
+ function registry() {
1636
+ return new $ZodRegistry();
1637
+ }
1638
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
1639
+ const globalRegistry = globalThis.__zod_globalRegistry;
1640
+ //#endregion
1641
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/api.js
1642
+ // @__NO_SIDE_EFFECTS__
1643
+ function _string(Class, params) {
1644
+ return new Class({
1645
+ type: "string",
1646
+ ...normalizeParams(params)
1647
+ });
1648
+ }
1649
+ // @__NO_SIDE_EFFECTS__
1650
+ function _email(Class, params) {
1651
+ return new Class({
1652
+ type: "string",
1653
+ format: "email",
1654
+ check: "string_format",
1655
+ abort: false,
1656
+ ...normalizeParams(params)
1657
+ });
1658
+ }
1659
+ // @__NO_SIDE_EFFECTS__
1660
+ function _guid(Class, params) {
1661
+ return new Class({
1662
+ type: "string",
1663
+ format: "guid",
1664
+ check: "string_format",
1665
+ abort: false,
1666
+ ...normalizeParams(params)
1667
+ });
1668
+ }
1669
+ // @__NO_SIDE_EFFECTS__
1670
+ function _uuid(Class, params) {
1671
+ return new Class({
1672
+ type: "string",
1673
+ format: "uuid",
1674
+ check: "string_format",
1675
+ abort: false,
1676
+ ...normalizeParams(params)
1677
+ });
1678
+ }
1679
+ // @__NO_SIDE_EFFECTS__
1680
+ function _uuidv4(Class, params) {
1681
+ return new Class({
1682
+ type: "string",
1683
+ format: "uuid",
1684
+ check: "string_format",
1685
+ abort: false,
1686
+ version: "v4",
1687
+ ...normalizeParams(params)
1688
+ });
1689
+ }
1690
+ // @__NO_SIDE_EFFECTS__
1691
+ function _uuidv6(Class, params) {
1692
+ return new Class({
1693
+ type: "string",
1694
+ format: "uuid",
1695
+ check: "string_format",
1696
+ abort: false,
1697
+ version: "v6",
1698
+ ...normalizeParams(params)
1699
+ });
1700
+ }
1701
+ // @__NO_SIDE_EFFECTS__
1702
+ function _uuidv7(Class, params) {
1703
+ return new Class({
1704
+ type: "string",
1705
+ format: "uuid",
1706
+ check: "string_format",
1707
+ abort: false,
1708
+ version: "v7",
1709
+ ...normalizeParams(params)
1710
+ });
1711
+ }
1712
+ // @__NO_SIDE_EFFECTS__
1713
+ function _url(Class, params) {
1714
+ return new Class({
1715
+ type: "string",
1716
+ format: "url",
1717
+ check: "string_format",
1718
+ abort: false,
1719
+ ...normalizeParams(params)
1720
+ });
1721
+ }
1722
+ // @__NO_SIDE_EFFECTS__
1723
+ function _emoji(Class, params) {
1724
+ return new Class({
1725
+ type: "string",
1726
+ format: "emoji",
1727
+ check: "string_format",
1728
+ abort: false,
1729
+ ...normalizeParams(params)
1730
+ });
1731
+ }
1732
+ // @__NO_SIDE_EFFECTS__
1733
+ function _nanoid(Class, params) {
1734
+ return new Class({
1735
+ type: "string",
1736
+ format: "nanoid",
1737
+ check: "string_format",
1738
+ abort: false,
1739
+ ...normalizeParams(params)
1740
+ });
1741
+ }
1742
+ /**
1743
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
1744
+ * (timestamps embedded in the id). Use {@link _cuid2} instead.
1745
+ * See https://github.com/paralleldrive/cuid.
1746
+ */
1747
+ // @__NO_SIDE_EFFECTS__
1748
+ function _cuid(Class, params) {
1749
+ return new Class({
1750
+ type: "string",
1751
+ format: "cuid",
1752
+ check: "string_format",
1753
+ abort: false,
1754
+ ...normalizeParams(params)
1755
+ });
1756
+ }
1757
+ // @__NO_SIDE_EFFECTS__
1758
+ function _cuid2(Class, params) {
1759
+ return new Class({
1760
+ type: "string",
1761
+ format: "cuid2",
1762
+ check: "string_format",
1763
+ abort: false,
1764
+ ...normalizeParams(params)
1765
+ });
1766
+ }
1767
+ // @__NO_SIDE_EFFECTS__
1768
+ function _ulid(Class, params) {
1769
+ return new Class({
1770
+ type: "string",
1771
+ format: "ulid",
1772
+ check: "string_format",
1773
+ abort: false,
1774
+ ...normalizeParams(params)
1775
+ });
1776
+ }
1777
+ // @__NO_SIDE_EFFECTS__
1778
+ function _xid(Class, params) {
1779
+ return new Class({
1780
+ type: "string",
1781
+ format: "xid",
1782
+ check: "string_format",
1783
+ abort: false,
1784
+ ...normalizeParams(params)
1785
+ });
1786
+ }
1787
+ // @__NO_SIDE_EFFECTS__
1788
+ function _ksuid(Class, params) {
1789
+ return new Class({
1790
+ type: "string",
1791
+ format: "ksuid",
1792
+ check: "string_format",
1793
+ abort: false,
1794
+ ...normalizeParams(params)
1795
+ });
1796
+ }
1797
+ // @__NO_SIDE_EFFECTS__
1798
+ function _ipv4(Class, params) {
1799
+ return new Class({
1800
+ type: "string",
1801
+ format: "ipv4",
1802
+ check: "string_format",
1803
+ abort: false,
1804
+ ...normalizeParams(params)
1805
+ });
1806
+ }
1807
+ // @__NO_SIDE_EFFECTS__
1808
+ function _ipv6(Class, params) {
1809
+ return new Class({
1810
+ type: "string",
1811
+ format: "ipv6",
1812
+ check: "string_format",
1813
+ abort: false,
1814
+ ...normalizeParams(params)
1815
+ });
1816
+ }
1817
+ // @__NO_SIDE_EFFECTS__
1818
+ function _cidrv4(Class, params) {
1819
+ return new Class({
1820
+ type: "string",
1821
+ format: "cidrv4",
1822
+ check: "string_format",
1823
+ abort: false,
1824
+ ...normalizeParams(params)
1825
+ });
1826
+ }
1827
+ // @__NO_SIDE_EFFECTS__
1828
+ function _cidrv6(Class, params) {
1829
+ return new Class({
1830
+ type: "string",
1831
+ format: "cidrv6",
1832
+ check: "string_format",
1833
+ abort: false,
1834
+ ...normalizeParams(params)
1835
+ });
1836
+ }
1837
+ // @__NO_SIDE_EFFECTS__
1838
+ function _base64(Class, params) {
1839
+ return new Class({
1840
+ type: "string",
1841
+ format: "base64",
1842
+ check: "string_format",
1843
+ abort: false,
1844
+ ...normalizeParams(params)
1845
+ });
1846
+ }
1847
+ // @__NO_SIDE_EFFECTS__
1848
+ function _base64url(Class, params) {
1849
+ return new Class({
1850
+ type: "string",
1851
+ format: "base64url",
1852
+ check: "string_format",
1853
+ abort: false,
1854
+ ...normalizeParams(params)
1855
+ });
1856
+ }
1857
+ // @__NO_SIDE_EFFECTS__
1858
+ function _e164(Class, params) {
1859
+ return new Class({
1860
+ type: "string",
1861
+ format: "e164",
1862
+ check: "string_format",
1863
+ abort: false,
1864
+ ...normalizeParams(params)
1865
+ });
1866
+ }
1867
+ // @__NO_SIDE_EFFECTS__
1868
+ function _jwt(Class, params) {
1869
+ return new Class({
1870
+ type: "string",
1871
+ format: "jwt",
1872
+ check: "string_format",
1873
+ abort: false,
1874
+ ...normalizeParams(params)
1875
+ });
1876
+ }
1877
+ // @__NO_SIDE_EFFECTS__
1878
+ function _isoDateTime(Class, params) {
1879
+ return new Class({
1880
+ type: "string",
1881
+ format: "datetime",
1882
+ check: "string_format",
1883
+ offset: false,
1884
+ local: false,
1885
+ precision: null,
1886
+ ...normalizeParams(params)
1887
+ });
1888
+ }
1889
+ // @__NO_SIDE_EFFECTS__
1890
+ function _isoDate(Class, params) {
1891
+ return new Class({
1892
+ type: "string",
1893
+ format: "date",
1894
+ check: "string_format",
1895
+ ...normalizeParams(params)
1896
+ });
1897
+ }
1898
+ // @__NO_SIDE_EFFECTS__
1899
+ function _isoTime(Class, params) {
1900
+ return new Class({
1901
+ type: "string",
1902
+ format: "time",
1903
+ check: "string_format",
1904
+ precision: null,
1905
+ ...normalizeParams(params)
1906
+ });
1907
+ }
1908
+ // @__NO_SIDE_EFFECTS__
1909
+ function _isoDuration(Class, params) {
1910
+ return new Class({
1911
+ type: "string",
1912
+ format: "duration",
1913
+ check: "string_format",
1914
+ ...normalizeParams(params)
1915
+ });
1916
+ }
1917
+ // @__NO_SIDE_EFFECTS__
1918
+ function _maxLength(maximum, params) {
1919
+ return new $ZodCheckMaxLength({
1920
+ check: "max_length",
1921
+ ...normalizeParams(params),
1922
+ maximum
1923
+ });
1924
+ }
1925
+ // @__NO_SIDE_EFFECTS__
1926
+ function _minLength(minimum, params) {
1927
+ return new $ZodCheckMinLength({
1928
+ check: "min_length",
1929
+ ...normalizeParams(params),
1930
+ minimum
1931
+ });
1932
+ }
1933
+ // @__NO_SIDE_EFFECTS__
1934
+ function _length(length, params) {
1935
+ return new $ZodCheckLengthEquals({
1936
+ check: "length_equals",
1937
+ ...normalizeParams(params),
1938
+ length
1939
+ });
1940
+ }
1941
+ // @__NO_SIDE_EFFECTS__
1942
+ function _regex(pattern, params) {
1943
+ return new $ZodCheckRegex({
1944
+ check: "string_format",
1945
+ format: "regex",
1946
+ ...normalizeParams(params),
1947
+ pattern
1948
+ });
1949
+ }
1950
+ // @__NO_SIDE_EFFECTS__
1951
+ function _lowercase(params) {
1952
+ return new $ZodCheckLowerCase({
1953
+ check: "string_format",
1954
+ format: "lowercase",
1955
+ ...normalizeParams(params)
1956
+ });
1957
+ }
1958
+ // @__NO_SIDE_EFFECTS__
1959
+ function _uppercase(params) {
1960
+ return new $ZodCheckUpperCase({
1961
+ check: "string_format",
1962
+ format: "uppercase",
1963
+ ...normalizeParams(params)
1964
+ });
1965
+ }
1966
+ // @__NO_SIDE_EFFECTS__
1967
+ function _includes(includes, params) {
1968
+ return new $ZodCheckIncludes({
1969
+ check: "string_format",
1970
+ format: "includes",
1971
+ ...normalizeParams(params),
1972
+ includes
1973
+ });
1974
+ }
1975
+ // @__NO_SIDE_EFFECTS__
1976
+ function _startsWith(prefix, params) {
1977
+ return new $ZodCheckStartsWith({
1978
+ check: "string_format",
1979
+ format: "starts_with",
1980
+ ...normalizeParams(params),
1981
+ prefix
1982
+ });
1983
+ }
1984
+ // @__NO_SIDE_EFFECTS__
1985
+ function _endsWith(suffix, params) {
1986
+ return new $ZodCheckEndsWith({
1987
+ check: "string_format",
1988
+ format: "ends_with",
1989
+ ...normalizeParams(params),
1990
+ suffix
1991
+ });
1992
+ }
1993
+ // @__NO_SIDE_EFFECTS__
1994
+ function _overwrite(tx) {
1995
+ return new $ZodCheckOverwrite({
1996
+ check: "overwrite",
1997
+ tx
1998
+ });
1999
+ }
2000
+ // @__NO_SIDE_EFFECTS__
2001
+ function _normalize(form) {
2002
+ return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
2003
+ }
2004
+ // @__NO_SIDE_EFFECTS__
2005
+ function _trim() {
2006
+ return /* @__PURE__ */ _overwrite((input) => input.trim());
2007
+ }
2008
+ // @__NO_SIDE_EFFECTS__
2009
+ function _toLowerCase() {
2010
+ return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
2011
+ }
2012
+ // @__NO_SIDE_EFFECTS__
2013
+ function _toUpperCase() {
2014
+ return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
2015
+ }
2016
+ // @__NO_SIDE_EFFECTS__
2017
+ function _slugify() {
2018
+ return /* @__PURE__ */ _overwrite((input) => slugify(input));
2019
+ }
2020
+ // @__NO_SIDE_EFFECTS__
2021
+ function _array(Class, element, params) {
2022
+ return new Class({
2023
+ type: "array",
2024
+ element,
2025
+ ...normalizeParams(params)
2026
+ });
2027
+ }
2028
+ // @__NO_SIDE_EFFECTS__
2029
+ function _refine(Class, fn, _params) {
2030
+ return new Class({
2031
+ type: "custom",
2032
+ check: "custom",
2033
+ fn,
2034
+ ...normalizeParams(_params)
2035
+ });
2036
+ }
2037
+ // @__NO_SIDE_EFFECTS__
2038
+ function _superRefine(fn, params) {
2039
+ const ch = /* @__PURE__ */ _check((payload) => {
2040
+ payload.addIssue = (issue$2) => {
2041
+ if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
2042
+ else {
2043
+ const _issue = issue$2;
2044
+ if (_issue.fatal) _issue.continue = false;
2045
+ _issue.code ?? (_issue.code = "custom");
2046
+ _issue.input ?? (_issue.input = payload.value);
2047
+ _issue.inst ?? (_issue.inst = ch);
2048
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2049
+ payload.issues.push(issue(_issue));
2050
+ }
2051
+ };
2052
+ return fn(payload.value, payload);
2053
+ }, params);
2054
+ return ch;
2055
+ }
2056
+ // @__NO_SIDE_EFFECTS__
2057
+ function _check(fn, params) {
2058
+ const ch = new $ZodCheck({
2059
+ check: "custom",
2060
+ ...normalizeParams(params)
2061
+ });
2062
+ ch._zod.check = fn;
2063
+ return ch;
2064
+ }
2065
+ //#endregion
2066
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/to-json-schema.js
2067
+ function initializeContext(params) {
2068
+ let target = params?.target ?? "draft-2020-12";
2069
+ if (target === "draft-4") target = "draft-04";
2070
+ if (target === "draft-7") target = "draft-07";
2071
+ return {
2072
+ processors: params.processors ?? {},
2073
+ metadataRegistry: params?.metadata ?? globalRegistry,
2074
+ target,
2075
+ unrepresentable: params?.unrepresentable ?? "throw",
2076
+ override: params?.override ?? (() => {}),
2077
+ io: params?.io ?? "output",
2078
+ counter: 0,
2079
+ seen: /* @__PURE__ */ new Map(),
2080
+ cycles: params?.cycles ?? "ref",
2081
+ reused: params?.reused ?? "inline",
2082
+ external: params?.external ?? void 0
2083
+ };
2084
+ }
2085
+ function process$1(schema, ctx, _params = {
2086
+ path: [],
2087
+ schemaPath: []
2088
+ }) {
2089
+ var _a;
2090
+ const def = schema._zod.def;
2091
+ const seen = ctx.seen.get(schema);
2092
+ if (seen) {
2093
+ seen.count++;
2094
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
2095
+ return seen.schema;
2096
+ }
2097
+ const result = {
2098
+ schema: {},
2099
+ count: 1,
2100
+ cycle: void 0,
2101
+ path: _params.path
2102
+ };
2103
+ ctx.seen.set(schema, result);
2104
+ const overrideSchema = schema._zod.toJSONSchema?.();
2105
+ if (overrideSchema) result.schema = overrideSchema;
2106
+ else {
2107
+ const params = {
2108
+ ..._params,
2109
+ schemaPath: [..._params.schemaPath, schema],
2110
+ path: _params.path
2111
+ };
2112
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
2113
+ else {
2114
+ const _json = result.schema;
2115
+ const processor = ctx.processors[def.type];
2116
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2117
+ processor(schema, ctx, _json, params);
2118
+ }
2119
+ const parent = schema._zod.parent;
2120
+ if (parent) {
2121
+ if (!result.ref) result.ref = parent;
2122
+ process$1(parent, ctx, params);
2123
+ ctx.seen.get(parent).isParent = true;
2124
+ }
2125
+ }
2126
+ const meta = ctx.metadataRegistry.get(schema);
2127
+ if (meta) Object.assign(result.schema, meta);
2128
+ if (ctx.io === "input" && isTransforming(schema)) {
2129
+ delete result.schema.examples;
2130
+ delete result.schema.default;
2131
+ }
2132
+ if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
2133
+ delete result.schema._prefault;
2134
+ return ctx.seen.get(schema).schema;
2135
+ }
2136
+ function extractDefs(ctx, schema) {
2137
+ const root = ctx.seen.get(schema);
2138
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2139
+ const idToSchema = /* @__PURE__ */ new Map();
2140
+ for (const entry of ctx.seen.entries()) {
2141
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2142
+ if (id) {
2143
+ const existing = idToSchema.get(id);
2144
+ if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
2145
+ idToSchema.set(id, entry[0]);
2146
+ }
2147
+ }
2148
+ const makeURI = (entry) => {
2149
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2150
+ if (ctx.external) {
2151
+ const externalId = ctx.external.registry.get(entry[0])?.id;
2152
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
2153
+ if (externalId) return { ref: uriGenerator(externalId) };
2154
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2155
+ entry[1].defId = id;
2156
+ return {
2157
+ defId: id,
2158
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
2159
+ };
2160
+ }
2161
+ if (entry[1] === root) return { ref: "#" };
2162
+ const defUriPrefix = `#/${defsSegment}/`;
2163
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2164
+ return {
2165
+ defId,
2166
+ ref: defUriPrefix + defId
2167
+ };
2168
+ };
2169
+ const extractToDef = (entry) => {
2170
+ if (entry[1].schema.$ref) return;
2171
+ const seen = entry[1];
2172
+ const { ref, defId } = makeURI(entry);
2173
+ seen.def = { ...seen.schema };
2174
+ if (defId) seen.defId = defId;
2175
+ const schema = seen.schema;
2176
+ for (const key in schema) delete schema[key];
2177
+ schema.$ref = ref;
2178
+ };
2179
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
2180
+ const seen = entry[1];
2181
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
2182
+
2183
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2184
+ }
2185
+ for (const entry of ctx.seen.entries()) {
2186
+ const seen = entry[1];
2187
+ if (schema === entry[0]) {
2188
+ extractToDef(entry);
2189
+ continue;
2190
+ }
2191
+ if (ctx.external) {
2192
+ const ext = ctx.external.registry.get(entry[0])?.id;
2193
+ if (schema !== entry[0] && ext) {
2194
+ extractToDef(entry);
2195
+ continue;
2196
+ }
2197
+ }
2198
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
2199
+ extractToDef(entry);
2200
+ continue;
2201
+ }
2202
+ if (seen.cycle) {
2203
+ extractToDef(entry);
2204
+ continue;
2205
+ }
2206
+ if (seen.count > 1) {
2207
+ if (ctx.reused === "ref") {
2208
+ extractToDef(entry);
2209
+ continue;
2210
+ }
2211
+ }
2212
+ }
2213
+ }
2214
+ function finalize(ctx, schema) {
2215
+ const root = ctx.seen.get(schema);
2216
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2217
+ const flattenRef = (zodSchema) => {
2218
+ const seen = ctx.seen.get(zodSchema);
2219
+ if (seen.ref === null) return;
2220
+ const schema = seen.def ?? seen.schema;
2221
+ const _cached = { ...schema };
2222
+ const ref = seen.ref;
2223
+ seen.ref = null;
2224
+ if (ref) {
2225
+ flattenRef(ref);
2226
+ const refSeen = ctx.seen.get(ref);
2227
+ const refSchema = refSeen.schema;
2228
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2229
+ schema.allOf = schema.allOf ?? [];
2230
+ schema.allOf.push(refSchema);
2231
+ } else Object.assign(schema, refSchema);
2232
+ Object.assign(schema, _cached);
2233
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
2234
+ if (key === "$ref" || key === "allOf") continue;
2235
+ if (!(key in _cached)) delete schema[key];
2236
+ }
2237
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
2238
+ if (key === "$ref" || key === "allOf") continue;
2239
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
2240
+ }
2241
+ }
2242
+ const parent = zodSchema._zod.parent;
2243
+ if (parent && parent !== ref) {
2244
+ flattenRef(parent);
2245
+ const parentSeen = ctx.seen.get(parent);
2246
+ if (parentSeen?.schema.$ref) {
2247
+ schema.$ref = parentSeen.schema.$ref;
2248
+ if (parentSeen.def) for (const key in schema) {
2249
+ if (key === "$ref" || key === "allOf") continue;
2250
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
2251
+ }
2252
+ }
2253
+ }
2254
+ ctx.override({
2255
+ zodSchema,
2256
+ jsonSchema: schema,
2257
+ path: seen.path ?? []
2258
+ });
2259
+ };
2260
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
2261
+ const result = {};
2262
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
2263
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
2264
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
2265
+ else if (ctx.target === "openapi-3.0") {}
2266
+ if (ctx.external?.uri) {
2267
+ const id = ctx.external.registry.get(schema)?.id;
2268
+ if (!id) throw new Error("Schema is missing an `id` property");
2269
+ result.$id = ctx.external.uri(id);
2270
+ }
2271
+ Object.assign(result, root.def ?? root.schema);
2272
+ const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
2273
+ if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
2274
+ const defs = ctx.external?.defs ?? {};
2275
+ for (const entry of ctx.seen.entries()) {
2276
+ const seen = entry[1];
2277
+ if (seen.def && seen.defId) {
2278
+ if (seen.def.id === seen.defId) delete seen.def.id;
2279
+ defs[seen.defId] = seen.def;
2280
+ }
2281
+ }
2282
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
2283
+ else result.definitions = defs;
2284
+ try {
2285
+ const finalized = JSON.parse(JSON.stringify(result));
2286
+ Object.defineProperty(finalized, "~standard", {
2287
+ value: {
2288
+ ...schema["~standard"],
2289
+ jsonSchema: {
2290
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
2291
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
2292
+ }
2293
+ },
2294
+ enumerable: false,
2295
+ writable: false
2296
+ });
2297
+ return finalized;
2298
+ } catch (_err) {
2299
+ throw new Error("Error converting schema to JSON.");
2300
+ }
2301
+ }
2302
+ function isTransforming(_schema, _ctx) {
2303
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
2304
+ if (ctx.seen.has(_schema)) return false;
2305
+ ctx.seen.add(_schema);
2306
+ const def = _schema._zod.def;
2307
+ if (def.type === "transform") return true;
2308
+ if (def.type === "array") return isTransforming(def.element, ctx);
2309
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
2310
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
2311
+ if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
2312
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
2313
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
2314
+ if (def.type === "pipe") {
2315
+ if (_schema._zod.traits.has("$ZodCodec")) return true;
2316
+ return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
2317
+ }
2318
+ if (def.type === "object") {
2319
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
2320
+ return false;
2321
+ }
2322
+ if (def.type === "union") {
2323
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
2324
+ return false;
2325
+ }
2326
+ if (def.type === "tuple") {
2327
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
2328
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
2329
+ return false;
2330
+ }
2331
+ return false;
2332
+ }
2333
+ /**
2334
+ * Creates a toJSONSchema method for a schema instance.
2335
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
2336
+ */
2337
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
2338
+ const ctx = initializeContext({
2339
+ ...params,
2340
+ processors
2341
+ });
2342
+ process$1(schema, ctx);
2343
+ extractDefs(ctx, schema);
2344
+ return finalize(ctx, schema);
2345
+ };
2346
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
2347
+ const { libraryOptions, target } = params ?? {};
2348
+ const ctx = initializeContext({
2349
+ ...libraryOptions ?? {},
2350
+ target,
2351
+ io,
2352
+ processors
2353
+ });
2354
+ process$1(schema, ctx);
2355
+ extractDefs(ctx, schema);
2356
+ return finalize(ctx, schema);
2357
+ };
2358
+ //#endregion
2359
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/json-schema-processors.js
2360
+ const formatMap = {
2361
+ guid: "uuid",
2362
+ url: "uri",
2363
+ datetime: "date-time",
2364
+ json_string: "json-string",
2365
+ regex: ""
2366
+ };
2367
+ const stringProcessor = (schema, ctx, _json, _params) => {
2368
+ const json = _json;
2369
+ json.type = "string";
2370
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
2371
+ if (typeof minimum === "number") json.minLength = minimum;
2372
+ if (typeof maximum === "number") json.maxLength = maximum;
2373
+ if (format) {
2374
+ json.format = formatMap[format] ?? format;
2375
+ if (json.format === "") delete json.format;
2376
+ if (format === "time") delete json.format;
2377
+ }
2378
+ if (contentEncoding) json.contentEncoding = contentEncoding;
2379
+ if (patterns && patterns.size > 0) {
2380
+ const regexes = [...patterns];
2381
+ if (regexes.length === 1) json.pattern = regexes[0].source;
2382
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
2383
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
2384
+ pattern: regex.source
2385
+ }))];
2386
+ }
2387
+ };
2388
+ const customProcessor = (_schema, ctx, _json, _params) => {
2389
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
2390
+ };
2391
+ const transformProcessor = (_schema, ctx, _json, _params) => {
2392
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
2393
+ };
2394
+ const arrayProcessor = (schema, ctx, _json, params) => {
2395
+ const json = _json;
2396
+ const def = schema._zod.def;
2397
+ const { minimum, maximum } = schema._zod.bag;
2398
+ if (typeof minimum === "number") json.minItems = minimum;
2399
+ if (typeof maximum === "number") json.maxItems = maximum;
2400
+ json.type = "array";
2401
+ json.items = process$1(def.element, ctx, {
2402
+ ...params,
2403
+ path: [...params.path, "items"]
2404
+ });
2405
+ };
2406
+ const unionProcessor = (schema, ctx, json, params) => {
2407
+ const def = schema._zod.def;
2408
+ const isExclusive = def.inclusive === false;
2409
+ const options = def.options.map((x, i) => process$1(x, ctx, {
2410
+ ...params,
2411
+ path: [
2412
+ ...params.path,
2413
+ isExclusive ? "oneOf" : "anyOf",
2414
+ i
2415
+ ]
2416
+ }));
2417
+ if (isExclusive) json.oneOf = options;
2418
+ else json.anyOf = options;
2419
+ };
2420
+ const intersectionProcessor = (schema, ctx, json, params) => {
2421
+ const def = schema._zod.def;
2422
+ const a = process$1(def.left, ctx, {
2423
+ ...params,
2424
+ path: [
2425
+ ...params.path,
2426
+ "allOf",
2427
+ 0
2428
+ ]
2429
+ });
2430
+ const b = process$1(def.right, ctx, {
2431
+ ...params,
2432
+ path: [
2433
+ ...params.path,
2434
+ "allOf",
2435
+ 1
2436
+ ]
2437
+ });
2438
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
2439
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
2440
+ };
2441
+ const nullableProcessor = (schema, ctx, json, params) => {
2442
+ const def = schema._zod.def;
2443
+ const inner = process$1(def.innerType, ctx, params);
2444
+ const seen = ctx.seen.get(schema);
2445
+ if (ctx.target === "openapi-3.0") {
2446
+ seen.ref = def.innerType;
2447
+ json.nullable = true;
2448
+ } else json.anyOf = [inner, { type: "null" }];
2449
+ };
2450
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
2451
+ const def = schema._zod.def;
2452
+ process$1(def.innerType, ctx, params);
2453
+ const seen = ctx.seen.get(schema);
2454
+ seen.ref = def.innerType;
2455
+ };
2456
+ const defaultProcessor = (schema, ctx, json, params) => {
2457
+ const def = schema._zod.def;
2458
+ process$1(def.innerType, ctx, params);
2459
+ const seen = ctx.seen.get(schema);
2460
+ seen.ref = def.innerType;
2461
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
2462
+ };
2463
+ const prefaultProcessor = (schema, ctx, json, params) => {
2464
+ const def = schema._zod.def;
2465
+ process$1(def.innerType, ctx, params);
2466
+ const seen = ctx.seen.get(schema);
2467
+ seen.ref = def.innerType;
2468
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
2469
+ };
2470
+ const catchProcessor = (schema, ctx, json, params) => {
2471
+ const def = schema._zod.def;
2472
+ process$1(def.innerType, ctx, params);
2473
+ const seen = ctx.seen.get(schema);
2474
+ seen.ref = def.innerType;
2475
+ let catchValue;
2476
+ try {
2477
+ catchValue = def.catchValue(void 0);
2478
+ } catch {
2479
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
2480
+ }
2481
+ json.default = catchValue;
2482
+ };
2483
+ const pipeProcessor = (schema, ctx, _json, params) => {
2484
+ const def = schema._zod.def;
2485
+ const inIsTransform = def.in._zod.traits.has("$ZodTransform");
2486
+ const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
2487
+ process$1(innerType, ctx, params);
2488
+ const seen = ctx.seen.get(schema);
2489
+ seen.ref = innerType;
2490
+ };
2491
+ const readonlyProcessor = (schema, ctx, json, params) => {
2492
+ const def = schema._zod.def;
2493
+ process$1(def.innerType, ctx, params);
2494
+ const seen = ctx.seen.get(schema);
2495
+ seen.ref = def.innerType;
2496
+ json.readOnly = true;
2497
+ };
2498
+ const optionalProcessor = (schema, ctx, _json, params) => {
2499
+ const def = schema._zod.def;
2500
+ process$1(def.innerType, ctx, params);
2501
+ const seen = ctx.seen.get(schema);
2502
+ seen.ref = def.innerType;
2503
+ };
2504
+ //#endregion
2505
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/iso.js
2506
+ const ZodISODateTime = /*@__PURE__*/ $constructor("ZodISODateTime", (inst, def) => {
2507
+ $ZodISODateTime.init(inst, def);
2508
+ ZodStringFormat.init(inst, def);
2509
+ });
2510
+ function datetime(params) {
2511
+ return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
2512
+ }
2513
+ const ZodISODate = /*@__PURE__*/ $constructor("ZodISODate", (inst, def) => {
2514
+ $ZodISODate.init(inst, def);
2515
+ ZodStringFormat.init(inst, def);
2516
+ });
2517
+ function date(params) {
2518
+ return /* @__PURE__ */ _isoDate(ZodISODate, params);
2519
+ }
2520
+ const ZodISOTime = /*@__PURE__*/ $constructor("ZodISOTime", (inst, def) => {
2521
+ $ZodISOTime.init(inst, def);
2522
+ ZodStringFormat.init(inst, def);
2523
+ });
2524
+ function time(params) {
2525
+ return /* @__PURE__ */ _isoTime(ZodISOTime, params);
2526
+ }
2527
+ const ZodISODuration = /*@__PURE__*/ $constructor("ZodISODuration", (inst, def) => {
2528
+ $ZodISODuration.init(inst, def);
2529
+ ZodStringFormat.init(inst, def);
2530
+ });
2531
+ function duration(params) {
2532
+ return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
2533
+ }
2534
+ //#endregion
2535
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/errors.js
2536
+ const initializer = (inst, issues) => {
2537
+ $ZodError.init(inst, issues);
2538
+ inst.name = "ZodError";
2539
+ Object.defineProperties(inst, {
2540
+ format: { value: (mapper) => formatError(inst, mapper) },
2541
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
2542
+ addIssue: { value: (issue) => {
2543
+ inst.issues.push(issue);
2544
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
2545
+ } },
2546
+ addIssues: { value: (issues) => {
2547
+ inst.issues.push(...issues);
2548
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
2549
+ } },
2550
+ isEmpty: { get() {
2551
+ return inst.issues.length === 0;
2552
+ } }
2553
+ });
2554
+ };
2555
+ const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, { Parent: Error });
2556
+ //#endregion
2557
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/parse.js
2558
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
2559
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
2560
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
2561
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
2562
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
2563
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
2564
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
2565
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
2566
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
2567
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
2568
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
2569
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
2570
+ //#endregion
2571
+ //#region ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/classic/schemas.js
2572
+ const _installedGroups = /* @__PURE__ */ new WeakMap();
2573
+ function _installLazyMethods(inst, group, methods) {
2574
+ const proto = Object.getPrototypeOf(inst);
2575
+ let installed = _installedGroups.get(proto);
2576
+ if (!installed) {
2577
+ installed = /* @__PURE__ */ new Set();
2578
+ _installedGroups.set(proto, installed);
2579
+ }
2580
+ if (installed.has(group)) return;
2581
+ installed.add(group);
2582
+ for (const key in methods) {
2583
+ const fn = methods[key];
2584
+ Object.defineProperty(proto, key, {
2585
+ configurable: true,
2586
+ enumerable: false,
2587
+ get() {
2588
+ const bound = fn.bind(this);
2589
+ Object.defineProperty(this, key, {
2590
+ configurable: true,
2591
+ writable: true,
2592
+ enumerable: true,
2593
+ value: bound
2594
+ });
2595
+ return bound;
2596
+ },
2597
+ set(v) {
2598
+ Object.defineProperty(this, key, {
2599
+ configurable: true,
2600
+ writable: true,
2601
+ enumerable: true,
2602
+ value: v
2603
+ });
2604
+ }
2605
+ });
2606
+ }
2607
+ }
2608
+ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
2609
+ $ZodType.init(inst, def);
2610
+ Object.assign(inst["~standard"], { jsonSchema: {
2611
+ input: createStandardJSONSchemaMethod(inst, "input"),
2612
+ output: createStandardJSONSchemaMethod(inst, "output")
2613
+ } });
2614
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
2615
+ inst.def = def;
2616
+ inst.type = def.type;
2617
+ Object.defineProperty(inst, "_def", { value: def });
2618
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
2619
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
2620
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
2621
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
2622
+ inst.spa = inst.safeParseAsync;
2623
+ inst.encode = (data, params) => encode(inst, data, params);
2624
+ inst.decode = (data, params) => decode(inst, data, params);
2625
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
2626
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
2627
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
2628
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
2629
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
2630
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
2631
+ _installLazyMethods(inst, "ZodType", {
2632
+ check(...chks) {
2633
+ const def = this.def;
2634
+ return this.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...chks.map((ch) => typeof ch === "function" ? { _zod: {
2635
+ check: ch,
2636
+ def: { check: "custom" },
2637
+ onattach: []
2638
+ } } : ch)] }), { parent: true });
2639
+ },
2640
+ with(...chks) {
2641
+ return this.check(...chks);
2642
+ },
2643
+ clone(def, params) {
2644
+ return clone(this, def, params);
2645
+ },
2646
+ brand() {
2647
+ return this;
2648
+ },
2649
+ register(reg, meta) {
2650
+ reg.add(this, meta);
2651
+ return this;
2652
+ },
2653
+ refine(check, params) {
2654
+ return this.check(refine(check, params));
2655
+ },
2656
+ superRefine(refinement, params) {
2657
+ return this.check(superRefine(refinement, params));
2658
+ },
2659
+ overwrite(fn) {
2660
+ return this.check(/* @__PURE__ */ _overwrite(fn));
2661
+ },
2662
+ optional() {
2663
+ return optional(this);
2664
+ },
2665
+ exactOptional() {
2666
+ return exactOptional(this);
2667
+ },
2668
+ nullable() {
2669
+ return nullable(this);
2670
+ },
2671
+ nullish() {
2672
+ return optional(nullable(this));
2673
+ },
2674
+ nonoptional(params) {
2675
+ return nonoptional(this, params);
2676
+ },
2677
+ array() {
2678
+ return array(this);
2679
+ },
2680
+ or(arg) {
2681
+ return union([this, arg]);
2682
+ },
2683
+ and(arg) {
2684
+ return intersection(this, arg);
2685
+ },
2686
+ transform(tx) {
2687
+ return pipe(this, transform(tx));
2688
+ },
2689
+ default(d) {
2690
+ return _default(this, d);
2691
+ },
2692
+ prefault(d) {
2693
+ return prefault(this, d);
2694
+ },
2695
+ catch(params) {
2696
+ return _catch(this, params);
2697
+ },
2698
+ pipe(target) {
2699
+ return pipe(this, target);
2700
+ },
2701
+ readonly() {
2702
+ return readonly(this);
2703
+ },
2704
+ describe(description) {
2705
+ const cl = this.clone();
2706
+ globalRegistry.add(cl, { description });
2707
+ return cl;
2708
+ },
2709
+ meta(...args) {
2710
+ if (args.length === 0) return globalRegistry.get(this);
2711
+ const cl = this.clone();
2712
+ globalRegistry.add(cl, args[0]);
2713
+ return cl;
2714
+ },
2715
+ isOptional() {
2716
+ return this.safeParse(void 0).success;
2717
+ },
2718
+ isNullable() {
2719
+ return this.safeParse(null).success;
2720
+ },
2721
+ apply(fn) {
2722
+ return fn(this);
2723
+ }
2724
+ });
2725
+ Object.defineProperty(inst, "description", {
2726
+ get() {
2727
+ return globalRegistry.get(inst)?.description;
2728
+ },
2729
+ configurable: true
2730
+ });
2731
+ return inst;
2732
+ });
2733
+ /** @internal */
2734
+ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
2735
+ $ZodString.init(inst, def);
2736
+ ZodType.init(inst, def);
2737
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
2738
+ const bag = inst._zod.bag;
2739
+ inst.format = bag.format ?? null;
2740
+ inst.minLength = bag.minimum ?? null;
2741
+ inst.maxLength = bag.maximum ?? null;
2742
+ _installLazyMethods(inst, "_ZodString", {
2743
+ regex(...args) {
2744
+ return this.check(/* @__PURE__ */ _regex(...args));
2745
+ },
2746
+ includes(...args) {
2747
+ return this.check(/* @__PURE__ */ _includes(...args));
2748
+ },
2749
+ startsWith(...args) {
2750
+ return this.check(/* @__PURE__ */ _startsWith(...args));
2751
+ },
2752
+ endsWith(...args) {
2753
+ return this.check(/* @__PURE__ */ _endsWith(...args));
2754
+ },
2755
+ min(...args) {
2756
+ return this.check(/* @__PURE__ */ _minLength(...args));
2757
+ },
2758
+ max(...args) {
2759
+ return this.check(/* @__PURE__ */ _maxLength(...args));
2760
+ },
2761
+ length(...args) {
2762
+ return this.check(/* @__PURE__ */ _length(...args));
2763
+ },
2764
+ nonempty(...args) {
2765
+ return this.check(/* @__PURE__ */ _minLength(1, ...args));
2766
+ },
2767
+ lowercase(params) {
2768
+ return this.check(/* @__PURE__ */ _lowercase(params));
2769
+ },
2770
+ uppercase(params) {
2771
+ return this.check(/* @__PURE__ */ _uppercase(params));
2772
+ },
2773
+ trim() {
2774
+ return this.check(/* @__PURE__ */ _trim());
2775
+ },
2776
+ normalize(...args) {
2777
+ return this.check(/* @__PURE__ */ _normalize(...args));
2778
+ },
2779
+ toLowerCase() {
2780
+ return this.check(/* @__PURE__ */ _toLowerCase());
2781
+ },
2782
+ toUpperCase() {
2783
+ return this.check(/* @__PURE__ */ _toUpperCase());
2784
+ },
2785
+ slugify() {
2786
+ return this.check(/* @__PURE__ */ _slugify());
2787
+ }
2788
+ });
2789
+ });
2790
+ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
2791
+ $ZodString.init(inst, def);
2792
+ _ZodString.init(inst, def);
2793
+ inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
2794
+ inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
2795
+ inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
2796
+ inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
2797
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
2798
+ inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
2799
+ inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
2800
+ inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
2801
+ inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
2802
+ inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
2803
+ inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
2804
+ inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
2805
+ inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
2806
+ inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
2807
+ inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
2808
+ inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
2809
+ inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
2810
+ inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
2811
+ inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
2812
+ inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
2813
+ inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
2814
+ inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
2815
+ inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
2816
+ inst.datetime = (params) => inst.check(datetime(params));
2817
+ inst.date = (params) => inst.check(date(params));
2818
+ inst.time = (params) => inst.check(time(params));
2819
+ inst.duration = (params) => inst.check(duration(params));
2820
+ });
2821
+ function string(params) {
2822
+ return /* @__PURE__ */ _string(ZodString, params);
2823
+ }
2824
+ const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
2825
+ $ZodStringFormat.init(inst, def);
2826
+ _ZodString.init(inst, def);
2827
+ });
2828
+ const ZodEmail = /*@__PURE__*/ $constructor("ZodEmail", (inst, def) => {
2829
+ $ZodEmail.init(inst, def);
2830
+ ZodStringFormat.init(inst, def);
2831
+ });
2832
+ const ZodGUID = /*@__PURE__*/ $constructor("ZodGUID", (inst, def) => {
2833
+ $ZodGUID.init(inst, def);
2834
+ ZodStringFormat.init(inst, def);
2835
+ });
2836
+ const ZodUUID = /*@__PURE__*/ $constructor("ZodUUID", (inst, def) => {
2837
+ $ZodUUID.init(inst, def);
2838
+ ZodStringFormat.init(inst, def);
2839
+ });
2840
+ const ZodURL = /*@__PURE__*/ $constructor("ZodURL", (inst, def) => {
2841
+ $ZodURL.init(inst, def);
2842
+ ZodStringFormat.init(inst, def);
2843
+ });
2844
+ const ZodEmoji = /*@__PURE__*/ $constructor("ZodEmoji", (inst, def) => {
2845
+ $ZodEmoji.init(inst, def);
2846
+ ZodStringFormat.init(inst, def);
2847
+ });
2848
+ const ZodNanoID = /*@__PURE__*/ $constructor("ZodNanoID", (inst, def) => {
2849
+ $ZodNanoID.init(inst, def);
2850
+ ZodStringFormat.init(inst, def);
2851
+ });
2852
+ /**
2853
+ * @deprecated CUID v1 is deprecated by its authors due to information leakage
2854
+ * (timestamps embedded in the id). Use {@link ZodCUID2} instead.
2855
+ * See https://github.com/paralleldrive/cuid.
2856
+ */
2857
+ const ZodCUID = /*@__PURE__*/ $constructor("ZodCUID", (inst, def) => {
2858
+ $ZodCUID.init(inst, def);
2859
+ ZodStringFormat.init(inst, def);
2860
+ });
2861
+ const ZodCUID2 = /*@__PURE__*/ $constructor("ZodCUID2", (inst, def) => {
2862
+ $ZodCUID2.init(inst, def);
2863
+ ZodStringFormat.init(inst, def);
2864
+ });
2865
+ const ZodULID = /*@__PURE__*/ $constructor("ZodULID", (inst, def) => {
2866
+ $ZodULID.init(inst, def);
2867
+ ZodStringFormat.init(inst, def);
2868
+ });
2869
+ const ZodXID = /*@__PURE__*/ $constructor("ZodXID", (inst, def) => {
2870
+ $ZodXID.init(inst, def);
2871
+ ZodStringFormat.init(inst, def);
2872
+ });
2873
+ const ZodKSUID = /*@__PURE__*/ $constructor("ZodKSUID", (inst, def) => {
2874
+ $ZodKSUID.init(inst, def);
2875
+ ZodStringFormat.init(inst, def);
2876
+ });
2877
+ const ZodIPv4 = /*@__PURE__*/ $constructor("ZodIPv4", (inst, def) => {
2878
+ $ZodIPv4.init(inst, def);
2879
+ ZodStringFormat.init(inst, def);
2880
+ });
2881
+ const ZodIPv6 = /*@__PURE__*/ $constructor("ZodIPv6", (inst, def) => {
2882
+ $ZodIPv6.init(inst, def);
2883
+ ZodStringFormat.init(inst, def);
2884
+ });
2885
+ const ZodCIDRv4 = /*@__PURE__*/ $constructor("ZodCIDRv4", (inst, def) => {
2886
+ $ZodCIDRv4.init(inst, def);
2887
+ ZodStringFormat.init(inst, def);
2888
+ });
2889
+ const ZodCIDRv6 = /*@__PURE__*/ $constructor("ZodCIDRv6", (inst, def) => {
2890
+ $ZodCIDRv6.init(inst, def);
2891
+ ZodStringFormat.init(inst, def);
2892
+ });
2893
+ const ZodBase64 = /*@__PURE__*/ $constructor("ZodBase64", (inst, def) => {
2894
+ $ZodBase64.init(inst, def);
2895
+ ZodStringFormat.init(inst, def);
2896
+ });
2897
+ const ZodBase64URL = /*@__PURE__*/ $constructor("ZodBase64URL", (inst, def) => {
2898
+ $ZodBase64URL.init(inst, def);
2899
+ ZodStringFormat.init(inst, def);
2900
+ });
2901
+ const ZodE164 = /*@__PURE__*/ $constructor("ZodE164", (inst, def) => {
2902
+ $ZodE164.init(inst, def);
2903
+ ZodStringFormat.init(inst, def);
2904
+ });
2905
+ const ZodJWT = /*@__PURE__*/ $constructor("ZodJWT", (inst, def) => {
2906
+ $ZodJWT.init(inst, def);
2907
+ ZodStringFormat.init(inst, def);
2908
+ });
2909
+ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
2910
+ $ZodArray.init(inst, def);
2911
+ ZodType.init(inst, def);
2912
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
2913
+ inst.element = def.element;
2914
+ _installLazyMethods(inst, "ZodArray", {
2915
+ min(n, params) {
2916
+ return this.check(/* @__PURE__ */ _minLength(n, params));
2917
+ },
2918
+ nonempty(params) {
2919
+ return this.check(/* @__PURE__ */ _minLength(1, params));
2920
+ },
2921
+ max(n, params) {
2922
+ return this.check(/* @__PURE__ */ _maxLength(n, params));
2923
+ },
2924
+ length(n, params) {
2925
+ return this.check(/* @__PURE__ */ _length(n, params));
2926
+ },
2927
+ unwrap() {
2928
+ return this.element;
2929
+ }
2930
+ });
2931
+ });
2932
+ function array(element, params) {
2933
+ return /* @__PURE__ */ _array(ZodArray, element, params);
2934
+ }
2935
+ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
2936
+ $ZodUnion.init(inst, def);
2937
+ ZodType.init(inst, def);
2938
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
2939
+ inst.options = def.options;
2940
+ });
2941
+ function union(options, params) {
2942
+ return new ZodUnion({
2943
+ type: "union",
2944
+ options,
2945
+ ...normalizeParams(params)
2946
+ });
2947
+ }
2948
+ const ZodIntersection = /*@__PURE__*/ $constructor("ZodIntersection", (inst, def) => {
2949
+ $ZodIntersection.init(inst, def);
2950
+ ZodType.init(inst, def);
2951
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
2952
+ });
2953
+ function intersection(left, right) {
2954
+ return new ZodIntersection({
2955
+ type: "intersection",
2956
+ left,
2957
+ right
2958
+ });
2959
+ }
2960
+ const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
2961
+ $ZodTransform.init(inst, def);
2962
+ ZodType.init(inst, def);
2963
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
2964
+ inst._zod.parse = (payload, _ctx) => {
2965
+ if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
2966
+ payload.addIssue = (issue$1) => {
2967
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
2968
+ else {
2969
+ const _issue = issue$1;
2970
+ if (_issue.fatal) _issue.continue = false;
2971
+ _issue.code ?? (_issue.code = "custom");
2972
+ _issue.input ?? (_issue.input = payload.value);
2973
+ _issue.inst ?? (_issue.inst = inst);
2974
+ payload.issues.push(issue(_issue));
2975
+ }
2976
+ };
2977
+ const output = def.transform(payload.value, payload);
2978
+ if (output instanceof Promise) return output.then((output) => {
2979
+ payload.value = output;
2980
+ payload.fallback = true;
2981
+ return payload;
2982
+ });
2983
+ payload.value = output;
2984
+ payload.fallback = true;
2985
+ return payload;
2986
+ };
2987
+ });
2988
+ function transform(fn) {
2989
+ return new ZodTransform({
2990
+ type: "transform",
2991
+ transform: fn
2992
+ });
2993
+ }
2994
+ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
2995
+ $ZodOptional.init(inst, def);
2996
+ ZodType.init(inst, def);
2997
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
2998
+ inst.unwrap = () => inst._zod.def.innerType;
2999
+ });
3000
+ function optional(innerType) {
3001
+ return new ZodOptional({
3002
+ type: "optional",
3003
+ innerType
3004
+ });
3005
+ }
3006
+ const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
3007
+ $ZodExactOptional.init(inst, def);
3008
+ ZodType.init(inst, def);
3009
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3010
+ inst.unwrap = () => inst._zod.def.innerType;
3011
+ });
3012
+ function exactOptional(innerType) {
3013
+ return new ZodExactOptional({
3014
+ type: "optional",
3015
+ innerType
3016
+ });
3017
+ }
3018
+ const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
3019
+ $ZodNullable.init(inst, def);
3020
+ ZodType.init(inst, def);
3021
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3022
+ inst.unwrap = () => inst._zod.def.innerType;
3023
+ });
3024
+ function nullable(innerType) {
3025
+ return new ZodNullable({
3026
+ type: "nullable",
3027
+ innerType
3028
+ });
3029
+ }
3030
+ const ZodDefault = /*@__PURE__*/ $constructor("ZodDefault", (inst, def) => {
3031
+ $ZodDefault.init(inst, def);
3032
+ ZodType.init(inst, def);
3033
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3034
+ inst.unwrap = () => inst._zod.def.innerType;
3035
+ inst.removeDefault = inst.unwrap;
3036
+ });
3037
+ function _default(innerType, defaultValue) {
3038
+ return new ZodDefault({
3039
+ type: "default",
3040
+ innerType,
3041
+ get defaultValue() {
3042
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3043
+ }
3044
+ });
3045
+ }
3046
+ const ZodPrefault = /*@__PURE__*/ $constructor("ZodPrefault", (inst, def) => {
3047
+ $ZodPrefault.init(inst, def);
3048
+ ZodType.init(inst, def);
3049
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3050
+ inst.unwrap = () => inst._zod.def.innerType;
3051
+ });
3052
+ function prefault(innerType, defaultValue) {
3053
+ return new ZodPrefault({
3054
+ type: "prefault",
3055
+ innerType,
3056
+ get defaultValue() {
3057
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3058
+ }
3059
+ });
3060
+ }
3061
+ const ZodNonOptional = /*@__PURE__*/ $constructor("ZodNonOptional", (inst, def) => {
3062
+ $ZodNonOptional.init(inst, def);
3063
+ ZodType.init(inst, def);
3064
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3065
+ inst.unwrap = () => inst._zod.def.innerType;
3066
+ });
3067
+ function nonoptional(innerType, params) {
3068
+ return new ZodNonOptional({
3069
+ type: "nonoptional",
3070
+ innerType,
3071
+ ...normalizeParams(params)
3072
+ });
3073
+ }
3074
+ const ZodCatch = /*@__PURE__*/ $constructor("ZodCatch", (inst, def) => {
3075
+ $ZodCatch.init(inst, def);
3076
+ ZodType.init(inst, def);
3077
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3078
+ inst.unwrap = () => inst._zod.def.innerType;
3079
+ inst.removeCatch = inst.unwrap;
3080
+ });
3081
+ function _catch(innerType, catchValue) {
3082
+ return new ZodCatch({
3083
+ type: "catch",
3084
+ innerType,
3085
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3086
+ });
3087
+ }
3088
+ const ZodPipe = /*@__PURE__*/ $constructor("ZodPipe", (inst, def) => {
3089
+ $ZodPipe.init(inst, def);
3090
+ ZodType.init(inst, def);
3091
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3092
+ inst.in = def.in;
3093
+ inst.out = def.out;
3094
+ });
3095
+ function pipe(in_, out) {
3096
+ return new ZodPipe({
3097
+ type: "pipe",
3098
+ in: in_,
3099
+ out
3100
+ });
3101
+ }
3102
+ const ZodReadonly = /*@__PURE__*/ $constructor("ZodReadonly", (inst, def) => {
3103
+ $ZodReadonly.init(inst, def);
3104
+ ZodType.init(inst, def);
3105
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3106
+ inst.unwrap = () => inst._zod.def.innerType;
3107
+ });
3108
+ function readonly(innerType) {
3109
+ return new ZodReadonly({
3110
+ type: "readonly",
3111
+ innerType
3112
+ });
3113
+ }
3114
+ const ZodCustom = /*@__PURE__*/ $constructor("ZodCustom", (inst, def) => {
3115
+ $ZodCustom.init(inst, def);
3116
+ ZodType.init(inst, def);
3117
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
3118
+ });
3119
+ function refine(fn, _params = {}) {
3120
+ return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
3121
+ }
3122
+ function superRefine(fn, params) {
3123
+ return /* @__PURE__ */ _superRefine(fn, params);
3124
+ }
3125
+ //#endregion
3126
+ //#region src/commands/init/validate.ts
3127
+ const projectNameSchema = string().min(1, "Project name cannot be empty.").max(214, "Project name must be 214 characters or fewer.").regex(/^[a-z0-9][a-z0-9._-]*$/u, "Project name must start with a lowercase letter or number, and can only contain letters, numbers, dots, hyphens, and underscores.").refine((val) => !/[._-]$/u.test(val), "Project name must not end with a dot, hyphen, or underscore.").refine((val) => !/__/u.test(val), "Project name must not contain consecutive underscores.").refine((val) => !/[._-]{2,}/u.test(val), "Project name must not contain consecutive dots, hyphens, or underscores.");
3128
+ const validateProjectName = (name) => {
3129
+ const result = projectNameSchema.safeParse(name);
3130
+ if (!result.success) return result.error.issues[0]?.message ?? "Invalid project name.";
3131
+ return null;
3132
+ };
3133
+ //#endregion
3134
+ //#region src/commands/init/prompts.ts
3135
+ const isCI = () => process.env.CI === "true" || process.env.CI === "1" || process.env.CIRCLECI === "true" || Boolean(process.env.GITHUB_ACTIONS) || Boolean(process.env.GITLAB_CI);
3136
+ const ciOrYes = (options) => options?.yes === true || isCI();
3137
+ const promptOrSkip = async (prompt, clack) => {
3138
+ const result = await prompt(clack);
3139
+ if (clack.isCancel(result)) {
3140
+ clack.cancel("Cancelled.");
3141
+ process.exit(0);
3142
+ }
3143
+ return result;
3144
+ };
3145
+ const collectPrompts = async (clack, projectDir, options) => {
3146
+ const cwd = process.cwd();
3147
+ let resolvedDir;
3148
+ let projectName;
3149
+ if (projectDir) {
3150
+ resolvedDir = path.resolve(cwd, projectDir);
3151
+ projectName = path.basename(resolvedDir);
3152
+ } else if (ciOrYes(options)) {
3153
+ projectName = "studio-project";
3154
+ resolvedDir = path.resolve(cwd, projectName);
3155
+ } else {
3156
+ projectName = (await promptOrSkip((p) => p.text({
3157
+ defaultValue: "studio-project",
3158
+ message: "What's your project name?",
3159
+ validate: (value) => {
3160
+ const trimmed = value.trim();
3161
+ if (trimmed.length === 0) return "Please enter a project name.";
3162
+ return validateProjectName(trimmed);
3163
+ }
3164
+ }), clack)).trim();
3165
+ resolvedDir = path.resolve(cwd, projectName);
3166
+ }
3167
+ if (!ciOrYes(options) && existsSync(resolvedDir)) {
3168
+ if (!await promptOrSkip((p) => p.confirm({
3169
+ initialValue: false,
3170
+ message: `Directory "${projectName}" already exists. Overwrite?`
3171
+ }), clack)) {
3172
+ clack.cancel("Cancelled.");
3173
+ process.exit(0);
3174
+ }
3175
+ }
3176
+ const templates = ciOrYes(options) ? ["bento-feature"] : await promptOrSkip((p) => p.multiselect({
3177
+ message: "Which templates would you like to scaffold?",
3178
+ options: [{
3179
+ hint: "Apple-style feature card",
3180
+ label: "Bento Feature",
3181
+ value: "bento-feature"
3182
+ }]
3183
+ }), clack);
3184
+ const locales = ciOrYes(options) ? ["en", "ar"] : await promptOrSkip((p) => p.multiselect({
3185
+ message: "Which locales would you like to include?",
3186
+ options: [{
3187
+ label: "English",
3188
+ value: "en"
3189
+ }, {
3190
+ label: "Arabic",
3191
+ value: "ar"
3192
+ }]
3193
+ }), clack);
3194
+ const alreadyInGitRepo = isInsideGitRepo(path.dirname(resolvedDir));
3195
+ let wantsGit = !alreadyInGitRepo && ciOrYes(options);
3196
+ if (!alreadyInGitRepo && !ciOrYes(options)) wantsGit = await promptOrSkip((p) => p.confirm({
3197
+ initialValue: true,
3198
+ message: "Initialize a git repository?"
3199
+ }), clack);
3200
+ const shouldInstall = ciOrYes(options) ? true : await promptOrSkip((p) => p.confirm({
3201
+ initialValue: true,
3202
+ message: "Install dependencies?"
3203
+ }), clack);
3204
+ return {
3205
+ locales,
3206
+ projectName,
3207
+ resolvedDir,
3208
+ shouldInstall,
3209
+ templates,
3210
+ wantsGit
3211
+ };
3212
+ };
3213
+ //#endregion
3214
+ //#region src/commands/init/version.ts
3215
+ const getScaffoldVersion = () => {
3216
+ try {
3217
+ return createRequire(import.meta.url)("@stdout-design/cli/package.json").version;
3218
+ } catch {
3219
+ return "latest";
3220
+ }
3221
+ };
3222
+ //#endregion
3223
+ //#region src/commands/init/scaffold.ts
3224
+ const getConfigTemplate = (version) => `import type { StudioConfig } from "@stdout-design/cli";
3225
+
3226
+ const config: StudioConfig = {
3227
+ scaffoldVersion: "${version}",
3228
+ defaultPreset: "instagram-square",
3229
+ outDir: "./out",
3230
+ presets: [
3231
+ { height: 1080, id: "instagram-square", platform: "instagram", width: 1080 },
3232
+ { height: 1200, id: "x-card", platform: "x", width: 1200 },
3233
+ ],
3234
+ templates: {
3235
+ "bento-feature": {
3236
+ componentPath: "./templates/bento-feature",
3237
+ description: "Apple-style bento feature card.",
3238
+ },
3239
+ },
3240
+ };
3241
+
3242
+ export default config;
3243
+ `;
3244
+ const getPkgJson = (name, version) => ({
3245
+ dependencies: {
3246
+ "@stdout-design/cli": `^${version}`,
3247
+ "takumi-js": "^2.0.2"
3248
+ },
3249
+ name,
3250
+ private: true,
3251
+ scripts: {
3252
+ build: "studio build",
3253
+ dev: "studio dev",
3254
+ export: "studio export"
3255
+ },
3256
+ type: "module"
3257
+ });
3258
+ const templateDir = () => path.resolve(import.meta.dirname, "../../../template");
3259
+ const templatesDir = () => path.resolve(import.meta.dirname, "../../../template/templates");
3260
+ const copyStaticAssets = async (dir) => {
3261
+ const base = templateDir();
3262
+ await cp(path.resolve(base, "tsconfig.json"), path.resolve(dir, "tsconfig.json"));
3263
+ await cp(path.resolve(base, ".gitignore"), path.resolve(dir, ".gitignore"));
3264
+ };
3265
+ const generateConfig = async (dir, version) => {
3266
+ await writeFile(path.resolve(dir, "studio.config.ts"), getConfigTemplate(version));
3267
+ };
3268
+ const generatePackageJson = async (dir, projectName, version) => {
3269
+ await writeFile(path.resolve(dir, "package.json"), JSON.stringify(getPkgJson(projectName, version), null, 2));
3270
+ };
3271
+ const copyTemplateFiles = async (dir, templates) => {
3272
+ if (templates.length === 0) return;
3273
+ const dstTemplatesDir = path.resolve(dir, "templates");
3274
+ await mkdir(dstTemplatesDir, { recursive: true });
3275
+ const srcTemplatesDir = templatesDir();
3276
+ for (const template of templates) if (!existsSync(path.resolve(srcTemplatesDir, `${template}.tsx`))) throw new Error(`Template "${template}" not found at templates/${template}.tsx`);
3277
+ await Promise.all(templates.map((template) => cp(path.resolve(srcTemplatesDir, `${template}.tsx`), path.resolve(dstTemplatesDir, `${template}.tsx`))));
3278
+ };
3279
+ const createLocaleFiles = async (dir, locales) => {
3280
+ if (locales.length === 0) return;
3281
+ const localesDir = path.resolve(dir, "locales");
3282
+ await mkdir(localesDir, { recursive: true });
3283
+ const localeData = {
3284
+ ar: { title: "التطبيق المميز" },
3285
+ en: { title: "Featured App" }
3286
+ };
3287
+ await Promise.all(locales.map((locale) => writeFile(path.resolve(localesDir, `${locale}.json`), JSON.stringify(localeData[locale] ?? { title: "Featured App" }, null, 2))));
3288
+ };
3289
+ const scaffold = async (dir, options) => {
3290
+ if (options.projectName.trim().length === 0) throw new Error("Project name cannot be empty.");
3291
+ const version = getScaffoldVersion();
3292
+ if (!existsSync(dir)) await mkdir(dir, { recursive: true });
3293
+ await copyStaticAssets(dir);
3294
+ await generateConfig(dir, version);
3295
+ await generatePackageJson(dir, options.projectName, version);
3296
+ await copyTemplateFiles(dir, options.templates);
3297
+ await createLocaleFiles(dir, options.locales);
3298
+ };
3299
+ //#endregion
3300
+ //#region src/commands/init.ts
3301
+ const detectPackageManager = async () => {
3302
+ const userAgent = getUserAgent();
3303
+ if (userAgent) return userAgent;
3304
+ const detected = await detect();
3305
+ if (detected) return detected.name;
3306
+ return "npm";
3307
+ };
3308
+ const runInstall = (dir, pm) => {
3309
+ const resolved = resolveCommand(pm, "install", []);
3310
+ if (!resolved) return;
3311
+ const { command, args } = resolved;
3312
+ spawnSync(command, args, {
3313
+ cwd: dir,
3314
+ stdio: "inherit"
3315
+ });
3316
+ };
3317
+ const init = async (projectDir, options) => {
3318
+ const { intro, outro, spinner } = await import("@clack/prompts");
3319
+ intro("studio init");
3320
+ const cwd = process.cwd();
3321
+ if (existsSync(path.resolve(cwd, projectDir ?? ".", "studio.config.ts"))) {
3322
+ console.log("studio.config.ts already exists — skipping scaffold.");
3323
+ outro("Done");
3324
+ return;
3325
+ }
3326
+ const collected = await collectPrompts(await import("@clack/prompts"), projectDir, options);
3327
+ const s = spinner();
3328
+ s.start("Creating project...");
3329
+ await scaffold(collected.resolvedDir, {
3330
+ git: collected.wantsGit,
3331
+ install: collected.shouldInstall,
3332
+ locales: collected.locales,
3333
+ projectName: collected.projectName,
3334
+ templates: collected.templates
3335
+ });
3336
+ s.stop("Project created");
3337
+ if (collected.wantsGit) {
3338
+ const gitSpinner = spinner();
3339
+ gitSpinner.start("Initializing git...");
3340
+ const initialized = tryGitInit(collected.resolvedDir);
3341
+ gitSpinner.stop(initialized ? "Git initialized" : "Git repo already exists or git is not available");
3342
+ }
3343
+ const pm = await detectPackageManager();
3344
+ if (collected.shouldInstall) {
3345
+ const installSpinner = spinner();
3346
+ installSpinner.start("Installing dependencies...");
3347
+ runInstall(collected.resolvedDir, pm);
3348
+ installSpinner.stop("Dependencies installed");
3349
+ }
3350
+ console.log("");
3351
+ console.log(` Created project at ${collected.resolvedDir}`);
3352
+ console.log("");
3353
+ console.log(" Next steps:");
3354
+ console.log(` cd ${path.relative(cwd, collected.resolvedDir) || "."}`);
3355
+ console.log(` ${pm} run dev`);
3356
+ console.log("");
3357
+ outro("Done");
3358
+ };
3359
+ //#endregion
3360
+ //#region src/commands/lint.ts
3361
+ const lint = (_rootDir) => {
3362
+ console.error("Lint command not yet implemented. Coming in a future release.");
3363
+ process.exit(1);
3364
+ };
3365
+ //#endregion
3366
+ //#region src/lib/prop-parser.ts
3367
+ const coerceValue = (value, type, _items) => {
3368
+ switch (type) {
3369
+ case "number": {
3370
+ const n = Number(value);
3371
+ return Number.isNaN(n) ? value : n;
3372
+ }
3373
+ case "boolean":
3374
+ if (value === "true" || value === "1") return true;
3375
+ if (value === "false" || value === "0") return false;
3376
+ return value;
3377
+ case "array":
3378
+ if (value.startsWith("[") && value.endsWith("]")) try {
3379
+ return JSON.parse(value);
3380
+ } catch {
3381
+ return value.split(",").map((s) => s.trim());
3382
+ }
3383
+ return value.split(",").map((s) => s.trim());
3384
+ default: return value;
3385
+ }
3386
+ };
3387
+ const parsePropArgs = (args, schema) => {
3388
+ const props = {};
3389
+ const properties = schema.properties ?? {};
3390
+ for (const arg of args) {
3391
+ const eqIndex = arg.indexOf("=");
3392
+ if (eqIndex === -1) {
3393
+ props[arg] = true;
3394
+ continue;
3395
+ }
3396
+ const key = arg.slice(0, eqIndex);
3397
+ const value = arg.slice(eqIndex + 1);
3398
+ const field = properties[key];
3399
+ props[key] = field ? coerceValue(value, field.type, field.items) : value;
3400
+ }
3401
+ return props;
3402
+ };
3403
+ const mergeDefaultProps = (schema, props) => {
3404
+ const properties = schema.properties ?? {};
3405
+ const merged = {};
3406
+ for (const [key, field] of Object.entries(properties)) if (field.default !== void 0) merged[key] = field.default;
3407
+ return {
3408
+ ...merged,
3409
+ ...props
3410
+ };
3411
+ };
3412
+ //#endregion
3413
+ //#region src/lib/suggest.ts
3414
+ const levenshteinDistance = (a, b) => {
3415
+ const aLen = a.length;
3416
+ const bLen = b.length;
3417
+ if (aLen === 0) return bLen;
3418
+ if (bLen === 0) return aLen;
3419
+ let prev = Array.from({ length: aLen + 1 }, (_, j) => j);
3420
+ let curr = Array.from({ length: aLen + 1 }).fill(0);
3421
+ for (let j = 1; j <= bLen; j += 1) {
3422
+ curr[0] = j;
3423
+ for (let i = 1; i <= aLen; i += 1) {
3424
+ const cost = b[j - 1] === a[i - 1] ? 0 : 1;
3425
+ curr[i] = Math.min((prev[i] ?? 0) + 1, (curr[i - 1] ?? 0) + 1, (prev[i - 1] ?? 0) + cost);
3426
+ }
3427
+ const tmp = prev;
3428
+ prev = curr;
3429
+ curr = tmp;
3430
+ }
3431
+ return prev[aLen] ?? 0;
3432
+ };
3433
+ const suggestClosest = (input, candidates, maxDistance = 3) => {
3434
+ let best;
3435
+ let bestDistance = Infinity;
3436
+ for (const candidate of candidates) {
3437
+ const dist = levenshteinDistance(input.toLowerCase(), candidate.toLowerCase());
3438
+ if (dist < bestDistance && dist <= maxDistance) {
3439
+ bestDistance = dist;
3440
+ best = candidate;
3441
+ }
3442
+ }
3443
+ return best;
3444
+ };
3445
+ //#endregion
3446
+ //#region src/commands/resolver.ts
3447
+ const resolveTemplate = (config, templateId) => {
3448
+ const entry = config.templates[templateId];
3449
+ if (!entry) {
3450
+ const candidates = Object.keys(config.templates);
3451
+ const suggestion = suggestClosest(templateId, candidates);
3452
+ const hint = suggestion ? ` Did you mean "${suggestion}"?` : "";
3453
+ throw new AppError(ErrorCode.TEMPLATE_NOT_FOUND, `Template "${templateId}" not found in studio.config.ts.${hint}`, {
3454
+ availableTemplates: candidates,
3455
+ templateId
3456
+ });
3457
+ }
3458
+ return {
3459
+ componentPath: entry.componentPath,
3460
+ templateId
3461
+ };
3462
+ };
3463
+ const resolveBatchOptions = (config, options) => {
3464
+ const presetIds = options?.preset ? options.preset.split(",").map((s) => s.trim()) : config.presets.map((p) => p.id);
3465
+ const localeIds = options?.locale ? options.locale.split(",").map((s) => s.trim()) : void 0;
3466
+ return {
3467
+ concurrency: Number(options?.concurrency ?? "4"),
3468
+ dataFile: options?.data,
3469
+ failFast: options?.failFast,
3470
+ locales: localeIds,
3471
+ outDir: options?.outDir ?? config.outDir ?? "out",
3472
+ presets: presetIds
3473
+ };
3474
+ };
3475
+ //#endregion
3476
+ //#region src/commands/render.ts
3477
+ const render = async (templateId, propArgs, options) => {
3478
+ const rootDir = process.cwd();
3479
+ const config = await loadConfig(rootDir);
3480
+ const { module } = await importTemplateForBatch(rootDir, resolveTemplate(config, templateId).componentPath, templateId);
3481
+ const schema = zodToJsonSchemaShape(module.propsSchema);
3482
+ const mergedProps = mergeDefaultProps(schema, parsePropArgs(propArgs, schema));
3483
+ const batchOpts = resolveBatchOptions(config, options);
3484
+ const { manifest } = await runBatch({
3485
+ baseProps: mergedProps,
3486
+ concurrency: batchOpts.concurrency,
3487
+ dataFile: batchOpts.dataFile,
3488
+ failFast: batchOpts.failFast,
3489
+ locales: batchOpts.locales,
3490
+ outDir: batchOpts.outDir,
3491
+ presets: batchOpts.presets,
3492
+ rootDir,
3493
+ rows: batchOpts.dataFile ? void 0 : [{}],
3494
+ templateId
3495
+ });
3496
+ if (options.json) console.log(JSON.stringify(manifest, null, 2));
3497
+ else console.log(formatManifestSummary(manifest));
3498
+ if (manifest.failed.length > 0) process.exit(1);
3499
+ };
8
3500
  //#endregion
9
3501
  //#region src/lib/runner.ts
3502
+ const handlers = {
3503
+ cache: cacheStats,
3504
+ cacheClean,
3505
+ cacheStats,
3506
+ dev,
3507
+ init,
3508
+ lint,
3509
+ render
3510
+ };
10
3511
  const run = (moduleName, handlerName) => async (...args) => {
11
3512
  try {
12
- const mod = await import(`../commands/${moduleName}.js`);
13
- await (handlerName ? mod[handlerName] : mod[moduleName])(...args);
3513
+ const handler = handlerName ? handlers[handlerName] : handlers[moduleName];
3514
+ if (!handler) throw new Error(`Unknown command: ${handlerName ?? moduleName}`);
3515
+ await handler(...args);
14
3516
  } catch (error) {
15
- console.error(formatError(error));
3517
+ console.error(formatError$1(error));
16
3518
  process.exit(1);
17
3519
  }
18
3520
  };