@rexeus/typeweaver 0.5.0 → 0.6.0

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.
@@ -0,0 +1,4250 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { Command } from "commander";
6
+ import { PluginContextBuilder, PluginRegistry } from "@rexeus/typeweaver-gen";
7
+ import TypesPlugin from "@rexeus/typeweaver-types";
8
+ import { render } from "ejs";
9
+ import { HttpMethod, HttpOperationDefinition, HttpResponseDefinition, HttpStatusCode, HttpStatusCodeNameMap } from "@rexeus/typeweaver-core";
10
+
11
+ //#region src/generators/IndexFileGenerator.ts
12
+ var IndexFileGenerator = class {
13
+ constructor(templateDir) {
14
+ this.templateDir = templateDir;
15
+ }
16
+ generate(context) {
17
+ const templateFilePath = path.join(this.templateDir, "Index.ejs");
18
+ const template = fs.readFileSync(templateFilePath, "utf8");
19
+ const indexPaths = /* @__PURE__ */ new Set();
20
+ for (const generatedFile of context.getGeneratedFiles()) indexPaths.add(`./${generatedFile.replace(/\.ts$/, "")}`);
21
+ const content = render(template, { indexPaths: Array.from(indexPaths).sort() });
22
+ fs.writeFileSync(path.join(context.outputDir, "index.ts"), content);
23
+ }
24
+ };
25
+
26
+ //#endregion
27
+ //#region src/generators/errors/PluginLoadingFailure.ts
28
+ var PluginLoadingFailure = class PluginLoadingFailure extends Error {
29
+ constructor(pluginName, attempts) {
30
+ super(`Failed to load plugin '${pluginName}'`);
31
+ this.pluginName = pluginName;
32
+ this.attempts = attempts;
33
+ Object.setPrototypeOf(this, PluginLoadingFailure.prototype);
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ //#region src/generators/PluginLoader.ts
39
+ /**
40
+ * Handles plugin discovery and loading for typeweaver
41
+ */
42
+ var PluginLoader = class {
43
+ constructor(registry, requiredPlugins, strategies = ["npm", "local"]) {
44
+ this.registry = registry;
45
+ this.requiredPlugins = requiredPlugins;
46
+ this.strategies = strategies;
47
+ }
48
+ /**
49
+ * Load all plugins from configuration
50
+ */
51
+ async loadPlugins(config) {
52
+ for (const requiredPlugin of this.requiredPlugins) this.registry.register(requiredPlugin);
53
+ if (!config?.plugins) return;
54
+ const successful = [];
55
+ for (const plugin of config.plugins) {
56
+ let result;
57
+ if (typeof plugin === "string") result = await this.loadPlugin(plugin);
58
+ else result = await this.loadPlugin(plugin[0]);
59
+ if (result.success === false) throw new PluginLoadingFailure(result.error.pluginName, result.error.attempts);
60
+ successful.push(result.value);
61
+ this.registry.register(result.value.plugin);
62
+ }
63
+ this.reportSuccessfulLoads(successful);
64
+ }
65
+ /**
66
+ * Load a plugin from a string identifier
67
+ */
68
+ async loadPlugin(pluginName) {
69
+ const possiblePaths = this.generatePluginPaths(pluginName);
70
+ const attempts = [];
71
+ for (const possiblePath of possiblePaths) try {
72
+ const pluginPackage = await import(possiblePath);
73
+ if (pluginPackage.default) return {
74
+ success: true,
75
+ value: {
76
+ plugin: new pluginPackage.default(),
77
+ source: possiblePath
78
+ }
79
+ };
80
+ attempts.push({
81
+ path: possiblePath,
82
+ error: "No default export found"
83
+ });
84
+ } catch (error) {
85
+ attempts.push({
86
+ path: possiblePath,
87
+ error: error instanceof Error ? error.message : String(error)
88
+ });
89
+ }
90
+ return {
91
+ success: false,
92
+ error: {
93
+ pluginName,
94
+ attempts
95
+ }
96
+ };
97
+ }
98
+ /**
99
+ * Generate possible plugin paths based on configured strategies
100
+ */
101
+ generatePluginPaths(pluginName) {
102
+ const paths = [];
103
+ for (const strategy of this.strategies) switch (strategy) {
104
+ case "npm":
105
+ paths.push(`@rexeus/typeweaver-${pluginName}`);
106
+ paths.push(`@rexeus/${pluginName}`);
107
+ break;
108
+ case "local":
109
+ paths.push(pluginName);
110
+ break;
111
+ }
112
+ return paths;
113
+ }
114
+ /**
115
+ * Report successful plugin loads
116
+ */
117
+ reportSuccessfulLoads(successful) {
118
+ if (successful.length > 0) {
119
+ console.info(`Successfully loaded ${successful.length} plugin(s):`);
120
+ for (const result of successful) console.info(` - ${result.plugin.name} (from ${result.source})`);
121
+ }
122
+ }
123
+ };
124
+
125
+ //#endregion
126
+ //#region src/generators/Formatter.ts
127
+ var Formatter = class {
128
+ constructor(outputDir) {
129
+ this.outputDir = outputDir;
130
+ }
131
+ async formatCode(startDir) {
132
+ const format = await this.loadFormatter();
133
+ if (!format) return;
134
+ const targetDir = startDir ?? this.outputDir;
135
+ await this.formatDirectory(targetDir, format);
136
+ }
137
+ async loadFormatter() {
138
+ try {
139
+ return (await import("oxfmt")).format;
140
+ } catch {
141
+ console.warn("oxfmt not installed - skipping formatting. Install with: npm install -D oxfmt");
142
+ return;
143
+ }
144
+ }
145
+ async formatDirectory(targetDir, format) {
146
+ const contents = fs.readdirSync(targetDir, { withFileTypes: true });
147
+ for (const content of contents) if (content.isFile()) {
148
+ const filePath = path.join(targetDir, content.name);
149
+ const { code } = await format(filePath, fs.readFileSync(filePath, "utf8"));
150
+ fs.writeFileSync(filePath, code);
151
+ } else if (content.isDirectory()) await this.formatDirectory(path.join(targetDir, content.name), format);
152
+ }
153
+ };
154
+
155
+ //#endregion
156
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js
157
+ /** A special constant with type `never` */
158
+ const NEVER = Object.freeze({ status: "aborted" });
159
+ function $constructor(name, initializer, params) {
160
+ function init(inst, def) {
161
+ if (!inst._zod) Object.defineProperty(inst, "_zod", {
162
+ value: {
163
+ def,
164
+ constr: _,
165
+ traits: /* @__PURE__ */ new Set()
166
+ },
167
+ enumerable: false
168
+ });
169
+ if (inst._zod.traits.has(name)) return;
170
+ inst._zod.traits.add(name);
171
+ initializer(inst, def);
172
+ const proto = _.prototype;
173
+ const keys = Object.keys(proto);
174
+ for (let i = 0; i < keys.length; i++) {
175
+ const k = keys[i];
176
+ if (!(k in inst)) inst[k] = proto[k].bind(inst);
177
+ }
178
+ }
179
+ const Parent = params?.Parent ?? Object;
180
+ class Definition extends Parent {}
181
+ Object.defineProperty(Definition, "name", { value: name });
182
+ function _(def) {
183
+ var _a;
184
+ const inst = params?.Parent ? new Definition() : this;
185
+ init(inst, def);
186
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
187
+ for (const fn of inst._zod.deferred) fn();
188
+ return inst;
189
+ }
190
+ Object.defineProperty(_, "init", { value: init });
191
+ Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
192
+ if (params?.Parent && inst instanceof params.Parent) return true;
193
+ return inst?._zod?.traits?.has(name);
194
+ } });
195
+ Object.defineProperty(_, "name", { value: name });
196
+ return _;
197
+ }
198
+ var $ZodAsyncError = class extends Error {
199
+ constructor() {
200
+ super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
201
+ }
202
+ };
203
+ var $ZodEncodeError = class extends Error {
204
+ constructor(name) {
205
+ super(`Encountered unidirectional transform during encode: ${name}`);
206
+ this.name = "ZodEncodeError";
207
+ }
208
+ };
209
+ const globalConfig = {};
210
+ function config(newConfig) {
211
+ if (newConfig) Object.assign(globalConfig, newConfig);
212
+ return globalConfig;
213
+ }
214
+
215
+ //#endregion
216
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js
217
+ function getEnumValues(entries) {
218
+ const numericValues = Object.values(entries).filter((v) => typeof v === "number");
219
+ return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
220
+ }
221
+ function jsonStringifyReplacer(_, value) {
222
+ if (typeof value === "bigint") return value.toString();
223
+ return value;
224
+ }
225
+ function cached(getter) {
226
+ return { get value() {
227
+ {
228
+ const value = getter();
229
+ Object.defineProperty(this, "value", { value });
230
+ return value;
231
+ }
232
+ throw new Error("cached value already set");
233
+ } };
234
+ }
235
+ function nullish(input) {
236
+ return input === null || input === void 0;
237
+ }
238
+ function cleanRegex(source) {
239
+ const start = source.startsWith("^") ? 1 : 0;
240
+ const end = source.endsWith("$") ? source.length - 1 : source.length;
241
+ return source.slice(start, end);
242
+ }
243
+ const EVALUATING = Symbol("evaluating");
244
+ function defineLazy(object, key, getter) {
245
+ let value = void 0;
246
+ Object.defineProperty(object, key, {
247
+ get() {
248
+ if (value === EVALUATING) return;
249
+ if (value === void 0) {
250
+ value = EVALUATING;
251
+ value = getter();
252
+ }
253
+ return value;
254
+ },
255
+ set(v) {
256
+ Object.defineProperty(object, key, { value: v });
257
+ },
258
+ configurable: true
259
+ });
260
+ }
261
+ function assignProp(target, prop, value) {
262
+ Object.defineProperty(target, prop, {
263
+ value,
264
+ writable: true,
265
+ enumerable: true,
266
+ configurable: true
267
+ });
268
+ }
269
+ function mergeDefs(...defs) {
270
+ const mergedDescriptors = {};
271
+ for (const def of defs) {
272
+ const descriptors = Object.getOwnPropertyDescriptors(def);
273
+ Object.assign(mergedDescriptors, descriptors);
274
+ }
275
+ return Object.defineProperties({}, mergedDescriptors);
276
+ }
277
+ function esc(str) {
278
+ return JSON.stringify(str);
279
+ }
280
+ function slugify(input) {
281
+ return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
282
+ }
283
+ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
284
+ function isObject(data) {
285
+ return typeof data === "object" && data !== null && !Array.isArray(data);
286
+ }
287
+ const allowsEval = cached(() => {
288
+ if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
289
+ try {
290
+ new Function("");
291
+ return true;
292
+ } catch (_) {
293
+ return false;
294
+ }
295
+ });
296
+ function isPlainObject(o) {
297
+ if (isObject(o) === false) return false;
298
+ const ctor = o.constructor;
299
+ if (ctor === void 0) return true;
300
+ if (typeof ctor !== "function") return true;
301
+ const prot = ctor.prototype;
302
+ if (isObject(prot) === false) return false;
303
+ if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
304
+ return true;
305
+ }
306
+ function shallowClone(o) {
307
+ if (isPlainObject(o)) return { ...o };
308
+ if (Array.isArray(o)) return [...o];
309
+ return o;
310
+ }
311
+ const propertyKeyTypes = new Set([
312
+ "string",
313
+ "number",
314
+ "symbol"
315
+ ]);
316
+ function escapeRegex(str) {
317
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
318
+ }
319
+ function clone(inst, def, params) {
320
+ const cl = new inst._zod.constr(def ?? inst._zod.def);
321
+ if (!def || params?.parent) cl._zod.parent = inst;
322
+ return cl;
323
+ }
324
+ function normalizeParams(_params) {
325
+ const params = _params;
326
+ if (!params) return {};
327
+ if (typeof params === "string") return { error: () => params };
328
+ if (params?.message !== void 0) {
329
+ if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
330
+ params.error = params.message;
331
+ }
332
+ delete params.message;
333
+ if (typeof params.error === "string") return {
334
+ ...params,
335
+ error: () => params.error
336
+ };
337
+ return params;
338
+ }
339
+ function optionalKeys(shape) {
340
+ return Object.keys(shape).filter((k) => {
341
+ return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
342
+ });
343
+ }
344
+ const NUMBER_FORMAT_RANGES = {
345
+ safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
346
+ int32: [-2147483648, 2147483647],
347
+ uint32: [0, 4294967295],
348
+ float32: [-34028234663852886e22, 34028234663852886e22],
349
+ float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
350
+ };
351
+ function pick(schema, mask) {
352
+ const currDef = schema._zod.def;
353
+ const checks = currDef.checks;
354
+ if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
355
+ return clone(schema, mergeDefs(schema._zod.def, {
356
+ get shape() {
357
+ const newShape = {};
358
+ for (const key in mask) {
359
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
360
+ if (!mask[key]) continue;
361
+ newShape[key] = currDef.shape[key];
362
+ }
363
+ assignProp(this, "shape", newShape);
364
+ return newShape;
365
+ },
366
+ checks: []
367
+ }));
368
+ }
369
+ function omit(schema, mask) {
370
+ const currDef = schema._zod.def;
371
+ const checks = currDef.checks;
372
+ if (checks && checks.length > 0) throw new Error(".omit() cannot be used on object schemas containing refinements");
373
+ return clone(schema, mergeDefs(schema._zod.def, {
374
+ get shape() {
375
+ const newShape = { ...schema._zod.def.shape };
376
+ for (const key in mask) {
377
+ if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
378
+ if (!mask[key]) continue;
379
+ delete newShape[key];
380
+ }
381
+ assignProp(this, "shape", newShape);
382
+ return newShape;
383
+ },
384
+ checks: []
385
+ }));
386
+ }
387
+ function extend(schema, shape) {
388
+ if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
389
+ const checks = schema._zod.def.checks;
390
+ if (checks && checks.length > 0) {
391
+ const existingShape = schema._zod.def.shape;
392
+ for (const key in shape) if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
393
+ }
394
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
395
+ const _shape = {
396
+ ...schema._zod.def.shape,
397
+ ...shape
398
+ };
399
+ assignProp(this, "shape", _shape);
400
+ return _shape;
401
+ } }));
402
+ }
403
+ function safeExtend(schema, shape) {
404
+ if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
405
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
406
+ const _shape = {
407
+ ...schema._zod.def.shape,
408
+ ...shape
409
+ };
410
+ assignProp(this, "shape", _shape);
411
+ return _shape;
412
+ } }));
413
+ }
414
+ function merge(a, b) {
415
+ return clone(a, mergeDefs(a._zod.def, {
416
+ get shape() {
417
+ const _shape = {
418
+ ...a._zod.def.shape,
419
+ ...b._zod.def.shape
420
+ };
421
+ assignProp(this, "shape", _shape);
422
+ return _shape;
423
+ },
424
+ get catchall() {
425
+ return b._zod.def.catchall;
426
+ },
427
+ checks: []
428
+ }));
429
+ }
430
+ function partial(Class, schema, mask) {
431
+ const checks = schema._zod.def.checks;
432
+ if (checks && checks.length > 0) throw new Error(".partial() cannot be used on object schemas containing refinements");
433
+ return clone(schema, mergeDefs(schema._zod.def, {
434
+ get shape() {
435
+ const oldShape = schema._zod.def.shape;
436
+ const shape = { ...oldShape };
437
+ if (mask) for (const key in mask) {
438
+ if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
439
+ if (!mask[key]) continue;
440
+ shape[key] = Class ? new Class({
441
+ type: "optional",
442
+ innerType: oldShape[key]
443
+ }) : oldShape[key];
444
+ }
445
+ else for (const key in oldShape) shape[key] = Class ? new Class({
446
+ type: "optional",
447
+ innerType: oldShape[key]
448
+ }) : oldShape[key];
449
+ assignProp(this, "shape", shape);
450
+ return shape;
451
+ },
452
+ checks: []
453
+ }));
454
+ }
455
+ function required(Class, schema, mask) {
456
+ return clone(schema, mergeDefs(schema._zod.def, { get shape() {
457
+ const oldShape = schema._zod.def.shape;
458
+ const shape = { ...oldShape };
459
+ if (mask) for (const key in mask) {
460
+ if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
461
+ if (!mask[key]) continue;
462
+ shape[key] = new Class({
463
+ type: "nonoptional",
464
+ innerType: oldShape[key]
465
+ });
466
+ }
467
+ else for (const key in oldShape) shape[key] = new Class({
468
+ type: "nonoptional",
469
+ innerType: oldShape[key]
470
+ });
471
+ assignProp(this, "shape", shape);
472
+ return shape;
473
+ } }));
474
+ }
475
+ function aborted(x, startIndex = 0) {
476
+ if (x.aborted === true) return true;
477
+ for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
478
+ return false;
479
+ }
480
+ function prefixIssues(path, issues) {
481
+ return issues.map((iss) => {
482
+ var _a;
483
+ (_a = iss).path ?? (_a.path = []);
484
+ iss.path.unshift(path);
485
+ return iss;
486
+ });
487
+ }
488
+ function unwrapMessage(message) {
489
+ return typeof message === "string" ? message : message?.message;
490
+ }
491
+ function finalizeIssue(iss, ctx, config) {
492
+ const full = {
493
+ ...iss,
494
+ path: iss.path ?? []
495
+ };
496
+ if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
497
+ delete full.inst;
498
+ delete full.continue;
499
+ if (!ctx?.reportInput) delete full.input;
500
+ return full;
501
+ }
502
+ function getLengthableOrigin(input) {
503
+ if (Array.isArray(input)) return "array";
504
+ if (typeof input === "string") return "string";
505
+ return "unknown";
506
+ }
507
+ function issue(...args) {
508
+ const [iss, input, inst] = args;
509
+ if (typeof iss === "string") return {
510
+ message: iss,
511
+ code: "custom",
512
+ input,
513
+ inst
514
+ };
515
+ return { ...iss };
516
+ }
517
+
518
+ //#endregion
519
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js
520
+ const initializer$1 = (inst, def) => {
521
+ inst.name = "$ZodError";
522
+ Object.defineProperty(inst, "_zod", {
523
+ value: inst._zod,
524
+ enumerable: false
525
+ });
526
+ Object.defineProperty(inst, "issues", {
527
+ value: def,
528
+ enumerable: false
529
+ });
530
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
531
+ Object.defineProperty(inst, "toString", {
532
+ value: () => inst.message,
533
+ enumerable: false
534
+ });
535
+ };
536
+ const $ZodError = $constructor("$ZodError", initializer$1);
537
+ const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
538
+ function flattenError(error, mapper = (issue) => issue.message) {
539
+ const fieldErrors = {};
540
+ const formErrors = [];
541
+ for (const sub of error.issues) if (sub.path.length > 0) {
542
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
543
+ fieldErrors[sub.path[0]].push(mapper(sub));
544
+ } else formErrors.push(mapper(sub));
545
+ return {
546
+ formErrors,
547
+ fieldErrors
548
+ };
549
+ }
550
+ function formatError(error, mapper = (issue) => issue.message) {
551
+ const fieldErrors = { _errors: [] };
552
+ const processError = (error) => {
553
+ for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }));
554
+ else if (issue.code === "invalid_key") processError({ issues: issue.issues });
555
+ else if (issue.code === "invalid_element") processError({ issues: issue.issues });
556
+ else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
557
+ else {
558
+ let curr = fieldErrors;
559
+ let i = 0;
560
+ while (i < issue.path.length) {
561
+ const el = issue.path[i];
562
+ if (!(i === issue.path.length - 1)) curr[el] = curr[el] || { _errors: [] };
563
+ else {
564
+ curr[el] = curr[el] || { _errors: [] };
565
+ curr[el]._errors.push(mapper(issue));
566
+ }
567
+ curr = curr[el];
568
+ i++;
569
+ }
570
+ }
571
+ };
572
+ processError(error);
573
+ return fieldErrors;
574
+ }
575
+
576
+ //#endregion
577
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js
578
+ const _parse = (_Err) => (schema, value, _ctx, _params) => {
579
+ const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
580
+ const result = schema._zod.run({
581
+ value,
582
+ issues: []
583
+ }, ctx);
584
+ if (result instanceof Promise) throw new $ZodAsyncError();
585
+ if (result.issues.length) {
586
+ const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
587
+ captureStackTrace(e, _params?.callee);
588
+ throw e;
589
+ }
590
+ return result.value;
591
+ };
592
+ const parse$1 = /* @__PURE__ */ _parse($ZodRealError);
593
+ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
594
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
595
+ let result = schema._zod.run({
596
+ value,
597
+ issues: []
598
+ }, ctx);
599
+ if (result instanceof Promise) result = await result;
600
+ if (result.issues.length) {
601
+ const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
602
+ captureStackTrace(e, params?.callee);
603
+ throw e;
604
+ }
605
+ return result.value;
606
+ };
607
+ const parseAsync$1 = /* @__PURE__ */ _parseAsync($ZodRealError);
608
+ const _safeParse = (_Err) => (schema, value, _ctx) => {
609
+ const ctx = _ctx ? {
610
+ ..._ctx,
611
+ async: false
612
+ } : { async: false };
613
+ const result = schema._zod.run({
614
+ value,
615
+ issues: []
616
+ }, ctx);
617
+ if (result instanceof Promise) throw new $ZodAsyncError();
618
+ return result.issues.length ? {
619
+ success: false,
620
+ error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
621
+ } : {
622
+ success: true,
623
+ data: result.value
624
+ };
625
+ };
626
+ const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
627
+ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
628
+ const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
629
+ let result = schema._zod.run({
630
+ value,
631
+ issues: []
632
+ }, ctx);
633
+ if (result instanceof Promise) result = await result;
634
+ return result.issues.length ? {
635
+ success: false,
636
+ error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
637
+ } : {
638
+ success: true,
639
+ data: result.value
640
+ };
641
+ };
642
+ const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
643
+ const _encode = (_Err) => (schema, value, _ctx) => {
644
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
645
+ return _parse(_Err)(schema, value, ctx);
646
+ };
647
+ const encode$1 = /* @__PURE__ */ _encode($ZodRealError);
648
+ const _decode = (_Err) => (schema, value, _ctx) => {
649
+ return _parse(_Err)(schema, value, _ctx);
650
+ };
651
+ const decode$1 = /* @__PURE__ */ _decode($ZodRealError);
652
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
653
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
654
+ return _parseAsync(_Err)(schema, value, ctx);
655
+ };
656
+ const encodeAsync$1 = /* @__PURE__ */ _encodeAsync($ZodRealError);
657
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
658
+ return _parseAsync(_Err)(schema, value, _ctx);
659
+ };
660
+ const decodeAsync$1 = /* @__PURE__ */ _decodeAsync($ZodRealError);
661
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
662
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
663
+ return _safeParse(_Err)(schema, value, ctx);
664
+ };
665
+ const safeEncode$1 = /* @__PURE__ */ _safeEncode($ZodRealError);
666
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
667
+ return _safeParse(_Err)(schema, value, _ctx);
668
+ };
669
+ const safeDecode$1 = /* @__PURE__ */ _safeDecode($ZodRealError);
670
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
671
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
672
+ return _safeParseAsync(_Err)(schema, value, ctx);
673
+ };
674
+ const safeEncodeAsync$1 = /* @__PURE__ */ _safeEncodeAsync($ZodRealError);
675
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
676
+ return _safeParseAsync(_Err)(schema, value, _ctx);
677
+ };
678
+ const safeDecodeAsync$1 = /* @__PURE__ */ _safeDecodeAsync($ZodRealError);
679
+
680
+ //#endregion
681
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/regexes.js
682
+ const cuid = /^[cC][^\s-]{8,}$/;
683
+ const cuid2 = /^[0-9a-z]+$/;
684
+ const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
685
+ const xid = /^[0-9a-vA-V]{20}$/;
686
+ const ksuid = /^[A-Za-z0-9]{27}$/;
687
+ const nanoid = /^[a-zA-Z0-9_-]{21}$/;
688
+ /** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
689
+ 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)?)?)$/;
690
+ /** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
691
+ 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})$/;
692
+ /** Returns a regex for validating an RFC 9562/4122 UUID.
693
+ *
694
+ * @param version Optionally specify a version 1-8. If no version is specified, all versions are supported. */
695
+ const uuid = (version) => {
696
+ 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)$/;
697
+ 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})$`);
698
+ };
699
+ /** Practical email validation */
700
+ const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
701
+ const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
702
+ function emoji() {
703
+ return new RegExp(_emoji$1, "u");
704
+ }
705
+ 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])$/;
706
+ 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}|:))$/;
707
+ 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])$/;
708
+ 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])$/;
709
+ const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
710
+ const base64url = /^[A-Za-z0-9_-]*$/;
711
+ const e164 = /^\+[1-9]\d{6,14}$/;
712
+ 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])))`;
713
+ const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
714
+ function timeSource(args) {
715
+ const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
716
+ 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+)?)?`;
717
+ }
718
+ function time$1(args) {
719
+ return new RegExp(`^${timeSource(args)}$`);
720
+ }
721
+ function datetime$1(args) {
722
+ const time = timeSource({ precision: args.precision });
723
+ const opts = ["Z"];
724
+ if (args.local) opts.push("");
725
+ if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
726
+ const timeRegex = `${time}(?:${opts.join("|")})`;
727
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
728
+ }
729
+ const string = (params) => {
730
+ const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
731
+ return new RegExp(`^${regex}$`);
732
+ };
733
+ const lowercase = /^[^A-Z]*$/;
734
+ const uppercase = /^[^a-z]*$/;
735
+
736
+ //#endregion
737
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.js
738
+ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
739
+ var _a;
740
+ inst._zod ?? (inst._zod = {});
741
+ inst._zod.def = def;
742
+ (_a = inst._zod).onattach ?? (_a.onattach = []);
743
+ });
744
+ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
745
+ var _a;
746
+ $ZodCheck.init(inst, def);
747
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
748
+ const val = payload.value;
749
+ return !nullish(val) && val.length !== void 0;
750
+ });
751
+ inst._zod.onattach.push((inst) => {
752
+ const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
753
+ if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
754
+ });
755
+ inst._zod.check = (payload) => {
756
+ const input = payload.value;
757
+ if (input.length <= def.maximum) return;
758
+ const origin = getLengthableOrigin(input);
759
+ payload.issues.push({
760
+ origin,
761
+ code: "too_big",
762
+ maximum: def.maximum,
763
+ inclusive: true,
764
+ input,
765
+ inst,
766
+ continue: !def.abort
767
+ });
768
+ };
769
+ });
770
+ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
771
+ var _a;
772
+ $ZodCheck.init(inst, def);
773
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
774
+ const val = payload.value;
775
+ return !nullish(val) && val.length !== void 0;
776
+ });
777
+ inst._zod.onattach.push((inst) => {
778
+ const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
779
+ if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
780
+ });
781
+ inst._zod.check = (payload) => {
782
+ const input = payload.value;
783
+ if (input.length >= def.minimum) return;
784
+ const origin = getLengthableOrigin(input);
785
+ payload.issues.push({
786
+ origin,
787
+ code: "too_small",
788
+ minimum: def.minimum,
789
+ inclusive: true,
790
+ input,
791
+ inst,
792
+ continue: !def.abort
793
+ });
794
+ };
795
+ });
796
+ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
797
+ var _a;
798
+ $ZodCheck.init(inst, def);
799
+ (_a = inst._zod.def).when ?? (_a.when = (payload) => {
800
+ const val = payload.value;
801
+ return !nullish(val) && val.length !== void 0;
802
+ });
803
+ inst._zod.onattach.push((inst) => {
804
+ const bag = inst._zod.bag;
805
+ bag.minimum = def.length;
806
+ bag.maximum = def.length;
807
+ bag.length = def.length;
808
+ });
809
+ inst._zod.check = (payload) => {
810
+ const input = payload.value;
811
+ const length = input.length;
812
+ if (length === def.length) return;
813
+ const origin = getLengthableOrigin(input);
814
+ const tooBig = length > def.length;
815
+ payload.issues.push({
816
+ origin,
817
+ ...tooBig ? {
818
+ code: "too_big",
819
+ maximum: def.length
820
+ } : {
821
+ code: "too_small",
822
+ minimum: def.length
823
+ },
824
+ inclusive: true,
825
+ exact: true,
826
+ input: payload.value,
827
+ inst,
828
+ continue: !def.abort
829
+ });
830
+ };
831
+ });
832
+ const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
833
+ var _a, _b;
834
+ $ZodCheck.init(inst, def);
835
+ inst._zod.onattach.push((inst) => {
836
+ const bag = inst._zod.bag;
837
+ bag.format = def.format;
838
+ if (def.pattern) {
839
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
840
+ bag.patterns.add(def.pattern);
841
+ }
842
+ });
843
+ if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
844
+ def.pattern.lastIndex = 0;
845
+ if (def.pattern.test(payload.value)) return;
846
+ payload.issues.push({
847
+ origin: "string",
848
+ code: "invalid_format",
849
+ format: def.format,
850
+ input: payload.value,
851
+ ...def.pattern ? { pattern: def.pattern.toString() } : {},
852
+ inst,
853
+ continue: !def.abort
854
+ });
855
+ });
856
+ else (_b = inst._zod).check ?? (_b.check = () => {});
857
+ });
858
+ const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
859
+ $ZodCheckStringFormat.init(inst, def);
860
+ inst._zod.check = (payload) => {
861
+ def.pattern.lastIndex = 0;
862
+ if (def.pattern.test(payload.value)) return;
863
+ payload.issues.push({
864
+ origin: "string",
865
+ code: "invalid_format",
866
+ format: "regex",
867
+ input: payload.value,
868
+ pattern: def.pattern.toString(),
869
+ inst,
870
+ continue: !def.abort
871
+ });
872
+ };
873
+ });
874
+ const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
875
+ def.pattern ?? (def.pattern = lowercase);
876
+ $ZodCheckStringFormat.init(inst, def);
877
+ });
878
+ const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
879
+ def.pattern ?? (def.pattern = uppercase);
880
+ $ZodCheckStringFormat.init(inst, def);
881
+ });
882
+ const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
883
+ $ZodCheck.init(inst, def);
884
+ const escapedRegex = escapeRegex(def.includes);
885
+ const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
886
+ def.pattern = pattern;
887
+ inst._zod.onattach.push((inst) => {
888
+ const bag = inst._zod.bag;
889
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
890
+ bag.patterns.add(pattern);
891
+ });
892
+ inst._zod.check = (payload) => {
893
+ if (payload.value.includes(def.includes, def.position)) return;
894
+ payload.issues.push({
895
+ origin: "string",
896
+ code: "invalid_format",
897
+ format: "includes",
898
+ includes: def.includes,
899
+ input: payload.value,
900
+ inst,
901
+ continue: !def.abort
902
+ });
903
+ };
904
+ });
905
+ const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
906
+ $ZodCheck.init(inst, def);
907
+ const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
908
+ def.pattern ?? (def.pattern = pattern);
909
+ inst._zod.onattach.push((inst) => {
910
+ const bag = inst._zod.bag;
911
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
912
+ bag.patterns.add(pattern);
913
+ });
914
+ inst._zod.check = (payload) => {
915
+ if (payload.value.startsWith(def.prefix)) return;
916
+ payload.issues.push({
917
+ origin: "string",
918
+ code: "invalid_format",
919
+ format: "starts_with",
920
+ prefix: def.prefix,
921
+ input: payload.value,
922
+ inst,
923
+ continue: !def.abort
924
+ });
925
+ };
926
+ });
927
+ const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
928
+ $ZodCheck.init(inst, def);
929
+ const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
930
+ def.pattern ?? (def.pattern = pattern);
931
+ inst._zod.onattach.push((inst) => {
932
+ const bag = inst._zod.bag;
933
+ bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
934
+ bag.patterns.add(pattern);
935
+ });
936
+ inst._zod.check = (payload) => {
937
+ if (payload.value.endsWith(def.suffix)) return;
938
+ payload.issues.push({
939
+ origin: "string",
940
+ code: "invalid_format",
941
+ format: "ends_with",
942
+ suffix: def.suffix,
943
+ input: payload.value,
944
+ inst,
945
+ continue: !def.abort
946
+ });
947
+ };
948
+ });
949
+ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
950
+ $ZodCheck.init(inst, def);
951
+ inst._zod.check = (payload) => {
952
+ payload.value = def.tx(payload.value);
953
+ };
954
+ });
955
+
956
+ //#endregion
957
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/doc.js
958
+ var Doc = class {
959
+ constructor(args = []) {
960
+ this.content = [];
961
+ this.indent = 0;
962
+ if (this) this.args = args;
963
+ }
964
+ indented(fn) {
965
+ this.indent += 1;
966
+ fn(this);
967
+ this.indent -= 1;
968
+ }
969
+ write(arg) {
970
+ if (typeof arg === "function") {
971
+ arg(this, { execution: "sync" });
972
+ arg(this, { execution: "async" });
973
+ return;
974
+ }
975
+ const lines = arg.split("\n").filter((x) => x);
976
+ const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
977
+ const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
978
+ for (const line of dedented) this.content.push(line);
979
+ }
980
+ compile() {
981
+ const F = Function;
982
+ const args = this?.args;
983
+ const lines = [...(this?.content ?? [``]).map((x) => ` ${x}`)];
984
+ return new F(...args, lines.join("\n"));
985
+ }
986
+ };
987
+
988
+ //#endregion
989
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.js
990
+ const version = {
991
+ major: 4,
992
+ minor: 3,
993
+ patch: 6
994
+ };
995
+
996
+ //#endregion
997
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.js
998
+ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
999
+ var _a;
1000
+ inst ?? (inst = {});
1001
+ inst._zod.def = def;
1002
+ inst._zod.bag = inst._zod.bag || {};
1003
+ inst._zod.version = version;
1004
+ const checks = [...inst._zod.def.checks ?? []];
1005
+ if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
1006
+ for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
1007
+ if (checks.length === 0) {
1008
+ (_a = inst._zod).deferred ?? (_a.deferred = []);
1009
+ inst._zod.deferred?.push(() => {
1010
+ inst._zod.run = inst._zod.parse;
1011
+ });
1012
+ } else {
1013
+ const runChecks = (payload, checks, ctx) => {
1014
+ let isAborted = aborted(payload);
1015
+ let asyncResult;
1016
+ for (const ch of checks) {
1017
+ if (ch._zod.def.when) {
1018
+ if (!ch._zod.def.when(payload)) continue;
1019
+ } else if (isAborted) continue;
1020
+ const currLen = payload.issues.length;
1021
+ const _ = ch._zod.check(payload);
1022
+ if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1023
+ if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1024
+ await _;
1025
+ if (payload.issues.length === currLen) return;
1026
+ if (!isAborted) isAborted = aborted(payload, currLen);
1027
+ });
1028
+ else {
1029
+ if (payload.issues.length === currLen) continue;
1030
+ if (!isAborted) isAborted = aborted(payload, currLen);
1031
+ }
1032
+ }
1033
+ if (asyncResult) return asyncResult.then(() => {
1034
+ return payload;
1035
+ });
1036
+ return payload;
1037
+ };
1038
+ const handleCanaryResult = (canary, payload, ctx) => {
1039
+ if (aborted(canary)) {
1040
+ canary.aborted = true;
1041
+ return canary;
1042
+ }
1043
+ const checkResult = runChecks(payload, checks, ctx);
1044
+ if (checkResult instanceof Promise) {
1045
+ if (ctx.async === false) throw new $ZodAsyncError();
1046
+ return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
1047
+ }
1048
+ return inst._zod.parse(checkResult, ctx);
1049
+ };
1050
+ inst._zod.run = (payload, ctx) => {
1051
+ if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
1052
+ if (ctx.direction === "backward") {
1053
+ const canary = inst._zod.parse({
1054
+ value: payload.value,
1055
+ issues: []
1056
+ }, {
1057
+ ...ctx,
1058
+ skipChecks: true
1059
+ });
1060
+ if (canary instanceof Promise) return canary.then((canary) => {
1061
+ return handleCanaryResult(canary, payload, ctx);
1062
+ });
1063
+ return handleCanaryResult(canary, payload, ctx);
1064
+ }
1065
+ const result = inst._zod.parse(payload, ctx);
1066
+ if (result instanceof Promise) {
1067
+ if (ctx.async === false) throw new $ZodAsyncError();
1068
+ return result.then((result) => runChecks(result, checks, ctx));
1069
+ }
1070
+ return runChecks(result, checks, ctx);
1071
+ };
1072
+ }
1073
+ defineLazy(inst, "~standard", () => ({
1074
+ validate: (value) => {
1075
+ try {
1076
+ const r = safeParse$1(inst, value);
1077
+ return r.success ? { value: r.data } : { issues: r.error?.issues };
1078
+ } catch (_) {
1079
+ return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1080
+ }
1081
+ },
1082
+ vendor: "zod",
1083
+ version: 1
1084
+ }));
1085
+ });
1086
+ const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
1087
+ $ZodType.init(inst, def);
1088
+ inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string(inst._zod.bag);
1089
+ inst._zod.parse = (payload, _) => {
1090
+ if (def.coerce) try {
1091
+ payload.value = String(payload.value);
1092
+ } catch (_) {}
1093
+ if (typeof payload.value === "string") return payload;
1094
+ payload.issues.push({
1095
+ expected: "string",
1096
+ code: "invalid_type",
1097
+ input: payload.value,
1098
+ inst
1099
+ });
1100
+ return payload;
1101
+ };
1102
+ });
1103
+ const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
1104
+ $ZodCheckStringFormat.init(inst, def);
1105
+ $ZodString.init(inst, def);
1106
+ });
1107
+ const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
1108
+ def.pattern ?? (def.pattern = guid);
1109
+ $ZodStringFormat.init(inst, def);
1110
+ });
1111
+ const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
1112
+ if (def.version) {
1113
+ const v = {
1114
+ v1: 1,
1115
+ v2: 2,
1116
+ v3: 3,
1117
+ v4: 4,
1118
+ v5: 5,
1119
+ v6: 6,
1120
+ v7: 7,
1121
+ v8: 8
1122
+ }[def.version];
1123
+ if (v === void 0) throw new Error(`Invalid UUID version: "${def.version}"`);
1124
+ def.pattern ?? (def.pattern = uuid(v));
1125
+ } else def.pattern ?? (def.pattern = uuid());
1126
+ $ZodStringFormat.init(inst, def);
1127
+ });
1128
+ const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
1129
+ def.pattern ?? (def.pattern = email);
1130
+ $ZodStringFormat.init(inst, def);
1131
+ });
1132
+ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
1133
+ $ZodStringFormat.init(inst, def);
1134
+ inst._zod.check = (payload) => {
1135
+ try {
1136
+ const trimmed = payload.value.trim();
1137
+ const url = new URL(trimmed);
1138
+ if (def.hostname) {
1139
+ def.hostname.lastIndex = 0;
1140
+ if (!def.hostname.test(url.hostname)) payload.issues.push({
1141
+ code: "invalid_format",
1142
+ format: "url",
1143
+ note: "Invalid hostname",
1144
+ pattern: def.hostname.source,
1145
+ input: payload.value,
1146
+ inst,
1147
+ continue: !def.abort
1148
+ });
1149
+ }
1150
+ if (def.protocol) {
1151
+ def.protocol.lastIndex = 0;
1152
+ if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
1153
+ code: "invalid_format",
1154
+ format: "url",
1155
+ note: "Invalid protocol",
1156
+ pattern: def.protocol.source,
1157
+ input: payload.value,
1158
+ inst,
1159
+ continue: !def.abort
1160
+ });
1161
+ }
1162
+ if (def.normalize) payload.value = url.href;
1163
+ else payload.value = trimmed;
1164
+ return;
1165
+ } catch (_) {
1166
+ payload.issues.push({
1167
+ code: "invalid_format",
1168
+ format: "url",
1169
+ input: payload.value,
1170
+ inst,
1171
+ continue: !def.abort
1172
+ });
1173
+ }
1174
+ };
1175
+ });
1176
+ const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
1177
+ def.pattern ?? (def.pattern = emoji());
1178
+ $ZodStringFormat.init(inst, def);
1179
+ });
1180
+ const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
1181
+ def.pattern ?? (def.pattern = nanoid);
1182
+ $ZodStringFormat.init(inst, def);
1183
+ });
1184
+ const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
1185
+ def.pattern ?? (def.pattern = cuid);
1186
+ $ZodStringFormat.init(inst, def);
1187
+ });
1188
+ const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
1189
+ def.pattern ?? (def.pattern = cuid2);
1190
+ $ZodStringFormat.init(inst, def);
1191
+ });
1192
+ const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
1193
+ def.pattern ?? (def.pattern = ulid);
1194
+ $ZodStringFormat.init(inst, def);
1195
+ });
1196
+ const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
1197
+ def.pattern ?? (def.pattern = xid);
1198
+ $ZodStringFormat.init(inst, def);
1199
+ });
1200
+ const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
1201
+ def.pattern ?? (def.pattern = ksuid);
1202
+ $ZodStringFormat.init(inst, def);
1203
+ });
1204
+ const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
1205
+ def.pattern ?? (def.pattern = datetime$1(def));
1206
+ $ZodStringFormat.init(inst, def);
1207
+ });
1208
+ const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
1209
+ def.pattern ?? (def.pattern = date$1);
1210
+ $ZodStringFormat.init(inst, def);
1211
+ });
1212
+ const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
1213
+ def.pattern ?? (def.pattern = time$1(def));
1214
+ $ZodStringFormat.init(inst, def);
1215
+ });
1216
+ const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
1217
+ def.pattern ?? (def.pattern = duration$1);
1218
+ $ZodStringFormat.init(inst, def);
1219
+ });
1220
+ const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
1221
+ def.pattern ?? (def.pattern = ipv4);
1222
+ $ZodStringFormat.init(inst, def);
1223
+ inst._zod.bag.format = `ipv4`;
1224
+ });
1225
+ const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
1226
+ def.pattern ?? (def.pattern = ipv6);
1227
+ $ZodStringFormat.init(inst, def);
1228
+ inst._zod.bag.format = `ipv6`;
1229
+ inst._zod.check = (payload) => {
1230
+ try {
1231
+ new URL(`http://[${payload.value}]`);
1232
+ } catch {
1233
+ payload.issues.push({
1234
+ code: "invalid_format",
1235
+ format: "ipv6",
1236
+ input: payload.value,
1237
+ inst,
1238
+ continue: !def.abort
1239
+ });
1240
+ }
1241
+ };
1242
+ });
1243
+ const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
1244
+ def.pattern ?? (def.pattern = cidrv4);
1245
+ $ZodStringFormat.init(inst, def);
1246
+ });
1247
+ const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
1248
+ def.pattern ?? (def.pattern = cidrv6);
1249
+ $ZodStringFormat.init(inst, def);
1250
+ inst._zod.check = (payload) => {
1251
+ const parts = payload.value.split("/");
1252
+ try {
1253
+ if (parts.length !== 2) throw new Error();
1254
+ const [address, prefix] = parts;
1255
+ if (!prefix) throw new Error();
1256
+ const prefixNum = Number(prefix);
1257
+ if (`${prefixNum}` !== prefix) throw new Error();
1258
+ if (prefixNum < 0 || prefixNum > 128) throw new Error();
1259
+ new URL(`http://[${address}]`);
1260
+ } catch {
1261
+ payload.issues.push({
1262
+ code: "invalid_format",
1263
+ format: "cidrv6",
1264
+ input: payload.value,
1265
+ inst,
1266
+ continue: !def.abort
1267
+ });
1268
+ }
1269
+ };
1270
+ });
1271
+ function isValidBase64(data) {
1272
+ if (data === "") return true;
1273
+ if (data.length % 4 !== 0) return false;
1274
+ try {
1275
+ atob(data);
1276
+ return true;
1277
+ } catch {
1278
+ return false;
1279
+ }
1280
+ }
1281
+ const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
1282
+ def.pattern ?? (def.pattern = base64);
1283
+ $ZodStringFormat.init(inst, def);
1284
+ inst._zod.bag.contentEncoding = "base64";
1285
+ inst._zod.check = (payload) => {
1286
+ if (isValidBase64(payload.value)) return;
1287
+ payload.issues.push({
1288
+ code: "invalid_format",
1289
+ format: "base64",
1290
+ input: payload.value,
1291
+ inst,
1292
+ continue: !def.abort
1293
+ });
1294
+ };
1295
+ });
1296
+ function isValidBase64URL(data) {
1297
+ if (!base64url.test(data)) return false;
1298
+ const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
1299
+ return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
1300
+ }
1301
+ const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
1302
+ def.pattern ?? (def.pattern = base64url);
1303
+ $ZodStringFormat.init(inst, def);
1304
+ inst._zod.bag.contentEncoding = "base64url";
1305
+ inst._zod.check = (payload) => {
1306
+ if (isValidBase64URL(payload.value)) return;
1307
+ payload.issues.push({
1308
+ code: "invalid_format",
1309
+ format: "base64url",
1310
+ input: payload.value,
1311
+ inst,
1312
+ continue: !def.abort
1313
+ });
1314
+ };
1315
+ });
1316
+ const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
1317
+ def.pattern ?? (def.pattern = e164);
1318
+ $ZodStringFormat.init(inst, def);
1319
+ });
1320
+ function isValidJWT(token, algorithm = null) {
1321
+ try {
1322
+ const tokensParts = token.split(".");
1323
+ if (tokensParts.length !== 3) return false;
1324
+ const [header] = tokensParts;
1325
+ if (!header) return false;
1326
+ const parsedHeader = JSON.parse(atob(header));
1327
+ if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT") return false;
1328
+ if (!parsedHeader.alg) return false;
1329
+ if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm)) return false;
1330
+ return true;
1331
+ } catch {
1332
+ return false;
1333
+ }
1334
+ }
1335
+ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
1336
+ $ZodStringFormat.init(inst, def);
1337
+ inst._zod.check = (payload) => {
1338
+ if (isValidJWT(payload.value, def.alg)) return;
1339
+ payload.issues.push({
1340
+ code: "invalid_format",
1341
+ format: "jwt",
1342
+ input: payload.value,
1343
+ inst,
1344
+ continue: !def.abort
1345
+ });
1346
+ };
1347
+ });
1348
+ const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1349
+ $ZodType.init(inst, def);
1350
+ inst._zod.parse = (payload) => payload;
1351
+ });
1352
+ const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1353
+ $ZodType.init(inst, def);
1354
+ inst._zod.parse = (payload, _ctx) => {
1355
+ payload.issues.push({
1356
+ expected: "never",
1357
+ code: "invalid_type",
1358
+ input: payload.value,
1359
+ inst
1360
+ });
1361
+ return payload;
1362
+ };
1363
+ });
1364
+ function handleArrayResult(result, final, index) {
1365
+ if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1366
+ final.value[index] = result.value;
1367
+ }
1368
+ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1369
+ $ZodType.init(inst, def);
1370
+ inst._zod.parse = (payload, ctx) => {
1371
+ const input = payload.value;
1372
+ if (!Array.isArray(input)) {
1373
+ payload.issues.push({
1374
+ expected: "array",
1375
+ code: "invalid_type",
1376
+ input,
1377
+ inst
1378
+ });
1379
+ return payload;
1380
+ }
1381
+ payload.value = Array(input.length);
1382
+ const proms = [];
1383
+ for (let i = 0; i < input.length; i++) {
1384
+ const item = input[i];
1385
+ const result = def.element._zod.run({
1386
+ value: item,
1387
+ issues: []
1388
+ }, ctx);
1389
+ if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
1390
+ else handleArrayResult(result, payload, i);
1391
+ }
1392
+ if (proms.length) return Promise.all(proms).then(() => payload);
1393
+ return payload;
1394
+ };
1395
+ });
1396
+ function handlePropertyResult(result, final, key, input, isOptionalOut) {
1397
+ if (result.issues.length) {
1398
+ if (isOptionalOut && !(key in input)) return;
1399
+ final.issues.push(...prefixIssues(key, result.issues));
1400
+ }
1401
+ if (result.value === void 0) {
1402
+ if (key in input) final.value[key] = void 0;
1403
+ } else final.value[key] = result.value;
1404
+ }
1405
+ function normalizeDef(def) {
1406
+ const keys = Object.keys(def.shape);
1407
+ for (const k of keys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1408
+ const okeys = optionalKeys(def.shape);
1409
+ return {
1410
+ ...def,
1411
+ keys,
1412
+ keySet: new Set(keys),
1413
+ numKeys: keys.length,
1414
+ optionalKeys: new Set(okeys)
1415
+ };
1416
+ }
1417
+ function handleCatchall(proms, input, payload, ctx, def, inst) {
1418
+ const unrecognized = [];
1419
+ const keySet = def.keySet;
1420
+ const _catchall = def.catchall._zod;
1421
+ const t = _catchall.def.type;
1422
+ const isOptionalOut = _catchall.optout === "optional";
1423
+ for (const key in input) {
1424
+ if (keySet.has(key)) continue;
1425
+ if (t === "never") {
1426
+ unrecognized.push(key);
1427
+ continue;
1428
+ }
1429
+ const r = _catchall.run({
1430
+ value: input[key],
1431
+ issues: []
1432
+ }, ctx);
1433
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1434
+ else handlePropertyResult(r, payload, key, input, isOptionalOut);
1435
+ }
1436
+ if (unrecognized.length) payload.issues.push({
1437
+ code: "unrecognized_keys",
1438
+ keys: unrecognized,
1439
+ input,
1440
+ inst
1441
+ });
1442
+ if (!proms.length) return payload;
1443
+ return Promise.all(proms).then(() => {
1444
+ return payload;
1445
+ });
1446
+ }
1447
+ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1448
+ $ZodType.init(inst, def);
1449
+ if (!Object.getOwnPropertyDescriptor(def, "shape")?.get) {
1450
+ const sh = def.shape;
1451
+ Object.defineProperty(def, "shape", { get: () => {
1452
+ const newSh = { ...sh };
1453
+ Object.defineProperty(def, "shape", { value: newSh });
1454
+ return newSh;
1455
+ } });
1456
+ }
1457
+ const _normalized = cached(() => normalizeDef(def));
1458
+ defineLazy(inst._zod, "propValues", () => {
1459
+ const shape = def.shape;
1460
+ const propValues = {};
1461
+ for (const key in shape) {
1462
+ const field = shape[key]._zod;
1463
+ if (field.values) {
1464
+ propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1465
+ for (const v of field.values) propValues[key].add(v);
1466
+ }
1467
+ }
1468
+ return propValues;
1469
+ });
1470
+ const isObject$2 = isObject;
1471
+ const catchall = def.catchall;
1472
+ let value;
1473
+ inst._zod.parse = (payload, ctx) => {
1474
+ value ?? (value = _normalized.value);
1475
+ const input = payload.value;
1476
+ if (!isObject$2(input)) {
1477
+ payload.issues.push({
1478
+ expected: "object",
1479
+ code: "invalid_type",
1480
+ input,
1481
+ inst
1482
+ });
1483
+ return payload;
1484
+ }
1485
+ payload.value = {};
1486
+ const proms = [];
1487
+ const shape = value.shape;
1488
+ for (const key of value.keys) {
1489
+ const el = shape[key];
1490
+ const isOptionalOut = el._zod.optout === "optional";
1491
+ const r = el._zod.run({
1492
+ value: input[key],
1493
+ issues: []
1494
+ }, ctx);
1495
+ if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
1496
+ else handlePropertyResult(r, payload, key, input, isOptionalOut);
1497
+ }
1498
+ if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1499
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1500
+ };
1501
+ });
1502
+ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
1503
+ $ZodObject.init(inst, def);
1504
+ const superParse = inst._zod.parse;
1505
+ const _normalized = cached(() => normalizeDef(def));
1506
+ const generateFastpass = (shape) => {
1507
+ const doc = new Doc([
1508
+ "shape",
1509
+ "payload",
1510
+ "ctx"
1511
+ ]);
1512
+ const normalized = _normalized.value;
1513
+ const parseStr = (key) => {
1514
+ const k = esc(key);
1515
+ return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1516
+ };
1517
+ doc.write(`const input = payload.value;`);
1518
+ const ids = Object.create(null);
1519
+ let counter = 0;
1520
+ for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1521
+ doc.write(`const newResult = {};`);
1522
+ for (const key of normalized.keys) {
1523
+ const id = ids[key];
1524
+ const k = esc(key);
1525
+ const isOptionalOut = shape[key]?._zod?.optout === "optional";
1526
+ doc.write(`const ${id} = ${parseStr(key)};`);
1527
+ if (isOptionalOut) doc.write(`
1528
+ if (${id}.issues.length) {
1529
+ if (${k} in input) {
1530
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1531
+ ...iss,
1532
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1533
+ })));
1534
+ }
1535
+ }
1536
+
1537
+ if (${id}.value === undefined) {
1538
+ if (${k} in input) {
1539
+ newResult[${k}] = undefined;
1540
+ }
1541
+ } else {
1542
+ newResult[${k}] = ${id}.value;
1543
+ }
1544
+
1545
+ `);
1546
+ else doc.write(`
1547
+ if (${id}.issues.length) {
1548
+ payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1549
+ ...iss,
1550
+ path: iss.path ? [${k}, ...iss.path] : [${k}]
1551
+ })));
1552
+ }
1553
+
1554
+ if (${id}.value === undefined) {
1555
+ if (${k} in input) {
1556
+ newResult[${k}] = undefined;
1557
+ }
1558
+ } else {
1559
+ newResult[${k}] = ${id}.value;
1560
+ }
1561
+
1562
+ `);
1563
+ }
1564
+ doc.write(`payload.value = newResult;`);
1565
+ doc.write(`return payload;`);
1566
+ const fn = doc.compile();
1567
+ return (payload, ctx) => fn(shape, payload, ctx);
1568
+ };
1569
+ let fastpass;
1570
+ const isObject$1 = isObject;
1571
+ const jit = !globalConfig.jitless;
1572
+ const allowsEval$1 = allowsEval;
1573
+ const fastEnabled = jit && allowsEval$1.value;
1574
+ const catchall = def.catchall;
1575
+ let value;
1576
+ inst._zod.parse = (payload, ctx) => {
1577
+ value ?? (value = _normalized.value);
1578
+ const input = payload.value;
1579
+ if (!isObject$1(input)) {
1580
+ payload.issues.push({
1581
+ expected: "object",
1582
+ code: "invalid_type",
1583
+ input,
1584
+ inst
1585
+ });
1586
+ return payload;
1587
+ }
1588
+ if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1589
+ if (!fastpass) fastpass = generateFastpass(def.shape);
1590
+ payload = fastpass(payload, ctx);
1591
+ if (!catchall) return payload;
1592
+ return handleCatchall([], input, payload, ctx, value, inst);
1593
+ }
1594
+ return superParse(payload, ctx);
1595
+ };
1596
+ });
1597
+ function handleUnionResults(results, final, inst, ctx) {
1598
+ for (const result of results) if (result.issues.length === 0) {
1599
+ final.value = result.value;
1600
+ return final;
1601
+ }
1602
+ const nonaborted = results.filter((r) => !aborted(r));
1603
+ if (nonaborted.length === 1) {
1604
+ final.value = nonaborted[0].value;
1605
+ return nonaborted[0];
1606
+ }
1607
+ final.issues.push({
1608
+ code: "invalid_union",
1609
+ input: final.value,
1610
+ inst,
1611
+ errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1612
+ });
1613
+ return final;
1614
+ }
1615
+ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1616
+ $ZodType.init(inst, def);
1617
+ defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1618
+ defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1619
+ defineLazy(inst._zod, "values", () => {
1620
+ if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1621
+ });
1622
+ defineLazy(inst._zod, "pattern", () => {
1623
+ if (def.options.every((o) => o._zod.pattern)) {
1624
+ const patterns = def.options.map((o) => o._zod.pattern);
1625
+ return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1626
+ }
1627
+ });
1628
+ const single = def.options.length === 1;
1629
+ const first = def.options[0]._zod.run;
1630
+ inst._zod.parse = (payload, ctx) => {
1631
+ if (single) return first(payload, ctx);
1632
+ let async = false;
1633
+ const results = [];
1634
+ for (const option of def.options) {
1635
+ const result = option._zod.run({
1636
+ value: payload.value,
1637
+ issues: []
1638
+ }, ctx);
1639
+ if (result instanceof Promise) {
1640
+ results.push(result);
1641
+ async = true;
1642
+ } else {
1643
+ if (result.issues.length === 0) return result;
1644
+ results.push(result);
1645
+ }
1646
+ }
1647
+ if (!async) return handleUnionResults(results, payload, inst, ctx);
1648
+ return Promise.all(results).then((results) => {
1649
+ return handleUnionResults(results, payload, inst, ctx);
1650
+ });
1651
+ };
1652
+ });
1653
+ const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1654
+ $ZodType.init(inst, def);
1655
+ inst._zod.parse = (payload, ctx) => {
1656
+ const input = payload.value;
1657
+ const left = def.left._zod.run({
1658
+ value: input,
1659
+ issues: []
1660
+ }, ctx);
1661
+ const right = def.right._zod.run({
1662
+ value: input,
1663
+ issues: []
1664
+ }, ctx);
1665
+ if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left, right]) => {
1666
+ return handleIntersectionResults(payload, left, right);
1667
+ });
1668
+ return handleIntersectionResults(payload, left, right);
1669
+ };
1670
+ });
1671
+ function mergeValues(a, b) {
1672
+ if (a === b) return {
1673
+ valid: true,
1674
+ data: a
1675
+ };
1676
+ if (a instanceof Date && b instanceof Date && +a === +b) return {
1677
+ valid: true,
1678
+ data: a
1679
+ };
1680
+ if (isPlainObject(a) && isPlainObject(b)) {
1681
+ const bKeys = Object.keys(b);
1682
+ const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1683
+ const newObj = {
1684
+ ...a,
1685
+ ...b
1686
+ };
1687
+ for (const key of sharedKeys) {
1688
+ const sharedValue = mergeValues(a[key], b[key]);
1689
+ if (!sharedValue.valid) return {
1690
+ valid: false,
1691
+ mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1692
+ };
1693
+ newObj[key] = sharedValue.data;
1694
+ }
1695
+ return {
1696
+ valid: true,
1697
+ data: newObj
1698
+ };
1699
+ }
1700
+ if (Array.isArray(a) && Array.isArray(b)) {
1701
+ if (a.length !== b.length) return {
1702
+ valid: false,
1703
+ mergeErrorPath: []
1704
+ };
1705
+ const newArray = [];
1706
+ for (let index = 0; index < a.length; index++) {
1707
+ const itemA = a[index];
1708
+ const itemB = b[index];
1709
+ const sharedValue = mergeValues(itemA, itemB);
1710
+ if (!sharedValue.valid) return {
1711
+ valid: false,
1712
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1713
+ };
1714
+ newArray.push(sharedValue.data);
1715
+ }
1716
+ return {
1717
+ valid: true,
1718
+ data: newArray
1719
+ };
1720
+ }
1721
+ return {
1722
+ valid: false,
1723
+ mergeErrorPath: []
1724
+ };
1725
+ }
1726
+ function handleIntersectionResults(result, left, right) {
1727
+ const unrecKeys = /* @__PURE__ */ new Map();
1728
+ let unrecIssue;
1729
+ for (const iss of left.issues) if (iss.code === "unrecognized_keys") {
1730
+ unrecIssue ?? (unrecIssue = iss);
1731
+ for (const k of iss.keys) {
1732
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1733
+ unrecKeys.get(k).l = true;
1734
+ }
1735
+ } else result.issues.push(iss);
1736
+ for (const iss of right.issues) if (iss.code === "unrecognized_keys") for (const k of iss.keys) {
1737
+ if (!unrecKeys.has(k)) unrecKeys.set(k, {});
1738
+ unrecKeys.get(k).r = true;
1739
+ }
1740
+ else result.issues.push(iss);
1741
+ const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
1742
+ if (bothKeys.length && unrecIssue) result.issues.push({
1743
+ ...unrecIssue,
1744
+ keys: bothKeys
1745
+ });
1746
+ if (aborted(result)) return result;
1747
+ const merged = mergeValues(left.value, right.value);
1748
+ if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1749
+ result.value = merged.data;
1750
+ return result;
1751
+ }
1752
+ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1753
+ $ZodType.init(inst, def);
1754
+ const values = getEnumValues(def.entries);
1755
+ const valuesSet = new Set(values);
1756
+ inst._zod.values = valuesSet;
1757
+ inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1758
+ inst._zod.parse = (payload, _ctx) => {
1759
+ const input = payload.value;
1760
+ if (valuesSet.has(input)) return payload;
1761
+ payload.issues.push({
1762
+ code: "invalid_value",
1763
+ values,
1764
+ input,
1765
+ inst
1766
+ });
1767
+ return payload;
1768
+ };
1769
+ });
1770
+ const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
1771
+ $ZodType.init(inst, def);
1772
+ if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
1773
+ const values = new Set(def.values);
1774
+ inst._zod.values = values;
1775
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
1776
+ inst._zod.parse = (payload, _ctx) => {
1777
+ const input = payload.value;
1778
+ if (values.has(input)) return payload;
1779
+ payload.issues.push({
1780
+ code: "invalid_value",
1781
+ values: def.values,
1782
+ input,
1783
+ inst
1784
+ });
1785
+ return payload;
1786
+ };
1787
+ });
1788
+ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1789
+ $ZodType.init(inst, def);
1790
+ inst._zod.parse = (payload, ctx) => {
1791
+ if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
1792
+ const _out = def.transform(payload.value, payload);
1793
+ if (ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1794
+ payload.value = output;
1795
+ return payload;
1796
+ });
1797
+ if (_out instanceof Promise) throw new $ZodAsyncError();
1798
+ payload.value = _out;
1799
+ return payload;
1800
+ };
1801
+ });
1802
+ function handleOptionalResult(result, input) {
1803
+ if (result.issues.length && input === void 0) return {
1804
+ issues: [],
1805
+ value: void 0
1806
+ };
1807
+ return result;
1808
+ }
1809
+ const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1810
+ $ZodType.init(inst, def);
1811
+ inst._zod.optin = "optional";
1812
+ inst._zod.optout = "optional";
1813
+ defineLazy(inst._zod, "values", () => {
1814
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
1815
+ });
1816
+ defineLazy(inst._zod, "pattern", () => {
1817
+ const pattern = def.innerType._zod.pattern;
1818
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1819
+ });
1820
+ inst._zod.parse = (payload, ctx) => {
1821
+ if (def.innerType._zod.optin === "optional") {
1822
+ const result = def.innerType._zod.run(payload, ctx);
1823
+ if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, payload.value));
1824
+ return handleOptionalResult(result, payload.value);
1825
+ }
1826
+ if (payload.value === void 0) return payload;
1827
+ return def.innerType._zod.run(payload, ctx);
1828
+ };
1829
+ });
1830
+ const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
1831
+ $ZodOptional.init(inst, def);
1832
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1833
+ defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
1834
+ inst._zod.parse = (payload, ctx) => {
1835
+ return def.innerType._zod.run(payload, ctx);
1836
+ };
1837
+ });
1838
+ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1839
+ $ZodType.init(inst, def);
1840
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1841
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1842
+ defineLazy(inst._zod, "pattern", () => {
1843
+ const pattern = def.innerType._zod.pattern;
1844
+ return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1845
+ });
1846
+ defineLazy(inst._zod, "values", () => {
1847
+ return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
1848
+ });
1849
+ inst._zod.parse = (payload, ctx) => {
1850
+ if (payload.value === null) return payload;
1851
+ return def.innerType._zod.run(payload, ctx);
1852
+ };
1853
+ });
1854
+ const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1855
+ $ZodType.init(inst, def);
1856
+ inst._zod.optin = "optional";
1857
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1858
+ inst._zod.parse = (payload, ctx) => {
1859
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1860
+ if (payload.value === void 0) {
1861
+ payload.value = def.defaultValue;
1862
+ /**
1863
+ * $ZodDefault returns the default value immediately in forward direction.
1864
+ * 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. */
1865
+ return payload;
1866
+ }
1867
+ const result = def.innerType._zod.run(payload, ctx);
1868
+ if (result instanceof Promise) return result.then((result) => handleDefaultResult(result, def));
1869
+ return handleDefaultResult(result, def);
1870
+ };
1871
+ });
1872
+ function handleDefaultResult(payload, def) {
1873
+ if (payload.value === void 0) payload.value = def.defaultValue;
1874
+ return payload;
1875
+ }
1876
+ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
1877
+ $ZodType.init(inst, def);
1878
+ inst._zod.optin = "optional";
1879
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1880
+ inst._zod.parse = (payload, ctx) => {
1881
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1882
+ if (payload.value === void 0) payload.value = def.defaultValue;
1883
+ return def.innerType._zod.run(payload, ctx);
1884
+ };
1885
+ });
1886
+ const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
1887
+ $ZodType.init(inst, def);
1888
+ defineLazy(inst._zod, "values", () => {
1889
+ const v = def.innerType._zod.values;
1890
+ return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1891
+ });
1892
+ inst._zod.parse = (payload, ctx) => {
1893
+ const result = def.innerType._zod.run(payload, ctx);
1894
+ if (result instanceof Promise) return result.then((result) => handleNonOptionalResult(result, inst));
1895
+ return handleNonOptionalResult(result, inst);
1896
+ };
1897
+ });
1898
+ function handleNonOptionalResult(payload, inst) {
1899
+ if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1900
+ code: "invalid_type",
1901
+ expected: "nonoptional",
1902
+ input: payload.value,
1903
+ inst
1904
+ });
1905
+ return payload;
1906
+ }
1907
+ const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
1908
+ $ZodType.init(inst, def);
1909
+ defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1910
+ defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1911
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1912
+ inst._zod.parse = (payload, ctx) => {
1913
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1914
+ const result = def.innerType._zod.run(payload, ctx);
1915
+ if (result instanceof Promise) return result.then((result) => {
1916
+ payload.value = result.value;
1917
+ if (result.issues.length) {
1918
+ payload.value = def.catchValue({
1919
+ ...payload,
1920
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1921
+ input: payload.value
1922
+ });
1923
+ payload.issues = [];
1924
+ }
1925
+ return payload;
1926
+ });
1927
+ payload.value = result.value;
1928
+ if (result.issues.length) {
1929
+ payload.value = def.catchValue({
1930
+ ...payload,
1931
+ error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1932
+ input: payload.value
1933
+ });
1934
+ payload.issues = [];
1935
+ }
1936
+ return payload;
1937
+ };
1938
+ });
1939
+ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
1940
+ $ZodType.init(inst, def);
1941
+ defineLazy(inst._zod, "values", () => def.in._zod.values);
1942
+ defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1943
+ defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1944
+ defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
1945
+ inst._zod.parse = (payload, ctx) => {
1946
+ if (ctx.direction === "backward") {
1947
+ const right = def.out._zod.run(payload, ctx);
1948
+ if (right instanceof Promise) return right.then((right) => handlePipeResult(right, def.in, ctx));
1949
+ return handlePipeResult(right, def.in, ctx);
1950
+ }
1951
+ const left = def.in._zod.run(payload, ctx);
1952
+ if (left instanceof Promise) return left.then((left) => handlePipeResult(left, def.out, ctx));
1953
+ return handlePipeResult(left, def.out, ctx);
1954
+ };
1955
+ });
1956
+ function handlePipeResult(left, next, ctx) {
1957
+ if (left.issues.length) {
1958
+ left.aborted = true;
1959
+ return left;
1960
+ }
1961
+ return next._zod.run({
1962
+ value: left.value,
1963
+ issues: left.issues
1964
+ }, ctx);
1965
+ }
1966
+ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
1967
+ $ZodType.init(inst, def);
1968
+ defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1969
+ defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1970
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1971
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1972
+ inst._zod.parse = (payload, ctx) => {
1973
+ if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
1974
+ const result = def.innerType._zod.run(payload, ctx);
1975
+ if (result instanceof Promise) return result.then(handleReadonlyResult);
1976
+ return handleReadonlyResult(result);
1977
+ };
1978
+ });
1979
+ function handleReadonlyResult(payload) {
1980
+ payload.value = Object.freeze(payload.value);
1981
+ return payload;
1982
+ }
1983
+ const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
1984
+ $ZodCheck.init(inst, def);
1985
+ $ZodType.init(inst, def);
1986
+ inst._zod.parse = (payload, _) => {
1987
+ return payload;
1988
+ };
1989
+ inst._zod.check = (payload) => {
1990
+ const input = payload.value;
1991
+ const r = def.fn(input);
1992
+ if (r instanceof Promise) return r.then((r) => handleRefineResult(r, payload, input, inst));
1993
+ handleRefineResult(r, payload, input, inst);
1994
+ };
1995
+ });
1996
+ function handleRefineResult(result, payload, input, inst) {
1997
+ if (!result) {
1998
+ const _iss = {
1999
+ code: "custom",
2000
+ input,
2001
+ inst,
2002
+ path: [...inst._zod.def.path ?? []],
2003
+ continue: !inst._zod.def.abort
2004
+ };
2005
+ if (inst._zod.def.params) _iss.params = inst._zod.def.params;
2006
+ payload.issues.push(issue(_iss));
2007
+ }
2008
+ }
2009
+
2010
+ //#endregion
2011
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js
2012
+ var _a;
2013
+ var $ZodRegistry = class {
2014
+ constructor() {
2015
+ this._map = /* @__PURE__ */ new WeakMap();
2016
+ this._idmap = /* @__PURE__ */ new Map();
2017
+ }
2018
+ add(schema, ..._meta) {
2019
+ const meta = _meta[0];
2020
+ this._map.set(schema, meta);
2021
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.set(meta.id, schema);
2022
+ return this;
2023
+ }
2024
+ clear() {
2025
+ this._map = /* @__PURE__ */ new WeakMap();
2026
+ this._idmap = /* @__PURE__ */ new Map();
2027
+ return this;
2028
+ }
2029
+ remove(schema) {
2030
+ const meta = this._map.get(schema);
2031
+ if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
2032
+ this._map.delete(schema);
2033
+ return this;
2034
+ }
2035
+ get(schema) {
2036
+ const p = schema._zod.parent;
2037
+ if (p) {
2038
+ const pm = { ...this.get(p) ?? {} };
2039
+ delete pm.id;
2040
+ const f = {
2041
+ ...pm,
2042
+ ...this._map.get(schema)
2043
+ };
2044
+ return Object.keys(f).length ? f : void 0;
2045
+ }
2046
+ return this._map.get(schema);
2047
+ }
2048
+ has(schema) {
2049
+ return this._map.has(schema);
2050
+ }
2051
+ };
2052
+ function registry() {
2053
+ return new $ZodRegistry();
2054
+ }
2055
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2056
+ const globalRegistry = globalThis.__zod_globalRegistry;
2057
+
2058
+ //#endregion
2059
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/api.js
2060
+ /* @__NO_SIDE_EFFECTS__ */
2061
+ function _email(Class, params) {
2062
+ return new Class({
2063
+ type: "string",
2064
+ format: "email",
2065
+ check: "string_format",
2066
+ abort: false,
2067
+ ...normalizeParams(params)
2068
+ });
2069
+ }
2070
+ /* @__NO_SIDE_EFFECTS__ */
2071
+ function _guid(Class, params) {
2072
+ return new Class({
2073
+ type: "string",
2074
+ format: "guid",
2075
+ check: "string_format",
2076
+ abort: false,
2077
+ ...normalizeParams(params)
2078
+ });
2079
+ }
2080
+ /* @__NO_SIDE_EFFECTS__ */
2081
+ function _uuid(Class, params) {
2082
+ return new Class({
2083
+ type: "string",
2084
+ format: "uuid",
2085
+ check: "string_format",
2086
+ abort: false,
2087
+ ...normalizeParams(params)
2088
+ });
2089
+ }
2090
+ /* @__NO_SIDE_EFFECTS__ */
2091
+ function _uuidv4(Class, params) {
2092
+ return new Class({
2093
+ type: "string",
2094
+ format: "uuid",
2095
+ check: "string_format",
2096
+ abort: false,
2097
+ version: "v4",
2098
+ ...normalizeParams(params)
2099
+ });
2100
+ }
2101
+ /* @__NO_SIDE_EFFECTS__ */
2102
+ function _uuidv6(Class, params) {
2103
+ return new Class({
2104
+ type: "string",
2105
+ format: "uuid",
2106
+ check: "string_format",
2107
+ abort: false,
2108
+ version: "v6",
2109
+ ...normalizeParams(params)
2110
+ });
2111
+ }
2112
+ /* @__NO_SIDE_EFFECTS__ */
2113
+ function _uuidv7(Class, params) {
2114
+ return new Class({
2115
+ type: "string",
2116
+ format: "uuid",
2117
+ check: "string_format",
2118
+ abort: false,
2119
+ version: "v7",
2120
+ ...normalizeParams(params)
2121
+ });
2122
+ }
2123
+ /* @__NO_SIDE_EFFECTS__ */
2124
+ function _url(Class, params) {
2125
+ return new Class({
2126
+ type: "string",
2127
+ format: "url",
2128
+ check: "string_format",
2129
+ abort: false,
2130
+ ...normalizeParams(params)
2131
+ });
2132
+ }
2133
+ /* @__NO_SIDE_EFFECTS__ */
2134
+ function _emoji(Class, params) {
2135
+ return new Class({
2136
+ type: "string",
2137
+ format: "emoji",
2138
+ check: "string_format",
2139
+ abort: false,
2140
+ ...normalizeParams(params)
2141
+ });
2142
+ }
2143
+ /* @__NO_SIDE_EFFECTS__ */
2144
+ function _nanoid(Class, params) {
2145
+ return new Class({
2146
+ type: "string",
2147
+ format: "nanoid",
2148
+ check: "string_format",
2149
+ abort: false,
2150
+ ...normalizeParams(params)
2151
+ });
2152
+ }
2153
+ /* @__NO_SIDE_EFFECTS__ */
2154
+ function _cuid(Class, params) {
2155
+ return new Class({
2156
+ type: "string",
2157
+ format: "cuid",
2158
+ check: "string_format",
2159
+ abort: false,
2160
+ ...normalizeParams(params)
2161
+ });
2162
+ }
2163
+ /* @__NO_SIDE_EFFECTS__ */
2164
+ function _cuid2(Class, params) {
2165
+ return new Class({
2166
+ type: "string",
2167
+ format: "cuid2",
2168
+ check: "string_format",
2169
+ abort: false,
2170
+ ...normalizeParams(params)
2171
+ });
2172
+ }
2173
+ /* @__NO_SIDE_EFFECTS__ */
2174
+ function _ulid(Class, params) {
2175
+ return new Class({
2176
+ type: "string",
2177
+ format: "ulid",
2178
+ check: "string_format",
2179
+ abort: false,
2180
+ ...normalizeParams(params)
2181
+ });
2182
+ }
2183
+ /* @__NO_SIDE_EFFECTS__ */
2184
+ function _xid(Class, params) {
2185
+ return new Class({
2186
+ type: "string",
2187
+ format: "xid",
2188
+ check: "string_format",
2189
+ abort: false,
2190
+ ...normalizeParams(params)
2191
+ });
2192
+ }
2193
+ /* @__NO_SIDE_EFFECTS__ */
2194
+ function _ksuid(Class, params) {
2195
+ return new Class({
2196
+ type: "string",
2197
+ format: "ksuid",
2198
+ check: "string_format",
2199
+ abort: false,
2200
+ ...normalizeParams(params)
2201
+ });
2202
+ }
2203
+ /* @__NO_SIDE_EFFECTS__ */
2204
+ function _ipv4(Class, params) {
2205
+ return new Class({
2206
+ type: "string",
2207
+ format: "ipv4",
2208
+ check: "string_format",
2209
+ abort: false,
2210
+ ...normalizeParams(params)
2211
+ });
2212
+ }
2213
+ /* @__NO_SIDE_EFFECTS__ */
2214
+ function _ipv6(Class, params) {
2215
+ return new Class({
2216
+ type: "string",
2217
+ format: "ipv6",
2218
+ check: "string_format",
2219
+ abort: false,
2220
+ ...normalizeParams(params)
2221
+ });
2222
+ }
2223
+ /* @__NO_SIDE_EFFECTS__ */
2224
+ function _cidrv4(Class, params) {
2225
+ return new Class({
2226
+ type: "string",
2227
+ format: "cidrv4",
2228
+ check: "string_format",
2229
+ abort: false,
2230
+ ...normalizeParams(params)
2231
+ });
2232
+ }
2233
+ /* @__NO_SIDE_EFFECTS__ */
2234
+ function _cidrv6(Class, params) {
2235
+ return new Class({
2236
+ type: "string",
2237
+ format: "cidrv6",
2238
+ check: "string_format",
2239
+ abort: false,
2240
+ ...normalizeParams(params)
2241
+ });
2242
+ }
2243
+ /* @__NO_SIDE_EFFECTS__ */
2244
+ function _base64(Class, params) {
2245
+ return new Class({
2246
+ type: "string",
2247
+ format: "base64",
2248
+ check: "string_format",
2249
+ abort: false,
2250
+ ...normalizeParams(params)
2251
+ });
2252
+ }
2253
+ /* @__NO_SIDE_EFFECTS__ */
2254
+ function _base64url(Class, params) {
2255
+ return new Class({
2256
+ type: "string",
2257
+ format: "base64url",
2258
+ check: "string_format",
2259
+ abort: false,
2260
+ ...normalizeParams(params)
2261
+ });
2262
+ }
2263
+ /* @__NO_SIDE_EFFECTS__ */
2264
+ function _e164(Class, params) {
2265
+ return new Class({
2266
+ type: "string",
2267
+ format: "e164",
2268
+ check: "string_format",
2269
+ abort: false,
2270
+ ...normalizeParams(params)
2271
+ });
2272
+ }
2273
+ /* @__NO_SIDE_EFFECTS__ */
2274
+ function _jwt(Class, params) {
2275
+ return new Class({
2276
+ type: "string",
2277
+ format: "jwt",
2278
+ check: "string_format",
2279
+ abort: false,
2280
+ ...normalizeParams(params)
2281
+ });
2282
+ }
2283
+ /* @__NO_SIDE_EFFECTS__ */
2284
+ function _isoDateTime(Class, params) {
2285
+ return new Class({
2286
+ type: "string",
2287
+ format: "datetime",
2288
+ check: "string_format",
2289
+ offset: false,
2290
+ local: false,
2291
+ precision: null,
2292
+ ...normalizeParams(params)
2293
+ });
2294
+ }
2295
+ /* @__NO_SIDE_EFFECTS__ */
2296
+ function _isoDate(Class, params) {
2297
+ return new Class({
2298
+ type: "string",
2299
+ format: "date",
2300
+ check: "string_format",
2301
+ ...normalizeParams(params)
2302
+ });
2303
+ }
2304
+ /* @__NO_SIDE_EFFECTS__ */
2305
+ function _isoTime(Class, params) {
2306
+ return new Class({
2307
+ type: "string",
2308
+ format: "time",
2309
+ check: "string_format",
2310
+ precision: null,
2311
+ ...normalizeParams(params)
2312
+ });
2313
+ }
2314
+ /* @__NO_SIDE_EFFECTS__ */
2315
+ function _isoDuration(Class, params) {
2316
+ return new Class({
2317
+ type: "string",
2318
+ format: "duration",
2319
+ check: "string_format",
2320
+ ...normalizeParams(params)
2321
+ });
2322
+ }
2323
+ /* @__NO_SIDE_EFFECTS__ */
2324
+ function _unknown(Class) {
2325
+ return new Class({ type: "unknown" });
2326
+ }
2327
+ /* @__NO_SIDE_EFFECTS__ */
2328
+ function _never(Class, params) {
2329
+ return new Class({
2330
+ type: "never",
2331
+ ...normalizeParams(params)
2332
+ });
2333
+ }
2334
+ /* @__NO_SIDE_EFFECTS__ */
2335
+ function _maxLength(maximum, params) {
2336
+ return new $ZodCheckMaxLength({
2337
+ check: "max_length",
2338
+ ...normalizeParams(params),
2339
+ maximum
2340
+ });
2341
+ }
2342
+ /* @__NO_SIDE_EFFECTS__ */
2343
+ function _minLength(minimum, params) {
2344
+ return new $ZodCheckMinLength({
2345
+ check: "min_length",
2346
+ ...normalizeParams(params),
2347
+ minimum
2348
+ });
2349
+ }
2350
+ /* @__NO_SIDE_EFFECTS__ */
2351
+ function _length(length, params) {
2352
+ return new $ZodCheckLengthEquals({
2353
+ check: "length_equals",
2354
+ ...normalizeParams(params),
2355
+ length
2356
+ });
2357
+ }
2358
+ /* @__NO_SIDE_EFFECTS__ */
2359
+ function _regex(pattern, params) {
2360
+ return new $ZodCheckRegex({
2361
+ check: "string_format",
2362
+ format: "regex",
2363
+ ...normalizeParams(params),
2364
+ pattern
2365
+ });
2366
+ }
2367
+ /* @__NO_SIDE_EFFECTS__ */
2368
+ function _lowercase(params) {
2369
+ return new $ZodCheckLowerCase({
2370
+ check: "string_format",
2371
+ format: "lowercase",
2372
+ ...normalizeParams(params)
2373
+ });
2374
+ }
2375
+ /* @__NO_SIDE_EFFECTS__ */
2376
+ function _uppercase(params) {
2377
+ return new $ZodCheckUpperCase({
2378
+ check: "string_format",
2379
+ format: "uppercase",
2380
+ ...normalizeParams(params)
2381
+ });
2382
+ }
2383
+ /* @__NO_SIDE_EFFECTS__ */
2384
+ function _includes(includes, params) {
2385
+ return new $ZodCheckIncludes({
2386
+ check: "string_format",
2387
+ format: "includes",
2388
+ ...normalizeParams(params),
2389
+ includes
2390
+ });
2391
+ }
2392
+ /* @__NO_SIDE_EFFECTS__ */
2393
+ function _startsWith(prefix, params) {
2394
+ return new $ZodCheckStartsWith({
2395
+ check: "string_format",
2396
+ format: "starts_with",
2397
+ ...normalizeParams(params),
2398
+ prefix
2399
+ });
2400
+ }
2401
+ /* @__NO_SIDE_EFFECTS__ */
2402
+ function _endsWith(suffix, params) {
2403
+ return new $ZodCheckEndsWith({
2404
+ check: "string_format",
2405
+ format: "ends_with",
2406
+ ...normalizeParams(params),
2407
+ suffix
2408
+ });
2409
+ }
2410
+ /* @__NO_SIDE_EFFECTS__ */
2411
+ function _overwrite(tx) {
2412
+ return new $ZodCheckOverwrite({
2413
+ check: "overwrite",
2414
+ tx
2415
+ });
2416
+ }
2417
+ /* @__NO_SIDE_EFFECTS__ */
2418
+ function _normalize(form) {
2419
+ return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
2420
+ }
2421
+ /* @__NO_SIDE_EFFECTS__ */
2422
+ function _trim() {
2423
+ return /* @__PURE__ */ _overwrite((input) => input.trim());
2424
+ }
2425
+ /* @__NO_SIDE_EFFECTS__ */
2426
+ function _toLowerCase() {
2427
+ return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
2428
+ }
2429
+ /* @__NO_SIDE_EFFECTS__ */
2430
+ function _toUpperCase() {
2431
+ return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
2432
+ }
2433
+ /* @__NO_SIDE_EFFECTS__ */
2434
+ function _slugify() {
2435
+ return /* @__PURE__ */ _overwrite((input) => slugify(input));
2436
+ }
2437
+ /* @__NO_SIDE_EFFECTS__ */
2438
+ function _array(Class, element, params) {
2439
+ return new Class({
2440
+ type: "array",
2441
+ element,
2442
+ ...normalizeParams(params)
2443
+ });
2444
+ }
2445
+ /* @__NO_SIDE_EFFECTS__ */
2446
+ function _refine(Class, fn, _params) {
2447
+ return new Class({
2448
+ type: "custom",
2449
+ check: "custom",
2450
+ fn,
2451
+ ...normalizeParams(_params)
2452
+ });
2453
+ }
2454
+ /* @__NO_SIDE_EFFECTS__ */
2455
+ function _superRefine(fn) {
2456
+ const ch = /* @__PURE__ */ _check((payload) => {
2457
+ payload.addIssue = (issue$2) => {
2458
+ if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
2459
+ else {
2460
+ const _issue = issue$2;
2461
+ if (_issue.fatal) _issue.continue = false;
2462
+ _issue.code ?? (_issue.code = "custom");
2463
+ _issue.input ?? (_issue.input = payload.value);
2464
+ _issue.inst ?? (_issue.inst = ch);
2465
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2466
+ payload.issues.push(issue(_issue));
2467
+ }
2468
+ };
2469
+ return fn(payload.value, payload);
2470
+ });
2471
+ return ch;
2472
+ }
2473
+ /* @__NO_SIDE_EFFECTS__ */
2474
+ function _check(fn, params) {
2475
+ const ch = new $ZodCheck({
2476
+ check: "custom",
2477
+ ...normalizeParams(params)
2478
+ });
2479
+ ch._zod.check = fn;
2480
+ return ch;
2481
+ }
2482
+ /* @__NO_SIDE_EFFECTS__ */
2483
+ function describe$1(description) {
2484
+ const ch = new $ZodCheck({ check: "describe" });
2485
+ ch._zod.onattach = [(inst) => {
2486
+ const existing = globalRegistry.get(inst) ?? {};
2487
+ globalRegistry.add(inst, {
2488
+ ...existing,
2489
+ description
2490
+ });
2491
+ }];
2492
+ ch._zod.check = () => {};
2493
+ return ch;
2494
+ }
2495
+ /* @__NO_SIDE_EFFECTS__ */
2496
+ function meta$1(metadata) {
2497
+ const ch = new $ZodCheck({ check: "meta" });
2498
+ ch._zod.onattach = [(inst) => {
2499
+ const existing = globalRegistry.get(inst) ?? {};
2500
+ globalRegistry.add(inst, {
2501
+ ...existing,
2502
+ ...metadata
2503
+ });
2504
+ }];
2505
+ ch._zod.check = () => {};
2506
+ return ch;
2507
+ }
2508
+
2509
+ //#endregion
2510
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.js
2511
+ function initializeContext(params) {
2512
+ let target = params?.target ?? "draft-2020-12";
2513
+ if (target === "draft-4") target = "draft-04";
2514
+ if (target === "draft-7") target = "draft-07";
2515
+ return {
2516
+ processors: params.processors ?? {},
2517
+ metadataRegistry: params?.metadata ?? globalRegistry,
2518
+ target,
2519
+ unrepresentable: params?.unrepresentable ?? "throw",
2520
+ override: params?.override ?? (() => {}),
2521
+ io: params?.io ?? "output",
2522
+ counter: 0,
2523
+ seen: /* @__PURE__ */ new Map(),
2524
+ cycles: params?.cycles ?? "ref",
2525
+ reused: params?.reused ?? "inline",
2526
+ external: params?.external ?? void 0
2527
+ };
2528
+ }
2529
+ function process$1(schema, ctx, _params = {
2530
+ path: [],
2531
+ schemaPath: []
2532
+ }) {
2533
+ var _a;
2534
+ const def = schema._zod.def;
2535
+ const seen = ctx.seen.get(schema);
2536
+ if (seen) {
2537
+ seen.count++;
2538
+ if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
2539
+ return seen.schema;
2540
+ }
2541
+ const result = {
2542
+ schema: {},
2543
+ count: 1,
2544
+ cycle: void 0,
2545
+ path: _params.path
2546
+ };
2547
+ ctx.seen.set(schema, result);
2548
+ const overrideSchema = schema._zod.toJSONSchema?.();
2549
+ if (overrideSchema) result.schema = overrideSchema;
2550
+ else {
2551
+ const params = {
2552
+ ..._params,
2553
+ schemaPath: [..._params.schemaPath, schema],
2554
+ path: _params.path
2555
+ };
2556
+ if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
2557
+ else {
2558
+ const _json = result.schema;
2559
+ const processor = ctx.processors[def.type];
2560
+ if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
2561
+ processor(schema, ctx, _json, params);
2562
+ }
2563
+ const parent = schema._zod.parent;
2564
+ if (parent) {
2565
+ if (!result.ref) result.ref = parent;
2566
+ process$1(parent, ctx, params);
2567
+ ctx.seen.get(parent).isParent = true;
2568
+ }
2569
+ }
2570
+ const meta = ctx.metadataRegistry.get(schema);
2571
+ if (meta) Object.assign(result.schema, meta);
2572
+ if (ctx.io === "input" && isTransforming(schema)) {
2573
+ delete result.schema.examples;
2574
+ delete result.schema.default;
2575
+ }
2576
+ if (ctx.io === "input" && result.schema._prefault) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
2577
+ delete result.schema._prefault;
2578
+ return ctx.seen.get(schema).schema;
2579
+ }
2580
+ function extractDefs(ctx, schema) {
2581
+ const root = ctx.seen.get(schema);
2582
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2583
+ const idToSchema = /* @__PURE__ */ new Map();
2584
+ for (const entry of ctx.seen.entries()) {
2585
+ const id = ctx.metadataRegistry.get(entry[0])?.id;
2586
+ if (id) {
2587
+ const existing = idToSchema.get(id);
2588
+ 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.`);
2589
+ idToSchema.set(id, entry[0]);
2590
+ }
2591
+ }
2592
+ const makeURI = (entry) => {
2593
+ const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
2594
+ if (ctx.external) {
2595
+ const externalId = ctx.external.registry.get(entry[0])?.id;
2596
+ const uriGenerator = ctx.external.uri ?? ((id) => id);
2597
+ if (externalId) return { ref: uriGenerator(externalId) };
2598
+ const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
2599
+ entry[1].defId = id;
2600
+ return {
2601
+ defId: id,
2602
+ ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
2603
+ };
2604
+ }
2605
+ if (entry[1] === root) return { ref: "#" };
2606
+ const defUriPrefix = `#/${defsSegment}/`;
2607
+ const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
2608
+ return {
2609
+ defId,
2610
+ ref: defUriPrefix + defId
2611
+ };
2612
+ };
2613
+ const extractToDef = (entry) => {
2614
+ if (entry[1].schema.$ref) return;
2615
+ const seen = entry[1];
2616
+ const { ref, defId } = makeURI(entry);
2617
+ seen.def = { ...seen.schema };
2618
+ if (defId) seen.defId = defId;
2619
+ const schema = seen.schema;
2620
+ for (const key in schema) delete schema[key];
2621
+ schema.$ref = ref;
2622
+ };
2623
+ if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
2624
+ const seen = entry[1];
2625
+ if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
2626
+
2627
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
2628
+ }
2629
+ for (const entry of ctx.seen.entries()) {
2630
+ const seen = entry[1];
2631
+ if (schema === entry[0]) {
2632
+ extractToDef(entry);
2633
+ continue;
2634
+ }
2635
+ if (ctx.external) {
2636
+ const ext = ctx.external.registry.get(entry[0])?.id;
2637
+ if (schema !== entry[0] && ext) {
2638
+ extractToDef(entry);
2639
+ continue;
2640
+ }
2641
+ }
2642
+ if (ctx.metadataRegistry.get(entry[0])?.id) {
2643
+ extractToDef(entry);
2644
+ continue;
2645
+ }
2646
+ if (seen.cycle) {
2647
+ extractToDef(entry);
2648
+ continue;
2649
+ }
2650
+ if (seen.count > 1) {
2651
+ if (ctx.reused === "ref") {
2652
+ extractToDef(entry);
2653
+ continue;
2654
+ }
2655
+ }
2656
+ }
2657
+ }
2658
+ function finalize(ctx, schema) {
2659
+ const root = ctx.seen.get(schema);
2660
+ if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
2661
+ const flattenRef = (zodSchema) => {
2662
+ const seen = ctx.seen.get(zodSchema);
2663
+ if (seen.ref === null) return;
2664
+ const schema = seen.def ?? seen.schema;
2665
+ const _cached = { ...schema };
2666
+ const ref = seen.ref;
2667
+ seen.ref = null;
2668
+ if (ref) {
2669
+ flattenRef(ref);
2670
+ const refSeen = ctx.seen.get(ref);
2671
+ const refSchema = refSeen.schema;
2672
+ if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
2673
+ schema.allOf = schema.allOf ?? [];
2674
+ schema.allOf.push(refSchema);
2675
+ } else Object.assign(schema, refSchema);
2676
+ Object.assign(schema, _cached);
2677
+ if (zodSchema._zod.parent === ref) for (const key in schema) {
2678
+ if (key === "$ref" || key === "allOf") continue;
2679
+ if (!(key in _cached)) delete schema[key];
2680
+ }
2681
+ if (refSchema.$ref && refSeen.def) for (const key in schema) {
2682
+ if (key === "$ref" || key === "allOf") continue;
2683
+ if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
2684
+ }
2685
+ }
2686
+ const parent = zodSchema._zod.parent;
2687
+ if (parent && parent !== ref) {
2688
+ flattenRef(parent);
2689
+ const parentSeen = ctx.seen.get(parent);
2690
+ if (parentSeen?.schema.$ref) {
2691
+ schema.$ref = parentSeen.schema.$ref;
2692
+ if (parentSeen.def) for (const key in schema) {
2693
+ if (key === "$ref" || key === "allOf") continue;
2694
+ if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
2695
+ }
2696
+ }
2697
+ }
2698
+ ctx.override({
2699
+ zodSchema,
2700
+ jsonSchema: schema,
2701
+ path: seen.path ?? []
2702
+ });
2703
+ };
2704
+ for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
2705
+ const result = {};
2706
+ if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
2707
+ else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
2708
+ else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
2709
+ else if (ctx.target === "openapi-3.0") {}
2710
+ if (ctx.external?.uri) {
2711
+ const id = ctx.external.registry.get(schema)?.id;
2712
+ if (!id) throw new Error("Schema is missing an `id` property");
2713
+ result.$id = ctx.external.uri(id);
2714
+ }
2715
+ Object.assign(result, root.def ?? root.schema);
2716
+ const defs = ctx.external?.defs ?? {};
2717
+ for (const entry of ctx.seen.entries()) {
2718
+ const seen = entry[1];
2719
+ if (seen.def && seen.defId) defs[seen.defId] = seen.def;
2720
+ }
2721
+ if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
2722
+ else result.definitions = defs;
2723
+ try {
2724
+ const finalized = JSON.parse(JSON.stringify(result));
2725
+ Object.defineProperty(finalized, "~standard", {
2726
+ value: {
2727
+ ...schema["~standard"],
2728
+ jsonSchema: {
2729
+ input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
2730
+ output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
2731
+ }
2732
+ },
2733
+ enumerable: false,
2734
+ writable: false
2735
+ });
2736
+ return finalized;
2737
+ } catch (_err) {
2738
+ throw new Error("Error converting schema to JSON.");
2739
+ }
2740
+ }
2741
+ function isTransforming(_schema, _ctx) {
2742
+ const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
2743
+ if (ctx.seen.has(_schema)) return false;
2744
+ ctx.seen.add(_schema);
2745
+ const def = _schema._zod.def;
2746
+ if (def.type === "transform") return true;
2747
+ if (def.type === "array") return isTransforming(def.element, ctx);
2748
+ if (def.type === "set") return isTransforming(def.valueType, ctx);
2749
+ if (def.type === "lazy") return isTransforming(def.getter(), ctx);
2750
+ 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);
2751
+ if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
2752
+ if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
2753
+ if (def.type === "pipe") return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
2754
+ if (def.type === "object") {
2755
+ for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
2756
+ return false;
2757
+ }
2758
+ if (def.type === "union") {
2759
+ for (const option of def.options) if (isTransforming(option, ctx)) return true;
2760
+ return false;
2761
+ }
2762
+ if (def.type === "tuple") {
2763
+ for (const item of def.items) if (isTransforming(item, ctx)) return true;
2764
+ if (def.rest && isTransforming(def.rest, ctx)) return true;
2765
+ return false;
2766
+ }
2767
+ return false;
2768
+ }
2769
+ /**
2770
+ * Creates a toJSONSchema method for a schema instance.
2771
+ * This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
2772
+ */
2773
+ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
2774
+ const ctx = initializeContext({
2775
+ ...params,
2776
+ processors
2777
+ });
2778
+ process$1(schema, ctx);
2779
+ extractDefs(ctx, schema);
2780
+ return finalize(ctx, schema);
2781
+ };
2782
+ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
2783
+ const { libraryOptions, target } = params ?? {};
2784
+ const ctx = initializeContext({
2785
+ ...libraryOptions ?? {},
2786
+ target,
2787
+ io,
2788
+ processors
2789
+ });
2790
+ process$1(schema, ctx);
2791
+ extractDefs(ctx, schema);
2792
+ return finalize(ctx, schema);
2793
+ };
2794
+
2795
+ //#endregion
2796
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema-processors.js
2797
+ const formatMap = {
2798
+ guid: "uuid",
2799
+ url: "uri",
2800
+ datetime: "date-time",
2801
+ json_string: "json-string",
2802
+ regex: ""
2803
+ };
2804
+ const stringProcessor = (schema, ctx, _json, _params) => {
2805
+ const json = _json;
2806
+ json.type = "string";
2807
+ const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
2808
+ if (typeof minimum === "number") json.minLength = minimum;
2809
+ if (typeof maximum === "number") json.maxLength = maximum;
2810
+ if (format) {
2811
+ json.format = formatMap[format] ?? format;
2812
+ if (json.format === "") delete json.format;
2813
+ if (format === "time") delete json.format;
2814
+ }
2815
+ if (contentEncoding) json.contentEncoding = contentEncoding;
2816
+ if (patterns && patterns.size > 0) {
2817
+ const regexes = [...patterns];
2818
+ if (regexes.length === 1) json.pattern = regexes[0].source;
2819
+ else if (regexes.length > 1) json.allOf = [...regexes.map((regex) => ({
2820
+ ...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
2821
+ pattern: regex.source
2822
+ }))];
2823
+ }
2824
+ };
2825
+ const neverProcessor = (_schema, _ctx, json, _params) => {
2826
+ json.not = {};
2827
+ };
2828
+ const unknownProcessor = (_schema, _ctx, _json, _params) => {};
2829
+ const enumProcessor = (schema, _ctx, json, _params) => {
2830
+ const def = schema._zod.def;
2831
+ const values = getEnumValues(def.entries);
2832
+ if (values.every((v) => typeof v === "number")) json.type = "number";
2833
+ if (values.every((v) => typeof v === "string")) json.type = "string";
2834
+ json.enum = values;
2835
+ };
2836
+ const literalProcessor = (schema, ctx, json, _params) => {
2837
+ const def = schema._zod.def;
2838
+ const vals = [];
2839
+ for (const val of def.values) if (val === void 0) {
2840
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
2841
+ } else if (typeof val === "bigint") if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
2842
+ else vals.push(Number(val));
2843
+ else vals.push(val);
2844
+ if (vals.length === 0) {} else if (vals.length === 1) {
2845
+ const val = vals[0];
2846
+ json.type = val === null ? "null" : typeof val;
2847
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
2848
+ else json.const = val;
2849
+ } else {
2850
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
2851
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
2852
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
2853
+ if (vals.every((v) => v === null)) json.type = "null";
2854
+ json.enum = vals;
2855
+ }
2856
+ };
2857
+ const customProcessor = (_schema, ctx, _json, _params) => {
2858
+ if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
2859
+ };
2860
+ const transformProcessor = (_schema, ctx, _json, _params) => {
2861
+ if (ctx.unrepresentable === "throw") throw new Error("Transforms cannot be represented in JSON Schema");
2862
+ };
2863
+ const arrayProcessor = (schema, ctx, _json, params) => {
2864
+ const json = _json;
2865
+ const def = schema._zod.def;
2866
+ const { minimum, maximum } = schema._zod.bag;
2867
+ if (typeof minimum === "number") json.minItems = minimum;
2868
+ if (typeof maximum === "number") json.maxItems = maximum;
2869
+ json.type = "array";
2870
+ json.items = process$1(def.element, ctx, {
2871
+ ...params,
2872
+ path: [...params.path, "items"]
2873
+ });
2874
+ };
2875
+ const objectProcessor = (schema, ctx, _json, params) => {
2876
+ const json = _json;
2877
+ const def = schema._zod.def;
2878
+ json.type = "object";
2879
+ json.properties = {};
2880
+ const shape = def.shape;
2881
+ for (const key in shape) json.properties[key] = process$1(shape[key], ctx, {
2882
+ ...params,
2883
+ path: [
2884
+ ...params.path,
2885
+ "properties",
2886
+ key
2887
+ ]
2888
+ });
2889
+ const allKeys = new Set(Object.keys(shape));
2890
+ const requiredKeys = new Set([...allKeys].filter((key) => {
2891
+ const v = def.shape[key]._zod;
2892
+ if (ctx.io === "input") return v.optin === void 0;
2893
+ else return v.optout === void 0;
2894
+ }));
2895
+ if (requiredKeys.size > 0) json.required = Array.from(requiredKeys);
2896
+ if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
2897
+ else if (!def.catchall) {
2898
+ if (ctx.io === "output") json.additionalProperties = false;
2899
+ } else if (def.catchall) json.additionalProperties = process$1(def.catchall, ctx, {
2900
+ ...params,
2901
+ path: [...params.path, "additionalProperties"]
2902
+ });
2903
+ };
2904
+ const unionProcessor = (schema, ctx, json, params) => {
2905
+ const def = schema._zod.def;
2906
+ const isExclusive = def.inclusive === false;
2907
+ const options = def.options.map((x, i) => process$1(x, ctx, {
2908
+ ...params,
2909
+ path: [
2910
+ ...params.path,
2911
+ isExclusive ? "oneOf" : "anyOf",
2912
+ i
2913
+ ]
2914
+ }));
2915
+ if (isExclusive) json.oneOf = options;
2916
+ else json.anyOf = options;
2917
+ };
2918
+ const intersectionProcessor = (schema, ctx, json, params) => {
2919
+ const def = schema._zod.def;
2920
+ const a = process$1(def.left, ctx, {
2921
+ ...params,
2922
+ path: [
2923
+ ...params.path,
2924
+ "allOf",
2925
+ 0
2926
+ ]
2927
+ });
2928
+ const b = process$1(def.right, ctx, {
2929
+ ...params,
2930
+ path: [
2931
+ ...params.path,
2932
+ "allOf",
2933
+ 1
2934
+ ]
2935
+ });
2936
+ const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
2937
+ json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
2938
+ };
2939
+ const nullableProcessor = (schema, ctx, json, params) => {
2940
+ const def = schema._zod.def;
2941
+ const inner = process$1(def.innerType, ctx, params);
2942
+ const seen = ctx.seen.get(schema);
2943
+ if (ctx.target === "openapi-3.0") {
2944
+ seen.ref = def.innerType;
2945
+ json.nullable = true;
2946
+ } else json.anyOf = [inner, { type: "null" }];
2947
+ };
2948
+ const nonoptionalProcessor = (schema, ctx, _json, params) => {
2949
+ const def = schema._zod.def;
2950
+ process$1(def.innerType, ctx, params);
2951
+ const seen = ctx.seen.get(schema);
2952
+ seen.ref = def.innerType;
2953
+ };
2954
+ const defaultProcessor = (schema, ctx, json, params) => {
2955
+ const def = schema._zod.def;
2956
+ process$1(def.innerType, ctx, params);
2957
+ const seen = ctx.seen.get(schema);
2958
+ seen.ref = def.innerType;
2959
+ json.default = JSON.parse(JSON.stringify(def.defaultValue));
2960
+ };
2961
+ const prefaultProcessor = (schema, ctx, json, params) => {
2962
+ const def = schema._zod.def;
2963
+ process$1(def.innerType, ctx, params);
2964
+ const seen = ctx.seen.get(schema);
2965
+ seen.ref = def.innerType;
2966
+ if (ctx.io === "input") json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
2967
+ };
2968
+ const catchProcessor = (schema, ctx, json, params) => {
2969
+ const def = schema._zod.def;
2970
+ process$1(def.innerType, ctx, params);
2971
+ const seen = ctx.seen.get(schema);
2972
+ seen.ref = def.innerType;
2973
+ let catchValue;
2974
+ try {
2975
+ catchValue = def.catchValue(void 0);
2976
+ } catch {
2977
+ throw new Error("Dynamic catch values are not supported in JSON Schema");
2978
+ }
2979
+ json.default = catchValue;
2980
+ };
2981
+ const pipeProcessor = (schema, ctx, _json, params) => {
2982
+ const def = schema._zod.def;
2983
+ const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
2984
+ process$1(innerType, ctx, params);
2985
+ const seen = ctx.seen.get(schema);
2986
+ seen.ref = innerType;
2987
+ };
2988
+ const readonlyProcessor = (schema, ctx, json, params) => {
2989
+ const def = schema._zod.def;
2990
+ process$1(def.innerType, ctx, params);
2991
+ const seen = ctx.seen.get(schema);
2992
+ seen.ref = def.innerType;
2993
+ json.readOnly = true;
2994
+ };
2995
+ const optionalProcessor = (schema, ctx, _json, params) => {
2996
+ const def = schema._zod.def;
2997
+ process$1(def.innerType, ctx, params);
2998
+ const seen = ctx.seen.get(schema);
2999
+ seen.ref = def.innerType;
3000
+ };
3001
+
3002
+ //#endregion
3003
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/iso.js
3004
+ const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
3005
+ $ZodISODateTime.init(inst, def);
3006
+ ZodStringFormat.init(inst, def);
3007
+ });
3008
+ function datetime(params) {
3009
+ return _isoDateTime(ZodISODateTime, params);
3010
+ }
3011
+ const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
3012
+ $ZodISODate.init(inst, def);
3013
+ ZodStringFormat.init(inst, def);
3014
+ });
3015
+ function date(params) {
3016
+ return _isoDate(ZodISODate, params);
3017
+ }
3018
+ const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
3019
+ $ZodISOTime.init(inst, def);
3020
+ ZodStringFormat.init(inst, def);
3021
+ });
3022
+ function time(params) {
3023
+ return _isoTime(ZodISOTime, params);
3024
+ }
3025
+ const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
3026
+ $ZodISODuration.init(inst, def);
3027
+ ZodStringFormat.init(inst, def);
3028
+ });
3029
+ function duration(params) {
3030
+ return _isoDuration(ZodISODuration, params);
3031
+ }
3032
+
3033
+ //#endregion
3034
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
3035
+ const initializer = (inst, issues) => {
3036
+ $ZodError.init(inst, issues);
3037
+ inst.name = "ZodError";
3038
+ Object.defineProperties(inst, {
3039
+ format: { value: (mapper) => formatError(inst, mapper) },
3040
+ flatten: { value: (mapper) => flattenError(inst, mapper) },
3041
+ addIssue: { value: (issue) => {
3042
+ inst.issues.push(issue);
3043
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3044
+ } },
3045
+ addIssues: { value: (issues) => {
3046
+ inst.issues.push(...issues);
3047
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
3048
+ } },
3049
+ isEmpty: { get() {
3050
+ return inst.issues.length === 0;
3051
+ } }
3052
+ });
3053
+ };
3054
+ const ZodError = $constructor("ZodError", initializer);
3055
+ const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
3056
+
3057
+ //#endregion
3058
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/parse.js
3059
+ const parse = /* @__PURE__ */ _parse(ZodRealError);
3060
+ const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
3061
+ const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
3062
+ const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
3063
+ const encode = /* @__PURE__ */ _encode(ZodRealError);
3064
+ const decode = /* @__PURE__ */ _decode(ZodRealError);
3065
+ const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
3066
+ const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
3067
+ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
3068
+ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
3069
+ const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
3070
+ const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
3071
+
3072
+ //#endregion
3073
+ //#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js
3074
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
3075
+ $ZodType.init(inst, def);
3076
+ Object.assign(inst["~standard"], { jsonSchema: {
3077
+ input: createStandardJSONSchemaMethod(inst, "input"),
3078
+ output: createStandardJSONSchemaMethod(inst, "output")
3079
+ } });
3080
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
3081
+ inst.def = def;
3082
+ inst.type = def.type;
3083
+ Object.defineProperty(inst, "_def", { value: def });
3084
+ inst.check = (...checks) => {
3085
+ return inst.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
3086
+ check: ch,
3087
+ def: { check: "custom" },
3088
+ onattach: []
3089
+ } } : ch)] }), { parent: true });
3090
+ };
3091
+ inst.with = inst.check;
3092
+ inst.clone = (def, params) => clone(inst, def, params);
3093
+ inst.brand = () => inst;
3094
+ inst.register = ((reg, meta) => {
3095
+ reg.add(inst, meta);
3096
+ return inst;
3097
+ });
3098
+ inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
3099
+ inst.safeParse = (data, params) => safeParse(inst, data, params);
3100
+ inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
3101
+ inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
3102
+ inst.spa = inst.safeParseAsync;
3103
+ inst.encode = (data, params) => encode(inst, data, params);
3104
+ inst.decode = (data, params) => decode(inst, data, params);
3105
+ inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
3106
+ inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
3107
+ inst.safeEncode = (data, params) => safeEncode(inst, data, params);
3108
+ inst.safeDecode = (data, params) => safeDecode(inst, data, params);
3109
+ inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
3110
+ inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
3111
+ inst.refine = (check, params) => inst.check(refine(check, params));
3112
+ inst.superRefine = (refinement) => inst.check(superRefine(refinement));
3113
+ inst.overwrite = (fn) => inst.check(_overwrite(fn));
3114
+ inst.optional = () => optional(inst);
3115
+ inst.exactOptional = () => exactOptional(inst);
3116
+ inst.nullable = () => nullable(inst);
3117
+ inst.nullish = () => optional(nullable(inst));
3118
+ inst.nonoptional = (params) => nonoptional(inst, params);
3119
+ inst.array = () => array(inst);
3120
+ inst.or = (arg) => union([inst, arg]);
3121
+ inst.and = (arg) => intersection(inst, arg);
3122
+ inst.transform = (tx) => pipe(inst, transform(tx));
3123
+ inst.default = (def) => _default(inst, def);
3124
+ inst.prefault = (def) => prefault(inst, def);
3125
+ inst.catch = (params) => _catch(inst, params);
3126
+ inst.pipe = (target) => pipe(inst, target);
3127
+ inst.readonly = () => readonly(inst);
3128
+ inst.describe = (description) => {
3129
+ const cl = inst.clone();
3130
+ globalRegistry.add(cl, { description });
3131
+ return cl;
3132
+ };
3133
+ Object.defineProperty(inst, "description", {
3134
+ get() {
3135
+ return globalRegistry.get(inst)?.description;
3136
+ },
3137
+ configurable: true
3138
+ });
3139
+ inst.meta = (...args) => {
3140
+ if (args.length === 0) return globalRegistry.get(inst);
3141
+ const cl = inst.clone();
3142
+ globalRegistry.add(cl, args[0]);
3143
+ return cl;
3144
+ };
3145
+ inst.isOptional = () => inst.safeParse(void 0).success;
3146
+ inst.isNullable = () => inst.safeParse(null).success;
3147
+ inst.apply = (fn) => fn(inst);
3148
+ return inst;
3149
+ });
3150
+ /** @internal */
3151
+ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
3152
+ $ZodString.init(inst, def);
3153
+ ZodType.init(inst, def);
3154
+ inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
3155
+ const bag = inst._zod.bag;
3156
+ inst.format = bag.format ?? null;
3157
+ inst.minLength = bag.minimum ?? null;
3158
+ inst.maxLength = bag.maximum ?? null;
3159
+ inst.regex = (...args) => inst.check(_regex(...args));
3160
+ inst.includes = (...args) => inst.check(_includes(...args));
3161
+ inst.startsWith = (...args) => inst.check(_startsWith(...args));
3162
+ inst.endsWith = (...args) => inst.check(_endsWith(...args));
3163
+ inst.min = (...args) => inst.check(_minLength(...args));
3164
+ inst.max = (...args) => inst.check(_maxLength(...args));
3165
+ inst.length = (...args) => inst.check(_length(...args));
3166
+ inst.nonempty = (...args) => inst.check(_minLength(1, ...args));
3167
+ inst.lowercase = (params) => inst.check(_lowercase(params));
3168
+ inst.uppercase = (params) => inst.check(_uppercase(params));
3169
+ inst.trim = () => inst.check(_trim());
3170
+ inst.normalize = (...args) => inst.check(_normalize(...args));
3171
+ inst.toLowerCase = () => inst.check(_toLowerCase());
3172
+ inst.toUpperCase = () => inst.check(_toUpperCase());
3173
+ inst.slugify = () => inst.check(_slugify());
3174
+ });
3175
+ const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
3176
+ $ZodString.init(inst, def);
3177
+ _ZodString.init(inst, def);
3178
+ inst.email = (params) => inst.check(_email(ZodEmail, params));
3179
+ inst.url = (params) => inst.check(_url(ZodURL, params));
3180
+ inst.jwt = (params) => inst.check(_jwt(ZodJWT, params));
3181
+ inst.emoji = (params) => inst.check(_emoji(ZodEmoji, params));
3182
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3183
+ inst.uuid = (params) => inst.check(_uuid(ZodUUID, params));
3184
+ inst.uuidv4 = (params) => inst.check(_uuidv4(ZodUUID, params));
3185
+ inst.uuidv6 = (params) => inst.check(_uuidv6(ZodUUID, params));
3186
+ inst.uuidv7 = (params) => inst.check(_uuidv7(ZodUUID, params));
3187
+ inst.nanoid = (params) => inst.check(_nanoid(ZodNanoID, params));
3188
+ inst.guid = (params) => inst.check(_guid(ZodGUID, params));
3189
+ inst.cuid = (params) => inst.check(_cuid(ZodCUID, params));
3190
+ inst.cuid2 = (params) => inst.check(_cuid2(ZodCUID2, params));
3191
+ inst.ulid = (params) => inst.check(_ulid(ZodULID, params));
3192
+ inst.base64 = (params) => inst.check(_base64(ZodBase64, params));
3193
+ inst.base64url = (params) => inst.check(_base64url(ZodBase64URL, params));
3194
+ inst.xid = (params) => inst.check(_xid(ZodXID, params));
3195
+ inst.ksuid = (params) => inst.check(_ksuid(ZodKSUID, params));
3196
+ inst.ipv4 = (params) => inst.check(_ipv4(ZodIPv4, params));
3197
+ inst.ipv6 = (params) => inst.check(_ipv6(ZodIPv6, params));
3198
+ inst.cidrv4 = (params) => inst.check(_cidrv4(ZodCIDRv4, params));
3199
+ inst.cidrv6 = (params) => inst.check(_cidrv6(ZodCIDRv6, params));
3200
+ inst.e164 = (params) => inst.check(_e164(ZodE164, params));
3201
+ inst.datetime = (params) => inst.check(datetime(params));
3202
+ inst.date = (params) => inst.check(date(params));
3203
+ inst.time = (params) => inst.check(time(params));
3204
+ inst.duration = (params) => inst.check(duration(params));
3205
+ });
3206
+ const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
3207
+ $ZodStringFormat.init(inst, def);
3208
+ _ZodString.init(inst, def);
3209
+ });
3210
+ const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
3211
+ $ZodEmail.init(inst, def);
3212
+ ZodStringFormat.init(inst, def);
3213
+ });
3214
+ const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
3215
+ $ZodGUID.init(inst, def);
3216
+ ZodStringFormat.init(inst, def);
3217
+ });
3218
+ const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
3219
+ $ZodUUID.init(inst, def);
3220
+ ZodStringFormat.init(inst, def);
3221
+ });
3222
+ const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
3223
+ $ZodURL.init(inst, def);
3224
+ ZodStringFormat.init(inst, def);
3225
+ });
3226
+ const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
3227
+ $ZodEmoji.init(inst, def);
3228
+ ZodStringFormat.init(inst, def);
3229
+ });
3230
+ const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
3231
+ $ZodNanoID.init(inst, def);
3232
+ ZodStringFormat.init(inst, def);
3233
+ });
3234
+ const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
3235
+ $ZodCUID.init(inst, def);
3236
+ ZodStringFormat.init(inst, def);
3237
+ });
3238
+ const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
3239
+ $ZodCUID2.init(inst, def);
3240
+ ZodStringFormat.init(inst, def);
3241
+ });
3242
+ const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
3243
+ $ZodULID.init(inst, def);
3244
+ ZodStringFormat.init(inst, def);
3245
+ });
3246
+ const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
3247
+ $ZodXID.init(inst, def);
3248
+ ZodStringFormat.init(inst, def);
3249
+ });
3250
+ const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
3251
+ $ZodKSUID.init(inst, def);
3252
+ ZodStringFormat.init(inst, def);
3253
+ });
3254
+ const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
3255
+ $ZodIPv4.init(inst, def);
3256
+ ZodStringFormat.init(inst, def);
3257
+ });
3258
+ const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
3259
+ $ZodIPv6.init(inst, def);
3260
+ ZodStringFormat.init(inst, def);
3261
+ });
3262
+ const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
3263
+ $ZodCIDRv4.init(inst, def);
3264
+ ZodStringFormat.init(inst, def);
3265
+ });
3266
+ const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
3267
+ $ZodCIDRv6.init(inst, def);
3268
+ ZodStringFormat.init(inst, def);
3269
+ });
3270
+ const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
3271
+ $ZodBase64.init(inst, def);
3272
+ ZodStringFormat.init(inst, def);
3273
+ });
3274
+ const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
3275
+ $ZodBase64URL.init(inst, def);
3276
+ ZodStringFormat.init(inst, def);
3277
+ });
3278
+ const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
3279
+ $ZodE164.init(inst, def);
3280
+ ZodStringFormat.init(inst, def);
3281
+ });
3282
+ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
3283
+ $ZodJWT.init(inst, def);
3284
+ ZodStringFormat.init(inst, def);
3285
+ });
3286
+ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3287
+ $ZodUnknown.init(inst, def);
3288
+ ZodType.init(inst, def);
3289
+ inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor(inst, ctx, json, params);
3290
+ });
3291
+ function unknown() {
3292
+ return _unknown(ZodUnknown);
3293
+ }
3294
+ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3295
+ $ZodNever.init(inst, def);
3296
+ ZodType.init(inst, def);
3297
+ inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json, params);
3298
+ });
3299
+ function never(params) {
3300
+ return _never(ZodNever, params);
3301
+ }
3302
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3303
+ $ZodArray.init(inst, def);
3304
+ ZodType.init(inst, def);
3305
+ inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
3306
+ inst.element = def.element;
3307
+ inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
3308
+ inst.nonempty = (params) => inst.check(_minLength(1, params));
3309
+ inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
3310
+ inst.length = (len, params) => inst.check(_length(len, params));
3311
+ inst.unwrap = () => inst.element;
3312
+ });
3313
+ function array(element, params) {
3314
+ return _array(ZodArray, element, params);
3315
+ }
3316
+ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3317
+ $ZodObjectJIT.init(inst, def);
3318
+ ZodType.init(inst, def);
3319
+ inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
3320
+ defineLazy(inst, "shape", () => {
3321
+ return def.shape;
3322
+ });
3323
+ inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
3324
+ inst.catchall = (catchall) => inst.clone({
3325
+ ...inst._zod.def,
3326
+ catchall
3327
+ });
3328
+ inst.passthrough = () => inst.clone({
3329
+ ...inst._zod.def,
3330
+ catchall: unknown()
3331
+ });
3332
+ inst.loose = () => inst.clone({
3333
+ ...inst._zod.def,
3334
+ catchall: unknown()
3335
+ });
3336
+ inst.strict = () => inst.clone({
3337
+ ...inst._zod.def,
3338
+ catchall: never()
3339
+ });
3340
+ inst.strip = () => inst.clone({
3341
+ ...inst._zod.def,
3342
+ catchall: void 0
3343
+ });
3344
+ inst.extend = (incoming) => {
3345
+ return extend(inst, incoming);
3346
+ };
3347
+ inst.safeExtend = (incoming) => {
3348
+ return safeExtend(inst, incoming);
3349
+ };
3350
+ inst.merge = (other) => merge(inst, other);
3351
+ inst.pick = (mask) => pick(inst, mask);
3352
+ inst.omit = (mask) => omit(inst, mask);
3353
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
3354
+ inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
3355
+ });
3356
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3357
+ $ZodUnion.init(inst, def);
3358
+ ZodType.init(inst, def);
3359
+ inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
3360
+ inst.options = def.options;
3361
+ });
3362
+ function union(options, params) {
3363
+ return new ZodUnion({
3364
+ type: "union",
3365
+ options,
3366
+ ...normalizeParams(params)
3367
+ });
3368
+ }
3369
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3370
+ $ZodIntersection.init(inst, def);
3371
+ ZodType.init(inst, def);
3372
+ inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
3373
+ });
3374
+ function intersection(left, right) {
3375
+ return new ZodIntersection({
3376
+ type: "intersection",
3377
+ left,
3378
+ right
3379
+ });
3380
+ }
3381
+ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3382
+ $ZodEnum.init(inst, def);
3383
+ ZodType.init(inst, def);
3384
+ inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
3385
+ inst.enum = def.entries;
3386
+ inst.options = Object.values(def.entries);
3387
+ const keys = new Set(Object.keys(def.entries));
3388
+ inst.extract = (values, params) => {
3389
+ const newEntries = {};
3390
+ for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
3391
+ else throw new Error(`Key ${value} not found in enum`);
3392
+ return new ZodEnum({
3393
+ ...def,
3394
+ checks: [],
3395
+ ...normalizeParams(params),
3396
+ entries: newEntries
3397
+ });
3398
+ };
3399
+ inst.exclude = (values, params) => {
3400
+ const newEntries = { ...def.entries };
3401
+ for (const value of values) if (keys.has(value)) delete newEntries[value];
3402
+ else throw new Error(`Key ${value} not found in enum`);
3403
+ return new ZodEnum({
3404
+ ...def,
3405
+ checks: [],
3406
+ ...normalizeParams(params),
3407
+ entries: newEntries
3408
+ });
3409
+ };
3410
+ });
3411
+ function _enum(values, params) {
3412
+ return new ZodEnum({
3413
+ type: "enum",
3414
+ entries: Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values,
3415
+ ...normalizeParams(params)
3416
+ });
3417
+ }
3418
+ const ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
3419
+ $ZodLiteral.init(inst, def);
3420
+ ZodType.init(inst, def);
3421
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
3422
+ inst.values = new Set(def.values);
3423
+ Object.defineProperty(inst, "value", { get() {
3424
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
3425
+ return def.values[0];
3426
+ } });
3427
+ });
3428
+ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
3429
+ $ZodTransform.init(inst, def);
3430
+ ZodType.init(inst, def);
3431
+ inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
3432
+ inst._zod.parse = (payload, _ctx) => {
3433
+ if (_ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
3434
+ payload.addIssue = (issue$1) => {
3435
+ if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
3436
+ else {
3437
+ const _issue = issue$1;
3438
+ if (_issue.fatal) _issue.continue = false;
3439
+ _issue.code ?? (_issue.code = "custom");
3440
+ _issue.input ?? (_issue.input = payload.value);
3441
+ _issue.inst ?? (_issue.inst = inst);
3442
+ payload.issues.push(issue(_issue));
3443
+ }
3444
+ };
3445
+ const output = def.transform(payload.value, payload);
3446
+ if (output instanceof Promise) return output.then((output) => {
3447
+ payload.value = output;
3448
+ return payload;
3449
+ });
3450
+ payload.value = output;
3451
+ return payload;
3452
+ };
3453
+ });
3454
+ function transform(fn) {
3455
+ return new ZodTransform({
3456
+ type: "transform",
3457
+ transform: fn
3458
+ });
3459
+ }
3460
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3461
+ $ZodOptional.init(inst, def);
3462
+ ZodType.init(inst, def);
3463
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3464
+ inst.unwrap = () => inst._zod.def.innerType;
3465
+ });
3466
+ function optional(innerType) {
3467
+ return new ZodOptional({
3468
+ type: "optional",
3469
+ innerType
3470
+ });
3471
+ }
3472
+ const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
3473
+ $ZodExactOptional.init(inst, def);
3474
+ ZodType.init(inst, def);
3475
+ inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
3476
+ inst.unwrap = () => inst._zod.def.innerType;
3477
+ });
3478
+ function exactOptional(innerType) {
3479
+ return new ZodExactOptional({
3480
+ type: "optional",
3481
+ innerType
3482
+ });
3483
+ }
3484
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3485
+ $ZodNullable.init(inst, def);
3486
+ ZodType.init(inst, def);
3487
+ inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
3488
+ inst.unwrap = () => inst._zod.def.innerType;
3489
+ });
3490
+ function nullable(innerType) {
3491
+ return new ZodNullable({
3492
+ type: "nullable",
3493
+ innerType
3494
+ });
3495
+ }
3496
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3497
+ $ZodDefault.init(inst, def);
3498
+ ZodType.init(inst, def);
3499
+ inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
3500
+ inst.unwrap = () => inst._zod.def.innerType;
3501
+ inst.removeDefault = inst.unwrap;
3502
+ });
3503
+ function _default(innerType, defaultValue) {
3504
+ return new ZodDefault({
3505
+ type: "default",
3506
+ innerType,
3507
+ get defaultValue() {
3508
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3509
+ }
3510
+ });
3511
+ }
3512
+ const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
3513
+ $ZodPrefault.init(inst, def);
3514
+ ZodType.init(inst, def);
3515
+ inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
3516
+ inst.unwrap = () => inst._zod.def.innerType;
3517
+ });
3518
+ function prefault(innerType, defaultValue) {
3519
+ return new ZodPrefault({
3520
+ type: "prefault",
3521
+ innerType,
3522
+ get defaultValue() {
3523
+ return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
3524
+ }
3525
+ });
3526
+ }
3527
+ const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
3528
+ $ZodNonOptional.init(inst, def);
3529
+ ZodType.init(inst, def);
3530
+ inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
3531
+ inst.unwrap = () => inst._zod.def.innerType;
3532
+ });
3533
+ function nonoptional(innerType, params) {
3534
+ return new ZodNonOptional({
3535
+ type: "nonoptional",
3536
+ innerType,
3537
+ ...normalizeParams(params)
3538
+ });
3539
+ }
3540
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3541
+ $ZodCatch.init(inst, def);
3542
+ ZodType.init(inst, def);
3543
+ inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
3544
+ inst.unwrap = () => inst._zod.def.innerType;
3545
+ inst.removeCatch = inst.unwrap;
3546
+ });
3547
+ function _catch(innerType, catchValue) {
3548
+ return new ZodCatch({
3549
+ type: "catch",
3550
+ innerType,
3551
+ catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
3552
+ });
3553
+ }
3554
+ const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
3555
+ $ZodPipe.init(inst, def);
3556
+ ZodType.init(inst, def);
3557
+ inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
3558
+ inst.in = def.in;
3559
+ inst.out = def.out;
3560
+ });
3561
+ function pipe(in_, out) {
3562
+ return new ZodPipe({
3563
+ type: "pipe",
3564
+ in: in_,
3565
+ out
3566
+ });
3567
+ }
3568
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3569
+ $ZodReadonly.init(inst, def);
3570
+ ZodType.init(inst, def);
3571
+ inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
3572
+ inst.unwrap = () => inst._zod.def.innerType;
3573
+ });
3574
+ function readonly(innerType) {
3575
+ return new ZodReadonly({
3576
+ type: "readonly",
3577
+ innerType
3578
+ });
3579
+ }
3580
+ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
3581
+ $ZodCustom.init(inst, def);
3582
+ ZodType.init(inst, def);
3583
+ inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx, json, params);
3584
+ });
3585
+ function refine(fn, _params = {}) {
3586
+ return _refine(ZodCustom, fn, _params);
3587
+ }
3588
+ function superRefine(fn) {
3589
+ return _superRefine(fn);
3590
+ }
3591
+ const describe = describe$1;
3592
+ const meta = meta$1;
3593
+
3594
+ //#endregion
3595
+ //#region src/generators/errors/DuplicateOperationIdError.ts
3596
+ var DuplicateOperationIdError = class extends Error {
3597
+ constructor(operationId, firstFile, duplicateFile) {
3598
+ super(`Duplicate operation ID '${operationId}' found.\n First defined in: \`${firstFile}\`\n Duplicate found in: \`${duplicateFile}\``);
3599
+ this.operationId = operationId;
3600
+ this.firstFile = firstFile;
3601
+ this.duplicateFile = duplicateFile;
3602
+ }
3603
+ };
3604
+
3605
+ //#endregion
3606
+ //#region src/generators/errors/DuplicateResponseNameError.ts
3607
+ var DuplicateResponseNameError = class extends Error {
3608
+ constructor(responseName, firstFile, duplicateFile) {
3609
+ super(`Duplicate response name '${responseName}' found.\n First defined in: \`${firstFile}\`\n Duplicate found in: \`${duplicateFile}\``);
3610
+ this.responseName = responseName;
3611
+ this.firstFile = firstFile;
3612
+ this.duplicateFile = duplicateFile;
3613
+ }
3614
+ };
3615
+
3616
+ //#endregion
3617
+ //#region src/generators/errors/DuplicateRouteError.ts
3618
+ var DuplicateRouteError = class extends Error {
3619
+ constructor(path, method, firstOperationId, firstFile, duplicateOperationId, duplicateFile) {
3620
+ super(`Duplicate route '${method} ${path}' found.\n First defined by operation '${firstOperationId}' in: \`${firstFile}\`\n Duplicate defined by operation '${duplicateOperationId}' in: \`${duplicateFile}\``);
3621
+ this.path = path;
3622
+ this.method = method;
3623
+ this.firstOperationId = firstOperationId;
3624
+ this.firstFile = firstFile;
3625
+ this.duplicateOperationId = duplicateOperationId;
3626
+ this.duplicateFile = duplicateFile;
3627
+ }
3628
+ };
3629
+
3630
+ //#endregion
3631
+ //#region src/generators/DefinitionRegistry.ts
3632
+ var DefinitionRegistry = class {
3633
+ operationIds = /* @__PURE__ */ new Map();
3634
+ responseNames = /* @__PURE__ */ new Map();
3635
+ routes = /* @__PURE__ */ new Map();
3636
+ registerOperation(operation, sourceFile) {
3637
+ const existingFile = this.operationIds.get(operation.operationId);
3638
+ if (existingFile) throw new DuplicateOperationIdError(operation.operationId, existingFile, sourceFile);
3639
+ this.operationIds.set(operation.operationId, sourceFile);
3640
+ const normalizedPath = this.normalizePath(operation.path);
3641
+ const routeKey = `${operation.method} ${normalizedPath}`;
3642
+ const existingRoute = this.routes.get(routeKey);
3643
+ if (existingRoute) throw new DuplicateRouteError(operation.path, operation.method, existingRoute.operationId, existingRoute.file, operation.operationId, sourceFile);
3644
+ this.routes.set(routeKey, {
3645
+ operationId: operation.operationId,
3646
+ file: sourceFile
3647
+ });
3648
+ }
3649
+ registerResponse(response, sourceFile) {
3650
+ const existingFile = this.responseNames.get(response.name);
3651
+ if (existingFile) throw new DuplicateResponseNameError(response.name, existingFile, sourceFile);
3652
+ this.responseNames.set(response.name, sourceFile);
3653
+ }
3654
+ hasOperationId(operationId) {
3655
+ return this.operationIds.has(operationId);
3656
+ }
3657
+ hasResponseName(name) {
3658
+ return this.responseNames.has(name);
3659
+ }
3660
+ hasRoute(method, path) {
3661
+ const routeKey = `${method} ${this.normalizePath(path)}`;
3662
+ return this.routes.has(routeKey);
3663
+ }
3664
+ getOperationFile(operationId) {
3665
+ return this.operationIds.get(operationId);
3666
+ }
3667
+ getResponseFile(name) {
3668
+ return this.responseNames.get(name);
3669
+ }
3670
+ getRouteInfo(method, path) {
3671
+ const routeKey = `${method} ${this.normalizePath(path)}`;
3672
+ return this.routes.get(routeKey);
3673
+ }
3674
+ normalizePath(path) {
3675
+ let paramIndex = 1;
3676
+ return path.replace(/:([a-zA-Z0-9_]+)/g, () => {
3677
+ return `:param${paramIndex++}`;
3678
+ });
3679
+ }
3680
+ };
3681
+
3682
+ //#endregion
3683
+ //#region src/generators/errors/EmptyResponseArrayError.ts
3684
+ var EmptyResponseArrayError = class extends Error {
3685
+ constructor(operationId, file) {
3686
+ super(`Operation '${operationId}' has no responses defined at \`${file}\`\n Operations must have at least one response definition`);
3687
+ this.operationId = operationId;
3688
+ this.file = file;
3689
+ }
3690
+ };
3691
+
3692
+ //#endregion
3693
+ //#region src/generators/errors/InvalidHttpMethodError.ts
3694
+ var InvalidHttpMethodError = class extends Error {
3695
+ constructor(operationId, method, file) {
3696
+ const validMethods = Object.values(HttpMethod).join(", ");
3697
+ super(`Invalid HTTP method '${method}' in operation '${operationId}' at \`${file}\`\n Valid methods: ${validMethods}`);
3698
+ this.operationId = operationId;
3699
+ this.method = method;
3700
+ this.file = file;
3701
+ }
3702
+ };
3703
+
3704
+ //#endregion
3705
+ //#region src/generators/errors/InvalidPathParameterError.ts
3706
+ var InvalidPathParameterError = class extends Error {
3707
+ constructor(operationId, path, issue, file) {
3708
+ super(`Invalid path parameters in operation '${operationId}' at \`${file}\`\n Path: ${path}\n Issue: ${issue}`);
3709
+ this.operationId = operationId;
3710
+ this.path = path;
3711
+ this.issue = issue;
3712
+ this.file = file;
3713
+ }
3714
+ };
3715
+
3716
+ //#endregion
3717
+ //#region src/generators/errors/InvalidSchemaError.ts
3718
+ var InvalidSchemaError = class extends Error {
3719
+ constructor(schemaType, definitionName, context, file) {
3720
+ super(`Invalid ${schemaType} schema in ${context} '${definitionName}' at \`${file}\`. ${schemaType === "body" ? "Must be a Zod schema" : "Must be a Zod object schema"}.`);
3721
+ this.schemaType = schemaType;
3722
+ this.definitionName = definitionName;
3723
+ this.context = context;
3724
+ this.file = file;
3725
+ }
3726
+ };
3727
+
3728
+ //#endregion
3729
+ //#region src/generators/errors/InvalidSchemaShapeError.ts
3730
+ var InvalidSchemaShapeError = class extends Error {
3731
+ constructor(schemaType, definitionName, context, propertyName, invalidType, file) {
3732
+ super(`Invalid ${schemaType} schema shape in ${context} '${definitionName}' at \`${file}\`\n Property '${propertyName}' has invalid type: ${invalidType}\n Allowed types: ${schemaType === "param" ? "string-based types (ZodString, ZodLiteral<string>, ZodEnum) or ZodOptional of these types" : "string-based types (ZodString, ZodLiteral<string>, ZodEnum), ZodOptional, or ZodArray of these types"}`);
3733
+ this.schemaType = schemaType;
3734
+ this.definitionName = definitionName;
3735
+ this.context = context;
3736
+ this.propertyName = propertyName;
3737
+ this.invalidType = invalidType;
3738
+ this.file = file;
3739
+ }
3740
+ };
3741
+
3742
+ //#endregion
3743
+ //#region src/generators/errors/InvalidStatusCodeError.ts
3744
+ var InvalidStatusCodeError = class extends Error {
3745
+ constructor(statusCode, responseName, file) {
3746
+ const validStatusCodes = Object.values(HttpStatusCode).join(", ");
3747
+ super(`Invalid status code '${statusCode}' in response '${responseName}' at \`${file}\`\n Valid status codes: ${validStatusCodes}`);
3748
+ this.statusCode = statusCode;
3749
+ this.responseName = responseName;
3750
+ this.file = file;
3751
+ }
3752
+ };
3753
+
3754
+ //#endregion
3755
+ //#region src/generators/errors/MissingRequiredFieldError.ts
3756
+ var MissingRequiredFieldError = class extends Error {
3757
+ constructor(entityType, entityName, missingField, file) {
3758
+ super(`Missing required field '${missingField}' in ${entityType} '${entityName}' at \`${file}\``);
3759
+ this.entityType = entityType;
3760
+ this.entityName = entityName;
3761
+ this.missingField = missingField;
3762
+ this.file = file;
3763
+ }
3764
+ };
3765
+
3766
+ //#endregion
3767
+ //#region src/generators/DefinitionValidator.ts
3768
+ var DefinitionValidator = class {
3769
+ registry;
3770
+ constructor(registry) {
3771
+ this.registry = registry ?? new DefinitionRegistry();
3772
+ }
3773
+ validateOperation(operation, sourceFile) {
3774
+ this.registry.registerOperation(operation, sourceFile);
3775
+ this.validateOperationRequiredFields(operation, sourceFile);
3776
+ this.validateHttpMethod(operation, sourceFile);
3777
+ if (operation.request) this.validateRequestSchemas(operation, sourceFile);
3778
+ this.validateOperationResponses(operation, sourceFile);
3779
+ this.validatePathParameters(operation, sourceFile);
3780
+ }
3781
+ validateResponse(response, sourceFile) {
3782
+ this.registry.registerResponse(response, sourceFile);
3783
+ this.validateResponseRequiredFields(response, sourceFile);
3784
+ this.validateStatusCode(response, sourceFile);
3785
+ this.validateResponseSchemas(response, sourceFile);
3786
+ }
3787
+ validateOperationRequiredFields(operation, sourceFile) {
3788
+ if (!operation.operationId) throw new MissingRequiredFieldError("operation", "unknown", "operationId", sourceFile);
3789
+ if (!operation.path) throw new MissingRequiredFieldError("operation", operation.operationId, "path", sourceFile);
3790
+ if (!operation.method) throw new MissingRequiredFieldError("operation", operation.operationId, "method", sourceFile);
3791
+ if (!operation.summary) throw new MissingRequiredFieldError("operation", operation.operationId, "summary", sourceFile);
3792
+ }
3793
+ validateHttpMethod(operation, sourceFile) {
3794
+ if (!Object.values(HttpMethod).includes(operation.method)) throw new InvalidHttpMethodError(operation.operationId, operation.method, sourceFile);
3795
+ }
3796
+ validateRequestSchemas(operation, sourceFile) {
3797
+ const request = operation.request;
3798
+ if (request.header) this.validateSchema(request.header, "header", operation.operationId, "request", sourceFile);
3799
+ if (request.query) this.validateSchema(request.query, "query", operation.operationId, "request", sourceFile);
3800
+ if (request.body) this.validateSchema(request.body, "body", operation.operationId, "request", sourceFile);
3801
+ if (request.param) this.validateSchema(request.param, "param", operation.operationId, "request", sourceFile);
3802
+ }
3803
+ validateOperationResponses(operation, sourceFile) {
3804
+ if (!operation.responses || operation.responses.length === 0) throw new EmptyResponseArrayError(operation.operationId, sourceFile);
3805
+ for (const response of operation.responses) {
3806
+ if (response instanceof HttpResponseDefinition) continue;
3807
+ this.validateResponse(response, sourceFile);
3808
+ }
3809
+ }
3810
+ validateResponseRequiredFields(response, sourceFile) {
3811
+ if (!response.name) throw new MissingRequiredFieldError("response", "unknown", "name", sourceFile);
3812
+ if (response.statusCode === void 0 || response.statusCode === null) throw new MissingRequiredFieldError("response", response.name, "statusCode", sourceFile);
3813
+ if (!response.description) throw new MissingRequiredFieldError("response", response.name, "description", sourceFile);
3814
+ }
3815
+ validateStatusCode(response, sourceFile) {
3816
+ if (!Object.values(HttpStatusCode).includes(response.statusCode)) throw new InvalidStatusCodeError(response.statusCode, response.name, sourceFile);
3817
+ }
3818
+ validateResponseSchemas(response, sourceFile) {
3819
+ if (response.header) this.validateSchema(response.header, "header", response.name, "response", sourceFile);
3820
+ if (response.body) this.validateSchema(response.body, "body", response.name, "response", sourceFile);
3821
+ }
3822
+ validateSchema(schema, schemaType, definitionName, context, sourceFile) {
3823
+ if (schemaType === "body") {
3824
+ if (!(schema instanceof ZodType)) throw new InvalidSchemaError(schemaType, definitionName, context, sourceFile);
3825
+ return;
3826
+ }
3827
+ if (schemaType === "query" || schemaType === "header") {
3828
+ if (!(schema instanceof ZodObject) && !(schema instanceof ZodOptional && schema.unwrap() instanceof ZodObject)) throw new InvalidSchemaError(schemaType, definitionName, context, sourceFile);
3829
+ this.validateHeaderOrQueryShape(schema, schemaType, definitionName, context, sourceFile);
3830
+ }
3831
+ if (schemaType === "param") {
3832
+ if (!(schema instanceof ZodObject)) throw new InvalidSchemaError(schemaType, definitionName, context, sourceFile);
3833
+ this.validateParamShape(schema, definitionName, sourceFile);
3834
+ }
3835
+ }
3836
+ validatePathParameters(operation, sourceFile) {
3837
+ const pathParamMatches = operation.path.matchAll(/:([a-zA-Z0-9_]+)/g);
3838
+ const pathParamsSet = /* @__PURE__ */ new Set();
3839
+ for (const match of pathParamMatches) {
3840
+ const paramName = match[1];
3841
+ if (pathParamsSet.has(paramName)) throw new InvalidPathParameterError(operation.operationId, operation.path, `Duplicate parameter name '${paramName}' in path`, sourceFile);
3842
+ pathParamsSet.add(paramName);
3843
+ }
3844
+ const paramSchema = operation.request?.param;
3845
+ if (pathParamsSet.size > 0 && !paramSchema) throw new InvalidPathParameterError(operation.operationId, operation.path, `Path contains parameters [${Array.from(pathParamsSet).join(", ")}] but request.param is not defined`, sourceFile);
3846
+ if (paramSchema && paramSchema instanceof ZodObject) {
3847
+ const paramShape = paramSchema.shape;
3848
+ const paramKeys = new Set(Object.keys(paramShape));
3849
+ for (const pathParam of pathParamsSet) if (!paramKeys.has(pathParam)) throw new InvalidPathParameterError(operation.operationId, operation.path, `Path parameter ':${pathParam}' is not defined in request.param`, sourceFile);
3850
+ for (const paramKey of paramKeys) if (!pathParamsSet.has(paramKey)) throw new InvalidPathParameterError(operation.operationId, operation.path, `Parameter '${paramKey}' is defined in request.param but not used in the path`, sourceFile);
3851
+ }
3852
+ }
3853
+ validateHeaderOrQueryShape(schema, schemaType, definitionName, context, sourceFile) {
3854
+ const shape = schema instanceof ZodObject ? schema.shape : schema.unwrap().shape;
3855
+ for (const [propName, propSchema] of Object.entries(shape)) if (!this.isValidHeaderOrQueryValue(propSchema)) throw new InvalidSchemaShapeError(schemaType, definitionName, context, propName, this.getZodTypeName(propSchema), sourceFile);
3856
+ }
3857
+ validateParamShape(schema, operationId, sourceFile) {
3858
+ const shape = schema instanceof ZodObject ? schema.shape : schema.unwrap().shape;
3859
+ for (const [propName, propSchema] of Object.entries(shape)) if (!this.isValidParamValue(propSchema)) throw new InvalidSchemaShapeError("param", operationId, "request", propName, this.getZodTypeName(propSchema), sourceFile);
3860
+ }
3861
+ isValidHeaderOrQueryValue(schema) {
3862
+ if (this.isStringBasedType(schema)) return true;
3863
+ if (schema instanceof ZodOptional) return this.isValidHeaderOrQueryValue(schema.unwrap());
3864
+ if (schema instanceof ZodArray) return this.isStringBasedType(schema.element);
3865
+ return false;
3866
+ }
3867
+ isValidParamValue(schema) {
3868
+ if (this.isStringBasedType(schema)) return true;
3869
+ if (schema instanceof ZodOptional) return this.isStringBasedType(schema.unwrap());
3870
+ return false;
3871
+ }
3872
+ isStringBasedType(schema) {
3873
+ if (schema instanceof ZodString) return true;
3874
+ if (schema instanceof ZodLiteral && typeof schema.value === "string") return true;
3875
+ if (schema instanceof ZodEnum) return true;
3876
+ const typeName = schema.constructor.name;
3877
+ if ([
3878
+ "ZodULID",
3879
+ "ZodUUID",
3880
+ "ZodUUIDv4",
3881
+ "ZodUUIDv7",
3882
+ "ZodUUIDv8",
3883
+ "ZodEmail",
3884
+ "ZodURL",
3885
+ "ZodCUID",
3886
+ "ZodCUID2",
3887
+ "ZodNanoID",
3888
+ "ZodBase64",
3889
+ "ZodBase64URL",
3890
+ "ZodEmoji",
3891
+ "ZodIPv4",
3892
+ "ZodIPv6",
3893
+ "ZodCIDRv4",
3894
+ "ZodCIDRv6",
3895
+ "ZodE164",
3896
+ "ZodJWT",
3897
+ "ZodASCII",
3898
+ "ZodUTF8",
3899
+ "ZodLowercase",
3900
+ "ZodGUID",
3901
+ "ZodISODate",
3902
+ "ZodISOTime",
3903
+ "ZodISODateTime",
3904
+ "ZodISODuration"
3905
+ ].includes(typeName)) return true;
3906
+ if (schema._def && schema._def.typeName && schema._def.typeName.includes("String")) return true;
3907
+ return false;
3908
+ }
3909
+ getZodTypeName(schema) {
3910
+ const typeName = schema.constructor.name;
3911
+ if (schema instanceof ZodOptional) return `ZodOptional<${this.getZodTypeName(schema.unwrap())}>`;
3912
+ if (schema instanceof ZodArray) return `ZodArray<${this.getZodTypeName(schema.element)}>`;
3913
+ if (schema instanceof ZodLiteral) return `ZodLiteral<${typeof schema.value}>`;
3914
+ return typeName;
3915
+ }
3916
+ getRegistry() {
3917
+ return this.registry;
3918
+ }
3919
+ };
3920
+
3921
+ //#endregion
3922
+ //#region src/generators/errors/InvalidSharedDirError.ts
3923
+ var InvalidSharedDirError = class extends Error {
3924
+ constructor(explanation) {
3925
+ super("Invalid shared dir");
3926
+ this.explanation = explanation;
3927
+ }
3928
+ };
3929
+
3930
+ //#endregion
3931
+ //#region src/generators/ResourceReader.ts
3932
+ var ResourceReader = class {
3933
+ constructor(config) {
3934
+ this.config = config;
3935
+ }
3936
+ async getResources() {
3937
+ const contents = fs.readdirSync(this.config.sourceDir, { withFileTypes: true });
3938
+ const result = {
3939
+ entityResources: {},
3940
+ sharedResponseResources: []
3941
+ };
3942
+ const validator = new DefinitionValidator();
3943
+ if (fs.existsSync(this.config.sharedSourceDir)) {
3944
+ if (!fs.statSync(this.config.sharedSourceDir).isDirectory()) throw new InvalidSharedDirError(`'${this.config.sharedSourceDir}' is a file, not a directory`);
3945
+ result.sharedResponseResources = await this.getSharedResponseResources(validator);
3946
+ console.info(`Found '${result.sharedResponseResources.length}' shared responses in '${this.config.sharedSourceDir}'`);
3947
+ } else console.info(`No shared directory found at '${this.config.sharedSourceDir}'`);
3948
+ const normalizedSharedPath = path.resolve(this.config.sharedSourceDir);
3949
+ for (const content of contents) {
3950
+ if (!content.isDirectory()) {
3951
+ console.info(`Skipping '${content.name}' as it is not a directory`);
3952
+ continue;
3953
+ }
3954
+ const entityName = content.name;
3955
+ const entitySourceDir = path.resolve(this.config.sourceDir, entityName);
3956
+ if (entitySourceDir === normalizedSharedPath || normalizedSharedPath.startsWith(entitySourceDir + path.sep)) {
3957
+ console.info(`Skipping '${content.name}' as it is or contains the shared directory`);
3958
+ continue;
3959
+ }
3960
+ const responseResources = await this.getEntityResponseResources(entitySourceDir, entityName, validator);
3961
+ const operationResources = await this.getEntityOperationResources(entitySourceDir, entityName, validator, [...result.sharedResponseResources, ...responseResources]);
3962
+ result.entityResources[entityName] = {
3963
+ operations: operationResources,
3964
+ responses: responseResources
3965
+ };
3966
+ console.info(`Found '${operationResources.length}' operation definitions for entity '${entityName}'`);
3967
+ if (responseResources.length > 0) console.info(`Found '${responseResources.length}' response definitions for entity '${entityName}'`);
3968
+ }
3969
+ return result;
3970
+ }
3971
+ scanDirectoryRecursively(dir) {
3972
+ const files = [];
3973
+ const contents = fs.readdirSync(dir, { withFileTypes: true });
3974
+ for (const content of contents) {
3975
+ const fullPath = path.join(dir, content.name);
3976
+ if (content.isDirectory()) files.push(...this.scanDirectoryRecursively(fullPath));
3977
+ else if (content.isFile() && content.name.endsWith(".ts")) files.push(fullPath);
3978
+ }
3979
+ return files;
3980
+ }
3981
+ async getSharedResponseResources(validator) {
3982
+ const files = this.scanDirectoryRecursively(this.config.sharedSourceDir);
3983
+ const sharedResponseResources = [];
3984
+ for (const sourceFile of files) {
3985
+ const sourceFileName = path.basename(sourceFile);
3986
+ const definition = await import(sourceFile);
3987
+ if (!definition.default) {
3988
+ console.info(`Skipping '${sourceFile}' as it does not have a default export`);
3989
+ continue;
3990
+ }
3991
+ if (!(definition.default instanceof HttpResponseDefinition)) {
3992
+ console.info(`Skipping '${sourceFile}' as it is not an instance of HttpResponseDefinition`);
3993
+ continue;
3994
+ }
3995
+ validator.validateResponse(definition.default, sourceFile);
3996
+ const outputDir = this.config.sharedOutputDir;
3997
+ const outputFileName = `${definition.default.name}Response.ts`;
3998
+ const outputFile = path.join(outputDir, outputFileName);
3999
+ sharedResponseResources.push({
4000
+ ...definition.default,
4001
+ sourceDir: this.config.sharedSourceDir,
4002
+ sourceFile,
4003
+ sourceFileName,
4004
+ outputFile,
4005
+ outputFileName,
4006
+ outputDir
4007
+ });
4008
+ }
4009
+ return sharedResponseResources;
4010
+ }
4011
+ async getEntityOperationResources(sourceDir, entityName, validator, referencedResponses) {
4012
+ const files = this.scanDirectoryRecursively(sourceDir);
4013
+ const definitions = [];
4014
+ for (const sourceFile of files) {
4015
+ const sourceFileName = path.basename(sourceFile);
4016
+ const definition = await import(sourceFile);
4017
+ if (!definition.default) {
4018
+ console.info(`Skipping '${sourceFile}' as it does not have a default export`);
4019
+ continue;
4020
+ }
4021
+ if (!(definition.default instanceof HttpOperationDefinition)) {
4022
+ console.info(`Skipping '${sourceFile}' as it is not an instance of HttpOperationDefinition`);
4023
+ continue;
4024
+ }
4025
+ validator.validateOperation(definition.default, sourceFile);
4026
+ const { operationId } = definition.default;
4027
+ const outputDir = path.join(this.config.outputDir, entityName);
4028
+ const outputRequestFileName = `${operationId}Request.ts`;
4029
+ const outputRequestFile = path.join(outputDir, outputRequestFileName);
4030
+ const outputResponseFileName = `${operationId}Response.ts`;
4031
+ const outputResponseFile = path.join(outputDir, outputResponseFileName);
4032
+ const outputRequestValidationFileName = `${operationId}RequestValidator.ts`;
4033
+ const outputRequestValidationFile = path.join(outputDir, outputRequestValidationFileName);
4034
+ const outputResponseValidationFileName = `${operationId}ResponseValidator.ts`;
4035
+ const outputResponseValidationFile = path.join(outputDir, outputResponseValidationFileName);
4036
+ const outputClientFileName = `${operationId}Client.ts`;
4037
+ const outputClientFile = path.join(outputDir, outputClientFileName);
4038
+ const operationResource = {
4039
+ sourceDir,
4040
+ sourceFile,
4041
+ sourceFileName,
4042
+ definition: {
4043
+ ...definition.default,
4044
+ responses: []
4045
+ },
4046
+ outputDir,
4047
+ entityName,
4048
+ outputRequestFile,
4049
+ outputResponseFile,
4050
+ outputResponseValidationFile,
4051
+ outputRequestValidationFile,
4052
+ outputRequestFileName,
4053
+ outputRequestValidationFileName,
4054
+ outputResponseFileName,
4055
+ outputResponseValidationFileName,
4056
+ outputClientFile,
4057
+ outputClientFileName
4058
+ };
4059
+ if (!definition.default.responses) throw new Error(`Operation '${operationId}' does not have any responses`);
4060
+ for (const response of definition.default.responses) if (referencedResponses.some((ref) => ref.name === response.name)) {
4061
+ const referencedResponse = {
4062
+ ...response,
4063
+ statusCodeName: HttpStatusCodeNameMap[response.statusCode],
4064
+ isReference: true
4065
+ };
4066
+ operationResource.definition.responses.push(referencedResponse);
4067
+ } else {
4068
+ const extendedResponse = {
4069
+ ...response,
4070
+ statusCodeName: HttpStatusCodeNameMap[response.statusCode],
4071
+ isReference: false
4072
+ };
4073
+ operationResource.definition.responses.push(extendedResponse);
4074
+ }
4075
+ definitions.push(operationResource);
4076
+ }
4077
+ return definitions;
4078
+ }
4079
+ async getEntityResponseResources(sourceDir, entityName, validator) {
4080
+ const files = this.scanDirectoryRecursively(sourceDir);
4081
+ const responseResources = [];
4082
+ for (const sourceFile of files) {
4083
+ const sourceFileName = path.basename(sourceFile);
4084
+ const definition = await import(sourceFile);
4085
+ if (!definition.default) continue;
4086
+ if (!(definition.default instanceof HttpResponseDefinition)) continue;
4087
+ validator.validateResponse(definition.default, sourceFile);
4088
+ const outputFileName = `${definition.default.name}Response.ts`;
4089
+ const outputFile = path.join(this.config.outputDir, entityName, outputFileName);
4090
+ responseResources.push({
4091
+ ...definition.default,
4092
+ sourceDir,
4093
+ sourceFile,
4094
+ sourceFileName,
4095
+ outputFile,
4096
+ outputFileName,
4097
+ outputDir: path.join(this.config.outputDir, entityName),
4098
+ entityName
4099
+ });
4100
+ }
4101
+ return responseResources;
4102
+ }
4103
+ };
4104
+
4105
+ //#endregion
4106
+ //#region src/generators/Generator.ts
4107
+ const moduleDir$1 = path.dirname(fileURLToPath(import.meta.url));
4108
+ /**
4109
+ * Main generator for typeweaver
4110
+ * Uses a plugin-based architecture for extensible code generation
4111
+ */
4112
+ var Generator = class {
4113
+ coreDir = "@rexeus/typeweaver-core";
4114
+ templateDir = path.join(moduleDir$1, "templates");
4115
+ registry;
4116
+ contextBuilder;
4117
+ pluginLoader;
4118
+ indexFileGenerator;
4119
+ resourceReader = null;
4120
+ formatter = null;
4121
+ inputDir = "";
4122
+ sharedInputDir = "";
4123
+ outputDir = "";
4124
+ sourceDir = "";
4125
+ sharedSourceDir = "";
4126
+ sharedOutputDir = "";
4127
+ constructor(registry, contextBuilder, pluginLoader, indexFileGenerator, requiredPlugins = [new TypesPlugin()]) {
4128
+ this.registry = registry ?? new PluginRegistry();
4129
+ this.contextBuilder = contextBuilder ?? new PluginContextBuilder();
4130
+ this.pluginLoader = pluginLoader ?? new PluginLoader(this.registry, requiredPlugins);
4131
+ this.indexFileGenerator = indexFileGenerator ?? new IndexFileGenerator(this.templateDir);
4132
+ }
4133
+ /**
4134
+ * Generate code using the plugin system
4135
+ */
4136
+ async generate(definitionDir, outputDir, config) {
4137
+ console.info("Starting generation...");
4138
+ this.initializeDirectories(definitionDir, outputDir, config?.shared);
4139
+ if (config?.clean ?? true) {
4140
+ console.info("Cleaning output directory...");
4141
+ fs.rmSync(this.outputDir, {
4142
+ recursive: true,
4143
+ force: true
4144
+ });
4145
+ }
4146
+ fs.mkdirSync(this.outputDir, { recursive: true });
4147
+ fs.mkdirSync(this.sharedOutputDir, { recursive: true });
4148
+ console.info(`Copying definitions from '${this.inputDir}' to '${this.sourceDir}'...`);
4149
+ fs.cpSync(this.inputDir, this.sourceDir, {
4150
+ recursive: true,
4151
+ filter: (src) => {
4152
+ return src.endsWith(".ts") || src.endsWith(".js") || src.endsWith(".json") || src.endsWith(".mjs") || src.endsWith(".cjs") || fs.statSync(src).isDirectory();
4153
+ }
4154
+ });
4155
+ await this.pluginLoader.loadPlugins(config);
4156
+ this.resourceReader = new ResourceReader({
4157
+ sourceDir: this.sourceDir,
4158
+ outputDir: this.outputDir,
4159
+ sharedSourceDir: this.sharedSourceDir,
4160
+ sharedOutputDir: this.sharedOutputDir
4161
+ });
4162
+ this.formatter = new Formatter(this.outputDir);
4163
+ console.info("Reading definitions...");
4164
+ let resources = await this.resourceReader.getResources();
4165
+ const pluginContext = this.contextBuilder.createPluginContext({
4166
+ outputDir: this.outputDir,
4167
+ inputDir: this.sourceDir,
4168
+ config: config ?? {}
4169
+ });
4170
+ console.info("Initializing plugins...");
4171
+ for (const registration of this.registry.getAll()) if (registration.plugin.initialize) await registration.plugin.initialize(pluginContext);
4172
+ console.info("Collecting resources...");
4173
+ for (const registration of this.registry.getAll()) if (registration.plugin.collectResources) resources = await registration.plugin.collectResources(resources);
4174
+ const generatorContext = this.contextBuilder.createGeneratorContext({
4175
+ outputDir: this.outputDir,
4176
+ inputDir: this.sourceDir,
4177
+ config: config ?? {},
4178
+ resources,
4179
+ templateDir: this.templateDir,
4180
+ coreDir: this.coreDir
4181
+ });
4182
+ console.info("Generating code...");
4183
+ for (const registration of this.registry.getAll()) {
4184
+ console.info(`Running plugin: ${registration.plugin.name}`);
4185
+ if (registration.plugin.generate) await registration.plugin.generate(generatorContext);
4186
+ }
4187
+ this.indexFileGenerator.generate(generatorContext);
4188
+ console.info("Finalizing plugins...");
4189
+ for (const registration of this.registry.getAll()) if (registration.plugin.finalize) await registration.plugin.finalize(pluginContext);
4190
+ if (config?.format ?? true) await this.formatter.formatCode();
4191
+ console.info("Generation complete!");
4192
+ console.info(`Generated files: ${this.contextBuilder.getGeneratedFiles().length}`);
4193
+ }
4194
+ initializeDirectories(definitionDir, outputDir, sharedDir) {
4195
+ this.inputDir = definitionDir;
4196
+ this.sharedInputDir = sharedDir ?? path.join(definitionDir, "shared");
4197
+ this.outputDir = outputDir;
4198
+ this.sharedOutputDir = path.join(outputDir, "shared");
4199
+ this.sourceDir = path.join(this.outputDir, "definition");
4200
+ const inputToSharedDirRelative = path.relative(this.inputDir, this.sharedInputDir);
4201
+ this.sharedSourceDir = path.join(this.sourceDir, inputToSharedDirRelative);
4202
+ }
4203
+ };
4204
+
4205
+ //#endregion
4206
+ //#region src/cli.ts
4207
+ const moduleDir = path.dirname(fileURLToPath(import.meta.url));
4208
+ const packageJson = JSON.parse(fs.readFileSync(path.join(moduleDir, "../package.json"), "utf-8"));
4209
+ const program = new Command();
4210
+ const execDir = process.cwd();
4211
+ program.name("@rexeus/typeweaver").description("Type-safe API framework with code generation for TypeScript").version(packageJson.version);
4212
+ program.command("generate").description("Generate types, validators, and clients from API definitions").option("-i, --input <inputDir>", "path to definition directory").option("-o, --output <outputDir>", "output directory for generated files").option("-s, --shared <path>", "path to shared definitions directory").option("-c, --config <configFile>", "path to configuration file").option("-p, --plugins <plugins>", "comma-separated list of plugins to use").option("--format", "format generated code with oxfmt (default: true)").option("--no-format", "disable code formatting").option("--clean", "clean output directory before generation (default: true)").option("--no-clean", "disable cleaning output directory").action(async (options) => {
4213
+ let config = {};
4214
+ if (options.config) {
4215
+ const configPath = path.isAbsolute(options.config) ? options.config : path.join(execDir, options.config);
4216
+ try {
4217
+ const configModule = await import(pathToFileURL(configPath).toString());
4218
+ config = configModule.default ?? configModule;
4219
+ console.info(`Loaded configuration from ${configPath}`);
4220
+ } catch (error) {
4221
+ console.error(`Failed to load configuration file: ${options.config}`);
4222
+ console.error(error);
4223
+ process.exit(1);
4224
+ }
4225
+ }
4226
+ const inputDir = options.input ?? config.input;
4227
+ const outputDir = options.output ?? config.output;
4228
+ const sharedDir = options.shared ?? config.shared;
4229
+ if (!inputDir) throw new Error("No input directory provided. Use --input or specify in config file.");
4230
+ if (!outputDir) throw new Error("No output directory provided. Use --output or specify in config file.");
4231
+ const resolvedInputDir = path.isAbsolute(inputDir) ? inputDir : path.join(execDir, inputDir);
4232
+ const resolvedOutputDir = path.isAbsolute(outputDir) ? outputDir : path.join(execDir, outputDir);
4233
+ const finalConfig = {
4234
+ input: resolvedInputDir,
4235
+ output: resolvedOutputDir,
4236
+ shared: sharedDir ? path.isAbsolute(sharedDir) ? sharedDir : path.join(execDir, sharedDir) : void 0,
4237
+ format: options.format ?? config.format ?? true,
4238
+ clean: options.clean ?? config.clean ?? true
4239
+ };
4240
+ if (options.plugins) finalConfig.plugins = options.plugins.split(",").map((p) => p.trim());
4241
+ else if (config.plugins) finalConfig.plugins = config.plugins;
4242
+ return new Generator().generate(resolvedInputDir, resolvedOutputDir, finalConfig);
4243
+ });
4244
+ program.command("init").description("Initialize a new typeweaver project (coming soon)").action(() => {
4245
+ console.log("The init command is coming soon!");
4246
+ });
4247
+ program.parse(process.argv);
4248
+
4249
+ //#endregion
4250
+ export { };