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