@ahoo-wang/fetcher-generator 3.16.0 → 3.16.2
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/aggregate/aggregateResolver.d.ts.map +1 -1
- package/dist/cli.cjs +2 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +142 -8
- package/dist/cli.js.map +1 -1
- package/dist/client/commandClientGenerator.d.ts.map +1 -1
- package/dist/client/decorators.d.ts.map +1 -1
- package/dist/client/queryClientGenerator.d.ts.map +1 -1
- package/dist/generateContext.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/model/modelGenerator.d.ts.map +1 -1
- package/dist/model/typeGenerator.d.ts.map +1 -1
- package/dist/src-BeMHvuFm.cjs +19 -0
- package/dist/src-BeMHvuFm.cjs.map +1 -0
- package/dist/{src-B15FuHXN.js → src-Drc8UO0Q.js} +261 -394
- package/dist/src-Drc8UO0Q.js.map +1 -0
- package/dist/utils/schemas.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/src-65Qr4jZF.cjs +0 -20
- package/dist/src-65Qr4jZF.cjs.map +0 -1
- package/dist/src-B15FuHXN.js.map +0 -1
|
@@ -2,170 +2,37 @@ import { Project as e, Scope as t, VariableDeclarationKind as n } from "ts-morph
|
|
|
2
2
|
import { ContentTypeValues as r, combineURLs as i } from "@ahoo-wang/fetcher";
|
|
3
3
|
import { parse as a } from "yaml";
|
|
4
4
|
import { readFile as o } from "fs";
|
|
5
|
-
import { join as s, relative as c, sep as
|
|
6
|
-
import { ResourceAttributionPathSpec as
|
|
7
|
-
//#region src/utils/logger.ts
|
|
8
|
-
var ee = class {
|
|
9
|
-
getTimestamp() {
|
|
10
|
-
return (/* @__PURE__ */ new Date()).toTimeString().slice(0, 8);
|
|
11
|
-
}
|
|
12
|
-
info(e, ...t) {
|
|
13
|
-
let n = this.getTimestamp();
|
|
14
|
-
t.length > 0 ? console.log(`[${n}] ℹ️ ${e}`, ...t) : console.log(`[${n}] ℹ️ ${e}`);
|
|
15
|
-
}
|
|
16
|
-
success(e, ...t) {
|
|
17
|
-
let n = this.getTimestamp();
|
|
18
|
-
t.length > 0 ? console.log(`[${n}] ✅ ${e}`, ...t) : console.log(`[${n}] ✅ ${e}`);
|
|
19
|
-
}
|
|
20
|
-
error(e, ...t) {
|
|
21
|
-
let n = this.getTimestamp();
|
|
22
|
-
t.length > 0 ? console.error(`[${n}] ❌ ${e}`, ...t) : console.error(`[${n}] ❌ ${e}`);
|
|
23
|
-
}
|
|
24
|
-
progress(e, t = 0, ...n) {
|
|
25
|
-
let r = this.getTimestamp(), i = " ".repeat(t);
|
|
26
|
-
n.length > 0 ? console.log(`[${r}] 🔄 ${i}${e}`, ...n) : console.log(`[${r}] 🔄 ${i}${e}`);
|
|
27
|
-
}
|
|
28
|
-
progressWithCount(e, t, n, r = 0, ...i) {
|
|
29
|
-
let a = this.getTimestamp(), o = " ".repeat(r), s = `[${e}/${t}]`;
|
|
30
|
-
i.length > 0 ? console.log(`[${a}] 🔄 ${o}${s} ${n}`, ...i) : console.log(`[${a}] 🔄 ${o}${s} ${n}`);
|
|
31
|
-
}
|
|
32
|
-
}, te = {
|
|
33
|
-
name: "@ahoo-wang/fetcher-generator",
|
|
34
|
-
version: "3.16.0",
|
|
35
|
-
description: "A powerful TypeScript code generation tool that automatically generates type-safe API client code based on OpenAPI specifications. It is designed for general use cases and is also deeply optimized for the [Wow](https://github.com/Ahoo-Wang/Wow) Domain-Driven Design framework, providing native support for the CQRS architectural pattern.",
|
|
36
|
-
keywords: [
|
|
37
|
-
"fetch",
|
|
38
|
-
"http",
|
|
39
|
-
"client",
|
|
40
|
-
"openapi",
|
|
41
|
-
"openapi3",
|
|
42
|
-
"swagger",
|
|
43
|
-
"generator",
|
|
44
|
-
"typescript",
|
|
45
|
-
"codegen",
|
|
46
|
-
"api",
|
|
47
|
-
"rest"
|
|
48
|
-
],
|
|
49
|
-
author: "Ahoo-Wang",
|
|
50
|
-
license: "Apache-2.0",
|
|
51
|
-
homepage: "https://github.com/Ahoo-Wang/fetcher/tree/master/packages/generator",
|
|
52
|
-
repository: {
|
|
53
|
-
type: "git",
|
|
54
|
-
url: "https://github.com/Ahoo-Wang/fetcher.git",
|
|
55
|
-
directory: "packages/generator"
|
|
56
|
-
},
|
|
57
|
-
bugs: { url: "https://github.com/Ahoo-Wang/fetcher/issues" },
|
|
58
|
-
type: "module",
|
|
59
|
-
engines: { node: ">=18.0.0" },
|
|
60
|
-
main: "./dist/index.umd.js",
|
|
61
|
-
module: "./dist/index.es.js",
|
|
62
|
-
types: "./dist/index.d.ts",
|
|
63
|
-
bin: { "fetcher-generator": "./dist/cli.js" },
|
|
64
|
-
exports: { ".": {
|
|
65
|
-
types: "./dist/index.d.ts",
|
|
66
|
-
import: "./dist/index.es.js",
|
|
67
|
-
require: "./dist/index.umd.js"
|
|
68
|
-
} },
|
|
69
|
-
files: [
|
|
70
|
-
"dist",
|
|
71
|
-
"README.md",
|
|
72
|
-
"README.zh-CN.md"
|
|
73
|
-
],
|
|
74
|
-
scripts: {
|
|
75
|
-
build: "vite build",
|
|
76
|
-
"test:ui": "vitest --ui",
|
|
77
|
-
test: "vitest run --coverage --testTimeout=15000",
|
|
78
|
-
lint: "eslint . --fix",
|
|
79
|
-
clean: "rm -rf dist",
|
|
80
|
-
analyze: "npx vite-bundle-analyzer -p auto",
|
|
81
|
-
generate: "node dist/cli.js generate -i test/demo.spec.json -o test-output -t tsconfig.json"
|
|
82
|
-
},
|
|
83
|
-
peerDependencies: {
|
|
84
|
-
"@ahoo-wang/fetcher": "workspace:^3.0.0",
|
|
85
|
-
"@ahoo-wang/fetcher-eventstream": "workspace:^3.0.0",
|
|
86
|
-
"@ahoo-wang/fetcher-decorator": "workspace:^3.0.0",
|
|
87
|
-
"@ahoo-wang/fetcher-openapi": "workspace:^3.0.0",
|
|
88
|
-
"@ahoo-wang/fetcher-wow": "workspace:^3.0.0"
|
|
89
|
-
},
|
|
90
|
-
dependencies: {
|
|
91
|
-
"ts-morph": "catalog:",
|
|
92
|
-
commander: "catalog:",
|
|
93
|
-
yaml: "catalog:"
|
|
94
|
-
},
|
|
95
|
-
devDependencies: {
|
|
96
|
-
"@eslint/js": "catalog:",
|
|
97
|
-
"@types/node": "catalog:",
|
|
98
|
-
"@vitest/coverage-v8": "catalog:",
|
|
99
|
-
"@vitest/ui": "catalog:",
|
|
100
|
-
eslint: "catalog:",
|
|
101
|
-
globals: "catalog:",
|
|
102
|
-
prettier: "catalog:",
|
|
103
|
-
typescript: "catalog:",
|
|
104
|
-
"typescript-eslint": "catalog:",
|
|
105
|
-
"unplugin-dts": "catalog:",
|
|
106
|
-
vite: "catalog:",
|
|
107
|
-
"vite-bundle-analyzer": "catalog:",
|
|
108
|
-
vitest: "catalog:"
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/utils/clis.ts
|
|
113
|
-
function ne(e) {
|
|
114
|
-
if (!e) return !1;
|
|
115
|
-
try {
|
|
116
|
-
let t = new URL(e);
|
|
117
|
-
return t.protocol === "http:" || t.protocol === "https:";
|
|
118
|
-
} catch {
|
|
119
|
-
return e.length > 0;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async function re(e) {
|
|
123
|
-
let t = new ee();
|
|
124
|
-
process.on("SIGINT", () => {
|
|
125
|
-
t.error("Generation interrupted by user"), process.exit(130);
|
|
126
|
-
}), ne(e.input) || (t.error("Invalid input: must be a valid file path or HTTP/HTTPS URL"), process.exit(2));
|
|
127
|
-
try {
|
|
128
|
-
t.info(`Fetcher Generator v${te.version}`), t.info("Starting code generation..."), await new $({
|
|
129
|
-
inputPath: e.input,
|
|
130
|
-
outputDir: e.output,
|
|
131
|
-
configPath: e.config,
|
|
132
|
-
tsConfigFilePath: e.tsConfigFilePath,
|
|
133
|
-
logger: t
|
|
134
|
-
}).generate(), t.success(`Code generation completed successfully! Files generated in: ${e.output}`);
|
|
135
|
-
} catch (e) {
|
|
136
|
-
t.error("Error during code generation: \n", e), process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
//#endregion
|
|
5
|
+
import { join as s, relative as c, sep as ee } from "path";
|
|
6
|
+
import { ResourceAttributionPathSpec as l } from "@ahoo-wang/fetcher-wow";
|
|
140
7
|
//#region src/utils/components.ts
|
|
141
|
-
var
|
|
142
|
-
`${
|
|
143
|
-
function
|
|
8
|
+
var u = "#/components/";
|
|
9
|
+
`${u}`, `${u}`, `${u}`, `${u}`, `${u}`;
|
|
10
|
+
function d(e) {
|
|
144
11
|
return e.$ref.split("/").pop();
|
|
145
12
|
}
|
|
146
|
-
function
|
|
147
|
-
let n =
|
|
13
|
+
function f(e, t) {
|
|
14
|
+
let n = d(e);
|
|
148
15
|
return t.schemas?.[n];
|
|
149
16
|
}
|
|
150
|
-
function
|
|
151
|
-
let n =
|
|
17
|
+
function p(e, t) {
|
|
18
|
+
let n = d(e);
|
|
152
19
|
return t.requestBodies?.[n];
|
|
153
20
|
}
|
|
154
|
-
function
|
|
155
|
-
let n =
|
|
21
|
+
function te(e, t) {
|
|
22
|
+
let n = d(e);
|
|
156
23
|
return t.parameters?.[n];
|
|
157
24
|
}
|
|
158
25
|
function m(e, t) {
|
|
159
26
|
return {
|
|
160
|
-
key:
|
|
161
|
-
schema:
|
|
27
|
+
key: d(e),
|
|
28
|
+
schema: f(e, t)
|
|
162
29
|
};
|
|
163
30
|
}
|
|
164
31
|
//#endregion
|
|
165
32
|
//#region src/utils/naming.ts
|
|
166
|
-
var
|
|
33
|
+
var ne = /[-_'\s./?;:,()[\]{}|\\]+/;
|
|
167
34
|
function h(e) {
|
|
168
|
-
return e.split(
|
|
35
|
+
return e.split(ne);
|
|
169
36
|
}
|
|
170
37
|
function g(e) {
|
|
171
38
|
return Array.isArray(e) ? e.flatMap((e) => _(h(e))) : _(h(e));
|
|
@@ -191,14 +58,14 @@ function y(e) {
|
|
|
191
58
|
let t = v(e);
|
|
192
59
|
return t.charAt(0).toLowerCase() + t.slice(1);
|
|
193
60
|
}
|
|
194
|
-
function
|
|
61
|
+
function re(e) {
|
|
195
62
|
return e === "" || Array.isArray(e) && e.length === 0 ? "" : g(e).filter((e) => e.length > 0).map((e) => e.toUpperCase()).join("_");
|
|
196
63
|
}
|
|
197
64
|
function b(e) {
|
|
198
65
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e) ? e : `'${e}'`;
|
|
199
66
|
}
|
|
200
|
-
function
|
|
201
|
-
return /^\d+$/.test(e) ? `NUM_${e}` : b(
|
|
67
|
+
function ie(e) {
|
|
68
|
+
return /^\d+$/.test(e) ? `NUM_${e}` : b(re(e));
|
|
202
69
|
}
|
|
203
70
|
//#endregion
|
|
204
71
|
//#region src/utils/references.ts
|
|
@@ -210,70 +77,70 @@ function x(e) {
|
|
|
210
77
|
function S(e, t) {
|
|
211
78
|
if (t && !x(t) && t.content) return t.content[e]?.schema;
|
|
212
79
|
}
|
|
213
|
-
function
|
|
80
|
+
function ae(e) {
|
|
214
81
|
return S(r.APPLICATION_JSON, e);
|
|
215
82
|
}
|
|
216
|
-
function
|
|
83
|
+
function oe(e) {
|
|
217
84
|
return S(r.TEXT_EVENT_STREAM, e);
|
|
218
85
|
}
|
|
219
|
-
function
|
|
86
|
+
function se(e) {
|
|
220
87
|
return S("*/*", e);
|
|
221
88
|
}
|
|
222
89
|
//#endregion
|
|
223
90
|
//#region src/utils/schemas.ts
|
|
224
|
-
var
|
|
91
|
+
var ce = [
|
|
225
92
|
"string",
|
|
226
93
|
"number",
|
|
227
94
|
"integer",
|
|
228
95
|
"boolean",
|
|
229
96
|
"null"
|
|
230
97
|
];
|
|
231
|
-
function
|
|
232
|
-
return Array.isArray(e) ? !0 :
|
|
98
|
+
function C(e) {
|
|
99
|
+
return Array.isArray(e) ? !0 : ce.includes(e);
|
|
233
100
|
}
|
|
234
|
-
function
|
|
101
|
+
function w(e) {
|
|
235
102
|
return Array.isArray(e.enum) && e.enum.length > 0;
|
|
236
103
|
}
|
|
237
|
-
var
|
|
238
|
-
function
|
|
239
|
-
return e[
|
|
104
|
+
var le = "x-enum-text";
|
|
105
|
+
function ue(e) {
|
|
106
|
+
return e[le];
|
|
240
107
|
}
|
|
241
|
-
function
|
|
108
|
+
function T(e) {
|
|
242
109
|
return e.type === "object" && !!e.properties;
|
|
243
110
|
}
|
|
244
|
-
function
|
|
111
|
+
function E(e) {
|
|
245
112
|
return e.type === "array" && !!e.items;
|
|
246
113
|
}
|
|
247
|
-
function
|
|
114
|
+
function de(e) {
|
|
248
115
|
return Array.isArray(e.anyOf) && e.anyOf.length > 0;
|
|
249
116
|
}
|
|
250
|
-
function
|
|
117
|
+
function fe(e) {
|
|
251
118
|
return Array.isArray(e.oneOf) && e.oneOf.length > 0;
|
|
252
119
|
}
|
|
253
|
-
function
|
|
120
|
+
function D(e) {
|
|
254
121
|
return Array.isArray(e.allOf) && e.allOf.length > 0;
|
|
255
122
|
}
|
|
256
|
-
function
|
|
257
|
-
return
|
|
123
|
+
function O(e) {
|
|
124
|
+
return de(e) || fe(e) || D(e);
|
|
258
125
|
}
|
|
259
|
-
function
|
|
126
|
+
function k(e) {
|
|
260
127
|
return e.includes("|") || e.includes("&") ? `(${e})[]` : `${e}[]`;
|
|
261
128
|
}
|
|
262
|
-
function
|
|
129
|
+
function A(e) {
|
|
263
130
|
return e.type === "object" && !e.properties && e.additionalProperties !== void 0;
|
|
264
131
|
}
|
|
265
|
-
var
|
|
266
|
-
function
|
|
267
|
-
return e[
|
|
132
|
+
var pe = "x-map-key-schema";
|
|
133
|
+
function me(e) {
|
|
134
|
+
return e[pe];
|
|
268
135
|
}
|
|
269
|
-
function
|
|
136
|
+
function he(e) {
|
|
270
137
|
return e.type === "object" ? e.properties ? Object.keys(e.properties).length === 0 : !0 : !1;
|
|
271
138
|
}
|
|
272
|
-
function
|
|
139
|
+
function ge(e) {
|
|
273
140
|
return e.readOnly === !0;
|
|
274
141
|
}
|
|
275
|
-
function
|
|
276
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
142
|
+
function j(e) {
|
|
143
|
+
if (Array.isArray(e)) return e.map((e) => j(e)).join(" | ");
|
|
277
144
|
switch (e) {
|
|
278
145
|
case "string": return "string";
|
|
279
146
|
case "number":
|
|
@@ -283,28 +150,28 @@ function k(e) {
|
|
|
283
150
|
default: return "any";
|
|
284
151
|
}
|
|
285
152
|
}
|
|
286
|
-
function
|
|
287
|
-
if (!
|
|
153
|
+
function _e(e) {
|
|
154
|
+
if (!T(e)) return [];
|
|
288
155
|
let t = e.required || [];
|
|
289
156
|
return Object.keys(e.properties).filter((e) => !t.includes(e));
|
|
290
157
|
}
|
|
291
158
|
//#endregion
|
|
292
159
|
//#region src/utils/operations.ts
|
|
293
|
-
function
|
|
160
|
+
function ve(e, t) {
|
|
294
161
|
return e.operation.operationId && t.operation.operationId ? e.operation.operationId.localeCompare(t.operation.operationId) : e.path && t.path ? e.path.localeCompare(t.path) : e.method && t.method ? e.method.localeCompare(t.method) : 0;
|
|
295
162
|
}
|
|
296
|
-
function
|
|
163
|
+
function M(e) {
|
|
297
164
|
let t = [];
|
|
298
|
-
for (let [n, r] of Object.entries(e))
|
|
165
|
+
for (let [n, r] of Object.entries(e)) N(r).forEach((e) => {
|
|
299
166
|
t.push({
|
|
300
167
|
method: e.method,
|
|
301
168
|
operation: e.operation,
|
|
302
169
|
path: n
|
|
303
170
|
});
|
|
304
171
|
});
|
|
305
|
-
return t.sort(
|
|
172
|
+
return t.sort(ve);
|
|
306
173
|
}
|
|
307
|
-
function
|
|
174
|
+
function N(e) {
|
|
308
175
|
return [
|
|
309
176
|
{
|
|
310
177
|
method: "get",
|
|
@@ -340,28 +207,28 @@ function j(e) {
|
|
|
340
207
|
}
|
|
341
208
|
].filter(({ operation: e }) => e !== void 0);
|
|
342
209
|
}
|
|
343
|
-
function
|
|
210
|
+
function P(e) {
|
|
344
211
|
return e.responses[200];
|
|
345
212
|
}
|
|
346
|
-
function
|
|
347
|
-
return
|
|
213
|
+
function F(e) {
|
|
214
|
+
return ae(P(e));
|
|
348
215
|
}
|
|
349
|
-
function
|
|
350
|
-
return e.parameters ? e.parameters.map((e) => x(e) ?
|
|
216
|
+
function ye(e, t) {
|
|
217
|
+
return e.parameters ? e.parameters.map((e) => x(e) ? te(e, t) : e).filter((e) => e.in === "path") : [];
|
|
351
218
|
}
|
|
352
|
-
var
|
|
353
|
-
function
|
|
354
|
-
return !e.schema || x(e.schema) || !e.schema.type || !
|
|
219
|
+
var be = "string";
|
|
220
|
+
function I(e) {
|
|
221
|
+
return !e.schema || x(e.schema) || !e.schema.type || !C(e.schema.type) ? be : j(e.schema.type);
|
|
355
222
|
}
|
|
356
223
|
//#endregion
|
|
357
224
|
//#region src/utils/resources.ts
|
|
358
|
-
function
|
|
359
|
-
return e.startsWith("http://") || e.startsWith("https://") ?
|
|
225
|
+
function L(e) {
|
|
226
|
+
return e.startsWith("http://") || e.startsWith("https://") ? xe(e) : Se(e);
|
|
360
227
|
}
|
|
361
|
-
async function
|
|
228
|
+
async function xe(e) {
|
|
362
229
|
return await (await fetch(e)).text();
|
|
363
230
|
}
|
|
364
|
-
function
|
|
231
|
+
function Se(e) {
|
|
365
232
|
return new Promise((t, n) => {
|
|
366
233
|
o(e, "utf-8", (e, r) => {
|
|
367
234
|
e ? n(e) : t(r);
|
|
@@ -370,124 +237,124 @@ function Oe(e) {
|
|
|
370
237
|
}
|
|
371
238
|
//#endregion
|
|
372
239
|
//#region src/utils/parsers.ts
|
|
373
|
-
async function
|
|
374
|
-
let t = await
|
|
375
|
-
switch (
|
|
376
|
-
case
|
|
377
|
-
case
|
|
240
|
+
async function Ce(e) {
|
|
241
|
+
let t = await L(e);
|
|
242
|
+
switch (z(t)) {
|
|
243
|
+
case R.JSON: return JSON.parse(t);
|
|
244
|
+
case R.YAML: return a(t);
|
|
378
245
|
default: throw Error(`Unsupported file format: ${e}`);
|
|
379
246
|
}
|
|
380
247
|
}
|
|
381
|
-
async function
|
|
382
|
-
let t = await
|
|
383
|
-
switch (
|
|
384
|
-
case
|
|
385
|
-
case
|
|
248
|
+
async function we(e) {
|
|
249
|
+
let t = await L(e);
|
|
250
|
+
switch (z(t)) {
|
|
251
|
+
case R.JSON: return JSON.parse(t);
|
|
252
|
+
case R.YAML: return a(t);
|
|
386
253
|
default: throw Error(`Unsupported file format: ${e}`);
|
|
387
254
|
}
|
|
388
255
|
}
|
|
389
|
-
var
|
|
256
|
+
var R = /* @__PURE__ */ function(e) {
|
|
390
257
|
return e.JSON = "json", e.YAML = "yaml", e;
|
|
391
258
|
}({});
|
|
392
|
-
function
|
|
259
|
+
function z(e) {
|
|
393
260
|
let t = e.trimStart();
|
|
394
|
-
if (t.startsWith("{") || t.startsWith("[")) return
|
|
395
|
-
if (t.startsWith("-") || t.startsWith("%YAML")) return
|
|
261
|
+
if (t.startsWith("{") || t.startsWith("[")) return R.JSON;
|
|
262
|
+
if (t.startsWith("-") || t.startsWith("%YAML")) return R.YAML;
|
|
396
263
|
try {
|
|
397
|
-
return JSON.parse(t),
|
|
264
|
+
return JSON.parse(t), R.JSON;
|
|
398
265
|
} catch {
|
|
399
|
-
if (t.length > 0) return
|
|
266
|
+
if (t.length > 0) return R.YAML;
|
|
400
267
|
}
|
|
401
268
|
throw Error("Unable to infer file format");
|
|
402
269
|
}
|
|
403
270
|
//#endregion
|
|
404
271
|
//#region src/utils/sourceFiles.ts
|
|
405
|
-
var
|
|
406
|
-
function
|
|
407
|
-
return i(e.path,
|
|
272
|
+
var B = "types.ts", Te = "@";
|
|
273
|
+
function Ee(e) {
|
|
274
|
+
return i(e.path, B);
|
|
408
275
|
}
|
|
409
|
-
function
|
|
276
|
+
function V(e, t, n) {
|
|
410
277
|
let r = i(t, n);
|
|
411
278
|
return e.getSourceFile(r) || e.createSourceFile(r, "", { overwrite: !0 });
|
|
412
279
|
}
|
|
413
|
-
function
|
|
280
|
+
function H(e, t, n) {
|
|
414
281
|
let r = e.getImportDeclaration((e) => e.getModuleSpecifierValue() === t);
|
|
415
282
|
r ||= e.addImportDeclaration({ moduleSpecifier: t }), n.forEach((e) => {
|
|
416
283
|
r.getNamedImports().some((t) => t.getName() === e) || r.addNamedImport(e);
|
|
417
284
|
});
|
|
418
285
|
}
|
|
419
|
-
function
|
|
420
|
-
if (n.path.startsWith(
|
|
421
|
-
|
|
286
|
+
function U(e, t, n) {
|
|
287
|
+
if (n.path.startsWith(Te)) {
|
|
288
|
+
H(e, n.path, [n.name]);
|
|
422
289
|
return;
|
|
423
290
|
}
|
|
424
|
-
let r = c(e.getDirectoryPath(), s(t, n.path,
|
|
425
|
-
r = r.replace(/\.ts$/, ""), r = r.split(
|
|
291
|
+
let r = c(e.getDirectoryPath(), s(t, n.path, B));
|
|
292
|
+
r = r.replace(/\.ts$/, ""), r = r.split(ee).join("/"), r.startsWith(".") || (r = "./" + r), H(e, r, [n.name]);
|
|
426
293
|
}
|
|
427
|
-
function
|
|
428
|
-
e.path !== r.path &&
|
|
294
|
+
function De(e, t, n, r) {
|
|
295
|
+
e.path !== r.path && U(t, n, r);
|
|
429
296
|
}
|
|
430
|
-
function
|
|
297
|
+
function Oe(e, t = "\n") {
|
|
431
298
|
if (!Array.isArray(e)) return;
|
|
432
299
|
let n = e.filter((e) => typeof e == "string" && e.length > 0);
|
|
433
300
|
return n.length > 0 ? n.join(t) : void 0;
|
|
434
301
|
}
|
|
435
|
-
function
|
|
436
|
-
let n =
|
|
302
|
+
function W(e, t) {
|
|
303
|
+
let n = Oe(t);
|
|
437
304
|
n && e.addJsDoc(n);
|
|
438
305
|
}
|
|
439
|
-
function
|
|
306
|
+
function G(e, t) {
|
|
440
307
|
let n = [e.title, e.description];
|
|
441
|
-
return t && n.push(`- key: ${t}`), e.format && n.push(`- format: ${e.format}`),
|
|
308
|
+
return t && n.push(`- key: ${t}`), e.format && n.push(`- format: ${e.format}`), je(n, e, "default"), je(n, e, "example"), Ne(n, e), Pe(n, e), Fe(n, e), n;
|
|
442
309
|
}
|
|
443
|
-
function
|
|
444
|
-
|
|
310
|
+
function ke(e, t, n) {
|
|
311
|
+
W(e, G(t, n));
|
|
445
312
|
}
|
|
446
|
-
function
|
|
447
|
-
let r =
|
|
448
|
-
|
|
313
|
+
function Ae(e, t, n) {
|
|
314
|
+
let r = G(t, n);
|
|
315
|
+
Me(r, "schema", t), W(e, r);
|
|
449
316
|
}
|
|
450
|
-
function
|
|
317
|
+
function je(e, t, n) {
|
|
451
318
|
let r = t[n];
|
|
452
319
|
if (r) {
|
|
453
320
|
if (typeof r != "object") {
|
|
454
321
|
e.push(`- ${n}: \`${r}\``);
|
|
455
322
|
return;
|
|
456
323
|
}
|
|
457
|
-
|
|
324
|
+
Me(e, n, r);
|
|
458
325
|
}
|
|
459
326
|
}
|
|
460
|
-
function
|
|
327
|
+
function Me(e, t, n) {
|
|
461
328
|
e.push(`- ${t}: `), e.push("```json"), e.push(JSON.stringify(n, null, 2)), e.push("```");
|
|
462
329
|
}
|
|
463
|
-
function
|
|
330
|
+
function Ne(e, t) {
|
|
464
331
|
let n = ["- Numeric Constraints"];
|
|
465
332
|
t.minimum !== void 0 && n.push(` - minimum: ${t.minimum}`), t.maximum !== void 0 && n.push(` - maximum: ${t.maximum}`), t.exclusiveMinimum !== void 0 && n.push(` - exclusiveMinimum: ${t.exclusiveMinimum}`), t.exclusiveMaximum !== void 0 && n.push(` - exclusiveMaximum: ${t.exclusiveMaximum}`), t.multipleOf !== void 0 && n.push(` - multipleOf: ${t.multipleOf}`), n.length !== 1 && e.push(...n);
|
|
466
333
|
}
|
|
467
|
-
function
|
|
334
|
+
function Pe(e, t) {
|
|
468
335
|
let n = ["- String Constraints"];
|
|
469
336
|
t.minLength !== void 0 && n.push(` - minLength: ${t.minLength}`), t.maxLength !== void 0 && n.push(` - maxLength: ${t.maxLength}`), t.pattern !== void 0 && n.push(` - pattern: ${t.pattern}`), n.length !== 1 && e.push(...n);
|
|
470
337
|
}
|
|
471
|
-
function
|
|
338
|
+
function Fe(e, t) {
|
|
472
339
|
let n = ["- Array Constraints"];
|
|
473
340
|
t.minItems !== void 0 && n.push(` - minItems: ${t.minItems}`), t.maxItems !== void 0 && n.push(` - maxItems: ${t.maxItems}`), t.uniqueItems !== void 0 && n.push(` - uniqueItems: ${t.uniqueItems}`), n.length !== 1 && e.push(...n);
|
|
474
341
|
}
|
|
475
342
|
//#endregion
|
|
476
343
|
//#region src/aggregate/utils.ts
|
|
477
|
-
function
|
|
344
|
+
function Ie(e) {
|
|
478
345
|
let t = e.split(".");
|
|
479
346
|
return t.length != 2 || t[0].length === 0 || t[1].length === 0 ? null : t;
|
|
480
347
|
}
|
|
481
|
-
function
|
|
482
|
-
let t =
|
|
348
|
+
function Le(e) {
|
|
349
|
+
let t = Ie(e.name);
|
|
483
350
|
return t ? {
|
|
484
351
|
tag: e,
|
|
485
352
|
contextAlias: t[0],
|
|
486
353
|
aggregateName: t[1]
|
|
487
354
|
} : null;
|
|
488
355
|
}
|
|
489
|
-
function
|
|
490
|
-
let t = e?.map((e) =>
|
|
356
|
+
function Re(e) {
|
|
357
|
+
let t = e?.map((e) => Le(e)).filter((e) => e !== null);
|
|
491
358
|
if (!t) return /* @__PURE__ */ new Map();
|
|
492
359
|
let n = /* @__PURE__ */ new Map();
|
|
493
360
|
return t.forEach((e) => {
|
|
@@ -498,20 +365,20 @@ function We(e) {
|
|
|
498
365
|
});
|
|
499
366
|
}), n;
|
|
500
367
|
}
|
|
501
|
-
function
|
|
368
|
+
function ze(e) {
|
|
502
369
|
if (!e) return null;
|
|
503
370
|
let t = e.split(".");
|
|
504
371
|
return t.length == 3 ? t[2] : null;
|
|
505
372
|
}
|
|
506
373
|
//#endregion
|
|
507
374
|
//#region src/aggregate/aggregateResolver.ts
|
|
508
|
-
var
|
|
375
|
+
var Be = "#/components/responses/wow.CommandOk", Ve = "#/components/parameters/wow.id", He = class {
|
|
509
376
|
aggregates;
|
|
510
377
|
constructor(e) {
|
|
511
|
-
this.openAPI = e, this.aggregates =
|
|
378
|
+
this.openAPI = e, this.aggregates = Re(e.tags), this.build();
|
|
512
379
|
}
|
|
513
380
|
build() {
|
|
514
|
-
let e =
|
|
381
|
+
let e = M(this.openAPI.paths);
|
|
515
382
|
for (let t of e) this.commands(t.path, t), this.state(t.operation), this.events(t.operation), this.fields(t.operation);
|
|
516
383
|
}
|
|
517
384
|
resolve() {
|
|
@@ -526,35 +393,35 @@ var Ke = "#/components/responses/wow.CommandOk", qe = "#/components/parameters/w
|
|
|
526
393
|
commands(e, t) {
|
|
527
394
|
let n = t.operation;
|
|
528
395
|
if (n.operationId === "wow.command.send") return;
|
|
529
|
-
let i =
|
|
396
|
+
let i = ze(n.operationId);
|
|
530
397
|
if (!i) return;
|
|
531
|
-
let a =
|
|
532
|
-
if (!a || !x(a) || a.$ref !==
|
|
533
|
-
let o = n.parameters ?? [], s = o.filter((e) => x(e) && e.$ref ===
|
|
398
|
+
let a = P(n);
|
|
399
|
+
if (!a || !x(a) || a.$ref !== Be || !n.requestBody) return;
|
|
400
|
+
let o = n.parameters ?? [], s = o.filter((e) => x(e) && e.$ref === Ve).at(0), c = o.filter((e) => !x(e) && e.in === "path");
|
|
534
401
|
if (s) {
|
|
535
|
-
let e =
|
|
402
|
+
let e = te(s, this.openAPI.components);
|
|
536
403
|
c.push(e);
|
|
537
404
|
}
|
|
538
|
-
let
|
|
539
|
-
|
|
540
|
-
let
|
|
405
|
+
let ee = n.requestBody.content[r.APPLICATION_JSON].schema, l = m(ee, this.openAPI.components);
|
|
406
|
+
l.schema.title = l.schema.title || n.summary, l.schema.description = l.schema.description || n.description;
|
|
407
|
+
let u = {
|
|
541
408
|
name: i,
|
|
542
409
|
method: t.method,
|
|
543
410
|
path: e,
|
|
544
411
|
pathParameters: c,
|
|
545
412
|
summary: n.summary,
|
|
546
413
|
description: n.description,
|
|
547
|
-
schema:
|
|
414
|
+
schema: l,
|
|
548
415
|
operation: n
|
|
549
416
|
};
|
|
550
417
|
n.tags?.forEach((e) => {
|
|
551
418
|
let t = this.aggregates.get(e);
|
|
552
|
-
t && t.commands.set(i,
|
|
419
|
+
t && t.commands.set(i, u);
|
|
553
420
|
});
|
|
554
421
|
}
|
|
555
422
|
state(e) {
|
|
556
423
|
if (!e.operationId?.endsWith(".snapshot_state.single")) return;
|
|
557
|
-
let t =
|
|
424
|
+
let t = F(e);
|
|
558
425
|
if (!x(t)) return;
|
|
559
426
|
let n = m(t, this.openAPI.components);
|
|
560
427
|
e.tags?.forEach((e) => {
|
|
@@ -564,11 +431,11 @@ var Ke = "#/components/responses/wow.CommandOk", qe = "#/components/parameters/w
|
|
|
564
431
|
}
|
|
565
432
|
events(e) {
|
|
566
433
|
if (!this.openAPI.components || !e.operationId?.endsWith(".event.list_query")) return;
|
|
567
|
-
let t =
|
|
434
|
+
let t = F(e);
|
|
568
435
|
if (x(t)) return;
|
|
569
436
|
let n = t?.items;
|
|
570
437
|
if (!x(n)) return;
|
|
571
|
-
let r =
|
|
438
|
+
let r = f(n, this.openAPI.components).properties.body.items.anyOf.map((e) => {
|
|
572
439
|
let t = e.title, n = e.properties.name.const, r = e.properties.body, i = m(r, this.openAPI.components);
|
|
573
440
|
return i.schema.title = i.schema.title || e.title, {
|
|
574
441
|
title: t,
|
|
@@ -585,13 +452,13 @@ var Ke = "#/components/responses/wow.CommandOk", qe = "#/components/parameters/w
|
|
|
585
452
|
}
|
|
586
453
|
fields(e) {
|
|
587
454
|
if (!this.openAPI.components || !e.operationId?.endsWith(".snapshot.count")) return;
|
|
588
|
-
let t =
|
|
455
|
+
let t = p(e.requestBody, this.openAPI.components).content[r.APPLICATION_JSON].schema, n = f(t, this.openAPI.components).properties?.field, i = m(n, this.openAPI.components);
|
|
589
456
|
e.tags?.forEach((e) => {
|
|
590
457
|
let t = this.aggregates.get(e);
|
|
591
458
|
t && (t.fields = i);
|
|
592
459
|
});
|
|
593
460
|
}
|
|
594
|
-
},
|
|
461
|
+
}, K = "@ahoo-wang/fetcher-wow", Ue = {
|
|
595
462
|
"wow.command.CommandResult": "CommandResult",
|
|
596
463
|
"wow.command.CommandResultArray": "CommandResultArray",
|
|
597
464
|
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
@@ -626,15 +493,15 @@ var Ke = "#/components/responses/wow.CommandOk", qe = "#/components/parameters/w
|
|
|
626
493
|
};
|
|
627
494
|
//#endregion
|
|
628
495
|
//#region src/model/modelInfo.ts
|
|
629
|
-
function
|
|
496
|
+
function q(e) {
|
|
630
497
|
if (!e) return {
|
|
631
498
|
name: "",
|
|
632
499
|
path: "/"
|
|
633
500
|
};
|
|
634
|
-
let t =
|
|
501
|
+
let t = Ue[e];
|
|
635
502
|
if (t) return {
|
|
636
503
|
name: t,
|
|
637
|
-
path:
|
|
504
|
+
path: K
|
|
638
505
|
};
|
|
639
506
|
let n = e.split("."), r = -1;
|
|
640
507
|
for (let e = 0; e < n.length; e++) if (n[e] && /^[A-Z]/.test(n[e])) {
|
|
@@ -647,29 +514,29 @@ function G(e) {
|
|
|
647
514
|
path: a
|
|
648
515
|
};
|
|
649
516
|
}
|
|
650
|
-
function
|
|
651
|
-
return
|
|
517
|
+
function J(e) {
|
|
518
|
+
return q(d(e));
|
|
652
519
|
}
|
|
653
|
-
function
|
|
654
|
-
return `${
|
|
520
|
+
function Y(e) {
|
|
521
|
+
return `${re(e)}_BOUNDED_CONTEXT_ALIAS`;
|
|
655
522
|
}
|
|
656
523
|
//#endregion
|
|
657
524
|
//#region src/model/typeGenerator.ts
|
|
658
|
-
var
|
|
525
|
+
var We = class {
|
|
659
526
|
constructor(e, t, n, r) {
|
|
660
527
|
this.modelInfo = e, this.sourceFile = t, this.keySchema = n, this.outputDir = r;
|
|
661
528
|
}
|
|
662
529
|
generate() {
|
|
663
530
|
let e = this.process();
|
|
664
|
-
e &&
|
|
531
|
+
e && Ae(e, this.keySchema.schema, this.keySchema.key);
|
|
665
532
|
}
|
|
666
533
|
process() {
|
|
667
534
|
let { schema: e } = this.keySchema;
|
|
668
|
-
return
|
|
535
|
+
return w(e) ? this.processEnum(e) : T(e) ? this.processInterface(e) : E(e) ? this.processArray(e) : D(e) ? this.processIntersection(e) : O(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
669
536
|
}
|
|
670
537
|
resolveReference(e) {
|
|
671
|
-
let t =
|
|
672
|
-
return
|
|
538
|
+
let t = J(e);
|
|
539
|
+
return De(this.modelInfo, this.sourceFile, this.outputDir, t), t;
|
|
673
540
|
}
|
|
674
541
|
resolveAdditionalProperties(e) {
|
|
675
542
|
return e.additionalProperties === void 0 || e.additionalProperties === !1 ? "" : e.additionalProperties === !0 ? "[key: string]: any" : `[key: string]: ${this.resolveType(e.additionalProperties)}`;
|
|
@@ -679,7 +546,7 @@ var Xe = class {
|
|
|
679
546
|
return Object.entries(t).map(([e, t]) => {
|
|
680
547
|
let n = this.resolveType(t), r = b(e);
|
|
681
548
|
if (!x(t)) {
|
|
682
|
-
let e =
|
|
549
|
+
let e = Oe(G(t), "\n * ");
|
|
683
550
|
if (e) return `
|
|
684
551
|
/**
|
|
685
552
|
* ${e}
|
|
@@ -692,7 +559,7 @@ var Xe = class {
|
|
|
692
559
|
}
|
|
693
560
|
resolveObjectType(e) {
|
|
694
561
|
let t = [];
|
|
695
|
-
if (
|
|
562
|
+
if (T(e)) {
|
|
696
563
|
let n = this.resolvePropertyDefinitions(e);
|
|
697
564
|
t.push(...n);
|
|
698
565
|
}
|
|
@@ -703,7 +570,7 @@ var Xe = class {
|
|
|
703
570
|
return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.resolveType(e.additionalProperties);
|
|
704
571
|
}
|
|
705
572
|
resolveMapKeyType(e) {
|
|
706
|
-
let t =
|
|
573
|
+
let t = me(e);
|
|
707
574
|
return t ? this.resolveType(t) : "string";
|
|
708
575
|
}
|
|
709
576
|
resolveMapType(e) {
|
|
@@ -711,29 +578,29 @@ var Xe = class {
|
|
|
711
578
|
}
|
|
712
579
|
resolveType(e) {
|
|
713
580
|
if (x(e)) return this.resolveReference(e).name;
|
|
714
|
-
if (
|
|
581
|
+
if (A(e)) return this.resolveMapType(e);
|
|
715
582
|
if (e.const) return `'${e.const}'`;
|
|
716
|
-
if (
|
|
717
|
-
if (
|
|
718
|
-
let t = (e.oneOf || e.anyOf || e.allOf || []).map((e) => this.resolveType(e)), n =
|
|
583
|
+
if (w(e)) return e.enum.map((e) => `\`${e}\``).join(" | ");
|
|
584
|
+
if (O(e)) {
|
|
585
|
+
let t = (e.oneOf || e.anyOf || e.allOf || []).map((e) => this.resolveType(e)), n = D(e) ? " & " : " | ";
|
|
719
586
|
return `(${t.join(n)})`;
|
|
720
587
|
}
|
|
721
|
-
return
|
|
588
|
+
return E(e) ? k(this.resolveType(e.items)) : e.type === "object" ? this.resolveObjectType(e) : e.type ? j(e.type) : "any";
|
|
722
589
|
}
|
|
723
590
|
processEnum(e) {
|
|
724
|
-
let t =
|
|
591
|
+
let t = ue(e);
|
|
725
592
|
return t && this.sourceFile.addEnum({
|
|
726
593
|
name: this.modelInfo.name + "EnumText",
|
|
727
594
|
isExported: !0,
|
|
728
595
|
members: Object.entries(t).map(([e, t]) => ({
|
|
729
|
-
name:
|
|
596
|
+
name: ie(e),
|
|
730
597
|
initializer: `\`${t}\``
|
|
731
598
|
}))
|
|
732
599
|
}), this.sourceFile.addEnum({
|
|
733
600
|
name: this.modelInfo.name,
|
|
734
601
|
isExported: !0,
|
|
735
602
|
members: e.enum.filter((e) => typeof e == "string" && e.length > 0).map((e) => ({
|
|
736
|
-
name:
|
|
603
|
+
name: ie(e),
|
|
737
604
|
initializer: `\`${e}\``
|
|
738
605
|
}))
|
|
739
606
|
});
|
|
@@ -743,8 +610,8 @@ var Xe = class {
|
|
|
743
610
|
a ? a.setType(r) : a = e.addProperty({
|
|
744
611
|
name: i,
|
|
745
612
|
type: r,
|
|
746
|
-
isReadonly:
|
|
747
|
-
}),
|
|
613
|
+
isReadonly: ge(n)
|
|
614
|
+
}), ke(a, n);
|
|
748
615
|
}
|
|
749
616
|
processInterface(e) {
|
|
750
617
|
let t = this.sourceFile.addInterface({
|
|
@@ -785,7 +652,7 @@ var Xe = class {
|
|
|
785
652
|
t.addExtends(n);
|
|
786
653
|
return;
|
|
787
654
|
}
|
|
788
|
-
|
|
655
|
+
T(e) && Object.entries(e.properties).forEach(([e, n]) => {
|
|
789
656
|
this.addPropertyToInterface(t, e, n);
|
|
790
657
|
});
|
|
791
658
|
}), t;
|
|
@@ -797,12 +664,12 @@ var Xe = class {
|
|
|
797
664
|
isExported: !0
|
|
798
665
|
});
|
|
799
666
|
}
|
|
800
|
-
},
|
|
667
|
+
}, Ge = class {
|
|
801
668
|
constructor(e) {
|
|
802
669
|
this.context = e;
|
|
803
670
|
}
|
|
804
671
|
getOrCreateSourceFile(e) {
|
|
805
|
-
let t =
|
|
672
|
+
let t = Ee(e);
|
|
806
673
|
return this.context.getOrCreateSourceFile(t);
|
|
807
674
|
}
|
|
808
675
|
generate() {
|
|
@@ -825,7 +692,7 @@ var Xe = class {
|
|
|
825
692
|
isWowSchema(e, t) {
|
|
826
693
|
if (e !== "wow.api.query.PagedList" && e.startsWith("wow.api.query.") && e.endsWith("PagedList") || e.startsWith("wow.api.query.Operator") && e.endsWith("Map")) return !1;
|
|
827
694
|
if (e.startsWith("wow.") || e.endsWith("AggregatedCondition") || e.endsWith("AggregatedDomainEventStream") || e.endsWith("AggregatedDomainEventStreamPagedList") || e.endsWith("AggregatedDomainEventStreamServerSentEventNonNullData") || e.endsWith("AggregatedListQuery") || e.endsWith("AggregatedPagedQuery") || e.endsWith("AggregatedSingleQuery")) return !0;
|
|
828
|
-
let n =
|
|
695
|
+
let n = q(e);
|
|
829
696
|
return t.has(n.name);
|
|
830
697
|
}
|
|
831
698
|
aggregatedSchemaSuffix = [
|
|
@@ -842,23 +709,23 @@ var Xe = class {
|
|
|
842
709
|
for (let [t, n] of this.context.contextAggregates) {
|
|
843
710
|
this.generateBoundedContext(t);
|
|
844
711
|
for (let t of n) this.aggregatedSchemaSuffix.forEach((n) => {
|
|
845
|
-
let r = v(
|
|
712
|
+
let r = v(q(t.state.key).name) + n;
|
|
846
713
|
e.add(r);
|
|
847
714
|
});
|
|
848
715
|
}
|
|
849
716
|
return e;
|
|
850
717
|
}
|
|
851
718
|
generateKeyedSchema(e) {
|
|
852
|
-
let t =
|
|
853
|
-
new
|
|
719
|
+
let t = q(e.key);
|
|
720
|
+
new We(t, this.getOrCreateSourceFile(t), e, this.context.outputDir).generate();
|
|
854
721
|
}
|
|
855
722
|
generateBoundedContext(e) {
|
|
856
723
|
let t = `${e}/boundedContext.ts`;
|
|
857
724
|
this.context.logger.info(`Creating bounded context file: ${t}`);
|
|
858
|
-
let n = this.context.getOrCreateSourceFile(t), r =
|
|
725
|
+
let n = this.context.getOrCreateSourceFile(t), r = Y(e);
|
|
859
726
|
n.addStatements(`export const ${r} = '${e}';`);
|
|
860
727
|
}
|
|
861
|
-
},
|
|
728
|
+
}, Ke = "@ahoo-wang/fetcher", qe = ["ResultExtractors"], Je = "@ahoo-wang/fetcher-decorator", Ye = [
|
|
862
729
|
"type ApiMetadata",
|
|
863
730
|
"type ApiMetadataCapable",
|
|
864
731
|
"type ParameterRequest",
|
|
@@ -872,20 +739,20 @@ var Xe = class {
|
|
|
872
739
|
"attribute",
|
|
873
740
|
"path",
|
|
874
741
|
"autoGeneratedError"
|
|
875
|
-
],
|
|
742
|
+
], Xe = {
|
|
876
743
|
type: "Promise<Response>",
|
|
877
744
|
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
878
|
-
},
|
|
745
|
+
}, Ze = {
|
|
879
746
|
type: "Promise<string>",
|
|
880
747
|
metadata: "{resultExtractor: ResultExtractors.Text }"
|
|
881
|
-
},
|
|
882
|
-
function
|
|
883
|
-
|
|
748
|
+
}, X = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}";
|
|
749
|
+
function Qe(e) {
|
|
750
|
+
H(e, Ke, qe);
|
|
884
751
|
}
|
|
885
|
-
function
|
|
886
|
-
|
|
752
|
+
function $e(e) {
|
|
753
|
+
H(e, Je, Ye);
|
|
887
754
|
}
|
|
888
|
-
function
|
|
755
|
+
function Z(e, t, n = [], r = [], i) {
|
|
889
756
|
return t.addClass({
|
|
890
757
|
name: e,
|
|
891
758
|
isExported: !0,
|
|
@@ -897,7 +764,7 @@ function Y(e, t, n = [], r = [], i) {
|
|
|
897
764
|
}]
|
|
898
765
|
});
|
|
899
766
|
}
|
|
900
|
-
function
|
|
767
|
+
function et(e, n) {
|
|
901
768
|
e.addImplements("ApiMetadataCapable"), e.addConstructor({ parameters: [{
|
|
902
769
|
name: "apiMetadata",
|
|
903
770
|
type: "ApiMetadata",
|
|
@@ -907,30 +774,30 @@ function ot(e, n) {
|
|
|
907
774
|
initializer: n
|
|
908
775
|
}] });
|
|
909
776
|
}
|
|
910
|
-
var
|
|
911
|
-
function
|
|
912
|
-
|
|
777
|
+
var tt = "@ahoo-wang/fetcher-eventstream";
|
|
778
|
+
function nt(e) {
|
|
779
|
+
H(e, tt, ["JsonEventStreamResultExtractor", "type JsonServerSentEventStream"]);
|
|
913
780
|
}
|
|
914
781
|
//#endregion
|
|
915
782
|
//#region src/client/utils.ts
|
|
916
|
-
function
|
|
783
|
+
function rt(e) {
|
|
917
784
|
let t = 0, n = 0;
|
|
918
785
|
return e.commands.forEach((e) => {
|
|
919
|
-
e.path.startsWith(
|
|
786
|
+
e.path.startsWith(l.TENANT) && (t += 1), e.path.startsWith(l.OWNER) && (n += 1);
|
|
920
787
|
}), t === 0 && n === 0 ? "ResourceAttributionPathSpec.NONE" : t > n ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
921
788
|
}
|
|
922
|
-
function
|
|
923
|
-
return
|
|
789
|
+
function it(e, t, n, r) {
|
|
790
|
+
return V(e, t, `${n.contextAlias}/${n.aggregateName}/${r}.ts`);
|
|
924
791
|
}
|
|
925
|
-
function
|
|
792
|
+
function Q(e, t) {
|
|
926
793
|
return `${v(e.aggregateName)}${t}`;
|
|
927
794
|
}
|
|
928
|
-
function
|
|
795
|
+
function $(e) {
|
|
929
796
|
return e === "delete" ? "del" : e;
|
|
930
797
|
}
|
|
931
|
-
var
|
|
932
|
-
function
|
|
933
|
-
let n = e[
|
|
798
|
+
var at = "x-fetcher-method";
|
|
799
|
+
function ot(e, t) {
|
|
800
|
+
let n = e[at];
|
|
934
801
|
if (n) return n;
|
|
935
802
|
if (!e.operationId) return;
|
|
936
803
|
let r = h(e.operationId);
|
|
@@ -942,12 +809,12 @@ function dt(e, t) {
|
|
|
942
809
|
}
|
|
943
810
|
//#endregion
|
|
944
811
|
//#region src/client/apiClientGenerator.ts
|
|
945
|
-
var
|
|
812
|
+
var st = class {
|
|
946
813
|
defaultParameterRequestType = "ParameterRequest";
|
|
947
|
-
defaultReturnType =
|
|
814
|
+
defaultReturnType = Xe;
|
|
948
815
|
apiMetadataCtorInitializer;
|
|
949
816
|
constructor(e) {
|
|
950
|
-
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${
|
|
817
|
+
this.context = e, this.apiMetadataCtorInitializer = this.context.currentContextAlias ? `{basePath:${Y(this.context.currentContextAlias)}}` : void 0;
|
|
951
818
|
}
|
|
952
819
|
generate() {
|
|
953
820
|
this.context.logger.info("Starting API client generation");
|
|
@@ -970,30 +837,30 @@ var ft = class {
|
|
|
970
837
|
return this.context.currentContextAlias && (t = i(this.context.currentContextAlias, t)), t = i(t, `${e.name}ApiClient.ts`), this.context.logger.info(`Creating API client file: ${t}`), this.context.getOrCreateSourceFile(t);
|
|
971
838
|
}
|
|
972
839
|
generateApiClient(e, t) {
|
|
973
|
-
let n =
|
|
840
|
+
let n = q(e.name);
|
|
974
841
|
this.context.logger.info(`Generating API client class: ${n.name}ApiClient with ${t.size} operations`);
|
|
975
842
|
let r = this.createApiClientFile(n);
|
|
976
|
-
|
|
977
|
-
let i =
|
|
978
|
-
|
|
843
|
+
Qe(r), $e(r), nt(r);
|
|
844
|
+
let i = Z(n.name + "ApiClient", r);
|
|
845
|
+
W(i, [e.description]), et(i, this.apiMetadataCtorInitializer), this.context.logger.info(`Processing ${t.size} operations for ${n.name}ApiClient`), t.forEach((t) => {
|
|
979
846
|
this.processOperation(e, r, i, t);
|
|
980
847
|
}), this.context.logger.success(`Completed API client: ${n.name}ApiClient`);
|
|
981
848
|
}
|
|
982
849
|
getMethodName(e, t) {
|
|
983
|
-
let n =
|
|
850
|
+
let n = ot(t, (t) => e.getMethod(t) !== void 0);
|
|
984
851
|
if (!n) throw Error(`Unable to resolve method name for apiClientClass:${e.getName()}.`);
|
|
985
852
|
return n;
|
|
986
853
|
}
|
|
987
854
|
resolveRequestType(e, t) {
|
|
988
855
|
if (!t.requestBody) return this.context.logger.info(`No request body found for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`), this.defaultParameterRequestType;
|
|
989
856
|
let n;
|
|
990
|
-
if (x(t.requestBody) ? (this.context.logger.info(`Extracting request body from reference for operation: ${t.operationId}`), n =
|
|
857
|
+
if (x(t.requestBody) ? (this.context.logger.info(`Extracting request body from reference for operation: ${t.operationId}`), n = p(t.requestBody, this.context.openAPI.components)) : n = t.requestBody, !n) return this.context.logger.info(`Request body extraction failed for operation ${t.operationId}, using default: ${this.defaultParameterRequestType}`), this.defaultParameterRequestType;
|
|
991
858
|
if (n.content["multipart/form-data"]) return this.context.logger.info(`Detected multipart/form-data content for operation ${t.operationId}, using ParameterRequest<FormData>`), "ParameterRequest<FormData>";
|
|
992
859
|
if (n.content["application/json"]) {
|
|
993
860
|
let r = n.content["application/json"].schema;
|
|
994
861
|
if (x(r)) {
|
|
995
|
-
let n =
|
|
996
|
-
this.context.logger.info(`Adding import for request body model: ${n.name} from ${n.path}`),
|
|
862
|
+
let n = J(r);
|
|
863
|
+
this.context.logger.info(`Adding import for request body model: ${n.name} from ${n.path}`), U(e, this.context.outputDir, n);
|
|
997
864
|
let i = `ParameterRequest<${n.name}>`;
|
|
998
865
|
return this.context.logger.info(`Resolved request type for operation ${t.operationId}: ${i}`), i;
|
|
999
866
|
}
|
|
@@ -1001,10 +868,10 @@ var ft = class {
|
|
|
1001
868
|
return this.context.logger.info(`Using default request type for operation ${t.operationId}: ${this.defaultParameterRequestType}`), this.defaultParameterRequestType;
|
|
1002
869
|
}
|
|
1003
870
|
resolveParameters(e, t, n) {
|
|
1004
|
-
let r =
|
|
871
|
+
let r = ye(n, this.context.openAPI.components).filter((t) => !this.context.isIgnoreApiClientPathParameters(e.name, t.name));
|
|
1005
872
|
this.context.logger.info(`Found ${r.length} path parameters for operation ${n.operationId}`);
|
|
1006
873
|
let i = r.map((e) => {
|
|
1007
|
-
let t =
|
|
874
|
+
let t = I(e);
|
|
1008
875
|
return this.context.logger.info(`Adding path parameter: ${e.name} (type: ${t})`), {
|
|
1009
876
|
name: e.name,
|
|
1010
877
|
type: t,
|
|
@@ -1035,48 +902,48 @@ var ft = class {
|
|
|
1035
902
|
}
|
|
1036
903
|
resolveType(e, t) {
|
|
1037
904
|
if (x(t)) {
|
|
1038
|
-
let n =
|
|
1039
|
-
return
|
|
905
|
+
let n = J(t);
|
|
906
|
+
return U(e, this.context.outputDir, n), n.name;
|
|
1040
907
|
}
|
|
1041
|
-
if (
|
|
1042
|
-
if (
|
|
908
|
+
if (E(t)) return k(this.resolveType(e, t.items));
|
|
909
|
+
if (A(t)) {
|
|
1043
910
|
let n = t.additionalProperties;
|
|
1044
911
|
return typeof n == "boolean" ? "Record<string, any>" : `Record<string, ${this.resolveType(e, n)}>`;
|
|
1045
912
|
}
|
|
1046
|
-
return t.type &&
|
|
913
|
+
return t.type && C(t.type) ? j(t.type) : "any";
|
|
1047
914
|
}
|
|
1048
915
|
resolveSchemaReturnType(e, t) {
|
|
1049
916
|
return `Promise<${this.resolveType(e, t)}>`;
|
|
1050
917
|
}
|
|
1051
918
|
resolveReturnType(e, t) {
|
|
1052
|
-
let n =
|
|
919
|
+
let n = P(t);
|
|
1053
920
|
if (!n) return this.context.logger.info(`No OK response found for operation ${t.operationId}, using default return type: ${this.defaultReturnType.type}`), this.defaultReturnType;
|
|
1054
|
-
let r =
|
|
921
|
+
let r = ae(n) || se(n);
|
|
1055
922
|
if (r) {
|
|
1056
923
|
let n = this.resolveSchemaReturnType(e, r);
|
|
1057
924
|
return this.context.logger.info(`Resolved JSON/wildcard response return type for operation ${t.operationId}: ${n}`), {
|
|
1058
925
|
type: n,
|
|
1059
|
-
metadata: n ===
|
|
926
|
+
metadata: n === Ze.type ? Ze.metadata : void 0
|
|
1060
927
|
};
|
|
1061
928
|
}
|
|
1062
|
-
let i =
|
|
929
|
+
let i = oe(n);
|
|
1063
930
|
if (i) {
|
|
1064
931
|
if (x(i)) {
|
|
1065
|
-
let n =
|
|
1066
|
-
if (
|
|
1067
|
-
let r =
|
|
1068
|
-
this.context.logger.info(`Adding import for event stream model: ${r.name} from ${r.path}`),
|
|
932
|
+
let n = f(i, this.context.openAPI.components);
|
|
933
|
+
if (E(n) && x(n.items)) {
|
|
934
|
+
let r = J(n.items);
|
|
935
|
+
this.context.logger.info(`Adding import for event stream model: ${r.name} from ${r.path}`), U(e, this.context.outputDir, r);
|
|
1069
936
|
let i = `Promise<JsonServerSentEventStream<${r.name.includes("ServerSentEvent") ? `${r.name}['data']` : r.name}>>`;
|
|
1070
937
|
return this.context.logger.info(`Resolved event stream return type for operation ${t.operationId}: ${i}`), {
|
|
1071
938
|
type: i,
|
|
1072
|
-
metadata:
|
|
939
|
+
metadata: X
|
|
1073
940
|
};
|
|
1074
941
|
}
|
|
1075
942
|
}
|
|
1076
943
|
let n = "Promise<JsonServerSentEventStream<any>>";
|
|
1077
944
|
return this.context.logger.info(`Resolved generic event stream return type for operation ${t.operationId}: ${n}`), {
|
|
1078
945
|
type: n,
|
|
1079
|
-
metadata:
|
|
946
|
+
metadata: X
|
|
1080
947
|
};
|
|
1081
948
|
}
|
|
1082
949
|
return this.context.logger.info(`Using default return type for operation ${t.operationId}: ${this.defaultReturnType.type}`), this.defaultReturnType;
|
|
@@ -1086,13 +953,13 @@ var ft = class {
|
|
|
1086
953
|
let i = this.getMethodName(n, r.operation);
|
|
1087
954
|
this.context.logger.info(`Generated method name: ${i}`);
|
|
1088
955
|
let a = this.resolveParameters(e, t, r.operation), o = this.resolveReturnType(t, r.operation), s = o.metadata ? {
|
|
1089
|
-
name:
|
|
956
|
+
name: $(r.method),
|
|
1090
957
|
arguments: [`'${r.path}'`, o.metadata]
|
|
1091
958
|
} : {
|
|
1092
|
-
name:
|
|
959
|
+
name: $(r.method),
|
|
1093
960
|
arguments: [`'${r.path}'`]
|
|
1094
961
|
};
|
|
1095
|
-
this.context.logger.info(`Creating method with ${a.length} parameters, return type: ${o.type}`),
|
|
962
|
+
this.context.logger.info(`Creating method with ${a.length} parameters, return type: ${o.type}`), W(n.addMethod({
|
|
1096
963
|
name: i,
|
|
1097
964
|
decorators: [s],
|
|
1098
965
|
parameters: a,
|
|
@@ -1107,7 +974,7 @@ var ft = class {
|
|
|
1107
974
|
}
|
|
1108
975
|
groupOperations(e) {
|
|
1109
976
|
this.context.logger.info("Grouping operations by API client tags");
|
|
1110
|
-
let t = /* @__PURE__ */ new Map(), n =
|
|
977
|
+
let t = /* @__PURE__ */ new Map(), n = M(this.context.openAPI.paths).filter((t) => {
|
|
1111
978
|
if (!t.operation.operationId) return !1;
|
|
1112
979
|
let n = t.operation.tags;
|
|
1113
980
|
return !n || n.length == 0 ? !1 : n.every((t) => e.has(t));
|
|
@@ -1123,7 +990,7 @@ var ft = class {
|
|
|
1123
990
|
resolveApiTags() {
|
|
1124
991
|
this.context.logger.info("Resolving API client tags from OpenAPI specification");
|
|
1125
992
|
let e = /* @__PURE__ */ new Map(), t = this.context.openAPI.tags?.length || 0;
|
|
1126
|
-
for (let t of Object.values(this.context.openAPI.paths))
|
|
993
|
+
for (let t of Object.values(this.context.openAPI.paths)) N(t).forEach((t) => {
|
|
1127
994
|
t.operation.tags?.forEach((t) => {
|
|
1128
995
|
!this.shouldIgnoreTag(t) && !e.has(t) && e.set(t, {
|
|
1129
996
|
name: t,
|
|
@@ -1140,7 +1007,7 @@ var ft = class {
|
|
|
1140
1007
|
for (let t of this.context.contextAggregates.values()) for (let n of t) if (n.aggregate.tag.name === e) return !0;
|
|
1141
1008
|
return !1;
|
|
1142
1009
|
}
|
|
1143
|
-
},
|
|
1010
|
+
}, ct = class {
|
|
1144
1011
|
commandEndpointPathsSuffix = "CommandEndpointPaths";
|
|
1145
1012
|
defaultCommandClientOptionsName = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
1146
1013
|
constructor(e) {
|
|
@@ -1157,7 +1024,7 @@ var ft = class {
|
|
|
1157
1024
|
}
|
|
1158
1025
|
processAggregate(e) {
|
|
1159
1026
|
this.context.logger.info(`Processing command client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`);
|
|
1160
|
-
let t =
|
|
1027
|
+
let t = it(this.context.project, this.context.outputDir, e.aggregate, "commandClient");
|
|
1161
1028
|
this.context.logger.info(`Processing command endpoint paths for ${e.commands.size} commands`);
|
|
1162
1029
|
let r = this.processCommandEndpointPaths(t, e);
|
|
1163
1030
|
this.processCommandTypes(t, e), this.context.logger.info(`Creating default command client options: ${this.defaultCommandClientOptionsName}`), t.addVariableStatement({
|
|
@@ -1166,12 +1033,12 @@ var ft = class {
|
|
|
1166
1033
|
name: this.defaultCommandClientOptionsName,
|
|
1167
1034
|
type: "ApiMetadata",
|
|
1168
1035
|
initializer: `{
|
|
1169
|
-
basePath: ${
|
|
1036
|
+
basePath: ${Y(e.aggregate.contextAlias)}
|
|
1170
1037
|
}`
|
|
1171
1038
|
}],
|
|
1172
1039
|
isExported: !1
|
|
1173
|
-
}), this.context.logger.info(`Adding imports from ${
|
|
1174
|
-
moduleSpecifier:
|
|
1040
|
+
}), this.context.logger.info(`Adding imports from ${K}: CommandRequest, CommandResult, CommandResultEventStream, CommandBody, DeleteAggregateCommand, RecoverAggregateCommand`), t.addImportDeclaration({
|
|
1041
|
+
moduleSpecifier: K,
|
|
1175
1042
|
namedImports: [
|
|
1176
1043
|
"CommandRequest",
|
|
1177
1044
|
"CommandResult",
|
|
@@ -1181,10 +1048,10 @@ var ft = class {
|
|
|
1181
1048
|
"RecoverAggregateCommand"
|
|
1182
1049
|
],
|
|
1183
1050
|
isTypeOnly: !0
|
|
1184
|
-
}), this.context.logger.info("Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"),
|
|
1051
|
+
}), this.context.logger.info("Adding import from @ahoo-wang/fetcher-eventstream: JsonEventStreamResultExtractor"), nt(t), this.context.logger.info("Adding import from @ahoo-wang/fetcher: ContentTypeValues"), H(t, "@ahoo-wang/fetcher", ["ContentTypeValues"]), this.context.logger.info("Adding imports from @ahoo-wang/fetcher-decorator: ApiMetadata types and decorators"), $e(t), this.context.logger.info("Generating standard command client class"), this.processCommandClient(t, e, r), this.context.logger.info("Generating stream command client class"), this.processStreamCommandClient(t, e), this.context.logger.success(`Command client generation completed for aggregate: ${e.aggregate.aggregateName}`);
|
|
1185
1052
|
}
|
|
1186
1053
|
resolveAggregateCommandEndpointPathsName(e) {
|
|
1187
|
-
return
|
|
1054
|
+
return Q(e, this.commandEndpointPathsSuffix);
|
|
1188
1055
|
}
|
|
1189
1056
|
processCommandEndpointPaths(e, t) {
|
|
1190
1057
|
let n = this.resolveAggregateCommandEndpointPathsName(t.aggregate);
|
|
@@ -1201,14 +1068,14 @@ var ft = class {
|
|
|
1201
1068
|
}), this.context.logger.success(`Command endpoint paths enum created with ${t.commands.size} entries`), n;
|
|
1202
1069
|
}
|
|
1203
1070
|
resolveCommandTypeName(e) {
|
|
1204
|
-
let t =
|
|
1071
|
+
let t = q(e.schema.key);
|
|
1205
1072
|
return [t, t.name + "Command"];
|
|
1206
1073
|
}
|
|
1207
1074
|
resolveCommandType(e, t) {
|
|
1208
1075
|
let [n, r] = this.resolveCommandTypeName(t);
|
|
1209
1076
|
if (n.path === "@ahoo-wang/fetcher-wow") return;
|
|
1210
|
-
|
|
1211
|
-
let i = `${n.name}`, a =
|
|
1077
|
+
U(e, this.context.outputDir, n);
|
|
1078
|
+
let i = `${n.name}`, a = _e(t.schema.schema).map((e) => `'${e}'`).join(" | ");
|
|
1212
1079
|
a !== "" && (i = `PartialBy<${i},${a}>`), i = `CommandBody<${i}>`, e.addTypeAlias({
|
|
1213
1080
|
name: r,
|
|
1214
1081
|
type: `${i}`,
|
|
@@ -1224,14 +1091,14 @@ var ft = class {
|
|
|
1224
1091
|
return `${e}.${t.name.toUpperCase()}`;
|
|
1225
1092
|
}
|
|
1226
1093
|
processCommandClient(e, t, n) {
|
|
1227
|
-
let r =
|
|
1228
|
-
|
|
1094
|
+
let r = Z(Q(t.aggregate, "CommandClient"), e, [], ["R = CommandResult"]);
|
|
1095
|
+
et(r, this.defaultCommandClientOptionsName), t.commands.forEach((e) => {
|
|
1229
1096
|
this.processCommandMethod(t, r, e, n);
|
|
1230
1097
|
});
|
|
1231
1098
|
}
|
|
1232
1099
|
processStreamCommandClient(e, t) {
|
|
1233
|
-
let n =
|
|
1234
|
-
|
|
1100
|
+
let n = Q(t.aggregate, "CommandClient");
|
|
1101
|
+
Z(Q(t.aggregate, "StreamCommandClient"), e, ["''", X], [], `${n}<CommandResultEventStream>`).addConstructor({
|
|
1235
1102
|
parameters: [{
|
|
1236
1103
|
name: "apiMetadata",
|
|
1237
1104
|
type: "ApiMetadata",
|
|
@@ -1244,7 +1111,7 @@ var ft = class {
|
|
|
1244
1111
|
let [n, r] = this.resolveCommandTypeName(t);
|
|
1245
1112
|
this.context.logger.info(`Adding import for command model: ${n.name} from path: ${n.path}`);
|
|
1246
1113
|
let i = t.pathParameters.filter((t) => !this.context.isIgnoreCommandClientPathParameters(e.name, t.name)).map((e) => {
|
|
1247
|
-
let t =
|
|
1114
|
+
let t = I(e);
|
|
1248
1115
|
return this.context.logger.info(`Adding path parameter: ${e.name} (type: ${t})`), {
|
|
1249
1116
|
name: e.name,
|
|
1250
1117
|
type: t,
|
|
@@ -1257,7 +1124,7 @@ var ft = class {
|
|
|
1257
1124
|
});
|
|
1258
1125
|
return this.context.logger.info(`Adding command request parameter: commandRequest (type: CommandRequest<${r}>)`), i.push({
|
|
1259
1126
|
name: "commandRequest",
|
|
1260
|
-
hasQuestionToken:
|
|
1127
|
+
hasQuestionToken: he(t.schema.schema),
|
|
1261
1128
|
type: `CommandRequest<${r}>`,
|
|
1262
1129
|
decorators: [{
|
|
1263
1130
|
name: "request",
|
|
@@ -1278,21 +1145,21 @@ var ft = class {
|
|
|
1278
1145
|
let i = this.resolveParameters(e.aggregate.tag, n), a = t.addMethod({
|
|
1279
1146
|
name: y(n.name),
|
|
1280
1147
|
decorators: [{
|
|
1281
|
-
name:
|
|
1148
|
+
name: $(n.method),
|
|
1282
1149
|
arguments: [`${this.getEndpointPath(r, n)}`]
|
|
1283
1150
|
}],
|
|
1284
1151
|
parameters: i,
|
|
1285
1152
|
returnType: "Promise<R>",
|
|
1286
1153
|
statements: `throw autoGeneratedError(${i.map((e) => e.name).join(",")});`
|
|
1287
1154
|
});
|
|
1288
|
-
this.context.logger.info(`Adding JSDoc documentation for method: ${y(n.name)}`),
|
|
1155
|
+
this.context.logger.info(`Adding JSDoc documentation for method: ${y(n.name)}`), W(a, [
|
|
1289
1156
|
n.summary,
|
|
1290
1157
|
n.description,
|
|
1291
1158
|
`- operationId: \`${n.operation.operationId}\``,
|
|
1292
1159
|
`- path: \`${n.path}\``
|
|
1293
1160
|
]), this.context.logger.success(`Command method generated: ${y(n.name)}`);
|
|
1294
1161
|
}
|
|
1295
|
-
},
|
|
1162
|
+
}, lt = class {
|
|
1296
1163
|
domainEventTypeSuffix = "DomainEventType";
|
|
1297
1164
|
domainEventTypeMapTitleSuffix = "DomainEventTypeMapTitle";
|
|
1298
1165
|
constructor(e) {
|
|
@@ -1308,12 +1175,12 @@ var ft = class {
|
|
|
1308
1175
|
this.context.logger.success("Query client generation completed");
|
|
1309
1176
|
}
|
|
1310
1177
|
createClientFilePath(e, t) {
|
|
1311
|
-
return
|
|
1178
|
+
return it(this.context.project, this.context.outputDir, e, t);
|
|
1312
1179
|
}
|
|
1313
1180
|
processQueryClient(e) {
|
|
1314
1181
|
let t = this.createClientFilePath(e.aggregate, "queryClient");
|
|
1315
|
-
this.context.logger.info(`Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`), this.context.logger.info(`Adding imports from ${
|
|
1316
|
-
moduleSpecifier:
|
|
1182
|
+
this.context.logger.info(`Processing query client for aggregate: ${e.aggregate.aggregateName} in context: ${e.aggregate.contextAlias}`), this.context.logger.info(`Adding imports from ${K}: QueryClientFactory, QueryClientOptions, ResourceAttributionPathSpec`), t.addImportDeclaration({
|
|
1183
|
+
moduleSpecifier: K,
|
|
1317
1184
|
namedImports: [
|
|
1318
1185
|
"QueryClientFactory",
|
|
1319
1186
|
"QueryClientOptions",
|
|
@@ -1327,15 +1194,15 @@ var ft = class {
|
|
|
1327
1194
|
name: r,
|
|
1328
1195
|
type: "QueryClientOptions",
|
|
1329
1196
|
initializer: `{
|
|
1330
|
-
contextAlias: ${
|
|
1197
|
+
contextAlias: ${Y(e.aggregate.contextAlias)},
|
|
1331
1198
|
aggregateName: '${e.aggregate.aggregateName}',
|
|
1332
|
-
resourceAttribution: ${
|
|
1199
|
+
resourceAttribution: ${rt(e)},
|
|
1333
1200
|
}`
|
|
1334
1201
|
}],
|
|
1335
1202
|
isExported: !1
|
|
1336
1203
|
}), this.processAggregateDomainEventTypes(e, t);
|
|
1337
|
-
let i = this.processAggregateDomainEventType(e, t), a = `${y(e.aggregate.aggregateName)}QueryClientFactory`, o =
|
|
1338
|
-
this.context.logger.info(`Adding import for state model: ${o.name} from path: ${o.path}`),
|
|
1204
|
+
let i = this.processAggregateDomainEventType(e, t), a = `${y(e.aggregate.aggregateName)}QueryClientFactory`, o = q(e.state.key), s = q(e.fields.key);
|
|
1205
|
+
this.context.logger.info(`Adding import for state model: ${o.name} from path: ${o.path}`), U(t, this.context.outputDir, o), this.context.logger.info(`Adding import for fields model: ${s.name} from path: ${s.path}`), U(t, this.context.outputDir, s), this.context.logger.info(`Creating query client factory: ${a}`), t.addVariableStatement({
|
|
1339
1206
|
declarationKind: n.Const,
|
|
1340
1207
|
declarations: [{
|
|
1341
1208
|
name: a,
|
|
@@ -1348,10 +1215,10 @@ var ft = class {
|
|
|
1348
1215
|
let n = [];
|
|
1349
1216
|
this.context.logger.info(`Processing ${e.events.size} domain events for aggregate: ${e.aggregate.aggregateName}`);
|
|
1350
1217
|
for (let r of e.events.values()) {
|
|
1351
|
-
let e =
|
|
1352
|
-
this.context.logger.info(`Adding import for event model: ${e.name} from path: ${e.path}`),
|
|
1218
|
+
let e = q(r.schema.key);
|
|
1219
|
+
this.context.logger.info(`Adding import for event model: ${e.name} from path: ${e.path}`), U(t, this.context.outputDir, e), n.push(e);
|
|
1353
1220
|
}
|
|
1354
|
-
let r =
|
|
1221
|
+
let r = Q(e.aggregate, this.domainEventTypeSuffix), i = n.map((e) => e.name).join(" | ");
|
|
1355
1222
|
return this.context.logger.info(`Creating domain event types union: ${r} = ${i}`), t.addTypeAlias({
|
|
1356
1223
|
isExported: !0,
|
|
1357
1224
|
name: r,
|
|
@@ -1359,7 +1226,7 @@ var ft = class {
|
|
|
1359
1226
|
}), r;
|
|
1360
1227
|
}
|
|
1361
1228
|
processAggregateDomainEventTypes(e, t) {
|
|
1362
|
-
let n =
|
|
1229
|
+
let n = Q(e.aggregate, this.domainEventTypeMapTitleSuffix), r = t.addEnum({
|
|
1363
1230
|
name: n,
|
|
1364
1231
|
isExported: !0
|
|
1365
1232
|
});
|
|
@@ -1368,12 +1235,12 @@ var ft = class {
|
|
|
1368
1235
|
initializer: `'${t.title}'`
|
|
1369
1236
|
});
|
|
1370
1237
|
}
|
|
1371
|
-
},
|
|
1238
|
+
}, ut = class {
|
|
1372
1239
|
queryClientGenerator;
|
|
1373
1240
|
commandClientGenerator;
|
|
1374
1241
|
apiClientGenerator;
|
|
1375
1242
|
constructor(e) {
|
|
1376
|
-
this.context = e, this.queryClientGenerator = new
|
|
1243
|
+
this.context = e, this.queryClientGenerator = new lt(e), this.commandClientGenerator = new ct(e), this.apiClientGenerator = new st(e);
|
|
1377
1244
|
}
|
|
1378
1245
|
generate() {
|
|
1379
1246
|
this.context.logger.info("--- Generating Clients ---"), this.context.logger.progress(`Generating clients for ${this.context.contextAggregates.size} bounded contexts`);
|
|
@@ -1381,7 +1248,7 @@ var ft = class {
|
|
|
1381
1248
|
for (let [t] of this.context.contextAggregates) e++, this.context.logger.progressWithCount(e, this.context.contextAggregates.size, `Processing bounded context: ${t}`, 1);
|
|
1382
1249
|
this.queryClientGenerator.generate(), this.commandClientGenerator.generate(), this.apiClientGenerator.generate(), this.context.logger.success("Client generation completed");
|
|
1383
1250
|
}
|
|
1384
|
-
},
|
|
1251
|
+
}, dt = class {
|
|
1385
1252
|
project;
|
|
1386
1253
|
openAPI;
|
|
1387
1254
|
outputDir;
|
|
@@ -1394,7 +1261,7 @@ var ft = class {
|
|
|
1394
1261
|
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"];
|
|
1395
1262
|
}
|
|
1396
1263
|
getOrCreateSourceFile(e) {
|
|
1397
|
-
return
|
|
1264
|
+
return V(this.project, this.outputDir, e);
|
|
1398
1265
|
}
|
|
1399
1266
|
isIgnoreApiClientPathParameters(e, t) {
|
|
1400
1267
|
return (this.config.apiClients?.[e]?.ignorePathParameters ?? this.defaultIgnorePathParameters).includes(t);
|
|
@@ -1402,7 +1269,7 @@ var ft = class {
|
|
|
1402
1269
|
isIgnoreCommandClientPathParameters(e, t) {
|
|
1403
1270
|
return this.defaultIgnorePathParameters.includes(t);
|
|
1404
1271
|
}
|
|
1405
|
-
},
|
|
1272
|
+
}, ft = "./fetcher-generator.config.json", pt = class {
|
|
1406
1273
|
project;
|
|
1407
1274
|
constructor(t) {
|
|
1408
1275
|
this.options = t, this.project = new e(t), this.options.logger.info(`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`);
|
|
@@ -1411,17 +1278,17 @@ var ft = class {
|
|
|
1411
1278
|
this.options.logger.info("Starting code generation from OpenAPI specification");
|
|
1412
1279
|
let e = process.cwd();
|
|
1413
1280
|
this.options.logger.info(`Work directory: ${e}`), 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");
|
|
1414
|
-
let t = await
|
|
1281
|
+
let t = await Ce(this.options.inputPath);
|
|
1415
1282
|
this.options.logger.info("OpenAPI specification parsed successfully"), this.options.logger.info("Resolving bounded context aggregates");
|
|
1416
|
-
let n = new
|
|
1283
|
+
let n = new He(t).resolve();
|
|
1417
1284
|
this.options.logger.info(`Resolved ${n.size} bounded context aggregates`);
|
|
1418
1285
|
let r = this.options.configPath ?? "./fetcher-generator.config.json", i = {};
|
|
1419
1286
|
try {
|
|
1420
|
-
this.options.logger.info(`Parsing configuration file: ${r}`), i = await
|
|
1287
|
+
this.options.logger.info(`Parsing configuration file: ${r}`), i = await we(r);
|
|
1421
1288
|
} catch (e) {
|
|
1422
1289
|
this.options.logger.info(`Configuration file parsing failed: ${e}`);
|
|
1423
1290
|
}
|
|
1424
|
-
let a = new
|
|
1291
|
+
let a = new dt({
|
|
1425
1292
|
openAPI: t,
|
|
1426
1293
|
project: this.project,
|
|
1427
1294
|
outputDir: this.options.outputDir,
|
|
@@ -1429,7 +1296,7 @@ var ft = class {
|
|
|
1429
1296
|
logger: this.options.logger,
|
|
1430
1297
|
config: i
|
|
1431
1298
|
});
|
|
1432
|
-
this.options.logger.info("Generating models"), new
|
|
1299
|
+
this.options.logger.info("Generating models"), new Ge(a).generate(), this.options.logger.info("Models generated successfully"), this.options.logger.info("Generating clients"), new ut(a).generate(), this.options.logger.info("Clients generated successfully");
|
|
1433
1300
|
let o = this.project.getDirectory(this.options.outputDir);
|
|
1434
1301
|
if (!o) {
|
|
1435
1302
|
this.options.logger.info("Output directory not found.");
|
|
@@ -1481,6 +1348,6 @@ var ft = class {
|
|
|
1481
1348
|
}
|
|
1482
1349
|
};
|
|
1483
1350
|
//#endregion
|
|
1484
|
-
export {
|
|
1351
|
+
export { ft as n, pt as t };
|
|
1485
1352
|
|
|
1486
|
-
//# sourceMappingURL=src-
|
|
1353
|
+
//# sourceMappingURL=src-Drc8UO0Q.js.map
|