@adhd/apigen-core-client 0.3.0 → 0.3.2

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