@ahoo-wang/wow-generator 9.2.0-rc.0
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/LICENSE +201 -0
- package/README.md +177 -0
- package/README.zh-CN.md +149 -0
- package/dist/analysis/aggregates.d.cts +21 -0
- package/dist/analysis/aggregates.d.ts +21 -0
- package/dist/analysis/analyze.d.cts +18 -0
- package/dist/analysis/analyze.d.ts +18 -0
- package/dist/analysis/apiClients.d.cts +14 -0
- package/dist/analysis/apiClients.d.ts +14 -0
- package/dist/analysis/clientNames.d.cts +55 -0
- package/dist/analysis/clientNames.d.ts +55 -0
- package/dist/analysis/model.d.cts +212 -0
- package/dist/analysis/model.d.ts +212 -0
- package/dist/analysis/modelInfo.d.cts +23 -0
- package/dist/analysis/modelInfo.d.ts +23 -0
- package/dist/analysis/models.d.cts +17 -0
- package/dist/analysis/models.d.ts +17 -0
- package/dist/api/configuration.d.cts +30 -0
- package/dist/api/configuration.d.ts +30 -0
- package/dist/api/errors.d.cts +41 -0
- package/dist/api/errors.d.ts +41 -0
- package/dist/api/logger.d.cts +61 -0
- package/dist/api/logger.d.ts +61 -0
- package/dist/api/options.d.cts +47 -0
- package/dist/api/options.d.ts +47 -0
- package/dist/cli/program.d.cts +35 -0
- package/dist/cli/program.d.ts +35 -0
- package/dist/cli/runGenerate.d.cts +65 -0
- package/dist/cli/runGenerate.d.ts +65 -0
- package/dist/cli.cjs +3 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +6 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +98 -0
- package/dist/cli.js.map +1 -0
- package/dist/codeGenerator-DpDTDC4o.cjs +23 -0
- package/dist/codeGenerator-DpDTDC4o.cjs.map +1 -0
- package/dist/codeGenerator-kyY9eLML.js +2583 -0
- package/dist/codeGenerator-kyY9eLML.js.map +1 -0
- package/dist/emit/importRegistry.d.cts +50 -0
- package/dist/emit/importRegistry.d.ts +50 -0
- package/dist/emit/imports.d.cts +49 -0
- package/dist/emit/imports.d.ts +49 -0
- package/dist/emit/jsdoc.d.cts +38 -0
- package/dist/emit/jsdoc.d.ts +38 -0
- package/dist/emit/moduleBuilder.d.cts +80 -0
- package/dist/emit/moduleBuilder.d.ts +80 -0
- package/dist/emitters/apiClients.d.cts +10 -0
- package/dist/emitters/apiClients.d.ts +10 -0
- package/dist/emitters/commandClients.d.cts +14 -0
- package/dist/emitters/commandClients.d.ts +14 -0
- package/dist/emitters/decorators.d.cts +83 -0
- package/dist/emitters/decorators.d.ts +83 -0
- package/dist/emitters/emit.d.cts +15 -0
- package/dist/emitters/emit.d.ts +15 -0
- package/dist/emitters/indexFiles.d.cts +12 -0
- package/dist/emitters/indexFiles.d.ts +12 -0
- package/dist/emitters/models.d.cts +77 -0
- package/dist/emitters/models.d.ts +77 -0
- package/dist/emitters/queryClients.d.cts +11 -0
- package/dist/emitters/queryClients.d.ts +11 -0
- package/dist/emitters/target.d.cts +14 -0
- package/dist/emitters/target.d.ts +14 -0
- package/dist/finalize/finalize.d.cts +16 -0
- package/dist/finalize/finalize.d.ts +16 -0
- package/dist/finalize/typeOnlyImports.d.cts +13 -0
- package/dist/finalize/typeOnlyImports.d.ts +13 -0
- package/dist/finalize/verification.d.cts +14 -0
- package/dist/finalize/verification.d.ts +14 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2 -0
- package/dist/input/configuration.d.cts +87 -0
- package/dist/input/configuration.d.ts +87 -0
- package/dist/input/parsers.d.cts +39 -0
- package/dist/input/parsers.d.ts +39 -0
- package/dist/input/resources.d.cts +36 -0
- package/dist/input/resources.d.ts +36 -0
- package/dist/naming/modelInfo.d.cts +10 -0
- package/dist/naming/modelInfo.d.ts +10 -0
- package/dist/naming/naming.d.cts +102 -0
- package/dist/naming/naming.d.ts +102 -0
- package/dist/naming/order.d.cts +2 -0
- package/dist/naming/order.d.ts +2 -0
- package/dist/naming/paths.d.cts +27 -0
- package/dist/naming/paths.d.ts +27 -0
- package/dist/openapi/components.d.cts +55 -0
- package/dist/openapi/components.d.ts +55 -0
- package/dist/openapi/document.d.cts +25 -0
- package/dist/openapi/document.d.ts +25 -0
- package/dist/openapi/operations.d.cts +78 -0
- package/dist/openapi/operations.d.ts +78 -0
- package/dist/openapi/references.d.cts +28 -0
- package/dist/openapi/references.d.ts +28 -0
- package/dist/openapi/responses.d.cts +44 -0
- package/dist/openapi/responses.d.ts +44 -0
- package/dist/openapi/schemas.d.cts +112 -0
- package/dist/openapi/schemas.d.ts +112 -0
- package/dist/output/outputStore.d.cts +92 -0
- package/dist/output/outputStore.d.ts +92 -0
- package/dist/pipeline/codeGenerator.d.cts +61 -0
- package/dist/pipeline/codeGenerator.d.ts +61 -0
- package/dist/pipeline/seams.d.cts +29 -0
- package/dist/pipeline/seams.d.ts +29 -0
- package/dist/types/typeResolver.d.cts +124 -0
- package/dist/types/typeResolver.d.ts +124 -0
- package/dist/version.d.cts +2 -0
- package/dist/version.d.ts +2 -0
- package/dist/wow/conventions.d.cts +154 -0
- package/dist/wow/conventions.d.ts +154 -0
- package/dist/wow/model.d.cts +116 -0
- package/dist/wow/model.d.ts +116 -0
- package/dist/wow/resolveWowModel.d.cts +21 -0
- package/dist/wow/resolveWowModel.d.ts +21 -0
- package/package.json +108 -0
|
@@ -0,0 +1,2583 @@
|
|
|
1
|
+
import { CodeBlockWriter as e, IndentationText as t, Node as n, Project as r, QuoteKind as i, Scope as a, StructureKind as o, SyntaxKind as s, VariableDeclarationKind as c, ts as l } from "ts-morph";
|
|
2
|
+
import { isAbsolute as u, join as d, relative as f, resolve as p, sep as m } from "path";
|
|
3
|
+
import { parse as ee } from "yaml";
|
|
4
|
+
import { readFile as te } from "fs";
|
|
5
|
+
//#region src/api/configuration.ts
|
|
6
|
+
var h = "./wow-generator.config.json", ne = {
|
|
7
|
+
success: 0,
|
|
8
|
+
internal: 1,
|
|
9
|
+
input: 2,
|
|
10
|
+
configuration: 3,
|
|
11
|
+
specification: 4,
|
|
12
|
+
output: 5,
|
|
13
|
+
interrupted: 130
|
|
14
|
+
}, g = class extends Error {
|
|
15
|
+
kind;
|
|
16
|
+
constructor(e, t, n) {
|
|
17
|
+
super(t, n), this.kind = e, this.name = "GeneratorError";
|
|
18
|
+
}
|
|
19
|
+
get exitCode() {
|
|
20
|
+
return ne[this.kind];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
function _(e) {
|
|
24
|
+
return e instanceof Error ? e.message : String(e);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/api/logger.ts
|
|
28
|
+
function re() {
|
|
29
|
+
return !!process.stdout?.isTTY && !process.env.NO_COLOR;
|
|
30
|
+
}
|
|
31
|
+
var ie = class {
|
|
32
|
+
level;
|
|
33
|
+
decorate;
|
|
34
|
+
constructor(e = {}) {
|
|
35
|
+
this.level = e.level ?? "normal", this.decorate = e.decorate ?? re();
|
|
36
|
+
}
|
|
37
|
+
format(e, t, n) {
|
|
38
|
+
let r = this.decorate ? `${e} ` : t ? `${t}: ` : "";
|
|
39
|
+
return `${this.level === "verbose" ? `[${(/* @__PURE__ */ new Date()).toTimeString().slice(0, 8)}] ` : ""}${r}${n}`;
|
|
40
|
+
}
|
|
41
|
+
debug(e, ...t) {
|
|
42
|
+
this.level === "verbose" && console.log(this.format("ℹ️ ", "", e), ...t);
|
|
43
|
+
}
|
|
44
|
+
info(e, ...t) {
|
|
45
|
+
this.level !== "quiet" && console.log(this.format("✅", "", e), ...t);
|
|
46
|
+
}
|
|
47
|
+
warn(e, ...t) {
|
|
48
|
+
console.warn(this.format("⚠️ ", "warning", e), ...t);
|
|
49
|
+
}
|
|
50
|
+
error(e, ...t) {
|
|
51
|
+
console.error(this.format("❌", "error", e), ...t);
|
|
52
|
+
}
|
|
53
|
+
}, ae = class {
|
|
54
|
+
debug() {}
|
|
55
|
+
info() {}
|
|
56
|
+
warn() {}
|
|
57
|
+
error() {}
|
|
58
|
+
}, oe = /[^\p{L}\p{N}$]+/u, se = /* @__PURE__ */ new Set(/* @__PURE__ */ "arguments.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.eval.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield".split("."));
|
|
59
|
+
function v(e) {
|
|
60
|
+
return /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u.test(e) && !se.has(e);
|
|
61
|
+
}
|
|
62
|
+
function ce(e) {
|
|
63
|
+
return /^\p{N}/u.test(e) ? `_${e}` : e;
|
|
64
|
+
}
|
|
65
|
+
function le(e) {
|
|
66
|
+
if (v(e)) return e;
|
|
67
|
+
let t = ce(y(e) || "_");
|
|
68
|
+
return se.has(t) ? `${t}_` : t;
|
|
69
|
+
}
|
|
70
|
+
function ue(e) {
|
|
71
|
+
return /^\p{Lu}[\p{L}\p{N}$]*$/u.test(e) && v(e);
|
|
72
|
+
}
|
|
73
|
+
function de(e) {
|
|
74
|
+
return ce((Array.isArray(e) ? e : [e]).map((e) => ue(e) ? e : he(e)).join("") || "_");
|
|
75
|
+
}
|
|
76
|
+
function fe(e) {
|
|
77
|
+
return e.split(oe);
|
|
78
|
+
}
|
|
79
|
+
function pe(e) {
|
|
80
|
+
return Array.isArray(e) ? e.flatMap((e) => me(fe(e))) : me(fe(e));
|
|
81
|
+
}
|
|
82
|
+
function me(e) {
|
|
83
|
+
return e.flatMap((e) => {
|
|
84
|
+
if (e.length === 0) return [];
|
|
85
|
+
let t = [], n = "";
|
|
86
|
+
for (let r = 0; r < e.length; r++) {
|
|
87
|
+
let i = e[r], a = /[A-Z]/.test(i), o = r > 0 && /[a-z]/.test(e[r - 1]);
|
|
88
|
+
a && o && n ? (t.push(n), n = i) : n += i;
|
|
89
|
+
}
|
|
90
|
+
return n && t.push(n), t;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function he(e) {
|
|
94
|
+
return e === "" || e.length === 0 ? "" : pe(e).filter((e) => e.length > 0).map((e) => {
|
|
95
|
+
let t = e.charAt(0), n = e.slice(1);
|
|
96
|
+
return (/[a-zA-Z]/.test(t) ? t.toUpperCase() : t) + n.toLowerCase();
|
|
97
|
+
}).join("");
|
|
98
|
+
}
|
|
99
|
+
function y(e) {
|
|
100
|
+
let t = he(e);
|
|
101
|
+
return t.charAt(0).toLowerCase() + t.slice(1);
|
|
102
|
+
}
|
|
103
|
+
function ge(e) {
|
|
104
|
+
return e === "" || Array.isArray(e) && e.length === 0 ? "" : pe(e).filter((e) => e.length > 0).map((e) => e.toUpperCase()).join("_");
|
|
105
|
+
}
|
|
106
|
+
function b(e) {
|
|
107
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e) ? e : x(e);
|
|
108
|
+
}
|
|
109
|
+
function _e(e) {
|
|
110
|
+
return /^\d+$/.test(e) ? `NUM_${e}` : ge(e) || e;
|
|
111
|
+
}
|
|
112
|
+
function x(e) {
|
|
113
|
+
return `'${JSON.stringify(e).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/naming/order.ts
|
|
117
|
+
var ve = new Intl.Collator("en-US");
|
|
118
|
+
function S(e, t) {
|
|
119
|
+
return ve.compare(e, t);
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/openapi/references.ts
|
|
123
|
+
function C(e) {
|
|
124
|
+
return !!(e && typeof e == "object" && "$ref" in e);
|
|
125
|
+
}
|
|
126
|
+
function ye(e, t) {
|
|
127
|
+
let n = t.slice(1);
|
|
128
|
+
try {
|
|
129
|
+
n = decodeURIComponent(n);
|
|
130
|
+
} catch {}
|
|
131
|
+
if (n === "") return e;
|
|
132
|
+
let r = e;
|
|
133
|
+
for (let e of n.slice(1).split("/")) {
|
|
134
|
+
if (typeof r != "object" || !r) return;
|
|
135
|
+
let t = e.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
136
|
+
if (!Object.hasOwn(r, t)) return;
|
|
137
|
+
r = r[t];
|
|
138
|
+
}
|
|
139
|
+
return r;
|
|
140
|
+
}
|
|
141
|
+
function be(e) {
|
|
142
|
+
let t = [], n = /* @__PURE__ */ new Set(), r = (i, a) => {
|
|
143
|
+
if (typeof i != "object" || !i || n.has(i)) return;
|
|
144
|
+
if (n.add(i), Array.isArray(i)) {
|
|
145
|
+
i.forEach((e, t) => r(e, `${a}/${t}`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
let o = i.$ref;
|
|
149
|
+
typeof o == "string" && o.startsWith("#/components/") && ye(e, o) === void 0 && t.push({
|
|
150
|
+
ref: o,
|
|
151
|
+
location: a || "/"
|
|
152
|
+
});
|
|
153
|
+
for (let [e, t] of Object.entries(i)) r(t, `${a}/${e.replace(/~/g, "~0").replace(/\//g, "~1")}`);
|
|
154
|
+
};
|
|
155
|
+
return r(e, ""), t;
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/openapi/components.ts
|
|
159
|
+
var w = "#/components/", xe = `${w}parameters/`, Se = `${w}requestBodies/`, T = `${w}responses/`, Ce = `${w}schemas/`;
|
|
160
|
+
function we(e) {
|
|
161
|
+
return e.$ref.split("/").pop();
|
|
162
|
+
}
|
|
163
|
+
function E(e, t, n) {
|
|
164
|
+
let r = /* @__PURE__ */ new Set(), i = e;
|
|
165
|
+
for (; C(i);) {
|
|
166
|
+
if (!i.$ref.startsWith(n)) return;
|
|
167
|
+
if (r.has(i.$ref)) throw new g("specification", `Cyclic component reference: ${i.$ref}`);
|
|
168
|
+
r.add(i.$ref), i = t?.[i.$ref.slice(n.length)];
|
|
169
|
+
}
|
|
170
|
+
return i;
|
|
171
|
+
}
|
|
172
|
+
function D(e, t) {
|
|
173
|
+
return E(e, t.schemas, Ce);
|
|
174
|
+
}
|
|
175
|
+
function Te(e, t) {
|
|
176
|
+
return E(e, t.responses, T);
|
|
177
|
+
}
|
|
178
|
+
function Ee(e, t) {
|
|
179
|
+
return E(e, t.requestBodies, Se);
|
|
180
|
+
}
|
|
181
|
+
function De(e, t) {
|
|
182
|
+
return E(e, t.parameters, xe);
|
|
183
|
+
}
|
|
184
|
+
function O(e, t) {
|
|
185
|
+
return {
|
|
186
|
+
key: we(e),
|
|
187
|
+
schema: D(e, t)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/openapi/responses.ts
|
|
192
|
+
var k = "application/json", Oe = "text/event-stream";
|
|
193
|
+
function A(e) {
|
|
194
|
+
return e.split(";")[0].trim().toLowerCase();
|
|
195
|
+
}
|
|
196
|
+
function ke(e) {
|
|
197
|
+
let t = A(e);
|
|
198
|
+
return t === "application/json" || /^application\/[^/]+\+json$/.test(t);
|
|
199
|
+
}
|
|
200
|
+
function Ae(e) {
|
|
201
|
+
let t = A(e);
|
|
202
|
+
return t.startsWith("text/") && t !== "text/event-stream";
|
|
203
|
+
}
|
|
204
|
+
function j(e, t, n = (e) => A(e) === t) {
|
|
205
|
+
if (!e) return;
|
|
206
|
+
if (e[t]) return e[t];
|
|
207
|
+
let r = Object.keys(e).find(n);
|
|
208
|
+
return r === void 0 ? void 0 : e[r];
|
|
209
|
+
}
|
|
210
|
+
function je(e, t) {
|
|
211
|
+
if (t && !C(t)) return j(t.content, e)?.schema;
|
|
212
|
+
}
|
|
213
|
+
function Me(e) {
|
|
214
|
+
if (e && !C(e)) return j(e.content, k, ke)?.schema;
|
|
215
|
+
}
|
|
216
|
+
function Ne(e) {
|
|
217
|
+
return je(Oe, e);
|
|
218
|
+
}
|
|
219
|
+
function Pe(e) {
|
|
220
|
+
return je("*/*", e);
|
|
221
|
+
}
|
|
222
|
+
function Fe(e) {
|
|
223
|
+
return !e || C(e) ? !1 : Object.keys(e.content ?? {}).some(Ae);
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/openapi/schemas.ts
|
|
227
|
+
var Ie = [
|
|
228
|
+
"string",
|
|
229
|
+
"number",
|
|
230
|
+
"integer",
|
|
231
|
+
"boolean",
|
|
232
|
+
"null"
|
|
233
|
+
];
|
|
234
|
+
function Le(e) {
|
|
235
|
+
return Array.isArray(e) ? !0 : Ie.includes(e);
|
|
236
|
+
}
|
|
237
|
+
function M(e) {
|
|
238
|
+
return Array.isArray(e.enum) && e.enum.length > 0;
|
|
239
|
+
}
|
|
240
|
+
var Re = "x-enum-text";
|
|
241
|
+
function ze(e) {
|
|
242
|
+
return e[Re];
|
|
243
|
+
}
|
|
244
|
+
function Be(e) {
|
|
245
|
+
return e.type === "object" && !!e.properties;
|
|
246
|
+
}
|
|
247
|
+
function Ve(e) {
|
|
248
|
+
return e.type === "array" && !!e.items;
|
|
249
|
+
}
|
|
250
|
+
function He(e) {
|
|
251
|
+
return Array.isArray(e.anyOf) && e.anyOf.length > 0;
|
|
252
|
+
}
|
|
253
|
+
function Ue(e) {
|
|
254
|
+
return Array.isArray(e.oneOf) && e.oneOf.length > 0;
|
|
255
|
+
}
|
|
256
|
+
function We(e) {
|
|
257
|
+
return Array.isArray(e.allOf) && e.allOf.length > 0;
|
|
258
|
+
}
|
|
259
|
+
function N(e) {
|
|
260
|
+
return He(e) || Ue(e) || We(e);
|
|
261
|
+
}
|
|
262
|
+
function Ge(e) {
|
|
263
|
+
return e.includes("|") || e.includes("&") ? `(${e})[]` : `${e}[]`;
|
|
264
|
+
}
|
|
265
|
+
function Ke(e) {
|
|
266
|
+
return e.type === "object" && !e.properties && e.additionalProperties !== void 0;
|
|
267
|
+
}
|
|
268
|
+
var qe = "x-map-key-schema";
|
|
269
|
+
function Je(e) {
|
|
270
|
+
return e[qe];
|
|
271
|
+
}
|
|
272
|
+
function Ye(e) {
|
|
273
|
+
return e.type === "object" ? !e.properties || Object.keys(e.properties).length === 0 : !1;
|
|
274
|
+
}
|
|
275
|
+
function Xe(e) {
|
|
276
|
+
return e.readOnly === !0;
|
|
277
|
+
}
|
|
278
|
+
function P(e) {
|
|
279
|
+
if (Array.isArray(e)) return e.map((e) => P(e)).join(" | ");
|
|
280
|
+
switch (e) {
|
|
281
|
+
case "string": return "string";
|
|
282
|
+
case "number":
|
|
283
|
+
case "integer": return "number";
|
|
284
|
+
case "boolean": return "boolean";
|
|
285
|
+
case "null": return "null";
|
|
286
|
+
default: return "any";
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function Ze(e, t) {
|
|
290
|
+
let n = [], r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = !1, o = (e) => {
|
|
291
|
+
if (!(!e || i.has(e) || a)) {
|
|
292
|
+
if (i.add(e), C(e)) {
|
|
293
|
+
o(t && D(e, t));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (e.nullable || Array.isArray(e.type)) {
|
|
297
|
+
a = !0;
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
for (let t of e.required ?? []) r.add(t);
|
|
301
|
+
for (let t of Object.keys(e.properties ?? {})) n.includes(t) || n.push(t);
|
|
302
|
+
e.allOf?.forEach(o);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return o(e), a ? [] : n.filter((e) => !r.has(e));
|
|
306
|
+
}
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/openapi/operations.ts
|
|
309
|
+
function Qe(e, t) {
|
|
310
|
+
return e.operation.operationId && t.operation.operationId ? S(e.operation.operationId, t.operation.operationId) : e.path && t.path ? S(e.path, t.path) : e.method && t.method ? S(e.method, t.method) : 0;
|
|
311
|
+
}
|
|
312
|
+
function $e(e, t, n) {
|
|
313
|
+
let r = /* @__PURE__ */ new Map();
|
|
314
|
+
for (let i of [...e, ...t]) {
|
|
315
|
+
let e = C(i) ? n && De(i, n) : i, t = e ? `${e.in}:${e.name}` : i.$ref;
|
|
316
|
+
r.set(t, i);
|
|
317
|
+
}
|
|
318
|
+
return [...r.values()];
|
|
319
|
+
}
|
|
320
|
+
function et(e, t) {
|
|
321
|
+
let n = [];
|
|
322
|
+
for (let [r, i] of Object.entries(e)) tt(i).forEach((e) => {
|
|
323
|
+
n.push({
|
|
324
|
+
method: e.method,
|
|
325
|
+
operation: i.parameters?.length ? {
|
|
326
|
+
...e.operation,
|
|
327
|
+
parameters: $e(i.parameters, e.operation.parameters ?? [], t)
|
|
328
|
+
} : e.operation,
|
|
329
|
+
path: r
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
return n.sort(Qe);
|
|
333
|
+
}
|
|
334
|
+
function tt(e) {
|
|
335
|
+
return [
|
|
336
|
+
{
|
|
337
|
+
method: "get",
|
|
338
|
+
operation: e.get
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
method: "put",
|
|
342
|
+
operation: e.put
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
method: "post",
|
|
346
|
+
operation: e.post
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
method: "delete",
|
|
350
|
+
operation: e.delete
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
method: "options",
|
|
354
|
+
operation: e.options
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
method: "head",
|
|
358
|
+
operation: e.head
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
method: "patch",
|
|
362
|
+
operation: e.patch
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
method: "trace",
|
|
366
|
+
operation: e.trace
|
|
367
|
+
}
|
|
368
|
+
].filter(({ operation: e }) => e !== void 0);
|
|
369
|
+
}
|
|
370
|
+
function nt(e) {
|
|
371
|
+
let t = Object.keys(e.responses ?? {});
|
|
372
|
+
if (t.includes("200")) return "200";
|
|
373
|
+
let n = t.filter((e) => /^2\d\d$/.test(e)).sort();
|
|
374
|
+
return n.length > 0 ? n[0] : t.find((e) => e.toUpperCase() === "2XX");
|
|
375
|
+
}
|
|
376
|
+
function F(e, t) {
|
|
377
|
+
let n = nt(e), r = n ? e.responses[n] : void 0;
|
|
378
|
+
return t && C(r) ? Te(r, t) : r;
|
|
379
|
+
}
|
|
380
|
+
function rt(e, t) {
|
|
381
|
+
return Me(F(e, t));
|
|
382
|
+
}
|
|
383
|
+
function it(e, t) {
|
|
384
|
+
return (e.parameters ?? []).map((e) => C(e) ? De(e, t) : e).filter((e) => e !== void 0);
|
|
385
|
+
}
|
|
386
|
+
function at(e, t) {
|
|
387
|
+
return e.parameters ? e.parameters.map((e) => C(e) ? De(e, t) : e).filter((e) => e?.in === "path") : [];
|
|
388
|
+
}
|
|
389
|
+
function ot(e, t) {
|
|
390
|
+
let n = (t) => {
|
|
391
|
+
let n = e.indexOf(`{${t.name}}`);
|
|
392
|
+
return n < 0 ? 2 ** 53 - 1 : n;
|
|
393
|
+
};
|
|
394
|
+
return [...t].sort((e, t) => n(e) - n(t));
|
|
395
|
+
}
|
|
396
|
+
var st = "string";
|
|
397
|
+
function ct(e) {
|
|
398
|
+
return !e.schema || C(e.schema) || !e.schema.type || !Le(e.schema.type) ? st : P(e.schema.type);
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/wow/conventions.ts
|
|
402
|
+
var lt = "8.10", ut = "x-wow-context-alias";
|
|
403
|
+
function dt(e) {
|
|
404
|
+
return e.info[ut];
|
|
405
|
+
}
|
|
406
|
+
function ft(e) {
|
|
407
|
+
let t = e.split(".");
|
|
408
|
+
return t.length != 2 || t[0].length === 0 || t[1].length === 0 ? null : t;
|
|
409
|
+
}
|
|
410
|
+
function pt(e) {
|
|
411
|
+
let t = ft(e.name);
|
|
412
|
+
return t ? {
|
|
413
|
+
tag: e,
|
|
414
|
+
contextAlias: t[0],
|
|
415
|
+
aggregateName: t[1]
|
|
416
|
+
} : null;
|
|
417
|
+
}
|
|
418
|
+
function mt(e) {
|
|
419
|
+
if (!e) return null;
|
|
420
|
+
let t = e.split(".");
|
|
421
|
+
return t.length == 3 ? t[2] : null;
|
|
422
|
+
}
|
|
423
|
+
var ht = ".snapshot_state.single", gt = ".snapshot.count", _t = "x-wow-query-fields", vt = /^(?:\/tenant\/\{tenantId\})?(?:\/owner\/\{ownerId\})?\/(.+?)\/snapshot(?:\/|$)/, yt = [
|
|
424
|
+
"MaterializedSnapshot",
|
|
425
|
+
"MaterializedSnapshotPagedList",
|
|
426
|
+
"MaterializedSnapshotCursorPage",
|
|
427
|
+
"MaterializedSnapshotServerSentEventNonNullData",
|
|
428
|
+
"PagedList",
|
|
429
|
+
"ServerSentEventNonNullData",
|
|
430
|
+
"Snapshot",
|
|
431
|
+
"StateEvent"
|
|
432
|
+
];
|
|
433
|
+
function bt(e) {
|
|
434
|
+
return yt.map((t) => e + t);
|
|
435
|
+
}
|
|
436
|
+
function xt(e, t, n) {
|
|
437
|
+
return e !== "wow.api.query.PagedList" && e.startsWith("wow.api.query.") && e.endsWith("PagedList") || e.startsWith("wow.api.query.Operator") && e.endsWith("Map") ? !1 : e.startsWith("wow.") || e.endsWith("AggregatedCondition") || e.endsWith("AggregatedDomainEventStream") || e.endsWith("AggregatedDomainEventStreamPagedList") || e.endsWith("AggregatedDomainEventStreamCursorPage") || e.endsWith("AggregatedDomainEventStreamServerSentEventNonNullData") || e.endsWith("AggregatedListQuery") || e.endsWith("AggregatedPagedQuery") || e.endsWith("AggregatedSingleQuery") ? !0 : n.has(t());
|
|
438
|
+
}
|
|
439
|
+
var I = "@ahoo-wang/wow-client", St = "@ahoo-wang/wow-client/legacy", Ct = /* @__PURE__ */ new Set([
|
|
440
|
+
"Condition",
|
|
441
|
+
"ConditionOptions",
|
|
442
|
+
"ListQuery",
|
|
443
|
+
"Operator",
|
|
444
|
+
"PagedQuery"
|
|
445
|
+
]), wt = {
|
|
446
|
+
"wow.command.CommandResult": "CommandResult",
|
|
447
|
+
"wow.command.CommandResultArray": "CommandResultArray",
|
|
448
|
+
"wow.MessageHeaderSqlType": "MessageHeaderSqlType",
|
|
449
|
+
"wow.api.BindingError": "BindingError",
|
|
450
|
+
"wow.api.DefaultErrorInfo": "ErrorInfo",
|
|
451
|
+
"wow.api.RecoverableType": "RecoverableType",
|
|
452
|
+
"wow.api.command.DefaultDeleteAggregate": "DeleteAggregate",
|
|
453
|
+
"wow.api.command.DefaultRecoverAggregate": "RecoverAggregate",
|
|
454
|
+
"wow.api.abac.DefaultApplyResourceTags": "ApplyResourceTags",
|
|
455
|
+
"wow.api.messaging.FunctionInfoData": "FunctionInfo",
|
|
456
|
+
"wow.api.messaging.FunctionKind": "FunctionKind",
|
|
457
|
+
"wow.api.modeling.AggregateId": "AggregateId",
|
|
458
|
+
"wow.api.query.Condition": "Condition",
|
|
459
|
+
"wow.api.query.ConditionOptions": "ConditionOptions",
|
|
460
|
+
"wow.api.query.ListQuery": "ListQuery",
|
|
461
|
+
"wow.api.query.Operator": "Operator",
|
|
462
|
+
"wow.api.query.PagedQuery": "PagedQuery",
|
|
463
|
+
"wow.api.query.Pagination": "Pagination",
|
|
464
|
+
"wow.api.query.Projection": "Projection",
|
|
465
|
+
"wow.api.query.Sort": "FieldSort",
|
|
466
|
+
"wow.api.query.Sort.Direction": "SortDirection",
|
|
467
|
+
"wow.api.query.DynamicDocument": "DynamicDocument",
|
|
468
|
+
"wow.api.query.DynamicDocumentArray": "DynamicDocumentArray",
|
|
469
|
+
"wow.command.CommandStage": "CommandStage",
|
|
470
|
+
"wow.command.SimpleWaitSignal": "WaitSignal",
|
|
471
|
+
"wow.configuration.Aggregate": "Aggregate",
|
|
472
|
+
"wow.configuration.BoundedContext": "BoundedContext",
|
|
473
|
+
"wow.configuration.WowMetadata": "WowMetadata",
|
|
474
|
+
"wow.modeling.DomainEvent": "DomainEvent",
|
|
475
|
+
"wow.openapi.BatchResult": "BatchResult",
|
|
476
|
+
"wow.messaging.CompensationTarget": "CompensationTarget"
|
|
477
|
+
};
|
|
478
|
+
function Tt(e, t) {
|
|
479
|
+
let n = wt[e];
|
|
480
|
+
if (t && "filter" in t && (e === "wow.api.query.ListQuery" ? n = "FilterListQuery" : e === "wow.api.query.PagedQuery" && (n = "FilterPagedQuery")), n) return {
|
|
481
|
+
name: n,
|
|
482
|
+
path: Ct.has(n) ? St : I
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
var Et = /* @__PURE__ */ new Set(["wow", "Actuator"]), Dt = ["tenantId", "ownerId"];
|
|
486
|
+
function Ot(e) {
|
|
487
|
+
let t = 0, n = 0;
|
|
488
|
+
return e.commands.forEach((e) => {
|
|
489
|
+
e.path.startsWith("/tenant/{tenantId}") && (t += 1), e.path.startsWith("/owner/{ownerId}") && (n += 1);
|
|
490
|
+
}), t === 0 && n === 0 ? "ResourceAttributionPathSpec.NONE" : t > n ? "ResourceAttributionPathSpec.TENANT" : "ResourceAttributionPathSpec.OWNER";
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/analysis/clientNames.ts
|
|
494
|
+
function kt(e, t) {
|
|
495
|
+
return `${e.contextAlias}/${e.aggregateName}/${t}.ts`;
|
|
496
|
+
}
|
|
497
|
+
function L(e, t) {
|
|
498
|
+
return `${de(e.aggregateName)}${t}`;
|
|
499
|
+
}
|
|
500
|
+
var At = "x-fetcher-method";
|
|
501
|
+
function jt(e, t) {
|
|
502
|
+
let n = t ?? e["x-fetcher-method"];
|
|
503
|
+
if (n !== void 0) {
|
|
504
|
+
if (typeof n != "string" || !Mt(n)) throw new g("specification", `${At} of ${e.operationId ?? "an operation"} is ${JSON.stringify(n)}, which is not a valid method name.`);
|
|
505
|
+
return n;
|
|
506
|
+
}
|
|
507
|
+
if (!e.operationId) return;
|
|
508
|
+
let r = y(e.operationId.split(".").pop()) || "_";
|
|
509
|
+
return /^\p{N}/u.test(r) ? `_${r}` : r;
|
|
510
|
+
}
|
|
511
|
+
function Mt(e) {
|
|
512
|
+
return v(e) || /^[a-z]+$/.test(e);
|
|
513
|
+
}
|
|
514
|
+
function Nt(e, t) {
|
|
515
|
+
let n = le(e), r = n;
|
|
516
|
+
for (let e = 2; t.has(r); e++) r = `${n}${e}`;
|
|
517
|
+
return t.add(r), r;
|
|
518
|
+
}
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/analysis/modelInfo.ts
|
|
521
|
+
function R(e, t) {
|
|
522
|
+
if (!e) return {
|
|
523
|
+
name: "",
|
|
524
|
+
path: "/"
|
|
525
|
+
};
|
|
526
|
+
let n = Tt(e, t?.properties);
|
|
527
|
+
if (n) return n;
|
|
528
|
+
let r = e.split("."), i = -1;
|
|
529
|
+
for (let e = 0; e < r.length; e++) if (r[e] && /^[A-Z]/.test(r[e])) {
|
|
530
|
+
i = e;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
let a = r.slice(0, i), o = a.length > 0 ? `/${a.join("/")}` : "/";
|
|
534
|
+
return {
|
|
535
|
+
name: de(r.slice(i)),
|
|
536
|
+
path: o
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
function Pt(e, t) {
|
|
540
|
+
if (!e.$ref.startsWith(Ce)) throw new g("specification", `Unsupported schema reference: ${e.$ref}. Bundle or inline external schemas before generation.`);
|
|
541
|
+
return R(we(e), t ? D(e, t) : void 0);
|
|
542
|
+
}
|
|
543
|
+
function z(e) {
|
|
544
|
+
let t = `${ge(e)}_BOUNDED_CONTEXT_ALIAS`;
|
|
545
|
+
return /^\p{N}/u.test(t) ? `_${t}` : t;
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/analysis/aggregates.ts
|
|
549
|
+
var Ft = "Command";
|
|
550
|
+
function It(e, t) {
|
|
551
|
+
return [...t.contexts.values()].flatMap((t) => [...t].map((t) => Lt(e, t)));
|
|
552
|
+
}
|
|
553
|
+
function Lt(e, t) {
|
|
554
|
+
let { contextAlias: n, aggregateName: r } = t.aggregate;
|
|
555
|
+
return {
|
|
556
|
+
contextAlias: n,
|
|
557
|
+
aggregateName: r,
|
|
558
|
+
context: {
|
|
559
|
+
alias: n,
|
|
560
|
+
constantName: z(n)
|
|
561
|
+
},
|
|
562
|
+
commandClient: Rt(e, t),
|
|
563
|
+
queryClient: Ut(t)
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
function Rt(e, t) {
|
|
567
|
+
let n = t.aggregate, r = Vt(t);
|
|
568
|
+
return {
|
|
569
|
+
file: kt(n, "commandClient"),
|
|
570
|
+
endpointPathsName: L(n, "CommandEndpointPaths"),
|
|
571
|
+
className: L(n, "CommandClient"),
|
|
572
|
+
streamClassName: L(n, "StreamCommandClient"),
|
|
573
|
+
commands: [...t.commands.values()].map((t) => {
|
|
574
|
+
let n = R(t.schema.key), i = /* @__PURE__ */ new Set(["commandRequest", "attributes"]);
|
|
575
|
+
return {
|
|
576
|
+
path: t.path,
|
|
577
|
+
endpointMember: r.get(t),
|
|
578
|
+
httpMethod: t.method,
|
|
579
|
+
methodName: Ht(t),
|
|
580
|
+
typeName: zt(n),
|
|
581
|
+
body: n,
|
|
582
|
+
bodyKey: t.schema.key,
|
|
583
|
+
optionalFields: Ze(t.schema.schema, e.components),
|
|
584
|
+
requestOptional: Ye(t.schema.schema),
|
|
585
|
+
pathParameters: ot(t.path, t.pathParameters).filter((e) => !Dt.includes(e.name)).map((e) => ({
|
|
586
|
+
name: Nt(e.name, i),
|
|
587
|
+
pathName: e.name,
|
|
588
|
+
type: ct(e)
|
|
589
|
+
})),
|
|
590
|
+
docs: [
|
|
591
|
+
t.summary,
|
|
592
|
+
t.description,
|
|
593
|
+
`- operationId: \`${t.operation.operationId}\``,
|
|
594
|
+
`- path: \`${t.path}\``
|
|
595
|
+
]
|
|
596
|
+
};
|
|
597
|
+
})
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function zt(e) {
|
|
601
|
+
return e.path === "@ahoo-wang/wow-client" ? `${e.name}Command` : e.name.endsWith(Ft) ? void 0 : `${e.name}${Ft}`;
|
|
602
|
+
}
|
|
603
|
+
function Bt(e, t) {
|
|
604
|
+
for (let n of e) {
|
|
605
|
+
let e = `/${n.contextAlias}/${n.aggregateName}`, r = /* @__PURE__ */ new Map();
|
|
606
|
+
for (let n of t) n.info.path === e && r.set(n.info.name, {
|
|
607
|
+
holder: `the model of schema ${n.key}`,
|
|
608
|
+
key: n.key
|
|
609
|
+
});
|
|
610
|
+
for (let { body: e, bodyKey: t } of n.commandClient.commands) e.path !== "@ahoo-wang/wow-client" && r.set(e.name, {
|
|
611
|
+
holder: `the model of schema ${t}`,
|
|
612
|
+
key: t
|
|
613
|
+
});
|
|
614
|
+
for (let e of n.commandClient.commands) {
|
|
615
|
+
let { typeName: t, bodyKey: i } = e;
|
|
616
|
+
if (t === void 0 || e.body.path === "@ahoo-wang/wow-client") continue;
|
|
617
|
+
let a = r.get(t);
|
|
618
|
+
if (a !== void 0 && a.bodyKey !== i) throw new g("specification", `Command ${e.methodName}() of aggregate ${n.contextAlias}.${n.aggregateName} generates the type ${t} for its body ${i}, but ${a.holder} already has that name. Rename the schema ${i} or ${a.key} in the document.`);
|
|
619
|
+
r.set(t, {
|
|
620
|
+
holder: `the type of command ${e.methodName}()`,
|
|
621
|
+
key: i,
|
|
622
|
+
bodyKey: i
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
function Vt(e) {
|
|
628
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set();
|
|
629
|
+
for (let r of e.commands.values()) {
|
|
630
|
+
let e = r.name.toUpperCase().replace(/[^\p{L}\p{N}_$]/gu, "_");
|
|
631
|
+
(!e || /^\p{N}/u.test(e)) && (e = `_${e}`);
|
|
632
|
+
let i = e;
|
|
633
|
+
for (let t = 2; n.has(i); t++) i = `${e}_${t}`;
|
|
634
|
+
n.add(i), t.set(r, i);
|
|
635
|
+
}
|
|
636
|
+
return t;
|
|
637
|
+
}
|
|
638
|
+
function Ht(e) {
|
|
639
|
+
let t = y(e.name) || "_";
|
|
640
|
+
return /^\p{N}/u.test(t) ? `_${t}` : t;
|
|
641
|
+
}
|
|
642
|
+
function Ut(e) {
|
|
643
|
+
let t = e.aggregate, n = y(t.aggregateName) || "_";
|
|
644
|
+
return {
|
|
645
|
+
file: kt(t, "queryClient"),
|
|
646
|
+
resourceName: e.resourceName,
|
|
647
|
+
resourceAttribution: Ot(e),
|
|
648
|
+
state: R(e.state.key),
|
|
649
|
+
fields: R(e.fields.key),
|
|
650
|
+
eventTitlesName: L(t, "DomainEventTypeMapTitle"),
|
|
651
|
+
eventTypeName: L(t, "DomainEventType"),
|
|
652
|
+
events: [...e.events.values()].map((e) => ({
|
|
653
|
+
memberName: b(e.name),
|
|
654
|
+
title: e.title,
|
|
655
|
+
body: R(e.schema.key)
|
|
656
|
+
})),
|
|
657
|
+
factoryName: `${/^\p{N}/u.test(n) ? "_" : ""}${n}QueryClientFactory`
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/naming/paths.ts
|
|
662
|
+
function B(e, t) {
|
|
663
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(t) ? t : t ? `${e.replace(/\/+$/, "")}/${t.replace(/^\/+/, "")}` : e;
|
|
664
|
+
}
|
|
665
|
+
var Wt = "types.ts";
|
|
666
|
+
function Gt(e) {
|
|
667
|
+
return B(e.path, Wt);
|
|
668
|
+
}
|
|
669
|
+
function Kt(e) {
|
|
670
|
+
return `${e}/boundedContext.ts`;
|
|
671
|
+
}
|
|
672
|
+
//#endregion
|
|
673
|
+
//#region src/wow/model.ts
|
|
674
|
+
function qt(e) {
|
|
675
|
+
return e.contextAlias !== void 0 || e.aggregateTags.size > 0;
|
|
676
|
+
}
|
|
677
|
+
function Jt(e, t) {
|
|
678
|
+
return t ? {
|
|
679
|
+
...e,
|
|
680
|
+
...t
|
|
681
|
+
} : e;
|
|
682
|
+
}
|
|
683
|
+
//#endregion
|
|
684
|
+
//#region src/analysis/apiClients.ts
|
|
685
|
+
var Yt = ["httpRequest", "attributes"];
|
|
686
|
+
function Xt(e, t, n, r) {
|
|
687
|
+
return new Zt(e, t, n, r).clients();
|
|
688
|
+
}
|
|
689
|
+
var Zt = class {
|
|
690
|
+
document;
|
|
691
|
+
wow;
|
|
692
|
+
config;
|
|
693
|
+
warnings;
|
|
694
|
+
basePath;
|
|
695
|
+
wowDocument;
|
|
696
|
+
constructor(e, t, n, r) {
|
|
697
|
+
this.document = e, this.wow = t, this.config = n, this.warnings = r, this.wowDocument = qt(t), t.contextAlias && (this.basePath = {
|
|
698
|
+
alias: t.contextAlias,
|
|
699
|
+
constantName: z(t.contextAlias)
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
clients() {
|
|
703
|
+
let e = this.tags(), t = this.groupOperations(e), n = /* @__PURE__ */ new Map();
|
|
704
|
+
return [...t.keys()].sort().map((r) => {
|
|
705
|
+
let i = R(r), a = i;
|
|
706
|
+
for (let e = 2; n.has(V(a)); e++) a = {
|
|
707
|
+
...i,
|
|
708
|
+
name: `${i.name}${e}`
|
|
709
|
+
};
|
|
710
|
+
return a !== i && this.warnings.push(`Tags ${n.get(V(i))} and ${r} both name the API client ${i.name}ApiClient; ${r} generates ${a.name}ApiClient.`), n.set(V(a), r), this.client(e.get(r), a, [...t.get(r)]);
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
client(e, t, n) {
|
|
714
|
+
let r = `${t.name}ApiClient`, i = t.path;
|
|
715
|
+
this.wow.contextAlias && (i = B(this.wow.contextAlias, i)), i = B(i, Qt(r));
|
|
716
|
+
let a = /* @__PURE__ */ new Map();
|
|
717
|
+
return {
|
|
718
|
+
tagName: e.name,
|
|
719
|
+
className: r,
|
|
720
|
+
file: i,
|
|
721
|
+
description: e.description,
|
|
722
|
+
basePath: this.basePath,
|
|
723
|
+
methods: n.map((t) => this.method(e, r, t, a))
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
method(e, t, n, r) {
|
|
727
|
+
let { operation: i } = n, a = this.methodName(e, t, n, r), o = new Set(Yt), s = this.parameters(e, n, o), c = this.body(i, o), l = [...s.filter(({ parameter: e }) => e.required), ...s.filter(({ parameter: e }) => !e.required)].filter(({ description: e }) => e);
|
|
728
|
+
return {
|
|
729
|
+
name: a,
|
|
730
|
+
httpMethod: n.method,
|
|
731
|
+
path: n.path,
|
|
732
|
+
parameters: s.map(({ parameter: e }) => e),
|
|
733
|
+
body: c,
|
|
734
|
+
returns: this.returns(i),
|
|
735
|
+
docs: [
|
|
736
|
+
i.summary,
|
|
737
|
+
i.description,
|
|
738
|
+
`- operationId: \`${i.operationId}\``,
|
|
739
|
+
`- path: \`${n.path}\``,
|
|
740
|
+
...l.map(({ parameter: e, description: t }) => `@param ${e.name} - ${t.replace(/\s*\n\s*/g, " ")}`)
|
|
741
|
+
]
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
methodName(e, t, n, r) {
|
|
745
|
+
let i = n.operation.operationId, a = jt(n.operation, this.config.apiClients?.[e.name]?.methodNames?.[i]), o = r.get(a);
|
|
746
|
+
if (o !== void 0) throw new g("specification", `Operations ${o} and ${i} of tag ${e.name} both generate the method ${t}.${a}(). Name one of them with apiClients["${e.name}"].methodNames in the generator configuration, or with the x-fetcher-method extension.`);
|
|
747
|
+
return r.set(a, i), a;
|
|
748
|
+
}
|
|
749
|
+
parameters(e, t, n) {
|
|
750
|
+
let r = it(t.operation, this.document.components ?? {}), i = [];
|
|
751
|
+
for (let a of [
|
|
752
|
+
"path",
|
|
753
|
+
"query",
|
|
754
|
+
"header"
|
|
755
|
+
]) {
|
|
756
|
+
let o = r.filter((e) => e.in === a);
|
|
757
|
+
for (let r of a === "path" ? ot(t.path, o) : o) a === "path" && this.ignoresPathParameter(e.name, r.name) || i.push({
|
|
758
|
+
parameter: {
|
|
759
|
+
name: Nt(r.name, n),
|
|
760
|
+
location: a,
|
|
761
|
+
parameterName: r.name,
|
|
762
|
+
schema: r.schema,
|
|
763
|
+
required: a === "path" || r.required === !0
|
|
764
|
+
},
|
|
765
|
+
description: r.description
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
let a = r.filter((e) => e.in === "cookie");
|
|
769
|
+
return a.length > 0 && this.warnings.push(`${t.method.toUpperCase()} ${t.path} leaves out its cookie parameter(s) ${a.map((e) => e.name).join(", ")}: the browser sends cookies, and fetch cannot set them.`), i;
|
|
770
|
+
}
|
|
771
|
+
ignoresPathParameter(e, t) {
|
|
772
|
+
return (this.config.apiClients?.[e]?.ignorePathParameters ?? (this.wowDocument ? Dt : [])).includes(t);
|
|
773
|
+
}
|
|
774
|
+
body(e, t) {
|
|
775
|
+
if (!e.requestBody) return;
|
|
776
|
+
let n = C(e.requestBody) ? Ee(e.requestBody, this.document.components) : e.requestBody;
|
|
777
|
+
if (!n) return;
|
|
778
|
+
let r = n.required === !0, i = n.content ?? {}, a = j(i, k, ke), o = Nt("body", t);
|
|
779
|
+
return a?.schema ? {
|
|
780
|
+
name: o,
|
|
781
|
+
required: r,
|
|
782
|
+
content: {
|
|
783
|
+
kind: "json",
|
|
784
|
+
schema: a.schema,
|
|
785
|
+
optionalFields: Ze(a.schema, this.document.components)
|
|
786
|
+
}
|
|
787
|
+
} : j(i, "multipart/form-data") ? {
|
|
788
|
+
name: o,
|
|
789
|
+
required: r,
|
|
790
|
+
content: { kind: "formData" }
|
|
791
|
+
} : j(i, "application/x-www-form-urlencoded") ? {
|
|
792
|
+
name: o,
|
|
793
|
+
required: r,
|
|
794
|
+
content: { kind: "urlEncoded" }
|
|
795
|
+
} : Object.keys(i).some(Ae) ? {
|
|
796
|
+
name: o,
|
|
797
|
+
required: r,
|
|
798
|
+
content: { kind: "text" }
|
|
799
|
+
} : {
|
|
800
|
+
name: o,
|
|
801
|
+
required: r,
|
|
802
|
+
content: { kind: "binary" }
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
returns(e) {
|
|
806
|
+
let t = F(e, this.document.components);
|
|
807
|
+
if (!t) return { kind: "response" };
|
|
808
|
+
let n = Me(t), r = n || Pe(t);
|
|
809
|
+
if (r) return {
|
|
810
|
+
kind: "json",
|
|
811
|
+
schema: r,
|
|
812
|
+
wildcard: !n
|
|
813
|
+
};
|
|
814
|
+
let i = Ne(t);
|
|
815
|
+
if (i) {
|
|
816
|
+
if (C(i)) {
|
|
817
|
+
let e = D(i, this.document.components);
|
|
818
|
+
if (Ve(e) && C(e.items)) {
|
|
819
|
+
let t = Pt(e.items, this.document.components);
|
|
820
|
+
return {
|
|
821
|
+
kind: "eventStream",
|
|
822
|
+
items: e.items,
|
|
823
|
+
serverSentEvent: t.name.includes("ServerSentEvent")
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
kind: "eventStream",
|
|
829
|
+
serverSentEvent: !1
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
return Fe(t) ? { kind: "text" } : { kind: "response" };
|
|
833
|
+
}
|
|
834
|
+
groupOperations(e) {
|
|
835
|
+
let t = /* @__PURE__ */ new Map();
|
|
836
|
+
for (let n of this.document.endpoints) {
|
|
837
|
+
let r = `${n.method.toUpperCase()} ${n.path}`, i = n.operation.tags ?? [];
|
|
838
|
+
if (i.length === 0) {
|
|
839
|
+
this.warnings.push(`Skipping ${r}: it has no tag, and the tag names its API client.`);
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
let a = i.filter((t) => e.has(t));
|
|
843
|
+
if (!(a.length < i.length)) {
|
|
844
|
+
if (!n.operation.operationId) {
|
|
845
|
+
this.warnings.push(`Skipping ${r}: it has no operationId, and the operationId names its method.`);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
for (let e of a) t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(n);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return t;
|
|
852
|
+
}
|
|
853
|
+
tags() {
|
|
854
|
+
let e = /* @__PURE__ */ new Map();
|
|
855
|
+
for (let { operation: t } of this.document.endpoints) t.tags?.forEach((t) => {
|
|
856
|
+
!this.ignoresTag(t) && !e.has(t) && e.set(t, {
|
|
857
|
+
name: t,
|
|
858
|
+
description: ""
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
return this.document.openAPI.tags?.forEach((t) => {
|
|
862
|
+
this.ignoresTag(t.name) || e.set(t.name, t);
|
|
863
|
+
}), e;
|
|
864
|
+
}
|
|
865
|
+
ignoresTag(e) {
|
|
866
|
+
return Et.has(e) || this.wow.aggregateTags.has(e);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
function Qt(e) {
|
|
870
|
+
return `${e.charAt(0).toLowerCase()}${e.slice(1)}.ts`;
|
|
871
|
+
}
|
|
872
|
+
function V(e) {
|
|
873
|
+
return `${e.path}/${e.name}`.toLowerCase();
|
|
874
|
+
}
|
|
875
|
+
//#endregion
|
|
876
|
+
//#region src/analysis/models.ts
|
|
877
|
+
function $t(e) {
|
|
878
|
+
let t = new Set(e.contexts.keys());
|
|
879
|
+
return e.contextAlias && t.add(e.contextAlias), [...t].sort().map((e) => ({
|
|
880
|
+
alias: e,
|
|
881
|
+
constantName: z(e),
|
|
882
|
+
file: Kt(e)
|
|
883
|
+
}));
|
|
884
|
+
}
|
|
885
|
+
function en(e, t) {
|
|
886
|
+
let n = e.components?.schemas;
|
|
887
|
+
if (!n) return [];
|
|
888
|
+
let r = nn(t), i = tn(e, t), a = Object.keys(n).filter((e) => !xt(e, () => R(e).name, r) || !e.startsWith("wow.") && i.has(e));
|
|
889
|
+
rn(a);
|
|
890
|
+
let o = an(t);
|
|
891
|
+
return a.map((e) => {
|
|
892
|
+
let r = n[e], i = R(e);
|
|
893
|
+
return {
|
|
894
|
+
key: e,
|
|
895
|
+
info: i,
|
|
896
|
+
file: Gt(i),
|
|
897
|
+
schema: r,
|
|
898
|
+
docSchema: Jt(r, t.schemaDocOverrides.get(e)),
|
|
899
|
+
emptyMessageBody: o.has(e) && on(r)
|
|
900
|
+
};
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
function tn(e, t) {
|
|
904
|
+
let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = e.components ?? {}, a = (e) => {
|
|
905
|
+
if (typeof e != "object" || !e || r.has(e)) return;
|
|
906
|
+
if (r.add(e), Array.isArray(e)) {
|
|
907
|
+
e.forEach(a);
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
let { $ref: t } = e;
|
|
911
|
+
if (typeof t == "string" && t.startsWith("#/components/")) {
|
|
912
|
+
let [e, ...r] = t.slice(w.length).split("/"), o = r.join("/");
|
|
913
|
+
e === "schemas" && n.add(o), a(i[e]?.[o]);
|
|
914
|
+
}
|
|
915
|
+
Object.values(e).forEach(a);
|
|
916
|
+
};
|
|
917
|
+
for (let { operation: n } of e.endpoints) {
|
|
918
|
+
let e = n.tags ?? [];
|
|
919
|
+
e.length > 0 && e.every((e) => !Et.has(e) && !t.aggregateTags.has(e)) && a(n);
|
|
920
|
+
}
|
|
921
|
+
return n;
|
|
922
|
+
}
|
|
923
|
+
function nn(e) {
|
|
924
|
+
let t = /* @__PURE__ */ new Set();
|
|
925
|
+
for (let n of e.contexts.values()) for (let e of n) bt(R(e.state.key).name).forEach((e) => t.add(e));
|
|
926
|
+
return t;
|
|
927
|
+
}
|
|
928
|
+
function rn(e) {
|
|
929
|
+
let t = /* @__PURE__ */ new Map();
|
|
930
|
+
for (let n of e) {
|
|
931
|
+
let e = R(n), r = `${e.path === "/" ? "" : e.path}/${e.name}`;
|
|
932
|
+
t.set(r, [...t.get(r) ?? [], n]);
|
|
933
|
+
}
|
|
934
|
+
let n = [...t].filter(([, e]) => e.length > 1);
|
|
935
|
+
if (n.length !== 0) throw new g("specification", `Schemas generate the same model: ${n.map(([e, t]) => `${t.join(", ")} → ${e}`).join("; ")}. Rename all but one of them in the document.`);
|
|
936
|
+
}
|
|
937
|
+
function an(e) {
|
|
938
|
+
return new Set([...e.contexts.values()].flatMap((e) => [...e].flatMap((e) => [...[...e.commands.values()].map((e) => e.schema.key), ...[...e.events.values()].map((e) => e.schema.key)])));
|
|
939
|
+
}
|
|
940
|
+
function on(e) {
|
|
941
|
+
return !C(e) && e.type === "object" && Object.keys(e.properties ?? {}).length === 0 && (e.additionalProperties === void 0 || e.additionalProperties === !1) && !e.required?.length && !N(e) && e.enum === void 0 && e.const === void 0;
|
|
942
|
+
}
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/analysis/analyze.ts
|
|
945
|
+
function sn(e, t, n) {
|
|
946
|
+
let r = [], i = $t(t), a = en(e, t), o = It(e, t);
|
|
947
|
+
return Bt(o, a), {
|
|
948
|
+
model: {
|
|
949
|
+
contexts: i,
|
|
950
|
+
models: a,
|
|
951
|
+
aggregates: o,
|
|
952
|
+
apiClients: Xt(e, t, n, r)
|
|
953
|
+
},
|
|
954
|
+
warnings: r
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region src/emit/importRegistry.ts
|
|
959
|
+
var cn = class {
|
|
960
|
+
declarations = /* @__PURE__ */ new Map();
|
|
961
|
+
add(e, t) {
|
|
962
|
+
let n = this.declarations.get(e);
|
|
963
|
+
n || (n = [], this.declarations.set(e, n));
|
|
964
|
+
for (let e of t) n.some((t) => t.name === e) || n.push({ name: e });
|
|
965
|
+
return n;
|
|
966
|
+
}
|
|
967
|
+
apply(e) {
|
|
968
|
+
for (let { moduleSpecifier: t, name: n, alias: r } of e) {
|
|
969
|
+
let e = this.add(t, [n]).find((e) => e.name === n);
|
|
970
|
+
r !== void 0 && (e.alias = r);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
entries() {
|
|
974
|
+
return [...this.declarations].flatMap(([e, t]) => t.map(({ name: t, alias: n }) => n === void 0 ? {
|
|
975
|
+
moduleSpecifier: e,
|
|
976
|
+
name: t
|
|
977
|
+
} : {
|
|
978
|
+
moduleSpecifier: e,
|
|
979
|
+
name: t,
|
|
980
|
+
alias: n
|
|
981
|
+
}));
|
|
982
|
+
}
|
|
983
|
+
localNames(e) {
|
|
984
|
+
return [...this.declarations.values()].flat().filter((t) => t !== e).map((e) => e.alias ?? e.name);
|
|
985
|
+
}
|
|
986
|
+
structures() {
|
|
987
|
+
return [...this.declarations].map(([e, t]) => ({
|
|
988
|
+
moduleSpecifier: e,
|
|
989
|
+
namedImports: t.map(({ name: e, alias: t }) => t === void 0 ? e : {
|
|
990
|
+
name: e,
|
|
991
|
+
alias: t
|
|
992
|
+
})
|
|
993
|
+
}));
|
|
994
|
+
}
|
|
995
|
+
}, ln = class {
|
|
996
|
+
sourceFile;
|
|
997
|
+
imports = new cn();
|
|
998
|
+
statements = [];
|
|
999
|
+
constructor(e) {
|
|
1000
|
+
this.sourceFile = e;
|
|
1001
|
+
}
|
|
1002
|
+
get directoryPath() {
|
|
1003
|
+
return this.sourceFile.getDirectoryPath();
|
|
1004
|
+
}
|
|
1005
|
+
add(e) {
|
|
1006
|
+
return this.statements.push(e), e;
|
|
1007
|
+
}
|
|
1008
|
+
build() {
|
|
1009
|
+
let e = [], t;
|
|
1010
|
+
for (let n of this.imports.structures()) t = {
|
|
1011
|
+
...n,
|
|
1012
|
+
kind: o.ImportDeclaration
|
|
1013
|
+
}, e.push(t);
|
|
1014
|
+
for (let n of this.statements) t && fn(t, n) && e.push(dn), e.push(n), t = n;
|
|
1015
|
+
return e.length > 0 && this.sourceFile.addStatements(e), this.sourceFile;
|
|
1016
|
+
}
|
|
1017
|
+
}, un = class {
|
|
1018
|
+
open;
|
|
1019
|
+
modules = /* @__PURE__ */ new Map();
|
|
1020
|
+
constructor(e) {
|
|
1021
|
+
this.open = e;
|
|
1022
|
+
}
|
|
1023
|
+
module(e) {
|
|
1024
|
+
let t = this.open(e), n = t.getFilePath(), r = this.modules.get(n);
|
|
1025
|
+
return r || (r = new ln(t), this.modules.set(n, r)), r;
|
|
1026
|
+
}
|
|
1027
|
+
build() {
|
|
1028
|
+
for (let e of this.modules.values()) e.build();
|
|
1029
|
+
this.modules.clear();
|
|
1030
|
+
}
|
|
1031
|
+
}, dn = (e) => {
|
|
1032
|
+
e.blankLineIfLastNot();
|
|
1033
|
+
};
|
|
1034
|
+
function fn(e, t) {
|
|
1035
|
+
if (typeof t == "string") return !1;
|
|
1036
|
+
switch (t.kind) {
|
|
1037
|
+
case o.TypeAlias:
|
|
1038
|
+
case o.VariableStatement: return typeof e == "string" || e.kind !== t.kind;
|
|
1039
|
+
default: return !0;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function pn(e) {
|
|
1043
|
+
return e.map((e) => ({
|
|
1044
|
+
...e,
|
|
1045
|
+
initializer: `${e.initializer},`
|
|
1046
|
+
}));
|
|
1047
|
+
}
|
|
1048
|
+
function mn(e, t) {
|
|
1049
|
+
return {
|
|
1050
|
+
name: "[key: string]",
|
|
1051
|
+
type: e,
|
|
1052
|
+
docs: t
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
//#endregion
|
|
1056
|
+
//#region src/emit/imports.ts
|
|
1057
|
+
var hn = "@";
|
|
1058
|
+
function H(e, t, n) {
|
|
1059
|
+
return e.imports.add(t, n);
|
|
1060
|
+
}
|
|
1061
|
+
function U(e, t, n) {
|
|
1062
|
+
return H(e, W(e, t, n), [n.name]);
|
|
1063
|
+
}
|
|
1064
|
+
function W(e, t, n) {
|
|
1065
|
+
return n.path.startsWith(hn) ? n.path : gn(e.directoryPath, d(t, n.path, Wt));
|
|
1066
|
+
}
|
|
1067
|
+
function gn(e, t) {
|
|
1068
|
+
let n = f(e, t).split(m).join("/");
|
|
1069
|
+
return n = n.endsWith(".ts") ? n.replace(/\.ts$/, ".js") : `${n}/index.js`, n.startsWith(".") ? n : `./${n}`;
|
|
1070
|
+
}
|
|
1071
|
+
function G(e, t, n, r) {
|
|
1072
|
+
return H(e, gn(e.directoryPath, d(t, Kt(n))), [r]);
|
|
1073
|
+
}
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/emit/jsdoc.ts
|
|
1076
|
+
function _n(e, t = "\n") {
|
|
1077
|
+
if (!Array.isArray(e)) return;
|
|
1078
|
+
let n = e.filter((e) => typeof e == "string" && e.length > 0).map(vn);
|
|
1079
|
+
return n.length > 0 ? n.join(t) : void 0;
|
|
1080
|
+
}
|
|
1081
|
+
function vn(e) {
|
|
1082
|
+
return e.replace(/\*\//g, "*\\/");
|
|
1083
|
+
}
|
|
1084
|
+
function K(e, t) {
|
|
1085
|
+
let n = _n(t);
|
|
1086
|
+
n && (e.docs = [...e.docs ?? [], n]);
|
|
1087
|
+
}
|
|
1088
|
+
function yn(e, t) {
|
|
1089
|
+
let n = [e.title, e.description];
|
|
1090
|
+
return t && n.push(`- key: ${t}`), e.format && n.push(e.format === "int64" ? "- format: int64 (a value beyond Number.MAX_SAFE_INTEGER loses precision)" : `- format: ${e.format}`), Sn(n, e, "default"), Sn(n, e, "example"), wn(n, e), Tn(n, e), En(n, e), n;
|
|
1091
|
+
}
|
|
1092
|
+
function bn(e, t, n) {
|
|
1093
|
+
K(e, yn(t, n));
|
|
1094
|
+
}
|
|
1095
|
+
function xn(e, t, n, r = !1) {
|
|
1096
|
+
let i = yn(t, n);
|
|
1097
|
+
r && Cn(i, "schema", t), K(e, i);
|
|
1098
|
+
}
|
|
1099
|
+
function Sn(e, t, n) {
|
|
1100
|
+
let r = t[n];
|
|
1101
|
+
if (r) {
|
|
1102
|
+
if (typeof r != "object") {
|
|
1103
|
+
e.push(`- ${n}: \`${r}\``);
|
|
1104
|
+
return;
|
|
1105
|
+
}
|
|
1106
|
+
Cn(e, n, r);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function Cn(e, t, n) {
|
|
1110
|
+
e.push(`- ${t}: `), e.push("```json"), e.push(JSON.stringify(n, null, 2)), e.push("```");
|
|
1111
|
+
}
|
|
1112
|
+
function wn(e, t) {
|
|
1113
|
+
let n = ["- Numeric Constraints"];
|
|
1114
|
+
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);
|
|
1115
|
+
}
|
|
1116
|
+
function Tn(e, t) {
|
|
1117
|
+
let n = ["- String Constraints"];
|
|
1118
|
+
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);
|
|
1119
|
+
}
|
|
1120
|
+
function En(e, t) {
|
|
1121
|
+
let n = ["- Array Constraints"];
|
|
1122
|
+
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);
|
|
1123
|
+
}
|
|
1124
|
+
//#endregion
|
|
1125
|
+
//#region src/types/typeResolver.ts
|
|
1126
|
+
function Dn(e, t) {
|
|
1127
|
+
let n;
|
|
1128
|
+
return {
|
|
1129
|
+
components: e,
|
|
1130
|
+
modelOf: (n) => t.ofReference(n, e),
|
|
1131
|
+
namesAt(r) {
|
|
1132
|
+
if (!n) {
|
|
1133
|
+
n = /* @__PURE__ */ new Map();
|
|
1134
|
+
for (let r of Object.keys(e?.schemas ?? {})) {
|
|
1135
|
+
let e = t.ofKey(r), i = n.get(e.path);
|
|
1136
|
+
i || (i = [], n.set(e.path, i)), i.push(e.name, `${e.name}EnumText`);
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return n.get(r) ?? [];
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
var On = [
|
|
1144
|
+
"Array",
|
|
1145
|
+
"Blob",
|
|
1146
|
+
"Exclude",
|
|
1147
|
+
"FormData",
|
|
1148
|
+
"Partial",
|
|
1149
|
+
"Promise",
|
|
1150
|
+
"ReadonlyArray",
|
|
1151
|
+
"Record",
|
|
1152
|
+
"Response",
|
|
1153
|
+
"Symbol",
|
|
1154
|
+
"URLSearchParams"
|
|
1155
|
+
], kn = /* @__PURE__ */ new Set([
|
|
1156
|
+
"string",
|
|
1157
|
+
"number",
|
|
1158
|
+
"boolean"
|
|
1159
|
+
]), An = /* @__PURE__ */ new Set([
|
|
1160
|
+
"$comment",
|
|
1161
|
+
"$schema",
|
|
1162
|
+
"default",
|
|
1163
|
+
"deprecated",
|
|
1164
|
+
"description",
|
|
1165
|
+
"example",
|
|
1166
|
+
"examples",
|
|
1167
|
+
"externalDocs",
|
|
1168
|
+
"readOnly",
|
|
1169
|
+
"title",
|
|
1170
|
+
"writeOnly",
|
|
1171
|
+
"xml"
|
|
1172
|
+
]);
|
|
1173
|
+
function jn(e, t) {
|
|
1174
|
+
return e === void 0 ? !1 : typeof e == "string" || typeof t == "string" ? e === t : e.primitive === t.primitive;
|
|
1175
|
+
}
|
|
1176
|
+
function q(e, t, n = /* @__PURE__ */ new Set()) {
|
|
1177
|
+
if (C(e)) {
|
|
1178
|
+
if (!t || n.has(e.$ref)) return;
|
|
1179
|
+
n.add(e.$ref);
|
|
1180
|
+
let r = D(e, t);
|
|
1181
|
+
return r ? q(r, t, n) : void 0;
|
|
1182
|
+
}
|
|
1183
|
+
if (!(e.nullable || Array.isArray(e.type))) {
|
|
1184
|
+
if (We(e) && e.type === void 0) {
|
|
1185
|
+
let r = e.allOf.map((e) => q(e, t, n)), [i] = r;
|
|
1186
|
+
return i !== void 0 && r.every((e) => jn(e, i)) ? i : void 0;
|
|
1187
|
+
}
|
|
1188
|
+
if (!(N(e) || e.const !== void 0 || e.type === void 0)) return e.type === "object" ? "object" : e.type === "array" ? "array" : { primitive: P(e.type) };
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
function Mn(e, t, n) {
|
|
1192
|
+
let r = q(t, n);
|
|
1193
|
+
if (typeof r != "object") return !1;
|
|
1194
|
+
let i = q(e, n);
|
|
1195
|
+
return i === void 0 || typeof i == "string" || i.primitive !== r.primitive;
|
|
1196
|
+
}
|
|
1197
|
+
function Nn(e, t) {
|
|
1198
|
+
let n = e.additionalProperties;
|
|
1199
|
+
return typeof n == "object" && Object.values(e.properties ?? {}).some((e) => Mn(e, n, t));
|
|
1200
|
+
}
|
|
1201
|
+
function Pn(e) {
|
|
1202
|
+
return e.nullable !== !0 || M(e) || !N(e) ? !1 : [
|
|
1203
|
+
e.allOf,
|
|
1204
|
+
e.oneOf,
|
|
1205
|
+
e.anyOf
|
|
1206
|
+
].every((e) => e === void 0 || e.every(C));
|
|
1207
|
+
}
|
|
1208
|
+
function Fn(e, t) {
|
|
1209
|
+
return t.type === void 0 || e === null && t.nullable ? !0 : [t.type].flat().some((t) => t === "null" ? e === null : t === "array" ? Array.isArray(e) : t === "object" ? typeof e == "object" && !!e && !Array.isArray(e) : t === "integer" ? typeof e == "number" && Number.isInteger(e) : typeof e === t);
|
|
1210
|
+
}
|
|
1211
|
+
function J(t) {
|
|
1212
|
+
if (typeof t == "string") return new e({ useSingleQuote: !0 }).quote(t).toString();
|
|
1213
|
+
if (Array.isArray(t)) return `[${t.map((e) => J(e)).join(", ")}]`;
|
|
1214
|
+
if (typeof t == "object" && t) {
|
|
1215
|
+
let e = Object.entries(t).map(([e, t]) => `${b(e)}: ${J(t)}`);
|
|
1216
|
+
return e.length ? `{ ${e.join("; ")}; readonly [globalThis.Symbol.iterator]?: never }` : "globalThis.Record<string, never>";
|
|
1217
|
+
}
|
|
1218
|
+
return JSON.stringify(t) ?? "never";
|
|
1219
|
+
}
|
|
1220
|
+
var In = class {
|
|
1221
|
+
scope;
|
|
1222
|
+
entries;
|
|
1223
|
+
requested = [];
|
|
1224
|
+
constructor(e) {
|
|
1225
|
+
this.scope = e, this.entries = e.imports.entries().map((e) => ({ ...e }));
|
|
1226
|
+
}
|
|
1227
|
+
get components() {
|
|
1228
|
+
return this.scope.context.components;
|
|
1229
|
+
}
|
|
1230
|
+
imports() {
|
|
1231
|
+
return this.requested.map(({ moduleSpecifier: e, name: t, alias: n }) => n === void 0 ? {
|
|
1232
|
+
moduleSpecifier: e,
|
|
1233
|
+
name: t
|
|
1234
|
+
} : {
|
|
1235
|
+
moduleSpecifier: e,
|
|
1236
|
+
name: t,
|
|
1237
|
+
alias: n
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
request(e) {
|
|
1241
|
+
this.requested.includes(e) || this.requested.push(e);
|
|
1242
|
+
}
|
|
1243
|
+
reference(e) {
|
|
1244
|
+
let t = this.scope.context.modelOf(e), { owner: n } = this.scope;
|
|
1245
|
+
if (n.path === t.path) return t.name;
|
|
1246
|
+
let r = this.scope.specifierOf(t), i = this.entries.find((e) => e.moduleSpecifier === r && e.name === t.name);
|
|
1247
|
+
if (i || (i = {
|
|
1248
|
+
moduleSpecifier: r,
|
|
1249
|
+
name: t.name
|
|
1250
|
+
}, this.entries.push(i)), this.request(i), i.alias) return i.alias;
|
|
1251
|
+
let a = /* @__PURE__ */ new Set([
|
|
1252
|
+
...On,
|
|
1253
|
+
n.name,
|
|
1254
|
+
...n.path === void 0 ? [] : this.scope.context.namesAt(n.path),
|
|
1255
|
+
...this.entries.filter((e) => e !== i).map((e) => e.alias ?? e.name)
|
|
1256
|
+
]);
|
|
1257
|
+
if (!a.has(t.name)) return t.name;
|
|
1258
|
+
let o = `_${t.name}`;
|
|
1259
|
+
for (; a.has(o);) o = `_${o}`;
|
|
1260
|
+
return i.alias = o, o;
|
|
1261
|
+
}
|
|
1262
|
+
additionalProperties(e) {
|
|
1263
|
+
return e.additionalProperties === !1 || e.additionalProperties === void 0 && !e.required?.some((t) => !Object.hasOwn(e.properties ?? {}, t)) ? "" : e.additionalProperties === !0 || e.additionalProperties === void 0 ? "[key: string]: any" : `[key: string]: ${this.additionalPropertyType(e)}`;
|
|
1264
|
+
}
|
|
1265
|
+
additionalPropertyType(e) {
|
|
1266
|
+
return this.type(typeof e.additionalProperties == "object" ? e.additionalProperties : {});
|
|
1267
|
+
}
|
|
1268
|
+
requiredAdditionalPropertyType(e) {
|
|
1269
|
+
return e.additionalProperties === !1 ? "never" : typeof e.additionalProperties == "object" ? this.type(e.additionalProperties) : "null | string | number | boolean | globalThis.Record<string, unknown> | readonly unknown[]";
|
|
1270
|
+
}
|
|
1271
|
+
propertyDefinitions(e) {
|
|
1272
|
+
let { properties: t } = e;
|
|
1273
|
+
return Object.entries(t).map(([e, t]) => {
|
|
1274
|
+
let n = this.type(t), r = (Xe(t) ? "readonly " : "") + b(e);
|
|
1275
|
+
if (!C(t)) {
|
|
1276
|
+
let e = _n(yn(t), "\n * ");
|
|
1277
|
+
if (e) return `
|
|
1278
|
+
/**
|
|
1279
|
+
* ${e}
|
|
1280
|
+
*/
|
|
1281
|
+
${r}: ${n}
|
|
1282
|
+
`;
|
|
1283
|
+
}
|
|
1284
|
+
return `${r}: ${n}`;
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
objectType(e) {
|
|
1288
|
+
let t = [];
|
|
1289
|
+
Be(e) && t.push(...this.propertyDefinitions(e));
|
|
1290
|
+
for (let n of e.required ?? []) Object.hasOwn(e.properties ?? {}, n) || t.push(`${b(n)}: ${this.requiredAdditionalPropertyType(e)}`);
|
|
1291
|
+
let n = Ke(e) && Je(e) ? this.mapType(e) : Nn(e, this.components) ? `globalThis.Record<string, ${this.additionalPropertyType(e)}>` : void 0, r = n ? "" : this.additionalProperties(e);
|
|
1292
|
+
if (r && t.push(r), t.length === 0) return "globalThis.Record<string, any>";
|
|
1293
|
+
let i = `{\n ${t.join(";\n ")}; \n}`;
|
|
1294
|
+
return n ? `(${i} & ${n})` : i;
|
|
1295
|
+
}
|
|
1296
|
+
mapValueType(e) {
|
|
1297
|
+
return e.additionalProperties === void 0 || e.additionalProperties === !1 || e.additionalProperties === !0 ? "any" : this.type(e.additionalProperties);
|
|
1298
|
+
}
|
|
1299
|
+
mapKeyType(e) {
|
|
1300
|
+
let t = Je(e);
|
|
1301
|
+
return t ? this.type(t) : "string";
|
|
1302
|
+
}
|
|
1303
|
+
mapType(e) {
|
|
1304
|
+
return `globalThis.Record<${this.mapKeyType(e)},${this.mapValueType(e)}>`;
|
|
1305
|
+
}
|
|
1306
|
+
objectConstrained(e) {
|
|
1307
|
+
let t = (e) => C(e) ? this.components && D(e, this.components) : e, n = t(e), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = n ? [n] : [];
|
|
1308
|
+
for (let e of a) {
|
|
1309
|
+
if (r.has(e)) continue;
|
|
1310
|
+
let n = [
|
|
1311
|
+
e.allOf,
|
|
1312
|
+
e.oneOf,
|
|
1313
|
+
e.anyOf
|
|
1314
|
+
].map((e) => e?.map(t) ?? []);
|
|
1315
|
+
r.set(e, n);
|
|
1316
|
+
for (let e of n) for (let t of e) t && !r.has(t) && a.push(t);
|
|
1317
|
+
(e.type === "object" || e.type === "null" || Array.isArray(e.type) && e.type.length > 0 && e.type.every((e) => e === "object" || e === "null")) && i.add(e);
|
|
1318
|
+
}
|
|
1319
|
+
let o = !0;
|
|
1320
|
+
for (; o;) {
|
|
1321
|
+
o = !1;
|
|
1322
|
+
for (let [e, [t, n, a]] of r) {
|
|
1323
|
+
if (i.has(e)) continue;
|
|
1324
|
+
let r = (e) => e !== void 0 && i.has(e);
|
|
1325
|
+
(t.some(r) || [n, a].some((e) => e.length > 0 && e.every(r))) && (i.add(e), o = !0);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return n !== void 0 && i.has(n);
|
|
1329
|
+
}
|
|
1330
|
+
type(e) {
|
|
1331
|
+
if (C(e)) return this.reference(e);
|
|
1332
|
+
if (Array.isArray(e.type)) return e.type.map((t) => {
|
|
1333
|
+
let n = this.type({
|
|
1334
|
+
...e,
|
|
1335
|
+
type: t
|
|
1336
|
+
});
|
|
1337
|
+
return /[|&]/.test(n) ? `(${n})` : n;
|
|
1338
|
+
}).join(" | ");
|
|
1339
|
+
if (Pn(e)) return `(${this.type({
|
|
1340
|
+
...e,
|
|
1341
|
+
nullable: !1
|
|
1342
|
+
})}) | null`;
|
|
1343
|
+
if (N(e)) {
|
|
1344
|
+
let t = this.simpleComposition(e);
|
|
1345
|
+
if (t !== void 0) return t;
|
|
1346
|
+
let n = [
|
|
1347
|
+
"allOf",
|
|
1348
|
+
"oneOf",
|
|
1349
|
+
"anyOf"
|
|
1350
|
+
].flatMap((t) => {
|
|
1351
|
+
let n = e[t];
|
|
1352
|
+
return n?.length ? [`(${n.map((n) => {
|
|
1353
|
+
let r = this.memberType(e, t, n);
|
|
1354
|
+
return r === "any" ? "unknown" : /[|&]/.test(r) ? `(${r})` : r;
|
|
1355
|
+
}).join(t === "allOf" ? " & " : " | ")})`] : [];
|
|
1356
|
+
}), r = n.length === 1 ? n[0] : `(${n.join(" & ")})`, i = {
|
|
1357
|
+
...e,
|
|
1358
|
+
oneOf: void 0,
|
|
1359
|
+
anyOf: void 0,
|
|
1360
|
+
allOf: void 0
|
|
1361
|
+
}, a = this.type(i), o = a === "any" ? r : `(${r} & (${a}))`;
|
|
1362
|
+
return this.objectConstrained(e) ? `globalThis.Exclude<${o}, string | number | boolean | readonly unknown[]> & ({ readonly [globalThis.Symbol.iterator]?: never } | null)` : o;
|
|
1363
|
+
}
|
|
1364
|
+
if (e.const !== void 0) {
|
|
1365
|
+
if (!Fn(e.const, e)) return "never";
|
|
1366
|
+
let t = J(e.const), n = this.type({
|
|
1367
|
+
...e,
|
|
1368
|
+
const: void 0
|
|
1369
|
+
});
|
|
1370
|
+
return n === "any" ? t : `(${t}) & (${n})`;
|
|
1371
|
+
}
|
|
1372
|
+
if (e.nullable && e.type && !M(e)) return `(${this.type({
|
|
1373
|
+
...e,
|
|
1374
|
+
nullable: !1
|
|
1375
|
+
})}) | null`;
|
|
1376
|
+
if (M(e)) {
|
|
1377
|
+
let t = e.enum.filter((t) => Fn(t, e)).map((e) => J(e)).join(" | ") || "never", n = this.type({
|
|
1378
|
+
...e,
|
|
1379
|
+
enum: void 0
|
|
1380
|
+
});
|
|
1381
|
+
return n === "any" || kn.has(n) ? t : `(${t}) & (${n})`;
|
|
1382
|
+
}
|
|
1383
|
+
return Ke(e) && !e.required?.length ? this.mapType(e) : e.type === "array" ? Ge(this.type(e.items ?? {})) : e.type === "object" ? this.objectType(e) : e.type ? P(e.type) : e.required?.length || Object.keys(e.properties ?? {}).length > 0 ? `(${this.objectType({
|
|
1384
|
+
...e,
|
|
1385
|
+
type: "object",
|
|
1386
|
+
additionalProperties: e.additionalProperties ?? !0
|
|
1387
|
+
})} | null | string | number | boolean | readonly unknown[])` : "any";
|
|
1388
|
+
}
|
|
1389
|
+
simpleComposition(e) {
|
|
1390
|
+
let t = [
|
|
1391
|
+
"allOf",
|
|
1392
|
+
"oneOf",
|
|
1393
|
+
"anyOf"
|
|
1394
|
+
].filter((t) => e[t]?.length);
|
|
1395
|
+
if (t.length !== 1) return;
|
|
1396
|
+
let [n] = t;
|
|
1397
|
+
if (Object.keys(e).filter((e) => e !== n && e !== "discriminator" && !e.startsWith("x-") && !An.has(e)).length > 0) return;
|
|
1398
|
+
let r = e[n], i = (e) => n !== "allOf" && [e.type].flat().every((e) => e === "null") && e.type !== void 0 && Object.keys(e).every((e) => e === "type" || An.has(e));
|
|
1399
|
+
if (!r.every((e) => C(e) || i(e))) return;
|
|
1400
|
+
let a = r.map((t) => C(t) ? this.memberType(e, n, t) : "null");
|
|
1401
|
+
return [...new Set(a)].join(n === "allOf" ? " & " : " | ");
|
|
1402
|
+
}
|
|
1403
|
+
memberType(e, t, n) {
|
|
1404
|
+
let r = this.type(n), i = e.discriminator;
|
|
1405
|
+
if (t === "allOf" || !i?.propertyName || !C(n)) return r;
|
|
1406
|
+
let a = we(n), o = Object.entries(i.mapping ?? {}).filter(([, e]) => e === n.$ref || e === a).map(([e]) => e), s = (o.length > 0 ? o : [a]).map((e) => x(e)).join(" | ");
|
|
1407
|
+
return `(${r} & { ${b(i.propertyName)}: ${s} })`;
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
function Y(e, t) {
|
|
1411
|
+
let n = new In(e);
|
|
1412
|
+
return {
|
|
1413
|
+
text: t(n),
|
|
1414
|
+
imports: n.imports()
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
function Ln(e, t) {
|
|
1418
|
+
return Y(t, (t) => t.type(e));
|
|
1419
|
+
}
|
|
1420
|
+
function Rn(e, t) {
|
|
1421
|
+
return Y(t, (t) => t.additionalProperties(e));
|
|
1422
|
+
}
|
|
1423
|
+
function zn(e, t) {
|
|
1424
|
+
return Y(t, (t) => t.additionalPropertyType(e));
|
|
1425
|
+
}
|
|
1426
|
+
function Bn(e, t) {
|
|
1427
|
+
return Y(t, (t) => t.requiredAdditionalPropertyType(e));
|
|
1428
|
+
}
|
|
1429
|
+
function Vn(e, t) {
|
|
1430
|
+
return Y(t, (t) => t.mapValueType(e));
|
|
1431
|
+
}
|
|
1432
|
+
//#endregion
|
|
1433
|
+
//#region src/emitters/decorators.ts
|
|
1434
|
+
var Hn = "@ahoo-wang/fetcher", Un = ["ContentTypeValues", "ResultExtractors"], Wn = "@ahoo-wang/fetcher-decorator", Gn = [
|
|
1435
|
+
"ApiMetadata",
|
|
1436
|
+
"ApiMetadataCapable",
|
|
1437
|
+
"ParameterRequest",
|
|
1438
|
+
"api",
|
|
1439
|
+
"get",
|
|
1440
|
+
"post",
|
|
1441
|
+
"put",
|
|
1442
|
+
"patch",
|
|
1443
|
+
"del",
|
|
1444
|
+
"request",
|
|
1445
|
+
"attribute",
|
|
1446
|
+
"path",
|
|
1447
|
+
"query",
|
|
1448
|
+
"header",
|
|
1449
|
+
"body",
|
|
1450
|
+
"autoGeneratedError"
|
|
1451
|
+
], Kn = {
|
|
1452
|
+
type: "Promise<Response>",
|
|
1453
|
+
metadata: "{resultExtractor: ResultExtractors.Response }"
|
|
1454
|
+
}, qn = {
|
|
1455
|
+
type: "Promise<string>",
|
|
1456
|
+
metadata: "{resultExtractor: ResultExtractors.Text }"
|
|
1457
|
+
}, Jn = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}", Yn = "COMMAND_STREAM_ENDPOINT";
|
|
1458
|
+
function Xn(e) {
|
|
1459
|
+
H(e, Hn, Un);
|
|
1460
|
+
}
|
|
1461
|
+
function Zn(e) {
|
|
1462
|
+
H(e, Wn, Gn);
|
|
1463
|
+
}
|
|
1464
|
+
function Qn(e, t, n = [], r = [], i) {
|
|
1465
|
+
return t.add({
|
|
1466
|
+
kind: o.Class,
|
|
1467
|
+
name: e,
|
|
1468
|
+
isExported: !0,
|
|
1469
|
+
typeParameters: r,
|
|
1470
|
+
extends: i,
|
|
1471
|
+
decorators: [{
|
|
1472
|
+
name: "api",
|
|
1473
|
+
arguments: n
|
|
1474
|
+
}]
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
function $n(e, t) {
|
|
1478
|
+
if (e.implements = [...[e.implements ?? []].flat(), "ApiMetadataCapable"], e.ctors ??= [], t === void 0) {
|
|
1479
|
+
e.ctors.push({ parameters: [{
|
|
1480
|
+
name: "apiMetadata",
|
|
1481
|
+
type: "ApiMetadata",
|
|
1482
|
+
hasQuestionToken: !0,
|
|
1483
|
+
scope: a.Public,
|
|
1484
|
+
isReadonly: !0
|
|
1485
|
+
}] });
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
e.properties = [...e.properties ?? [], {
|
|
1489
|
+
name: "apiMetadata",
|
|
1490
|
+
type: "ApiMetadata",
|
|
1491
|
+
isReadonly: !0
|
|
1492
|
+
}], e.ctors.push({
|
|
1493
|
+
parameters: [{
|
|
1494
|
+
name: "apiMetadata",
|
|
1495
|
+
type: "ApiMetadata",
|
|
1496
|
+
hasQuestionToken: !0
|
|
1497
|
+
}],
|
|
1498
|
+
statements: `this.apiMetadata = { ${t}, ...apiMetadata };`,
|
|
1499
|
+
docs: ["@param apiMetadata - Merged over the defaults, so passing only a `fetcher` keeps the base path."]
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
function er(e) {
|
|
1503
|
+
return e === "delete" ? "del" : e;
|
|
1504
|
+
}
|
|
1505
|
+
var tr = "@ahoo-wang/fetcher-eventstream";
|
|
1506
|
+
function nr(e) {
|
|
1507
|
+
H(e, tr, ["JsonEventStreamResultExtractor", "JsonServerSentEventStream"]);
|
|
1508
|
+
}
|
|
1509
|
+
//#endregion
|
|
1510
|
+
//#region src/emitters/apiClients.ts
|
|
1511
|
+
function rr(e, t) {
|
|
1512
|
+
let n = t.modules.module(e.file);
|
|
1513
|
+
Xn(n), Zn(n), nr(n);
|
|
1514
|
+
let r = Qn(e.className, n);
|
|
1515
|
+
K(r, [e.description]);
|
|
1516
|
+
let i;
|
|
1517
|
+
e.basePath && (G(n, t.outputDir, e.basePath.alias, e.basePath.constantName), i = `basePath: ${e.basePath.constantName}`), $n(r, i);
|
|
1518
|
+
let a = ir(e.className, n, t);
|
|
1519
|
+
for (let t of e.methods) (r.methods ??= []).push(ar(t, a));
|
|
1520
|
+
}
|
|
1521
|
+
function ir(e, t, n) {
|
|
1522
|
+
let r = {
|
|
1523
|
+
context: n.types,
|
|
1524
|
+
owner: { name: e },
|
|
1525
|
+
specifierOf: (e) => W(t, n.outputDir, e),
|
|
1526
|
+
imports: t.imports
|
|
1527
|
+
};
|
|
1528
|
+
return {
|
|
1529
|
+
module: t,
|
|
1530
|
+
resolveType(e) {
|
|
1531
|
+
let n = Ln(e, r);
|
|
1532
|
+
return t.imports.apply(n.imports), n.text;
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
function ar(e, t) {
|
|
1537
|
+
let n = [], r = [];
|
|
1538
|
+
for (let i of e.parameters) (i.required ? n : r).push({
|
|
1539
|
+
name: i.name,
|
|
1540
|
+
type: i.schema ? t.resolveType(i.schema) : "string",
|
|
1541
|
+
hasQuestionToken: !i.required,
|
|
1542
|
+
decorators: [{
|
|
1543
|
+
name: i.location,
|
|
1544
|
+
arguments: [x(i.parameterName)]
|
|
1545
|
+
}]
|
|
1546
|
+
});
|
|
1547
|
+
e.body && (e.body.required ? n : r).push({
|
|
1548
|
+
name: e.body.name,
|
|
1549
|
+
type: or(e.body, t),
|
|
1550
|
+
hasQuestionToken: !e.body.required,
|
|
1551
|
+
decorators: [{
|
|
1552
|
+
name: "body",
|
|
1553
|
+
arguments: []
|
|
1554
|
+
}]
|
|
1555
|
+
});
|
|
1556
|
+
let i = [
|
|
1557
|
+
...n,
|
|
1558
|
+
...r,
|
|
1559
|
+
{
|
|
1560
|
+
name: "httpRequest",
|
|
1561
|
+
hasQuestionToken: !0,
|
|
1562
|
+
type: "ParameterRequest",
|
|
1563
|
+
decorators: [{
|
|
1564
|
+
name: "request",
|
|
1565
|
+
arguments: []
|
|
1566
|
+
}]
|
|
1567
|
+
},
|
|
1568
|
+
{
|
|
1569
|
+
name: "attributes",
|
|
1570
|
+
hasQuestionToken: !0,
|
|
1571
|
+
type: "Record<string, unknown>",
|
|
1572
|
+
decorators: [{
|
|
1573
|
+
name: "attribute",
|
|
1574
|
+
arguments: []
|
|
1575
|
+
}]
|
|
1576
|
+
}
|
|
1577
|
+
], a = sr(e.returns, t), o = x(e.path), s = {
|
|
1578
|
+
name: e.name,
|
|
1579
|
+
decorators: [{
|
|
1580
|
+
name: er(e.httpMethod),
|
|
1581
|
+
arguments: a.metadata ? [o, a.metadata] : [o]
|
|
1582
|
+
}],
|
|
1583
|
+
parameters: i,
|
|
1584
|
+
returnType: a.type,
|
|
1585
|
+
statements: [`throw autoGeneratedError(${i.map((e) => e.name).join(",")});`]
|
|
1586
|
+
};
|
|
1587
|
+
return K(s, [...e.docs]), s;
|
|
1588
|
+
}
|
|
1589
|
+
function or(e, t) {
|
|
1590
|
+
let { content: n } = e;
|
|
1591
|
+
switch (n.kind) {
|
|
1592
|
+
case "json": {
|
|
1593
|
+
let e = t.resolveType(n.schema), r = n.optionalFields;
|
|
1594
|
+
return r.length === 0 || /[|&]/.test(e) || e === "any" ? e : (H(t.module, Hn, ["PartialBy"]), `PartialBy<${e}, ${r.map(x).join(" | ")}>`);
|
|
1595
|
+
}
|
|
1596
|
+
case "formData": return "FormData";
|
|
1597
|
+
case "urlEncoded": return "URLSearchParams";
|
|
1598
|
+
case "text": return "string";
|
|
1599
|
+
case "binary": return "BodyInit";
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
function sr(e, t) {
|
|
1603
|
+
switch (e.kind) {
|
|
1604
|
+
case "json": {
|
|
1605
|
+
let n = t.resolveType(e.schema);
|
|
1606
|
+
return e.wildcard && n === "string" ? qn : { type: `Promise<${n}>` };
|
|
1607
|
+
}
|
|
1608
|
+
case "eventStream": {
|
|
1609
|
+
if (!e.items) return {
|
|
1610
|
+
type: "Promise<JsonServerSentEventStream<any>>",
|
|
1611
|
+
metadata: Jn
|
|
1612
|
+
};
|
|
1613
|
+
let n = t.resolveType(e.items);
|
|
1614
|
+
return {
|
|
1615
|
+
type: `Promise<JsonServerSentEventStream<${e.serverSentEvent ? `${n}['data']` : n}>>`,
|
|
1616
|
+
metadata: Jn
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
case "text": return qn;
|
|
1620
|
+
case "response": return Kn;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
//#endregion
|
|
1624
|
+
//#region src/emitters/commandClients.ts
|
|
1625
|
+
var cr = "DEFAULT_COMMAND_CLIENT_OPTIONS";
|
|
1626
|
+
function lr(e, t) {
|
|
1627
|
+
let n = e.commandClient;
|
|
1628
|
+
if (n.commands.length === 0) return;
|
|
1629
|
+
let r = t.modules.module(n.file);
|
|
1630
|
+
r.add({
|
|
1631
|
+
kind: o.Enum,
|
|
1632
|
+
name: n.endpointPathsName,
|
|
1633
|
+
isExported: !0,
|
|
1634
|
+
members: pn(n.commands.map((e) => ({
|
|
1635
|
+
name: e.endpointMember,
|
|
1636
|
+
initializer: x(e.path)
|
|
1637
|
+
})))
|
|
1638
|
+
});
|
|
1639
|
+
let i = /* @__PURE__ */ new Set(), a = n.commands.map((e) => ur(r, t.outputDir, e, i));
|
|
1640
|
+
G(r, t.outputDir, e.context.alias, e.context.constantName), r.add({
|
|
1641
|
+
kind: o.VariableStatement,
|
|
1642
|
+
declarationKind: c.Const,
|
|
1643
|
+
declarations: [{
|
|
1644
|
+
name: cr,
|
|
1645
|
+
type: "ApiMetadata",
|
|
1646
|
+
initializer: `{
|
|
1647
|
+
basePath: ${e.context.constantName}
|
|
1648
|
+
}`
|
|
1649
|
+
}],
|
|
1650
|
+
isExported: !1
|
|
1651
|
+
}), H(r, I, [
|
|
1652
|
+
"CommandRequest",
|
|
1653
|
+
"CommandResult",
|
|
1654
|
+
"CommandResultEventStream",
|
|
1655
|
+
"CommandBody",
|
|
1656
|
+
Yn
|
|
1657
|
+
]), H(r, "@ahoo-wang/fetcher", ["PartialBy"]), Zn(r);
|
|
1658
|
+
let s = Qn(n.className, r, [], ["R = CommandResult"]);
|
|
1659
|
+
$n(s, `...${cr}`);
|
|
1660
|
+
for (let [e, t] of n.commands.entries()) {
|
|
1661
|
+
let r = dr(t, a[e]), i = {
|
|
1662
|
+
name: t.methodName,
|
|
1663
|
+
decorators: [{
|
|
1664
|
+
name: er(t.httpMethod),
|
|
1665
|
+
arguments: [`${n.endpointPathsName}.${t.endpointMember}`]
|
|
1666
|
+
}],
|
|
1667
|
+
parameters: r,
|
|
1668
|
+
returnType: "Promise<R>",
|
|
1669
|
+
statements: `throw autoGeneratedError(${r.map((e) => e.name).join(",")});`
|
|
1670
|
+
};
|
|
1671
|
+
(s.methods ??= []).push(i), K(i, [...t.docs]);
|
|
1672
|
+
}
|
|
1673
|
+
Qn(n.streamClassName, r, ["''", Yn], [], `${n.className}<CommandResultEventStream>`);
|
|
1674
|
+
}
|
|
1675
|
+
function ur(e, t, n, r) {
|
|
1676
|
+
if (n.body.path === "@ahoo-wang/wow-client") return H(e, I, [n.typeName]), n.typeName;
|
|
1677
|
+
U(e, t, n.body);
|
|
1678
|
+
let i = n.body.name, a = n.optionalFields.map(x).join(" | ");
|
|
1679
|
+
a !== "" && (i = `PartialBy<${i},${a}>`);
|
|
1680
|
+
let s = `CommandBody<${i}>`;
|
|
1681
|
+
return n.typeName === void 0 ? s : r.has(n.typeName) ? n.typeName : (r.add(n.typeName), e.add({
|
|
1682
|
+
kind: o.TypeAlias,
|
|
1683
|
+
name: n.typeName,
|
|
1684
|
+
type: s,
|
|
1685
|
+
isExported: !0
|
|
1686
|
+
}), n.typeName);
|
|
1687
|
+
}
|
|
1688
|
+
function dr(e, t) {
|
|
1689
|
+
return [
|
|
1690
|
+
...e.pathParameters.map((e) => ({
|
|
1691
|
+
name: e.name,
|
|
1692
|
+
type: e.type,
|
|
1693
|
+
hasQuestionToken: !1,
|
|
1694
|
+
decorators: [{
|
|
1695
|
+
name: "path",
|
|
1696
|
+
arguments: [x(e.pathName)]
|
|
1697
|
+
}]
|
|
1698
|
+
})),
|
|
1699
|
+
{
|
|
1700
|
+
name: "commandRequest",
|
|
1701
|
+
hasQuestionToken: e.requestOptional,
|
|
1702
|
+
type: `CommandRequest<${t}>`,
|
|
1703
|
+
decorators: [{
|
|
1704
|
+
name: "request",
|
|
1705
|
+
arguments: []
|
|
1706
|
+
}]
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
name: "attributes",
|
|
1710
|
+
hasQuestionToken: !0,
|
|
1711
|
+
type: "Record<string, unknown>",
|
|
1712
|
+
decorators: [{
|
|
1713
|
+
name: "attribute",
|
|
1714
|
+
arguments: []
|
|
1715
|
+
}]
|
|
1716
|
+
}
|
|
1717
|
+
];
|
|
1718
|
+
}
|
|
1719
|
+
//#endregion
|
|
1720
|
+
//#region src/emitters/models.ts
|
|
1721
|
+
function fr(e) {
|
|
1722
|
+
return Dn(e, {
|
|
1723
|
+
ofKey: (e) => R(e),
|
|
1724
|
+
ofReference: Pt
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
function pr(e, t) {
|
|
1728
|
+
let n = t.modules.module(e.file);
|
|
1729
|
+
if (e.emptyMessageBody) {
|
|
1730
|
+
xn(n.add({
|
|
1731
|
+
kind: o.TypeAlias,
|
|
1732
|
+
name: e.info.name,
|
|
1733
|
+
type: "globalThis.Record<string, never>",
|
|
1734
|
+
isExported: !0
|
|
1735
|
+
}), e.docSchema, e.key, t.schemaDocs === "full");
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
new hr(e, n, t).write();
|
|
1739
|
+
}
|
|
1740
|
+
function mr(e) {
|
|
1741
|
+
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
|
|
1742
|
+
for (let r of e) {
|
|
1743
|
+
let e = _e(r), i = [e];
|
|
1744
|
+
/^\d/.test(r) || i.push(r);
|
|
1745
|
+
let a = i.find((e) => !t.has(e));
|
|
1746
|
+
for (let n = 2; a === void 0; n++) t.has(`${e}_${n}`) || (a = `${e}_${n}`);
|
|
1747
|
+
t.add(a), n.set(r, b(a));
|
|
1748
|
+
}
|
|
1749
|
+
return n;
|
|
1750
|
+
}
|
|
1751
|
+
var hr = class {
|
|
1752
|
+
model;
|
|
1753
|
+
module;
|
|
1754
|
+
target;
|
|
1755
|
+
modelInfo;
|
|
1756
|
+
components;
|
|
1757
|
+
constructor(e, t, n) {
|
|
1758
|
+
this.model = e, this.module = t, this.target = n, this.modelInfo = e.info, this.components = n.types.components, this.scope = {
|
|
1759
|
+
context: n.types,
|
|
1760
|
+
owner: e.info,
|
|
1761
|
+
specifierOf: (e) => W(t, n.outputDir, e),
|
|
1762
|
+
imports: t.imports
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1765
|
+
write() {
|
|
1766
|
+
let e = this.process();
|
|
1767
|
+
e && xn(e, this.model.docSchema, this.model.key, this.target.schemaDocs === "full");
|
|
1768
|
+
}
|
|
1769
|
+
process() {
|
|
1770
|
+
let { schema: e } = this.model;
|
|
1771
|
+
return C(e) ? this.processTypeAlias(e) : M(e) ? this.processEnum(e) : e.const !== void 0 || e.nullable && e.type || N(e) && (e.type || e.properties || e.required) ? this.processTypeAlias(e) : Be(e) ? this.processInterface(e) : Ke(e) && typeof e.additionalProperties == "object" && !Je(e) && !e.required?.length ? this.processIndexSignature(e) : Ve(e) ? this.processArray(e) : N(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
1772
|
+
}
|
|
1773
|
+
scope;
|
|
1774
|
+
emit(e) {
|
|
1775
|
+
return this.module.imports.apply(e.imports), e.text;
|
|
1776
|
+
}
|
|
1777
|
+
resolveType(e) {
|
|
1778
|
+
return this.emit(Ln(e, this.scope));
|
|
1779
|
+
}
|
|
1780
|
+
processEnum(e) {
|
|
1781
|
+
let t = ze(e);
|
|
1782
|
+
if (t) {
|
|
1783
|
+
let e = mr(Object.keys(t));
|
|
1784
|
+
this.module.add({
|
|
1785
|
+
kind: o.Enum,
|
|
1786
|
+
name: this.modelInfo.name + "EnumText",
|
|
1787
|
+
isExported: !0,
|
|
1788
|
+
members: [...e].map(([e, n]) => ({
|
|
1789
|
+
name: n,
|
|
1790
|
+
initializer: J(t[e])
|
|
1791
|
+
}))
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
let n = [...new Set(e.enum.filter((e) => typeof e == "string"))], r = mr(n);
|
|
1795
|
+
return N(e) || e.const !== void 0 || e.type !== void 0 && e.type !== "string" || e.enum.some((e) => typeof e != "string") ? (n.length && this.module.add({
|
|
1796
|
+
kind: o.VariableStatement,
|
|
1797
|
+
declarationKind: c.Const,
|
|
1798
|
+
isExported: !0,
|
|
1799
|
+
declarations: [{
|
|
1800
|
+
name: this.modelInfo.name,
|
|
1801
|
+
initializer: (e) => {
|
|
1802
|
+
e.inlineBlock(() => {
|
|
1803
|
+
for (let t of n) e.write(`${r.get(t)}: `).quote(t).write(",").newLine();
|
|
1804
|
+
}), e.write(" as const");
|
|
1805
|
+
}
|
|
1806
|
+
}]
|
|
1807
|
+
}), this.processTypeAlias(e)) : this.module.add({
|
|
1808
|
+
kind: o.Enum,
|
|
1809
|
+
name: this.modelInfo.name,
|
|
1810
|
+
isExported: !0,
|
|
1811
|
+
members: n.map((e) => ({
|
|
1812
|
+
name: r.get(e),
|
|
1813
|
+
initializer: J(e)
|
|
1814
|
+
}))
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
addPropertyToInterface(e, t, n) {
|
|
1818
|
+
let r = {
|
|
1819
|
+
name: b(t),
|
|
1820
|
+
type: this.resolveType(n),
|
|
1821
|
+
isReadonly: Xe(n)
|
|
1822
|
+
};
|
|
1823
|
+
(e.properties ??= []).push(r), bn(r, n);
|
|
1824
|
+
}
|
|
1825
|
+
processInterface(e) {
|
|
1826
|
+
if (Nn(e, this.components)) return this.processTypeAlias(e);
|
|
1827
|
+
let t = [], n = this.module.add({
|
|
1828
|
+
kind: o.Interface,
|
|
1829
|
+
name: this.modelInfo.name,
|
|
1830
|
+
isExported: !0,
|
|
1831
|
+
properties: t
|
|
1832
|
+
}), r = e.properties || {};
|
|
1833
|
+
Object.entries(r).forEach(([e, t]) => {
|
|
1834
|
+
this.addPropertyToInterface(n, e, t);
|
|
1835
|
+
});
|
|
1836
|
+
for (let n of e.required ?? []) Object.hasOwn(r, n) || t.push({
|
|
1837
|
+
name: b(n),
|
|
1838
|
+
type: this.emit(Bn(e, this.scope))
|
|
1839
|
+
});
|
|
1840
|
+
return this.emit(Rn(e, this.scope)) && t.push(mn(this.emit(zn(e, this.scope)), ["Additional properties"])), n;
|
|
1841
|
+
}
|
|
1842
|
+
processArray(e) {
|
|
1843
|
+
let t = this.resolveType(e.items);
|
|
1844
|
+
return this.module.add({
|
|
1845
|
+
kind: o.TypeAlias,
|
|
1846
|
+
name: this.modelInfo.name,
|
|
1847
|
+
type: Ge(t),
|
|
1848
|
+
isExported: !0
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
processIndexSignature(e) {
|
|
1852
|
+
return this.module.add({
|
|
1853
|
+
kind: o.Interface,
|
|
1854
|
+
name: this.modelInfo.name,
|
|
1855
|
+
isExported: !0,
|
|
1856
|
+
properties: [mn(this.emit(Vn(e, this.scope)))]
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
processComposition(e) {
|
|
1860
|
+
return this.module.add({
|
|
1861
|
+
kind: o.TypeAlias,
|
|
1862
|
+
name: this.modelInfo.name,
|
|
1863
|
+
type: this.resolveType(e),
|
|
1864
|
+
isExported: !0
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
processTypeAlias(e) {
|
|
1868
|
+
return this.module.add({
|
|
1869
|
+
kind: o.TypeAlias,
|
|
1870
|
+
name: this.modelInfo.name,
|
|
1871
|
+
type: this.resolveType(e),
|
|
1872
|
+
isExported: !0
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
}, gr = "DEFAULT_QUERY_CLIENT_OPTIONS";
|
|
1876
|
+
function _r(e, t) {
|
|
1877
|
+
let n = e.queryClient, r = t.modules.module(n.file);
|
|
1878
|
+
H(r, I, [
|
|
1879
|
+
"QueryClientFactory",
|
|
1880
|
+
"QueryClientOptions",
|
|
1881
|
+
"ResourceAttributionPathSpec"
|
|
1882
|
+
]), G(r, t.outputDir, e.context.alias, e.context.constantName), r.add({
|
|
1883
|
+
kind: o.VariableStatement,
|
|
1884
|
+
declarationKind: c.Const,
|
|
1885
|
+
declarations: [{
|
|
1886
|
+
name: gr,
|
|
1887
|
+
type: "QueryClientOptions",
|
|
1888
|
+
initializer: `{
|
|
1889
|
+
contextAlias: ${e.context.constantName},
|
|
1890
|
+
aggregateName: ${x(n.resourceName)},
|
|
1891
|
+
resourceAttribution: ${n.resourceAttribution},
|
|
1892
|
+
}`
|
|
1893
|
+
}],
|
|
1894
|
+
isExported: !1
|
|
1895
|
+
}), r.add({
|
|
1896
|
+
kind: o.Enum,
|
|
1897
|
+
name: n.eventTitlesName,
|
|
1898
|
+
isExported: !0,
|
|
1899
|
+
members: pn(n.events.map((e) => ({
|
|
1900
|
+
name: e.memberName,
|
|
1901
|
+
initializer: x(e.title)
|
|
1902
|
+
})))
|
|
1903
|
+
});
|
|
1904
|
+
for (let e of n.events) U(r, t.outputDir, e.body);
|
|
1905
|
+
r.add({
|
|
1906
|
+
kind: o.TypeAlias,
|
|
1907
|
+
isExported: !0,
|
|
1908
|
+
name: n.eventTypeName,
|
|
1909
|
+
type: n.events.map((e) => e.body.name).join(" | ") || "never"
|
|
1910
|
+
}), U(r, t.outputDir, n.state), U(r, t.outputDir, n.fields), r.add({
|
|
1911
|
+
kind: o.VariableStatement,
|
|
1912
|
+
declarationKind: c.Const,
|
|
1913
|
+
declarations: [{
|
|
1914
|
+
name: n.factoryName,
|
|
1915
|
+
initializer: `new QueryClientFactory<${n.state.name}, \`\${${n.fields.name}}\`, ${n.eventTypeName}>(${gr})`
|
|
1916
|
+
}],
|
|
1917
|
+
isExported: !0
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
//#endregion
|
|
1921
|
+
//#region src/emitters/emit.ts
|
|
1922
|
+
function vr(e, t) {
|
|
1923
|
+
e.contexts.forEach((e) => yr(e, t)), e.models.forEach((e) => pr(e, t)), e.aggregates.forEach((e) => _r(e, t)), e.aggregates.forEach((e) => lr(e, t)), e.apiClients.forEach((e) => rr(e, t));
|
|
1924
|
+
}
|
|
1925
|
+
function yr(e, t) {
|
|
1926
|
+
t.modules.module(e.file).add(`export const ${e.constantName} = ${x(e.alias)};`);
|
|
1927
|
+
}
|
|
1928
|
+
//#endregion
|
|
1929
|
+
//#region src/emitters/indexFiles.ts
|
|
1930
|
+
function br(e, t) {
|
|
1931
|
+
let n = [];
|
|
1932
|
+
return xr(e, t, n), n;
|
|
1933
|
+
}
|
|
1934
|
+
function xr(e, t, n) {
|
|
1935
|
+
let r = [];
|
|
1936
|
+
for (let t of e.getSourceFiles()) {
|
|
1937
|
+
let e = t.getBaseName();
|
|
1938
|
+
e.endsWith(".ts") && e !== "index.ts" && r.push({
|
|
1939
|
+
specifier: `./${t.getBaseNameWithoutExtension()}.js`,
|
|
1940
|
+
exports: Cr(t)
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
for (let i of e.getDirectories()) {
|
|
1944
|
+
let e = xr(i, t, n);
|
|
1945
|
+
e && r.push({
|
|
1946
|
+
specifier: `./${i.getBaseName()}/index.js`,
|
|
1947
|
+
exports: e
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
let i = e.getPath();
|
|
1951
|
+
return r.length === 0 ? e.getProject().getSourceFile(`${i}/index.ts`) ? /* @__PURE__ */ new Map() : void 0 : Sr(i, r, t, n);
|
|
1952
|
+
}
|
|
1953
|
+
function Sr(e, t, n, r) {
|
|
1954
|
+
let i = /* @__PURE__ */ new Map();
|
|
1955
|
+
for (let e of t) for (let t of e.exports.keys()) i.set(t, [...i.get(t) ?? [], e.specifier]);
|
|
1956
|
+
let a = [...i].filter(([, e]) => e.length > 1).map(([e]) => e).sort();
|
|
1957
|
+
for (let t of a) r.push(`${t} is exported by both ${i.get(t).join(" and ")} in ${e}; its index leaves it out, so import it from its own module.`);
|
|
1958
|
+
let o = n(e);
|
|
1959
|
+
o.removeText();
|
|
1960
|
+
let s = /* @__PURE__ */ new Map();
|
|
1961
|
+
for (let e of t) {
|
|
1962
|
+
let t = [...e.exports].filter(([e]) => !a.includes(e)).sort(([e], [t]) => S(e, t));
|
|
1963
|
+
t.forEach(([e, t]) => s.set(e, t)), t.length === e.exports.size ? o.addExportDeclaration({ moduleSpecifier: e.specifier }) : t.length > 0 && o.addExportDeclaration({
|
|
1964
|
+
moduleSpecifier: e.specifier,
|
|
1965
|
+
namedExports: t.map(([e, t]) => ({
|
|
1966
|
+
name: e,
|
|
1967
|
+
isTypeOnly: t
|
|
1968
|
+
}))
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
return o.getStatements().length === 0 && o.addStatements("export {};"), s;
|
|
1972
|
+
}
|
|
1973
|
+
function Cr(e) {
|
|
1974
|
+
let t = /* @__PURE__ */ new Map();
|
|
1975
|
+
for (let [r, i] of e.getExportedDeclarations()) t.set(r, i.every((e) => n.isInterfaceDeclaration(e) || n.isTypeAliasDeclaration(e)));
|
|
1976
|
+
return t;
|
|
1977
|
+
}
|
|
1978
|
+
//#endregion
|
|
1979
|
+
//#region src/finalize/typeOnlyImports.ts
|
|
1980
|
+
function wr(e) {
|
|
1981
|
+
let t = e;
|
|
1982
|
+
for (let e = t.getParent(); e; t = e, e = e.getParent()) {
|
|
1983
|
+
if (n.isQualifiedName(e)) {
|
|
1984
|
+
if (e.getLeft() !== t) return !1;
|
|
1985
|
+
continue;
|
|
1986
|
+
}
|
|
1987
|
+
if (n.isPropertyAccessExpression(e)) {
|
|
1988
|
+
if (e.getExpression() !== t) return !1;
|
|
1989
|
+
continue;
|
|
1990
|
+
}
|
|
1991
|
+
if (n.isExpressionWithTypeArguments(e)) {
|
|
1992
|
+
let t = e.getParent(), r = t?.getParent();
|
|
1993
|
+
return !(n.isHeritageClause(t) && t.getToken() === s.ExtendsKeyword && (n.isClassDeclaration(r) || n.isClassExpression(r)));
|
|
1994
|
+
}
|
|
1995
|
+
return n.isTypeNode(e);
|
|
1996
|
+
}
|
|
1997
|
+
return !1;
|
|
1998
|
+
}
|
|
1999
|
+
function Tr(e) {
|
|
2000
|
+
let t = e.getImportDeclarations().filter((e) => !e.getDefaultImport() && !e.getNamespaceImport() && e.getNamedImports().length > 0);
|
|
2001
|
+
if (t.length === 0) return [];
|
|
2002
|
+
let r = new Set(t.flatMap((e) => e.getNamedImports().map((e) => (e.getAliasNode() ?? e.getNameNode()).getText()))), i = /* @__PURE__ */ new Set();
|
|
2003
|
+
return e.forEachDescendant((e, t) => {
|
|
2004
|
+
if (n.isImportDeclaration(e)) {
|
|
2005
|
+
t.skip();
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
if (n.isIdentifier(e) && r.has(e.getText()) && !wr(e)) {
|
|
2009
|
+
let t = e.getSymbol();
|
|
2010
|
+
t && i.add(t.compilerSymbol);
|
|
2011
|
+
}
|
|
2012
|
+
}), t.map((e) => Er(e, (e) => {
|
|
2013
|
+
let t = e.getSymbol();
|
|
2014
|
+
return !!t && !i.has(t.compilerSymbol);
|
|
2015
|
+
}));
|
|
2016
|
+
}
|
|
2017
|
+
function Er(e, t) {
|
|
2018
|
+
let n = e.getNamedImports(), r = n.map(t), i = r.every(Boolean);
|
|
2019
|
+
return () => {
|
|
2020
|
+
n.forEach((e, t) => {
|
|
2021
|
+
let n = !i && r[t];
|
|
2022
|
+
e.isTypeOnly() !== n && e.setIsTypeOnly(n);
|
|
2023
|
+
}), e.isTypeOnly() !== i && e.setIsTypeOnly(i);
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
function Dr(e) {
|
|
2027
|
+
let t = e.flatMap(Tr);
|
|
2028
|
+
for (let e of t) e();
|
|
2029
|
+
}
|
|
2030
|
+
//#endregion
|
|
2031
|
+
//#region src/finalize/verification.ts
|
|
2032
|
+
var Or = /* @__PURE__ */ new Set([
|
|
2033
|
+
2300,
|
|
2034
|
+
2304,
|
|
2035
|
+
2308,
|
|
2036
|
+
2393,
|
|
2037
|
+
2451,
|
|
2038
|
+
2456,
|
|
2039
|
+
2503,
|
|
2040
|
+
2552
|
|
2041
|
+
]);
|
|
2042
|
+
function kr(e) {
|
|
2043
|
+
let t = [];
|
|
2044
|
+
for (let n of e) for (let e of n.getPreEmitDiagnostics()) {
|
|
2045
|
+
if (!Or.has(e.getCode()) || e.getSourceFile() !== n) continue;
|
|
2046
|
+
let r = l.flattenDiagnosticMessageText(e.compilerObject.messageText, " ");
|
|
2047
|
+
t.push(`${n.getFilePath()}:${e.getLineNumber() ?? 0} TS${e.getCode()} ${r}`);
|
|
2048
|
+
}
|
|
2049
|
+
if (t.length > 0) throw Error(`The generated code does not compile; nothing was written. This is a wow-generator bug:\n${t.join("\n")}`);
|
|
2050
|
+
}
|
|
2051
|
+
//#endregion
|
|
2052
|
+
//#region src/finalize/finalize.ts
|
|
2053
|
+
var Ar = "// Code generated by wow-generator. DO NOT EDIT.\n\n", jr = {
|
|
2054
|
+
indentSize: 2,
|
|
2055
|
+
tabSize: 2,
|
|
2056
|
+
convertTabsToSpaces: !0,
|
|
2057
|
+
semicolons: "insert",
|
|
2058
|
+
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: !0
|
|
2059
|
+
};
|
|
2060
|
+
function Mr(e, t) {
|
|
2061
|
+
e.forEach((n, r) => {
|
|
2062
|
+
t.debug(`Optimizing file [${n.getFilePath()}] - ${r + 1}/${e.length}`), n.formatText(jr), n.organizeImports(jr);
|
|
2063
|
+
}), Dr(e), kr(e);
|
|
2064
|
+
for (let t of e) t.insertText(0, Ar);
|
|
2065
|
+
}
|
|
2066
|
+
//#endregion
|
|
2067
|
+
//#region src/input/resources.ts
|
|
2068
|
+
var Nr = 3e4;
|
|
2069
|
+
function Pr(e) {
|
|
2070
|
+
return /^https?:\/\//i.test(e);
|
|
2071
|
+
}
|
|
2072
|
+
function Fr(e, t = {}) {
|
|
2073
|
+
return Pr(e) ? Ir(e, t) : Rr(e);
|
|
2074
|
+
}
|
|
2075
|
+
async function Ir(e, t = {}) {
|
|
2076
|
+
let n = t.timeoutMs ?? 3e4, r;
|
|
2077
|
+
try {
|
|
2078
|
+
let i = AbortSignal.timeout(n);
|
|
2079
|
+
r = await fetch(e, {
|
|
2080
|
+
headers: t.headers,
|
|
2081
|
+
signal: t.signal ? AbortSignal.any([t.signal, i]) : i
|
|
2082
|
+
});
|
|
2083
|
+
} catch (e) {
|
|
2084
|
+
let t = e instanceof Error && e.name === "TimeoutError" ? `no response within ${n} ms` : Lr(e);
|
|
2085
|
+
throw Error(t, { cause: e });
|
|
2086
|
+
}
|
|
2087
|
+
if (!r.ok) {
|
|
2088
|
+
let e = [r.status, r.statusText].filter(Boolean).join(" ");
|
|
2089
|
+
throw Error(`HTTP ${e}`);
|
|
2090
|
+
}
|
|
2091
|
+
return await r.text();
|
|
2092
|
+
}
|
|
2093
|
+
function Lr(e) {
|
|
2094
|
+
if (!(e instanceof Error)) return String(e);
|
|
2095
|
+
let t = e.cause;
|
|
2096
|
+
return t instanceof Error && t.message ? `${e.message} (${t.message})` : e.message;
|
|
2097
|
+
}
|
|
2098
|
+
function Rr(e) {
|
|
2099
|
+
return new Promise((t, n) => {
|
|
2100
|
+
te(e, "utf-8", (e, r) => {
|
|
2101
|
+
e ? n(e) : t(r);
|
|
2102
|
+
});
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
//#endregion
|
|
2106
|
+
//#region src/input/parsers.ts
|
|
2107
|
+
async function zr(e, t) {
|
|
2108
|
+
let n;
|
|
2109
|
+
try {
|
|
2110
|
+
n = await Fr(e, t);
|
|
2111
|
+
} catch (t) {
|
|
2112
|
+
throw new g("input", `Cannot read the OpenAPI document ${e}: ${_(t)}`, { cause: t });
|
|
2113
|
+
}
|
|
2114
|
+
let r;
|
|
2115
|
+
try {
|
|
2116
|
+
r = Vr(n);
|
|
2117
|
+
} catch (t) {
|
|
2118
|
+
throw new g("input", `Cannot parse the OpenAPI document ${e}: ${_(t)}`, { cause: t });
|
|
2119
|
+
}
|
|
2120
|
+
return Br(r, e);
|
|
2121
|
+
}
|
|
2122
|
+
function Br(e, t) {
|
|
2123
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new g("input", `${t} is not an OpenAPI document: expected an object at the top level.`);
|
|
2124
|
+
let n = e;
|
|
2125
|
+
if (n.swagger !== void 0) throw new g("input", `${t} is a Swagger ${String(n.swagger)} document; wow-generator reads OpenAPI 3.x only. Convert it first, for example with swagger2openapi.`);
|
|
2126
|
+
if (typeof n.openapi != "string" || !/^3\.\d+/.test(n.openapi)) throw new g("input", `${t} is not an OpenAPI 3.x document: its "openapi" field is ${n.openapi === void 0 ? "missing" : JSON.stringify(n.openapi)}.`);
|
|
2127
|
+
if (typeof n.info != "object" || n.info === null || Array.isArray(n.info)) throw new g("input", `${t} is not a valid OpenAPI document: its "info" object is missing.`);
|
|
2128
|
+
return {
|
|
2129
|
+
...n,
|
|
2130
|
+
paths: n.paths ?? {}
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
function Vr(e) {
|
|
2134
|
+
switch (Hr(e)) {
|
|
2135
|
+
case "json": return JSON.parse(e);
|
|
2136
|
+
case "yaml": return ee(e);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
function Hr(e) {
|
|
2140
|
+
let t = e.trimStart();
|
|
2141
|
+
if (t.startsWith("{") || t.startsWith("[")) return "json";
|
|
2142
|
+
if (t.startsWith("-") || t.startsWith("%YAML")) return "yaml";
|
|
2143
|
+
try {
|
|
2144
|
+
return JSON.parse(t), "json";
|
|
2145
|
+
} catch {
|
|
2146
|
+
if (t.length > 0) return "yaml";
|
|
2147
|
+
}
|
|
2148
|
+
throw Error("Unable to infer file format");
|
|
2149
|
+
}
|
|
2150
|
+
//#endregion
|
|
2151
|
+
//#region src/input/configuration.ts
|
|
2152
|
+
var Ur = "./fetcher-generator.config.json";
|
|
2153
|
+
async function Wr(e, t, n) {
|
|
2154
|
+
if (e !== void 0) return {
|
|
2155
|
+
...await qr({
|
|
2156
|
+
path: e,
|
|
2157
|
+
explicit: !0
|
|
2158
|
+
}, t, n),
|
|
2159
|
+
origin: X(e)
|
|
2160
|
+
};
|
|
2161
|
+
for (let e of [h, Ur]) {
|
|
2162
|
+
let r = await qr({
|
|
2163
|
+
path: e,
|
|
2164
|
+
explicit: !1
|
|
2165
|
+
}, t, n);
|
|
2166
|
+
if (r === void 0) continue;
|
|
2167
|
+
let i = [...r.warnings];
|
|
2168
|
+
return e === "./fetcher-generator.config.json" && i.push(`${X(e)} uses the deprecated name; rename it to ${h.slice(2)}. The old name is no longer read from v10.`), {
|
|
2169
|
+
config: r.config,
|
|
2170
|
+
origin: X(e),
|
|
2171
|
+
warnings: i
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
return t.debug("No configuration file found, generating with defaults"), {
|
|
2175
|
+
config: {},
|
|
2176
|
+
warnings: []
|
|
2177
|
+
};
|
|
2178
|
+
}
|
|
2179
|
+
var Gr = ["apiClients"], Kr = ["ignorePathParameters", "methodNames"];
|
|
2180
|
+
async function qr(e, t, n) {
|
|
2181
|
+
let r = X(e.path);
|
|
2182
|
+
t.debug(`Reading configuration: ${r}`);
|
|
2183
|
+
let i;
|
|
2184
|
+
try {
|
|
2185
|
+
i = await Fr(e.path, n);
|
|
2186
|
+
} catch (n) {
|
|
2187
|
+
if (!e.explicit && Jr(n)) {
|
|
2188
|
+
t.debug(`No configuration file at ${r}`);
|
|
2189
|
+
return;
|
|
2190
|
+
}
|
|
2191
|
+
throw new g("configuration", `Cannot read configuration ${r}: ${_(n)}`, { cause: n });
|
|
2192
|
+
}
|
|
2193
|
+
if (!i.trim()) return {
|
|
2194
|
+
config: {},
|
|
2195
|
+
warnings: [`Configuration ${r} is empty, generating with defaults`]
|
|
2196
|
+
};
|
|
2197
|
+
let a;
|
|
2198
|
+
try {
|
|
2199
|
+
a = Vr(i);
|
|
2200
|
+
} catch (e) {
|
|
2201
|
+
throw new g("configuration", `Cannot parse configuration ${r}: ${_(e)}`, { cause: e });
|
|
2202
|
+
}
|
|
2203
|
+
let o = Xr(a, r);
|
|
2204
|
+
return t.debug(`Configuration loaded from ${r}: ${Qr(o.config)}`), o;
|
|
2205
|
+
}
|
|
2206
|
+
function X(e) {
|
|
2207
|
+
return Pr(e) || u(e) ? e : p(e);
|
|
2208
|
+
}
|
|
2209
|
+
function Jr(e) {
|
|
2210
|
+
return typeof e == "object" && !!e && e.code === "ENOENT";
|
|
2211
|
+
}
|
|
2212
|
+
function Z(e) {
|
|
2213
|
+
return e === null ? "null" : Array.isArray(e) ? "an array" : `a ${typeof e}`;
|
|
2214
|
+
}
|
|
2215
|
+
function Q(e) {
|
|
2216
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
2217
|
+
}
|
|
2218
|
+
function Yr(e, t, n, r, i) {
|
|
2219
|
+
let a = Object.keys(r).filter((e) => !i.includes(e));
|
|
2220
|
+
a.length && e.push(`Ignoring unknown ${n} option(s) in ${t}: ${a.join(", ")}. Known option(s): ${i.join(", ")}`);
|
|
2221
|
+
}
|
|
2222
|
+
function Xr(e, t) {
|
|
2223
|
+
if (!Q(e)) throw new g("configuration", `Configuration ${t} must be a JSON or YAML object, found ${Z(e)}`);
|
|
2224
|
+
let n = [];
|
|
2225
|
+
return Yr(n, t, "configuration", e, Gr), Zr(e.apiClients, t, n), {
|
|
2226
|
+
config: e,
|
|
2227
|
+
warnings: n
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
function Zr(e, t, n) {
|
|
2231
|
+
if (e !== void 0) {
|
|
2232
|
+
if (!Q(e)) throw new g("configuration", `apiClients in ${t} must be an object keyed by tag name, found ${Z(e)}`);
|
|
2233
|
+
for (let [r, i] of Object.entries(e)) {
|
|
2234
|
+
if (!Q(i)) throw new g("configuration", `apiClients["${r}"] in ${t} must be an object, found ${Z(i)}`);
|
|
2235
|
+
Yr(n, t, `apiClients["${r}"]`, i, Kr);
|
|
2236
|
+
let { ignorePathParameters: e } = i;
|
|
2237
|
+
if (e !== void 0 && !(Array.isArray(e) && e.every((e) => typeof e == "string"))) throw new g("configuration", `apiClients["${r}"].ignorePathParameters in ${t} must be an array of strings, found ${Z(e)}`);
|
|
2238
|
+
let { methodNames: a } = i;
|
|
2239
|
+
if (a !== void 0) {
|
|
2240
|
+
if (!Q(a)) throw new g("configuration", `apiClients["${r}"].methodNames in ${t} must be an object mapping operationIds to method names, found ${Z(a)}`);
|
|
2241
|
+
for (let [e, n] of Object.entries(a)) if (typeof n != "string" || !v(n)) throw new g("configuration", `apiClients["${r}"].methodNames["${e}"] in ${t} must be a valid method name, found ${JSON.stringify(n)}`);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
function Qr(e) {
|
|
2247
|
+
let t = Object.keys(e.apiClients ?? {});
|
|
2248
|
+
return `apiClients=${t.length ? t.join(", ") : "none"}`;
|
|
2249
|
+
}
|
|
2250
|
+
//#endregion
|
|
2251
|
+
//#region src/openapi/document.ts
|
|
2252
|
+
function $r(e) {
|
|
2253
|
+
return {
|
|
2254
|
+
openAPI: e,
|
|
2255
|
+
components: e.components,
|
|
2256
|
+
endpoints: et(e.paths, e.components)
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
//#endregion
|
|
2260
|
+
//#region src/output/outputStore.ts
|
|
2261
|
+
var ei = ".wow-generator.json", ti = ".fetcher-generator.json", ni = class e {
|
|
2262
|
+
project;
|
|
2263
|
+
outputPath;
|
|
2264
|
+
outputDir;
|
|
2265
|
+
previous;
|
|
2266
|
+
legacyManifest;
|
|
2267
|
+
written = /* @__PURE__ */ new Set();
|
|
2268
|
+
stale = /* @__PURE__ */ new Set();
|
|
2269
|
+
constructor(e, t, n, r, i) {
|
|
2270
|
+
this.project = e, this.outputPath = t, this.outputDir = n, this.previous = r, this.legacyManifest = i;
|
|
2271
|
+
}
|
|
2272
|
+
static open(t, n, r) {
|
|
2273
|
+
let i = t.getFileSystem(), a = n;
|
|
2274
|
+
n = p(i.getCurrentDirectory(), n);
|
|
2275
|
+
let o = d(n, ti), s = i.fileExistsSync(o) ? o : void 0, c = d(n, ei);
|
|
2276
|
+
!i.fileExistsSync(c) && s && (c = s);
|
|
2277
|
+
let l = /* @__PURE__ */ new Map();
|
|
2278
|
+
if (i.fileExistsSync(c)) {
|
|
2279
|
+
let e = ri(c, i.readFileSync(c));
|
|
2280
|
+
for (let [t, r] of Object.entries(e.files)) {
|
|
2281
|
+
let e = p(n, t);
|
|
2282
|
+
if (oi(n, e), u(t) || !t.endsWith(".ts") || typeof r != "string" || !/^[a-f0-9]{64}$/.test(r)) throw new g("output", `Invalid generated file entry in ${c}: ${t}`);
|
|
2283
|
+
l.set(e, r);
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
let f = /* @__PURE__ */ new Set([...r?.written ?? [], ...l.keys()]);
|
|
2287
|
+
for (let e of t.getSourceFiles()) f.has(e.getFilePath()) && e.forget();
|
|
2288
|
+
return new e(t, a, n, l, s);
|
|
2289
|
+
}
|
|
2290
|
+
get files() {
|
|
2291
|
+
return this.written;
|
|
2292
|
+
}
|
|
2293
|
+
claim(e, t = this.outputPath) {
|
|
2294
|
+
let n = B(t, e);
|
|
2295
|
+
oi(t, n);
|
|
2296
|
+
let r = this.project.getSourceFile(n) ?? this.project.createSourceFile(n, "", { overwrite: !0 }), i = r.getFilePath();
|
|
2297
|
+
return this.written.has(i) || (r.removeText(), this.written.add(i)), r;
|
|
2298
|
+
}
|
|
2299
|
+
forgetStale() {
|
|
2300
|
+
for (let [e, t] of this.previous) !this.written.has(e) && this.isUnchanged(e, t) && this.stale.add(e);
|
|
2301
|
+
for (let e of this.project.getSourceFiles()) this.stale.has(e.getFilePath()) && e.forget();
|
|
2302
|
+
}
|
|
2303
|
+
async commit(e) {
|
|
2304
|
+
e?.throwIfAborted();
|
|
2305
|
+
let t = this.project.getFileSystem(), n = new Set([...this.written].map((e) => e.toLowerCase()));
|
|
2306
|
+
for (let e of this.stale) !this.written.has(e) && n.has(e.toLowerCase()) && this.isUnchanged(e, this.previous.get(e)) && (await $("delete", e, () => t.delete(e)), this.stale.delete(e));
|
|
2307
|
+
let r = [...this.written].sort().map((e) => this.project.getSourceFileOrThrow(e));
|
|
2308
|
+
(await Promise.allSettled(r.map((e) => e.save()))).forEach((e, t) => {
|
|
2309
|
+
if (e.status === "rejected") throw ai("write", r[t].getFilePath(), e.reason);
|
|
2310
|
+
}), e?.throwIfAborted();
|
|
2311
|
+
for (let e of this.stale) !this.written.has(e) && this.isUnchanged(e, this.previous.get(e)) && await $("delete", e, () => t.delete(e));
|
|
2312
|
+
let i = d(this.outputDir, ei), a = JSON.stringify({
|
|
2313
|
+
version: 1,
|
|
2314
|
+
files: Object.fromEntries(r.map((e) => [f(this.outputDir, e.getFilePath()).split(m).join("/"), ii(t.readFileSync(e.getFilePath()))]))
|
|
2315
|
+
}, null, 2) + "\n";
|
|
2316
|
+
await $("write", i, async () => {
|
|
2317
|
+
t.mkdirSync(this.outputDir), await t.writeFile(i, a);
|
|
2318
|
+
});
|
|
2319
|
+
let o = this.legacyManifest;
|
|
2320
|
+
o && t.fileExistsSync(o) && await $("delete", o, () => t.delete(o));
|
|
2321
|
+
}
|
|
2322
|
+
isUnchanged(e, t) {
|
|
2323
|
+
let n = this.project.getFileSystem();
|
|
2324
|
+
return n.fileExistsSync(e) ? (oi(n.realpathSync(this.outputDir), n.realpathSync(e)), ii(n.readFileSync(e)) === t) : !1;
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
function ri(e, t) {
|
|
2328
|
+
let n = "delete it; without it this run cannot remove the stale files of the last run", r;
|
|
2329
|
+
try {
|
|
2330
|
+
r = JSON.parse(t);
|
|
2331
|
+
} catch (t) {
|
|
2332
|
+
throw new g("output", `Cannot parse the generation manifest ${e}: ${_(t)}. Resolve the merge conflict in it if it has one, or ${n}.`, { cause: t });
|
|
2333
|
+
}
|
|
2334
|
+
let i = r?.version;
|
|
2335
|
+
if (typeof i == "number" && Number.isInteger(i) && i > 1) throw new g("output", `The generation manifest ${e} was written by a newer wow-generator (manifest version ${i}); this one reads version 1. Upgrade wow-generator.`);
|
|
2336
|
+
if (i !== 1 || !r.files || typeof r.files != "object" || Array.isArray(r.files)) throw new g("output", `Invalid generation manifest ${e}: expected "version": 1 and a "files" object. Restore it from version control, or ${n}.`);
|
|
2337
|
+
return r;
|
|
2338
|
+
}
|
|
2339
|
+
function ii(e) {
|
|
2340
|
+
if (!l.sys.createSHA256Hash) throw Error("SHA-256 hashing is unavailable in this environment.");
|
|
2341
|
+
return l.sys.createSHA256Hash(e);
|
|
2342
|
+
}
|
|
2343
|
+
function ai(e, t, n) {
|
|
2344
|
+
return n instanceof g ? n : new g("output", `Cannot ${e} ${t}: ${_(n)}`, { cause: n });
|
|
2345
|
+
}
|
|
2346
|
+
async function $(e, t, n) {
|
|
2347
|
+
try {
|
|
2348
|
+
await n();
|
|
2349
|
+
} catch (n) {
|
|
2350
|
+
throw ai(e, t, n);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
function oi(e, t) {
|
|
2354
|
+
let n = t.split("/").join(m), r = p(e), i = p(n), a = f(r, i);
|
|
2355
|
+
if (a === "" || a.startsWith("..") || u(a)) throw new g("output", `Path traversal detected: "${t}" resolves outside the output directory "${e}".`);
|
|
2356
|
+
}
|
|
2357
|
+
//#endregion
|
|
2358
|
+
//#region src/wow/resolveWowModel.ts
|
|
2359
|
+
function si(e) {
|
|
2360
|
+
let { openAPI: t, components: n, endpoints: r } = e, i = [], a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = t.tags ?? [], c = new Set(s.map((e) => e.name)), l = new Set(r.flatMap((e) => e.operation.tags ?? []).filter((e) => !c.has(e))), u = /* @__PURE__ */ new Map();
|
|
2361
|
+
for (let e of [...s, ...[...l].map((e) => ({ name: e }))]) {
|
|
2362
|
+
let t = pt(e);
|
|
2363
|
+
t && u.set(e.name, {
|
|
2364
|
+
aggregate: t,
|
|
2365
|
+
commands: /* @__PURE__ */ new Map(),
|
|
2366
|
+
events: /* @__PURE__ */ new Map()
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
let d = (e) => (e.tags ?? []).flatMap((e) => {
|
|
2370
|
+
let t = u.get(e);
|
|
2371
|
+
return t ? (o.add(e), [t]) : [];
|
|
2372
|
+
}), f = (e, t, n) => {
|
|
2373
|
+
let r = a.get(e.key);
|
|
2374
|
+
r || (r = {}, a.set(e.key, r));
|
|
2375
|
+
let i = t in r ? r[t] : e.schema[t];
|
|
2376
|
+
r[t] = i || n;
|
|
2377
|
+
}, p = (e, t) => new g("specification", `Cannot read the Wow metadata of ${e.operationId}: ${t}. wow-generator reads documents from Wow ${lt} or later.`), m = (e, t) => {
|
|
2378
|
+
let n = vt.exec(t)?.[1];
|
|
2379
|
+
n && e.forEach((e) => {
|
|
2380
|
+
e.resourceName ??= n;
|
|
2381
|
+
});
|
|
2382
|
+
}, ee = (e) => {
|
|
2383
|
+
let { operation: t, path: r } = e;
|
|
2384
|
+
if (t.operationId === "wow.command.send") return;
|
|
2385
|
+
let a = mt(t.operationId);
|
|
2386
|
+
if (!a) return;
|
|
2387
|
+
let o = F(t), s = /* @__PURE__ */ new Set();
|
|
2388
|
+
for (; o && C(o) && o.$ref !== "#/components/responses/wow.CommandOk";) {
|
|
2389
|
+
if (!o.$ref.startsWith(T)) return;
|
|
2390
|
+
if (s.has(o.$ref)) throw new g("specification", `Cyclic component reference: ${o.$ref}`);
|
|
2391
|
+
s.add(o.$ref), o = n?.responses?.[o.$ref.slice(T.length)];
|
|
2392
|
+
}
|
|
2393
|
+
if (!o || !C(o) || o.$ref !== "#/components/responses/wow.CommandOk") return;
|
|
2394
|
+
let c = d(t);
|
|
2395
|
+
if (!t.requestBody) return;
|
|
2396
|
+
let l = at(t, n ?? {}), u = (C(t.requestBody) ? Ee(t.requestBody, n ?? {}) : t.requestBody)?.content?.[k]?.schema;
|
|
2397
|
+
if (!C(u)) {
|
|
2398
|
+
c.length > 0 && i.push(`Skipping command ${t.operationId} (${e.method.toUpperCase()} ${r}): its application/json request body is not a $ref to a component schema.`);
|
|
2399
|
+
return;
|
|
2400
|
+
}
|
|
2401
|
+
let p = O(u, n ?? {});
|
|
2402
|
+
if (!p.schema) return;
|
|
2403
|
+
f(p, "title", t.summary), f(p, "description", t.description);
|
|
2404
|
+
let m = {
|
|
2405
|
+
name: a,
|
|
2406
|
+
method: e.method,
|
|
2407
|
+
path: r,
|
|
2408
|
+
pathParameters: l,
|
|
2409
|
+
summary: t.summary,
|
|
2410
|
+
description: t.description,
|
|
2411
|
+
schema: p,
|
|
2412
|
+
operation: t
|
|
2413
|
+
};
|
|
2414
|
+
c.forEach((e) => {
|
|
2415
|
+
e.commands.set(a, m);
|
|
2416
|
+
});
|
|
2417
|
+
}, te = ({ operation: e, path: t }) => {
|
|
2418
|
+
if (!e.operationId?.endsWith(".snapshot_state.single")) return;
|
|
2419
|
+
let r = d(e);
|
|
2420
|
+
m(r, t);
|
|
2421
|
+
let i = rt(e, n);
|
|
2422
|
+
if (!C(i)) {
|
|
2423
|
+
if (r.length > 0) throw p(e, "its 200 application/json response is not a $ref to the state schema");
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
let a = O(i, n);
|
|
2427
|
+
r.forEach((e) => {
|
|
2428
|
+
e.state = a;
|
|
2429
|
+
});
|
|
2430
|
+
}, h = ({ operation: e }) => {
|
|
2431
|
+
if (!n || !e.operationId?.endsWith(".event.list_query")) return;
|
|
2432
|
+
let t = d(e);
|
|
2433
|
+
if (t.length === 0) return;
|
|
2434
|
+
let r = rt(e, n);
|
|
2435
|
+
if (C(r)) return;
|
|
2436
|
+
let i = r?.items;
|
|
2437
|
+
if (!C(i)) throw p(e, "its 200 application/json response is not an array of a $ref to the event stream schema");
|
|
2438
|
+
let a = ci(D(i, n), [
|
|
2439
|
+
"properties",
|
|
2440
|
+
"body",
|
|
2441
|
+
"items",
|
|
2442
|
+
"anyOf"
|
|
2443
|
+
]);
|
|
2444
|
+
if (!Array.isArray(a)) throw p(e, `the event stream schema ${i.$ref} has no properties.body.items.anyOf listing the domain events`);
|
|
2445
|
+
let o = a.map((t, r) => {
|
|
2446
|
+
let a = ci(t, [
|
|
2447
|
+
"properties",
|
|
2448
|
+
"name",
|
|
2449
|
+
"const"
|
|
2450
|
+
]), o = ci(t, ["properties", "body"]);
|
|
2451
|
+
if (typeof a != "string" || !C(o)) throw p(e, `domain event ${r} of ${i.$ref} needs a properties.name.const and a properties.body that is a $ref to the event schema`);
|
|
2452
|
+
let s = O(o, n);
|
|
2453
|
+
return f(s, "title", t.title), {
|
|
2454
|
+
title: t.title ?? a,
|
|
2455
|
+
name: a,
|
|
2456
|
+
schema: s
|
|
2457
|
+
};
|
|
2458
|
+
});
|
|
2459
|
+
t.forEach((e) => {
|
|
2460
|
+
o.forEach((t) => {
|
|
2461
|
+
e.events.set(t.name, t);
|
|
2462
|
+
});
|
|
2463
|
+
});
|
|
2464
|
+
}, ne = ({ operation: e, path: t }) => {
|
|
2465
|
+
if (!n || !e.operationId?.endsWith(".snapshot.count")) return;
|
|
2466
|
+
let r = d(e);
|
|
2467
|
+
if (r.length === 0) return;
|
|
2468
|
+
m(r, t);
|
|
2469
|
+
let i = e.requestBody ? C(e.requestBody) ? Ee(e.requestBody, n) : e.requestBody : void 0;
|
|
2470
|
+
if (!i) throw p(e, "it has no request body");
|
|
2471
|
+
let a = i[_t], o;
|
|
2472
|
+
if (a !== void 0) {
|
|
2473
|
+
if (!C(a)) throw p(e, `${_t} must be a schema reference`);
|
|
2474
|
+
o = a;
|
|
2475
|
+
} else {
|
|
2476
|
+
let t = i.content?.[k]?.schema, r = (C(t) ? D(t, n) : void 0)?.properties?.field;
|
|
2477
|
+
if (!C(r)) throw p(e, `its request body has no ${_t}, and its condition schema has no field $ref to read the query fields from`);
|
|
2478
|
+
o = r;
|
|
2479
|
+
}
|
|
2480
|
+
let s = O(o, n);
|
|
2481
|
+
r.forEach((e) => {
|
|
2482
|
+
e.fields = s;
|
|
2483
|
+
});
|
|
2484
|
+
};
|
|
2485
|
+
for (let e of r) ee(e), te(e), h(e), ne(e);
|
|
2486
|
+
let _ = /* @__PURE__ */ new Map();
|
|
2487
|
+
for (let [e, t] of u) {
|
|
2488
|
+
if (!t.state || !t.fields) {
|
|
2489
|
+
if (o.has(e)) {
|
|
2490
|
+
let n = [t.state ? void 0 : `${e}${ht}`, t.fields ? void 0 : `${e}${gt}`].filter(Boolean);
|
|
2491
|
+
i.push(`Skipping aggregate ${e}: the document has no ${n.join(" or ")} operation, so it generates neither command nor query clients for it.`);
|
|
2492
|
+
}
|
|
2493
|
+
continue;
|
|
2494
|
+
}
|
|
2495
|
+
let n = t.aggregate.contextAlias, r = _.get(n);
|
|
2496
|
+
r || (r = /* @__PURE__ */ new Set(), _.set(n, r)), r.add({
|
|
2497
|
+
...t,
|
|
2498
|
+
resourceName: t.resourceName ?? t.aggregate.aggregateName
|
|
2499
|
+
});
|
|
2500
|
+
}
|
|
2501
|
+
return {
|
|
2502
|
+
contextAlias: dt(t),
|
|
2503
|
+
contexts: _,
|
|
2504
|
+
aggregateTags: o,
|
|
2505
|
+
schemaDocOverrides: a,
|
|
2506
|
+
warnings: i
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
function ci(e, t) {
|
|
2510
|
+
let n = e;
|
|
2511
|
+
for (let e of t) {
|
|
2512
|
+
if (typeof n != "object" || !n) return;
|
|
2513
|
+
n = n[e];
|
|
2514
|
+
}
|
|
2515
|
+
return n;
|
|
2516
|
+
}
|
|
2517
|
+
//#endregion
|
|
2518
|
+
//#region src/pipeline/seams.ts
|
|
2519
|
+
var li = Symbol("project"), ui = Symbol("signal"), di = class {
|
|
2520
|
+
options;
|
|
2521
|
+
project;
|
|
2522
|
+
logger;
|
|
2523
|
+
signal;
|
|
2524
|
+
output;
|
|
2525
|
+
constructor(e) {
|
|
2526
|
+
this.options = e, this.logger = e.logger ?? new ie(), this.signal = e[ui], this.project = e[li] ?? fi(e.tsConfigFilePath), this.project.manipulationSettings.set({
|
|
2527
|
+
indentationText: t.TwoSpaces,
|
|
2528
|
+
quoteKind: i.Single,
|
|
2529
|
+
useTrailingCommas: !0
|
|
2530
|
+
}), this.logger.debug(`Project instance created with tsConfigFilePath: ${this.options.tsConfigFilePath}`);
|
|
2531
|
+
}
|
|
2532
|
+
async generate() {
|
|
2533
|
+
let { logger: e, signal: t, options: n } = this, r = 0, i = (t) => {
|
|
2534
|
+
for (let n of t) r++, e.warn(n);
|
|
2535
|
+
};
|
|
2536
|
+
e.debug("Starting code generation from OpenAPI specification"), e.debug(`Work directory: ${process.cwd()}`), e.debug(`Input path: ${n.inputPath}`), e.debug(`Output directory: ${n.outputDir}`);
|
|
2537
|
+
let a = {
|
|
2538
|
+
headers: n.headers,
|
|
2539
|
+
timeoutMs: n.timeoutMs,
|
|
2540
|
+
signal: t
|
|
2541
|
+
}, o = await Wr(n.configPath, e, a);
|
|
2542
|
+
i(o.warnings), t?.throwIfAborted(), e.debug("Parsing OpenAPI specification");
|
|
2543
|
+
let s = await zr(n.inputPath, a);
|
|
2544
|
+
t?.throwIfAborted(), e.debug("OpenAPI specification parsed successfully");
|
|
2545
|
+
let c = be(s);
|
|
2546
|
+
if (c.length > 0) throw new g("specification", `${n.inputPath} has ${c.length} $ref(s) that point at nothing: ${c.slice(0, 10).map(({ ref: e, location: t }) => `${e} (at ${t})`).join(", ")}${c.length > 10 ? ", …" : ""}`);
|
|
2547
|
+
let l = $r(s);
|
|
2548
|
+
e.debug("Resolving bounded context aggregates");
|
|
2549
|
+
let u = si(l);
|
|
2550
|
+
i(u.warnings), e.debug(`Resolved ${u.contexts.size} bounded context aggregates`);
|
|
2551
|
+
let d = ni.open(this.project, n.outputDir, this.output);
|
|
2552
|
+
this.output = d, e.debug("Analysing the document");
|
|
2553
|
+
let f = sn(l, u, o.config);
|
|
2554
|
+
i(f.warnings), e.debug("Writing generated modules");
|
|
2555
|
+
let p = new un((e) => d.claim(e));
|
|
2556
|
+
vr(f.model, {
|
|
2557
|
+
modules: p,
|
|
2558
|
+
outputDir: n.outputDir,
|
|
2559
|
+
types: fr(l.components),
|
|
2560
|
+
schemaDocs: n.schemaDocs ?? "summary"
|
|
2561
|
+
}), p.build(), e.debug("Generated modules written"), d.forgetStale();
|
|
2562
|
+
let m = this.project.getDirectory(n.outputDir);
|
|
2563
|
+
return m ? (e.debug("Generating index files"), i(br(m, (e) => d.claim("index.ts", e))), e.debug("Optimizing source files"), Mr(m.getDescendantSourceFiles().filter((e) => d.files.has(e.getFilePath())), e), e.debug("Source files optimized successfully")) : e.debug("Output directory not found."), e.debug("Saving project to disk"), await d.commit(t), e.debug("Code generation completed successfully"), {
|
|
2564
|
+
files: [...d.files].sort(),
|
|
2565
|
+
configPath: o.origin,
|
|
2566
|
+
warnings: r
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
function fi(e) {
|
|
2571
|
+
try {
|
|
2572
|
+
return new r({
|
|
2573
|
+
tsConfigFilePath: e,
|
|
2574
|
+
skipAddingFilesFromTsConfig: !0
|
|
2575
|
+
});
|
|
2576
|
+
} catch (t) {
|
|
2577
|
+
throw new g("configuration", `Cannot read the TypeScript configuration ${e}: ${_(t)}`, { cause: t });
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
//#endregion
|
|
2581
|
+
export { ae as a, h as c, ie as i, ui as n, ne as o, Nr as r, g as s, di as t };
|
|
2582
|
+
|
|
2583
|
+
//# sourceMappingURL=codeGenerator-kyY9eLML.js.map
|