@ahoo-wang/fetcher-generator 3.4.5 → 3.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.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/apiClientGenerator.d.ts +1 -0
- package/dist/client/apiClientGenerator.d.ts.map +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +109 -113
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Scope as
|
|
1
|
+
import { Scope as Ae, VariableDeclarationKind as O, Project as Ce } from "ts-morph";
|
|
2
2
|
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
|
-
import { readFile as
|
|
6
|
-
import { join as
|
|
5
|
+
import { readFile as Pe } from "fs";
|
|
6
|
+
import { join as $e, relative as Te, sep as ve } from "path";
|
|
7
7
|
function P(n) {
|
|
8
8
|
return n.$ref.split("/").pop();
|
|
9
9
|
}
|
|
@@ -25,12 +25,12 @@ function $(n, e) {
|
|
|
25
25
|
schema: S(n, e)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
return n.split(
|
|
28
|
+
const Ie = /[-_'\s./?;:,()[\]{}|\\]+/;
|
|
29
|
+
function M(n) {
|
|
30
|
+
return n.split(Ie);
|
|
31
31
|
}
|
|
32
32
|
function X(n) {
|
|
33
|
-
return Array.isArray(n) ? n.flatMap((e) => B(
|
|
33
|
+
return Array.isArray(n) ? n.flatMap((e) => B(M(e))) : B(M(n));
|
|
34
34
|
}
|
|
35
35
|
function B(n) {
|
|
36
36
|
return n.flatMap((e) => {
|
|
@@ -45,24 +45,24 @@ function B(n) {
|
|
|
45
45
|
return o && t.push(o), t;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function w(n) {
|
|
49
49
|
return n === "" || n.length === 0 ? "" : X(n).filter((t) => t.length > 0).map((t) => {
|
|
50
50
|
const o = t.charAt(0), r = t.slice(1);
|
|
51
51
|
return (/[a-zA-Z]/.test(o) ? o.toUpperCase() : o) + r.toLowerCase();
|
|
52
52
|
}).join("");
|
|
53
53
|
}
|
|
54
54
|
function f(n) {
|
|
55
|
-
const e =
|
|
55
|
+
const e = w(n);
|
|
56
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
57
|
}
|
|
58
58
|
function ee(n) {
|
|
59
59
|
return n === "" || Array.isArray(n) && n.length === 0 ? "" : X(n).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function b(n) {
|
|
62
62
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n) ? n : `'${n}'`;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
return /^\d+$/.test(n) ? `NUM_${n}` :
|
|
64
|
+
function Ee(n) {
|
|
65
|
+
return /^\d+$/.test(n) ? `NUM_${n}` : b(ee(n));
|
|
66
66
|
}
|
|
67
67
|
function p(n) {
|
|
68
68
|
return !!(n && typeof n == "object" && "$ref" in n);
|
|
@@ -74,13 +74,13 @@ function G(n, e) {
|
|
|
74
74
|
function te(n) {
|
|
75
75
|
return G(I.APPLICATION_JSON, n);
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function Se(n) {
|
|
78
78
|
return G(I.TEXT_EVENT_STREAM, n);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function Re(n) {
|
|
81
81
|
return G("*/*", n);
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const we = [
|
|
84
84
|
"string",
|
|
85
85
|
"number",
|
|
86
86
|
"integer",
|
|
@@ -88,7 +88,7 @@ const Se = [
|
|
|
88
88
|
"null"
|
|
89
89
|
];
|
|
90
90
|
function ne(n) {
|
|
91
|
-
return Array.isArray(n) ? !0 :
|
|
91
|
+
return Array.isArray(n) ? !0 : we.includes(n);
|
|
92
92
|
}
|
|
93
93
|
function U(n) {
|
|
94
94
|
return Array.isArray(n.enum) && n.enum.length > 0;
|
|
@@ -96,25 +96,25 @@ function U(n) {
|
|
|
96
96
|
function T(n) {
|
|
97
97
|
return n.type === "object" && !!n.properties;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function R(n) {
|
|
100
100
|
return n.type === "array" && !!n.items;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function De(n) {
|
|
103
103
|
return Array.isArray(n.anyOf) && n.anyOf.length > 0;
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function Ne(n) {
|
|
106
106
|
return Array.isArray(n.oneOf) && n.oneOf.length > 0;
|
|
107
107
|
}
|
|
108
108
|
function q(n) {
|
|
109
109
|
return Array.isArray(n.allOf) && n.allOf.length > 0;
|
|
110
110
|
}
|
|
111
111
|
function J(n) {
|
|
112
|
-
return
|
|
112
|
+
return De(n) || Ne(n) || q(n);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function oe(n) {
|
|
115
115
|
return n.includes("|") || n.includes("&") ? `(${n})[]` : `${n}[]`;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function re(n) {
|
|
118
118
|
return n.type === "object" && !n.properties && n.additionalProperties !== void 0;
|
|
119
119
|
}
|
|
120
120
|
function Oe(n) {
|
|
@@ -123,9 +123,9 @@ function Oe(n) {
|
|
|
123
123
|
function Me(n) {
|
|
124
124
|
return n.readOnly === !0;
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function D(n) {
|
|
127
127
|
if (Array.isArray(n))
|
|
128
|
-
return n.map((e) =>
|
|
128
|
+
return n.map((e) => D(e)).join(" | ");
|
|
129
129
|
switch (n) {
|
|
130
130
|
case "string":
|
|
131
131
|
return "string";
|
|
@@ -151,10 +151,10 @@ function qe(n, e) {
|
|
|
151
151
|
e.operation.operationId
|
|
152
152
|
) : n.path && e.path ? n.path.localeCompare(e.path) : n.method && e.method ? n.method.localeCompare(e.method) : 0;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function ie(n) {
|
|
155
155
|
const e = [];
|
|
156
156
|
for (const [t, o] of Object.entries(n))
|
|
157
|
-
|
|
157
|
+
se(o).forEach((r) => {
|
|
158
158
|
e.push({
|
|
159
159
|
method: r.method,
|
|
160
160
|
operation: r.operation,
|
|
@@ -163,7 +163,7 @@ function oe(n) {
|
|
|
163
163
|
});
|
|
164
164
|
return e.sort(qe);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function se(n) {
|
|
167
167
|
return [
|
|
168
168
|
{ method: "get", operation: n.get },
|
|
169
169
|
{ method: "put", operation: n.put },
|
|
@@ -186,10 +186,10 @@ function Fe(n, e) {
|
|
|
186
186
|
return n.parameters ? n.parameters.map((t) => p(t) ? Z(t, e) : t).filter((t) => t.in === "path") : [];
|
|
187
187
|
}
|
|
188
188
|
const je = "string";
|
|
189
|
-
function
|
|
190
|
-
return !n.schema || p(n.schema) || !n.schema.type || !ne(n.schema.type) ? je :
|
|
189
|
+
function ae(n) {
|
|
190
|
+
return !n.schema || p(n.schema) || !n.schema.type || !ne(n.schema.type) ? je : D(n.schema.type);
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function ce(n) {
|
|
193
193
|
return n.startsWith("http://") || n.startsWith("https://") ? _e(n) : Ge(n);
|
|
194
194
|
}
|
|
195
195
|
async function _e(n) {
|
|
@@ -197,14 +197,14 @@ async function _e(n) {
|
|
|
197
197
|
}
|
|
198
198
|
function Ge(n) {
|
|
199
199
|
return new Promise((e, t) => {
|
|
200
|
-
|
|
200
|
+
Pe(n, "utf-8", (o, r) => {
|
|
201
201
|
o ? t(o) : e(r);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
async function We(n) {
|
|
206
|
-
const e = await
|
|
207
|
-
switch (
|
|
206
|
+
const e = await ce(n);
|
|
207
|
+
switch (pe(e)) {
|
|
208
208
|
case "json":
|
|
209
209
|
return JSON.parse(e);
|
|
210
210
|
case "yaml":
|
|
@@ -214,8 +214,8 @@ async function We(n) {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
async function ke(n) {
|
|
217
|
-
const e = await
|
|
218
|
-
switch (
|
|
217
|
+
const e = await ce(n);
|
|
218
|
+
switch (pe(e)) {
|
|
219
219
|
case "json":
|
|
220
220
|
return JSON.parse(e);
|
|
221
221
|
case "yaml":
|
|
@@ -224,7 +224,7 @@ async function ke(n) {
|
|
|
224
224
|
throw new Error(`Unsupported file format: ${n}`);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function pe(n) {
|
|
228
228
|
const e = n.trimStart();
|
|
229
229
|
if (e.startsWith("{") || e.startsWith("["))
|
|
230
230
|
return "json";
|
|
@@ -238,11 +238,11 @@ function ae(n) {
|
|
|
238
238
|
}
|
|
239
239
|
throw new Error("Unable to infer file format");
|
|
240
240
|
}
|
|
241
|
-
const
|
|
241
|
+
const ge = "types.ts", ze = "@";
|
|
242
242
|
function Le(n) {
|
|
243
|
-
return E(n.path,
|
|
243
|
+
return E(n.path, ge);
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function ue(n, e, t) {
|
|
246
246
|
const o = E(e, t), r = n.getSourceFile(o);
|
|
247
247
|
return r || n.createSourceFile(o, "", {
|
|
248
248
|
overwrite: !0
|
|
@@ -265,14 +265,14 @@ function m(n, e, t) {
|
|
|
265
265
|
A(n, t.path, [t.name]);
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
|
-
const o = n.getDirectoryPath(), r =
|
|
269
|
-
let i =
|
|
270
|
-
i = i.replace(/\.ts$/, ""), i = i.split(
|
|
268
|
+
const o = n.getDirectoryPath(), r = $e(e, t.path, ge);
|
|
269
|
+
let i = Te(o, r);
|
|
270
|
+
i = i.replace(/\.ts$/, ""), i = i.split(ve).join("/"), i.startsWith(".") || (i = "./" + i), A(n, i, [t.name]);
|
|
271
271
|
}
|
|
272
272
|
function Be(n, e, t, o) {
|
|
273
273
|
n.path !== o.path && m(e, t, o);
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function le(n, e = `
|
|
276
276
|
`) {
|
|
277
277
|
if (!Array.isArray(n))
|
|
278
278
|
return;
|
|
@@ -282,7 +282,7 @@ function ge(n, e = `
|
|
|
282
282
|
return t.length > 0 ? t.join(e) : void 0;
|
|
283
283
|
}
|
|
284
284
|
function C(n, e) {
|
|
285
|
-
const t =
|
|
285
|
+
const t = le(e);
|
|
286
286
|
t && n.addJsDoc(t);
|
|
287
287
|
}
|
|
288
288
|
function k(n, e) {
|
|
@@ -298,7 +298,7 @@ function Ue(n, e, t) {
|
|
|
298
298
|
}
|
|
299
299
|
function Je(n, e, t) {
|
|
300
300
|
const o = k(e, t);
|
|
301
|
-
|
|
301
|
+
me(o, "schema", e), C(n, o);
|
|
302
302
|
}
|
|
303
303
|
function V(n, e, t) {
|
|
304
304
|
const o = e[t];
|
|
@@ -307,10 +307,10 @@ function V(n, e, t) {
|
|
|
307
307
|
n.push(`- ${t}: \`${o}\``);
|
|
308
308
|
return;
|
|
309
309
|
}
|
|
310
|
-
|
|
310
|
+
me(n, t, o);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function me(n, e, t) {
|
|
314
314
|
n.push(`- ${e}: `), n.push("```json"), n.push(JSON.stringify(t, null, 2)), n.push("```");
|
|
315
315
|
}
|
|
316
316
|
function Qe(n, e) {
|
|
@@ -375,7 +375,7 @@ class nt {
|
|
|
375
375
|
* @private
|
|
376
376
|
*/
|
|
377
377
|
build() {
|
|
378
|
-
const e =
|
|
378
|
+
const e = ie(this.openAPI.paths);
|
|
379
379
|
for (const t of e)
|
|
380
380
|
this.commands(t.path, t), this.state(t.operation), this.events(t.operation), this.fields(t.operation);
|
|
381
381
|
}
|
|
@@ -424,7 +424,7 @@ class nt {
|
|
|
424
424
|
this.openAPI.components
|
|
425
425
|
);
|
|
426
426
|
d.schema.title = d.schema.title || o.summary, d.schema.description = d.schema.description || o.description;
|
|
427
|
-
const
|
|
427
|
+
const xe = {
|
|
428
428
|
name: r,
|
|
429
429
|
method: t.method,
|
|
430
430
|
path: e,
|
|
@@ -436,7 +436,7 @@ class nt {
|
|
|
436
436
|
};
|
|
437
437
|
o.tags?.forEach((u) => {
|
|
438
438
|
const z = this.aggregates.get(u);
|
|
439
|
-
z && z.commands.set(r,
|
|
439
|
+
z && z.commands.set(r, xe);
|
|
440
440
|
});
|
|
441
441
|
}
|
|
442
442
|
/**
|
|
@@ -558,13 +558,13 @@ function l(n) {
|
|
|
558
558
|
break;
|
|
559
559
|
}
|
|
560
560
|
const r = t.slice(0, o), i = r.length > 0 ? `/${r.join("/")}` : "/", s = t.slice(o);
|
|
561
|
-
return { name:
|
|
561
|
+
return { name: w(s), path: i };
|
|
562
562
|
}
|
|
563
563
|
function v(n) {
|
|
564
564
|
const e = P(n);
|
|
565
565
|
return l(e);
|
|
566
566
|
}
|
|
567
|
-
function
|
|
567
|
+
function N(n) {
|
|
568
568
|
return `${ee(n)}_BOUNDED_CONTEXT_ALIAS`;
|
|
569
569
|
}
|
|
570
570
|
class rt {
|
|
@@ -577,7 +577,7 @@ class rt {
|
|
|
577
577
|
}
|
|
578
578
|
process() {
|
|
579
579
|
const { schema: e } = this.keySchema;
|
|
580
|
-
return U(e) ? this.processEnum(e) : T(e) ? this.processInterface(e) :
|
|
580
|
+
return U(e) ? this.processEnum(e) : T(e) ? this.processInterface(e) : R(e) ? this.processArray(e) : q(e) ? this.processIntersection(e) : J(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
581
581
|
}
|
|
582
582
|
resolveReference(e) {
|
|
583
583
|
const t = v(e);
|
|
@@ -594,9 +594,9 @@ class rt {
|
|
|
594
594
|
resolvePropertyDefinitions(e) {
|
|
595
595
|
const { properties: t } = e;
|
|
596
596
|
return Object.entries(t).map(([o, r]) => {
|
|
597
|
-
const i = this.resolveType(r), s =
|
|
597
|
+
const i = this.resolveType(r), s = b(o);
|
|
598
598
|
if (!p(r)) {
|
|
599
|
-
const a = k(r), c =
|
|
599
|
+
const a = k(r), c = le(a, `
|
|
600
600
|
* `);
|
|
601
601
|
if (c)
|
|
602
602
|
return `
|
|
@@ -627,7 +627,7 @@ class rt {
|
|
|
627
627
|
resolveType(e) {
|
|
628
628
|
if (p(e))
|
|
629
629
|
return this.resolveReference(e).name;
|
|
630
|
-
if (
|
|
630
|
+
if (re(e))
|
|
631
631
|
return `Record<string,${this.resolveMapValueType(e)}>`;
|
|
632
632
|
if (e.const)
|
|
633
633
|
return `'${e.const}'`;
|
|
@@ -637,24 +637,24 @@ class rt {
|
|
|
637
637
|
const o = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r = q(e) ? " & " : " | ";
|
|
638
638
|
return `(${o.join(r)})`;
|
|
639
639
|
}
|
|
640
|
-
if (
|
|
640
|
+
if (R(e)) {
|
|
641
641
|
const t = this.resolveType(e.items);
|
|
642
|
-
return
|
|
642
|
+
return oe(t);
|
|
643
643
|
}
|
|
644
|
-
return e.type === "object" ? this.resolveObjectType(e) : e.type ?
|
|
644
|
+
return e.type === "object" ? this.resolveObjectType(e) : e.type ? D(e.type) : "any";
|
|
645
645
|
}
|
|
646
646
|
processEnum(e) {
|
|
647
647
|
return this.sourceFile.addEnum({
|
|
648
648
|
name: this.modelInfo.name,
|
|
649
649
|
isExported: !0,
|
|
650
650
|
members: e.enum.filter((t) => typeof t == "string" && t.length > 0).map((t) => ({
|
|
651
|
-
name:
|
|
651
|
+
name: Ee(t),
|
|
652
652
|
initializer: `\`${t}\``
|
|
653
653
|
}))
|
|
654
654
|
});
|
|
655
655
|
}
|
|
656
656
|
addPropertyToInterface(e, t, o) {
|
|
657
|
-
const r = this.resolveType(o), i =
|
|
657
|
+
const r = this.resolveType(o), i = b(t);
|
|
658
658
|
let s = e.getProperty(i);
|
|
659
659
|
s ? s.setType(r) : s = e.addProperty({
|
|
660
660
|
name: i,
|
|
@@ -789,7 +789,7 @@ class it {
|
|
|
789
789
|
this.generateBoundedContext(t);
|
|
790
790
|
for (const r of o)
|
|
791
791
|
this.aggregatedSchemaSuffix.forEach((i) => {
|
|
792
|
-
const s = l(r.state.key), a =
|
|
792
|
+
const s = l(r.state.key), a = w(s.name) + i;
|
|
793
793
|
e.add(a);
|
|
794
794
|
});
|
|
795
795
|
}
|
|
@@ -819,7 +819,7 @@ class it {
|
|
|
819
819
|
generateBoundedContext(e) {
|
|
820
820
|
const t = `${e}/boundedContext.ts`;
|
|
821
821
|
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
822
|
-
const o = this.context.getOrCreateSourceFile(t), r =
|
|
822
|
+
const o = this.context.getOrCreateSourceFile(t), r = N(e);
|
|
823
823
|
o.addStatements(`export const ${r} = '${e}';`);
|
|
824
824
|
}
|
|
825
825
|
}
|
|
@@ -852,7 +852,7 @@ const st = "@ahoo-wang/fetcher", at = [
|
|
|
852
852
|
function ut(n) {
|
|
853
853
|
A(n, st, at);
|
|
854
854
|
}
|
|
855
|
-
function
|
|
855
|
+
function de(n) {
|
|
856
856
|
A(n, ct, pt);
|
|
857
857
|
}
|
|
858
858
|
function j(n, e, t = [], o = [], r) {
|
|
@@ -869,14 +869,14 @@ function j(n, e, t = [], o = [], r) {
|
|
|
869
869
|
]
|
|
870
870
|
});
|
|
871
871
|
}
|
|
872
|
-
function
|
|
872
|
+
function fe(n, e) {
|
|
873
873
|
n.addImplements("ApiMetadataCapable"), n.addConstructor({
|
|
874
874
|
parameters: [
|
|
875
875
|
{
|
|
876
876
|
name: "apiMetadata",
|
|
877
877
|
type: "ApiMetadata",
|
|
878
878
|
hasQuestionToken: e === void 0,
|
|
879
|
-
scope:
|
|
879
|
+
scope: Ae.Public,
|
|
880
880
|
isReadonly: !0,
|
|
881
881
|
initializer: e
|
|
882
882
|
}
|
|
@@ -884,7 +884,7 @@ function me(n, e) {
|
|
|
884
884
|
});
|
|
885
885
|
}
|
|
886
886
|
const lt = "@ahoo-wang/fetcher-eventstream";
|
|
887
|
-
function
|
|
887
|
+
function he(n) {
|
|
888
888
|
A(n, lt, [
|
|
889
889
|
"JsonEventStreamResultExtractor",
|
|
890
890
|
"type JsonServerSentEventStream"
|
|
@@ -896,12 +896,12 @@ function mt(n) {
|
|
|
896
896
|
o.path.startsWith(L.TENANT) && (e += 1), o.path.startsWith(L.OWNER) && (t += 1);
|
|
897
897
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
898
898
|
}
|
|
899
|
-
function
|
|
899
|
+
function ye(n, e, t, o) {
|
|
900
900
|
const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
|
|
901
|
-
return
|
|
901
|
+
return ue(n, e, r);
|
|
902
902
|
}
|
|
903
903
|
function y(n, e) {
|
|
904
|
-
return `${
|
|
904
|
+
return `${w(n.aggregateName)}${e}`;
|
|
905
905
|
}
|
|
906
906
|
function _(n) {
|
|
907
907
|
return n === "delete" ? "del" : n;
|
|
@@ -913,7 +913,7 @@ function ft(n, e) {
|
|
|
913
913
|
return t;
|
|
914
914
|
if (!n.operationId)
|
|
915
915
|
return;
|
|
916
|
-
const o =
|
|
916
|
+
const o = M(n.operationId);
|
|
917
917
|
for (let r = o.length - 1; r >= 0; r--) {
|
|
918
918
|
const i = f(o.slice(r));
|
|
919
919
|
if (!e(i))
|
|
@@ -927,7 +927,7 @@ class ht {
|
|
|
927
927
|
* @param context - The generation context containing OpenAPI spec and configuration
|
|
928
928
|
*/
|
|
929
929
|
constructor(e) {
|
|
930
|
-
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${
|
|
930
|
+
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${N(this.context.currentContextAlias)}}` : void 0;
|
|
931
931
|
}
|
|
932
932
|
defaultParameterRequestType = "ParameterRequest";
|
|
933
933
|
defaultReturnType = gt;
|
|
@@ -987,12 +987,12 @@ class ht {
|
|
|
987
987
|
`Generating API client class: ${o.name}ApiClient with ${t.size} operations`
|
|
988
988
|
);
|
|
989
989
|
const r = this.createApiClientFile(o);
|
|
990
|
-
ut(r),
|
|
990
|
+
ut(r), de(r), he(r);
|
|
991
991
|
const i = j(
|
|
992
992
|
o.name + "ApiClient",
|
|
993
993
|
r
|
|
994
994
|
);
|
|
995
|
-
C(i, [e.description]),
|
|
995
|
+
C(i, [e.description]), fe(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
996
996
|
`Processing ${t.size} operations for ${o.name}ApiClient`
|
|
997
997
|
), t.forEach((s) => {
|
|
998
998
|
this.processOperation(e, r, i, s);
|
|
@@ -1075,7 +1075,7 @@ class ht {
|
|
|
1075
1075
|
`Found ${r.length} path parameters for operation ${o.operationId}`
|
|
1076
1076
|
);
|
|
1077
1077
|
const i = r.map((a) => {
|
|
1078
|
-
const c =
|
|
1078
|
+
const c = ae(a);
|
|
1079
1079
|
return this.context.logger.info(
|
|
1080
1080
|
`Adding path parameter: ${a.name} (type: ${c})`
|
|
1081
1081
|
), {
|
|
@@ -1114,6 +1114,21 @@ class ht {
|
|
|
1114
1114
|
]
|
|
1115
1115
|
}), i;
|
|
1116
1116
|
}
|
|
1117
|
+
resolveType(e, t) {
|
|
1118
|
+
if (p(t)) {
|
|
1119
|
+
const o = v(t);
|
|
1120
|
+
return m(e, this.context.outputDir, o), o.name;
|
|
1121
|
+
}
|
|
1122
|
+
if (R(t)) {
|
|
1123
|
+
const o = this.resolveType(e, t.items);
|
|
1124
|
+
return oe(o);
|
|
1125
|
+
}
|
|
1126
|
+
if (re(t)) {
|
|
1127
|
+
const o = t.additionalProperties;
|
|
1128
|
+
return typeof o == "boolean" ? "Record<string, any>" : `Record<string, ${this.resolveType(e, o)}>`;
|
|
1129
|
+
}
|
|
1130
|
+
return t.type && ne(t.type) ? D(t.type) : "any";
|
|
1131
|
+
}
|
|
1117
1132
|
/**
|
|
1118
1133
|
* Resolves the return type for a schema.
|
|
1119
1134
|
* @param sourceFile - The source file to add imports to
|
|
@@ -1121,26 +1136,7 @@ class ht {
|
|
|
1121
1136
|
* @returns The resolved return type string
|
|
1122
1137
|
*/
|
|
1123
1138
|
resolveSchemaReturnType(e, t) {
|
|
1124
|
-
|
|
1125
|
-
if (p(t)) {
|
|
1126
|
-
const r = v(t);
|
|
1127
|
-
this.context.logger.info(
|
|
1128
|
-
`Adding import for response model: ${r.name} from ${r.path}`
|
|
1129
|
-
), m(e, this.context.outputDir, r);
|
|
1130
|
-
const i = `Promise<${r.name}>`;
|
|
1131
|
-
return this.context.logger.info(`Resolved reference return type: ${i}`), i;
|
|
1132
|
-
}
|
|
1133
|
-
if (!t.type)
|
|
1134
|
-
return this.context.logger.info(
|
|
1135
|
-
`Schema has no type, using default return type: ${o}`
|
|
1136
|
-
), o;
|
|
1137
|
-
if (ne(t.type)) {
|
|
1138
|
-
const i = `Promise<${w(t.type)}>`;
|
|
1139
|
-
return this.context.logger.info(`Resolved primitive return type: ${i}`), i;
|
|
1140
|
-
}
|
|
1141
|
-
return this.context.logger.info(
|
|
1142
|
-
`Using default return type: ${o}`
|
|
1143
|
-
), o;
|
|
1139
|
+
return `Promise<${this.resolveType(e, t)}>`;
|
|
1144
1140
|
}
|
|
1145
1141
|
/**
|
|
1146
1142
|
* Resolves the return type for an operation based on its responses.
|
|
@@ -1154,7 +1150,7 @@ class ht {
|
|
|
1154
1150
|
return this.context.logger.info(
|
|
1155
1151
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1156
1152
|
), this.defaultReturnType;
|
|
1157
|
-
const r = te(o) ||
|
|
1153
|
+
const r = te(o) || Re(o);
|
|
1158
1154
|
if (r) {
|
|
1159
1155
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1160
1156
|
return this.context.logger.info(
|
|
@@ -1164,14 +1160,14 @@ class ht {
|
|
|
1164
1160
|
metadata: s === H.type ? H.metadata : void 0
|
|
1165
1161
|
};
|
|
1166
1162
|
}
|
|
1167
|
-
const i =
|
|
1163
|
+
const i = Se(o);
|
|
1168
1164
|
if (i) {
|
|
1169
1165
|
if (p(i)) {
|
|
1170
1166
|
const a = S(
|
|
1171
1167
|
i,
|
|
1172
1168
|
this.context.openAPI.components
|
|
1173
1169
|
);
|
|
1174
|
-
if (
|
|
1170
|
+
if (R(a) && p(a.items)) {
|
|
1175
1171
|
const c = v(a.items);
|
|
1176
1172
|
this.context.logger.info(
|
|
1177
1173
|
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
@@ -1244,7 +1240,7 @@ class ht {
|
|
|
1244
1240
|
*/
|
|
1245
1241
|
groupOperations(e) {
|
|
1246
1242
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1247
|
-
const t = /* @__PURE__ */ new Map(), o =
|
|
1243
|
+
const t = /* @__PURE__ */ new Map(), o = ie(
|
|
1248
1244
|
this.context.openAPI.paths
|
|
1249
1245
|
).filter((i) => {
|
|
1250
1246
|
if (!i.operation.operationId)
|
|
@@ -1275,7 +1271,7 @@ class ht {
|
|
|
1275
1271
|
);
|
|
1276
1272
|
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1277
1273
|
for (const r of Object.values(this.context.openAPI.paths))
|
|
1278
|
-
|
|
1274
|
+
se(r).forEach((i) => {
|
|
1279
1275
|
i.operation.tags?.forEach((s) => {
|
|
1280
1276
|
!this.shouldIgnoreTag(s) && !e.has(s) && e.set(s, {
|
|
1281
1277
|
name: s,
|
|
@@ -1339,7 +1335,7 @@ class yt {
|
|
|
1339
1335
|
this.context.logger.info(
|
|
1340
1336
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1341
1337
|
);
|
|
1342
|
-
const t =
|
|
1338
|
+
const t = ye(
|
|
1343
1339
|
this.context.project,
|
|
1344
1340
|
this.context.outputDir,
|
|
1345
1341
|
e.aggregate,
|
|
@@ -1355,13 +1351,13 @@ class yt {
|
|
|
1355
1351
|
this.processCommandTypes(t, e), this.context.logger.info(
|
|
1356
1352
|
`Creating default command client options: ${this.defaultCommandClientOptionsName}`
|
|
1357
1353
|
), t.addVariableStatement({
|
|
1358
|
-
declarationKind:
|
|
1354
|
+
declarationKind: O.Const,
|
|
1359
1355
|
declarations: [
|
|
1360
1356
|
{
|
|
1361
1357
|
name: this.defaultCommandClientOptionsName,
|
|
1362
1358
|
type: "ApiMetadata",
|
|
1363
1359
|
initializer: `{
|
|
1364
|
-
basePath: ${
|
|
1360
|
+
basePath: ${N(e.aggregate.contextAlias)}
|
|
1365
1361
|
}`
|
|
1366
1362
|
}
|
|
1367
1363
|
],
|
|
@@ -1381,11 +1377,11 @@ class yt {
|
|
|
1381
1377
|
isTypeOnly: !0
|
|
1382
1378
|
}), this.context.logger.info(
|
|
1383
1379
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1384
|
-
),
|
|
1380
|
+
), he(t), this.context.logger.info(
|
|
1385
1381
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1386
1382
|
), A(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1387
1383
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1388
|
-
),
|
|
1384
|
+
), de(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(
|
|
1389
1385
|
t,
|
|
1390
1386
|
e,
|
|
1391
1387
|
o
|
|
@@ -1453,7 +1449,7 @@ class yt {
|
|
|
1453
1449
|
[],
|
|
1454
1450
|
["R = CommandResult"]
|
|
1455
1451
|
);
|
|
1456
|
-
|
|
1452
|
+
fe(i, this.defaultCommandClientOptionsName), t.commands.forEach((s) => {
|
|
1457
1453
|
this.processCommandMethod(
|
|
1458
1454
|
t,
|
|
1459
1455
|
i,
|
|
@@ -1496,7 +1492,7 @@ class yt {
|
|
|
1496
1492
|
e.name,
|
|
1497
1493
|
s.name
|
|
1498
1494
|
)).map((s) => {
|
|
1499
|
-
const a =
|
|
1495
|
+
const a = ae(s);
|
|
1500
1496
|
return this.context.logger.info(
|
|
1501
1497
|
`Adding path parameter: ${s.name} (type: ${a})`
|
|
1502
1498
|
), {
|
|
@@ -1610,7 +1606,7 @@ class xt {
|
|
|
1610
1606
|
* @returns The source file for the client
|
|
1611
1607
|
*/
|
|
1612
1608
|
createClientFilePath(e, t) {
|
|
1613
|
-
return
|
|
1609
|
+
return ye(
|
|
1614
1610
|
this.context.project,
|
|
1615
1611
|
this.context.outputDir,
|
|
1616
1612
|
e,
|
|
@@ -1642,13 +1638,13 @@ class xt {
|
|
|
1642
1638
|
this.context.logger.info(
|
|
1643
1639
|
`Creating default query client options: ${o}`
|
|
1644
1640
|
), t.addVariableStatement({
|
|
1645
|
-
declarationKind:
|
|
1641
|
+
declarationKind: O.Const,
|
|
1646
1642
|
declarations: [
|
|
1647
1643
|
{
|
|
1648
1644
|
name: o,
|
|
1649
1645
|
type: "QueryClientOptions",
|
|
1650
1646
|
initializer: `{
|
|
1651
|
-
contextAlias: ${
|
|
1647
|
+
contextAlias: ${N(e.aggregate.contextAlias)},
|
|
1652
1648
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1653
1649
|
resourceAttribution: ${mt(e)},
|
|
1654
1650
|
}`
|
|
@@ -1667,7 +1663,7 @@ class xt {
|
|
|
1667
1663
|
), m(t, this.context.outputDir, a), this.context.logger.info(
|
|
1668
1664
|
`Creating query client factory: ${i}`
|
|
1669
1665
|
), t.addVariableStatement({
|
|
1670
|
-
declarationKind:
|
|
1666
|
+
declarationKind: O.Const,
|
|
1671
1667
|
declarations: [
|
|
1672
1668
|
{
|
|
1673
1669
|
name: i,
|
|
@@ -1768,7 +1764,7 @@ class Ct {
|
|
|
1768
1764
|
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"];
|
|
1769
1765
|
}
|
|
1770
1766
|
getOrCreateSourceFile(e) {
|
|
1771
|
-
return
|
|
1767
|
+
return ue(this.project, this.outputDir, e);
|
|
1772
1768
|
}
|
|
1773
1769
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1774
1770
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1786,7 +1782,7 @@ class Rt {
|
|
|
1786
1782
|
* @throws Error if the project initialization fails due to invalid TypeScript configuration or missing files.
|
|
1787
1783
|
*/
|
|
1788
1784
|
constructor(e) {
|
|
1789
|
-
this.options = e, this.project = new
|
|
1785
|
+
this.options = e, this.project = new Ce(e), this.options.logger.info(
|
|
1790
1786
|
`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`
|
|
1791
1787
|
);
|
|
1792
1788
|
}
|