@ahoo-wang/fetcher-generator 3.2.8 → 3.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -114
- package/dist/index.js.map +1 -1
- package/dist/utils/sourceFiles.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Scope as
|
|
1
|
+
import { Scope as Ae, VariableDeclarationKind as D, Project as Ce } 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 {
|
|
4
|
+
import { parse as Z } from "yaml";
|
|
5
|
+
import { readFile as Pe } from "fs";
|
|
6
|
+
import { posix as B } from "path";
|
|
7
7
|
function P(n) {
|
|
8
8
|
return n.$ref.split("/").pop();
|
|
9
9
|
}
|
|
@@ -11,11 +11,11 @@ function S(n, e) {
|
|
|
11
11
|
const t = P(n);
|
|
12
12
|
return e.schemas?.[t];
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function X(n, e) {
|
|
15
15
|
const t = P(n);
|
|
16
16
|
return e.requestBodies?.[t];
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function ee(n, e) {
|
|
19
19
|
const t = P(n);
|
|
20
20
|
return e.parameters?.[t];
|
|
21
21
|
}
|
|
@@ -29,10 +29,10 @@ const $e = /[-_'\s.]+/;
|
|
|
29
29
|
function O(n) {
|
|
30
30
|
return n.split($e);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return Array.isArray(n) ? n.flatMap((e) =>
|
|
32
|
+
function te(n) {
|
|
33
|
+
return Array.isArray(n) ? n.flatMap((e) => U(O(e))) : U(O(n));
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function U(n) {
|
|
36
36
|
return n.flatMap((e) => {
|
|
37
37
|
if (e.length === 0)
|
|
38
38
|
return [];
|
|
@@ -46,7 +46,7 @@ function B(n) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
function R(n) {
|
|
49
|
-
return n === "" || n.length === 0 ? "" :
|
|
49
|
+
return n === "" || n.length === 0 ? "" : te(n).filter((t) => t.length > 0).map((t) => {
|
|
50
50
|
const o = t.charAt(0), r = t.slice(1);
|
|
51
51
|
return (/[a-zA-Z]/.test(o) ? o.toUpperCase() : o) + r.toLowerCase();
|
|
52
52
|
}).join("");
|
|
@@ -55,23 +55,23 @@ function f(n) {
|
|
|
55
55
|
const e = R(n);
|
|
56
56
|
return e.charAt(0).toLowerCase() + e.slice(1);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return n === "" || Array.isArray(n) && n.length === 0 ? "" :
|
|
58
|
+
function ne(n) {
|
|
59
|
+
return n === "" || Array.isArray(n) && n.length === 0 ? "" : te(n).filter((t) => t.length > 0).map((t) => t.toUpperCase()).join("_");
|
|
60
60
|
}
|
|
61
61
|
function M(n) {
|
|
62
62
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n) ? n : `'${n}'`;
|
|
63
63
|
}
|
|
64
64
|
function Te(n) {
|
|
65
|
-
return /^\d+$/.test(n) ? `NUM_${n}` : M(
|
|
65
|
+
return /^\d+$/.test(n) ? `NUM_${n}` : M(ne(n));
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function p(n) {
|
|
68
68
|
return !!(n && typeof n == "object" && "$ref" in n);
|
|
69
69
|
}
|
|
70
70
|
function G(n, e) {
|
|
71
|
-
if (e && !
|
|
71
|
+
if (e && !p(e) && e.content)
|
|
72
72
|
return e.content[n]?.schema;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function oe(n) {
|
|
75
75
|
return G(I.APPLICATION_JSON, n);
|
|
76
76
|
}
|
|
77
77
|
function ve(n) {
|
|
@@ -87,10 +87,10 @@ const Ee = [
|
|
|
87
87
|
"boolean",
|
|
88
88
|
"null"
|
|
89
89
|
];
|
|
90
|
-
function
|
|
90
|
+
function re(n) {
|
|
91
91
|
return Array.isArray(n) ? !0 : Ee.includes(n);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function J(n) {
|
|
94
94
|
return Array.isArray(n.enum) && n.enum.length > 0;
|
|
95
95
|
}
|
|
96
96
|
function T(n) {
|
|
@@ -108,7 +108,7 @@ function Re(n) {
|
|
|
108
108
|
function q(n) {
|
|
109
109
|
return Array.isArray(n.allOf) && n.allOf.length > 0;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function Q(n) {
|
|
112
112
|
return Se(n) || Re(n) || q(n);
|
|
113
113
|
}
|
|
114
114
|
function we(n) {
|
|
@@ -151,10 +151,10 @@ function be(n, e) {
|
|
|
151
151
|
e.operation.operationId
|
|
152
152
|
) : n.path && e.path ? n.path.localeCompare(e.path) : n.method && e.method ? n.method.localeCompare(e.method) : 0;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function ie(n) {
|
|
155
155
|
const e = [];
|
|
156
156
|
for (const [t, o] of Object.entries(n))
|
|
157
|
-
|
|
157
|
+
se(o).forEach((r) => {
|
|
158
158
|
e.push({
|
|
159
159
|
method: r.method,
|
|
160
160
|
operation: r.operation,
|
|
@@ -163,7 +163,7 @@ function oe(n) {
|
|
|
163
163
|
});
|
|
164
164
|
return e.sort(be);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function se(n) {
|
|
167
167
|
return [
|
|
168
168
|
{ method: "get", operation: n.get },
|
|
169
169
|
{ method: "put", operation: n.put },
|
|
@@ -178,18 +178,18 @@ function re(n) {
|
|
|
178
178
|
function W(n) {
|
|
179
179
|
return n.responses[200];
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function V(n) {
|
|
182
182
|
const e = W(n);
|
|
183
|
-
return
|
|
183
|
+
return oe(e);
|
|
184
184
|
}
|
|
185
185
|
function qe(n, e) {
|
|
186
|
-
return n.parameters ? n.parameters.map((t) =>
|
|
186
|
+
return n.parameters ? n.parameters.map((t) => p(t) ? ee(t, e) : t).filter((t) => t.in === "path") : [];
|
|
187
187
|
}
|
|
188
188
|
const Fe = "string";
|
|
189
|
-
function
|
|
190
|
-
return !n.schema ||
|
|
189
|
+
function ae(n) {
|
|
190
|
+
return !n.schema || p(n.schema) || !n.schema.type || !re(n.schema.type) ? Fe : w(n.schema.type);
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function ce(n) {
|
|
193
193
|
return n.startsWith("http://") || n.startsWith("https://") ? je(n) : _e(n);
|
|
194
194
|
}
|
|
195
195
|
async function je(n) {
|
|
@@ -197,34 +197,34 @@ async function je(n) {
|
|
|
197
197
|
}
|
|
198
198
|
function _e(n) {
|
|
199
199
|
return new Promise((e, t) => {
|
|
200
|
-
|
|
200
|
+
Pe(n, "utf-8", (o, r) => {
|
|
201
201
|
o ? t(o) : e(r);
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
async function Ge(n) {
|
|
206
|
-
const e = await
|
|
207
|
-
switch (
|
|
206
|
+
const e = await ce(n);
|
|
207
|
+
switch (pe(e)) {
|
|
208
208
|
case "json":
|
|
209
209
|
return JSON.parse(e);
|
|
210
210
|
case "yaml":
|
|
211
|
-
return
|
|
211
|
+
return Z(e);
|
|
212
212
|
default:
|
|
213
213
|
throw new Error(`Unsupported file format: ${n}`);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
async function We(n) {
|
|
217
|
-
const e = await
|
|
218
|
-
switch (
|
|
217
|
+
const e = await ce(n);
|
|
218
|
+
switch (pe(e)) {
|
|
219
219
|
case "json":
|
|
220
220
|
return JSON.parse(e);
|
|
221
221
|
case "yaml":
|
|
222
|
-
return
|
|
222
|
+
return Z(e);
|
|
223
223
|
default:
|
|
224
224
|
throw new Error(`Unsupported file format: ${n}`);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
function
|
|
227
|
+
function pe(n) {
|
|
228
228
|
const e = n.trimStart();
|
|
229
229
|
if (e.startsWith("{") || e.startsWith("["))
|
|
230
230
|
return "json";
|
|
@@ -238,11 +238,11 @@ function ae(n) {
|
|
|
238
238
|
}
|
|
239
239
|
throw new Error("Unable to infer file format");
|
|
240
240
|
}
|
|
241
|
-
const
|
|
241
|
+
const ge = "types.ts", ke = "@";
|
|
242
242
|
function ze(n) {
|
|
243
|
-
return E(n.path,
|
|
243
|
+
return E(n.path, ge);
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function ue(n, e, t) {
|
|
246
246
|
const o = E(e, t), r = n.getSourceFile(o);
|
|
247
247
|
return r || n.createSourceFile(o, "", {
|
|
248
248
|
overwrite: !0
|
|
@@ -260,19 +260,22 @@ function A(n, e, t) {
|
|
|
260
260
|
) || o.addNamedImport(r);
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
|
+
function H(n) {
|
|
264
|
+
return n.split("\\").join("/");
|
|
265
|
+
}
|
|
263
266
|
function d(n, e, t) {
|
|
264
267
|
if (t.path.startsWith(ke)) {
|
|
265
268
|
A(n, t.path, [t.name]);
|
|
266
269
|
return;
|
|
267
270
|
}
|
|
268
|
-
const o = n.getDirectoryPath(), r =
|
|
269
|
-
let
|
|
270
|
-
|
|
271
|
+
const o = H(n.getDirectoryPath()), r = H(e), i = B.join(r, t.path, ge);
|
|
272
|
+
let s = B.relative(o, i);
|
|
273
|
+
s = s.replace(/\.ts$/, ""), s.startsWith(".") || (s = "./" + s), A(n, s, [t.name]);
|
|
271
274
|
}
|
|
272
275
|
function Le(n, e, t, o) {
|
|
273
276
|
n.path !== o.path && d(e, t, o);
|
|
274
277
|
}
|
|
275
|
-
function
|
|
278
|
+
function le(n, e = `
|
|
276
279
|
`) {
|
|
277
280
|
if (!Array.isArray(n))
|
|
278
281
|
return;
|
|
@@ -282,7 +285,7 @@ function pe(n, e = `
|
|
|
282
285
|
return t.length > 0 ? t.join(e) : void 0;
|
|
283
286
|
}
|
|
284
287
|
function C(n, e) {
|
|
285
|
-
const t =
|
|
288
|
+
const t = le(e);
|
|
286
289
|
t && n.addJsDoc(t);
|
|
287
290
|
}
|
|
288
291
|
function k(n, e) {
|
|
@@ -290,7 +293,7 @@ function k(n, e) {
|
|
|
290
293
|
n.title,
|
|
291
294
|
n.description
|
|
292
295
|
];
|
|
293
|
-
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`),
|
|
296
|
+
return e && t.push(`- key: ${e}`), n.format && t.push(`- format: ${n.format}`), K(t, n, "default"), K(t, n, "example"), Je(t, n), Qe(t, n), Ve(t, n), t;
|
|
294
297
|
}
|
|
295
298
|
function Be(n, e, t) {
|
|
296
299
|
const o = k(e, t);
|
|
@@ -298,19 +301,19 @@ function Be(n, e, t) {
|
|
|
298
301
|
}
|
|
299
302
|
function Ue(n, e, t) {
|
|
300
303
|
const o = k(e, t);
|
|
301
|
-
|
|
304
|
+
me(o, "schema", e), C(n, o);
|
|
302
305
|
}
|
|
303
|
-
function
|
|
306
|
+
function K(n, e, t) {
|
|
304
307
|
const o = e[t];
|
|
305
308
|
if (o) {
|
|
306
309
|
if (typeof o != "object") {
|
|
307
310
|
n.push(`- ${t}: \`${o}\``);
|
|
308
311
|
return;
|
|
309
312
|
}
|
|
310
|
-
|
|
313
|
+
me(n, t, o);
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
|
-
function
|
|
316
|
+
function me(n, e, t) {
|
|
314
317
|
n.push(`- ${e}: `), n.push("```json"), n.push(JSON.stringify(t, null, 2)), n.push("```");
|
|
315
318
|
}
|
|
316
319
|
function Je(n, e) {
|
|
@@ -375,7 +378,7 @@ class tt {
|
|
|
375
378
|
* @private
|
|
376
379
|
*/
|
|
377
380
|
build() {
|
|
378
|
-
const e =
|
|
381
|
+
const e = ie(this.openAPI.paths);
|
|
379
382
|
for (const t of e)
|
|
380
383
|
this.commands(t.path, t), this.state(t.operation), this.events(t.operation), this.fields(t.operation);
|
|
381
384
|
}
|
|
@@ -407,24 +410,24 @@ class tt {
|
|
|
407
410
|
if (!r)
|
|
408
411
|
return;
|
|
409
412
|
const i = W(o);
|
|
410
|
-
if (!i || !
|
|
413
|
+
if (!i || !p(i) || i.$ref !== Xe || !o.requestBody)
|
|
411
414
|
return;
|
|
412
|
-
const s = o.parameters ?? [], a = s.filter((l) =>
|
|
413
|
-
(l) => !
|
|
415
|
+
const s = o.parameters ?? [], a = s.filter((l) => p(l) && l.$ref === et).at(0), c = s.filter(
|
|
416
|
+
(l) => !p(l) && l.in === "path"
|
|
414
417
|
);
|
|
415
418
|
if (a) {
|
|
416
|
-
const l =
|
|
419
|
+
const l = ee(
|
|
417
420
|
a,
|
|
418
421
|
this.openAPI.components
|
|
419
422
|
);
|
|
420
423
|
c.push(l);
|
|
421
424
|
}
|
|
422
|
-
const
|
|
423
|
-
|
|
425
|
+
const g = o.requestBody.content[I.APPLICATION_JSON].schema, x = $(
|
|
426
|
+
g,
|
|
424
427
|
this.openAPI.components
|
|
425
428
|
);
|
|
426
429
|
x.schema.title = x.schema.title || o.summary, x.schema.description = x.schema.description || o.description;
|
|
427
|
-
const
|
|
430
|
+
const xe = {
|
|
428
431
|
name: r,
|
|
429
432
|
method: t.method,
|
|
430
433
|
path: e,
|
|
@@ -436,7 +439,7 @@ class tt {
|
|
|
436
439
|
};
|
|
437
440
|
o.tags?.forEach((l) => {
|
|
438
441
|
const z = this.aggregates.get(l);
|
|
439
|
-
z && z.commands.set(r,
|
|
442
|
+
z && z.commands.set(r, xe);
|
|
440
443
|
});
|
|
441
444
|
}
|
|
442
445
|
/**
|
|
@@ -446,8 +449,8 @@ class tt {
|
|
|
446
449
|
state(e) {
|
|
447
450
|
if (!e.operationId?.endsWith(".snapshot_state.single"))
|
|
448
451
|
return;
|
|
449
|
-
const t =
|
|
450
|
-
if (!
|
|
452
|
+
const t = V(e);
|
|
453
|
+
if (!p(t))
|
|
451
454
|
return;
|
|
452
455
|
const o = $(
|
|
453
456
|
t,
|
|
@@ -465,24 +468,24 @@ class tt {
|
|
|
465
468
|
events(e) {
|
|
466
469
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query"))
|
|
467
470
|
return;
|
|
468
|
-
const t =
|
|
469
|
-
if (
|
|
471
|
+
const t = V(e);
|
|
472
|
+
if (p(t))
|
|
470
473
|
return;
|
|
471
474
|
const o = t?.items;
|
|
472
|
-
if (!
|
|
475
|
+
if (!p(o))
|
|
473
476
|
return;
|
|
474
477
|
const i = S(
|
|
475
478
|
o,
|
|
476
479
|
this.openAPI.components
|
|
477
480
|
).properties.body.items.anyOf.map((s) => {
|
|
478
|
-
const a = s.title, c = s.properties.name.const, u = s.properties.body,
|
|
481
|
+
const a = s.title, c = s.properties.name.const, u = s.properties.body, g = $(
|
|
479
482
|
u,
|
|
480
483
|
this.openAPI.components
|
|
481
484
|
);
|
|
482
|
-
return
|
|
485
|
+
return g.schema.title = g.schema.title || s.title, {
|
|
483
486
|
title: a,
|
|
484
487
|
name: c,
|
|
485
|
-
schema:
|
|
488
|
+
schema: g
|
|
486
489
|
};
|
|
487
490
|
});
|
|
488
491
|
e.tags?.forEach((s) => {
|
|
@@ -499,7 +502,7 @@ class tt {
|
|
|
499
502
|
fields(e) {
|
|
500
503
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count"))
|
|
501
504
|
return;
|
|
502
|
-
const o =
|
|
505
|
+
const o = X(
|
|
503
506
|
e.requestBody,
|
|
504
507
|
this.openAPI.components
|
|
505
508
|
).content[I.APPLICATION_JSON].schema, i = S(
|
|
@@ -563,7 +566,7 @@ function v(n) {
|
|
|
563
566
|
return m(e);
|
|
564
567
|
}
|
|
565
568
|
function N(n) {
|
|
566
|
-
return `${
|
|
569
|
+
return `${ne(n)}_BOUNDED_CONTEXT_ALIAS`;
|
|
567
570
|
}
|
|
568
571
|
class ot {
|
|
569
572
|
constructor(e, t, o, r) {
|
|
@@ -575,7 +578,7 @@ class ot {
|
|
|
575
578
|
}
|
|
576
579
|
process() {
|
|
577
580
|
const { schema: e } = this.keySchema;
|
|
578
|
-
return
|
|
581
|
+
return J(e) ? this.processEnum(e) : T(e) ? this.processInterface(e) : b(e) ? this.processArray(e) : q(e) ? this.processIntersection(e) : Q(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
579
582
|
}
|
|
580
583
|
resolveReference(e) {
|
|
581
584
|
const t = v(e);
|
|
@@ -593,8 +596,8 @@ class ot {
|
|
|
593
596
|
const { properties: t } = e;
|
|
594
597
|
return Object.entries(t).map(([o, r]) => {
|
|
595
598
|
const i = this.resolveType(r), s = M(o);
|
|
596
|
-
if (!
|
|
597
|
-
const a = k(r), c =
|
|
599
|
+
if (!p(r)) {
|
|
600
|
+
const a = k(r), c = le(a, `
|
|
598
601
|
* `);
|
|
599
602
|
if (c)
|
|
600
603
|
return `
|
|
@@ -623,15 +626,15 @@ class ot {
|
|
|
623
626
|
return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.resolveType(e.additionalProperties);
|
|
624
627
|
}
|
|
625
628
|
resolveType(e) {
|
|
626
|
-
if (
|
|
629
|
+
if (p(e))
|
|
627
630
|
return this.resolveReference(e).name;
|
|
628
631
|
if (Ne(e))
|
|
629
632
|
return `Record<string,${this.resolveMapValueType(e)}>`;
|
|
630
633
|
if (e.const)
|
|
631
634
|
return `'${e.const}'`;
|
|
632
|
-
if (
|
|
635
|
+
if (J(e))
|
|
633
636
|
return e.enum.map((t) => `\`${t}\``).join(" | ");
|
|
634
|
-
if (
|
|
637
|
+
if (Q(e)) {
|
|
635
638
|
const o = (e.oneOf || e.anyOf || e.allOf || []).map((i) => this.resolveType(i)), r = q(e) ? " & " : " | ";
|
|
636
639
|
return `(${o.join(r)})`;
|
|
637
640
|
}
|
|
@@ -696,7 +699,7 @@ class ot {
|
|
|
696
699
|
isExported: !0
|
|
697
700
|
});
|
|
698
701
|
return e.allOf.forEach((o) => {
|
|
699
|
-
if (
|
|
702
|
+
if (p(o)) {
|
|
700
703
|
const r = this.resolveType(o);
|
|
701
704
|
t.addExtends(r);
|
|
702
705
|
return;
|
|
@@ -838,14 +841,14 @@ const it = "@ahoo-wang/fetcher-decorator", st = [
|
|
|
838
841
|
], at = {
|
|
839
842
|
type: "Promise<Response>",
|
|
840
843
|
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
841
|
-
},
|
|
844
|
+
}, Y = {
|
|
842
845
|
type: "Promise<string>",
|
|
843
846
|
metadata: "{resultExtractor: ResultExtractors.Text }"
|
|
844
847
|
}, F = `{
|
|
845
848
|
headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },
|
|
846
849
|
resultExtractor: JsonEventStreamResultExtractor,
|
|
847
850
|
}`;
|
|
848
|
-
function
|
|
851
|
+
function de(n) {
|
|
849
852
|
A(n, it, st);
|
|
850
853
|
}
|
|
851
854
|
function j(n, e, t = [], o = [], r) {
|
|
@@ -862,14 +865,14 @@ function j(n, e, t = [], o = [], r) {
|
|
|
862
865
|
]
|
|
863
866
|
});
|
|
864
867
|
}
|
|
865
|
-
function
|
|
868
|
+
function fe(n, e) {
|
|
866
869
|
n.addImplements("ApiMetadataCapable"), n.addConstructor({
|
|
867
870
|
parameters: [
|
|
868
871
|
{
|
|
869
872
|
name: "apiMetadata",
|
|
870
873
|
type: "ApiMetadata",
|
|
871
874
|
hasQuestionToken: e === void 0,
|
|
872
|
-
scope:
|
|
875
|
+
scope: Ae.Public,
|
|
873
876
|
isReadonly: !0,
|
|
874
877
|
initializer: e
|
|
875
878
|
}
|
|
@@ -877,21 +880,21 @@ function me(n, e) {
|
|
|
877
880
|
});
|
|
878
881
|
}
|
|
879
882
|
const ct = "@ahoo-wang/fetcher-eventstream";
|
|
880
|
-
function
|
|
883
|
+
function he(n) {
|
|
881
884
|
A(n, ct, [
|
|
882
885
|
"JsonEventStreamResultExtractor",
|
|
883
886
|
"type JsonServerSentEventStream"
|
|
884
887
|
]);
|
|
885
888
|
}
|
|
886
|
-
function
|
|
889
|
+
function pt(n) {
|
|
887
890
|
let e = 0, t = 0;
|
|
888
891
|
return n.commands.forEach((o) => {
|
|
889
892
|
o.path.startsWith(L.TENANT) && (e += 1), o.path.startsWith(L.OWNER) && (t += 1);
|
|
890
893
|
}), e === 0 && t === 0 ? "ResourceAttributionPathSpec.NONE" : e > t ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
891
894
|
}
|
|
892
|
-
function
|
|
895
|
+
function ye(n, e, t, o) {
|
|
893
896
|
const r = `${t.contextAlias}/${t.aggregateName}/${o}.ts`;
|
|
894
|
-
return
|
|
897
|
+
return ue(n, e, r);
|
|
895
898
|
}
|
|
896
899
|
function h(n, e) {
|
|
897
900
|
return `${R(n.aggregateName)}${e}`;
|
|
@@ -899,9 +902,9 @@ function h(n, e) {
|
|
|
899
902
|
function _(n) {
|
|
900
903
|
return n === "delete" ? "del" : n;
|
|
901
904
|
}
|
|
902
|
-
const
|
|
905
|
+
const gt = "x-fetcher-method";
|
|
903
906
|
function ut(n, e) {
|
|
904
|
-
const t = n[
|
|
907
|
+
const t = n[gt];
|
|
905
908
|
if (t)
|
|
906
909
|
return t;
|
|
907
910
|
if (!n.operationId)
|
|
@@ -980,12 +983,12 @@ class lt {
|
|
|
980
983
|
`Generating API client class: ${o.name}ApiClient with ${t.size} operations`
|
|
981
984
|
);
|
|
982
985
|
const r = this.createApiClientFile(o);
|
|
983
|
-
|
|
986
|
+
de(r), he(r);
|
|
984
987
|
const i = j(
|
|
985
988
|
o.name + "ApiClient",
|
|
986
989
|
r
|
|
987
990
|
);
|
|
988
|
-
C(i, [e.description]),
|
|
991
|
+
C(i, [e.description]), fe(i, this.apiMetadataCtorInitializer), this.context.logger.info(
|
|
989
992
|
`Processing ${t.size} operations for ${o.name}ApiClient`
|
|
990
993
|
), t.forEach((s) => {
|
|
991
994
|
this.processOperation(e, r, i, s);
|
|
@@ -1019,9 +1022,9 @@ class lt {
|
|
|
1019
1022
|
`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`
|
|
1020
1023
|
), this.defaultParameterRequestType;
|
|
1021
1024
|
let o;
|
|
1022
|
-
if (
|
|
1025
|
+
if (p(t.requestBody) ? (this.context.logger.info(
|
|
1023
1026
|
`Extracting request body from reference for operation: ${t.operationId}`
|
|
1024
|
-
), o =
|
|
1027
|
+
), o = X(
|
|
1025
1028
|
t.requestBody,
|
|
1026
1029
|
this.context.openAPI.components
|
|
1027
1030
|
)) : o = t.requestBody, !o)
|
|
@@ -1034,7 +1037,7 @@ class lt {
|
|
|
1034
1037
|
), "ParameterRequest<FormData>";
|
|
1035
1038
|
if (o.content["application/json"]) {
|
|
1036
1039
|
const r = o.content["application/json"].schema;
|
|
1037
|
-
if (
|
|
1040
|
+
if (p(r)) {
|
|
1038
1041
|
const i = v(r);
|
|
1039
1042
|
this.context.logger.info(
|
|
1040
1043
|
`Adding import for request body model: ${i.name} from ${i.path}`
|
|
@@ -1068,7 +1071,7 @@ class lt {
|
|
|
1068
1071
|
`Found ${r.length} path parameters for operation ${o.operationId}`
|
|
1069
1072
|
);
|
|
1070
1073
|
const i = r.map((a) => {
|
|
1071
|
-
const c =
|
|
1074
|
+
const c = ae(a);
|
|
1072
1075
|
return this.context.logger.info(
|
|
1073
1076
|
`Adding path parameter: ${a.name} (type: ${c})`
|
|
1074
1077
|
), {
|
|
@@ -1115,7 +1118,7 @@ class lt {
|
|
|
1115
1118
|
*/
|
|
1116
1119
|
resolveSchemaReturnType(e, t) {
|
|
1117
1120
|
const o = "Promise<any>";
|
|
1118
|
-
if (
|
|
1121
|
+
if (p(t)) {
|
|
1119
1122
|
const r = v(t);
|
|
1120
1123
|
this.context.logger.info(
|
|
1121
1124
|
`Adding import for response model: ${r.name} from ${r.path}`
|
|
@@ -1127,7 +1130,7 @@ class lt {
|
|
|
1127
1130
|
return this.context.logger.info(
|
|
1128
1131
|
`Schema has no type, using default return type: ${o}`
|
|
1129
1132
|
), o;
|
|
1130
|
-
if (
|
|
1133
|
+
if (re(t.type)) {
|
|
1131
1134
|
const i = `Promise<${w(t.type)}>`;
|
|
1132
1135
|
return this.context.logger.info(`Resolved primitive return type: ${i}`), i;
|
|
1133
1136
|
}
|
|
@@ -1147,33 +1150,33 @@ class lt {
|
|
|
1147
1150
|
return this.context.logger.info(
|
|
1148
1151
|
`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`
|
|
1149
1152
|
), this.defaultReturnType;
|
|
1150
|
-
const r =
|
|
1153
|
+
const r = oe(o) || Ie(o);
|
|
1151
1154
|
if (r) {
|
|
1152
1155
|
const s = this.resolveSchemaReturnType(e, r);
|
|
1153
1156
|
return this.context.logger.info(
|
|
1154
1157
|
`Resolved JSON/wildcard response return type for operation ${t.operationId}: ${s}`
|
|
1155
1158
|
), {
|
|
1156
1159
|
type: s,
|
|
1157
|
-
metadata: s ===
|
|
1160
|
+
metadata: s === Y.type ? Y.metadata : void 0
|
|
1158
1161
|
};
|
|
1159
1162
|
}
|
|
1160
1163
|
const i = ve(o);
|
|
1161
1164
|
if (i) {
|
|
1162
|
-
if (
|
|
1165
|
+
if (p(i)) {
|
|
1163
1166
|
const a = S(
|
|
1164
1167
|
i,
|
|
1165
1168
|
this.context.openAPI.components
|
|
1166
1169
|
);
|
|
1167
|
-
if (b(a) &&
|
|
1170
|
+
if (b(a) && p(a.items)) {
|
|
1168
1171
|
const c = v(a.items);
|
|
1169
1172
|
this.context.logger.info(
|
|
1170
1173
|
`Adding import for event stream model: ${c.name} from ${c.path}`
|
|
1171
1174
|
), d(e, this.context.outputDir, c);
|
|
1172
|
-
const
|
|
1175
|
+
const g = `Promise<JsonServerSentEventStream<${c.name.includes("ServerSentEvent") ? `${c.name}['data']` : c.name}>>`;
|
|
1173
1176
|
return this.context.logger.info(
|
|
1174
|
-
`Resolved event stream return type for operation ${t.operationId}: ${
|
|
1177
|
+
`Resolved event stream return type for operation ${t.operationId}: ${g}`
|
|
1175
1178
|
), {
|
|
1176
|
-
type:
|
|
1179
|
+
type: g,
|
|
1177
1180
|
metadata: F
|
|
1178
1181
|
};
|
|
1179
1182
|
}
|
|
@@ -1220,7 +1223,7 @@ class lt {
|
|
|
1220
1223
|
parameters: s,
|
|
1221
1224
|
returnType: a.type,
|
|
1222
1225
|
statements: [
|
|
1223
|
-
`throw autoGeneratedError(${s.map((
|
|
1226
|
+
`throw autoGeneratedError(${s.map((g) => g.name).join(",")});`
|
|
1224
1227
|
]
|
|
1225
1228
|
});
|
|
1226
1229
|
C(u, [
|
|
@@ -1237,7 +1240,7 @@ class lt {
|
|
|
1237
1240
|
*/
|
|
1238
1241
|
groupOperations(e) {
|
|
1239
1242
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1240
|
-
const t = /* @__PURE__ */ new Map(), o =
|
|
1243
|
+
const t = /* @__PURE__ */ new Map(), o = ie(
|
|
1241
1244
|
this.context.openAPI.paths
|
|
1242
1245
|
).filter((i) => {
|
|
1243
1246
|
if (!i.operation.operationId)
|
|
@@ -1268,7 +1271,7 @@ class lt {
|
|
|
1268
1271
|
);
|
|
1269
1272
|
const e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1270
1273
|
for (const r of Object.values(this.context.openAPI.paths))
|
|
1271
|
-
|
|
1274
|
+
se(r).forEach((i) => {
|
|
1272
1275
|
i.operation.tags?.forEach((s) => {
|
|
1273
1276
|
!this.shouldIgnoreTag(s) && !e.has(s) && e.set(s, {
|
|
1274
1277
|
name: s,
|
|
@@ -1332,7 +1335,7 @@ class mt {
|
|
|
1332
1335
|
this.context.logger.info(
|
|
1333
1336
|
`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`
|
|
1334
1337
|
);
|
|
1335
|
-
const t =
|
|
1338
|
+
const t = ye(
|
|
1336
1339
|
this.context.project,
|
|
1337
1340
|
this.context.outputDir,
|
|
1338
1341
|
e.aggregate,
|
|
@@ -1374,11 +1377,11 @@ class mt {
|
|
|
1374
1377
|
isTypeOnly: !0
|
|
1375
1378
|
}), this.context.logger.info(
|
|
1376
1379
|
"Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"
|
|
1377
|
-
),
|
|
1380
|
+
), he(t), this.context.logger.info(
|
|
1378
1381
|
"Adding import from @ahoo-wang/fetcher: ContentTypeValues"
|
|
1379
1382
|
), A(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info(
|
|
1380
1383
|
"Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"
|
|
1381
|
-
),
|
|
1384
|
+
), de(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(
|
|
1382
1385
|
t,
|
|
1383
1386
|
e,
|
|
1384
1387
|
o
|
|
@@ -1446,7 +1449,7 @@ class mt {
|
|
|
1446
1449
|
[],
|
|
1447
1450
|
["R = CommandResult"]
|
|
1448
1451
|
);
|
|
1449
|
-
|
|
1452
|
+
fe(i, this.defaultCommandClientOptionsName), t.commands.forEach((s) => {
|
|
1450
1453
|
this.processCommandMethod(
|
|
1451
1454
|
t,
|
|
1452
1455
|
i,
|
|
@@ -1489,7 +1492,7 @@ class mt {
|
|
|
1489
1492
|
e.name,
|
|
1490
1493
|
s.name
|
|
1491
1494
|
)).map((s) => {
|
|
1492
|
-
const a =
|
|
1495
|
+
const a = ae(s);
|
|
1493
1496
|
return this.context.logger.info(
|
|
1494
1497
|
`Adding path parameter: ${s.name} (type: ${a})`
|
|
1495
1498
|
), {
|
|
@@ -1603,7 +1606,7 @@ class dt {
|
|
|
1603
1606
|
* @returns The source file for the client
|
|
1604
1607
|
*/
|
|
1605
1608
|
createClientFilePath(e, t) {
|
|
1606
|
-
return
|
|
1609
|
+
return ye(
|
|
1607
1610
|
this.context.project,
|
|
1608
1611
|
this.context.outputDir,
|
|
1609
1612
|
e,
|
|
@@ -1643,7 +1646,7 @@ class dt {
|
|
|
1643
1646
|
initializer: `{
|
|
1644
1647
|
contextAlias: ${N(e.aggregate.contextAlias)},
|
|
1645
1648
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1646
|
-
resourceAttribution: ${
|
|
1649
|
+
resourceAttribution: ${pt(e)},
|
|
1647
1650
|
}`
|
|
1648
1651
|
}
|
|
1649
1652
|
],
|
|
@@ -1761,7 +1764,7 @@ class ht {
|
|
|
1761
1764
|
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"];
|
|
1762
1765
|
}
|
|
1763
1766
|
getOrCreateSourceFile(e) {
|
|
1764
|
-
return
|
|
1767
|
+
return ue(this.project, this.outputDir, e);
|
|
1765
1768
|
}
|
|
1766
1769
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1767
1770
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1779,7 +1782,7 @@ class vt {
|
|
|
1779
1782
|
* @throws Error if the project initialization fails due to invalid TypeScript configuration or missing files.
|
|
1780
1783
|
*/
|
|
1781
1784
|
constructor(e) {
|
|
1782
|
-
this.options = e, this.project = new
|
|
1785
|
+
this.options = e, this.project = new Ce(e), this.options.logger.info(
|
|
1783
1786
|
`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`
|
|
1784
1787
|
);
|
|
1785
1788
|
}
|
|
@@ -1817,8 +1820,8 @@ class vt {
|
|
|
1817
1820
|
let i = {};
|
|
1818
1821
|
try {
|
|
1819
1822
|
this.options.logger.info(`Parsing configuration file: ${r}`), i = await We(r);
|
|
1820
|
-
} catch (
|
|
1821
|
-
this.options.logger.info(`Configuration file parsing failed: ${
|
|
1823
|
+
} catch (g) {
|
|
1824
|
+
this.options.logger.info(`Configuration file parsing failed: ${g}`);
|
|
1822
1825
|
}
|
|
1823
1826
|
const s = new ht({
|
|
1824
1827
|
openAPI: e,
|