@alienplatform/bindings 1.0.0 → 2.0.0

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