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