@adhd/apigen-engine-runtime 0.2.0 → 0.2.1

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