@ahoo-wang/fetcher-generator 2.2.9 → 2.3.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/README.zh-CN.md +2 -2
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +196 -184
- package/dist/index.js.map +1 -1
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/utils/naming.d.ts +12 -0
- package/dist/utils/naming.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { VariableDeclarationKind as E, Scope as
|
|
2
|
-
import { parse as
|
|
1
|
+
import { VariableDeclarationKind as E, Scope as L } from "ts-morph";
|
|
2
|
+
import { parse as U } from "yaml";
|
|
3
3
|
import * as v from "fs";
|
|
4
|
-
import { readFile as
|
|
5
|
-
import { ContentTypeValues as S, combineURLs as
|
|
6
|
-
import * as
|
|
7
|
-
import { join as
|
|
4
|
+
import { readFile as K } from "fs";
|
|
5
|
+
import { ContentTypeValues as S, combineURLs as G } from "@ahoo-wang/fetcher";
|
|
6
|
+
import * as J from "path";
|
|
7
|
+
import { join as V, relative as H } from "path";
|
|
8
8
|
import { ResourceAttributionPathSpec as b } from "@ahoo-wang/fetcher-wow";
|
|
9
9
|
function f(n) {
|
|
10
10
|
return n.$ref.split("/").pop();
|
|
@@ -13,11 +13,11 @@ function I(n, e) {
|
|
|
13
13
|
const t = f(n);
|
|
14
14
|
return e.schemas?.[t];
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function Y(n, e) {
|
|
17
17
|
const t = f(n);
|
|
18
18
|
return e.requestBodies?.[t];
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function X(n, e) {
|
|
21
21
|
const t = f(n);
|
|
22
22
|
return e.parameters?.[t];
|
|
23
23
|
}
|
|
@@ -27,46 +27,62 @@ function C(n, e) {
|
|
|
27
27
|
schema: I(n, e)
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
const R = /[-_\s.]
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
30
|
+
const R = /[-_\s.]+/;
|
|
31
|
+
function F(n) {
|
|
32
|
+
return Array.isArray(n) ? n.flatMap((e) => j(e.split(R))) : j(n.split(R));
|
|
33
|
+
}
|
|
34
|
+
function j(n) {
|
|
35
|
+
return n.flatMap((e) => {
|
|
36
|
+
if (e.length === 0)
|
|
37
|
+
return [];
|
|
38
|
+
const t = [];
|
|
39
|
+
let o = "";
|
|
40
|
+
for (let r = 0; r < e.length; r++) {
|
|
41
|
+
const s = e[r], i = /[A-Z]/.test(s), c = r > 0 && /[a-z]/.test(e[r - 1]);
|
|
42
|
+
i && c && o ? (t.push(o), o = s) : o += s;
|
|
43
|
+
}
|
|
44
|
+
return o && t.push(o), t;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function $(n) {
|
|
48
|
+
return n === "" || n.length === 0 ? "" : F(n).filter((t) => t.length > 0).map((t) => {
|
|
36
49
|
if (t.length === 0) return "";
|
|
37
50
|
const o = t.charAt(0), r = t.slice(1);
|
|
38
51
|
return (/[a-zA-Z]/.test(o) ? o.toUpperCase() : o) + r.toLowerCase();
|
|
39
52
|
}).join("");
|
|
40
53
|
}
|
|
41
54
|
function h(n) {
|
|
42
|
-
const e =
|
|
55
|
+
const e = $(n);
|
|
43
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
44
57
|
}
|
|
45
|
-
function
|
|
46
|
-
return n
|
|
58
|
+
function Z(n) {
|
|
59
|
+
return n === "" || Array.isArray(n) && n.length === 0 ? "" : F(n).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
|
+
}
|
|
61
|
+
function ee(n) {
|
|
62
|
+
return n.startsWith("http://") || n.startsWith("https://") ? te(n) : oe(n);
|
|
47
63
|
}
|
|
48
|
-
async function
|
|
64
|
+
async function te(n) {
|
|
49
65
|
return await (await fetch(n)).text();
|
|
50
66
|
}
|
|
51
|
-
function
|
|
67
|
+
function oe(n) {
|
|
52
68
|
return new Promise((e, t) => {
|
|
53
|
-
|
|
69
|
+
K(n, "utf-8", (o, r) => {
|
|
54
70
|
o ? t(o) : e(r);
|
|
55
71
|
});
|
|
56
72
|
});
|
|
57
73
|
}
|
|
58
|
-
async function
|
|
59
|
-
const e = await
|
|
60
|
-
switch (
|
|
74
|
+
async function ne(n) {
|
|
75
|
+
const e = await ee(n);
|
|
76
|
+
switch (re(e)) {
|
|
61
77
|
case "json":
|
|
62
78
|
return JSON.parse(e);
|
|
63
79
|
case "yaml":
|
|
64
|
-
return
|
|
80
|
+
return U(e);
|
|
65
81
|
default:
|
|
66
82
|
throw new Error(`Unsupported file format: ${n}`);
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
|
-
function
|
|
85
|
+
function re(n) {
|
|
70
86
|
const e = n.trimStart();
|
|
71
87
|
if (e.startsWith("{") || e.startsWith("["))
|
|
72
88
|
return "json";
|
|
@@ -83,10 +99,10 @@ function te(n) {
|
|
|
83
99
|
function g(n) {
|
|
84
100
|
return !!(n && typeof n == "object" && "$ref" in n);
|
|
85
101
|
}
|
|
86
|
-
function
|
|
102
|
+
function se(n) {
|
|
87
103
|
return !n || g(n) || !n.content ? void 0 : n.content[S.APPLICATION_JSON]?.schema;
|
|
88
104
|
}
|
|
89
|
-
function
|
|
105
|
+
function ie(n) {
|
|
90
106
|
return [
|
|
91
107
|
{ method: "get", operation: n.get },
|
|
92
108
|
{ method: "put", operation: n.put },
|
|
@@ -98,48 +114,48 @@ function ne(n) {
|
|
|
98
114
|
{ method: "trace", operation: n.trace }
|
|
99
115
|
].filter(({ operation: e }) => e !== void 0);
|
|
100
116
|
}
|
|
101
|
-
function
|
|
117
|
+
function W(n) {
|
|
102
118
|
return n.responses[200];
|
|
103
119
|
}
|
|
104
|
-
function
|
|
105
|
-
const e =
|
|
106
|
-
return
|
|
120
|
+
function M(n) {
|
|
121
|
+
const e = W(n);
|
|
122
|
+
return se(e);
|
|
107
123
|
}
|
|
108
|
-
const
|
|
124
|
+
const ae = [
|
|
109
125
|
"string",
|
|
110
126
|
"number",
|
|
111
127
|
"integer",
|
|
112
128
|
"boolean",
|
|
113
129
|
"null"
|
|
114
130
|
];
|
|
115
|
-
function
|
|
116
|
-
return Array.isArray(n) ? !0 :
|
|
131
|
+
function ce(n) {
|
|
132
|
+
return Array.isArray(n) ? !0 : ae.includes(n);
|
|
117
133
|
}
|
|
118
|
-
function
|
|
134
|
+
function ge(n) {
|
|
119
135
|
return n.type === "array";
|
|
120
136
|
}
|
|
121
|
-
function
|
|
137
|
+
function le(n) {
|
|
122
138
|
return Array.isArray(n.enum) && n.enum.length > 0;
|
|
123
139
|
}
|
|
124
|
-
function
|
|
140
|
+
function _(n) {
|
|
125
141
|
return Array.isArray(n.anyOf) && n.anyOf.length > 0;
|
|
126
142
|
}
|
|
127
|
-
function
|
|
143
|
+
function B(n) {
|
|
128
144
|
return Array.isArray(n.oneOf) && n.oneOf.length > 0;
|
|
129
145
|
}
|
|
130
|
-
function
|
|
131
|
-
return
|
|
146
|
+
function pe(n) {
|
|
147
|
+
return _(n) || B(n);
|
|
132
148
|
}
|
|
133
|
-
function
|
|
149
|
+
function me(n) {
|
|
134
150
|
return Array.isArray(n.allOf) && n.allOf.length > 0;
|
|
135
151
|
}
|
|
136
|
-
function
|
|
137
|
-
return
|
|
152
|
+
function q(n) {
|
|
153
|
+
return _(n) || B(n) || me(n);
|
|
138
154
|
}
|
|
139
|
-
function
|
|
155
|
+
function ue(n) {
|
|
140
156
|
return n.includes("|") || n.includes("&") ? `(${n})[]` : `${n}[]`;
|
|
141
157
|
}
|
|
142
|
-
function
|
|
158
|
+
function de(n) {
|
|
143
159
|
return n.type !== "object" ? !1 : n.properties ? Object.keys(n.properties).length === 0 : !0;
|
|
144
160
|
}
|
|
145
161
|
function N(n) {
|
|
@@ -159,17 +175,17 @@ function N(n) {
|
|
|
159
175
|
return "any";
|
|
160
176
|
}
|
|
161
177
|
}
|
|
162
|
-
const
|
|
163
|
-
function
|
|
164
|
-
return
|
|
178
|
+
const z = "types.ts", fe = "@";
|
|
179
|
+
function he(n) {
|
|
180
|
+
return G(n.path, z);
|
|
165
181
|
}
|
|
166
182
|
function T(n, e, t) {
|
|
167
|
-
const o =
|
|
183
|
+
const o = G(e, t), r = n.getSourceFile(o);
|
|
168
184
|
return r || n.createSourceFile(o, "", {
|
|
169
185
|
overwrite: !0
|
|
170
186
|
});
|
|
171
187
|
}
|
|
172
|
-
function
|
|
188
|
+
function w(n, e, t) {
|
|
173
189
|
let o = n.getImportDeclaration(
|
|
174
190
|
(r) => r.getModuleSpecifierValue() === e
|
|
175
191
|
);
|
|
@@ -177,23 +193,23 @@ function $(n, e, t) {
|
|
|
177
193
|
moduleSpecifier: e
|
|
178
194
|
})), t.forEach((r) => {
|
|
179
195
|
o.getNamedImports().some(
|
|
180
|
-
(
|
|
196
|
+
(i) => i.getName() === r
|
|
181
197
|
) || o.addNamedImport(r);
|
|
182
198
|
});
|
|
183
199
|
}
|
|
184
200
|
function y(n, e, t) {
|
|
185
|
-
if (t.path.startsWith(
|
|
186
|
-
|
|
201
|
+
if (t.path.startsWith(fe)) {
|
|
202
|
+
w(n, t.path, [t.name]);
|
|
187
203
|
return;
|
|
188
204
|
}
|
|
189
|
-
const o = n.getDirectoryPath(), r =
|
|
190
|
-
let s =
|
|
191
|
-
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s),
|
|
205
|
+
const o = n.getDirectoryPath(), r = V(e, t.path, z);
|
|
206
|
+
let s = H(o, r);
|
|
207
|
+
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), w(n, s, [t.name]);
|
|
192
208
|
}
|
|
193
209
|
function O(n, e, t, o) {
|
|
194
210
|
n.path !== o.path && y(e, t, o);
|
|
195
211
|
}
|
|
196
|
-
function
|
|
212
|
+
function ye(n, e) {
|
|
197
213
|
const t = [n, e].filter(
|
|
198
214
|
(o) => o !== void 0 && o.length > 0
|
|
199
215
|
);
|
|
@@ -201,25 +217,25 @@ function de(n, e) {
|
|
|
201
217
|
`) : void 0;
|
|
202
218
|
}
|
|
203
219
|
function P(n, e, t) {
|
|
204
|
-
const o =
|
|
220
|
+
const o = ye(e, t);
|
|
205
221
|
o && n.addJsDoc({
|
|
206
222
|
description: o
|
|
207
223
|
});
|
|
208
224
|
}
|
|
209
|
-
function
|
|
225
|
+
function Ae(n) {
|
|
210
226
|
const e = n.split(".");
|
|
211
227
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
212
228
|
}
|
|
213
|
-
function
|
|
214
|
-
const e =
|
|
229
|
+
function Ce(n) {
|
|
230
|
+
const e = Ae(n.name);
|
|
215
231
|
return e ? {
|
|
216
232
|
tag: n,
|
|
217
233
|
contextAlias: e[0],
|
|
218
234
|
aggregateName: e[1]
|
|
219
235
|
} : null;
|
|
220
236
|
}
|
|
221
|
-
function
|
|
222
|
-
const e = n?.map((o) =>
|
|
237
|
+
function Pe(n) {
|
|
238
|
+
const e = n?.map((o) => Ce(o)).filter((o) => o !== null);
|
|
223
239
|
if (!e)
|
|
224
240
|
return /* @__PURE__ */ new Map();
|
|
225
241
|
const t = /* @__PURE__ */ new Map();
|
|
@@ -231,20 +247,20 @@ function ye(n) {
|
|
|
231
247
|
});
|
|
232
248
|
}), t;
|
|
233
249
|
}
|
|
234
|
-
function
|
|
250
|
+
function we(n) {
|
|
235
251
|
if (!n)
|
|
236
252
|
return null;
|
|
237
253
|
const e = n.split(".");
|
|
238
254
|
return e.length != 3 ? null : e[2];
|
|
239
255
|
}
|
|
240
|
-
const
|
|
241
|
-
class
|
|
256
|
+
const $e = "#/components/responses/wow.CommandOk", xe = "#/components/parameters/wow.id";
|
|
257
|
+
class Oe {
|
|
242
258
|
/**
|
|
243
259
|
* Creates a new AggregateResolver instance.
|
|
244
260
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
245
261
|
*/
|
|
246
262
|
constructor(e) {
|
|
247
|
-
this.openAPI = e, this.aggregates =
|
|
263
|
+
this.openAPI = e, this.aggregates = Pe(e.tags), this.build();
|
|
248
264
|
}
|
|
249
265
|
aggregates;
|
|
250
266
|
/**
|
|
@@ -253,7 +269,7 @@ class $e {
|
|
|
253
269
|
*/
|
|
254
270
|
build() {
|
|
255
271
|
for (const [e, t] of Object.entries(this.openAPI.paths)) {
|
|
256
|
-
const o =
|
|
272
|
+
const o = ie(t);
|
|
257
273
|
for (const r of o)
|
|
258
274
|
this.commands(e, r), this.state(r.operation), this.events(r.operation), this.fields(r.operation);
|
|
259
275
|
}
|
|
@@ -282,32 +298,32 @@ class $e {
|
|
|
282
298
|
const o = t.operation;
|
|
283
299
|
if (o.operationId === "wow.command.send")
|
|
284
300
|
return;
|
|
285
|
-
const r =
|
|
301
|
+
const r = we(o.operationId);
|
|
286
302
|
if (!r)
|
|
287
303
|
return;
|
|
288
|
-
const s =
|
|
289
|
-
if (!s || !g(s) || s.$ref !==
|
|
304
|
+
const s = W(o);
|
|
305
|
+
if (!s || !g(s) || s.$ref !== $e || !o.requestBody)
|
|
290
306
|
return;
|
|
291
|
-
const
|
|
307
|
+
const i = o.parameters ?? [], c = i.filter((u) => g(u) && u.$ref === xe).at(0), a = i.filter(
|
|
292
308
|
(u) => !g(u) && u.in === "path"
|
|
293
309
|
);
|
|
294
310
|
if (c) {
|
|
295
|
-
const u =
|
|
311
|
+
const u = X(
|
|
296
312
|
c,
|
|
297
313
|
this.openAPI.components
|
|
298
314
|
);
|
|
299
|
-
|
|
315
|
+
a.push(u);
|
|
300
316
|
}
|
|
301
317
|
const m = o.requestBody.content[S.APPLICATION_JSON].schema, l = C(
|
|
302
318
|
m,
|
|
303
319
|
this.openAPI.components
|
|
304
320
|
);
|
|
305
321
|
l.schema.title = l.schema.title || o.summary, l.schema.description = l.schema.description || o.description;
|
|
306
|
-
const
|
|
322
|
+
const Q = {
|
|
307
323
|
name: r,
|
|
308
324
|
method: t.method,
|
|
309
325
|
path: e,
|
|
310
|
-
pathParameters:
|
|
326
|
+
pathParameters: a,
|
|
311
327
|
summary: o.summary,
|
|
312
328
|
description: o.description,
|
|
313
329
|
schema: l,
|
|
@@ -315,7 +331,7 @@ class $e {
|
|
|
315
331
|
};
|
|
316
332
|
o.tags?.forEach((u) => {
|
|
317
333
|
const D = this.aggregates.get(u);
|
|
318
|
-
D && D.commands.set(r,
|
|
334
|
+
D && D.commands.set(r, Q);
|
|
319
335
|
});
|
|
320
336
|
}
|
|
321
337
|
/**
|
|
@@ -325,7 +341,7 @@ class $e {
|
|
|
325
341
|
state(e) {
|
|
326
342
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
327
343
|
return;
|
|
328
|
-
const t =
|
|
344
|
+
const t = M(e);
|
|
329
345
|
if (!g(t))
|
|
330
346
|
return;
|
|
331
347
|
const o = C(
|
|
@@ -344,7 +360,7 @@ class $e {
|
|
|
344
360
|
events(e) {
|
|
345
361
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
346
362
|
return;
|
|
347
|
-
const t =
|
|
363
|
+
const t = M(e);
|
|
348
364
|
if (g(t))
|
|
349
365
|
return;
|
|
350
366
|
const o = t?.items;
|
|
@@ -353,21 +369,21 @@ class $e {
|
|
|
353
369
|
const s = I(
|
|
354
370
|
o,
|
|
355
371
|
this.openAPI.components
|
|
356
|
-
).properties.body.items.anyOf.map((
|
|
357
|
-
const c =
|
|
372
|
+
).properties.body.items.anyOf.map((i) => {
|
|
373
|
+
const c = i.title, a = i.properties.name.const, p = i.properties.body, m = C(
|
|
358
374
|
p,
|
|
359
375
|
this.openAPI.components
|
|
360
376
|
);
|
|
361
|
-
return m.schema.title = m.schema.title ||
|
|
377
|
+
return m.schema.title = m.schema.title || i.title, {
|
|
362
378
|
title: c,
|
|
363
|
-
name:
|
|
379
|
+
name: a,
|
|
364
380
|
schema: m
|
|
365
381
|
};
|
|
366
382
|
});
|
|
367
|
-
e.tags?.forEach((
|
|
368
|
-
const c = this.aggregates.get(
|
|
369
|
-
c && s.forEach((
|
|
370
|
-
c.events.set(
|
|
383
|
+
e.tags?.forEach((i) => {
|
|
384
|
+
const c = this.aggregates.get(i);
|
|
385
|
+
c && s.forEach((a) => {
|
|
386
|
+
c.events.set(a.name, a);
|
|
371
387
|
});
|
|
372
388
|
});
|
|
373
389
|
}
|
|
@@ -378,20 +394,20 @@ class $e {
|
|
|
378
394
|
fields(e) {
|
|
379
395
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
380
396
|
return;
|
|
381
|
-
const o =
|
|
397
|
+
const o = Y(
|
|
382
398
|
e.requestBody,
|
|
383
399
|
this.openAPI.components
|
|
384
400
|
).content[S.APPLICATION_JSON].schema, s = I(
|
|
385
401
|
o,
|
|
386
402
|
this.openAPI.components
|
|
387
|
-
).properties?.field,
|
|
403
|
+
).properties?.field, i = C(s, this.openAPI.components);
|
|
388
404
|
e.tags?.forEach((c) => {
|
|
389
|
-
const
|
|
390
|
-
|
|
405
|
+
const a = this.aggregates.get(c);
|
|
406
|
+
a && (a.fields = i);
|
|
391
407
|
});
|
|
392
408
|
}
|
|
393
409
|
}
|
|
394
|
-
const A = "@ahoo-wang/fetcher-wow",
|
|
410
|
+
const A = "@ahoo-wang/fetcher-wow", Ee = {
|
|
395
411
|
"wow.command.CommandResult": "CommandResult",
|
|
396
412
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
397
413
|
"wow.api.BindingError": "BindingError",
|
|
@@ -423,20 +439,20 @@ const A = "@ahoo-wang/fetcher-wow", we = {
|
|
|
423
439
|
function d(n) {
|
|
424
440
|
if (!n)
|
|
425
441
|
return { name: "", path: "/" };
|
|
426
|
-
const e =
|
|
442
|
+
const e = Ee[n];
|
|
427
443
|
if (e)
|
|
428
444
|
return { name: e, path: A };
|
|
429
445
|
const t = n.split(".");
|
|
430
446
|
let o = -1;
|
|
431
|
-
for (let
|
|
432
|
-
if (t[
|
|
433
|
-
o =
|
|
447
|
+
for (let a = 0; a < t.length; a++)
|
|
448
|
+
if (t[a] && /^[A-Z]/.test(t[a])) {
|
|
449
|
+
o = a;
|
|
434
450
|
break;
|
|
435
451
|
}
|
|
436
452
|
if (o === -1)
|
|
437
453
|
return { name: n, path: "/" };
|
|
438
|
-
const r = t.slice(0, o), s = r.length > 0 ? `/${r.join("/")}` : "/",
|
|
439
|
-
return { name:
|
|
454
|
+
const r = t.slice(0, o), s = r.length > 0 ? `/${r.join("/")}` : "/", i = t.slice(o);
|
|
455
|
+
return { name: $(i), path: s };
|
|
440
456
|
}
|
|
441
457
|
class x {
|
|
442
458
|
/** The ts-morph project instance used for code generation */
|
|
@@ -457,12 +473,12 @@ class x {
|
|
|
457
473
|
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger;
|
|
458
474
|
}
|
|
459
475
|
}
|
|
460
|
-
class
|
|
476
|
+
class Se extends x {
|
|
461
477
|
constructor(e) {
|
|
462
478
|
super(e);
|
|
463
479
|
}
|
|
464
480
|
getOrCreateSourceFile(e) {
|
|
465
|
-
const t =
|
|
481
|
+
const t = he(e);
|
|
466
482
|
return T(this.project, this.outputDir, t);
|
|
467
483
|
}
|
|
468
484
|
/**
|
|
@@ -480,9 +496,7 @@ class xe extends x {
|
|
|
480
496
|
return;
|
|
481
497
|
}
|
|
482
498
|
const t = this.filterSchemas(e);
|
|
483
|
-
this.logger.progress(
|
|
484
|
-
`Generating models for ${t.length} schemas`
|
|
485
|
-
), t.forEach((o, r) => {
|
|
499
|
+
this.logger.progress(`Generating models for ${t.length} schemas`), t.forEach((o, r) => {
|
|
486
500
|
this.logger.progressWithCount(
|
|
487
501
|
r + 1,
|
|
488
502
|
t.length,
|
|
@@ -492,12 +506,10 @@ class xe extends x {
|
|
|
492
506
|
}), this.logger.success("Model generation completed");
|
|
493
507
|
}
|
|
494
508
|
filterSchemas(e) {
|
|
495
|
-
return Object.entries(e).map(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
})
|
|
500
|
-
).filter((t) => !this.isWowSchema(t.key));
|
|
509
|
+
return Object.entries(e).map(([t, o]) => ({
|
|
510
|
+
key: t,
|
|
511
|
+
schema: o
|
|
512
|
+
})).filter((t) => !this.isWowSchema(t.key));
|
|
501
513
|
}
|
|
502
514
|
isWowSchema(e) {
|
|
503
515
|
return e.startsWith("wow.");
|
|
@@ -521,12 +533,12 @@ class xe extends x {
|
|
|
521
533
|
s && P(s, t.title, t.description);
|
|
522
534
|
}
|
|
523
535
|
process(e, t, o) {
|
|
524
|
-
if (
|
|
536
|
+
if (le(o))
|
|
525
537
|
return t.addEnum({
|
|
526
538
|
name: e.name,
|
|
527
539
|
isExported: !0,
|
|
528
540
|
members: o.enum.filter((s) => typeof s == "string" && s.length > 0).map((s) => ({
|
|
529
|
-
name: s,
|
|
541
|
+
name: Z(s),
|
|
530
542
|
initializer: `'${s}'`
|
|
531
543
|
}))
|
|
532
544
|
});
|
|
@@ -539,10 +551,10 @@ class xe extends x {
|
|
|
539
551
|
e,
|
|
540
552
|
o,
|
|
541
553
|
r
|
|
542
|
-
) : (
|
|
543
|
-
if (g(
|
|
554
|
+
) : (q(o) && (o.anyOf || o.oneOf || o.allOf).forEach((i) => {
|
|
555
|
+
if (g(i)) {
|
|
544
556
|
const c = d(
|
|
545
|
-
f(
|
|
557
|
+
f(i)
|
|
546
558
|
);
|
|
547
559
|
O(
|
|
548
560
|
e,
|
|
@@ -555,7 +567,7 @@ class xe extends x {
|
|
|
555
567
|
this.processInterface(
|
|
556
568
|
t,
|
|
557
569
|
e,
|
|
558
|
-
|
|
570
|
+
i,
|
|
559
571
|
r
|
|
560
572
|
);
|
|
561
573
|
}), r);
|
|
@@ -573,18 +585,18 @@ class xe extends x {
|
|
|
573
585
|
);
|
|
574
586
|
}
|
|
575
587
|
processInterface(e, t, o, r) {
|
|
576
|
-
for (const [s,
|
|
588
|
+
for (const [s, i] of Object.entries(o.properties)) {
|
|
577
589
|
const c = this.resolvePropertyType(
|
|
578
590
|
t,
|
|
579
591
|
e,
|
|
580
592
|
s,
|
|
581
|
-
|
|
593
|
+
i
|
|
582
594
|
);
|
|
583
|
-
let
|
|
584
|
-
|
|
595
|
+
let a = r.getProperty(s);
|
|
596
|
+
a ? a.setType(c) : a = r.addProperty({
|
|
585
597
|
name: s,
|
|
586
598
|
type: c
|
|
587
|
-
}), g(
|
|
599
|
+
}), g(i) || P(a, i.title, i.description);
|
|
588
600
|
}
|
|
589
601
|
return r;
|
|
590
602
|
}
|
|
@@ -600,18 +612,18 @@ class xe extends x {
|
|
|
600
612
|
}
|
|
601
613
|
if (r.const)
|
|
602
614
|
return `'${r.const}'`;
|
|
603
|
-
if (
|
|
615
|
+
if (ge(r)) {
|
|
604
616
|
const s = this.resolvePropertyType(
|
|
605
617
|
e,
|
|
606
618
|
t,
|
|
607
619
|
o,
|
|
608
620
|
r.items
|
|
609
621
|
);
|
|
610
|
-
return
|
|
622
|
+
return ue(s);
|
|
611
623
|
}
|
|
612
|
-
if (r.type &&
|
|
624
|
+
if (r.type && ce(r.type))
|
|
613
625
|
return N(r.type);
|
|
614
|
-
if (
|
|
626
|
+
if (q(r))
|
|
615
627
|
return this.resolvePropertyCompositionType(
|
|
616
628
|
e,
|
|
617
629
|
t,
|
|
@@ -620,13 +632,13 @@ class xe extends x {
|
|
|
620
632
|
if (r.type === "object" && r.properties) {
|
|
621
633
|
const s = {
|
|
622
634
|
path: e.path,
|
|
623
|
-
name: `${e.name}${
|
|
624
|
-
},
|
|
635
|
+
name: `${e.name}${$(o)}`
|
|
636
|
+
}, i = this.processObject(
|
|
625
637
|
t,
|
|
626
638
|
s,
|
|
627
639
|
r
|
|
628
640
|
);
|
|
629
|
-
return P(
|
|
641
|
+
return P(i, r.title, r.description), s.name;
|
|
630
642
|
}
|
|
631
643
|
return "any";
|
|
632
644
|
}
|
|
@@ -634,37 +646,37 @@ class xe extends x {
|
|
|
634
646
|
const r = o.anyOf || o.oneOf || o.allOf, s = /* @__PURE__ */ new Set();
|
|
635
647
|
r.forEach((c) => {
|
|
636
648
|
if (g(c)) {
|
|
637
|
-
const
|
|
649
|
+
const a = d(
|
|
638
650
|
f(c)
|
|
639
651
|
);
|
|
640
652
|
O(
|
|
641
653
|
e,
|
|
642
654
|
t,
|
|
643
655
|
this.outputDir,
|
|
644
|
-
|
|
645
|
-
), s.add(
|
|
656
|
+
a
|
|
657
|
+
), s.add(a.name);
|
|
646
658
|
return;
|
|
647
659
|
}
|
|
648
660
|
s.add(N(c.type ?? "string"));
|
|
649
661
|
});
|
|
650
|
-
const
|
|
651
|
-
return Array.from(s).join(
|
|
662
|
+
const i = pe(o) ? "|" : "&";
|
|
663
|
+
return Array.from(s).join(i);
|
|
652
664
|
}
|
|
653
665
|
}
|
|
654
|
-
function
|
|
666
|
+
function Ie(n) {
|
|
655
667
|
let e = 0, t = 0;
|
|
656
668
|
return n.commands.forEach((o) => {
|
|
657
669
|
o.path.startsWith(b.TENANT) && (e += 1), o.path.startsWith(b.OWNER) && (t += 1);
|
|
658
670
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
659
671
|
}
|
|
660
|
-
function
|
|
672
|
+
function k(n, e, t, o) {
|
|
661
673
|
const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
|
|
662
674
|
return T(n, e, r);
|
|
663
675
|
}
|
|
664
|
-
function
|
|
665
|
-
return `${
|
|
676
|
+
function Ne(n, e) {
|
|
677
|
+
return `${$(n.aggregateName)}${e}`;
|
|
666
678
|
}
|
|
667
|
-
class
|
|
679
|
+
class Te extends x {
|
|
668
680
|
/**
|
|
669
681
|
* Creates a new QueryClientGenerator instance.
|
|
670
682
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -701,7 +713,7 @@ class Se extends x {
|
|
|
701
713
|
* @returns The source file for the client
|
|
702
714
|
*/
|
|
703
715
|
createClientFilePath(e, t) {
|
|
704
|
-
return
|
|
716
|
+
return k(
|
|
705
717
|
this.project,
|
|
706
718
|
this.outputDir,
|
|
707
719
|
e,
|
|
@@ -741,7 +753,7 @@ class Se extends x {
|
|
|
741
753
|
initializer: `{
|
|
742
754
|
contextAlias: '${e.aggregate.contextAlias}',
|
|
743
755
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
744
|
-
resourceAttribution: ${
|
|
756
|
+
resourceAttribution: ${Ie(e)},
|
|
745
757
|
}`
|
|
746
758
|
}
|
|
747
759
|
],
|
|
@@ -757,24 +769,24 @@ class Se extends x {
|
|
|
757
769
|
`Adding import for event model: ${l.name} from path: ${l.path}`
|
|
758
770
|
), y(t, this.outputDir, l), r.push(l);
|
|
759
771
|
}
|
|
760
|
-
const s = "DOMAIN_EVENT_TYPES",
|
|
772
|
+
const s = "DOMAIN_EVENT_TYPES", i = r.map((m) => m.name).join(" | ");
|
|
761
773
|
this.logger.info(
|
|
762
|
-
`Creating domain event types union: ${s} = ${
|
|
774
|
+
`Creating domain event types union: ${s} = ${i}`
|
|
763
775
|
), t.addTypeAlias({
|
|
764
776
|
name: s,
|
|
765
|
-
type:
|
|
777
|
+
type: i
|
|
766
778
|
});
|
|
767
|
-
const c = `${h(e.aggregate.aggregateName)}QueryClientFactory`,
|
|
779
|
+
const c = `${h(e.aggregate.aggregateName)}QueryClientFactory`, a = d(e.state.key), p = d(e.fields.key);
|
|
768
780
|
this.logger.info(
|
|
769
|
-
`Adding import for state model: ${
|
|
770
|
-
), y(t, this.outputDir,
|
|
781
|
+
`Adding import for state model: ${a.name} from path: ${a.path}`
|
|
782
|
+
), y(t, this.outputDir, a), this.logger.info(
|
|
771
783
|
`Adding import for fields model: ${p.name} from path: ${p.path}`
|
|
772
784
|
), y(t, this.outputDir, p), this.logger.info(`Creating query client factory: ${c}`), t.addVariableStatement({
|
|
773
785
|
declarationKind: E.Const,
|
|
774
786
|
declarations: [
|
|
775
787
|
{
|
|
776
788
|
name: c,
|
|
777
|
-
initializer: `new QueryClientFactory<${
|
|
789
|
+
initializer: `new QueryClientFactory<${a.name}, ${p.name} | string, ${s}>(${o})`
|
|
778
790
|
}
|
|
779
791
|
],
|
|
780
792
|
isExported: !0
|
|
@@ -783,7 +795,7 @@ class Se extends x {
|
|
|
783
795
|
);
|
|
784
796
|
}
|
|
785
797
|
}
|
|
786
|
-
class
|
|
798
|
+
class De extends x {
|
|
787
799
|
commandEndpointPathsName = "COMMAND_ENDPOINT_PATHS";
|
|
788
800
|
defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
789
801
|
/**
|
|
@@ -823,7 +835,7 @@ class Ie extends x {
|
|
|
823
835
|
this.logger.info(
|
|
824
836
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
825
837
|
);
|
|
826
|
-
const t =
|
|
838
|
+
const t = k(
|
|
827
839
|
this.project,
|
|
828
840
|
this.outputDir,
|
|
829
841
|
e.aggregate,
|
|
@@ -864,9 +876,9 @@ class Ie extends x {
|
|
|
864
876
|
namedImports: ["JsonEventStreamResultExtractor"]
|
|
865
877
|
}), this.logger.info(
|
|
866
878
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
867
|
-
),
|
|
879
|
+
), w(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.logger.info(
|
|
868
880
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
869
|
-
),
|
|
881
|
+
), w(t, "@ahoo-wang/fetcher-decorator", [
|
|
870
882
|
"type ApiMetadata",
|
|
871
883
|
"type ApiMetadataCapable",
|
|
872
884
|
"api",
|
|
@@ -907,7 +919,7 @@ class Ie extends x {
|
|
|
907
919
|
let r = "CommandClient", s = {
|
|
908
920
|
name: "api",
|
|
909
921
|
arguments: []
|
|
910
|
-
},
|
|
922
|
+
}, i = "Promise<CommandResult>";
|
|
911
923
|
o && (r = "Stream" + r, s = {
|
|
912
924
|
name: "api",
|
|
913
925
|
arguments: [
|
|
@@ -917,28 +929,28 @@ class Ie extends x {
|
|
|
917
929
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
918
930
|
}`
|
|
919
931
|
]
|
|
920
|
-
},
|
|
921
|
-
const c =
|
|
932
|
+
}, i = "Promise<CommandResultEventStream>");
|
|
933
|
+
const c = Ne(
|
|
922
934
|
t.aggregate,
|
|
923
935
|
r
|
|
924
|
-
),
|
|
936
|
+
), a = e.addClass({
|
|
925
937
|
name: c,
|
|
926
938
|
isExported: !0,
|
|
927
939
|
decorators: [s],
|
|
928
940
|
implements: ["ApiMetadataCapable"]
|
|
929
941
|
});
|
|
930
|
-
|
|
942
|
+
a.addConstructor({
|
|
931
943
|
parameters: [
|
|
932
944
|
{
|
|
933
945
|
name: "apiMetadata",
|
|
934
946
|
type: "ApiMetadata",
|
|
935
|
-
scope:
|
|
947
|
+
scope: L.Public,
|
|
936
948
|
isReadonly: !0,
|
|
937
949
|
initializer: `${this.defaultCommandClientOptionsName}`
|
|
938
950
|
}
|
|
939
951
|
]
|
|
940
952
|
}), t.commands.forEach((p) => {
|
|
941
|
-
this.processCommandMethod(e,
|
|
953
|
+
this.processCommandMethod(e, a, p, i);
|
|
942
954
|
});
|
|
943
955
|
}
|
|
944
956
|
methodToDecorator(e) {
|
|
@@ -959,24 +971,24 @@ class Ie extends x {
|
|
|
959
971
|
), this.logger.info(
|
|
960
972
|
`Command method details: HTTP ${o.method}, path: ${o.path}, return type: ${r}`
|
|
961
973
|
);
|
|
962
|
-
const
|
|
963
|
-
`Adding path parameter: ${
|
|
974
|
+
const i = o.pathParameters.map((a) => (this.logger.info(
|
|
975
|
+
`Adding path parameter: ${a.name} (type: string)`
|
|
964
976
|
), {
|
|
965
|
-
name:
|
|
977
|
+
name: a.name,
|
|
966
978
|
type: "string",
|
|
967
979
|
hasQuestionToken: !1,
|
|
968
980
|
decorators: [
|
|
969
981
|
{
|
|
970
982
|
name: "path",
|
|
971
|
-
arguments: [`'${
|
|
983
|
+
arguments: [`'${a.name}'`]
|
|
972
984
|
}
|
|
973
985
|
]
|
|
974
986
|
}));
|
|
975
987
|
this.logger.info(
|
|
976
988
|
`Adding command request parameter: commandRequest (type: CommandRequest<${s.name}>)`
|
|
977
|
-
),
|
|
989
|
+
), i.push({
|
|
978
990
|
name: "commandRequest",
|
|
979
|
-
hasQuestionToken:
|
|
991
|
+
hasQuestionToken: de(o.schema.schema),
|
|
980
992
|
type: `CommandRequest<${s.name}>`,
|
|
981
993
|
decorators: [
|
|
982
994
|
{
|
|
@@ -986,7 +998,7 @@ class Ie extends x {
|
|
|
986
998
|
]
|
|
987
999
|
}), this.logger.info(
|
|
988
1000
|
"Adding attributes parameter: attributes (type: Record<string, any>)"
|
|
989
|
-
),
|
|
1001
|
+
), i.push({
|
|
990
1002
|
name: "attributes",
|
|
991
1003
|
hasQuestionToken: !0,
|
|
992
1004
|
type: "Record<string, any>",
|
|
@@ -1005,10 +1017,10 @@ class Ie extends x {
|
|
|
1005
1017
|
arguments: [`${this.getEndpointPath(o)}`]
|
|
1006
1018
|
}
|
|
1007
1019
|
],
|
|
1008
|
-
parameters:
|
|
1020
|
+
parameters: i,
|
|
1009
1021
|
returnType: r,
|
|
1010
1022
|
statements: [
|
|
1011
|
-
`throw autoGeneratedError(${
|
|
1023
|
+
`throw autoGeneratedError(${i.map((a) => a.name).join(",")});`
|
|
1012
1024
|
]
|
|
1013
1025
|
});
|
|
1014
1026
|
(o.summary || o.description) && this.logger.info(
|
|
@@ -1018,7 +1030,7 @@ class Ie extends x {
|
|
|
1018
1030
|
);
|
|
1019
1031
|
}
|
|
1020
1032
|
}
|
|
1021
|
-
class
|
|
1033
|
+
class ve extends x {
|
|
1022
1034
|
queryClientGenerator;
|
|
1023
1035
|
commandClientGenerator;
|
|
1024
1036
|
/**
|
|
@@ -1026,7 +1038,7 @@ class Ne extends x {
|
|
|
1026
1038
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1027
1039
|
*/
|
|
1028
1040
|
constructor(e) {
|
|
1029
|
-
super(e), this.queryClientGenerator = new
|
|
1041
|
+
super(e), this.queryClientGenerator = new Te(e), this.commandClientGenerator = new De(e);
|
|
1030
1042
|
}
|
|
1031
1043
|
/**
|
|
1032
1044
|
* Generates client classes for all aggregates.
|
|
@@ -1062,7 +1074,7 @@ class Ne extends x {
|
|
|
1062
1074
|
);
|
|
1063
1075
|
}
|
|
1064
1076
|
}
|
|
1065
|
-
class
|
|
1077
|
+
class Fe {
|
|
1066
1078
|
/**
|
|
1067
1079
|
* Creates a new CodeGenerator instance.
|
|
1068
1080
|
* @param options - Configuration options for code generation
|
|
@@ -1080,9 +1092,9 @@ class Me {
|
|
|
1080
1092
|
this.options.logger.info(
|
|
1081
1093
|
"Starting code generation from OpenAPI specification"
|
|
1082
1094
|
), 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");
|
|
1083
|
-
const e = await
|
|
1095
|
+
const e = await ne(this.options.inputPath);
|
|
1084
1096
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1085
|
-
const o = new
|
|
1097
|
+
const o = new Oe(e).resolve();
|
|
1086
1098
|
this.options.logger.info(
|
|
1087
1099
|
`Resolved ${o.size} bounded context aggregates`
|
|
1088
1100
|
);
|
|
@@ -1093,7 +1105,7 @@ class Me {
|
|
|
1093
1105
|
contextAggregates: o,
|
|
1094
1106
|
logger: this.options.logger
|
|
1095
1107
|
};
|
|
1096
|
-
this.options.logger.info("Generating models"), new
|
|
1108
|
+
this.options.logger.info("Generating models"), new Se(r).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ve(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");
|
|
1097
1109
|
}
|
|
1098
1110
|
/**
|
|
1099
1111
|
* Generates index.ts files for all subdirectories in the output directory.
|
|
@@ -1132,8 +1144,8 @@ class Me {
|
|
|
1132
1144
|
let r = [];
|
|
1133
1145
|
try {
|
|
1134
1146
|
r = v.readdirSync(t).filter((c) => {
|
|
1135
|
-
const
|
|
1136
|
-
return v.statSync(
|
|
1147
|
+
const a = J.join(t, c);
|
|
1148
|
+
return v.statSync(a).isDirectory();
|
|
1137
1149
|
});
|
|
1138
1150
|
} catch (c) {
|
|
1139
1151
|
this.options.logger.error(
|
|
@@ -1150,22 +1162,22 @@ class Me {
|
|
|
1150
1162
|
}
|
|
1151
1163
|
const s = `${t}/index.ts`;
|
|
1152
1164
|
this.options.logger.info(`Creating/updating index file: ${s}`);
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1165
|
+
const i = this.project.getSourceFile(s) || this.project.createSourceFile(s, "", { overwrite: !0 });
|
|
1166
|
+
i.removeText();
|
|
1155
1167
|
for (const c of o) {
|
|
1156
|
-
const
|
|
1157
|
-
this.options.logger.info(`Adding export for file: ${
|
|
1158
|
-
moduleSpecifier:
|
|
1168
|
+
const a = `./${c.getBaseNameWithoutExtension()}`;
|
|
1169
|
+
this.options.logger.info(`Adding export for file: ${a}`), i.addExportDeclaration({
|
|
1170
|
+
moduleSpecifier: a,
|
|
1159
1171
|
isTypeOnly: !1,
|
|
1160
1172
|
namedExports: []
|
|
1161
1173
|
});
|
|
1162
1174
|
}
|
|
1163
1175
|
for (const c of r) {
|
|
1164
|
-
const
|
|
1176
|
+
const a = `./${c}`;
|
|
1165
1177
|
this.options.logger.info(
|
|
1166
|
-
`Adding export for subdirectory: ${
|
|
1167
|
-
),
|
|
1168
|
-
moduleSpecifier:
|
|
1178
|
+
`Adding export for subdirectory: ${a}`
|
|
1179
|
+
), i.addExportDeclaration({
|
|
1180
|
+
moduleSpecifier: a,
|
|
1169
1181
|
isTypeOnly: !1,
|
|
1170
1182
|
namedExports: []
|
|
1171
1183
|
});
|
|
@@ -1184,6 +1196,6 @@ class Me {
|
|
|
1184
1196
|
}
|
|
1185
1197
|
}
|
|
1186
1198
|
export {
|
|
1187
|
-
|
|
1199
|
+
Fe as CodeGenerator
|
|
1188
1200
|
};
|
|
1189
1201
|
//# sourceMappingURL=index.js.map
|