@ahoo-wang/wow-generator 9.9.0 → 10.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +99 -62
  2. package/README.zh-CN.md +85 -48
  3. package/dist/analysis/analyze.d.cts +5 -8
  4. package/dist/analysis/analyze.d.ts +5 -8
  5. package/dist/analysis/apiClients.d.cts +3 -4
  6. package/dist/analysis/apiClients.d.ts +3 -4
  7. package/dist/analysis/clientNames.d.cts +0 -20
  8. package/dist/analysis/clientNames.d.ts +0 -20
  9. package/dist/analysis/model.d.cts +2 -102
  10. package/dist/analysis/model.d.ts +2 -102
  11. package/dist/analysis/modelInfo.d.cts +12 -3
  12. package/dist/analysis/modelInfo.d.ts +12 -3
  13. package/dist/analysis/models.d.cts +3 -11
  14. package/dist/analysis/models.d.ts +3 -11
  15. package/dist/api/configuration.d.cts +1 -5
  16. package/dist/api/configuration.d.ts +1 -5
  17. package/dist/cli/program.d.cts +0 -5
  18. package/dist/cli/program.d.ts +0 -5
  19. package/dist/cli.cjs +9 -1
  20. package/dist/cli.cjs.map +1 -1
  21. package/dist/cli.js +102 -3
  22. package/dist/cli.js.map +1 -1
  23. package/dist/codeGenerator-CU1TGcUI.js +2407 -0
  24. package/dist/codeGenerator-CU1TGcUI.js.map +1 -0
  25. package/dist/codeGenerator-DzI0zCgM.cjs +27 -0
  26. package/dist/codeGenerator-DzI0zCgM.cjs.map +1 -0
  27. package/dist/emit/imports.d.cts +0 -9
  28. package/dist/emit/imports.d.ts +0 -9
  29. package/dist/emitters/decorators.d.cts +3 -18
  30. package/dist/emitters/decorators.d.ts +3 -18
  31. package/dist/emitters/emit.d.cts +2 -3
  32. package/dist/emitters/emit.d.ts +2 -3
  33. package/dist/emitters/manifestClients.d.cts +15 -0
  34. package/dist/emitters/manifestClients.d.ts +15 -0
  35. package/dist/emitters/models.d.cts +1 -1
  36. package/dist/emitters/models.d.ts +1 -1
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/input/configuration.d.cts +2 -4
  40. package/dist/input/configuration.d.ts +2 -4
  41. package/dist/input/parsers.d.cts +13 -0
  42. package/dist/input/parsers.d.ts +13 -0
  43. package/dist/manifest/analyze.d.cts +148 -0
  44. package/dist/manifest/analyze.d.ts +148 -0
  45. package/dist/manifest/document.d.cts +89 -0
  46. package/dist/manifest/document.d.ts +89 -0
  47. package/dist/naming/modelInfo.d.cts +1 -2
  48. package/dist/naming/modelInfo.d.ts +1 -2
  49. package/dist/naming/paths.d.cts +0 -5
  50. package/dist/naming/paths.d.ts +0 -5
  51. package/dist/output/outputStore.d.cts +2 -6
  52. package/dist/output/outputStore.d.ts +2 -6
  53. package/dist/pipeline/codeGenerator.d.cts +19 -11
  54. package/dist/pipeline/codeGenerator.d.ts +19 -11
  55. package/package.json +8 -8
  56. package/dist/analysis/aggregates.d.cts +0 -21
  57. package/dist/analysis/aggregates.d.ts +0 -21
  58. package/dist/codeGenerator-BMyiC0tW.cjs +0 -23
  59. package/dist/codeGenerator-BMyiC0tW.cjs.map +0 -1
  60. package/dist/codeGenerator-CsWf0pZy.js +0 -2572
  61. package/dist/codeGenerator-CsWf0pZy.js.map +0 -1
  62. package/dist/emitters/commandClients.d.cts +0 -14
  63. package/dist/emitters/commandClients.d.ts +0 -14
  64. package/dist/emitters/queryClients.d.cts +0 -11
  65. package/dist/emitters/queryClients.d.ts +0 -11
  66. package/dist/fetcherGeneratorCli.cjs +0 -3
  67. package/dist/fetcherGeneratorCli.cjs.map +0 -1
  68. package/dist/fetcherGeneratorCli.d.cts +0 -8
  69. package/dist/fetcherGeneratorCli.d.ts +0 -8
  70. package/dist/fetcherGeneratorCli.js +0 -6
  71. package/dist/fetcherGeneratorCli.js.map +0 -1
  72. package/dist/program-64WQvLq1.js +0 -103
  73. package/dist/program-64WQvLq1.js.map +0 -1
  74. package/dist/program-DWjbTSVJ.cjs +0 -10
  75. package/dist/program-DWjbTSVJ.cjs.map +0 -1
  76. package/dist/wow/conventions.d.cts +0 -154
  77. package/dist/wow/conventions.d.ts +0 -154
  78. package/dist/wow/model.d.cts +0 -116
  79. package/dist/wow/model.d.ts +0 -116
  80. package/dist/wow/resolveWowModel.d.cts +0 -21
  81. package/dist/wow/resolveWowModel.d.ts +0 -21
@@ -0,0 +1,2407 @@
1
+ import { CodeBlockWriter as e, IndentationText as t, Node as n, Project as r, QuoteKind as i, Scope as a, StructureKind as o, SyntaxKind as s, VariableDeclarationKind as c, ts as l } from "ts-morph";
2
+ import { isAbsolute as u, join as d, relative as f, resolve as p, sep as m } from "path";
3
+ import { parse as ee } from "yaml";
4
+ import { readFile as te } from "fs";
5
+ import { join as ne } from "node:path";
6
+ //#region src/api/configuration.ts
7
+ var re = "./wow-generator.config.json", ie = {
8
+ success: 0,
9
+ internal: 1,
10
+ input: 2,
11
+ configuration: 3,
12
+ specification: 4,
13
+ output: 5,
14
+ interrupted: 130
15
+ }, h = class extends Error {
16
+ kind;
17
+ constructor(e, t, n) {
18
+ super(t, n), this.kind = e, this.name = "GeneratorError";
19
+ }
20
+ get exitCode() {
21
+ return ie[this.kind];
22
+ }
23
+ };
24
+ function g(e) {
25
+ return e instanceof Error ? e.message : String(e);
26
+ }
27
+ //#endregion
28
+ //#region src/api/logger.ts
29
+ function ae() {
30
+ return !!process.stdout?.isTTY && !process.env.NO_COLOR;
31
+ }
32
+ var oe = class {
33
+ level;
34
+ decorate;
35
+ constructor(e = {}) {
36
+ this.level = e.level ?? "normal", this.decorate = e.decorate ?? ae();
37
+ }
38
+ format(e, t, n) {
39
+ let r = this.decorate ? `${e} ` : t ? `${t}: ` : "";
40
+ return `${this.level === "verbose" ? `[${(/* @__PURE__ */ new Date()).toTimeString().slice(0, 8)}] ` : ""}${r}${n}`;
41
+ }
42
+ debug(e, ...t) {
43
+ this.level === "verbose" && console.log(this.format("ℹ️ ", "", e), ...t);
44
+ }
45
+ info(e, ...t) {
46
+ this.level !== "quiet" && console.log(this.format("✅", "", e), ...t);
47
+ }
48
+ warn(e, ...t) {
49
+ console.warn(this.format("⚠️ ", "warning", e), ...t);
50
+ }
51
+ error(e, ...t) {
52
+ console.error(this.format("❌", "error", e), ...t);
53
+ }
54
+ }, se = class {
55
+ debug() {}
56
+ info() {}
57
+ warn() {}
58
+ error() {}
59
+ };
60
+ //#endregion
61
+ //#region src/naming/paths.ts
62
+ function ce(e, t) {
63
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t) ? t : t ? `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}` : e;
64
+ }
65
+ var le = "types.ts";
66
+ function ue(e) {
67
+ return ce(e.path, le);
68
+ }
69
+ //#endregion
70
+ //#region src/openapi/references.ts
71
+ function _(e) {
72
+ return !!(e && typeof e == "object" && "$ref" in e);
73
+ }
74
+ function de(e, t) {
75
+ let n = t.slice(1);
76
+ try {
77
+ n = decodeURIComponent(n);
78
+ } catch {}
79
+ if (n === "") return e;
80
+ let r = e;
81
+ for (let e of n.slice(1).split("/")) {
82
+ if (typeof r != "object" || !r) return;
83
+ let t = e.replace(/~1/g, "/").replace(/~0/g, "~");
84
+ if (!Object.hasOwn(r, t)) return;
85
+ r = r[t];
86
+ }
87
+ return r;
88
+ }
89
+ function fe(e) {
90
+ let t = [], n = /* @__PURE__ */ new Set(), r = (i, a) => {
91
+ if (typeof i != "object" || !i || n.has(i)) return;
92
+ if (n.add(i), Array.isArray(i)) {
93
+ i.forEach((e, t) => r(e, `${a}/${t}`));
94
+ return;
95
+ }
96
+ let o = i.$ref;
97
+ typeof o == "string" && o.startsWith("#/components/") && de(e, o) === void 0 && t.push({
98
+ ref: o,
99
+ location: a || "/"
100
+ });
101
+ for (let [e, t] of Object.entries(i)) r(t, `${a}/${e.replace(/~/g, "~0").replace(/\//g, "~1")}`);
102
+ };
103
+ return r(e, ""), t;
104
+ }
105
+ //#endregion
106
+ //#region src/openapi/components.ts
107
+ var v = "#/components/", pe = `${v}parameters/`, me = `${v}requestBodies/`, he = `${v}responses/`, ge = `${v}schemas/`;
108
+ function _e(e) {
109
+ return e.$ref.split("/").pop();
110
+ }
111
+ function y(e, t, n) {
112
+ let r = /* @__PURE__ */ new Set(), i = e;
113
+ for (; _(i);) {
114
+ if (!i.$ref.startsWith(n)) return;
115
+ if (r.has(i.$ref)) throw new h("specification", `Cyclic component reference: ${i.$ref}`);
116
+ r.add(i.$ref), i = t?.[i.$ref.slice(n.length)];
117
+ }
118
+ return i;
119
+ }
120
+ function b(e, t) {
121
+ return y(e, t.schemas, ge);
122
+ }
123
+ function ve(e, t) {
124
+ return y(e, t.responses, he);
125
+ }
126
+ function ye(e, t) {
127
+ return y(e, t.requestBodies, me);
128
+ }
129
+ function be(e, t) {
130
+ return y(e, t.parameters, pe);
131
+ }
132
+ //#endregion
133
+ //#region src/naming/order.ts
134
+ var xe = new Intl.Collator("en-US");
135
+ function x(e, t) {
136
+ return xe.compare(e, t);
137
+ }
138
+ //#endregion
139
+ //#region src/openapi/responses.ts
140
+ var Se = "application/json", Ce = "text/event-stream";
141
+ function we(e) {
142
+ return e.split(";")[0].trim().toLowerCase();
143
+ }
144
+ function Te(e) {
145
+ let t = we(e);
146
+ return t === "application/json" || /^application\/[^/]+\+json$/.test(t);
147
+ }
148
+ function Ee(e) {
149
+ let t = we(e);
150
+ return t.startsWith("text/") && t !== "text/event-stream";
151
+ }
152
+ function S(e, t, n = (e) => we(e) === t) {
153
+ if (!e) return;
154
+ if (e[t]) return e[t];
155
+ let r = Object.keys(e).find(n);
156
+ return r === void 0 ? void 0 : e[r];
157
+ }
158
+ function De(e, t) {
159
+ if (t && !_(t)) return S(t.content, e)?.schema;
160
+ }
161
+ function Oe(e) {
162
+ if (e && !_(e)) return S(e.content, Se, Te)?.schema;
163
+ }
164
+ function ke(e) {
165
+ return De(Ce, e);
166
+ }
167
+ function Ae(e) {
168
+ return De("*/*", e);
169
+ }
170
+ function je(e) {
171
+ return !e || _(e) ? !1 : Object.keys(e.content ?? {}).some(Ee);
172
+ }
173
+ //#endregion
174
+ //#region src/openapi/schemas.ts
175
+ function C(e) {
176
+ return Array.isArray(e.enum) && e.enum.length > 0;
177
+ }
178
+ var Me = "x-enum-text";
179
+ function Ne(e) {
180
+ return e[Me];
181
+ }
182
+ function Pe(e) {
183
+ return e.type === "object" && !!e.properties;
184
+ }
185
+ function Fe(e) {
186
+ return e.type === "array" && !!e.items;
187
+ }
188
+ function Ie(e) {
189
+ return Array.isArray(e.anyOf) && e.anyOf.length > 0;
190
+ }
191
+ function Le(e) {
192
+ return Array.isArray(e.oneOf) && e.oneOf.length > 0;
193
+ }
194
+ function Re(e) {
195
+ return Array.isArray(e.allOf) && e.allOf.length > 0;
196
+ }
197
+ function w(e) {
198
+ return Ie(e) || Le(e) || Re(e);
199
+ }
200
+ function ze(e) {
201
+ return e.includes("|") || e.includes("&") ? `(${e})[]` : `${e}[]`;
202
+ }
203
+ function T(e) {
204
+ return e.type === "object" && !e.properties && e.additionalProperties !== void 0;
205
+ }
206
+ var Be = "x-map-key-schema";
207
+ function E(e) {
208
+ return e[Be];
209
+ }
210
+ function Ve(e) {
211
+ return e.readOnly === !0;
212
+ }
213
+ function D(e) {
214
+ if (Array.isArray(e)) return e.map((e) => D(e)).join(" | ");
215
+ switch (e) {
216
+ case "string": return "string";
217
+ case "number":
218
+ case "integer": return "number";
219
+ case "boolean": return "boolean";
220
+ case "null": return "null";
221
+ default: return "any";
222
+ }
223
+ }
224
+ function He(e, t) {
225
+ let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = !1, o = (e) => {
226
+ if (!(!e || i.has(e) || a)) {
227
+ if (i.add(e), _(e)) o(t && b(e, t));
228
+ else if (e.nullable || Array.isArray(e.type)) a = !0;
229
+ else {
230
+ for (let t of e.required ?? []) r.add(t);
231
+ for (let t of Object.keys(e.properties ?? {})) n.includes(t) || n.push(t);
232
+ e.allOf?.forEach(o);
233
+ }
234
+ }
235
+ };
236
+ return o(e), a ? [] : n.filter((e) => !r.has(e));
237
+ }
238
+ //#endregion
239
+ //#region src/openapi/operations.ts
240
+ function Ue(e, t) {
241
+ return e.operation.operationId && t.operation.operationId ? x(e.operation.operationId, t.operation.operationId) : e.path && t.path ? x(e.path, t.path) : e.method && t.method ? x(e.method, t.method) : 0;
242
+ }
243
+ function We(e, t, n) {
244
+ let r = /* @__PURE__ */ new Map();
245
+ for (let i of [...e, ...t]) {
246
+ let e = _(i) ? n && be(i, n) : i, t = e ? `${e.in}:${e.name}` : i.$ref;
247
+ r.set(t, i);
248
+ }
249
+ return [...r.values()];
250
+ }
251
+ function Ge(e, t) {
252
+ let n = [];
253
+ for (let [r, i] of Object.entries(e)) Ke(i).forEach((e) => {
254
+ n.push({
255
+ method: e.method,
256
+ operation: i.parameters?.length ? {
257
+ ...e.operation,
258
+ parameters: We(i.parameters, e.operation.parameters ?? [], t)
259
+ } : e.operation,
260
+ path: r
261
+ });
262
+ });
263
+ return n.sort(Ue);
264
+ }
265
+ function Ke(e) {
266
+ return [
267
+ {
268
+ method: "get",
269
+ operation: e.get
270
+ },
271
+ {
272
+ method: "put",
273
+ operation: e.put
274
+ },
275
+ {
276
+ method: "post",
277
+ operation: e.post
278
+ },
279
+ {
280
+ method: "delete",
281
+ operation: e.delete
282
+ },
283
+ {
284
+ method: "options",
285
+ operation: e.options
286
+ },
287
+ {
288
+ method: "head",
289
+ operation: e.head
290
+ },
291
+ {
292
+ method: "patch",
293
+ operation: e.patch
294
+ },
295
+ {
296
+ method: "trace",
297
+ operation: e.trace
298
+ }
299
+ ].filter(({ operation: e }) => e !== void 0);
300
+ }
301
+ function qe(e) {
302
+ let t = Object.keys(e.responses ?? {});
303
+ if (t.includes("200")) return "200";
304
+ let n = t.filter((e) => /^2\d\d$/.test(e)).sort();
305
+ return n.length > 0 ? n[0] : t.find((e) => e.toUpperCase() === "2XX");
306
+ }
307
+ function Je(e, t) {
308
+ let n = qe(e), r = n ? e.responses[n] : void 0;
309
+ return t && _(r) ? ve(r, t) : r;
310
+ }
311
+ function Ye(e, t) {
312
+ return (e.parameters ?? []).map((e) => _(e) ? be(e, t) : e).filter((e) => e !== void 0);
313
+ }
314
+ function Xe(e, t) {
315
+ let n = (t) => {
316
+ let n = e.indexOf(`{${t.name}}`);
317
+ return n < 0 ? 2 ** 53 - 1 : n;
318
+ };
319
+ return [...t].sort((e, t) => n(e) - n(t));
320
+ }
321
+ //#endregion
322
+ //#region src/naming/naming.ts
323
+ var Ze = /[^\p{L}\p{N}$]+/u, Qe = /* @__PURE__ */ new Set(/* @__PURE__ */ "arguments.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.eval.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield".split("."));
324
+ function O(e) {
325
+ return /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u.test(e) && !Qe.has(e);
326
+ }
327
+ function $e(e) {
328
+ return /^\p{N}/u.test(e) ? `_${e}` : e;
329
+ }
330
+ function et(e) {
331
+ if (O(e)) return e;
332
+ let t = $e(j(e) || "_");
333
+ return Qe.has(t) ? `${t}_` : t;
334
+ }
335
+ function tt(e) {
336
+ return /^\p{Lu}[\p{L}\p{N}$]*$/u.test(e) && O(e);
337
+ }
338
+ function k(e) {
339
+ return $e((Array.isArray(e) ? e : [e]).map((e) => tt(e) ? e : A(e)).join("") || "_");
340
+ }
341
+ function nt(e) {
342
+ return e.split(Ze);
343
+ }
344
+ function rt(e) {
345
+ return Array.isArray(e) ? e.flatMap((e) => it(nt(e))) : it(nt(e));
346
+ }
347
+ function it(e) {
348
+ return e.flatMap((e) => {
349
+ if (e.length === 0) return [];
350
+ let t = [], n = "";
351
+ for (let r = 0; r < e.length; r++) {
352
+ let i = e[r], a = /[A-Z]/.test(i), o = r > 0 && /[a-z]/.test(e[r - 1]);
353
+ a && o && n ? (t.push(n), n = i) : n += i;
354
+ }
355
+ return n && t.push(n), t;
356
+ });
357
+ }
358
+ function A(e) {
359
+ return e === "" || e.length === 0 ? "" : rt(e).filter((e) => e.length > 0).map((e) => {
360
+ let t = e.charAt(0), n = e.slice(1);
361
+ return (/[a-zA-Z]/.test(t) ? t.toUpperCase() : t) + n.toLowerCase();
362
+ }).join("");
363
+ }
364
+ function j(e) {
365
+ let t = A(e);
366
+ return t.charAt(0).toLowerCase() + t.slice(1);
367
+ }
368
+ function M(e) {
369
+ return e === "" || Array.isArray(e) && e.length === 0 ? "" : rt(e).filter((e) => e.length > 0).map((e) => e.toUpperCase()).join("_");
370
+ }
371
+ function N(e) {
372
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e) ? e : P(e);
373
+ }
374
+ function at(e) {
375
+ return /^\d+$/.test(e) ? `NUM_${e}` : M(e) || e;
376
+ }
377
+ function P(e) {
378
+ return `'${JSON.stringify(e).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
379
+ }
380
+ //#endregion
381
+ //#region src/analysis/clientNames.ts
382
+ var ot = "x-fetcher-method";
383
+ function st(e, t) {
384
+ let n = t ?? e["x-fetcher-method"];
385
+ if (n !== void 0) {
386
+ if (typeof n != "string" || !ct(n)) throw new h("specification", `${ot} of ${e.operationId ?? "an operation"} is ${JSON.stringify(n)}, which is not a valid method name.`);
387
+ return n;
388
+ }
389
+ if (!e.operationId) return;
390
+ let r = j(e.operationId.split(".").pop()) || "_";
391
+ return /^\p{N}/u.test(r) ? `_${r}` : r;
392
+ }
393
+ function ct(e) {
394
+ return O(e) || /^[a-z]+$/.test(e);
395
+ }
396
+ function lt(e, t) {
397
+ let n = et(e), r = n;
398
+ for (let e = 2; t.has(r); e++) r = `${n}${e}`;
399
+ return t.add(r), r;
400
+ }
401
+ //#endregion
402
+ //#region src/analysis/modelInfo.ts
403
+ function F(e) {
404
+ if (!e) return {
405
+ name: "",
406
+ path: "/"
407
+ };
408
+ let t = e.split("."), n = -1;
409
+ for (let e = 0; e < t.length; e++) if (t[e] && /^[A-Z]/.test(t[e])) {
410
+ n = e;
411
+ break;
412
+ }
413
+ let r = t.slice(0, n), i = r.length > 0 ? `/${r.join("/")}` : "/";
414
+ return {
415
+ name: k(t.slice(n)),
416
+ path: i
417
+ };
418
+ }
419
+ function ut(e, t) {
420
+ if (!e.$ref.startsWith(ge)) throw new h("specification", `Unsupported schema reference: ${e.$ref}. Bundle or inline external schemas before generation.`);
421
+ return t && b(e, t), F(_e(e));
422
+ }
423
+ //#endregion
424
+ //#region src/analysis/apiClients.ts
425
+ var dt = ["httpRequest", "attributes"];
426
+ function ft(e, t, n) {
427
+ return new pt(e, t, n).clients();
428
+ }
429
+ var pt = class {
430
+ document;
431
+ config;
432
+ warnings;
433
+ constructor(e, t, n) {
434
+ this.document = e, this.config = t, this.warnings = n;
435
+ }
436
+ clients() {
437
+ let e = this.tags(), t = this.groupOperations(), n = /* @__PURE__ */ new Map();
438
+ return [...t.keys()].sort().map((r) => {
439
+ let i = F(r), a = i;
440
+ for (let e = 2; n.has(I(a)); e++) a = {
441
+ ...i,
442
+ name: `${i.name}${e}`
443
+ };
444
+ return a !== i && this.warnings.push(`Tags ${n.get(I(i))} and ${r} both name the API client ${i.name}ApiClient; ${r} generates ${a.name}ApiClient.`), n.set(I(a), r), this.client(e.get(r), a, [...t.get(r)]);
445
+ });
446
+ }
447
+ client(e, t, n) {
448
+ let r = `${t.name}ApiClient`, i = ce(t.path, mt(r)), a = /* @__PURE__ */ new Map();
449
+ return {
450
+ tagName: e.name,
451
+ className: r,
452
+ file: i,
453
+ description: e.description,
454
+ methods: n.map((t) => this.method(e, r, t, a))
455
+ };
456
+ }
457
+ method(e, t, n, r) {
458
+ let { operation: i } = n, a = this.methodName(e, t, n, r), o = new Set(dt), s = this.parameters(e, n, o), c = this.body(i, o), l = [...s.filter(({ parameter: e }) => e.required), ...s.filter(({ parameter: e }) => !e.required)].filter(({ description: e }) => e);
459
+ return {
460
+ name: a,
461
+ httpMethod: n.method,
462
+ path: n.path,
463
+ parameters: s.map(({ parameter: e }) => e),
464
+ body: c,
465
+ returns: this.returns(i),
466
+ docs: [
467
+ i.summary,
468
+ i.description,
469
+ `- operationId: \`${i.operationId}\``,
470
+ `- path: \`${n.path}\``,
471
+ ...l.map(({ parameter: e, description: t }) => `@param ${e.name} - ${t.replace(/\s*\n\s*/g, " ")}`)
472
+ ]
473
+ };
474
+ }
475
+ methodName(e, t, n, r) {
476
+ let i = n.operation.operationId, a = st(n.operation, this.config.apiClients?.[e.name]?.methodNames?.[i]), o = r.get(a);
477
+ if (o !== void 0) throw new h("specification", `Operations ${o} and ${i} of tag ${e.name} both generate the method ${t}.${a}(). Name one of them with apiClients["${e.name}"].methodNames in the generator configuration, or with the x-fetcher-method extension.`);
478
+ return r.set(a, i), a;
479
+ }
480
+ parameters(e, t, n) {
481
+ let r = Ye(t.operation, this.document.components ?? {}), i = [];
482
+ for (let a of [
483
+ "path",
484
+ "query",
485
+ "header"
486
+ ]) {
487
+ let o = r.filter((e) => e.in === a);
488
+ for (let r of a === "path" ? Xe(t.path, o) : o) a === "path" && this.ignoresPathParameter(e.name, r.name) || i.push({
489
+ parameter: {
490
+ name: lt(r.name, n),
491
+ location: a,
492
+ parameterName: r.name,
493
+ schema: r.schema,
494
+ required: a === "path" || r.required === !0
495
+ },
496
+ description: r.description
497
+ });
498
+ }
499
+ let a = r.filter((e) => e.in === "cookie");
500
+ return a.length > 0 && this.warnings.push(`${t.method.toUpperCase()} ${t.path} leaves out its cookie parameter(s) ${a.map((e) => e.name).join(", ")}: the browser sends cookies, and fetch cannot set them.`), i;
501
+ }
502
+ ignoresPathParameter(e, t) {
503
+ return (this.config.apiClients?.[e]?.ignorePathParameters)?.includes(t) ?? !1;
504
+ }
505
+ body(e, t) {
506
+ if (!e.requestBody) return;
507
+ let n = _(e.requestBody) ? ye(e.requestBody, this.document.components) : e.requestBody;
508
+ if (!n) return;
509
+ let r = n.required === !0, i = n.content ?? {}, a = S(i, Se, Te), o = lt("body", t);
510
+ return a?.schema ? {
511
+ name: o,
512
+ required: r,
513
+ content: {
514
+ kind: "json",
515
+ schema: a.schema,
516
+ optionalFields: He(a.schema, this.document.components)
517
+ }
518
+ } : S(i, "multipart/form-data") ? {
519
+ name: o,
520
+ required: r,
521
+ content: { kind: "formData" }
522
+ } : S(i, "application/x-www-form-urlencoded") ? {
523
+ name: o,
524
+ required: r,
525
+ content: { kind: "urlEncoded" }
526
+ } : Object.keys(i).some(Ee) ? {
527
+ name: o,
528
+ required: r,
529
+ content: { kind: "text" }
530
+ } : {
531
+ name: o,
532
+ required: r,
533
+ content: { kind: "binary" }
534
+ };
535
+ }
536
+ returns(e) {
537
+ let t = Je(e, this.document.components);
538
+ if (!t) return { kind: "response" };
539
+ let n = Oe(t), r = n || Ae(t);
540
+ if (r) return {
541
+ kind: "json",
542
+ schema: r,
543
+ wildcard: !n
544
+ };
545
+ let i = ke(t);
546
+ if (i) {
547
+ if (_(i)) {
548
+ let e = b(i, this.document.components);
549
+ if (Fe(e) && _(e.items)) {
550
+ let t = ut(e.items, this.document.components);
551
+ return {
552
+ kind: "eventStream",
553
+ items: e.items,
554
+ serverSentEvent: t.name.includes("ServerSentEvent")
555
+ };
556
+ }
557
+ }
558
+ return {
559
+ kind: "eventStream",
560
+ serverSentEvent: !1
561
+ };
562
+ }
563
+ return je(t) ? { kind: "text" } : { kind: "response" };
564
+ }
565
+ groupOperations() {
566
+ let e = /* @__PURE__ */ new Map();
567
+ for (let t of this.document.endpoints) {
568
+ let n = `${t.method.toUpperCase()} ${t.path}`, r = t.operation.tags ?? [];
569
+ if (r.length === 0) this.warnings.push(`Skipping ${n}: it has no tag, and the tag names its API client.`);
570
+ else if (!t.operation.operationId) this.warnings.push(`Skipping ${n}: it has no operationId, and the operationId names its method.`);
571
+ else for (let n of r) e.has(n) || e.set(n, /* @__PURE__ */ new Set()), e.get(n).add(t);
572
+ }
573
+ return e;
574
+ }
575
+ tags() {
576
+ let e = /* @__PURE__ */ new Map();
577
+ for (let { operation: t } of this.document.endpoints) t.tags?.forEach((t) => {
578
+ e.has(t) || e.set(t, {
579
+ name: t,
580
+ description: ""
581
+ });
582
+ });
583
+ return this.document.openAPI.tags?.forEach((t) => e.set(t.name, t)), e;
584
+ }
585
+ };
586
+ function mt(e) {
587
+ return `${e.charAt(0).toLowerCase()}${e.slice(1)}.ts`;
588
+ }
589
+ function I(e) {
590
+ return `${e.path}/${e.name}`.toLowerCase();
591
+ }
592
+ //#endregion
593
+ //#region src/analysis/models.ts
594
+ function ht(e) {
595
+ let t = e.components?.schemas;
596
+ if (!t) return [];
597
+ let n = Object.keys(t);
598
+ return gt(n), n.map((e) => {
599
+ let n = t[e], r = F(e);
600
+ return {
601
+ key: e,
602
+ info: r,
603
+ file: ue(r),
604
+ schema: n
605
+ };
606
+ });
607
+ }
608
+ function gt(e) {
609
+ let t = /* @__PURE__ */ new Map();
610
+ for (let n of e) {
611
+ let e = F(n), r = `${e.path === "/" ? "" : e.path}/${e.name}`;
612
+ t.set(r, [...t.get(r) ?? [], n]);
613
+ }
614
+ let n = [...t].filter(([, e]) => e.length > 1);
615
+ if (n.length !== 0) throw new h("specification", `Schemas generate the same model: ${n.map(([e, t]) => `${t.join(", ")} → ${e}`).join("; ")}. Rename all but one of them in the document.`);
616
+ }
617
+ //#endregion
618
+ //#region src/analysis/analyze.ts
619
+ function _t(e, t) {
620
+ let n = [];
621
+ return {
622
+ model: {
623
+ models: ht(e),
624
+ apiClients: ft(e, t, n)
625
+ },
626
+ warnings: n
627
+ };
628
+ }
629
+ //#endregion
630
+ //#region src/emit/importRegistry.ts
631
+ var vt = class {
632
+ declarations = /* @__PURE__ */ new Map();
633
+ add(e, t) {
634
+ let n = this.declarations.get(e);
635
+ n || (n = [], this.declarations.set(e, n));
636
+ for (let e of t) n.some((t) => t.name === e) || n.push({ name: e });
637
+ return n;
638
+ }
639
+ apply(e) {
640
+ for (let { moduleSpecifier: t, name: n, alias: r } of e) {
641
+ let e = this.add(t, [n]).find((e) => e.name === n);
642
+ r !== void 0 && (e.alias = r);
643
+ }
644
+ }
645
+ entries() {
646
+ return [...this.declarations].flatMap(([e, t]) => t.map(({ name: t, alias: n }) => n === void 0 ? {
647
+ moduleSpecifier: e,
648
+ name: t
649
+ } : {
650
+ moduleSpecifier: e,
651
+ name: t,
652
+ alias: n
653
+ }));
654
+ }
655
+ localNames(e) {
656
+ return [...this.declarations.values()].flat().filter((t) => t !== e).map((e) => e.alias ?? e.name);
657
+ }
658
+ structures() {
659
+ return [...this.declarations].map(([e, t]) => ({
660
+ moduleSpecifier: e,
661
+ namedImports: t.map(({ name: e, alias: t }) => t === void 0 ? e : {
662
+ name: e,
663
+ alias: t
664
+ })
665
+ }));
666
+ }
667
+ }, yt = class {
668
+ sourceFile;
669
+ imports = new vt();
670
+ statements = [];
671
+ constructor(e) {
672
+ this.sourceFile = e;
673
+ }
674
+ get directoryPath() {
675
+ return this.sourceFile.getDirectoryPath();
676
+ }
677
+ add(e) {
678
+ return this.statements.push(e), e;
679
+ }
680
+ build() {
681
+ let e = [], t;
682
+ for (let n of this.imports.structures()) t = {
683
+ ...n,
684
+ kind: o.ImportDeclaration
685
+ }, e.push(t);
686
+ for (let n of this.statements) t && St(t, n) && e.push(xt), e.push(n), t = n;
687
+ return e.length > 0 && this.sourceFile.addStatements(e), this.sourceFile;
688
+ }
689
+ }, bt = class {
690
+ open;
691
+ modules = /* @__PURE__ */ new Map();
692
+ constructor(e) {
693
+ this.open = e;
694
+ }
695
+ module(e) {
696
+ let t = this.open(e), n = t.getFilePath(), r = this.modules.get(n);
697
+ return r || (r = new yt(t), this.modules.set(n, r)), r;
698
+ }
699
+ build() {
700
+ for (let e of this.modules.values()) e.build();
701
+ this.modules.clear();
702
+ }
703
+ }, xt = (e) => {
704
+ e.blankLineIfLastNot();
705
+ };
706
+ function St(e, t) {
707
+ if (typeof t == "string") return !1;
708
+ switch (t.kind) {
709
+ case o.TypeAlias:
710
+ case o.VariableStatement: return typeof e == "string" || e.kind !== t.kind;
711
+ default: return !0;
712
+ }
713
+ }
714
+ function Ct(e, t) {
715
+ return {
716
+ name: "[key: string]",
717
+ type: e,
718
+ docs: t
719
+ };
720
+ }
721
+ //#endregion
722
+ //#region src/emit/imports.ts
723
+ var wt = "@";
724
+ function L(e, t, n) {
725
+ return e.imports.add(t, n);
726
+ }
727
+ function Tt(e, t, n) {
728
+ return n.path.startsWith(wt) ? n.path : Et(e.directoryPath, d(t, n.path, le));
729
+ }
730
+ function Et(e, t) {
731
+ let n = f(e, t).split(m).join("/");
732
+ return n = n.endsWith(".ts") ? n.replace(/\.ts$/, ".js") : `${n}/index.js`, n.startsWith(".") ? n : `./${n}`;
733
+ }
734
+ //#endregion
735
+ //#region src/emit/jsdoc.ts
736
+ function Dt(e, t = "\n") {
737
+ if (!Array.isArray(e)) return;
738
+ let n = e.filter((e) => typeof e == "string" && e.length > 0).map(Ot);
739
+ return n.length > 0 ? n.join(t) : void 0;
740
+ }
741
+ function Ot(e) {
742
+ return e.replace(/\*\//g, "*\\/");
743
+ }
744
+ function R(e, t) {
745
+ let n = Dt(t);
746
+ n && (e.docs = [...e.docs ?? [], n]);
747
+ }
748
+ function z(e, t, n = !1) {
749
+ e = jt(e);
750
+ let r = [e.title, e.description];
751
+ return t && r.push(`- key: ${t}`), n && Mt(r, e), e.format && r.push(e.format === "int64" ? "- format: int64 (a value beyond Number.MAX_SAFE_INTEGER loses precision)" : `- format: ${e.format}`), Nt(r, e, "default"), Nt(r, e, "example"), Ft(r, e), It(r, e), Lt(r, e), r;
752
+ }
753
+ function kt(e, t, n) {
754
+ R(e, z(t, n));
755
+ }
756
+ function At(e, t, n, r = !1) {
757
+ let i = z(t, n, !0);
758
+ r && Pt(i, "schema", t), R(e, i);
759
+ }
760
+ function jt(e) {
761
+ for (let t of ["anyOf", "oneOf"]) {
762
+ let n = e[t];
763
+ if (!Array.isArray(n) || n.length < 2) continue;
764
+ let r = n.filter((e) => "$ref" in e || e.type !== "null"), [i] = r;
765
+ if (r.length !== 1 || "$ref" in i) continue;
766
+ let a = { ...i };
767
+ for (let [n, r] of Object.entries(e)) n !== t && r !== void 0 && (a[n] = r);
768
+ return a;
769
+ }
770
+ return e;
771
+ }
772
+ function Mt(e, t) {
773
+ let n = t.required ?? [];
774
+ (n.length || Object.keys(t.properties ?? {}).length) && e.push(`- required: ${n.length ? n.join(", ") : "(none)"}`);
775
+ }
776
+ function Nt(e, t, n) {
777
+ let r = t[n];
778
+ r && (typeof r == "object" ? Pt(e, n, r) : e.push(`- ${n}: \`${r}\``));
779
+ }
780
+ function Pt(e, t, n) {
781
+ e.push(`- ${t}: `), e.push("```json"), e.push(JSON.stringify(n, null, 2)), e.push("```");
782
+ }
783
+ function Ft(e, t) {
784
+ let n = ["- Numeric Constraints"];
785
+ t.minimum !== void 0 && n.push(` - minimum: ${t.minimum}`), t.maximum !== void 0 && n.push(` - maximum: ${t.maximum}`), t.exclusiveMinimum !== void 0 && n.push(` - exclusiveMinimum: ${t.exclusiveMinimum}`), t.exclusiveMaximum !== void 0 && n.push(` - exclusiveMaximum: ${t.exclusiveMaximum}`), t.multipleOf !== void 0 && n.push(` - multipleOf: ${t.multipleOf}`), n.length !== 1 && e.push(...n);
786
+ }
787
+ function It(e, t) {
788
+ let n = ["- String Constraints"];
789
+ t.minLength !== void 0 && n.push(` - minLength: ${t.minLength}`), t.maxLength !== void 0 && n.push(` - maxLength: ${t.maxLength}`), t.pattern !== void 0 && n.push(` - pattern: ${t.pattern}`), n.length !== 1 && e.push(...n);
790
+ }
791
+ function Lt(e, t) {
792
+ let n = ["- Array Constraints"];
793
+ t.minItems !== void 0 && n.push(` - minItems: ${t.minItems}`), t.maxItems !== void 0 && n.push(` - maxItems: ${t.maxItems}`), t.uniqueItems !== void 0 && n.push(` - uniqueItems: ${t.uniqueItems}`), n.length !== 1 && e.push(...n);
794
+ }
795
+ //#endregion
796
+ //#region src/types/typeResolver.ts
797
+ function Rt(e, t) {
798
+ let n;
799
+ return {
800
+ components: e,
801
+ modelOf: (n) => t.ofReference(n, e),
802
+ namesAt(r) {
803
+ if (!n) {
804
+ n = /* @__PURE__ */ new Map();
805
+ for (let r of Object.keys(e?.schemas ?? {})) {
806
+ let e = t.ofKey(r), i = n.get(e.path);
807
+ i || (i = [], n.set(e.path, i)), i.push(e.name, `${e.name}EnumText`);
808
+ }
809
+ }
810
+ return n.get(r) ?? [];
811
+ }
812
+ };
813
+ }
814
+ var zt = [
815
+ "Array",
816
+ "Blob",
817
+ "Exclude",
818
+ "FormData",
819
+ "Partial",
820
+ "Promise",
821
+ "ReadonlyArray",
822
+ "Record",
823
+ "Response",
824
+ "Symbol",
825
+ "URLSearchParams"
826
+ ], Bt = /* @__PURE__ */ new Set([
827
+ "string",
828
+ "number",
829
+ "boolean"
830
+ ]), Vt = /* @__PURE__ */ new Set([
831
+ "$comment",
832
+ "$schema",
833
+ "default",
834
+ "deprecated",
835
+ "description",
836
+ "example",
837
+ "examples",
838
+ "externalDocs",
839
+ "readOnly",
840
+ "title",
841
+ "writeOnly",
842
+ "xml"
843
+ ]);
844
+ function Ht(e, t) {
845
+ return e === void 0 ? !1 : typeof e == "string" || typeof t == "string" ? e === t : e.primitive === t.primitive;
846
+ }
847
+ function B(e, t, n = /* @__PURE__ */ new Set()) {
848
+ if (_(e)) {
849
+ if (!t || n.has(e.$ref)) return;
850
+ n.add(e.$ref);
851
+ let r = b(e, t);
852
+ return r ? B(r, t, n) : void 0;
853
+ }
854
+ if (!(e.nullable || Array.isArray(e.type))) {
855
+ if (Re(e) && e.type === void 0) {
856
+ let r = e.allOf.map((e) => B(e, t, n)), [i] = r;
857
+ return i !== void 0 && r.every((e) => Ht(e, i)) ? i : void 0;
858
+ }
859
+ if (!(w(e) || e.const !== void 0 || e.type === void 0)) return e.type === "object" ? "object" : e.type === "array" ? "array" : { primitive: D(e.type) };
860
+ }
861
+ }
862
+ function Ut(e, t, n) {
863
+ let r = B(t, n);
864
+ if (typeof r != "object") return !1;
865
+ let i = B(e, n);
866
+ return i === void 0 || typeof i == "string" || i.primitive !== r.primitive;
867
+ }
868
+ function Wt(e, t) {
869
+ let n = e.additionalProperties;
870
+ return typeof n == "object" && Object.values(e.properties ?? {}).some((e) => Ut(e, n, t));
871
+ }
872
+ function Gt(e) {
873
+ return e.nullable !== !0 || C(e) || !w(e) ? !1 : [
874
+ e.allOf,
875
+ e.oneOf,
876
+ e.anyOf
877
+ ].every((e) => e === void 0 || e.every(_));
878
+ }
879
+ function Kt(e, t) {
880
+ return t.type === void 0 || e === null && t.nullable ? !0 : [t.type].flat().some((t) => t === "null" ? e === null : t === "array" ? Array.isArray(e) : t === "object" ? typeof e == "object" && !!e && !Array.isArray(e) : t === "integer" ? typeof e == "number" && Number.isInteger(e) : typeof e === t);
881
+ }
882
+ function V(t) {
883
+ if (typeof t == "string") return new e({ useSingleQuote: !0 }).quote(t).toString();
884
+ if (Array.isArray(t)) return `[${t.map((e) => V(e)).join(", ")}]`;
885
+ if (typeof t == "object" && t) {
886
+ let e = Object.entries(t).map(([e, t]) => `${N(e)}: ${V(t)}`);
887
+ return e.length ? `{ ${e.join("; ")}; readonly [globalThis.Symbol.iterator]?: never }` : "globalThis.Record<string, never>";
888
+ }
889
+ return JSON.stringify(t) ?? "never";
890
+ }
891
+ var qt = class {
892
+ scope;
893
+ entries;
894
+ requested = [];
895
+ constructor(e) {
896
+ this.scope = e, this.entries = e.imports.entries().map((e) => ({ ...e }));
897
+ }
898
+ get components() {
899
+ return this.scope.context.components;
900
+ }
901
+ imports() {
902
+ return this.requested.map(({ moduleSpecifier: e, name: t, alias: n }) => n === void 0 ? {
903
+ moduleSpecifier: e,
904
+ name: t
905
+ } : {
906
+ moduleSpecifier: e,
907
+ name: t,
908
+ alias: n
909
+ });
910
+ }
911
+ request(e) {
912
+ this.requested.includes(e) || this.requested.push(e);
913
+ }
914
+ reference(e) {
915
+ let t = this.scope.context.modelOf(e), { owner: n } = this.scope;
916
+ if (n.path === t.path) return t.name;
917
+ let r = this.scope.specifierOf(t), i = this.entries.find((e) => e.moduleSpecifier === r && e.name === t.name);
918
+ if (i || (i = {
919
+ moduleSpecifier: r,
920
+ name: t.name
921
+ }, this.entries.push(i)), this.request(i), i.alias) return i.alias;
922
+ let a = /* @__PURE__ */ new Set([
923
+ ...zt,
924
+ n.name,
925
+ ...n.path === void 0 ? [] : this.scope.context.namesAt(n.path),
926
+ ...this.entries.filter((e) => e !== i).map((e) => e.alias ?? e.name)
927
+ ]);
928
+ if (!a.has(t.name)) return t.name;
929
+ let o = `_${t.name}`;
930
+ for (; a.has(o);) o = `_${o}`;
931
+ return i.alias = o, o;
932
+ }
933
+ additionalProperties(e) {
934
+ return e.additionalProperties === !1 || e.additionalProperties === void 0 && !e.required?.some((t) => !Object.hasOwn(e.properties ?? {}, t)) ? "" : e.additionalProperties === !0 || e.additionalProperties === void 0 ? "[key: string]: any" : `[key: string]: ${this.additionalPropertyType(e)}`;
935
+ }
936
+ additionalPropertyType(e) {
937
+ return this.type(typeof e.additionalProperties == "object" ? e.additionalProperties : {});
938
+ }
939
+ requiredAdditionalPropertyType(e) {
940
+ return e.additionalProperties === !1 ? "never" : typeof e.additionalProperties == "object" ? this.type(e.additionalProperties) : "null | string | number | boolean | globalThis.Record<string, unknown> | readonly unknown[]";
941
+ }
942
+ propertyDefinitions(e) {
943
+ let { properties: t } = e;
944
+ return Object.entries(t).map(([e, t]) => {
945
+ let n = this.type(t), r = (Ve(t) ? "readonly " : "") + N(e);
946
+ if (!_(t)) {
947
+ let e = Dt(z(t), "\n * ");
948
+ if (e) return `
949
+ /**
950
+ * ${e}
951
+ */
952
+ ${r}: ${n}
953
+ `;
954
+ }
955
+ return `${r}: ${n}`;
956
+ });
957
+ }
958
+ objectType(e) {
959
+ let t = [];
960
+ Pe(e) && t.push(...this.propertyDefinitions(e));
961
+ for (let n of e.required ?? []) Object.hasOwn(e.properties ?? {}, n) || t.push(`${N(n)}: ${this.requiredAdditionalPropertyType(e)}`);
962
+ let n = T(e) && E(e) ? this.mapType(e) : Wt(e, this.components) ? `globalThis.Record<string, ${this.additionalPropertyType(e)}>` : void 0, r = n ? "" : this.additionalProperties(e);
963
+ if (r && t.push(r), t.length === 0) return "globalThis.Record<string, any>";
964
+ let i = `{\n ${t.join(";\n ")}; \n}`;
965
+ return n ? `(${i} & ${n})` : i;
966
+ }
967
+ mapValueType(e) {
968
+ return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.type(e.additionalProperties);
969
+ }
970
+ mapKeyType(e) {
971
+ let t = E(e);
972
+ return t ? this.type(t) : "string";
973
+ }
974
+ mapType(e) {
975
+ return `globalThis.Record<${this.mapKeyType(e)},${this.mapValueType(e)}>`;
976
+ }
977
+ objectConstrained(e) {
978
+ let t = (e) => _(e) ? this.components && b(e, this.components) : e, n = t(e), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = n ? [n] : [];
979
+ for (let e of a) {
980
+ if (r.has(e)) continue;
981
+ let n = [
982
+ e.allOf,
983
+ e.oneOf,
984
+ e.anyOf
985
+ ].map((e) => e?.map(t) ?? []);
986
+ r.set(e, n);
987
+ for (let e of n) for (let t of e) t && !r.has(t) && a.push(t);
988
+ (e.type === "object" || e.type === "null" || Array.isArray(e.type) && e.type.length > 0 && e.type.every((e) => e === "object" || e === "null")) && i.add(e);
989
+ }
990
+ let o = !0;
991
+ for (; o;) {
992
+ o = !1;
993
+ for (let [e, [t, n, a]] of r) {
994
+ if (i.has(e)) continue;
995
+ let r = (e) => e !== void 0 && i.has(e);
996
+ (t.some(r) || [n, a].some((e) => e.length > 0 && e.every(r))) && (i.add(e), o = !0);
997
+ }
998
+ }
999
+ return n !== void 0 && i.has(n);
1000
+ }
1001
+ type(e) {
1002
+ if (_(e)) return this.reference(e);
1003
+ if (Array.isArray(e.type)) return e.type.map((t) => {
1004
+ let n = this.type({
1005
+ ...e,
1006
+ type: t
1007
+ });
1008
+ return /[|&]/.test(n) ? `(${n})` : n;
1009
+ }).join(" | ");
1010
+ if (Gt(e)) return `(${this.type({
1011
+ ...e,
1012
+ nullable: !1
1013
+ })}) | null`;
1014
+ if (w(e)) {
1015
+ let t = this.simpleComposition(e);
1016
+ if (t !== void 0) return t;
1017
+ let n = [
1018
+ "allOf",
1019
+ "oneOf",
1020
+ "anyOf"
1021
+ ].flatMap((t) => {
1022
+ let n = e[t];
1023
+ return n?.length ? [`(${n.map((n) => {
1024
+ let r = this.memberType(e, t, n);
1025
+ return r === "any" ? "unknown" : /[|&]/.test(r) ? `(${r})` : r;
1026
+ }).join(t === "allOf" ? " & " : " | ")})`] : [];
1027
+ }), r = n.length === 1 ? n[0] : `(${n.join(" & ")})`, i = {
1028
+ ...e,
1029
+ oneOf: void 0,
1030
+ anyOf: void 0,
1031
+ allOf: void 0
1032
+ }, a = this.type(i), o = a === "any" ? r : `(${r} & (${a}))`;
1033
+ return this.objectConstrained(e) ? `globalThis.Exclude<${o}, string | number | boolean | readonly unknown[]> & ({ readonly [globalThis.Symbol.iterator]?: never } | null)` : o;
1034
+ }
1035
+ if (e.const !== void 0) {
1036
+ if (!Kt(e.const, e)) return "never";
1037
+ let t = V(e.const), n = this.type({
1038
+ ...e,
1039
+ const: void 0
1040
+ });
1041
+ return n === "any" ? t : `(${t}) & (${n})`;
1042
+ }
1043
+ if (e.nullable && e.type && !C(e)) return `(${this.type({
1044
+ ...e,
1045
+ nullable: !1
1046
+ })}) | null`;
1047
+ if (C(e)) {
1048
+ let t = e.enum.filter((t) => Kt(t, e)).map((e) => V(e)).join(" | ") || "never", n = this.type({
1049
+ ...e,
1050
+ enum: void 0
1051
+ });
1052
+ return n === "any" || Bt.has(n) ? t : `(${t}) & (${n})`;
1053
+ }
1054
+ return T(e) && !e.required?.length ? this.mapType(e) : e.type === "array" ? ze(this.type(e.items ?? {})) : e.type === "object" ? this.objectType(e) : e.type ? D(e.type) : e.required?.length || Object.keys(e.properties ?? {}).length > 0 ? `(${this.objectType({
1055
+ ...e,
1056
+ type: "object",
1057
+ additionalProperties: e.additionalProperties ?? !0
1058
+ })} | null | string | number | boolean | readonly unknown[])` : "any";
1059
+ }
1060
+ simpleComposition(e) {
1061
+ let t = [
1062
+ "allOf",
1063
+ "oneOf",
1064
+ "anyOf"
1065
+ ].filter((t) => e[t]?.length);
1066
+ if (t.length !== 1) return;
1067
+ let [n] = t;
1068
+ if (Object.keys(e).filter((e) => e !== n && e !== "discriminator" && !e.startsWith("x-") && !Vt.has(e)).length > 0) return;
1069
+ let r = e[n], i = (e) => n !== "allOf" && [e.type].flat().every((e) => e === "null") && e.type !== void 0 && Object.keys(e).every((e) => e === "type" || Vt.has(e));
1070
+ if (!r.every((e) => _(e) || i(e))) return;
1071
+ let a = r.map((t) => _(t) ? this.memberType(e, n, t) : "null");
1072
+ return [...new Set(a)].join(n === "allOf" ? " & " : " | ");
1073
+ }
1074
+ memberType(e, t, n) {
1075
+ let r = this.type(n), i = e.discriminator;
1076
+ if (t === "allOf" || !i?.propertyName || !_(n)) return r;
1077
+ let a = _e(n), o = Object.entries(i.mapping ?? {}).filter(([, e]) => e === n.$ref || e === a).map(([e]) => e), s = (o.length > 0 ? o : [a]).map((e) => P(e)).join(" | ");
1078
+ return `(${r} & { ${N(i.propertyName)}: ${s} })`;
1079
+ }
1080
+ };
1081
+ function H(e, t) {
1082
+ let n = new qt(e);
1083
+ return {
1084
+ text: t(n),
1085
+ imports: n.imports()
1086
+ };
1087
+ }
1088
+ function Jt(e, t) {
1089
+ return H(t, (t) => t.type(e));
1090
+ }
1091
+ function Yt(e, t) {
1092
+ return H(t, (t) => t.additionalProperties(e));
1093
+ }
1094
+ function Xt(e, t) {
1095
+ return H(t, (t) => t.additionalPropertyType(e));
1096
+ }
1097
+ function Zt(e, t) {
1098
+ return H(t, (t) => t.requiredAdditionalPropertyType(e));
1099
+ }
1100
+ function Qt(e, t) {
1101
+ return H(t, (t) => t.mapValueType(e));
1102
+ }
1103
+ //#endregion
1104
+ //#region src/emitters/decorators.ts
1105
+ var $t = "@ahoo-wang/fetcher", en = ["ContentTypeValues", "ResultExtractors"], tn = "@ahoo-wang/fetcher-decorator", nn = [
1106
+ "ApiMetadata",
1107
+ "ApiMetadataCapable",
1108
+ "ParameterRequest",
1109
+ "api",
1110
+ "get",
1111
+ "post",
1112
+ "put",
1113
+ "patch",
1114
+ "del",
1115
+ "request",
1116
+ "attribute",
1117
+ "path",
1118
+ "query",
1119
+ "header",
1120
+ "body",
1121
+ "autoGeneratedError"
1122
+ ], rn = {
1123
+ type: "Promise<Response>",
1124
+ metadata: "{resultExtractor: ResultExtractors.Response }"
1125
+ }, an = {
1126
+ type: "Promise<string>",
1127
+ metadata: "{resultExtractor: ResultExtractors.Text }"
1128
+ }, on = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}";
1129
+ function sn(e) {
1130
+ L(e, $t, en);
1131
+ }
1132
+ function cn(e) {
1133
+ L(e, tn, nn);
1134
+ }
1135
+ function ln(e, t, n = [], r = [], i) {
1136
+ return t.add({
1137
+ kind: o.Class,
1138
+ name: e,
1139
+ isExported: !0,
1140
+ typeParameters: r,
1141
+ extends: i,
1142
+ decorators: [{
1143
+ name: "api",
1144
+ arguments: n
1145
+ }]
1146
+ });
1147
+ }
1148
+ function un(e) {
1149
+ e.implements = [...[e.implements ?? []].flat(), "ApiMetadataCapable"], e.ctors ??= [], e.ctors.push({ parameters: [{
1150
+ name: "apiMetadata",
1151
+ type: "ApiMetadata",
1152
+ hasQuestionToken: !0,
1153
+ scope: a.Public,
1154
+ isReadonly: !0
1155
+ }] });
1156
+ }
1157
+ function dn(e) {
1158
+ return e === "delete" ? "del" : e;
1159
+ }
1160
+ var fn = "@ahoo-wang/fetcher-eventstream";
1161
+ function pn(e) {
1162
+ L(e, fn, ["JsonEventStreamResultExtractor", "JsonServerSentEventStream"]);
1163
+ }
1164
+ //#endregion
1165
+ //#region src/emitters/apiClients.ts
1166
+ function mn(e, t) {
1167
+ let n = t.modules.module(e.file);
1168
+ sn(n), cn(n), pn(n);
1169
+ let r = ln(e.className, n);
1170
+ R(r, [e.description]), un(r);
1171
+ let i = hn(e.className, n, t);
1172
+ for (let t of e.methods) (r.methods ??= []).push(gn(t, i));
1173
+ }
1174
+ function hn(e, t, n) {
1175
+ let r = {
1176
+ context: n.types,
1177
+ owner: { name: e },
1178
+ specifierOf: (e) => Tt(t, n.outputDir, e),
1179
+ imports: t.imports
1180
+ };
1181
+ return {
1182
+ module: t,
1183
+ resolveType(e) {
1184
+ let n = Jt(e, r);
1185
+ return t.imports.apply(n.imports), n.text;
1186
+ }
1187
+ };
1188
+ }
1189
+ function gn(e, t) {
1190
+ let n = [], r = [];
1191
+ for (let i of e.parameters) (i.required ? n : r).push({
1192
+ name: i.name,
1193
+ type: i.schema ? t.resolveType(i.schema) : "string",
1194
+ hasQuestionToken: !i.required,
1195
+ decorators: [{
1196
+ name: i.location,
1197
+ arguments: [P(i.parameterName)]
1198
+ }]
1199
+ });
1200
+ e.body && (e.body.required ? n : r).push({
1201
+ name: e.body.name,
1202
+ type: _n(e.body, t),
1203
+ hasQuestionToken: !e.body.required,
1204
+ decorators: [{
1205
+ name: "body",
1206
+ arguments: []
1207
+ }]
1208
+ });
1209
+ let i = [
1210
+ ...n,
1211
+ ...r,
1212
+ {
1213
+ name: "httpRequest",
1214
+ hasQuestionToken: !0,
1215
+ type: "ParameterRequest",
1216
+ decorators: [{
1217
+ name: "request",
1218
+ arguments: []
1219
+ }]
1220
+ },
1221
+ {
1222
+ name: "attributes",
1223
+ hasQuestionToken: !0,
1224
+ type: "Record<string, unknown>",
1225
+ decorators: [{
1226
+ name: "attribute",
1227
+ arguments: []
1228
+ }]
1229
+ }
1230
+ ], a = vn(e.returns, t), o = P(e.path), s = {
1231
+ name: e.name,
1232
+ decorators: [{
1233
+ name: dn(e.httpMethod),
1234
+ arguments: a.metadata ? [o, a.metadata] : [o]
1235
+ }],
1236
+ parameters: i,
1237
+ returnType: a.type,
1238
+ statements: [`throw autoGeneratedError(${i.map((e) => e.name).join(",")});`]
1239
+ };
1240
+ return R(s, [...e.docs]), s;
1241
+ }
1242
+ function _n(e, t) {
1243
+ let { content: n } = e;
1244
+ switch (n.kind) {
1245
+ case "json": {
1246
+ let e = t.resolveType(n.schema), r = n.optionalFields;
1247
+ return r.length === 0 || /[|&]/.test(e) || e === "any" ? e : (L(t.module, $t, ["PartialBy"]), `PartialBy<${e}, ${r.map(P).join(" | ")}>`);
1248
+ }
1249
+ case "formData": return "FormData";
1250
+ case "urlEncoded": return "URLSearchParams";
1251
+ case "text": return "string";
1252
+ case "binary": return "BodyInit";
1253
+ }
1254
+ }
1255
+ function vn(e, t) {
1256
+ switch (e.kind) {
1257
+ case "json": {
1258
+ let n = t.resolveType(e.schema);
1259
+ return e.wildcard && n === "string" ? an : { type: `Promise<${n}>` };
1260
+ }
1261
+ case "eventStream": {
1262
+ if (!e.items) return {
1263
+ type: "Promise<JsonServerSentEventStream<any>>",
1264
+ metadata: on
1265
+ };
1266
+ let n = t.resolveType(e.items);
1267
+ return {
1268
+ type: `Promise<JsonServerSentEventStream<${e.serverSentEvent ? `${n}['data']` : n}>>`,
1269
+ metadata: on
1270
+ };
1271
+ }
1272
+ case "text": return an;
1273
+ case "response": return rn;
1274
+ }
1275
+ }
1276
+ //#endregion
1277
+ //#region src/emitters/models.ts
1278
+ function yn(e) {
1279
+ return Rt(e, {
1280
+ ofKey: (e) => F(e),
1281
+ ofReference: ut
1282
+ });
1283
+ }
1284
+ function bn(e, t) {
1285
+ new Sn(e, t.modules.module(e.file), t).write();
1286
+ }
1287
+ function xn(e) {
1288
+ let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
1289
+ for (let r of e) {
1290
+ let e = at(r), i = [e];
1291
+ /^\d/.test(r) || i.push(r);
1292
+ let a = i.find((e) => !t.has(e));
1293
+ for (let n = 2; a === void 0; n++) t.has(`${e}_${n}`) || (a = `${e}_${n}`);
1294
+ t.add(a), n.set(r, N(a));
1295
+ }
1296
+ return n;
1297
+ }
1298
+ var Sn = class {
1299
+ model;
1300
+ module;
1301
+ target;
1302
+ modelInfo;
1303
+ components;
1304
+ constructor(e, t, n) {
1305
+ this.model = e, this.module = t, this.target = n, this.modelInfo = e.info, this.components = n.types.components, this.scope = {
1306
+ context: n.types,
1307
+ owner: e.info,
1308
+ specifierOf: (e) => Tt(t, n.outputDir, e),
1309
+ imports: t.imports
1310
+ };
1311
+ }
1312
+ write() {
1313
+ let e = this.process();
1314
+ e && At(e, this.model.schema, this.model.key, this.target.schemaDocs === "full");
1315
+ }
1316
+ process() {
1317
+ let { schema: e } = this.model;
1318
+ return _(e) ? this.processTypeAlias(e) : C(e) ? this.processEnum(e) : e.const !== void 0 || e.nullable && e.type || w(e) && (e.type || e.properties || e.required) ? this.processTypeAlias(e) : Pe(e) ? this.processInterface(e) : T(e) && typeof e.additionalProperties == "object" && !E(e) && !e.required?.length ? this.processIndexSignature(e) : Fe(e) ? this.processArray(e) : w(e) ? this.processComposition(e) : this.processTypeAlias(e);
1319
+ }
1320
+ scope;
1321
+ emit(e) {
1322
+ return this.module.imports.apply(e.imports), e.text;
1323
+ }
1324
+ resolveType(e) {
1325
+ return this.emit(Jt(e, this.scope));
1326
+ }
1327
+ processEnum(e) {
1328
+ let t = Ne(e);
1329
+ if (t) {
1330
+ let e = xn(Object.keys(t));
1331
+ this.module.add({
1332
+ kind: o.Enum,
1333
+ name: this.modelInfo.name + "EnumText",
1334
+ isExported: !0,
1335
+ members: [...e].map(([e, n]) => ({
1336
+ name: n,
1337
+ initializer: V(t[e])
1338
+ }))
1339
+ });
1340
+ }
1341
+ let n = [...new Set(e.enum.filter((e) => typeof e == "string"))], r = xn(n);
1342
+ return w(e) || e.const !== void 0 || e.type !== void 0 && e.type !== "string" || e.enum.some((e) => typeof e != "string") ? (n.length && this.module.add({
1343
+ kind: o.VariableStatement,
1344
+ declarationKind: c.Const,
1345
+ isExported: !0,
1346
+ declarations: [{
1347
+ name: this.modelInfo.name,
1348
+ initializer: (e) => {
1349
+ e.inlineBlock(() => {
1350
+ for (let t of n) e.write(`${r.get(t)}: `).quote(t).write(",").newLine();
1351
+ }), e.write(" as const");
1352
+ }
1353
+ }]
1354
+ }), this.processTypeAlias(e)) : this.module.add({
1355
+ kind: o.Enum,
1356
+ name: this.modelInfo.name,
1357
+ isExported: !0,
1358
+ members: n.map((e) => ({
1359
+ name: r.get(e),
1360
+ initializer: V(e)
1361
+ }))
1362
+ });
1363
+ }
1364
+ addPropertyToInterface(e, t, n) {
1365
+ let r = {
1366
+ name: N(t),
1367
+ type: this.resolveType(n),
1368
+ isReadonly: Ve(n)
1369
+ };
1370
+ (e.properties ??= []).push(r), kt(r, n);
1371
+ }
1372
+ processInterface(e) {
1373
+ if (Wt(e, this.components)) return this.processTypeAlias(e);
1374
+ let t = [], n = this.module.add({
1375
+ kind: o.Interface,
1376
+ name: this.modelInfo.name,
1377
+ isExported: !0,
1378
+ properties: t
1379
+ }), r = e.properties || {};
1380
+ Object.entries(r).forEach(([e, t]) => {
1381
+ this.addPropertyToInterface(n, e, t);
1382
+ });
1383
+ for (let n of e.required ?? []) Object.hasOwn(r, n) || t.push({
1384
+ name: N(n),
1385
+ type: this.emit(Zt(e, this.scope))
1386
+ });
1387
+ return this.emit(Yt(e, this.scope)) && t.push(Ct(this.emit(Xt(e, this.scope)), ["Additional properties"])), n;
1388
+ }
1389
+ processArray(e) {
1390
+ let t = this.resolveType(e.items);
1391
+ return this.module.add({
1392
+ kind: o.TypeAlias,
1393
+ name: this.modelInfo.name,
1394
+ type: ze(t),
1395
+ isExported: !0
1396
+ });
1397
+ }
1398
+ processIndexSignature(e) {
1399
+ return this.module.add({
1400
+ kind: o.Interface,
1401
+ name: this.modelInfo.name,
1402
+ isExported: !0,
1403
+ properties: [Ct(this.emit(Qt(e, this.scope)))]
1404
+ });
1405
+ }
1406
+ processComposition(e) {
1407
+ return this.module.add({
1408
+ kind: o.TypeAlias,
1409
+ name: this.modelInfo.name,
1410
+ type: this.resolveType(e),
1411
+ isExported: !0
1412
+ });
1413
+ }
1414
+ processTypeAlias(e) {
1415
+ return this.module.add({
1416
+ kind: o.TypeAlias,
1417
+ name: this.modelInfo.name,
1418
+ type: this.resolveType(e),
1419
+ isExported: !0
1420
+ });
1421
+ }
1422
+ };
1423
+ //#endregion
1424
+ //#region src/emitters/emit.ts
1425
+ function Cn(e, t) {
1426
+ e.models.forEach((e) => bn(e, t)), e.apiClients.forEach((e) => mn(e, t));
1427
+ }
1428
+ //#endregion
1429
+ //#region src/emitters/indexFiles.ts
1430
+ function wn(e, t) {
1431
+ let n = [];
1432
+ return Tn(e, t, n), n;
1433
+ }
1434
+ function Tn(e, t, n) {
1435
+ let r = [];
1436
+ for (let t of e.getSourceFiles()) {
1437
+ let e = t.getBaseName();
1438
+ e.endsWith(".ts") && e !== "index.ts" && r.push({
1439
+ specifier: `./${t.getBaseNameWithoutExtension()}.js`,
1440
+ exports: Dn(t)
1441
+ });
1442
+ }
1443
+ for (let i of e.getDirectories()) {
1444
+ let e = Tn(i, t, n);
1445
+ e && r.push({
1446
+ specifier: `./${i.getBaseName()}/index.js`,
1447
+ exports: e
1448
+ });
1449
+ }
1450
+ let i = e.getPath();
1451
+ return r.length === 0 ? e.getProject().getSourceFile(`${i}/index.ts`) ? /* @__PURE__ */ new Map() : void 0 : En(i, r, t, n);
1452
+ }
1453
+ function En(e, t, n, r) {
1454
+ let i = /* @__PURE__ */ new Map();
1455
+ for (let e of t) for (let t of e.exports.keys()) i.set(t, [...i.get(t) ?? [], e.specifier]);
1456
+ let a = [...i].filter(([, e]) => e.length > 1).map(([e]) => e).sort();
1457
+ for (let t of a) r.push(`${t} is exported by both ${i.get(t).join(" and ")} in ${e}; its index leaves it out, so import it from its own module.`);
1458
+ let o = n(e);
1459
+ o.removeText();
1460
+ let s = /* @__PURE__ */ new Map();
1461
+ for (let e of t) {
1462
+ let t = [...e.exports].filter(([e]) => !a.includes(e)).sort(([e], [t]) => x(e, t));
1463
+ t.forEach(([e, t]) => s.set(e, t)), t.length === e.exports.size ? o.addExportDeclaration({ moduleSpecifier: e.specifier }) : t.length > 0 && o.addExportDeclaration({
1464
+ moduleSpecifier: e.specifier,
1465
+ namedExports: t.map(([e, t]) => ({
1466
+ name: e,
1467
+ isTypeOnly: t
1468
+ }))
1469
+ });
1470
+ }
1471
+ return o.getStatements().length === 0 && o.addStatements("export {};"), s;
1472
+ }
1473
+ function Dn(e) {
1474
+ let t = /* @__PURE__ */ new Map();
1475
+ for (let [r, i] of e.getExportedDeclarations()) t.set(r, i.every((e) => n.isInterfaceDeclaration(e) || n.isTypeAliasDeclaration(e)));
1476
+ return t;
1477
+ }
1478
+ //#endregion
1479
+ //#region src/finalize/typeOnlyImports.ts
1480
+ function On(e) {
1481
+ let t = e;
1482
+ for (let e = t.getParent(); e; t = e, e = e.getParent()) if (n.isQualifiedName(e)) {
1483
+ if (e.getLeft() !== t) return !1;
1484
+ } else if (n.isPropertyAccessExpression(e)) {
1485
+ if (e.getExpression() !== t) return !1;
1486
+ } else {
1487
+ if (n.isExpressionWithTypeArguments(e)) {
1488
+ let t = e.getParent(), r = t?.getParent();
1489
+ return !(n.isHeritageClause(t) && t.getToken() === s.ExtendsKeyword && (n.isClassDeclaration(r) || n.isClassExpression(r)));
1490
+ }
1491
+ return n.isTypeNode(e);
1492
+ }
1493
+ return !1;
1494
+ }
1495
+ function kn(e) {
1496
+ let t = e.getImportDeclarations().filter((e) => !e.getDefaultImport() && !e.getNamespaceImport() && e.getNamedImports().length > 0);
1497
+ if (t.length === 0) return [];
1498
+ let r = new Set(t.flatMap((e) => e.getNamedImports().map((e) => (e.getAliasNode() ?? e.getNameNode()).getText()))), i = /* @__PURE__ */ new Set();
1499
+ return e.forEachDescendant((e, t) => {
1500
+ if (n.isImportDeclaration(e)) t.skip();
1501
+ else if (n.isIdentifier(e) && r.has(e.getText()) && !On(e)) {
1502
+ let t = e.getSymbol();
1503
+ t && i.add(t.compilerSymbol);
1504
+ }
1505
+ }), t.map((e) => An(e, (e) => {
1506
+ let t = e.getSymbol();
1507
+ return !!t && !i.has(t.compilerSymbol);
1508
+ }));
1509
+ }
1510
+ function An(e, t) {
1511
+ let n = e.getNamedImports(), r = n.map(t), i = r.every(Boolean);
1512
+ return () => {
1513
+ n.forEach((e, t) => {
1514
+ let n = !i && r[t];
1515
+ e.isTypeOnly() !== n && e.setIsTypeOnly(n);
1516
+ }), e.isTypeOnly() !== i && e.setIsTypeOnly(i);
1517
+ };
1518
+ }
1519
+ function jn(e) {
1520
+ let t = e.flatMap(kn);
1521
+ for (let e of t) e();
1522
+ }
1523
+ //#endregion
1524
+ //#region src/finalize/verification.ts
1525
+ var Mn = /* @__PURE__ */ new Set([
1526
+ 2300,
1527
+ 2304,
1528
+ 2308,
1529
+ 2393,
1530
+ 2451,
1531
+ 2456,
1532
+ 2503,
1533
+ 2552
1534
+ ]);
1535
+ function Nn(e) {
1536
+ let t = [];
1537
+ for (let n of e) for (let e of n.getPreEmitDiagnostics()) {
1538
+ if (!Mn.has(e.getCode()) || e.getSourceFile() !== n) continue;
1539
+ let r = l.flattenDiagnosticMessageText(e.compilerObject.messageText, " ");
1540
+ t.push(`${n.getFilePath()}:${e.getLineNumber() ?? 0} TS${e.getCode()} ${r}`);
1541
+ }
1542
+ if (t.length > 0) throw Error(`The generated code does not compile; nothing was written. This is a wow-generator bug:\n${t.join("\n")}`);
1543
+ }
1544
+ //#endregion
1545
+ //#region src/finalize/finalize.ts
1546
+ var Pn = "// Code generated by wow-generator. DO NOT EDIT.\n\n", Fn = {
1547
+ indentSize: 2,
1548
+ tabSize: 2,
1549
+ convertTabsToSpaces: !0,
1550
+ semicolons: "insert",
1551
+ insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: !0
1552
+ };
1553
+ function In(e, t) {
1554
+ e.forEach((n, r) => {
1555
+ t.debug(`Optimizing file [${n.getFilePath()}] - ${r + 1}/${e.length}`), n.formatText(Fn), n.organizeImports(Fn);
1556
+ }), jn(e), Nn(e);
1557
+ for (let t of e) t.insertText(0, Pn);
1558
+ }
1559
+ //#endregion
1560
+ //#region src/input/resources.ts
1561
+ var Ln = 3e4;
1562
+ function Rn(e) {
1563
+ return /^https?:\/\//i.test(e);
1564
+ }
1565
+ function zn(e, t = {}) {
1566
+ return Rn(e) ? Bn(e, t) : Hn(e);
1567
+ }
1568
+ async function Bn(e, t = {}) {
1569
+ let n = t.timeoutMs ?? 3e4, r;
1570
+ try {
1571
+ let i = AbortSignal.timeout(n);
1572
+ r = await fetch(e, {
1573
+ headers: t.headers,
1574
+ signal: t.signal ? AbortSignal.any([t.signal, i]) : i
1575
+ });
1576
+ } catch (e) {
1577
+ let t = e instanceof Error && e.name === "TimeoutError" ? `no response within ${n} ms` : Vn(e);
1578
+ throw Error(t, { cause: e });
1579
+ }
1580
+ if (!r.ok) {
1581
+ let e = [r.status, r.statusText].filter(Boolean).join(" ");
1582
+ throw Error(`HTTP ${e}`);
1583
+ }
1584
+ return await r.text();
1585
+ }
1586
+ function Vn(e) {
1587
+ if (!(e instanceof Error)) return String(e);
1588
+ let t = e.cause;
1589
+ return t instanceof Error && t.message ? `${e.message} (${t.message})` : e.message;
1590
+ }
1591
+ function Hn(e) {
1592
+ return new Promise((t, n) => {
1593
+ te(e, "utf-8", (e, r) => {
1594
+ e ? n(e) : t(r);
1595
+ });
1596
+ });
1597
+ }
1598
+ //#endregion
1599
+ //#region src/input/parsers.ts
1600
+ async function Un(e, t) {
1601
+ let n;
1602
+ try {
1603
+ n = await zn(e, t);
1604
+ } catch (t) {
1605
+ throw new h("input", `Cannot read the OpenAPI document ${e}: ${g(t)}`, { cause: t });
1606
+ }
1607
+ try {
1608
+ return Gn(n);
1609
+ } catch (t) {
1610
+ throw new h("input", `Cannot parse the OpenAPI document ${e}: ${g(t)}`, { cause: t });
1611
+ }
1612
+ }
1613
+ function Wn(e, t) {
1614
+ if (typeof e != "object" || !e || Array.isArray(e)) throw new h("input", `${t} is not an OpenAPI document: expected an object at the top level.`);
1615
+ let n = e;
1616
+ if (n.swagger !== void 0) throw new h("input", `${t} is a Swagger ${String(n.swagger)} document; wow-generator reads OpenAPI 3.x only. Convert it first, for example with swagger2openapi.`);
1617
+ if (typeof n.openapi != "string" || !/^3\.\d+/.test(n.openapi)) throw new h("input", `${t} is not an OpenAPI 3.x document: its "openapi" field is ${n.openapi === void 0 ? "missing" : JSON.stringify(n.openapi)}.`);
1618
+ if (typeof n.info != "object" || n.info === null || Array.isArray(n.info)) throw new h("input", `${t} is not a valid OpenAPI document: its "info" object is missing.`);
1619
+ return {
1620
+ ...n,
1621
+ paths: n.paths ?? {}
1622
+ };
1623
+ }
1624
+ function Gn(e) {
1625
+ switch (Kn(e)) {
1626
+ case "json": return JSON.parse(e);
1627
+ case "yaml": return ee(e);
1628
+ }
1629
+ }
1630
+ function Kn(e) {
1631
+ let t = e.trimStart();
1632
+ if (t.startsWith("{") || t.startsWith("[")) return "json";
1633
+ if (t.startsWith("-") || t.startsWith("%YAML")) return "yaml";
1634
+ try {
1635
+ return JSON.parse(t), "json";
1636
+ } catch {
1637
+ if (t.length > 0) return "yaml";
1638
+ }
1639
+ throw Error("Unable to infer file format");
1640
+ }
1641
+ //#endregion
1642
+ //#region src/input/configuration.ts
1643
+ async function qn(e, t, n) {
1644
+ if (e !== void 0) return {
1645
+ ...await Xn({
1646
+ path: e,
1647
+ explicit: !0
1648
+ }, t, n),
1649
+ origin: U(e)
1650
+ };
1651
+ let r = await Xn({
1652
+ path: re,
1653
+ explicit: !1
1654
+ }, t, n);
1655
+ return r === void 0 ? (t.debug("No configuration file found, generating with defaults"), {
1656
+ config: {},
1657
+ warnings: []
1658
+ }) : {
1659
+ ...r,
1660
+ origin: U(re)
1661
+ };
1662
+ }
1663
+ var Jn = ["apiClients"], Yn = ["ignorePathParameters", "methodNames"];
1664
+ async function Xn(e, t, n) {
1665
+ let r = U(e.path);
1666
+ t.debug(`Reading configuration: ${r}`);
1667
+ let i;
1668
+ try {
1669
+ i = await zn(e.path, n);
1670
+ } catch (n) {
1671
+ if (!e.explicit && Zn(n)) {
1672
+ t.debug(`No configuration file at ${r}`);
1673
+ return;
1674
+ }
1675
+ throw new h("configuration", `Cannot read configuration ${r}: ${g(n)}`, { cause: n });
1676
+ }
1677
+ if (!i.trim()) return {
1678
+ config: {},
1679
+ warnings: [`Configuration ${r} is empty, generating with defaults`]
1680
+ };
1681
+ let a;
1682
+ try {
1683
+ a = Gn(i);
1684
+ } catch (e) {
1685
+ throw new h("configuration", `Cannot parse configuration ${r}: ${g(e)}`, { cause: e });
1686
+ }
1687
+ let o = $n(a, r);
1688
+ return t.debug(`Configuration loaded from ${r}: ${tr(o.config)}`), o;
1689
+ }
1690
+ function U(e) {
1691
+ return Rn(e) || u(e) ? e : p(e);
1692
+ }
1693
+ function Zn(e) {
1694
+ return typeof e == "object" && !!e && e.code === "ENOENT";
1695
+ }
1696
+ function W(e) {
1697
+ return e === null ? "null" : Array.isArray(e) ? "an array" : `a ${typeof e}`;
1698
+ }
1699
+ function G(e) {
1700
+ return typeof e == "object" && !!e && !Array.isArray(e);
1701
+ }
1702
+ function Qn(e, t, n, r, i) {
1703
+ let a = Object.keys(r).filter((e) => !i.includes(e));
1704
+ a.length && e.push(`Ignoring unknown ${n} option(s) in ${t}: ${a.join(", ")}. Known option(s): ${i.join(", ")}`);
1705
+ }
1706
+ function $n(e, t) {
1707
+ if (!G(e)) throw new h("configuration", `Configuration ${t} must be a JSON or YAML object, found ${W(e)}`);
1708
+ let n = [];
1709
+ return Qn(n, t, "configuration", e, Jn), er(e.apiClients, t, n), {
1710
+ config: e,
1711
+ warnings: n
1712
+ };
1713
+ }
1714
+ function er(e, t, n) {
1715
+ if (e !== void 0) {
1716
+ if (!G(e)) throw new h("configuration", `apiClients in ${t} must be an object keyed by tag name, found ${W(e)}`);
1717
+ for (let [r, i] of Object.entries(e)) {
1718
+ if (!G(i)) throw new h("configuration", `apiClients["${r}"] in ${t} must be an object, found ${W(i)}`);
1719
+ Qn(n, t, `apiClients["${r}"]`, i, Yn);
1720
+ let { ignorePathParameters: e } = i;
1721
+ if (e !== void 0 && !(Array.isArray(e) && e.every((e) => typeof e == "string"))) throw new h("configuration", `apiClients["${r}"].ignorePathParameters in ${t} must be an array of strings, found ${W(e)}`);
1722
+ let { methodNames: a } = i;
1723
+ if (a !== void 0) {
1724
+ if (!G(a)) throw new h("configuration", `apiClients["${r}"].methodNames in ${t} must be an object mapping operationIds to method names, found ${W(a)}`);
1725
+ for (let [e, n] of Object.entries(a)) if (typeof n != "string" || !O(n)) throw new h("configuration", `apiClients["${r}"].methodNames["${e}"] in ${t} must be a valid method name, found ${JSON.stringify(n)}`);
1726
+ }
1727
+ }
1728
+ }
1729
+ }
1730
+ function tr(e) {
1731
+ let t = Object.keys(e.apiClients ?? {});
1732
+ return `apiClients=${t.length ? t.join(", ") : "none"}`;
1733
+ }
1734
+ var nr = "#/$defs/";
1735
+ function K(e) {
1736
+ return e.startsWith(nr) ? e.slice(8) : void 0;
1737
+ }
1738
+ function rr(e) {
1739
+ if (typeof e != "object" || !e) return !1;
1740
+ let t = e;
1741
+ return t.openapi === void 0 && t.swagger === void 0 && typeof t.format == "number" && Array.isArray(t.contexts);
1742
+ }
1743
+ function q(e) {
1744
+ return typeof e == "object" && !!e && !Array.isArray(e);
1745
+ }
1746
+ function ir(e, t) {
1747
+ let n = e;
1748
+ if (n.format !== 1) throw new h("input", `${t} is a Wow Manifest of format ${n.format}; wow-generator reads format 1.`);
1749
+ let r = [];
1750
+ if (n.contexts.forEach((e, t) => {
1751
+ !q(e) || typeof e.name != "string" ? r.push(`contexts[${t}] has no name`) : (e.aggregates ?? []).forEach((t, n) => {
1752
+ let i = `${e.name}.aggregates[${n}]`;
1753
+ !q(t) || typeof t.name != "string" ? r.push(`${i} has no name`) : !q(t.state) || typeof t.state.schema != "string" ? r.push(`${e.name}.${t.name} has no state schema`) : ((t.commands ?? []).forEach((n) => {
1754
+ (typeof n?.name != "string" || typeof n.schema != "string") && r.push(`a command of ${e.name}.${t.name} has no name or schema`);
1755
+ }), (t.events ?? []).forEach((n) => {
1756
+ (typeof n?.name != "string" || typeof n.schema != "string") && r.push(`an event of ${e.name}.${t.name} has no name or schema`);
1757
+ }));
1758
+ });
1759
+ }), n.$defs !== void 0 && !q(n.$defs) && r.push("$defs is not an object"), r.length > 0) throw new h("specification", `${t} is not a Manifest wow-generator can read: ${r.join("; ")}.`);
1760
+ return n;
1761
+ }
1762
+ //#endregion
1763
+ //#region src/manifest/analyze.ts
1764
+ var ar = /* @__PURE__ */ new Set([
1765
+ "int64",
1766
+ "bigint",
1767
+ "decimal"
1768
+ ]), or = {
1769
+ "wow.lifecycle.TransferOwner": "TransferOwner",
1770
+ "wow.lifecycle.TransferSpace": "TransferSpace",
1771
+ "wow.lifecycle.ApplyTags": "ApplyTags"
1772
+ }, sr = /* @__PURE__ */ new Set([
1773
+ "wow.lifecycle.DeleteAggregate",
1774
+ "wow.lifecycle.RestoreAggregate",
1775
+ "wow.lifecycle.TransferOwner",
1776
+ "wow.lifecycle.TransferSpace",
1777
+ "wow.lifecycle.ApplyTags"
1778
+ ]), cr = 4;
1779
+ function J(e) {
1780
+ return typeof e == "object" && !!e && !Array.isArray(e);
1781
+ }
1782
+ function Y(e) {
1783
+ let t = e.type;
1784
+ return typeof t == "string" ? [t] : Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
1785
+ }
1786
+ function lr(e, t) {
1787
+ let n = [...new Set(e)];
1788
+ return n.length === 1 ? n[0] : n.map((e) => / [|&] /.test(e) && !e.startsWith("{") ? `(${e})` : e).join(t);
1789
+ }
1790
+ function ur(e) {
1791
+ return typeof e == "string" ? P(e) : JSON.stringify(e);
1792
+ }
1793
+ var dr = class {
1794
+ defs;
1795
+ names = /* @__PURE__ */ new Map();
1796
+ warnings = [];
1797
+ constructor(e) {
1798
+ this.defs = e;
1799
+ }
1800
+ inlined(e) {
1801
+ return e.includes("(");
1802
+ }
1803
+ name(e) {
1804
+ let t = new Set(e);
1805
+ for (let e = 0; t.size > 0; e++) {
1806
+ let n = /* @__PURE__ */ new Map();
1807
+ for (let r of t.keys()) {
1808
+ let t = r.split("."), i = t[t.length - 1].split("$"), a = k([...t.slice(Math.max(0, t.length - 1 - e), t.length - 1), ...i].map((e) => /^[a-z]/.test(e) ? A(e) : e));
1809
+ n.set(a, [...n.get(a) ?? [], r]);
1810
+ }
1811
+ let r = new Set(this.names.values());
1812
+ for (let [i, a] of n) {
1813
+ let n = a.filter((t) => t.split(".").length - 1 <= e), o = a.length === 1 && !r.has(i) ? a : n;
1814
+ for (let e of o) {
1815
+ let n = i;
1816
+ for (let e = 2; r.has(n); e++) n = `${i}${e}`;
1817
+ r.add(n), this.names.set(e, n), t.delete(e);
1818
+ }
1819
+ }
1820
+ }
1821
+ }
1822
+ schemaOf(e) {
1823
+ let t = this.defs[e];
1824
+ return J(t) ? t : void 0;
1825
+ }
1826
+ resolve(e, t = /* @__PURE__ */ new Set()) {
1827
+ let n = e.$ref;
1828
+ if (typeof n != "string") return e;
1829
+ let r = K(n);
1830
+ if (r === void 0 || t.has(r)) return e;
1831
+ let i = this.schemaOf(r);
1832
+ return i ? this.resolve(i, /* @__PURE__ */ new Set([...t, r])) : e;
1833
+ }
1834
+ references(e, t = /* @__PURE__ */ new Set()) {
1835
+ if (Array.isArray(e)) e.forEach((e) => this.references(e, t));
1836
+ else if (J(e)) for (let [n, r] of Object.entries(e)) if (n === "$ref" && typeof r == "string") {
1837
+ let e = K(r);
1838
+ e !== void 0 && t.add(e);
1839
+ } else n !== "enum" && n !== "const" && this.references(r, t);
1840
+ return t;
1841
+ }
1842
+ namedReferences(e) {
1843
+ let t = /* @__PURE__ */ new Set();
1844
+ for (let n of this.references(e)) {
1845
+ let e = this.schemaOf(n);
1846
+ e !== void 0 && this.inlined(n) ? this.namedReferences(e).forEach((e) => t.add(e)) : t.add(n);
1847
+ }
1848
+ return t;
1849
+ }
1850
+ closure(e) {
1851
+ let t = /* @__PURE__ */ new Set(), n = [...e];
1852
+ for (; n.length > 0;) {
1853
+ let e = n.pop();
1854
+ if (t.has(e)) continue;
1855
+ t.add(e);
1856
+ let r = this.schemaOf(e);
1857
+ r && n.push(...this.references(r));
1858
+ }
1859
+ return [...t];
1860
+ }
1861
+ refType(e, t) {
1862
+ let n = this.schemaOf(e);
1863
+ if (n !== void 0 && this.inlined(e)) return this.type(n, t);
1864
+ let r = this.names.get(e);
1865
+ return r !== void 0 && this.schemaOf(e) ? r : (this.warnings.push(`${t} refers to the schema ${e}, which the Manifest's $defs does not hold; it is typed as unknown.`), "unknown");
1866
+ }
1867
+ type(e, t) {
1868
+ if (e === !0 || e === void 0) return "unknown";
1869
+ if (e === !1) return "never";
1870
+ if (!J(e)) return "unknown";
1871
+ if (typeof e.$ref == "string") {
1872
+ let n = K(e.$ref);
1873
+ return n === void 0 ? "unknown" : this.refType(n, t);
1874
+ }
1875
+ if ("const" in e) return ur(e.const);
1876
+ if (Array.isArray(e.enum)) return e.enum.length === 0 ? "never" : lr(e.enum.map(ur), " | ");
1877
+ for (let [n, r] of [
1878
+ ["oneOf", " | "],
1879
+ ["anyOf", " | "],
1880
+ ["allOf", " & "]
1881
+ ]) {
1882
+ let i = e[n];
1883
+ if (Array.isArray(i) && i.length > 0) return lr(i.map((e) => this.type(e, t)), r);
1884
+ }
1885
+ let n = Y(e);
1886
+ return n.length === 0 ? J(e.properties) ? this.objectType(e, t) : "unknown" : lr(n.map((n) => this.primitive(n, e, t)), " | ");
1887
+ }
1888
+ primitive(e, t, n) {
1889
+ switch (e) {
1890
+ case "string": return "string";
1891
+ case "integer":
1892
+ case "number": return typeof t.format == "string" && ar.has(t.format) ? "string" : "number";
1893
+ case "boolean": return "boolean";
1894
+ case "null": return "null";
1895
+ case "array": {
1896
+ let e = t.items === void 0 ? "unknown" : this.type(t.items, n);
1897
+ return / [|&] /.test(e) ? `(${e})[]` : `${e}[]`;
1898
+ }
1899
+ case "object": return this.objectType(t, n);
1900
+ default: return "unknown";
1901
+ }
1902
+ }
1903
+ objectType(e, t) {
1904
+ let n = this.properties(e, t), r = this.additional(e, t);
1905
+ if (n.length === 0) return `Record<string, ${r ?? "unknown"}>`;
1906
+ let i = n.map((e) => `${e.name}${e.optional ? "?" : ""}: ${e.type}`);
1907
+ return r !== void 0 && i.push("[key: string]: unknown"), `{ ${i.join("; ")} }`;
1908
+ }
1909
+ properties(e, t) {
1910
+ if (!J(e.properties)) return [];
1911
+ let n = new Set(Array.isArray(e.required) ? e.required : []);
1912
+ return Object.entries(e.properties).map(([e, r]) => {
1913
+ let i = J(r) ? r.description : void 0;
1914
+ return {
1915
+ name: N(e),
1916
+ type: this.type(r, `${t}.${e}`),
1917
+ optional: !n.has(e),
1918
+ ...typeof i == "string" ? { description: i } : {}
1919
+ };
1920
+ });
1921
+ }
1922
+ additional(e, t) {
1923
+ let n = e.additionalProperties;
1924
+ if (n !== void 0 && n !== !1) return this.type(n, t);
1925
+ }
1926
+ isInterface(e) {
1927
+ let t = Y(e);
1928
+ return J(e.properties) && (t.length === 0 || t.length === 1 && t[0] === "object") && e.$ref === void 0 && e.allOf === void 0 && e.oneOf === void 0 && e.anyOf === void 0;
1929
+ }
1930
+ textNumbers(e, t = /* @__PURE__ */ new Set()) {
1931
+ if (!J(e)) return;
1932
+ let n = typeof e.$ref == "string" ? K(e.$ref) : void 0;
1933
+ if (n !== void 0) {
1934
+ let e = this.schemaOf(n);
1935
+ return t.has(n) || e === void 0 ? void 0 : this.textNumbers(e, /* @__PURE__ */ new Set([...t, n]));
1936
+ }
1937
+ let r = [
1938
+ "oneOf",
1939
+ "anyOf",
1940
+ "allOf"
1941
+ ].flatMap((t) => Array.isArray(e[t]) ? e[t] : []).map((e) => this.textNumbers(e, t)).filter((e) => e !== void 0), i = Y(e);
1942
+ (i.includes("integer") || i.includes("number")) && typeof e.format == "string" && ar.has(e.format) && r.push(!0);
1943
+ let a = {};
1944
+ if (J(e.properties)) for (let [n, r] of Object.entries(e.properties)) {
1945
+ let e = this.textNumbers(r, t);
1946
+ e !== void 0 && (a[n] = e);
1947
+ }
1948
+ let o = this.textNumbers(e.items, t) ?? this.textNumbers(e.additionalProperties, t);
1949
+ return o !== void 0 && (a["*"] = o), Object.keys(a).length > 0 && r.push(a), fr(r);
1950
+ }
1951
+ fields(e, t, n = 1, r = /* @__PURE__ */ new Set()) {
1952
+ let i = this.resolve(e), a = typeof e.$ref == "string" ? K(e.$ref) : void 0;
1953
+ if (a !== void 0 && r.has(a)) return [];
1954
+ let o = a === void 0 ? r : /* @__PURE__ */ new Set([...r, a]);
1955
+ if (!J(i.properties)) return [];
1956
+ let s = [];
1957
+ for (let [e, r] of Object.entries(i.properties)) {
1958
+ let i = `${t}.${e}`;
1959
+ s.push(i), n < cr && J(r) && (Y(this.resolve(r)).includes("array") || s.push(...this.fields(r, i, n + 1, o)));
1960
+ }
1961
+ return s;
1962
+ }
1963
+ };
1964
+ function fr(e) {
1965
+ if (e.length === 0) return;
1966
+ let t = e.filter((e) => e !== !0);
1967
+ if (t.length === 0) return !0;
1968
+ let n = {};
1969
+ for (let e of t) for (let [t, r] of Object.entries(e)) (n[t] ??= []).push(r);
1970
+ return Object.fromEntries(Object.entries(n).map(([e, t]) => [e, fr(t)]));
1971
+ }
1972
+ function pr(e, t) {
1973
+ if (t === void 0) return !0;
1974
+ let n = e.resolve(t);
1975
+ return !Array.isArray(n.required) || n.required.length === 0;
1976
+ }
1977
+ function mr(e, t) {
1978
+ return [
1979
+ t.state.schema,
1980
+ ...(t.commands ?? []).map((e) => e.schema),
1981
+ ...(t.events ?? []).map((e) => e.schema)
1982
+ ].map(K).filter((e) => e !== void 0).concat(hr(e, t));
1983
+ }
1984
+ function hr(e, t) {
1985
+ return (t.lifecycle ?? []).filter((t) => or[t] !== void 0 && e.schemaOf(t));
1986
+ }
1987
+ function gr(e) {
1988
+ let t = new dr(e.$defs ?? {}), n = e.contexts, r = /* @__PURE__ */ new Map();
1989
+ for (let e of n) {
1990
+ let n = (e.aggregates ?? []).flatMap((e) => mr(t, e));
1991
+ for (let i of t.closure(n).sort(x)) r.has(i) || r.set(i, e.name);
1992
+ }
1993
+ let i = [...r.keys()].filter((e) => t.schemaOf(e) && !t.inlined(e));
1994
+ t.name([...i].sort(x));
1995
+ let a = i.map((e) => _r(t, e, `${r.get(e)}/types.ts`)).sort((e, t) => x(e.file, t.file) || x(e.name, t.name)), o = n.map((e) => vr(t, e));
1996
+ return {
1997
+ model: {
1998
+ ...e.service?.name ? { service: e.service.name } : {},
1999
+ types: a,
2000
+ contexts: o
2001
+ },
2002
+ warnings: [...new Set(t.warnings)]
2003
+ };
2004
+ }
2005
+ function _r(e, t, n) {
2006
+ let r = e.schemaOf(t), i = e.names.get(t), a = typeof r.description == "string" ? r.description : void 0, o = [...e.namedReferences(r)].map((t) => e.names.get(t)).filter((e) => e !== void 0 && e !== i), s = {
2007
+ key: t,
2008
+ name: i,
2009
+ file: n,
2010
+ ...a === void 0 ? {} : { description: a },
2011
+ references: [...new Set(o)].sort(x)
2012
+ };
2013
+ if (e.isInterface(r)) {
2014
+ let n = e.additional(r, t);
2015
+ return {
2016
+ ...s,
2017
+ properties: e.properties(r, t),
2018
+ ...n === void 0 ? {} : { type: "unknown" }
2019
+ };
2020
+ }
2021
+ return {
2022
+ ...s,
2023
+ type: e.type(r, t)
2024
+ };
2025
+ }
2026
+ function vr(e, t) {
2027
+ let n = `${t.name}.`;
2028
+ return {
2029
+ name: t.name,
2030
+ ...t.description ? { description: t.description } : {},
2031
+ typeName: k(A(t.name)),
2032
+ constantName: M(t.name),
2033
+ directory: t.name,
2034
+ errors: (t.errors ?? []).map((e) => ({
2035
+ member: M((e.code.startsWith(n) ? e.code.slice(n.length) : e.code).split(/[^A-Za-z0-9]+/)) || "ERROR",
2036
+ code: e.code,
2037
+ status: e.status,
2038
+ ...e.description ? { description: e.description } : {}
2039
+ })),
2040
+ subscriptions: [...new Set((t.subscriptions ?? []).map((e) => e.name))].sort(x),
2041
+ aggregates: (t.aggregates ?? []).map((n) => br(e, t, n))
2042
+ };
2043
+ }
2044
+ function yr(e, t, n) {
2045
+ let r = K(t);
2046
+ return r === void 0 ? "unknown" : e.refType(r, n);
2047
+ }
2048
+ function br(e, t, n) {
2049
+ let r = `${t.name}.${n.name}`, i = k(A(n.name)), a = new Set(hr(e, n)), o = (n.lifecycle ?? []).filter((e) => sr.has(e)).map((t) => {
2050
+ let n = t.split(".").pop(), i = e.schemaOf(t)?.description;
2051
+ return {
2052
+ name: t,
2053
+ member: M(n),
2054
+ method: et(j(n)),
2055
+ ...a.has(t) ? {
2056
+ bodyType: e.refType(t, r),
2057
+ bodyGenerated: !0
2058
+ } : or[t] ? { bodyType: or[t] } : {},
2059
+ ...typeof i == "string" ? { description: i } : {}
2060
+ };
2061
+ }), s = new Set(o.map((e) => e.method)), c = (n.commands ?? []).map((t) => {
2062
+ let n = et(j(t.name));
2063
+ (s.has(n) || n === "gateway") && (n = `${n}Command`), s.add(n);
2064
+ let i = M(t.name), a = (t.routes ?? []).filter((e) => e.method === "POST"), o = a.find((e) => e.path.includes("{id}")), c = a.find((e) => !e.path.includes("{id}")), l = K(t.schema);
2065
+ return {
2066
+ name: t.name,
2067
+ method: n,
2068
+ ...o ? { byIdPath: {
2069
+ member: i,
2070
+ path: o.path
2071
+ } } : {},
2072
+ ...c ? { unaddressedPath: {
2073
+ member: o ? `${i}_WITHOUT_ID` : i,
2074
+ path: c.path
2075
+ } } : {},
2076
+ bodyType: yr(e, t.schema, `${r}.${t.name}`),
2077
+ bodyOptional: pr(e, l === void 0 ? void 0 : e.schemaOf(l)),
2078
+ creation: t.creation ?? "NONE",
2079
+ mounted: t.mounted ?? !1,
2080
+ produces: t.produces ?? [],
2081
+ ...t.description ? { description: t.description } : {},
2082
+ ...e.textNumbers({ $ref: t.schema }) === void 0 ? {} : { bodyNumbers: !0 }
2083
+ };
2084
+ }), l = e.textNumbers({ $ref: n.state.schema }), u = Object.fromEntries((n.events ?? []).flatMap((r) => {
2085
+ let i = e.textNumbers({ $ref: r.schema });
2086
+ return i === void 0 ? [] : [[xr(t, n, r.name), i]];
2087
+ })), d = Object.fromEntries((n.commands ?? []).flatMap((t) => {
2088
+ let n = e.textNumbers({ $ref: t.schema });
2089
+ return n === void 0 ? [] : [[t.name, n]];
2090
+ })), f = {
2091
+ ...l === void 0 ? {} : { state: l },
2092
+ ...Object.keys(u).length === 0 ? {} : { events: u },
2093
+ ...Object.keys(d).length === 0 ? {} : { commands: d }
2094
+ }, p = K(n.state.schema), m = p === void 0 ? void 0 : e.schemaOf(p);
2095
+ return {
2096
+ context: t.name,
2097
+ name: n.name,
2098
+ ...n.description ? { description: n.description } : {},
2099
+ typeName: i,
2100
+ directory: `${t.name}/${n.name}`,
2101
+ ownership: n.ownership ?? "OWNER",
2102
+ snapshot: n.snapshot?.enabled ?? !0,
2103
+ stateType: yr(e, n.state.schema, `${r} state`),
2104
+ stateFields: m === void 0 ? [] : e.fields({ $ref: n.state.schema }, "state"),
2105
+ commands: c,
2106
+ events: (n.events ?? []).map((i) => ({
2107
+ name: i.name,
2108
+ wireName: xr(t, n, i.name),
2109
+ revision: i.revision ?? 1,
2110
+ type: yr(e, i.schema, `${r}.${i.name}`)
2111
+ })),
2112
+ lifecycle: o,
2113
+ queryModels: (n.queries ?? []).map((e) => e.model),
2114
+ ...Object.keys(f).length === 0 ? {} : { textNumbers: f }
2115
+ };
2116
+ }
2117
+ function xr(e, t, n) {
2118
+ return n.includes(".") ? n : `${e.name}.${t.name}.${n}`;
2119
+ }
2120
+ //#endregion
2121
+ //#region src/emitters/manifestClients.ts
2122
+ var X = "@ahoo-wang/wow-client";
2123
+ function Z(e, t = "") {
2124
+ let n = e.filter((e) => typeof e == "string" && e !== "").flatMap((e) => Ot(e).split("\n"));
2125
+ return n.length === 0 ? "" : n.length === 1 ? `${t}/** ${n[0]} */\n` : `${t}/**\n${n.map((e) => `${t} * ${e}`.trimEnd()).join("\n")}\n${t} */\n`;
2126
+ }
2127
+ function Q(e, t) {
2128
+ e.add(`\n${t}`);
2129
+ }
2130
+ function Sr(e) {
2131
+ return e.length === 0 ? "never" : e.join(" | ");
2132
+ }
2133
+ function $(e, t, n, r, i) {
2134
+ let a = /* @__PURE__ */ new Map();
2135
+ for (let e of new Set(r)) {
2136
+ let t = n.get(e);
2137
+ t !== void 0 && t !== i && a.set(t, [...a.get(t) ?? [], e]);
2138
+ }
2139
+ for (let [n, r] of a) e.imports.add(Et(e.directoryPath, ne(t, n)), r);
2140
+ }
2141
+ function Cr(e, t, n) {
2142
+ let r = new Map(e.types.map((e) => [e.name, e.file]));
2143
+ for (let i of e.types) wr(t.module(i.file), i, r, n);
2144
+ for (let i of e.contexts) {
2145
+ Tr(i, t);
2146
+ for (let e of i.aggregates) Or(e, i, t, r, n), jr(e, t, r, n), Mr(e, t, r, n);
2147
+ }
2148
+ }
2149
+ function wr(e, t, n, r) {
2150
+ $(e, r, n, t.references, t.file);
2151
+ let i = Z([t.description, `- key: \`${t.key}\``]);
2152
+ if (t.properties === void 0) {
2153
+ Q(e, `${i}export type ${t.name} = ${t.type};`);
2154
+ return;
2155
+ }
2156
+ let a = t.properties.map((e) => `${Z([e.description], " ")} ${e.name}${e.optional ? "?" : ""}: ${e.type};`);
2157
+ t.type !== void 0 && a.push(` [key: string]: ${t.type};`), Q(e, `${i}export interface ${t.name} {\n${a.join("\n")}\n}`);
2158
+ }
2159
+ function Tr(e, t) {
2160
+ let n = t.module(`${e.directory}/boundedContext.ts`), r = `${e.constantName}_BOUNDED_CONTEXT`;
2161
+ n.imports.add(X, ["Hop", "wait"]), Q(n, `${Z([`The bounded context \`${e.name}\`.`, e.description])}export const ${r} = ${P(e.name)};`);
2162
+ let i = e.errors.map((e) => `${Z([`${e.status}: ${e.description ?? e.code}`], " ")} ${e.member}: ${P(e.code)},`);
2163
+ Q(n, `${Z([`The domain error codes of \`${e.name}\`, each a problem's \`code\` with the status the Manifest gives it.`])}export const ${e.typeName}ErrorCodes = {\n${i.join("\n")}\n} as const;`), Q(n, `${Z([`A {@link ${e.typeName}ErrorCodes} value.`])}export type ${e.typeName}ErrorCode = (typeof ${e.typeName}ErrorCodes)[keyof typeof ${e.typeName}ErrorCodes];`);
2164
+ let a = e.subscriptions.length > 0;
2165
+ a && Q(n, `${Z([`The subscriptions of \`${e.name}\` a \`handled\` hop names.`])}export type ${e.typeName}Subscription = ${Sr(e.subscriptions.map(P))};`);
2166
+ let o = [
2167
+ ` /** Until a command of \`${e.name}\` passed admission. */\n accepted: (): Hop => wait.accepted(${r}),`,
2168
+ ` /** Until a command's events are appended to the log of \`${e.name}\`. */\n committed: (): Hop => wait.committed(${r}),`,
2169
+ ` /** Until the snapshot of \`${e.name}\` holds the commit. */\n snapshot: (): Hop => wait.snapshot(${r}),`
2170
+ ];
2171
+ a && o.push(` /** Until a subscription of \`${e.name}\` handled the commit. */\n handled: (subscription: ${e.typeName}Subscription): Hop => wait.handled(subscription, ${r}),`), Q(n, `${Z([`The hops of a wait chain (\`Wow-Wait\`) in \`${e.name}\`.`])}export const ${j(e.name)}Wait = {\n${o.join("\n")}\n} as const;`);
2172
+ }
2173
+ function Er(e) {
2174
+ return e === !0 ? "true" : `{ ${Object.entries(e).map(([e, t]) => `${N(e)}: ${Er(t)}`).join(", ")} }`;
2175
+ }
2176
+ function Dr(e) {
2177
+ let t = e.textNumbers;
2178
+ return t === void 0 ? "" : ` textNumbers: {\n${[
2179
+ "state",
2180
+ "events",
2181
+ "commands"
2182
+ ].flatMap((e) => {
2183
+ let n = t[e];
2184
+ return n === void 0 ? [] : e === "state" ? [` state: ${Er(n)},`] : [` ${e}: {\n${Object.entries(n).map(([e, t]) => ` ${N(e)}: ${Er(t)},`).join("\n")}\n },`];
2185
+ }).join("\n")}\n },\n`;
2186
+ }
2187
+ function Or(e, t, n, r, i) {
2188
+ let a = n.module(`${e.directory}/aggregate.ts`), o = e.typeName;
2189
+ Q(a, `${Z([`The aggregate \`${e.context}.${e.name}\`.`, e.description])}export const ${o}Aggregate = {\n context: ${P(t.name)},\n name: ${P(e.name)},\n path: ${P(`/${t.name}/${e.name}`)},\n ownership: ${P(e.ownership)},\n snapshot: ${e.snapshot},\n${Dr(e)}} as const;`), Q(a, `${Z([`The \`state.*\` paths of \`${e.name}\`'s snapshots a query filters, sorts and projects on.`])}export type ${o}StateField = ${Sr(e.stateFields.map(P))};`);
2190
+ let s = e.events.map((e) => `EventView<${P(e.wireName)}, ${e.type}>`);
2191
+ a.imports.add(X, s.length > 0 ? ["EventView", "SystemEvent"] : ["SystemEvent"]), Q(a, `${Z([`The events of \`${e.name}\`, named as the server sends them, \`${e.context}.${e.name}.<Event>\` at its current revision (the \`events\` query upgrades older records), and the system events every aggregate has.`])}export type ${o}Event = ${Sr([...s, "SystemEvent"])};`), $(a, i, r, e.events.map((e) => e.type));
2192
+ }
2193
+ function kr(e) {
2194
+ let t = [e.byIdPath, e.unaddressedPath].filter((e) => e !== void 0).map((e) => `\`POST ${e.path}\``).join(", "), n = e.creation === "REQUIRED" ? "Creates the aggregate." : e.creation === "ALLOWED" ? "Creates the aggregate, or acts on the one that exists." : void 0;
2195
+ return Z([
2196
+ e.description,
2197
+ `\`${e.name}\`${e.mounted ? ", mounted (a transformer finds its aggregate)" : ""}: ${t}.`,
2198
+ n,
2199
+ e.produces.length > 0 ? `Produces ${e.produces.map((e) => `\`${e}\``).join(", ")}.` : void 0
2200
+ ], " ");
2201
+ }
2202
+ function Ar(e, t, n, r) {
2203
+ let i = e.bodyNumbers ? `, bodyNumbers: ${r}.textNumbers.commands.${N(e.name) === e.name ? e.name : `[${P(e.name)}]`}` : "", a = e.bodyType === "unknown" ? "object" : e.bodyType, o = e.bodyOptional ? `body: ${a} = {}` : `body: ${a}`, s = n ? "stream" : "send", c = n ? "Promise<CommandResultStream>" : "Promise<CommandResult>", l = n ? `${e.method}Stream` : e.method, u = n ? Z([`\`${e.name}\`, answered as one result per hop of its wait (\`text/event-stream\`).`], " ") : kr(e), d = e.byIdPath, f = e.unaddressedPath;
2204
+ return d && f ? `${u} ${l}(${o}, options?: CreateCommandOptions): ${c} {\n return this.gateway.${s}(options?.id === undefined ? ${t}.${f.member} : ${t}.${d.member}, body, ${i ? `{ ...options${i} }` : "options"});\n }` : d ? `${u} ${l}(id: string, ${o}, options?: CommandOptions): ${c} {\n return this.gateway.${s}(${t}.${d.member}, body, { ...options, id${i} });\n }` : `${u} ${l}(${o}, options?: CommandOptions): ${c} {\n return this.gateway.${s}(${t}.${f.member}, body, ${i ? `{ ...options${i} }` : "options"});\n }`;
2205
+ }
2206
+ function jr(e, t, n, r) {
2207
+ let i = t.module(`${e.directory}/commandClient.ts`), a = e.typeName, o = `${a}CommandPaths`, s = e.commands.filter((e) => e.byIdPath || e.unaddressedPath), c = s.flatMap((e) => [e.byIdPath, e.unaddressedPath].filter((e) => e !== void 0).map((e) => ` ${e.member}: ${P(e.path)},`));
2208
+ Q(i, `${Z([`The command routes of \`${e.context}.${e.name}\`.`])}export const ${o} = {\n${c.join("\n")}\n} as const;`);
2209
+ let l = s.flatMap((e) => [Ar(e, o, !1, `${a}Aggregate`), Ar(e, o, !0, `${a}Aggregate`)]), u = [
2210
+ "CommandGateway",
2211
+ "CommandResult",
2212
+ "WowClientOptions"
2213
+ ];
2214
+ s.length > 0 && u.push("CommandResultStream"), s.some((e) => e.byIdPath && e.unaddressedPath) && u.push("CreateCommandOptions"), (s.some((e) => !(e.byIdPath && e.unaddressedPath)) || e.lifecycle.length > 0) && u.push("CommandOptions");
2215
+ let d = [];
2216
+ for (let t of e.lifecycle) {
2217
+ u.push("LifecycleCommands"), t.bodyType && (t.bodyGenerated ? d : u).push(t.bodyType);
2218
+ let e = t.bodyType ? `id: string, body: ${t.bodyType}, options?: CommandOptions` : "id: string, options?: CommandOptions";
2219
+ l.push(`${Z([t.description, `The lifecycle command \`${t.name}\`.`], " ")} ${t.method}(${e}): Promise<CommandResult> {\n return this.gateway.lifecycle(${a}Aggregate.path, id, LifecycleCommands.${t.member}, ${t.bodyType ? "body" : "undefined"}, options);\n }`);
2220
+ }
2221
+ (e.lifecycle.length > 0 || s.some((e) => e.bodyNumbers)) && i.imports.add("./aggregate.js", [`${a}Aggregate`]), i.imports.add(X, [...new Set(u)].sort()), $(i, r, n, [...s.map((e) => e.bodyType), ...d]), Q(i, `${Z([`Sends the commands of \`${e.context}.${e.name}\`; a command that did not succeed rejects with a \`WowProblemError\` holding its result.`])}export class ${a}CommandClient {\n readonly gateway: CommandGateway;\n\n /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n this.gateway = new CommandGateway(options);\n }\n\n${l.join("\n\n")}\n}`);
2222
+ }
2223
+ function Mr(e, t, n, r) {
2224
+ let i = t.module(`${e.directory}/queryClient.ts`), a = e.typeName, o = e.stateType, s = ["StateClient", "WowClientOptions"], c = [`${a}Aggregate`, `${a}Event`], l = ` /** @param options - How the service is reached */\n constructor(options?: WowClientOptions) {\n super(${a}Aggregate, options);\n }`;
2225
+ e.queryModels.includes("snapshot") && (s.push("SnapshotQueryClient"), c.push(`${a}StateField`), Q(i, `${Z([`Queries the snapshots of \`${e.context}.${e.name}\`: \`POST /${e.context}/${e.name}/snapshot/query\`.`])}export class ${a}SnapshotQueryClient extends SnapshotQueryClient<${o}, ${a}StateField> {\n${l}\n}`)), e.queryModels.includes("events") && (s.push("EventQueryClient"), Q(i, `${Z([`Queries the event streams of \`${e.context}.${e.name}\`, one record per commit: \`POST /${e.context}/${e.name}/events/query\`.`])}export class ${a}EventQueryClient extends EventQueryClient<${a}Event> {\n${l}\n}`)), Q(i, `${Z([`Reads the states of \`${e.context}.${e.name}\`, at a version or a time, and their traces: \`GET /${e.context}/${e.name}/{id}/state\`.`])}export class ${a}StateClient extends StateClient<${o}, ${a}Event> {\n${l}\n}`), i.imports.add(X, s.sort()), i.imports.add("./aggregate.js", c), $(i, r, n, [o]);
2226
+ }
2227
+ //#endregion
2228
+ //#region src/openapi/document.ts
2229
+ function Nr(e) {
2230
+ return {
2231
+ openAPI: e,
2232
+ components: e.components,
2233
+ endpoints: Ge(e.paths, e.components)
2234
+ };
2235
+ }
2236
+ //#endregion
2237
+ //#region src/output/outputStore.ts
2238
+ var Pr = ".wow-generator.json", Fr = class e {
2239
+ project;
2240
+ outputPath;
2241
+ outputDir;
2242
+ previous;
2243
+ written = /* @__PURE__ */ new Set();
2244
+ stale = /* @__PURE__ */ new Set();
2245
+ constructor(e, t, n, r) {
2246
+ this.project = e, this.outputPath = t, this.outputDir = n, this.previous = r;
2247
+ }
2248
+ static open(t, n, r) {
2249
+ let i = t.getFileSystem(), a = n;
2250
+ n = p(i.getCurrentDirectory(), n);
2251
+ let o = d(n, Pr), s = /* @__PURE__ */ new Map();
2252
+ if (i.fileExistsSync(o)) {
2253
+ let e = Ir(o, i.readFileSync(o));
2254
+ for (let [t, r] of Object.entries(e.files)) {
2255
+ let e = p(n, t);
2256
+ if (Br(n, e), u(t) || !t.endsWith(".ts") || typeof r != "string" || !/^[a-f0-9]{64}$/.test(r)) throw new h("output", `Invalid generated file entry in ${o}: ${t}`);
2257
+ s.set(e, r);
2258
+ }
2259
+ }
2260
+ let c = /* @__PURE__ */ new Set([...r?.written ?? [], ...s.keys()]);
2261
+ for (let e of t.getSourceFiles()) c.has(e.getFilePath()) && e.forget();
2262
+ return new e(t, a, n, s);
2263
+ }
2264
+ get files() {
2265
+ return this.written;
2266
+ }
2267
+ claim(e, t = this.outputPath) {
2268
+ let n = ce(t, e);
2269
+ Br(t, n);
2270
+ let r = this.project.getSourceFile(n) ?? this.project.createSourceFile(n, "", { overwrite: !0 }), i = r.getFilePath();
2271
+ return this.written.has(i) || (r.removeText(), this.written.add(i)), r;
2272
+ }
2273
+ forgetStale() {
2274
+ for (let [e, t] of this.previous) !this.written.has(e) && this.isUnchanged(e, t) && this.stale.add(e);
2275
+ for (let e of this.project.getSourceFiles()) this.stale.has(e.getFilePath()) && e.forget();
2276
+ }
2277
+ async commit(e) {
2278
+ e?.throwIfAborted();
2279
+ let t = this.project.getFileSystem(), n = new Set([...this.written].map((e) => e.toLowerCase()));
2280
+ for (let e of this.stale) !this.written.has(e) && n.has(e.toLowerCase()) && this.isUnchanged(e, this.previous.get(e)) && (await zr("delete", e, () => t.delete(e)), this.stale.delete(e));
2281
+ let r = [...this.written].sort().map((e) => this.project.getSourceFileOrThrow(e));
2282
+ (await Promise.allSettled(r.map((e) => e.save()))).forEach((e, t) => {
2283
+ if (e.status === "rejected") throw Rr("write", r[t].getFilePath(), e.reason);
2284
+ }), e?.throwIfAborted();
2285
+ for (let e of this.stale) !this.written.has(e) && this.isUnchanged(e, this.previous.get(e)) && await zr("delete", e, () => t.delete(e));
2286
+ let i = d(this.outputDir, Pr), a = JSON.stringify({
2287
+ version: 1,
2288
+ files: Object.fromEntries(r.map((e) => [f(this.outputDir, e.getFilePath()).split(m).join("/"), Lr(t.readFileSync(e.getFilePath()))]))
2289
+ }, null, 2) + "\n";
2290
+ await zr("write", i, async () => {
2291
+ t.mkdirSync(this.outputDir), await t.writeFile(i, a);
2292
+ });
2293
+ }
2294
+ isUnchanged(e, t) {
2295
+ let n = this.project.getFileSystem();
2296
+ return n.fileExistsSync(e) ? (Br(n.realpathSync(this.outputDir), n.realpathSync(e)), Lr(n.readFileSync(e)) === t) : !1;
2297
+ }
2298
+ };
2299
+ function Ir(e, t) {
2300
+ let n = "delete it; without it this run cannot remove the stale files of the last run", r;
2301
+ try {
2302
+ r = JSON.parse(t);
2303
+ } catch (t) {
2304
+ throw new h("output", `Cannot parse the generation manifest ${e}: ${g(t)}. Resolve the merge conflict in it if it has one, or ${n}.`, { cause: t });
2305
+ }
2306
+ let i = r?.version;
2307
+ if (typeof i == "number" && Number.isInteger(i) && i > 1) throw new h("output", `The generation manifest ${e} was written by a newer wow-generator (manifest version ${i}); this one reads version 1. Upgrade wow-generator.`);
2308
+ if (i !== 1 || !r.files || typeof r.files != "object" || Array.isArray(r.files)) throw new h("output", `Invalid generation manifest ${e}: expected "version": 1 and a "files" object. Restore it from version control, or ${n}.`);
2309
+ return r;
2310
+ }
2311
+ function Lr(e) {
2312
+ if (!l.sys.createSHA256Hash) throw Error("SHA-256 hashing is unavailable in this environment.");
2313
+ return l.sys.createSHA256Hash(e);
2314
+ }
2315
+ function Rr(e, t, n) {
2316
+ return n instanceof h ? n : new h("output", `Cannot ${e} ${t}: ${g(n)}`, { cause: n });
2317
+ }
2318
+ async function zr(e, t, n) {
2319
+ try {
2320
+ await n();
2321
+ } catch (n) {
2322
+ throw Rr(e, t, n);
2323
+ }
2324
+ }
2325
+ function Br(e, t) {
2326
+ let n = t.split("/").join(m), r = p(e), i = p(n), a = f(r, i);
2327
+ if (a === "" || a.startsWith("..") || u(a)) throw new h("output", `Path traversal detected: "${t}" resolves outside the output directory "${e}".`);
2328
+ }
2329
+ //#endregion
2330
+ //#region src/pipeline/seams.ts
2331
+ var Vr = Symbol("project"), Hr = Symbol("signal"), Ur = class {
2332
+ options;
2333
+ project;
2334
+ logger;
2335
+ signal;
2336
+ output;
2337
+ constructor(e) {
2338
+ this.options = e, this.logger = e.logger ?? new oe(), this.signal = e[Hr], this.project = e[Vr] ?? Wr(e.tsConfigFilePath), this.project.manipulationSettings.set({
2339
+ indentationText: t.TwoSpaces,
2340
+ quoteKind: i.Single,
2341
+ useTrailingCommas: !0
2342
+ }), this.logger.debug(`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`);
2343
+ }
2344
+ async generate() {
2345
+ let { logger: e, signal: t, options: n } = this, r = 0, i = (t) => {
2346
+ for (let n of t) r++, e.warn(n);
2347
+ };
2348
+ e.debug("Starting code generation"), e.debug(`Work directory: ${process.cwd()}`), e.debug(`Input path: ${n.inputPath}`), e.debug(`Output directory: ${n.outputDir}`);
2349
+ let a = {
2350
+ headers: n.headers,
2351
+ timeoutMs: n.timeoutMs,
2352
+ signal: t
2353
+ }, o = await qn(n.configPath, e, a);
2354
+ i(o.warnings), t?.throwIfAborted(), e.debug("Parsing the input document");
2355
+ let s = await Un(n.inputPath, a);
2356
+ if (t?.throwIfAborted(), rr(s)) return this.generateFromManifest(ir(s, n.inputPath), o.origin, i, () => r);
2357
+ let c = Wn(s, n.inputPath);
2358
+ e.debug("OpenAPI specification parsed successfully");
2359
+ let l = fe(c);
2360
+ if (l.length > 0) throw new h("specification", `${n.inputPath} has ${l.length} $ref(s) that point at nothing: ${l.slice(0, 10).map(({ ref: e, location: t }) => `${e} (at ${t})`).join(", ")}${l.length > 10 ? ", …" : ""}`);
2361
+ let u = Nr(c), d = Fr.open(this.project, n.outputDir, this.output);
2362
+ this.output = d, e.debug("Analysing the document");
2363
+ let f = _t(u, o.config);
2364
+ i(f.warnings), e.debug("Writing generated modules");
2365
+ let p = new bt((e) => d.claim(e));
2366
+ Cn(f.model, {
2367
+ modules: p,
2368
+ outputDir: n.outputDir,
2369
+ types: yn(u.components),
2370
+ schemaDocs: n.schemaDocs ?? "summary"
2371
+ }), p.build(), e.debug("Generated modules written"), d.forgetStale();
2372
+ let m = this.project.getDirectory(n.outputDir);
2373
+ return m ? (e.debug("Generating index files"), i(wn(m, (e) => d.claim("index.ts", e))), e.debug("Optimizing source files"), In(m.getDescendantSourceFiles().filter((e) => d.files.has(e.getFilePath())), e), e.debug("Source files optimized successfully")) : e.debug("Output directory not found."), e.debug("Saving project to disk"), await d.commit(t), e.debug("Code generation completed successfully"), {
2374
+ files: [...d.files].sort(),
2375
+ configPath: o.origin,
2376
+ warnings: r
2377
+ };
2378
+ }
2379
+ async generateFromManifest(e, t, n, r) {
2380
+ let { logger: i, signal: a, options: o } = this, s = Fr.open(this.project, o.outputDir, this.output);
2381
+ this.output = s, i.debug("Analysing the Manifest");
2382
+ let c = gr(e);
2383
+ n(c.warnings);
2384
+ let l = new bt((e) => s.claim(e));
2385
+ Cr(c.model, l, o.outputDir), l.build(), s.forgetStale();
2386
+ let u = this.project.getDirectory(o.outputDir);
2387
+ return u && (n(wn(u, (e) => s.claim("index.ts", e))), In(u.getDescendantSourceFiles().filter((e) => s.files.has(e.getFilePath())), i)), await s.commit(a), i.debug("Code generation from the Manifest completed successfully"), {
2388
+ files: [...s.files].sort(),
2389
+ configPath: t,
2390
+ warnings: r()
2391
+ };
2392
+ }
2393
+ };
2394
+ function Wr(e) {
2395
+ try {
2396
+ return new r({
2397
+ tsConfigFilePath: e,
2398
+ skipAddingFilesFromTsConfig: !0
2399
+ });
2400
+ } catch (t) {
2401
+ throw new h("configuration", `Cannot read the TypeScript configuration ${e}: ${g(t)}`, { cause: t });
2402
+ }
2403
+ }
2404
+ //#endregion
2405
+ export { se as a, re as c, oe as i, Hr as n, ie as o, Ln as r, h as s, Ur as t };
2406
+
2407
+ //# sourceMappingURL=codeGenerator-CU1TGcUI.js.map