@ahoo-wang/fetcher-generator 2.1.0 → 2.1.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/baseCodeGenerator.d.ts +6 -1
- package/dist/baseCodeGenerator.d.ts.map +1 -1
- package/dist/cli.cjs +2 -1
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +23 -22
- package/dist/cli.js.map +1 -0
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/index.cjs +7 -6
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +443 -469
- package/dist/index.js.map +1 -0
- package/dist/model/modelGenerator.d.ts +6 -90
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +8 -8
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/schemas.d.ts +63 -2
- package/dist/utils/schemas.d.ts.map +1 -1
- package/dist/utils/sourceFiles.d.ts +3 -3
- package/dist/utils/sourceFiles.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { VariableDeclarationKind as S, Scope as
|
|
2
|
-
import { parse as
|
|
1
|
+
import { VariableDeclarationKind as S, Scope as k } from "ts-morph";
|
|
2
|
+
import { parse as Q } from "yaml";
|
|
3
3
|
import { readFile as K } from "fs";
|
|
4
|
-
import { ContentTypeValues as
|
|
5
|
-
import { ResourceAttributionPathSpec as
|
|
6
|
-
function
|
|
7
|
-
return
|
|
4
|
+
import { ContentTypeValues as T, combineURLs as C } from "@ahoo-wang/fetcher";
|
|
5
|
+
import { ResourceAttributionPathSpec as b } from "@ahoo-wang/fetcher-wow";
|
|
6
|
+
function d(t) {
|
|
7
|
+
return t.$ref.split("/").pop();
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const n =
|
|
9
|
+
function R(t, e) {
|
|
10
|
+
const n = d(t);
|
|
11
11
|
return e.schemas?.[n];
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const n =
|
|
13
|
+
function J(t, e) {
|
|
14
|
+
const n = d(t);
|
|
15
15
|
return e.requestBodies?.[n];
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
const n =
|
|
17
|
+
function U(t, e) {
|
|
18
|
+
const n = d(t);
|
|
19
19
|
return e.parameters?.[n];
|
|
20
20
|
}
|
|
21
|
-
function y(
|
|
21
|
+
function y(t, e) {
|
|
22
22
|
return {
|
|
23
|
-
key:
|
|
24
|
-
schema:
|
|
23
|
+
key: d(t),
|
|
24
|
+
schema: R(t, e)
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
function
|
|
29
|
-
if (
|
|
27
|
+
const $ = /[-_\s.]+|(?=[A-Z])/;
|
|
28
|
+
function P(t) {
|
|
29
|
+
if (t === "" || t.length === 0)
|
|
30
30
|
return "";
|
|
31
31
|
let e;
|
|
32
|
-
return Array.isArray(
|
|
32
|
+
return Array.isArray(t) ? e = t.flatMap((n) => n.split($)) : e = t.split($), e.filter((n) => n.length > 0).map((n) => {
|
|
33
33
|
if (n.length === 0) return "";
|
|
34
|
-
const
|
|
35
|
-
return (/[a-zA-Z]/.test(
|
|
34
|
+
const r = n.charAt(0), o = n.slice(1);
|
|
35
|
+
return (/[a-zA-Z]/.test(r) ? r.toUpperCase() : r) + o.toLowerCase();
|
|
36
36
|
}).join("");
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const e =
|
|
38
|
+
function q(t) {
|
|
39
|
+
const e = P(t);
|
|
40
40
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
42
|
+
function V(t) {
|
|
43
|
+
return t.startsWith("http://") || t.startsWith("https://") ? z(t) : H(t);
|
|
44
44
|
}
|
|
45
|
-
async function
|
|
46
|
-
return await (await fetch(
|
|
45
|
+
async function z(t) {
|
|
46
|
+
return await (await fetch(t)).text();
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function H(t) {
|
|
49
49
|
return new Promise((e, n) => {
|
|
50
|
-
K(
|
|
51
|
-
|
|
50
|
+
K(t, "utf-8", (r, o) => {
|
|
51
|
+
r ? n(r) : e(o);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
async function
|
|
56
|
-
const e = await
|
|
57
|
-
switch (
|
|
55
|
+
async function Y(t) {
|
|
56
|
+
const e = await V(t);
|
|
57
|
+
switch (Z(e)) {
|
|
58
58
|
case "json":
|
|
59
59
|
return JSON.parse(e);
|
|
60
60
|
case "yaml":
|
|
61
|
-
return
|
|
61
|
+
return Q(e);
|
|
62
62
|
default:
|
|
63
|
-
throw new Error(`Unsupported file format: ${
|
|
63
|
+
throw new Error(`Unsupported file format: ${t}`);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const e =
|
|
66
|
+
function Z(t) {
|
|
67
|
+
const e = t.trimStart();
|
|
68
68
|
if (e.startsWith("{") || e.startsWith("["))
|
|
69
69
|
return "json";
|
|
70
70
|
if (e.startsWith("-") || e.startsWith("%YAML"))
|
|
@@ -77,38 +77,69 @@ function H(r) {
|
|
|
77
77
|
}
|
|
78
78
|
throw new Error("Unable to infer file format");
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
return !!(
|
|
80
|
+
function u(t) {
|
|
81
|
+
return !!(t && typeof t == "object" && "$ref" in t);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return !
|
|
83
|
+
function X(t) {
|
|
84
|
+
return !t || u(t) || !t.content ? void 0 : t.content[T.APPLICATION_JSON]?.schema;
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function ee(t) {
|
|
87
87
|
return [
|
|
88
|
-
{ method: "get", operation:
|
|
89
|
-
{ method: "put", operation:
|
|
90
|
-
{ method: "post", operation:
|
|
91
|
-
{ method: "delete", operation:
|
|
92
|
-
{ method: "options", operation:
|
|
93
|
-
{ method: "head", operation:
|
|
94
|
-
{ method: "patch", operation:
|
|
95
|
-
{ method: "trace", operation:
|
|
88
|
+
{ method: "get", operation: t.get },
|
|
89
|
+
{ method: "put", operation: t.put },
|
|
90
|
+
{ method: "post", operation: t.post },
|
|
91
|
+
{ method: "delete", operation: t.delete },
|
|
92
|
+
{ method: "options", operation: t.options },
|
|
93
|
+
{ method: "head", operation: t.head },
|
|
94
|
+
{ method: "patch", operation: t.patch },
|
|
95
|
+
{ method: "trace", operation: t.trace }
|
|
96
96
|
].filter(({ operation: e }) => e !== void 0);
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
return
|
|
98
|
+
function _(t) {
|
|
99
|
+
return t.responses[200];
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
const e =
|
|
103
|
-
return
|
|
101
|
+
function M(t) {
|
|
102
|
+
const e = _(t);
|
|
103
|
+
return X(e);
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const te = [
|
|
106
|
+
"string",
|
|
107
|
+
"number",
|
|
108
|
+
"integer",
|
|
109
|
+
"boolean",
|
|
110
|
+
"null"
|
|
111
|
+
];
|
|
112
|
+
function ne(t) {
|
|
113
|
+
return Array.isArray(t) ? !0 : te.includes(t);
|
|
107
114
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
function re(t) {
|
|
116
|
+
return t.type === "array";
|
|
117
|
+
}
|
|
118
|
+
function oe(t) {
|
|
119
|
+
return Array.isArray(t.enum) && t.enum.length > 0;
|
|
120
|
+
}
|
|
121
|
+
function G(t) {
|
|
122
|
+
return Array.isArray(t.anyOf) && t.anyOf.length > 0;
|
|
123
|
+
}
|
|
124
|
+
function W(t) {
|
|
125
|
+
return Array.isArray(t.oneOf) && t.oneOf.length > 0;
|
|
126
|
+
}
|
|
127
|
+
function ae(t) {
|
|
128
|
+
return G(t) || W(t);
|
|
129
|
+
}
|
|
130
|
+
function se(t) {
|
|
131
|
+
return Array.isArray(t.allOf) && t.allOf.length > 0;
|
|
132
|
+
}
|
|
133
|
+
function j(t) {
|
|
134
|
+
return G(t) || W(t) || se(t);
|
|
135
|
+
}
|
|
136
|
+
function ie(t) {
|
|
137
|
+
return t.includes("|") || t.includes("&") ? `(${t})[]` : `${t}[]`;
|
|
138
|
+
}
|
|
139
|
+
function x(t) {
|
|
140
|
+
if (Array.isArray(t))
|
|
141
|
+
return t.map((e) => x(e)).join(" | ");
|
|
142
|
+
switch (t) {
|
|
112
143
|
case "string":
|
|
113
144
|
return "string";
|
|
114
145
|
case "number":
|
|
@@ -122,93 +153,291 @@ function $(r) {
|
|
|
122
153
|
return "any";
|
|
123
154
|
}
|
|
124
155
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
156
|
+
const E = "@ahoo-wang/fetcher-wow", ce = {
|
|
157
|
+
"wow.command.CommandResult": "CommandResult",
|
|
158
|
+
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
159
|
+
"wow.api.BindingError": "BindingError",
|
|
160
|
+
"wow.api.DefaultErrorInfo": "ErrorInfo",
|
|
161
|
+
"wow.api.RecoverableType": "RecoverableType",
|
|
162
|
+
"wow.api.command.DefaultDeleteAggregate": "DeleteAggregate",
|
|
163
|
+
"wow.api.command.DefaultRecoverAggregate": "RecoverAggregate",
|
|
164
|
+
"wow.api.messaging.FunctionInfoData": "FunctionInfo",
|
|
165
|
+
"wow.api.messaging.FunctionKind": "FunctionKind",
|
|
166
|
+
"wow.api.modeling.AggregateId": "AggregateId",
|
|
167
|
+
"wow.api.query.Condition": "Condition",
|
|
168
|
+
"wow.api.query.ConditionOptions": "ConditionOptions",
|
|
169
|
+
"wow.api.query.ListQuery": "ListQuery",
|
|
170
|
+
"wow.api.query.Operator": "Operator",
|
|
171
|
+
"wow.api.query.PagedQuery": "PagedQuery",
|
|
172
|
+
"wow.api.query.Pagination": "Pagination",
|
|
173
|
+
"wow.api.query.Projection": "Projection",
|
|
174
|
+
"wow.api.query.Sort": "FieldSort",
|
|
175
|
+
"wow.api.query.Sort.Direction": "SortDirection",
|
|
176
|
+
"wow.command.CommandStage": "CommandStage",
|
|
177
|
+
"wow.command.SimpleWaitSignal": "WaitSignal",
|
|
178
|
+
"wow.configuration.Aggregate": "Aggregate",
|
|
179
|
+
"wow.configuration.BoundedContext": "BoundedContext",
|
|
180
|
+
"wow.configuration.WowMetadata": "WowMetadata",
|
|
181
|
+
"wow.modeling.DomainEvent": "DomainEvent",
|
|
182
|
+
"wow.openapi.BatchResult": "BatchResult",
|
|
183
|
+
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
184
|
+
};
|
|
185
|
+
function l(t) {
|
|
186
|
+
if (!t)
|
|
187
|
+
return { name: "", path: "/" };
|
|
188
|
+
const e = ce[t];
|
|
189
|
+
if (e)
|
|
190
|
+
return { name: e, path: E };
|
|
191
|
+
const n = t.split(".");
|
|
192
|
+
let r = -1;
|
|
193
|
+
for (let i = 0; i < n.length; i++)
|
|
194
|
+
if (n[i] && /^[A-Z]/.test(n[i])) {
|
|
195
|
+
r = i;
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (r === -1)
|
|
199
|
+
return { name: t, path: "/" };
|
|
200
|
+
const o = n.slice(0, r), a = o.length > 0 ? `/${o.join("/")}` : "/", s = n.slice(r);
|
|
201
|
+
return { name: P(s), path: a };
|
|
202
|
+
}
|
|
203
|
+
class O {
|
|
204
|
+
/** The ts-morph project instance used for code generation */
|
|
205
|
+
project;
|
|
206
|
+
/** The OpenAPI specification object */
|
|
207
|
+
openAPI;
|
|
208
|
+
/** The output directory path for generated files */
|
|
209
|
+
outputDir;
|
|
210
|
+
/** Map of bounded context aggregates for domain modeling */
|
|
211
|
+
contextAggregates;
|
|
212
|
+
/** Optional logger for generation progress and errors */
|
|
213
|
+
logger;
|
|
214
|
+
/**
|
|
215
|
+
* Creates a new ClientGenerator instance.
|
|
216
|
+
* @param context - The generation context containing OpenAPI spec and project details
|
|
217
|
+
*/
|
|
218
|
+
constructor(e) {
|
|
219
|
+
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger;
|
|
220
|
+
}
|
|
128
221
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
222
|
+
class ue extends O {
|
|
223
|
+
constructor(e) {
|
|
224
|
+
super(e);
|
|
225
|
+
}
|
|
226
|
+
getOrCreateSourceFile(e) {
|
|
227
|
+
const n = B(e);
|
|
228
|
+
return v(this.project, this.outputDir, n);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Generates models for all schemas in the OpenAPI specification.
|
|
232
|
+
* Skips schemas with keys starting with 'wow.'.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* This method iterates through all schemas in the OpenAPI specification
|
|
236
|
+
* and generates corresponding TypeScript models for each one.
|
|
237
|
+
*/
|
|
238
|
+
generate() {
|
|
239
|
+
const e = this.openAPI.components?.schemas;
|
|
240
|
+
if (!e) {
|
|
241
|
+
this.logger.info("No schemas found in OpenAPI specification");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
this.logger.progress(
|
|
245
|
+
`Generating models for ${Object.keys(e).length} schemas`
|
|
246
|
+
), Object.entries(e).forEach(([n, r]) => {
|
|
247
|
+
if (n.startsWith("wow."))
|
|
248
|
+
return;
|
|
249
|
+
this.logger.progress(`Processing schema: ${n}`);
|
|
250
|
+
const o = {
|
|
251
|
+
key: n,
|
|
252
|
+
schema: r
|
|
253
|
+
};
|
|
254
|
+
this.generateKeyedSchema(o);
|
|
255
|
+
}), this.logger.success("Model generation completed");
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Generates a model for a specific schema key.
|
|
259
|
+
* Processes enums, objects, unions, and type aliases in order.
|
|
260
|
+
*
|
|
261
|
+
* @param schemaKey - The key of the schema to generate
|
|
262
|
+
* @param schema - The schema definition
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* The generation process follows this order:
|
|
266
|
+
* 1. Enum processing
|
|
267
|
+
* 2. Object processing
|
|
268
|
+
* 3. Union processing
|
|
269
|
+
* 4. Type alias processing
|
|
270
|
+
*/
|
|
271
|
+
generateKeyedSchema({ key: e, schema: n }) {
|
|
272
|
+
const r = l(e), o = this.getOrCreateSourceFile(r), a = this.process(r, o, n);
|
|
273
|
+
a && A(a, n.title, n.description);
|
|
274
|
+
}
|
|
275
|
+
process(e, n, r) {
|
|
276
|
+
if (oe(r))
|
|
277
|
+
return n.addEnum({
|
|
278
|
+
name: e.name,
|
|
279
|
+
isExported: !0,
|
|
280
|
+
members: r.enum.filter((a) => typeof a == "string" && a.length > 0).map((a) => ({
|
|
281
|
+
name: a,
|
|
282
|
+
initializer: `'${a}'`
|
|
283
|
+
}))
|
|
284
|
+
});
|
|
285
|
+
const o = n.addInterface({
|
|
286
|
+
name: e.name,
|
|
287
|
+
isExported: !0
|
|
288
|
+
});
|
|
289
|
+
return r.type === "object" && r.properties ? this.processInterface(n, e, r, o) : (j(r) && (r.anyOf || r.oneOf || r.allOf).forEach((s) => {
|
|
290
|
+
if (u(s)) {
|
|
291
|
+
const c = l(d(s));
|
|
292
|
+
N(e, n, this.outputDir, c), o.addExtends(c.name);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
this.processInterface(n, e, s, o);
|
|
296
|
+
}), o);
|
|
297
|
+
}
|
|
298
|
+
processObject(e, n, r) {
|
|
299
|
+
const o = e.addInterface({
|
|
300
|
+
name: n.name,
|
|
301
|
+
isExported: !0
|
|
302
|
+
});
|
|
303
|
+
return this.processInterface(e, n, r, o);
|
|
304
|
+
}
|
|
305
|
+
processInterface(e, n, r, o) {
|
|
306
|
+
for (const [a, s] of Object.entries(r.properties)) {
|
|
307
|
+
const c = this.resolvePropertyType(n, e, a, s);
|
|
308
|
+
let i = o.getProperty(a);
|
|
309
|
+
i ? i.setType(c) : i = o.addProperty({
|
|
310
|
+
name: a,
|
|
311
|
+
type: c
|
|
312
|
+
}), u(s) || A(i, s.title, s.description);
|
|
313
|
+
}
|
|
314
|
+
return o;
|
|
315
|
+
}
|
|
316
|
+
resolvePropertyType(e, n, r, o) {
|
|
317
|
+
if (u(o)) {
|
|
318
|
+
const a = l(d(o));
|
|
319
|
+
return N(e, n, this.outputDir, a), a.name;
|
|
320
|
+
}
|
|
321
|
+
if (o.const)
|
|
322
|
+
return `'${o.const}'`;
|
|
323
|
+
if (re(o)) {
|
|
324
|
+
const a = this.resolvePropertyType(e, n, r, o.items);
|
|
325
|
+
return ie(a);
|
|
326
|
+
}
|
|
327
|
+
if (o.type && ne(o.type))
|
|
328
|
+
return x(o.type);
|
|
329
|
+
if (j(o))
|
|
330
|
+
return this.resolvePropertyCompositionType(e, n, o);
|
|
331
|
+
if (o.type === "object" && o.properties) {
|
|
332
|
+
const a = {
|
|
333
|
+
path: e.path,
|
|
334
|
+
name: `${e.name}${P(r)}`
|
|
335
|
+
}, s = this.processObject(n, a, o);
|
|
336
|
+
return A(s, o.title, o.description), a.name;
|
|
337
|
+
}
|
|
338
|
+
return "any";
|
|
339
|
+
}
|
|
340
|
+
resolvePropertyCompositionType(e, n, r) {
|
|
341
|
+
const o = r.anyOf || r.oneOf || r.allOf, a = /* @__PURE__ */ new Set();
|
|
342
|
+
o.forEach((c) => {
|
|
343
|
+
if (u(c)) {
|
|
344
|
+
const i = l(d(c));
|
|
345
|
+
N(e, n, this.outputDir, i), a.add(i.name);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
a.add(x(c.type ?? "string"));
|
|
349
|
+
});
|
|
350
|
+
const s = ae(r) ? "|" : "&";
|
|
351
|
+
return Array.from(a).join(s);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const pe = "types.ts", I = "@";
|
|
355
|
+
function B(t) {
|
|
356
|
+
return C(t.path, pe);
|
|
357
|
+
}
|
|
358
|
+
function v(t, e, n) {
|
|
359
|
+
const r = C(e, n), o = t.getSourceFile(r);
|
|
360
|
+
return o || t.createSourceFile(r, "", {
|
|
132
361
|
overwrite: !0
|
|
133
362
|
});
|
|
134
363
|
}
|
|
135
|
-
function
|
|
136
|
-
let
|
|
364
|
+
function w(t, e, n) {
|
|
365
|
+
let r = t.getImportDeclaration(
|
|
137
366
|
(o) => o.getModuleSpecifierValue() === e
|
|
138
367
|
);
|
|
139
|
-
|
|
368
|
+
r || (r = t.addImportDeclaration({
|
|
140
369
|
moduleSpecifier: e
|
|
141
370
|
})), n.forEach((o) => {
|
|
142
|
-
|
|
371
|
+
r.getNamedImports().some(
|
|
143
372
|
(s) => s.getName() === o
|
|
144
|
-
) ||
|
|
373
|
+
) || r.addNamedImport(o);
|
|
145
374
|
});
|
|
146
375
|
}
|
|
147
|
-
function
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
376
|
+
function h(t, e, n) {
|
|
377
|
+
if (n.path === E) {
|
|
378
|
+
w(t, n.path, [n.name]);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
let r = B(n);
|
|
382
|
+
n.path.startsWith(I) || (r = C(e, r));
|
|
383
|
+
let o = r;
|
|
384
|
+
r.startsWith(I) || (o = C(I, r)), w(t, o, [n.name]);
|
|
152
385
|
}
|
|
153
|
-
function
|
|
154
|
-
|
|
386
|
+
function N(t, e, n, r) {
|
|
387
|
+
t.path !== r.path && h(e, n, r);
|
|
155
388
|
}
|
|
156
|
-
function
|
|
157
|
-
const n = [
|
|
158
|
-
(
|
|
389
|
+
function me(t, e) {
|
|
390
|
+
const n = [t, e].filter(
|
|
391
|
+
(r) => r !== void 0 && r.length > 0
|
|
159
392
|
);
|
|
160
393
|
return n.length > 0 ? n.join(`
|
|
161
394
|
`) : void 0;
|
|
162
395
|
}
|
|
163
|
-
function
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function G(r, e, n) {
|
|
168
|
-
const t = _(e, n);
|
|
169
|
-
t && r.addJsDoc({
|
|
170
|
-
description: t
|
|
396
|
+
function A(t, e, n) {
|
|
397
|
+
const r = me(e, n);
|
|
398
|
+
r && t.addJsDoc({
|
|
399
|
+
description: r
|
|
171
400
|
});
|
|
172
401
|
}
|
|
173
|
-
function
|
|
174
|
-
const e =
|
|
402
|
+
function ge(t) {
|
|
403
|
+
const e = t.split(".");
|
|
175
404
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
176
405
|
}
|
|
177
|
-
function
|
|
178
|
-
const e =
|
|
406
|
+
function le(t) {
|
|
407
|
+
const e = ge(t.name);
|
|
179
408
|
return e ? {
|
|
180
|
-
tag:
|
|
409
|
+
tag: t,
|
|
181
410
|
contextAlias: e[0],
|
|
182
411
|
aggregateName: e[1]
|
|
183
412
|
} : null;
|
|
184
413
|
}
|
|
185
|
-
function
|
|
186
|
-
const e =
|
|
414
|
+
function de(t) {
|
|
415
|
+
const e = t?.map((r) => le(r)).filter((r) => r !== null);
|
|
187
416
|
if (!e)
|
|
188
417
|
return /* @__PURE__ */ new Map();
|
|
189
418
|
const n = /* @__PURE__ */ new Map();
|
|
190
|
-
return e.forEach((
|
|
191
|
-
n.set(
|
|
192
|
-
aggregate:
|
|
419
|
+
return e.forEach((r) => {
|
|
420
|
+
n.set(r.tag.name, {
|
|
421
|
+
aggregate: r,
|
|
193
422
|
commands: /* @__PURE__ */ new Map(),
|
|
194
423
|
events: /* @__PURE__ */ new Map()
|
|
195
424
|
});
|
|
196
425
|
}), n;
|
|
197
426
|
}
|
|
198
|
-
function
|
|
199
|
-
if (!
|
|
427
|
+
function fe(t) {
|
|
428
|
+
if (!t)
|
|
200
429
|
return null;
|
|
201
|
-
const e =
|
|
430
|
+
const e = t.split(".");
|
|
202
431
|
return e.length != 3 ? null : e[2];
|
|
203
432
|
}
|
|
204
|
-
const
|
|
205
|
-
class
|
|
433
|
+
const he = "#/components/responses/wow.CommandOk", ye = "#/components/parameters/wow.id";
|
|
434
|
+
class Ae {
|
|
206
435
|
/**
|
|
207
436
|
* Creates a new AggregateResolver instance.
|
|
208
437
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
209
438
|
*/
|
|
210
439
|
constructor(e) {
|
|
211
|
-
this.openAPI = e, this.aggregates =
|
|
440
|
+
this.openAPI = e, this.aggregates = de(e.tags), this.build();
|
|
212
441
|
}
|
|
213
442
|
aggregates;
|
|
214
443
|
/**
|
|
@@ -217,8 +446,8 @@ class ce {
|
|
|
217
446
|
*/
|
|
218
447
|
build() {
|
|
219
448
|
for (const [e, n] of Object.entries(this.openAPI.paths)) {
|
|
220
|
-
const
|
|
221
|
-
for (const o of
|
|
449
|
+
const r = ee(n);
|
|
450
|
+
for (const o of r)
|
|
222
451
|
this.commands(e, o), this.state(o.operation), this.events(o.operation), this.fields(o.operation);
|
|
223
452
|
}
|
|
224
453
|
}
|
|
@@ -231,9 +460,9 @@ class ce {
|
|
|
231
460
|
for (const n of this.aggregates.values()) {
|
|
232
461
|
if (!n.state || !n.fields)
|
|
233
462
|
continue;
|
|
234
|
-
const
|
|
235
|
-
let o = e.get(
|
|
236
|
-
o || (o = /* @__PURE__ */ new Set(), e.set(
|
|
463
|
+
const r = n.aggregate.contextAlias;
|
|
464
|
+
let o = e.get(r);
|
|
465
|
+
o || (o = /* @__PURE__ */ new Set(), e.set(r, o)), o.add(n);
|
|
237
466
|
}
|
|
238
467
|
return e;
|
|
239
468
|
}
|
|
@@ -243,43 +472,43 @@ class ce {
|
|
|
243
472
|
* @param methodOperation - The HTTP method and operation details
|
|
244
473
|
*/
|
|
245
474
|
commands(e, n) {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
475
|
+
const r = n.operation;
|
|
476
|
+
if (r.operationId === "wow.command.send")
|
|
248
477
|
return;
|
|
249
|
-
const o =
|
|
478
|
+
const o = fe(r.operationId);
|
|
250
479
|
if (!o)
|
|
251
480
|
return;
|
|
252
|
-
const a =
|
|
253
|
-
if (!a || !
|
|
481
|
+
const a = _(r);
|
|
482
|
+
if (!a || !u(a) || a.$ref !== he || !r.requestBody)
|
|
254
483
|
return;
|
|
255
|
-
const s =
|
|
256
|
-
(
|
|
484
|
+
const s = r.parameters ?? [], c = s.filter((p) => u(p) && p.$ref === ye).at(0), i = s.filter(
|
|
485
|
+
(p) => !u(p) && p.in === "path"
|
|
257
486
|
);
|
|
258
487
|
if (c) {
|
|
259
|
-
const
|
|
488
|
+
const p = U(
|
|
260
489
|
c,
|
|
261
490
|
this.openAPI.components
|
|
262
491
|
);
|
|
263
|
-
i.push(
|
|
492
|
+
i.push(p);
|
|
264
493
|
}
|
|
265
|
-
const
|
|
266
|
-
|
|
494
|
+
const g = r.requestBody.content[T.APPLICATION_JSON].schema, f = y(
|
|
495
|
+
g,
|
|
267
496
|
this.openAPI.components
|
|
268
497
|
);
|
|
269
|
-
|
|
270
|
-
const
|
|
498
|
+
f.schema.title = f.schema.title || r.summary, f.schema.description = f.schema.description || r.description;
|
|
499
|
+
const L = {
|
|
271
500
|
name: o,
|
|
272
501
|
method: n.method,
|
|
273
502
|
path: e,
|
|
274
503
|
pathParameters: i,
|
|
275
|
-
summary:
|
|
276
|
-
description:
|
|
277
|
-
schema:
|
|
278
|
-
operation:
|
|
504
|
+
summary: r.summary,
|
|
505
|
+
description: r.description,
|
|
506
|
+
schema: f,
|
|
507
|
+
operation: r
|
|
279
508
|
};
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
|
|
509
|
+
r.tags?.forEach((p) => {
|
|
510
|
+
const D = this.aggregates.get(p);
|
|
511
|
+
D && D.commands.set(o, L);
|
|
283
512
|
});
|
|
284
513
|
}
|
|
285
514
|
/**
|
|
@@ -289,16 +518,16 @@ class ce {
|
|
|
289
518
|
state(e) {
|
|
290
519
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
291
520
|
return;
|
|
292
|
-
const n =
|
|
293
|
-
if (!
|
|
521
|
+
const n = M(e);
|
|
522
|
+
if (!u(n))
|
|
294
523
|
return;
|
|
295
|
-
const
|
|
524
|
+
const r = y(
|
|
296
525
|
n,
|
|
297
526
|
this.openAPI.components
|
|
298
527
|
);
|
|
299
528
|
e.tags?.forEach((o) => {
|
|
300
529
|
const a = this.aggregates.get(o);
|
|
301
|
-
a && (a.state =
|
|
530
|
+
a && (a.state = r);
|
|
302
531
|
});
|
|
303
532
|
}
|
|
304
533
|
/**
|
|
@@ -308,24 +537,24 @@ class ce {
|
|
|
308
537
|
events(e) {
|
|
309
538
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
310
539
|
return;
|
|
311
|
-
const n =
|
|
312
|
-
if (
|
|
540
|
+
const n = M(e);
|
|
541
|
+
if (u(n))
|
|
313
542
|
return;
|
|
314
|
-
const
|
|
315
|
-
if (!
|
|
543
|
+
const r = n?.items;
|
|
544
|
+
if (!u(r))
|
|
316
545
|
return;
|
|
317
|
-
const a =
|
|
318
|
-
|
|
546
|
+
const a = R(
|
|
547
|
+
r,
|
|
319
548
|
this.openAPI.components
|
|
320
549
|
).properties.body.items.anyOf.map((s) => {
|
|
321
|
-
const c = s.title, i = s.properties.name.const,
|
|
322
|
-
|
|
550
|
+
const c = s.title, i = s.properties.name.const, m = s.properties.body, g = y(
|
|
551
|
+
m,
|
|
323
552
|
this.openAPI.components
|
|
324
553
|
);
|
|
325
|
-
return
|
|
554
|
+
return g.schema.title = g.schema.title || s.title, {
|
|
326
555
|
title: c,
|
|
327
556
|
name: i,
|
|
328
|
-
schema:
|
|
557
|
+
schema: g
|
|
329
558
|
};
|
|
330
559
|
});
|
|
331
560
|
e.tags?.forEach((s) => {
|
|
@@ -342,11 +571,11 @@ class ce {
|
|
|
342
571
|
fields(e) {
|
|
343
572
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
344
573
|
return;
|
|
345
|
-
const
|
|
574
|
+
const r = J(
|
|
346
575
|
e.requestBody,
|
|
347
576
|
this.openAPI.components
|
|
348
|
-
).content[
|
|
349
|
-
|
|
577
|
+
).content[T.APPLICATION_JSON].schema, a = R(
|
|
578
|
+
r,
|
|
350
579
|
this.openAPI.components
|
|
351
580
|
).properties?.field, s = y(a, this.openAPI.components);
|
|
352
581
|
e.tags?.forEach((c) => {
|
|
@@ -355,277 +584,20 @@ class ce {
|
|
|
355
584
|
});
|
|
356
585
|
}
|
|
357
586
|
}
|
|
358
|
-
|
|
359
|
-
"wow.command.CommandResult": "CommandResult",
|
|
360
|
-
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
361
|
-
"wow.api.BindingError": "BindingError",
|
|
362
|
-
"wow.api.DefaultErrorInfo": "ErrorInfo",
|
|
363
|
-
"wow.api.RecoverableType": "RecoverableType",
|
|
364
|
-
"wow.api.command.DefaultDeleteAggregate": "DeleteAggregate",
|
|
365
|
-
"wow.api.command.DefaultRecoverAggregate": "RecoverAggregate",
|
|
366
|
-
"wow.api.messaging.FunctionInfoData": "FunctionInfo",
|
|
367
|
-
"wow.api.messaging.FunctionKind": "FunctionKind",
|
|
368
|
-
"wow.api.modeling.AggregateId": "AggregateId",
|
|
369
|
-
"wow.api.query.Condition": "Condition",
|
|
370
|
-
"wow.api.query.ConditionOptions": "ConditionOptions",
|
|
371
|
-
"wow.api.query.ListQuery": "ListQuery",
|
|
372
|
-
"wow.api.query.Operator": "Operator",
|
|
373
|
-
"wow.api.query.PagedQuery": "PagedQuery",
|
|
374
|
-
"wow.api.query.Pagination": "Pagination",
|
|
375
|
-
"wow.api.query.Projection": "Projection",
|
|
376
|
-
"wow.api.query.Sort": "FieldSort",
|
|
377
|
-
"wow.api.query.Sort.Direction": "SortDirection",
|
|
378
|
-
"wow.command.CommandStage": "CommandStage",
|
|
379
|
-
"wow.command.SimpleWaitSignal": "WaitSignal",
|
|
380
|
-
"wow.configuration.Aggregate": "Aggregate",
|
|
381
|
-
"wow.configuration.BoundedContext": "BoundedContext",
|
|
382
|
-
"wow.configuration.WowMetadata": "WowMetadata",
|
|
383
|
-
"wow.modeling.DomainEvent": "DomainEvent",
|
|
384
|
-
"wow.openapi.BatchResult": "BatchResult",
|
|
385
|
-
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
386
|
-
};
|
|
387
|
-
function g(r) {
|
|
388
|
-
if (!r)
|
|
389
|
-
return { name: "", path: "/" };
|
|
390
|
-
const e = pe[r];
|
|
391
|
-
if (e)
|
|
392
|
-
return { name: e, path: v };
|
|
393
|
-
const n = r.split(".");
|
|
394
|
-
let t = -1;
|
|
395
|
-
for (let i = 0; i < n.length; i++)
|
|
396
|
-
if (n[i] && /^[A-Z]/.test(n[i])) {
|
|
397
|
-
t = i;
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
if (t === -1)
|
|
401
|
-
return { name: r, path: "/" };
|
|
402
|
-
const o = n.slice(0, t), a = o.length > 0 ? `/${o.join("/")}` : "/", s = n.slice(t);
|
|
403
|
-
return { name: O(s), path: a };
|
|
404
|
-
}
|
|
405
|
-
class C {
|
|
406
|
-
project;
|
|
407
|
-
openAPI;
|
|
408
|
-
outputDir;
|
|
409
|
-
contextAggregates;
|
|
410
|
-
logger;
|
|
411
|
-
/**
|
|
412
|
-
* Creates a new ClientGenerator instance.
|
|
413
|
-
* @param context - The generation context containing OpenAPI spec and project details
|
|
414
|
-
*/
|
|
415
|
-
constructor(e) {
|
|
416
|
-
this.project = e.project, this.openAPI = e.openAPI, this.outputDir = e.outputDir, this.contextAggregates = e.contextAggregates, this.logger = e.logger;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
class me extends C {
|
|
420
|
-
constructor(e) {
|
|
421
|
-
super(e);
|
|
422
|
-
}
|
|
423
|
-
getOrCreateSourceFile(e) {
|
|
424
|
-
const n = q(e);
|
|
425
|
-
return T(this.project, this.outputDir, n);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Generates models for all schemas in the OpenAPI specification.
|
|
429
|
-
* Skips schemas with keys starting with 'wow.'.
|
|
430
|
-
*
|
|
431
|
-
* @remarks
|
|
432
|
-
* This method iterates through all schemas in the OpenAPI specification
|
|
433
|
-
* and generates corresponding TypeScript models for each one.
|
|
434
|
-
*/
|
|
435
|
-
generate() {
|
|
436
|
-
const e = this.openAPI.components?.schemas;
|
|
437
|
-
if (!e) {
|
|
438
|
-
this.logger?.info("No schemas found in OpenAPI specification");
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
this.logger?.progress(
|
|
442
|
-
`Generating models for ${Object.keys(e).length} schemas`
|
|
443
|
-
), Object.entries(e).forEach(([n, t]) => {
|
|
444
|
-
n.startsWith("wow.") || (this.logger?.progress(`Processing schema: ${n}`), this.generateKeyedSchema(n, t));
|
|
445
|
-
}), this.logger?.success("Model generation completed");
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Generates a model for a specific schema key.
|
|
449
|
-
* Processes enums, objects, unions, and type aliases in order.
|
|
450
|
-
*
|
|
451
|
-
* @param schemaKey - The key of the schema to generate
|
|
452
|
-
* @param schema - The schema definition
|
|
453
|
-
*
|
|
454
|
-
* @remarks
|
|
455
|
-
* The generation process follows this order:
|
|
456
|
-
* 1. Enum processing
|
|
457
|
-
* 2. Object processing
|
|
458
|
-
* 3. Union processing
|
|
459
|
-
* 4. Type alias processing
|
|
460
|
-
*/
|
|
461
|
-
generateKeyedSchema(e, n) {
|
|
462
|
-
const t = g(e), o = this.getOrCreateSourceFile(t), a = this.process(t, o, n);
|
|
463
|
-
return G(a, n.title, n.description), o;
|
|
464
|
-
}
|
|
465
|
-
process(e, n, t) {
|
|
466
|
-
let o = this.processEnum(
|
|
467
|
-
e,
|
|
468
|
-
n,
|
|
469
|
-
t
|
|
470
|
-
);
|
|
471
|
-
return o || (o = this.processObject(e, n, t), o) || (o = this.processUnion(e, n, t), o) ? o : this.processTypeAlias(e, n, t);
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Processes enum schemas and generates TypeScript enums.
|
|
475
|
-
*
|
|
476
|
-
* @param modelInfo - The model information
|
|
477
|
-
* @param sourceFile - The source file to add the enum to
|
|
478
|
-
* @param schema - The enum schema
|
|
479
|
-
* @returns true if the schema was processed as an enum, false otherwise
|
|
480
|
-
*
|
|
481
|
-
* @remarks
|
|
482
|
-
* This method filters out non-string enum values and generates
|
|
483
|
-
* a TypeScript enum with string literal initializers.
|
|
484
|
-
*/
|
|
485
|
-
processEnum(e, n, t) {
|
|
486
|
-
if (X(t))
|
|
487
|
-
return n.addEnum({
|
|
488
|
-
name: e.name,
|
|
489
|
-
isExported: !0,
|
|
490
|
-
members: t.enum.filter((o) => typeof o == "string" && o.length > 0).map((o) => ({
|
|
491
|
-
name: o,
|
|
492
|
-
initializer: `'${o}'`
|
|
493
|
-
}))
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* Processes object schemas and generates TypeScript interfaces.
|
|
498
|
-
*
|
|
499
|
-
* @param modelInfo - The model information
|
|
500
|
-
* @param sourceFile - The source file to add the interface to
|
|
501
|
-
* @param schema - The object schema
|
|
502
|
-
* @returns true if the schema was processed as an object, false otherwise
|
|
503
|
-
*
|
|
504
|
-
* @remarks
|
|
505
|
-
* This method handles optional properties by checking the required array
|
|
506
|
-
* and adds undefined union types for optional properties.
|
|
507
|
-
*/
|
|
508
|
-
processObject(e, n, t) {
|
|
509
|
-
if (t.type !== "object" || !t.properties)
|
|
510
|
-
return;
|
|
511
|
-
const o = {}, a = t.required || [];
|
|
512
|
-
for (const [s, c] of Object.entries(t.properties)) {
|
|
513
|
-
const i = this.resolveType(e, n, c), p = !a.includes(s);
|
|
514
|
-
o[s] = p ? `${i} | undefined` : i;
|
|
515
|
-
}
|
|
516
|
-
return n.addInterface({
|
|
517
|
-
name: e.name,
|
|
518
|
-
isExported: !0,
|
|
519
|
-
properties: Object.entries(o).map(([s, c]) => ({
|
|
520
|
-
name: s,
|
|
521
|
-
type: c
|
|
522
|
-
}))
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Processes union schemas (allOf, anyOf, oneOf) and generates TypeScript type aliases.
|
|
527
|
-
*
|
|
528
|
-
* @param modelInfo - The model information
|
|
529
|
-
* @param sourceFile - The source file to add the type alias to
|
|
530
|
-
* @param schema - The union schema
|
|
531
|
-
* @returns true if the schema was processed as a union, false otherwise
|
|
532
|
-
*
|
|
533
|
-
* @remarks
|
|
534
|
-
* This method handles three types of unions:
|
|
535
|
-
* - allOf: Generates intersection types (&)
|
|
536
|
-
* - anyOf: Generates union types (|)
|
|
537
|
-
* - oneOf: Generates union types (|)
|
|
538
|
-
*/
|
|
539
|
-
processUnion(e, n, t) {
|
|
540
|
-
let o = null;
|
|
541
|
-
if (t.allOf ? o = t.allOf.map((a) => this.resolveType(e, n, a)).join(" & ") : t.anyOf ? o = t.anyOf.map((a) => this.resolveType(e, n, a)).join(" | ") : t.oneOf && (o = t.oneOf.map((a) => this.resolveType(e, n, a)).join(" | ")), !!o)
|
|
542
|
-
return n.addTypeAlias({
|
|
543
|
-
name: e.name,
|
|
544
|
-
type: o,
|
|
545
|
-
isExported: !0,
|
|
546
|
-
docs: D(t.title, t.description)
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Processes type alias schemas and generates TypeScript type aliases.
|
|
551
|
-
*
|
|
552
|
-
* @param modelInfo - The model information
|
|
553
|
-
* @param sourceFile - The source file to add the type alias to
|
|
554
|
-
* @param schema - The schema to process
|
|
555
|
-
*
|
|
556
|
-
* @remarks
|
|
557
|
-
* This method is used as a fallback for schemas that don't match
|
|
558
|
-
* enum, object, or union patterns. It resolves the type and creates
|
|
559
|
-
* a simple type alias.
|
|
560
|
-
*/
|
|
561
|
-
processTypeAlias(e, n, t) {
|
|
562
|
-
const o = this.resolveType(e, n, t);
|
|
563
|
-
return n.addTypeAlias({
|
|
564
|
-
name: e.name,
|
|
565
|
-
type: o,
|
|
566
|
-
isExported: !0,
|
|
567
|
-
docs: D(t.title, t.description)
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Resolves the TypeScript type for a given schema or reference.
|
|
572
|
-
* Handles arrays, objects, primitives, and references.
|
|
573
|
-
*
|
|
574
|
-
* @param modelInfo - The model information
|
|
575
|
-
* @param sourceFile - The source file for import management
|
|
576
|
-
* @param schema - The schema or reference to resolve
|
|
577
|
-
* @returns The resolved TypeScript type as a string
|
|
578
|
-
*
|
|
579
|
-
* @remarks
|
|
580
|
-
* This method handles various schema types:
|
|
581
|
-
* - References: Resolves to imported types
|
|
582
|
-
* - Arrays: Resolves item types and adds array notation
|
|
583
|
-
* - Objects: Resolves to Record<string, any> for generic objects
|
|
584
|
-
* - Primitives: Maps to TypeScript primitives
|
|
585
|
-
* - Nullable: Adds null union type
|
|
586
|
-
*/
|
|
587
|
-
resolveType(e, n, t) {
|
|
588
|
-
if (l(t))
|
|
589
|
-
return this.resolveReference(e, n, t);
|
|
590
|
-
if (t.type === "array")
|
|
591
|
-
return `${t.items ? this.resolveType(e, n, t.items) : "any"}[]`;
|
|
592
|
-
if (t.type === "object" && !t.properties)
|
|
593
|
-
return "Record<string, any>";
|
|
594
|
-
let o;
|
|
595
|
-
return t.type ? o = $(t.type) : o = "any", t.nullable && (o = `${o} | null`), o;
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Resolves a reference to another schema.
|
|
599
|
-
* Handles mapped types and imports.
|
|
600
|
-
*
|
|
601
|
-
* @param modelInfo - The current model information
|
|
602
|
-
* @param sourceFile - The source file for import management
|
|
603
|
-
* @param ref - The reference to resolve
|
|
604
|
-
* @returns The resolved type name
|
|
605
|
-
*
|
|
606
|
-
* @remarks
|
|
607
|
-
* This method checks for mapped types first (WOW_TYPE_MAPPING).
|
|
608
|
-
* If not found, it adds an import for the referenced model.
|
|
609
|
-
*/
|
|
610
|
-
resolveReference(e, n, t) {
|
|
611
|
-
const o = h(t), a = g(o);
|
|
612
|
-
return te(e, n, this.outputDir, a), a.name;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function ue(r) {
|
|
587
|
+
function Ce(t) {
|
|
616
588
|
let e = 0, n = 0;
|
|
617
|
-
return
|
|
618
|
-
|
|
589
|
+
return t.commands.forEach((r) => {
|
|
590
|
+
r.path.startsWith(b.TENANT) && (e += 1), r.path.startsWith(b.OWNER) && (n += 1);
|
|
619
591
|
}), e === 0 && n === 0 ? "ResourceAttributionPathSpec.NONE" : e > n ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
620
592
|
}
|
|
621
|
-
function
|
|
622
|
-
const o = `${n.contextAlias}/${n.aggregateName}/${
|
|
623
|
-
return
|
|
593
|
+
function F(t, e, n, r) {
|
|
594
|
+
const o = `${n.contextAlias}/${n.aggregateName}/${r}.ts`;
|
|
595
|
+
return v(t, e, o);
|
|
624
596
|
}
|
|
625
|
-
function
|
|
626
|
-
return `${
|
|
597
|
+
function we(t, e) {
|
|
598
|
+
return `${P(t.aggregateName)}${e}`;
|
|
627
599
|
}
|
|
628
|
-
class
|
|
600
|
+
class Pe extends O {
|
|
629
601
|
/**
|
|
630
602
|
* Creates a new QueryClientGenerator instance.
|
|
631
603
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -638,16 +610,16 @@ class ge extends C {
|
|
|
638
610
|
*/
|
|
639
611
|
generate() {
|
|
640
612
|
const e = Array.from(this.contextAggregates.values()).flat().length;
|
|
641
|
-
this.logger
|
|
613
|
+
this.logger.progress(
|
|
642
614
|
`Generating query clients for ${e} aggregates`
|
|
643
615
|
);
|
|
644
616
|
for (const [, n] of this.contextAggregates)
|
|
645
|
-
n.forEach((
|
|
646
|
-
this.logger
|
|
647
|
-
`Processing query client for aggregate: ${
|
|
648
|
-
), this.processQueryClient(
|
|
617
|
+
n.forEach((r) => {
|
|
618
|
+
this.logger.progress(
|
|
619
|
+
`Processing query client for aggregate: ${r.aggregate.aggregateName}`
|
|
620
|
+
), this.processQueryClient(r);
|
|
649
621
|
});
|
|
650
|
-
this.logger
|
|
622
|
+
this.logger.success("Query client generation completed");
|
|
651
623
|
}
|
|
652
624
|
/**
|
|
653
625
|
* Creates or retrieves a source file for client generation.
|
|
@@ -656,7 +628,7 @@ class ge extends C {
|
|
|
656
628
|
* @returns The source file for the client
|
|
657
629
|
*/
|
|
658
630
|
createClientFilePath(e, n) {
|
|
659
|
-
return
|
|
631
|
+
return F(
|
|
660
632
|
this.project,
|
|
661
633
|
this.outputDir,
|
|
662
634
|
e,
|
|
@@ -673,53 +645,53 @@ class ge extends C {
|
|
|
673
645
|
"queryClient"
|
|
674
646
|
);
|
|
675
647
|
n.addImportDeclaration({
|
|
676
|
-
moduleSpecifier:
|
|
648
|
+
moduleSpecifier: E,
|
|
677
649
|
namedImports: [
|
|
678
650
|
"QueryClientFactory",
|
|
679
651
|
"QueryClientOptions",
|
|
680
652
|
"ResourceAttributionPathSpec"
|
|
681
653
|
]
|
|
682
654
|
});
|
|
683
|
-
const
|
|
655
|
+
const r = "DEFAULT_QUERY_CLIENT_OPTIONS";
|
|
684
656
|
n.addVariableStatement({
|
|
685
657
|
declarationKind: S.Const,
|
|
686
658
|
declarations: [
|
|
687
659
|
{
|
|
688
|
-
name:
|
|
660
|
+
name: r,
|
|
689
661
|
type: "QueryClientOptions",
|
|
690
662
|
initializer: `{
|
|
691
663
|
contextAlias: '${e.aggregate.contextAlias}',
|
|
692
664
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
693
|
-
resourceAttribution: ${
|
|
665
|
+
resourceAttribution: ${Ce(e)},
|
|
694
666
|
}`
|
|
695
667
|
}
|
|
696
668
|
],
|
|
697
669
|
isExported: !1
|
|
698
670
|
});
|
|
699
671
|
const o = [];
|
|
700
|
-
for (const
|
|
701
|
-
const
|
|
702
|
-
|
|
672
|
+
for (const m of e.events.values()) {
|
|
673
|
+
const g = l(m.schema.key);
|
|
674
|
+
h(n, this.outputDir, g), o.push(g);
|
|
703
675
|
}
|
|
704
676
|
const a = "DOMAIN_EVENT_TYPES";
|
|
705
677
|
n.addTypeAlias({
|
|
706
678
|
name: a,
|
|
707
|
-
type: o.map((
|
|
679
|
+
type: o.map((m) => m.name).join(" | ")
|
|
708
680
|
});
|
|
709
|
-
const s = `${
|
|
710
|
-
|
|
681
|
+
const s = `${q(e.aggregate.aggregateName)}QueryClientFactory`, c = l(e.state.key), i = l(e.fields.key);
|
|
682
|
+
h(n, this.outputDir, c), h(n, this.outputDir, i), n.addVariableStatement({
|
|
711
683
|
declarationKind: S.Const,
|
|
712
684
|
declarations: [
|
|
713
685
|
{
|
|
714
686
|
name: s,
|
|
715
|
-
initializer: `new QueryClientFactory<${c.name}, ${i.name} | string, ${a}>(${
|
|
687
|
+
initializer: `new QueryClientFactory<${c.name}, ${i.name} | string, ${a}>(${r})`
|
|
716
688
|
}
|
|
717
689
|
],
|
|
718
690
|
isExported: !0
|
|
719
691
|
});
|
|
720
692
|
}
|
|
721
693
|
}
|
|
722
|
-
class
|
|
694
|
+
class Ee extends O {
|
|
723
695
|
commandEndpointPathsName = "COMMAND_ENDPOINT_PATHS";
|
|
724
696
|
defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
725
697
|
/**
|
|
@@ -734,23 +706,23 @@ class de extends C {
|
|
|
734
706
|
*/
|
|
735
707
|
generate() {
|
|
736
708
|
const e = Array.from(this.contextAggregates.values()).flat().length;
|
|
737
|
-
this.logger
|
|
709
|
+
this.logger.progress(
|
|
738
710
|
`Generating command clients for ${e} aggregates`
|
|
739
711
|
);
|
|
740
712
|
for (const [, n] of this.contextAggregates)
|
|
741
|
-
n.forEach((
|
|
742
|
-
this.logger
|
|
743
|
-
`Processing command client for aggregate: ${
|
|
744
|
-
), this.processAggregate(
|
|
713
|
+
n.forEach((r) => {
|
|
714
|
+
this.logger.progress(
|
|
715
|
+
`Processing command client for aggregate: ${r.aggregate.aggregateName}`
|
|
716
|
+
), this.processAggregate(r);
|
|
745
717
|
});
|
|
746
|
-
this.logger
|
|
718
|
+
this.logger.success("Command client generation completed");
|
|
747
719
|
}
|
|
748
720
|
/**
|
|
749
721
|
* Processes and generates command client for an aggregate.
|
|
750
722
|
* @param aggregate - The aggregate definition
|
|
751
723
|
*/
|
|
752
724
|
processAggregate(e) {
|
|
753
|
-
const n =
|
|
725
|
+
const n = F(
|
|
754
726
|
this.project,
|
|
755
727
|
this.outputDir,
|
|
756
728
|
e.aggregate,
|
|
@@ -769,7 +741,7 @@ class de extends C {
|
|
|
769
741
|
],
|
|
770
742
|
isExported: !1
|
|
771
743
|
}), n.addImportDeclaration({
|
|
772
|
-
moduleSpecifier:
|
|
744
|
+
moduleSpecifier: E,
|
|
773
745
|
namedImports: [
|
|
774
746
|
"CommandRequest",
|
|
775
747
|
"CommandResult",
|
|
@@ -781,12 +753,13 @@ class de extends C {
|
|
|
781
753
|
}), n.addImportDeclaration({
|
|
782
754
|
moduleSpecifier: "@ahoo-wang/fetcher-eventstream",
|
|
783
755
|
namedImports: ["JsonEventStreamResultExtractor"]
|
|
784
|
-
}),
|
|
756
|
+
}), w(n, "@ahoo-wang/fetcher", ["ContentTypeValues"]), w(n, "@ahoo-wang/fetcher-decorator", [
|
|
785
757
|
"type ApiMetadata",
|
|
786
758
|
"type ApiMetadataCapable",
|
|
787
759
|
"api",
|
|
788
760
|
"post",
|
|
789
761
|
"put",
|
|
762
|
+
"patch",
|
|
790
763
|
"del",
|
|
791
764
|
"request",
|
|
792
765
|
"attribute",
|
|
@@ -795,11 +768,11 @@ class de extends C {
|
|
|
795
768
|
]), this.processCommandClient(n, e), this.processCommandClient(n, e, !0);
|
|
796
769
|
}
|
|
797
770
|
processCommandEndpointPaths(e, n) {
|
|
798
|
-
const
|
|
771
|
+
const r = e.addEnum({
|
|
799
772
|
name: this.commandEndpointPathsName
|
|
800
773
|
});
|
|
801
774
|
n.commands.forEach((o) => {
|
|
802
|
-
|
|
775
|
+
r.addMember({
|
|
803
776
|
name: o.name.toUpperCase(),
|
|
804
777
|
initializer: `'${o.path}'`
|
|
805
778
|
});
|
|
@@ -808,12 +781,12 @@ class de extends C {
|
|
|
808
781
|
getEndpointPath(e) {
|
|
809
782
|
return `${this.commandEndpointPathsName}.${e.name.toUpperCase()}`;
|
|
810
783
|
}
|
|
811
|
-
processCommandClient(e, n,
|
|
784
|
+
processCommandClient(e, n, r = !1) {
|
|
812
785
|
let o = "CommandClient", a = {
|
|
813
786
|
name: "api",
|
|
814
787
|
arguments: []
|
|
815
788
|
}, s = "Promise<CommandResult>";
|
|
816
|
-
|
|
789
|
+
r && (o = "Stream" + o, a = {
|
|
817
790
|
name: "api",
|
|
818
791
|
arguments: [
|
|
819
792
|
"''",
|
|
@@ -823,7 +796,7 @@ class de extends C {
|
|
|
823
796
|
}`
|
|
824
797
|
]
|
|
825
798
|
}, s = "Promise<CommandResultEventStream>");
|
|
826
|
-
const c =
|
|
799
|
+
const c = we(
|
|
827
800
|
n.aggregate,
|
|
828
801
|
o
|
|
829
802
|
), i = e.addClass({
|
|
@@ -837,13 +810,13 @@ class de extends C {
|
|
|
837
810
|
{
|
|
838
811
|
name: "apiMetadata",
|
|
839
812
|
type: "ApiMetadata",
|
|
840
|
-
scope:
|
|
813
|
+
scope: k.Public,
|
|
841
814
|
isReadonly: !0,
|
|
842
815
|
initializer: `${this.defaultCommandClientOptionsName}`
|
|
843
816
|
}
|
|
844
817
|
]
|
|
845
|
-
}), n.commands.forEach((
|
|
846
|
-
this.processCommandMethod(e, i,
|
|
818
|
+
}), n.commands.forEach((m) => {
|
|
819
|
+
this.processCommandMethod(e, i, m, s);
|
|
847
820
|
});
|
|
848
821
|
}
|
|
849
822
|
methodToDecorator(e) {
|
|
@@ -855,10 +828,10 @@ class de extends C {
|
|
|
855
828
|
* @param client - The client class declaration
|
|
856
829
|
* @param definition - The command definition
|
|
857
830
|
*/
|
|
858
|
-
processCommandMethod(e, n,
|
|
859
|
-
const a =
|
|
860
|
-
|
|
861
|
-
const s =
|
|
831
|
+
processCommandMethod(e, n, r, o) {
|
|
832
|
+
const a = l(r.schema.key);
|
|
833
|
+
h(e, this.outputDir, a);
|
|
834
|
+
const s = r.pathParameters.map((i) => ({
|
|
862
835
|
name: i.name,
|
|
863
836
|
type: "string",
|
|
864
837
|
decorators: [
|
|
@@ -888,11 +861,11 @@ class de extends C {
|
|
|
888
861
|
]
|
|
889
862
|
});
|
|
890
863
|
const c = n.addMethod({
|
|
891
|
-
name:
|
|
864
|
+
name: q(r.name),
|
|
892
865
|
decorators: [
|
|
893
866
|
{
|
|
894
|
-
name: this.methodToDecorator(
|
|
895
|
-
arguments: [`${this.getEndpointPath(
|
|
867
|
+
name: this.methodToDecorator(r.method),
|
|
868
|
+
arguments: [`${this.getEndpointPath(r)}`]
|
|
896
869
|
}
|
|
897
870
|
],
|
|
898
871
|
parameters: s,
|
|
@@ -901,10 +874,10 @@ class de extends C {
|
|
|
901
874
|
`throw autoGeneratedError(${s.map((i) => i.name).join(",")});`
|
|
902
875
|
]
|
|
903
876
|
});
|
|
904
|
-
|
|
877
|
+
A(c, r.summary, r.description);
|
|
905
878
|
}
|
|
906
879
|
}
|
|
907
|
-
class
|
|
880
|
+
class Oe extends O {
|
|
908
881
|
queryClientGenerator;
|
|
909
882
|
commandClientGenerator;
|
|
910
883
|
/**
|
|
@@ -912,18 +885,18 @@ class fe extends C {
|
|
|
912
885
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
913
886
|
*/
|
|
914
887
|
constructor(e) {
|
|
915
|
-
super(e), this.queryClientGenerator = new
|
|
888
|
+
super(e), this.queryClientGenerator = new Pe(e), this.commandClientGenerator = new Ee(e);
|
|
916
889
|
}
|
|
917
890
|
/**
|
|
918
891
|
* Generates client classes for all aggregates.
|
|
919
892
|
*/
|
|
920
893
|
generate() {
|
|
921
|
-
this.logger
|
|
894
|
+
this.logger.progress(
|
|
922
895
|
`Generating clients for ${this.contextAggregates.size} bounded contexts`
|
|
923
896
|
);
|
|
924
897
|
for (const [e] of this.contextAggregates)
|
|
925
|
-
this.logger
|
|
926
|
-
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.logger
|
|
898
|
+
this.logger.progress(`Processing bounded context: ${e}`), this.processBoundedContext(e);
|
|
899
|
+
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.logger.success("Client generation completed");
|
|
927
900
|
}
|
|
928
901
|
/**
|
|
929
902
|
* Processes a bounded context by creating a file with the context alias constant.
|
|
@@ -931,12 +904,12 @@ class fe extends C {
|
|
|
931
904
|
*/
|
|
932
905
|
processBoundedContext(e) {
|
|
933
906
|
const n = `${e}/boundedContext.ts`;
|
|
934
|
-
|
|
907
|
+
v(this.project, this.outputDir, n).addStatements(
|
|
935
908
|
`export const BOUNDED_CONTEXT_ALIAS = '${e}';`
|
|
936
909
|
);
|
|
937
910
|
}
|
|
938
911
|
}
|
|
939
|
-
class
|
|
912
|
+
class xe {
|
|
940
913
|
/**
|
|
941
914
|
* Creates a new CodeGenerator instance.
|
|
942
915
|
* @param options - Configuration options for code generation
|
|
@@ -951,18 +924,19 @@ class Se {
|
|
|
951
924
|
* and formats the output files.
|
|
952
925
|
*/
|
|
953
926
|
async generate() {
|
|
954
|
-
const e = await
|
|
927
|
+
const e = await Y(this.options.inputPath), r = new Ae(e).resolve(), o = {
|
|
955
928
|
openAPI: e,
|
|
956
929
|
project: this.project,
|
|
957
930
|
outputDir: this.options.outputDir,
|
|
958
|
-
contextAggregates:
|
|
931
|
+
contextAggregates: r,
|
|
959
932
|
logger: this.options.logger
|
|
960
933
|
};
|
|
961
|
-
new
|
|
934
|
+
new ue(o).generate(), new Oe(o).generate(), this.project.getSourceFiles().forEach((c) => {
|
|
962
935
|
c.formatText(), c.organizeImports(), c.fixMissingImports();
|
|
963
936
|
}), await this.project.save();
|
|
964
937
|
}
|
|
965
938
|
}
|
|
966
939
|
export {
|
|
967
|
-
|
|
940
|
+
xe as CodeGenerator
|
|
968
941
|
};
|
|
942
|
+
//# sourceMappingURL=index.js.map
|