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