@ahoo-wang/fetcher-generator 2.3.0 → 2.3.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 +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +278 -291
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,89 +1,87 @@
|
|
|
1
|
-
import { VariableDeclarationKind as E, Scope as
|
|
2
|
-
import { parse as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function f(n) {
|
|
10
|
-
return n.$ref.split("/").pop();
|
|
1
|
+
import { VariableDeclarationKind as E, Scope as Q } from "ts-morph";
|
|
2
|
+
import { parse as L } from "yaml";
|
|
3
|
+
import { readFile as U } from "fs";
|
|
4
|
+
import { ContentTypeValues as I, combineURLs as q } from "@ahoo-wang/fetcher";
|
|
5
|
+
import { join as K, relative as J } from "path";
|
|
6
|
+
import { ResourceAttributionPathSpec as v } from "@ahoo-wang/fetcher-wow";
|
|
7
|
+
function f(o) {
|
|
8
|
+
return o.$ref.split("/").pop();
|
|
11
9
|
}
|
|
12
|
-
function
|
|
13
|
-
const t = f(
|
|
10
|
+
function S(o, e) {
|
|
11
|
+
const t = f(o);
|
|
14
12
|
return e.schemas?.[t];
|
|
15
13
|
}
|
|
16
|
-
function
|
|
17
|
-
const t = f(
|
|
14
|
+
function V(o, e) {
|
|
15
|
+
const t = f(o);
|
|
18
16
|
return e.requestBodies?.[t];
|
|
19
17
|
}
|
|
20
|
-
function
|
|
21
|
-
const t = f(
|
|
18
|
+
function H(o, e) {
|
|
19
|
+
const t = f(o);
|
|
22
20
|
return e.parameters?.[t];
|
|
23
21
|
}
|
|
24
|
-
function C(
|
|
22
|
+
function C(o, e) {
|
|
25
23
|
return {
|
|
26
|
-
key: f(
|
|
27
|
-
schema:
|
|
24
|
+
key: f(o),
|
|
25
|
+
schema: S(o, e)
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
-
return Array.isArray(
|
|
28
|
+
const b = /[-_\s.]+/;
|
|
29
|
+
function G(o) {
|
|
30
|
+
return Array.isArray(o) ? o.flatMap((e) => R(e.split(b))) : R(o.split(b));
|
|
33
31
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
32
|
+
function R(o) {
|
|
33
|
+
return o.flatMap((e) => {
|
|
36
34
|
if (e.length === 0)
|
|
37
35
|
return [];
|
|
38
36
|
const t = [];
|
|
39
|
-
let
|
|
37
|
+
let n = "";
|
|
40
38
|
for (let r = 0; r < e.length; r++) {
|
|
41
39
|
const s = e[r], i = /[A-Z]/.test(s), c = r > 0 && /[a-z]/.test(e[r - 1]);
|
|
42
|
-
i && c &&
|
|
40
|
+
i && c && n ? (t.push(n), n = s) : n += s;
|
|
43
41
|
}
|
|
44
|
-
return
|
|
42
|
+
return n && t.push(n), t;
|
|
45
43
|
});
|
|
46
44
|
}
|
|
47
|
-
function $(
|
|
48
|
-
return
|
|
45
|
+
function $(o) {
|
|
46
|
+
return o === "" || o.length === 0 ? "" : G(o).filter((t) => t.length > 0).map((t) => {
|
|
49
47
|
if (t.length === 0) return "";
|
|
50
|
-
const
|
|
51
|
-
return (/[a-zA-Z]/.test(
|
|
48
|
+
const n = t.charAt(0), r = t.slice(1);
|
|
49
|
+
return (/[a-zA-Z]/.test(n) ? n.toUpperCase() : n) + r.toLowerCase();
|
|
52
50
|
}).join("");
|
|
53
51
|
}
|
|
54
|
-
function h(
|
|
55
|
-
const e = $(
|
|
52
|
+
function h(o) {
|
|
53
|
+
const e = $(o);
|
|
56
54
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
55
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
56
|
+
function Y(o) {
|
|
57
|
+
return o === "" || Array.isArray(o) && o.length === 0 ? "" : G(o).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
58
|
}
|
|
61
|
-
function
|
|
62
|
-
return
|
|
59
|
+
function X(o) {
|
|
60
|
+
return o.startsWith("http://") || o.startsWith("https://") ? Z(o) : ee(o);
|
|
63
61
|
}
|
|
64
|
-
async function
|
|
65
|
-
return await (await fetch(
|
|
62
|
+
async function Z(o) {
|
|
63
|
+
return await (await fetch(o)).text();
|
|
66
64
|
}
|
|
67
|
-
function
|
|
65
|
+
function ee(o) {
|
|
68
66
|
return new Promise((e, t) => {
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
U(o, "utf-8", (n, r) => {
|
|
68
|
+
n ? t(n) : e(r);
|
|
71
69
|
});
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
|
-
async function
|
|
75
|
-
const e = await
|
|
76
|
-
switch (
|
|
72
|
+
async function te(o) {
|
|
73
|
+
const e = await X(o);
|
|
74
|
+
switch (ne(e)) {
|
|
77
75
|
case "json":
|
|
78
76
|
return JSON.parse(e);
|
|
79
77
|
case "yaml":
|
|
80
|
-
return
|
|
78
|
+
return L(e);
|
|
81
79
|
default:
|
|
82
|
-
throw new Error(`Unsupported file format: ${
|
|
80
|
+
throw new Error(`Unsupported file format: ${o}`);
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
|
-
function
|
|
86
|
-
const e =
|
|
83
|
+
function ne(o) {
|
|
84
|
+
const e = o.trimStart();
|
|
87
85
|
if (e.startsWith("{") || e.startsWith("["))
|
|
88
86
|
return "json";
|
|
89
87
|
if (e.startsWith("-") || e.startsWith("%YAML"))
|
|
@@ -96,72 +94,72 @@ function re(n) {
|
|
|
96
94
|
}
|
|
97
95
|
throw new Error("Unable to infer file format");
|
|
98
96
|
}
|
|
99
|
-
function g(
|
|
100
|
-
return !!(
|
|
97
|
+
function g(o) {
|
|
98
|
+
return !!(o && typeof o == "object" && "$ref" in o);
|
|
101
99
|
}
|
|
102
|
-
function
|
|
103
|
-
return !
|
|
100
|
+
function oe(o) {
|
|
101
|
+
return !o || g(o) || !o.content ? void 0 : o.content[I.APPLICATION_JSON]?.schema;
|
|
104
102
|
}
|
|
105
|
-
function
|
|
103
|
+
function re(o) {
|
|
106
104
|
return [
|
|
107
|
-
{ method: "get", operation:
|
|
108
|
-
{ method: "put", operation:
|
|
109
|
-
{ method: "post", operation:
|
|
110
|
-
{ method: "delete", operation:
|
|
111
|
-
{ method: "options", operation:
|
|
112
|
-
{ method: "head", operation:
|
|
113
|
-
{ method: "patch", operation:
|
|
114
|
-
{ method: "trace", operation:
|
|
105
|
+
{ method: "get", operation: o.get },
|
|
106
|
+
{ method: "put", operation: o.put },
|
|
107
|
+
{ method: "post", operation: o.post },
|
|
108
|
+
{ method: "delete", operation: o.delete },
|
|
109
|
+
{ method: "options", operation: o.options },
|
|
110
|
+
{ method: "head", operation: o.head },
|
|
111
|
+
{ method: "patch", operation: o.patch },
|
|
112
|
+
{ method: "trace", operation: o.trace }
|
|
115
113
|
].filter(({ operation: e }) => e !== void 0);
|
|
116
114
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
115
|
+
function F(o) {
|
|
116
|
+
return o.responses[200];
|
|
119
117
|
}
|
|
120
|
-
function
|
|
121
|
-
const e =
|
|
122
|
-
return
|
|
118
|
+
function j(o) {
|
|
119
|
+
const e = F(o);
|
|
120
|
+
return oe(e);
|
|
123
121
|
}
|
|
124
|
-
const
|
|
122
|
+
const se = [
|
|
125
123
|
"string",
|
|
126
124
|
"number",
|
|
127
125
|
"integer",
|
|
128
126
|
"boolean",
|
|
129
127
|
"null"
|
|
130
128
|
];
|
|
131
|
-
function
|
|
132
|
-
return Array.isArray(
|
|
129
|
+
function ie(o) {
|
|
130
|
+
return Array.isArray(o) ? !0 : se.includes(o);
|
|
133
131
|
}
|
|
134
|
-
function
|
|
135
|
-
return
|
|
132
|
+
function ae(o) {
|
|
133
|
+
return o.type === "array";
|
|
136
134
|
}
|
|
137
|
-
function
|
|
138
|
-
return Array.isArray(
|
|
135
|
+
function ce(o) {
|
|
136
|
+
return Array.isArray(o.enum) && o.enum.length > 0;
|
|
139
137
|
}
|
|
140
|
-
function
|
|
141
|
-
return Array.isArray(
|
|
138
|
+
function W(o) {
|
|
139
|
+
return Array.isArray(o.anyOf) && o.anyOf.length > 0;
|
|
142
140
|
}
|
|
143
|
-
function
|
|
144
|
-
return Array.isArray(
|
|
141
|
+
function _(o) {
|
|
142
|
+
return Array.isArray(o.oneOf) && o.oneOf.length > 0;
|
|
145
143
|
}
|
|
146
|
-
function
|
|
147
|
-
return
|
|
144
|
+
function ge(o) {
|
|
145
|
+
return W(o) || _(o);
|
|
148
146
|
}
|
|
149
|
-
function
|
|
150
|
-
return Array.isArray(
|
|
147
|
+
function le(o) {
|
|
148
|
+
return Array.isArray(o.allOf) && o.allOf.length > 0;
|
|
151
149
|
}
|
|
152
|
-
function
|
|
153
|
-
return
|
|
150
|
+
function M(o) {
|
|
151
|
+
return W(o) || _(o) || le(o);
|
|
154
152
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
153
|
+
function pe(o) {
|
|
154
|
+
return o.includes("|") || o.includes("&") ? `(${o})[]` : `${o}[]`;
|
|
157
155
|
}
|
|
158
|
-
function
|
|
159
|
-
return
|
|
156
|
+
function ue(o) {
|
|
157
|
+
return o.type !== "object" ? !1 : o.properties ? Object.keys(o.properties).length === 0 : !0;
|
|
160
158
|
}
|
|
161
|
-
function N(
|
|
162
|
-
if (Array.isArray(
|
|
163
|
-
return
|
|
164
|
-
switch (
|
|
159
|
+
function N(o) {
|
|
160
|
+
if (Array.isArray(o))
|
|
161
|
+
return o.map((e) => N(e)).join(" | ");
|
|
162
|
+
switch (o) {
|
|
165
163
|
case "string":
|
|
166
164
|
return "string";
|
|
167
165
|
case "number":
|
|
@@ -175,92 +173,92 @@ function N(n) {
|
|
|
175
173
|
return "any";
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
|
-
const
|
|
179
|
-
function
|
|
180
|
-
return
|
|
176
|
+
const B = "types.ts", me = "@";
|
|
177
|
+
function de(o) {
|
|
178
|
+
return q(o.path, B);
|
|
181
179
|
}
|
|
182
|
-
function
|
|
183
|
-
const
|
|
184
|
-
return r ||
|
|
180
|
+
function D(o, e, t) {
|
|
181
|
+
const n = q(e, t), r = o.getSourceFile(n);
|
|
182
|
+
return r || o.createSourceFile(n, "", {
|
|
185
183
|
overwrite: !0
|
|
186
184
|
});
|
|
187
185
|
}
|
|
188
|
-
function w(
|
|
189
|
-
let
|
|
186
|
+
function w(o, e, t) {
|
|
187
|
+
let n = o.getImportDeclaration(
|
|
190
188
|
(r) => r.getModuleSpecifierValue() === e
|
|
191
189
|
);
|
|
192
|
-
|
|
190
|
+
n || (n = o.addImportDeclaration({
|
|
193
191
|
moduleSpecifier: e
|
|
194
192
|
})), t.forEach((r) => {
|
|
195
|
-
|
|
193
|
+
n.getNamedImports().some(
|
|
196
194
|
(i) => i.getName() === r
|
|
197
|
-
) ||
|
|
195
|
+
) || n.addNamedImport(r);
|
|
198
196
|
});
|
|
199
197
|
}
|
|
200
|
-
function y(
|
|
201
|
-
if (t.path.startsWith(
|
|
202
|
-
w(
|
|
198
|
+
function y(o, e, t) {
|
|
199
|
+
if (t.path.startsWith(me)) {
|
|
200
|
+
w(o, t.path, [t.name]);
|
|
203
201
|
return;
|
|
204
202
|
}
|
|
205
|
-
const
|
|
206
|
-
let s =
|
|
207
|
-
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), w(
|
|
203
|
+
const n = o.getDirectoryPath(), r = K(e, t.path, B);
|
|
204
|
+
let s = J(n, r);
|
|
205
|
+
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), w(o, s, [t.name]);
|
|
208
206
|
}
|
|
209
|
-
function O(
|
|
210
|
-
|
|
207
|
+
function O(o, e, t, n) {
|
|
208
|
+
o.path !== n.path && y(e, t, n);
|
|
211
209
|
}
|
|
212
|
-
function
|
|
213
|
-
const t = [
|
|
214
|
-
(
|
|
210
|
+
function fe(o, e) {
|
|
211
|
+
const t = [o, e].filter(
|
|
212
|
+
(n) => n !== void 0 && n.length > 0
|
|
215
213
|
);
|
|
216
214
|
return t.length > 0 ? t.join(`
|
|
217
215
|
`) : void 0;
|
|
218
216
|
}
|
|
219
|
-
function P(
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
description:
|
|
217
|
+
function P(o, e, t) {
|
|
218
|
+
const n = fe(e, t);
|
|
219
|
+
n && o.addJsDoc({
|
|
220
|
+
description: n
|
|
223
221
|
});
|
|
224
222
|
}
|
|
225
|
-
function
|
|
226
|
-
const e =
|
|
223
|
+
function he(o) {
|
|
224
|
+
const e = o.split(".");
|
|
227
225
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
228
226
|
}
|
|
229
|
-
function
|
|
230
|
-
const e =
|
|
227
|
+
function ye(o) {
|
|
228
|
+
const e = he(o.name);
|
|
231
229
|
return e ? {
|
|
232
|
-
tag:
|
|
230
|
+
tag: o,
|
|
233
231
|
contextAlias: e[0],
|
|
234
232
|
aggregateName: e[1]
|
|
235
233
|
} : null;
|
|
236
234
|
}
|
|
237
|
-
function
|
|
238
|
-
const e =
|
|
235
|
+
function Ae(o) {
|
|
236
|
+
const e = o?.map((n) => ye(n)).filter((n) => n !== null);
|
|
239
237
|
if (!e)
|
|
240
238
|
return /* @__PURE__ */ new Map();
|
|
241
239
|
const t = /* @__PURE__ */ new Map();
|
|
242
|
-
return e.forEach((
|
|
243
|
-
t.set(
|
|
244
|
-
aggregate:
|
|
240
|
+
return e.forEach((n) => {
|
|
241
|
+
t.set(n.tag.name, {
|
|
242
|
+
aggregate: n,
|
|
245
243
|
commands: /* @__PURE__ */ new Map(),
|
|
246
244
|
events: /* @__PURE__ */ new Map()
|
|
247
245
|
});
|
|
248
246
|
}), t;
|
|
249
247
|
}
|
|
250
|
-
function
|
|
251
|
-
if (!
|
|
248
|
+
function Ce(o) {
|
|
249
|
+
if (!o)
|
|
252
250
|
return null;
|
|
253
|
-
const e =
|
|
251
|
+
const e = o.split(".");
|
|
254
252
|
return e.length != 3 ? null : e[2];
|
|
255
253
|
}
|
|
256
|
-
const
|
|
257
|
-
class
|
|
254
|
+
const Pe = "#/components/responses/wow.CommandOk", we = "#/components/parameters/wow.id";
|
|
255
|
+
class $e {
|
|
258
256
|
/**
|
|
259
257
|
* Creates a new AggregateResolver instance.
|
|
260
258
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
261
259
|
*/
|
|
262
260
|
constructor(e) {
|
|
263
|
-
this.openAPI = e, this.aggregates =
|
|
261
|
+
this.openAPI = e, this.aggregates = Ae(e.tags), this.build();
|
|
264
262
|
}
|
|
265
263
|
aggregates;
|
|
266
264
|
/**
|
|
@@ -269,8 +267,8 @@ class Oe {
|
|
|
269
267
|
*/
|
|
270
268
|
build() {
|
|
271
269
|
for (const [e, t] of Object.entries(this.openAPI.paths)) {
|
|
272
|
-
const
|
|
273
|
-
for (const r of
|
|
270
|
+
const n = re(t);
|
|
271
|
+
for (const r of n)
|
|
274
272
|
this.commands(e, r), this.state(r.operation), this.events(r.operation), this.fields(r.operation);
|
|
275
273
|
}
|
|
276
274
|
}
|
|
@@ -283,9 +281,9 @@ class Oe {
|
|
|
283
281
|
for (const t of this.aggregates.values()) {
|
|
284
282
|
if (!t.state || !t.fields)
|
|
285
283
|
continue;
|
|
286
|
-
const
|
|
287
|
-
let r = e.get(
|
|
288
|
-
r || (r = /* @__PURE__ */ new Set(), e.set(
|
|
284
|
+
const n = t.aggregate.contextAlias;
|
|
285
|
+
let r = e.get(n);
|
|
286
|
+
r || (r = /* @__PURE__ */ new Set(), e.set(n, r)), r.add(t);
|
|
289
287
|
}
|
|
290
288
|
return e;
|
|
291
289
|
}
|
|
@@ -295,43 +293,43 @@ class Oe {
|
|
|
295
293
|
* @param methodOperation - The HTTP method and operation details
|
|
296
294
|
*/
|
|
297
295
|
commands(e, t) {
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
296
|
+
const n = t.operation;
|
|
297
|
+
if (n.operationId === "wow.command.send")
|
|
300
298
|
return;
|
|
301
|
-
const r =
|
|
299
|
+
const r = Ce(n.operationId);
|
|
302
300
|
if (!r)
|
|
303
301
|
return;
|
|
304
|
-
const s =
|
|
305
|
-
if (!s || !g(s) || s.$ref !==
|
|
302
|
+
const s = F(n);
|
|
303
|
+
if (!s || !g(s) || s.$ref !== Pe || !n.requestBody)
|
|
306
304
|
return;
|
|
307
|
-
const i =
|
|
308
|
-
(
|
|
305
|
+
const i = n.parameters ?? [], c = i.filter((m) => g(m) && m.$ref === we).at(0), a = i.filter(
|
|
306
|
+
(m) => !g(m) && m.in === "path"
|
|
309
307
|
);
|
|
310
308
|
if (c) {
|
|
311
|
-
const
|
|
309
|
+
const m = H(
|
|
312
310
|
c,
|
|
313
311
|
this.openAPI.components
|
|
314
312
|
);
|
|
315
|
-
a.push(
|
|
313
|
+
a.push(m);
|
|
316
314
|
}
|
|
317
|
-
const
|
|
318
|
-
|
|
315
|
+
const u = n.requestBody.content[I.APPLICATION_JSON].schema, l = C(
|
|
316
|
+
u,
|
|
319
317
|
this.openAPI.components
|
|
320
318
|
);
|
|
321
|
-
l.schema.title = l.schema.title ||
|
|
322
|
-
const
|
|
319
|
+
l.schema.title = l.schema.title || n.summary, l.schema.description = l.schema.description || n.description;
|
|
320
|
+
const k = {
|
|
323
321
|
name: r,
|
|
324
322
|
method: t.method,
|
|
325
323
|
path: e,
|
|
326
324
|
pathParameters: a,
|
|
327
|
-
summary:
|
|
328
|
-
description:
|
|
325
|
+
summary: n.summary,
|
|
326
|
+
description: n.description,
|
|
329
327
|
schema: l,
|
|
330
|
-
operation:
|
|
328
|
+
operation: n
|
|
331
329
|
};
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
|
|
330
|
+
n.tags?.forEach((m) => {
|
|
331
|
+
const T = this.aggregates.get(m);
|
|
332
|
+
T && T.commands.set(r, k);
|
|
335
333
|
});
|
|
336
334
|
}
|
|
337
335
|
/**
|
|
@@ -341,16 +339,16 @@ class Oe {
|
|
|
341
339
|
state(e) {
|
|
342
340
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
343
341
|
return;
|
|
344
|
-
const t =
|
|
342
|
+
const t = j(e);
|
|
345
343
|
if (!g(t))
|
|
346
344
|
return;
|
|
347
|
-
const
|
|
345
|
+
const n = C(
|
|
348
346
|
t,
|
|
349
347
|
this.openAPI.components
|
|
350
348
|
);
|
|
351
349
|
e.tags?.forEach((r) => {
|
|
352
350
|
const s = this.aggregates.get(r);
|
|
353
|
-
s && (s.state =
|
|
351
|
+
s && (s.state = n);
|
|
354
352
|
});
|
|
355
353
|
}
|
|
356
354
|
/**
|
|
@@ -360,24 +358,24 @@ class Oe {
|
|
|
360
358
|
events(e) {
|
|
361
359
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
362
360
|
return;
|
|
363
|
-
const t =
|
|
361
|
+
const t = j(e);
|
|
364
362
|
if (g(t))
|
|
365
363
|
return;
|
|
366
|
-
const
|
|
367
|
-
if (!g(
|
|
364
|
+
const n = t?.items;
|
|
365
|
+
if (!g(n))
|
|
368
366
|
return;
|
|
369
|
-
const s =
|
|
370
|
-
|
|
367
|
+
const s = S(
|
|
368
|
+
n,
|
|
371
369
|
this.openAPI.components
|
|
372
370
|
).properties.body.items.anyOf.map((i) => {
|
|
373
|
-
const c = i.title, a = i.properties.name.const, p = i.properties.body,
|
|
371
|
+
const c = i.title, a = i.properties.name.const, p = i.properties.body, u = C(
|
|
374
372
|
p,
|
|
375
373
|
this.openAPI.components
|
|
376
374
|
);
|
|
377
|
-
return
|
|
375
|
+
return u.schema.title = u.schema.title || i.title, {
|
|
378
376
|
title: c,
|
|
379
377
|
name: a,
|
|
380
|
-
schema:
|
|
378
|
+
schema: u
|
|
381
379
|
};
|
|
382
380
|
});
|
|
383
381
|
e.tags?.forEach((i) => {
|
|
@@ -394,11 +392,11 @@ class Oe {
|
|
|
394
392
|
fields(e) {
|
|
395
393
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
396
394
|
return;
|
|
397
|
-
const
|
|
395
|
+
const n = V(
|
|
398
396
|
e.requestBody,
|
|
399
397
|
this.openAPI.components
|
|
400
|
-
).content[
|
|
401
|
-
|
|
398
|
+
).content[I.APPLICATION_JSON].schema, s = S(
|
|
399
|
+
n,
|
|
402
400
|
this.openAPI.components
|
|
403
401
|
).properties?.field, i = C(s, this.openAPI.components);
|
|
404
402
|
e.tags?.forEach((c) => {
|
|
@@ -407,7 +405,7 @@ class Oe {
|
|
|
407
405
|
});
|
|
408
406
|
}
|
|
409
407
|
}
|
|
410
|
-
const A = "@ahoo-wang/fetcher-wow",
|
|
408
|
+
const A = "@ahoo-wang/fetcher-wow", xe = {
|
|
411
409
|
"wow.command.CommandResult": "CommandResult",
|
|
412
410
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
413
411
|
"wow.api.BindingError": "BindingError",
|
|
@@ -436,22 +434,22 @@ const A = "@ahoo-wang/fetcher-wow", Ee = {
|
|
|
436
434
|
"wow.openapi.BatchResult": "BatchResult",
|
|
437
435
|
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
438
436
|
};
|
|
439
|
-
function d(
|
|
440
|
-
if (!
|
|
437
|
+
function d(o) {
|
|
438
|
+
if (!o)
|
|
441
439
|
return { name: "", path: "/" };
|
|
442
|
-
const e =
|
|
440
|
+
const e = xe[o];
|
|
443
441
|
if (e)
|
|
444
442
|
return { name: e, path: A };
|
|
445
|
-
const t =
|
|
446
|
-
let
|
|
443
|
+
const t = o.split(".");
|
|
444
|
+
let n = -1;
|
|
447
445
|
for (let a = 0; a < t.length; a++)
|
|
448
446
|
if (t[a] && /^[A-Z]/.test(t[a])) {
|
|
449
|
-
|
|
447
|
+
n = a;
|
|
450
448
|
break;
|
|
451
449
|
}
|
|
452
|
-
if (
|
|
453
|
-
return { name:
|
|
454
|
-
const r = t.slice(0,
|
|
450
|
+
if (n === -1)
|
|
451
|
+
return { name: o, path: "/" };
|
|
452
|
+
const r = t.slice(0, n), s = r.length > 0 ? `/${r.join("/")}` : "/", i = t.slice(n);
|
|
455
453
|
return { name: $(i), path: s };
|
|
456
454
|
}
|
|
457
455
|
class x {
|
|
@@ -473,13 +471,13 @@ class x {
|
|
|
473
471
|
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger;
|
|
474
472
|
}
|
|
475
473
|
}
|
|
476
|
-
class
|
|
474
|
+
class Oe extends x {
|
|
477
475
|
constructor(e) {
|
|
478
476
|
super(e);
|
|
479
477
|
}
|
|
480
478
|
getOrCreateSourceFile(e) {
|
|
481
|
-
const t =
|
|
482
|
-
return
|
|
479
|
+
const t = de(e);
|
|
480
|
+
return D(this.project, this.outputDir, t);
|
|
483
481
|
}
|
|
484
482
|
/**
|
|
485
483
|
* Generates models for all schemas in the OpenAPI specification.
|
|
@@ -496,19 +494,19 @@ class Se extends x {
|
|
|
496
494
|
return;
|
|
497
495
|
}
|
|
498
496
|
const t = this.filterSchemas(e);
|
|
499
|
-
this.logger.progress(`Generating models for ${t.length} schemas`), t.forEach((
|
|
497
|
+
this.logger.progress(`Generating models for ${t.length} schemas`), t.forEach((n, r) => {
|
|
500
498
|
this.logger.progressWithCount(
|
|
501
499
|
r + 1,
|
|
502
500
|
t.length,
|
|
503
|
-
`Processing schema: ${
|
|
501
|
+
`Processing schema: ${n.key}`,
|
|
504
502
|
2
|
|
505
|
-
), this.generateKeyedSchema(
|
|
503
|
+
), this.generateKeyedSchema(n);
|
|
506
504
|
}), this.logger.success("Model generation completed");
|
|
507
505
|
}
|
|
508
506
|
filterSchemas(e) {
|
|
509
|
-
return Object.entries(e).map(([t,
|
|
507
|
+
return Object.entries(e).map(([t, n]) => ({
|
|
510
508
|
key: t,
|
|
511
|
-
schema:
|
|
509
|
+
schema: n
|
|
512
510
|
})).filter((t) => !this.isWowSchema(t.key));
|
|
513
511
|
}
|
|
514
512
|
isWowSchema(e) {
|
|
@@ -529,16 +527,16 @@ class Se extends x {
|
|
|
529
527
|
* 4. Type alias processing
|
|
530
528
|
*/
|
|
531
529
|
generateKeyedSchema({ key: e, schema: t }) {
|
|
532
|
-
const
|
|
530
|
+
const n = d(e), r = this.getOrCreateSourceFile(n), s = this.process(n, r, t);
|
|
533
531
|
s && P(s, t.title, t.description);
|
|
534
532
|
}
|
|
535
|
-
process(e, t,
|
|
536
|
-
if (
|
|
533
|
+
process(e, t, n) {
|
|
534
|
+
if (ce(n))
|
|
537
535
|
return t.addEnum({
|
|
538
536
|
name: e.name,
|
|
539
537
|
isExported: !0,
|
|
540
|
-
members:
|
|
541
|
-
name:
|
|
538
|
+
members: n.enum.filter((s) => typeof s == "string" && s.length > 0).map((s) => ({
|
|
539
|
+
name: Y(s),
|
|
542
540
|
initializer: `'${s}'`
|
|
543
541
|
}))
|
|
544
542
|
});
|
|
@@ -546,12 +544,12 @@ class Se extends x {
|
|
|
546
544
|
name: e.name,
|
|
547
545
|
isExported: !0
|
|
548
546
|
});
|
|
549
|
-
return
|
|
547
|
+
return n.type === "object" && n.properties ? this.processInterface(
|
|
550
548
|
t,
|
|
551
549
|
e,
|
|
552
|
-
|
|
550
|
+
n,
|
|
553
551
|
r
|
|
554
|
-
) : (
|
|
552
|
+
) : (M(n) && (n.anyOf || n.oneOf || n.allOf).forEach((i) => {
|
|
555
553
|
if (g(i)) {
|
|
556
554
|
const c = d(
|
|
557
555
|
f(i)
|
|
@@ -572,7 +570,7 @@ class Se extends x {
|
|
|
572
570
|
);
|
|
573
571
|
}), r);
|
|
574
572
|
}
|
|
575
|
-
processObject(e, t,
|
|
573
|
+
processObject(e, t, n) {
|
|
576
574
|
const r = e.addInterface({
|
|
577
575
|
name: t.name,
|
|
578
576
|
isExported: !0
|
|
@@ -580,12 +578,12 @@ class Se extends x {
|
|
|
580
578
|
return this.processInterface(
|
|
581
579
|
e,
|
|
582
580
|
t,
|
|
583
|
-
|
|
581
|
+
n,
|
|
584
582
|
r
|
|
585
583
|
);
|
|
586
584
|
}
|
|
587
|
-
processInterface(e, t,
|
|
588
|
-
for (const [s, i] of Object.entries(
|
|
585
|
+
processInterface(e, t, n, r) {
|
|
586
|
+
for (const [s, i] of Object.entries(n.properties)) {
|
|
589
587
|
const c = this.resolvePropertyType(
|
|
590
588
|
t,
|
|
591
589
|
e,
|
|
@@ -600,7 +598,7 @@ class Se extends x {
|
|
|
600
598
|
}
|
|
601
599
|
return r;
|
|
602
600
|
}
|
|
603
|
-
resolvePropertyType(e, t,
|
|
601
|
+
resolvePropertyType(e, t, n, r) {
|
|
604
602
|
if (g(r)) {
|
|
605
603
|
const s = d(f(r));
|
|
606
604
|
return O(
|
|
@@ -612,18 +610,18 @@ class Se extends x {
|
|
|
612
610
|
}
|
|
613
611
|
if (r.const)
|
|
614
612
|
return `'${r.const}'`;
|
|
615
|
-
if (
|
|
613
|
+
if (ae(r)) {
|
|
616
614
|
const s = this.resolvePropertyType(
|
|
617
615
|
e,
|
|
618
616
|
t,
|
|
619
|
-
|
|
617
|
+
n,
|
|
620
618
|
r.items
|
|
621
619
|
);
|
|
622
|
-
return
|
|
620
|
+
return pe(s);
|
|
623
621
|
}
|
|
624
|
-
if (r.type &&
|
|
622
|
+
if (r.type && ie(r.type))
|
|
625
623
|
return N(r.type);
|
|
626
|
-
if (
|
|
624
|
+
if (M(r))
|
|
627
625
|
return this.resolvePropertyCompositionType(
|
|
628
626
|
e,
|
|
629
627
|
t,
|
|
@@ -632,7 +630,7 @@ class Se extends x {
|
|
|
632
630
|
if (r.type === "object" && r.properties) {
|
|
633
631
|
const s = {
|
|
634
632
|
path: e.path,
|
|
635
|
-
name: `${e.name}${$(
|
|
633
|
+
name: `${e.name}${$(n)}`
|
|
636
634
|
}, i = this.processObject(
|
|
637
635
|
t,
|
|
638
636
|
s,
|
|
@@ -642,8 +640,8 @@ class Se extends x {
|
|
|
642
640
|
}
|
|
643
641
|
return "any";
|
|
644
642
|
}
|
|
645
|
-
resolvePropertyCompositionType(e, t,
|
|
646
|
-
const r =
|
|
643
|
+
resolvePropertyCompositionType(e, t, n) {
|
|
644
|
+
const r = n.anyOf || n.oneOf || n.allOf, s = /* @__PURE__ */ new Set();
|
|
647
645
|
r.forEach((c) => {
|
|
648
646
|
if (g(c)) {
|
|
649
647
|
const a = d(
|
|
@@ -659,24 +657,24 @@ class Se extends x {
|
|
|
659
657
|
}
|
|
660
658
|
s.add(N(c.type ?? "string"));
|
|
661
659
|
});
|
|
662
|
-
const i =
|
|
660
|
+
const i = ge(n) ? "|" : "&";
|
|
663
661
|
return Array.from(s).join(i);
|
|
664
662
|
}
|
|
665
663
|
}
|
|
666
|
-
function
|
|
664
|
+
function Ee(o) {
|
|
667
665
|
let e = 0, t = 0;
|
|
668
|
-
return
|
|
669
|
-
|
|
666
|
+
return o.commands.forEach((n) => {
|
|
667
|
+
n.path.startsWith(v.TENANT) && (e += 1), n.path.startsWith(v.OWNER) && (t += 1);
|
|
670
668
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
671
669
|
}
|
|
672
|
-
function
|
|
673
|
-
const r = `${t.contextAlias}/${t.aggregateName}/${
|
|
674
|
-
return
|
|
670
|
+
function z(o, e, t, n) {
|
|
671
|
+
const r = `${t.contextAlias}/${t.aggregateName}/${n}.ts`;
|
|
672
|
+
return D(o, e, r);
|
|
675
673
|
}
|
|
676
|
-
function
|
|
677
|
-
return `${$(
|
|
674
|
+
function Ie(o, e) {
|
|
675
|
+
return `${$(o.aggregateName)}${e}`;
|
|
678
676
|
}
|
|
679
|
-
class
|
|
677
|
+
class Se extends x {
|
|
680
678
|
/**
|
|
681
679
|
* Creates a new QueryClientGenerator instance.
|
|
682
680
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -689,15 +687,15 @@ class Te extends x {
|
|
|
689
687
|
*/
|
|
690
688
|
generate() {
|
|
691
689
|
const e = Array.from(this.contextAggregates.values()).reduce(
|
|
692
|
-
(
|
|
690
|
+
(n, r) => n + r.size,
|
|
693
691
|
0
|
|
694
692
|
);
|
|
695
693
|
this.logger.info("--- Generating Query Clients ---"), this.logger.progress(
|
|
696
694
|
`Generating query clients for ${e} aggregates`
|
|
697
695
|
);
|
|
698
696
|
let t = 0;
|
|
699
|
-
for (const [,
|
|
700
|
-
|
|
697
|
+
for (const [, n] of this.contextAggregates)
|
|
698
|
+
n.forEach((r) => {
|
|
701
699
|
t++, this.logger.progressWithCount(
|
|
702
700
|
t,
|
|
703
701
|
e,
|
|
@@ -713,7 +711,7 @@ class Te extends x {
|
|
|
713
711
|
* @returns The source file for the client
|
|
714
712
|
*/
|
|
715
713
|
createClientFilePath(e, t) {
|
|
716
|
-
return
|
|
714
|
+
return z(
|
|
717
715
|
this.project,
|
|
718
716
|
this.outputDir,
|
|
719
717
|
e,
|
|
@@ -741,19 +739,19 @@ class Te extends x {
|
|
|
741
739
|
"ResourceAttributionPathSpec"
|
|
742
740
|
]
|
|
743
741
|
});
|
|
744
|
-
const
|
|
742
|
+
const n = "DEFAULT_QUERY_CLIENT_OPTIONS";
|
|
745
743
|
this.logger.info(
|
|
746
|
-
`Creating default query client options: ${
|
|
744
|
+
`Creating default query client options: ${n}`
|
|
747
745
|
), t.addVariableStatement({
|
|
748
746
|
declarationKind: E.Const,
|
|
749
747
|
declarations: [
|
|
750
748
|
{
|
|
751
|
-
name:
|
|
749
|
+
name: n,
|
|
752
750
|
type: "QueryClientOptions",
|
|
753
751
|
initializer: `{
|
|
754
752
|
contextAlias: '${e.aggregate.contextAlias}',
|
|
755
753
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
756
|
-
resourceAttribution: ${
|
|
754
|
+
resourceAttribution: ${Ee(e)},
|
|
757
755
|
}`
|
|
758
756
|
}
|
|
759
757
|
],
|
|
@@ -763,13 +761,13 @@ class Te extends x {
|
|
|
763
761
|
this.logger.info(
|
|
764
762
|
`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
|
|
765
763
|
);
|
|
766
|
-
for (const
|
|
767
|
-
const l = d(
|
|
764
|
+
for (const u of e.events.values()) {
|
|
765
|
+
const l = d(u.schema.key);
|
|
768
766
|
this.logger.info(
|
|
769
767
|
`Adding import for event model: ${l.name} from path: ${l.path}`
|
|
770
768
|
), y(t, this.outputDir, l), r.push(l);
|
|
771
769
|
}
|
|
772
|
-
const s = "DOMAIN_EVENT_TYPES", i = r.map((
|
|
770
|
+
const s = "DOMAIN_EVENT_TYPES", i = r.map((u) => u.name).join(" | ");
|
|
773
771
|
this.logger.info(
|
|
774
772
|
`Creating domain event types union: ${s} = ${i}`
|
|
775
773
|
), t.addTypeAlias({
|
|
@@ -786,7 +784,7 @@ class Te extends x {
|
|
|
786
784
|
declarations: [
|
|
787
785
|
{
|
|
788
786
|
name: c,
|
|
789
|
-
initializer: `new QueryClientFactory<${a.name}, ${p.name} | string, ${s}>(${
|
|
787
|
+
initializer: `new QueryClientFactory<${a.name}, ${p.name} | string, ${s}>(${n})`
|
|
790
788
|
}
|
|
791
789
|
],
|
|
792
790
|
isExported: !0
|
|
@@ -795,7 +793,7 @@ class Te extends x {
|
|
|
795
793
|
);
|
|
796
794
|
}
|
|
797
795
|
}
|
|
798
|
-
class
|
|
796
|
+
class Ne extends x {
|
|
799
797
|
commandEndpointPathsName = "COMMAND_ENDPOINT_PATHS";
|
|
800
798
|
defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
801
799
|
/**
|
|
@@ -810,15 +808,15 @@ class De extends x {
|
|
|
810
808
|
*/
|
|
811
809
|
generate() {
|
|
812
810
|
const e = Array.from(this.contextAggregates.values()).reduce(
|
|
813
|
-
(
|
|
811
|
+
(n, r) => n + r.size,
|
|
814
812
|
0
|
|
815
813
|
);
|
|
816
814
|
this.logger.info("--- Generating Command Clients ---"), this.logger.progress(
|
|
817
815
|
`Generating command clients for ${e} aggregates`
|
|
818
816
|
);
|
|
819
817
|
let t = 0;
|
|
820
|
-
for (const [,
|
|
821
|
-
|
|
818
|
+
for (const [, n] of this.contextAggregates)
|
|
819
|
+
n.forEach((r) => {
|
|
822
820
|
t++, this.logger.progressWithCount(
|
|
823
821
|
t,
|
|
824
822
|
e,
|
|
@@ -835,7 +833,7 @@ class De extends x {
|
|
|
835
833
|
this.logger.info(
|
|
836
834
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
837
835
|
);
|
|
838
|
-
const t =
|
|
836
|
+
const t = z(
|
|
839
837
|
this.project,
|
|
840
838
|
this.outputDir,
|
|
841
839
|
e.aggregate,
|
|
@@ -898,13 +896,13 @@ class De extends x {
|
|
|
898
896
|
this.logger.info(
|
|
899
897
|
`Creating command endpoint paths enum: ${this.commandEndpointPathsName}`
|
|
900
898
|
);
|
|
901
|
-
const
|
|
899
|
+
const n = e.addEnum({
|
|
902
900
|
name: this.commandEndpointPathsName
|
|
903
901
|
});
|
|
904
902
|
t.commands.forEach((r) => {
|
|
905
903
|
this.logger.info(
|
|
906
904
|
`Adding command endpoint: ${r.name.toUpperCase()} = '${r.path}'`
|
|
907
|
-
),
|
|
905
|
+
), n.addMember({
|
|
908
906
|
name: r.name.toUpperCase(),
|
|
909
907
|
initializer: `'${r.path}'`
|
|
910
908
|
});
|
|
@@ -915,12 +913,12 @@ class De extends x {
|
|
|
915
913
|
getEndpointPath(e) {
|
|
916
914
|
return `${this.commandEndpointPathsName}.${e.name.toUpperCase()}`;
|
|
917
915
|
}
|
|
918
|
-
processCommandClient(e, t,
|
|
916
|
+
processCommandClient(e, t, n = !1) {
|
|
919
917
|
let r = "CommandClient", s = {
|
|
920
918
|
name: "api",
|
|
921
919
|
arguments: []
|
|
922
920
|
}, i = "Promise<CommandResult>";
|
|
923
|
-
|
|
921
|
+
n && (r = "Stream" + r, s = {
|
|
924
922
|
name: "api",
|
|
925
923
|
arguments: [
|
|
926
924
|
"''",
|
|
@@ -930,7 +928,7 @@ class De extends x {
|
|
|
930
928
|
}`
|
|
931
929
|
]
|
|
932
930
|
}, i = "Promise<CommandResultEventStream>");
|
|
933
|
-
const c =
|
|
931
|
+
const c = Ie(
|
|
934
932
|
t.aggregate,
|
|
935
933
|
r
|
|
936
934
|
), a = e.addClass({
|
|
@@ -944,7 +942,7 @@ class De extends x {
|
|
|
944
942
|
{
|
|
945
943
|
name: "apiMetadata",
|
|
946
944
|
type: "ApiMetadata",
|
|
947
|
-
scope:
|
|
945
|
+
scope: Q.Public,
|
|
948
946
|
isReadonly: !0,
|
|
949
947
|
initializer: `${this.defaultCommandClientOptionsName}`
|
|
950
948
|
}
|
|
@@ -962,16 +960,16 @@ class De extends x {
|
|
|
962
960
|
* @param client - The client class declaration
|
|
963
961
|
* @param definition - The command definition
|
|
964
962
|
*/
|
|
965
|
-
processCommandMethod(e, t,
|
|
966
|
-
const s = d(
|
|
963
|
+
processCommandMethod(e, t, n, r) {
|
|
964
|
+
const s = d(n.schema.key);
|
|
967
965
|
this.logger.info(
|
|
968
966
|
`Adding import for command model: ${s.name} from path: ${s.path}`
|
|
969
967
|
), y(e, this.outputDir, s), this.logger.info(
|
|
970
|
-
`Generating command method: ${h(
|
|
968
|
+
`Generating command method: ${h(n.name)} for command: ${n.name}`
|
|
971
969
|
), this.logger.info(
|
|
972
|
-
`Command method details: HTTP ${
|
|
970
|
+
`Command method details: HTTP ${n.method}, path: ${n.path}, return type: ${r}`
|
|
973
971
|
);
|
|
974
|
-
const i =
|
|
972
|
+
const i = n.pathParameters.map((a) => (this.logger.info(
|
|
975
973
|
`Adding path parameter: ${a.name} (type: string)`
|
|
976
974
|
), {
|
|
977
975
|
name: a.name,
|
|
@@ -988,7 +986,7 @@ class De extends x {
|
|
|
988
986
|
`Adding command request parameter: commandRequest (type: CommandRequest<${s.name}>)`
|
|
989
987
|
), i.push({
|
|
990
988
|
name: "commandRequest",
|
|
991
|
-
hasQuestionToken:
|
|
989
|
+
hasQuestionToken: ue(n.schema.schema),
|
|
992
990
|
type: `CommandRequest<${s.name}>`,
|
|
993
991
|
decorators: [
|
|
994
992
|
{
|
|
@@ -1010,11 +1008,11 @@ class De extends x {
|
|
|
1010
1008
|
]
|
|
1011
1009
|
});
|
|
1012
1010
|
const c = t.addMethod({
|
|
1013
|
-
name: h(
|
|
1011
|
+
name: h(n.name),
|
|
1014
1012
|
decorators: [
|
|
1015
1013
|
{
|
|
1016
|
-
name: this.methodToDecorator(
|
|
1017
|
-
arguments: [`${this.getEndpointPath(
|
|
1014
|
+
name: this.methodToDecorator(n.method),
|
|
1015
|
+
arguments: [`${this.getEndpointPath(n)}`]
|
|
1018
1016
|
}
|
|
1019
1017
|
],
|
|
1020
1018
|
parameters: i,
|
|
@@ -1023,14 +1021,14 @@ class De extends x {
|
|
|
1023
1021
|
`throw autoGeneratedError(${i.map((a) => a.name).join(",")});`
|
|
1024
1022
|
]
|
|
1025
1023
|
});
|
|
1026
|
-
(
|
|
1027
|
-
`Adding JSDoc documentation for method: ${h(
|
|
1028
|
-
), P(c,
|
|
1029
|
-
`Command method generated: ${h(
|
|
1024
|
+
(n.summary || n.description) && this.logger.info(
|
|
1025
|
+
`Adding JSDoc documentation for method: ${h(n.name)}`
|
|
1026
|
+
), P(c, n.summary, n.description), this.logger.success(
|
|
1027
|
+
`Command method generated: ${h(n.name)}`
|
|
1030
1028
|
);
|
|
1031
1029
|
}
|
|
1032
1030
|
}
|
|
1033
|
-
class
|
|
1031
|
+
class De extends x {
|
|
1034
1032
|
queryClientGenerator;
|
|
1035
1033
|
commandClientGenerator;
|
|
1036
1034
|
/**
|
|
@@ -1038,7 +1036,7 @@ class ve extends x {
|
|
|
1038
1036
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1039
1037
|
*/
|
|
1040
1038
|
constructor(e) {
|
|
1041
|
-
super(e), this.queryClientGenerator = new
|
|
1039
|
+
super(e), this.queryClientGenerator = new Se(e), this.commandClientGenerator = new Ne(e);
|
|
1042
1040
|
}
|
|
1043
1041
|
/**
|
|
1044
1042
|
* Generates client classes for all aggregates.
|
|
@@ -1064,17 +1062,17 @@ class ve extends x {
|
|
|
1064
1062
|
processBoundedContext(e) {
|
|
1065
1063
|
const t = `${e}/boundedContext.ts`;
|
|
1066
1064
|
this.logger.info(`Creating bounded context file: ${t}`);
|
|
1067
|
-
const
|
|
1065
|
+
const n = D(this.project, this.outputDir, t);
|
|
1068
1066
|
this.logger.info(
|
|
1069
1067
|
`Adding bounded context alias constant: BOUNDED_CONTEXT_ALIAS = '${e}'`
|
|
1070
|
-
),
|
|
1068
|
+
), n.addStatements(
|
|
1071
1069
|
`export const BOUNDED_CONTEXT_ALIAS = '${e}';`
|
|
1072
1070
|
), this.logger.success(
|
|
1073
1071
|
`Bounded context file created successfully: ${t}`
|
|
1074
1072
|
);
|
|
1075
1073
|
}
|
|
1076
1074
|
}
|
|
1077
|
-
class
|
|
1075
|
+
class qe {
|
|
1078
1076
|
/**
|
|
1079
1077
|
* Creates a new CodeGenerator instance.
|
|
1080
1078
|
* @param options - Configuration options for code generation
|
|
@@ -1092,20 +1090,20 @@ class Fe {
|
|
|
1092
1090
|
this.options.logger.info(
|
|
1093
1091
|
"Starting code generation from OpenAPI specification"
|
|
1094
1092
|
), 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");
|
|
1095
|
-
const e = await
|
|
1093
|
+
const e = await te(this.options.inputPath);
|
|
1096
1094
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1097
|
-
const
|
|
1095
|
+
const n = new $e(e).resolve();
|
|
1098
1096
|
this.options.logger.info(
|
|
1099
|
-
`Resolved ${
|
|
1097
|
+
`Resolved ${n.size} bounded context aggregates`
|
|
1100
1098
|
);
|
|
1101
1099
|
const r = {
|
|
1102
1100
|
openAPI: e,
|
|
1103
1101
|
project: this.project,
|
|
1104
1102
|
outputDir: this.options.outputDir,
|
|
1105
|
-
contextAggregates:
|
|
1103
|
+
contextAggregates: n,
|
|
1106
1104
|
logger: this.options.logger
|
|
1107
1105
|
};
|
|
1108
|
-
this.options.logger.info("Generating models"), new
|
|
1106
|
+
this.options.logger.info("Generating models"), new Oe(r).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new De(r).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");
|
|
1109
1107
|
}
|
|
1110
1108
|
/**
|
|
1111
1109
|
* Generates index.ts files for all subdirectories in the output directory.
|
|
@@ -1123,13 +1121,13 @@ class Fe {
|
|
|
1123
1121
|
);
|
|
1124
1122
|
return;
|
|
1125
1123
|
}
|
|
1126
|
-
this.processDirectory(e), this.options.logger.info("Index file generation completed");
|
|
1124
|
+
this.processDirectory(e), this.generateIndexForDirectory(e), this.options.logger.info("Index file generation completed");
|
|
1127
1125
|
}
|
|
1128
1126
|
processDirectory(e) {
|
|
1129
1127
|
const t = e.getDirectories();
|
|
1130
1128
|
this.options.logger.info(`Processing ${t.length} subdirectories`);
|
|
1131
|
-
for (const
|
|
1132
|
-
this.options.logger.info(`Processing subdirectory: ${
|
|
1129
|
+
for (const n of t)
|
|
1130
|
+
this.options.logger.info(`Processing subdirectory: ${n.getPath()}`), this.generateIndexForDirectory(n), this.processDirectory(n);
|
|
1133
1131
|
}
|
|
1134
1132
|
/**
|
|
1135
1133
|
* Generates an index.ts file for a specific directory.
|
|
@@ -1138,23 +1136,12 @@ class Fe {
|
|
|
1138
1136
|
generateIndexForDirectory(e) {
|
|
1139
1137
|
const t = e.getPath();
|
|
1140
1138
|
this.options.logger.info(`Generating index for directory: ${t}`);
|
|
1141
|
-
const
|
|
1139
|
+
const n = e.getSourceFiles().filter(
|
|
1142
1140
|
(c) => c.getBaseName().endsWith(".ts") && c.getBaseName() !== "index.ts"
|
|
1143
|
-
);
|
|
1144
|
-
let r = [];
|
|
1145
|
-
try {
|
|
1146
|
-
r = v.readdirSync(t).filter((c) => {
|
|
1147
|
-
const a = J.join(t, c);
|
|
1148
|
-
return v.statSync(a).isDirectory();
|
|
1149
|
-
});
|
|
1150
|
-
} catch (c) {
|
|
1151
|
-
this.options.logger.error(
|
|
1152
|
-
`Failed to read subdirectories for ${t}: ${c}`
|
|
1153
|
-
);
|
|
1154
|
-
}
|
|
1141
|
+
), r = e.getDirectories();
|
|
1155
1142
|
if (this.options.logger.info(
|
|
1156
|
-
`Found ${
|
|
1157
|
-
),
|
|
1143
|
+
`Found ${n.length} TypeScript files and ${r.length} subdirectories in ${t}`
|
|
1144
|
+
), n.length === 0 && r.length === 0) {
|
|
1158
1145
|
this.options.logger.info(
|
|
1159
1146
|
`No files or subdirectories to export in ${t}, skipping index generation`
|
|
1160
1147
|
);
|
|
@@ -1164,7 +1151,7 @@ class Fe {
|
|
|
1164
1151
|
this.options.logger.info(`Creating/updating index file: ${s}`);
|
|
1165
1152
|
const i = this.project.getSourceFile(s) || this.project.createSourceFile(s, "", { overwrite: !0 });
|
|
1166
1153
|
i.removeText();
|
|
1167
|
-
for (const c of
|
|
1154
|
+
for (const c of n) {
|
|
1168
1155
|
const a = `./${c.getBaseNameWithoutExtension()}`;
|
|
1169
1156
|
this.options.logger.info(`Adding export for file: ${a}`), i.addExportDeclaration({
|
|
1170
1157
|
moduleSpecifier: a,
|
|
@@ -1173,7 +1160,7 @@ class Fe {
|
|
|
1173
1160
|
});
|
|
1174
1161
|
}
|
|
1175
1162
|
for (const c of r) {
|
|
1176
|
-
const a = `./${c}`;
|
|
1163
|
+
const a = `./${c.getBaseName()}`;
|
|
1177
1164
|
this.options.logger.info(
|
|
1178
1165
|
`Adding export for subdirectory: ${a}`
|
|
1179
1166
|
), i.addExportDeclaration({
|
|
@@ -1183,19 +1170,19 @@ class Fe {
|
|
|
1183
1170
|
});
|
|
1184
1171
|
}
|
|
1185
1172
|
this.options.logger.info(
|
|
1186
|
-
`Index file generated for ${t} with ${
|
|
1173
|
+
`Index file generated for ${t} with ${n.length + r.length} exports`
|
|
1187
1174
|
);
|
|
1188
1175
|
}
|
|
1189
1176
|
optimizeSourceFiles() {
|
|
1190
1177
|
const e = this.project.getSourceFiles();
|
|
1191
|
-
this.options.logger.info(`Optimizing ${e.length} source files`), e.forEach((t,
|
|
1178
|
+
this.options.logger.info(`Optimizing ${e.length} source files`), e.forEach((t, n) => {
|
|
1192
1179
|
this.options.logger.info(
|
|
1193
|
-
`Optimizing file ${
|
|
1180
|
+
`Optimizing file ${n + 1}/${e.length}`
|
|
1194
1181
|
), t.formatText(), t.organizeImports(), t.fixMissingImports();
|
|
1195
1182
|
}), this.options.logger.info("All source files optimized");
|
|
1196
1183
|
}
|
|
1197
1184
|
}
|
|
1198
1185
|
export {
|
|
1199
|
-
|
|
1186
|
+
qe as CodeGenerator
|
|
1200
1187
|
};
|
|
1201
1188
|
//# sourceMappingURL=index.js.map
|