@ahoo-wang/fetcher-generator 2.11.0 → 2.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -36
- package/dist/index.js.map +1 -1
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/model/wowTypeMapping.d.ts +1 -0
- package/dist/model/wowTypeMapping.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function V(o, e) {
|
|
|
15
15
|
const t = $(o);
|
|
16
16
|
return e.requestBodies?.[t];
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function H(o, e) {
|
|
19
19
|
const t = $(o);
|
|
20
20
|
return e.parameters?.[t];
|
|
21
21
|
}
|
|
@@ -29,10 +29,10 @@ const he = /[-_\s.]+/;
|
|
|
29
29
|
function N(o) {
|
|
30
30
|
return o.split(he);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return Array.isArray(o) ? o.flatMap((e) =>
|
|
32
|
+
function Y(o) {
|
|
33
|
+
return Array.isArray(o) ? o.flatMap((e) => L(N(e))) : L(N(o));
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function L(o) {
|
|
36
36
|
return o.flatMap((e) => {
|
|
37
37
|
if (e.length === 0)
|
|
38
38
|
return [];
|
|
@@ -46,7 +46,7 @@ function z(o) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
function x(o) {
|
|
49
|
-
return o === "" || o.length === 0 ? "" :
|
|
49
|
+
return o === "" || o.length === 0 ? "" : Y(o).filter((t) => t.length > 0).map((t) => {
|
|
50
50
|
const n = t.charAt(0), r = t.slice(1);
|
|
51
51
|
return (/[a-zA-Z]/.test(n) ? n.toUpperCase() : n) + r.toLowerCase();
|
|
52
52
|
}).join("");
|
|
@@ -56,7 +56,7 @@ function h(o) {
|
|
|
56
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
57
|
}
|
|
58
58
|
function ye(o) {
|
|
59
|
-
return o === "" || Array.isArray(o) && o.length === 0 ? "" :
|
|
59
|
+
return o === "" || Array.isArray(o) && o.length === 0 ? "" : Y(o).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
60
|
}
|
|
61
61
|
function g(o) {
|
|
62
62
|
return !!(o && typeof o == "object" && "$ref" in o);
|
|
@@ -65,7 +65,7 @@ function j(o, e) {
|
|
|
65
65
|
if (e && !g(e) && e.content)
|
|
66
66
|
return e.content[o]?.schema;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function K(o) {
|
|
69
69
|
return j(E.APPLICATION_JSON, o);
|
|
70
70
|
}
|
|
71
71
|
function xe(o) {
|
|
@@ -102,7 +102,7 @@ function $e(o) {
|
|
|
102
102
|
function Ie(o) {
|
|
103
103
|
return Array.isArray(o.allOf) && o.allOf.length > 0;
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function z(o) {
|
|
106
106
|
return X(o) || Z(o) || Ie(o);
|
|
107
107
|
}
|
|
108
108
|
function k(o) {
|
|
@@ -145,29 +145,29 @@ function F(o) {
|
|
|
145
145
|
}
|
|
146
146
|
function B(o) {
|
|
147
147
|
const e = F(o);
|
|
148
|
-
return
|
|
148
|
+
return K(e);
|
|
149
149
|
}
|
|
150
150
|
function Ee(o, e) {
|
|
151
|
-
return o.parameters ? o.parameters.map((t) => g(t) ?
|
|
151
|
+
return o.parameters ? o.parameters.map((t) => g(t) ? H(t, e) : t).filter((t) => t.in === "path") : [];
|
|
152
152
|
}
|
|
153
153
|
const ve = "string";
|
|
154
154
|
function ee(o) {
|
|
155
155
|
return !o.schema || g(o.schema) || !o.schema.type || !_(o.schema.type) ? ve : A(o.schema.type);
|
|
156
156
|
}
|
|
157
157
|
function te(o) {
|
|
158
|
-
return o.startsWith("http://") || o.startsWith("https://") ? Se(o) :
|
|
158
|
+
return o.startsWith("http://") || o.startsWith("https://") ? Se(o) : we(o);
|
|
159
159
|
}
|
|
160
160
|
async function Se(o) {
|
|
161
161
|
return await (await fetch(o)).text();
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function we(o) {
|
|
164
164
|
return new Promise((e, t) => {
|
|
165
165
|
me(o, "utf-8", (n, r) => {
|
|
166
166
|
n ? t(n) : e(r);
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
async function
|
|
170
|
+
async function Re(o) {
|
|
171
171
|
const e = await te(o);
|
|
172
172
|
switch (ne(e)) {
|
|
173
173
|
case "json":
|
|
@@ -246,16 +246,16 @@ function Me(o) {
|
|
|
246
246
|
return e.length > 0 ? e.join(`
|
|
247
247
|
`) : void 0;
|
|
248
248
|
}
|
|
249
|
-
function
|
|
249
|
+
function w(o, e) {
|
|
250
250
|
const t = Me(e);
|
|
251
251
|
t && o.addJsDoc(t);
|
|
252
252
|
}
|
|
253
|
-
function
|
|
253
|
+
function R(o, e) {
|
|
254
254
|
const t = [
|
|
255
255
|
e.title,
|
|
256
256
|
e.description
|
|
257
257
|
];
|
|
258
|
-
e.format && t.push(`- format: ${e.format}`), U(t, e, "default"), U(t, e, "example"), be(t, e), qe(t, e), je(t, e),
|
|
258
|
+
e.format && t.push(`- format: ${e.format}`), U(t, e, "default"), U(t, e, "example"), be(t, e), qe(t, e), je(t, e), w(o, t);
|
|
259
259
|
}
|
|
260
260
|
function U(o, e, t) {
|
|
261
261
|
const n = e[t];
|
|
@@ -314,7 +314,7 @@ function We(o) {
|
|
|
314
314
|
const e = o.split(".");
|
|
315
315
|
return e.length != 3 ? null : e[2];
|
|
316
316
|
}
|
|
317
|
-
const
|
|
317
|
+
const Le = "#/components/responses/wow.CommandOk", ze = "#/components/parameters/wow.id";
|
|
318
318
|
class ke {
|
|
319
319
|
/**
|
|
320
320
|
* Creates a new AggregateResolver instance.
|
|
@@ -363,13 +363,13 @@ class ke {
|
|
|
363
363
|
if (!r)
|
|
364
364
|
return;
|
|
365
365
|
const i = F(n);
|
|
366
|
-
if (!i || !g(i) || i.$ref !==
|
|
366
|
+
if (!i || !g(i) || i.$ref !== Le || !n.requestBody)
|
|
367
367
|
return;
|
|
368
|
-
const s = n.parameters ?? [], a = s.filter((m) => g(m) && m.$ref ===
|
|
368
|
+
const s = n.parameters ?? [], a = s.filter((m) => g(m) && m.$ref === ze).at(0), c = s.filter(
|
|
369
369
|
(m) => !g(m) && m.in === "path"
|
|
370
370
|
);
|
|
371
371
|
if (a) {
|
|
372
|
-
const m =
|
|
372
|
+
const m = H(
|
|
373
373
|
a,
|
|
374
374
|
this.openAPI.components
|
|
375
375
|
);
|
|
@@ -470,6 +470,7 @@ class ke {
|
|
|
470
470
|
}
|
|
471
471
|
const P = "@ahoo-wang/fetcher-wow", Be = {
|
|
472
472
|
"wow.command.CommandResult": "CommandResult",
|
|
473
|
+
"wow.command.CommandResultArray": "CommandResultArray",
|
|
473
474
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
474
475
|
"wow.api.BindingError": "BindingError",
|
|
475
476
|
"wow.api.DefaultErrorInfo": "ErrorInfo",
|
|
@@ -556,6 +557,8 @@ class Ue {
|
|
|
556
557
|
})).filter((n) => !this.isWowSchema(n.key, t));
|
|
557
558
|
}
|
|
558
559
|
isWowSchema(e, t) {
|
|
560
|
+
if (e !== "wow.api.query.PagedList" && e.startsWith("wow.api.query.") && e.endsWith("PagedList"))
|
|
561
|
+
return !1;
|
|
559
562
|
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"))
|
|
560
563
|
return !0;
|
|
561
564
|
const n = d(e);
|
|
@@ -598,7 +601,7 @@ class Ue {
|
|
|
598
601
|
*/
|
|
599
602
|
generateKeyedSchema({ key: e, schema: t }) {
|
|
600
603
|
const n = d(e), r = this.getOrCreateSourceFile(n), i = this.process(n, r, t);
|
|
601
|
-
i &&
|
|
604
|
+
i && R(i, t);
|
|
602
605
|
}
|
|
603
606
|
process(e, t, n) {
|
|
604
607
|
if (Pe(n))
|
|
@@ -632,7 +635,7 @@ class Ue {
|
|
|
632
635
|
e,
|
|
633
636
|
n,
|
|
634
637
|
r
|
|
635
|
-
) : (
|
|
638
|
+
) : (z(n) && (n.anyOf || n.oneOf || n.allOf).forEach((s) => {
|
|
636
639
|
if (g(s)) {
|
|
637
640
|
const a = y(s);
|
|
638
641
|
T(
|
|
@@ -675,7 +678,7 @@ class Ue {
|
|
|
675
678
|
c ? c.setType(a) : c = r.addProperty({
|
|
676
679
|
name: i,
|
|
677
680
|
type: a
|
|
678
|
-
}), g(s) ||
|
|
681
|
+
}), g(s) || R(c, s);
|
|
679
682
|
}
|
|
680
683
|
return r;
|
|
681
684
|
}
|
|
@@ -702,7 +705,7 @@ class Ue {
|
|
|
702
705
|
}
|
|
703
706
|
if (r.type && _(r.type))
|
|
704
707
|
return A(r.type);
|
|
705
|
-
if (
|
|
708
|
+
if (z(r))
|
|
706
709
|
return this.resolvePropertyCompositionType(
|
|
707
710
|
e,
|
|
708
711
|
t,
|
|
@@ -717,7 +720,7 @@ class Ue {
|
|
|
717
720
|
i,
|
|
718
721
|
r
|
|
719
722
|
);
|
|
720
|
-
return
|
|
723
|
+
return R(s, r), i.name;
|
|
721
724
|
}
|
|
722
725
|
return "any";
|
|
723
726
|
}
|
|
@@ -793,11 +796,11 @@ function ae(o, e) {
|
|
|
793
796
|
]
|
|
794
797
|
});
|
|
795
798
|
}
|
|
796
|
-
const
|
|
799
|
+
const He = "@ahoo-wang/fetcher-eventstream";
|
|
797
800
|
function ce(o) {
|
|
798
|
-
C(o,
|
|
801
|
+
C(o, He, ["JsonEventStreamResultExtractor", "type JsonServerSentEventStream"]);
|
|
799
802
|
}
|
|
800
|
-
function
|
|
803
|
+
function Ye(o) {
|
|
801
804
|
let e = 0, t = 0;
|
|
802
805
|
return o.commands.forEach((n) => {
|
|
803
806
|
n.path.startsWith(W.TENANT) && (e += 1), n.path.startsWith(W.OWNER) && (t += 1);
|
|
@@ -807,7 +810,7 @@ function ge(o, e, t, n) {
|
|
|
807
810
|
const r = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
|
|
808
811
|
return re(o, e, r);
|
|
809
812
|
}
|
|
810
|
-
function
|
|
813
|
+
function Ke(o, e) {
|
|
811
814
|
return `${x(o.aggregateName)}${e}`;
|
|
812
815
|
}
|
|
813
816
|
function q(o) {
|
|
@@ -899,7 +902,7 @@ class et {
|
|
|
899
902
|
n.name + "ApiClient",
|
|
900
903
|
r
|
|
901
904
|
);
|
|
902
|
-
|
|
905
|
+
w(i, [e.description]), ae(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
903
906
|
`Processing ${t.size} operations for ${n.name}ApiClient`
|
|
904
907
|
), t.forEach((s) => {
|
|
905
908
|
this.processOperation(e, r, i, s);
|
|
@@ -1056,7 +1059,7 @@ class et {
|
|
|
1056
1059
|
return this.context.logger.info(
|
|
1057
1060
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1058
1061
|
), this.defaultReturnType;
|
|
1059
|
-
const r =
|
|
1062
|
+
const r = K(n) || Ae(n);
|
|
1060
1063
|
if (r) {
|
|
1061
1064
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1062
1065
|
return this.context.logger.info(
|
|
@@ -1132,11 +1135,12 @@ class et {
|
|
|
1132
1135
|
`throw autoGeneratedError(${s.map((l) => l.name).join(",")});`
|
|
1133
1136
|
]
|
|
1134
1137
|
});
|
|
1135
|
-
|
|
1138
|
+
w(
|
|
1136
1139
|
u,
|
|
1137
1140
|
[
|
|
1138
1141
|
r.operation.summary,
|
|
1139
1142
|
r.operation.description,
|
|
1143
|
+
`- operationId: \`${r.operation.operationId}\``,
|
|
1140
1144
|
`- path: \`${r.path}\``
|
|
1141
1145
|
]
|
|
1142
1146
|
), this.context.logger.success(`Operation method generated: ${i}`);
|
|
@@ -1325,7 +1329,7 @@ class tt {
|
|
|
1325
1329
|
"''",
|
|
1326
1330
|
b
|
|
1327
1331
|
], s = "Promise<CommandResultEventStream>");
|
|
1328
|
-
const a =
|
|
1332
|
+
const a = Ke(
|
|
1329
1333
|
t.aggregate,
|
|
1330
1334
|
r
|
|
1331
1335
|
), c = se(a, e, i);
|
|
@@ -1405,7 +1409,15 @@ class tt {
|
|
|
1405
1409
|
});
|
|
1406
1410
|
this.context.logger.info(
|
|
1407
1411
|
`Adding JSDoc documentation for method: ${h(r.name)}`
|
|
1408
|
-
),
|
|
1412
|
+
), w(
|
|
1413
|
+
a,
|
|
1414
|
+
[
|
|
1415
|
+
r.summary,
|
|
1416
|
+
r.description,
|
|
1417
|
+
`- operationId: \`${r.operation.operationId}\``,
|
|
1418
|
+
`- path: \`${r.path}\``
|
|
1419
|
+
]
|
|
1420
|
+
), this.context.logger.success(
|
|
1409
1421
|
`Command method generated: ${h(r.name)}`
|
|
1410
1422
|
);
|
|
1411
1423
|
}
|
|
@@ -1487,7 +1499,7 @@ class nt {
|
|
|
1487
1499
|
initializer: `{
|
|
1488
1500
|
contextAlias: '${e.aggregate.contextAlias}',
|
|
1489
1501
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1490
|
-
resourceAttribution: ${
|
|
1502
|
+
resourceAttribution: ${Ye(e)},
|
|
1491
1503
|
}`
|
|
1492
1504
|
}
|
|
1493
1505
|
],
|
|
@@ -1620,7 +1632,7 @@ class pt {
|
|
|
1620
1632
|
this.options.logger.info(
|
|
1621
1633
|
"Starting code generation from OpenAPI specification"
|
|
1622
1634
|
), 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");
|
|
1623
|
-
const e = await
|
|
1635
|
+
const e = await Re(this.options.inputPath);
|
|
1624
1636
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1625
1637
|
const n = new ke(e).resolve();
|
|
1626
1638
|
this.options.logger.info(
|