@ahoo-wang/fetcher-generator 2.3.6 → 2.5.0

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 (44) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/cli.cjs.map +1 -1
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +18 -17
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client/apiClientGenerator.d.ts +97 -0
  7. package/dist/client/apiClientGenerator.d.ts.map +1 -0
  8. package/dist/client/clientGenerator.d.ts +4 -3
  9. package/dist/client/clientGenerator.d.ts.map +1 -1
  10. package/dist/client/commandClientGenerator.d.ts +3 -4
  11. package/dist/client/commandClientGenerator.d.ts.map +1 -1
  12. package/dist/client/decorators.d.ts +54 -0
  13. package/dist/client/decorators.d.ts.map +1 -0
  14. package/dist/client/index.d.ts +5 -0
  15. package/dist/client/index.d.ts.map +1 -1
  16. package/dist/client/queryClientGenerator.d.ts +3 -3
  17. package/dist/client/queryClientGenerator.d.ts.map +1 -1
  18. package/dist/client/utils.d.ts +1 -0
  19. package/dist/client/utils.d.ts.map +1 -1
  20. package/dist/{baseCodeGenerator.d.ts → generateContext.d.ts} +13 -10
  21. package/dist/generateContext.d.ts.map +1 -0
  22. package/dist/index.cjs +7 -7
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +864 -398
  27. package/dist/index.js.map +1 -1
  28. package/dist/model/modelGenerator.d.ts +5 -3
  29. package/dist/model/modelGenerator.d.ts.map +1 -1
  30. package/dist/model/modelInfo.d.ts +2 -0
  31. package/dist/model/modelInfo.d.ts.map +1 -1
  32. package/dist/types.d.ts +17 -1
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/utils/clis.d.ts.map +1 -1
  35. package/dist/utils/index.d.ts +1 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/naming.d.ts.map +1 -1
  38. package/dist/utils/{openAPIParser.d.ts → parsers.d.ts} +3 -1
  39. package/dist/utils/parsers.d.ts.map +1 -0
  40. package/dist/utils/responses.d.ts +5 -2
  41. package/dist/utils/responses.d.ts.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/baseCodeGenerator.d.ts.map +0 -1
  44. package/dist/utils/openAPIParser.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,86 +1,127 @@
1
- import { VariableDeclarationKind as E, Scope as Q } from "ts-morph";
2
- import { parse as L } from "yaml";
3
- import { readFile as U } from "fs";
4
- import { ContentTypeValues as I, combineURLs as q } from "@ahoo-wang/fetcher";
5
- import { join as K, relative as J } from "path";
6
- import { ResourceAttributionPathSpec as v } from "@ahoo-wang/fetcher-wow";
7
- function f(o) {
1
+ import { ContentTypeValues as I, combineURLs as S } from "@ahoo-wang/fetcher";
2
+ import { VariableDeclarationKind as v, Scope as se } from "ts-morph";
3
+ import { ResourceAttributionPathSpec as M } from "@ahoo-wang/fetcher-wow";
4
+ import { parse as z } from "yaml";
5
+ import { readFile as ie } from "fs";
6
+ import { join as ae, relative as ce } from "path";
7
+ function ge(o) {
8
+ const e = o.split(".");
9
+ return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
10
+ }
11
+ function le(o) {
12
+ const e = ge(o.name);
13
+ return e ? {
14
+ tag: o,
15
+ contextAlias: e[0],
16
+ aggregateName: e[1]
17
+ } : null;
18
+ }
19
+ function pe(o) {
20
+ const e = o?.map((n) => le(n)).filter((n) => n !== null);
21
+ if (!e)
22
+ return /* @__PURE__ */ new Map();
23
+ const t = /* @__PURE__ */ new Map();
24
+ return e.forEach((n) => {
25
+ t.set(n.tag.name, {
26
+ aggregate: n,
27
+ commands: /* @__PURE__ */ new Map(),
28
+ events: /* @__PURE__ */ new Map()
29
+ });
30
+ }), t;
31
+ }
32
+ function ue(o) {
33
+ if (!o)
34
+ return null;
35
+ const e = o.split(".");
36
+ return e.length != 3 ? null : e[2];
37
+ }
38
+ function $(o) {
8
39
  return o.$ref.split("/").pop();
9
40
  }
10
- function S(o, e) {
11
- const t = f(o);
41
+ function w(o, e) {
42
+ const t = $(o);
12
43
  return e.schemas?.[t];
13
44
  }
14
- function V(o, e) {
15
- const t = f(o);
45
+ function B(o, e) {
46
+ const t = $(o);
16
47
  return e.requestBodies?.[t];
17
48
  }
18
- function H(o, e) {
19
- const t = f(o);
49
+ function de(o, e) {
50
+ const t = $(o);
20
51
  return e.parameters?.[t];
21
52
  }
22
- function C(o, e) {
53
+ function P(o, e) {
23
54
  return {
24
- key: f(o),
25
- schema: S(o, e)
55
+ key: $(o),
56
+ schema: w(o, e)
26
57
  };
27
58
  }
28
- const b = /[-_\s.]+/;
29
- function G(o) {
30
- return Array.isArray(o) ? o.flatMap((e) => R(e.split(b))) : R(o.split(b));
59
+ const j = /[-_\s.]+/;
60
+ function k(o) {
61
+ return Array.isArray(o) ? o.flatMap((e) => G(e.split(j))) : G(o.split(j));
31
62
  }
32
- function R(o) {
63
+ function G(o) {
33
64
  return o.flatMap((e) => {
34
65
  if (e.length === 0)
35
66
  return [];
36
67
  const t = [];
37
68
  let n = "";
38
69
  for (let r = 0; r < e.length; r++) {
39
- const s = e[r], i = /[A-Z]/.test(s), c = r > 0 && /[a-z]/.test(e[r - 1]);
40
- i && c && n ? (t.push(n), n = s) : n += s;
70
+ const s = e[r], i = /[A-Z]/.test(s), a = r > 0 && /[a-z]/.test(e[r - 1]);
71
+ i && a && n ? (t.push(n), n = s) : n += s;
41
72
  }
42
73
  return n && t.push(n), t;
43
74
  });
44
75
  }
45
- function $(o) {
46
- return o === "" || o.length === 0 ? "" : G(o).filter((t) => t.length > 0).map((t) => {
47
- if (t.length === 0) return "";
76
+ function A(o) {
77
+ return o === "" || o.length === 0 ? "" : k(o).filter((t) => t.length > 0).map((t) => {
48
78
  const n = t.charAt(0), r = t.slice(1);
49
79
  return (/[a-zA-Z]/.test(n) ? n.toUpperCase() : n) + r.toLowerCase();
50
80
  }).join("");
51
81
  }
52
82
  function h(o) {
53
- const e = $(o);
83
+ const e = A(o);
54
84
  return e.charAt(0).toLowerCase() + e.slice(1);
55
85
  }
56
- function Y(o) {
57
- return o === "" || Array.isArray(o) && o.length === 0 ? "" : G(o).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
86
+ function me(o) {
87
+ return o === "" || Array.isArray(o) && o.length === 0 ? "" : k(o).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
58
88
  }
59
- function X(o) {
60
- return o.startsWith("http://") || o.startsWith("https://") ? Z(o) : ee(o);
89
+ function Q(o) {
90
+ return o.startsWith("http://") || o.startsWith("https://") ? fe(o) : he(o);
61
91
  }
62
- async function Z(o) {
92
+ async function fe(o) {
63
93
  return await (await fetch(o)).text();
64
94
  }
65
- function ee(o) {
95
+ function he(o) {
66
96
  return new Promise((e, t) => {
67
- U(o, "utf-8", (n, r) => {
97
+ ie(o, "utf-8", (n, r) => {
68
98
  n ? t(n) : e(r);
69
99
  });
70
100
  });
71
101
  }
72
- async function te(o) {
73
- const e = await X(o);
74
- switch (ne(e)) {
102
+ async function ye(o) {
103
+ const e = await Q(o);
104
+ switch (L(e)) {
75
105
  case "json":
76
106
  return JSON.parse(e);
77
107
  case "yaml":
78
- return L(e);
108
+ return z(e);
79
109
  default:
80
110
  throw new Error(`Unsupported file format: ${o}`);
81
111
  }
82
112
  }
83
- function ne(o) {
113
+ async function xe(o) {
114
+ const e = await Q(o);
115
+ switch (L(e)) {
116
+ case "json":
117
+ return JSON.parse(e);
118
+ case "yaml":
119
+ return z(e);
120
+ default:
121
+ throw new Error(`Unsupported file format: ${o}`);
122
+ }
123
+ }
124
+ function L(o) {
84
125
  const e = o.trimStart();
85
126
  if (e.startsWith("{") || e.startsWith("["))
86
127
  return "json";
@@ -94,13 +135,23 @@ function ne(o) {
94
135
  }
95
136
  throw new Error("Unable to infer file format");
96
137
  }
97
- function g(o) {
138
+ function l(o) {
98
139
  return !!(o && typeof o == "object" && "$ref" in o);
99
140
  }
100
- function oe(o) {
101
- return !o || g(o) || !o.content ? void 0 : o.content[I.APPLICATION_JSON]?.schema;
141
+ function D(o, e) {
142
+ if (e && !l(e) && e.content)
143
+ return e.content[o]?.schema;
144
+ }
145
+ function U(o) {
146
+ return D(I.APPLICATION_JSON, o);
147
+ }
148
+ function Ae(o) {
149
+ return D(I.TEXT_EVENT_STREAM, o);
150
+ }
151
+ function Ce(o) {
152
+ return D("*/*", o);
102
153
  }
103
- function re(o) {
154
+ function J(o) {
104
155
  return [
105
156
  { method: "get", operation: o.get },
106
157
  { method: "put", operation: o.put },
@@ -112,53 +163,53 @@ function re(o) {
112
163
  { method: "trace", operation: o.trace }
113
164
  ].filter(({ operation: e }) => e !== void 0);
114
165
  }
115
- function F(o) {
166
+ function b(o) {
116
167
  return o.responses[200];
117
168
  }
118
- function j(o) {
119
- const e = F(o);
120
- return oe(e);
169
+ function F(o) {
170
+ const e = b(o);
171
+ return U(e);
121
172
  }
122
- const se = [
173
+ const $e = [
123
174
  "string",
124
175
  "number",
125
176
  "integer",
126
177
  "boolean",
127
178
  "null"
128
179
  ];
129
- function ie(o) {
130
- return Array.isArray(o) ? !0 : se.includes(o);
180
+ function V(o) {
181
+ return Array.isArray(o) ? !0 : $e.includes(o);
131
182
  }
132
- function ae(o) {
183
+ function O(o) {
133
184
  return o.type === "array";
134
185
  }
135
- function ce(o) {
186
+ function Pe(o) {
136
187
  return Array.isArray(o.enum) && o.enum.length > 0;
137
188
  }
138
- function W(o) {
189
+ function K(o) {
139
190
  return Array.isArray(o.anyOf) && o.anyOf.length > 0;
140
191
  }
141
- function _(o) {
192
+ function H(o) {
142
193
  return Array.isArray(o.oneOf) && o.oneOf.length > 0;
143
194
  }
144
- function ge(o) {
145
- return W(o) || _(o);
195
+ function Te(o) {
196
+ return K(o) || H(o);
146
197
  }
147
- function le(o) {
198
+ function Ie(o) {
148
199
  return Array.isArray(o.allOf) && o.allOf.length > 0;
149
200
  }
150
- function M(o) {
151
- return W(o) || _(o) || le(o);
201
+ function _(o) {
202
+ return K(o) || H(o) || Ie(o);
152
203
  }
153
- function pe(o) {
204
+ function W(o) {
154
205
  return o.includes("|") || o.includes("&") ? `(${o})[]` : `${o}[]`;
155
206
  }
156
- function ue(o) {
207
+ function Se(o) {
157
208
  return o.type !== "object" ? !1 : o.properties ? Object.keys(o.properties).length === 0 : !0;
158
209
  }
159
- function N(o) {
210
+ function R(o) {
160
211
  if (Array.isArray(o))
161
- return o.map((e) => N(e)).join(" | ");
212
+ return o.map((e) => R(e)).join(" | ");
162
213
  switch (o) {
163
214
  case "string":
164
215
  return "string";
@@ -173,17 +224,17 @@ function N(o) {
173
224
  return "any";
174
225
  }
175
226
  }
176
- const B = "types.ts", me = "@";
177
- function de(o) {
178
- return q(o.path, B);
227
+ const X = "types.ts", we = "@";
228
+ function Re(o) {
229
+ return S(o.path, X);
179
230
  }
180
- function D(o, e, t) {
181
- const n = q(e, t), r = o.getSourceFile(n);
231
+ function Y(o, e, t) {
232
+ const n = S(e, t), r = o.getSourceFile(n);
182
233
  return r || o.createSourceFile(n, "", {
183
234
  overwrite: !0
184
235
  });
185
236
  }
186
- function w(o, e, t) {
237
+ function E(o, e, t) {
187
238
  let n = o.getImportDeclaration(
188
239
  (r) => r.getModuleSpecifierValue() === e
189
240
  );
@@ -195,70 +246,39 @@ function w(o, e, t) {
195
246
  ) || n.addNamedImport(r);
196
247
  });
197
248
  }
198
- function y(o, e, t) {
199
- if (t.path.startsWith(me)) {
200
- w(o, t.path, [t.name]);
249
+ function f(o, e, t) {
250
+ if (t.path.startsWith(we)) {
251
+ E(o, t.path, [t.name]);
201
252
  return;
202
253
  }
203
- const n = o.getDirectoryPath(), r = K(e, t.path, B);
204
- let s = J(n, r);
205
- s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), w(o, s, [t.name]);
254
+ const n = o.getDirectoryPath(), r = ae(e, t.path, X);
255
+ let s = ce(n, r);
256
+ s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), E(o, s, [t.name]);
206
257
  }
207
- function O(o, e, t, n) {
208
- o.path !== n.path && y(e, t, n);
258
+ function T(o, e, t, n) {
259
+ o.path !== n.path && f(e, t, n);
209
260
  }
210
- function fe(o, e) {
261
+ function Ee(o, e) {
211
262
  const t = [o, e].filter(
212
263
  (n) => n !== void 0 && n.length > 0
213
264
  );
214
265
  return t.length > 0 ? t.join(`
215
266
  `) : void 0;
216
267
  }
217
- function P(o, e, t) {
218
- const n = fe(e, t);
268
+ function x(o, e, t) {
269
+ const n = Ee(e, t);
219
270
  n && o.addJsDoc({
220
271
  description: n
221
272
  });
222
273
  }
223
- function he(o) {
224
- const e = o.split(".");
225
- return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
226
- }
227
- function ye(o) {
228
- const e = he(o.name);
229
- return e ? {
230
- tag: o,
231
- contextAlias: e[0],
232
- aggregateName: e[1]
233
- } : null;
234
- }
235
- function Ae(o) {
236
- const e = o?.map((n) => ye(n)).filter((n) => n !== null);
237
- if (!e)
238
- return /* @__PURE__ */ new Map();
239
- const t = /* @__PURE__ */ new Map();
240
- return e.forEach((n) => {
241
- t.set(n.tag.name, {
242
- aggregate: n,
243
- commands: /* @__PURE__ */ new Map(),
244
- events: /* @__PURE__ */ new Map()
245
- });
246
- }), t;
247
- }
248
- function Ce(o) {
249
- if (!o)
250
- return null;
251
- const e = o.split(".");
252
- return e.length != 3 ? null : e[2];
253
- }
254
- const Pe = "#/components/responses/wow.CommandOk", we = "#/components/parameters/wow.id";
255
- class $e {
274
+ const ve = "#/components/responses/wow.CommandOk", Oe = "#/components/parameters/wow.id";
275
+ class Ne {
256
276
  /**
257
277
  * Creates a new AggregateResolver instance.
258
278
  * @param openAPI - The OpenAPI specification to resolve aggregates from
259
279
  */
260
280
  constructor(e) {
261
- this.openAPI = e, this.aggregates = Ae(e.tags), this.build();
281
+ this.openAPI = e, this.aggregates = pe(e.tags), this.build();
262
282
  }
263
283
  aggregates;
264
284
  /**
@@ -267,7 +287,7 @@ class $e {
267
287
  */
268
288
  build() {
269
289
  for (const [e, t] of Object.entries(this.openAPI.paths)) {
270
- const n = re(t);
290
+ const n = J(t);
271
291
  for (const r of n)
272
292
  this.commands(e, r), this.state(r.operation), this.events(r.operation), this.fields(r.operation);
273
293
  }
@@ -296,40 +316,40 @@ class $e {
296
316
  const n = t.operation;
297
317
  if (n.operationId === "wow.command.send")
298
318
  return;
299
- const r = Ce(n.operationId);
319
+ const r = ue(n.operationId);
300
320
  if (!r)
301
321
  return;
302
- const s = F(n);
303
- if (!s || !g(s) || s.$ref !== Pe || !n.requestBody)
322
+ const s = b(n);
323
+ if (!s || !l(s) || s.$ref !== ve || !n.requestBody)
304
324
  return;
305
- const i = n.parameters ?? [], c = i.filter((m) => g(m) && m.$ref === we).at(0), a = i.filter(
306
- (m) => !g(m) && m.in === "path"
325
+ const i = n.parameters ?? [], a = i.filter((d) => l(d) && d.$ref === Oe).at(0), c = i.filter(
326
+ (d) => !l(d) && d.in === "path"
307
327
  );
308
- if (c) {
309
- const m = H(
310
- c,
328
+ if (a) {
329
+ const d = de(
330
+ a,
311
331
  this.openAPI.components
312
332
  );
313
- a.push(m);
333
+ c.push(d);
314
334
  }
315
- const u = n.requestBody.content[I.APPLICATION_JSON].schema, l = C(
335
+ const u = n.requestBody.content[I.APPLICATION_JSON].schema, p = P(
316
336
  u,
317
337
  this.openAPI.components
318
338
  );
319
- l.schema.title = l.schema.title || n.summary, l.schema.description = l.schema.description || n.description;
320
- const k = {
339
+ p.schema.title = p.schema.title || n.summary, p.schema.description = p.schema.description || n.description;
340
+ const re = {
321
341
  name: r,
322
342
  method: t.method,
323
343
  path: e,
324
- pathParameters: a,
344
+ pathParameters: c,
325
345
  summary: n.summary,
326
346
  description: n.description,
327
- schema: l,
347
+ schema: p,
328
348
  operation: n
329
349
  };
330
- n.tags?.forEach((m) => {
331
- const T = this.aggregates.get(m);
332
- T && T.commands.set(r, k);
350
+ n.tags?.forEach((d) => {
351
+ const q = this.aggregates.get(d);
352
+ q && q.commands.set(r, re);
333
353
  });
334
354
  }
335
355
  /**
@@ -339,10 +359,10 @@ class $e {
339
359
  state(e) {
340
360
  if (!e.operationId?.endsWith(".snapshot_state.single"))
341
361
  return;
342
- const t = j(e);
343
- if (!g(t))
362
+ const t = F(e);
363
+ if (!l(t))
344
364
  return;
345
- const n = C(
365
+ const n = P(
346
366
  t,
347
367
  this.openAPI.components
348
368
  );
@@ -358,30 +378,30 @@ class $e {
358
378
  events(e) {
359
379
  if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
360
380
  return;
361
- const t = j(e);
362
- if (g(t))
381
+ const t = F(e);
382
+ if (l(t))
363
383
  return;
364
384
  const n = t?.items;
365
- if (!g(n))
385
+ if (!l(n))
366
386
  return;
367
- const s = S(
387
+ const s = w(
368
388
  n,
369
389
  this.openAPI.components
370
390
  ).properties.body.items.anyOf.map((i) => {
371
- const c = i.title, a = i.properties.name.const, p = i.properties.body, u = C(
372
- p,
391
+ const a = i.title, c = i.properties.name.const, g = i.properties.body, u = P(
392
+ g,
373
393
  this.openAPI.components
374
394
  );
375
395
  return u.schema.title = u.schema.title || i.title, {
376
- title: c,
377
- name: a,
396
+ title: a,
397
+ name: c,
378
398
  schema: u
379
399
  };
380
400
  });
381
401
  e.tags?.forEach((i) => {
382
- const c = this.aggregates.get(i);
383
- c && s.forEach((a) => {
384
- c.events.set(a.name, a);
402
+ const a = this.aggregates.get(i);
403
+ a && s.forEach((c) => {
404
+ a.events.set(c.name, c);
385
405
  });
386
406
  });
387
407
  }
@@ -392,20 +412,20 @@ class $e {
392
412
  fields(e) {
393
413
  if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
394
414
  return;
395
- const n = V(
415
+ const n = B(
396
416
  e.requestBody,
397
417
  this.openAPI.components
398
- ).content[I.APPLICATION_JSON].schema, s = S(
418
+ ).content[I.APPLICATION_JSON].schema, s = w(
399
419
  n,
400
420
  this.openAPI.components
401
- ).properties?.field, i = C(s, this.openAPI.components);
402
- e.tags?.forEach((c) => {
403
- const a = this.aggregates.get(c);
404
- a && (a.fields = i);
421
+ ).properties?.field, i = P(s, this.openAPI.components);
422
+ e.tags?.forEach((a) => {
423
+ const c = this.aggregates.get(a);
424
+ c && (c.fields = i);
405
425
  });
406
426
  }
407
427
  }
408
- const A = "@ahoo-wang/fetcher-wow", xe = {
428
+ const C = "@ahoo-wang/fetcher-wow", De = {
409
429
  "wow.command.CommandResult": "CommandResult",
410
430
  "wow.MessageHeaderSqlType": "MessageHeaderSqlType",
411
431
  "wow.api.BindingError": "BindingError",
@@ -434,50 +454,35 @@ const A = "@ahoo-wang/fetcher-wow", xe = {
434
454
  "wow.openapi.BatchResult": "BatchResult",
435
455
  "wow.messaging.CompensationTarget": "CompensationTarget"
436
456
  };
437
- function d(o) {
457
+ function m(o) {
438
458
  if (!o)
439
459
  return { name: "", path: "/" };
440
- const e = xe[o];
460
+ const e = De[o];
441
461
  if (e)
442
- return { name: e, path: A };
462
+ return { name: e, path: C };
443
463
  const t = o.split(".");
444
464
  let n = -1;
445
- for (let a = 0; a < t.length; a++)
446
- if (t[a] && /^[A-Z]/.test(t[a])) {
447
- n = a;
465
+ for (let c = 0; c < t.length; c++)
466
+ if (t[c] && /^[A-Z]/.test(t[c])) {
467
+ n = c;
448
468
  break;
449
469
  }
450
470
  if (n === -1)
451
471
  return { name: o, path: "/" };
452
472
  const r = t.slice(0, n), s = r.length > 0 ? `/${r.join("/")}` : "/", i = t.slice(n);
453
- return { name: $(i), path: s };
473
+ return { name: A(i), path: s };
454
474
  }
455
- class x {
456
- /** The ts-morph project instance used for code generation */
457
- project;
458
- /** The OpenAPI specification object */
459
- openAPI;
460
- /** The output directory path for generated files */
461
- outputDir;
462
- /** Map of bounded context aggregates for domain modeling */
463
- contextAggregates;
464
- /** Optional logger for generation progress and errors */
465
- logger;
466
- /**
467
- * Creates a new ClientGenerator instance.
468
- * @param context - The generation context containing OpenAPI spec and project details
469
- */
470
- constructor(e) {
471
- this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger;
472
- }
475
+ function y(o) {
476
+ const e = $(o);
477
+ return m(e);
473
478
  }
474
- class Oe extends x {
479
+ class be {
475
480
  constructor(e) {
476
- super(e);
481
+ this.context = e;
477
482
  }
478
483
  getOrCreateSourceFile(e) {
479
- const t = de(e);
480
- return D(this.project, this.outputDir, t);
484
+ const t = Re(e);
485
+ return this.context.getOrCreateSourceFile(t);
481
486
  }
482
487
  /**
483
488
  * Generates models for all schemas in the OpenAPI specification.
@@ -488,29 +493,53 @@ class Oe extends x {
488
493
  * and generates corresponding TypeScript models for each one.
489
494
  */
490
495
  generate() {
491
- const e = this.openAPI.components?.schemas;
496
+ const e = this.context.openAPI.components?.schemas;
492
497
  if (!e) {
493
- this.logger.info("No schemas found in OpenAPI specification");
498
+ this.context.logger.info("No schemas found in OpenAPI specification");
494
499
  return;
495
500
  }
496
- const t = this.filterSchemas(e);
497
- this.logger.progress(`Generating models for ${t.length} schemas`), t.forEach((n, r) => {
498
- this.logger.progressWithCount(
499
- r + 1,
500
- t.length,
501
- `Processing schema: ${n.key}`,
501
+ const t = this.stateAggregatedTypeNames(), n = this.filterSchemas(e, t);
502
+ this.context.logger.progress(`Generating models for ${n.length} schemas`), n.forEach((r, s) => {
503
+ this.context.logger.progressWithCount(
504
+ s + 1,
505
+ n.length,
506
+ `Processing schema: ${r.key}`,
502
507
  2
503
- ), this.generateKeyedSchema(n);
504
- }), this.logger.success("Model generation completed");
508
+ ), this.generateKeyedSchema(r);
509
+ }), this.context.logger.success("Model generation completed");
510
+ }
511
+ filterSchemas(e, t) {
512
+ return Object.entries(e).map(([n, r]) => ({
513
+ key: n,
514
+ schema: r
515
+ })).filter((n) => !this.isWowSchema(n.key, t));
505
516
  }
506
- filterSchemas(e) {
507
- return Object.entries(e).map(([t, n]) => ({
508
- key: t,
509
- schema: n
510
- })).filter((t) => !this.isWowSchema(t.key));
517
+ isWowSchema(e, t) {
518
+ if (e.startsWith("wow.") || e.endsWith("AggregatedCondition") || e.endsWith("AggregatedDomainEventStream") || e.endsWith("AggregatedDomainEventStreamPagedList") || e.endsWith("AggregatedDomainEventStreamServerSentEventNonNullData") || e.endsWith("AggregatedListQuery") || e.endsWith("AggregatedPagedQuery") || e.endsWith("AggregatedSingleQuery"))
519
+ return !0;
520
+ const n = m(e);
521
+ return t.has(n.name);
511
522
  }
512
- isWowSchema(e) {
513
- return e.startsWith("wow.");
523
+ aggregatedSchemaSuffix = [
524
+ "MaterializedSnapshot",
525
+ "MaterializedSnapshotPagedList",
526
+ "MaterializedSnapshotServerSentEventNonNullData",
527
+ "PagedList",
528
+ "ServerSentEventNonNullData",
529
+ "Snapshot",
530
+ "StateEvent"
531
+ ];
532
+ stateAggregatedTypeNames() {
533
+ const e = /* @__PURE__ */ new Set();
534
+ for (const t of this.context.contextAggregates.values())
535
+ for (const n of t)
536
+ this.aggregatedSchemaSuffix.forEach(
537
+ (r) => {
538
+ const s = m(n.state.key), i = A(s.name) + r;
539
+ e.add(i);
540
+ }
541
+ );
542
+ return e;
514
543
  }
515
544
  /**
516
545
  * Generates a model for a specific schema key.
@@ -527,19 +556,32 @@ class Oe extends x {
527
556
  * 4. Type alias processing
528
557
  */
529
558
  generateKeyedSchema({ key: e, schema: t }) {
530
- const n = d(e), r = this.getOrCreateSourceFile(n), s = this.process(n, r, t);
531
- s && P(s, t.title, t.description);
559
+ const n = m(e), r = this.getOrCreateSourceFile(n), s = this.process(n, r, t);
560
+ s && x(s, t.title, t.description);
532
561
  }
533
562
  process(e, t, n) {
534
- if (ce(n))
563
+ if (Pe(n))
535
564
  return t.addEnum({
536
565
  name: e.name,
537
566
  isExported: !0,
538
567
  members: n.enum.filter((s) => typeof s == "string" && s.length > 0).map((s) => ({
539
- name: Y(s),
568
+ name: me(s),
540
569
  initializer: `'${s}'`
541
570
  }))
542
571
  });
572
+ if (O(n) && l(n.items)) {
573
+ const s = y(n.items);
574
+ return T(
575
+ e,
576
+ t,
577
+ this.context.outputDir,
578
+ s
579
+ ), t.addTypeAlias({
580
+ name: e.name,
581
+ type: W(s.name),
582
+ isExported: !0
583
+ });
584
+ }
543
585
  const r = t.addInterface({
544
586
  name: e.name,
545
587
  isExported: !0
@@ -549,17 +591,15 @@ class Oe extends x {
549
591
  e,
550
592
  n,
551
593
  r
552
- ) : (M(n) && (n.anyOf || n.oneOf || n.allOf).forEach((i) => {
553
- if (g(i)) {
554
- const c = d(
555
- f(i)
556
- );
557
- O(
594
+ ) : (_(n) && (n.anyOf || n.oneOf || n.allOf).forEach((i) => {
595
+ if (l(i)) {
596
+ const a = y(i);
597
+ T(
558
598
  e,
559
599
  t,
560
- this.outputDir,
561
- c
562
- ), r.addExtends(c.name);
600
+ this.context.outputDir,
601
+ a
602
+ ), r.addExtends(a.name);
563
603
  return;
564
604
  }
565
605
  this.processInterface(
@@ -584,44 +624,44 @@ class Oe extends x {
584
624
  }
585
625
  processInterface(e, t, n, r) {
586
626
  for (const [s, i] of Object.entries(n.properties)) {
587
- const c = this.resolvePropertyType(
627
+ const a = this.resolvePropertyType(
588
628
  t,
589
629
  e,
590
630
  s,
591
631
  i
592
632
  );
593
- let a = r.getProperty(s);
594
- a ? a.setType(c) : a = r.addProperty({
633
+ let c = r.getProperty(s);
634
+ c ? c.setType(a) : c = r.addProperty({
595
635
  name: s,
596
- type: c
597
- }), g(i) || P(a, i.title, i.description);
636
+ type: a
637
+ }), l(i) || x(c, i.title, i.description);
598
638
  }
599
639
  return r;
600
640
  }
601
641
  resolvePropertyType(e, t, n, r) {
602
- if (g(r)) {
603
- const s = d(f(r));
604
- return O(
642
+ if (l(r)) {
643
+ const s = y(r);
644
+ return T(
605
645
  e,
606
646
  t,
607
- this.outputDir,
647
+ this.context.outputDir,
608
648
  s
609
649
  ), s.name;
610
650
  }
611
651
  if (r.const)
612
652
  return `'${r.const}'`;
613
- if (ae(r)) {
653
+ if (O(r)) {
614
654
  const s = this.resolvePropertyType(
615
655
  e,
616
656
  t,
617
657
  n,
618
658
  r.items
619
659
  );
620
- return pe(s);
660
+ return W(s);
621
661
  }
622
- if (r.type && ie(r.type))
623
- return N(r.type);
624
- if (M(r))
662
+ if (r.type && V(r.type))
663
+ return R(r.type);
664
+ if (_(r))
625
665
  return this.resolvePropertyCompositionType(
626
666
  e,
627
667
  t,
@@ -630,79 +670,80 @@ class Oe extends x {
630
670
  if (r.type === "object" && r.properties) {
631
671
  const s = {
632
672
  path: e.path,
633
- name: `${e.name}${$(n)}`
673
+ name: `${e.name}${A(n)}`
634
674
  }, i = this.processObject(
635
675
  t,
636
676
  s,
637
677
  r
638
678
  );
639
- return P(i, r.title, r.description), s.name;
679
+ return x(i, r.title, r.description), s.name;
640
680
  }
641
681
  return "any";
642
682
  }
643
683
  resolvePropertyCompositionType(e, t, n) {
644
684
  const r = n.anyOf || n.oneOf || n.allOf, s = /* @__PURE__ */ new Set();
645
- r.forEach((c) => {
646
- if (g(c)) {
647
- const a = d(
648
- f(c)
649
- );
650
- O(
685
+ r.forEach((a) => {
686
+ if (l(a)) {
687
+ const c = y(a);
688
+ T(
651
689
  e,
652
690
  t,
653
- this.outputDir,
654
- a
655
- ), s.add(a.name);
691
+ this.context.outputDir,
692
+ c
693
+ ), s.add(c.name);
656
694
  return;
657
695
  }
658
- s.add(N(c.type ?? "string"));
696
+ s.add(R(a.type ?? "string"));
659
697
  });
660
- const i = ge(n) ? "|" : "&";
698
+ const i = Te(n) ? "|" : "&";
661
699
  return Array.from(s).join(i);
662
700
  }
663
701
  }
664
- function Ee(o) {
702
+ function qe(o) {
665
703
  let e = 0, t = 0;
666
704
  return o.commands.forEach((n) => {
667
- n.path.startsWith(v.TENANT) && (e += 1), n.path.startsWith(v.OWNER) && (t += 1);
705
+ n.path.startsWith(M.TENANT) && (e += 1), n.path.startsWith(M.OWNER) && (t += 1);
668
706
  }), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
669
707
  }
670
- function z(o, e, t, n) {
708
+ function Z(o, e, t, n) {
671
709
  const r = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
672
- return D(o, e, r);
710
+ return Y(o, e, r);
673
711
  }
674
- function Ie(o, e) {
675
- return `${$(o.aggregateName)}${e}`;
712
+ function Me(o, e) {
713
+ return `${A(o.aggregateName)}${e}`;
676
714
  }
677
- class Se extends x {
715
+ function N(o) {
716
+ return o === "delete" ? "del" : o;
717
+ }
718
+ class je {
678
719
  /**
679
720
  * Creates a new QueryClientGenerator instance.
680
721
  * @param context - The generation context containing OpenAPI spec and project details
681
722
  */
682
723
  constructor(e) {
683
- super(e);
724
+ this.context = e;
684
725
  }
685
726
  /**
686
727
  * Generates query client classes for all aggregates.
687
728
  */
688
729
  generate() {
689
- const e = Array.from(this.contextAggregates.values()).reduce(
730
+ const e = Array.from(this.context.contextAggregates.values()).reduce(
690
731
  (n, r) => n + r.size,
691
732
  0
692
733
  );
693
- this.logger.info("--- Generating Query Clients ---"), this.logger.progress(
734
+ this.context.logger.info("--- Generating Query Clients ---"), this.context.logger.progress(
694
735
  `Generating query clients for ${e} aggregates`
695
736
  );
696
737
  let t = 0;
697
- for (const [, n] of this.contextAggregates)
738
+ for (const [, n] of this.context.contextAggregates)
698
739
  n.forEach((r) => {
699
- t++, this.logger.progressWithCount(
740
+ t++, this.context.logger.progressWithCount(
700
741
  t,
701
742
  e,
702
743
  `Processing query client for aggregate: ${r.aggregate.aggregateName}`
703
744
  ), this.processQueryClient(r);
704
745
  });
705
- this.logger.success("Query client generation completed");
746
+ this.context.logger.success("Query client generation completed");
706
747
  }
707
748
  /**
708
749
  * Creates or retrieves a source file for client generation.
@@ -711,9 +752,9 @@ class Se extends x {
711
752
  * @returns The source file for the client
712
753
  */
713
754
  createClientFilePath(e, t) {
714
- return z(
715
- this.project,
716
- this.outputDir,
755
+ return Z(
756
+ this.context.project,
757
+ this.context.outputDir,
717
758
  e,
718
759
  t
719
760
  );
@@ -727,12 +768,12 @@ class Se extends x {
727
768
  e.aggregate,
728
769
  "queryClient"
729
770
  );
730
- this.logger.info(
771
+ this.context.logger.info(
731
772
  `Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
732
- ), this.logger.info(
733
- `Adding imports from ${A}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
773
+ ), this.context.logger.info(
774
+ `Adding imports from ${C}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
734
775
  ), t.addImportDeclaration({
735
- moduleSpecifier: A,
776
+ moduleSpecifier: C,
736
777
  namedImports: [
737
778
  "QueryClientFactory",
738
779
  "QueryClientOptions",
@@ -740,10 +781,10 @@ class Se extends x {
740
781
  ]
741
782
  });
742
783
  const n = "DEFAULT_QUERY_CLIENT_OPTIONS";
743
- this.logger.info(
784
+ this.context.logger.info(
744
785
  `Creating default query client options: ${n}`
745
786
  ), t.addVariableStatement({
746
- declarationKind: E.Const,
787
+ declarationKind: v.Const,
747
788
  declarations: [
748
789
  {
749
790
  name: n,
@@ -751,100 +792,145 @@ class Se extends x {
751
792
  initializer: `{
752
793
  contextAlias: '${e.aggregate.contextAlias}',
753
794
  aggregateName: '${e.aggregate.aggregateName}',
754
- resourceAttribution: ${Ee(e)},
795
+ resourceAttribution: ${qe(e)},
755
796
  }`
756
797
  }
757
798
  ],
758
799
  isExported: !1
759
800
  });
760
801
  const r = [];
761
- this.logger.info(
802
+ this.context.logger.info(
762
803
  `Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
763
804
  );
764
805
  for (const u of e.events.values()) {
765
- const l = d(u.schema.key);
766
- this.logger.info(
767
- `Adding import for event model: ${l.name} from path: ${l.path}`
768
- ), y(t, this.outputDir, l), r.push(l);
806
+ const p = m(u.schema.key);
807
+ this.context.logger.info(
808
+ `Adding import for event model: ${p.name} from path: ${p.path}`
809
+ ), f(t, this.context.outputDir, p), r.push(p);
769
810
  }
770
811
  const s = "DOMAIN_EVENT_TYPES", i = r.map((u) => u.name).join(" | ");
771
- this.logger.info(
812
+ this.context.logger.info(
772
813
  `Creating domain event types union: ${s} = ${i}`
773
814
  ), t.addTypeAlias({
774
815
  name: s,
775
816
  type: i
776
817
  });
777
- const c = `${h(e.aggregate.aggregateName)}QueryClientFactory`, a = d(e.state.key), p = d(e.fields.key);
778
- this.logger.info(
779
- `Adding import for state model: ${a.name} from path: ${a.path}`
780
- ), y(t, this.outputDir, a), this.logger.info(
781
- `Adding import for fields model: ${p.name} from path: ${p.path}`
782
- ), y(t, this.outputDir, p), this.logger.info(`Creating query client factory: ${c}`), t.addVariableStatement({
783
- declarationKind: E.Const,
818
+ const a = `${h(e.aggregate.aggregateName)}QueryClientFactory`, c = m(e.state.key), g = m(e.fields.key);
819
+ this.context.logger.info(
820
+ `Adding import for state model: ${c.name} from path: ${c.path}`
821
+ ), f(t, this.context.outputDir, c), this.context.logger.info(
822
+ `Adding import for fields model: ${g.name} from path: ${g.path}`
823
+ ), f(t, this.context.outputDir, g), this.context.logger.info(`Creating query client factory: ${a}`), t.addVariableStatement({
824
+ declarationKind: v.Const,
784
825
  declarations: [
785
826
  {
786
- name: c,
787
- initializer: `new QueryClientFactory<${a.name}, ${p.name} | string, ${s}>(${n})`
827
+ name: a,
828
+ initializer: `new QueryClientFactory<${c.name}, ${g.name} | string, ${s}>(${n})`
788
829
  }
789
830
  ],
790
831
  isExported: !0
791
- }), this.logger.success(
832
+ }), this.context.logger.success(
792
833
  `Query client generation completed for aggregate: ${e.aggregate.aggregateName}`
793
834
  );
794
835
  }
795
836
  }
796
- class Ne extends x {
797
- commandEndpointPathsName = "COMMAND_ENDPOINT_PATHS";
798
- defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
837
+ const Ge = "@ahoo-wang/fetcher-decorator", Fe = [
838
+ "type ApiMetadata",
839
+ "type ApiMetadataCapable",
840
+ "api",
841
+ "post",
842
+ "put",
843
+ "patch",
844
+ "del",
845
+ "request",
846
+ "attribute",
847
+ "path",
848
+ "autoGeneratedError"
849
+ ], ee = `{
850
+ headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
851
+ resultExtractor: JsonEventStreamResultExtractor,
852
+ }`;
853
+ function te(o) {
854
+ E(o, Ge, Fe);
855
+ }
856
+ function ne(o, e, t = []) {
857
+ return e.addClass({
858
+ name: o,
859
+ isExported: !0,
860
+ decorators: [
861
+ {
862
+ name: "api",
863
+ arguments: t
864
+ }
865
+ ]
866
+ });
867
+ }
868
+ function oe(o, e) {
869
+ o.addImplements("ApiMetadataCapable"), o.addConstructor({
870
+ parameters: [
871
+ {
872
+ name: "apiMetadata",
873
+ type: "ApiMetadata",
874
+ hasQuestionToken: e === void 0,
875
+ scope: se.Public,
876
+ isReadonly: !0,
877
+ initializer: e
878
+ }
879
+ ]
880
+ });
881
+ }
882
+ class _e {
799
883
  /**
800
884
  * Creates a new CommandClientGenerator instance.
801
885
  * @param context - The generation context containing OpenAPI spec and project details
802
886
  */
803
887
  constructor(e) {
804
- super(e);
888
+ this.context = e;
805
889
  }
890
+ commandEndpointPathsName = "COMMAND_ENDPOINT_PATHS";
891
+ defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
806
892
  /**
807
893
  * Generates command client classes for all aggregates.
808
894
  */
809
895
  generate() {
810
- const e = Array.from(this.contextAggregates.values()).reduce(
896
+ const e = Array.from(this.context.contextAggregates.values()).reduce(
811
897
  (n, r) => n + r.size,
812
898
  0
813
899
  );
814
- this.logger.info("--- Generating Command Clients ---"), this.logger.progress(
900
+ this.context.logger.info("--- Generating Command Clients ---"), this.context.logger.progress(
815
901
  `Generating command clients for ${e} aggregates`
816
902
  );
817
903
  let t = 0;
818
- for (const [, n] of this.contextAggregates)
904
+ for (const [, n] of this.context.contextAggregates)
819
905
  n.forEach((r) => {
820
- t++, this.logger.progressWithCount(
906
+ t++, this.context.logger.progressWithCount(
821
907
  t,
822
908
  e,
823
909
  `Processing command client for aggregate: ${r.aggregate.aggregateName}`
824
910
  ), this.processAggregate(r);
825
911
  });
826
- this.logger.success("Command client generation completed");
912
+ this.context.logger.success("Command client generation completed");
827
913
  }
828
914
  /**
829
915
  * Processes and generates command client for an aggregate.
830
916
  * @param aggregate - The aggregate definition
831
917
  */
832
918
  processAggregate(e) {
833
- this.logger.info(
919
+ this.context.logger.info(
834
920
  `Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
835
921
  );
836
- const t = z(
837
- this.project,
838
- this.outputDir,
922
+ const t = Z(
923
+ this.context.project,
924
+ this.context.outputDir,
839
925
  e.aggregate,
840
926
  "commandClient"
841
927
  );
842
- this.logger.info(
928
+ this.context.logger.info(
843
929
  `Processing command endpoint paths for ${e.commands.size} commands`
844
- ), this.processCommandEndpointPaths(t, e), this.logger.info(
930
+ ), this.processCommandEndpointPaths(t, e), this.context.logger.info(
845
931
  `Creating default command client options: ${this.defaultCommandClientOptionsName}`
846
932
  ), t.addVariableStatement({
847
- declarationKind: E.Const,
933
+ declarationKind: v.Const,
848
934
  declarations: [
849
935
  {
850
936
  name: this.defaultCommandClientOptionsName,
@@ -855,10 +941,10 @@ class Ne extends x {
855
941
  }
856
942
  ],
857
943
  isExported: !1
858
- }), this.logger.info(
859
- `Adding imports from ${A}: CommandRequest, CommandResult, CommandResultEventStream, DeleteAggregate, RecoverAggregate`
944
+ }), this.context.logger.info(
945
+ `Adding imports from ${C}: CommandRequest, CommandResult, CommandResultEventStream, DeleteAggregate, RecoverAggregate`
860
946
  ), t.addImportDeclaration({
861
- moduleSpecifier: A,
947
+ moduleSpecifier: C,
862
948
  namedImports: [
863
949
  "CommandRequest",
864
950
  "CommandResult",
@@ -867,46 +953,34 @@ class Ne extends x {
867
953
  "RecoverAggregate"
868
954
  ],
869
955
  isTypeOnly: !0
870
- }), this.logger.info(
956
+ }), this.context.logger.info(
871
957
  "Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
872
958
  ), t.addImportDeclaration({
873
959
  moduleSpecifier: "@ahoo-wang/fetcher-eventstream",
874
960
  namedImports: ["JsonEventStreamResultExtractor"]
875
- }), this.logger.info(
961
+ }), this.context.logger.info(
876
962
  "Adding import from @ahoo-wang/fetcher: ContentTypeValues"
877
- ), w(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.logger.info(
963
+ ), E(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
878
964
  "Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
879
- ), w(t, "@ahoo-wang/fetcher-decorator", [
880
- "type ApiMetadata",
881
- "type ApiMetadataCapable",
882
- "api",
883
- "post",
884
- "put",
885
- "patch",
886
- "del",
887
- "request",
888
- "attribute",
889
- "path",
890
- "autoGeneratedError"
891
- ]), this.logger.info("Generating standard command client class"), this.processCommandClient(t, e), this.logger.info("Generating stream command client class"), this.processCommandClient(t, e, !0), this.logger.success(
965
+ ), te(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e), this.context.logger.info("Generating stream command client class"), this.processCommandClient(t, e, !0), this.context.logger.success(
892
966
  `Command client generation completed for aggregate: ${e.aggregate.aggregateName}`
893
967
  );
894
968
  }
895
969
  processCommandEndpointPaths(e, t) {
896
- this.logger.info(
970
+ this.context.logger.info(
897
971
  `Creating command endpoint paths enum: ${this.commandEndpointPathsName}`
898
972
  );
899
973
  const n = e.addEnum({
900
974
  name: this.commandEndpointPathsName
901
975
  });
902
976
  t.commands.forEach((r) => {
903
- this.logger.info(
977
+ this.context.logger.info(
904
978
  `Adding command endpoint: ${r.name.toUpperCase()} = '${r.path}'`
905
979
  ), n.addMember({
906
980
  name: r.name.toUpperCase(),
907
981
  initializer: `'${r.path}'`
908
982
  });
909
- }), this.logger.success(
983
+ }), this.context.logger.success(
910
984
  `Command endpoint paths enum created with ${t.commands.size} entries`
911
985
  );
912
986
  }
@@ -914,45 +988,18 @@ class Ne extends x {
914
988
  return `${this.commandEndpointPathsName}.${e.name.toUpperCase()}`;
915
989
  }
916
990
  processCommandClient(e, t, n = !1) {
917
- let r = "CommandClient", s = {
918
- name: "api",
919
- arguments: []
920
- }, i = "Promise<CommandResult>";
921
- n && (r = "Stream" + r, s = {
922
- name: "api",
923
- arguments: [
924
- "''",
925
- `{
926
- headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
927
- resultExtractor: JsonEventStreamResultExtractor,
928
- }`
929
- ]
930
- }, i = "Promise<CommandResultEventStream>");
931
- const c = Ie(
991
+ let r = "CommandClient", s = [], i = "Promise<CommandResult>";
992
+ n && (r = "Stream" + r, s = [
993
+ "''",
994
+ ee
995
+ ], i = "Promise<CommandResultEventStream>");
996
+ const a = Me(
932
997
  t.aggregate,
933
998
  r
934
- ), a = e.addClass({
935
- name: c,
936
- isExported: !0,
937
- decorators: [s],
938
- implements: ["ApiMetadataCapable"]
999
+ ), c = ne(a, e, s);
1000
+ oe(c, this.defaultCommandClientOptionsName), t.commands.forEach((g) => {
1001
+ this.processCommandMethod(e, c, g, i);
939
1002
  });
940
- a.addConstructor({
941
- parameters: [
942
- {
943
- name: "apiMetadata",
944
- type: "ApiMetadata",
945
- scope: Q.Public,
946
- isReadonly: !0,
947
- initializer: `${this.defaultCommandClientOptionsName}`
948
- }
949
- ]
950
- }), t.commands.forEach((p) => {
951
- this.processCommandMethod(e, a, p, i);
952
- });
953
- }
954
- methodToDecorator(e) {
955
- return e === "delete" ? "del" : e;
956
1003
  }
957
1004
  /**
958
1005
  * Processes and generates a command method for the command client.
@@ -961,32 +1008,32 @@ class Ne extends x {
961
1008
  * @param definition - The command definition
962
1009
  */
963
1010
  processCommandMethod(e, t, n, r) {
964
- const s = d(n.schema.key);
965
- this.logger.info(
1011
+ const s = m(n.schema.key);
1012
+ this.context.logger.info(
966
1013
  `Adding import for command model: ${s.name} from path: ${s.path}`
967
- ), y(e, this.outputDir, s), this.logger.info(
1014
+ ), f(e, this.context.outputDir, s), this.context.logger.info(
968
1015
  `Generating command method: ${h(n.name)} for command: ${n.name}`
969
- ), this.logger.info(
1016
+ ), this.context.logger.info(
970
1017
  `Command method details: HTTP ${n.method}, path: ${n.path}, return type: ${r}`
971
1018
  );
972
- const i = n.pathParameters.map((a) => (this.logger.info(
973
- `Adding path parameter: ${a.name} (type: string)`
1019
+ const i = n.pathParameters.map((c) => (this.context.logger.info(
1020
+ `Adding path parameter: ${c.name} (type: string)`
974
1021
  ), {
975
- name: a.name,
1022
+ name: c.name,
976
1023
  type: "string",
977
1024
  hasQuestionToken: !1,
978
1025
  decorators: [
979
1026
  {
980
1027
  name: "path",
981
- arguments: [`'${a.name}'`]
1028
+ arguments: [`'${c.name}'`]
982
1029
  }
983
1030
  ]
984
1031
  }));
985
- this.logger.info(
1032
+ this.context.logger.info(
986
1033
  `Adding command request parameter: commandRequest (type: CommandRequest<${s.name}>)`
987
1034
  ), i.push({
988
1035
  name: "commandRequest",
989
- hasQuestionToken: ue(n.schema.schema),
1036
+ hasQuestionToken: Se(n.schema.schema),
990
1037
  type: `CommandRequest<${s.name}>`,
991
1038
  decorators: [
992
1039
  {
@@ -994,7 +1041,7 @@ class Ne extends x {
994
1041
  arguments: []
995
1042
  }
996
1043
  ]
997
- }), this.logger.info(
1044
+ }), this.context.logger.info(
998
1045
  "Adding attributes parameter: attributes (type: Record<string, any>)"
999
1046
  ), i.push({
1000
1047
  name: "attributes",
@@ -1007,53 +1054,438 @@ class Ne extends x {
1007
1054
  }
1008
1055
  ]
1009
1056
  });
1010
- const c = t.addMethod({
1057
+ const a = t.addMethod({
1011
1058
  name: h(n.name),
1012
1059
  decorators: [
1013
1060
  {
1014
- name: this.methodToDecorator(n.method),
1061
+ name: N(n.method),
1015
1062
  arguments: [`${this.getEndpointPath(n)}`]
1016
1063
  }
1017
1064
  ],
1018
1065
  parameters: i,
1019
1066
  returnType: r,
1020
1067
  statements: [
1021
- `throw autoGeneratedError(${i.map((a) => a.name).join(",")});`
1068
+ `throw autoGeneratedError(${i.map((c) => c.name).join(",")});`
1022
1069
  ]
1023
1070
  });
1024
- (n.summary || n.description) && this.logger.info(
1071
+ (n.summary || n.description) && this.context.logger.info(
1025
1072
  `Adding JSDoc documentation for method: ${h(n.name)}`
1026
- ), P(c, n.summary, n.description), this.logger.success(
1073
+ ), x(a, n.summary, n.description), this.context.logger.success(
1027
1074
  `Command method generated: ${h(n.name)}`
1028
1075
  );
1029
1076
  }
1030
1077
  }
1031
- class De extends x {
1032
- queryClientGenerator;
1033
- commandClientGenerator;
1078
+ class We {
1079
+ /**
1080
+ * Creates a new ApiClientGenerator instance.
1081
+ * @param context - The generation context containing OpenAPI spec and configuration
1082
+ */
1083
+ constructor(e) {
1084
+ this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:'${this.context.currentContextAlias}'}` : void 0;
1085
+ }
1086
+ defaultParameterRequestType = "ParameterRequest";
1087
+ defaultReturnType = { type: "Promise<any>" };
1088
+ apiMetadataCtorInitializer;
1089
+ /**
1090
+ * Generates API client classes for all valid tags in the OpenAPI specification.
1091
+ * Processes tags, groups operations, and creates client classes with methods.
1092
+ */
1093
+ generate() {
1094
+ this.context.logger.info("Starting API client generation");
1095
+ const e = this.resolveApiTags();
1096
+ this.context.logger.info(
1097
+ `Resolved ${e.size} API client tags: ${Array.from(e.keys()).join(", ")}`
1098
+ );
1099
+ const t = this.groupOperations(e);
1100
+ this.context.logger.info(
1101
+ `Grouped operations into ${t.size} tag groups`
1102
+ ), this.generateApiClients(e, t), this.context.logger.success("API client generation completed");
1103
+ }
1104
+ /**
1105
+ * Generates API client classes for each tag group.
1106
+ * @param apiClientTags - Map of valid API client tags
1107
+ * @param groupOperations - Map of operations grouped by tag
1108
+ */
1109
+ generateApiClients(e, t) {
1110
+ this.context.logger.info(
1111
+ `Generating ${t.size} API client classes`
1112
+ );
1113
+ let n = 0;
1114
+ for (const [r, s] of t) {
1115
+ n++, this.context.logger.progressWithCount(
1116
+ n,
1117
+ t.size,
1118
+ `Generating API client for tag: ${r}`
1119
+ );
1120
+ const i = e.get(r);
1121
+ this.generateApiClient(i, s);
1122
+ }
1123
+ }
1124
+ /**
1125
+ * Creates a new source file for the API client.
1126
+ * @param modelInfo - The model information for the client
1127
+ * @returns The created source file
1128
+ */
1129
+ createApiClientFile(e) {
1130
+ let t = e.path;
1131
+ return this.context.currentContextAlias && (t = S(this.context.currentContextAlias, t)), t = S(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
1132
+ }
1133
+ /**
1134
+ * Generates a single API client class for the given tag and operations.
1135
+ * @param tag - The OpenAPI tag for the client
1136
+ * @param operations - Set of operations for this client
1137
+ */
1138
+ generateApiClient(e, t) {
1139
+ const n = m(e.name);
1140
+ this.context.logger.info(
1141
+ `Generating API client class: ${n.name}ApiClient with ${t.size} operations`
1142
+ );
1143
+ const r = this.createApiClientFile(n);
1144
+ te(r);
1145
+ const s = ne(
1146
+ n.name + "ApiClient",
1147
+ r
1148
+ );
1149
+ x(s, e.description), oe(s, this.apiMetadataCtorInitializer), this.context.logger.info(
1150
+ `Processing ${t.size} operations for ${n.name}ApiClient`
1151
+ ), t.forEach((i) => {
1152
+ this.processOperation(e, r, s, i);
1153
+ }), this.context.logger.success(
1154
+ `Completed API client: ${n.name}ApiClient`
1155
+ );
1156
+ }
1157
+ /**
1158
+ * Generates a unique method name for the operation.
1159
+ * @param apiClientClass - The client class to check for existing methods
1160
+ * @param operation - The operation to generate a name for
1161
+ * @returns A unique camelCase method name
1162
+ */
1163
+ getMethodName(e, t) {
1164
+ const n = t.operationId.split(".");
1165
+ for (let r = n.length - 1; r >= 0; r--) {
1166
+ const s = h(n.slice(r));
1167
+ if (!e.getMethod(s))
1168
+ return s;
1169
+ }
1170
+ return h(n);
1171
+ }
1172
+ /**
1173
+ * Resolves the request type for an operation based on its request body.
1174
+ * @param sourceFile - The source file to add imports to
1175
+ * @param operation - The operation to resolve the request type for
1176
+ * @returns The resolved request type string
1177
+ */
1178
+ resolveRequestType(e, t) {
1179
+ if (!t.requestBody)
1180
+ return this.context.logger.info(
1181
+ `No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
1182
+ ), this.defaultParameterRequestType;
1183
+ let n;
1184
+ if (l(t.requestBody) ? (this.context.logger.info(
1185
+ `Extracting request body from reference for operation: ${t.operationId}`
1186
+ ), n = B(
1187
+ t.requestBody,
1188
+ this.context.openAPI.components
1189
+ )) : n = t.requestBody, !n)
1190
+ return this.context.logger.info(
1191
+ `Request body extraction failed for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
1192
+ ), this.defaultParameterRequestType;
1193
+ if (n.content["multipart/form-data"])
1194
+ return this.context.logger.info(
1195
+ `Detected multipart/form-data content for operation ${t.operationId}, using ParameterRequest<FormData>`
1196
+ ), "ParameterRequest<FormData>";
1197
+ if (n.content["application/json"]) {
1198
+ const r = n.content["application/json"].schema;
1199
+ if (l(r)) {
1200
+ const s = y(r);
1201
+ this.context.logger.info(
1202
+ `Adding import for request body model: ${s.name} from ${s.path}`
1203
+ ), f(e, this.context.outputDir, s);
1204
+ const i = `ParameterRequest<${s.name}>`;
1205
+ return this.context.logger.info(
1206
+ `Resolved request type for operation ${t.operationId}: ${i}`
1207
+ ), i;
1208
+ }
1209
+ }
1210
+ return this.context.logger.info(
1211
+ `Using default request type for operation ${t.operationId}: ${this.defaultParameterRequestType}`
1212
+ ), this.defaultParameterRequestType;
1213
+ }
1214
+ /**
1215
+ * Resolves method parameters for an operation.
1216
+ * @param tag - The tag for parameter filtering
1217
+ * @param sourceFile - The source file to add imports to
1218
+ * @param operation - The operation to resolve parameters for
1219
+ * @returns Array of parameter declarations
1220
+ */
1221
+ resolveParameters(e, t, n) {
1222
+ if (!n.parameters)
1223
+ return this.context.logger.info(
1224
+ `No parameters found for operation ${n.operationId}`
1225
+ ), [];
1226
+ const r = n.parameters?.filter((a) => !l(a) && a.in === "path" && !this.context.isIgnoreApiClientPathParameters(
1227
+ e.name,
1228
+ a.name
1229
+ )) ?? [];
1230
+ this.context.logger.info(
1231
+ `Found ${r.length} path parameters for operation ${n.operationId}`
1232
+ );
1233
+ const s = r.map((a) => (this.context.logger.info(
1234
+ `Adding path parameter: ${a.name} (type: string)`
1235
+ ), {
1236
+ name: a.name,
1237
+ type: "string",
1238
+ hasQuestionToken: !1,
1239
+ decorators: [
1240
+ {
1241
+ name: "path",
1242
+ arguments: [`'${a.name}'`]
1243
+ }
1244
+ ]
1245
+ })), i = this.resolveRequestType(t, n);
1246
+ return this.context.logger.info(`Adding httpRequest parameter: ${i}`), s.push({
1247
+ name: "httpRequest",
1248
+ hasQuestionToken: i === this.defaultParameterRequestType,
1249
+ type: `${i}`,
1250
+ decorators: [
1251
+ {
1252
+ name: "request",
1253
+ arguments: []
1254
+ }
1255
+ ]
1256
+ }), this.context.logger.info(
1257
+ "Adding attributes parameter: Record<string, any>"
1258
+ ), s.push({
1259
+ name: "attributes",
1260
+ hasQuestionToken: !0,
1261
+ type: "Record<string, any>",
1262
+ decorators: [
1263
+ {
1264
+ name: "attribute",
1265
+ arguments: []
1266
+ }
1267
+ ]
1268
+ }), s;
1269
+ }
1270
+ /**
1271
+ * Resolves the return type for a schema.
1272
+ * @param sourceFile - The source file to add imports to
1273
+ * @param schema - The schema to resolve the return type for
1274
+ * @returns The resolved return type string
1275
+ */
1276
+ resolveSchemaReturnType(e, t) {
1277
+ if (l(t)) {
1278
+ const n = y(t);
1279
+ this.context.logger.info(
1280
+ `Adding import for response model: ${n.name} from ${n.path}`
1281
+ ), f(e, this.context.outputDir, n);
1282
+ const r = `Promise<${n.name}>`;
1283
+ return this.context.logger.info(`Resolved reference return type: ${r}`), r;
1284
+ }
1285
+ if (!t.type)
1286
+ return this.context.logger.info(
1287
+ `Schema has no type, using default return type: ${this.defaultReturnType.type}`
1288
+ ), this.defaultReturnType.type;
1289
+ if (V(t.type)) {
1290
+ const r = `Promise<${R(t.type)}>`;
1291
+ return this.context.logger.info(`Resolved primitive return type: ${r}`), r;
1292
+ }
1293
+ return this.context.logger.info(
1294
+ `Using default return type: ${this.defaultReturnType.type}`
1295
+ ), this.defaultReturnType.type;
1296
+ }
1297
+ /**
1298
+ * Resolves the return type for an operation based on its responses.
1299
+ * @param sourceFile - The source file to add imports to
1300
+ * @param operation - The operation to resolve the return type for
1301
+ * @returns Object containing type and optional stream flag
1302
+ */
1303
+ resolveReturnType(e, t) {
1304
+ const n = b(t);
1305
+ if (!n)
1306
+ return this.context.logger.info(
1307
+ `No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
1308
+ ), this.defaultReturnType;
1309
+ const r = U(n);
1310
+ if (r) {
1311
+ const a = this.resolveSchemaReturnType(e, r);
1312
+ return this.context.logger.info(
1313
+ `Resolved JSON response return type for operation ${t.operationId}: ${a}`
1314
+ ), {
1315
+ stream: !1,
1316
+ type: a
1317
+ };
1318
+ }
1319
+ const s = Ae(n);
1320
+ if (s) {
1321
+ if (l(s)) {
1322
+ const c = w(
1323
+ s,
1324
+ this.context.openAPI.components
1325
+ );
1326
+ if (O(c) && l(c.items)) {
1327
+ const g = y(c.items);
1328
+ this.context.logger.info(
1329
+ `Adding import for event stream model: ${g.name} from ${g.path}`
1330
+ ), f(e, this.context.outputDir, g);
1331
+ const p = `Promise<JsonServerSentEventStream<${g.name.includes("ServerSentEvent") ? `${g.name}['data']` : g.name}>>`;
1332
+ return this.context.logger.info(
1333
+ `Resolved event stream return type for operation ${t.operationId}: ${p}`
1334
+ ), {
1335
+ stream: !0,
1336
+ type: p
1337
+ };
1338
+ }
1339
+ }
1340
+ const a = "Promise<JsonServerSentEventStream<any>>";
1341
+ return this.context.logger.info(
1342
+ `Resolved generic event stream return type for operation ${t.operationId}: ${a}`
1343
+ ), { stream: !0, type: a };
1344
+ }
1345
+ const i = Ce(n);
1346
+ if (i) {
1347
+ const a = this.resolveSchemaReturnType(
1348
+ e,
1349
+ i
1350
+ );
1351
+ return this.context.logger.info(
1352
+ `Resolved wildcard response return type for operation ${t.operationId}: ${a}`
1353
+ ), { type: a };
1354
+ }
1355
+ return this.context.logger.info(
1356
+ `Using default return type for operation ${t.operationId}: ${this.defaultReturnType.type}`
1357
+ ), this.defaultReturnType;
1358
+ }
1359
+ /**
1360
+ * Processes a single operation and adds it as a method to the client class.
1361
+ * @param tag - The tag for parameter filtering
1362
+ * @param sourceFile - The source file containing the client
1363
+ * @param apiClientClass - The client class to add the method to
1364
+ * @param operation - The operation to process
1365
+ */
1366
+ processOperation(e, t, n, r) {
1367
+ this.context.logger.info(
1368
+ `Processing operation: ${r.operation.operationId} (${r.method} ${r.path})`
1369
+ );
1370
+ const s = this.getMethodName(n, r.operation);
1371
+ this.context.logger.info(`Generated method name: ${s}`);
1372
+ const i = this.resolveParameters(
1373
+ e,
1374
+ t,
1375
+ r.operation
1376
+ ), a = this.resolveReturnType(t, r.operation), c = a.stream ? {
1377
+ name: N(r.method),
1378
+ arguments: [`'${r.path}'`, ee]
1379
+ } : {
1380
+ name: N(r.method),
1381
+ arguments: [`'${r.path}'`]
1382
+ };
1383
+ this.context.logger.info(
1384
+ `Creating method with ${i.length} parameters, return type: ${a.type}, stream: ${a.stream || !1}`
1385
+ );
1386
+ const g = n.addMethod({
1387
+ name: s,
1388
+ decorators: [c],
1389
+ parameters: i,
1390
+ returnType: a.type,
1391
+ statements: [
1392
+ `throw autoGeneratedError(${i.map((u) => u.name).join(",")});`
1393
+ ]
1394
+ });
1395
+ x(
1396
+ g,
1397
+ r.operation.summary,
1398
+ r.operation.description
1399
+ ), this.context.logger.success(`Operation method generated: ${s}`);
1400
+ }
1401
+ /**
1402
+ * Groups operations by their tags for client generation.
1403
+ * @param apiClientTags - Map of valid API client tags
1404
+ * @returns Map of operations grouped by tag name
1405
+ */
1406
+ groupOperations(e) {
1407
+ this.context.logger.info("Grouping operations by API client tags");
1408
+ const t = /* @__PURE__ */ new Map();
1409
+ let n = 0;
1410
+ for (const [r, s] of Object.entries(this.context.openAPI.paths)) {
1411
+ const i = J(s).filter(
1412
+ (a) => {
1413
+ if (!a.operation.operationId)
1414
+ return !1;
1415
+ const c = a.operation.tags;
1416
+ return !c || c.length == 0 ? !1 : c.every((g) => e.has(g));
1417
+ }
1418
+ );
1419
+ this.context.logger.info(
1420
+ `Path ${r}: found ${i.length} valid operations`
1421
+ );
1422
+ for (const a of i)
1423
+ a.operation.tags.forEach((c) => {
1424
+ const g = {
1425
+ ...a,
1426
+ path: r
1427
+ };
1428
+ t.has(c) || t.set(c, /* @__PURE__ */ new Set()), t.get(c).add(g), n++;
1429
+ });
1430
+ }
1431
+ return this.context.logger.info(
1432
+ `Grouped ${n} operations into ${t.size} tag groups`
1433
+ ), t;
1434
+ }
1435
+ /**
1436
+ * Resolves valid API client tags from the OpenAPI specification.
1437
+ * Filters out system tags like 'wow' and 'Actuator' and aggregate tags.
1438
+ * @returns Map of valid API client tags
1439
+ */
1440
+ resolveApiTags() {
1441
+ this.context.logger.info(
1442
+ "Resolving API client tags from OpenAPI specification"
1443
+ );
1444
+ const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
1445
+ let n = 0;
1446
+ return this.context.openAPI.tags?.forEach((r) => {
1447
+ r.name != "wow" && r.name != "Actuator" && !this.isAggregateTag(r) ? (e.set(r.name, r), n++, this.context.logger.info(`Included API client tag: ${r.name}`)) : this.context.logger.info(
1448
+ `Excluded tag: ${r.name} (wow/Actuator/aggregate)`
1449
+ );
1450
+ }), this.context.logger.info(
1451
+ `Resolved ${n} API client tags from ${t} total tags`
1452
+ ), e;
1453
+ }
1454
+ isAggregateTag(e) {
1455
+ for (const t of this.context.contextAggregates.values())
1456
+ for (const n of t)
1457
+ if (n.aggregate.tag.name === e.name)
1458
+ return !0;
1459
+ return !1;
1460
+ }
1461
+ }
1462
+ class ze {
1034
1463
  /**
1035
1464
  * Creates a new ClientGenerator instance.
1036
1465
  * @param context - The generation context containing OpenAPI spec and project details
1037
1466
  */
1038
1467
  constructor(e) {
1039
- super(e), this.queryClientGenerator = new Se(e), this.commandClientGenerator = new Ne(e);
1468
+ this.context = e, this.queryClientGenerator = new je(e), this.commandClientGenerator = new _e(e), this.apiClientGenerator = new We(e);
1040
1469
  }
1470
+ queryClientGenerator;
1471
+ commandClientGenerator;
1472
+ apiClientGenerator;
1041
1473
  /**
1042
1474
  * Generates client classes for all aggregates.
1043
1475
  */
1044
1476
  generate() {
1045
- this.logger.info("--- Generating Clients ---"), this.logger.progress(
1046
- `Generating clients for ${this.contextAggregates.size} bounded contexts`
1477
+ this.context.logger.info("--- Generating Clients ---"), this.context.logger.progress(
1478
+ `Generating clients for ${this.context.contextAggregates.size} bounded contexts`
1047
1479
  );
1048
1480
  let e = 0;
1049
- for (const [t] of this.contextAggregates)
1050
- e++, this.logger.progressWithCount(
1481
+ for (const [t] of this.context.contextAggregates)
1482
+ e++, this.context.logger.progressWithCount(
1051
1483
  e,
1052
- this.contextAggregates.size,
1484
+ this.context.contextAggregates.size,
1053
1485
  `Processing bounded context: ${t}`,
1054
1486
  1
1055
1487
  ), this.processBoundedContext(t);
1056
- this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.logger.success("Client generation completed");
1488
+ this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
1057
1489
  }
1058
1490
  /**
1059
1491
  * Processes a bounded context by creating a file with the context alias constant.
@@ -1061,18 +1493,43 @@ class De extends x {
1061
1493
  */
1062
1494
  processBoundedContext(e) {
1063
1495
  const t = `${e}/boundedContext.ts`;
1064
- this.logger.info(`Creating bounded context file: ${t}`);
1065
- const n = D(this.project, this.outputDir, t);
1066
- this.logger.info(
1496
+ this.context.logger.info(`Creating bounded context file: ${t}`);
1497
+ const n = this.context.getOrCreateSourceFile(t);
1498
+ this.context.logger.info(
1067
1499
  `Adding bounded context alias constant: BOUNDED_CONTEXT_ALIAS = '${e}'`
1068
1500
  ), n.addStatements(
1069
1501
  `export const BOUNDED_CONTEXT_ALIAS = '${e}';`
1070
- ), this.logger.success(
1502
+ ), this.context.logger.success(
1071
1503
  `Bounded context file created successfully: ${t}`
1072
1504
  );
1073
1505
  }
1074
1506
  }
1075
- class qe {
1507
+ class Be {
1508
+ /** The ts-morph project instance used for code generation */
1509
+ project;
1510
+ /** The OpenAPI specification object */
1511
+ openAPI;
1512
+ /** The output directory path for generated files */
1513
+ outputDir;
1514
+ /** Map of bounded context aggregates for domain modeling */
1515
+ contextAggregates;
1516
+ /** Optional logger for generation progress and errors */
1517
+ logger;
1518
+ config;
1519
+ defaultIgnorePathParameters = ["tenantId", "ownerId"];
1520
+ currentContextAlias;
1521
+ constructor(e) {
1522
+ this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger, this.config = e.config ?? {}, this.currentContextAlias = this.openAPI.info["x-wow-context-alias"];
1523
+ }
1524
+ getOrCreateSourceFile(e) {
1525
+ return Y(this.project, this.outputDir, e);
1526
+ }
1527
+ isIgnoreApiClientPathParameters(e, t) {
1528
+ return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
1529
+ }
1530
+ }
1531
+ const ke = "./fetcher-generator.config.json";
1532
+ class He {
1076
1533
  /**
1077
1534
  * Creates a new CodeGenerator instance.
1078
1535
  * @param options - Configuration options for code generation
@@ -1090,20 +1547,28 @@ class qe {
1090
1547
  this.options.logger.info(
1091
1548
  "Starting code generation from OpenAPI specification"
1092
1549
  ), this.options.logger.info(`Input path: ${this.options.inputPath}`), this.options.logger.info(`Output directory: ${this.options.outputDir}`), this.options.logger.info("Parsing OpenAPI specification");
1093
- const e = await te(this.options.inputPath);
1550
+ const e = await ye(this.options.inputPath);
1094
1551
  this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
1095
- const n = new $e(e).resolve();
1552
+ const n = new Ne(e).resolve();
1096
1553
  this.options.logger.info(
1097
1554
  `Resolved ${n.size} bounded context aggregates`
1098
1555
  );
1099
- const r = {
1556
+ const r = this.options.configPath ?? ke;
1557
+ let s = {};
1558
+ try {
1559
+ this.options.logger.info("Parsing configuration file:", r), s = await xe(r);
1560
+ } catch (g) {
1561
+ this.options.logger.info("Configuration file parsing failed ", g);
1562
+ }
1563
+ const i = new Be({
1100
1564
  openAPI: e,
1101
1565
  project: this.project,
1102
1566
  outputDir: this.options.outputDir,
1103
1567
  contextAggregates: n,
1104
- logger: this.options.logger
1105
- };
1106
- this.options.logger.info("Generating models"), new Oe(r).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new De(r).generate(), this.options.logger.info("Clients generated successfully"), this.options.logger.info("Generating index files"), this.generateIndex(), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(), this.options.logger.info("Source files optimized successfully"), this.options.logger.info("Saving project to disk"), await this.project.save(), this.options.logger.info("Code generation completed successfully");
1568
+ logger: this.options.logger,
1569
+ config: s
1570
+ });
1571
+ this.options.logger.info("Generating models"), new be(i).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ze(i).generate(), this.options.logger.info("Clients generated successfully"), this.options.logger.info("Generating index files"), this.generateIndex(), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(), this.options.logger.info("Source files optimized successfully"), this.options.logger.info("Saving project to disk"), await this.project.save(), this.options.logger.info("Code generation completed successfully");
1107
1572
  }
1108
1573
  /**
1109
1574
  * Generates index.ts files for all subdirectories in the output directory.
@@ -1137,7 +1602,7 @@ class qe {
1137
1602
  const t = e.getPath();
1138
1603
  this.options.logger.info(`Generating index for directory: ${t}`);
1139
1604
  const n = e.getSourceFiles().filter(
1140
- (c) => c.getBaseName().endsWith(".ts") && c.getBaseName() !== "index.ts"
1605
+ (a) => a.getBaseName().endsWith(".ts") && a.getBaseName() !== "index.ts"
1141
1606
  ), r = e.getDirectories();
1142
1607
  if (this.options.logger.info(
1143
1608
  `Found ${n.length} TypeScript files and ${r.length} subdirectories in ${t}`
@@ -1151,20 +1616,20 @@ class qe {
1151
1616
  this.options.logger.info(`Creating/updating index file: ${s}`);
1152
1617
  const i = this.project.getSourceFile(s) || this.project.createSourceFile(s, "", { overwrite: !0 });
1153
1618
  i.removeText();
1154
- for (const c of n) {
1155
- const a = `./${c.getBaseNameWithoutExtension()}`;
1156
- this.options.logger.info(`Adding export for file: ${a}`), i.addExportDeclaration({
1157
- moduleSpecifier: a,
1619
+ for (const a of n) {
1620
+ const c = `./${a.getBaseNameWithoutExtension()}`;
1621
+ this.options.logger.info(`Adding export for file: ${c}`), i.addExportDeclaration({
1622
+ moduleSpecifier: c,
1158
1623
  isTypeOnly: !1,
1159
1624
  namedExports: []
1160
1625
  });
1161
1626
  }
1162
- for (const c of r) {
1163
- const a = `./${c.getBaseName()}`;
1627
+ for (const a of r) {
1628
+ const c = `./${a.getBaseName()}`;
1164
1629
  this.options.logger.info(
1165
- `Adding export for subdirectory: ${a}`
1630
+ `Adding export for subdirectory: ${c}`
1166
1631
  ), i.addExportDeclaration({
1167
- moduleSpecifier: a,
1632
+ moduleSpecifier: c,
1168
1633
  isTypeOnly: !1,
1169
1634
  namedExports: []
1170
1635
  });
@@ -1183,6 +1648,7 @@ class qe {
1183
1648
  }
1184
1649
  }
1185
1650
  export {
1186
- qe as CodeGenerator
1651
+ He as CodeGenerator,
1652
+ ke as DEFAULT_CONFIG_PATH
1187
1653
  };
1188
1654
  //# sourceMappingURL=index.js.map