@ahoo-wang/fetcher-generator 2.15.9 → 2.16.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/client/clientGenerator.d.ts +0 -5
- package/dist/client/clientGenerator.d.ts.map +1 -1
- package/dist/client/commandClientGenerator.d.ts +7 -6
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/client/queryClientGenerator.d.ts +3 -0
- package/dist/client/queryClientGenerator.d.ts.map +1 -1
- package/dist/client/utils.d.ts +1 -21
- package/dist/client/utils.d.ts.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +281 -262
- package/dist/index.js.map +1 -1
- package/dist/model/modelGenerator.d.ts +1 -0
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Scope as
|
|
2
|
-
import { ContentTypeValues as
|
|
1
|
+
import { Scope as fe, VariableDeclarationKind as D, Project as he } from "ts-morph";
|
|
2
|
+
import { ContentTypeValues as T, combineURLs as v } from "@ahoo-wang/fetcher";
|
|
3
3
|
import { ResourceAttributionPathSpec as W } from "@ahoo-wang/fetcher-wow";
|
|
4
4
|
import { parse as V } from "yaml";
|
|
5
|
-
import { readFile as
|
|
6
|
-
import { join as
|
|
7
|
-
function
|
|
5
|
+
import { readFile as ye } from "fs";
|
|
6
|
+
import { join as xe, relative as Ae } from "path";
|
|
7
|
+
function C(n) {
|
|
8
8
|
return n.$ref.split("/").pop();
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
const t =
|
|
10
|
+
function I(n, e) {
|
|
11
|
+
const t = C(n);
|
|
12
12
|
return e.schemas?.[t];
|
|
13
13
|
}
|
|
14
14
|
function H(n, e) {
|
|
15
|
-
const t =
|
|
15
|
+
const t = C(n);
|
|
16
16
|
return e.requestBodies?.[t];
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const t =
|
|
18
|
+
function K(n, e) {
|
|
19
|
+
const t = C(n);
|
|
20
20
|
return e.parameters?.[t];
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function P(n, e) {
|
|
23
23
|
return {
|
|
24
|
-
key:
|
|
25
|
-
schema:
|
|
24
|
+
key: C(n),
|
|
25
|
+
schema: I(n, e)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
return n.split(
|
|
28
|
+
const Ce = /[-_\s.]+/;
|
|
29
|
+
function O(n) {
|
|
30
|
+
return n.split(Ce);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return Array.isArray(n) ? n.flatMap((e) => k(
|
|
32
|
+
function Y(n) {
|
|
33
|
+
return Array.isArray(n) ? n.flatMap((e) => k(O(e))) : k(O(n));
|
|
34
34
|
}
|
|
35
35
|
function k(n) {
|
|
36
36
|
return n.flatMap((e) => {
|
|
@@ -46,17 +46,17 @@ function k(n) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
function S(n) {
|
|
49
|
-
return n === "" || n.length === 0 ? "" :
|
|
49
|
+
return n === "" || n.length === 0 ? "" : Y(n).filter((t) => t.length > 0).map((t) => {
|
|
50
50
|
const o = t.charAt(0), r = t.slice(1);
|
|
51
51
|
return (/[a-zA-Z]/.test(o) ? o.toUpperCase() : o) + r.toLowerCase();
|
|
52
52
|
}).join("");
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function f(n) {
|
|
55
55
|
const e = S(n);
|
|
56
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return n === "" || Array.isArray(n) && n.length === 0 ? "" :
|
|
58
|
+
function X(n) {
|
|
59
|
+
return n === "" || Array.isArray(n) && n.length === 0 ? "" : Y(n).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
60
|
}
|
|
61
61
|
function g(n) {
|
|
62
62
|
return !!(n && typeof n == "object" && "$ref" in n);
|
|
@@ -65,58 +65,58 @@ function j(n, e) {
|
|
|
65
65
|
if (e && !g(e) && e.content)
|
|
66
66
|
return e.content[n]?.schema;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
return j(
|
|
68
|
+
function Z(n) {
|
|
69
|
+
return j(T.APPLICATION_JSON, n);
|
|
70
70
|
}
|
|
71
71
|
function Pe(n) {
|
|
72
|
-
return j(
|
|
72
|
+
return j(T.TEXT_EVENT_STREAM, n);
|
|
73
73
|
}
|
|
74
74
|
function $e(n) {
|
|
75
75
|
return j("*/*", n);
|
|
76
76
|
}
|
|
77
|
-
const
|
|
77
|
+
const Te = [
|
|
78
78
|
"string",
|
|
79
79
|
"number",
|
|
80
80
|
"integer",
|
|
81
81
|
"boolean",
|
|
82
82
|
"null"
|
|
83
83
|
];
|
|
84
|
-
function
|
|
85
|
-
return Array.isArray(n) ? !0 :
|
|
84
|
+
function ee(n) {
|
|
85
|
+
return Array.isArray(n) ? !0 : Te.includes(n);
|
|
86
86
|
}
|
|
87
87
|
function z(n) {
|
|
88
88
|
return Array.isArray(n.enum) && n.enum.length > 0;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function w(n) {
|
|
91
91
|
return n.type === "object" && !!n.properties;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function N(n) {
|
|
94
94
|
return n.type === "array" && !!n.items;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function ve(n) {
|
|
97
97
|
return Array.isArray(n.anyOf) && n.anyOf.length > 0;
|
|
98
98
|
}
|
|
99
|
-
function
|
|
99
|
+
function Ie(n) {
|
|
100
100
|
return Array.isArray(n.oneOf) && n.oneOf.length > 0;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function b(n) {
|
|
103
103
|
return Array.isArray(n.allOf) && n.allOf.length > 0;
|
|
104
104
|
}
|
|
105
105
|
function L(n) {
|
|
106
|
-
return
|
|
106
|
+
return ve(n) || Ie(n) || b(n);
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function Ee(n) {
|
|
109
109
|
return n.includes("|") || n.includes("&") ? `(${n})[]` : `${n}[]`;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function Se(n) {
|
|
112
112
|
return n.type === "object" && !n.properties && n.additionalProperties !== void 0;
|
|
113
113
|
}
|
|
114
114
|
function Re(n) {
|
|
115
115
|
return n.type !== "object" ? !1 : n.properties ? Object.keys(n.properties).length === 0 : !0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function R(n) {
|
|
118
118
|
if (Array.isArray(n))
|
|
119
|
-
return n.map((e) =>
|
|
119
|
+
return n.map((e) => R(e)).join(" | ");
|
|
120
120
|
switch (n) {
|
|
121
121
|
case "string":
|
|
122
122
|
return "string";
|
|
@@ -136,10 +136,10 @@ function we(n, e) {
|
|
|
136
136
|
e.operation.operationId
|
|
137
137
|
) : n.path && e.path ? n.path.localeCompare(e.path) : n.method && e.method ? n.method.localeCompare(e.method) : 0;
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function te(n) {
|
|
140
140
|
const e = [];
|
|
141
141
|
for (const [t, o] of Object.entries(n))
|
|
142
|
-
|
|
142
|
+
ne(o).forEach((r) => {
|
|
143
143
|
e.push({
|
|
144
144
|
method: r.method,
|
|
145
145
|
operation: r.operation,
|
|
@@ -148,7 +148,7 @@ function ee(n) {
|
|
|
148
148
|
});
|
|
149
149
|
return e.sort(we);
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function ne(n) {
|
|
152
152
|
return [
|
|
153
153
|
{ method: "get", operation: n.get },
|
|
154
154
|
{ method: "put", operation: n.put },
|
|
@@ -160,36 +160,36 @@ function te(n) {
|
|
|
160
160
|
{ method: "trace", operation: n.trace }
|
|
161
161
|
].filter(({ operation: e }) => e !== void 0);
|
|
162
162
|
}
|
|
163
|
-
function
|
|
163
|
+
function G(n) {
|
|
164
164
|
return n.responses[200];
|
|
165
165
|
}
|
|
166
166
|
function B(n) {
|
|
167
|
-
const e =
|
|
168
|
-
return
|
|
167
|
+
const e = G(n);
|
|
168
|
+
return Z(e);
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
return n.parameters ? n.parameters.map((t) => g(t) ?
|
|
172
|
-
}
|
|
173
|
-
const Ne = "string";
|
|
174
|
-
function ne(n) {
|
|
175
|
-
return !n.schema || g(n.schema) || !n.schema.type || !Z(n.schema.type) ? Ne : E(n.schema.type);
|
|
170
|
+
function De(n, e) {
|
|
171
|
+
return n.parameters ? n.parameters.map((t) => g(t) ? K(t, e) : t).filter((t) => t.in === "path") : [];
|
|
176
172
|
}
|
|
173
|
+
const Oe = "string";
|
|
177
174
|
function oe(n) {
|
|
178
|
-
return n.
|
|
175
|
+
return !n.schema || g(n.schema) || !n.schema.type || !ee(n.schema.type) ? Oe : R(n.schema.type);
|
|
176
|
+
}
|
|
177
|
+
function re(n) {
|
|
178
|
+
return n.startsWith("http://") || n.startsWith("https://") ? Ne(n) : be(n);
|
|
179
179
|
}
|
|
180
|
-
async function
|
|
180
|
+
async function Ne(n) {
|
|
181
181
|
return await (await fetch(n)).text();
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function be(n) {
|
|
184
184
|
return new Promise((e, t) => {
|
|
185
|
-
|
|
185
|
+
ye(n, "utf-8", (o, r) => {
|
|
186
186
|
o ? t(o) : e(r);
|
|
187
187
|
});
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
async function
|
|
191
|
-
const e = await
|
|
192
|
-
switch (
|
|
190
|
+
async function Me(n) {
|
|
191
|
+
const e = await re(n);
|
|
192
|
+
switch (ie(e)) {
|
|
193
193
|
case "json":
|
|
194
194
|
return JSON.parse(e);
|
|
195
195
|
case "yaml":
|
|
@@ -199,8 +199,8 @@ async function be(n) {
|
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
async function qe(n) {
|
|
202
|
-
const e = await
|
|
203
|
-
switch (
|
|
202
|
+
const e = await re(n);
|
|
203
|
+
switch (ie(e)) {
|
|
204
204
|
case "json":
|
|
205
205
|
return JSON.parse(e);
|
|
206
206
|
case "yaml":
|
|
@@ -209,7 +209,7 @@ async function qe(n) {
|
|
|
209
209
|
throw new Error(`Unsupported file format: ${n}`);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
function
|
|
212
|
+
function ie(n) {
|
|
213
213
|
const e = n.trimStart();
|
|
214
214
|
if (e.startsWith("{") || e.startsWith("["))
|
|
215
215
|
return "json";
|
|
@@ -223,17 +223,17 @@ function re(n) {
|
|
|
223
223
|
}
|
|
224
224
|
throw new Error("Unable to infer file format");
|
|
225
225
|
}
|
|
226
|
-
const
|
|
226
|
+
const se = "types.ts", Fe = "@";
|
|
227
227
|
function je(n) {
|
|
228
|
-
return
|
|
228
|
+
return v(n.path, se);
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
const o =
|
|
230
|
+
function ae(n, e, t) {
|
|
231
|
+
const o = v(e, t), r = n.getSourceFile(o);
|
|
232
232
|
return r || n.createSourceFile(o, "", {
|
|
233
233
|
overwrite: !0
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function x(n, e, t) {
|
|
237
237
|
let o = n.getImportDeclaration(
|
|
238
238
|
(r) => r.getModuleSpecifierValue() === e
|
|
239
239
|
);
|
|
@@ -245,19 +245,19 @@ function y(n, e, t) {
|
|
|
245
245
|
) || o.addNamedImport(r);
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
|
-
function
|
|
248
|
+
function d(n, e, t) {
|
|
249
249
|
if (t.path.startsWith(Fe)) {
|
|
250
|
-
|
|
250
|
+
x(n, t.path, [t.name]);
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
|
-
const o = n.getDirectoryPath(), r =
|
|
254
|
-
let i =
|
|
255
|
-
i = i.replace(/\.ts$/, ""), i.startsWith(".") || (i = "./" + i),
|
|
253
|
+
const o = n.getDirectoryPath(), r = xe(e, t.path, se);
|
|
254
|
+
let i = Ae(o, r);
|
|
255
|
+
i = i.replace(/\.ts$/, ""), i.startsWith(".") || (i = "./" + i), x(n, i, [t.name]);
|
|
256
256
|
}
|
|
257
|
-
function
|
|
258
|
-
n.path !== o.path &&
|
|
257
|
+
function Ge(n, e, t, o) {
|
|
258
|
+
n.path !== o.path && d(e, t, o);
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function ce(n, e = `
|
|
261
261
|
`) {
|
|
262
262
|
if (!Array.isArray(n))
|
|
263
263
|
return;
|
|
@@ -266,20 +266,20 @@ function ae(n, e = `
|
|
|
266
266
|
);
|
|
267
267
|
return t.length > 0 ? t.join(e) : void 0;
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
const t =
|
|
269
|
+
function E(n, e) {
|
|
270
|
+
const t = ce(e);
|
|
271
271
|
t && n.addJsDoc(t);
|
|
272
272
|
}
|
|
273
|
-
function
|
|
273
|
+
function ge(n, e) {
|
|
274
274
|
const t = [
|
|
275
275
|
n.title,
|
|
276
276
|
n.description
|
|
277
277
|
];
|
|
278
|
-
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), U(t, n, "default"), U(t, n, "example"),
|
|
278
|
+
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), U(t, n, "default"), U(t, n, "example"), _e(t, n), We(t, n), ke(t, n), t;
|
|
279
279
|
}
|
|
280
280
|
function Q(n, e, t) {
|
|
281
|
-
const o =
|
|
282
|
-
|
|
281
|
+
const o = ge(e, t);
|
|
282
|
+
E(n, o);
|
|
283
283
|
}
|
|
284
284
|
function U(n, e, t) {
|
|
285
285
|
const o = e[t];
|
|
@@ -291,7 +291,7 @@ function U(n, e, t) {
|
|
|
291
291
|
n.push(`- ${t}: `), n.push("```json"), n.push(JSON.stringify(o)), n.push("```");
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
function
|
|
294
|
+
function _e(n, e) {
|
|
295
295
|
const t = ["- Numeric Constraints"];
|
|
296
296
|
e.minimum !== void 0 && t.push(` - minimum: ${e.minimum}`), e.maximum !== void 0 && t.push(` - maximum: ${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(
|
|
297
297
|
` - exclusiveMinimum: ${e.exclusiveMinimum}`
|
|
@@ -353,7 +353,7 @@ class Ve {
|
|
|
353
353
|
* @private
|
|
354
354
|
*/
|
|
355
355
|
build() {
|
|
356
|
-
const e =
|
|
356
|
+
const e = te(this.openAPI.paths);
|
|
357
357
|
for (const t of e)
|
|
358
358
|
this.commands(t.path, t), this.state(t.operation), this.events(t.operation), this.fields(t.operation);
|
|
359
359
|
}
|
|
@@ -384,37 +384,37 @@ class Ve {
|
|
|
384
384
|
const r = Qe(o.operationId);
|
|
385
385
|
if (!r)
|
|
386
386
|
return;
|
|
387
|
-
const i =
|
|
387
|
+
const i = G(o);
|
|
388
388
|
if (!i || !g(i) || i.$ref !== Ue || !o.requestBody)
|
|
389
389
|
return;
|
|
390
|
-
const s = o.parameters ?? [], a = s.filter((
|
|
391
|
-
(
|
|
390
|
+
const s = o.parameters ?? [], a = s.filter((u) => g(u) && u.$ref === Je).at(0), c = s.filter(
|
|
391
|
+
(u) => !g(u) && u.in === "path"
|
|
392
392
|
);
|
|
393
393
|
if (a) {
|
|
394
|
-
const
|
|
394
|
+
const u = K(
|
|
395
395
|
a,
|
|
396
396
|
this.openAPI.components
|
|
397
397
|
);
|
|
398
|
-
c.push(
|
|
398
|
+
c.push(u);
|
|
399
399
|
}
|
|
400
|
-
const p = o.requestBody.content[
|
|
400
|
+
const p = o.requestBody.content[T.APPLICATION_JSON].schema, y = P(
|
|
401
401
|
p,
|
|
402
402
|
this.openAPI.components
|
|
403
403
|
);
|
|
404
|
-
|
|
405
|
-
const
|
|
404
|
+
y.schema.title = y.schema.title || o.summary, y.schema.description = y.schema.description || o.description;
|
|
405
|
+
const me = {
|
|
406
406
|
name: r,
|
|
407
407
|
method: t.method,
|
|
408
408
|
path: e,
|
|
409
409
|
pathParameters: c,
|
|
410
410
|
summary: o.summary,
|
|
411
411
|
description: o.description,
|
|
412
|
-
schema:
|
|
412
|
+
schema: y,
|
|
413
413
|
operation: o
|
|
414
414
|
};
|
|
415
|
-
o.tags?.forEach((
|
|
416
|
-
const
|
|
417
|
-
|
|
415
|
+
o.tags?.forEach((u) => {
|
|
416
|
+
const _ = this.aggregates.get(u);
|
|
417
|
+
_ && _.commands.set(r, me);
|
|
418
418
|
});
|
|
419
419
|
}
|
|
420
420
|
/**
|
|
@@ -427,7 +427,7 @@ class Ve {
|
|
|
427
427
|
const t = B(e);
|
|
428
428
|
if (!g(t))
|
|
429
429
|
return;
|
|
430
|
-
const o =
|
|
430
|
+
const o = P(
|
|
431
431
|
t,
|
|
432
432
|
this.openAPI.components
|
|
433
433
|
);
|
|
@@ -449,12 +449,12 @@ class Ve {
|
|
|
449
449
|
const o = t?.items;
|
|
450
450
|
if (!g(o))
|
|
451
451
|
return;
|
|
452
|
-
const i =
|
|
452
|
+
const i = I(
|
|
453
453
|
o,
|
|
454
454
|
this.openAPI.components
|
|
455
455
|
).properties.body.items.anyOf.map((s) => {
|
|
456
|
-
const a = s.title, c = s.properties.name.const,
|
|
457
|
-
|
|
456
|
+
const a = s.title, c = s.properties.name.const, m = s.properties.body, p = P(
|
|
457
|
+
m,
|
|
458
458
|
this.openAPI.components
|
|
459
459
|
);
|
|
460
460
|
return p.schema.title = p.schema.title || s.title, {
|
|
@@ -480,17 +480,17 @@ class Ve {
|
|
|
480
480
|
const o = H(
|
|
481
481
|
e.requestBody,
|
|
482
482
|
this.openAPI.components
|
|
483
|
-
).content[
|
|
483
|
+
).content[T.APPLICATION_JSON].schema, i = I(
|
|
484
484
|
o,
|
|
485
485
|
this.openAPI.components
|
|
486
|
-
).properties?.field, s =
|
|
486
|
+
).properties?.field, s = P(i, this.openAPI.components);
|
|
487
487
|
e.tags?.forEach((a) => {
|
|
488
488
|
const c = this.aggregates.get(a);
|
|
489
489
|
c && (c.fields = s);
|
|
490
490
|
});
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
|
-
const
|
|
493
|
+
const A = "@ahoo-wang/fetcher-wow", He = {
|
|
494
494
|
"wow.command.CommandResult": "CommandResult",
|
|
495
495
|
"wow.command.CommandResultArray": "CommandResultArray",
|
|
496
496
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
@@ -520,12 +520,12 @@ const x = "@ahoo-wang/fetcher-wow", He = {
|
|
|
520
520
|
"wow.openapi.BatchResult": "BatchResult",
|
|
521
521
|
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
522
522
|
};
|
|
523
|
-
function
|
|
523
|
+
function l(n) {
|
|
524
524
|
if (!n)
|
|
525
525
|
return { name: "", path: "/" };
|
|
526
526
|
const e = He[n];
|
|
527
527
|
if (e)
|
|
528
|
-
return { name: e, path:
|
|
528
|
+
return { name: e, path: A };
|
|
529
529
|
const t = n.split(".");
|
|
530
530
|
let o = -1;
|
|
531
531
|
for (let c = 0; c < t.length; c++)
|
|
@@ -536,11 +536,11 @@ function m(n) {
|
|
|
536
536
|
const r = t.slice(0, o), i = r.length > 0 ? `/${r.join("/")}` : "/", s = t.slice(o);
|
|
537
537
|
return { name: S(s), path: i };
|
|
538
538
|
}
|
|
539
|
-
function
|
|
540
|
-
const e =
|
|
541
|
-
return
|
|
539
|
+
function $(n) {
|
|
540
|
+
const e = C(n);
|
|
541
|
+
return l(e);
|
|
542
542
|
}
|
|
543
|
-
class
|
|
543
|
+
class Ke {
|
|
544
544
|
constructor(e, t, o, r) {
|
|
545
545
|
this.modelInfo = e, this.sourceFile = t, this.keySchema = o, this.outputDir = r;
|
|
546
546
|
}
|
|
@@ -550,11 +550,11 @@ class Ye {
|
|
|
550
550
|
}
|
|
551
551
|
process() {
|
|
552
552
|
const { schema: e } = this.keySchema;
|
|
553
|
-
return z(e) ? this.processEnum(e) :
|
|
553
|
+
return z(e) ? this.processEnum(e) : w(e) ? this.processInterface(e) : N(e) ? this.processArray(e) : b(e) ? this.processIntersection(e) : L(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
554
554
|
}
|
|
555
555
|
resolveReference(e) {
|
|
556
|
-
const t =
|
|
557
|
-
return
|
|
556
|
+
const t = $(e);
|
|
557
|
+
return Ge(
|
|
558
558
|
this.modelInfo,
|
|
559
559
|
this.sourceFile,
|
|
560
560
|
this.outputDir,
|
|
@@ -571,7 +571,7 @@ class Ye {
|
|
|
571
571
|
return Object.entries(t).map(([o, r]) => {
|
|
572
572
|
const i = this.resolveType(r);
|
|
573
573
|
if (!g(r)) {
|
|
574
|
-
const s =
|
|
574
|
+
const s = ge(r), a = ce(s, `
|
|
575
575
|
* `);
|
|
576
576
|
if (a)
|
|
577
577
|
return `
|
|
@@ -586,7 +586,7 @@ class Ye {
|
|
|
586
586
|
}
|
|
587
587
|
resolveObjectType(e) {
|
|
588
588
|
const t = [];
|
|
589
|
-
if (
|
|
589
|
+
if (w(e)) {
|
|
590
590
|
const r = this.resolvePropertyDefinitions(e);
|
|
591
591
|
t.push(...r);
|
|
592
592
|
}
|
|
@@ -602,28 +602,28 @@ class Ye {
|
|
|
602
602
|
resolveType(e) {
|
|
603
603
|
if (g(e))
|
|
604
604
|
return this.resolveReference(e).name;
|
|
605
|
-
if (
|
|
605
|
+
if (Se(e))
|
|
606
606
|
return `Record<string,${this.resolveMapValueType(e)}>`;
|
|
607
607
|
if (e.const)
|
|
608
608
|
return `'${e.const}'`;
|
|
609
609
|
if (z(e))
|
|
610
610
|
return e.enum.map((t) => `'${t}'`).join(" | ");
|
|
611
611
|
if (L(e)) {
|
|
612
|
-
const o = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r =
|
|
612
|
+
const o = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r = b(e) ? " & " : " | ";
|
|
613
613
|
return `(${o.join(r)})`;
|
|
614
614
|
}
|
|
615
|
-
if (
|
|
615
|
+
if (N(e)) {
|
|
616
616
|
const t = this.resolveType(e.items);
|
|
617
|
-
return
|
|
617
|
+
return Ee(t);
|
|
618
618
|
}
|
|
619
|
-
return e.type === "object" ? this.resolveObjectType(e) : e.type ?
|
|
619
|
+
return e.type === "object" ? this.resolveObjectType(e) : e.type ? R(e.type) : "any";
|
|
620
620
|
}
|
|
621
621
|
processEnum(e) {
|
|
622
622
|
return this.sourceFile.addEnum({
|
|
623
623
|
name: this.modelInfo.name,
|
|
624
624
|
isExported: !0,
|
|
625
625
|
members: e.enum.filter((t) => typeof t == "string" && t.length > 0).map((t) => ({
|
|
626
|
-
name:
|
|
626
|
+
name: X(t),
|
|
627
627
|
initializer: `'${t}'`
|
|
628
628
|
}))
|
|
629
629
|
});
|
|
@@ -677,7 +677,7 @@ class Ye {
|
|
|
677
677
|
t.addExtends(r);
|
|
678
678
|
return;
|
|
679
679
|
}
|
|
680
|
-
|
|
680
|
+
w(o) && Object.entries(o.properties).forEach(
|
|
681
681
|
([r, i]) => {
|
|
682
682
|
this.addPropertyToInterface(
|
|
683
683
|
t,
|
|
@@ -696,7 +696,7 @@ class Ye {
|
|
|
696
696
|
});
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
|
-
class
|
|
699
|
+
class Ye {
|
|
700
700
|
constructor(e) {
|
|
701
701
|
this.context = e;
|
|
702
702
|
}
|
|
@@ -739,7 +739,7 @@ class Ke {
|
|
|
739
739
|
return !1;
|
|
740
740
|
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"))
|
|
741
741
|
return !0;
|
|
742
|
-
const o =
|
|
742
|
+
const o = l(e);
|
|
743
743
|
return t.has(o.name);
|
|
744
744
|
}
|
|
745
745
|
aggregatedSchemaSuffix = [
|
|
@@ -753,14 +753,16 @@ class Ke {
|
|
|
753
753
|
];
|
|
754
754
|
stateAggregatedTypeNames() {
|
|
755
755
|
const e = /* @__PURE__ */ new Set();
|
|
756
|
-
for (const t of this.context.contextAggregates
|
|
757
|
-
|
|
756
|
+
for (const [t, o] of this.context.contextAggregates) {
|
|
757
|
+
this.generateBoundedContext(t);
|
|
758
|
+
for (const r of o)
|
|
758
759
|
this.aggregatedSchemaSuffix.forEach(
|
|
759
|
-
(
|
|
760
|
-
const
|
|
761
|
-
e.add(
|
|
760
|
+
(i) => {
|
|
761
|
+
const s = l(r.state.key), a = S(s.name) + i;
|
|
762
|
+
e.add(a);
|
|
762
763
|
}
|
|
763
764
|
);
|
|
765
|
+
}
|
|
764
766
|
return e;
|
|
765
767
|
}
|
|
766
768
|
/**
|
|
@@ -776,8 +778,16 @@ class Ke {
|
|
|
776
778
|
* 4. Type alias processing
|
|
777
779
|
*/
|
|
778
780
|
generateKeyedSchema(e) {
|
|
779
|
-
const t =
|
|
780
|
-
new
|
|
781
|
+
const t = l(e.key), o = this.getOrCreateSourceFile(t);
|
|
782
|
+
new Ke(t, o, e, this.context.outputDir).generate();
|
|
783
|
+
}
|
|
784
|
+
generateBoundedContext(e) {
|
|
785
|
+
const t = `${e}/boundedContext.ts`;
|
|
786
|
+
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
787
|
+
const o = this.context.getOrCreateSourceFile(t), r = X(e);
|
|
788
|
+
o.addStatements(
|
|
789
|
+
`export const ${r}_BOUNDED_CONTEXT_ALIAS = '${e}';`
|
|
790
|
+
);
|
|
781
791
|
}
|
|
782
792
|
}
|
|
783
793
|
const Xe = "@ahoo-wang/fetcher-decorator", Ze = [
|
|
@@ -800,12 +810,12 @@ const Xe = "@ahoo-wang/fetcher-decorator", Ze = [
|
|
|
800
810
|
}, J = {
|
|
801
811
|
type: "Promise<string>",
|
|
802
812
|
metadata: "{resultExtractor: ResultExtractors.Text }"
|
|
803
|
-
},
|
|
813
|
+
}, M = `{
|
|
804
814
|
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
805
815
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
806
816
|
}`;
|
|
807
|
-
function
|
|
808
|
-
|
|
817
|
+
function pe(n) {
|
|
818
|
+
x(n, Xe, Ze);
|
|
809
819
|
}
|
|
810
820
|
function q(n, e, t = [], o = [], r) {
|
|
811
821
|
return e.addClass({
|
|
@@ -821,14 +831,14 @@ function q(n, e, t = [], o = [], r) {
|
|
|
821
831
|
]
|
|
822
832
|
});
|
|
823
833
|
}
|
|
824
|
-
function
|
|
834
|
+
function ue(n, e) {
|
|
825
835
|
n.addImplements("ApiMetadataCapable"), n.addConstructor({
|
|
826
836
|
parameters: [
|
|
827
837
|
{
|
|
828
838
|
name: "apiMetadata",
|
|
829
839
|
type: "ApiMetadata",
|
|
830
840
|
hasQuestionToken: e === void 0,
|
|
831
|
-
scope:
|
|
841
|
+
scope: fe.Public,
|
|
832
842
|
isReadonly: !0,
|
|
833
843
|
initializer: e
|
|
834
844
|
}
|
|
@@ -836,8 +846,8 @@ function pe(n, e) {
|
|
|
836
846
|
});
|
|
837
847
|
}
|
|
838
848
|
const tt = "@ahoo-wang/fetcher-eventstream";
|
|
839
|
-
function
|
|
840
|
-
|
|
849
|
+
function le(n) {
|
|
850
|
+
x(n, tt, [
|
|
841
851
|
"JsonEventStreamResultExtractor",
|
|
842
852
|
"type JsonServerSentEventStream"
|
|
843
853
|
]);
|
|
@@ -848,11 +858,11 @@ function nt(n) {
|
|
|
848
858
|
o.path.startsWith(W.TENANT) && (e += 1), o.path.startsWith(W.OWNER) && (t += 1);
|
|
849
859
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
850
860
|
}
|
|
851
|
-
function
|
|
861
|
+
function de(n, e, t, o) {
|
|
852
862
|
const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
|
|
853
|
-
return
|
|
863
|
+
return ae(n, e, r);
|
|
854
864
|
}
|
|
855
|
-
function
|
|
865
|
+
function h(n, e) {
|
|
856
866
|
return `${S(n.aggregateName)}${e}`;
|
|
857
867
|
}
|
|
858
868
|
function F(n) {
|
|
@@ -865,13 +875,13 @@ function rt(n, e) {
|
|
|
865
875
|
return t;
|
|
866
876
|
if (!n.operationId)
|
|
867
877
|
return;
|
|
868
|
-
const o =
|
|
878
|
+
const o = O(n.operationId);
|
|
869
879
|
for (let r = o.length - 1; r >= 0; r--) {
|
|
870
|
-
const i =
|
|
880
|
+
const i = f(o.slice(r));
|
|
871
881
|
if (!e(i))
|
|
872
882
|
return i;
|
|
873
883
|
}
|
|
874
|
-
return
|
|
884
|
+
return f(o);
|
|
875
885
|
}
|
|
876
886
|
class it {
|
|
877
887
|
/**
|
|
@@ -926,7 +936,7 @@ class it {
|
|
|
926
936
|
*/
|
|
927
937
|
createApiClientFile(e) {
|
|
928
938
|
let t = e.path;
|
|
929
|
-
return this.context.currentContextAlias && (t =
|
|
939
|
+
return this.context.currentContextAlias && (t = v(this.context.currentContextAlias, t)), t = v(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
|
|
930
940
|
}
|
|
931
941
|
/**
|
|
932
942
|
* Generates a single API client class for the given tag and operations.
|
|
@@ -934,17 +944,17 @@ class it {
|
|
|
934
944
|
* @param operations - Set of operations for this client
|
|
935
945
|
*/
|
|
936
946
|
generateApiClient(e, t) {
|
|
937
|
-
const o =
|
|
947
|
+
const o = l(e.name);
|
|
938
948
|
this.context.logger.info(
|
|
939
949
|
`Generating API client class: ${o.name}ApiClient with ${t.size} operations`
|
|
940
950
|
);
|
|
941
951
|
const r = this.createApiClientFile(o);
|
|
942
|
-
|
|
952
|
+
pe(r), le(r);
|
|
943
953
|
const i = q(
|
|
944
954
|
o.name + "ApiClient",
|
|
945
955
|
r
|
|
946
956
|
);
|
|
947
|
-
|
|
957
|
+
E(i, [e.description]), ue(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
948
958
|
`Processing ${t.size} operations for ${o.name}ApiClient`
|
|
949
959
|
), t.forEach((s) => {
|
|
950
960
|
this.processOperation(e, r, i, s);
|
|
@@ -992,10 +1002,10 @@ class it {
|
|
|
992
1002
|
if (o.content["application/json"]) {
|
|
993
1003
|
const r = o.content["application/json"].schema;
|
|
994
1004
|
if (g(r)) {
|
|
995
|
-
const i =
|
|
1005
|
+
const i = $(r);
|
|
996
1006
|
this.context.logger.info(
|
|
997
1007
|
`Adding import for request body model: ${i.name} from ${i.path}`
|
|
998
|
-
),
|
|
1008
|
+
), d(e, this.context.outputDir, i);
|
|
999
1009
|
const s = `ParameterRequest<${i.name}>`;
|
|
1000
1010
|
return this.context.logger.info(
|
|
1001
1011
|
`Resolved request type for operation ${t.operationId}: ${s}`
|
|
@@ -1014,7 +1024,7 @@ class it {
|
|
|
1014
1024
|
* @returns Array of parameter declarations
|
|
1015
1025
|
*/
|
|
1016
1026
|
resolveParameters(e, t, o) {
|
|
1017
|
-
const r =
|
|
1027
|
+
const r = De(o, this.context.openAPI.components).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
1018
1028
|
e.name,
|
|
1019
1029
|
a.name
|
|
1020
1030
|
));
|
|
@@ -1022,7 +1032,7 @@ class it {
|
|
|
1022
1032
|
`Found ${r.length} path parameters for operation ${o.operationId}`
|
|
1023
1033
|
);
|
|
1024
1034
|
const i = r.map((a) => {
|
|
1025
|
-
const c =
|
|
1035
|
+
const c = oe(a);
|
|
1026
1036
|
return this.context.logger.info(
|
|
1027
1037
|
`Adding path parameter: ${a.name} (type: ${c})`
|
|
1028
1038
|
), {
|
|
@@ -1070,10 +1080,10 @@ class it {
|
|
|
1070
1080
|
resolveSchemaReturnType(e, t) {
|
|
1071
1081
|
const o = "Promise<any>";
|
|
1072
1082
|
if (g(t)) {
|
|
1073
|
-
const r =
|
|
1083
|
+
const r = $(t);
|
|
1074
1084
|
this.context.logger.info(
|
|
1075
1085
|
`Adding import for response model: ${r.name} from ${r.path}`
|
|
1076
|
-
),
|
|
1086
|
+
), d(e, this.context.outputDir, r);
|
|
1077
1087
|
const i = `Promise<${r.name}>`;
|
|
1078
1088
|
return this.context.logger.info(`Resolved reference return type: ${i}`), i;
|
|
1079
1089
|
}
|
|
@@ -1081,8 +1091,8 @@ class it {
|
|
|
1081
1091
|
return this.context.logger.info(
|
|
1082
1092
|
`Schema has no type, using default return type: ${o}`
|
|
1083
1093
|
), o;
|
|
1084
|
-
if (
|
|
1085
|
-
const i = `Promise<${
|
|
1094
|
+
if (ee(t.type)) {
|
|
1095
|
+
const i = `Promise<${R(t.type)}>`;
|
|
1086
1096
|
return this.context.logger.info(`Resolved primitive return type: ${i}`), i;
|
|
1087
1097
|
}
|
|
1088
1098
|
return this.context.logger.info(
|
|
@@ -1096,12 +1106,12 @@ class it {
|
|
|
1096
1106
|
* @returns Object containing type and optional stream flag
|
|
1097
1107
|
*/
|
|
1098
1108
|
resolveReturnType(e, t) {
|
|
1099
|
-
const o =
|
|
1109
|
+
const o = G(t);
|
|
1100
1110
|
if (!o)
|
|
1101
1111
|
return this.context.logger.info(
|
|
1102
1112
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1103
1113
|
), this.defaultReturnType;
|
|
1104
|
-
const r =
|
|
1114
|
+
const r = Z(o) || $e(o);
|
|
1105
1115
|
if (r) {
|
|
1106
1116
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1107
1117
|
return this.context.logger.info(
|
|
@@ -1114,28 +1124,28 @@ class it {
|
|
|
1114
1124
|
const i = Pe(o);
|
|
1115
1125
|
if (i) {
|
|
1116
1126
|
if (g(i)) {
|
|
1117
|
-
const a =
|
|
1127
|
+
const a = I(
|
|
1118
1128
|
i,
|
|
1119
1129
|
this.context.openAPI.components
|
|
1120
1130
|
);
|
|
1121
|
-
if (
|
|
1122
|
-
const c =
|
|
1131
|
+
if (N(a) && g(a.items)) {
|
|
1132
|
+
const c = $(a.items);
|
|
1123
1133
|
this.context.logger.info(
|
|
1124
1134
|
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
1125
|
-
),
|
|
1135
|
+
), d(e, this.context.outputDir, c);
|
|
1126
1136
|
const p = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
|
|
1127
1137
|
return this.context.logger.info(
|
|
1128
1138
|
`Resolved event stream return type for operation ${t.operationId}: ${p}`
|
|
1129
1139
|
), {
|
|
1130
1140
|
type: p,
|
|
1131
|
-
metadata:
|
|
1141
|
+
metadata: M
|
|
1132
1142
|
};
|
|
1133
1143
|
}
|
|
1134
1144
|
}
|
|
1135
1145
|
const s = "Promise<JsonServerSentEventStream<any>>";
|
|
1136
1146
|
return this.context.logger.info(
|
|
1137
1147
|
`Resolved generic event stream return type for operation ${t.operationId}: ${s}`
|
|
1138
|
-
), { type: s, metadata:
|
|
1148
|
+
), { type: s, metadata: M };
|
|
1139
1149
|
}
|
|
1140
1150
|
return this.context.logger.info(
|
|
1141
1151
|
`Using default return type for operation ${t.operationId}: ${this.defaultReturnType.type}`
|
|
@@ -1168,7 +1178,7 @@ class it {
|
|
|
1168
1178
|
this.context.logger.info(
|
|
1169
1179
|
`Creating method with ${s.length} parameters, return type: ${a.type}`
|
|
1170
1180
|
);
|
|
1171
|
-
const
|
|
1181
|
+
const m = o.addMethod({
|
|
1172
1182
|
name: i,
|
|
1173
1183
|
decorators: [c],
|
|
1174
1184
|
parameters: s,
|
|
@@ -1177,8 +1187,8 @@ class it {
|
|
|
1177
1187
|
`throw autoGeneratedError(${s.map((p) => p.name).join(",")});`
|
|
1178
1188
|
]
|
|
1179
1189
|
});
|
|
1180
|
-
|
|
1181
|
-
|
|
1190
|
+
E(
|
|
1191
|
+
m,
|
|
1182
1192
|
[
|
|
1183
1193
|
r.operation.summary,
|
|
1184
1194
|
r.operation.description,
|
|
@@ -1194,7 +1204,7 @@ class it {
|
|
|
1194
1204
|
*/
|
|
1195
1205
|
groupOperations(e) {
|
|
1196
1206
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1197
|
-
const t = /* @__PURE__ */ new Map(), o =
|
|
1207
|
+
const t = /* @__PURE__ */ new Map(), o = te(this.context.openAPI.paths).filter(
|
|
1198
1208
|
(i) => {
|
|
1199
1209
|
if (!i.operation.operationId)
|
|
1200
1210
|
return !1;
|
|
@@ -1225,7 +1235,7 @@ class it {
|
|
|
1225
1235
|
);
|
|
1226
1236
|
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1227
1237
|
for (const r of Object.values(this.context.openAPI.paths))
|
|
1228
|
-
|
|
1238
|
+
ne(r).forEach((i) => {
|
|
1229
1239
|
i.operation.tags?.forEach((s) => {
|
|
1230
1240
|
!this.shouldIgnoreTag(s) && !e.has(s) && e.set(s, {
|
|
1231
1241
|
name: s,
|
|
@@ -1258,7 +1268,7 @@ class st {
|
|
|
1258
1268
|
constructor(e) {
|
|
1259
1269
|
this.context = e;
|
|
1260
1270
|
}
|
|
1261
|
-
|
|
1271
|
+
commandEndpointPathsSuffix = "CommandEndpointPaths";
|
|
1262
1272
|
defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
1263
1273
|
/**
|
|
1264
1274
|
* Generates command client classes for all aggregates.
|
|
@@ -1289,7 +1299,7 @@ class st {
|
|
|
1289
1299
|
this.context.logger.info(
|
|
1290
1300
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1291
1301
|
);
|
|
1292
|
-
const t =
|
|
1302
|
+
const t = de(
|
|
1293
1303
|
this.context.project,
|
|
1294
1304
|
this.context.outputDir,
|
|
1295
1305
|
e.aggregate,
|
|
@@ -1297,10 +1307,12 @@ class st {
|
|
|
1297
1307
|
);
|
|
1298
1308
|
this.context.logger.info(
|
|
1299
1309
|
`Processing command endpoint paths for ${e.commands.size} commands`
|
|
1300
|
-
)
|
|
1310
|
+
);
|
|
1311
|
+
const o = this.processCommandEndpointPaths(t, e);
|
|
1312
|
+
this.context.logger.info(
|
|
1301
1313
|
`Creating default command client options: ${this.defaultCommandClientOptionsName}`
|
|
1302
1314
|
), t.addVariableStatement({
|
|
1303
|
-
declarationKind:
|
|
1315
|
+
declarationKind: D.Const,
|
|
1304
1316
|
declarations: [
|
|
1305
1317
|
{
|
|
1306
1318
|
name: this.defaultCommandClientOptionsName,
|
|
@@ -1312,9 +1324,9 @@ class st {
|
|
|
1312
1324
|
],
|
|
1313
1325
|
isExported: !1
|
|
1314
1326
|
}), this.context.logger.info(
|
|
1315
|
-
`Adding imports from ${
|
|
1327
|
+
`Adding imports from ${A}: CommandRequest, CommandResult, CommandResultEventStream, DeleteAggregate, RecoverAggregate`
|
|
1316
1328
|
), t.addImportDeclaration({
|
|
1317
|
-
moduleSpecifier:
|
|
1329
|
+
moduleSpecifier: A,
|
|
1318
1330
|
namedImports: [
|
|
1319
1331
|
"CommandRequest",
|
|
1320
1332
|
"CommandResult",
|
|
@@ -1325,66 +1337,74 @@ class st {
|
|
|
1325
1337
|
isTypeOnly: !0
|
|
1326
1338
|
}), this.context.logger.info(
|
|
1327
1339
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1328
|
-
),
|
|
1340
|
+
), le(t), this.context.logger.info(
|
|
1329
1341
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1330
|
-
),
|
|
1342
|
+
), x(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1331
1343
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1332
|
-
),
|
|
1344
|
+
), pe(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e, o), this.context.logger.info("Generating stream command client class"), this.processStreamCommandClient(t, e), this.context.logger.success(
|
|
1333
1345
|
`Command client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
1334
1346
|
);
|
|
1335
1347
|
}
|
|
1348
|
+
resolveAggregateCommandEndpointPathsName(e) {
|
|
1349
|
+
return h(e, this.commandEndpointPathsSuffix);
|
|
1350
|
+
}
|
|
1336
1351
|
processCommandEndpointPaths(e, t) {
|
|
1352
|
+
const o = this.resolveAggregateCommandEndpointPathsName(
|
|
1353
|
+
t.aggregate
|
|
1354
|
+
);
|
|
1337
1355
|
this.context.logger.info(
|
|
1338
|
-
`Creating command endpoint paths enum: ${
|
|
1356
|
+
`Creating command endpoint paths enum: ${o}`
|
|
1339
1357
|
);
|
|
1340
|
-
const
|
|
1341
|
-
name:
|
|
1358
|
+
const r = e.addEnum({
|
|
1359
|
+
name: o,
|
|
1360
|
+
isExported: !0
|
|
1342
1361
|
});
|
|
1343
|
-
t.commands.forEach((
|
|
1362
|
+
return t.commands.forEach((i) => {
|
|
1344
1363
|
this.context.logger.info(
|
|
1345
|
-
`Adding command endpoint: ${
|
|
1346
|
-
),
|
|
1347
|
-
name:
|
|
1348
|
-
initializer: `'${
|
|
1364
|
+
`Adding command endpoint: ${i.name.toUpperCase()} = '${i.path}'`
|
|
1365
|
+
), r.addMember({
|
|
1366
|
+
name: i.name.toUpperCase(),
|
|
1367
|
+
initializer: `'${i.path}'`
|
|
1349
1368
|
});
|
|
1350
1369
|
}), this.context.logger.success(
|
|
1351
1370
|
`Command endpoint paths enum created with ${t.commands.size} entries`
|
|
1352
|
-
);
|
|
1371
|
+
), o;
|
|
1353
1372
|
}
|
|
1354
|
-
getEndpointPath(e) {
|
|
1355
|
-
return `${
|
|
1373
|
+
getEndpointPath(e, t) {
|
|
1374
|
+
return `${e}.${t.name.toUpperCase()}`;
|
|
1356
1375
|
}
|
|
1357
|
-
processCommandClient(e, t) {
|
|
1358
|
-
const
|
|
1376
|
+
processCommandClient(e, t, o) {
|
|
1377
|
+
const r = h(
|
|
1359
1378
|
t.aggregate,
|
|
1360
1379
|
"CommandClient"
|
|
1361
|
-
),
|
|
1362
|
-
|
|
1380
|
+
), i = q(
|
|
1381
|
+
r,
|
|
1363
1382
|
e,
|
|
1364
1383
|
[],
|
|
1365
1384
|
["R = CommandResult"]
|
|
1366
1385
|
);
|
|
1367
|
-
|
|
1386
|
+
ue(i, this.defaultCommandClientOptionsName), t.commands.forEach((s) => {
|
|
1368
1387
|
this.processCommandMethod(
|
|
1369
1388
|
t,
|
|
1370
1389
|
e,
|
|
1371
|
-
|
|
1372
|
-
|
|
1390
|
+
i,
|
|
1391
|
+
s,
|
|
1392
|
+
o
|
|
1373
1393
|
);
|
|
1374
1394
|
});
|
|
1375
1395
|
}
|
|
1376
1396
|
processStreamCommandClient(e, t) {
|
|
1377
|
-
const o =
|
|
1397
|
+
const o = h(
|
|
1378
1398
|
t.aggregate,
|
|
1379
1399
|
"CommandClient"
|
|
1380
|
-
), r =
|
|
1400
|
+
), r = h(
|
|
1381
1401
|
t.aggregate,
|
|
1382
1402
|
"StreamCommandClient"
|
|
1383
1403
|
);
|
|
1384
1404
|
q(
|
|
1385
1405
|
r,
|
|
1386
1406
|
e,
|
|
1387
|
-
["''",
|
|
1407
|
+
["''", M],
|
|
1388
1408
|
[],
|
|
1389
1409
|
`${o}<CommandResultEventStream>`
|
|
1390
1410
|
).addConstructor({
|
|
@@ -1399,15 +1419,15 @@ class st {
|
|
|
1399
1419
|
});
|
|
1400
1420
|
}
|
|
1401
1421
|
resolveParameters(e, t, o) {
|
|
1402
|
-
const r =
|
|
1422
|
+
const r = l(o.schema.key);
|
|
1403
1423
|
this.context.logger.info(
|
|
1404
1424
|
`Adding import for command model: ${r.name} from path: ${r.path}`
|
|
1405
|
-
),
|
|
1425
|
+
), d(t, this.context.outputDir, r);
|
|
1406
1426
|
const i = o.pathParameters.filter((s) => !this.context.isIgnoreCommandClientPathParameters(
|
|
1407
1427
|
e.name,
|
|
1408
1428
|
s.name
|
|
1409
1429
|
)).map((s) => {
|
|
1410
|
-
const a =
|
|
1430
|
+
const a = oe(s);
|
|
1411
1431
|
return this.context.logger.info(
|
|
1412
1432
|
`Adding path parameter: ${s.name} (type: ${a})`
|
|
1413
1433
|
), {
|
|
@@ -1448,37 +1468,37 @@ class st {
|
|
|
1448
1468
|
]
|
|
1449
1469
|
}), i;
|
|
1450
1470
|
}
|
|
1451
|
-
processCommandMethod(e, t, o, r) {
|
|
1471
|
+
processCommandMethod(e, t, o, r, i) {
|
|
1452
1472
|
this.context.logger.info(
|
|
1453
|
-
`Generating command method: ${
|
|
1473
|
+
`Generating command method: ${f(r.name)} for command: ${r.name}`
|
|
1454
1474
|
), this.context.logger.info(
|
|
1455
1475
|
`Command method details: HTTP ${r.method}, path: ${r.path}`
|
|
1456
1476
|
);
|
|
1457
|
-
const
|
|
1477
|
+
const s = this.resolveParameters(
|
|
1458
1478
|
e.aggregate.tag,
|
|
1459
1479
|
t,
|
|
1460
1480
|
r
|
|
1461
|
-
),
|
|
1462
|
-
name:
|
|
1481
|
+
), a = o.addMethod({
|
|
1482
|
+
name: f(r.name),
|
|
1463
1483
|
decorators: [
|
|
1464
1484
|
{
|
|
1465
1485
|
name: F(r.method),
|
|
1466
|
-
arguments: [`${this.getEndpointPath(r)}`]
|
|
1486
|
+
arguments: [`${this.getEndpointPath(i, r)}`]
|
|
1467
1487
|
}
|
|
1468
1488
|
],
|
|
1469
|
-
parameters:
|
|
1489
|
+
parameters: s,
|
|
1470
1490
|
returnType: "Promise<R>",
|
|
1471
|
-
statements: `throw autoGeneratedError(${
|
|
1491
|
+
statements: `throw autoGeneratedError(${s.map((c) => c.name).join(",")});`
|
|
1472
1492
|
});
|
|
1473
1493
|
this.context.logger.info(
|
|
1474
|
-
`Adding JSDoc documentation for method: ${
|
|
1475
|
-
),
|
|
1494
|
+
`Adding JSDoc documentation for method: ${f(r.name)}`
|
|
1495
|
+
), E(a, [
|
|
1476
1496
|
r.summary,
|
|
1477
1497
|
r.description,
|
|
1478
1498
|
`- operationId: \`${r.operation.operationId}\``,
|
|
1479
1499
|
`- path: \`${r.path}\``
|
|
1480
1500
|
]), this.context.logger.success(
|
|
1481
|
-
`Command method generated: ${
|
|
1501
|
+
`Command method generated: ${f(r.name)}`
|
|
1482
1502
|
);
|
|
1483
1503
|
}
|
|
1484
1504
|
}
|
|
@@ -1490,6 +1510,7 @@ class at {
|
|
|
1490
1510
|
constructor(e) {
|
|
1491
1511
|
this.context = e;
|
|
1492
1512
|
}
|
|
1513
|
+
domainEventTypeSuffix = "DomainEventType";
|
|
1493
1514
|
/**
|
|
1494
1515
|
* Generates query client classes for all aggregates.
|
|
1495
1516
|
*/
|
|
@@ -1519,7 +1540,7 @@ class at {
|
|
|
1519
1540
|
* @returns The source file for the client
|
|
1520
1541
|
*/
|
|
1521
1542
|
createClientFilePath(e, t) {
|
|
1522
|
-
return
|
|
1543
|
+
return de(
|
|
1523
1544
|
this.context.project,
|
|
1524
1545
|
this.context.outputDir,
|
|
1525
1546
|
e,
|
|
@@ -1538,9 +1559,9 @@ class at {
|
|
|
1538
1559
|
this.context.logger.info(
|
|
1539
1560
|
`Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1540
1561
|
), this.context.logger.info(
|
|
1541
|
-
`Adding imports from ${
|
|
1562
|
+
`Adding imports from ${A}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`
|
|
1542
1563
|
), t.addImportDeclaration({
|
|
1543
|
-
moduleSpecifier:
|
|
1564
|
+
moduleSpecifier: A,
|
|
1544
1565
|
namedImports: [
|
|
1545
1566
|
"QueryClientFactory",
|
|
1546
1567
|
"QueryClientOptions",
|
|
@@ -1551,7 +1572,7 @@ class at {
|
|
|
1551
1572
|
this.context.logger.info(
|
|
1552
1573
|
`Creating default query client options: ${o}`
|
|
1553
1574
|
), t.addVariableStatement({
|
|
1554
|
-
declarationKind:
|
|
1575
|
+
declarationKind: D.Const,
|
|
1555
1576
|
declarations: [
|
|
1556
1577
|
{
|
|
1557
1578
|
name: o,
|
|
@@ -1564,35 +1585,18 @@ class at {
|
|
|
1564
1585
|
}
|
|
1565
1586
|
],
|
|
1566
1587
|
isExported: !1
|
|
1567
|
-
});
|
|
1568
|
-
const r =
|
|
1569
|
-
this.context.logger.info(
|
|
1570
|
-
`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
|
|
1571
|
-
);
|
|
1572
|
-
for (const p of e.events.values()) {
|
|
1573
|
-
const l = m(p.schema.key);
|
|
1574
|
-
this.context.logger.info(
|
|
1575
|
-
`Adding import for event model: ${l.name} from path: ${l.path}`
|
|
1576
|
-
), f(t, this.context.outputDir, l), r.push(l);
|
|
1577
|
-
}
|
|
1578
|
-
const i = "DOMAIN_EVENT_TYPES", s = r.map((p) => p.name).join(" | ");
|
|
1579
|
-
this.context.logger.info(
|
|
1580
|
-
`Creating domain event types union: ${i} = ${s}`
|
|
1581
|
-
), t.addTypeAlias({
|
|
1582
|
-
name: i,
|
|
1583
|
-
type: s
|
|
1584
|
-
});
|
|
1585
|
-
const a = `${h(e.aggregate.aggregateName)}QueryClientFactory`, c = m(e.state.key), u = m(e.fields.key);
|
|
1588
|
+
}), this.processAggregateDomainEventTypes(e, t);
|
|
1589
|
+
const r = this.processAggregateDomainEventType(e, t), i = `${f(e.aggregate.aggregateName)}QueryClientFactory`, s = l(e.state.key), a = l(e.fields.key);
|
|
1586
1590
|
this.context.logger.info(
|
|
1587
|
-
`Adding import for state model: ${
|
|
1588
|
-
),
|
|
1589
|
-
`Adding import for fields model: ${
|
|
1590
|
-
),
|
|
1591
|
-
declarationKind:
|
|
1591
|
+
`Adding import for state model: ${s.name} from path: ${s.path}`
|
|
1592
|
+
), d(t, this.context.outputDir, s), this.context.logger.info(
|
|
1593
|
+
`Adding import for fields model: ${a.name} from path: ${a.path}`
|
|
1594
|
+
), d(t, this.context.outputDir, a), this.context.logger.info(`Creating query client factory: ${i}`), t.addVariableStatement({
|
|
1595
|
+
declarationKind: D.Const,
|
|
1592
1596
|
declarations: [
|
|
1593
1597
|
{
|
|
1594
|
-
name:
|
|
1595
|
-
initializer: `new QueryClientFactory<${
|
|
1598
|
+
name: i,
|
|
1599
|
+
initializer: `new QueryClientFactory<${s.name}, ${a.name} | string, ${r}>(${o})`
|
|
1596
1600
|
}
|
|
1597
1601
|
],
|
|
1598
1602
|
isExported: !0
|
|
@@ -1600,6 +1604,37 @@ class at {
|
|
|
1600
1604
|
`Query client generation completed for aggregate: ${e.aggregate.aggregateName}`
|
|
1601
1605
|
);
|
|
1602
1606
|
}
|
|
1607
|
+
processAggregateDomainEventType(e, t) {
|
|
1608
|
+
const o = [];
|
|
1609
|
+
this.context.logger.info(
|
|
1610
|
+
`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`
|
|
1611
|
+
);
|
|
1612
|
+
for (const s of e.events.values()) {
|
|
1613
|
+
const a = l(s.schema.key);
|
|
1614
|
+
this.context.logger.info(
|
|
1615
|
+
`Adding import for event model: ${a.name} from path: ${a.path}`
|
|
1616
|
+
), d(t, this.context.outputDir, a), o.push(a);
|
|
1617
|
+
}
|
|
1618
|
+
const r = h(e.aggregate, this.domainEventTypeSuffix), i = o.map((s) => s.name).join(" | ");
|
|
1619
|
+
return this.context.logger.info(
|
|
1620
|
+
`Creating domain event types union: ${r} = ${i}`
|
|
1621
|
+
), t.addTypeAlias({
|
|
1622
|
+
isExported: !0,
|
|
1623
|
+
name: r,
|
|
1624
|
+
type: i
|
|
1625
|
+
}), r;
|
|
1626
|
+
}
|
|
1627
|
+
processAggregateDomainEventTypes(e, t) {
|
|
1628
|
+
const o = h(e.aggregate, this.domainEventTypeSuffix + "s"), r = t.addEnum({
|
|
1629
|
+
name: o,
|
|
1630
|
+
isExported: !0
|
|
1631
|
+
});
|
|
1632
|
+
for (const i of e.events.values())
|
|
1633
|
+
r.addMember({
|
|
1634
|
+
name: i.name,
|
|
1635
|
+
initializer: `'${i.title}'`
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1603
1638
|
}
|
|
1604
1639
|
class ct {
|
|
1605
1640
|
/**
|
|
@@ -1626,25 +1661,9 @@ class ct {
|
|
|
1626
1661
|
this.context.contextAggregates.size,
|
|
1627
1662
|
`Processing bounded context: ${t}`,
|
|
1628
1663
|
1
|
|
1629
|
-
)
|
|
1664
|
+
);
|
|
1630
1665
|
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
|
|
1631
1666
|
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Processes a bounded context by creating a file with the context alias constant.
|
|
1634
|
-
* @param contextAlias - The alias of the bounded context to process
|
|
1635
|
-
*/
|
|
1636
|
-
processBoundedContext(e) {
|
|
1637
|
-
const t = `${e}/boundedContext.ts`;
|
|
1638
|
-
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
1639
|
-
const o = this.context.getOrCreateSourceFile(t);
|
|
1640
|
-
this.context.logger.info(
|
|
1641
|
-
`Adding bounded context alias constant: BOUNDED_CONTEXT_ALIAS = '${e}'`
|
|
1642
|
-
), o.addStatements(
|
|
1643
|
-
`export const BOUNDED_CONTEXT_ALIAS = '${e}';`
|
|
1644
|
-
), this.context.logger.success(
|
|
1645
|
-
`Bounded context file created successfully: ${t}`
|
|
1646
|
-
);
|
|
1647
|
-
}
|
|
1648
1667
|
}
|
|
1649
1668
|
class gt {
|
|
1650
1669
|
/** The ts-morph project instance used for code generation */
|
|
@@ -1664,7 +1683,7 @@ class gt {
|
|
|
1664
1683
|
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger, this.config = e.config ?? {}, this.currentContextAlias = this.openAPI.info["x-wow-context-alias"];
|
|
1665
1684
|
}
|
|
1666
1685
|
getOrCreateSourceFile(e) {
|
|
1667
|
-
return
|
|
1686
|
+
return ae(this.project, this.outputDir, e);
|
|
1668
1687
|
}
|
|
1669
1688
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1670
1689
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1680,7 +1699,7 @@ class yt {
|
|
|
1680
1699
|
* @param options - Configuration options for code generation
|
|
1681
1700
|
*/
|
|
1682
1701
|
constructor(e) {
|
|
1683
|
-
this.options = e, this.project = new
|
|
1702
|
+
this.options = e, this.project = new he(e), this.options.logger.info("Project instance created with tsConfigFilePath: ", this.options.tsConfigFilePath);
|
|
1684
1703
|
}
|
|
1685
1704
|
project;
|
|
1686
1705
|
/**
|
|
@@ -1692,7 +1711,7 @@ class yt {
|
|
|
1692
1711
|
this.options.logger.info(
|
|
1693
1712
|
"Starting code generation from OpenAPI specification"
|
|
1694
1713
|
), 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");
|
|
1695
|
-
const e = await
|
|
1714
|
+
const e = await Me(this.options.inputPath);
|
|
1696
1715
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1697
1716
|
const o = new Ve(e).resolve();
|
|
1698
1717
|
this.options.logger.info(
|
|
@@ -1702,8 +1721,8 @@ class yt {
|
|
|
1702
1721
|
let i = {};
|
|
1703
1722
|
try {
|
|
1704
1723
|
this.options.logger.info("Parsing configuration file:", r), i = await qe(r);
|
|
1705
|
-
} catch (
|
|
1706
|
-
this.options.logger.info("Configuration file parsing failed ",
|
|
1724
|
+
} catch (m) {
|
|
1725
|
+
this.options.logger.info("Configuration file parsing failed ", m);
|
|
1707
1726
|
}
|
|
1708
1727
|
const s = new gt({
|
|
1709
1728
|
openAPI: e,
|
|
@@ -1713,7 +1732,7 @@ class yt {
|
|
|
1713
1732
|
logger: this.options.logger,
|
|
1714
1733
|
config: i
|
|
1715
1734
|
});
|
|
1716
|
-
this.options.logger.info("Generating models"), new
|
|
1735
|
+
this.options.logger.info("Generating models"), new Ye(s).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ct(s).generate(), this.options.logger.info("Clients generated successfully"), this.options.logger.info("Generating index files"), this.generateIndex(), this.options.logger.info("Index files generated successfully"), this.options.logger.info("Optimizing source files"), this.optimizeSourceFiles(), this.options.logger.info("Source files optimized successfully"), this.options.logger.info("Saving project to disk"), await this.project.save(), this.options.logger.info("Code generation completed successfully");
|
|
1717
1736
|
}
|
|
1718
1737
|
/**
|
|
1719
1738
|
* Generates index.ts files for all subdirectories in the output directory.
|