@adhd/apigen-engine-runtime 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -1,70 +1,69 @@
1
- import "ts-morph";
2
1
  import "node:fs";
2
+ import { createRequire as he } from "node:module";
3
3
  import "node:path";
4
- import "ts-json-schema-generator";
5
4
  import N from "pino";
6
- import ge from "ajv";
7
- import we from "ajv-formats";
8
- const C = "$apigen";
9
- class W extends Error {
5
+ import _e from "ajv";
6
+ import ke from "ajv-formats";
7
+ const M = "$apigen";
8
+ let Z = class extends Error {
10
9
  constructor(t) {
11
10
  super(t), this.code = "E_DUP_CODEC", this.name = "CodecRegistryError";
12
11
  }
13
- }
14
- function be(e) {
12
+ };
13
+ function Ie(e) {
15
14
  const t = /* @__PURE__ */ new Map();
16
15
  return {
17
- register(r, n) {
18
- if (t.has(r.id) && !(n != null && n.override))
19
- throw new W(
20
- `E_DUP_CODEC: a codec is already registered for id "${r.id}"`
16
+ register(n, r) {
17
+ if (t.has(n.id) && !(r != null && r.override))
18
+ throw new Z(
19
+ `E_DUP_CODEC: a codec is already registered for id "${n.id}"`
21
20
  );
22
- t.set(r.id, r);
21
+ t.set(n.id, n);
23
22
  },
24
- resolve(r) {
25
- for (const n of t.values())
26
- if (n.matches(r))
27
- return n;
23
+ resolve(n) {
24
+ for (const r of t.values())
25
+ if (r.matches(n))
26
+ return r;
28
27
  },
29
- get(r) {
30
- return t.get(r);
28
+ get(n) {
29
+ return t.get(n);
31
30
  },
32
31
  ids() {
33
32
  return [...t.keys()];
34
33
  },
35
34
  freeze() {
36
- const r = new Map(t), n = {
35
+ const n = new Map(t), r = {
37
36
  register() {
38
- throw new W(
37
+ throw new Z(
39
38
  "E_DUP_CODEC: registry is frozen and cannot accept new codecs"
40
39
  );
41
40
  },
42
41
  resolve(o) {
43
- for (const i of r.values())
42
+ for (const i of n.values())
44
43
  if (i.matches(o))
45
44
  return i;
46
45
  },
47
46
  get(o) {
48
- return r.get(o);
47
+ return n.get(o);
49
48
  },
50
49
  ids() {
51
- return [...r.keys()];
50
+ return [...n.keys()];
52
51
  },
53
52
  freeze() {
54
- return n;
53
+ return r;
55
54
  }
56
55
  };
57
- return n;
56
+ return r;
58
57
  }
59
58
  };
60
59
  }
61
- const L = "x-apigen-logical", R = "x-apigen-codec", S = "x-apigen-ctor", x = "x-apigen-tojson", ve = "0.1.0";
62
- function G(e, t) {
60
+ const F = "x-apigen-logical", V = "x-apigen-codec", T = "x-apigen-ctor", P = "x-apigen-tojson", Ce = "0.1.0";
61
+ function Q(e, t) {
63
62
  return {
64
63
  registry: e,
65
- resolve: (r) => {
64
+ resolve: (n) => {
66
65
  throw new Error(
67
- `[apigen-logical] $ref "${r}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`
66
+ `[apigen-logical] $ref "${n}" cannot be resolved in run-mode without a descriptor root. Supply a resolve() in the ctx override to handle $ref.`
68
67
  );
69
68
  },
70
69
  seen: /* @__PURE__ */ new WeakSet(),
@@ -73,66 +72,66 @@ function G(e, t) {
73
72
  ...t
74
73
  };
75
74
  }
76
- function v(e, t, r) {
77
- const n = r.registry.resolve(t);
78
- if (n)
79
- return n.encode(e, t, r);
75
+ function v(e, t, n) {
76
+ const r = n.registry.resolve(t);
77
+ if (r)
78
+ return r.encode(e, t, n);
80
79
  const o = t.$ref;
81
80
  if (typeof o == "string") {
82
- const a = r.resolve(o);
83
- return v(e, a, r);
81
+ const a = n.resolve(o);
82
+ return v(e, a, n);
84
83
  }
85
84
  const i = t.oneOf;
86
85
  if (Array.isArray(i)) {
87
- const a = ue(e, i, t);
88
- return v(e, a, r);
86
+ const a = ge(e, i, t, n);
87
+ return v(e, a, n);
89
88
  }
90
89
  const s = t.type;
91
90
  if (s === "array") {
92
91
  if (!Array.isArray(e))
93
- return _(e, t, r);
92
+ return A(e, t, n);
94
93
  const a = t.items;
95
94
  if (!a)
96
- return e.map((c) => w(c));
97
- const f = r.path;
98
- return Array.isArray(a) ? e.map((c, u) => {
99
- const p = a[u];
100
- return p === void 0 ? w(c) : v(c, p, { ...r, path: `${f}/${u}` });
95
+ return e.map((u) => w(u));
96
+ const f = n.path;
97
+ return Array.isArray(a) ? e.map((u, c) => {
98
+ const l = a[c];
99
+ return l === void 0 ? w(u) : v(u, l, { ...n, path: `${f}/${c}` });
101
100
  }) : e.map(
102
- (c, u) => v(c, a, { ...r, path: `${f}/${u}` })
101
+ (u, c) => v(u, a, { ...n, path: `${f}/${c}` })
103
102
  );
104
103
  }
105
104
  if (s === "object") {
106
105
  if (e === null || typeof e != "object" || Array.isArray(e))
107
- return _(e, t, r);
106
+ return A(e, t, n);
108
107
  const a = t.properties;
109
108
  if (!a)
110
109
  return w(e);
111
- const f = r.path, c = {};
112
- for (const [u, p] of Object.entries(a)) {
113
- const d = e[u];
114
- d !== void 0 && (c[u] = v(d, p, {
115
- ...r,
116
- path: `${f}/${u}`
110
+ const f = n.path, u = {};
111
+ for (const [c, l] of Object.entries(a)) {
112
+ const p = e[c];
113
+ p !== void 0 && (u[c] = v(p, l, {
114
+ ...n,
115
+ path: `${f}/${c}`
117
116
  }));
118
117
  }
119
- return c;
118
+ return u;
120
119
  }
121
- return s == null ? _(e, t, r) : w(e);
120
+ return s == null ? A(e, t, n) : w(e);
122
121
  }
123
- function $(e, t, r) {
124
- const n = r.registry.resolve(t);
125
- if (n)
126
- return n.decode(e, t, r);
122
+ function $(e, t, n) {
123
+ const r = n.registry.resolve(t);
124
+ if (r)
125
+ return r.decode(e, t, n);
127
126
  const o = t.$ref;
128
127
  if (typeof o == "string") {
129
- const a = r.resolve(o);
130
- return $(e, a, r);
128
+ const a = n.resolve(o);
129
+ return $(e, a, n);
131
130
  }
132
131
  const i = t.oneOf;
133
132
  if (Array.isArray(i)) {
134
- const a = ue(e, i, t);
135
- return $(e, a, r);
133
+ const a = ge(e, i, t, n);
134
+ return $(e, a, n);
136
135
  }
137
136
  const s = t.type;
138
137
  if (s === "array") {
@@ -141,12 +140,12 @@ function $(e, t, r) {
141
140
  const a = t.items;
142
141
  if (!a)
143
142
  return e;
144
- const f = r.path;
145
- return Array.isArray(a) ? e.map((c, u) => {
146
- const p = a[u];
147
- return p === void 0 ? c : $(c, p, { ...r, path: `${f}/${u}` });
143
+ const f = n.path;
144
+ return Array.isArray(a) ? e.map((u, c) => {
145
+ const l = a[c];
146
+ return l === void 0 ? u : $(u, l, { ...n, path: `${f}/${c}` });
148
147
  }) : e.map(
149
- (c, u) => $(c, a, { ...r, path: `${f}/${u}` })
148
+ (u, c) => $(u, a, { ...n, path: `${f}/${c}` })
150
149
  );
151
150
  }
152
151
  if (s === "object") {
@@ -155,50 +154,176 @@ function $(e, t, r) {
155
154
  const a = t.properties;
156
155
  if (!a)
157
156
  return e;
158
- const f = r.path, c = {};
159
- for (const [u, p] of Object.entries(a)) {
160
- const d = e[u];
161
- d !== void 0 && (c[u] = $(d, p, {
162
- ...r,
163
- path: `${f}/${u}`
157
+ const f = n.path, u = {};
158
+ for (const [c, l] of Object.entries(a)) {
159
+ const p = e[c];
160
+ p !== void 0 && (u[c] = $(p, l, {
161
+ ...n,
162
+ path: `${f}/${c}`
164
163
  }));
165
164
  }
166
- return c;
165
+ for (const [c, l] of Object.entries(e))
166
+ !(c in a) && l !== void 0 && (u[c] = l);
167
+ return u;
167
168
  }
168
- return s == null ? $e(e, r) : e;
169
- }
170
- function ue(e, t, r, n) {
171
- const o = r.discriminator;
172
- if (o != null && o.propertyName) {
173
- const i = e !== null && typeof e == "object" ? e[o.propertyName] : void 0;
174
- if (typeof i == "string" && o.mapping) {
175
- const s = o.mapping[i];
176
- if (s) {
177
- const a = t.find((f) => f.$ref === s);
178
- if (a)
179
- return a;
169
+ return s == null ? D(e, n) : e;
170
+ }
171
+ function ge(e, t, n, r) {
172
+ var o;
173
+ const i = n.discriminator;
174
+ if (i != null && i.propertyName) {
175
+ const u = i.propertyName, c = e !== null && typeof e == "object" ? e[u] : void 0;
176
+ if (typeof c == "string") {
177
+ if (i.mapping) {
178
+ const l = i.mapping[c];
179
+ if (l) {
180
+ const p = t.find((y) => y.$ref === l);
181
+ if (p)
182
+ return p;
183
+ }
184
+ }
185
+ for (const l of t) {
186
+ const p = (o = _(l, r).properties) == null ? void 0 : o[u];
187
+ if (!p)
188
+ continue;
189
+ const y = p.enum;
190
+ if (p.const === c || Array.isArray(y) && y.includes(c))
191
+ return l;
180
192
  }
181
193
  }
182
194
  }
183
- return t[0] ?? {};
195
+ const s = xe(e, t, r);
196
+ if (s)
197
+ return s;
198
+ let a, f = -1;
199
+ for (const u of t) {
200
+ const c = _(u, r), l = we(e, c, r);
201
+ l !== null && l > f && (f = l, a = u);
202
+ }
203
+ return a !== void 0 ? a : t[0] ?? {};
204
+ }
205
+ function _(e, t) {
206
+ const n = e.$ref;
207
+ return typeof n == "string" ? t.resolve(n) : e;
208
+ }
209
+ function X(e) {
210
+ if ("const" in e)
211
+ return e.const;
212
+ const t = e.enum;
213
+ if (Array.isArray(t) && t.length === 1)
214
+ return t[0];
215
+ }
216
+ function xe(e, t, n) {
217
+ if (e === null || typeof e != "object" || Array.isArray(e))
218
+ return;
219
+ const r = e, o = t.map((s) => _(s, n)), i = /* @__PURE__ */ new Set();
220
+ for (const s of o) {
221
+ const a = s.properties;
222
+ if (a)
223
+ for (const [f, u] of Object.entries(a))
224
+ X(u) !== void 0 && i.add(f);
225
+ }
226
+ for (const s of i) {
227
+ const a = o.map((p) => {
228
+ const y = p.properties, d = y == null ? void 0 : y[s];
229
+ return d ? X(d) : void 0;
230
+ }), f = a.filter((p) => p !== void 0), u = new Set(f);
231
+ if (f.length < 2 || u.size !== f.length)
232
+ continue;
233
+ const c = r[s];
234
+ if (c === void 0)
235
+ continue;
236
+ const l = a.findIndex((p) => p === c);
237
+ if (l !== -1)
238
+ return t[l];
239
+ }
184
240
  }
185
- function _(e, t, r) {
186
- for (const n of r.registry.ids()) {
187
- const o = r.registry.get(n);
188
- if (o)
189
- try {
190
- const i = o.encode(e, o.schema, r);
191
- return { [C]: n, v: i };
192
- } catch {
241
+ function Se(e) {
242
+ if (e === null)
243
+ return "null";
244
+ if (Array.isArray(e))
245
+ return "array";
246
+ const t = typeof e;
247
+ return t === "number" ? Number.isInteger(e) ? "integer" : "number" : t;
248
+ }
249
+ function we(e, t, n) {
250
+ const r = t.oneOf;
251
+ if (Array.isArray(r)) {
252
+ let c = null;
253
+ for (const l of r) {
254
+ const p = we(e, _(l, n), n);
255
+ p !== null && (c === null || p > c) && (c = p);
256
+ }
257
+ return c;
258
+ }
259
+ const o = t.type, i = Se(e);
260
+ if (typeof o == "string") {
261
+ if (!(o === i || o === "number" && i === "integer"))
262
+ return null;
263
+ } else if (Array.isArray(o) && !o.some(
264
+ (c) => c === i || c === "number" && i === "integer"
265
+ ))
266
+ return null;
267
+ if (e === null || typeof e != "object" || Array.isArray(e))
268
+ return typeof o == "string" ? 1 : 0;
269
+ const s = e, a = t.required;
270
+ let f = 0;
271
+ if (Array.isArray(a)) {
272
+ for (const c of a)
273
+ if (typeof c == "string") {
274
+ if (s[c] === void 0)
275
+ return null;
276
+ f += 2;
193
277
  }
194
278
  }
279
+ const u = t.properties;
280
+ if (u) {
281
+ for (const c of Object.keys(u))
282
+ s[c] !== void 0 && (f += 1);
283
+ for (const c of Object.keys(s))
284
+ u[c] === void 0 && (f -= 1);
285
+ }
286
+ return f;
287
+ }
288
+ function A(e, t, n) {
289
+ var r;
290
+ for (const o of n.registry.ids()) {
291
+ const i = n.registry.get(o);
292
+ if ((r = i == null ? void 0 : i.ownsValue) != null && r.call(i, e))
293
+ return {
294
+ [M]: o,
295
+ v: i.encode(e, i.schema, n)
296
+ };
297
+ }
298
+ if (Array.isArray(e))
299
+ return e.map((o) => A(o, {}, n));
300
+ if (be(e)) {
301
+ const o = {};
302
+ for (const [i, s] of Object.entries(e))
303
+ s !== void 0 && (o[i] = A(s, {}, n));
304
+ return o;
305
+ }
195
306
  return w(e);
196
307
  }
197
- function $e(e, t) {
198
- if (e !== null && typeof e == "object" && !Array.isArray(e) && C in e) {
199
- const r = e, n = r[C], o = t.registry.get(n);
308
+ function be(e) {
309
+ if (e === null || typeof e != "object" || Array.isArray(e))
310
+ return !1;
311
+ const t = Object.getPrototypeOf(e);
312
+ return t === Object.prototype || t === null;
313
+ }
314
+ function D(e, t) {
315
+ if (e !== null && typeof e == "object" && !Array.isArray(e) && M in e) {
316
+ const n = e, r = n[M], o = t.registry.get(r);
200
317
  if (o)
201
- return o.decode(r.v, o.schema, t);
318
+ return o.decode(n.v, o.schema, t);
319
+ }
320
+ if (Array.isArray(e))
321
+ return e.map((n) => D(n, t));
322
+ if (be(e)) {
323
+ const n = {};
324
+ for (const [r, o] of Object.entries(e))
325
+ n[r] = D(o, t);
326
+ return n;
202
327
  }
203
328
  return e;
204
329
  }
@@ -209,63 +334,69 @@ function w(e) {
209
334
  return e.map(w);
210
335
  if (typeof e == "object") {
211
336
  const t = {};
212
- for (const [r, n] of Object.entries(e))
213
- n !== void 0 && (t[r] = w(n));
337
+ for (const [n, r] of Object.entries(e))
338
+ r !== void 0 && (t[n] = w(r));
214
339
  return t;
215
340
  }
216
341
  return null;
217
342
  }
218
- function je(e) {
343
+ function Me(e) {
219
344
  return {
220
- encode(t, r, n) {
221
- const o = G(e, n);
222
- return v(t, r, o);
345
+ encode(t, n, r) {
346
+ const o = Q(e, r);
347
+ return v(t, n, o);
223
348
  },
224
- decode(t, r, n) {
225
- const o = G(e, n);
226
- return $(t, r, o);
349
+ decode(t, n, r) {
350
+ const o = Q(e, r);
351
+ return $(t, n, o);
227
352
  }
228
353
  };
229
354
  }
230
- const B = {
355
+ const H = {
231
356
  id: "date-time",
232
357
  kind: "scalar",
233
358
  schema: { type: "string", format: "date-time" },
234
359
  matches(e) {
235
360
  return e.type === "string" && e.format === "date-time";
236
361
  },
237
- encode(e, t, r) {
362
+ ownsValue(e) {
363
+ return e instanceof Date;
364
+ },
365
+ encode(e, t, n) {
238
366
  return e.toISOString();
239
367
  },
240
- decode(e, t, r) {
368
+ decode(e, t, n) {
241
369
  if (typeof e != "string") {
242
- if (r.mode === "strict")
370
+ if (n.mode === "strict")
243
371
  throw new TypeError(
244
- `[date-time] expected a string on the wire at "${r.path}", got ${typeof e}`
372
+ `[date-time] expected a string on the wire at "${n.path}", got ${typeof e}`
245
373
  );
246
374
  return new Date(String(e));
247
375
  }
248
- if (r.mode === "strict" && Number.isNaN(new Date(e).getTime()))
376
+ if (n.mode === "strict" && Number.isNaN(new Date(e).getTime()))
249
377
  throw new TypeError(
250
- `[date-time] invalid date-time string at "${r.path}": ${JSON.stringify(e)}`
378
+ `[date-time] invalid date-time string at "${n.path}": ${JSON.stringify(e)}`
251
379
  );
252
380
  return new Date(e);
253
381
  }
254
- }, F = {
382
+ }, K = {
255
383
  id: "int64",
256
384
  kind: "scalar",
257
385
  schema: { type: "string", format: "int64" },
258
386
  matches(e) {
259
387
  return e.type === "string" && e.format === "int64";
260
388
  },
261
- encode(e, t, r) {
389
+ ownsValue(e) {
390
+ return typeof e == "bigint";
391
+ },
392
+ encode(e, t, n) {
262
393
  return String(e);
263
394
  },
264
- decode(e, t, r) {
395
+ decode(e, t, n) {
265
396
  if (typeof e != "string") {
266
- if (r.mode === "strict")
397
+ if (n.mode === "strict")
267
398
  throw new TypeError(
268
- `[int64] expected a string on the wire at "${r.path}", got ${typeof e}`
399
+ `[int64] expected a string on the wire at "${n.path}", got ${typeof e}`
269
400
  );
270
401
  try {
271
402
  return BigInt(Math.trunc(Number(e)));
@@ -273,7 +404,7 @@ const B = {
273
404
  return BigInt(0);
274
405
  }
275
406
  }
276
- if (r.mode === "strict")
407
+ if (n.mode === "strict")
277
408
  return BigInt(e);
278
409
  if (/^-?\d+$/.test(e))
279
410
  try {
@@ -283,176 +414,296 @@ const B = {
283
414
  }
284
415
  return BigInt(0);
285
416
  }
286
- }, K = {
417
+ }, z = {
287
418
  id: "decimal",
288
419
  kind: "scalar",
289
420
  schema: { type: "string", format: "decimal" },
290
421
  matches(e) {
291
422
  return e.type === "string" && e.format === "decimal";
292
423
  },
293
- encode(e, t, r) {
424
+ encode(e, t, n) {
294
425
  return e;
295
426
  },
296
- decode(e, t, r) {
427
+ decode(e, t, n) {
297
428
  if (typeof e != "string") {
298
- if (r.mode === "strict")
429
+ if (n.mode === "strict")
299
430
  throw new TypeError(
300
- `[decimal] expected a string on the wire at "${r.path}", got ${typeof e}`
431
+ `[decimal] expected a string on the wire at "${n.path}", got ${typeof e}`
301
432
  );
302
433
  return String(e);
303
434
  }
304
- if (r.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e))
435
+ if (n.mode === "strict" && !/^-?\d+(\.\d+)?$/.test(e))
305
436
  throw new TypeError(
306
- `[decimal] wire value "${e}" at "${r.path}" is not a valid decimal string`
437
+ `[decimal] wire value "${e}" at "${n.path}" is not a valid decimal string`
307
438
  );
308
439
  return e;
309
440
  }
310
- }, H = {
441
+ }, J = {
311
442
  id: "byte",
312
443
  kind: "scalar",
313
444
  schema: { type: "string", format: "byte" },
314
445
  matches(e) {
315
446
  return e.type === "string" && e.format === "byte";
316
447
  },
317
- encode(e, t, r) {
448
+ ownsValue(e) {
449
+ return e instanceof Uint8Array;
450
+ },
451
+ encode(e, t, n) {
318
452
  return Buffer.from(e).toString("base64");
319
453
  },
320
- decode(e, t, r) {
454
+ decode(e, t, n) {
321
455
  if (typeof e != "string") {
322
- if (r.mode === "strict")
456
+ if (n.mode === "strict")
323
457
  throw new TypeError(
324
- `[byte] expected a base64 string on the wire at "${r.path}", got ${typeof e}`
458
+ `[byte] expected a base64 string on the wire at "${n.path}", got ${typeof e}`
325
459
  );
326
460
  return new Uint8Array(0);
327
461
  }
328
- if (r.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e))
462
+ if (n.mode === "strict" && !/^[A-Za-z0-9+/]*={0,2}$/.test(e))
329
463
  throw new TypeError(
330
- `[byte] wire value at "${r.path}" is not standard base64 (format:byte): "${e}"`
464
+ `[byte] wire value at "${n.path}" is not standard base64 (format:byte): "${e}"`
331
465
  );
332
466
  return new Uint8Array(Buffer.from(e, "base64"));
333
467
  }
334
- }, Ne = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, q = {
468
+ }, Te = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, W = {
335
469
  id: "uuid",
336
470
  kind: "scalar",
337
471
  schema: { type: "string", format: "uuid" },
338
472
  matches(e) {
339
473
  return e.type === "string" && e.format === "uuid";
340
474
  },
341
- encode(e, t, r) {
475
+ encode(e, t, n) {
342
476
  return e.toLowerCase();
343
477
  },
344
- decode(e, t, r) {
478
+ decode(e, t, n) {
345
479
  if (typeof e != "string") {
346
- if (r.mode === "strict")
480
+ if (n.mode === "strict")
347
481
  throw new TypeError(
348
- `[uuid] expected a string on the wire at "${r.path}", got ${typeof e}`
482
+ `[uuid] expected a string on the wire at "${n.path}", got ${typeof e}`
349
483
  );
350
484
  return String(e).toLowerCase();
351
485
  }
352
- if (r.mode === "strict" && !Ne.test(e))
486
+ if (n.mode === "strict" && !Te.test(e))
353
487
  throw new TypeError(
354
- `[uuid] wire value "${e}" at "${r.path}" is not a lowercase-hyphenated RFC 4122 UUID`
488
+ `[uuid] wire value "${e}" at "${n.path}" is not a lowercase-hyphenated RFC 4122 UUID`
355
489
  );
356
490
  return e;
357
491
  }
358
- }, M = "NaN", T = "Infinity", P = "-Infinity", Oe = /* @__PURE__ */ new Set([
359
- M,
360
- T,
361
- P
362
- ]), z = {
492
+ }, U = "NaN", R = "Infinity", L = "-Infinity", Pe = /* @__PURE__ */ new Set([
493
+ U,
494
+ R,
495
+ L
496
+ ]), G = {
363
497
  id: "number-special",
364
498
  kind: "scalar",
365
499
  schema: { type: "number" },
366
500
  matches(e) {
367
501
  return e.type === "number" && e.format === void 0;
368
502
  },
369
- encode(e, t, r) {
370
- return Number.isNaN(e) ? M : e === 1 / 0 ? T : e === -1 / 0 ? P : e;
503
+ ownsValue(e) {
504
+ return typeof e == "number" && !Number.isFinite(e);
505
+ },
506
+ encode(e, t, n) {
507
+ return Number.isNaN(e) ? U : e === 1 / 0 ? R : e === -1 / 0 ? L : e;
371
508
  },
372
- decode(e, t, r) {
509
+ decode(e, t, n) {
373
510
  if (typeof e == "number")
374
511
  return e;
375
512
  if (typeof e == "string") {
376
- if (e === M)
513
+ if (e === U)
377
514
  return NaN;
378
- if (e === T)
515
+ if (e === R)
379
516
  return 1 / 0;
380
- if (e === P)
517
+ if (e === L)
381
518
  return -1 / 0;
382
- const n = Number(e);
383
- if (!Number.isNaN(n))
384
- return n;
519
+ const r = Number(e);
520
+ if (!Number.isNaN(r))
521
+ return r;
385
522
  }
386
- if (r.mode === "strict")
523
+ if (n.mode === "strict")
387
524
  throw new TypeError(
388
- `[number-special] unrecognized wire value at "${r.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...Oe].join(", ")}.`
525
+ `[number-special] unrecognized wire value at "${n.path}": ${JSON.stringify(e)}. Expected a number or one of ${[...Pe].join(", ")}.`
389
526
  );
390
527
  return NaN;
391
528
  }
392
- }, Ae = [
393
- B,
394
- F,
395
- K,
529
+ }, De = [
396
530
  H,
397
- q,
398
- z
531
+ K,
532
+ z,
533
+ J,
534
+ W,
535
+ G
399
536
  ];
400
- function _e(e, t = {}) {
401
- for (const r of Ae)
402
- e.register(r, { override: t.override ?? !1 });
403
- }
404
- B.id, // 'date-time'
405
- F.id, // 'int64'
406
- K.id, // 'decimal'
407
- H.id, // 'byte'
408
- q.id, // 'uuid'
409
- z.id;
410
- const fe = be();
411
- _e(fe);
412
- const pe = je(fe.freeze());
413
- function Ee(e, t) {
414
- var n;
415
- const r = ((n = e.input) == null ? void 0 : n.properties) ?? {};
416
- return t in r;
417
- }
418
- function ke(e) {
419
- var r, n;
420
- const t = (n = (r = e.input) == null ? void 0 : r.properties) == null ? void 0 : n.data;
537
+ function Ue(e, t = {}) {
538
+ for (const n of De)
539
+ e.register(n, { override: t.override ?? !1 });
540
+ }
541
+ const Re = 12;
542
+ function Le(e, t) {
543
+ const n = /^#\/(definitions|\$defs)\/(.+)$/.exec(e);
544
+ if (!n)
545
+ return;
546
+ const [, r, o] = n, i = r === "$defs" ? t.$defs : t.definitions;
547
+ return i == null ? void 0 : i[decodeURIComponent(o)];
548
+ }
549
+ function ee(e) {
550
+ return Array.isArray(e) && e.length > 0 ? e[0] : void 0;
551
+ }
552
+ function Be(e) {
553
+ if (Array.isArray(e.type))
554
+ return e.type.find((t) => t !== "null") ?? e.type[0];
555
+ if (typeof e.type == "string")
556
+ return e.type;
557
+ if (e.properties)
558
+ return "object";
559
+ }
560
+ function qe(e) {
561
+ switch (e.format) {
562
+ case "date-time":
563
+ return "1970-01-01T00:00:00.000Z";
564
+ case "date":
565
+ return "1970-01-01";
566
+ case "time":
567
+ return "00:00:00Z";
568
+ case "uuid":
569
+ return "00000000-0000-0000-0000-000000000000";
570
+ case "email":
571
+ return "user@example.com";
572
+ case "uri":
573
+ case "url":
574
+ case "uri-reference":
575
+ return "https://example.com";
576
+ case "hostname":
577
+ return "example.com";
578
+ case "ipv4":
579
+ return "127.0.0.1";
580
+ case "ipv6":
581
+ return "::1";
582
+ case "decimal":
583
+ return "0";
584
+ case "int64":
585
+ return "0";
586
+ case "byte":
587
+ return "";
588
+ default:
589
+ return "<string>";
590
+ }
591
+ }
592
+ function te(e, t, n) {
593
+ const r = e.properties ?? {}, o = e.required ?? [], i = {};
594
+ for (const s of o) {
595
+ const a = r[s];
596
+ i[s] = a !== void 0 ? j(a, t, n + 1) : `<${s}>`;
597
+ }
598
+ return i;
599
+ }
600
+ function Fe(e, t, n) {
601
+ const r = Array.isArray(e.items) ? e.items[0] : e.items;
602
+ return r ? [j(r, t, n + 1)] : [];
603
+ }
604
+ function j(e, t = e ?? {}, n = 0) {
605
+ if (!e || n > Re)
606
+ return null;
607
+ if (typeof e.$ref == "string") {
608
+ const o = Le(e.$ref, t);
609
+ return o !== void 0 ? j(o, t, n + 1) : null;
610
+ }
611
+ if (e.const !== void 0)
612
+ return e.const;
613
+ if (Array.isArray(e.enum) && e.enum.length > 0)
614
+ return e.enum[0];
615
+ if (Array.isArray(e.allOf) && e.allOf.length > 0) {
616
+ const o = {}, i = [];
617
+ for (const s of e.allOf) {
618
+ Object.assign(o, s.properties ?? {});
619
+ for (const a of s.required ?? [])
620
+ i.includes(a) || i.push(a);
621
+ }
622
+ return te(
623
+ { ...e, properties: o, required: i },
624
+ t,
625
+ n
626
+ );
627
+ }
628
+ const r = ee(e.oneOf) ?? ee(e.anyOf);
629
+ if (r)
630
+ return j(r, t, n + 1);
631
+ switch (Be(e)) {
632
+ case "object":
633
+ return te(e, t, n);
634
+ case "array":
635
+ return Fe(e, t, n);
636
+ case "string":
637
+ return qe(e);
638
+ case "integer":
639
+ case "number":
640
+ return 0;
641
+ case "boolean":
642
+ return !1;
643
+ case "null":
644
+ return null;
645
+ default:
646
+ return null;
647
+ }
648
+ }
649
+ function ve(e) {
650
+ if (!e)
651
+ return;
652
+ const t = j(e);
653
+ return `Example: ${JSON.stringify(t)}`;
654
+ }
655
+ H.id, // 'date-time'
656
+ K.id, // 'int64'
657
+ z.id, // 'decimal'
658
+ J.id, // 'byte'
659
+ W.id, // 'uuid'
660
+ G.id;
661
+ const $e = Ie();
662
+ Ue($e);
663
+ const Ae = Me($e.freeze());
664
+ function Ve(e, t) {
665
+ var r;
666
+ const n = ((r = e.input) == null ? void 0 : r.properties) ?? {};
667
+ return t in n;
668
+ }
669
+ function He(e) {
670
+ var n, r;
671
+ const t = (r = (n = e.input) == null ? void 0 : n.properties) == null ? void 0 : r.data;
421
672
  return Object.keys((t == null ? void 0 : t.properties) ?? {});
422
673
  }
423
- function Ie(e, t) {
674
+ function Ke(e, t) {
424
675
  var o, i, s;
425
- const r = (s = (i = (o = e.input) == null ? void 0 : o.properties) == null ? void 0 : i.data) == null ? void 0 : s.properties, n = r == null ? void 0 : r[t];
426
- return n !== void 0 ? n : void 0;
676
+ const n = (s = (i = (o = e.input) == null ? void 0 : o.properties) == null ? void 0 : i.data) == null ? void 0 : s.properties, r = n == null ? void 0 : n[t];
677
+ return r !== void 0 ? r : void 0;
427
678
  }
428
- function Ce(e, t) {
429
- return t === void 0 || e === void 0 ? e : pe.decode(e, t);
679
+ function ze(e, t) {
680
+ return t === void 0 || e === void 0 ? e : Ae.decode(e, t);
430
681
  }
431
- function E(e, t) {
432
- const r = t.output;
433
- return !r || Object.keys(r).length === 0 ? e : pe.encode(e, r);
682
+ function C(e, t) {
683
+ const n = t.output;
684
+ return !n || Object.keys(n).length === 0 ? e : Ae.encode(e, n);
434
685
  }
435
- async function Se(e, t, r, n, o, i) {
436
- const a = ke(r).map(
437
- (c) => Ce(i[c], Ie(r, c))
686
+ async function Je(e, t, n, r, o, i) {
687
+ const a = He(n).map(
688
+ (u) => ze(i[u], Ke(n, u))
438
689
  );
439
- if (Ee(r, "session") && t) {
440
- const c = await t({ session: o.session }), u = await e[n](c, ...a);
441
- return E(u, r);
690
+ if (Ve(n, "session") && t) {
691
+ const u = await t({ session: o.session }), c = await e[r](u, ...a);
692
+ return C(c, n);
442
693
  }
443
- if (r.hasCtx) {
444
- const c = t ? await t(o) : void 0, u = await e[n](c, ...a);
445
- return E(u, r);
694
+ if (n.hasCtx) {
695
+ const u = t ? await t(o) : void 0, c = await e[r](u, ...a);
696
+ return C(c, n);
446
697
  }
447
- const f = await e[n](...a);
448
- return E(f, r);
698
+ const f = await e[r](...a);
699
+ return C(f, n);
449
700
  }
450
- class xe {
701
+ class We {
451
702
  constructor() {
452
703
  this._map = /* @__PURE__ */ new Map();
453
704
  }
454
- set(t, r) {
455
- this._map.set(t, r);
705
+ set(t, n) {
706
+ this._map.set(t, n);
456
707
  }
457
708
  get(t) {
458
709
  return this._map.get(t);
@@ -462,31 +713,31 @@ class xe {
462
713
  return this._map.has(t);
463
714
  }
464
715
  }
465
- function Me(e = []) {
466
- return async function(r, n, o) {
467
- const i = o.schemas[r];
716
+ function Ge(e = []) {
717
+ return async function(n, r, o) {
718
+ const i = o.schemas[n];
468
719
  if (!i)
469
720
  throw new Error(
470
- `apigen/invoke: no schema found for operation "${r}"`
721
+ `apigen/invoke: no schema found for operation "${n}"`
471
722
  );
472
- const s = () => Se(
723
+ const s = () => Je(
473
724
  o.fns,
474
725
  o.createClient,
475
726
  i,
476
- r,
477
- n.envelope,
478
- n.domainArgs
727
+ n,
728
+ r.envelope,
729
+ r.domainArgs
479
730
  );
480
731
  return e.reduceRight(
481
- (f, c) => () => c(n, f),
732
+ (f, u) => () => u(r, f),
482
733
  s
483
734
  )();
484
735
  };
485
736
  }
486
- function Kt(e) {
737
+ function ln(e) {
487
738
  return e;
488
739
  }
489
- class Te {
740
+ class Ye {
490
741
  constructor() {
491
742
  this.handlers = /* @__PURE__ */ new Map();
492
743
  }
@@ -495,16 +746,16 @@ class Te {
495
746
  * per-request/per-package MUST be removed (via the returned fn, {@link off},
496
747
  * or {@link clear}) or they accumulate for the bus's lifetime.
497
748
  */
498
- on(t, r) {
499
- const n = this.handlers.get(t) ?? [];
500
- return this.handlers.set(t, [...n, r]), () => this.off(t, r);
749
+ on(t, n) {
750
+ const r = this.handlers.get(t) ?? [];
751
+ return this.handlers.set(t, [...r, n]), () => this.off(t, n);
501
752
  }
502
753
  /** Remove a previously registered handler (no-op if absent). */
503
- off(t, r) {
504
- const n = this.handlers.get(t);
505
- if (!n)
754
+ off(t, n) {
755
+ const r = this.handlers.get(t);
756
+ if (!r)
506
757
  return;
507
- const o = n.filter((i) => i !== r);
758
+ const o = r.filter((i) => i !== n);
508
759
  o.length === 0 ? this.handlers.delete(t) : this.handlers.set(t, o);
509
760
  }
510
761
  /** Remove every handler — call on package/server teardown. */
@@ -512,115 +763,116 @@ class Te {
512
763
  this.handlers.clear();
513
764
  }
514
765
  async emit(t) {
515
- for (const [r, n] of this.handlers)
516
- if (Pe(r, t))
517
- for (const o of n)
766
+ for (const [n, r] of this.handlers)
767
+ if (Ze(n, t))
768
+ for (const o of r)
518
769
  await o(t);
519
770
  }
520
771
  }
521
- function Pe(e, t) {
522
- const [r, n, o] = e.split(":");
523
- return !(r !== "*" && r !== t.module || n && n !== "*" && n !== t.method || o && o !== "*" && o !== t.lifecycle);
772
+ function Ze(e, t) {
773
+ const [n, r, o] = e.split(":");
774
+ return !(n !== "*" && n !== t.module || r && r !== "*" && r !== t.method || o && o !== "*" && o !== t.lifecycle);
524
775
  }
525
- function De(e, t) {
526
- for (const r of e)
527
- if (r.eventMapping)
528
- for (const [n, o] of Object.entries(r.eventMapping))
529
- t.on(n, o);
776
+ function Qe(e, t) {
777
+ for (const n of e)
778
+ if (n.eventMapping)
779
+ for (const [r, o] of Object.entries(n.eventMapping))
780
+ t.on(r, o);
530
781
  }
531
- async function Ue(e, t, r) {
532
- let n = { ...t };
782
+ async function Xe(e, t, n) {
783
+ let r = { ...t };
533
784
  for (const o of e)
534
785
  if (o.createContext) {
535
- await r.emit({
786
+ await n.emit({
536
787
  module: o.id,
537
788
  method: "createContext",
538
789
  lifecycle: "start",
539
- ctx: n
790
+ ctx: r
540
791
  });
541
792
  try {
542
- const i = await o.createContext(n);
543
- n = { ...n, ...i }, await r.emit({
793
+ const i = await o.createContext(r);
794
+ r = { ...r, ...i }, await n.emit({
544
795
  module: o.id,
545
796
  method: "createContext",
546
797
  lifecycle: "complete",
547
- ctx: n
798
+ ctx: r
548
799
  });
549
800
  } catch (i) {
550
- throw await r.emit({
801
+ throw await n.emit({
551
802
  module: o.id,
552
803
  method: "createContext",
553
804
  lifecycle: "error",
554
- ctx: n,
805
+ ctx: r,
555
806
  error: i
556
807
  }), i;
557
808
  }
558
809
  }
559
- return n;
810
+ return r;
560
811
  }
561
- function J(e, t) {
562
- const r = /* @__PURE__ */ new Set(), n = [e];
563
- for (; n.length > 0; ) {
564
- const o = n.pop();
565
- if (!o || r.has(o))
812
+ he(import.meta.url);
813
+ function ne(e, t) {
814
+ const n = /* @__PURE__ */ new Set(), r = [e];
815
+ for (; r.length > 0; ) {
816
+ const o = r.pop();
817
+ if (!o || n.has(o))
566
818
  continue;
567
- r.add(o);
819
+ n.add(o);
568
820
  const i = o.$ref;
569
821
  if (typeof i == "string") {
570
822
  if (t) {
571
- const p = t[i];
572
- if (!p) {
573
- const d = Object.keys(t).join(", ") || "(none)";
823
+ const l = t[i];
824
+ if (!l) {
825
+ const p = Object.keys(t).join(", ") || "(none)";
574
826
  throw new Error(
575
- `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${d}`
827
+ `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`
576
828
  );
577
829
  }
578
- n.push(p);
830
+ r.push(l);
579
831
  }
580
832
  continue;
581
833
  }
582
834
  const s = o.oneOf;
583
835
  if (Array.isArray(s))
584
- for (const p of s)
585
- typeof p == "object" && p !== null && n.push(p);
836
+ for (const l of s)
837
+ typeof l == "object" && l !== null && r.push(l);
586
838
  const a = o.properties;
587
839
  if (a)
588
- for (const p of Object.values(a))
589
- n.push(p);
840
+ for (const l of Object.values(a))
841
+ r.push(l);
590
842
  const f = o.items;
591
843
  if (Array.isArray(f))
592
- for (const p of f)
593
- typeof p == "object" && p !== null && n.push(p);
844
+ for (const l of f)
845
+ typeof l == "object" && l !== null && r.push(l);
594
846
  else
595
- typeof f == "object" && f !== null && n.push(f);
596
- const c = o.additionalProperties;
597
- typeof c == "object" && c !== null && n.push(c);
598
- const u = o.propertyNames;
599
- typeof u == "object" && u !== null && n.push(u);
847
+ typeof f == "object" && f !== null && r.push(f);
848
+ const u = o.additionalProperties;
849
+ typeof u == "object" && u !== null && r.push(u);
850
+ const c = o.propertyNames;
851
+ typeof c == "object" && c !== null && r.push(c);
600
852
  }
601
853
  }
602
- const Y = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
603
- function Le(e) {
854
+ const re = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
855
+ function et(e) {
604
856
  if (typeof e != "object" || e === null)
605
857
  return !1;
606
858
  const t = e;
607
859
  if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
608
860
  return !1;
609
- const { type: r } = t;
610
- return typeof r == "string" ? Y.has(r) : Array.isArray(r) ? r.every((n) => Y.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
861
+ const { type: n } = t;
862
+ return typeof n == "string" ? re.has(n) : Array.isArray(n) ? n.every((r) => re.has(r) || r === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((r) => ["string", "number", "boolean"].includes(typeof r)) : !1;
611
863
  }
612
- function Re(e) {
864
+ function tt(e) {
613
865
  if (!e || typeof e != "object")
614
866
  return !1;
615
867
  const t = e.properties;
616
868
  return t === void 0 || typeof t != "object" || t === null ? !1 : Object.values(t).every(
617
- Le
869
+ et
618
870
  );
619
871
  }
620
- function Be(e) {
621
- const t = {}, r = (n) => {
872
+ function nt(e) {
873
+ const t = {}, n = (r) => {
622
874
  for (const o of ["definitions", "$defs"]) {
623
- const i = n[o];
875
+ const i = r[o];
624
876
  if (i)
625
877
  for (const [s, a] of Object.entries(i)) {
626
878
  const f = s.startsWith("#/") ? s : `#/${o}/${s}`;
@@ -628,80 +880,80 @@ function Be(e) {
628
880
  }
629
881
  }
630
882
  };
631
- for (const n of Object.values(e.schemas))
632
- r(n.input), r(n.output);
883
+ for (const r of Object.values(e.schemas))
884
+ n(r.input), n(r.output);
633
885
  if (Object.keys(t).length !== 0)
634
- for (const [n, o] of Object.entries(e.schemas))
886
+ for (const [r, o] of Object.entries(e.schemas))
635
887
  try {
636
- J(o.input, t), J(o.output, t);
888
+ ne(o.input, t), ne(o.output, t);
637
889
  } catch (i) {
638
890
  throw new Error(
639
- `[apigen-core-client] Schema validation failed for function "${n}": ${i.message}`
891
+ `[apigen-core-client] Schema validation failed for function "${r}": ${i.message}`
640
892
  );
641
893
  }
642
894
  }
643
- function Fe(e, t) {
644
- const r = [
895
+ function rt(e, t) {
896
+ const n = [
645
897
  'apigen calling convention: all domain parameters go inside a "data" envelope — e.g. { "data": { ... } }' + (t ? "." : " (an empty object for this zero-parameter tool).")
646
898
  ];
647
- return e.length > 0 && r.push(
648
- `Field(s) ${e.map((n) => `"${n}"`).join(", ")} are transport-level envelope metadata, NOT domain data — do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`
649
- ), r.join(" ");
899
+ return e.length > 0 && n.push(
900
+ `Field(s) ${e.map((r) => `"${r}"`).join(", ")} are transport-level envelope metadata, NOT domain data — do not nest them under "data". Over MCP they are read from arguments._meta["x-<pluginId>-<field>"] (default pluginId "adhd"); see @adhd/apigen-engine-naming's envelopeMetaKey/envelopeCliFlag/envelopeEnvVar for the HTTP-header / CLI-flag / env-var equivalents.`
901
+ ), n.join(" ");
650
902
  }
651
- function Ke(e, t, r) {
652
- Be(e);
653
- const n = {};
903
+ function ot(e, t, n) {
904
+ nt(e);
905
+ const r = {};
654
906
  for (const [o, i] of Object.entries(e.schemas)) {
655
- const s = (r == null ? void 0 : r[o]) ?? {}, a = i.input.properties ?? {}, f = i.input.required ?? [], c = {}, u = [], p = {};
907
+ const s = (n == null ? void 0 : n[o]) ?? {}, a = i.input.properties ?? {}, f = i.input.required ?? [], u = {}, c = [], l = {};
656
908
  for (const h of t)
657
909
  if (h.envelope && s[h.id] !== !1)
658
- for (const [b, he] of Object.entries(h.envelope))
659
- c[b] = he, p[b] = h.id, u.includes(b) || u.push(b);
660
- const d = {
910
+ for (const [b, Ee] of Object.entries(h.envelope))
911
+ u[b] = Ee, l[b] = h.id, c.includes(b) || c.push(b);
912
+ const p = {
661
913
  type: "object",
662
914
  properties: a,
663
915
  additionalProperties: !1,
664
916
  ...f.length > 0 ? { required: f } : {}
665
- }, m = i.safe === !0 || Re(i.input), l = i.input.definitions, y = i.input.$defs;
666
- n[o] = {
917
+ }, y = i.safe === !0 || tt(i.input), d = i.input.definitions, m = i.input.$defs;
918
+ r[o] = {
667
919
  input: {
668
920
  type: "object",
669
- properties: { ...c, data: d },
921
+ properties: { ...u, data: p },
670
922
  required: [
671
- ...u,
923
+ ...c,
672
924
  ...f.length > 0 ? ["data"] : []
673
925
  ],
674
926
  // BUG-APIGEN-017: reject any property that isn't a declared envelope
675
927
  // field or the "data" wrapper — no silently-ignored junk params.
676
928
  additionalProperties: !1,
677
929
  // BUG-APIGEN-020: document the envelope/data calling convention inline.
678
- description: Fe(
679
- Object.keys(c),
930
+ description: rt(
931
+ Object.keys(u),
680
932
  Object.keys(a).length > 0
681
933
  ),
682
- ...l ? { definitions: l } : {},
683
- ...y ? { $defs: y } : {}
934
+ ...d ? { definitions: d } : {},
935
+ ...m ? { $defs: m } : {}
684
936
  },
685
937
  output: i.output,
686
938
  // Carry the ctx-param flag through to dispatch (BUG-APIGEN-001).
687
939
  ...i.hasCtx ? { hasCtx: !0 } : {},
688
- "x-apigen-safe": m,
940
+ "x-apigen-safe": y,
689
941
  // DEBT-APIGEN-ENVELOPE-CAPABILITY-UNWIRED-001: field → pluginId map,
690
942
  // read by `op-plan.ts`'s `computeEnvelopeFields`. Omitted (not an empty
691
943
  // object) when no middleware contributed an envelope field, matching
692
944
  // `x-apigen-safe`'s own "absent means nothing to report" convention.
693
- ...Object.keys(p).length > 0 ? { "x-apigen-envelope": p } : {}
945
+ ...Object.keys(l).length > 0 ? { "x-apigen-envelope": l } : {}
694
946
  };
695
947
  }
696
- return n;
948
+ return r;
697
949
  }
698
- const He = {
950
+ const it = {
699
951
  "decimal.js": "Decimal"
700
952
  };
701
- function qe(e) {
953
+ function st(e) {
702
954
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
703
955
  }
704
- Object.entries(He).map(([e, t]) => ({
956
+ Object.entries(it).map(([e, t]) => ({
705
957
  // Matches: import("...{modSpec}...").<anyMemberName> (single or double quotes)
706
958
  // The module specifier appears inside an absolute path, so we allow any
707
959
  // characters between the quote and the specifier, and between the specifier
@@ -709,127 +961,155 @@ Object.entries(He).map(([e, t]) => ({
709
961
  // …) is matched generically (`\w+`) rather than anchored to one spelling —
710
962
  // see the doc comment above for why.
711
963
  pattern: new RegExp(
712
- `import\\(["'][^"']*${qe(e)}[^"']*["']\\)\\.\\w+`,
964
+ `import\\(["'][^"']*${st(e)}[^"']*["']\\)\\.\\w+`,
713
965
  "g"
714
966
  ),
715
967
  key: t
716
968
  }));
717
- class D extends Error {
969
+ class B extends Error {
718
970
  constructor(t) {
719
971
  super(t), this.name = "ConfigurationError";
720
972
  }
721
973
  }
722
- function ze(e) {
974
+ function at(e) {
723
975
  for (const t of e)
724
- for (const r of Object.keys(t.eventMapping ?? {})) {
725
- const [n] = r.split(":");
726
- if (n !== "*" && n === t.id)
727
- throw new D(
728
- `Middleware "${t.id}" subscribes to its own events via "${r}". This would cause infinite recursion.`
976
+ for (const n of Object.keys(t.eventMapping ?? {})) {
977
+ const [r] = n.split(":");
978
+ if (r !== "*" && r === t.id)
979
+ throw new B(
980
+ `Middleware "${t.id}" subscribes to its own events via "${n}". This would cause infinite recursion.`
729
981
  );
730
982
  }
731
983
  }
732
- function Ht(e) {
984
+ function pn(e) {
733
985
  const {
734
986
  domainSchemas: t,
735
- middlewares: r,
736
- overrides: n = {},
987
+ middlewares: n,
988
+ overrides: r = {},
737
989
  strict: o = !1
738
990
  } = e;
739
- ze(r);
740
- for (const c of Object.keys(n))
741
- if (!(c in t.schemas)) {
742
- const u = `Override key "${c}" not found in domain schemas.`;
991
+ at(n);
992
+ for (const u of Object.keys(r))
993
+ if (!(u in t.schemas)) {
994
+ const c = `Override key "${u}" not found in domain schemas.`;
743
995
  if (o)
744
- throw new D(u);
745
- console.warn("[apigen-runtime]", u);
996
+ throw new B(c);
997
+ console.warn("[apigen-runtime]", c);
746
998
  }
747
- const i = new Set(r.map((c) => c.id));
748
- for (const [c, u] of Object.entries(n))
749
- for (const p of Object.keys(u ?? {}))
750
- if (!i.has(p)) {
751
- const d = `Override key "${c}.${p}" does not match any declared middleware id.`;
999
+ const i = new Set(n.map((u) => u.id));
1000
+ for (const [u, c] of Object.entries(r))
1001
+ for (const l of Object.keys(c ?? {}))
1002
+ if (!i.has(l)) {
1003
+ const p = `Override key "${u}.${l}" does not match any declared middleware id.`;
752
1004
  if (o)
753
- throw new D(d);
754
- console.warn("[apigen-runtime]", d);
1005
+ throw new B(p);
1006
+ console.warn("[apigen-runtime]", p);
755
1007
  }
756
- const s = Ke(
1008
+ const s = ot(
757
1009
  t,
758
- r,
759
- n
760
- ), a = new Te();
761
- return De(r, a), { schemas: s, createClient: async (c) => Ue(r, c, a), dispose: () => a.clear() };
1010
+ n,
1011
+ r
1012
+ ), a = new Ye();
1013
+ return Qe(n, a), { schemas: s, createClient: async (u) => Xe(n, u, a), dispose: () => a.clear() };
762
1014
  }
763
- function qt(e = {}) {
764
- const t = e.level ?? "info", r = typeof e.destination == "string" && e.destination.length > 0, n = !r && !!process.stderr.isTTY, o = e.format ?? (n ? "pretty" : "json"), i = { level: t };
1015
+ function dn(e = {}) {
1016
+ const t = e.level ?? "info", n = typeof e.destination == "string" && e.destination.length > 0, r = !n && !!process.stderr.isTTY, o = e.format ?? (r ? "pretty" : "json"), i = { level: t };
765
1017
  if (o === "pretty")
766
1018
  return i.transport = {
767
1019
  target: "pino-pretty",
768
1020
  options: {
769
- colorize: !r,
1021
+ colorize: !n,
770
1022
  translateTime: "SYS:HH:MM:ss.l",
771
1023
  ignore: "pid,hostname",
772
- ...r ? { destination: e.destination, mkdir: !0 } : { destination: 2 }
1024
+ ...n ? { destination: e.destination, mkdir: !0 } : { destination: 2 }
773
1025
  }
774
1026
  }, N(i);
775
- const s = r ? N.destination({ dest: e.destination, mkdir: !0, sync: !0 }) : N.destination(2);
1027
+ const s = n ? N.destination({ dest: e.destination, mkdir: !0, sync: !0 }) : N.destination(2);
776
1028
  return N(i, s);
777
1029
  }
778
- function le(e) {
779
- return e ? e.type === "array" ? `${le(e.items)}[]` : e.enum ? "enum" : e.$ref ? String(e.$ref).split("/").pop() || "object" : e.anyOf || e.oneOf ? "union" : e.type ?? "object" : "unknown";
1030
+ function ct(e) {
1031
+ if (!e || e.type !== "object" || !e.properties)
1032
+ return;
1033
+ const t = Object.entries(e.properties);
1034
+ if (t.length === 0)
1035
+ return;
1036
+ const n = new Set(e.required ?? []);
1037
+ return `{ ${t.map(([o, i]) => `${o}${n.has(o) ? "" : "?"}: ${k(i)}`).join(", ")} }`;
1038
+ }
1039
+ function ut(e) {
1040
+ return typeof e == "string" ? `'${e}'` : JSON.stringify(e);
1041
+ }
1042
+ function ft(e) {
1043
+ const t = e.enum ?? [];
1044
+ return t.length === 0 ? "unknown" : t.map(ut).join("|");
780
1045
  }
781
- function Ve(e) {
1046
+ function lt(e, t) {
1047
+ return e.map((n) => k(n, t)).join(" | ");
1048
+ }
1049
+ function k(e, t = 0) {
1050
+ if (!e)
1051
+ return "unknown";
1052
+ if (e.type === "array")
1053
+ return `${k(e.items, 0)}[]`;
1054
+ if (e.enum)
1055
+ return ft(e);
1056
+ if (e.$ref)
1057
+ return String(e.$ref).split("/").pop() || "object";
1058
+ const n = e.anyOf ?? e.oneOf;
1059
+ return n ? n.length === 0 ? "unknown" : t >= 2 ? lt(n, t - 1) : "union" : t >= 1 && e.type === "object" ? ct(e) ?? "object" : e.type ?? "object";
1060
+ }
1061
+ function pt(e) {
782
1062
  var a;
783
- const r = (a = ((e == null ? void 0 : e.input) ?? {}).properties) == null ? void 0 : a.data, n = (r == null ? void 0 : r.properties) ?? {}, o = new Set((r == null ? void 0 : r.required) ?? []), i = Object.entries(n).map(([f, c]) => ({
1063
+ const n = (a = ((e == null ? void 0 : e.input) ?? {}).properties) == null ? void 0 : a.data, r = (n == null ? void 0 : n.properties) ?? {}, o = new Set((n == null ? void 0 : n.required) ?? []), i = Object.entries(r).map(([f, u]) => ({
784
1064
  name: f,
785
- type: le(c),
1065
+ type: k(u, 2),
786
1066
  required: o.has(f)
787
1067
  })), s = i.map((f) => `${f.name}${f.required ? "" : "?"}: ${f.type}`).join(", ");
788
1068
  return { params: i, text: s };
789
1069
  }
790
- function We(e) {
1070
+ function dt(e) {
791
1071
  let t;
792
- return Array.isArray(e) ? t = e : e ? t = [e] : t = [], t.find((r) => r === "number" || r === "integer" || r === "boolean");
1072
+ return Array.isArray(e) ? t = e : e ? t = [e] : t = [], t.find((n) => n === "number" || n === "integer" || n === "boolean");
793
1073
  }
794
- function zt(e, t) {
1074
+ function yn(e, t) {
795
1075
  var i, s;
796
- const n = ((s = (i = ((t == null ? void 0 : t.input) ?? {}).properties) == null ? void 0 : i.data) == null ? void 0 : s.properties) ?? {}, o = { ...e };
797
- for (const [a, f] of Object.entries(n)) {
798
- const c = o[a];
799
- if (typeof c != "string")
1076
+ const r = ((s = (i = ((t == null ? void 0 : t.input) ?? {}).properties) == null ? void 0 : i.data) == null ? void 0 : s.properties) ?? {}, o = { ...e };
1077
+ for (const [a, f] of Object.entries(r)) {
1078
+ const u = o[a];
1079
+ if (typeof u != "string")
800
1080
  continue;
801
- const u = We(f == null ? void 0 : f.type);
802
- if (u === "number" || u === "integer") {
803
- const p = Number(c);
804
- !Number.isNaN(p) && c.trim() !== "" && (o[a] = p);
1081
+ const c = dt(f == null ? void 0 : f.type);
1082
+ if (c === "number" || c === "integer") {
1083
+ const l = Number(u);
1084
+ !Number.isNaN(l) && u.trim() !== "" && (o[a] = l);
805
1085
  } else
806
- u === "boolean" && (c === "true" ? o[a] = !0 : c === "false" && (o[a] = !1));
1086
+ c === "boolean" && (u === "true" ? o[a] = !0 : u === "false" && (o[a] = !1));
807
1087
  }
808
1088
  return o;
809
1089
  }
810
- const X = /* @__PURE__ */ new Set(["default", "module.exports", "__esModule"]);
811
- function Vt(e) {
812
- const t = {}, r = (n, o) => {
813
- for (const [i, s] of Object.entries(n))
1090
+ const oe = /* @__PURE__ */ new Set(["default", "module.exports", "__esModule"]);
1091
+ function mn(e) {
1092
+ const t = {}, n = (r, o) => {
1093
+ for (const [i, s] of Object.entries(r))
814
1094
  if (typeof s == "function") {
815
- !X.has(i) && !(i in t) && (t[i] = s);
1095
+ !oe.has(i) && !(i in t) && (t[i] = s);
816
1096
  const a = s.name;
817
1097
  a && !(a in t) && (t[a] = s);
818
1098
  } else
819
- s && typeof s == "object" && o < 2 && X.has(i) && r(s, o + 1);
1099
+ s && typeof s == "object" && o < 2 && oe.has(i) && n(s, o + 1);
820
1100
  };
821
- return r(e, 0), t;
1101
+ return n(e, 0), t;
822
1102
  }
823
- const Ge = [
1103
+ const yt = [
824
1104
  "invalid_argument",
825
1105
  "unauthenticated",
826
1106
  "permission_denied",
827
1107
  "not_found",
828
1108
  "internal"
829
1109
  ];
830
- class A extends Error {
831
- constructor(t, r, n) {
832
- super(r), this.name = "ApiError", this.code = t, this.details = n, Object.setPrototypeOf(this, new.target.prototype);
1110
+ class I extends Error {
1111
+ constructor(t, n, r) {
1112
+ super(n), this.name = "ApiError", this.code = t, this.details = r, Object.setPrototypeOf(this, new.target.prototype);
833
1113
  }
834
1114
  /** Serialise to a plain object suitable for JSON transport. */
835
1115
  toJSON() {
@@ -840,81 +1120,85 @@ class A extends Error {
840
1120
  return this.details !== void 0 && (t.details = this.details), t;
841
1121
  }
842
1122
  }
843
- function de(e) {
844
- return typeof e == "object" && e !== null && e.name === "ApiError" && Ge.includes(e.code) && typeof e.toJSON == "function";
1123
+ function je(e) {
1124
+ return typeof e == "object" && e !== null && e.name === "ApiError" && yt.includes(e.code) && typeof e.toJSON == "function";
845
1125
  }
846
- function Q(e, t, r = 0) {
847
- return e === "before-first-chunk" ? { phase: e, error: t } : { phase: e, error: t, chunksDelivered: r };
1126
+ function ie(e, t, n = 0) {
1127
+ return e === "before-first-chunk" ? { phase: e, error: t } : { phase: e, error: t, chunksDelivered: n };
848
1128
  }
849
- const j = new ge({ allErrors: !0 });
850
- we(j);
1129
+ const O = new _e({ allErrors: !0 });
1130
+ ke(O);
851
1131
  for (const e of [
852
- L,
853
- R,
854
- S,
855
- x,
1132
+ F,
1133
+ V,
1134
+ T,
1135
+ P,
856
1136
  "discriminator"
857
1137
  ])
858
- j.addKeyword({ keyword: e, valid: !0 });
859
- j.addFormat("decimal", /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);
860
- function ye(e) {
1138
+ O.addKeyword({ keyword: e, valid: !0 });
1139
+ O.addFormat("decimal", /^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/);
1140
+ function mt(e) {
861
1141
  return e.map(
862
1142
  (t) => `${t.instancePath || "(root)"} ${t.message ?? "failed schema check"}`
863
1143
  ).join("; ");
864
1144
  }
865
- const Wt = async (e, t) => {
866
- const r = e.ctx.get(Je);
867
- if (r === void 0)
1145
+ function Oe(e, t) {
1146
+ const n = ve(t), r = [`Validation failed: ${mt(e)}`];
1147
+ return n && r.push(n), r.join(" — ");
1148
+ }
1149
+ const hn = async (e, t) => {
1150
+ const n = e.ctx.get(ht);
1151
+ if (n === void 0)
868
1152
  return t();
869
- const n = e.operation.id, o = r[n];
1153
+ const r = e.operation.id, o = n[r];
870
1154
  if (o === void 0)
871
1155
  return t();
872
1156
  const i = {
873
1157
  data: e.domainArgs,
874
1158
  ...e.envelope
875
- }, s = j.compile(o.input);
1159
+ }, s = O.compile(o.input);
876
1160
  if (!s(i)) {
877
1161
  const f = s.errors ?? [];
878
- throw new A(
1162
+ throw new I(
879
1163
  "invalid_argument",
880
- `Validation failed: ${ye(f)}`,
1164
+ Oe(f, o.input),
881
1165
  f
882
1166
  );
883
1167
  }
884
1168
  return t();
885
- }, Je = Symbol("ValidateSchemasToken");
886
- function Ye(e) {
887
- return async function(r, n) {
888
- const o = r.operation.id, i = e[o];
1169
+ }, ht = Symbol("ValidateSchemasToken");
1170
+ function gt(e) {
1171
+ return async function(n, r) {
1172
+ const o = n.operation.id, i = e[o];
889
1173
  if (i === void 0)
890
- return n();
1174
+ return r();
891
1175
  const s = {
892
- data: r.domainArgs,
893
- ...r.envelope
894
- }, a = j.compile(i.input);
1176
+ data: n.domainArgs,
1177
+ ...n.envelope
1178
+ }, a = O.compile(i.input);
895
1179
  if (!a(s)) {
896
- const c = a.errors ?? [];
897
- throw new A(
1180
+ const u = a.errors ?? [];
1181
+ throw new I(
898
1182
  "invalid_argument",
899
- `Validation failed: ${ye(c)}`,
900
- c
1183
+ Oe(u, i.input),
1184
+ u
901
1185
  );
902
1186
  }
903
- return n();
1187
+ return r();
904
1188
  };
905
1189
  }
906
- function Xe() {
1190
+ function wt() {
907
1191
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
908
1192
  const t = Math.random() * 16 | 0;
909
1193
  return (e === "x" ? t : t & 3 | 8).toString(16);
910
1194
  });
911
1195
  }
912
- class Gt {
1196
+ class gn {
913
1197
  constructor(t = {}) {
914
- var n, o;
1198
+ var r, o;
915
1199
  this._store = /* @__PURE__ */ new Map(), this._sweeper = null, this._defaultTtlMs = t.defaultTtlMs;
916
- let r = null;
917
- t.sweepIntervalMs === 0 ? r = null : t.sweepIntervalMs !== void 0 ? r = t.sweepIntervalMs : this._defaultTtlMs !== void 0 ? r = Math.max(1e3, Math.floor(this._defaultTtlMs / 4)) : r = null, r !== null && r > 0 && (this._sweeper = setInterval(() => this._sweep(), r), (o = (n = this._sweeper).unref) == null || o.call(n));
1200
+ let n = null;
1201
+ t.sweepIntervalMs === 0 ? n = null : t.sweepIntervalMs !== void 0 ? n = t.sweepIntervalMs : this._defaultTtlMs !== void 0 ? n = Math.max(1e3, Math.floor(this._defaultTtlMs / 4)) : n = null, n !== null && n > 0 && (this._sweeper = setInterval(() => this._sweep(), n), (o = (r = this._sweeper).unref) == null || o.call(r));
918
1202
  }
919
1203
  // ---------------------------------------------------------------------------
920
1204
  // create — construct + register
@@ -927,8 +1211,8 @@ class Gt {
927
1211
  * @param ttlMs - Per-entry TTL override. Falls back to `defaultTtlMs`.
928
1212
  * @returns `{ instanceId }` — pass this to `dispatch()` / `get()`.
929
1213
  */
930
- create(t, r = [], n) {
931
- const o = new t(...r), i = Xe(), s = n ?? this._defaultTtlMs, a = s !== void 0 ? Date.now() + s : null;
1214
+ create(t, n = [], r) {
1215
+ const o = new t(...n), i = wt(), s = r ?? this._defaultTtlMs, a = s !== void 0 ? Date.now() + s : null;
932
1216
  return this._store.set(i, { instance: o, expiresAt: a }), { instanceId: i };
933
1217
  }
934
1218
  // ---------------------------------------------------------------------------
@@ -940,16 +1224,16 @@ class Gt {
940
1224
  * @throws When `instanceId` is unknown or the entry has expired.
941
1225
  */
942
1226
  get(t) {
943
- const r = this._store.get(t);
944
- if (!r)
1227
+ const n = this._store.get(t);
1228
+ if (!n)
945
1229
  throw new Error(
946
1230
  `[instance-registry] Unknown instanceId: "${t}"`
947
1231
  );
948
- if (r.expiresAt !== null && Date.now() > r.expiresAt)
949
- throw this._evict(t, r), new Error(
1232
+ if (n.expiresAt !== null && Date.now() > n.expiresAt)
1233
+ throw this._evict(t, n), new Error(
950
1234
  `[instance-registry] Instance "${t}" has expired`
951
1235
  );
952
- return r.instance;
1236
+ return n.instance;
953
1237
  }
954
1238
  // ---------------------------------------------------------------------------
955
1239
  // dispatch — call a method on a live instance
@@ -960,13 +1244,13 @@ class Gt {
960
1244
  * @throws When `instanceId` is unknown/expired, or `method` is not a function
961
1245
  * on the instance.
962
1246
  */
963
- async dispatch(t, r, n = []) {
964
- const o = this.get(t), i = o[r];
1247
+ async dispatch(t, n, r = []) {
1248
+ const o = this.get(t), i = o[n];
965
1249
  if (typeof i != "function")
966
1250
  throw new Error(
967
- `[instance-registry] Method "${r}" not found on instance "${t}"`
1251
+ `[instance-registry] Method "${n}" not found on instance "${t}"`
968
1252
  );
969
- return i.call(o, ...n);
1253
+ return i.call(o, ...r);
970
1254
  }
971
1255
  // ---------------------------------------------------------------------------
972
1256
  // dispose — explicit teardown
@@ -976,8 +1260,8 @@ class Gt {
976
1260
  * instance exposes one (opt-in lifecycle hook).
977
1261
  */
978
1262
  async dispose(t) {
979
- const r = this._store.get(t);
980
- r && (this._store.delete(t), await k(r.instance));
1263
+ const n = this._store.get(t);
1264
+ n && (this._store.delete(t), await x(n.instance));
981
1265
  }
982
1266
  // ---------------------------------------------------------------------------
983
1267
  // disposeAll — full teardown
@@ -989,7 +1273,7 @@ class Gt {
989
1273
  async disposeAll() {
990
1274
  this._sweeper !== null && (clearInterval(this._sweeper), this._sweeper = null);
991
1275
  const t = [...this._store.entries()];
992
- this._store.clear(), await Promise.all(t.map(([, r]) => k(r.instance)));
1276
+ this._store.clear(), await Promise.all(t.map(([, n]) => x(n.instance)));
993
1277
  }
994
1278
  // ---------------------------------------------------------------------------
995
1279
  // size — diagnostic helper
@@ -1003,27 +1287,27 @@ class Gt {
1003
1287
  // ---------------------------------------------------------------------------
1004
1288
  _sweep() {
1005
1289
  const t = Date.now();
1006
- for (const [r, n] of this._store)
1007
- n.expiresAt !== null && t > n.expiresAt && this._evict(r, n);
1290
+ for (const [n, r] of this._store)
1291
+ r.expiresAt !== null && t > r.expiresAt && this._evict(n, r);
1008
1292
  }
1009
- _evict(t, r) {
1010
- this._store.delete(t), k(r.instance);
1293
+ _evict(t, n) {
1294
+ this._store.delete(t), x(n.instance);
1011
1295
  }
1012
1296
  }
1013
- async function k(e) {
1297
+ async function x(e) {
1014
1298
  if (e !== null && typeof e == "object" && "dispose" in e) {
1015
1299
  const t = e.dispose;
1016
1300
  typeof t == "function" && await t.call(e);
1017
1301
  }
1018
1302
  }
1019
- function Jt(e) {
1020
- const { produce: t, signal: r } = e, n = r ?? new AbortController().signal;
1303
+ function wn(e) {
1304
+ const { produce: t, signal: n } = e, r = n ?? new AbortController().signal;
1021
1305
  return {
1022
1306
  [Symbol.asyncIterator]() {
1023
- const o = t(n);
1307
+ const o = t(r);
1024
1308
  return {
1025
1309
  async next() {
1026
- return n.aborted ? (await o.return(void 0), { done: !0, value: void 0 }) : o.next();
1310
+ return r.aborted ? (await o.return(void 0), { done: !0, value: void 0 }) : o.next();
1027
1311
  },
1028
1312
  async return(i) {
1029
1313
  return await o.return(i), { done: !0, value: void 0 };
@@ -1035,183 +1319,183 @@ function Jt(e) {
1035
1319
  }
1036
1320
  };
1037
1321
  }
1038
- async function Yt(e) {
1322
+ async function bn(e) {
1039
1323
  const t = [];
1040
- for await (const r of e)
1041
- t.push(r);
1324
+ for await (const n of e)
1325
+ t.push(n);
1042
1326
  return t;
1043
1327
  }
1044
- async function Qe(e) {
1328
+ async function bt(e) {
1045
1329
  const t = [];
1046
1330
  try {
1047
- for await (const r of e)
1048
- t.push(r);
1331
+ for await (const n of e)
1332
+ t.push(n);
1049
1333
  return { ok: !0, chunks: t };
1050
- } catch (r) {
1051
- const n = de(r) ? r : new A(
1334
+ } catch (n) {
1335
+ const r = je(n) ? n : new I(
1052
1336
  "internal",
1053
- r instanceof Error ? r.message : String(r)
1337
+ n instanceof Error ? n.message : String(n)
1054
1338
  );
1055
1339
  return t.length === 0 ? {
1056
1340
  ok: !1,
1057
- carrier: Q("before-first-chunk", n)
1341
+ carrier: ie("before-first-chunk", r)
1058
1342
  } : {
1059
1343
  ok: !1,
1060
- carrier: Q("after-first-chunk", n, t.length)
1344
+ carrier: ie("after-first-chunk", r, t.length)
1061
1345
  };
1062
1346
  }
1063
1347
  }
1064
- function Ze(e) {
1348
+ function vt(e) {
1065
1349
  return e !== null && typeof e == "object" && Symbol.asyncIterator in e;
1066
1350
  }
1067
1351
  class g extends Error {
1068
- constructor(t, r) {
1069
- super(r), this.name = "UnionCodecError", this.code = t;
1352
+ constructor(t, n) {
1353
+ super(n), this.name = "UnionCodecError", this.code = t;
1070
1354
  }
1071
1355
  }
1072
- function I(e) {
1356
+ function S(e) {
1073
1357
  const t = e.discriminator;
1074
1358
  if (t === null || typeof t != "object" || Array.isArray(t))
1075
1359
  return;
1076
- const r = t;
1077
- if (typeof r.propertyName != "string")
1360
+ const n = t;
1361
+ if (typeof n.propertyName != "string")
1078
1362
  return;
1079
- const n = r.mapping;
1080
- if (!(n === null || typeof n != "object" || Array.isArray(n)))
1363
+ const r = n.mapping;
1364
+ if (!(r === null || typeof r != "object" || Array.isArray(r)))
1081
1365
  return {
1082
- propertyName: r.propertyName,
1083
- mapping: n
1366
+ propertyName: n.propertyName,
1367
+ mapping: r
1084
1368
  };
1085
1369
  }
1086
- function me(e, t) {
1087
- const r = e[R];
1088
- if (typeof r == "string") {
1089
- const n = t.registry.get(r);
1090
- if (n)
1091
- return n;
1370
+ function Ne(e, t) {
1371
+ const n = e[V];
1372
+ if (typeof n == "string") {
1373
+ const r = t.registry.get(n);
1374
+ if (r)
1375
+ return r;
1092
1376
  }
1093
1377
  return t.registry.resolve(e);
1094
1378
  }
1095
- function et(e, t, r) {
1096
- const n = me(t, r);
1097
- return n ? n.encode(e, t, r) : e;
1379
+ function $t(e, t, n) {
1380
+ const r = Ne(t, n);
1381
+ return r ? r.encode(e, t, n) : e;
1098
1382
  }
1099
- function tt(e, t, r) {
1100
- const n = me(t, r);
1101
- return n ? n.decode(e, t, r) : e;
1383
+ function At(e, t, n) {
1384
+ const r = Ne(t, n);
1385
+ return r ? r.decode(e, t, n) : e;
1102
1386
  }
1103
- function rt(e) {
1104
- const { id: t, schema: r } = e;
1387
+ function jt(e) {
1388
+ const { id: t, schema: n } = e;
1105
1389
  return {
1106
1390
  id: t,
1107
1391
  kind: "union",
1108
- schema: r,
1392
+ schema: n,
1109
1393
  /**
1110
1394
  * Structural ownership test: the node carries both `oneOf` (non-empty array)
1111
1395
  * and `discriminator.propertyName`. The `x-apigen-logical:"union"` hint
1112
1396
  * accelerates the match but is advisory — the structure is authoritative.
1113
1397
  */
1114
- matches(n) {
1115
- if (n[L] === "union")
1398
+ matches(r) {
1399
+ if (r[F] === "union")
1116
1400
  return !0;
1117
- const o = n.oneOf;
1118
- return !Array.isArray(o) || o.length === 0 ? !1 : I(n) !== void 0;
1401
+ const o = r.oneOf;
1402
+ return !Array.isArray(o) || o.length === 0 ? !1 : S(r) !== void 0;
1119
1403
  },
1120
- encode(n, o, i) {
1121
- const s = I(o);
1404
+ encode(r, o, i) {
1405
+ const s = S(o);
1122
1406
  if (!s)
1123
1407
  throw new g(
1124
1408
  "E_UNION_NO_DISCRIMINATOR",
1125
1409
  `[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`
1126
1410
  );
1127
- const { propertyName: a, mapping: f } = s, c = n[a];
1128
- if (c == null)
1411
+ const { propertyName: a, mapping: f } = s, u = r[a];
1412
+ if (u == null)
1129
1413
  throw new g(
1130
1414
  "E_UNION_NO_DISCRIMINATOR",
1131
1415
  `[${t}] value at "${i.path}" is missing the discriminator property "${a}".`
1132
1416
  );
1133
- const u = String(c), p = f[u];
1134
- if (!p)
1417
+ const c = String(u), l = f[c];
1418
+ if (!l)
1135
1419
  throw new g(
1136
1420
  "E_UNION_UNKNOWN_TAG",
1137
- `[${t}] discriminator tag "${u}" at "${i.path}" is not in the mapping (known: ${Object.keys(f).join(", ")}).`
1421
+ `[${t}] discriminator tag "${c}" at "${i.path}" is not in the mapping (known: ${Object.keys(f).join(", ")}).`
1138
1422
  );
1139
- const d = i.resolve(p);
1140
- return et(n, d, {
1423
+ const p = i.resolve(l);
1424
+ return $t(r, p, {
1141
1425
  ...i,
1142
- path: `${i.path}[${u}]`
1426
+ path: `${i.path}[${c}]`
1143
1427
  });
1144
1428
  },
1145
- decode(n, o, i) {
1146
- if (n === null || typeof n != "object" || Array.isArray(n)) {
1147
- let l;
1148
- throw n === null ? l = "null" : Array.isArray(n) ? l = "array" : l = typeof n, new g(
1429
+ decode(r, o, i) {
1430
+ if (r === null || typeof r != "object" || Array.isArray(r)) {
1431
+ let d;
1432
+ throw r === null ? d = "null" : Array.isArray(r) ? d = "array" : d = typeof r, new g(
1149
1433
  "E_UNION_INVALID_WIRE",
1150
- `[${t}] expected a JSON object on the wire at "${i.path}", got ${l}.`
1434
+ `[${t}] expected a JSON object on the wire at "${i.path}", got ${d}.`
1151
1435
  );
1152
1436
  }
1153
- const s = n, a = I(o);
1437
+ const s = r, a = S(o);
1154
1438
  if (!a)
1155
1439
  throw new g(
1156
1440
  "E_UNION_NO_DISCRIMINATOR",
1157
1441
  `[${t}] schema node at "${i.path}" has no discriminator.propertyName; cannot dispatch union branch.`
1158
1442
  );
1159
- const { propertyName: f, mapping: c } = a, u = s[f];
1160
- if (u == null)
1443
+ const { propertyName: f, mapping: u } = a, c = s[f];
1444
+ if (c == null)
1161
1445
  throw new g(
1162
1446
  "E_UNION_NO_DISCRIMINATOR",
1163
1447
  `[${t}] wire object at "${i.path}" is missing the discriminator property "${f}".`
1164
1448
  );
1165
- const p = String(u), d = c[p];
1166
- if (!d)
1449
+ const l = String(c), p = u[l];
1450
+ if (!p)
1167
1451
  throw new g(
1168
1452
  "E_UNION_UNKNOWN_TAG",
1169
- `[${t}] discriminator tag "${p}" on the wire at "${i.path}" is not in the mapping (known: ${Object.keys(c).join(", ")}).`
1453
+ `[${t}] discriminator tag "${l}" on the wire at "${i.path}" is not in the mapping (known: ${Object.keys(u).join(", ")}).`
1170
1454
  );
1171
- const m = i.resolve(d);
1172
- return tt(n, m, {
1455
+ const y = i.resolve(p);
1456
+ return At(r, y, {
1173
1457
  ...i,
1174
- path: `${i.path}[${p}]`
1458
+ path: `${i.path}[${l}]`
1175
1459
  });
1176
1460
  }
1177
1461
  };
1178
1462
  }
1179
- const nt = "x-apigen-instances";
1180
- class O extends Error {
1181
- constructor(t, r) {
1182
- super(r), this.name = "NominalCodecError", this.code = t;
1463
+ const Ot = "x-apigen-instances";
1464
+ class E extends Error {
1465
+ constructor(t, n) {
1466
+ super(n), this.name = "NominalCodecError", this.code = t;
1183
1467
  }
1184
1468
  }
1185
- function Z(e) {
1469
+ function se(e) {
1186
1470
  const t = e.properties;
1187
1471
  return t && typeof t == "object" && !Array.isArray(t) ? t : {};
1188
1472
  }
1189
- function ot(e) {
1473
+ function Nt(e) {
1190
1474
  const t = e.required;
1191
- return Array.isArray(t) ? t.filter((r) => typeof r == "string") : [];
1475
+ return Array.isArray(t) ? t.filter((n) => typeof n == "string") : [];
1192
1476
  }
1193
- function ee(e, t, r) {
1477
+ function ae(e, t, n) {
1194
1478
  if (t) {
1195
- const n = r.registry.resolve(t);
1196
- if (n)
1197
- return n.encode(e, t, r);
1479
+ const r = n.registry.resolve(t);
1480
+ if (r)
1481
+ return r.encode(e, t, n);
1198
1482
  }
1199
1483
  return e;
1200
1484
  }
1201
- function it(e, t, r) {
1485
+ function Et(e, t, n) {
1202
1486
  if (t) {
1203
- const n = r.registry.resolve(t);
1204
- if (n)
1205
- return n.decode(e, t, r);
1487
+ const r = n.registry.resolve(t);
1488
+ if (r)
1489
+ return r.decode(e, t, n);
1206
1490
  }
1207
1491
  return e;
1208
1492
  }
1209
- function st(e) {
1210
- const { id: t, schema: r, ctor: n } = e;
1493
+ function _t(e) {
1494
+ const { id: t, schema: n, ctor: r } = e;
1211
1495
  return {
1212
1496
  id: t,
1213
1497
  kind: "nominal",
1214
- schema: r,
1498
+ schema: n,
1215
1499
  /**
1216
1500
  * Structural ownership test: the node advertises `x-apigen-logical:'nominal'`
1217
1501
  * or carries an `x-apigen-codec` matching this codec's id. Per
@@ -1220,14 +1504,14 @@ function st(e) {
1220
1504
  * handled by the transcoder walk, not by this cheap test.
1221
1505
  */
1222
1506
  matches(o) {
1223
- return o[L] === "nominal" ? !0 : o[R] === t;
1507
+ return o[F] === "nominal" ? !0 : o[V] === t;
1224
1508
  },
1225
1509
  encode(o, i, s) {
1226
1510
  if (o === null || typeof o != "object")
1227
1511
  return o;
1228
1512
  if (s.seen.has(o)) {
1229
1513
  if (s.mode === "strict")
1230
- throw new O(
1514
+ throw new E(
1231
1515
  "E_NOMINAL_CYCLE",
1232
1516
  `[${t}] cycle detected at "${s.path}": a nominal instance references itself. Strict mode rejects cycles (DESIGN §8.3); break the cycle or use 'lossy' mode.`
1233
1517
  );
@@ -1235,125 +1519,125 @@ function st(e) {
1235
1519
  }
1236
1520
  s.seen.add(o);
1237
1521
  try {
1238
- const a = Z(i), f = typeof i[x] == "string" ? i[x] : "toJSON", c = o[f];
1239
- if (typeof c == "function") {
1240
- const l = c.call(o);
1241
- if (l !== null && typeof l == "object" && !Array.isArray(l)) {
1242
- const y = {};
1522
+ const a = se(i), f = typeof i[P] == "string" ? i[P] : "toJSON", u = o[f];
1523
+ if (typeof u == "function") {
1524
+ const d = u.call(o);
1525
+ if (d !== null && typeof d == "object" && !Array.isArray(d)) {
1526
+ const m = {};
1243
1527
  for (const [h, b] of Object.entries(
1244
- l
1528
+ d
1245
1529
  ))
1246
- y[h] = ee(b, a[h], {
1530
+ m[h] = ae(b, a[h], {
1247
1531
  ...s,
1248
1532
  path: `${s.path}/${h}`
1249
1533
  });
1250
- return y;
1534
+ return m;
1251
1535
  }
1252
- return l;
1536
+ return d;
1253
1537
  }
1254
- const u = {}, p = Object.keys(a), d = o, m = p.length > 0 ? p : Object.keys(d);
1255
- for (const l of m) {
1256
- const y = d[l];
1257
- y !== void 0 && (u[l] = ee(y, a[l], {
1538
+ const c = {}, l = Object.keys(a), p = o, y = l.length > 0 ? l : Object.keys(p);
1539
+ for (const d of y) {
1540
+ const m = p[d];
1541
+ m !== void 0 && (c[d] = ae(m, a[d], {
1258
1542
  ...s,
1259
- path: `${s.path}/${l}`
1543
+ path: `${s.path}/${d}`
1260
1544
  }));
1261
1545
  }
1262
- return u;
1546
+ return c;
1263
1547
  } finally {
1264
1548
  s.seen.delete(o);
1265
1549
  }
1266
1550
  },
1267
1551
  decode(o, i, s) {
1268
1552
  if (o === null || typeof o != "object" || Array.isArray(o)) {
1269
- let u;
1270
- throw o === null ? u = "null" : Array.isArray(o) ? u = "array" : u = typeof o, new O(
1553
+ let c;
1554
+ throw o === null ? c = "null" : Array.isArray(o) ? c = "array" : c = typeof o, new E(
1271
1555
  "E_NOMINAL_INVALID_WIRE",
1272
- `[${t}] expected a JSON object on the wire at "${s.path}", got ${u}.`
1556
+ `[${t}] expected a JSON object on the wire at "${s.path}", got ${c}.`
1273
1557
  );
1274
1558
  }
1275
1559
  const a = o;
1276
- for (const u of ot(i))
1277
- if (!(u in a))
1278
- throw new O(
1560
+ for (const c of Nt(i))
1561
+ if (!(c in a))
1562
+ throw new E(
1279
1563
  "E_NOMINAL_INVALID_WIRE",
1280
- `[${t}] required field "${u}" missing on the wire at "${s.path}".`
1564
+ `[${t}] required field "${c}" missing on the wire at "${s.path}".`
1281
1565
  );
1282
- if (i[nt] === !1)
1283
- throw new O(
1566
+ if (i[Ot] === !1)
1567
+ throw new E(
1284
1568
  "E_NOMINAL_NONRECONSTRUCTABLE",
1285
1569
  `[${t}] is encode-only: the extractor marked it non-reconstructable (x-apigen-instances:false). It cannot be decoded back to a live instance.`
1286
1570
  );
1287
- const f = Z(i), c = {};
1288
- for (const [u, p] of Object.entries(a))
1289
- c[u] = it(p, f[u], {
1571
+ const f = se(i), u = {};
1572
+ for (const [c, l] of Object.entries(a))
1573
+ u[c] = Et(l, f[c], {
1290
1574
  ...s,
1291
- path: `${s.path}/${u}`
1575
+ path: `${s.path}/${c}`
1292
1576
  });
1293
- if (n) {
1294
- const u = typeof i[S] == "string" ? i[S] : "fromJSON", p = n[u];
1295
- if (typeof p == "function")
1296
- return p.call(
1297
- n,
1298
- c
1577
+ if (r) {
1578
+ const c = typeof i[T] == "string" ? i[T] : "fromJSON", l = r[c];
1579
+ if (typeof l == "function")
1580
+ return l.call(
1581
+ r,
1582
+ u
1299
1583
  );
1300
- const d = n;
1301
- return new d(c);
1584
+ const p = r;
1585
+ return new p(u);
1302
1586
  }
1303
- return c;
1587
+ return u;
1304
1588
  }
1305
1589
  };
1306
1590
  }
1307
- const at = [
1308
- B,
1309
- F,
1310
- K,
1591
+ const kt = [
1311
1592
  H,
1312
- q,
1313
- z
1314
- ], ct = {
1593
+ K,
1594
+ z,
1595
+ J,
1596
+ W,
1597
+ G
1598
+ ], It = {
1315
1599
  type: "object",
1316
1600
  "x-apigen-logical": "nominal",
1317
1601
  "x-apigen-codec": "ts.NominalSentinel"
1318
- }, te = st({
1602
+ }, ce = _t({
1319
1603
  id: "ts.NominalSentinel",
1320
- schema: ct
1321
- }), ut = {
1604
+ schema: It
1605
+ }), Ct = {
1322
1606
  oneOf: [],
1323
1607
  discriminator: { propertyName: "kind", mapping: {} },
1324
1608
  "x-apigen-logical": "union",
1325
1609
  "x-apigen-codec": "ts.UnionSentinel"
1326
- }, re = rt({
1610
+ }, ue = jt({
1327
1611
  id: "ts.UnionSentinel",
1328
- schema: ut
1612
+ schema: Ct
1329
1613
  });
1330
- function ft() {
1614
+ function xt() {
1331
1615
  const e = [
1332
1616
  // 6 well-known scalars
1333
- ...at.map((t) => [
1617
+ ...kt.map((t) => [
1334
1618
  t.id,
1335
1619
  t
1336
1620
  ]),
1337
1621
  // nominal kind sentinel
1338
- [te.id, te],
1622
+ [ce.id, ce],
1339
1623
  // union kind sentinel
1340
- [re.id, re]
1624
+ [ue.id, ue]
1341
1625
  ];
1342
1626
  return Object.freeze(new Map(e));
1343
1627
  }
1344
- const Xt = Object.freeze({
1628
+ const vn = Object.freeze({
1345
1629
  host: "ts",
1346
- logicalTypeVersion: ve,
1347
- codecs: ft()
1630
+ logicalTypeVersion: Ce,
1631
+ codecs: xt()
1348
1632
  });
1349
- function Qt(e, t, r) {
1350
- var i;
1351
- const n = typeof ((i = t == null ? void 0 : t.input) == null ? void 0 : i.description) == "string" ? t.input.description : void 0, o = [r, n].filter(
1352
- (s) => typeof s == "string" && s.length > 0
1633
+ function $n(e, t, n) {
1634
+ var s;
1635
+ const r = typeof ((s = t == null ? void 0 : t.input) == null ? void 0 : s.description) == "string" ? t.input.description : void 0, o = ve(t == null ? void 0 : t.input), i = [n, r, o].filter(
1636
+ (a) => typeof a == "string" && a.length > 0
1353
1637
  );
1354
- return o.length > 0 ? o.join(" — ") : e;
1638
+ return i.length > 0 ? i.join(" — ") : e;
1355
1639
  }
1356
- function Zt(e) {
1640
+ function An(e) {
1357
1641
  if (!e || typeof e != "object" || Array.isArray(e) || Object.keys(e).length === 0)
1358
1642
  return { outputSchema: void 0, wrapped: !1 };
1359
1643
  const t = e;
@@ -1366,144 +1650,145 @@ function Zt(e) {
1366
1650
  wrapped: !0
1367
1651
  };
1368
1652
  }
1369
- function er(e, t) {
1653
+ function jn(e, t) {
1370
1654
  return e ? { result: t } : t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
1371
1655
  }
1372
- const pt = 4, lt = 32;
1373
- function U(e) {
1374
- return de(e) ? e : e instanceof Error ? new A("internal", e.message) : e;
1656
+ const St = 4, Mt = 32;
1657
+ function q(e) {
1658
+ return je(e) ? e : e instanceof Error ? new I("internal", e.message) : e;
1375
1659
  }
1376
- function dt(e, t) {
1660
+ function Tt(e, t) {
1377
1661
  if (e === "serial" || e === "chained")
1378
1662
  return 1;
1379
- const r = t ?? pt;
1380
- return !Number.isFinite(r) || r < 1 ? 1 : Math.min(Math.floor(r), lt);
1663
+ const n = t ?? St;
1664
+ return !Number.isFinite(n) || n < 1 ? 1 : Math.min(Math.floor(n), Mt);
1381
1665
  }
1382
- function yt() {
1666
+ function Pt() {
1383
1667
  }
1384
- function mt(e, t) {
1668
+ function Dt(e, t) {
1385
1669
  var i;
1386
1670
  if (!e && !t)
1387
- return { signal: void 0, dispose: yt };
1388
- const r = new AbortController(), n = () => {
1389
- r.abort(e == null ? void 0 : e.reason);
1671
+ return { signal: void 0, dispose: Pt };
1672
+ const n = new AbortController(), r = () => {
1673
+ n.abort(e == null ? void 0 : e.reason);
1390
1674
  };
1391
- e && (e.aborted ? r.abort(e.reason) : e.addEventListener("abort", n, { once: !0 }));
1675
+ e && (e.aborted ? n.abort(e.reason) : e.addEventListener("abort", r, { once: !0 }));
1392
1676
  let o;
1393
- return t !== void 0 && !r.signal.aborted && (o = setTimeout(() => {
1394
- r.abort(
1677
+ return t !== void 0 && !n.signal.aborted && (o = setTimeout(() => {
1678
+ n.abort(
1395
1679
  new DOMException(
1396
1680
  `apigen/invokeBatch: item timed out after ${t}ms`,
1397
1681
  "TimeoutError"
1398
1682
  )
1399
1683
  );
1400
1684
  }, t), (i = o.unref) == null || i.call(o)), {
1401
- signal: r.signal,
1685
+ signal: n.signal,
1402
1686
  dispose() {
1403
- e && e.removeEventListener("abort", n), o && clearTimeout(o);
1687
+ e && e.removeEventListener("abort", r), o && clearTimeout(o);
1404
1688
  }
1405
1689
  };
1406
1690
  }
1407
- async function ne(e, t, r, n, o, i) {
1408
- const s = mt(n.signal, i);
1691
+ async function fe(e, t, n, r, o, i) {
1692
+ const s = Dt(r.signal, i);
1409
1693
  try {
1410
- const a = s.signal ? { ...n, signal: s.signal } : n, f = await e(t, a, o);
1411
- if (Ze(f)) {
1412
- const c = await Qe(f);
1413
- if (c.ok)
1414
- return { index: r, status: "fulfilled", chunks: c.chunks };
1415
- const u = c.carrier;
1694
+ const a = s.signal ? { ...r, signal: s.signal } : r, f = await e(t, a, o);
1695
+ if (vt(f)) {
1696
+ const u = await bt(f);
1697
+ if (u.ok)
1698
+ return { index: n, status: "fulfilled", chunks: u.chunks };
1699
+ const c = u.carrier;
1416
1700
  return {
1417
- index: r,
1701
+ index: n,
1418
1702
  status: "rejected",
1419
- reason: U(u.error),
1420
- ...u.phase === "after-first-chunk" ? { chunksDelivered: u.chunksDelivered } : {}
1703
+ reason: q(c.error),
1704
+ ...c.phase === "after-first-chunk" ? { chunksDelivered: c.chunksDelivered } : {}
1421
1705
  };
1422
1706
  }
1423
- return { index: r, status: "fulfilled", value: f };
1707
+ return { index: n, status: "fulfilled", value: f };
1424
1708
  } catch (a) {
1425
- return { index: r, status: "rejected", reason: U(a) };
1709
+ return { index: n, status: "rejected", reason: q(a) };
1426
1710
  } finally {
1427
1711
  s.dispose();
1428
1712
  }
1429
1713
  }
1430
- async function tr(e, t, r, n, o = {}) {
1431
- const i = o.mode ?? "parallel", s = o.onItemError ?? "continue", a = dt(i, o.concurrency), f = new Array(r.length), c = (l) => ({
1432
- index: l,
1714
+ async function On(e, t, n, r, o = {}) {
1715
+ const i = o.mode ?? "parallel", s = o.onItemError ?? "continue", a = Tt(i, o.concurrency), f = new Array(n.length), u = (d) => ({
1716
+ index: d,
1433
1717
  status: "rejected",
1434
- reason: U(
1718
+ reason: q(
1435
1719
  new Error(
1436
1720
  "apigen/invokeBatch: not attempted — an earlier item failed and " + (i === "chained" ? 'mode is "chained"' : 'onItemError is "abort"')
1437
1721
  )
1438
1722
  )
1439
1723
  });
1440
1724
  if (i === "serial" || i === "chained") {
1441
- let l = !1;
1442
- for (let y = 0; y < r.length; y++) {
1443
- if (l) {
1444
- f[y] = c(y);
1725
+ let d = !1;
1726
+ for (let m = 0; m < n.length; m++) {
1727
+ if (d) {
1728
+ f[m] = u(m);
1445
1729
  continue;
1446
1730
  }
1447
- const h = await ne(
1731
+ const h = await fe(
1448
1732
  e,
1449
1733
  t,
1450
- y,
1451
- r[y],
1452
- n,
1734
+ m,
1735
+ n[m],
1736
+ r,
1453
1737
  o.itemTimeoutMs
1454
1738
  );
1455
- f[y] = h, h.status === "rejected" && (i === "chained" || s === "abort") && (l = !0);
1739
+ f[m] = h, h.status === "rejected" && (i === "chained" || s === "abort") && (d = !0);
1456
1740
  }
1457
1741
  return f;
1458
1742
  }
1459
- let u = 0, p = !1;
1460
- const d = Math.max(1, Math.min(a, r.length)), m = Array.from({ length: d }, async () => {
1743
+ let c = 0, l = !1;
1744
+ const p = Math.max(1, Math.min(a, n.length)), y = Array.from({ length: p }, async () => {
1461
1745
  for (; ; ) {
1462
- const l = u++;
1463
- if (l >= r.length)
1746
+ const d = c++;
1747
+ if (d >= n.length)
1464
1748
  return;
1465
- if (p) {
1466
- f[l] = c(l);
1749
+ if (l) {
1750
+ f[d] = u(d);
1467
1751
  continue;
1468
1752
  }
1469
- const y = await ne(
1753
+ const m = await fe(
1470
1754
  e,
1471
1755
  t,
1472
- l,
1473
- r[l],
1474
- n,
1756
+ d,
1757
+ n[d],
1758
+ r,
1475
1759
  o.itemTimeoutMs
1476
1760
  );
1477
- f[l] = y, y.status === "rejected" && s === "abort" && (p = !0);
1761
+ f[d] = m, m.status === "rejected" && s === "abort" && (l = !0);
1478
1762
  }
1479
1763
  });
1480
- return await Promise.all(m), f;
1764
+ return await Promise.all(y), f;
1481
1765
  }
1482
- const oe = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
1483
- function ht(e) {
1766
+ he(import.meta.url);
1767
+ const le = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
1768
+ function Ut(e) {
1484
1769
  if (typeof e != "object" || e === null)
1485
1770
  return !1;
1486
1771
  const t = e;
1487
1772
  if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
1488
1773
  return !1;
1489
- const { type: r } = t;
1490
- return typeof r == "string" ? oe.has(r) : Array.isArray(r) ? r.every((n) => oe.has(n) || n === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((n) => ["string", "number", "boolean"].includes(typeof n)) : !1;
1774
+ const { type: n } = t;
1775
+ return typeof n == "string" ? le.has(n) : Array.isArray(n) ? n.every((r) => le.has(r) || r === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((r) => ["string", "number", "boolean"].includes(typeof r)) : !1;
1491
1776
  }
1492
- function gt(e) {
1777
+ function Rt(e) {
1493
1778
  if (!e || typeof e != "object")
1494
1779
  return !1;
1495
1780
  const t = e.properties;
1496
1781
  return t === void 0 || typeof t != "object" || t === null ? !1 : Object.values(t).every(
1497
- ht
1782
+ Ut
1498
1783
  );
1499
1784
  }
1500
- const wt = {
1785
+ const Lt = {
1501
1786
  "decimal.js": "Decimal"
1502
1787
  };
1503
- function bt(e) {
1788
+ function Bt(e) {
1504
1789
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1505
1790
  }
1506
- Object.entries(wt).map(([e, t]) => ({
1791
+ Object.entries(Lt).map(([e, t]) => ({
1507
1792
  // Matches: import("...{modSpec}...").<anyMemberName> (single or double quotes)
1508
1793
  // The module specifier appears inside an absolute path, so we allow any
1509
1794
  // characters between the quote and the specifier, and between the specifier
@@ -1511,136 +1796,137 @@ Object.entries(wt).map(([e, t]) => ({
1511
1796
  // …) is matched generically (`\w+`) rather than anchored to one spelling —
1512
1797
  // see the doc comment above for why.
1513
1798
  pattern: new RegExp(
1514
- `import\\(["'][^"']*${bt(e)}[^"']*["']\\)\\.\\w+`,
1799
+ `import\\(["'][^"']*${Bt(e)}[^"']*["']\\)\\.\\w+`,
1515
1800
  "g"
1516
1801
  ),
1517
1802
  key: t
1518
1803
  }));
1519
- function ie(e) {
1804
+ function pe(e) {
1520
1805
  return e.words.join("-");
1521
1806
  }
1522
- function se(e) {
1523
- return e.words.map(Ot).join("");
1807
+ function de(e) {
1808
+ return e.words.map(Kt).join("");
1524
1809
  }
1525
- function ae(e) {
1810
+ function ye(e) {
1526
1811
  return e.words.join("_");
1527
1812
  }
1528
- function vt(e, t = {}) {
1529
- var r, n;
1530
- const o = [e.namespace, ...e.path], i = e.safe || gt(e.input) ? "GET" : "POST", s = ((n = (r = t.http) == null ? void 0 : r.verb) == null ? void 0 : n[e.id]) ?? i, a = "/" + o.map((m) => ie(m)).join("/"), f = o.map((m) => ae(m)).join("_"), c = o.map((m) => ae(m)).slice(0, -1).join("."), u = se(o[o.length - 2] ?? o[0]), p = se(o[o.length - 1]), d = o.map((m) => ie(m));
1813
+ function qt(e, t = {}) {
1814
+ var n, r;
1815
+ const o = [e.namespace, ...e.path], i = e.safe || Rt(e.input) ? "GET" : "POST", s = ((r = (n = t.http) == null ? void 0 : n.verb) == null ? void 0 : r[e.id]) ?? i, a = "/" + o.map((y) => pe(y)).join("/"), f = o.map((y) => ye(y)).join("_"), u = o.map((y) => ye(y)).slice(0, -1).join("."), c = de(o[o.length - 2] ?? o[0]), l = de(o[o.length - 1]), p = o.map((y) => pe(y));
1531
1816
  return {
1532
1817
  http: { verb: s, route: a },
1533
1818
  mcp: { name: f },
1534
- grpc: { package: c, service: u, method: p },
1535
- cli: { path: d }
1819
+ grpc: { package: u, service: c, method: l },
1820
+ cli: { path: p }
1536
1821
  };
1537
1822
  }
1538
- function $t(e, t) {
1823
+ function Ft(e, t) {
1539
1824
  return `x-${e}-${t}`;
1540
1825
  }
1541
- function jt(e, t) {
1826
+ function Vt(e, t) {
1542
1827
  return `--${e}-${t}`;
1543
1828
  }
1544
- function Nt(e, t) {
1545
- const r = (n) => n.toUpperCase().replace(/-/g, "_");
1546
- return e === "adhd" ? `APIGEN_${r(t)}` : `APIGEN_${r(e)}_${r(t)}`;
1829
+ function Ht(e, t) {
1830
+ const n = (r) => r.toUpperCase().replace(/-/g, "_");
1831
+ return e === "adhd" ? `APIGEN_${n(t)}` : `APIGEN_${n(e)}_${n(t)}`;
1547
1832
  }
1548
- function Ot(e) {
1833
+ function Kt(e) {
1549
1834
  return e.length === 0 ? e : e[0].toUpperCase() + e.slice(1);
1550
1835
  }
1551
- function V(e) {
1836
+ function Y(e) {
1552
1837
  return e.anyOf ?? e.oneOf;
1553
1838
  }
1554
- function At(e) {
1839
+ function zt(e) {
1555
1840
  if (!e)
1556
1841
  return !1;
1557
1842
  if (e.type === "array" || e.type === "object")
1558
1843
  return !0;
1559
- const t = V(e);
1844
+ const t = Y(e);
1560
1845
  if (t) {
1561
- const r = t.filter((n) => n.type !== "null");
1562
- return r.length > 0 && r.every((n) => n.type === "array" || n.type === "object");
1846
+ const n = t.filter((r) => r.type !== "null");
1847
+ return n.length > 0 && n.every((r) => r.type === "array" || r.type === "object");
1563
1848
  }
1564
1849
  return !1;
1565
1850
  }
1566
- function _t(e) {
1851
+ function Jt(e) {
1567
1852
  if (!e)
1568
1853
  return !1;
1569
1854
  if (e.type === "boolean")
1570
1855
  return !0;
1571
- const t = V(e);
1856
+ const t = Y(e);
1572
1857
  if (t) {
1573
- const r = t.filter((n) => n.type !== "null");
1574
- return r.length > 0 && r.every((n) => n.type === "boolean");
1858
+ const n = t.filter((r) => r.type !== "null");
1859
+ return n.length > 0 && n.every((r) => r.type === "boolean");
1575
1860
  }
1576
1861
  return !1;
1577
1862
  }
1578
- function Et(e) {
1863
+ function Wt(e) {
1579
1864
  if (!e)
1580
1865
  return !1;
1581
1866
  if (e.type === "number" || e.type === "integer")
1582
1867
  return !0;
1583
- const t = V(e);
1868
+ const t = Y(e);
1584
1869
  if (t) {
1585
- const r = t.filter((n) => n.type !== "null");
1586
- return r.length > 0 && r.every((n) => n.type === "number" || n.type === "integer");
1870
+ const n = t.filter((r) => r.type !== "null");
1871
+ return n.length > 0 && n.every((r) => r.type === "number" || r.type === "integer");
1587
1872
  }
1588
1873
  return !1;
1589
1874
  }
1590
- function kt(e) {
1875
+ function Gt(e) {
1591
1876
  return e.replace(/[A-Z]/g, (t) => "-" + t.toLowerCase());
1592
1877
  }
1593
- function It(e) {
1878
+ function Yt(e) {
1594
1879
  var o, i;
1595
- const t = (i = (o = e.input) == null ? void 0 : o.properties) == null ? void 0 : i.data, r = (t == null ? void 0 : t.properties) ?? {}, n = (t == null ? void 0 : t.required) ?? [];
1596
- return { props: r, required: n };
1880
+ const t = (i = (o = e.input) == null ? void 0 : o.properties) == null ? void 0 : i.data, n = (t == null ? void 0 : t.properties) ?? {}, r = (t == null ? void 0 : t.required) ?? [];
1881
+ return { props: n, required: r };
1597
1882
  }
1598
- function ce(e) {
1883
+ function me(e) {
1599
1884
  return typeof e.handler == "function";
1600
1885
  }
1601
- function Ct(e) {
1886
+ function Zt(e) {
1602
1887
  var o;
1603
- const t = ((o = e.input) == null ? void 0 : o.properties) ?? {}, r = e["x-apigen-envelope"], n = [];
1888
+ const t = ((o = e.input) == null ? void 0 : o.properties) ?? {}, n = e["x-apigen-envelope"], r = [];
1604
1889
  for (const i of Object.keys(t)) {
1605
1890
  if (i === "data")
1606
1891
  continue;
1607
- const s = (r == null ? void 0 : r[i]) ?? "adhd", a = $t(s, i);
1608
- n.push({
1892
+ const s = (n == null ? void 0 : n[i]) ?? "adhd", a = Ft(s, i);
1893
+ r.push({
1609
1894
  field: i,
1610
1895
  pluginId: s,
1611
1896
  httpHeader: a,
1612
1897
  mcpMetaKey: a,
1613
- cliFlag: jt(s, i),
1614
- envVar: Nt(s, i)
1898
+ cliFlag: Vt(s, i),
1899
+ envVar: Ht(s, i)
1615
1900
  });
1616
1901
  }
1617
- return n;
1902
+ return r;
1618
1903
  }
1619
- function St(e, t) {
1620
- const r = /* @__PURE__ */ new Map(), { props: n } = It(e);
1621
- for (const [o, i] of Object.entries(n)) {
1904
+ function Qt(e, t, n, r) {
1905
+ t === n || e.has(t) || e.set(t, { ...r, aliasOf: n });
1906
+ }
1907
+ function Xt(e, t) {
1908
+ const n = /* @__PURE__ */ new Map(), { props: r } = Yt(e);
1909
+ for (const [o, i] of Object.entries(r)) {
1622
1910
  let s = "string";
1623
- _t(i) ? s = "boolean" : (At(i) || Et(i)) && (s = "json"), r.set(kt(o), {
1624
- camelKey: o,
1625
- kind: "domain",
1626
- valueKind: s
1627
- });
1911
+ Jt(i) ? s = "boolean" : (zt(i) || Wt(i)) && (s = "json");
1912
+ const a = Gt(o), f = { camelKey: o, kind: "domain", valueKind: s };
1913
+ n.set(a, f), Qt(n, o, a, f);
1628
1914
  }
1629
1915
  for (const o of t) {
1630
- const i = o.cliFlag.replace(/^--/, "");
1631
- r.set(i, {
1916
+ const i = o.cliFlag.replace(/^--/, ""), s = {
1632
1917
  camelKey: o.field,
1633
1918
  kind: "envelope",
1634
1919
  valueKind: "string",
1635
1920
  envVar: o.envVar
1636
- });
1921
+ };
1922
+ n.set(i, s);
1637
1923
  }
1638
- return r;
1924
+ return n;
1639
1925
  }
1640
- function rr(e) {
1641
- const { op: t, schema: r, transport: n, projection: o } = e, i = vt(t, o), s = r ? Ct(r) : [], a = r ? St(r, s) : /* @__PURE__ */ new Map(), f = r ? Ve(r).params : void 0, c = {
1926
+ function Nn(e) {
1927
+ const { op: t, schema: n, transport: r, projection: o } = e, i = qt(t, o), s = n ? Zt(n) : [], a = n ? Xt(n, s) : /* @__PURE__ */ new Map(), f = n ? pt(n).params : void 0, u = {
1642
1928
  op: t,
1643
- transport: n,
1929
+ transport: r,
1644
1930
  http: i.http,
1645
1931
  mcp: i.mcp,
1646
1932
  cli: i.cli,
@@ -1649,58 +1935,62 @@ function rr(e) {
1649
1935
  envelope: s,
1650
1936
  cliFlags: a,
1651
1937
  streaming: t.streaming,
1652
- isMount: ce(t)
1938
+ isMount: me(t)
1653
1939
  };
1654
- if (ce(t)) {
1655
- const u = t.handler;
1656
- c.mountHandler = async (p) => u(p);
1940
+ if (me(t)) {
1941
+ const c = t.handler;
1942
+ u.mountHandler = async (l) => c(l);
1657
1943
  }
1658
- return c;
1944
+ return u;
1659
1945
  }
1660
- function nr(e) {
1946
+ function En(e) {
1661
1947
  const t = e.usePlugins;
1662
1948
  return Array.isArray(t) ? t : [];
1663
1949
  }
1664
- function or(e) {
1950
+ function _n(e) {
1951
+ const t = e.exitCode;
1952
+ return typeof t == "function" ? t : void 0;
1953
+ }
1954
+ function kn(e) {
1665
1955
  const t = e.useOptions;
1666
1956
  return t && typeof t == "object" ? t : {};
1667
1957
  }
1668
- function xt(e) {
1669
- return async function(r, n) {
1670
- const o = Object.assign(r, { data: r.domainArgs });
1671
- return await e.layer(o, n);
1958
+ function en(e) {
1959
+ return async function(n, r) {
1960
+ const o = Object.assign(n, { data: n.domainArgs });
1961
+ return await e.layer(o, r);
1672
1962
  };
1673
1963
  }
1674
- function ir(e, t) {
1675
- var n;
1676
- const r = [];
1964
+ function In(e, t) {
1965
+ var r;
1966
+ const n = [];
1677
1967
  for (const o of t) {
1678
- const i = (n = o.capabilities) == null ? void 0 : n.layer;
1679
- i && r.push(xt(i));
1968
+ const i = (r = o.capabilities) == null ? void 0 : r.layer;
1969
+ i && n.push(en(i));
1680
1970
  }
1681
- return r.push(Ye(e)), Me(r);
1971
+ return n.push(gt(e)), Ge(n);
1682
1972
  }
1683
- function Mt() {
1973
+ function tn() {
1684
1974
  const e = /* @__PURE__ */ new Map();
1685
1975
  return {
1686
1976
  get: (t) => e.get(t),
1687
- set: (t, r) => {
1688
- e.set(t, r);
1977
+ set: (t, n) => {
1978
+ e.set(t, n);
1689
1979
  }
1690
1980
  };
1691
1981
  }
1692
- const Tt = {
1982
+ const nn = {
1693
1983
  input: {
1694
1984
  type: "object",
1695
1985
  properties: { data: { type: "object", properties: {} } }
1696
1986
  },
1697
1987
  output: {}
1698
1988
  };
1699
- async function sr(e, t, r, n) {
1989
+ async function Cn(e, t, n, r) {
1700
1990
  const o = {
1701
- ...r,
1991
+ ...n,
1702
1992
  operation: { id: e.op.id },
1703
- ctx: new xe()
1993
+ ctx: new We()
1704
1994
  };
1705
1995
  if (e.isMount) {
1706
1996
  const i = e.mountHandler;
@@ -1710,58 +2000,59 @@ async function sr(e, t, r, n) {
1710
2000
  );
1711
2001
  const s = {
1712
2002
  operation: e.op,
1713
- data: r.domainArgs,
1714
- envelope: r.envelope,
1715
- ctx: Mt(),
2003
+ data: n.domainArgs,
2004
+ envelope: n.envelope,
2005
+ ctx: tn(),
1716
2006
  transport: e.transport,
1717
- signal: r.signal ?? new AbortController().signal
2007
+ signal: n.signal ?? new AbortController().signal
1718
2008
  }, a = {
1719
- ...n,
2009
+ ...r,
1720
2010
  fns: { [e.op.id]: () => i(s) },
1721
- schemas: { [e.op.id]: Tt }
2011
+ schemas: { [e.op.id]: nn }
1722
2012
  };
1723
2013
  return t(e.op.id, o, a);
1724
2014
  }
1725
- return t(e.op.id, o, n);
2015
+ return t(e.op.id, o, r);
1726
2016
  }
1727
2017
  export {
1728
- pt as BATCH_DEFAULT_CONCURRENCY,
1729
- lt as BATCH_MAX_CONCURRENCY,
1730
- Te as EventBus,
1731
- Gt as InstanceRegistry,
1732
- xe as LayerContext,
2018
+ St as BATCH_DEFAULT_CONCURRENCY,
2019
+ Mt as BATCH_MAX_CONCURRENCY,
2020
+ Ye as EventBus,
2021
+ gn as InstanceRegistry,
2022
+ We as LayerContext,
1733
2023
  g as UnionCodecError,
1734
- Je as ValidateSchemasToken,
1735
- at as WELL_KNOWN_TS_CODECS,
1736
- xt as adaptCoreLayer,
1737
- ze as assertNoSelfSubscription,
1738
- Ue as buildContext,
1739
- Vt as buildFnTable,
1740
- Zt as buildMcpOutputSchema,
1741
- rr as buildOpPlan,
1742
- Qt as buildToolDescription,
1743
- zt as coerceQueryParams,
1744
- Qe as collectWithPhase,
1745
- Ht as createApiPackage,
1746
- Me as createInvoker,
1747
- qt as createLogger,
1748
- ir as createPackageInvoker,
1749
- Jt as createStream,
1750
- rt as createUnionCodec,
1751
- ke as dataParamNames,
1752
- Kt as defineMiddleware,
1753
- Ve as describeParams,
1754
- Se as dispatch,
1755
- sr as dispatchForPlan,
1756
- Yt as drainStream,
1757
- tr as invokeBatch,
1758
- Ze as isApiStream,
1759
- Ye as makeValidateLayer,
1760
- Ee as needsEnvelopeField,
1761
- or as readUseOptions,
1762
- nr as readUsePlugins,
1763
- Xt as tsHostBinding,
1764
- Wt as validateLayer,
1765
- De as wireObservers,
1766
- er as wrapMcpStructuredContent
2024
+ ht as ValidateSchemasToken,
2025
+ kt as WELL_KNOWN_TS_CODECS,
2026
+ en as adaptCoreLayer,
2027
+ at as assertNoSelfSubscription,
2028
+ Xe as buildContext,
2029
+ mn as buildFnTable,
2030
+ An as buildMcpOutputSchema,
2031
+ Nn as buildOpPlan,
2032
+ $n as buildToolDescription,
2033
+ yn as coerceQueryParams,
2034
+ bt as collectWithPhase,
2035
+ pn as createApiPackage,
2036
+ Ge as createInvoker,
2037
+ dn as createLogger,
2038
+ In as createPackageInvoker,
2039
+ wn as createStream,
2040
+ jt as createUnionCodec,
2041
+ He as dataParamNames,
2042
+ ln as defineMiddleware,
2043
+ pt as describeParams,
2044
+ Je as dispatch,
2045
+ Cn as dispatchForPlan,
2046
+ bn as drainStream,
2047
+ On as invokeBatch,
2048
+ vt as isApiStream,
2049
+ gt as makeValidateLayer,
2050
+ Ve as needsEnvelopeField,
2051
+ _n as readExitCodeHook,
2052
+ kn as readUseOptions,
2053
+ En as readUsePlugins,
2054
+ vn as tsHostBinding,
2055
+ hn as validateLayer,
2056
+ Qe as wireObservers,
2057
+ jn as wrapMcpStructuredContent
1767
2058
  };