@ahoo-wang/fetcher-generator 3.0.9 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/commandClientGenerator.d.ts +5 -1
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +452 -428
- package/dist/index.js.map +1 -1
- package/dist/utils/schemas.d.ts +1 -0
- package/dist/utils/schemas.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { Scope as he, VariableDeclarationKind as
|
|
2
|
-
import { ContentTypeValues as
|
|
1
|
+
import { Scope as he, VariableDeclarationKind as D, Project as ye } from "ts-morph";
|
|
2
|
+
import { ContentTypeValues as v, combineURLs as I } from "@ahoo-wang/fetcher";
|
|
3
3
|
import { ResourceAttributionPathSpec as k } from "@ahoo-wang/fetcher-wow";
|
|
4
4
|
import { parse as H } from "yaml";
|
|
5
5
|
import { readFile as xe } from "fs";
|
|
6
6
|
import { join as Ae, relative as Ce } from "path";
|
|
7
|
-
function C(
|
|
8
|
-
return
|
|
7
|
+
function C(o) {
|
|
8
|
+
return o.$ref.split("/").pop();
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const t = C(
|
|
10
|
+
function E(o, e) {
|
|
11
|
+
const t = C(o);
|
|
12
12
|
return e.schemas?.[t];
|
|
13
13
|
}
|
|
14
|
-
function K(
|
|
15
|
-
const t = C(
|
|
14
|
+
function K(o, e) {
|
|
15
|
+
const t = C(o);
|
|
16
16
|
return e.requestBodies?.[t];
|
|
17
17
|
}
|
|
18
|
-
function Y(
|
|
19
|
-
const t = C(
|
|
18
|
+
function Y(o, e) {
|
|
19
|
+
const t = C(o);
|
|
20
20
|
return e.parameters?.[t];
|
|
21
21
|
}
|
|
22
|
-
function P(
|
|
22
|
+
function P(o, e) {
|
|
23
23
|
return {
|
|
24
|
-
key: C(
|
|
25
|
-
schema:
|
|
24
|
+
key: C(o),
|
|
25
|
+
schema: E(o, e)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
const Pe = /[-_\s.]+/;
|
|
29
|
-
function N(
|
|
30
|
-
return
|
|
29
|
+
function N(o) {
|
|
30
|
+
return o.split(Pe);
|
|
31
31
|
}
|
|
32
|
-
function X(
|
|
33
|
-
return Array.isArray(
|
|
32
|
+
function X(o) {
|
|
33
|
+
return Array.isArray(o) ? o.flatMap((e) => z(N(e))) : z(N(o));
|
|
34
34
|
}
|
|
35
|
-
function z(
|
|
36
|
-
return
|
|
35
|
+
function z(o) {
|
|
36
|
+
return o.flatMap((e) => {
|
|
37
37
|
if (e.length === 0)
|
|
38
38
|
return [];
|
|
39
39
|
const t = [];
|
|
40
|
-
let
|
|
40
|
+
let n = "";
|
|
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 && n ? (t.push(n), n = i) : n += i;
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return n && t.push(n), t;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
return
|
|
50
|
-
const
|
|
51
|
-
return (/[a-zA-Z]/.test(
|
|
48
|
+
function R(o) {
|
|
49
|
+
return o === "" || o.length === 0 ? "" : X(o).filter((t) => t.length > 0).map((t) => {
|
|
50
|
+
const n = t.charAt(0), r = t.slice(1);
|
|
51
|
+
return (/[a-zA-Z]/.test(n) ? n.toUpperCase() : n) + r.toLowerCase();
|
|
52
52
|
}).join("");
|
|
53
53
|
}
|
|
54
|
-
function f(
|
|
55
|
-
const e =
|
|
54
|
+
function f(o) {
|
|
55
|
+
const e = R(o);
|
|
56
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
57
|
}
|
|
58
|
-
function Z(
|
|
59
|
-
return
|
|
58
|
+
function Z(o) {
|
|
59
|
+
return o === "" || Array.isArray(o) && o.length === 0 ? "" : X(o).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
60
|
}
|
|
61
|
-
function g(
|
|
62
|
-
return !!(
|
|
61
|
+
function g(o) {
|
|
62
|
+
return !!(o && typeof o == "object" && "$ref" in o);
|
|
63
63
|
}
|
|
64
|
-
function G(
|
|
64
|
+
function G(o, e) {
|
|
65
65
|
if (e && !g(e) && e.content)
|
|
66
|
-
return e.content[
|
|
66
|
+
return e.content[o]?.schema;
|
|
67
67
|
}
|
|
68
|
-
function ee(
|
|
69
|
-
return G(
|
|
68
|
+
function ee(o) {
|
|
69
|
+
return G(v.APPLICATION_JSON, o);
|
|
70
70
|
}
|
|
71
|
-
function $e(
|
|
72
|
-
return G(
|
|
71
|
+
function $e(o) {
|
|
72
|
+
return G(v.TEXT_EVENT_STREAM, o);
|
|
73
73
|
}
|
|
74
|
-
function Te(
|
|
75
|
-
return G("*/*",
|
|
74
|
+
function Te(o) {
|
|
75
|
+
return G("*/*", o);
|
|
76
76
|
}
|
|
77
77
|
const ve = [
|
|
78
78
|
"string",
|
|
@@ -81,46 +81,46 @@ const ve = [
|
|
|
81
81
|
"boolean",
|
|
82
82
|
"null"
|
|
83
83
|
];
|
|
84
|
-
function te(
|
|
85
|
-
return Array.isArray(
|
|
84
|
+
function te(o) {
|
|
85
|
+
return Array.isArray(o) ? !0 : ve.includes(o);
|
|
86
86
|
}
|
|
87
|
-
function L(
|
|
88
|
-
return Array.isArray(
|
|
87
|
+
function L(o) {
|
|
88
|
+
return Array.isArray(o.enum) && o.enum.length > 0;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
return
|
|
90
|
+
function $(o) {
|
|
91
|
+
return o.type === "object" && !!o.properties;
|
|
92
92
|
}
|
|
93
|
-
function M(
|
|
94
|
-
return
|
|
93
|
+
function M(o) {
|
|
94
|
+
return o.type === "array" && !!o.items;
|
|
95
95
|
}
|
|
96
|
-
function Ie(
|
|
97
|
-
return Array.isArray(
|
|
96
|
+
function Ie(o) {
|
|
97
|
+
return Array.isArray(o.anyOf) && o.anyOf.length > 0;
|
|
98
98
|
}
|
|
99
|
-
function Ee(
|
|
100
|
-
return Array.isArray(
|
|
99
|
+
function Ee(o) {
|
|
100
|
+
return Array.isArray(o.oneOf) && o.oneOf.length > 0;
|
|
101
101
|
}
|
|
102
|
-
function b(
|
|
103
|
-
return Array.isArray(
|
|
102
|
+
function b(o) {
|
|
103
|
+
return Array.isArray(o.allOf) && o.allOf.length > 0;
|
|
104
104
|
}
|
|
105
|
-
function B(
|
|
106
|
-
return Ie(
|
|
105
|
+
function B(o) {
|
|
106
|
+
return Ie(o) || Ee(o) || b(o);
|
|
107
107
|
}
|
|
108
|
-
function Se(
|
|
109
|
-
return
|
|
108
|
+
function Se(o) {
|
|
109
|
+
return o.includes("|") || o.includes("&") ? `(${o})[]` : `${o}[]`;
|
|
110
110
|
}
|
|
111
|
-
function Re(
|
|
112
|
-
return
|
|
111
|
+
function Re(o) {
|
|
112
|
+
return o.type === "object" && !o.properties && o.additionalProperties !== void 0;
|
|
113
113
|
}
|
|
114
|
-
function we(
|
|
115
|
-
return
|
|
114
|
+
function we(o) {
|
|
115
|
+
return o.type !== "object" ? !1 : o.properties ? Object.keys(o.properties).length === 0 : !0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
117
|
+
function Oe(o) {
|
|
118
|
+
return o.readOnly === !0;
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
if (Array.isArray(
|
|
122
|
-
return
|
|
123
|
-
switch (
|
|
120
|
+
function w(o) {
|
|
121
|
+
if (Array.isArray(o))
|
|
122
|
+
return o.map((e) => w(e)).join(" | ");
|
|
123
|
+
switch (o) {
|
|
124
124
|
case "string":
|
|
125
125
|
return "string";
|
|
126
126
|
case "number":
|
|
@@ -134,86 +134,92 @@ function R(n) {
|
|
|
134
134
|
return "any";
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
137
|
+
function De(o) {
|
|
138
|
+
if (!$(o))
|
|
139
|
+
return [];
|
|
140
|
+
const e = o.required || [];
|
|
141
|
+
return Object.keys(o.properties).filter((t) => !e.includes(t));
|
|
142
|
+
}
|
|
143
|
+
function Ne(o, e) {
|
|
144
|
+
return o.operation.operationId && e.operation.operationId ? o.operation.operationId.localeCompare(
|
|
139
145
|
e.operation.operationId
|
|
140
|
-
) :
|
|
146
|
+
) : o.path && e.path ? o.path.localeCompare(e.path) : o.method && e.method ? o.method.localeCompare(e.method) : 0;
|
|
141
147
|
}
|
|
142
|
-
function ne(
|
|
148
|
+
function ne(o) {
|
|
143
149
|
const e = [];
|
|
144
|
-
for (const [t,
|
|
145
|
-
oe(
|
|
150
|
+
for (const [t, n] of Object.entries(o))
|
|
151
|
+
oe(n).forEach((r) => {
|
|
146
152
|
e.push({
|
|
147
153
|
method: r.method,
|
|
148
154
|
operation: r.operation,
|
|
149
155
|
path: t
|
|
150
156
|
});
|
|
151
157
|
});
|
|
152
|
-
return e.sort(
|
|
158
|
+
return e.sort(Ne);
|
|
153
159
|
}
|
|
154
|
-
function oe(
|
|
160
|
+
function oe(o) {
|
|
155
161
|
return [
|
|
156
|
-
{ method: "get", operation:
|
|
157
|
-
{ method: "put", operation:
|
|
158
|
-
{ method: "post", operation:
|
|
159
|
-
{ method: "delete", operation:
|
|
160
|
-
{ method: "options", operation:
|
|
161
|
-
{ method: "head", operation:
|
|
162
|
-
{ method: "patch", operation:
|
|
163
|
-
{ method: "trace", operation:
|
|
162
|
+
{ method: "get", operation: o.get },
|
|
163
|
+
{ method: "put", operation: o.put },
|
|
164
|
+
{ method: "post", operation: o.post },
|
|
165
|
+
{ method: "delete", operation: o.delete },
|
|
166
|
+
{ method: "options", operation: o.options },
|
|
167
|
+
{ method: "head", operation: o.head },
|
|
168
|
+
{ method: "patch", operation: o.patch },
|
|
169
|
+
{ method: "trace", operation: o.trace }
|
|
164
170
|
].filter(({ operation: e }) => e !== void 0);
|
|
165
171
|
}
|
|
166
|
-
function _(
|
|
167
|
-
return
|
|
172
|
+
function _(o) {
|
|
173
|
+
return o.responses[200];
|
|
168
174
|
}
|
|
169
|
-
function U(
|
|
170
|
-
const e = _(
|
|
175
|
+
function U(o) {
|
|
176
|
+
const e = _(o);
|
|
171
177
|
return ee(e);
|
|
172
178
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
179
|
+
function Me(o, e) {
|
|
180
|
+
return o.parameters ? o.parameters.map((t) => g(t) ? Y(t, e) : t).filter((t) => t.in === "path") : [];
|
|
175
181
|
}
|
|
176
|
-
const
|
|
177
|
-
function re(
|
|
178
|
-
return !
|
|
182
|
+
const be = "string";
|
|
183
|
+
function re(o) {
|
|
184
|
+
return !o.schema || g(o.schema) || !o.schema.type || !te(o.schema.type) ? be : w(o.schema.type);
|
|
179
185
|
}
|
|
180
|
-
function ie(
|
|
181
|
-
return
|
|
186
|
+
function ie(o) {
|
|
187
|
+
return o.startsWith("http://") || o.startsWith("https://") ? qe(o) : Fe(o);
|
|
182
188
|
}
|
|
183
|
-
async function
|
|
184
|
-
return await (await fetch(
|
|
189
|
+
async function qe(o) {
|
|
190
|
+
return await (await fetch(o)).text();
|
|
185
191
|
}
|
|
186
|
-
function
|
|
192
|
+
function Fe(o) {
|
|
187
193
|
return new Promise((e, t) => {
|
|
188
|
-
xe(
|
|
189
|
-
|
|
194
|
+
xe(o, "utf-8", (n, r) => {
|
|
195
|
+
n ? t(n) : e(r);
|
|
190
196
|
});
|
|
191
197
|
});
|
|
192
198
|
}
|
|
193
|
-
async function
|
|
194
|
-
const e = await ie(
|
|
199
|
+
async function je(o) {
|
|
200
|
+
const e = await ie(o);
|
|
195
201
|
switch (se(e)) {
|
|
196
202
|
case "json":
|
|
197
203
|
return JSON.parse(e);
|
|
198
204
|
case "yaml":
|
|
199
205
|
return H(e);
|
|
200
206
|
default:
|
|
201
|
-
throw new Error(`Unsupported file format: ${
|
|
207
|
+
throw new Error(`Unsupported file format: ${o}`);
|
|
202
208
|
}
|
|
203
209
|
}
|
|
204
|
-
async function
|
|
205
|
-
const e = await ie(
|
|
210
|
+
async function Ge(o) {
|
|
211
|
+
const e = await ie(o);
|
|
206
212
|
switch (se(e)) {
|
|
207
213
|
case "json":
|
|
208
214
|
return JSON.parse(e);
|
|
209
215
|
case "yaml":
|
|
210
216
|
return H(e);
|
|
211
217
|
default:
|
|
212
|
-
throw new Error(`Unsupported file format: ${
|
|
218
|
+
throw new Error(`Unsupported file format: ${o}`);
|
|
213
219
|
}
|
|
214
220
|
}
|
|
215
|
-
function se(
|
|
216
|
-
const e =
|
|
221
|
+
function se(o) {
|
|
222
|
+
const e = o.trimStart();
|
|
217
223
|
if (e.startsWith("{") || e.startsWith("["))
|
|
218
224
|
return "json";
|
|
219
225
|
if (e.startsWith("-") || e.startsWith("%YAML"))
|
|
@@ -226,129 +232,129 @@ function se(n) {
|
|
|
226
232
|
}
|
|
227
233
|
throw new Error("Unable to infer file format");
|
|
228
234
|
}
|
|
229
|
-
const ae = "types.ts",
|
|
230
|
-
function
|
|
231
|
-
return
|
|
235
|
+
const ae = "types.ts", _e = "@";
|
|
236
|
+
function We(o) {
|
|
237
|
+
return I(o.path, ae);
|
|
232
238
|
}
|
|
233
|
-
function ce(
|
|
234
|
-
const
|
|
235
|
-
return r ||
|
|
239
|
+
function ce(o, e, t) {
|
|
240
|
+
const n = I(e, t), r = o.getSourceFile(n);
|
|
241
|
+
return r || o.createSourceFile(n, "", {
|
|
236
242
|
overwrite: !0
|
|
237
243
|
});
|
|
238
244
|
}
|
|
239
|
-
function x(
|
|
240
|
-
let
|
|
245
|
+
function x(o, e, t) {
|
|
246
|
+
let n = o.getImportDeclaration(
|
|
241
247
|
(r) => r.getModuleSpecifierValue() === e
|
|
242
248
|
);
|
|
243
|
-
|
|
249
|
+
n || (n = o.addImportDeclaration({
|
|
244
250
|
moduleSpecifier: e
|
|
245
251
|
})), t.forEach((r) => {
|
|
246
|
-
|
|
252
|
+
n.getNamedImports().some(
|
|
247
253
|
(s) => s.getName() === r
|
|
248
|
-
) ||
|
|
254
|
+
) || n.addNamedImport(r);
|
|
249
255
|
});
|
|
250
256
|
}
|
|
251
|
-
function
|
|
252
|
-
if (t.path.startsWith(
|
|
253
|
-
x(
|
|
257
|
+
function d(o, e, t) {
|
|
258
|
+
if (t.path.startsWith(_e)) {
|
|
259
|
+
x(o, t.path, [t.name]);
|
|
254
260
|
return;
|
|
255
261
|
}
|
|
256
|
-
const
|
|
257
|
-
let i = Ce(
|
|
258
|
-
i = i.replace(/\.ts$/, ""), i.startsWith(".") || (i = "./" + i), x(
|
|
262
|
+
const n = o.getDirectoryPath(), r = Ae(e, t.path, ae);
|
|
263
|
+
let i = Ce(n, r);
|
|
264
|
+
i = i.replace(/\.ts$/, ""), i.startsWith(".") || (i = "./" + i), x(o, i, [t.name]);
|
|
259
265
|
}
|
|
260
|
-
function
|
|
261
|
-
|
|
266
|
+
function ke(o, e, t, n) {
|
|
267
|
+
o.path !== n.path && d(e, t, n);
|
|
262
268
|
}
|
|
263
|
-
function ge(
|
|
269
|
+
function ge(o, e = `
|
|
264
270
|
`) {
|
|
265
|
-
if (!Array.isArray(
|
|
271
|
+
if (!Array.isArray(o))
|
|
266
272
|
return;
|
|
267
|
-
const t =
|
|
268
|
-
(
|
|
273
|
+
const t = o.filter(
|
|
274
|
+
(n) => typeof n == "string" && n.length > 0
|
|
269
275
|
);
|
|
270
276
|
return t.length > 0 ? t.join(e) : void 0;
|
|
271
277
|
}
|
|
272
|
-
function
|
|
278
|
+
function S(o, e) {
|
|
273
279
|
const t = ge(e);
|
|
274
|
-
t &&
|
|
280
|
+
t && o.addJsDoc(t);
|
|
275
281
|
}
|
|
276
|
-
function pe(
|
|
282
|
+
function pe(o, e) {
|
|
277
283
|
const t = [
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
o.title,
|
|
285
|
+
o.description
|
|
280
286
|
];
|
|
281
|
-
return e && t.push(`- key: ${e}`),
|
|
287
|
+
return e && t.push(`- key: ${e}`), o.format && t.push(`- format: ${o.format}`), J(t, o, "default"), J(t, o, "example"), ze(t, o), Le(t, o), Be(t, o), t;
|
|
282
288
|
}
|
|
283
|
-
function Q(
|
|
284
|
-
const
|
|
285
|
-
|
|
289
|
+
function Q(o, e, t) {
|
|
290
|
+
const n = pe(e, t);
|
|
291
|
+
S(o, n);
|
|
286
292
|
}
|
|
287
|
-
function J(
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
if (typeof
|
|
291
|
-
|
|
293
|
+
function J(o, e, t) {
|
|
294
|
+
const n = e[t];
|
|
295
|
+
if (n) {
|
|
296
|
+
if (typeof n != "object") {
|
|
297
|
+
o.push(`- ${t}: \`${n}\``);
|
|
292
298
|
return;
|
|
293
299
|
}
|
|
294
|
-
|
|
300
|
+
o.push(`- ${t}: `), o.push("```json"), o.push(JSON.stringify(n)), o.push("```");
|
|
295
301
|
}
|
|
296
302
|
}
|
|
297
|
-
function
|
|
303
|
+
function ze(o, e) {
|
|
298
304
|
const t = ["- Numeric Constraints"];
|
|
299
305
|
e.minimum !== void 0 && t.push(` - minimum: ${e.minimum}`), e.maximum !== void 0 && t.push(` - maximum: ${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(
|
|
300
306
|
` - exclusiveMinimum: ${e.exclusiveMinimum}`
|
|
301
307
|
), e.exclusiveMaximum !== void 0 && t.push(
|
|
302
308
|
` - exclusiveMaximum: ${e.exclusiveMaximum}`
|
|
303
|
-
), e.multipleOf !== void 0 && t.push(` - multipleOf: ${e.multipleOf}`), t.length !== 1 &&
|
|
309
|
+
), e.multipleOf !== void 0 && t.push(` - multipleOf: ${e.multipleOf}`), t.length !== 1 && o.push(...t);
|
|
304
310
|
}
|
|
305
|
-
function
|
|
311
|
+
function Le(o, e) {
|
|
306
312
|
const t = ["- String Constraints"];
|
|
307
|
-
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 &&
|
|
313
|
+
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);
|
|
308
314
|
}
|
|
309
|
-
function
|
|
315
|
+
function Be(o, e) {
|
|
310
316
|
const t = ["- Array Constraints"];
|
|
311
|
-
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 &&
|
|
317
|
+
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);
|
|
312
318
|
}
|
|
313
|
-
function
|
|
314
|
-
const e =
|
|
319
|
+
function Ue(o) {
|
|
320
|
+
const e = o.split(".");
|
|
315
321
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
316
322
|
}
|
|
317
|
-
function
|
|
318
|
-
const e =
|
|
323
|
+
function Qe(o) {
|
|
324
|
+
const e = Ue(o.name);
|
|
319
325
|
return e ? {
|
|
320
|
-
tag:
|
|
326
|
+
tag: o,
|
|
321
327
|
contextAlias: e[0],
|
|
322
328
|
aggregateName: e[1]
|
|
323
329
|
} : null;
|
|
324
330
|
}
|
|
325
|
-
function
|
|
326
|
-
const e =
|
|
331
|
+
function Je(o) {
|
|
332
|
+
const e = o?.map((n) => Qe(n)).filter((n) => n !== null);
|
|
327
333
|
if (!e)
|
|
328
334
|
return /* @__PURE__ */ new Map();
|
|
329
335
|
const t = /* @__PURE__ */ new Map();
|
|
330
|
-
return e.forEach((
|
|
331
|
-
t.set(
|
|
332
|
-
aggregate:
|
|
336
|
+
return e.forEach((n) => {
|
|
337
|
+
t.set(n.tag.name, {
|
|
338
|
+
aggregate: n,
|
|
333
339
|
commands: /* @__PURE__ */ new Map(),
|
|
334
340
|
events: /* @__PURE__ */ new Map()
|
|
335
341
|
});
|
|
336
342
|
}), t;
|
|
337
343
|
}
|
|
338
|
-
function
|
|
339
|
-
if (!
|
|
344
|
+
function Ve(o) {
|
|
345
|
+
if (!o)
|
|
340
346
|
return null;
|
|
341
|
-
const e =
|
|
347
|
+
const e = o.split(".");
|
|
342
348
|
return e.length != 3 ? null : e[2];
|
|
343
349
|
}
|
|
344
|
-
const
|
|
345
|
-
class
|
|
350
|
+
const He = "#/components/responses/wow.CommandOk", Ke = "#/components/parameters/wow.id";
|
|
351
|
+
class Ye {
|
|
346
352
|
/**
|
|
347
353
|
* Creates a new AggregateResolver instance.
|
|
348
354
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
349
355
|
*/
|
|
350
356
|
constructor(e) {
|
|
351
|
-
this.openAPI = e, this.aggregates =
|
|
357
|
+
this.openAPI = e, this.aggregates = Je(e.tags), this.build();
|
|
352
358
|
}
|
|
353
359
|
aggregates;
|
|
354
360
|
/**
|
|
@@ -369,9 +375,9 @@ class Ke {
|
|
|
369
375
|
for (const t of this.aggregates.values()) {
|
|
370
376
|
if (!t.state || !t.fields)
|
|
371
377
|
continue;
|
|
372
|
-
const
|
|
373
|
-
let r = e.get(
|
|
374
|
-
r || (r = /* @__PURE__ */ new Set(), e.set(
|
|
378
|
+
const n = t.aggregate.contextAlias;
|
|
379
|
+
let r = e.get(n);
|
|
380
|
+
r || (r = /* @__PURE__ */ new Set(), e.set(n, r)), r.add(t);
|
|
375
381
|
}
|
|
376
382
|
return e;
|
|
377
383
|
}
|
|
@@ -381,16 +387,16 @@ class Ke {
|
|
|
381
387
|
* @param methodOperation - The HTTP method and operation details
|
|
382
388
|
*/
|
|
383
389
|
commands(e, t) {
|
|
384
|
-
const
|
|
385
|
-
if (
|
|
390
|
+
const n = t.operation;
|
|
391
|
+
if (n.operationId === "wow.command.send")
|
|
386
392
|
return;
|
|
387
|
-
const r =
|
|
393
|
+
const r = Ve(n.operationId);
|
|
388
394
|
if (!r)
|
|
389
395
|
return;
|
|
390
|
-
const i = _(
|
|
391
|
-
if (!i || !g(i) || i.$ref !==
|
|
396
|
+
const i = _(n);
|
|
397
|
+
if (!i || !g(i) || i.$ref !== He || !n.requestBody)
|
|
392
398
|
return;
|
|
393
|
-
const s =
|
|
399
|
+
const s = n.parameters ?? [], a = s.filter((l) => g(l) && l.$ref === Ke).at(0), c = s.filter(
|
|
394
400
|
(l) => !g(l) && l.in === "path"
|
|
395
401
|
);
|
|
396
402
|
if (a) {
|
|
@@ -400,22 +406,22 @@ class Ke {
|
|
|
400
406
|
);
|
|
401
407
|
c.push(l);
|
|
402
408
|
}
|
|
403
|
-
const p =
|
|
409
|
+
const p = n.requestBody.content[v.APPLICATION_JSON].schema, y = P(
|
|
404
410
|
p,
|
|
405
411
|
this.openAPI.components
|
|
406
412
|
);
|
|
407
|
-
y.schema.title = y.schema.title ||
|
|
413
|
+
y.schema.title = y.schema.title || n.summary, y.schema.description = y.schema.description || n.description;
|
|
408
414
|
const fe = {
|
|
409
415
|
name: r,
|
|
410
416
|
method: t.method,
|
|
411
417
|
path: e,
|
|
412
418
|
pathParameters: c,
|
|
413
|
-
summary:
|
|
414
|
-
description:
|
|
419
|
+
summary: n.summary,
|
|
420
|
+
description: n.description,
|
|
415
421
|
schema: y,
|
|
416
|
-
operation:
|
|
422
|
+
operation: n
|
|
417
423
|
};
|
|
418
|
-
|
|
424
|
+
n.tags?.forEach((l) => {
|
|
419
425
|
const W = this.aggregates.get(l);
|
|
420
426
|
W && W.commands.set(r, fe);
|
|
421
427
|
});
|
|
@@ -430,13 +436,13 @@ class Ke {
|
|
|
430
436
|
const t = U(e);
|
|
431
437
|
if (!g(t))
|
|
432
438
|
return;
|
|
433
|
-
const
|
|
439
|
+
const n = P(
|
|
434
440
|
t,
|
|
435
441
|
this.openAPI.components
|
|
436
442
|
);
|
|
437
443
|
e.tags?.forEach((r) => {
|
|
438
444
|
const i = this.aggregates.get(r);
|
|
439
|
-
i && (i.state =
|
|
445
|
+
i && (i.state = n);
|
|
440
446
|
});
|
|
441
447
|
}
|
|
442
448
|
/**
|
|
@@ -449,11 +455,11 @@ class Ke {
|
|
|
449
455
|
const t = U(e);
|
|
450
456
|
if (g(t))
|
|
451
457
|
return;
|
|
452
|
-
const
|
|
453
|
-
if (!g(
|
|
458
|
+
const n = t?.items;
|
|
459
|
+
if (!g(n))
|
|
454
460
|
return;
|
|
455
|
-
const i =
|
|
456
|
-
|
|
461
|
+
const i = E(
|
|
462
|
+
n,
|
|
457
463
|
this.openAPI.components
|
|
458
464
|
).properties.body.items.anyOf.map((s) => {
|
|
459
465
|
const a = s.title, c = s.properties.name.const, u = s.properties.body, p = P(
|
|
@@ -480,11 +486,11 @@ class Ke {
|
|
|
480
486
|
fields(e) {
|
|
481
487
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
482
488
|
return;
|
|
483
|
-
const
|
|
489
|
+
const n = K(
|
|
484
490
|
e.requestBody,
|
|
485
491
|
this.openAPI.components
|
|
486
|
-
).content[
|
|
487
|
-
|
|
492
|
+
).content[v.APPLICATION_JSON].schema, i = E(
|
|
493
|
+
n,
|
|
488
494
|
this.openAPI.components
|
|
489
495
|
).properties?.field, s = P(i, this.openAPI.components);
|
|
490
496
|
e.tags?.forEach((a) => {
|
|
@@ -493,7 +499,7 @@ class Ke {
|
|
|
493
499
|
});
|
|
494
500
|
}
|
|
495
501
|
}
|
|
496
|
-
const A = "@ahoo-wang/fetcher-wow",
|
|
502
|
+
const A = "@ahoo-wang/fetcher-wow", Xe = {
|
|
497
503
|
"wow.command.CommandResult": "CommandResult",
|
|
498
504
|
"wow.command.CommandResultArray": "CommandResultArray",
|
|
499
505
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
@@ -523,32 +529,32 @@ const A = "@ahoo-wang/fetcher-wow", Ye = {
|
|
|
523
529
|
"wow.openapi.BatchResult": "BatchResult",
|
|
524
530
|
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
525
531
|
};
|
|
526
|
-
function
|
|
527
|
-
if (!
|
|
532
|
+
function m(o) {
|
|
533
|
+
if (!o)
|
|
528
534
|
return { name: "", path: "/" };
|
|
529
|
-
const e =
|
|
535
|
+
const e = Xe[o];
|
|
530
536
|
if (e)
|
|
531
537
|
return { name: e, path: A };
|
|
532
|
-
const t =
|
|
533
|
-
let
|
|
538
|
+
const t = o.split(".");
|
|
539
|
+
let n = -1;
|
|
534
540
|
for (let c = 0; c < t.length; c++)
|
|
535
541
|
if (t[c] && /^[A-Z]/.test(t[c])) {
|
|
536
|
-
|
|
542
|
+
n = c;
|
|
537
543
|
break;
|
|
538
544
|
}
|
|
539
|
-
const r = t.slice(0,
|
|
540
|
-
return { name:
|
|
545
|
+
const r = t.slice(0, n), i = r.length > 0 ? `/${r.join("/")}` : "/", s = t.slice(n);
|
|
546
|
+
return { name: R(s), path: i };
|
|
541
547
|
}
|
|
542
|
-
function
|
|
543
|
-
const e = C(
|
|
544
|
-
return
|
|
548
|
+
function T(o) {
|
|
549
|
+
const e = C(o);
|
|
550
|
+
return m(e);
|
|
545
551
|
}
|
|
546
|
-
function
|
|
547
|
-
return `${Z(
|
|
552
|
+
function O(o) {
|
|
553
|
+
return `${Z(o)}_BOUNDED_CONTEXT_ALIAS`;
|
|
548
554
|
}
|
|
549
|
-
class
|
|
550
|
-
constructor(e, t,
|
|
551
|
-
this.modelInfo = e, this.sourceFile = t, this.keySchema =
|
|
555
|
+
class Ze {
|
|
556
|
+
constructor(e, t, n, r) {
|
|
557
|
+
this.modelInfo = e, this.sourceFile = t, this.keySchema = n, this.outputDir = r;
|
|
552
558
|
}
|
|
553
559
|
generate() {
|
|
554
560
|
const e = this.process();
|
|
@@ -556,11 +562,11 @@ class Xe {
|
|
|
556
562
|
}
|
|
557
563
|
process() {
|
|
558
564
|
const { schema: e } = this.keySchema;
|
|
559
|
-
return L(e) ? this.processEnum(e) :
|
|
565
|
+
return L(e) ? this.processEnum(e) : $(e) ? this.processInterface(e) : M(e) ? this.processArray(e) : b(e) ? this.processIntersection(e) : B(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
560
566
|
}
|
|
561
567
|
resolveReference(e) {
|
|
562
|
-
const t =
|
|
563
|
-
return
|
|
568
|
+
const t = T(e);
|
|
569
|
+
return ke(
|
|
564
570
|
this.modelInfo,
|
|
565
571
|
this.sourceFile,
|
|
566
572
|
this.outputDir,
|
|
@@ -574,7 +580,7 @@ class Xe {
|
|
|
574
580
|
}
|
|
575
581
|
resolvePropertyDefinitions(e) {
|
|
576
582
|
const { properties: t } = e;
|
|
577
|
-
return Object.entries(t).map(([
|
|
583
|
+
return Object.entries(t).map(([n, r]) => {
|
|
578
584
|
const i = this.resolveType(r);
|
|
579
585
|
if (!g(r)) {
|
|
580
586
|
const s = pe(r), a = ge(s, `
|
|
@@ -584,20 +590,20 @@ class Xe {
|
|
|
584
590
|
/**
|
|
585
591
|
* ${a}
|
|
586
592
|
*/
|
|
587
|
-
${
|
|
593
|
+
${n}: ${i}
|
|
588
594
|
`;
|
|
589
595
|
}
|
|
590
|
-
return `${
|
|
596
|
+
return `${n}: ${i}`;
|
|
591
597
|
});
|
|
592
598
|
}
|
|
593
599
|
resolveObjectType(e) {
|
|
594
600
|
const t = [];
|
|
595
|
-
if (
|
|
601
|
+
if ($(e)) {
|
|
596
602
|
const r = this.resolvePropertyDefinitions(e);
|
|
597
603
|
t.push(...r);
|
|
598
604
|
}
|
|
599
|
-
const
|
|
600
|
-
return
|
|
605
|
+
const n = this.resolveAdditionalProperties(e);
|
|
606
|
+
return n && t.push(n), t.length === 0 ? "Record<string, any>" : `{
|
|
601
607
|
${t.join(`;
|
|
602
608
|
`)};
|
|
603
609
|
}`;
|
|
@@ -615,14 +621,14 @@ class Xe {
|
|
|
615
621
|
if (L(e))
|
|
616
622
|
return e.enum.map((t) => `'${t}'`).join(" | ");
|
|
617
623
|
if (B(e)) {
|
|
618
|
-
const
|
|
619
|
-
return `(${
|
|
624
|
+
const n = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r = b(e) ? " & " : " | ";
|
|
625
|
+
return `(${n.join(r)})`;
|
|
620
626
|
}
|
|
621
627
|
if (M(e)) {
|
|
622
628
|
const t = this.resolveType(e.items);
|
|
623
629
|
return Se(t);
|
|
624
630
|
}
|
|
625
|
-
return e.type === "object" ? this.resolveObjectType(e) : e.type ?
|
|
631
|
+
return e.type === "object" ? this.resolveObjectType(e) : e.type ? w(e.type) : "any";
|
|
626
632
|
}
|
|
627
633
|
processEnum(e) {
|
|
628
634
|
return this.sourceFile.addEnum({
|
|
@@ -634,21 +640,21 @@ class Xe {
|
|
|
634
640
|
}))
|
|
635
641
|
});
|
|
636
642
|
}
|
|
637
|
-
addPropertyToInterface(e, t,
|
|
638
|
-
const r = this.resolveType(
|
|
643
|
+
addPropertyToInterface(e, t, n) {
|
|
644
|
+
const r = this.resolveType(n);
|
|
639
645
|
let i = e.getProperty(t);
|
|
640
646
|
i ? i.setType(r) : i = e.addProperty({
|
|
641
647
|
name: t,
|
|
642
648
|
type: r,
|
|
643
|
-
isReadonly:
|
|
644
|
-
}), Q(i,
|
|
649
|
+
isReadonly: Oe(n)
|
|
650
|
+
}), Q(i, n);
|
|
645
651
|
}
|
|
646
652
|
processInterface(e) {
|
|
647
653
|
const t = this.sourceFile.addInterface({
|
|
648
654
|
name: this.modelInfo.name,
|
|
649
655
|
isExported: !0
|
|
650
|
-
}),
|
|
651
|
-
return Object.entries(
|
|
656
|
+
}), n = e.properties || {};
|
|
657
|
+
return Object.entries(n).forEach(([r, i]) => {
|
|
652
658
|
this.addPropertyToInterface(t, r, i);
|
|
653
659
|
}), e.additionalProperties && t.addIndexSignature({
|
|
654
660
|
keyName: "key",
|
|
@@ -678,13 +684,13 @@ class Xe {
|
|
|
678
684
|
name: this.modelInfo.name,
|
|
679
685
|
isExported: !0
|
|
680
686
|
});
|
|
681
|
-
return e.allOf.forEach((
|
|
682
|
-
if (g(
|
|
683
|
-
const r = this.resolveType(
|
|
687
|
+
return e.allOf.forEach((n) => {
|
|
688
|
+
if (g(n)) {
|
|
689
|
+
const r = this.resolveType(n);
|
|
684
690
|
t.addExtends(r);
|
|
685
691
|
return;
|
|
686
692
|
}
|
|
687
|
-
|
|
693
|
+
$(n) && Object.entries(n.properties).forEach(
|
|
688
694
|
([r, i]) => {
|
|
689
695
|
this.addPropertyToInterface(
|
|
690
696
|
t,
|
|
@@ -703,12 +709,12 @@ class Xe {
|
|
|
703
709
|
});
|
|
704
710
|
}
|
|
705
711
|
}
|
|
706
|
-
class
|
|
712
|
+
class et {
|
|
707
713
|
constructor(e) {
|
|
708
714
|
this.context = e;
|
|
709
715
|
}
|
|
710
716
|
getOrCreateSourceFile(e) {
|
|
711
|
-
const t =
|
|
717
|
+
const t = We(e);
|
|
712
718
|
return this.context.getOrCreateSourceFile(t);
|
|
713
719
|
}
|
|
714
720
|
/**
|
|
@@ -725,29 +731,29 @@ class Ze {
|
|
|
725
731
|
this.context.logger.info("No schemas found in OpenAPI specification");
|
|
726
732
|
return;
|
|
727
733
|
}
|
|
728
|
-
const t = this.stateAggregatedTypeNames(),
|
|
729
|
-
this.context.logger.progress(`Generating models for ${
|
|
734
|
+
const t = this.stateAggregatedTypeNames(), n = this.filterSchemas(e, t);
|
|
735
|
+
this.context.logger.progress(`Generating models for ${n.length} schemas`), n.forEach((r, i) => {
|
|
730
736
|
this.context.logger.progressWithCount(
|
|
731
737
|
i + 1,
|
|
732
|
-
|
|
738
|
+
n.length,
|
|
733
739
|
`Processing schema: ${r.key}`,
|
|
734
740
|
2
|
|
735
741
|
), this.generateKeyedSchema(r);
|
|
736
742
|
}), this.context.logger.success("Model generation completed");
|
|
737
743
|
}
|
|
738
744
|
filterSchemas(e, t) {
|
|
739
|
-
return Object.entries(e).map(([
|
|
740
|
-
key:
|
|
745
|
+
return Object.entries(e).map(([n, r]) => ({
|
|
746
|
+
key: n,
|
|
741
747
|
schema: r
|
|
742
|
-
})).filter((
|
|
748
|
+
})).filter((n) => !this.isWowSchema(n.key, t));
|
|
743
749
|
}
|
|
744
750
|
isWowSchema(e, t) {
|
|
745
751
|
if (e !== "wow.api.query.PagedList" && e.startsWith("wow.api.query.") && e.endsWith("PagedList"))
|
|
746
752
|
return !1;
|
|
747
753
|
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"))
|
|
748
754
|
return !0;
|
|
749
|
-
const
|
|
750
|
-
return t.has(
|
|
755
|
+
const n = m(e);
|
|
756
|
+
return t.has(n.name);
|
|
751
757
|
}
|
|
752
758
|
aggregatedSchemaSuffix = [
|
|
753
759
|
"MaterializedSnapshot",
|
|
@@ -760,12 +766,12 @@ class Ze {
|
|
|
760
766
|
];
|
|
761
767
|
stateAggregatedTypeNames() {
|
|
762
768
|
const e = /* @__PURE__ */ new Set();
|
|
763
|
-
for (const [t,
|
|
769
|
+
for (const [t, n] of this.context.contextAggregates) {
|
|
764
770
|
this.generateBoundedContext(t);
|
|
765
|
-
for (const r of
|
|
771
|
+
for (const r of n)
|
|
766
772
|
this.aggregatedSchemaSuffix.forEach(
|
|
767
773
|
(i) => {
|
|
768
|
-
const s =
|
|
774
|
+
const s = m(r.state.key), a = R(s.name) + i;
|
|
769
775
|
e.add(a);
|
|
770
776
|
}
|
|
771
777
|
);
|
|
@@ -785,19 +791,19 @@ class Ze {
|
|
|
785
791
|
* 4. Type alias processing
|
|
786
792
|
*/
|
|
787
793
|
generateKeyedSchema(e) {
|
|
788
|
-
const t =
|
|
789
|
-
new
|
|
794
|
+
const t = m(e.key), n = this.getOrCreateSourceFile(t);
|
|
795
|
+
new Ze(t, n, e, this.context.outputDir).generate();
|
|
790
796
|
}
|
|
791
797
|
generateBoundedContext(e) {
|
|
792
798
|
const t = `${e}/boundedContext.ts`;
|
|
793
799
|
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
794
|
-
const
|
|
795
|
-
|
|
800
|
+
const n = this.context.getOrCreateSourceFile(t), r = O(e);
|
|
801
|
+
n.addStatements(
|
|
796
802
|
`export const ${r} = '${e}';`
|
|
797
803
|
);
|
|
798
804
|
}
|
|
799
805
|
}
|
|
800
|
-
const
|
|
806
|
+
const tt = "@ahoo-wang/fetcher-decorator", nt = [
|
|
801
807
|
"type ApiMetadata",
|
|
802
808
|
"type ApiMetadataCapable",
|
|
803
809
|
"type ParameterRequest",
|
|
@@ -811,7 +817,7 @@ const et = "@ahoo-wang/fetcher-decorator", tt = [
|
|
|
811
817
|
"attribute",
|
|
812
818
|
"path",
|
|
813
819
|
"autoGeneratedError"
|
|
814
|
-
],
|
|
820
|
+
], ot = {
|
|
815
821
|
type: "Promise<Response>",
|
|
816
822
|
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
817
823
|
}, V = {
|
|
@@ -821,14 +827,14 @@ const et = "@ahoo-wang/fetcher-decorator", tt = [
|
|
|
821
827
|
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
822
828
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
823
829
|
}`;
|
|
824
|
-
function ue(
|
|
825
|
-
x(
|
|
830
|
+
function ue(o) {
|
|
831
|
+
x(o, tt, nt);
|
|
826
832
|
}
|
|
827
|
-
function F(
|
|
833
|
+
function F(o, e, t = [], n = [], r) {
|
|
828
834
|
return e.addClass({
|
|
829
|
-
name:
|
|
835
|
+
name: o,
|
|
830
836
|
isExported: !0,
|
|
831
|
-
typeParameters:
|
|
837
|
+
typeParameters: n,
|
|
832
838
|
extends: r,
|
|
833
839
|
decorators: [
|
|
834
840
|
{
|
|
@@ -838,8 +844,8 @@ function F(n, e, t = [], o = [], r) {
|
|
|
838
844
|
]
|
|
839
845
|
});
|
|
840
846
|
}
|
|
841
|
-
function le(
|
|
842
|
-
|
|
847
|
+
function le(o, e) {
|
|
848
|
+
o.addImplements("ApiMetadataCapable"), o.addConstructor({
|
|
843
849
|
parameters: [
|
|
844
850
|
{
|
|
845
851
|
name: "apiMetadata",
|
|
@@ -852,54 +858,54 @@ function le(n, e) {
|
|
|
852
858
|
]
|
|
853
859
|
});
|
|
854
860
|
}
|
|
855
|
-
const
|
|
856
|
-
function
|
|
857
|
-
x(
|
|
861
|
+
const rt = "@ahoo-wang/fetcher-eventstream";
|
|
862
|
+
function me(o) {
|
|
863
|
+
x(o, rt, [
|
|
858
864
|
"JsonEventStreamResultExtractor",
|
|
859
865
|
"type JsonServerSentEventStream"
|
|
860
866
|
]);
|
|
861
867
|
}
|
|
862
|
-
function
|
|
868
|
+
function it(o) {
|
|
863
869
|
let e = 0, t = 0;
|
|
864
|
-
return
|
|
865
|
-
|
|
870
|
+
return o.commands.forEach((n) => {
|
|
871
|
+
n.path.startsWith(k.TENANT) && (e += 1), n.path.startsWith(k.OWNER) && (t += 1);
|
|
866
872
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
867
873
|
}
|
|
868
|
-
function
|
|
869
|
-
const r = `${t.contextAlias}/${t.aggregateName}/${
|
|
870
|
-
return ce(
|
|
874
|
+
function de(o, e, t, n) {
|
|
875
|
+
const r = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
|
|
876
|
+
return ce(o, e, r);
|
|
871
877
|
}
|
|
872
|
-
function h(
|
|
873
|
-
return `${
|
|
878
|
+
function h(o, e) {
|
|
879
|
+
return `${R(o.aggregateName)}${e}`;
|
|
874
880
|
}
|
|
875
|
-
function j(
|
|
876
|
-
return
|
|
881
|
+
function j(o) {
|
|
882
|
+
return o === "delete" ? "del" : o;
|
|
877
883
|
}
|
|
878
|
-
const
|
|
879
|
-
function
|
|
880
|
-
const t =
|
|
884
|
+
const st = "x-fetcher-method";
|
|
885
|
+
function at(o, e) {
|
|
886
|
+
const t = o[st];
|
|
881
887
|
if (t)
|
|
882
888
|
return t;
|
|
883
|
-
if (!
|
|
889
|
+
if (!o.operationId)
|
|
884
890
|
return;
|
|
885
|
-
const
|
|
886
|
-
for (let r =
|
|
887
|
-
const i = f(
|
|
891
|
+
const n = N(o.operationId);
|
|
892
|
+
for (let r = n.length - 1; r >= 0; r--) {
|
|
893
|
+
const i = f(n.slice(r));
|
|
888
894
|
if (!e(i))
|
|
889
895
|
return i;
|
|
890
896
|
}
|
|
891
|
-
return f(
|
|
897
|
+
return f(n);
|
|
892
898
|
}
|
|
893
|
-
class
|
|
899
|
+
class ct {
|
|
894
900
|
/**
|
|
895
901
|
* Creates a new ApiClientGenerator instance.
|
|
896
902
|
* @param context - The generation context containing OpenAPI spec and configuration
|
|
897
903
|
*/
|
|
898
904
|
constructor(e) {
|
|
899
|
-
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${
|
|
905
|
+
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${O(this.context.currentContextAlias)}}` : void 0;
|
|
900
906
|
}
|
|
901
907
|
defaultParameterRequestType = "ParameterRequest";
|
|
902
|
-
defaultReturnType =
|
|
908
|
+
defaultReturnType = ot;
|
|
903
909
|
apiMetadataCtorInitializer;
|
|
904
910
|
/**
|
|
905
911
|
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
@@ -925,10 +931,10 @@ class at {
|
|
|
925
931
|
this.context.logger.info(
|
|
926
932
|
`Generating ${t.size} API client classes`
|
|
927
933
|
);
|
|
928
|
-
let
|
|
934
|
+
let n = 0;
|
|
929
935
|
for (const [r, i] of t) {
|
|
930
|
-
|
|
931
|
-
|
|
936
|
+
n++, this.context.logger.progressWithCount(
|
|
937
|
+
n,
|
|
932
938
|
t.size,
|
|
933
939
|
`Generating API client for tag: ${r}`
|
|
934
940
|
);
|
|
@@ -943,7 +949,7 @@ class at {
|
|
|
943
949
|
*/
|
|
944
950
|
createApiClientFile(e) {
|
|
945
951
|
let t = e.path;
|
|
946
|
-
return this.context.currentContextAlias && (t =
|
|
952
|
+
return this.context.currentContextAlias && (t = I(this.context.currentContextAlias, t)), t = I(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
|
|
947
953
|
}
|
|
948
954
|
/**
|
|
949
955
|
* Generates a single API client class for the given tag and operations.
|
|
@@ -951,22 +957,22 @@ class at {
|
|
|
951
957
|
* @param operations - Set of operations for this client
|
|
952
958
|
*/
|
|
953
959
|
generateApiClient(e, t) {
|
|
954
|
-
const
|
|
960
|
+
const n = m(e.name);
|
|
955
961
|
this.context.logger.info(
|
|
956
|
-
`Generating API client class: ${
|
|
962
|
+
`Generating API client class: ${n.name}ApiClient with ${t.size} operations`
|
|
957
963
|
);
|
|
958
|
-
const r = this.createApiClientFile(
|
|
959
|
-
ue(r),
|
|
964
|
+
const r = this.createApiClientFile(n);
|
|
965
|
+
ue(r), me(r);
|
|
960
966
|
const i = F(
|
|
961
|
-
|
|
967
|
+
n.name + "ApiClient",
|
|
962
968
|
r
|
|
963
969
|
);
|
|
964
|
-
|
|
965
|
-
`Processing ${t.size} operations for ${
|
|
970
|
+
S(i, [e.description]), le(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
971
|
+
`Processing ${t.size} operations for ${n.name}ApiClient`
|
|
966
972
|
), t.forEach((s) => {
|
|
967
973
|
this.processOperation(e, r, i, s);
|
|
968
974
|
}), this.context.logger.success(
|
|
969
|
-
`Completed API client: ${
|
|
975
|
+
`Completed API client: ${n.name}ApiClient`
|
|
970
976
|
);
|
|
971
977
|
}
|
|
972
978
|
/**
|
|
@@ -976,10 +982,10 @@ class at {
|
|
|
976
982
|
* @returns A unique camelCase method name
|
|
977
983
|
*/
|
|
978
984
|
getMethodName(e, t) {
|
|
979
|
-
const
|
|
980
|
-
if (!
|
|
985
|
+
const n = at(t, (r) => e.getMethod(r) !== void 0);
|
|
986
|
+
if (!n)
|
|
981
987
|
throw new Error(`Unable to resolve method name for apiClientClass:${e.getName()}.`);
|
|
982
|
-
return
|
|
988
|
+
return n;
|
|
983
989
|
}
|
|
984
990
|
/**
|
|
985
991
|
* Resolves the request type for an operation based on its request body.
|
|
@@ -992,27 +998,27 @@ class at {
|
|
|
992
998
|
return this.context.logger.info(
|
|
993
999
|
`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
994
1000
|
), this.defaultParameterRequestType;
|
|
995
|
-
let
|
|
1001
|
+
let n;
|
|
996
1002
|
if (g(t.requestBody) ? (this.context.logger.info(
|
|
997
1003
|
`Extracting request body from reference for operation: ${t.operationId}`
|
|
998
|
-
),
|
|
1004
|
+
), n = K(
|
|
999
1005
|
t.requestBody,
|
|
1000
1006
|
this.context.openAPI.components
|
|
1001
|
-
)) :
|
|
1007
|
+
)) : n = t.requestBody, !n)
|
|
1002
1008
|
return this.context.logger.info(
|
|
1003
1009
|
`Request body extraction failed for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
1004
1010
|
), this.defaultParameterRequestType;
|
|
1005
|
-
if (
|
|
1011
|
+
if (n.content["multipart/form-data"])
|
|
1006
1012
|
return this.context.logger.info(
|
|
1007
1013
|
`Detected multipart/form-data content for operation ${t.operationId}, using ParameterRequest<FormData>`
|
|
1008
1014
|
), "ParameterRequest<FormData>";
|
|
1009
|
-
if (
|
|
1010
|
-
const r =
|
|
1015
|
+
if (n.content["application/json"]) {
|
|
1016
|
+
const r = n.content["application/json"].schema;
|
|
1011
1017
|
if (g(r)) {
|
|
1012
|
-
const i =
|
|
1018
|
+
const i = T(r);
|
|
1013
1019
|
this.context.logger.info(
|
|
1014
1020
|
`Adding import for request body model: ${i.name} from ${i.path}`
|
|
1015
|
-
),
|
|
1021
|
+
), d(e, this.context.outputDir, i);
|
|
1016
1022
|
const s = `ParameterRequest<${i.name}>`;
|
|
1017
1023
|
return this.context.logger.info(
|
|
1018
1024
|
`Resolved request type for operation ${t.operationId}: ${s}`
|
|
@@ -1030,13 +1036,13 @@ class at {
|
|
|
1030
1036
|
* @param operation - The operation to resolve parameters for
|
|
1031
1037
|
* @returns Array of parameter declarations
|
|
1032
1038
|
*/
|
|
1033
|
-
resolveParameters(e, t,
|
|
1034
|
-
const r =
|
|
1039
|
+
resolveParameters(e, t, n) {
|
|
1040
|
+
const r = Me(n, this.context.openAPI.components).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
1035
1041
|
e.name,
|
|
1036
1042
|
a.name
|
|
1037
1043
|
));
|
|
1038
1044
|
this.context.logger.info(
|
|
1039
|
-
`Found ${r.length} path parameters for operation ${
|
|
1045
|
+
`Found ${r.length} path parameters for operation ${n.operationId}`
|
|
1040
1046
|
);
|
|
1041
1047
|
const i = r.map((a) => {
|
|
1042
1048
|
const c = re(a);
|
|
@@ -1053,7 +1059,7 @@ class at {
|
|
|
1053
1059
|
}
|
|
1054
1060
|
]
|
|
1055
1061
|
};
|
|
1056
|
-
}), s = this.resolveRequestType(t,
|
|
1062
|
+
}), s = this.resolveRequestType(t, n);
|
|
1057
1063
|
return this.context.logger.info(`Adding httpRequest parameter: ${s}`), i.push({
|
|
1058
1064
|
name: "httpRequest",
|
|
1059
1065
|
hasQuestionToken: s === this.defaultParameterRequestType,
|
|
@@ -1085,26 +1091,26 @@ class at {
|
|
|
1085
1091
|
* @returns The resolved return type string
|
|
1086
1092
|
*/
|
|
1087
1093
|
resolveSchemaReturnType(e, t) {
|
|
1088
|
-
const
|
|
1094
|
+
const n = "Promise<any>";
|
|
1089
1095
|
if (g(t)) {
|
|
1090
|
-
const r =
|
|
1096
|
+
const r = T(t);
|
|
1091
1097
|
this.context.logger.info(
|
|
1092
1098
|
`Adding import for response model: ${r.name} from ${r.path}`
|
|
1093
|
-
),
|
|
1099
|
+
), d(e, this.context.outputDir, r);
|
|
1094
1100
|
const i = `Promise<${r.name}>`;
|
|
1095
1101
|
return this.context.logger.info(`Resolved reference return type: ${i}`), i;
|
|
1096
1102
|
}
|
|
1097
1103
|
if (!t.type)
|
|
1098
1104
|
return this.context.logger.info(
|
|
1099
|
-
`Schema has no type, using default return type: ${
|
|
1100
|
-
),
|
|
1105
|
+
`Schema has no type, using default return type: ${n}`
|
|
1106
|
+
), n;
|
|
1101
1107
|
if (te(t.type)) {
|
|
1102
|
-
const i = `Promise<${
|
|
1108
|
+
const i = `Promise<${w(t.type)}>`;
|
|
1103
1109
|
return this.context.logger.info(`Resolved primitive return type: ${i}`), i;
|
|
1104
1110
|
}
|
|
1105
1111
|
return this.context.logger.info(
|
|
1106
|
-
`Using default return type: ${
|
|
1107
|
-
),
|
|
1112
|
+
`Using default return type: ${n}`
|
|
1113
|
+
), n;
|
|
1108
1114
|
}
|
|
1109
1115
|
/**
|
|
1110
1116
|
* Resolves the return type for an operation based on its responses.
|
|
@@ -1113,12 +1119,12 @@ class at {
|
|
|
1113
1119
|
* @returns Object containing type and optional stream flag
|
|
1114
1120
|
*/
|
|
1115
1121
|
resolveReturnType(e, t) {
|
|
1116
|
-
const
|
|
1117
|
-
if (!
|
|
1122
|
+
const n = _(t);
|
|
1123
|
+
if (!n)
|
|
1118
1124
|
return this.context.logger.info(
|
|
1119
1125
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1120
1126
|
), this.defaultReturnType;
|
|
1121
|
-
const r = ee(
|
|
1127
|
+
const r = ee(n) || Te(n);
|
|
1122
1128
|
if (r) {
|
|
1123
1129
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1124
1130
|
return this.context.logger.info(
|
|
@@ -1128,18 +1134,18 @@ class at {
|
|
|
1128
1134
|
metadata: s === V.type ? V.metadata : void 0
|
|
1129
1135
|
};
|
|
1130
1136
|
}
|
|
1131
|
-
const i = $e(
|
|
1137
|
+
const i = $e(n);
|
|
1132
1138
|
if (i) {
|
|
1133
1139
|
if (g(i)) {
|
|
1134
|
-
const a =
|
|
1140
|
+
const a = E(
|
|
1135
1141
|
i,
|
|
1136
1142
|
this.context.openAPI.components
|
|
1137
1143
|
);
|
|
1138
1144
|
if (M(a) && g(a.items)) {
|
|
1139
|
-
const c =
|
|
1145
|
+
const c = T(a.items);
|
|
1140
1146
|
this.context.logger.info(
|
|
1141
1147
|
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
1142
|
-
),
|
|
1148
|
+
), d(e, this.context.outputDir, c);
|
|
1143
1149
|
const p = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
|
|
1144
1150
|
return this.context.logger.info(
|
|
1145
1151
|
`Resolved event stream return type for operation ${t.operationId}: ${p}`
|
|
@@ -1165,11 +1171,11 @@ class at {
|
|
|
1165
1171
|
* @param apiClientClass - The client class to add the method to
|
|
1166
1172
|
* @param operation - The operation to process
|
|
1167
1173
|
*/
|
|
1168
|
-
processOperation(e, t,
|
|
1174
|
+
processOperation(e, t, n, r) {
|
|
1169
1175
|
this.context.logger.info(
|
|
1170
1176
|
`Processing operation: ${r.operation.operationId} (${r.method} ${r.path})`
|
|
1171
1177
|
);
|
|
1172
|
-
const i = this.getMethodName(
|
|
1178
|
+
const i = this.getMethodName(n, r.operation);
|
|
1173
1179
|
this.context.logger.info(`Generated method name: ${i}`);
|
|
1174
1180
|
const s = this.resolveParameters(
|
|
1175
1181
|
e,
|
|
@@ -1185,7 +1191,7 @@ class at {
|
|
|
1185
1191
|
this.context.logger.info(
|
|
1186
1192
|
`Creating method with ${s.length} parameters, return type: ${a.type}`
|
|
1187
1193
|
);
|
|
1188
|
-
const u =
|
|
1194
|
+
const u = n.addMethod({
|
|
1189
1195
|
name: i,
|
|
1190
1196
|
decorators: [c],
|
|
1191
1197
|
parameters: s,
|
|
@@ -1194,7 +1200,7 @@ class at {
|
|
|
1194
1200
|
`throw autoGeneratedError(${s.map((p) => p.name).join(",")});`
|
|
1195
1201
|
]
|
|
1196
1202
|
});
|
|
1197
|
-
|
|
1203
|
+
S(
|
|
1198
1204
|
u,
|
|
1199
1205
|
[
|
|
1200
1206
|
r.operation.summary,
|
|
@@ -1211,7 +1217,7 @@ class at {
|
|
|
1211
1217
|
*/
|
|
1212
1218
|
groupOperations(e) {
|
|
1213
1219
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1214
|
-
const t = /* @__PURE__ */ new Map(),
|
|
1220
|
+
const t = /* @__PURE__ */ new Map(), n = ne(this.context.openAPI.paths).filter(
|
|
1215
1221
|
(i) => {
|
|
1216
1222
|
if (!i.operation.operationId)
|
|
1217
1223
|
return !1;
|
|
@@ -1220,7 +1226,7 @@ class at {
|
|
|
1220
1226
|
}
|
|
1221
1227
|
);
|
|
1222
1228
|
let r = 0;
|
|
1223
|
-
for (const i of
|
|
1229
|
+
for (const i of n)
|
|
1224
1230
|
i.operation.tags.forEach((s) => {
|
|
1225
1231
|
t.has(s) || t.set(s, /* @__PURE__ */ new Set()), t.get(s).add(i), r++;
|
|
1226
1232
|
});
|
|
@@ -1250,24 +1256,24 @@ class at {
|
|
|
1250
1256
|
});
|
|
1251
1257
|
});
|
|
1252
1258
|
});
|
|
1253
|
-
let
|
|
1259
|
+
let n = 0;
|
|
1254
1260
|
return this.context.openAPI.tags?.forEach((r) => {
|
|
1255
1261
|
this.shouldIgnoreTag(r.name) ? this.context.logger.info(
|
|
1256
1262
|
`Excluded tag: ${r.name} (wow/Actuator/aggregate)`
|
|
1257
|
-
) : (e.set(r.name, r),
|
|
1263
|
+
) : (e.set(r.name, r), n++, this.context.logger.info(`Included API client tag: ${r.name}`));
|
|
1258
1264
|
}), this.context.logger.info(
|
|
1259
|
-
`Resolved ${
|
|
1265
|
+
`Resolved ${n} API client tags from ${t} total tags`
|
|
1260
1266
|
), e;
|
|
1261
1267
|
}
|
|
1262
1268
|
isAggregateTag(e) {
|
|
1263
1269
|
for (const t of this.context.contextAggregates.values())
|
|
1264
|
-
for (const
|
|
1265
|
-
if (
|
|
1270
|
+
for (const n of t)
|
|
1271
|
+
if (n.aggregate.tag.name === e)
|
|
1266
1272
|
return !0;
|
|
1267
1273
|
return !1;
|
|
1268
1274
|
}
|
|
1269
1275
|
}
|
|
1270
|
-
class
|
|
1276
|
+
class gt {
|
|
1271
1277
|
/**
|
|
1272
1278
|
* Creates a new CommandClientGenerator instance.
|
|
1273
1279
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1283,13 +1289,13 @@ class ct {
|
|
|
1283
1289
|
generate() {
|
|
1284
1290
|
const e = Array.from(
|
|
1285
1291
|
this.context.contextAggregates.values()
|
|
1286
|
-
).reduce((
|
|
1292
|
+
).reduce((n, r) => n + r.size, 0);
|
|
1287
1293
|
this.context.logger.info("--- Generating Command Clients ---"), this.context.logger.progress(
|
|
1288
1294
|
`Generating command clients for ${e} aggregates`
|
|
1289
1295
|
);
|
|
1290
1296
|
let t = 0;
|
|
1291
|
-
for (const [,
|
|
1292
|
-
|
|
1297
|
+
for (const [, n] of this.context.contextAggregates)
|
|
1298
|
+
n.forEach((r) => {
|
|
1293
1299
|
t++, this.context.logger.progressWithCount(
|
|
1294
1300
|
t,
|
|
1295
1301
|
e,
|
|
@@ -1306,7 +1312,7 @@ class ct {
|
|
|
1306
1312
|
this.context.logger.info(
|
|
1307
1313
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1308
1314
|
);
|
|
1309
|
-
const t =
|
|
1315
|
+
const t = de(
|
|
1310
1316
|
this.context.project,
|
|
1311
1317
|
this.context.outputDir,
|
|
1312
1318
|
e.aggregate,
|
|
@@ -1315,17 +1321,17 @@ class ct {
|
|
|
1315
1321
|
this.context.logger.info(
|
|
1316
1322
|
`Processing command endpoint paths for ${e.commands.size} commands`
|
|
1317
1323
|
);
|
|
1318
|
-
const
|
|
1319
|
-
this.context.logger.info(
|
|
1324
|
+
const n = this.processCommandEndpointPaths(t, e);
|
|
1325
|
+
this.processCommandTypes(t, e), this.context.logger.info(
|
|
1320
1326
|
`Creating default command client options: ${this.defaultCommandClientOptionsName}`
|
|
1321
1327
|
), t.addVariableStatement({
|
|
1322
|
-
declarationKind:
|
|
1328
|
+
declarationKind: D.Const,
|
|
1323
1329
|
declarations: [
|
|
1324
1330
|
{
|
|
1325
1331
|
name: this.defaultCommandClientOptionsName,
|
|
1326
1332
|
type: "ApiMetadata",
|
|
1327
1333
|
initializer: `{
|
|
1328
|
-
basePath: ${
|
|
1334
|
+
basePath: ${O(e.aggregate.contextAlias)}
|
|
1329
1335
|
}`
|
|
1330
1336
|
}
|
|
1331
1337
|
],
|
|
@@ -1344,11 +1350,11 @@ class ct {
|
|
|
1344
1350
|
isTypeOnly: !0
|
|
1345
1351
|
}), this.context.logger.info(
|
|
1346
1352
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1347
|
-
),
|
|
1353
|
+
), me(t), this.context.logger.info(
|
|
1348
1354
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1349
1355
|
), x(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1350
1356
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1351
|
-
), ue(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e,
|
|
1357
|
+
), ue(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e, n), this.context.logger.info("Generating stream command client class"), this.processStreamCommandClient(t, e), this.context.logger.success(
|
|
1352
1358
|
`Command client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
1353
1359
|
);
|
|
1354
1360
|
}
|
|
@@ -1356,14 +1362,14 @@ class ct {
|
|
|
1356
1362
|
return h(e, this.commandEndpointPathsSuffix);
|
|
1357
1363
|
}
|
|
1358
1364
|
processCommandEndpointPaths(e, t) {
|
|
1359
|
-
const
|
|
1365
|
+
const n = this.resolveAggregateCommandEndpointPathsName(
|
|
1360
1366
|
t.aggregate
|
|
1361
1367
|
);
|
|
1362
1368
|
this.context.logger.info(
|
|
1363
|
-
`Creating command endpoint paths enum: ${
|
|
1369
|
+
`Creating command endpoint paths enum: ${n}`
|
|
1364
1370
|
);
|
|
1365
1371
|
const r = e.addEnum({
|
|
1366
|
-
name:
|
|
1372
|
+
name: n,
|
|
1367
1373
|
isExported: !0
|
|
1368
1374
|
});
|
|
1369
1375
|
return t.commands.forEach((i) => {
|
|
@@ -1375,12 +1381,32 @@ class ct {
|
|
|
1375
1381
|
});
|
|
1376
1382
|
}), this.context.logger.success(
|
|
1377
1383
|
`Command endpoint paths enum created with ${t.commands.size} entries`
|
|
1378
|
-
),
|
|
1384
|
+
), n;
|
|
1385
|
+
}
|
|
1386
|
+
resolveCommandTypeName(e) {
|
|
1387
|
+
const t = m(e.schema.key);
|
|
1388
|
+
return [t, t.name + "Command"];
|
|
1389
|
+
}
|
|
1390
|
+
resolveCommandType(e, t) {
|
|
1391
|
+
const [n, r] = this.resolveCommandTypeName(t);
|
|
1392
|
+
d(e, this.context.outputDir, n);
|
|
1393
|
+
let i = `${n.name}`;
|
|
1394
|
+
const s = De(t.schema.schema).map((a) => `'${a}'`).join(" | ");
|
|
1395
|
+
s !== "" && (i = `PartialBy<${i},${s}>`), i = `RemoveReadonlyFields<${i}>`, e.addTypeAlias({
|
|
1396
|
+
name: r,
|
|
1397
|
+
type: `${i}`,
|
|
1398
|
+
isExported: !0
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
processCommandTypes(e, t) {
|
|
1402
|
+
t.commands.forEach((n) => {
|
|
1403
|
+
this.resolveCommandType(e, n);
|
|
1404
|
+
});
|
|
1379
1405
|
}
|
|
1380
1406
|
getEndpointPath(e, t) {
|
|
1381
1407
|
return `${e}.${t.name.toUpperCase()}`;
|
|
1382
1408
|
}
|
|
1383
|
-
processCommandClient(e, t,
|
|
1409
|
+
processCommandClient(e, t, n) {
|
|
1384
1410
|
const r = h(
|
|
1385
1411
|
t.aggregate,
|
|
1386
1412
|
"CommandClient"
|
|
@@ -1393,15 +1419,14 @@ class ct {
|
|
|
1393
1419
|
le(i, this.defaultCommandClientOptionsName), t.commands.forEach((s) => {
|
|
1394
1420
|
this.processCommandMethod(
|
|
1395
1421
|
t,
|
|
1396
|
-
e,
|
|
1397
1422
|
i,
|
|
1398
1423
|
s,
|
|
1399
|
-
|
|
1424
|
+
n
|
|
1400
1425
|
);
|
|
1401
1426
|
});
|
|
1402
1427
|
}
|
|
1403
1428
|
processStreamCommandClient(e, t) {
|
|
1404
|
-
const
|
|
1429
|
+
const n = h(
|
|
1405
1430
|
t.aggregate,
|
|
1406
1431
|
"CommandClient"
|
|
1407
1432
|
), r = h(
|
|
@@ -1413,7 +1438,7 @@ class ct {
|
|
|
1413
1438
|
e,
|
|
1414
1439
|
["''", q],
|
|
1415
1440
|
[],
|
|
1416
|
-
`${
|
|
1441
|
+
`${n}<CommandResultEventStream>`
|
|
1417
1442
|
).addConstructor({
|
|
1418
1443
|
parameters: [
|
|
1419
1444
|
{
|
|
@@ -1425,12 +1450,12 @@ class ct {
|
|
|
1425
1450
|
statements: "super(apiMetadata);"
|
|
1426
1451
|
});
|
|
1427
1452
|
}
|
|
1428
|
-
resolveParameters(e, t
|
|
1429
|
-
const r =
|
|
1453
|
+
resolveParameters(e, t) {
|
|
1454
|
+
const [n, r] = this.resolveCommandTypeName(t);
|
|
1430
1455
|
this.context.logger.info(
|
|
1431
|
-
`Adding import for command model: ${
|
|
1432
|
-
)
|
|
1433
|
-
const i =
|
|
1456
|
+
`Adding import for command model: ${n.name} from path: ${n.path}`
|
|
1457
|
+
);
|
|
1458
|
+
const i = t.pathParameters.filter((s) => !this.context.isIgnoreCommandClientPathParameters(
|
|
1434
1459
|
e.name,
|
|
1435
1460
|
s.name
|
|
1436
1461
|
)).map((s) => {
|
|
@@ -1450,11 +1475,11 @@ class ct {
|
|
|
1450
1475
|
};
|
|
1451
1476
|
});
|
|
1452
1477
|
return this.context.logger.info(
|
|
1453
|
-
`Adding command request parameter: commandRequest (type: CommandRequest<${r
|
|
1478
|
+
`Adding command request parameter: commandRequest (type: CommandRequest<${r}>)`
|
|
1454
1479
|
), i.push({
|
|
1455
1480
|
name: "commandRequest",
|
|
1456
|
-
hasQuestionToken: we(
|
|
1457
|
-
type: `CommandRequest<${r
|
|
1481
|
+
hasQuestionToken: we(t.schema.schema),
|
|
1482
|
+
type: `CommandRequest<${r}>`,
|
|
1458
1483
|
decorators: [
|
|
1459
1484
|
{
|
|
1460
1485
|
name: "request",
|
|
@@ -1475,41 +1500,40 @@ class ct {
|
|
|
1475
1500
|
]
|
|
1476
1501
|
}), i;
|
|
1477
1502
|
}
|
|
1478
|
-
processCommandMethod(e, t,
|
|
1503
|
+
processCommandMethod(e, t, n, r) {
|
|
1479
1504
|
this.context.logger.info(
|
|
1480
|
-
`Generating command method: ${f(
|
|
1505
|
+
`Generating command method: ${f(n.name)} for command: ${n.name}`
|
|
1481
1506
|
), this.context.logger.info(
|
|
1482
|
-
`Command method details: HTTP ${
|
|
1507
|
+
`Command method details: HTTP ${n.method}, path: ${n.path}`
|
|
1483
1508
|
);
|
|
1484
|
-
const
|
|
1509
|
+
const i = this.resolveParameters(
|
|
1485
1510
|
e.aggregate.tag,
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
name: f(r.name),
|
|
1511
|
+
n
|
|
1512
|
+
), s = t.addMethod({
|
|
1513
|
+
name: f(n.name),
|
|
1490
1514
|
decorators: [
|
|
1491
1515
|
{
|
|
1492
|
-
name: j(
|
|
1493
|
-
arguments: [`${this.getEndpointPath(
|
|
1516
|
+
name: j(n.method),
|
|
1517
|
+
arguments: [`${this.getEndpointPath(r, n)}`]
|
|
1494
1518
|
}
|
|
1495
1519
|
],
|
|
1496
|
-
parameters:
|
|
1520
|
+
parameters: i,
|
|
1497
1521
|
returnType: "Promise<R>",
|
|
1498
|
-
statements: `throw autoGeneratedError(${
|
|
1522
|
+
statements: `throw autoGeneratedError(${i.map((a) => a.name).join(",")});`
|
|
1499
1523
|
});
|
|
1500
1524
|
this.context.logger.info(
|
|
1501
|
-
`Adding JSDoc documentation for method: ${f(
|
|
1502
|
-
),
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
`- operationId: \`${
|
|
1506
|
-
`- path: \`${
|
|
1525
|
+
`Adding JSDoc documentation for method: ${f(n.name)}`
|
|
1526
|
+
), S(s, [
|
|
1527
|
+
n.summary,
|
|
1528
|
+
n.description,
|
|
1529
|
+
`- operationId: \`${n.operation.operationId}\``,
|
|
1530
|
+
`- path: \`${n.path}\``
|
|
1507
1531
|
]), this.context.logger.success(
|
|
1508
|
-
`Command method generated: ${f(
|
|
1532
|
+
`Command method generated: ${f(n.name)}`
|
|
1509
1533
|
);
|
|
1510
1534
|
}
|
|
1511
1535
|
}
|
|
1512
|
-
class
|
|
1536
|
+
class pt {
|
|
1513
1537
|
/**
|
|
1514
1538
|
* Creates a new QueryClientGenerator instance.
|
|
1515
1539
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1524,15 +1548,15 @@ class gt {
|
|
|
1524
1548
|
*/
|
|
1525
1549
|
generate() {
|
|
1526
1550
|
const e = Array.from(this.context.contextAggregates.values()).reduce(
|
|
1527
|
-
(
|
|
1551
|
+
(n, r) => n + r.size,
|
|
1528
1552
|
0
|
|
1529
1553
|
);
|
|
1530
1554
|
this.context.logger.info("--- Generating Query Clients ---"), this.context.logger.progress(
|
|
1531
1555
|
`Generating query clients for ${e} aggregates`
|
|
1532
1556
|
);
|
|
1533
1557
|
let t = 0;
|
|
1534
|
-
for (const [,
|
|
1535
|
-
|
|
1558
|
+
for (const [, n] of this.context.contextAggregates)
|
|
1559
|
+
n.forEach((r) => {
|
|
1536
1560
|
t++, this.context.logger.progressWithCount(
|
|
1537
1561
|
t,
|
|
1538
1562
|
e,
|
|
@@ -1548,7 +1572,7 @@ class gt {
|
|
|
1548
1572
|
* @returns The source file for the client
|
|
1549
1573
|
*/
|
|
1550
1574
|
createClientFilePath(e, t) {
|
|
1551
|
-
return
|
|
1575
|
+
return de(
|
|
1552
1576
|
this.context.project,
|
|
1553
1577
|
this.context.outputDir,
|
|
1554
1578
|
e,
|
|
@@ -1576,35 +1600,35 @@ class gt {
|
|
|
1576
1600
|
"ResourceAttributionPathSpec"
|
|
1577
1601
|
]
|
|
1578
1602
|
});
|
|
1579
|
-
const
|
|
1603
|
+
const n = "DEFAULT_QUERY_CLIENT_OPTIONS";
|
|
1580
1604
|
this.context.logger.info(
|
|
1581
|
-
`Creating default query client options: ${
|
|
1605
|
+
`Creating default query client options: ${n}`
|
|
1582
1606
|
), t.addVariableStatement({
|
|
1583
|
-
declarationKind:
|
|
1607
|
+
declarationKind: D.Const,
|
|
1584
1608
|
declarations: [
|
|
1585
1609
|
{
|
|
1586
|
-
name:
|
|
1610
|
+
name: n,
|
|
1587
1611
|
type: "QueryClientOptions",
|
|
1588
1612
|
initializer: `{
|
|
1589
|
-
contextAlias: ${
|
|
1613
|
+
contextAlias: ${O(e.aggregate.contextAlias)},
|
|
1590
1614
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1591
|
-
resourceAttribution: ${
|
|
1615
|
+
resourceAttribution: ${it(e)},
|
|
1592
1616
|
}`
|
|
1593
1617
|
}
|
|
1594
1618
|
],
|
|
1595
1619
|
isExported: !1
|
|
1596
1620
|
}), this.processAggregateDomainEventTypes(e, t);
|
|
1597
|
-
const r = this.processAggregateDomainEventType(e, t), i = `${f(e.aggregate.aggregateName)}QueryClientFactory`, s =
|
|
1621
|
+
const r = this.processAggregateDomainEventType(e, t), i = `${f(e.aggregate.aggregateName)}QueryClientFactory`, s = m(e.state.key), a = m(e.fields.key);
|
|
1598
1622
|
this.context.logger.info(
|
|
1599
1623
|
`Adding import for state model: ${s.name} from path: ${s.path}`
|
|
1600
|
-
),
|
|
1624
|
+
), d(t, this.context.outputDir, s), this.context.logger.info(
|
|
1601
1625
|
`Adding import for fields model: ${a.name} from path: ${a.path}`
|
|
1602
|
-
),
|
|
1603
|
-
declarationKind:
|
|
1626
|
+
), d(t, this.context.outputDir, a), this.context.logger.info(`Creating query client factory: ${i}`), t.addVariableStatement({
|
|
1627
|
+
declarationKind: D.Const,
|
|
1604
1628
|
declarations: [
|
|
1605
1629
|
{
|
|
1606
1630
|
name: i,
|
|
1607
|
-
initializer: `new QueryClientFactory<${s.name}, ${a.name} | string, ${r}>(${
|
|
1631
|
+
initializer: `new QueryClientFactory<${s.name}, ${a.name} | string, ${r}>(${n})`
|
|
1608
1632
|
}
|
|
1609
1633
|
],
|
|
1610
1634
|
isExported: !0
|
|
@@ -1613,17 +1637,17 @@ class gt {
|
|
|
1613
1637
|
);
|
|
1614
1638
|
}
|
|
1615
1639
|
processAggregateDomainEventType(e, t) {
|
|
1616
|
-
const
|
|
1640
|
+
const n = [];
|
|
1617
1641
|
this.context.logger.info(
|
|
1618
1642
|
`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
|
|
1619
1643
|
);
|
|
1620
1644
|
for (const s of e.events.values()) {
|
|
1621
|
-
const a =
|
|
1645
|
+
const a = m(s.schema.key);
|
|
1622
1646
|
this.context.logger.info(
|
|
1623
1647
|
`Adding import for event model: ${a.name} from path: ${a.path}`
|
|
1624
|
-
),
|
|
1648
|
+
), d(t, this.context.outputDir, a), n.push(a);
|
|
1625
1649
|
}
|
|
1626
|
-
const r = h(e.aggregate, this.domainEventTypeSuffix), i =
|
|
1650
|
+
const r = h(e.aggregate, this.domainEventTypeSuffix), i = n.map((s) => s.name).join(" | ");
|
|
1627
1651
|
return this.context.logger.info(
|
|
1628
1652
|
`Creating domain event types union: ${r} = ${i}`
|
|
1629
1653
|
), t.addTypeAlias({
|
|
@@ -1633,8 +1657,8 @@ class gt {
|
|
|
1633
1657
|
}), r;
|
|
1634
1658
|
}
|
|
1635
1659
|
processAggregateDomainEventTypes(e, t) {
|
|
1636
|
-
const
|
|
1637
|
-
name:
|
|
1660
|
+
const n = h(e.aggregate, this.domainEventTypeMapTitleSuffix), r = t.addEnum({
|
|
1661
|
+
name: n,
|
|
1638
1662
|
isExported: !0
|
|
1639
1663
|
});
|
|
1640
1664
|
for (const i of e.events.values())
|
|
@@ -1644,13 +1668,13 @@ class gt {
|
|
|
1644
1668
|
});
|
|
1645
1669
|
}
|
|
1646
1670
|
}
|
|
1647
|
-
class
|
|
1671
|
+
class ut {
|
|
1648
1672
|
/**
|
|
1649
1673
|
* Creates a new ClientGenerator instance.
|
|
1650
1674
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1651
1675
|
*/
|
|
1652
1676
|
constructor(e) {
|
|
1653
|
-
this.context = e, this.queryClientGenerator = new
|
|
1677
|
+
this.context = e, this.queryClientGenerator = new pt(e), this.commandClientGenerator = new gt(e), this.apiClientGenerator = new ct(e);
|
|
1654
1678
|
}
|
|
1655
1679
|
queryClientGenerator;
|
|
1656
1680
|
commandClientGenerator;
|
|
@@ -1673,7 +1697,7 @@ class pt {
|
|
|
1673
1697
|
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
|
|
1674
1698
|
}
|
|
1675
1699
|
}
|
|
1676
|
-
class
|
|
1700
|
+
class lt {
|
|
1677
1701
|
/** The ts-morph project instance used for code generation */
|
|
1678
1702
|
project;
|
|
1679
1703
|
/** The OpenAPI specification object */
|
|
@@ -1700,8 +1724,8 @@ class ut {
|
|
|
1700
1724
|
return this.defaultIgnorePathParameters.includes(t);
|
|
1701
1725
|
}
|
|
1702
1726
|
}
|
|
1703
|
-
const
|
|
1704
|
-
class
|
|
1727
|
+
const mt = "./fetcher-generator.config.json";
|
|
1728
|
+
class Ct {
|
|
1705
1729
|
/**
|
|
1706
1730
|
* Creates a new CodeGenerator instance with the specified options.
|
|
1707
1731
|
*
|
|
@@ -1737,28 +1761,28 @@ class At {
|
|
|
1737
1761
|
this.options.logger.info(
|
|
1738
1762
|
"Starting code generation from OpenAPI specification"
|
|
1739
1763
|
), 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");
|
|
1740
|
-
const e = await
|
|
1764
|
+
const e = await je(this.options.inputPath);
|
|
1741
1765
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1742
|
-
const
|
|
1766
|
+
const n = new Ye(e).resolve();
|
|
1743
1767
|
this.options.logger.info(
|
|
1744
|
-
`Resolved ${
|
|
1768
|
+
`Resolved ${n.size} bounded context aggregates`
|
|
1745
1769
|
);
|
|
1746
|
-
const r = this.options.configPath ??
|
|
1770
|
+
const r = this.options.configPath ?? mt;
|
|
1747
1771
|
let i = {};
|
|
1748
1772
|
try {
|
|
1749
|
-
this.options.logger.info(`Parsing configuration file: ${r}`), i = await
|
|
1773
|
+
this.options.logger.info(`Parsing configuration file: ${r}`), i = await Ge(r);
|
|
1750
1774
|
} catch (p) {
|
|
1751
1775
|
this.options.logger.info(`Configuration file parsing failed: ${p}`);
|
|
1752
1776
|
}
|
|
1753
|
-
const s = new
|
|
1777
|
+
const s = new lt({
|
|
1754
1778
|
openAPI: e,
|
|
1755
1779
|
project: this.project,
|
|
1756
1780
|
outputDir: this.options.outputDir,
|
|
1757
|
-
contextAggregates:
|
|
1781
|
+
contextAggregates: n,
|
|
1758
1782
|
logger: this.options.logger,
|
|
1759
1783
|
config: i
|
|
1760
1784
|
});
|
|
1761
|
-
this.options.logger.info("Generating models"), new
|
|
1785
|
+
this.options.logger.info("Generating models"), new et(s).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ut(s).generate(), this.options.logger.info("Clients generated successfully");
|
|
1762
1786
|
const u = this.project.getDirectory(this.options.outputDir);
|
|
1763
1787
|
if (!u) {
|
|
1764
1788
|
this.options.logger.info("Output directory not found.");
|
|
@@ -1791,8 +1815,8 @@ class At {
|
|
|
1791
1815
|
processDirectory(e) {
|
|
1792
1816
|
const t = e.getDirectories();
|
|
1793
1817
|
this.options.logger.info(`Processing ${t.length} subdirectories`);
|
|
1794
|
-
for (const
|
|
1795
|
-
this.options.logger.info(`Processing subdirectory: ${
|
|
1818
|
+
for (const n of t)
|
|
1819
|
+
this.options.logger.info(`Processing subdirectory: ${n.getPath()}`), this.generateIndexForDirectory(n), this.processDirectory(n);
|
|
1796
1820
|
}
|
|
1797
1821
|
/**
|
|
1798
1822
|
* Generates an index.ts file for a specific directory.
|
|
@@ -1804,12 +1828,12 @@ class At {
|
|
|
1804
1828
|
generateIndexForDirectory(e) {
|
|
1805
1829
|
const t = e.getPath();
|
|
1806
1830
|
this.options.logger.info(`Generating index for directory: ${t}`);
|
|
1807
|
-
const
|
|
1831
|
+
const n = e.getSourceFiles().filter(
|
|
1808
1832
|
(a) => a.getBaseName().endsWith(".ts") && a.getBaseName() !== "index.ts"
|
|
1809
1833
|
), r = e.getDirectories();
|
|
1810
1834
|
if (this.options.logger.info(
|
|
1811
|
-
`Found ${
|
|
1812
|
-
),
|
|
1835
|
+
`Found ${n.length} TypeScript files and ${r.length} subdirectories in ${t}`
|
|
1836
|
+
), n.length === 0 && r.length === 0) {
|
|
1813
1837
|
this.options.logger.info(
|
|
1814
1838
|
`No files or subdirectories to export in ${t}, skipping index generation`
|
|
1815
1839
|
);
|
|
@@ -1817,7 +1841,7 @@ class At {
|
|
|
1817
1841
|
}
|
|
1818
1842
|
const i = `${t}/index.ts`, s = this.project.getSourceFile(i) || this.project.createSourceFile(i, "", { overwrite: !0 });
|
|
1819
1843
|
s.removeText();
|
|
1820
|
-
for (const a of
|
|
1844
|
+
for (const a of n) {
|
|
1821
1845
|
const c = `./${a.getBaseNameWithoutExtension()}`;
|
|
1822
1846
|
s.addExportDeclaration({
|
|
1823
1847
|
moduleSpecifier: c,
|
|
@@ -1834,7 +1858,7 @@ class At {
|
|
|
1834
1858
|
});
|
|
1835
1859
|
}
|
|
1836
1860
|
this.options.logger.info(
|
|
1837
|
-
`Index file generated for ${t} with ${
|
|
1861
|
+
`Index file generated for ${t} with ${n.length + r.length} exports`
|
|
1838
1862
|
);
|
|
1839
1863
|
}
|
|
1840
1864
|
/**
|
|
@@ -1847,15 +1871,15 @@ class At {
|
|
|
1847
1871
|
const t = e.getDescendantSourceFiles();
|
|
1848
1872
|
this.options.logger.info(
|
|
1849
1873
|
`Optimizing ${t.length} source files in ${e.getPath()}`
|
|
1850
|
-
), t.forEach((
|
|
1874
|
+
), t.forEach((n, r) => {
|
|
1851
1875
|
this.options.logger.info(
|
|
1852
|
-
`Optimizing file [${
|
|
1853
|
-
),
|
|
1876
|
+
`Optimizing file [${n.getFilePath()}] - ${r + 1}/${t.length}`
|
|
1877
|
+
), n.formatText(), n.organizeImports(), n.fixMissingImports();
|
|
1854
1878
|
}), this.options.logger.info("All source files optimized");
|
|
1855
1879
|
}
|
|
1856
1880
|
}
|
|
1857
1881
|
export {
|
|
1858
|
-
|
|
1859
|
-
|
|
1882
|
+
Ct as CodeGenerator,
|
|
1883
|
+
mt as DEFAULT_CONFIG_PATH
|
|
1860
1884
|
};
|
|
1861
1885
|
//# sourceMappingURL=index.js.map
|