@adhd/apigen-core-client 0.2.2 → 0.3.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
@@ -1,277 +1,306 @@
1
- import { Project as te, Scope as L } from "ts-morph";
2
- import Ne from "node:fs";
3
- import * as Oe from "node:path";
4
- import Y from "node:path";
5
- import { createParser as ke, createFormatter as Ee, SchemaGenerator as Ce, AnnotatedType as ne, StringType as re } from "ts-json-schema-generator";
6
- function oe(e) {
1
+ import De from "node:fs";
2
+ import { createRequire as qe } from "node:module";
3
+ import * as Be from "node:path";
4
+ import ce from "node:path";
5
+ function ge(e) {
7
6
  return {
8
7
  raw: e,
9
8
  words: e.split(/(?=[A-Z])|[-_]/).map((t) => t.toLowerCase()).filter(Boolean)
10
9
  };
11
10
  }
12
- function Ie(e, t, n = {}) {
11
+ function We(e, t, r = {}) {
13
12
  const o = e.split("/");
14
- if (o.length < 2 || o.some((l) => l.length === 0))
13
+ if (o.length < 2 || o.some((u) => u.length === 0))
15
14
  throw new Error(
16
15
  `syntheticOp: id "${e}" must be "<namespace>/<path...>" with non-empty segments`
17
16
  );
18
- const [r, ...i] = o, s = r.replace(/^_+/, ""), a = n.kind ?? "action", c = {
17
+ const [n, ...i] = o, s = n.replace(/^_+/, ""), a = r.kind ?? "action", c = {
19
18
  id: e,
20
19
  host: t.host,
21
- namespace: oe(s),
22
- path: i.map(oe),
20
+ namespace: ge(s),
21
+ path: i.map(ge),
23
22
  kind: a,
24
- async: n.async ?? !1,
25
- streaming: n.streaming ?? !1,
26
- safe: n.safe ?? a === "query",
27
- input: n.input ?? {},
28
- output: n.output ?? {},
29
- envelope: n.envelope ?? {},
30
- typeText: n.typeText ?? null
23
+ async: r.async ?? !1,
24
+ streaming: r.streaming ?? !1,
25
+ safe: r.safe ?? a === "query",
26
+ input: r.input ?? {},
27
+ output: r.output ?? {},
28
+ envelope: r.envelope ?? {},
29
+ typeText: r.typeText ?? null
31
30
  };
32
- return n.hasCtx !== void 0 && (c.hasCtx = n.hasCtx), n.transports !== void 0 && (c.transports = n.transports), c;
31
+ return r.hasCtx !== void 0 && (c.hasCtx = r.hasCtx), r.transports !== void 0 && (c.transports = r.transports), c;
33
32
  }
34
- const ge = Symbol.for("adhd.apigen.extraction-session");
35
- function de(e, t) {
36
- const n = [
33
+ const N = qe(import.meta.url);
34
+ let z;
35
+ function Ne() {
36
+ return z || (z = N("ts-morph").Project, z);
37
+ }
38
+ const Oe = Symbol.for("adhd.apigen.extraction-session");
39
+ function ue(e, t) {
40
+ const r = [
37
41
  ...e.getImportDeclarations().map((o) => o.getModuleSpecifierSourceFile()),
38
42
  ...e.getExportDeclarations().map((o) => o.getModuleSpecifierSourceFile())
39
43
  ];
40
- for (const o of n) {
44
+ for (const o of r) {
41
45
  if (!o)
42
46
  continue;
43
- const r = o.getFilePath();
44
- if (!r.includes("/node_modules/") && !t.has(r)) {
45
- t.add(r);
47
+ const n = o.getFilePath();
48
+ if (!n.includes("/node_modules/") && !t.has(n)) {
49
+ t.add(n);
46
50
  try {
47
51
  o.refreshFromFileSystemSync();
48
52
  } catch {
49
53
  }
50
- de(o, t);
54
+ ue(o, t);
51
55
  }
52
56
  }
53
57
  }
54
- function ye(e) {
58
+ function ke(e) {
55
59
  try {
56
- const t = Ne.statSync(e);
60
+ const t = De.statSync(e);
57
61
  return `${t.mtimeMs}:${t.size}`;
58
62
  } catch {
59
63
  return "nostat";
60
64
  }
61
65
  }
62
- const F = /* @__PURE__ */ new Map(), Z = /* @__PURE__ */ new Map();
63
- function Fe(e, t, n) {
64
- const o = t ?? "", r = F.get(o);
65
- let i = n;
66
- if (r && r.fileVersions.size > 0) {
67
- const c = [n], l = [...r.fileVersions.entries()].sort(
68
- ([u], [f]) => u.localeCompare(f)
66
+ const M = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map();
67
+ function Ue(e, t, r) {
68
+ const o = t ?? "", n = M.get(o);
69
+ let i = r;
70
+ if (n && n.fileVersions.size > 0) {
71
+ const c = [r], u = [...n.fileVersions.entries()].sort(
72
+ ([l], [f]) => l.localeCompare(f)
69
73
  );
70
- for (const [u, f] of l)
71
- u !== e && c.push(`${u}:${f}`);
74
+ for (const [l, f] of u)
75
+ l !== e && c.push(`${l}:${f}`);
72
76
  i = c.join("|");
73
77
  }
74
78
  const s = `${e}\0${t ?? ""}`;
75
- let a = Z.get(s);
76
- return (!a || a.version !== i) && (a = { version: i, schemas: /* @__PURE__ */ new Map() }, Z.set(s, a)), a.schemas;
79
+ let a = ne.get(s);
80
+ return (!a || a.version !== i) && (a = { version: i, schemas: /* @__PURE__ */ new Map() }, ne.set(s, a)), a.schemas;
81
+ }
82
+ function Qt() {
83
+ M.clear(), ne.clear(), G = void 0;
84
+ }
85
+ let G;
86
+ function Ge() {
87
+ if (!G) {
88
+ const e = Ne();
89
+ G = new e({
90
+ skipAddingFilesFromTsConfig: !0,
91
+ compilerOptions: { noLib: !0 }
92
+ });
93
+ }
94
+ return G;
77
95
  }
78
- function Ft() {
79
- F.clear(), Z.clear();
96
+ function Xt(e) {
97
+ const t = Ge(), r = t.getSourceFile(e), o = r ?? t.addSourceFileAtPath(e);
98
+ if (r)
99
+ try {
100
+ r.refreshFromFileSystemSync();
101
+ } catch {
102
+ }
103
+ const n = /* @__PURE__ */ new Set([e]);
104
+ return ue(o, n), [...n].sort();
80
105
  }
81
- function he() {
106
+ function Ee() {
82
107
  const e = {
83
108
  projectsBuilt: 0,
84
109
  generatorsBuilt: 0,
85
110
  schemaCacheHits: 0,
86
111
  schemaCacheMisses: 0
87
112
  }, t = /* @__PURE__ */ new Map();
88
- let n = !1;
113
+ let r = !1;
89
114
  return {
90
- [ge]: !0,
115
+ [Oe]: !0,
91
116
  stats: e,
92
117
  schemaCache: /* @__PURE__ */ new Map(),
93
118
  aliasCache: /* @__PURE__ */ new WeakMap(),
94
119
  zodImportCache: /* @__PURE__ */ new WeakMap(),
95
120
  generatorCache: /* @__PURE__ */ new Map(),
96
- projectFor(r) {
97
- if (n)
121
+ projectFor(n) {
122
+ if (r)
98
123
  throw new Error("apigen-core: ExtractionSession used after dispose()");
99
- const i = r ?? "", s = r ? this.statVersion(r) : "";
100
- let a = F.get(i);
101
- return a && a.tsconfigVersion !== s && (a = void 0), a || (a = { project: r ? new te({
102
- tsConfigFilePath: r,
103
- skipAddingFilesFromTsConfig: !0
104
- }) : new te({ skipAddingFilesFromTsConfig: !0 }), tsconfigVersion: s, fileVersions: /* @__PURE__ */ new Map() }, F.set(i, a), e.projectsBuilt++), a.project;
124
+ const i = n ?? "", s = n ? this.statVersion(n) : "";
125
+ let a = M.get(i);
126
+ if (a && a.tsconfigVersion !== s && (a = void 0), !a) {
127
+ const c = Ne();
128
+ a = { project: n ? new c({
129
+ tsConfigFilePath: n,
130
+ skipAddingFilesFromTsConfig: !0
131
+ }) : new c({ skipAddingFilesFromTsConfig: !0 }), tsconfigVersion: s, fileVersions: /* @__PURE__ */ new Map() }, M.set(i, a), e.projectsBuilt++;
132
+ }
133
+ return a.project;
105
134
  },
106
- sourceFileFor(r, i) {
107
- const s = this.projectFor(i), a = F.get(i ?? ""), c = this.statVersion(r);
108
- let l = s.getSourceFile(r);
109
- if (l === void 0 ? l = s.addSourceFileAtPath(r) : a && a.fileVersions.get(r) !== c && l.refreshFromFileSystemSync(), a == null || a.fileVersions.set(r, c), a) {
110
- const u = /* @__PURE__ */ new Set([r]);
111
- de(l, u);
112
- for (const f of u)
113
- f !== r && a.fileVersions.set(f, this.statVersion(f));
135
+ sourceFileFor(n, i) {
136
+ const s = this.projectFor(i), a = M.get(i ?? ""), c = this.statVersion(n);
137
+ let u = s.getSourceFile(n);
138
+ if (u === void 0 ? u = s.addSourceFileAtPath(n) : a && a.fileVersions.get(n) !== c && u.refreshFromFileSystemSync(), a == null || a.fileVersions.set(n, c), a) {
139
+ const l = /* @__PURE__ */ new Set([n]);
140
+ ue(u, l);
141
+ for (const f of l)
142
+ f !== n && a.fileVersions.set(f, this.statVersion(f));
114
143
  }
115
- return l;
144
+ return u;
116
145
  },
117
- statVersion(r) {
118
- let i = t.get(r);
119
- return i === void 0 && (i = ye(r), t.set(r, i)), i;
146
+ statVersion(n) {
147
+ let i = t.get(n);
148
+ return i === void 0 && (i = ke(n), t.set(n, i)), i;
120
149
  },
121
150
  dispose() {
122
- n = !0, this.schemaCache.clear(), this.generatorCache.clear(), t.clear();
151
+ r = !0, this.schemaCache.clear(), this.generatorCache.clear(), t.clear();
123
152
  }
124
153
  };
125
154
  }
126
- function Te(e) {
155
+ function Ie(e) {
127
156
  const t = e;
128
- if (t[ge] !== !0)
157
+ if (t[Oe] !== !0)
129
158
  throw new Error(
130
159
  "apigen-core: unknown ExtractionSession implementation — create sessions with createExtractionSession()"
131
160
  );
132
161
  return t;
133
162
  }
134
- const K = "x-apigen-logical";
135
- function ie(e, t) {
136
- const n = /* @__PURE__ */ new Set(), o = [e];
163
+ const Z = "x-apigen-logical";
164
+ function ye(e, t) {
165
+ const r = /* @__PURE__ */ new Set(), o = [e];
137
166
  for (; o.length > 0; ) {
138
- const r = o.pop();
139
- if (!r || n.has(r))
167
+ const n = o.pop();
168
+ if (!n || r.has(n))
140
169
  continue;
141
- n.add(r);
142
- const i = r.$ref;
170
+ r.add(n);
171
+ const i = n.$ref;
143
172
  if (typeof i == "string") {
144
173
  if (t) {
145
174
  const f = t[i];
146
175
  if (!f) {
147
- const p = Object.keys(t).join(", ") || "(none)";
176
+ const m = Object.keys(t).join(", ") || "(none)";
148
177
  throw new Error(
149
- `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${p}`
178
+ `[apigen-logical] $ref "${i}" cannot be resolved. Available $defs: ${m}`
150
179
  );
151
180
  }
152
181
  o.push(f);
153
182
  }
154
183
  continue;
155
184
  }
156
- const s = r.oneOf;
185
+ const s = n.oneOf;
157
186
  if (Array.isArray(s))
158
187
  for (const f of s)
159
188
  typeof f == "object" && f !== null && o.push(f);
160
- const a = r.properties;
189
+ const a = n.properties;
161
190
  if (a)
162
191
  for (const f of Object.values(a))
163
192
  o.push(f);
164
- const c = r.items;
193
+ const c = n.items;
165
194
  if (Array.isArray(c))
166
195
  for (const f of c)
167
196
  typeof f == "object" && f !== null && o.push(f);
168
197
  else
169
198
  typeof c == "object" && c !== null && o.push(c);
170
- const l = r.additionalProperties;
171
- typeof l == "object" && l !== null && o.push(l);
172
- const u = r.propertyNames;
199
+ const u = n.additionalProperties;
173
200
  typeof u == "object" && u !== null && o.push(u);
201
+ const l = n.propertyNames;
202
+ typeof l == "object" && l !== null && o.push(l);
174
203
  }
175
204
  }
176
- const se = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
177
- function Re(e) {
205
+ const he = /* @__PURE__ */ new Set(["string", "number", "boolean", "integer"]);
206
+ function He(e) {
178
207
  if (typeof e != "object" || e === null)
179
208
  return !1;
180
209
  const t = e;
181
210
  if (t.$ref !== void 0 || t.oneOf || t.anyOf || t.allOf)
182
211
  return !1;
183
- const { type: n } = t;
184
- return typeof n == "string" ? se.has(n) : Array.isArray(n) ? n.every((o) => se.has(o) || o === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((o) => ["string", "number", "boolean"].includes(typeof o)) : !1;
212
+ const { type: r } = t;
213
+ return typeof r == "string" ? he.has(r) : Array.isArray(r) ? r.every((o) => he.has(o) || o === "null") : Array.isArray(t.enum) && t.enum.length > 0 ? t.enum.every((o) => ["string", "number", "boolean"].includes(typeof o)) : !1;
185
214
  }
186
- function _e(e) {
215
+ function Je(e) {
187
216
  if (!e || typeof e != "object")
188
217
  return !1;
189
218
  const t = e.properties;
190
219
  return t === void 0 || typeof t != "object" || t === null ? !1 : Object.values(t).every(
191
- Re
220
+ He
192
221
  );
193
222
  }
194
- function Rt(e) {
195
- var n, o;
223
+ function Yt(e) {
224
+ var r, o;
196
225
  const t = [];
197
- for (const r of e) {
226
+ for (const n of e) {
198
227
  const i = {
199
- ...(n = r.capabilities.layer) == null ? void 0 : n.envelopeFields,
200
- ...(o = r.capabilities.envelope) == null ? void 0 : o.request
228
+ ...(r = n.capabilities.layer) == null ? void 0 : r.envelopeFields,
229
+ ...(o = n.capabilities.envelope) == null ? void 0 : o.request
201
230
  };
202
- Object.keys(i).length > 0 && t.push({ id: r.id, envelope: i });
231
+ Object.keys(i).length > 0 && t.push({ id: n.id, envelope: i });
203
232
  }
204
233
  return t;
205
234
  }
206
- function Le(e) {
207
- const t = {}, n = (o) => {
208
- for (const r of ["definitions", "$defs"]) {
209
- const i = o[r];
235
+ function Ze(e) {
236
+ const t = {}, r = (o) => {
237
+ for (const n of ["definitions", "$defs"]) {
238
+ const i = o[n];
210
239
  if (i)
211
240
  for (const [s, a] of Object.entries(i)) {
212
- const c = s.startsWith("#/") ? s : `#/${r}/${s}`;
241
+ const c = s.startsWith("#/") ? s : `#/${n}/${s}`;
213
242
  t[c] = a;
214
243
  }
215
244
  }
216
245
  };
217
246
  for (const o of Object.values(e.schemas))
218
- n(o.input), n(o.output);
247
+ r(o.input), r(o.output);
219
248
  if (Object.keys(t).length !== 0)
220
- for (const [o, r] of Object.entries(e.schemas))
249
+ for (const [o, n] of Object.entries(e.schemas))
221
250
  try {
222
- ie(r.input, t), ie(r.output, t);
251
+ ye(n.input, t), ye(n.output, t);
223
252
  } catch (i) {
224
253
  throw new Error(
225
254
  `[apigen-core-client] Schema validation failed for function "${o}": ${i.message}`
226
255
  );
227
256
  }
228
257
  }
229
- function Me(e, t) {
230
- const n = [
258
+ function Qe(e, t) {
259
+ const r = [
231
260
  'apigen calling convention: all domain parameters go inside a "data" envelope — e.g. { "data": { ... } }' + (t ? "." : " (an empty object for this zero-parameter tool).")
232
261
  ];
233
- return e.length > 0 && n.push(
262
+ return e.length > 0 && r.push(
234
263
  `Field(s) ${e.map((o) => `"${o}"`).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.`
235
- ), n.join(" ");
264
+ ), r.join(" ");
236
265
  }
237
- function _t(e, t, n) {
238
- Le(e);
266
+ function en(e, t, r) {
267
+ Ze(e);
239
268
  const o = {};
240
- for (const [r, i] of Object.entries(e.schemas)) {
241
- const s = (n == null ? void 0 : n[r]) ?? {}, a = i.input.properties ?? {}, c = i.input.required ?? [], l = {}, u = [], f = {};
242
- for (const b of t)
243
- if (b.envelope && s[b.id] !== !1)
244
- for (const [y, h] of Object.entries(b.envelope))
245
- l[y] = h, f[y] = b.id, u.includes(y) || u.push(y);
246
- const p = {
269
+ for (const [n, i] of Object.entries(e.schemas)) {
270
+ const s = (r == null ? void 0 : r[n]) ?? {}, a = i.input.properties ?? {}, c = i.input.required ?? [], u = {}, l = [], f = {};
271
+ for (const g of t)
272
+ if (g.envelope && s[g.id] !== !1)
273
+ for (const [x, p] of Object.entries(g.envelope))
274
+ u[x] = p, f[x] = g.id, l.includes(x) || l.push(x);
275
+ const m = {
247
276
  type: "object",
248
277
  properties: a,
249
278
  additionalProperties: !1,
250
279
  ...c.length > 0 ? { required: c } : {}
251
- }, T = i.safe === !0 || _e(i.input), d = i.input.definitions, m = i.input.$defs;
252
- o[r] = {
280
+ }, h = i.safe === !0 || Je(i.input), y = i.input.definitions, d = i.input.$defs;
281
+ o[n] = {
253
282
  input: {
254
283
  type: "object",
255
- properties: { ...l, data: p },
284
+ properties: { ...u, data: m },
256
285
  required: [
257
- ...u,
286
+ ...l,
258
287
  ...c.length > 0 ? ["data"] : []
259
288
  ],
260
289
  // BUG-APIGEN-017: reject any property that isn't a declared envelope
261
290
  // field or the "data" wrapper — no silently-ignored junk params.
262
291
  additionalProperties: !1,
263
292
  // BUG-APIGEN-020: document the envelope/data calling convention inline.
264
- description: Me(
265
- Object.keys(l),
293
+ description: Qe(
294
+ Object.keys(u),
266
295
  Object.keys(a).length > 0
267
296
  ),
268
- ...d ? { definitions: d } : {},
269
- ...m ? { $defs: m } : {}
297
+ ...y ? { definitions: y } : {},
298
+ ...d ? { $defs: d } : {}
270
299
  },
271
300
  output: i.output,
272
301
  // Carry the ctx-param flag through to dispatch (BUG-APIGEN-001).
273
302
  ...i.hasCtx ? { hasCtx: !0 } : {},
274
- "x-apigen-safe": T,
303
+ "x-apigen-safe": h,
275
304
  // DEBT-APIGEN-ENVELOPE-CAPABILITY-UNWIRED-001: field → pluginId map,
276
305
  // read by `op-plan.ts`'s `computeEnvelopeFields`. Omitted (not an empty
277
306
  // object) when no middleware contributed an envelope field, matching
@@ -281,8 +310,8 @@ function _t(e, t, n) {
281
310
  }
282
311
  return o;
283
312
  }
284
- const Ve = 8;
285
- function qe(e, t) {
313
+ const Xe = 8;
314
+ function Ye(e, t) {
286
315
  try {
287
316
  return t ? e.getText(t) : e.getText();
288
317
  } catch {
@@ -293,12 +322,12 @@ function qe(e, t) {
293
322
  }
294
323
  }
295
324
  }
296
- let ze = 0;
297
- async function Ke(e, t, n, o) {
298
- const r = `__ApigenProbe_${process.pid}_${ze++}`;
325
+ let et = 0;
326
+ async function tt(e, t, r, o) {
327
+ const n = `__ApigenProbe_${process.pid}_${et++}`;
299
328
  let i;
300
329
  try {
301
- i = t.addTypeAlias({ name: r, type: n });
330
+ i = t.addTypeAlias({ name: n, type: r });
302
331
  const s = i.getType();
303
332
  return await o(s);
304
333
  } catch {
@@ -310,8 +339,8 @@ async function Ke(e, t, n, o) {
310
339
  }
311
340
  }
312
341
  }
313
- async function be(e, t, n) {
314
- if (n > Ve)
342
+ async function Fe(e, t, r) {
343
+ if (r > Xe)
315
344
  return {};
316
345
  if (e.isString() || e.isStringLiteral())
317
346
  return e.isStringLiteral() ? { type: "string", enum: [e.getLiteralValue()] } : { type: "string" };
@@ -336,12 +365,12 @@ async function be(e, t, n) {
336
365
  enum: o.map((c) => c.getLiteralValue())
337
366
  };
338
367
  const s = await Promise.all(
339
- o.map((c) => be(c, t, n + 1))
340
- ), a = D(s);
368
+ o.map((c) => Fe(c, t, r + 1))
369
+ ), a = Q(s);
341
370
  return {
342
371
  oneOf: s,
343
372
  ...a ? { discriminator: a } : {},
344
- [K]: "union"
373
+ [Z]: "union"
345
374
  };
346
375
  }
347
376
  if (e.isArray()) {
@@ -349,80 +378,100 @@ async function be(e, t, n) {
349
378
  return { type: "array", items: o ? await t(o.getText()) : {} };
350
379
  }
351
380
  if (e.isTuple()) {
352
- const o = e.getTupleElements(), r = await Promise.all(
381
+ const o = e.getTupleElements(), n = await Promise.all(
353
382
  o.map((i) => t(i.getText()))
354
383
  );
355
384
  return {
356
385
  type: "array",
357
- items: r,
358
- minItems: r.length,
359
- maxItems: r.length
386
+ items: n,
387
+ minItems: n.length,
388
+ maxItems: n.length
360
389
  };
361
390
  }
362
391
  if (e.isObject()) {
363
- const o = e.getStringIndexType(), r = e.getNumberIndexType(), i = o ?? r, s = e.getProperties();
392
+ const o = e.getStringIndexType(), n = e.getNumberIndexType(), i = o ?? n, s = e.getProperties();
364
393
  if (i && s.length === 0)
365
394
  return { type: "object", additionalProperties: await t(i.getText()) };
366
395
  const a = {}, c = [];
367
- for (const l of s) {
368
- const u = l.getName(), p = l.getDeclarations()[0];
369
- let T;
370
- if (p)
396
+ for (const u of s) {
397
+ const l = u.getName(), m = u.getDeclarations()[0];
398
+ let h;
399
+ if (m)
371
400
  try {
372
- T = l.getTypeAtLocation(p);
401
+ h = u.getTypeAtLocation(m);
373
402
  } catch {
374
- T = void 0;
403
+ h = void 0;
375
404
  }
376
- if (T !== void 0 && T.getCallSignatures().length > 0)
405
+ if (h !== void 0 && h.getCallSignatures().length > 0)
377
406
  continue;
378
- const d = T !== void 0 ? qe(T, p) : void 0;
379
- a[u] = d !== void 0 ? await t(d) : {}, l.isOptional() || c.push(u);
407
+ const y = h !== void 0 ? Ye(h, m) : void 0;
408
+ a[l] = y !== void 0 ? await t(y) : {}, u.isOptional() || c.push(l);
380
409
  }
381
- return Object.keys(a).length > 0 ? {
382
- type: "object",
383
- properties: a,
384
- // Match ts-json-schema-generator's own convention: omit `required`
385
- // entirely when no property is required, rather than emitting `[]`.
386
- ...c.length > 0 ? { required: c } : {}
387
- } : {};
410
+ if (Object.keys(a).length > 0) {
411
+ const u = i ? await t(i.getText()) : !1;
412
+ return {
413
+ type: "object",
414
+ properties: a,
415
+ // Match ts-json-schema-generator's own convention: omit `required`
416
+ // entirely when no property is required, rather than emitting `[]`.
417
+ ...c.length > 0 ? { required: c } : {},
418
+ // BUG-APIGEN-017 (nested case): mirror compose-schemas.ts's top-level
419
+ // additionalProperties:false so Ajv rejects unknown keys on THIS
420
+ // interface-derived nested object too, not only at the envelope/data
421
+ // wrapper. Without this, an unrecognized key nested inside a domain
422
+ // param object (e.g. a typo'd flag on a query-options interface)
423
+ // validates successfully and is then silently discarded by
424
+ // `decodeNode`'s object branch (runtime.ts) instead of erroring —
425
+ // confirmed as BUG-BACKLOG-QUERY-001's actual mechanism: `full`/
426
+ // `view`-shaped optional keys on a nested options object were
427
+ // accepted-and-ignored rather than rejected.
428
+ // Index-signature aware: an interface WITH a string/number index
429
+ // signature legitimately accepts extra keys, so closing it with a
430
+ // hardcoded `false` would reject valid input. `indexValue ? <resolved>
431
+ // : false` keeps the BUG-APIGEN-017 closure above as the default and
432
+ // only opens the schema where the TYPE itself declares it open.
433
+ additionalProperties: u
434
+ };
435
+ }
436
+ return {};
388
437
  }
389
438
  return {};
390
439
  }
391
- function D(e) {
440
+ function Q(e) {
392
441
  if (e.length < 2)
393
442
  return;
394
443
  const t = [];
395
444
  for (const o of e) {
396
445
  if (o.type !== "object")
397
446
  return;
398
- const r = o.properties;
399
- if (!r || typeof r != "object")
447
+ const n = o.properties;
448
+ if (!n || typeof n != "object")
400
449
  return;
401
- t.push(r);
450
+ t.push(n);
402
451
  }
403
- const n = Object.keys(t[0]).filter(
404
- (o) => t.every((r) => Object.prototype.hasOwnProperty.call(r, o))
452
+ const r = Object.keys(t[0]).filter(
453
+ (o) => t.every((n) => Object.prototype.hasOwnProperty.call(n, o))
405
454
  );
406
- for (const o of n) {
407
- const r = [];
455
+ for (const o of r) {
456
+ const n = [];
408
457
  let i = !0;
409
458
  for (const a of t) {
410
- const c = a[o], l = c && (c.type === "string" || c.type === "number"), u = c == null ? void 0 : c.enum;
411
- if (!l || !Array.isArray(u) || u.length !== 1) {
459
+ const c = a[o], u = c && (c.type === "string" || c.type === "number"), l = c == null ? void 0 : c.enum;
460
+ if (!u || !Array.isArray(l) || l.length !== 1) {
412
461
  i = !1;
413
462
  break;
414
463
  }
415
- r.push(String(u[0]));
464
+ n.push(String(l[0]));
416
465
  }
417
- if (!i || new Set(r).size !== r.length)
466
+ if (!i || new Set(n).size !== n.length)
418
467
  continue;
419
468
  const s = {};
420
- return r.forEach((a, c) => {
469
+ return n.forEach((a, c) => {
421
470
  s[a] = `#/oneOf/${c}`;
422
471
  }), { propertyName: o, mapping: s };
423
472
  }
424
473
  }
425
- function q(e, t, n) {
474
+ function H(e, t, r) {
426
475
  if (t > 6)
427
476
  return {};
428
477
  const o = e.trim();
@@ -436,13 +485,13 @@ function q(e, t, n) {
436
485
  return { type: "null" };
437
486
  if (o === "undefined")
438
487
  return { type: "null" };
439
- const r = H[o];
440
- if (r !== void 0)
441
- return r;
442
- if (n != null && n.size) {
443
- const i = n.get(o);
488
+ const n = re[o];
489
+ if (n !== void 0)
490
+ return n;
491
+ if (r != null && r.size) {
492
+ const i = r.get(o);
444
493
  if (i !== void 0) {
445
- const s = H[i];
494
+ const s = re[i];
446
495
  if (s !== void 0)
447
496
  return s;
448
497
  }
@@ -450,59 +499,59 @@ function q(e, t, n) {
450
499
  if (o.endsWith("[]"))
451
500
  return {
452
501
  type: "array",
453
- items: q(o.slice(0, -2), t + 1, n)
502
+ items: H(o.slice(0, -2), t + 1, r)
454
503
  };
455
504
  if (o.includes("|")) {
456
505
  const i = o.split("|").map((c) => c.trim());
457
506
  if (i.every((c) => c.startsWith("'")))
458
507
  return { type: "string", enum: i.map((c) => c.replace(/'/g, "")) };
459
- const s = i.map((c) => q(c, t + 1, n)), a = D(s);
508
+ const s = i.map((c) => H(c, t + 1, r)), a = Q(s);
460
509
  return {
461
510
  oneOf: s,
462
511
  ...a ? { discriminator: a } : {},
463
- [K]: "union"
512
+ [Z]: "union"
464
513
  };
465
514
  }
466
515
  if (o.startsWith("{") && o.endsWith("}")) {
467
516
  const i = o.slice(1, -1).trim(), s = {};
468
517
  for (const a of i.split(";").filter(Boolean)) {
469
- const [c, l] = a.split(":").map((u) => u.trim());
470
- c && l && (s[c.replace("?", "")] = q(l, t + 1, n));
518
+ const [c, u] = a.split(":").map((l) => l.trim());
519
+ c && u && (s[c.replace("?", "")] = H(u, t + 1, r));
471
520
  }
472
521
  return { type: "object", properties: s };
473
522
  }
474
523
  return {};
475
524
  }
476
- function Se(e) {
525
+ function Ce(e) {
477
526
  const t = [];
478
- let n = 0, o = 0;
527
+ let r = 0, o = 0;
479
528
  for (let i = 0; i < e.length; i++) {
480
529
  const s = e[i];
481
- s === "<" || s === "[" || s === "{" || s === "(" ? n++ : s === ">" || s === "]" || s === "}" || s === ")" ? n-- : s === "," && n === 0 && (t.push(e.slice(o, i).trim()), o = i + 1);
530
+ s === "<" || s === "[" || s === "{" || s === "(" ? r++ : s === ">" || s === "]" || s === "}" || s === ")" ? r-- : s === "," && r === 0 && (t.push(e.slice(o, i).trim()), o = i + 1);
482
531
  }
483
- const r = e.slice(o).trim();
484
- return r.length > 0 && t.push(r), t;
532
+ const n = e.slice(o).trim();
533
+ return n.length > 0 && t.push(n), t;
485
534
  }
486
- function De(e) {
535
+ function nt(e) {
487
536
  const t = /^(?:Readonly)?Map<(.+)>$/.exec(e);
488
537
  return t ? t[1] : void 0;
489
538
  }
490
- function Be(e) {
539
+ function rt(e) {
491
540
  const t = /^(?:Readonly)?Set<(.+)>$/.exec(e);
492
541
  return t ? t[1] : void 0;
493
542
  }
494
- function We(e) {
543
+ function ot(e) {
495
544
  let t = e.trim();
496
545
  if (t.startsWith("readonly ") && (t = t.slice(9).trim()), !t.startsWith("[") || !t.endsWith("]"))
497
546
  return;
498
- const n = t.slice(1, -1).trim();
499
- if (n.length !== 0)
500
- return Se(n);
547
+ const r = t.slice(1, -1).trim();
548
+ if (r.length !== 0)
549
+ return Ce(r);
501
550
  }
502
- async function Ue(e, t) {
503
- const n = e.trim(), o = De(n);
551
+ async function it(e, t) {
552
+ const r = e.trim(), o = nt(r);
504
553
  if (o !== void 0) {
505
- const s = Se(o);
554
+ const s = Ce(o);
506
555
  if (s.length === 2) {
507
556
  const [a, c] = await Promise.all([
508
557
  t(s[0]),
@@ -519,10 +568,10 @@ async function Ue(e, t) {
519
568
  };
520
569
  }
521
570
  }
522
- const r = Be(n);
523
- if (r !== void 0)
524
- return { type: "array", items: await t(r), uniqueItems: !0 };
525
- const i = We(n);
571
+ const n = rt(r);
572
+ if (n !== void 0)
573
+ return { type: "array", items: await t(n), uniqueItems: !0 };
574
+ const i = ot(r);
526
575
  if (i !== void 0) {
527
576
  const s = await Promise.all(i.map((a) => t(a)));
528
577
  return {
@@ -533,9 +582,9 @@ async function Ue(e, t) {
533
582
  };
534
583
  }
535
584
  }
536
- const xe = {
585
+ const Re = {
537
586
  "decimal.js": "Decimal"
538
- }, H = {
587
+ }, re = {
539
588
  Date: { type: "string", format: "date-time" },
540
589
  bigint: { type: "string", format: "int64" },
541
590
  Uint8Array: { type: "string", format: "byte" },
@@ -543,16 +592,16 @@ const xe = {
543
592
  URL: { type: "string", format: "uri" },
544
593
  RegExp: { type: "string", format: "regex" },
545
594
  Decimal: { type: "string", format: "decimal" }
546
- }, ae = {
595
+ }, Te = {
547
596
  Uint8Array: "byte",
548
597
  Buffer: "byte",
549
598
  Decimal: "decimal"
550
599
  };
551
- function ce(e) {
552
- var n;
600
+ function Se(e) {
601
+ var r;
553
602
  const t = /* @__PURE__ */ new Map();
554
603
  for (const o of e.getImportDeclarations()) {
555
- const r = o.getModuleSpecifierValue(), i = xe[r];
604
+ const n = o.getModuleSpecifierValue(), i = Re[n];
556
605
  if (!i)
557
606
  continue;
558
607
  const s = o.getDefaultImport();
@@ -561,229 +610,234 @@ function ce(e) {
561
610
  a !== i && t.set(a, i);
562
611
  }
563
612
  for (const a of o.getNamedImports()) {
564
- const c = ((n = a.getAliasNode()) == null ? void 0 : n.getText()) ?? a.getName();
613
+ const c = ((r = a.getAliasNode()) == null ? void 0 : r.getText()) ?? a.getName();
565
614
  c !== i && t.set(c, i);
566
615
  }
567
616
  }
568
617
  return t;
569
618
  }
570
- function Ge(e, t) {
571
- return (n) => {
572
- n.addNodeParser({
619
+ function st(e, t) {
620
+ return (r) => {
621
+ r.addNodeParser({
573
622
  supportsNode(o) {
574
623
  var i, s, a;
575
624
  if (o.kind !== t)
576
625
  return !1;
577
- const r = ((i = o.typeName) == null ? void 0 : i.escapedText) ?? ((a = (s = o.typeName) == null ? void 0 : s.right) == null ? void 0 : a.escapedText);
578
- return r !== void 0 && Object.prototype.hasOwnProperty.call(ae, r);
626
+ const n = ((i = o.typeName) == null ? void 0 : i.escapedText) ?? ((a = (s = o.typeName) == null ? void 0 : s.right) == null ? void 0 : a.escapedText);
627
+ return n !== void 0 && Object.prototype.hasOwnProperty.call(Te, n);
579
628
  },
580
629
  createType(o) {
581
- var i, s, a;
582
- const r = ((i = o.typeName) == null ? void 0 : i.escapedText) ?? ((a = (s = o.typeName) == null ? void 0 : s.right) == null ? void 0 : a.escapedText);
583
- return new ne(
584
- new re(),
585
- { format: ae[r] },
630
+ var a, c, u;
631
+ const n = ((a = o.typeName) == null ? void 0 : a.escapedText) ?? ((u = (c = o.typeName) == null ? void 0 : c.right) == null ? void 0 : u.escapedText), { AnnotatedType: i, StringType: s } = oe();
632
+ return new i(
633
+ new s(),
634
+ { format: Te[n] },
586
635
  !1
587
636
  );
588
637
  }
589
- }), n.addNodeParser({
638
+ }), r.addNodeParser({
590
639
  supportsNode(o) {
591
640
  return o.kind === e;
592
641
  },
593
642
  createType() {
594
- return new ne(new re(), { format: "int64" }, !1);
643
+ const { AnnotatedType: o, StringType: n } = oe();
644
+ return new o(new n(), { format: "int64" }, !1);
595
645
  }
596
646
  });
597
647
  };
598
648
  }
599
- let C;
600
- function Ze() {
601
- if (C)
602
- return C;
649
+ let D;
650
+ function oe() {
651
+ return D || (D = N("ts-json-schema-generator"), D);
652
+ }
653
+ let _;
654
+ function at() {
655
+ if (_)
656
+ return _;
603
657
  try {
604
- const e = Y.dirname(
605
- require.resolve("ts-json-schema-generator/package.json")
658
+ const e = ce.dirname(
659
+ N.resolve("ts-json-schema-generator/package.json")
606
660
  );
607
- C = require(require.resolve("typescript", {
661
+ _ = N(N.resolve("typescript", {
608
662
  paths: [e]
609
663
  }));
610
664
  } catch {
611
- C = require("typescript");
665
+ _ = N("typescript");
612
666
  }
613
- return C;
667
+ return _;
614
668
  }
615
- const k = /* @__PURE__ */ new Map();
616
- function He() {
669
+ const I = /* @__PURE__ */ new Map();
670
+ function ct() {
617
671
  const e = process.env.APIGEN_PROGRAM_CACHE, t = e === void 0 ? NaN : Number(e);
618
672
  return Number.isFinite(t) && t >= 0 ? t : 8;
619
673
  }
620
- function Qe(e) {
621
- const t = k.get(e);
622
- return t && (k.delete(e), k.set(e, t)), t;
674
+ function ut(e) {
675
+ const t = I.get(e);
676
+ return t && (I.delete(e), I.set(e, t)), t;
623
677
  }
624
- function Je(e, t) {
625
- const n = He();
626
- if (n !== 0)
627
- for (k.delete(e), k.set(e, t); k.size > n; ) {
628
- const o = k.keys().next().value;
629
- k.delete(o);
678
+ function lt(e, t) {
679
+ const r = ct();
680
+ if (r !== 0)
681
+ for (I.delete(e), I.set(e, t); I.size > r; ) {
682
+ const o = I.keys().next().value;
683
+ I.delete(o);
630
684
  }
631
685
  }
632
- function Xe(e, t) {
686
+ function ft(e, t) {
633
687
  return `${e}\0${t ?? ""}`;
634
688
  }
635
- const Ye = /* @__PURE__ */ new Set(["zod", /^zod\/./]);
636
- function et(e) {
689
+ const pt = /* @__PURE__ */ new Set(["zod", /^zod\/./]);
690
+ function mt(e) {
637
691
  for (const t of e.getImportDeclarations()) {
638
- const n = t.getModuleSpecifierValue();
639
- for (const o of Ye)
692
+ const r = t.getModuleSpecifierValue();
693
+ for (const o of pt)
640
694
  if (typeof o == "string") {
641
- if (n === o)
695
+ if (r === o)
642
696
  return !0;
643
- } else if (o.test(n))
697
+ } else if (o.test(r))
644
698
  return !0;
645
699
  }
646
700
  return !1;
647
701
  }
648
- function tt(e) {
702
+ function dt(e) {
649
703
  for (const t of ["$defs", "definitions"]) {
650
- const n = e[t];
651
- if (!n || typeof n != "object")
704
+ const r = e[t];
705
+ if (!r || typeof r != "object")
652
706
  continue;
653
- const o = Object.keys(n);
707
+ const o = Object.keys(r);
654
708
  if (o.length === 0)
655
709
  continue;
656
- const r = new Set(o.filter((i) => /zod/i.test(i)));
657
- for (const [i, s] of Object.entries(n)) {
658
- if (r.has(i) || typeof s != "object" || s === null)
710
+ const n = new Set(o.filter((i) => /zod/i.test(i)));
711
+ for (const [i, s] of Object.entries(r)) {
712
+ if (n.has(i) || typeof s != "object" || s === null)
659
713
  continue;
660
714
  const a = s, c = typeof a.$ref == "string" ? a.$ref : "";
661
715
  if (c) {
662
- for (const l of r)
663
- if (c.includes(l)) {
664
- r.add(i);
716
+ for (const u of n)
717
+ if (c.includes(u)) {
718
+ n.add(i);
665
719
  break;
666
720
  }
667
721
  }
668
722
  }
669
- for (const i of r)
670
- delete n[i];
723
+ for (const i of n)
724
+ delete r[i];
671
725
  }
672
- Q(e);
726
+ ie(e);
673
727
  }
674
- function Q(e, t) {
728
+ function ie(e, t) {
675
729
  if (!e || typeof e != "object")
676
730
  return;
677
- const n = t ?? /* @__PURE__ */ new WeakSet();
678
- if (!n.has(e)) {
679
- n.add(e);
731
+ const r = t ?? /* @__PURE__ */ new WeakSet();
732
+ if (!r.has(e)) {
733
+ r.add(e);
680
734
  for (const o of Object.keys(e))
681
735
  if (o === "$ref" && typeof e[o] == "string") {
682
- const r = e[o];
683
- /zod/i.test(r) && delete e[o];
736
+ const n = e[o];
737
+ /zod/i.test(n) && delete e[o];
684
738
  }
685
739
  for (const [, o] of Object.entries(e))
686
740
  if (typeof o == "object" && o !== null)
687
741
  if (Array.isArray(o))
688
- for (const r of o)
689
- typeof r == "object" && r !== null && Q(r, n);
742
+ for (const n of o)
743
+ typeof n == "object" && n !== null && ie(n, r);
690
744
  else
691
- Q(o, n);
745
+ ie(o, r);
692
746
  }
693
747
  }
694
- function nt(e) {
748
+ function gt(e) {
695
749
  const t = /* @__PURE__ */ new Set();
696
750
  for (const o of ["$defs", "definitions"]) {
697
- const r = e[o];
698
- if (r && typeof r == "object")
699
- for (const i of Object.keys(r))
751
+ const n = e[o];
752
+ if (n && typeof n == "object")
753
+ for (const i of Object.keys(n))
700
754
  t.add(i);
701
755
  }
702
- const n = J(e, t);
703
- if (n.length > 0)
756
+ const r = se(e, t);
757
+ if (r.length > 0)
704
758
  throw new Error(
705
- `[apigen-core-client] Generated schema contains ${n.length} unresolvable $ref(s): ${n.join(", ")}. This usually means zod-internal definitions were stripped but $ref references to them remain. Check the source file's imports or the ts-json-schema-generator output.`
759
+ `[apigen-core-client] Generated schema contains ${r.length} unresolvable $ref(s): ${r.join(", ")}. This usually means zod-internal definitions were stripped but $ref references to them remain. Check the source file's imports or the ts-json-schema-generator output.`
706
760
  );
707
761
  }
708
- function J(e, t) {
762
+ function se(e, t) {
709
763
  if (!e || typeof e != "object")
710
764
  return [];
711
- const n = [];
712
- for (const [o, r] of Object.entries(e))
713
- if (o === "$ref" && typeof r == "string") {
714
- const i = r.match(/#\/(?:\$defs|definitions)\/(.+)$/);
715
- i && !t.has(i[1]) && n.push(r);
716
- } else if (typeof r == "object" && r !== null)
717
- if (Array.isArray(r))
718
- for (const i of r)
719
- typeof i == "object" && i !== null && n.push(
720
- ...J(i, t)
765
+ const r = [];
766
+ for (const [o, n] of Object.entries(e))
767
+ if (o === "$ref" && typeof n == "string") {
768
+ const i = n.match(/#\/(?:\$defs|definitions)\/(.+)$/);
769
+ i && !t.has(i[1]) && r.push(n);
770
+ } else if (typeof n == "object" && n !== null)
771
+ if (Array.isArray(n))
772
+ for (const i of n)
773
+ typeof i == "object" && i !== null && r.push(
774
+ ...se(i, t)
721
775
  );
722
776
  else
723
- n.push(
724
- ...J(r, t)
777
+ r.push(
778
+ ...se(n, t)
725
779
  );
726
- return n;
780
+ return r;
727
781
  }
728
- function rt(e) {
782
+ function yt(e) {
729
783
  const t = e.anyOf;
730
784
  if (!Array.isArray(t) || t.length < 2)
731
785
  return e;
732
- const n = t, o = D(n), r = { ...e };
733
- return delete r.anyOf, {
734
- ...r,
735
- oneOf: n,
786
+ const r = t, o = Q(r), n = { ...e };
787
+ return delete n.anyOf, {
788
+ ...n,
789
+ oneOf: r,
736
790
  ...o ? { discriminator: o } : {},
737
- [K]: r[K] ?? "union"
791
+ [Z]: n[Z] ?? "union"
738
792
  };
739
793
  }
740
- function ot(e, t, n) {
741
- const { DEFAULT_CONFIG: o } = require("ts-json-schema-generator/dist/src/Config.js"), r = { ...o, ...e }, i = r.path, s = Xe(i, r.tsconfig);
794
+ function ht(e, t, r) {
795
+ const { DEFAULT_CONFIG: o } = N("ts-json-schema-generator/dist/src/Config.js"), n = { ...o, ...e }, i = n.path, s = ft(i, n.tsconfig);
742
796
  let a;
743
- a = n ? n.statVersion(i) : ye(i);
797
+ a = r ? r.statVersion(i) : ke(i);
744
798
  let c;
745
799
  if (s !== void 0) {
746
- const u = (n == null ? void 0 : n.generatorCache.get(s)) ?? Qe(s);
747
- u && u.version === a && (c = u.gen);
800
+ const l = (r == null ? void 0 : r.generatorCache.get(s)) ?? ut(s);
801
+ l && l.version === a && (c = l.gen);
748
802
  }
749
803
  if (!c) {
750
- const { createProgram: u } = require("ts-json-schema-generator/dist/factory/program.js"), f = Ze(), p = Ge(
751
- f.SyntaxKind.BigIntKeyword,
752
- f.SyntaxKind.TypeReference
753
- ), T = u(r), d = ke(
754
- T,
755
- r,
756
- p
757
- ), m = Ee(r);
758
- if (c = new Ce(
759
- T,
760
- d,
761
- m,
762
- r
763
- ), n && n.stats.generatorsBuilt++, s !== void 0 && a !== void 0) {
764
- const b = { version: a, gen: c };
765
- Je(s, b), n == null || n.generatorCache.set(s, b);
804
+ const { createProgram: l } = N("ts-json-schema-generator/dist/factory/program.js"), { createParser: f, createFormatter: m, SchemaGenerator: h } = oe(), y = at(), d = st(
805
+ y.SyntaxKind.BigIntKeyword,
806
+ y.SyntaxKind.TypeReference
807
+ ), g = l(n), x = f(
808
+ g,
809
+ n,
810
+ d
811
+ ), p = m(n);
812
+ if (c = new h(
813
+ g,
814
+ x,
815
+ p,
816
+ n
817
+ ), r && r.stats.generatorsBuilt++, s !== void 0 && a !== void 0) {
818
+ const T = { version: a, gen: c };
819
+ lt(s, T), r == null || r.generatorCache.set(s, T);
766
820
  }
767
821
  }
768
- const l = c.createSchema(r.type);
769
- return tt(l), nt(l), l;
770
- }
771
- function it(e, t) {
772
- let n = e.trim();
773
- if (n = we(n), t != null && t.size) {
774
- const r = t.get(n);
775
- if (r !== void 0)
776
- return r;
822
+ const u = c.createSchema(n.type);
823
+ return dt(u), gt(u), u;
824
+ }
825
+ function Tt(e, t) {
826
+ let r = e.trim();
827
+ if (r = Le(r), t != null && t.size) {
828
+ const n = t.get(r);
829
+ if (n !== void 0)
830
+ return n;
777
831
  }
778
- const o = n.match(/^ReadonlyArray<(.+)>$/);
779
- for (o && (n = `${o[1].trim()}[]`); n.startsWith("readonly "); )
780
- n = n.slice(9).trim();
781
- return n;
832
+ const o = r.match(/^ReadonlyArray<(.+)>$/);
833
+ for (o && (r = `${o[1].trim()}[]`); r.startsWith("readonly "); )
834
+ r = r.slice(9).trim();
835
+ return r;
782
836
  }
783
- function ve(e) {
837
+ function _e(e) {
784
838
  return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
785
839
  }
786
- const st = Object.entries(xe).map(([e, t]) => ({
840
+ const St = Object.entries(Re).map(([e, t]) => ({
787
841
  // Matches: import("...{modSpec}...").<anyMemberName> (single or double quotes)
788
842
  // The module specifier appears inside an absolute path, so we allow any
789
843
  // characters between the quote and the specifier, and between the specifier
@@ -791,88 +845,88 @@ const st = Object.entries(xe).map(([e, t]) => ({
791
845
  // …) is matched generically (`\w+`) rather than anchored to one spelling —
792
846
  // see the doc comment above for why.
793
847
  pattern: new RegExp(
794
- `import\\(["'][^"']*${ve(e)}[^"']*["']\\)\\.\\w+`,
848
+ `import\\(["'][^"']*${_e(e)}[^"']*["']\\)\\.\\w+`,
795
849
  "g"
796
850
  ),
797
851
  key: t
798
852
  }));
799
- function we(e) {
853
+ function Le(e) {
800
854
  let t = e;
801
- for (const { pattern: n, key: o } of st)
802
- t = t.replace(n, o);
855
+ for (const { pattern: r, key: o } of St)
856
+ t = t.replace(r, o);
803
857
  return t;
804
858
  }
805
- function at(e, t) {
806
- let n = we(e);
807
- for (const [o, r] of t)
808
- n = n.replace(
809
- new RegExp(`\\b${ve(o)}\\b`, "g"),
810
- r
859
+ function bt(e, t) {
860
+ let r = Le(e);
861
+ for (const [o, n] of t)
862
+ r = r.replace(
863
+ new RegExp(`\\b${_e(o)}\\b`, "g"),
864
+ n
811
865
  );
812
- return n;
866
+ return r;
813
867
  }
814
- async function A(e, t, n, o, r, i) {
815
- const s = t.getFilePath(), a = `${s}\0${o ?? ""}\0${n}`, c = i ?? /* @__PURE__ */ new Set();
868
+ async function O(e, t, r, o, n, i) {
869
+ const s = t.getFilePath(), a = `${s}\0${o ?? ""}\0${r}`, c = i ?? /* @__PURE__ */ new Set();
816
870
  if (c.has(a))
817
871
  return {};
818
- if (!r) {
819
- const d = new Set(c);
820
- return d.add(a), ue(
872
+ if (!n) {
873
+ const y = new Set(c);
874
+ return y.add(a), be(
821
875
  e,
822
876
  t,
823
- n,
877
+ r,
824
878
  o,
825
879
  void 0,
826
- d
880
+ y
827
881
  );
828
882
  }
829
- const l = r.schemaCache.get(a);
830
- if (l !== void 0)
831
- return r.stats.schemaCacheHits++, l;
832
- const u = Fe(
883
+ const u = n.schemaCache.get(a);
884
+ if (u !== void 0)
885
+ return n.stats.schemaCacheHits++, u;
886
+ const l = Ue(
833
887
  s,
834
888
  o,
835
- r.statVersion(s)
836
- ), f = u.get(n);
889
+ n.statVersion(s)
890
+ ), f = l.get(r);
837
891
  if (f !== void 0)
838
- return r.stats.schemaCacheHits++, r.schemaCache.set(a, Promise.resolve(f)), f;
839
- r.stats.schemaCacheMisses++;
840
- const p = new Set(c);
841
- p.add(a);
842
- const T = ue(
892
+ return n.stats.schemaCacheHits++, n.schemaCache.set(a, Promise.resolve(f)), f;
893
+ n.stats.schemaCacheMisses++;
894
+ const m = new Set(c);
895
+ m.add(a);
896
+ const h = be(
843
897
  e,
844
898
  t,
845
- n,
846
- o,
847
899
  r,
848
- p
849
- ).then((d) => (u.set(n, d), d)).catch((d) => {
850
- throw r.schemaCache.delete(a), d;
900
+ o,
901
+ n,
902
+ m
903
+ ).then((y) => (l.set(r, y), y)).catch((y) => {
904
+ throw n.schemaCache.delete(a), y;
851
905
  });
852
- return r.schemaCache.set(a, T), T;
906
+ return n.schemaCache.set(a, h), h;
853
907
  }
854
- async function ue(e, t, n, o, r, i) {
855
- if (["void", "undefined", "null", "Promise<void>"].includes(n))
908
+ async function be(e, t, r, o, n, i) {
909
+ if (["void", "undefined", "null", "Promise<void>"].includes(r))
856
910
  return { type: "null" };
857
911
  let s;
858
- if (r) {
859
- const p = r.aliasCache.get(t);
860
- s = p ?? ce(t), p || r.aliasCache.set(t, s);
912
+ if (n) {
913
+ const m = n.aliasCache.get(t);
914
+ s = m ?? Se(t), m || n.aliasCache.set(t, s);
861
915
  } else
862
- s = ce(t);
863
- const a = it(n, s), c = H[a];
916
+ s = Se(t);
917
+ const a = Tt(r, s), c = re[a];
864
918
  if (c !== void 0)
865
919
  return c;
866
- const l = await Ue(
920
+ const u = await it(
867
921
  a,
868
- (p) => A(e, t, p, o, r, i)
922
+ (m) => O(e, t, m, o, n, i)
869
923
  );
870
- if (l !== void 0)
871
- return l;
872
- const u = (r == null ? void 0 : r.zodImportCache.get(t)) ?? et(t);
873
- if (r && r.zodImportCache.set(t, u), !u)
924
+ if (u !== void 0)
925
+ return u;
926
+ const l = (n == null ? void 0 : n.zodImportCache.get(t)) ?? mt(t);
927
+ if (n && n.zodImportCache.set(t, l), !l)
874
928
  try {
875
- const p = {
929
+ const m = {
876
930
  path: t.getFilePath(),
877
931
  type: a,
878
932
  skipTypeCheck: !0,
@@ -899,52 +953,52 @@ async function ue(e, t, n, o, r, i) {
899
953
  // dereference/hoist pass and is tracked separately, unresolved, in
900
954
  // BUG-APIGEN-026's BACKLOG entry.
901
955
  topRef: !1
902
- }, T = ot(p, !0, r);
903
- return rt(T);
956
+ }, h = ht(m, !0, n);
957
+ return yt(h);
904
958
  } catch {
905
959
  }
906
960
  try {
907
- const p = await Ke(
961
+ const m = await tt(
908
962
  e,
909
963
  t,
910
964
  a,
911
- (T) => be(
912
- T,
913
- (d) => A(e, t, d, o, r, i),
965
+ (h) => Fe(
966
+ h,
967
+ (y) => O(e, t, y, o, n, i),
914
968
  0
915
969
  )
916
970
  );
917
- if (p !== void 0)
918
- return p;
971
+ if (m !== void 0)
972
+ return m;
919
973
  } catch {
920
974
  }
921
- const f = at(a, s);
922
- return q(f, 0, s);
975
+ const f = bt(a, s);
976
+ return H(f, 0, s);
923
977
  }
924
- function ee(e, t, n) {
978
+ function le(e, t, r) {
925
979
  if (e != null && e.hasInitializer()) {
926
980
  const o = e.getInitializer();
927
981
  if (o)
928
982
  return o.getText();
929
983
  }
930
- return ct(n, t);
984
+ return vt(r, t);
931
985
  }
932
- function ct(e, t) {
986
+ function vt(e, t) {
933
987
  var s;
934
- const n = e, o = ((s = n == null ? void 0 : n.getJsDocs) == null ? void 0 : s.call(n)) ?? [], r = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), i = new RegExp(`\\[\\s*${r}\\s*=\\s*([^\\]]+)\\]`);
988
+ const r = e, o = ((s = r == null ? void 0 : r.getJsDocs) == null ? void 0 : s.call(r)) ?? [], n = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), i = new RegExp(`\\[\\s*${n}\\s*=\\s*([^\\]]+)\\]`);
935
989
  for (const a of o)
936
990
  for (const c of a.getTags()) {
937
991
  if (c.getTagName() !== "param")
938
992
  continue;
939
- const l = c.getText().match(i);
940
- if (l)
941
- return l[1].trim();
993
+ const u = c.getText().match(i);
994
+ if (u)
995
+ return u[1].trim();
942
996
  }
943
997
  }
944
- function ut(e) {
945
- const t = e.trim(), n = t.match(/^(['"`])([\s\S]*)\1$/);
946
- if (n)
947
- return n[2];
998
+ function xt(e) {
999
+ const t = e.trim(), r = t.match(/^(['"`])([\s\S]*)\1$/);
1000
+ if (r)
1001
+ return r[2];
948
1002
  if (t === "true")
949
1003
  return !0;
950
1004
  if (t === "false")
@@ -961,302 +1015,420 @@ function ut(e) {
961
1015
  }
962
1016
  }
963
1017
  }
964
- function lt(e, t) {
965
- const n = ut(t);
966
- if (n === void 0)
1018
+ function wt(e, t) {
1019
+ const r = xt(t);
1020
+ if (r === void 0)
967
1021
  return;
968
- e.default = n;
969
- const o = typeof n == "string" ? n : JSON.stringify(n), r = typeof e.description == "string" ? e.description : void 0;
970
- e.description = r ? `${r} (default: ${o})` : `(default: ${o})`;
1022
+ e.default = r;
1023
+ const o = typeof r == "string" ? r : JSON.stringify(r), n = typeof e.description == "string" ? e.description : void 0;
1024
+ e.description = n ? `${n} (default: ${o})` : `(default: ${o})`;
1025
+ }
1026
+ let q;
1027
+ function jt() {
1028
+ return q || (q = N("ts-morph").SyntaxKind, q);
971
1029
  }
972
- async function Lt(e) {
973
- const t = e.session === void 0, n = Te(e.session ?? he());
1030
+ function X(e) {
974
1031
  try {
975
- return await ft(e, n);
1032
+ if (!e)
1033
+ return;
1034
+ const t = jt();
1035
+ if (e.getKind() !== t.TypeReference)
1036
+ return;
1037
+ const r = e;
1038
+ if (r.getTypeArguments().length > 0)
1039
+ return;
1040
+ const o = r.getTypeName();
1041
+ if (o.getKind() !== t.Identifier)
1042
+ return;
1043
+ const i = o.getSymbol();
1044
+ if (!i)
1045
+ return;
1046
+ const s = i.getDeclarations().find((f) => f.getKindName() === "TypeAliasDeclaration");
1047
+ if (!s)
1048
+ return;
1049
+ const a = s, c = a.getType();
1050
+ if (!(c.isString() || c.isNumber() || c.isBoolean()))
1051
+ return;
1052
+ const l = a.getJsDocs();
1053
+ for (const f of l)
1054
+ for (const m of f.getTags())
1055
+ if (m.getTagName() === "format") {
1056
+ const h = m.getCommentText();
1057
+ if (h !== void 0)
1058
+ return h.trim();
1059
+ }
1060
+ return;
1061
+ } catch {
1062
+ return;
1063
+ }
1064
+ }
1065
+ const At = /* @__PURE__ */ new Set([
1066
+ "AsyncGenerator",
1067
+ "AsyncIterableIterator",
1068
+ "AsyncIterable",
1069
+ "Generator",
1070
+ "IterableIterator",
1071
+ "Iterable",
1072
+ // Project-specific: `@adhd/apigen-engine-runtime`'s `ApiStream<T>` — a type
1073
+ // alias for `AsyncIterable<T>` (see that package's `stream.ts`). Aliases
1074
+ // used directly (not structurally decomposed) are NOT expanded by
1075
+ // `getText()`, so this wrapper never surfaces as `AsyncIterable<T>` and
1076
+ // must be recognized by its own name.
1077
+ "ApiStream"
1078
+ ]);
1079
+ function $t(e) {
1080
+ const t = [];
1081
+ let r = 0, o = "";
1082
+ for (const n of e)
1083
+ n === "<" || n === "(" || n === "[" || n === "{" ? r++ : (n === ">" || n === ")" || n === "]" || n === "}") && r--, n === "," && r === 0 ? (t.push(o.trim()), o = "") : o += n;
1084
+ return o.trim().length > 0 && t.push(o.trim()), t;
1085
+ }
1086
+ function fe(e) {
1087
+ const t = e.trim(), r = t.indexOf("<");
1088
+ if (r === -1 || !t.endsWith(">"))
1089
+ return null;
1090
+ const o = t.slice(0, r), n = o.includes(".") ? o.slice(o.lastIndexOf(".") + 1) : o;
1091
+ if (!At.has(n))
1092
+ return null;
1093
+ let i = 0;
1094
+ for (let c = r; c < t.length; c++) {
1095
+ const u = t[c];
1096
+ if (u === "<")
1097
+ i++;
1098
+ else if (u === ">" && (i--, i === 0 && c !== t.length - 1))
1099
+ return null;
1100
+ }
1101
+ if (i !== 0)
1102
+ return null;
1103
+ const s = t.slice(r + 1, -1), a = $t(s);
1104
+ return a.length > 0 ? a[0] : null;
1105
+ }
1106
+ async function tn(e) {
1107
+ const t = e.session === void 0, r = Ie(e.session ?? Ee());
1108
+ try {
1109
+ return await Pt(e, r);
976
1110
  } finally {
977
- t && n.dispose();
1111
+ t && r.dispose();
978
1112
  }
979
1113
  }
980
- async function ft(e, t) {
1114
+ async function Pt(e, t) {
981
1115
  const {
982
- sourceFile: n,
1116
+ sourceFile: r,
983
1117
  namespace: o = "",
984
- dropFileSegment: r = !1,
1118
+ dropFileSegment: n = !1,
985
1119
  tsconfig: i
986
- } = e, s = t.projectFor(i), a = t.sourceFileFor(n, i), c = Y.basename(n), l = N(gt(c)), u = r ? null : l, f = N(o), p = [];
987
- for (const [m, b] of a.getExportedDeclarations()) {
988
- if (m === "default" || V(m))
1120
+ } = e, s = t.projectFor(i), a = t.sourceFileFor(r, i), c = ce.basename(r), u = k(Ot(c)), l = n ? null : u, f = k(o), m = [];
1121
+ for (const [d, g] of a.getExportedDeclarations()) {
1122
+ if (d === "default" || W(d))
989
1123
  continue;
990
- const y = yt(b);
991
- if (y) {
992
- const S = y.getSignature(), v = le(S, y), w = S.getReturnType().getText();
993
- p.push(
994
- await M(
1124
+ const x = Et(g);
1125
+ if (x) {
1126
+ const S = x.getSignature(), j = we(S, x), b = S.getReturnType().getText(), A = C(S);
1127
+ m.push(
1128
+ await B(
995
1129
  s,
996
1130
  a,
997
1131
  f,
998
- u,
999
- m,
1000
- v,
1001
- w,
1002
- y.isAsync(),
1132
+ l,
1133
+ d,
1134
+ j,
1135
+ b,
1136
+ x.isAsync(),
1003
1137
  i,
1004
- t
1138
+ t,
1139
+ A
1005
1140
  )
1006
1141
  );
1007
1142
  continue;
1008
1143
  }
1009
- const h = b.find(
1144
+ const p = g.find(
1010
1145
  (S) => S.getKindName() === "VariableDeclaration"
1011
1146
  );
1012
- if (!h)
1147
+ if (!p)
1013
1148
  continue;
1014
- const g = h.getInitializer(), x = g == null ? void 0 : g.getKindName();
1015
- if (g && ["ArrowFunction", "FunctionExpression"].includes(x ?? "")) {
1016
- const v = h.getType().getCallSignatures();
1017
- if (v.length === 0)
1149
+ const T = p.getInitializer(), w = T == null ? void 0 : T.getKindName();
1150
+ if (T && ["ArrowFunction", "FunctionExpression"].includes(w ?? "")) {
1151
+ const j = p.getType().getCallSignatures();
1152
+ if (j.length === 0)
1018
1153
  continue;
1019
- const w = v[0], $ = fe(
1020
- w,
1021
- h,
1022
- h.getVariableStatement()
1023
- ), j = w.getReturnType().getText(), P = g.isAsync();
1024
- p.push(
1025
- await M(
1154
+ const b = j[0], A = je(
1155
+ b,
1156
+ p,
1157
+ p.getVariableStatement()
1158
+ ), $ = b.getReturnType().getText(), v = C(b), P = T.isAsync();
1159
+ m.push(
1160
+ await B(
1026
1161
  s,
1027
1162
  a,
1028
1163
  f,
1029
- u,
1030
- m,
1164
+ l,
1165
+ d,
1166
+ A,
1031
1167
  $,
1032
- j,
1033
1168
  P,
1034
1169
  i,
1035
- t
1170
+ t,
1171
+ v
1036
1172
  )
1037
1173
  );
1038
- } else if (x === "ObjectLiteralExpression") {
1039
- const S = h.getType();
1040
- for (const v of S.getProperties()) {
1041
- const w = v.getName();
1042
- if (V(w))
1174
+ } else if (w === "ObjectLiteralExpression") {
1175
+ const S = p.getType();
1176
+ for (const j of S.getProperties()) {
1177
+ const b = j.getName();
1178
+ if (W(b))
1043
1179
  continue;
1044
- const j = v.getTypeAtLocation(h).getCallSignatures();
1045
- if (j.length === 0)
1180
+ const $ = j.getTypeAtLocation(p).getCallSignatures();
1181
+ if ($.length === 0)
1046
1182
  continue;
1047
- const P = j[0], B = fe(
1048
- P,
1049
- h,
1050
- h.getVariableStatement()
1051
- ), R = P.getReturnType().getText(), _ = [
1052
- ...u ? [u] : [],
1053
- N(m),
1054
- N(w)
1183
+ const v = $[0], P = je(
1184
+ v,
1185
+ p,
1186
+ p.getVariableStatement()
1187
+ ), F = v.getReturnType().getText(), K = C(v), V = [
1188
+ ...l ? [l] : [],
1189
+ k(d),
1190
+ k(b)
1055
1191
  ];
1056
- p.push(
1057
- await z(
1192
+ m.push(
1193
+ await J(
1058
1194
  s,
1059
1195
  a,
1060
1196
  f,
1061
- _,
1062
- w,
1063
- B,
1064
- R,
1197
+ V,
1198
+ b,
1199
+ P,
1200
+ F,
1065
1201
  !1,
1066
1202
  i,
1067
- t
1203
+ t,
1204
+ K
1068
1205
  )
1069
1206
  );
1070
1207
  }
1071
1208
  } else {
1072
- const S = h.getType(), v = S.getText();
1073
- if (E(S, h)) {
1074
- const w = await A(
1209
+ const S = p.getType(), j = S.getText();
1210
+ if (R(S, p)) {
1211
+ const b = await O(
1075
1212
  s,
1076
1213
  a,
1077
- v,
1214
+ j,
1078
1215
  i,
1079
1216
  t
1080
1217
  );
1081
- p.push(
1082
- mt(f, u, m, w)
1218
+ m.push(
1219
+ Nt(f, l, d, b)
1083
1220
  );
1084
1221
  } else
1085
1222
  console.warn(
1086
- `[apigen-core] Skipping non-callable, non-serializable export: ${m}`
1223
+ `[apigen-core] Skipping non-callable, non-serializable export: ${d}`
1087
1224
  );
1088
1225
  }
1089
1226
  }
1090
- const T = a.getDefaultExportSymbol();
1091
- if (T) {
1092
- const m = a.getExportAssignment((b) => !b.isExportEquals());
1093
- if (m) {
1094
- const b = m.getExpression(), y = b.getKindName();
1095
- if (["ArrowFunction", "FunctionExpression"].includes(y)) {
1096
- const g = b.getType().getCallSignatures();
1097
- if (g.length > 0) {
1098
- const x = g[0], S = W(x, m), v = x.getReturnType().getText(), w = b.isAsync();
1099
- p.push(
1100
- await M(
1227
+ const h = a.getDefaultExportSymbol();
1228
+ if (h) {
1229
+ const d = a.getExportAssignment((g) => !g.isExportEquals());
1230
+ if (d) {
1231
+ const g = d.getExpression(), x = g.getKindName();
1232
+ if (["ArrowFunction", "FunctionExpression"].includes(x)) {
1233
+ const T = g.getType().getCallSignatures();
1234
+ if (T.length > 0) {
1235
+ const w = T[0], S = Y(w, d), j = w.getReturnType().getText(), b = C(w), A = g.isAsync();
1236
+ m.push(
1237
+ await B(
1101
1238
  s,
1102
1239
  a,
1103
1240
  f,
1104
- u,
1241
+ l,
1105
1242
  "default",
1106
1243
  S,
1107
- v,
1108
- w,
1244
+ j,
1245
+ A,
1109
1246
  i,
1110
- t
1247
+ t,
1248
+ b
1111
1249
  )
1112
1250
  );
1113
1251
  }
1114
1252
  } else {
1115
- const h = b.getType();
1116
- for (const g of h.getProperties()) {
1117
- const x = g.getName();
1118
- if (V(x))
1253
+ const p = g.getType();
1254
+ for (const T of p.getProperties()) {
1255
+ const w = T.getName();
1256
+ if (W(w))
1119
1257
  continue;
1120
- const v = g.getTypeAtLocation(m).getCallSignatures();
1121
- if (v.length === 0)
1258
+ const j = T.getTypeAtLocation(d).getCallSignatures();
1259
+ if (j.length === 0)
1122
1260
  continue;
1123
- const w = v[0], $ = W(w, m), j = w.getReturnType().getText(), P = [
1124
- ...u ? [u] : [],
1125
- N("default"),
1126
- N(x)
1261
+ const b = j[0], A = Y(b, d), $ = b.getReturnType().getText(), v = C(b), P = [
1262
+ ...l ? [l] : [],
1263
+ k("default"),
1264
+ k(w)
1127
1265
  ];
1128
- p.push(
1129
- await z(
1266
+ m.push(
1267
+ await J(
1130
1268
  s,
1131
1269
  a,
1132
1270
  f,
1133
1271
  P,
1134
- x,
1272
+ w,
1273
+ A,
1135
1274
  $,
1136
- j,
1137
1275
  !1,
1138
1276
  i,
1139
- t
1277
+ t,
1278
+ v
1140
1279
  )
1141
1280
  );
1142
1281
  }
1143
1282
  }
1144
1283
  } else {
1145
- const b = T.getDeclarations();
1146
- for (const y of b) {
1147
- if (y.getKindName() !== "FunctionDeclaration")
1284
+ const g = h.getDeclarations();
1285
+ for (const x of g) {
1286
+ if (x.getKindName() !== "FunctionDeclaration")
1148
1287
  continue;
1149
- const h = y, g = h.getName(), x = g && g.length > 0 ? g : "default", S = h.getSignature(), v = le(S, h), w = S.getReturnType().getText();
1150
- p.push(
1151
- await M(
1288
+ const p = x, T = p.getName(), w = T && T.length > 0 ? T : "default", S = p.getSignature(), j = we(S, p), b = S.getReturnType().getText(), A = C(S);
1289
+ m.push(
1290
+ await B(
1152
1291
  s,
1153
1292
  a,
1154
1293
  f,
1155
- u,
1156
- x,
1157
- v,
1294
+ l,
1158
1295
  w,
1159
- h.isAsync(),
1296
+ j,
1297
+ b,
1298
+ p.isAsync(),
1160
1299
  i,
1161
- t
1300
+ t,
1301
+ A
1162
1302
  )
1163
1303
  );
1164
1304
  }
1165
1305
  }
1166
1306
  }
1167
- const d = dt(a);
1168
- if (d.length > 0)
1169
- for (const { name: m, sig: b } of d) {
1170
- if (V(m))
1307
+ const y = kt(a);
1308
+ if (y.length > 0)
1309
+ for (const { name: d, sig: g } of y) {
1310
+ if (W(d))
1171
1311
  continue;
1172
- const y = W(b), h = b.getReturnType().getText(), g = [
1173
- ...u ? [u] : [],
1174
- N(m)
1312
+ const x = Y(g), p = g.getReturnType().getText(), T = C(g), w = [
1313
+ ...l ? [l] : [],
1314
+ k(d)
1175
1315
  ];
1176
- p.push(
1177
- await z(
1316
+ m.push(
1317
+ await J(
1178
1318
  s,
1179
1319
  a,
1180
1320
  f,
1181
- g,
1182
- m,
1183
- y,
1184
- h,
1321
+ w,
1322
+ d,
1323
+ x,
1324
+ p,
1185
1325
  !1,
1186
1326
  i,
1187
- t
1327
+ t,
1328
+ T
1188
1329
  )
1189
1330
  );
1190
1331
  }
1191
- return p;
1332
+ return m;
1192
1333
  }
1193
- function pt(e, t, n, o) {
1194
- const r = /* @__PURE__ */ new Set(), i = (s) => {
1334
+ function ve(e, t, r, o) {
1335
+ const n = /* @__PURE__ */ new Set(), i = (s) => {
1195
1336
  if (Array.isArray(s))
1196
1337
  return s.map(i);
1197
- if (!s || typeof s != "object" || r.has(s))
1338
+ if (!s || typeof s != "object" || n.has(s))
1198
1339
  return s;
1199
- r.add(s);
1340
+ n.add(s);
1200
1341
  try {
1201
1342
  const a = s, c = {};
1202
- for (const [l, u] of Object.entries(a)) {
1203
- if (l === "definitions" || l === "$defs") {
1204
- const f = l, p = t[f];
1205
- for (const [T, d] of Object.entries(
1206
- u
1343
+ for (const [u, l] of Object.entries(a)) {
1344
+ if (u === "definitions" || u === "$defs") {
1345
+ const f = u, m = t[f];
1346
+ for (const [h, y] of Object.entries(
1347
+ l
1207
1348
  )) {
1208
- const m = i(d), b = p[T];
1209
- if (b !== void 0 && JSON.stringify(b) !== JSON.stringify(m))
1349
+ const d = i(y), g = m[h];
1350
+ if (g !== void 0 && JSON.stringify(g) !== JSON.stringify(d))
1210
1351
  throw new Error(
1211
- `[apigen-core-client] Function "${n}": param "${o}" contributes a "${f}.${T}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`
1352
+ `[apigen-core-client] Function "${r}": param "${o}" contributes a "${f}.${h}" definition that conflicts with an identically-named definition already hoisted from another param/output in the same function. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one function-level schema.`
1212
1353
  );
1213
- p[T] = m;
1354
+ m[h] = d;
1214
1355
  }
1215
1356
  continue;
1216
1357
  }
1217
- c[l] = i(u);
1358
+ c[u] = i(l);
1218
1359
  }
1219
1360
  return c;
1220
1361
  } finally {
1221
- r.delete(s);
1362
+ n.delete(s);
1222
1363
  }
1223
1364
  };
1224
1365
  return i(e);
1225
1366
  }
1226
- async function M(e, t, n, o, r, i, s, a, c, l) {
1227
- const u = N(r);
1228
- return z(
1367
+ function xe(e, t) {
1368
+ if (!t || e.format !== void 0 || "$ref" in e || "properties" in e || "items" in e)
1369
+ return;
1370
+ const r = e.type;
1371
+ (r === "string" || r === "number" || r === "integer" || r === "boolean") && (e.format = t);
1372
+ }
1373
+ function C(e) {
1374
+ var t;
1375
+ try {
1376
+ return X((t = e.getDeclaration()) == null ? void 0 : t.getReturnTypeNode());
1377
+ } catch {
1378
+ return;
1379
+ }
1380
+ }
1381
+ async function B(e, t, r, o, n, i, s, a, c, u, l) {
1382
+ const f = k(n);
1383
+ return J(
1229
1384
  e,
1230
1385
  t,
1231
- n,
1232
- o ? [o, u] : [u],
1233
1386
  r,
1387
+ o ? [o, f] : [f],
1388
+ n,
1234
1389
  i,
1235
1390
  s,
1236
1391
  a,
1237
1392
  c,
1393
+ u,
1238
1394
  l
1239
1395
  );
1240
1396
  }
1241
- async function z(e, t, n, o, r, i, s, a, c, l) {
1242
- const u = i.length > 0 && i[0].name === "ctx", f = i.filter((g) => g.name !== "ctx"), p = f.filter((g) => !g.optional).map((g) => g.name), T = {}, d = {
1397
+ async function J(e, t, r, o, n, i, s, a, c, u, l) {
1398
+ const f = i.length > 0 && i[0].name === "ctx", m = i.filter((v) => v.name !== "ctx"), h = m.filter((v) => !v.optional).map((v) => v.name), y = {}, d = {
1243
1399
  definitions: {},
1244
1400
  $defs: {}
1245
1401
  };
1246
- for (const g of f) {
1247
- const x = await A(e, t, g.type, c, l), S = pt(x, d, r, g.name);
1248
- g.defaultValue !== void 0 && lt(S, g.defaultValue), T[g.name] = S;
1402
+ for (const v of m) {
1403
+ const P = await O(e, t, v.type, c, u), F = ve(P, d, n, v.name);
1404
+ v.defaultValue !== void 0 && wt(F, v.defaultValue), xe(F, v.format), y[v.name] = F;
1249
1405
  }
1250
- const m = s.replace(/^Promise<(.+)>$/, "$1").trim(), b = await A(
1406
+ const g = s.replace(/^Promise<(.+)>$/, "$1").trim(), x = fe(g), p = x !== null, T = p ? x : g, w = await O(
1251
1407
  e,
1252
1408
  t,
1253
- m,
1409
+ T,
1254
1410
  c,
1255
- l
1256
- ), y = {
1411
+ u
1412
+ ), S = {
1413
+ definitions: {},
1414
+ $defs: {}
1415
+ }, j = ve(
1416
+ w,
1417
+ S,
1418
+ n,
1419
+ "<return>"
1420
+ ), b = l ? { ...j } : j;
1421
+ xe(b, l), Object.keys(S.definitions).length > 0 && (b.definitions = {
1422
+ ...b.definitions,
1423
+ ...S.definitions
1424
+ }), Object.keys(S.$defs).length > 0 && (b.$defs = {
1425
+ ...b.$defs,
1426
+ ...S.$defs
1427
+ });
1428
+ const A = {
1257
1429
  type: "object",
1258
- properties: T,
1259
- required: p,
1430
+ properties: y,
1431
+ required: h,
1260
1432
  // BUG-APIGEN-029: hoisted definitions from param fragments — see
1261
1433
  // hoistNestedDefs. Only attached when non-empty so the common
1262
1434
  // (no-recursive-type) case's schema shape is unchanged.
@@ -1264,30 +1436,30 @@ async function z(e, t, n, o, r, i, s, a, c, l) {
1264
1436
  ...Object.keys(d.$defs).length > 0 ? { $defs: d.$defs } : {}
1265
1437
  };
1266
1438
  return {
1267
- id: je(n, o),
1439
+ id: Me(r, o),
1268
1440
  host: "ts",
1269
- namespace: n,
1441
+ namespace: r,
1270
1442
  path: o,
1271
1443
  kind: "action",
1272
1444
  async: a,
1273
- streaming: !1,
1445
+ streaming: p,
1274
1446
  safe: !1,
1275
1447
  // action → false per §4
1276
- input: y,
1448
+ input: A,
1277
1449
  output: b,
1278
1450
  envelope: {},
1279
1451
  typeText: {
1280
1452
  lang: "ts",
1281
- input: ht(i),
1282
- output: m
1453
+ input: It(i),
1454
+ output: T
1283
1455
  },
1284
- ...u ? { hasCtx: !0 } : {}
1456
+ ...f ? { hasCtx: !0 } : {}
1285
1457
  };
1286
1458
  }
1287
- function mt(e, t, n, o) {
1288
- const r = N(n), i = t ? [t, r] : [r];
1459
+ function Nt(e, t, r, o) {
1460
+ const n = k(r), i = t ? [t, n] : [n];
1289
1461
  return {
1290
- id: je(e, i),
1462
+ id: Me(e, i),
1291
1463
  host: "ts",
1292
1464
  namespace: e,
1293
1465
  path: i,
@@ -1302,10 +1474,10 @@ function mt(e, t, n, o) {
1302
1474
  typeText: null
1303
1475
  };
1304
1476
  }
1305
- function je(e, t) {
1477
+ function Me(e, t) {
1306
1478
  return (e.raw ? [e, ...t] : t).map((o) => o.words.join("-")).join("/");
1307
1479
  }
1308
- function $e(e) {
1480
+ function Ke(e) {
1309
1481
  return e.split(/[-_.]+/).flatMap(
1310
1482
  (t) => (
1311
1483
  // Then split PascalCase / camelCase transitions
@@ -1313,196 +1485,220 @@ function $e(e) {
1313
1485
  )
1314
1486
  ).map((t) => t.toLowerCase()).filter(Boolean);
1315
1487
  }
1316
- function N(e) {
1317
- return { raw: e, words: $e(e) };
1488
+ function k(e) {
1489
+ return { raw: e, words: Ke(e) };
1318
1490
  }
1319
- function gt(e) {
1491
+ function Ot(e) {
1320
1492
  return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
1321
1493
  }
1322
- function dt(e) {
1494
+ function kt(e) {
1323
1495
  const t = [];
1324
- for (const n of e.getStatements()) {
1325
- if (n.getKindName() !== "ExpressionStatement")
1496
+ for (const r of e.getStatements()) {
1497
+ if (r.getKindName() !== "ExpressionStatement")
1326
1498
  continue;
1327
- const o = n.getExpression();
1499
+ const o = r.getExpression();
1328
1500
  if (o.getKindName() !== "BinaryExpression")
1329
1501
  continue;
1330
- const r = o;
1331
- if (r.getLeft().getText().trim() !== "module.exports" || r.getOperatorToken().getKindName() !== "EqualsToken")
1502
+ const n = o;
1503
+ if (n.getLeft().getText().trim() !== "module.exports" || n.getOperatorToken().getKindName() !== "EqualsToken")
1332
1504
  continue;
1333
- const s = r.getRight(), a = s.getType();
1505
+ const s = n.getRight(), a = s.getType();
1334
1506
  for (const c of a.getProperties()) {
1335
- const u = c.getTypeAtLocation(s).getCallSignatures();
1336
- u.length !== 0 && t.push({ name: c.getName(), sig: u[0] });
1507
+ const l = c.getTypeAtLocation(s).getCallSignatures();
1508
+ l.length !== 0 && t.push({ name: c.getName(), sig: l[0] });
1337
1509
  }
1338
1510
  }
1339
1511
  return t;
1340
1512
  }
1341
- function yt(e) {
1513
+ function Et(e) {
1342
1514
  let t;
1343
- for (const n of e) {
1344
- if (n.getKindName() !== "FunctionDeclaration")
1515
+ for (const r of e) {
1516
+ if (r.getKindName() !== "FunctionDeclaration")
1345
1517
  continue;
1346
- const o = n;
1518
+ const o = r;
1347
1519
  if (t || (t = o), o.getBody())
1348
1520
  return o;
1349
1521
  }
1350
1522
  return t;
1351
1523
  }
1352
- function le(e, t) {
1353
- return e.getParameters().map((n) => {
1524
+ function we(e, t) {
1525
+ return e.getParameters().map((r) => {
1354
1526
  var s;
1355
- const o = n.getDeclarations(), r = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = n.isOptional() || ((r == null ? void 0 : r.hasInitializer()) ?? !1) || (((s = r == null ? void 0 : r.hasQuestionToken) == null ? void 0 : s.call(r)) ?? !1);
1527
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1356
1528
  return {
1357
- name: n.getName(),
1358
- type: n.getTypeAtLocation(e.getDeclaration()).getText(),
1529
+ name: r.getName(),
1530
+ type: r.getTypeAtLocation(e.getDeclaration()).getText(),
1359
1531
  optional: i,
1360
- defaultValue: ee(r, n.getName(), t)
1532
+ defaultValue: le(n, r.getName(), t),
1533
+ format: X(n == null ? void 0 : n.getTypeNode())
1361
1534
  };
1362
1535
  });
1363
1536
  }
1364
- function fe(e, t, n) {
1537
+ function je(e, t, r) {
1365
1538
  return e.getParameters().map((o) => {
1366
1539
  var a;
1367
- const r = o.getDeclarations(), i = r.length > 0 && r[0].getKindName() === "Parameter" ? r[0] : null, s = o.isOptional() || ((i == null ? void 0 : i.hasInitializer()) ?? !1) || (((a = i == null ? void 0 : i.hasQuestionToken) == null ? void 0 : a.call(i)) ?? !1);
1540
+ const n = o.getDeclarations(), i = n.length > 0 && n[0].getKindName() === "Parameter" ? n[0] : null, s = o.isOptional() || ((i == null ? void 0 : i.hasInitializer()) ?? !1) || (((a = i == null ? void 0 : i.hasQuestionToken) == null ? void 0 : a.call(i)) ?? !1);
1368
1541
  return {
1369
1542
  name: o.getName(),
1370
1543
  type: o.getTypeAtLocation(t).getText(),
1371
1544
  optional: s,
1372
- defaultValue: ee(
1545
+ defaultValue: le(
1373
1546
  i,
1374
1547
  o.getName(),
1375
- n ?? t
1376
- )
1548
+ r ?? t
1549
+ ),
1550
+ format: X(i == null ? void 0 : i.getTypeNode())
1377
1551
  };
1378
1552
  });
1379
1553
  }
1380
- function W(e, t) {
1381
- return e.getParameters().map((n) => {
1554
+ function Y(e, t) {
1555
+ return e.getParameters().map((r) => {
1382
1556
  var s, a, c;
1383
- const o = n.getDeclarations(), r = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = n.isOptional() || ((r == null ? void 0 : r.hasInitializer()) ?? !1) || (((s = r == null ? void 0 : r.hasQuestionToken) == null ? void 0 : s.call(r)) ?? !1);
1557
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1384
1558
  return {
1385
- name: n.getName(),
1386
- type: r ? r.getType().getText() : ((c = (a = n.getValueDeclaration()) == null ? void 0 : a.getType()) == null ? void 0 : c.getText()) ?? "unknown",
1559
+ name: r.getName(),
1560
+ type: n ? n.getType().getText() : ((c = (a = r.getValueDeclaration()) == null ? void 0 : a.getType()) == null ? void 0 : c.getText()) ?? "unknown",
1387
1561
  optional: i,
1388
- defaultValue: ee(r, n.getName(), t)
1562
+ defaultValue: le(n, r.getName(), t),
1563
+ format: X(n == null ? void 0 : n.getTypeNode())
1389
1564
  };
1390
1565
  });
1391
1566
  }
1392
- function ht(e) {
1393
- const t = e.filter((n) => n.name !== "ctx");
1394
- return t.length === 0 ? "()" : "(" + t.map((n) => `${n.name}${n.optional ? "?" : ""}: ${n.type}`).join(", ") + ")";
1567
+ function It(e) {
1568
+ const t = e.filter((r) => r.name !== "ctx");
1569
+ return t.length === 0 ? "()" : "(" + t.map((r) => `${r.name}${r.optional ? "?" : ""}: ${r.type}`).join(", ") + ")";
1395
1570
  }
1396
- function V(e) {
1571
+ function W(e) {
1397
1572
  return !!(e === "__samples__" || e.startsWith("__"));
1398
1573
  }
1399
- function E(e, t, n = /* @__PURE__ */ new Set()) {
1574
+ function R(e, t, r = /* @__PURE__ */ new Set()) {
1400
1575
  if (e.getCallSignatures().length > 0 || e.getConstructSignatures().length > 0)
1401
1576
  return !1;
1402
1577
  if (e.isString() || e.isNumber() || e.isBoolean() || e.isNull() || e.isUndefined() || e.isStringLiteral() || e.isNumberLiteral() || e.isBooleanLiteral() || e.isEnumLiteral())
1403
1578
  return !0;
1404
1579
  if (e.isArray() || e.isReadonlyArray()) {
1405
1580
  const o = e.getArrayElementType();
1406
- return o ? E(o, t, n) : !1;
1581
+ return o ? R(o, t, r) : !1;
1407
1582
  }
1408
1583
  if (e.isTuple())
1409
- return e.getTupleElements().every((o) => E(o, t, n));
1584
+ return e.getTupleElements().every((o) => R(o, t, r));
1410
1585
  if (e.isUnion())
1411
- return e.getUnionTypes().every((o) => E(o, t, n));
1586
+ return e.getUnionTypes().every((o) => R(o, t, r));
1412
1587
  if (e.isIntersection())
1413
- return e.getIntersectionTypes().every((o) => E(o, t, n));
1588
+ return e.getIntersectionTypes().every((o) => R(o, t, r));
1414
1589
  if (e.isObject()) {
1415
1590
  const o = e.getText(t);
1416
- if (n.has(o))
1591
+ if (r.has(o))
1417
1592
  return !0;
1418
- n.add(o);
1419
- const r = e.getStringIndexType(), i = e.getNumberIndexType();
1420
- if (r || i)
1421
- return [r, i].every(
1422
- (a) => !a || E(a, t, n)
1593
+ r.add(o);
1594
+ const n = e.getStringIndexType(), i = e.getNumberIndexType();
1595
+ if (n || i)
1596
+ return [n, i].every(
1597
+ (a) => !a || R(a, t, r)
1423
1598
  );
1424
1599
  const s = e.getProperties();
1425
1600
  return s.length === 0 ? !0 : s.every((a) => {
1426
1601
  const c = a.getTypeAtLocation(t);
1427
- return E(c, t, n);
1602
+ return R(c, t, r);
1428
1603
  });
1429
1604
  }
1430
1605
  return !1;
1431
1606
  }
1432
- async function Mt(e) {
1433
- const t = e.session === void 0, n = Te(e.session ?? he());
1607
+ function Ft(e, t) {
1608
+ return async (r) => {
1609
+ let o = () => t(r);
1610
+ for (let n = e.length - 1; n >= 0; n--) {
1611
+ const i = e[n], s = o;
1612
+ o = () => i(r, s);
1613
+ }
1614
+ return o();
1615
+ };
1616
+ }
1617
+ function Ct(e, t) {
1618
+ return Ft(e, t);
1619
+ }
1620
+ function nn(e, t, r = {}) {
1621
+ const o = e.map((n) => n.capabilities.extractLayer).filter((n) => !!n).map((n) => n.createLayer ? n.createLayer(r) : n.layer).filter((n) => !!n);
1622
+ return Ct(o, t);
1623
+ }
1624
+ let U;
1625
+ function Rt() {
1626
+ return U || (U = N("ts-morph").Scope, U);
1627
+ }
1628
+ async function rn(e) {
1629
+ const t = e.session === void 0, r = Ie(e.session ?? Ee());
1434
1630
  try {
1435
- return await Tt(e, n);
1631
+ return await _t(e, r);
1436
1632
  } finally {
1437
- t && n.dispose();
1633
+ t && r.dispose();
1438
1634
  }
1439
1635
  }
1440
- async function Tt(e, t) {
1636
+ async function _t(e, t) {
1441
1637
  const {
1442
- sourceFile: n,
1638
+ sourceFile: r,
1443
1639
  namespace: o = "",
1444
- tsconfig: r,
1640
+ tsconfig: n,
1445
1641
  includeInstances: i = !1
1446
- } = e, s = t.projectFor(r), a = t.sourceFileFor(n, r), c = Y.basename(n), l = I(St(c)), u = I(o), f = [];
1447
- for (const [p, T] of a.getExportedDeclarations()) {
1448
- const d = T.find(
1449
- (y) => y.getKindName() === "ClassDeclaration"
1642
+ } = e, s = t.projectFor(n), a = t.sourceFileFor(r, n), c = ce.basename(r), u = L(Mt(c)), l = L(o), f = [];
1643
+ for (const [m, h] of a.getExportedDeclarations()) {
1644
+ const y = h.find(
1645
+ (p) => p.getKindName() === "ClassDeclaration"
1450
1646
  );
1451
- if (!d)
1647
+ if (!y)
1452
1648
  continue;
1453
- const m = p === "default" ? d.getName() : p;
1454
- if (!m || G(m))
1649
+ const d = m === "default" ? y.getName() : m;
1650
+ if (!d || te(d))
1455
1651
  continue;
1456
- const b = I(m);
1457
- for (const y of d.getStaticMethods()) {
1458
- const h = y.getName();
1459
- if (G(h))
1652
+ const g = L(d), x = Rt();
1653
+ for (const p of y.getStaticMethods()) {
1654
+ const T = p.getName();
1655
+ if (te(T))
1460
1656
  continue;
1461
- const g = y.getScope();
1462
- if (g === L.Private || g === L.Protected)
1657
+ const w = p.getScope();
1658
+ if (w === x.Private || w === x.Protected)
1463
1659
  continue;
1464
- const x = y.getSignature(), S = U(x, y), v = x.getReturnType().getText(), w = y.isAsync(), $ = [l, b, I(h)];
1660
+ const S = p.getSignature(), j = ee(S, p), b = S.getReturnType().getText(), A = p.isAsync(), $ = [u, g, L(T)];
1465
1661
  f.push(
1466
- await bt(
1662
+ await Lt(
1467
1663
  s,
1468
1664
  a,
1469
- u,
1665
+ l,
1470
1666
  $,
1471
- S,
1472
- v,
1473
- w,
1474
- r,
1667
+ j,
1668
+ b,
1669
+ A,
1670
+ n,
1475
1671
  t
1476
1672
  )
1477
1673
  );
1478
1674
  }
1479
1675
  if (i) {
1480
1676
  {
1481
- const h = d.getConstructors()[0] ?? null;
1482
- let g = [];
1483
- if (h) {
1484
- const j = h.getSignature();
1485
- g = U(j, h);
1677
+ const T = y.getConstructors()[0] ?? null;
1678
+ let w = [];
1679
+ if (T) {
1680
+ const v = T.getSignature();
1681
+ w = ee(v, T);
1486
1682
  }
1487
- const x = [l, b], S = X(u, x), v = g.filter((j) => j.name !== "ctx"), w = v.filter((j) => !j.optional).map((j) => j.name), $ = {};
1488
- for (const j of v)
1489
- $[j.name] = await A(
1683
+ const S = [u, g], j = ae(l, S), b = w.filter((v) => v.name !== "ctx"), A = b.filter((v) => !v.optional).map((v) => v.name), $ = {};
1684
+ for (const v of b)
1685
+ $[v.name] = await O(
1490
1686
  s,
1491
1687
  a,
1492
- j.type,
1493
- r,
1688
+ v.type,
1689
+ n,
1494
1690
  t
1495
1691
  );
1496
1692
  f.push({
1497
- id: S,
1693
+ id: j,
1498
1694
  host: "ts",
1499
- namespace: u,
1500
- path: x,
1695
+ namespace: l,
1696
+ path: S,
1501
1697
  kind: "constructor",
1502
1698
  async: !1,
1503
1699
  streaming: !1,
1504
1700
  safe: !1,
1505
- input: { type: "object", properties: $, required: w },
1701
+ input: { type: "object", properties: $, required: A },
1506
1702
  output: {
1507
1703
  type: "object",
1508
1704
  properties: { instanceId: { type: "string" } },
@@ -1511,45 +1707,45 @@ async function Tt(e, t) {
1511
1707
  envelope: {},
1512
1708
  typeText: {
1513
1709
  lang: "ts",
1514
- input: xt(g),
1710
+ input: Kt(w),
1515
1711
  output: "{ instanceId: string }"
1516
1712
  }
1517
1713
  });
1518
1714
  }
1519
- for (const y of d.getInstanceMethods()) {
1520
- const h = y.getName();
1521
- if (G(h))
1715
+ for (const p of y.getInstanceMethods()) {
1716
+ const T = p.getName();
1717
+ if (te(T))
1522
1718
  continue;
1523
- const g = y.getScope();
1524
- if (g === L.Private || g === L.Protected)
1719
+ const w = p.getScope();
1720
+ if (w === x.Private || w === x.Protected)
1525
1721
  continue;
1526
- const x = y.getSignature(), S = U(x, y), v = x.getReturnType().getText(), w = y.isAsync(), $ = [l, b, I(h)], j = X(u, $), P = S.filter((O) => O.name !== "ctx"), B = P.filter((O) => !O.optional).map((O) => O.name), R = {};
1527
- for (const O of P)
1528
- R[O.name] = await A(
1722
+ const S = p.getSignature(), j = ee(S, p), b = S.getReturnType().getText(), A = p.isAsync(), $ = [u, g, L(T)], v = ae(l, $), P = j.filter((E) => E.name !== "ctx"), F = P.filter((E) => !E.optional).map((E) => E.name), K = {};
1723
+ for (const E of P)
1724
+ K[E.name] = await O(
1529
1725
  s,
1530
1726
  a,
1531
- O.type,
1532
- r,
1727
+ E.type,
1728
+ n,
1533
1729
  t
1534
1730
  );
1535
- const _ = v.replace(/^Promise<(.+)>$/, "$1").trim(), Pe = await A(
1731
+ const V = b.replace(/^Promise<(.+)>$/, "$1").trim(), pe = fe(V), me = pe !== null, de = me ? pe : V, ze = await O(
1536
1732
  s,
1537
1733
  a,
1538
- _,
1539
- r,
1734
+ de,
1735
+ n,
1540
1736
  t
1541
1737
  );
1542
1738
  f.push({
1543
- id: j,
1739
+ id: v,
1544
1740
  host: "ts",
1545
- namespace: u,
1741
+ namespace: l,
1546
1742
  path: $,
1547
1743
  kind: "instance-method",
1548
- async: w,
1549
- streaming: !1,
1744
+ async: A,
1745
+ streaming: me,
1550
1746
  safe: !1,
1551
- input: { type: "object", properties: R, required: B },
1552
- output: Pe,
1747
+ input: { type: "object", properties: K, required: F },
1748
+ output: ze,
1553
1749
  envelope: {
1554
1750
  type: "object",
1555
1751
  properties: { instanceId: { type: "string" } },
@@ -1557,8 +1753,8 @@ async function Tt(e, t) {
1557
1753
  },
1558
1754
  typeText: {
1559
1755
  lang: "ts",
1560
- input: Ae(S),
1561
- output: _
1756
+ input: Ve(j),
1757
+ output: de
1562
1758
  }
1563
1759
  });
1564
1760
  }
@@ -1566,74 +1762,74 @@ async function Tt(e, t) {
1566
1762
  }
1567
1763
  return f;
1568
1764
  }
1569
- async function bt(e, t, n, o, r, i, s, a, c) {
1570
- const l = r.filter((m) => m.name !== "ctx"), u = l.filter((m) => !m.optional).map((m) => m.name), f = {};
1571
- for (const m of l)
1572
- f[m.name] = await A(
1765
+ async function Lt(e, t, r, o, n, i, s, a, c) {
1766
+ const u = n.filter((p) => p.name !== "ctx"), l = u.filter((p) => !p.optional).map((p) => p.name), f = {};
1767
+ for (const p of u)
1768
+ f[p.name] = await O(
1573
1769
  e,
1574
1770
  t,
1575
- m.type,
1771
+ p.type,
1576
1772
  a,
1577
1773
  c
1578
1774
  );
1579
- const p = i.replace(/^Promise<(.+)>$/, "$1").trim(), T = await A(
1775
+ const m = i.replace(/^Promise<(.+)>$/, "$1").trim(), h = fe(m), y = h !== null, d = y ? h : m, g = await O(
1580
1776
  e,
1581
1777
  t,
1582
- p,
1778
+ d,
1583
1779
  a,
1584
1780
  c
1585
1781
  );
1586
1782
  return {
1587
- id: X(n, o),
1783
+ id: ae(r, o),
1588
1784
  host: "ts",
1589
- namespace: n,
1785
+ namespace: r,
1590
1786
  path: o,
1591
1787
  kind: "action",
1592
1788
  async: s,
1593
- streaming: !1,
1789
+ streaming: y,
1594
1790
  safe: !1,
1595
1791
  // action → false per §4
1596
- input: { type: "object", properties: f, required: u },
1597
- output: T,
1792
+ input: { type: "object", properties: f, required: l },
1793
+ output: g,
1598
1794
  envelope: {},
1599
1795
  typeText: {
1600
1796
  lang: "ts",
1601
- input: Ae(r),
1602
- output: p
1797
+ input: Ve(n),
1798
+ output: d
1603
1799
  }
1604
1800
  };
1605
1801
  }
1606
- function X(e, t) {
1802
+ function ae(e, t) {
1607
1803
  return (e.raw ? [e, ...t] : t).map((o) => o.words.join("-")).join("/");
1608
1804
  }
1609
- function I(e) {
1610
- return { raw: e, words: $e(e) };
1805
+ function L(e) {
1806
+ return { raw: e, words: Ke(e) };
1611
1807
  }
1612
- function St(e) {
1808
+ function Mt(e) {
1613
1809
  return e.replace(/\.[^.]+$/, "").replace(/[._]+/g, "-");
1614
1810
  }
1615
- function U(e, t) {
1616
- return e.getParameters().map((n) => {
1811
+ function ee(e, t) {
1812
+ return e.getParameters().map((r) => {
1617
1813
  var s;
1618
- const o = n.getDeclarations(), r = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = n.isOptional() || ((r == null ? void 0 : r.hasInitializer()) ?? !1) || (((s = r == null ? void 0 : r.hasQuestionToken) == null ? void 0 : s.call(r)) ?? !1);
1814
+ const o = r.getDeclarations(), n = o.length > 0 && o[0].getKindName() === "Parameter" ? o[0] : null, i = r.isOptional() || ((n == null ? void 0 : n.hasInitializer()) ?? !1) || (((s = n == null ? void 0 : n.hasQuestionToken) == null ? void 0 : s.call(n)) ?? !1);
1619
1815
  return {
1620
- name: n.getName(),
1621
- type: n.getTypeAtLocation(t).getText(),
1816
+ name: r.getName(),
1817
+ type: r.getTypeAtLocation(t).getText(),
1622
1818
  optional: i
1623
1819
  };
1624
1820
  });
1625
1821
  }
1626
- function Ae(e) {
1627
- const t = e.filter((n) => n.name !== "ctx");
1628
- return t.length === 0 ? "()" : "(" + t.map((n) => `${n.name}${n.optional ? "?" : ""}: ${n.type}`).join(", ") + ")";
1822
+ function Ve(e) {
1823
+ const t = e.filter((r) => r.name !== "ctx");
1824
+ return t.length === 0 ? "()" : "(" + t.map((r) => `${r.name}${r.optional ? "?" : ""}: ${r.type}`).join(", ") + ")";
1629
1825
  }
1630
- function xt(e) {
1826
+ function Kt(e) {
1631
1827
  return e.length === 0 ? "()" : "(" + e.map((t) => `${t.name}${t.optional ? "?" : ""}: ${t.type}`).join(", ") + ")";
1632
1828
  }
1633
- function G(e) {
1829
+ function te(e) {
1634
1830
  return !!(e === "__samples__" || e.startsWith("__") || e.startsWith("_"));
1635
1831
  }
1636
- const vt = /* @__PURE__ */ new Map([
1832
+ const Vt = /* @__PURE__ */ new Map([
1637
1833
  // TypeScript variants
1638
1834
  [".ts", "ts"],
1639
1835
  [".tsx", "ts"],
@@ -1648,21 +1844,21 @@ const vt = /* @__PURE__ */ new Map([
1648
1844
  // Java / Kotlin (both are JVM host languages for the purposes of routing)
1649
1845
  [".java", "java"]
1650
1846
  ]);
1651
- function wt(e) {
1652
- const t = Oe.extname(e).toLowerCase();
1653
- return vt.get(t);
1847
+ function zt(e) {
1848
+ const t = Be.extname(e).toLowerCase();
1849
+ return Vt.get(t);
1654
1850
  }
1655
- function jt(e) {
1851
+ function Dt(e) {
1656
1852
  return e.language ?? "ts";
1657
1853
  }
1658
- function $t(e, t) {
1659
- const n = wt(t);
1660
- return n === void 0 ? !1 : n === jt(e);
1854
+ function qt(e, t) {
1855
+ const r = zt(t);
1856
+ return r === void 0 ? !1 : r === Dt(e);
1661
1857
  }
1662
- function Vt(e, t) {
1663
- return t.filter((n) => $t(e, n));
1858
+ function on(e, t) {
1859
+ return t.filter((r) => qt(e, r));
1664
1860
  }
1665
- function At(e) {
1861
+ function Bt(e) {
1666
1862
  return {
1667
1863
  oneOf: [
1668
1864
  {
@@ -1696,103 +1892,145 @@ function At(e) {
1696
1892
  ]
1697
1893
  };
1698
1894
  }
1699
- function Pt(e) {
1895
+ function Wt(e) {
1700
1896
  return {
1701
1897
  operationConst: e.id,
1702
1898
  itemsSchema: e.input,
1703
- resultSchema: At(e.output)
1899
+ resultSchema: Bt(e.output)
1704
1900
  };
1705
1901
  }
1706
- function Nt(e, t = {}) {
1707
- const n = new Set(t.exclude ?? []), o = /* @__PURE__ */ new Map();
1708
- for (const r of e) {
1709
- if (n.has(r.id))
1902
+ function Ut(e, t = {}) {
1903
+ const r = new Set(t.exclude ?? []), o = /* @__PURE__ */ new Map();
1904
+ for (const n of e) {
1905
+ if (r.has(n.id))
1710
1906
  continue;
1711
- const i = o.get(r.kind);
1712
- i ? i.push(r) : o.set(r.kind, [r]);
1907
+ const i = o.get(n.kind);
1908
+ i ? i.push(n) : o.set(n.kind, [n]);
1713
1909
  }
1714
1910
  return o;
1715
1911
  }
1716
- function pe(e) {
1912
+ function Ae(e) {
1717
1913
  return { type: "string", enum: [e] };
1718
1914
  }
1719
- function me(e, t) {
1915
+ function $e(e, t) {
1720
1916
  return {
1721
1917
  type: "object",
1722
- required: ["operation", "items"],
1918
+ required: ["input"],
1723
1919
  properties: {
1724
- operation: t,
1725
- items: { type: "array", items: e.itemsSchema },
1726
- concurrency: { type: "number" },
1727
- mode: { type: "string", enum: ["parallel", "serial", "chained"] },
1728
- onItemError: { type: "string", enum: ["continue", "abort"] },
1729
- itemTimeoutMs: { type: "number" }
1920
+ input: {
1921
+ type: "object",
1922
+ required: ["operation", "items"],
1923
+ properties: {
1924
+ operation: t,
1925
+ items: { type: "array", items: e.itemsSchema },
1926
+ concurrency: { type: "number" },
1927
+ mode: { type: "string", enum: ["parallel", "serial", "chained"] },
1928
+ onItemError: { type: "string", enum: ["continue", "abort"] },
1929
+ itemTimeoutMs: { type: "number" }
1930
+ },
1931
+ // Additive-forward-compat (§7 open-question 3): a future `batchId`
1932
+ // control-plane field must be addable without a breaking change, so
1933
+ // this branch object must never be a closed schema.
1934
+ additionalProperties: !0
1935
+ }
1730
1936
  },
1731
- // Additive-forward-compat (§7 open-question 3): a future `batchId`
1732
- // control-plane field must be addable without a breaking change, so this
1733
- // branch object must never be a closed schema.
1734
- additionalProperties: !0
1937
+ // The outer wrapper IS a closed shape — `input` is the only sanctioned
1938
+ // top-level key for a `_batch/<kind>` mount call, mirroring
1939
+ // `compose-schemas.ts`'s BUG-APIGEN-017 top-level `additionalProperties:
1940
+ // false` for every extracted source op's envelope+data wrapper.
1941
+ additionalProperties: !1
1735
1942
  };
1736
1943
  }
1737
- function Ot(e) {
1944
+ function Pe(e, t) {
1945
+ const r = {}, o = {}, n = [
1946
+ ["definitions", r],
1947
+ ["$defs", o]
1948
+ ];
1949
+ for (const i of e) {
1950
+ const s = t(i);
1951
+ for (const [a, c] of n) {
1952
+ const u = s[a];
1953
+ if (u)
1954
+ for (const [l, f] of Object.entries(u)) {
1955
+ const m = c[l];
1956
+ if (m !== void 0 && JSON.stringify(m) !== JSON.stringify(f))
1957
+ throw new Error(
1958
+ `[apigen-core-client] _batch mount: operation "${i.id}" contributes a "${a}.${l}" definition that conflicts with an identically-named definition already hoisted from another batched operation. Two structurally different types share the same generated definition key, so apigen cannot safely merge them into one _batch/<kind> schema.`
1959
+ );
1960
+ c[l] = f;
1961
+ }
1962
+ }
1963
+ }
1964
+ return {
1965
+ ...Object.keys(r).length > 0 ? { definitions: r } : {},
1966
+ ...Object.keys(o).length > 0 ? { $defs: o } : {}
1967
+ };
1968
+ }
1969
+ function Gt(e) {
1738
1970
  if (e.length === 0)
1739
1971
  throw new Error("buildBatchKindSchema: at least one operation is required");
1740
- const t = e.map(Pt);
1972
+ const t = e.map(Wt), r = Pe(e, (s) => s.input), o = Pe(e, (s) => s.output);
1741
1973
  if (e.length === 1) {
1742
- const [r] = e, [i] = t;
1974
+ const [s] = e, [a] = t;
1743
1975
  return {
1744
- input: me(i, pe(r.id)),
1745
- output: { type: "array", items: i.resultSchema }
1976
+ input: { ...$e(a, Ae(s.id)), ...r },
1977
+ output: { type: "array", items: a.resultSchema, ...o }
1746
1978
  };
1747
1979
  }
1748
1980
  const n = e.map(
1749
- (r, i) => me(t[i], pe(r.id))
1750
- ), o = D(
1981
+ (s, a) => $e(t[a], Ae(s.id))
1982
+ ), i = Q(
1751
1983
  n
1752
1984
  );
1753
1985
  return {
1754
1986
  input: {
1755
1987
  oneOf: n,
1756
- ...o ? { discriminator: o } : {}
1988
+ ...i ? { discriminator: i } : {},
1989
+ ...r
1757
1990
  },
1758
1991
  output: {
1759
- oneOf: t.map((r) => ({ type: "array", items: r.resultSchema }))
1992
+ oneOf: t.map((s) => ({ type: "array", items: s.resultSchema })),
1993
+ ...o
1760
1994
  },
1761
- ...o ? { discriminator: o } : {}
1995
+ ...i ? { discriminator: i } : {}
1762
1996
  };
1763
1997
  }
1764
- function qt(e, t = {}) {
1765
- const n = Nt(e.operations, t), o = [];
1766
- for (const [r, i] of n) {
1767
- const { input: s, output: a } = Ot(i), c = Ie(`_batch/${r}`, e, {
1768
- kind: r,
1769
- safe: r === "query",
1998
+ function sn(e, t = {}) {
1999
+ const r = Ut(e.operations, t), o = [];
2000
+ for (const [n, i] of r) {
2001
+ const { input: s, output: a } = Gt(i), c = We(`_batch/${n}`, e, {
2002
+ kind: n,
2003
+ safe: n === "query",
1770
2004
  input: s,
1771
2005
  output: a
1772
2006
  });
1773
2007
  o.push({
1774
2008
  ...c,
1775
- operationIds: i.map((l) => l.id)
2009
+ operationIds: i.map((u) => u.id)
1776
2010
  });
1777
2011
  }
1778
2012
  return o;
1779
2013
  }
1780
2014
  export {
1781
- Ot as buildBatchKindSchema,
1782
- qt as buildBatchMountedOperations,
1783
- Ft as clearPersistentProjectCache,
1784
- _t as composeSchemas,
1785
- he as createExtractionSession,
1786
- Pt as deriveBatchOperationBranch,
1787
- jt as effectiveLanguage,
1788
- Lt as extract,
1789
- Mt as extractClasses,
1790
- Nt as groupBatchableOperationsByKind,
1791
- _e as isPrimitiveOnlyInputSchema,
1792
- wt as languageOfSource,
1793
- $t as pluginConsumesSource,
1794
- Rt as pluginsToEnvelopeMiddlewares,
1795
- Vt as sourcesForPlugin,
1796
- Ie as syntheticOp,
1797
- $e as tokenize
2015
+ Gt as buildBatchKindSchema,
2016
+ sn as buildBatchMountedOperations,
2017
+ Qt as clearPersistentProjectCache,
2018
+ Xt as collectLocalImportPaths,
2019
+ Ft as composeOnion,
2020
+ en as composeSchemas,
2021
+ Ct as createExtractInvoker,
2022
+ nn as createExtractInvokerFromPlugins,
2023
+ Ee as createExtractionSession,
2024
+ Wt as deriveBatchOperationBranch,
2025
+ Dt as effectiveLanguage,
2026
+ tn as extract,
2027
+ rn as extractClasses,
2028
+ Ut as groupBatchableOperationsByKind,
2029
+ Je as isPrimitiveOnlyInputSchema,
2030
+ zt as languageOfSource,
2031
+ qt as pluginConsumesSource,
2032
+ Yt as pluginsToEnvelopeMiddlewares,
2033
+ on as sourcesForPlugin,
2034
+ We as syntheticOp,
2035
+ Ke as tokenize
1798
2036
  };