@piplfy/widget 0.0.1 → 0.0.2

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