@ahoo-wang/fetcher-generator 2.5.5 → 2.5.6
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/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/apiClientGenerator.d.ts.map +1 -1
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/client/decorators.d.ts +2 -0
- package/dist/client/decorators.d.ts.map +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +120 -117
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Scope as
|
|
1
|
+
import { Scope as ce, VariableDeclarationKind as v, Project as ge } from "ts-morph";
|
|
2
2
|
import { ContentTypeValues as S, combineURLs as w } from "@ahoo-wang/fetcher";
|
|
3
3
|
import { ResourceAttributionPathSpec as F } from "@ahoo-wang/fetcher-wow";
|
|
4
4
|
import { parse as k } from "yaml";
|
|
5
|
-
import { readFile as
|
|
6
|
-
import { join as
|
|
7
|
-
function
|
|
5
|
+
import { readFile as le } from "fs";
|
|
6
|
+
import { join as pe, relative as ue } from "path";
|
|
7
|
+
function T(r) {
|
|
8
8
|
return r.$ref.split("/").pop();
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const t =
|
|
10
|
+
function R(r, e) {
|
|
11
|
+
const t = T(r);
|
|
12
12
|
return e.schemas?.[t];
|
|
13
13
|
}
|
|
14
14
|
function L(r, e) {
|
|
15
|
-
const t =
|
|
15
|
+
const t = T(r);
|
|
16
16
|
return e.requestBodies?.[t];
|
|
17
17
|
}
|
|
18
18
|
function Q(r, e) {
|
|
19
|
-
const t =
|
|
19
|
+
const t = T(r);
|
|
20
20
|
return e.parameters?.[t];
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function I(r, e) {
|
|
23
23
|
return {
|
|
24
|
-
key:
|
|
25
|
-
schema:
|
|
24
|
+
key: T(r),
|
|
25
|
+
schema: R(r, e)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const _ = /[-_\s.]+/;
|
|
29
29
|
function U(r) {
|
|
30
|
-
return Array.isArray(r) ? r.flatMap((e) =>
|
|
30
|
+
return Array.isArray(r) ? r.flatMap((e) => G(e.split(_))) : G(r.split(_));
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function G(r) {
|
|
33
33
|
return r.flatMap((e) => {
|
|
34
34
|
if (e.length === 0)
|
|
35
35
|
return [];
|
|
@@ -52,7 +52,7 @@ function h(r) {
|
|
|
52
52
|
const e = A(r);
|
|
53
53
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function me(r) {
|
|
56
56
|
return r === "" || Array.isArray(r) && r.length === 0 ? "" : U(r).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
57
57
|
}
|
|
58
58
|
function g(r) {
|
|
@@ -65,13 +65,13 @@ function b(r, e) {
|
|
|
65
65
|
function J(r) {
|
|
66
66
|
return b(S.APPLICATION_JSON, r);
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function de(r) {
|
|
69
69
|
return b(S.TEXT_EVENT_STREAM, r);
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function fe(r) {
|
|
72
72
|
return b("*/*", r);
|
|
73
73
|
}
|
|
74
|
-
const
|
|
74
|
+
const he = [
|
|
75
75
|
"string",
|
|
76
76
|
"number",
|
|
77
77
|
"integer",
|
|
@@ -79,12 +79,12 @@ const fe = [
|
|
|
79
79
|
"null"
|
|
80
80
|
];
|
|
81
81
|
function q(r) {
|
|
82
|
-
return Array.isArray(r) ? !0 :
|
|
82
|
+
return Array.isArray(r) ? !0 : he.includes(r);
|
|
83
83
|
}
|
|
84
84
|
function O(r) {
|
|
85
85
|
return r.type === "array";
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function ye(r) {
|
|
88
88
|
return Array.isArray(r.enum) && r.enum.length > 0;
|
|
89
89
|
}
|
|
90
90
|
function V(r) {
|
|
@@ -93,19 +93,19 @@ function V(r) {
|
|
|
93
93
|
function K(r) {
|
|
94
94
|
return Array.isArray(r.oneOf) && r.oneOf.length > 0;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function xe(r) {
|
|
97
97
|
return V(r) || K(r);
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function Ae(r) {
|
|
100
100
|
return Array.isArray(r.allOf) && r.allOf.length > 0;
|
|
101
101
|
}
|
|
102
102
|
function W(r) {
|
|
103
|
-
return V(r) || K(r) ||
|
|
103
|
+
return V(r) || K(r) || Ae(r);
|
|
104
104
|
}
|
|
105
105
|
function z(r) {
|
|
106
106
|
return r.includes("|") || r.includes("&") ? `(${r})[]` : `${r}[]`;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function Ce(r) {
|
|
109
109
|
return r.type !== "object" ? !1 : r.properties ? Object.keys(r.properties).length === 0 : !0;
|
|
110
110
|
}
|
|
111
111
|
function C(r) {
|
|
@@ -144,27 +144,27 @@ function B(r) {
|
|
|
144
144
|
const e = M(r);
|
|
145
145
|
return J(e);
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function Pe(r, e) {
|
|
148
148
|
return r.parameters ? r.parameters.map((t) => g(t) ? Q(t, e) : t).filter((t) => t.in === "path") : [];
|
|
149
149
|
}
|
|
150
|
-
const
|
|
150
|
+
const $e = "string";
|
|
151
151
|
function Y(r) {
|
|
152
|
-
return !r.schema || g(r.schema) || !r.schema.type || !q(r.schema.type) ?
|
|
152
|
+
return !r.schema || g(r.schema) || !r.schema.type || !q(r.schema.type) ? $e : C(r.schema.type);
|
|
153
153
|
}
|
|
154
154
|
function X(r) {
|
|
155
|
-
return r.startsWith("http://") || r.startsWith("https://") ?
|
|
155
|
+
return r.startsWith("http://") || r.startsWith("https://") ? Te(r) : Ie(r);
|
|
156
156
|
}
|
|
157
|
-
async function
|
|
157
|
+
async function Te(r) {
|
|
158
158
|
return await (await fetch(r)).text();
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function Ie(r) {
|
|
161
161
|
return new Promise((e, t) => {
|
|
162
|
-
|
|
162
|
+
le(r, "utf-8", (n, o) => {
|
|
163
163
|
n ? t(n) : e(o);
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
async function
|
|
167
|
+
async function Ee(r) {
|
|
168
168
|
const e = await X(r);
|
|
169
169
|
switch (Z(e)) {
|
|
170
170
|
case "json":
|
|
@@ -201,7 +201,7 @@ function Z(r) {
|
|
|
201
201
|
throw new Error("Unable to infer file format");
|
|
202
202
|
}
|
|
203
203
|
const ee = "types.ts", we = "@";
|
|
204
|
-
function
|
|
204
|
+
function Re(r) {
|
|
205
205
|
return w(r.path, ee);
|
|
206
206
|
}
|
|
207
207
|
function te(r, e, t) {
|
|
@@ -210,7 +210,7 @@ function te(r, e, t) {
|
|
|
210
210
|
overwrite: !0
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function P(r, e, t) {
|
|
214
214
|
let n = r.getImportDeclaration(
|
|
215
215
|
(o) => o.getModuleSpecifierValue() === e
|
|
216
216
|
);
|
|
@@ -224,17 +224,17 @@ function R(r, e, t) {
|
|
|
224
224
|
}
|
|
225
225
|
function f(r, e, t) {
|
|
226
226
|
if (t.path.startsWith(we)) {
|
|
227
|
-
|
|
227
|
+
P(r, t.path, [t.name]);
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
-
const n = r.getDirectoryPath(), o =
|
|
231
|
-
let s =
|
|
232
|
-
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s),
|
|
230
|
+
const n = r.getDirectoryPath(), o = pe(e, t.path, ee);
|
|
231
|
+
let s = ue(n, o);
|
|
232
|
+
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), P(r, s, [t.name]);
|
|
233
233
|
}
|
|
234
|
-
function
|
|
234
|
+
function E(r, e, t, n) {
|
|
235
235
|
r.path !== n.path && f(e, t, n);
|
|
236
236
|
}
|
|
237
|
-
function
|
|
237
|
+
function ve(r, e) {
|
|
238
238
|
const t = [r, e].filter(
|
|
239
239
|
(n) => n !== void 0 && n.length > 0
|
|
240
240
|
);
|
|
@@ -242,25 +242,25 @@ function Re(r, e) {
|
|
|
242
242
|
`) : void 0;
|
|
243
243
|
}
|
|
244
244
|
function x(r, e, t) {
|
|
245
|
-
const n =
|
|
245
|
+
const n = ve(e, t);
|
|
246
246
|
n && r.addJsDoc({
|
|
247
247
|
description: n
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
function
|
|
250
|
+
function Oe(r) {
|
|
251
251
|
const e = r.split(".");
|
|
252
252
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
253
253
|
}
|
|
254
|
-
function
|
|
255
|
-
const e =
|
|
254
|
+
function Ne(r) {
|
|
255
|
+
const e = Oe(r.name);
|
|
256
256
|
return e ? {
|
|
257
257
|
tag: r,
|
|
258
258
|
contextAlias: e[0],
|
|
259
259
|
aggregateName: e[1]
|
|
260
260
|
} : null;
|
|
261
261
|
}
|
|
262
|
-
function
|
|
263
|
-
const e = r?.map((n) =>
|
|
262
|
+
function De(r) {
|
|
263
|
+
const e = r?.map((n) => Ne(n)).filter((n) => n !== null);
|
|
264
264
|
if (!e)
|
|
265
265
|
return /* @__PURE__ */ new Map();
|
|
266
266
|
const t = /* @__PURE__ */ new Map();
|
|
@@ -272,20 +272,20 @@ function Ne(r) {
|
|
|
272
272
|
});
|
|
273
273
|
}), t;
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function be(r) {
|
|
276
276
|
if (!r)
|
|
277
277
|
return null;
|
|
278
278
|
const e = r.split(".");
|
|
279
279
|
return e.length != 3 ? null : e[2];
|
|
280
280
|
}
|
|
281
|
-
const
|
|
282
|
-
class
|
|
281
|
+
const qe = "#/components/responses/wow.CommandOk", Me = "#/components/parameters/wow.id";
|
|
282
|
+
class je {
|
|
283
283
|
/**
|
|
284
284
|
* Creates a new AggregateResolver instance.
|
|
285
285
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
286
286
|
*/
|
|
287
287
|
constructor(e) {
|
|
288
|
-
this.openAPI = e, this.aggregates =
|
|
288
|
+
this.openAPI = e, this.aggregates = De(e.tags), this.build();
|
|
289
289
|
}
|
|
290
290
|
aggregates;
|
|
291
291
|
/**
|
|
@@ -323,13 +323,13 @@ class Me {
|
|
|
323
323
|
const n = t.operation;
|
|
324
324
|
if (n.operationId === "wow.command.send")
|
|
325
325
|
return;
|
|
326
|
-
const o =
|
|
326
|
+
const o = be(n.operationId);
|
|
327
327
|
if (!o)
|
|
328
328
|
return;
|
|
329
329
|
const s = M(n);
|
|
330
|
-
if (!s || !g(s) || s.$ref !==
|
|
330
|
+
if (!s || !g(s) || s.$ref !== qe || !n.requestBody)
|
|
331
331
|
return;
|
|
332
|
-
const i = n.parameters ?? [], a = i.filter((m) => g(m) && m.$ref ===
|
|
332
|
+
const i = n.parameters ?? [], a = i.filter((m) => g(m) && m.$ref === Me).at(0), c = i.filter(
|
|
333
333
|
(m) => !g(m) && m.in === "path"
|
|
334
334
|
);
|
|
335
335
|
if (a) {
|
|
@@ -339,12 +339,12 @@ class Me {
|
|
|
339
339
|
);
|
|
340
340
|
c.push(m);
|
|
341
341
|
}
|
|
342
|
-
const p = n.requestBody.content[S.APPLICATION_JSON].schema, u =
|
|
342
|
+
const p = n.requestBody.content[S.APPLICATION_JSON].schema, u = I(
|
|
343
343
|
p,
|
|
344
344
|
this.openAPI.components
|
|
345
345
|
);
|
|
346
346
|
u.schema.title = u.schema.title || n.summary, u.schema.description = u.schema.description || n.description;
|
|
347
|
-
const
|
|
347
|
+
const ae = {
|
|
348
348
|
name: o,
|
|
349
349
|
method: t.method,
|
|
350
350
|
path: e,
|
|
@@ -356,7 +356,7 @@ class Me {
|
|
|
356
356
|
};
|
|
357
357
|
n.tags?.forEach((m) => {
|
|
358
358
|
const j = this.aggregates.get(m);
|
|
359
|
-
j && j.commands.set(o,
|
|
359
|
+
j && j.commands.set(o, ae);
|
|
360
360
|
});
|
|
361
361
|
}
|
|
362
362
|
/**
|
|
@@ -369,7 +369,7 @@ class Me {
|
|
|
369
369
|
const t = B(e);
|
|
370
370
|
if (!g(t))
|
|
371
371
|
return;
|
|
372
|
-
const n =
|
|
372
|
+
const n = I(
|
|
373
373
|
t,
|
|
374
374
|
this.openAPI.components
|
|
375
375
|
);
|
|
@@ -391,11 +391,11 @@ class Me {
|
|
|
391
391
|
const n = t?.items;
|
|
392
392
|
if (!g(n))
|
|
393
393
|
return;
|
|
394
|
-
const s =
|
|
394
|
+
const s = R(
|
|
395
395
|
n,
|
|
396
396
|
this.openAPI.components
|
|
397
397
|
).properties.body.items.anyOf.map((i) => {
|
|
398
|
-
const a = i.title, c = i.properties.name.const, l = i.properties.body, p =
|
|
398
|
+
const a = i.title, c = i.properties.name.const, l = i.properties.body, p = I(
|
|
399
399
|
l,
|
|
400
400
|
this.openAPI.components
|
|
401
401
|
);
|
|
@@ -422,17 +422,17 @@ class Me {
|
|
|
422
422
|
const n = L(
|
|
423
423
|
e.requestBody,
|
|
424
424
|
this.openAPI.components
|
|
425
|
-
).content[S.APPLICATION_JSON].schema, s =
|
|
425
|
+
).content[S.APPLICATION_JSON].schema, s = R(
|
|
426
426
|
n,
|
|
427
427
|
this.openAPI.components
|
|
428
|
-
).properties?.field, i =
|
|
428
|
+
).properties?.field, i = I(s, this.openAPI.components);
|
|
429
429
|
e.tags?.forEach((a) => {
|
|
430
430
|
const c = this.aggregates.get(a);
|
|
431
431
|
c && (c.fields = i);
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
|
-
const
|
|
435
|
+
const $ = "@ahoo-wang/fetcher-wow", Fe = {
|
|
436
436
|
"wow.command.CommandResult": "CommandResult",
|
|
437
437
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
438
438
|
"wow.api.BindingError": "BindingError",
|
|
@@ -464,9 +464,9 @@ const P = "@ahoo-wang/fetcher-wow", je = {
|
|
|
464
464
|
function d(r) {
|
|
465
465
|
if (!r)
|
|
466
466
|
return { name: "", path: "/" };
|
|
467
|
-
const e =
|
|
467
|
+
const e = Fe[r];
|
|
468
468
|
if (e)
|
|
469
|
-
return { name: e, path:
|
|
469
|
+
return { name: e, path: $ };
|
|
470
470
|
const t = r.split(".");
|
|
471
471
|
let n = -1;
|
|
472
472
|
for (let c = 0; c < t.length; c++)
|
|
@@ -478,15 +478,15 @@ function d(r) {
|
|
|
478
478
|
return { name: A(i), path: s };
|
|
479
479
|
}
|
|
480
480
|
function y(r) {
|
|
481
|
-
const e =
|
|
481
|
+
const e = T(r);
|
|
482
482
|
return d(e);
|
|
483
483
|
}
|
|
484
|
-
class
|
|
484
|
+
class _e {
|
|
485
485
|
constructor(e) {
|
|
486
486
|
this.context = e;
|
|
487
487
|
}
|
|
488
488
|
getOrCreateSourceFile(e) {
|
|
489
|
-
const t =
|
|
489
|
+
const t = Re(e);
|
|
490
490
|
return this.context.getOrCreateSourceFile(t);
|
|
491
491
|
}
|
|
492
492
|
/**
|
|
@@ -565,18 +565,18 @@ class Fe {
|
|
|
565
565
|
s && x(s, t.title, t.description);
|
|
566
566
|
}
|
|
567
567
|
process(e, t, n) {
|
|
568
|
-
if (
|
|
568
|
+
if (ye(n))
|
|
569
569
|
return t.addEnum({
|
|
570
570
|
name: e.name,
|
|
571
571
|
isExported: !0,
|
|
572
572
|
members: n.enum.filter((s) => typeof s == "string" && s.length > 0).map((s) => ({
|
|
573
|
-
name:
|
|
573
|
+
name: me(s),
|
|
574
574
|
initializer: `'${s}'`
|
|
575
575
|
}))
|
|
576
576
|
});
|
|
577
577
|
if (O(n) && g(n.items)) {
|
|
578
578
|
const s = y(n.items);
|
|
579
|
-
return
|
|
579
|
+
return E(
|
|
580
580
|
e,
|
|
581
581
|
t,
|
|
582
582
|
this.context.outputDir,
|
|
@@ -599,7 +599,7 @@ class Fe {
|
|
|
599
599
|
) : (W(n) && (n.anyOf || n.oneOf || n.allOf).forEach((i) => {
|
|
600
600
|
if (g(i)) {
|
|
601
601
|
const a = y(i);
|
|
602
|
-
|
|
602
|
+
E(
|
|
603
603
|
e,
|
|
604
604
|
t,
|
|
605
605
|
this.context.outputDir,
|
|
@@ -646,7 +646,7 @@ class Fe {
|
|
|
646
646
|
resolvePropertyType(e, t, n, o) {
|
|
647
647
|
if (g(o)) {
|
|
648
648
|
const s = y(o);
|
|
649
|
-
return
|
|
649
|
+
return E(
|
|
650
650
|
e,
|
|
651
651
|
t,
|
|
652
652
|
this.context.outputDir,
|
|
@@ -690,7 +690,7 @@ class Fe {
|
|
|
690
690
|
o.forEach((a) => {
|
|
691
691
|
if (g(a)) {
|
|
692
692
|
const c = y(a);
|
|
693
|
-
|
|
693
|
+
E(
|
|
694
694
|
e,
|
|
695
695
|
t,
|
|
696
696
|
this.context.outputDir,
|
|
@@ -700,14 +700,16 @@ class Fe {
|
|
|
700
700
|
}
|
|
701
701
|
s.add(C(a.type ?? "string"));
|
|
702
702
|
});
|
|
703
|
-
const i =
|
|
703
|
+
const i = xe(n) ? "|" : "&";
|
|
704
704
|
return Array.from(s).join(i);
|
|
705
705
|
}
|
|
706
706
|
}
|
|
707
|
-
const Ge = "@ahoo-wang/fetcher-decorator",
|
|
707
|
+
const Ge = "@ahoo-wang/fetcher-decorator", We = [
|
|
708
708
|
"type ApiMetadata",
|
|
709
709
|
"type ApiMetadataCapable",
|
|
710
|
+
"type ParameterRequest",
|
|
710
711
|
"api",
|
|
712
|
+
"get",
|
|
711
713
|
"post",
|
|
712
714
|
"put",
|
|
713
715
|
"patch",
|
|
@@ -716,7 +718,7 @@ const Ge = "@ahoo-wang/fetcher-decorator", _e = [
|
|
|
716
718
|
"attribute",
|
|
717
719
|
"path",
|
|
718
720
|
"autoGeneratedError"
|
|
719
|
-
],
|
|
721
|
+
], ze = {
|
|
720
722
|
type: "Promise<Response>",
|
|
721
723
|
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
722
724
|
}, N = `{
|
|
@@ -724,7 +726,7 @@ const Ge = "@ahoo-wang/fetcher-decorator", _e = [
|
|
|
724
726
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
725
727
|
}`;
|
|
726
728
|
function ne(r) {
|
|
727
|
-
|
|
729
|
+
P(r, Ge, We);
|
|
728
730
|
}
|
|
729
731
|
function oe(r, e, t = []) {
|
|
730
732
|
return e.addClass({
|
|
@@ -745,30 +747,34 @@ function re(r, e) {
|
|
|
745
747
|
name: "apiMetadata",
|
|
746
748
|
type: "ApiMetadata",
|
|
747
749
|
hasQuestionToken: e === void 0,
|
|
748
|
-
scope:
|
|
750
|
+
scope: ce.Public,
|
|
749
751
|
isReadonly: !0,
|
|
750
752
|
initializer: e
|
|
751
753
|
}
|
|
752
754
|
]
|
|
753
755
|
});
|
|
754
756
|
}
|
|
755
|
-
|
|
757
|
+
const Be = "@ahoo-wang/fetcher-eventstream";
|
|
758
|
+
function se(r) {
|
|
759
|
+
P(r, Be, ["JsonEventStreamResultExtractor", "type JsonServerSentEventStream"]);
|
|
760
|
+
}
|
|
761
|
+
function ke(r) {
|
|
756
762
|
let e = 0, t = 0;
|
|
757
763
|
return r.commands.forEach((n) => {
|
|
758
764
|
n.path.startsWith(F.TENANT) && (e += 1), n.path.startsWith(F.OWNER) && (t += 1);
|
|
759
765
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
760
766
|
}
|
|
761
|
-
function
|
|
767
|
+
function ie(r, e, t, n) {
|
|
762
768
|
const o = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
|
|
763
769
|
return te(r, e, o);
|
|
764
770
|
}
|
|
765
|
-
function
|
|
771
|
+
function Le(r, e) {
|
|
766
772
|
return `${A(r.aggregateName)}${e}`;
|
|
767
773
|
}
|
|
768
774
|
function D(r) {
|
|
769
775
|
return r === "delete" ? "del" : r;
|
|
770
776
|
}
|
|
771
|
-
class
|
|
777
|
+
class Qe {
|
|
772
778
|
/**
|
|
773
779
|
* Creates a new ApiClientGenerator instance.
|
|
774
780
|
* @param context - The generation context containing OpenAPI spec and configuration
|
|
@@ -777,7 +783,7 @@ class ke {
|
|
|
777
783
|
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:'${this.context.currentContextAlias}'}` : void 0;
|
|
778
784
|
}
|
|
779
785
|
defaultParameterRequestType = "ParameterRequest";
|
|
780
|
-
defaultReturnType =
|
|
786
|
+
defaultReturnType = ze;
|
|
781
787
|
apiMetadataCtorInitializer;
|
|
782
788
|
/**
|
|
783
789
|
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
@@ -834,7 +840,7 @@ class ke {
|
|
|
834
840
|
`Generating API client class: ${n.name}ApiClient with ${t.size} operations`
|
|
835
841
|
);
|
|
836
842
|
const o = this.createApiClientFile(n);
|
|
837
|
-
ne(o);
|
|
843
|
+
ne(o), se(o);
|
|
838
844
|
const s = oe(
|
|
839
845
|
n.name + "ApiClient",
|
|
840
846
|
o
|
|
@@ -912,7 +918,7 @@ class ke {
|
|
|
912
918
|
* @returns Array of parameter declarations
|
|
913
919
|
*/
|
|
914
920
|
resolveParameters(e, t, n) {
|
|
915
|
-
const o =
|
|
921
|
+
const o = Pe(n, this.context.openAPI.components).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
916
922
|
e.name,
|
|
917
923
|
a.name
|
|
918
924
|
));
|
|
@@ -999,7 +1005,7 @@ class ke {
|
|
|
999
1005
|
return this.context.logger.info(
|
|
1000
1006
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1001
1007
|
), this.defaultReturnType;
|
|
1002
|
-
const o = J(n) ||
|
|
1008
|
+
const o = J(n) || fe(n);
|
|
1003
1009
|
if (o) {
|
|
1004
1010
|
const i = this.resolveSchemaReturnType(e, o);
|
|
1005
1011
|
return this.context.logger.info(
|
|
@@ -1008,10 +1014,10 @@ class ke {
|
|
|
1008
1014
|
type: i
|
|
1009
1015
|
};
|
|
1010
1016
|
}
|
|
1011
|
-
const s =
|
|
1017
|
+
const s = de(n);
|
|
1012
1018
|
if (s) {
|
|
1013
1019
|
if (g(s)) {
|
|
1014
|
-
const a =
|
|
1020
|
+
const a = R(
|
|
1015
1021
|
s,
|
|
1016
1022
|
this.context.openAPI.components
|
|
1017
1023
|
);
|
|
@@ -1141,7 +1147,7 @@ class ke {
|
|
|
1141
1147
|
return !1;
|
|
1142
1148
|
}
|
|
1143
1149
|
}
|
|
1144
|
-
class
|
|
1150
|
+
class Ue {
|
|
1145
1151
|
/**
|
|
1146
1152
|
* Creates a new CommandClientGenerator instance.
|
|
1147
1153
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1181,7 +1187,7 @@ class Le {
|
|
|
1181
1187
|
this.context.logger.info(
|
|
1182
1188
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1183
1189
|
);
|
|
1184
|
-
const t =
|
|
1190
|
+
const t = ie(
|
|
1185
1191
|
this.context.project,
|
|
1186
1192
|
this.context.outputDir,
|
|
1187
1193
|
e.aggregate,
|
|
@@ -1204,9 +1210,9 @@ class Le {
|
|
|
1204
1210
|
],
|
|
1205
1211
|
isExported: !1
|
|
1206
1212
|
}), this.context.logger.info(
|
|
1207
|
-
`Adding imports from ${
|
|
1213
|
+
`Adding imports from ${$}: CommandRequest, CommandResult, CommandResultEventStream, DeleteAggregate, RecoverAggregate`
|
|
1208
1214
|
), t.addImportDeclaration({
|
|
1209
|
-
moduleSpecifier:
|
|
1215
|
+
moduleSpecifier: $,
|
|
1210
1216
|
namedImports: [
|
|
1211
1217
|
"CommandRequest",
|
|
1212
1218
|
"CommandResult",
|
|
@@ -1217,12 +1223,9 @@ class Le {
|
|
|
1217
1223
|
isTypeOnly: !0
|
|
1218
1224
|
}), this.context.logger.info(
|
|
1219
1225
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1220
|
-
), t.
|
|
1221
|
-
moduleSpecifier: "@ahoo-wang/fetcher-eventstream",
|
|
1222
|
-
namedImports: ["JsonEventStreamResultExtractor"]
|
|
1223
|
-
}), this.context.logger.info(
|
|
1226
|
+
), se(t), this.context.logger.info(
|
|
1224
1227
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1225
|
-
),
|
|
1228
|
+
), P(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1226
1229
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1227
1230
|
), ne(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(
|
|
1228
1231
|
`Command client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
@@ -1255,7 +1258,7 @@ class Le {
|
|
|
1255
1258
|
"''",
|
|
1256
1259
|
N
|
|
1257
1260
|
], i = "Promise<CommandResultEventStream>");
|
|
1258
|
-
const a =
|
|
1261
|
+
const a = Le(
|
|
1259
1262
|
t.aggregate,
|
|
1260
1263
|
o
|
|
1261
1264
|
), c = oe(a, e, s);
|
|
@@ -1291,7 +1294,7 @@ class Le {
|
|
|
1291
1294
|
`Adding command request parameter: commandRequest (type: CommandRequest<${o.name}>)`
|
|
1292
1295
|
), s.push({
|
|
1293
1296
|
name: "commandRequest",
|
|
1294
|
-
hasQuestionToken:
|
|
1297
|
+
hasQuestionToken: Ce(n.schema.schema),
|
|
1295
1298
|
type: `CommandRequest<${o.name}>`,
|
|
1296
1299
|
decorators: [
|
|
1297
1300
|
{
|
|
@@ -1340,7 +1343,7 @@ class Le {
|
|
|
1340
1343
|
);
|
|
1341
1344
|
}
|
|
1342
1345
|
}
|
|
1343
|
-
class
|
|
1346
|
+
class Je {
|
|
1344
1347
|
/**
|
|
1345
1348
|
* Creates a new QueryClientGenerator instance.
|
|
1346
1349
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1377,7 +1380,7 @@ class Qe {
|
|
|
1377
1380
|
* @returns The source file for the client
|
|
1378
1381
|
*/
|
|
1379
1382
|
createClientFilePath(e, t) {
|
|
1380
|
-
return
|
|
1383
|
+
return ie(
|
|
1381
1384
|
this.context.project,
|
|
1382
1385
|
this.context.outputDir,
|
|
1383
1386
|
e,
|
|
@@ -1396,9 +1399,9 @@ class Qe {
|
|
|
1396
1399
|
this.context.logger.info(
|
|
1397
1400
|
`Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1398
1401
|
), this.context.logger.info(
|
|
1399
|
-
`Adding imports from ${
|
|
1402
|
+
`Adding imports from ${$}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
|
|
1400
1403
|
), t.addImportDeclaration({
|
|
1401
|
-
moduleSpecifier:
|
|
1404
|
+
moduleSpecifier: $,
|
|
1402
1405
|
namedImports: [
|
|
1403
1406
|
"QueryClientFactory",
|
|
1404
1407
|
"QueryClientOptions",
|
|
@@ -1417,7 +1420,7 @@ class Qe {
|
|
|
1417
1420
|
initializer: `{
|
|
1418
1421
|
contextAlias: '${e.aggregate.contextAlias}',
|
|
1419
1422
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1420
|
-
resourceAttribution: ${
|
|
1423
|
+
resourceAttribution: ${ke(e)},
|
|
1421
1424
|
}`
|
|
1422
1425
|
}
|
|
1423
1426
|
],
|
|
@@ -1459,13 +1462,13 @@ class Qe {
|
|
|
1459
1462
|
);
|
|
1460
1463
|
}
|
|
1461
1464
|
}
|
|
1462
|
-
class
|
|
1465
|
+
class Ve {
|
|
1463
1466
|
/**
|
|
1464
1467
|
* Creates a new ClientGenerator instance.
|
|
1465
1468
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1466
1469
|
*/
|
|
1467
1470
|
constructor(e) {
|
|
1468
|
-
this.context = e, this.queryClientGenerator = new
|
|
1471
|
+
this.context = e, this.queryClientGenerator = new Je(e), this.commandClientGenerator = new Ue(e), this.apiClientGenerator = new Qe(e);
|
|
1469
1472
|
}
|
|
1470
1473
|
queryClientGenerator;
|
|
1471
1474
|
commandClientGenerator;
|
|
@@ -1504,7 +1507,7 @@ class Ue {
|
|
|
1504
1507
|
);
|
|
1505
1508
|
}
|
|
1506
1509
|
}
|
|
1507
|
-
class
|
|
1510
|
+
class Ke {
|
|
1508
1511
|
/** The ts-morph project instance used for code generation */
|
|
1509
1512
|
project;
|
|
1510
1513
|
/** The OpenAPI specification object */
|
|
@@ -1531,14 +1534,14 @@ class Je {
|
|
|
1531
1534
|
return this.defaultIgnorePathParameters.includes(t);
|
|
1532
1535
|
}
|
|
1533
1536
|
}
|
|
1534
|
-
const
|
|
1535
|
-
class
|
|
1537
|
+
const He = "./fetcher-generator.config.json";
|
|
1538
|
+
class ot {
|
|
1536
1539
|
/**
|
|
1537
1540
|
* Creates a new CodeGenerator instance.
|
|
1538
1541
|
* @param options - Configuration options for code generation
|
|
1539
1542
|
*/
|
|
1540
1543
|
constructor(e) {
|
|
1541
|
-
this.options = e, this.project = new
|
|
1544
|
+
this.options = e, this.project = new ge({ tsConfigFilePath: this.options.tsConfigFilePath }), this.options.logger.info("Project instance created with tsConfigFilePath: ", this.options.tsConfigFilePath);
|
|
1542
1545
|
}
|
|
1543
1546
|
project;
|
|
1544
1547
|
/**
|
|
@@ -1550,20 +1553,20 @@ class tt {
|
|
|
1550
1553
|
this.options.logger.info(
|
|
1551
1554
|
"Starting code generation from OpenAPI specification"
|
|
1552
1555
|
), 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");
|
|
1553
|
-
const e = await
|
|
1556
|
+
const e = await Ee(this.options.inputPath);
|
|
1554
1557
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1555
|
-
const n = new
|
|
1558
|
+
const n = new je(e).resolve();
|
|
1556
1559
|
this.options.logger.info(
|
|
1557
1560
|
`Resolved ${n.size} bounded context aggregates`
|
|
1558
1561
|
);
|
|
1559
|
-
const o = this.options.configPath ??
|
|
1562
|
+
const o = this.options.configPath ?? He;
|
|
1560
1563
|
let s = {};
|
|
1561
1564
|
try {
|
|
1562
1565
|
this.options.logger.info("Parsing configuration file:", o), s = await Se(o);
|
|
1563
1566
|
} catch (l) {
|
|
1564
1567
|
this.options.logger.info("Configuration file parsing failed ", l);
|
|
1565
1568
|
}
|
|
1566
|
-
const i = new
|
|
1569
|
+
const i = new Ke({
|
|
1567
1570
|
openAPI: e,
|
|
1568
1571
|
project: this.project,
|
|
1569
1572
|
outputDir: this.options.outputDir,
|
|
@@ -1571,7 +1574,7 @@ class tt {
|
|
|
1571
1574
|
logger: this.options.logger,
|
|
1572
1575
|
config: s
|
|
1573
1576
|
});
|
|
1574
|
-
this.options.logger.info("Generating models"), new
|
|
1577
|
+
this.options.logger.info("Generating models"), new _e(i).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new Ve(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");
|
|
1575
1578
|
}
|
|
1576
1579
|
/**
|
|
1577
1580
|
* Generates index.ts files for all subdirectories in the output directory.
|
|
@@ -1651,7 +1654,7 @@ class tt {
|
|
|
1651
1654
|
}
|
|
1652
1655
|
}
|
|
1653
1656
|
export {
|
|
1654
|
-
|
|
1655
|
-
|
|
1657
|
+
ot as CodeGenerator,
|
|
1658
|
+
He as DEFAULT_CONFIG_PATH
|
|
1656
1659
|
};
|
|
1657
1660
|
//# sourceMappingURL=index.js.map
|