@ahoo-wang/fetcher-generator 3.3.1 → 3.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { ContentTypeValues as I, combineURLs as E } from "@ahoo-wang/fetcher";
3
3
  import { ResourceAttributionPathSpec as L } from "@ahoo-wang/fetcher-wow";
4
4
  import { parse as K } from "yaml";
5
5
  import { readFile as Ae } from "fs";
6
+ import { join as Ce, relative as Pe, sep as $e } from "path";
6
7
  function P(n) {
7
8
  return n.$ref.split("/").pop();
8
9
  }
@@ -24,9 +25,9 @@ function $(n, e) {
24
25
  schema: S(n, e)
25
26
  };
26
27
  }
27
- const Ce = /[-_'\s.]+/;
28
+ const Te = /[-_'\s./?;:,()[\]{}|\\]+/;
28
29
  function O(n) {
29
- return n.split(Ce);
30
+ return n.split(Te);
30
31
  }
31
32
  function X(n) {
32
33
  return Array.isArray(n) ? n.flatMap((e) => B(O(e))) : B(O(n));
@@ -60,26 +61,26 @@ function ee(n) {
60
61
  function M(n) {
61
62
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n) ? n : `'${n}'`;
62
63
  }
63
- function Pe(n) {
64
+ function ve(n) {
64
65
  return /^\d+$/.test(n) ? `NUM_${n}` : M(ee(n));
65
66
  }
66
- function g(n) {
67
+ function p(n) {
67
68
  return !!(n && typeof n == "object" && "$ref" in n);
68
69
  }
69
70
  function G(n, e) {
70
- if (e && !g(e) && e.content)
71
+ if (e && !p(e) && e.content)
71
72
  return e.content[n]?.schema;
72
73
  }
73
74
  function te(n) {
74
75
  return G(I.APPLICATION_JSON, n);
75
76
  }
76
- function $e(n) {
77
+ function Ie(n) {
77
78
  return G(I.TEXT_EVENT_STREAM, n);
78
79
  }
79
- function Te(n) {
80
+ function Ee(n) {
80
81
  return G("*/*", n);
81
82
  }
82
- const ve = [
83
+ const Se = [
83
84
  "string",
84
85
  "number",
85
86
  "integer",
@@ -87,7 +88,7 @@ const ve = [
87
88
  "null"
88
89
  ];
89
90
  function ne(n) {
90
- return Array.isArray(n) ? !0 : ve.includes(n);
91
+ return Array.isArray(n) ? !0 : Se.includes(n);
91
92
  }
92
93
  function U(n) {
93
94
  return Array.isArray(n.enum) && n.enum.length > 0;
@@ -98,28 +99,28 @@ function T(n) {
98
99
  function b(n) {
99
100
  return n.type === "array" && !!n.items;
100
101
  }
101
- function Ie(n) {
102
+ function Re(n) {
102
103
  return Array.isArray(n.anyOf) && n.anyOf.length > 0;
103
104
  }
104
- function Ee(n) {
105
+ function we(n) {
105
106
  return Array.isArray(n.oneOf) && n.oneOf.length > 0;
106
107
  }
107
108
  function q(n) {
108
109
  return Array.isArray(n.allOf) && n.allOf.length > 0;
109
110
  }
110
111
  function J(n) {
111
- return Ie(n) || Ee(n) || q(n);
112
+ return Re(n) || we(n) || q(n);
112
113
  }
113
- function Se(n) {
114
+ function De(n) {
114
115
  return n.includes("|") || n.includes("&") ? `(${n})[]` : `${n}[]`;
115
116
  }
116
- function Re(n) {
117
+ function Ne(n) {
117
118
  return n.type === "object" && !n.properties && n.additionalProperties !== void 0;
118
119
  }
119
- function we(n) {
120
+ function Oe(n) {
120
121
  return n.type !== "object" ? !1 : n.properties ? Object.keys(n.properties).length === 0 : !0;
121
122
  }
122
- function De(n) {
123
+ function Me(n) {
123
124
  return n.readOnly === !0;
124
125
  }
125
126
  function w(n) {
@@ -139,13 +140,13 @@ function w(n) {
139
140
  return "any";
140
141
  }
141
142
  }
142
- function Ne(n) {
143
+ function be(n) {
143
144
  if (!T(n))
144
145
  return [];
145
146
  const e = n.required || [];
146
147
  return Object.keys(n.properties).filter((t) => !e.includes(t));
147
148
  }
148
- function Oe(n, e) {
149
+ function qe(n, e) {
149
150
  return n.operation.operationId && e.operation.operationId ? n.operation.operationId.localeCompare(
150
151
  e.operation.operationId
151
152
  ) : n.path && e.path ? n.path.localeCompare(e.path) : n.method && e.method ? n.method.localeCompare(e.method) : 0;
@@ -160,7 +161,7 @@ function oe(n) {
160
161
  path: t
161
162
  });
162
163
  });
163
- return e.sort(Oe);
164
+ return e.sort(qe);
164
165
  }
165
166
  function re(n) {
166
167
  return [
@@ -181,27 +182,27 @@ function Q(n) {
181
182
  const e = W(n);
182
183
  return te(e);
183
184
  }
184
- function Me(n, e) {
185
- return n.parameters ? n.parameters.map((t) => g(t) ? Z(t, e) : t).filter((t) => t.in === "path") : [];
185
+ function Fe(n, e) {
186
+ return n.parameters ? n.parameters.map((t) => p(t) ? Z(t, e) : t).filter((t) => t.in === "path") : [];
186
187
  }
187
- const be = "string";
188
+ const je = "string";
188
189
  function ie(n) {
189
- return !n.schema || g(n.schema) || !n.schema.type || !ne(n.schema.type) ? be : w(n.schema.type);
190
+ return !n.schema || p(n.schema) || !n.schema.type || !ne(n.schema.type) ? je : w(n.schema.type);
190
191
  }
191
192
  function se(n) {
192
- return n.startsWith("http://") || n.startsWith("https://") ? qe(n) : Fe(n);
193
+ return n.startsWith("http://") || n.startsWith("https://") ? _e(n) : Ge(n);
193
194
  }
194
- async function qe(n) {
195
+ async function _e(n) {
195
196
  return await (await fetch(n)).text();
196
197
  }
197
- function Fe(n) {
198
+ function Ge(n) {
198
199
  return new Promise((e, t) => {
199
200
  Ae(n, "utf-8", (o, r) => {
200
201
  o ? t(o) : e(r);
201
202
  });
202
203
  });
203
204
  }
204
- async function je(n) {
205
+ async function We(n) {
205
206
  const e = await se(n);
206
207
  switch (ae(e)) {
207
208
  case "json":
@@ -212,7 +213,7 @@ async function je(n) {
212
213
  throw new Error(`Unsupported file format: ${n}`);
213
214
  }
214
215
  }
215
- async function _e(n) {
216
+ async function ke(n) {
216
217
  const e = await se(n);
217
218
  switch (ae(e)) {
218
219
  case "json":
@@ -237,11 +238,11 @@ function ae(n) {
237
238
  }
238
239
  throw new Error("Unable to infer file format");
239
240
  }
240
- const ce = "types.ts", Ge = "@";
241
- function We(n) {
241
+ const ce = "types.ts", ze = "@";
242
+ function Le(n) {
242
243
  return E(n.path, ce);
243
244
  }
244
- function ge(n, e, t) {
245
+ function pe(n, e, t) {
245
246
  const o = E(e, t), r = n.getSourceFile(o);
246
247
  return r || n.createSourceFile(o, "", {
247
248
  overwrite: !0
@@ -259,19 +260,19 @@ function A(n, e, t) {
259
260
  ) || o.addNamedImport(r);
260
261
  });
261
262
  }
262
- function d(n, e, t) {
263
- if (t.path.startsWith(Ge)) {
263
+ function m(n, e, t) {
264
+ if (t.path.startsWith(ze)) {
264
265
  A(n, t.path, [t.name]);
265
266
  return;
266
267
  }
267
- const o = n.getDirectoryPath(), r = (void 0)(e, t.path, ce);
268
- let i = (void 0)(o, r);
269
- i = i.replace(/\.ts$/, ""), i = i.split(void 0).join("/"), i.startsWith(".") || (i = "./" + i), A(n, i, [t.name]);
268
+ const o = n.getDirectoryPath(), r = Ce(e, t.path, ce);
269
+ let i = Pe(o, r);
270
+ i = i.replace(/\.ts$/, ""), i = i.split($e).join("/"), i.startsWith(".") || (i = "./" + i), A(n, i, [t.name]);
270
271
  }
271
- function ke(n, e, t, o) {
272
- n.path !== o.path && d(e, t, o);
272
+ function Be(n, e, t, o) {
273
+ n.path !== o.path && m(e, t, o);
273
274
  }
274
- function pe(n, e = `
275
+ function ge(n, e = `
275
276
  `) {
276
277
  if (!Array.isArray(n))
277
278
  return;
@@ -281,7 +282,7 @@ function pe(n, e = `
281
282
  return t.length > 0 ? t.join(e) : void 0;
282
283
  }
283
284
  function C(n, e) {
284
- const t = pe(e);
285
+ const t = ge(e);
285
286
  t && n.addJsDoc(t);
286
287
  }
287
288
  function k(n, e) {
@@ -289,13 +290,13 @@ function k(n, e) {
289
290
  n.title,
290
291
  n.description
291
292
  ];
292
- return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), V(t, n, "default"), V(t, n, "example"), Be(t, n), Ue(t, n), Je(t, n), t;
293
+ return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), V(t, n, "default"), V(t, n, "example"), Qe(t, n), Ve(t, n), He(t, n), t;
293
294
  }
294
- function ze(n, e, t) {
295
+ function Ue(n, e, t) {
295
296
  const o = k(e, t);
296
297
  C(n, o);
297
298
  }
298
- function Le(n, e, t) {
299
+ function Je(n, e, t) {
299
300
  const o = k(e, t);
300
301
  ue(o, "schema", e), C(n, o);
301
302
  }
@@ -312,7 +313,7 @@ function V(n, e, t) {
312
313
  function ue(n, e, t) {
313
314
  n.push(`- ${e}: `), n.push("```json"), n.push(JSON.stringify(t, null, 2)), n.push("```");
314
315
  }
315
- function Be(n, e) {
316
+ function Qe(n, e) {
316
317
  const t = ["- Numeric Constraints"];
317
318
  e.minimum !== void 0 && t.push(` - minimum: ${e.minimum}`), e.maximum !== void 0 && t.push(` - maximum: ${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(
318
319
  ` - exclusiveMinimum: ${e.exclusiveMinimum}`
@@ -320,28 +321,28 @@ function Be(n, e) {
320
321
  ` - exclusiveMaximum: ${e.exclusiveMaximum}`
321
322
  ), e.multipleOf !== void 0 && t.push(` - multipleOf: ${e.multipleOf}`), t.length !== 1 && n.push(...t);
322
323
  }
323
- function Ue(n, e) {
324
+ function Ve(n, e) {
324
325
  const t = ["- String Constraints"];
325
326
  e.minLength !== void 0 && t.push(` - minLength: ${e.minLength}`), e.maxLength !== void 0 && t.push(` - maxLength: ${e.maxLength}`), e.pattern !== void 0 && t.push(` - pattern: ${e.pattern}`), t.length !== 1 && n.push(...t);
326
327
  }
327
- function Je(n, e) {
328
+ function He(n, e) {
328
329
  const t = ["- Array Constraints"];
329
330
  e.minItems !== void 0 && t.push(` - minItems: ${e.minItems}`), e.maxItems !== void 0 && t.push(` - maxItems: ${e.maxItems}`), e.uniqueItems !== void 0 && t.push(` - uniqueItems: ${e.uniqueItems}`), t.length !== 1 && n.push(...t);
330
331
  }
331
- function Qe(n) {
332
+ function Ke(n) {
332
333
  const e = n.split(".");
333
334
  return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
334
335
  }
335
- function Ve(n) {
336
- const e = Qe(n.name);
336
+ function Ye(n) {
337
+ const e = Ke(n.name);
337
338
  return e ? {
338
339
  tag: n,
339
340
  contextAlias: e[0],
340
341
  aggregateName: e[1]
341
342
  } : null;
342
343
  }
343
- function He(n) {
344
- const e = n?.map((o) => Ve(o)).filter((o) => o !== null);
344
+ function Ze(n) {
345
+ const e = n?.map((o) => Ye(o)).filter((o) => o !== null);
345
346
  if (!e)
346
347
  return /* @__PURE__ */ new Map();
347
348
  const t = /* @__PURE__ */ new Map();
@@ -353,20 +354,20 @@ function He(n) {
353
354
  });
354
355
  }), t;
355
356
  }
356
- function Ke(n) {
357
+ function Xe(n) {
357
358
  if (!n)
358
359
  return null;
359
360
  const e = n.split(".");
360
361
  return e.length != 3 ? null : e[2];
361
362
  }
362
- const Ye = "#/components/responses/wow.CommandOk", Ze = "#/components/parameters/wow.id";
363
- class Xe {
363
+ const et = "#/components/responses/wow.CommandOk", tt = "#/components/parameters/wow.id";
364
+ class nt {
364
365
  /**
365
366
  * Creates a new AggregateResolver instance.
366
367
  * @param openAPI - The OpenAPI specification to resolve aggregates from
367
368
  */
368
369
  constructor(e) {
369
- this.openAPI = e, this.aggregates = He(e.tags), this.build();
370
+ this.openAPI = e, this.aggregates = Ze(e.tags), this.build();
370
371
  }
371
372
  aggregates;
372
373
  /**
@@ -402,27 +403,27 @@ class Xe {
402
403
  const o = t.operation;
403
404
  if (o.operationId === "wow.command.send")
404
405
  return;
405
- const r = Ke(o.operationId);
406
+ const r = Xe(o.operationId);
406
407
  if (!r)
407
408
  return;
408
409
  const i = W(o);
409
- if (!i || !g(i) || i.$ref !== Ye || !o.requestBody)
410
+ if (!i || !p(i) || i.$ref !== et || !o.requestBody)
410
411
  return;
411
- const s = o.parameters ?? [], a = s.filter((l) => g(l) && l.$ref === Ze).at(0), c = s.filter(
412
- (l) => !g(l) && l.in === "path"
412
+ const s = o.parameters ?? [], a = s.filter((u) => p(u) && u.$ref === tt).at(0), c = s.filter(
413
+ (u) => !p(u) && u.in === "path"
413
414
  );
414
415
  if (a) {
415
- const l = Z(
416
+ const u = Z(
416
417
  a,
417
418
  this.openAPI.components
418
419
  );
419
- c.push(l);
420
+ c.push(u);
420
421
  }
421
- const p = o.requestBody.content[I.APPLICATION_JSON].schema, x = $(
422
- p,
422
+ const g = o.requestBody.content[I.APPLICATION_JSON].schema, d = $(
423
+ g,
423
424
  this.openAPI.components
424
425
  );
425
- x.schema.title = x.schema.title || o.summary, x.schema.description = x.schema.description || o.description;
426
+ d.schema.title = d.schema.title || o.summary, d.schema.description = d.schema.description || o.description;
426
427
  const he = {
427
428
  name: r,
428
429
  method: t.method,
@@ -430,11 +431,11 @@ class Xe {
430
431
  pathParameters: c,
431
432
  summary: o.summary,
432
433
  description: o.description,
433
- schema: x,
434
+ schema: d,
434
435
  operation: o
435
436
  };
436
- o.tags?.forEach((l) => {
437
- const z = this.aggregates.get(l);
437
+ o.tags?.forEach((u) => {
438
+ const z = this.aggregates.get(u);
438
439
  z && z.commands.set(r, he);
439
440
  });
440
441
  }
@@ -446,7 +447,7 @@ class Xe {
446
447
  if (!e.operationId?.endsWith(".snapshot_state.single"))
447
448
  return;
448
449
  const t = Q(e);
449
- if (!g(t))
450
+ if (!p(t))
450
451
  return;
451
452
  const o = $(
452
453
  t,
@@ -465,23 +466,23 @@ class Xe {
465
466
  if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
466
467
  return;
467
468
  const t = Q(e);
468
- if (g(t))
469
+ if (p(t))
469
470
  return;
470
471
  const o = t?.items;
471
- if (!g(o))
472
+ if (!p(o))
472
473
  return;
473
474
  const i = S(
474
475
  o,
475
476
  this.openAPI.components
476
477
  ).properties.body.items.anyOf.map((s) => {
477
- const a = s.title, c = s.properties.name.const, u = s.properties.body, p = $(
478
- u,
478
+ const a = s.title, c = s.properties.name.const, h = s.properties.body, g = $(
479
+ h,
479
480
  this.openAPI.components
480
481
  );
481
- return p.schema.title = p.schema.title || s.title, {
482
+ return g.schema.title = g.schema.title || s.title, {
482
483
  title: a,
483
484
  name: c,
484
- schema: p
485
+ schema: g
485
486
  };
486
487
  });
487
488
  e.tags?.forEach((s) => {
@@ -511,7 +512,7 @@ class Xe {
511
512
  });
512
513
  }
513
514
  }
514
- const y = "@ahoo-wang/fetcher-wow", et = {
515
+ const x = "@ahoo-wang/fetcher-wow", ot = {
515
516
  "wow.command.CommandResult": "CommandResult",
516
517
  "wow.command.CommandResultArray": "CommandResultArray",
517
518
  "wow.MessageHeaderSqlType": "MessageHeaderSqlType",
@@ -543,12 +544,12 @@ const y = "@ahoo-wang/fetcher-wow", et = {
543
544
  "wow.openapi.BatchResult": "BatchResult",
544
545
  "wow.messaging.CompensationTarget": "CompensationTarget"
545
546
  };
546
- function m(n) {
547
+ function l(n) {
547
548
  if (!n)
548
549
  return { name: "", path: "/" };
549
- const e = et[n];
550
+ const e = ot[n];
550
551
  if (e)
551
- return { name: e, path: y };
552
+ return { name: e, path: x };
552
553
  const t = n.split(".");
553
554
  let o = -1;
554
555
  for (let c = 0; c < t.length; c++)
@@ -561,18 +562,18 @@ function m(n) {
561
562
  }
562
563
  function v(n) {
563
564
  const e = P(n);
564
- return m(e);
565
+ return l(e);
565
566
  }
566
567
  function D(n) {
567
568
  return `${ee(n)}_BOUNDED_CONTEXT_ALIAS`;
568
569
  }
569
- class tt {
570
+ class rt {
570
571
  constructor(e, t, o, r) {
571
572
  this.modelInfo = e, this.sourceFile = t, this.keySchema = o, this.outputDir = r;
572
573
  }
573
574
  generate() {
574
575
  const e = this.process();
575
- e && Le(e, this.keySchema.schema, this.keySchema.key);
576
+ e && Je(e, this.keySchema.schema, this.keySchema.key);
576
577
  }
577
578
  process() {
578
579
  const { schema: e } = this.keySchema;
@@ -580,7 +581,7 @@ class tt {
580
581
  }
581
582
  resolveReference(e) {
582
583
  const t = v(e);
583
- return ke(
584
+ return Be(
584
585
  this.modelInfo,
585
586
  this.sourceFile,
586
587
  this.outputDir,
@@ -594,8 +595,8 @@ class tt {
594
595
  const { properties: t } = e;
595
596
  return Object.entries(t).map(([o, r]) => {
596
597
  const i = this.resolveType(r), s = M(o);
597
- if (!g(r)) {
598
- const a = k(r), c = pe(a, `
598
+ if (!p(r)) {
599
+ const a = k(r), c = ge(a, `
599
600
  * `);
600
601
  if (c)
601
602
  return `
@@ -624,9 +625,9 @@ class tt {
624
625
  return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.resolveType(e.additionalProperties);
625
626
  }
626
627
  resolveType(e) {
627
- if (g(e))
628
+ if (p(e))
628
629
  return this.resolveReference(e).name;
629
- if (Re(e))
630
+ if (Ne(e))
630
631
  return `Record<string,${this.resolveMapValueType(e)}>`;
631
632
  if (e.const)
632
633
  return `'${e.const}'`;
@@ -638,7 +639,7 @@ class tt {
638
639
  }
639
640
  if (b(e)) {
640
641
  const t = this.resolveType(e.items);
641
- return Se(t);
642
+ return De(t);
642
643
  }
643
644
  return e.type === "object" ? this.resolveObjectType(e) : e.type ? w(e.type) : "any";
644
645
  }
@@ -647,7 +648,7 @@ class tt {
647
648
  name: this.modelInfo.name,
648
649
  isExported: !0,
649
650
  members: e.enum.filter((t) => typeof t == "string" && t.length > 0).map((t) => ({
650
- name: Pe(t),
651
+ name: ve(t),
651
652
  initializer: `\`${t}\``
652
653
  }))
653
654
  });
@@ -658,8 +659,8 @@ class tt {
658
659
  s ? s.setType(r) : s = e.addProperty({
659
660
  name: i,
660
661
  type: r,
661
- isReadonly: De(o)
662
- }), ze(s, o);
662
+ isReadonly: Me(o)
663
+ }), Ue(s, o);
663
664
  }
664
665
  processInterface(e) {
665
666
  const t = this.sourceFile.addInterface({
@@ -697,7 +698,7 @@ class tt {
697
698
  isExported: !0
698
699
  });
699
700
  return e.allOf.forEach((o) => {
700
- if (g(o)) {
701
+ if (p(o)) {
701
702
  const r = this.resolveType(o);
702
703
  t.addExtends(r);
703
704
  return;
@@ -721,12 +722,12 @@ class tt {
721
722
  });
722
723
  }
723
724
  }
724
- class nt {
725
+ class it {
725
726
  constructor(e) {
726
727
  this.context = e;
727
728
  }
728
729
  getOrCreateSourceFile(e) {
729
- const t = We(e);
730
+ const t = Le(e);
730
731
  return this.context.getOrCreateSourceFile(t);
731
732
  }
732
733
  /**
@@ -770,7 +771,7 @@ class nt {
770
771
  "AggregatedDomainEventStreamServerSentEventNonNullData"
771
772
  ) || e.endsWith("AggregatedListQuery") || e.endsWith("AggregatedPagedQuery") || e.endsWith("AggregatedSingleQuery"))
772
773
  return !0;
773
- const o = m(e);
774
+ const o = l(e);
774
775
  return t.has(o.name);
775
776
  }
776
777
  aggregatedSchemaSuffix = [
@@ -788,7 +789,7 @@ class nt {
788
789
  this.generateBoundedContext(t);
789
790
  for (const r of o)
790
791
  this.aggregatedSchemaSuffix.forEach((i) => {
791
- const s = m(r.state.key), a = R(s.name) + i;
792
+ const s = l(r.state.key), a = R(s.name) + i;
792
793
  e.add(a);
793
794
  });
794
795
  }
@@ -807,8 +808,8 @@ class nt {
807
808
  * 4. Type alias processing
808
809
  */
809
810
  generateKeyedSchema(e) {
810
- const t = m(e.key), o = this.getOrCreateSourceFile(t);
811
- new tt(
811
+ const t = l(e.key), o = this.getOrCreateSourceFile(t);
812
+ new rt(
812
813
  t,
813
814
  o,
814
815
  e,
@@ -822,7 +823,7 @@ class nt {
822
823
  o.addStatements(`export const ${r} = '${e}';`);
823
824
  }
824
825
  }
825
- const ot = "@ahoo-wang/fetcher-decorator", rt = [
826
+ const st = "@ahoo-wang/fetcher-decorator", at = [
826
827
  "type ApiMetadata",
827
828
  "type ApiMetadataCapable",
828
829
  "type ParameterRequest",
@@ -836,7 +837,7 @@ const ot = "@ahoo-wang/fetcher-decorator", rt = [
836
837
  "attribute",
837
838
  "path",
838
839
  "autoGeneratedError"
839
- ], it = {
840
+ ], ct = {
840
841
  type: "Promise<Response>",
841
842
  metadata: "{resultExtractor: ResultExtractors.Response }"
842
843
  }, H = {
@@ -847,7 +848,7 @@ const ot = "@ahoo-wang/fetcher-decorator", rt = [
847
848
  resultExtractor: JsonEventStreamResultExtractor,
848
849
  }`;
849
850
  function le(n) {
850
- A(n, ot, rt);
851
+ A(n, st, at);
851
852
  }
852
853
  function j(n, e, t = [], o = [], r) {
853
854
  return e.addClass({
@@ -877,14 +878,14 @@ function me(n, e) {
877
878
  ]
878
879
  });
879
880
  }
880
- const st = "@ahoo-wang/fetcher-eventstream";
881
+ const pt = "@ahoo-wang/fetcher-eventstream";
881
882
  function de(n) {
882
- A(n, st, [
883
+ A(n, pt, [
883
884
  "JsonEventStreamResultExtractor",
884
885
  "type JsonServerSentEventStream"
885
886
  ]);
886
887
  }
887
- function at(n) {
888
+ function gt(n) {
888
889
  let e = 0, t = 0;
889
890
  return n.commands.forEach((o) => {
890
891
  o.path.startsWith(L.TENANT) && (e += 1), o.path.startsWith(L.OWNER) && (t += 1);
@@ -892,17 +893,17 @@ function at(n) {
892
893
  }
893
894
  function fe(n, e, t, o) {
894
895
  const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
895
- return ge(n, e, r);
896
+ return pe(n, e, r);
896
897
  }
897
- function h(n, e) {
898
+ function y(n, e) {
898
899
  return `${R(n.aggregateName)}${e}`;
899
900
  }
900
901
  function _(n) {
901
902
  return n === "delete" ? "del" : n;
902
903
  }
903
- const ct = "x-fetcher-method";
904
- function gt(n, e) {
905
- const t = n[ct];
904
+ const ut = "x-fetcher-method";
905
+ function lt(n, e) {
906
+ const t = n[ut];
906
907
  if (t)
907
908
  return t;
908
909
  if (!n.operationId)
@@ -915,7 +916,7 @@ function gt(n, e) {
915
916
  }
916
917
  return f(o);
917
918
  }
918
- class pt {
919
+ class mt {
919
920
  /**
920
921
  * Creates a new ApiClientGenerator instance.
921
922
  * @param context - The generation context containing OpenAPI spec and configuration
@@ -924,7 +925,7 @@ class pt {
924
925
  this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${D(this.context.currentContextAlias)}}` : void 0;
925
926
  }
926
927
  defaultParameterRequestType = "ParameterRequest";
927
- defaultReturnType = it;
928
+ defaultReturnType = ct;
928
929
  apiMetadataCtorInitializer;
929
930
  /**
930
931
  * Generates API client classes for all valid tags in the OpenAPI specification.
@@ -976,7 +977,7 @@ class pt {
976
977
  * @param operations - Set of operations for this client
977
978
  */
978
979
  generateApiClient(e, t) {
979
- const o = m(e.name);
980
+ const o = l(e.name);
980
981
  this.context.logger.info(
981
982
  `Generating API client class: ${o.name}ApiClient with ${t.size} operations`
982
983
  );
@@ -1001,7 +1002,7 @@ class pt {
1001
1002
  * @returns A unique camelCase method name
1002
1003
  */
1003
1004
  getMethodName(e, t) {
1004
- const o = gt(t, (r) => e.getMethod(r) !== void 0);
1005
+ const o = lt(t, (r) => e.getMethod(r) !== void 0);
1005
1006
  if (!o)
1006
1007
  throw new Error(
1007
1008
  `Unable to resolve method name for apiClientClass:${e.getName()}.`
@@ -1020,7 +1021,7 @@ class pt {
1020
1021
  `No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
1021
1022
  ), this.defaultParameterRequestType;
1022
1023
  let o;
1023
- if (g(t.requestBody) ? (this.context.logger.info(
1024
+ if (p(t.requestBody) ? (this.context.logger.info(
1024
1025
  `Extracting request body from reference for operation: ${t.operationId}`
1025
1026
  ), o = Y(
1026
1027
  t.requestBody,
@@ -1035,11 +1036,11 @@ class pt {
1035
1036
  ), "ParameterRequest<FormData>";
1036
1037
  if (o.content["application/json"]) {
1037
1038
  const r = o.content["application/json"].schema;
1038
- if (g(r)) {
1039
+ if (p(r)) {
1039
1040
  const i = v(r);
1040
1041
  this.context.logger.info(
1041
1042
  `Adding import for request body model: ${i.name} from ${i.path}`
1042
- ), d(e, this.context.outputDir, i);
1043
+ ), m(e, this.context.outputDir, i);
1043
1044
  const s = `ParameterRequest<${i.name}>`;
1044
1045
  return this.context.logger.info(
1045
1046
  `Resolved request type for operation ${t.operationId}: ${s}`
@@ -1058,7 +1059,7 @@ class pt {
1058
1059
  * @returns Array of parameter declarations
1059
1060
  */
1060
1061
  resolveParameters(e, t, o) {
1061
- const r = Me(
1062
+ const r = Fe(
1062
1063
  o,
1063
1064
  this.context.openAPI.components
1064
1065
  ).filter((a) => !this.context.isIgnoreApiClientPathParameters(
@@ -1116,11 +1117,11 @@ class pt {
1116
1117
  */
1117
1118
  resolveSchemaReturnType(e, t) {
1118
1119
  const o = "Promise<any>";
1119
- if (g(t)) {
1120
+ if (p(t)) {
1120
1121
  const r = v(t);
1121
1122
  this.context.logger.info(
1122
1123
  `Adding import for response model: ${r.name} from ${r.path}`
1123
- ), d(e, this.context.outputDir, r);
1124
+ ), m(e, this.context.outputDir, r);
1124
1125
  const i = `Promise<${r.name}>`;
1125
1126
  return this.context.logger.info(`Resolved reference return type: ${i}`), i;
1126
1127
  }
@@ -1148,7 +1149,7 @@ class pt {
1148
1149
  return this.context.logger.info(
1149
1150
  `No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
1150
1151
  ), this.defaultReturnType;
1151
- const r = te(o) || Te(o);
1152
+ const r = te(o) || Ee(o);
1152
1153
  if (r) {
1153
1154
  const s = this.resolveSchemaReturnType(e, r);
1154
1155
  return this.context.logger.info(
@@ -1158,23 +1159,23 @@ class pt {
1158
1159
  metadata: s === H.type ? H.metadata : void 0
1159
1160
  };
1160
1161
  }
1161
- const i = $e(o);
1162
+ const i = Ie(o);
1162
1163
  if (i) {
1163
- if (g(i)) {
1164
+ if (p(i)) {
1164
1165
  const a = S(
1165
1166
  i,
1166
1167
  this.context.openAPI.components
1167
1168
  );
1168
- if (b(a) && g(a.items)) {
1169
+ if (b(a) && p(a.items)) {
1169
1170
  const c = v(a.items);
1170
1171
  this.context.logger.info(
1171
1172
  `Adding import for event stream model: ${c.name} from ${c.path}`
1172
- ), d(e, this.context.outputDir, c);
1173
- const p = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
1173
+ ), m(e, this.context.outputDir, c);
1174
+ const g = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
1174
1175
  return this.context.logger.info(
1175
- `Resolved event stream return type for operation ${t.operationId}: ${p}`
1176
+ `Resolved event stream return type for operation ${t.operationId}: ${g}`
1176
1177
  ), {
1177
- type: p,
1178
+ type: g,
1178
1179
  metadata: F
1179
1180
  };
1180
1181
  }
@@ -1215,16 +1216,16 @@ class pt {
1215
1216
  this.context.logger.info(
1216
1217
  `Creating method with ${s.length} parameters, return type: ${a.type}`
1217
1218
  );
1218
- const u = o.addMethod({
1219
+ const h = o.addMethod({
1219
1220
  name: i,
1220
1221
  decorators: [c],
1221
1222
  parameters: s,
1222
1223
  returnType: a.type,
1223
1224
  statements: [
1224
- `throw autoGeneratedError(${s.map((p) => p.name).join(",")});`
1225
+ `throw autoGeneratedError(${s.map((g) => g.name).join(",")});`
1225
1226
  ]
1226
1227
  });
1227
- C(u, [
1228
+ C(h, [
1228
1229
  r.operation.summary,
1229
1230
  r.operation.description,
1230
1231
  `- operationId: \`${r.operation.operationId}\``,
@@ -1294,7 +1295,7 @@ class pt {
1294
1295
  return !1;
1295
1296
  }
1296
1297
  }
1297
- class ut {
1298
+ class dt {
1298
1299
  /**
1299
1300
  * Creates a new CommandClientGenerator instance.
1300
1301
  * @param context - The generation context containing OpenAPI spec and project details
@@ -1361,9 +1362,9 @@ class ut {
1361
1362
  ],
1362
1363
  isExported: !1
1363
1364
  }), this.context.logger.info(
1364
- `Adding imports from ${y}: CommandRequest, CommandResult, CommandResultEventStream, CommandBody, DeleteAggregateCommand, RecoverAggregateCommand`
1365
+ `Adding imports from ${x}: CommandRequest, CommandResult, CommandResultEventStream, CommandBody, DeleteAggregateCommand, RecoverAggregateCommand`
1365
1366
  ), t.addImportDeclaration({
1366
- moduleSpecifier: y,
1367
+ moduleSpecifier: x,
1367
1368
  namedImports: [
1368
1369
  "CommandRequest",
1369
1370
  "CommandResult",
@@ -1388,7 +1389,7 @@ class ut {
1388
1389
  );
1389
1390
  }
1390
1391
  resolveAggregateCommandEndpointPathsName(e) {
1391
- return h(e, this.commandEndpointPathsSuffix);
1392
+ return y(e, this.commandEndpointPathsSuffix);
1392
1393
  }
1393
1394
  processCommandEndpointPaths(e, t) {
1394
1395
  const o = this.resolveAggregateCommandEndpointPathsName(
@@ -1413,16 +1414,16 @@ class ut {
1413
1414
  ), o;
1414
1415
  }
1415
1416
  resolveCommandTypeName(e) {
1416
- const t = m(e.schema.key);
1417
+ const t = l(e.schema.key);
1417
1418
  return [t, t.name + "Command"];
1418
1419
  }
1419
1420
  resolveCommandType(e, t) {
1420
1421
  const [o, r] = this.resolveCommandTypeName(t);
1421
- if (o.path === y)
1422
+ if (o.path === x)
1422
1423
  return;
1423
- d(e, this.context.outputDir, o);
1424
+ m(e, this.context.outputDir, o);
1424
1425
  let i = `${o.name}`;
1425
- const s = Ne(t.schema.schema).map((a) => `'${a}'`).join(" | ");
1426
+ const s = be(t.schema.schema).map((a) => `'${a}'`).join(" | ");
1426
1427
  s !== "" && (i = `PartialBy<${i},${s}>`), i = `CommandBody<${i}>`, e.addTypeAlias({
1427
1428
  name: r,
1428
1429
  type: `${i}`,
@@ -1438,7 +1439,7 @@ class ut {
1438
1439
  return `${e}.${t.name.toUpperCase()}`;
1439
1440
  }
1440
1441
  processCommandClient(e, t, o) {
1441
- const r = h(
1442
+ const r = y(
1442
1443
  t.aggregate,
1443
1444
  "CommandClient"
1444
1445
  ), i = j(
@@ -1457,10 +1458,10 @@ class ut {
1457
1458
  });
1458
1459
  }
1459
1460
  processStreamCommandClient(e, t) {
1460
- const o = h(
1461
+ const o = y(
1461
1462
  t.aggregate,
1462
1463
  "CommandClient"
1463
- ), r = h(
1464
+ ), r = y(
1464
1465
  t.aggregate,
1465
1466
  "StreamCommandClient"
1466
1467
  );
@@ -1509,7 +1510,7 @@ class ut {
1509
1510
  `Adding command request parameter: commandRequest (type: CommandRequest<${r}>)`
1510
1511
  ), i.push({
1511
1512
  name: "commandRequest",
1512
- hasQuestionToken: we(t.schema.schema),
1513
+ hasQuestionToken: Oe(t.schema.schema),
1513
1514
  type: `CommandRequest<${r}>`,
1514
1515
  decorators: [
1515
1516
  {
@@ -1566,7 +1567,7 @@ class ut {
1566
1567
  );
1567
1568
  }
1568
1569
  }
1569
- class lt {
1570
+ class ft {
1570
1571
  /**
1571
1572
  * Creates a new QueryClientGenerator instance.
1572
1573
  * @param context - The generation context containing OpenAPI spec and project details
@@ -1623,9 +1624,9 @@ class lt {
1623
1624
  this.context.logger.info(
1624
1625
  `Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
1625
1626
  ), this.context.logger.info(
1626
- `Adding imports from ${y}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
1627
+ `Adding imports from ${x}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
1627
1628
  ), t.addImportDeclaration({
1628
- moduleSpecifier: y,
1629
+ moduleSpecifier: x,
1629
1630
  namedImports: [
1630
1631
  "QueryClientFactory",
1631
1632
  "QueryClientOptions",
@@ -1644,7 +1645,7 @@ class lt {
1644
1645
  initializer: `{
1645
1646
  contextAlias: ${D(e.aggregate.contextAlias)},
1646
1647
  aggregateName: '${e.aggregate.aggregateName}',
1647
- resourceAttribution: ${at(e)},
1648
+ resourceAttribution: ${gt(e)},
1648
1649
  }`
1649
1650
  }
1650
1651
  ],
@@ -1653,12 +1654,12 @@ class lt {
1653
1654
  const r = this.processAggregateDomainEventType(
1654
1655
  e,
1655
1656
  t
1656
- ), i = `${f(e.aggregate.aggregateName)}QueryClientFactory`, s = m(e.state.key), a = m(e.fields.key);
1657
+ ), i = `${f(e.aggregate.aggregateName)}QueryClientFactory`, s = l(e.state.key), a = l(e.fields.key);
1657
1658
  this.context.logger.info(
1658
1659
  `Adding import for state model: ${s.name} from path: ${s.path}`
1659
- ), d(t, this.context.outputDir, s), this.context.logger.info(
1660
+ ), m(t, this.context.outputDir, s), this.context.logger.info(
1660
1661
  `Adding import for fields model: ${a.name} from path: ${a.path}`
1661
- ), d(t, this.context.outputDir, a), this.context.logger.info(
1662
+ ), m(t, this.context.outputDir, a), this.context.logger.info(
1662
1663
  `Creating query client factory: ${i}`
1663
1664
  ), t.addVariableStatement({
1664
1665
  declarationKind: N.Const,
@@ -1679,16 +1680,16 @@ class lt {
1679
1680
  `Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
1680
1681
  );
1681
1682
  for (const s of e.events.values()) {
1682
- const a = m(s.schema.key);
1683
+ const a = l(s.schema.key);
1683
1684
  this.context.logger.info(
1684
1685
  `Adding import for event model: ${a.name} from path: ${a.path}`
1685
- ), d(
1686
+ ), m(
1686
1687
  t,
1687
1688
  this.context.outputDir,
1688
1689
  a
1689
1690
  ), o.push(a);
1690
1691
  }
1691
- const r = h(
1692
+ const r = y(
1692
1693
  e.aggregate,
1693
1694
  this.domainEventTypeSuffix
1694
1695
  ), i = o.map((s) => s.name).join(" | ");
@@ -1701,7 +1702,7 @@ class lt {
1701
1702
  }), r;
1702
1703
  }
1703
1704
  processAggregateDomainEventTypes(e, t) {
1704
- const o = h(
1705
+ const o = y(
1705
1706
  e.aggregate,
1706
1707
  this.domainEventTypeMapTitleSuffix
1707
1708
  ), r = t.addEnum({
@@ -1715,13 +1716,13 @@ class lt {
1715
1716
  });
1716
1717
  }
1717
1718
  }
1718
- class mt {
1719
+ class ht {
1719
1720
  /**
1720
1721
  * Creates a new ClientGenerator instance.
1721
1722
  * @param context - The generation context containing OpenAPI spec and project details
1722
1723
  */
1723
1724
  constructor(e) {
1724
- this.context = e, this.queryClientGenerator = new lt(e), this.commandClientGenerator = new ut(e), this.apiClientGenerator = new pt(e);
1725
+ this.context = e, this.queryClientGenerator = new ft(e), this.commandClientGenerator = new dt(e), this.apiClientGenerator = new mt(e);
1725
1726
  }
1726
1727
  queryClientGenerator;
1727
1728
  commandClientGenerator;
@@ -1744,7 +1745,7 @@ class mt {
1744
1745
  this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
1745
1746
  }
1746
1747
  }
1747
- class dt {
1748
+ class yt {
1748
1749
  /** The ts-morph project instance used for code generation */
1749
1750
  project;
1750
1751
  /** The OpenAPI specification object */
@@ -1762,7 +1763,7 @@ class dt {
1762
1763
  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"];
1763
1764
  }
1764
1765
  getOrCreateSourceFile(e) {
1765
- return ge(this.project, this.outputDir, e);
1766
+ return pe(this.project, this.outputDir, e);
1766
1767
  }
1767
1768
  isIgnoreApiClientPathParameters(e, t) {
1768
1769
  return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
@@ -1771,8 +1772,8 @@ class dt {
1771
1772
  return this.defaultIgnorePathParameters.includes(t);
1772
1773
  }
1773
1774
  }
1774
- const ft = "./fetcher-generator.config.json";
1775
- class Pt {
1775
+ const xt = "./fetcher-generator.config.json";
1776
+ class It {
1776
1777
  /**
1777
1778
  * Creates a new CodeGenerator instance with the specified options.
1778
1779
  *
@@ -1807,35 +1808,37 @@ class Pt {
1807
1808
  async generate() {
1808
1809
  this.options.logger.info(
1809
1810
  "Starting code generation from OpenAPI specification"
1810
- ), 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");
1811
- const e = await je(this.options.inputPath);
1811
+ );
1812
+ const e = process.cwd();
1813
+ this.options.logger.info(`Work directory: ${e}`), 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");
1814
+ const t = await We(this.options.inputPath);
1812
1815
  this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
1813
- const o = new Xe(e).resolve();
1816
+ const r = new nt(t).resolve();
1814
1817
  this.options.logger.info(
1815
- `Resolved ${o.size} bounded context aggregates`
1818
+ `Resolved ${r.size} bounded context aggregates`
1816
1819
  );
1817
- const r = this.options.configPath ?? ft;
1818
- let i = {};
1820
+ const i = this.options.configPath ?? xt;
1821
+ let s = {};
1819
1822
  try {
1820
- this.options.logger.info(`Parsing configuration file: ${r}`), i = await _e(r);
1821
- } catch (p) {
1822
- this.options.logger.info(`Configuration file parsing failed: ${p}`);
1823
+ this.options.logger.info(`Parsing configuration file: ${i}`), s = await ke(i);
1824
+ } catch (d) {
1825
+ this.options.logger.info(`Configuration file parsing failed: ${d}`);
1823
1826
  }
1824
- const s = new dt({
1825
- openAPI: e,
1827
+ const a = new yt({
1828
+ openAPI: t,
1826
1829
  project: this.project,
1827
1830
  outputDir: this.options.outputDir,
1828
- contextAggregates: o,
1831
+ contextAggregates: r,
1829
1832
  logger: this.options.logger,
1830
- config: i
1833
+ config: s
1831
1834
  });
1832
- this.options.logger.info("Generating models"), new nt(s).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new mt(s).generate(), this.options.logger.info("Clients generated successfully");
1833
- const u = this.project.getDirectory(this.options.outputDir);
1834
- if (!u) {
1835
+ this.options.logger.info("Generating models"), new it(a).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ht(a).generate(), this.options.logger.info("Clients generated successfully");
1836
+ const g = this.project.getDirectory(this.options.outputDir);
1837
+ if (!g) {
1835
1838
  this.options.logger.info("Output directory not found.");
1836
1839
  return;
1837
1840
  }
1838
- this.options.logger.info("Generating index files"), this.generateIndex(u), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(u), 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");
1841
+ this.options.logger.info("Generating index files"), this.generateIndex(g), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(g), 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");
1839
1842
  }
1840
1843
  /**
1841
1844
  * Generates index.ts files for all subdirectories in the output directory.
@@ -1926,7 +1929,7 @@ class Pt {
1926
1929
  }
1927
1930
  }
1928
1931
  export {
1929
- Pt as CodeGenerator,
1930
- ft as DEFAULT_CONFIG_PATH
1932
+ It as CodeGenerator,
1933
+ xt as DEFAULT_CONFIG_PATH
1931
1934
  };
1932
1935
  //# sourceMappingURL=index.js.map