@adhd/apigen-engine-runtime 0.1.1 → 0.1.3

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