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