@ahoo-wang/fetcher-generator 3.2.9 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +2 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +206 -208
- package/dist/index.js.map +1 -1
- package/dist/model/wowTypeMapping.d.ts +2 -0
- package/dist/model/wowTypeMapping.d.ts.map +1 -1
- package/dist/utils/sourceFiles.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Scope as
|
|
1
|
+
import { Scope as ye, VariableDeclarationKind as N, Project as xe } from "ts-morph";
|
|
2
2
|
import { ContentTypeValues as I, combineURLs as E } from "@ahoo-wang/fetcher";
|
|
3
3
|
import { ResourceAttributionPathSpec as L } from "@ahoo-wang/fetcher-wow";
|
|
4
|
-
import { parse as
|
|
5
|
-
import { readFile as
|
|
6
|
-
import { posix as B } from "path";
|
|
4
|
+
import { parse as K } from "yaml";
|
|
5
|
+
import { readFile as Ae } from "fs";
|
|
7
6
|
function P(n) {
|
|
8
7
|
return n.$ref.split("/").pop();
|
|
9
8
|
}
|
|
@@ -11,11 +10,11 @@ function S(n, e) {
|
|
|
11
10
|
const t = P(n);
|
|
12
11
|
return e.schemas?.[t];
|
|
13
12
|
}
|
|
14
|
-
function
|
|
13
|
+
function Y(n, e) {
|
|
15
14
|
const t = P(n);
|
|
16
15
|
return e.requestBodies?.[t];
|
|
17
16
|
}
|
|
18
|
-
function
|
|
17
|
+
function Z(n, e) {
|
|
19
18
|
const t = P(n);
|
|
20
19
|
return e.parameters?.[t];
|
|
21
20
|
}
|
|
@@ -25,14 +24,14 @@ function $(n, e) {
|
|
|
25
24
|
schema: S(n, e)
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
const
|
|
27
|
+
const Ce = /[-_'\s.]+/;
|
|
29
28
|
function O(n) {
|
|
30
|
-
return n.split(
|
|
29
|
+
return n.split(Ce);
|
|
31
30
|
}
|
|
32
|
-
function
|
|
33
|
-
return Array.isArray(n) ? n.flatMap((e) =>
|
|
31
|
+
function X(n) {
|
|
32
|
+
return Array.isArray(n) ? n.flatMap((e) => B(O(e))) : B(O(n));
|
|
34
33
|
}
|
|
35
|
-
function
|
|
34
|
+
function B(n) {
|
|
36
35
|
return n.flatMap((e) => {
|
|
37
36
|
if (e.length === 0)
|
|
38
37
|
return [];
|
|
@@ -46,7 +45,7 @@ function U(n) {
|
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
function R(n) {
|
|
49
|
-
return n === "" || n.length === 0 ? "" :
|
|
48
|
+
return n === "" || n.length === 0 ? "" : X(n).filter((t) => t.length > 0).map((t) => {
|
|
50
49
|
const o = t.charAt(0), r = t.slice(1);
|
|
51
50
|
return (/[a-zA-Z]/.test(o) ? o.toUpperCase() : o) + r.toLowerCase();
|
|
52
51
|
}).join("");
|
|
@@ -55,42 +54,42 @@ function f(n) {
|
|
|
55
54
|
const e = R(n);
|
|
56
55
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
56
|
}
|
|
58
|
-
function
|
|
59
|
-
return n === "" || Array.isArray(n) && n.length === 0 ? "" :
|
|
57
|
+
function ee(n) {
|
|
58
|
+
return n === "" || Array.isArray(n) && n.length === 0 ? "" : X(n).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
59
|
}
|
|
61
60
|
function M(n) {
|
|
62
61
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n) ? n : `'${n}'`;
|
|
63
62
|
}
|
|
64
|
-
function
|
|
65
|
-
return /^\d+$/.test(n) ? `NUM_${n}` : M(
|
|
63
|
+
function Pe(n) {
|
|
64
|
+
return /^\d+$/.test(n) ? `NUM_${n}` : M(ee(n));
|
|
66
65
|
}
|
|
67
|
-
function
|
|
66
|
+
function g(n) {
|
|
68
67
|
return !!(n && typeof n == "object" && "$ref" in n);
|
|
69
68
|
}
|
|
70
69
|
function G(n, e) {
|
|
71
|
-
if (e && !
|
|
70
|
+
if (e && !g(e) && e.content)
|
|
72
71
|
return e.content[n]?.schema;
|
|
73
72
|
}
|
|
74
|
-
function
|
|
73
|
+
function te(n) {
|
|
75
74
|
return G(I.APPLICATION_JSON, n);
|
|
76
75
|
}
|
|
77
|
-
function
|
|
76
|
+
function $e(n) {
|
|
78
77
|
return G(I.TEXT_EVENT_STREAM, n);
|
|
79
78
|
}
|
|
80
|
-
function
|
|
79
|
+
function Te(n) {
|
|
81
80
|
return G("*/*", n);
|
|
82
81
|
}
|
|
83
|
-
const
|
|
82
|
+
const ve = [
|
|
84
83
|
"string",
|
|
85
84
|
"number",
|
|
86
85
|
"integer",
|
|
87
86
|
"boolean",
|
|
88
87
|
"null"
|
|
89
88
|
];
|
|
90
|
-
function
|
|
91
|
-
return Array.isArray(n) ? !0 :
|
|
89
|
+
function ne(n) {
|
|
90
|
+
return Array.isArray(n) ? !0 : ve.includes(n);
|
|
92
91
|
}
|
|
93
|
-
function
|
|
92
|
+
function U(n) {
|
|
94
93
|
return Array.isArray(n.enum) && n.enum.length > 0;
|
|
95
94
|
}
|
|
96
95
|
function T(n) {
|
|
@@ -99,28 +98,28 @@ function T(n) {
|
|
|
99
98
|
function b(n) {
|
|
100
99
|
return n.type === "array" && !!n.items;
|
|
101
100
|
}
|
|
102
|
-
function
|
|
101
|
+
function Ie(n) {
|
|
103
102
|
return Array.isArray(n.anyOf) && n.anyOf.length > 0;
|
|
104
103
|
}
|
|
105
|
-
function
|
|
104
|
+
function Ee(n) {
|
|
106
105
|
return Array.isArray(n.oneOf) && n.oneOf.length > 0;
|
|
107
106
|
}
|
|
108
107
|
function q(n) {
|
|
109
108
|
return Array.isArray(n.allOf) && n.allOf.length > 0;
|
|
110
109
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
110
|
+
function J(n) {
|
|
111
|
+
return Ie(n) || Ee(n) || q(n);
|
|
113
112
|
}
|
|
114
|
-
function
|
|
113
|
+
function Se(n) {
|
|
115
114
|
return n.includes("|") || n.includes("&") ? `(${n})[]` : `${n}[]`;
|
|
116
115
|
}
|
|
117
|
-
function
|
|
116
|
+
function Re(n) {
|
|
118
117
|
return n.type === "object" && !n.properties && n.additionalProperties !== void 0;
|
|
119
118
|
}
|
|
120
|
-
function
|
|
119
|
+
function we(n) {
|
|
121
120
|
return n.type !== "object" ? !1 : n.properties ? Object.keys(n.properties).length === 0 : !0;
|
|
122
121
|
}
|
|
123
|
-
function
|
|
122
|
+
function De(n) {
|
|
124
123
|
return n.readOnly === !0;
|
|
125
124
|
}
|
|
126
125
|
function w(n) {
|
|
@@ -140,30 +139,30 @@ function w(n) {
|
|
|
140
139
|
return "any";
|
|
141
140
|
}
|
|
142
141
|
}
|
|
143
|
-
function
|
|
142
|
+
function Ne(n) {
|
|
144
143
|
if (!T(n))
|
|
145
144
|
return [];
|
|
146
145
|
const e = n.required || [];
|
|
147
146
|
return Object.keys(n.properties).filter((t) => !e.includes(t));
|
|
148
147
|
}
|
|
149
|
-
function
|
|
148
|
+
function Oe(n, e) {
|
|
150
149
|
return n.operation.operationId && e.operation.operationId ? n.operation.operationId.localeCompare(
|
|
151
150
|
e.operation.operationId
|
|
152
151
|
) : n.path && e.path ? n.path.localeCompare(e.path) : n.method && e.method ? n.method.localeCompare(e.method) : 0;
|
|
153
152
|
}
|
|
154
|
-
function
|
|
153
|
+
function oe(n) {
|
|
155
154
|
const e = [];
|
|
156
155
|
for (const [t, o] of Object.entries(n))
|
|
157
|
-
|
|
156
|
+
re(o).forEach((r) => {
|
|
158
157
|
e.push({
|
|
159
158
|
method: r.method,
|
|
160
159
|
operation: r.operation,
|
|
161
160
|
path: t
|
|
162
161
|
});
|
|
163
162
|
});
|
|
164
|
-
return e.sort(
|
|
163
|
+
return e.sort(Oe);
|
|
165
164
|
}
|
|
166
|
-
function
|
|
165
|
+
function re(n) {
|
|
167
166
|
return [
|
|
168
167
|
{ method: "get", operation: n.get },
|
|
169
168
|
{ method: "put", operation: n.put },
|
|
@@ -178,53 +177,53 @@ function se(n) {
|
|
|
178
177
|
function W(n) {
|
|
179
178
|
return n.responses[200];
|
|
180
179
|
}
|
|
181
|
-
function
|
|
180
|
+
function Q(n) {
|
|
182
181
|
const e = W(n);
|
|
183
|
-
return
|
|
182
|
+
return te(e);
|
|
184
183
|
}
|
|
185
|
-
function
|
|
186
|
-
return n.parameters ? n.parameters.map((t) =>
|
|
184
|
+
function Me(n, e) {
|
|
185
|
+
return n.parameters ? n.parameters.map((t) => g(t) ? Z(t, e) : t).filter((t) => t.in === "path") : [];
|
|
187
186
|
}
|
|
188
|
-
const
|
|
189
|
-
function
|
|
190
|
-
return !n.schema ||
|
|
187
|
+
const be = "string";
|
|
188
|
+
function ie(n) {
|
|
189
|
+
return !n.schema || g(n.schema) || !n.schema.type || !ne(n.schema.type) ? be : w(n.schema.type);
|
|
191
190
|
}
|
|
192
|
-
function
|
|
193
|
-
return n.startsWith("http://") || n.startsWith("https://") ?
|
|
191
|
+
function se(n) {
|
|
192
|
+
return n.startsWith("http://") || n.startsWith("https://") ? qe(n) : Fe(n);
|
|
194
193
|
}
|
|
195
|
-
async function
|
|
194
|
+
async function qe(n) {
|
|
196
195
|
return await (await fetch(n)).text();
|
|
197
196
|
}
|
|
198
|
-
function
|
|
197
|
+
function Fe(n) {
|
|
199
198
|
return new Promise((e, t) => {
|
|
200
|
-
|
|
199
|
+
Ae(n, "utf-8", (o, r) => {
|
|
201
200
|
o ? t(o) : e(r);
|
|
202
201
|
});
|
|
203
202
|
});
|
|
204
203
|
}
|
|
205
|
-
async function
|
|
206
|
-
const e = await
|
|
207
|
-
switch (
|
|
204
|
+
async function je(n) {
|
|
205
|
+
const e = await se(n);
|
|
206
|
+
switch (ae(e)) {
|
|
208
207
|
case "json":
|
|
209
208
|
return JSON.parse(e);
|
|
210
209
|
case "yaml":
|
|
211
|
-
return
|
|
210
|
+
return K(e);
|
|
212
211
|
default:
|
|
213
212
|
throw new Error(`Unsupported file format: ${n}`);
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
|
-
async function
|
|
217
|
-
const e = await
|
|
218
|
-
switch (
|
|
215
|
+
async function _e(n) {
|
|
216
|
+
const e = await se(n);
|
|
217
|
+
switch (ae(e)) {
|
|
219
218
|
case "json":
|
|
220
219
|
return JSON.parse(e);
|
|
221
220
|
case "yaml":
|
|
222
|
-
return
|
|
221
|
+
return K(e);
|
|
223
222
|
default:
|
|
224
223
|
throw new Error(`Unsupported file format: ${n}`);
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
|
-
function
|
|
226
|
+
function ae(n) {
|
|
228
227
|
const e = n.trimStart();
|
|
229
228
|
if (e.startsWith("{") || e.startsWith("["))
|
|
230
229
|
return "json";
|
|
@@ -238,11 +237,11 @@ function pe(n) {
|
|
|
238
237
|
}
|
|
239
238
|
throw new Error("Unable to infer file format");
|
|
240
239
|
}
|
|
241
|
-
const
|
|
242
|
-
function
|
|
243
|
-
return E(n.path,
|
|
240
|
+
const ce = "types.ts", Ge = "@";
|
|
241
|
+
function We(n) {
|
|
242
|
+
return E(n.path, ce);
|
|
244
243
|
}
|
|
245
|
-
function
|
|
244
|
+
function ge(n, e, t) {
|
|
246
245
|
const o = E(e, t), r = n.getSourceFile(o);
|
|
247
246
|
return r || n.createSourceFile(o, "", {
|
|
248
247
|
overwrite: !0
|
|
@@ -260,22 +259,19 @@ function A(n, e, t) {
|
|
|
260
259
|
) || o.addNamedImport(r);
|
|
261
260
|
});
|
|
262
261
|
}
|
|
263
|
-
function H(n) {
|
|
264
|
-
return n.split("\\").join("/");
|
|
265
|
-
}
|
|
266
262
|
function d(n, e, t) {
|
|
267
|
-
if (t.path.startsWith(
|
|
263
|
+
if (t.path.startsWith(Ge)) {
|
|
268
264
|
A(n, t.path, [t.name]);
|
|
269
265
|
return;
|
|
270
266
|
}
|
|
271
|
-
const o =
|
|
272
|
-
let
|
|
273
|
-
|
|
267
|
+
const o = n.getDirectoryPath(), r = (void 0)(e, t.path, ce);
|
|
268
|
+
let i = (void 0)(o, r);
|
|
269
|
+
i = i.replace(/\.ts$/, ""), i = i.split(void 0).join("/"), i.startsWith(".") || (i = "./" + i), A(n, i, [t.name]);
|
|
274
270
|
}
|
|
275
|
-
function
|
|
271
|
+
function ke(n, e, t, o) {
|
|
276
272
|
n.path !== o.path && d(e, t, o);
|
|
277
273
|
}
|
|
278
|
-
function
|
|
274
|
+
function pe(n, e = `
|
|
279
275
|
`) {
|
|
280
276
|
if (!Array.isArray(n))
|
|
281
277
|
return;
|
|
@@ -285,7 +281,7 @@ function le(n, e = `
|
|
|
285
281
|
return t.length > 0 ? t.join(e) : void 0;
|
|
286
282
|
}
|
|
287
283
|
function C(n, e) {
|
|
288
|
-
const t =
|
|
284
|
+
const t = pe(e);
|
|
289
285
|
t && n.addJsDoc(t);
|
|
290
286
|
}
|
|
291
287
|
function k(n, e) {
|
|
@@ -293,30 +289,30 @@ function k(n, e) {
|
|
|
293
289
|
n.title,
|
|
294
290
|
n.description
|
|
295
291
|
];
|
|
296
|
-
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`),
|
|
292
|
+
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), V(t, n, "default"), V(t, n, "example"), Be(t, n), Ue(t, n), Je(t, n), t;
|
|
297
293
|
}
|
|
298
|
-
function
|
|
294
|
+
function ze(n, e, t) {
|
|
299
295
|
const o = k(e, t);
|
|
300
296
|
C(n, o);
|
|
301
297
|
}
|
|
302
|
-
function
|
|
298
|
+
function Le(n, e, t) {
|
|
303
299
|
const o = k(e, t);
|
|
304
|
-
|
|
300
|
+
ue(o, "schema", e), C(n, o);
|
|
305
301
|
}
|
|
306
|
-
function
|
|
302
|
+
function V(n, e, t) {
|
|
307
303
|
const o = e[t];
|
|
308
304
|
if (o) {
|
|
309
305
|
if (typeof o != "object") {
|
|
310
306
|
n.push(`- ${t}: \`${o}\``);
|
|
311
307
|
return;
|
|
312
308
|
}
|
|
313
|
-
|
|
309
|
+
ue(n, t, o);
|
|
314
310
|
}
|
|
315
311
|
}
|
|
316
|
-
function
|
|
312
|
+
function ue(n, e, t) {
|
|
317
313
|
n.push(`- ${e}: `), n.push("```json"), n.push(JSON.stringify(t, null, 2)), n.push("```");
|
|
318
314
|
}
|
|
319
|
-
function
|
|
315
|
+
function Be(n, e) {
|
|
320
316
|
const t = ["- Numeric Constraints"];
|
|
321
317
|
e.minimum !== void 0 && t.push(` - minimum: ${e.minimum}`), e.maximum !== void 0 && t.push(` - maximum: ${e.maximum}`), e.exclusiveMinimum !== void 0 && t.push(
|
|
322
318
|
` - exclusiveMinimum: ${e.exclusiveMinimum}`
|
|
@@ -324,28 +320,28 @@ function Je(n, e) {
|
|
|
324
320
|
` - exclusiveMaximum: ${e.exclusiveMaximum}`
|
|
325
321
|
), e.multipleOf !== void 0 && t.push(` - multipleOf: ${e.multipleOf}`), t.length !== 1 && n.push(...t);
|
|
326
322
|
}
|
|
327
|
-
function
|
|
323
|
+
function Ue(n, e) {
|
|
328
324
|
const t = ["- String Constraints"];
|
|
329
325
|
e.minLength !== void 0 && t.push(` - minLength: ${e.minLength}`), e.maxLength !== void 0 && t.push(` - maxLength: ${e.maxLength}`), e.pattern !== void 0 && t.push(` - pattern: ${e.pattern}`), t.length !== 1 && n.push(...t);
|
|
330
326
|
}
|
|
331
|
-
function
|
|
327
|
+
function Je(n, e) {
|
|
332
328
|
const t = ["- Array Constraints"];
|
|
333
329
|
e.minItems !== void 0 && t.push(` - minItems: ${e.minItems}`), e.maxItems !== void 0 && t.push(` - maxItems: ${e.maxItems}`), e.uniqueItems !== void 0 && t.push(` - uniqueItems: ${e.uniqueItems}`), t.length !== 1 && n.push(...t);
|
|
334
330
|
}
|
|
335
|
-
function
|
|
331
|
+
function Qe(n) {
|
|
336
332
|
const e = n.split(".");
|
|
337
333
|
return e.length != 2 || e[0].length === 0 || e[1].length === 0 ? null : e;
|
|
338
334
|
}
|
|
339
|
-
function
|
|
340
|
-
const e =
|
|
335
|
+
function Ve(n) {
|
|
336
|
+
const e = Qe(n.name);
|
|
341
337
|
return e ? {
|
|
342
338
|
tag: n,
|
|
343
339
|
contextAlias: e[0],
|
|
344
340
|
aggregateName: e[1]
|
|
345
341
|
} : null;
|
|
346
342
|
}
|
|
347
|
-
function
|
|
348
|
-
const e = n?.map((o) =>
|
|
343
|
+
function He(n) {
|
|
344
|
+
const e = n?.map((o) => Ve(o)).filter((o) => o !== null);
|
|
349
345
|
if (!e)
|
|
350
346
|
return /* @__PURE__ */ new Map();
|
|
351
347
|
const t = /* @__PURE__ */ new Map();
|
|
@@ -357,20 +353,20 @@ function Ye(n) {
|
|
|
357
353
|
});
|
|
358
354
|
}), t;
|
|
359
355
|
}
|
|
360
|
-
function
|
|
356
|
+
function Ke(n) {
|
|
361
357
|
if (!n)
|
|
362
358
|
return null;
|
|
363
359
|
const e = n.split(".");
|
|
364
360
|
return e.length != 3 ? null : e[2];
|
|
365
361
|
}
|
|
366
|
-
const
|
|
367
|
-
class
|
|
362
|
+
const Ye = "#/components/responses/wow.CommandOk", Ze = "#/components/parameters/wow.id";
|
|
363
|
+
class Xe {
|
|
368
364
|
/**
|
|
369
365
|
* Creates a new AggregateResolver instance.
|
|
370
366
|
* @param openAPI - The OpenAPI specification to resolve aggregates from
|
|
371
367
|
*/
|
|
372
368
|
constructor(e) {
|
|
373
|
-
this.openAPI = e, this.aggregates =
|
|
369
|
+
this.openAPI = e, this.aggregates = He(e.tags), this.build();
|
|
374
370
|
}
|
|
375
371
|
aggregates;
|
|
376
372
|
/**
|
|
@@ -378,7 +374,7 @@ class tt {
|
|
|
378
374
|
* @private
|
|
379
375
|
*/
|
|
380
376
|
build() {
|
|
381
|
-
const e =
|
|
377
|
+
const e = oe(this.openAPI.paths);
|
|
382
378
|
for (const t of e)
|
|
383
379
|
this.commands(t.path, t), this.state(t.operation), this.events(t.operation), this.fields(t.operation);
|
|
384
380
|
}
|
|
@@ -406,28 +402,28 @@ class tt {
|
|
|
406
402
|
const o = t.operation;
|
|
407
403
|
if (o.operationId === "wow.command.send")
|
|
408
404
|
return;
|
|
409
|
-
const r =
|
|
405
|
+
const r = Ke(o.operationId);
|
|
410
406
|
if (!r)
|
|
411
407
|
return;
|
|
412
408
|
const i = W(o);
|
|
413
|
-
if (!i || !
|
|
409
|
+
if (!i || !g(i) || i.$ref !== Ye || !o.requestBody)
|
|
414
410
|
return;
|
|
415
|
-
const s = o.parameters ?? [], a = s.filter((l) =>
|
|
416
|
-
(l) => !
|
|
411
|
+
const s = o.parameters ?? [], a = s.filter((l) => g(l) && l.$ref === Ze).at(0), c = s.filter(
|
|
412
|
+
(l) => !g(l) && l.in === "path"
|
|
417
413
|
);
|
|
418
414
|
if (a) {
|
|
419
|
-
const l =
|
|
415
|
+
const l = Z(
|
|
420
416
|
a,
|
|
421
417
|
this.openAPI.components
|
|
422
418
|
);
|
|
423
419
|
c.push(l);
|
|
424
420
|
}
|
|
425
|
-
const
|
|
426
|
-
|
|
421
|
+
const p = o.requestBody.content[I.APPLICATION_JSON].schema, x = $(
|
|
422
|
+
p,
|
|
427
423
|
this.openAPI.components
|
|
428
424
|
);
|
|
429
425
|
x.schema.title = x.schema.title || o.summary, x.schema.description = x.schema.description || o.description;
|
|
430
|
-
const
|
|
426
|
+
const he = {
|
|
431
427
|
name: r,
|
|
432
428
|
method: t.method,
|
|
433
429
|
path: e,
|
|
@@ -439,7 +435,7 @@ class tt {
|
|
|
439
435
|
};
|
|
440
436
|
o.tags?.forEach((l) => {
|
|
441
437
|
const z = this.aggregates.get(l);
|
|
442
|
-
z && z.commands.set(r,
|
|
438
|
+
z && z.commands.set(r, he);
|
|
443
439
|
});
|
|
444
440
|
}
|
|
445
441
|
/**
|
|
@@ -449,8 +445,8 @@ class tt {
|
|
|
449
445
|
state(e) {
|
|
450
446
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
451
447
|
return;
|
|
452
|
-
const t =
|
|
453
|
-
if (!
|
|
448
|
+
const t = Q(e);
|
|
449
|
+
if (!g(t))
|
|
454
450
|
return;
|
|
455
451
|
const o = $(
|
|
456
452
|
t,
|
|
@@ -468,24 +464,24 @@ class tt {
|
|
|
468
464
|
events(e) {
|
|
469
465
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
470
466
|
return;
|
|
471
|
-
const t =
|
|
472
|
-
if (
|
|
467
|
+
const t = Q(e);
|
|
468
|
+
if (g(t))
|
|
473
469
|
return;
|
|
474
470
|
const o = t?.items;
|
|
475
|
-
if (!
|
|
471
|
+
if (!g(o))
|
|
476
472
|
return;
|
|
477
473
|
const i = S(
|
|
478
474
|
o,
|
|
479
475
|
this.openAPI.components
|
|
480
476
|
).properties.body.items.anyOf.map((s) => {
|
|
481
|
-
const a = s.title, c = s.properties.name.const, u = s.properties.body,
|
|
477
|
+
const a = s.title, c = s.properties.name.const, u = s.properties.body, p = $(
|
|
482
478
|
u,
|
|
483
479
|
this.openAPI.components
|
|
484
480
|
);
|
|
485
|
-
return
|
|
481
|
+
return p.schema.title = p.schema.title || s.title, {
|
|
486
482
|
title: a,
|
|
487
483
|
name: c,
|
|
488
|
-
schema:
|
|
484
|
+
schema: p
|
|
489
485
|
};
|
|
490
486
|
});
|
|
491
487
|
e.tags?.forEach((s) => {
|
|
@@ -502,7 +498,7 @@ class tt {
|
|
|
502
498
|
fields(e) {
|
|
503
499
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
504
500
|
return;
|
|
505
|
-
const o =
|
|
501
|
+
const o = Y(
|
|
506
502
|
e.requestBody,
|
|
507
503
|
this.openAPI.components
|
|
508
504
|
).content[I.APPLICATION_JSON].schema, i = S(
|
|
@@ -515,7 +511,7 @@ class tt {
|
|
|
515
511
|
});
|
|
516
512
|
}
|
|
517
513
|
}
|
|
518
|
-
const y = "@ahoo-wang/fetcher-wow",
|
|
514
|
+
const y = "@ahoo-wang/fetcher-wow", et = {
|
|
519
515
|
"wow.command.CommandResult": "CommandResult",
|
|
520
516
|
"wow.command.CommandResultArray": "CommandResultArray",
|
|
521
517
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
@@ -536,6 +532,8 @@ const y = "@ahoo-wang/fetcher-wow", nt = {
|
|
|
536
532
|
"wow.api.query.Projection": "Projection",
|
|
537
533
|
"wow.api.query.Sort": "FieldSort",
|
|
538
534
|
"wow.api.query.Sort.Direction": "SortDirection",
|
|
535
|
+
"wow.api.query.DynamicDocument": "DynamicDocument",
|
|
536
|
+
"wow.api.query.DynamicDocumentArray": "DynamicDocumentArray",
|
|
539
537
|
"wow.command.CommandStage": "CommandStage",
|
|
540
538
|
"wow.command.SimpleWaitSignal": "WaitSignal",
|
|
541
539
|
"wow.configuration.Aggregate": "Aggregate",
|
|
@@ -548,7 +546,7 @@ const y = "@ahoo-wang/fetcher-wow", nt = {
|
|
|
548
546
|
function m(n) {
|
|
549
547
|
if (!n)
|
|
550
548
|
return { name: "", path: "/" };
|
|
551
|
-
const e =
|
|
549
|
+
const e = et[n];
|
|
552
550
|
if (e)
|
|
553
551
|
return { name: e, path: y };
|
|
554
552
|
const t = n.split(".");
|
|
@@ -565,24 +563,24 @@ function v(n) {
|
|
|
565
563
|
const e = P(n);
|
|
566
564
|
return m(e);
|
|
567
565
|
}
|
|
568
|
-
function
|
|
569
|
-
return `${
|
|
566
|
+
function D(n) {
|
|
567
|
+
return `${ee(n)}_BOUNDED_CONTEXT_ALIAS`;
|
|
570
568
|
}
|
|
571
|
-
class
|
|
569
|
+
class tt {
|
|
572
570
|
constructor(e, t, o, r) {
|
|
573
571
|
this.modelInfo = e, this.sourceFile = t, this.keySchema = o, this.outputDir = r;
|
|
574
572
|
}
|
|
575
573
|
generate() {
|
|
576
574
|
const e = this.process();
|
|
577
|
-
e &&
|
|
575
|
+
e && Le(e, this.keySchema.schema, this.keySchema.key);
|
|
578
576
|
}
|
|
579
577
|
process() {
|
|
580
578
|
const { schema: e } = this.keySchema;
|
|
581
|
-
return
|
|
579
|
+
return U(e) ? this.processEnum(e) : T(e) ? this.processInterface(e) : b(e) ? this.processArray(e) : q(e) ? this.processIntersection(e) : J(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
582
580
|
}
|
|
583
581
|
resolveReference(e) {
|
|
584
582
|
const t = v(e);
|
|
585
|
-
return
|
|
583
|
+
return ke(
|
|
586
584
|
this.modelInfo,
|
|
587
585
|
this.sourceFile,
|
|
588
586
|
this.outputDir,
|
|
@@ -596,8 +594,8 @@ class ot {
|
|
|
596
594
|
const { properties: t } = e;
|
|
597
595
|
return Object.entries(t).map(([o, r]) => {
|
|
598
596
|
const i = this.resolveType(r), s = M(o);
|
|
599
|
-
if (!
|
|
600
|
-
const a = k(r), c =
|
|
597
|
+
if (!g(r)) {
|
|
598
|
+
const a = k(r), c = pe(a, `
|
|
601
599
|
* `);
|
|
602
600
|
if (c)
|
|
603
601
|
return `
|
|
@@ -626,21 +624,21 @@ class ot {
|
|
|
626
624
|
return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.resolveType(e.additionalProperties);
|
|
627
625
|
}
|
|
628
626
|
resolveType(e) {
|
|
629
|
-
if (
|
|
627
|
+
if (g(e))
|
|
630
628
|
return this.resolveReference(e).name;
|
|
631
|
-
if (
|
|
629
|
+
if (Re(e))
|
|
632
630
|
return `Record<string,${this.resolveMapValueType(e)}>`;
|
|
633
631
|
if (e.const)
|
|
634
632
|
return `'${e.const}'`;
|
|
635
|
-
if (
|
|
633
|
+
if (U(e))
|
|
636
634
|
return e.enum.map((t) => `\`${t}\``).join(" | ");
|
|
637
|
-
if (
|
|
635
|
+
if (J(e)) {
|
|
638
636
|
const o = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r = q(e) ? " & " : " | ";
|
|
639
637
|
return `(${o.join(r)})`;
|
|
640
638
|
}
|
|
641
639
|
if (b(e)) {
|
|
642
640
|
const t = this.resolveType(e.items);
|
|
643
|
-
return
|
|
641
|
+
return Se(t);
|
|
644
642
|
}
|
|
645
643
|
return e.type === "object" ? this.resolveObjectType(e) : e.type ? w(e.type) : "any";
|
|
646
644
|
}
|
|
@@ -649,7 +647,7 @@ class ot {
|
|
|
649
647
|
name: this.modelInfo.name,
|
|
650
648
|
isExported: !0,
|
|
651
649
|
members: e.enum.filter((t) => typeof t == "string" && t.length > 0).map((t) => ({
|
|
652
|
-
name:
|
|
650
|
+
name: Pe(t),
|
|
653
651
|
initializer: `\`${t}\``
|
|
654
652
|
}))
|
|
655
653
|
});
|
|
@@ -660,8 +658,8 @@ class ot {
|
|
|
660
658
|
s ? s.setType(r) : s = e.addProperty({
|
|
661
659
|
name: i,
|
|
662
660
|
type: r,
|
|
663
|
-
isReadonly:
|
|
664
|
-
}),
|
|
661
|
+
isReadonly: De(o)
|
|
662
|
+
}), ze(s, o);
|
|
665
663
|
}
|
|
666
664
|
processInterface(e) {
|
|
667
665
|
const t = this.sourceFile.addInterface({
|
|
@@ -699,7 +697,7 @@ class ot {
|
|
|
699
697
|
isExported: !0
|
|
700
698
|
});
|
|
701
699
|
return e.allOf.forEach((o) => {
|
|
702
|
-
if (
|
|
700
|
+
if (g(o)) {
|
|
703
701
|
const r = this.resolveType(o);
|
|
704
702
|
t.addExtends(r);
|
|
705
703
|
return;
|
|
@@ -723,12 +721,12 @@ class ot {
|
|
|
723
721
|
});
|
|
724
722
|
}
|
|
725
723
|
}
|
|
726
|
-
class
|
|
724
|
+
class nt {
|
|
727
725
|
constructor(e) {
|
|
728
726
|
this.context = e;
|
|
729
727
|
}
|
|
730
728
|
getOrCreateSourceFile(e) {
|
|
731
|
-
const t =
|
|
729
|
+
const t = We(e);
|
|
732
730
|
return this.context.getOrCreateSourceFile(t);
|
|
733
731
|
}
|
|
734
732
|
/**
|
|
@@ -810,7 +808,7 @@ class rt {
|
|
|
810
808
|
*/
|
|
811
809
|
generateKeyedSchema(e) {
|
|
812
810
|
const t = m(e.key), o = this.getOrCreateSourceFile(t);
|
|
813
|
-
new
|
|
811
|
+
new tt(
|
|
814
812
|
t,
|
|
815
813
|
o,
|
|
816
814
|
e,
|
|
@@ -820,11 +818,11 @@ class rt {
|
|
|
820
818
|
generateBoundedContext(e) {
|
|
821
819
|
const t = `${e}/boundedContext.ts`;
|
|
822
820
|
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
823
|
-
const o = this.context.getOrCreateSourceFile(t), r =
|
|
821
|
+
const o = this.context.getOrCreateSourceFile(t), r = D(e);
|
|
824
822
|
o.addStatements(`export const ${r} = '${e}';`);
|
|
825
823
|
}
|
|
826
824
|
}
|
|
827
|
-
const
|
|
825
|
+
const ot = "@ahoo-wang/fetcher-decorator", rt = [
|
|
828
826
|
"type ApiMetadata",
|
|
829
827
|
"type ApiMetadataCapable",
|
|
830
828
|
"type ParameterRequest",
|
|
@@ -838,18 +836,18 @@ const it = "@ahoo-wang/fetcher-decorator", st = [
|
|
|
838
836
|
"attribute",
|
|
839
837
|
"path",
|
|
840
838
|
"autoGeneratedError"
|
|
841
|
-
],
|
|
839
|
+
], it = {
|
|
842
840
|
type: "Promise<Response>",
|
|
843
841
|
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
844
|
-
},
|
|
842
|
+
}, H = {
|
|
845
843
|
type: "Promise<string>",
|
|
846
844
|
metadata: "{resultExtractor: ResultExtractors.Text }"
|
|
847
845
|
}, F = `{
|
|
848
846
|
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
849
847
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
850
848
|
}`;
|
|
851
|
-
function
|
|
852
|
-
A(n,
|
|
849
|
+
function le(n) {
|
|
850
|
+
A(n, ot, rt);
|
|
853
851
|
}
|
|
854
852
|
function j(n, e, t = [], o = [], r) {
|
|
855
853
|
return e.addClass({
|
|
@@ -865,36 +863,36 @@ function j(n, e, t = [], o = [], r) {
|
|
|
865
863
|
]
|
|
866
864
|
});
|
|
867
865
|
}
|
|
868
|
-
function
|
|
866
|
+
function me(n, e) {
|
|
869
867
|
n.addImplements("ApiMetadataCapable"), n.addConstructor({
|
|
870
868
|
parameters: [
|
|
871
869
|
{
|
|
872
870
|
name: "apiMetadata",
|
|
873
871
|
type: "ApiMetadata",
|
|
874
872
|
hasQuestionToken: e === void 0,
|
|
875
|
-
scope:
|
|
873
|
+
scope: ye.Public,
|
|
876
874
|
isReadonly: !0,
|
|
877
875
|
initializer: e
|
|
878
876
|
}
|
|
879
877
|
]
|
|
880
878
|
});
|
|
881
879
|
}
|
|
882
|
-
const
|
|
883
|
-
function
|
|
884
|
-
A(n,
|
|
880
|
+
const st = "@ahoo-wang/fetcher-eventstream";
|
|
881
|
+
function de(n) {
|
|
882
|
+
A(n, st, [
|
|
885
883
|
"JsonEventStreamResultExtractor",
|
|
886
884
|
"type JsonServerSentEventStream"
|
|
887
885
|
]);
|
|
888
886
|
}
|
|
889
|
-
function
|
|
887
|
+
function at(n) {
|
|
890
888
|
let e = 0, t = 0;
|
|
891
889
|
return n.commands.forEach((o) => {
|
|
892
890
|
o.path.startsWith(L.TENANT) && (e += 1), o.path.startsWith(L.OWNER) && (t += 1);
|
|
893
891
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
894
892
|
}
|
|
895
|
-
function
|
|
893
|
+
function fe(n, e, t, o) {
|
|
896
894
|
const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
|
|
897
|
-
return
|
|
895
|
+
return ge(n, e, r);
|
|
898
896
|
}
|
|
899
897
|
function h(n, e) {
|
|
900
898
|
return `${R(n.aggregateName)}${e}`;
|
|
@@ -902,9 +900,9 @@ function h(n, e) {
|
|
|
902
900
|
function _(n) {
|
|
903
901
|
return n === "delete" ? "del" : n;
|
|
904
902
|
}
|
|
905
|
-
const
|
|
906
|
-
function
|
|
907
|
-
const t = n[
|
|
903
|
+
const ct = "x-fetcher-method";
|
|
904
|
+
function gt(n, e) {
|
|
905
|
+
const t = n[ct];
|
|
908
906
|
if (t)
|
|
909
907
|
return t;
|
|
910
908
|
if (!n.operationId)
|
|
@@ -917,16 +915,16 @@ function ut(n, e) {
|
|
|
917
915
|
}
|
|
918
916
|
return f(o);
|
|
919
917
|
}
|
|
920
|
-
class
|
|
918
|
+
class pt {
|
|
921
919
|
/**
|
|
922
920
|
* Creates a new ApiClientGenerator instance.
|
|
923
921
|
* @param context - The generation context containing OpenAPI spec and configuration
|
|
924
922
|
*/
|
|
925
923
|
constructor(e) {
|
|
926
|
-
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${
|
|
924
|
+
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${D(this.context.currentContextAlias)}}` : void 0;
|
|
927
925
|
}
|
|
928
926
|
defaultParameterRequestType = "ParameterRequest";
|
|
929
|
-
defaultReturnType =
|
|
927
|
+
defaultReturnType = it;
|
|
930
928
|
apiMetadataCtorInitializer;
|
|
931
929
|
/**
|
|
932
930
|
* Generates API client classes for all valid tags in the OpenAPI specification.
|
|
@@ -983,12 +981,12 @@ class lt {
|
|
|
983
981
|
`Generating API client class: ${o.name}ApiClient with ${t.size} operations`
|
|
984
982
|
);
|
|
985
983
|
const r = this.createApiClientFile(o);
|
|
986
|
-
|
|
984
|
+
le(r), de(r);
|
|
987
985
|
const i = j(
|
|
988
986
|
o.name + "ApiClient",
|
|
989
987
|
r
|
|
990
988
|
);
|
|
991
|
-
C(i, [e.description]),
|
|
989
|
+
C(i, [e.description]), me(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
992
990
|
`Processing ${t.size} operations for ${o.name}ApiClient`
|
|
993
991
|
), t.forEach((s) => {
|
|
994
992
|
this.processOperation(e, r, i, s);
|
|
@@ -1003,7 +1001,7 @@ class lt {
|
|
|
1003
1001
|
* @returns A unique camelCase method name
|
|
1004
1002
|
*/
|
|
1005
1003
|
getMethodName(e, t) {
|
|
1006
|
-
const o =
|
|
1004
|
+
const o = gt(t, (r) => e.getMethod(r) !== void 0);
|
|
1007
1005
|
if (!o)
|
|
1008
1006
|
throw new Error(
|
|
1009
1007
|
`Unable to resolve method name for apiClientClass:${e.getName()}.`
|
|
@@ -1022,9 +1020,9 @@ class lt {
|
|
|
1022
1020
|
`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
1023
1021
|
), this.defaultParameterRequestType;
|
|
1024
1022
|
let o;
|
|
1025
|
-
if (
|
|
1023
|
+
if (g(t.requestBody) ? (this.context.logger.info(
|
|
1026
1024
|
`Extracting request body from reference for operation: ${t.operationId}`
|
|
1027
|
-
), o =
|
|
1025
|
+
), o = Y(
|
|
1028
1026
|
t.requestBody,
|
|
1029
1027
|
this.context.openAPI.components
|
|
1030
1028
|
)) : o = t.requestBody, !o)
|
|
@@ -1037,7 +1035,7 @@ class lt {
|
|
|
1037
1035
|
), "ParameterRequest<FormData>";
|
|
1038
1036
|
if (o.content["application/json"]) {
|
|
1039
1037
|
const r = o.content["application/json"].schema;
|
|
1040
|
-
if (
|
|
1038
|
+
if (g(r)) {
|
|
1041
1039
|
const i = v(r);
|
|
1042
1040
|
this.context.logger.info(
|
|
1043
1041
|
`Adding import for request body model: ${i.name} from ${i.path}`
|
|
@@ -1060,7 +1058,7 @@ class lt {
|
|
|
1060
1058
|
* @returns Array of parameter declarations
|
|
1061
1059
|
*/
|
|
1062
1060
|
resolveParameters(e, t, o) {
|
|
1063
|
-
const r =
|
|
1061
|
+
const r = Me(
|
|
1064
1062
|
o,
|
|
1065
1063
|
this.context.openAPI.components
|
|
1066
1064
|
).filter((a) => !this.context.isIgnoreApiClientPathParameters(
|
|
@@ -1071,7 +1069,7 @@ class lt {
|
|
|
1071
1069
|
`Found ${r.length} path parameters for operation ${o.operationId}`
|
|
1072
1070
|
);
|
|
1073
1071
|
const i = r.map((a) => {
|
|
1074
|
-
const c =
|
|
1072
|
+
const c = ie(a);
|
|
1075
1073
|
return this.context.logger.info(
|
|
1076
1074
|
`Adding path parameter: ${a.name} (type: ${c})`
|
|
1077
1075
|
), {
|
|
@@ -1118,7 +1116,7 @@ class lt {
|
|
|
1118
1116
|
*/
|
|
1119
1117
|
resolveSchemaReturnType(e, t) {
|
|
1120
1118
|
const o = "Promise<any>";
|
|
1121
|
-
if (
|
|
1119
|
+
if (g(t)) {
|
|
1122
1120
|
const r = v(t);
|
|
1123
1121
|
this.context.logger.info(
|
|
1124
1122
|
`Adding import for response model: ${r.name} from ${r.path}`
|
|
@@ -1130,7 +1128,7 @@ class lt {
|
|
|
1130
1128
|
return this.context.logger.info(
|
|
1131
1129
|
`Schema has no type, using default return type: ${o}`
|
|
1132
1130
|
), o;
|
|
1133
|
-
if (
|
|
1131
|
+
if (ne(t.type)) {
|
|
1134
1132
|
const i = `Promise<${w(t.type)}>`;
|
|
1135
1133
|
return this.context.logger.info(`Resolved primitive return type: ${i}`), i;
|
|
1136
1134
|
}
|
|
@@ -1150,33 +1148,33 @@ class lt {
|
|
|
1150
1148
|
return this.context.logger.info(
|
|
1151
1149
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1152
1150
|
), this.defaultReturnType;
|
|
1153
|
-
const r =
|
|
1151
|
+
const r = te(o) || Te(o);
|
|
1154
1152
|
if (r) {
|
|
1155
1153
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1156
1154
|
return this.context.logger.info(
|
|
1157
1155
|
`Resolved JSON/wildcard response return type for operation ${t.operationId}: ${s}`
|
|
1158
1156
|
), {
|
|
1159
1157
|
type: s,
|
|
1160
|
-
metadata: s ===
|
|
1158
|
+
metadata: s === H.type ? H.metadata : void 0
|
|
1161
1159
|
};
|
|
1162
1160
|
}
|
|
1163
|
-
const i =
|
|
1161
|
+
const i = $e(o);
|
|
1164
1162
|
if (i) {
|
|
1165
|
-
if (
|
|
1163
|
+
if (g(i)) {
|
|
1166
1164
|
const a = S(
|
|
1167
1165
|
i,
|
|
1168
1166
|
this.context.openAPI.components
|
|
1169
1167
|
);
|
|
1170
|
-
if (b(a) &&
|
|
1168
|
+
if (b(a) && g(a.items)) {
|
|
1171
1169
|
const c = v(a.items);
|
|
1172
1170
|
this.context.logger.info(
|
|
1173
1171
|
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
1174
1172
|
), d(e, this.context.outputDir, c);
|
|
1175
|
-
const
|
|
1173
|
+
const p = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
|
|
1176
1174
|
return this.context.logger.info(
|
|
1177
|
-
`Resolved event stream return type for operation ${t.operationId}: ${
|
|
1175
|
+
`Resolved event stream return type for operation ${t.operationId}: ${p}`
|
|
1178
1176
|
), {
|
|
1179
|
-
type:
|
|
1177
|
+
type: p,
|
|
1180
1178
|
metadata: F
|
|
1181
1179
|
};
|
|
1182
1180
|
}
|
|
@@ -1223,7 +1221,7 @@ class lt {
|
|
|
1223
1221
|
parameters: s,
|
|
1224
1222
|
returnType: a.type,
|
|
1225
1223
|
statements: [
|
|
1226
|
-
`throw autoGeneratedError(${s.map((
|
|
1224
|
+
`throw autoGeneratedError(${s.map((p) => p.name).join(",")});`
|
|
1227
1225
|
]
|
|
1228
1226
|
});
|
|
1229
1227
|
C(u, [
|
|
@@ -1240,7 +1238,7 @@ class lt {
|
|
|
1240
1238
|
*/
|
|
1241
1239
|
groupOperations(e) {
|
|
1242
1240
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1243
|
-
const t = /* @__PURE__ */ new Map(), o =
|
|
1241
|
+
const t = /* @__PURE__ */ new Map(), o = oe(
|
|
1244
1242
|
this.context.openAPI.paths
|
|
1245
1243
|
).filter((i) => {
|
|
1246
1244
|
if (!i.operation.operationId)
|
|
@@ -1271,7 +1269,7 @@ class lt {
|
|
|
1271
1269
|
);
|
|
1272
1270
|
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1273
1271
|
for (const r of Object.values(this.context.openAPI.paths))
|
|
1274
|
-
|
|
1272
|
+
re(r).forEach((i) => {
|
|
1275
1273
|
i.operation.tags?.forEach((s) => {
|
|
1276
1274
|
!this.shouldIgnoreTag(s) && !e.has(s) && e.set(s, {
|
|
1277
1275
|
name: s,
|
|
@@ -1296,7 +1294,7 @@ class lt {
|
|
|
1296
1294
|
return !1;
|
|
1297
1295
|
}
|
|
1298
1296
|
}
|
|
1299
|
-
class
|
|
1297
|
+
class ut {
|
|
1300
1298
|
/**
|
|
1301
1299
|
* Creates a new CommandClientGenerator instance.
|
|
1302
1300
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1335,7 +1333,7 @@ class mt {
|
|
|
1335
1333
|
this.context.logger.info(
|
|
1336
1334
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1337
1335
|
);
|
|
1338
|
-
const t =
|
|
1336
|
+
const t = fe(
|
|
1339
1337
|
this.context.project,
|
|
1340
1338
|
this.context.outputDir,
|
|
1341
1339
|
e.aggregate,
|
|
@@ -1351,13 +1349,13 @@ class mt {
|
|
|
1351
1349
|
this.processCommandTypes(t, e), this.context.logger.info(
|
|
1352
1350
|
`Creating default command client options: ${this.defaultCommandClientOptionsName}`
|
|
1353
1351
|
), t.addVariableStatement({
|
|
1354
|
-
declarationKind:
|
|
1352
|
+
declarationKind: N.Const,
|
|
1355
1353
|
declarations: [
|
|
1356
1354
|
{
|
|
1357
1355
|
name: this.defaultCommandClientOptionsName,
|
|
1358
1356
|
type: "ApiMetadata",
|
|
1359
1357
|
initializer: `{
|
|
1360
|
-
basePath: ${
|
|
1358
|
+
basePath: ${D(e.aggregate.contextAlias)}
|
|
1361
1359
|
}`
|
|
1362
1360
|
}
|
|
1363
1361
|
],
|
|
@@ -1377,11 +1375,11 @@ class mt {
|
|
|
1377
1375
|
isTypeOnly: !0
|
|
1378
1376
|
}), this.context.logger.info(
|
|
1379
1377
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1380
|
-
),
|
|
1378
|
+
), de(t), this.context.logger.info(
|
|
1381
1379
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1382
1380
|
), A(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1383
1381
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1384
|
-
),
|
|
1382
|
+
), le(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(
|
|
1385
1383
|
t,
|
|
1386
1384
|
e,
|
|
1387
1385
|
o
|
|
@@ -1424,7 +1422,7 @@ class mt {
|
|
|
1424
1422
|
return;
|
|
1425
1423
|
d(e, this.context.outputDir, o);
|
|
1426
1424
|
let i = `${o.name}`;
|
|
1427
|
-
const s =
|
|
1425
|
+
const s = Ne(t.schema.schema).map((a) => `'${a}'`).join(" | ");
|
|
1428
1426
|
s !== "" && (i = `PartialBy<${i},${s}>`), i = `CommandBody<${i}>`, e.addTypeAlias({
|
|
1429
1427
|
name: r,
|
|
1430
1428
|
type: `${i}`,
|
|
@@ -1449,7 +1447,7 @@ class mt {
|
|
|
1449
1447
|
[],
|
|
1450
1448
|
["R = CommandResult"]
|
|
1451
1449
|
);
|
|
1452
|
-
|
|
1450
|
+
me(i, this.defaultCommandClientOptionsName), t.commands.forEach((s) => {
|
|
1453
1451
|
this.processCommandMethod(
|
|
1454
1452
|
t,
|
|
1455
1453
|
i,
|
|
@@ -1492,7 +1490,7 @@ class mt {
|
|
|
1492
1490
|
e.name,
|
|
1493
1491
|
s.name
|
|
1494
1492
|
)).map((s) => {
|
|
1495
|
-
const a =
|
|
1493
|
+
const a = ie(s);
|
|
1496
1494
|
return this.context.logger.info(
|
|
1497
1495
|
`Adding path parameter: ${s.name} (type: ${a})`
|
|
1498
1496
|
), {
|
|
@@ -1511,7 +1509,7 @@ class mt {
|
|
|
1511
1509
|
`Adding command request parameter: commandRequest (type: CommandRequest<${r}>)`
|
|
1512
1510
|
), i.push({
|
|
1513
1511
|
name: "commandRequest",
|
|
1514
|
-
hasQuestionToken:
|
|
1512
|
+
hasQuestionToken: we(t.schema.schema),
|
|
1515
1513
|
type: `CommandRequest<${r}>`,
|
|
1516
1514
|
decorators: [
|
|
1517
1515
|
{
|
|
@@ -1568,7 +1566,7 @@ class mt {
|
|
|
1568
1566
|
);
|
|
1569
1567
|
}
|
|
1570
1568
|
}
|
|
1571
|
-
class
|
|
1569
|
+
class lt {
|
|
1572
1570
|
/**
|
|
1573
1571
|
* Creates a new QueryClientGenerator instance.
|
|
1574
1572
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
@@ -1606,7 +1604,7 @@ class dt {
|
|
|
1606
1604
|
* @returns The source file for the client
|
|
1607
1605
|
*/
|
|
1608
1606
|
createClientFilePath(e, t) {
|
|
1609
|
-
return
|
|
1607
|
+
return fe(
|
|
1610
1608
|
this.context.project,
|
|
1611
1609
|
this.context.outputDir,
|
|
1612
1610
|
e,
|
|
@@ -1638,15 +1636,15 @@ class dt {
|
|
|
1638
1636
|
this.context.logger.info(
|
|
1639
1637
|
`Creating default query client options: ${o}`
|
|
1640
1638
|
), t.addVariableStatement({
|
|
1641
|
-
declarationKind:
|
|
1639
|
+
declarationKind: N.Const,
|
|
1642
1640
|
declarations: [
|
|
1643
1641
|
{
|
|
1644
1642
|
name: o,
|
|
1645
1643
|
type: "QueryClientOptions",
|
|
1646
1644
|
initializer: `{
|
|
1647
|
-
contextAlias: ${
|
|
1645
|
+
contextAlias: ${D(e.aggregate.contextAlias)},
|
|
1648
1646
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1649
|
-
resourceAttribution: ${
|
|
1647
|
+
resourceAttribution: ${at(e)},
|
|
1650
1648
|
}`
|
|
1651
1649
|
}
|
|
1652
1650
|
],
|
|
@@ -1663,7 +1661,7 @@ class dt {
|
|
|
1663
1661
|
), d(t, this.context.outputDir, a), this.context.logger.info(
|
|
1664
1662
|
`Creating query client factory: ${i}`
|
|
1665
1663
|
), t.addVariableStatement({
|
|
1666
|
-
declarationKind:
|
|
1664
|
+
declarationKind: N.Const,
|
|
1667
1665
|
declarations: [
|
|
1668
1666
|
{
|
|
1669
1667
|
name: i,
|
|
@@ -1717,13 +1715,13 @@ class dt {
|
|
|
1717
1715
|
});
|
|
1718
1716
|
}
|
|
1719
1717
|
}
|
|
1720
|
-
class
|
|
1718
|
+
class mt {
|
|
1721
1719
|
/**
|
|
1722
1720
|
* Creates a new ClientGenerator instance.
|
|
1723
1721
|
* @param context - The generation context containing OpenAPI spec and project details
|
|
1724
1722
|
*/
|
|
1725
1723
|
constructor(e) {
|
|
1726
|
-
this.context = e, this.queryClientGenerator = new
|
|
1724
|
+
this.context = e, this.queryClientGenerator = new lt(e), this.commandClientGenerator = new ut(e), this.apiClientGenerator = new pt(e);
|
|
1727
1725
|
}
|
|
1728
1726
|
queryClientGenerator;
|
|
1729
1727
|
commandClientGenerator;
|
|
@@ -1746,7 +1744,7 @@ class ft {
|
|
|
1746
1744
|
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
|
|
1747
1745
|
}
|
|
1748
1746
|
}
|
|
1749
|
-
class
|
|
1747
|
+
class dt {
|
|
1750
1748
|
/** The ts-morph project instance used for code generation */
|
|
1751
1749
|
project;
|
|
1752
1750
|
/** The OpenAPI specification object */
|
|
@@ -1764,7 +1762,7 @@ class ht {
|
|
|
1764
1762
|
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"];
|
|
1765
1763
|
}
|
|
1766
1764
|
getOrCreateSourceFile(e) {
|
|
1767
|
-
return
|
|
1765
|
+
return ge(this.project, this.outputDir, e);
|
|
1768
1766
|
}
|
|
1769
1767
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1770
1768
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1773,8 +1771,8 @@ class ht {
|
|
|
1773
1771
|
return this.defaultIgnorePathParameters.includes(t);
|
|
1774
1772
|
}
|
|
1775
1773
|
}
|
|
1776
|
-
const
|
|
1777
|
-
class
|
|
1774
|
+
const ft = "./fetcher-generator.config.json";
|
|
1775
|
+
class Pt {
|
|
1778
1776
|
/**
|
|
1779
1777
|
* Creates a new CodeGenerator instance with the specified options.
|
|
1780
1778
|
*
|
|
@@ -1782,7 +1780,7 @@ class vt {
|
|
|
1782
1780
|
* @throws Error if the project initialization fails due to invalid TypeScript configuration or missing files.
|
|
1783
1781
|
*/
|
|
1784
1782
|
constructor(e) {
|
|
1785
|
-
this.options = e, this.project = new
|
|
1783
|
+
this.options = e, this.project = new xe(e), this.options.logger.info(
|
|
1786
1784
|
`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`
|
|
1787
1785
|
);
|
|
1788
1786
|
}
|
|
@@ -1810,20 +1808,20 @@ class vt {
|
|
|
1810
1808
|
this.options.logger.info(
|
|
1811
1809
|
"Starting code generation from OpenAPI specification"
|
|
1812
1810
|
), 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");
|
|
1813
|
-
const e = await
|
|
1811
|
+
const e = await je(this.options.inputPath);
|
|
1814
1812
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1815
|
-
const o = new
|
|
1813
|
+
const o = new Xe(e).resolve();
|
|
1816
1814
|
this.options.logger.info(
|
|
1817
1815
|
`Resolved ${o.size} bounded context aggregates`
|
|
1818
1816
|
);
|
|
1819
|
-
const r = this.options.configPath ??
|
|
1817
|
+
const r = this.options.configPath ?? ft;
|
|
1820
1818
|
let i = {};
|
|
1821
1819
|
try {
|
|
1822
|
-
this.options.logger.info(`Parsing configuration file: ${r}`), i = await
|
|
1823
|
-
} catch (
|
|
1824
|
-
this.options.logger.info(`Configuration file parsing failed: ${
|
|
1820
|
+
this.options.logger.info(`Parsing configuration file: ${r}`), i = await _e(r);
|
|
1821
|
+
} catch (p) {
|
|
1822
|
+
this.options.logger.info(`Configuration file parsing failed: ${p}`);
|
|
1825
1823
|
}
|
|
1826
|
-
const s = new
|
|
1824
|
+
const s = new dt({
|
|
1827
1825
|
openAPI: e,
|
|
1828
1826
|
project: this.project,
|
|
1829
1827
|
outputDir: this.options.outputDir,
|
|
@@ -1831,7 +1829,7 @@ class vt {
|
|
|
1831
1829
|
logger: this.options.logger,
|
|
1832
1830
|
config: i
|
|
1833
1831
|
});
|
|
1834
|
-
this.options.logger.info("Generating models"), new
|
|
1832
|
+
this.options.logger.info("Generating models"), new nt(s).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new mt(s).generate(), this.options.logger.info("Clients generated successfully");
|
|
1835
1833
|
const u = this.project.getDirectory(this.options.outputDir);
|
|
1836
1834
|
if (!u) {
|
|
1837
1835
|
this.options.logger.info("Output directory not found.");
|
|
@@ -1928,7 +1926,7 @@ class vt {
|
|
|
1928
1926
|
}
|
|
1929
1927
|
}
|
|
1930
1928
|
export {
|
|
1931
|
-
|
|
1932
|
-
|
|
1929
|
+
Pt as CodeGenerator,
|
|
1930
|
+
ft as DEFAULT_CONFIG_PATH
|
|
1933
1931
|
};
|
|
1934
1932
|
//# sourceMappingURL=index.js.map
|