@ahoo-wang/wow-generator 10.0.0-alpha.6 → 10.0.0-beta.1
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 +17 -15
- package/README.zh-CN.md +16 -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-CADTvm2G.cjs +37 -0
- package/dist/codeGenerator-CADTvm2G.cjs.map +1 -0
- package/dist/{codeGenerator-CU1TGcUI.js → codeGenerator-Cxlr_VOh.js} +619 -539
- package/dist/codeGenerator-Cxlr_VOh.js.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 +58 -5
- package/dist/manifest/analyze.d.ts +58 -5
- package/dist/manifest/document.d.cts +12 -62
- package/dist/manifest/document.d.ts +12 -62
- package/package.json +14 -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 v = "./wow-generator.config.json", ee = {
|
|
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
|
+
}, y = 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 ee[this.kind];
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
function
|
|
24
|
+
function b(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 te() {
|
|
30
29
|
return !!process.stdout?.isTTY && !process.env.NO_COLOR;
|
|
31
30
|
}
|
|
32
|
-
var
|
|
31
|
+
var ne = 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 ?? te();
|
|
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
|
+
}, re = 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 ie(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 ae = "types.ts";
|
|
64
|
+
function oe(e) {
|
|
65
|
+
return ie(e.path, ae);
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
function _(e) {
|
|
67
|
+
// src/openapi/references.ts
|
|
68
|
+
function x(e) {
|
|
72
69
|
return !!(e && typeof e == "object" && "$ref" in e);
|
|
73
70
|
}
|
|
74
|
-
function
|
|
71
|
+
function se(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 ce(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/") && se(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 S = "#/components/", le = `${S}parameters/`, ue = `${S}requestBodies/`, de = `${S}responses/`, fe = `${S}schemas/`;
|
|
104
|
+
function pe(e) {
|
|
109
105
|
return e.$ref.split("/").pop();
|
|
110
106
|
}
|
|
111
|
-
function
|
|
107
|
+
function C(e, t, n) {
|
|
112
108
|
let r = /* @__PURE__ */ new Set(), i = e;
|
|
113
|
-
for (;
|
|
109
|
+
for (; x(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 y("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 w(e, t) {
|
|
117
|
+
return C(e, t.schemas, fe);
|
|
122
118
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
119
|
+
function me(e, t) {
|
|
120
|
+
return C(e, t.responses, de);
|
|
125
121
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
122
|
+
function he(e, t) {
|
|
123
|
+
return C(e, t.requestBodies, ue);
|
|
128
124
|
}
|
|
129
|
-
function
|
|
130
|
-
return
|
|
125
|
+
function ge(e, t) {
|
|
126
|
+
return C(e, t.parameters, le);
|
|
131
127
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return xe.compare(e, t);
|
|
128
|
+
// src/naming/order.ts
|
|
129
|
+
var _e = new Intl.Collator("en-US");
|
|
130
|
+
function T(e, t) {
|
|
131
|
+
return _e.compare(e, t);
|
|
137
132
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
function we(e) {
|
|
133
|
+
// src/openapi/responses.ts
|
|
134
|
+
var ve = "application/json", ye = "text/event-stream";
|
|
135
|
+
function be(e) {
|
|
142
136
|
return e.split(";")[0].trim().toLowerCase();
|
|
143
137
|
}
|
|
144
|
-
function
|
|
145
|
-
let t =
|
|
138
|
+
function xe(e) {
|
|
139
|
+
let t = be(e);
|
|
146
140
|
return t === "application/json" || /^application\/[^/]+\+json$/.test(t);
|
|
147
141
|
}
|
|
148
|
-
function
|
|
149
|
-
let t =
|
|
142
|
+
function Se(e) {
|
|
143
|
+
let t = be(e);
|
|
150
144
|
return t.startsWith("text/") && t !== "text/event-stream";
|
|
151
145
|
}
|
|
152
|
-
function
|
|
146
|
+
function E(e, t, n = (e) => be(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 Ce(e, t) {
|
|
153
|
+
if (t && !x(t)) return E(t.content, e)?.schema;
|
|
160
154
|
}
|
|
161
|
-
function
|
|
162
|
-
if (e && !
|
|
155
|
+
function we(e) {
|
|
156
|
+
if (e && !x(e)) return E(e.content, ve, xe)?.schema;
|
|
163
157
|
}
|
|
164
|
-
function
|
|
165
|
-
return
|
|
158
|
+
function Te(e) {
|
|
159
|
+
return Ce(ye, e);
|
|
166
160
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
161
|
+
function Ee(e) {
|
|
162
|
+
return Ce("*/*", e);
|
|
169
163
|
}
|
|
170
|
-
function
|
|
171
|
-
return !e ||
|
|
164
|
+
function De(e) {
|
|
165
|
+
return !e || x(e) ? !1 : Object.keys(e.content ?? {}).some(Se);
|
|
172
166
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
function C(e) {
|
|
167
|
+
// src/openapi/schemas.ts
|
|
168
|
+
function D(e) {
|
|
176
169
|
return Array.isArray(e.enum) && e.enum.length > 0;
|
|
177
170
|
}
|
|
178
|
-
var
|
|
179
|
-
function
|
|
180
|
-
return e[
|
|
171
|
+
var Oe = "x-enum-text";
|
|
172
|
+
function ke(e) {
|
|
173
|
+
return e[Oe];
|
|
181
174
|
}
|
|
182
|
-
function
|
|
175
|
+
function Ae(e) {
|
|
183
176
|
return e.type === "object" && !!e.properties;
|
|
184
177
|
}
|
|
185
|
-
function
|
|
178
|
+
function je(e) {
|
|
186
179
|
return e.type === "array" && !!e.items;
|
|
187
180
|
}
|
|
188
|
-
function
|
|
181
|
+
function Me(e) {
|
|
189
182
|
return Array.isArray(e.anyOf) && e.anyOf.length > 0;
|
|
190
183
|
}
|
|
191
|
-
function
|
|
184
|
+
function Ne(e) {
|
|
192
185
|
return Array.isArray(e.oneOf) && e.oneOf.length > 0;
|
|
193
186
|
}
|
|
194
|
-
function
|
|
187
|
+
function Pe(e) {
|
|
195
188
|
return Array.isArray(e.allOf) && e.allOf.length > 0;
|
|
196
189
|
}
|
|
197
|
-
function
|
|
198
|
-
return
|
|
190
|
+
function O(e) {
|
|
191
|
+
return Me(e) || Ne(e) || Pe(e);
|
|
199
192
|
}
|
|
200
|
-
function
|
|
193
|
+
function Fe(e) {
|
|
201
194
|
return e.includes("|") || e.includes("&") ? `(${e})[]` : `${e}[]`;
|
|
202
195
|
}
|
|
203
|
-
function
|
|
196
|
+
function Ie(e) {
|
|
204
197
|
return e.type === "object" && !e.properties && e.additionalProperties !== void 0;
|
|
205
198
|
}
|
|
206
|
-
var
|
|
207
|
-
function
|
|
208
|
-
return e[
|
|
199
|
+
var Le = "x-map-key-schema";
|
|
200
|
+
function Re(e) {
|
|
201
|
+
return e[Le];
|
|
209
202
|
}
|
|
210
|
-
function
|
|
203
|
+
function ze(e) {
|
|
211
204
|
return e.readOnly === !0;
|
|
212
205
|
}
|
|
213
|
-
function
|
|
214
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
206
|
+
function Be(e) {
|
|
207
|
+
if (Array.isArray(e)) return e.map((e) => Be(e)).join(" | ");
|
|
215
208
|
switch (e) {
|
|
216
209
|
case "string": return "string";
|
|
217
210
|
case "number":
|
|
@@ -221,10 +214,10 @@ function D(e) {
|
|
|
221
214
|
default: return "any";
|
|
222
215
|
}
|
|
223
216
|
}
|
|
224
|
-
function
|
|
217
|
+
function Ve(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), x(e)) o(t && w(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,34 +228,33 @@ function He(e, t) {
|
|
|
235
228
|
};
|
|
236
229
|
return o(e), a ? [] : n.filter((e) => !r.has(e));
|
|
237
230
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return e.operation.operationId && t.operation.operationId ? x(e.operation.operationId, t.operation.operationId) : e.path && t.path ? x(e.path, t.path) : e.method && t.method ? x(e.method, t.method) : 0;
|
|
231
|
+
// src/openapi/operations.ts
|
|
232
|
+
function He(e, t) {
|
|
233
|
+
return e.operation.operationId && t.operation.operationId ? T(e.operation.operationId, t.operation.operationId) : e.path && t.path ? T(e.path, t.path) : e.method && t.method ? T(e.method, t.method) : 0;
|
|
242
234
|
}
|
|
243
|
-
function
|
|
235
|
+
function Ue(e, t, n) {
|
|
244
236
|
let r = /* @__PURE__ */ new Map();
|
|
245
237
|
for (let i of [...e, ...t]) {
|
|
246
|
-
let e =
|
|
238
|
+
let e = x(i) ? n && ge(i, n) : i, t = e ? `${e.in}:${e.name}` : i.$ref;
|
|
247
239
|
r.set(t, i);
|
|
248
240
|
}
|
|
249
241
|
return [...r.values()];
|
|
250
242
|
}
|
|
251
|
-
function
|
|
243
|
+
function We(e, t) {
|
|
252
244
|
let n = [];
|
|
253
|
-
for (let [r, i] of Object.entries(e))
|
|
245
|
+
for (let [r, i] of Object.entries(e)) Ge(i).forEach((e) => {
|
|
254
246
|
n.push({
|
|
255
247
|
method: e.method,
|
|
256
248
|
operation: i.parameters?.length ? {
|
|
257
249
|
...e.operation,
|
|
258
|
-
parameters:
|
|
250
|
+
parameters: Ue(i.parameters, e.operation.parameters ?? [], t)
|
|
259
251
|
} : e.operation,
|
|
260
252
|
path: r
|
|
261
253
|
});
|
|
262
254
|
});
|
|
263
|
-
return n.sort(
|
|
255
|
+
return n.sort(He);
|
|
264
256
|
}
|
|
265
|
-
function
|
|
257
|
+
function Ge(e) {
|
|
266
258
|
return [
|
|
267
259
|
{
|
|
268
260
|
method: "get",
|
|
@@ -298,53 +290,52 @@ function Ke(e) {
|
|
|
298
290
|
}
|
|
299
291
|
].filter(({ operation: e }) => e !== void 0);
|
|
300
292
|
}
|
|
301
|
-
function
|
|
293
|
+
function Ke(e) {
|
|
302
294
|
let t = Object.keys(e.responses ?? {});
|
|
303
295
|
if (t.includes("200")) return "200";
|
|
304
296
|
let n = t.filter((e) => /^2\d\d$/.test(e)).sort();
|
|
305
297
|
return n.length > 0 ? n[0] : t.find((e) => e.toUpperCase() === "2XX");
|
|
306
298
|
}
|
|
299
|
+
function qe(e, t) {
|
|
300
|
+
let n = Ke(e), r = n ? e.responses[n] : void 0;
|
|
301
|
+
return t && x(r) ? me(r, t) : r;
|
|
302
|
+
}
|
|
307
303
|
function Je(e, t) {
|
|
308
|
-
|
|
309
|
-
return t && _(r) ? ve(r, t) : r;
|
|
304
|
+
return (e.parameters ?? []).map((e) => x(e) ? ge(e, t) : e).filter((e) => e !== void 0);
|
|
310
305
|
}
|
|
311
306
|
function Ye(e, t) {
|
|
312
|
-
return (e.parameters ?? []).map((e) => _(e) ? be(e, t) : e).filter((e) => e !== void 0);
|
|
313
|
-
}
|
|
314
|
-
function Xe(e, t) {
|
|
315
307
|
let n = (t) => {
|
|
316
308
|
let n = e.indexOf(`{${t.name}}`);
|
|
317
309
|
return n < 0 ? 2 ** 53 - 1 : n;
|
|
318
310
|
};
|
|
319
311
|
return [...t].sort((e, t) => n(e) - n(t));
|
|
320
312
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u.test(e) && !Qe.has(e);
|
|
313
|
+
// src/naming/naming.ts
|
|
314
|
+
var Xe = /[^\p{L}\p{N}$]+/u, Ze = /* @__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("."));
|
|
315
|
+
function k(e) {
|
|
316
|
+
return /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u.test(e) && !Ze.has(e);
|
|
326
317
|
}
|
|
327
|
-
function
|
|
318
|
+
function Qe(e) {
|
|
328
319
|
return /^\p{N}/u.test(e) ? `_${e}` : e;
|
|
329
320
|
}
|
|
321
|
+
function $e(e) {
|
|
322
|
+
if (k(e)) return e;
|
|
323
|
+
let t = Qe(M(e) || "_");
|
|
324
|
+
return Ze.has(t) ? `${t}_` : t;
|
|
325
|
+
}
|
|
330
326
|
function et(e) {
|
|
331
|
-
|
|
332
|
-
let t = $e(j(e) || "_");
|
|
333
|
-
return Qe.has(t) ? `${t}_` : t;
|
|
327
|
+
return /^\p{Lu}[\p{L}\p{N}$]*$/u.test(e) && k(e);
|
|
334
328
|
}
|
|
335
|
-
function
|
|
336
|
-
return
|
|
329
|
+
function A(e) {
|
|
330
|
+
return Qe((Array.isArray(e) ? e : [e]).map((e) => et(e) ? e : j(e)).join("") || "_");
|
|
337
331
|
}
|
|
338
|
-
function
|
|
339
|
-
return
|
|
332
|
+
function tt(e) {
|
|
333
|
+
return e.split(Xe);
|
|
340
334
|
}
|
|
341
335
|
function nt(e) {
|
|
342
|
-
return e.
|
|
336
|
+
return Array.isArray(e) ? e.flatMap((e) => rt(tt(e))) : rt(tt(e));
|
|
343
337
|
}
|
|
344
338
|
function rt(e) {
|
|
345
|
-
return Array.isArray(e) ? e.flatMap((e) => it(nt(e))) : it(nt(e));
|
|
346
|
-
}
|
|
347
|
-
function it(e) {
|
|
348
339
|
return e.flatMap((e) => {
|
|
349
340
|
if (e.length === 0) return [];
|
|
350
341
|
let t = [], n = "";
|
|
@@ -355,52 +346,50 @@ function it(e) {
|
|
|
355
346
|
return n && t.push(n), t;
|
|
356
347
|
});
|
|
357
348
|
}
|
|
358
|
-
function
|
|
359
|
-
return e === "" || e.length === 0 ? "" :
|
|
349
|
+
function j(e) {
|
|
350
|
+
return e === "" || e.length === 0 ? "" : nt(e).filter((e) => e.length > 0).map((e) => {
|
|
360
351
|
let t = e.charAt(0), n = e.slice(1);
|
|
361
352
|
return (/[a-zA-Z]/.test(t) ? t.toUpperCase() : t) + n.toLowerCase();
|
|
362
353
|
}).join("");
|
|
363
354
|
}
|
|
364
|
-
function j(e) {
|
|
365
|
-
let t = A(e);
|
|
366
|
-
return t.charAt(0).toLowerCase() + t.slice(1);
|
|
367
|
-
}
|
|
368
355
|
function M(e) {
|
|
369
|
-
|
|
356
|
+
let t = j(e);
|
|
357
|
+
return t.charAt(0).toLowerCase() + t.slice(1);
|
|
370
358
|
}
|
|
371
359
|
function N(e) {
|
|
372
|
-
return
|
|
373
|
-
}
|
|
374
|
-
function at(e) {
|
|
375
|
-
return /^\d+$/.test(e) ? `NUM_${e}` : M(e) || e;
|
|
360
|
+
return e === "" || Array.isArray(e) && e.length === 0 ? "" : nt(e).filter((e) => e.length > 0).map((e) => e.toUpperCase()).join("_");
|
|
376
361
|
}
|
|
377
362
|
function P(e) {
|
|
363
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e) ? e : F(e);
|
|
364
|
+
}
|
|
365
|
+
function it(e) {
|
|
366
|
+
return /^\d+$/.test(e) ? `NUM_${e}` : N(e) || e;
|
|
367
|
+
}
|
|
368
|
+
function F(e) {
|
|
378
369
|
return `'${JSON.stringify(e).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
379
370
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
function st(e, t) {
|
|
371
|
+
// src/analysis/clientNames.ts
|
|
372
|
+
var at = "x-fetcher-method";
|
|
373
|
+
function ot(e, t) {
|
|
384
374
|
let n = t ?? e["x-fetcher-method"];
|
|
385
375
|
if (n !== void 0) {
|
|
386
|
-
if (typeof n != "string" || !
|
|
376
|
+
if (typeof n != "string" || !st(n)) throw new y("specification", `${at} 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;
|
|
390
|
-
let r =
|
|
380
|
+
let r = M(e.operationId.split(".").pop()) || "_";
|
|
391
381
|
return /^\p{N}/u.test(r) ? `_${r}` : r;
|
|
392
382
|
}
|
|
393
|
-
function
|
|
394
|
-
return
|
|
383
|
+
function st(e) {
|
|
384
|
+
return k(e) || /^[a-z]+$/.test(e);
|
|
395
385
|
}
|
|
396
|
-
function
|
|
397
|
-
let n =
|
|
386
|
+
function ct(e, t) {
|
|
387
|
+
let n = $e(e), r = n;
|
|
398
388
|
for (let e = 2; t.has(r); e++) r = `${n}${e}`;
|
|
399
389
|
return t.add(r), r;
|
|
400
390
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
function F(e) {
|
|
391
|
+
// src/analysis/modelInfo.ts
|
|
392
|
+
function I(e) {
|
|
404
393
|
if (!e) return {
|
|
405
394
|
name: "",
|
|
406
395
|
path: "/"
|
|
@@ -412,21 +401,20 @@ function F(e) {
|
|
|
412
401
|
}
|
|
413
402
|
let r = t.slice(0, n), i = r.length > 0 ? `/${r.join("/")}` : "/";
|
|
414
403
|
return {
|
|
415
|
-
name:
|
|
404
|
+
name: A(t.slice(n)),
|
|
416
405
|
path: i
|
|
417
406
|
};
|
|
418
407
|
}
|
|
419
|
-
function
|
|
420
|
-
if (!e.$ref.startsWith(
|
|
421
|
-
return t &&
|
|
408
|
+
function lt(e, t) {
|
|
409
|
+
if (!e.$ref.startsWith("#/components/schemas/")) throw new y("specification", `Unsupported schema reference: ${e.$ref}. Bundle or inline external schemas before generation.`);
|
|
410
|
+
return t && w(e, t), I(pe(e));
|
|
422
411
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return new pt(e, t, n).clients();
|
|
412
|
+
// src/analysis/apiClients.ts
|
|
413
|
+
var ut = ["httpRequest", "attributes"];
|
|
414
|
+
function dt(e, t, n) {
|
|
415
|
+
return new ft(e, t, n).clients();
|
|
428
416
|
}
|
|
429
|
-
var
|
|
417
|
+
var ft = class {
|
|
430
418
|
document;
|
|
431
419
|
config;
|
|
432
420
|
warnings;
|
|
@@ -436,16 +424,16 @@ var pt = class {
|
|
|
436
424
|
clients() {
|
|
437
425
|
let e = this.tags(), t = this.groupOperations(), n = /* @__PURE__ */ new Map();
|
|
438
426
|
return [...t.keys()].sort().map((r) => {
|
|
439
|
-
let i =
|
|
440
|
-
for (let e = 2; n.has(
|
|
427
|
+
let i = I(r), a = i;
|
|
428
|
+
for (let e = 2; n.has(mt(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(mt(i))} and ${r} both name the API client ${i.name}ApiClient; ${r} generates ${a.name}ApiClient.`), n.set(mt(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 = ie(t.path, pt(r)), a = /* @__PURE__ */ new Map();
|
|
449
437
|
return {
|
|
450
438
|
tagName: e.name,
|
|
451
439
|
className: r,
|
|
@@ -455,7 +443,7 @@ var pt = class {
|
|
|
455
443
|
};
|
|
456
444
|
}
|
|
457
445
|
method(e, t, n, r) {
|
|
458
|
-
let { operation: i } = n, a = this.methodName(e, t, n, r), o = new Set(
|
|
446
|
+
let { operation: i } = n, a = this.methodName(e, t, n, r), o = new Set(ut), s = this.parameters(e, n, o), c = this.body(i, o), l = [...s.filter(({ parameter: e }) => e.required), ...s.filter(({ parameter: e }) => !e.required)].filter(({ description: e }) => e);
|
|
459
447
|
return {
|
|
460
448
|
name: a,
|
|
461
449
|
httpMethod: n.method,
|
|
@@ -473,21 +461,21 @@ var pt = class {
|
|
|
473
461
|
};
|
|
474
462
|
}
|
|
475
463
|
methodName(e, t, n, r) {
|
|
476
|
-
let i = n.operation.operationId, a =
|
|
477
|
-
if (o !== void 0) throw new
|
|
464
|
+
let i = n.operation.operationId, a = ot(n.operation, this.config.apiClients?.[e.name]?.methodNames?.[i]), o = r.get(a);
|
|
465
|
+
if (o !== void 0) throw new y("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) {
|
|
481
|
-
let r =
|
|
469
|
+
let r = Je(t.operation, this.document.components ?? {}), i = [];
|
|
482
470
|
for (let a of [
|
|
483
471
|
"path",
|
|
484
472
|
"query",
|
|
485
473
|
"header"
|
|
486
474
|
]) {
|
|
487
475
|
let o = r.filter((e) => e.in === a);
|
|
488
|
-
for (let r of a === "path" ?
|
|
476
|
+
for (let r of a === "path" ? Ye(t.path, o) : o) a === "path" && this.ignoresPathParameter(e.name, r.name) || i.push({
|
|
489
477
|
parameter: {
|
|
490
|
-
name:
|
|
478
|
+
name: ct(r.name, n),
|
|
491
479
|
location: a,
|
|
492
480
|
parameterName: r.name,
|
|
493
481
|
schema: r.schema,
|
|
@@ -504,26 +492,26 @@ var pt = class {
|
|
|
504
492
|
}
|
|
505
493
|
body(e, t) {
|
|
506
494
|
if (!e.requestBody) return;
|
|
507
|
-
let n =
|
|
495
|
+
let n = x(e.requestBody) ? he(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 = E(i, ve, xe), o = ct("body", t);
|
|
510
498
|
return a?.schema ? {
|
|
511
499
|
name: o,
|
|
512
500
|
required: r,
|
|
513
501
|
content: {
|
|
514
502
|
kind: "json",
|
|
515
503
|
schema: a.schema,
|
|
516
|
-
optionalFields:
|
|
504
|
+
optionalFields: Ve(a.schema, this.document.components)
|
|
517
505
|
}
|
|
518
|
-
} :
|
|
506
|
+
} : E(i, "multipart/form-data") ? {
|
|
519
507
|
name: o,
|
|
520
508
|
required: r,
|
|
521
509
|
content: { kind: "formData" }
|
|
522
|
-
} :
|
|
510
|
+
} : E(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(Se) ? {
|
|
527
515
|
name: o,
|
|
528
516
|
required: r,
|
|
529
517
|
content: { kind: "text" }
|
|
@@ -534,20 +522,20 @@ var pt = class {
|
|
|
534
522
|
};
|
|
535
523
|
}
|
|
536
524
|
returns(e) {
|
|
537
|
-
let t =
|
|
525
|
+
let t = qe(e, this.document.components);
|
|
538
526
|
if (!t) return { kind: "response" };
|
|
539
|
-
let n =
|
|
527
|
+
let n = we(t), r = n || Ee(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 = Te(t);
|
|
546
534
|
if (i) {
|
|
547
|
-
if (
|
|
548
|
-
let e =
|
|
549
|
-
if (
|
|
550
|
-
let t =
|
|
535
|
+
if (x(i)) {
|
|
536
|
+
let e = w(i, this.document.components);
|
|
537
|
+
if (je(e) && x(e.items)) {
|
|
538
|
+
let t = lt(e.items, this.document.components);
|
|
551
539
|
return {
|
|
552
540
|
kind: "eventStream",
|
|
553
541
|
items: e.items,
|
|
@@ -560,7 +548,7 @@ var pt = class {
|
|
|
560
548
|
serverSentEvent: !1
|
|
561
549
|
};
|
|
562
550
|
}
|
|
563
|
-
return
|
|
551
|
+
return De(t) ? { kind: "text" } : { kind: "response" };
|
|
564
552
|
}
|
|
565
553
|
groupOperations() {
|
|
566
554
|
let e = /* @__PURE__ */ new Map();
|
|
@@ -583,24 +571,23 @@ var pt = class {
|
|
|
583
571
|
return this.document.openAPI.tags?.forEach((t) => e.set(t.name, t)), e;
|
|
584
572
|
}
|
|
585
573
|
};
|
|
586
|
-
function
|
|
574
|
+
function pt(e) {
|
|
587
575
|
return `${e.charAt(0).toLowerCase()}${e.slice(1)}.ts`;
|
|
588
576
|
}
|
|
589
|
-
function
|
|
577
|
+
function mt(e) {
|
|
590
578
|
return `${e.path}/${e.name}`.toLowerCase();
|
|
591
579
|
}
|
|
592
|
-
|
|
593
|
-
//#region src/analysis/models.ts
|
|
580
|
+
// src/analysis/models.ts
|
|
594
581
|
function ht(e) {
|
|
595
582
|
let t = e.components?.schemas;
|
|
596
583
|
if (!t) return [];
|
|
597
584
|
let n = Object.keys(t);
|
|
598
585
|
return gt(n), n.map((e) => {
|
|
599
|
-
let n = t[e], r =
|
|
586
|
+
let n = t[e], r = I(e);
|
|
600
587
|
return {
|
|
601
588
|
key: e,
|
|
602
589
|
info: r,
|
|
603
|
-
file:
|
|
590
|
+
file: oe(r),
|
|
604
591
|
schema: n
|
|
605
592
|
};
|
|
606
593
|
});
|
|
@@ -608,26 +595,24 @@ function ht(e) {
|
|
|
608
595
|
function gt(e) {
|
|
609
596
|
let t = /* @__PURE__ */ new Map();
|
|
610
597
|
for (let n of e) {
|
|
611
|
-
let e =
|
|
598
|
+
let e = I(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 y("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
|
-
//#region src/analysis/analyze.ts
|
|
604
|
+
// src/analysis/analyze.ts
|
|
619
605
|
function _t(e, t) {
|
|
620
606
|
let n = [];
|
|
621
607
|
return {
|
|
622
608
|
model: {
|
|
623
609
|
models: ht(e),
|
|
624
|
-
apiClients:
|
|
610
|
+
apiClients: dt(e, t, n)
|
|
625
611
|
},
|
|
626
612
|
warnings: n
|
|
627
613
|
};
|
|
628
614
|
}
|
|
629
|
-
|
|
630
|
-
//#region src/emit/importRegistry.ts
|
|
615
|
+
// src/emit/importRegistry.ts
|
|
631
616
|
var vt = class {
|
|
632
617
|
declarations = /* @__PURE__ */ new Map();
|
|
633
618
|
add(e, t) {
|
|
@@ -718,44 +703,42 @@ function Ct(e, t) {
|
|
|
718
703
|
docs: t
|
|
719
704
|
};
|
|
720
705
|
}
|
|
721
|
-
|
|
722
|
-
//#region src/emit/imports.ts
|
|
706
|
+
// src/emit/imports.ts
|
|
723
707
|
var wt = "@";
|
|
724
708
|
function L(e, t, n) {
|
|
725
709
|
return e.imports.add(t, n);
|
|
726
710
|
}
|
|
727
711
|
function Tt(e, t, n) {
|
|
728
|
-
return n.path.startsWith(wt) ? n.path :
|
|
712
|
+
return n.path.startsWith(wt) ? n.path : R(e.directoryPath, d(t, n.path, ae));
|
|
729
713
|
}
|
|
730
|
-
function
|
|
714
|
+
function R(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
|
-
|
|
736
|
-
function Dt(e, t = "\n") {
|
|
718
|
+
// src/emit/jsdoc.ts
|
|
719
|
+
function Et(e, t = "\n") {
|
|
737
720
|
if (!Array.isArray(e)) return;
|
|
738
|
-
let n = e.filter((e) => typeof e == "string" && e.length > 0).map(
|
|
721
|
+
let n = e.filter((e) => typeof e == "string" && e.length > 0).map(Dt);
|
|
739
722
|
return n.length > 0 ? n.join(t) : void 0;
|
|
740
723
|
}
|
|
741
|
-
function
|
|
724
|
+
function Dt(e) {
|
|
742
725
|
return e.replace(/\*\//g, "*\\/");
|
|
743
726
|
}
|
|
744
|
-
function
|
|
745
|
-
let n =
|
|
727
|
+
function z(e, t) {
|
|
728
|
+
let n = Et(t);
|
|
746
729
|
n && (e.docs = [...e.docs ?? [], n]);
|
|
747
730
|
}
|
|
748
|
-
function
|
|
731
|
+
function Ot(e, t, n = !1) {
|
|
749
732
|
e = jt(e);
|
|
750
733
|
let r = [e.title, e.description];
|
|
751
734
|
return t && r.push(`- key: ${t}`), n && Mt(r, e), e.format && r.push(e.format === "int64" ? "- format: int64 (a value beyond Number.MAX_SAFE_INTEGER loses precision)" : `- format: ${e.format}`), Nt(r, e, "default"), Nt(r, e, "example"), Ft(r, e), It(r, e), Lt(r, e), r;
|
|
752
735
|
}
|
|
753
736
|
function kt(e, t, n) {
|
|
754
|
-
|
|
737
|
+
z(e, Ot(t, n));
|
|
755
738
|
}
|
|
756
739
|
function At(e, t, n, r = !1) {
|
|
757
|
-
let i =
|
|
758
|
-
r && Pt(i, "schema", t),
|
|
740
|
+
let i = Ot(t, n, !0);
|
|
741
|
+
r && Pt(i, "schema", t), z(e, i);
|
|
759
742
|
}
|
|
760
743
|
function jt(e) {
|
|
761
744
|
for (let t of ["anyOf", "oneOf"]) {
|
|
@@ -792,8 +775,7 @@ function Lt(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
|
-
//#region src/types/typeResolver.ts
|
|
778
|
+
// src/types/typeResolver.ts
|
|
797
779
|
function Rt(e, t) {
|
|
798
780
|
let n;
|
|
799
781
|
return {
|
|
@@ -845,18 +827,18 @@ function Ht(e, t) {
|
|
|
845
827
|
return e === void 0 ? !1 : typeof e == "string" || typeof t == "string" ? e === t : e.primitive === t.primitive;
|
|
846
828
|
}
|
|
847
829
|
function B(e, t, n = /* @__PURE__ */ new Set()) {
|
|
848
|
-
if (
|
|
830
|
+
if (x(e)) {
|
|
849
831
|
if (!t || n.has(e.$ref)) return;
|
|
850
832
|
n.add(e.$ref);
|
|
851
|
-
let r =
|
|
833
|
+
let r = w(e, t);
|
|
852
834
|
return r ? B(r, t, n) : void 0;
|
|
853
835
|
}
|
|
854
836
|
if (!(e.nullable || Array.isArray(e.type))) {
|
|
855
|
-
if (
|
|
837
|
+
if (Pe(e) && e.type === void 0) {
|
|
856
838
|
let r = e.allOf.map((e) => B(e, t, n)), [i] = r;
|
|
857
839
|
return i !== void 0 && r.every((e) => Ht(e, i)) ? i : void 0;
|
|
858
840
|
}
|
|
859
|
-
if (!(
|
|
841
|
+
if (!(O(e) || e.const !== void 0 || e.type === void 0)) return e.type === "object" ? "object" : e.type === "array" ? "array" : { primitive: Be(e.type) };
|
|
860
842
|
}
|
|
861
843
|
}
|
|
862
844
|
function Ut(e, t, n) {
|
|
@@ -870,11 +852,11 @@ function Wt(e, t) {
|
|
|
870
852
|
return typeof n == "object" && Object.values(e.properties ?? {}).some((e) => Ut(e, n, t));
|
|
871
853
|
}
|
|
872
854
|
function Gt(e) {
|
|
873
|
-
return e.nullable !== !0 ||
|
|
855
|
+
return e.nullable !== !0 || D(e) || !O(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(x));
|
|
878
860
|
}
|
|
879
861
|
function Kt(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);
|
|
@@ -883,7 +865,7 @@ function V(t) {
|
|
|
883
865
|
if (typeof t == "string") return new e({ useSingleQuote: !0 }).quote(t).toString();
|
|
884
866
|
if (Array.isArray(t)) return `[${t.map((e) => V(e)).join(", ")}]`;
|
|
885
867
|
if (typeof t == "object" && t) {
|
|
886
|
-
let e = Object.entries(t).map(([e, t]) => `${
|
|
868
|
+
let e = Object.entries(t).map(([e, t]) => `${P(e)}: ${V(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";
|
|
@@ -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 =
|
|
927
|
+
let n = this.type(t), r = (ze(t) ? "readonly " : "") + P(e);
|
|
928
|
+
if (!x(t)) {
|
|
929
|
+
let e = Et(Ot(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
|
-
|
|
961
|
-
for (let n of e.required ?? []) Object.hasOwn(e.properties ?? {}, n) || t.push(`${
|
|
962
|
-
let n =
|
|
942
|
+
Ae(e) && t.push(...this.propertyDefinitions(e));
|
|
943
|
+
for (let n of e.required ?? []) Object.hasOwn(e.properties ?? {}, n) || t.push(`${P(n)}: ${this.requiredAdditionalPropertyType(e)}`);
|
|
944
|
+
let n = Ie(e) && Re(e) ? this.mapType(e) : Wt(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 = Re(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) => x(e) ? this.components && w(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 (x(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,
|
|
@@ -1011,7 +993,7 @@ var qt = class {
|
|
|
1011
993
|
...e,
|
|
1012
994
|
nullable: !1
|
|
1013
995
|
})}) | null`;
|
|
1014
|
-
if (
|
|
996
|
+
if (O(e)) {
|
|
1015
997
|
let t = this.simpleComposition(e);
|
|
1016
998
|
if (t !== void 0) return t;
|
|
1017
999
|
let n = [
|
|
@@ -1040,18 +1022,18 @@ var qt = class {
|
|
|
1040
1022
|
});
|
|
1041
1023
|
return n === "any" ? t : `(${t}) & (${n})`;
|
|
1042
1024
|
}
|
|
1043
|
-
if (e.nullable && e.type && !
|
|
1025
|
+
if (e.nullable && e.type && !D(e)) return `(${this.type({
|
|
1044
1026
|
...e,
|
|
1045
1027
|
nullable: !1
|
|
1046
1028
|
})}) | null`;
|
|
1047
|
-
if (
|
|
1029
|
+
if (D(e)) {
|
|
1048
1030
|
let t = e.enum.filter((t) => Kt(t, e)).map((e) => V(e)).join(" | ") || "never", n = this.type({
|
|
1049
1031
|
...e,
|
|
1050
1032
|
enum: void 0
|
|
1051
1033
|
});
|
|
1052
1034
|
return n === "any" || Bt.has(n) ? t : `(${t}) & (${n})`;
|
|
1053
1035
|
}
|
|
1054
|
-
return
|
|
1036
|
+
return Ie(e) && !e.required?.length ? this.mapType(e) : e.type === "array" ? Fe(this.type(e.items ?? {})) : e.type === "object" ? this.objectType(e) : e.type ? Be(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
|
|
@@ -1067,15 +1049,15 @@ var qt = class {
|
|
|
1067
1049
|
let [n] = t;
|
|
1068
1050
|
if (Object.keys(e).filter((e) => e !== n && e !== "discriminator" && !e.startsWith("x-") && !Vt.has(e)).length > 0) return;
|
|
1069
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" || Vt.has(e));
|
|
1070
|
-
if (!r.every((e) =>
|
|
1071
|
-
let a = r.map((t) =>
|
|
1052
|
+
if (!r.every((e) => x(e) || i(e))) return;
|
|
1053
|
+
let a = r.map((t) => x(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 =
|
|
1078
|
-
return `(${r} & { ${
|
|
1058
|
+
if (t === "allOf" || !i?.propertyName || !x(n)) return r;
|
|
1059
|
+
let a = pe(n), o = Object.entries(i.mapping ?? {}).filter(([, e]) => e === n.$ref || e === a).map(([e]) => e), s = (o.length > 0 ? o : [a]).map((e) => F(e)).join(" | ");
|
|
1060
|
+
return `(${r} & { ${P(i.propertyName)}: ${s} })`;
|
|
1079
1061
|
}
|
|
1080
1062
|
};
|
|
1081
1063
|
function H(e, t) {
|
|
@@ -1100,8 +1082,7 @@ function Zt(e, t) {
|
|
|
1100
1082
|
function Qt(e, t) {
|
|
1101
1083
|
return H(t, (t) => t.mapValueType(e));
|
|
1102
1084
|
}
|
|
1103
|
-
|
|
1104
|
-
//#region src/emitters/decorators.ts
|
|
1085
|
+
// src/emitters/decorators.ts
|
|
1105
1086
|
var $t = "@ahoo-wang/fetcher", en = ["ContentTypeValues", "ResultExtractors"], tn = "@ahoo-wang/fetcher-decorator", nn = [
|
|
1106
1087
|
"ApiMetadata",
|
|
1107
1088
|
"ApiMetadataCapable",
|
|
@@ -1161,13 +1142,12 @@ var fn = "@ahoo-wang/fetcher-eventstream";
|
|
|
1161
1142
|
function pn(e) {
|
|
1162
1143
|
L(e, fn, ["JsonEventStreamResultExtractor", "JsonServerSentEventStream"]);
|
|
1163
1144
|
}
|
|
1164
|
-
|
|
1165
|
-
//#region src/emitters/apiClients.ts
|
|
1145
|
+
// src/emitters/apiClients.ts
|
|
1166
1146
|
function mn(e, t) {
|
|
1167
1147
|
let n = t.modules.module(e.file);
|
|
1168
1148
|
sn(n), cn(n), pn(n);
|
|
1169
1149
|
let r = ln(e.className, n);
|
|
1170
|
-
|
|
1150
|
+
z(r, [e.description]), un(r);
|
|
1171
1151
|
let i = hn(e.className, n, t);
|
|
1172
1152
|
for (let t of e.methods) (r.methods ??= []).push(gn(t, i));
|
|
1173
1153
|
}
|
|
@@ -1194,7 +1174,7 @@ function gn(e, t) {
|
|
|
1194
1174
|
hasQuestionToken: !i.required,
|
|
1195
1175
|
decorators: [{
|
|
1196
1176
|
name: i.location,
|
|
1197
|
-
arguments: [
|
|
1177
|
+
arguments: [F(i.parameterName)]
|
|
1198
1178
|
}]
|
|
1199
1179
|
});
|
|
1200
1180
|
e.body && (e.body.required ? n : r).push({
|
|
@@ -1227,7 +1207,7 @@ function gn(e, t) {
|
|
|
1227
1207
|
arguments: []
|
|
1228
1208
|
}]
|
|
1229
1209
|
}
|
|
1230
|
-
], a = vn(e.returns, t), o =
|
|
1210
|
+
], a = vn(e.returns, t), o = F(e.path), s = {
|
|
1231
1211
|
name: e.name,
|
|
1232
1212
|
decorators: [{
|
|
1233
1213
|
name: dn(e.httpMethod),
|
|
@@ -1237,14 +1217,14 @@ function gn(e, t) {
|
|
|
1237
1217
|
returnType: a.type,
|
|
1238
1218
|
statements: [`throw autoGeneratedError(${i.map((e) => e.name).join(",")});`]
|
|
1239
1219
|
};
|
|
1240
|
-
return
|
|
1220
|
+
return z(s, [...e.docs]), s;
|
|
1241
1221
|
}
|
|
1242
1222
|
function _n(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 : (L(t.module, $t, ["PartialBy"]), `PartialBy<${e}, ${r.map(
|
|
1227
|
+
return r.length === 0 || /[|&]/.test(e) || e === "any" ? e : (L(t.module, $t, ["PartialBy"]), `PartialBy<${e}, ${r.map(F).join(" | ")}>`);
|
|
1248
1228
|
}
|
|
1249
1229
|
case "formData": return "FormData";
|
|
1250
1230
|
case "urlEncoded": return "URLSearchParams";
|
|
@@ -1273,12 +1253,11 @@ function vn(e, t) {
|
|
|
1273
1253
|
case "response": return rn;
|
|
1274
1254
|
}
|
|
1275
1255
|
}
|
|
1276
|
-
|
|
1277
|
-
//#region src/emitters/models.ts
|
|
1256
|
+
// src/emitters/models.ts
|
|
1278
1257
|
function yn(e) {
|
|
1279
1258
|
return Rt(e, {
|
|
1280
|
-
ofKey: (e) =>
|
|
1281
|
-
ofReference:
|
|
1259
|
+
ofKey: (e) => I(e),
|
|
1260
|
+
ofReference: lt
|
|
1282
1261
|
});
|
|
1283
1262
|
}
|
|
1284
1263
|
function bn(e, t) {
|
|
@@ -1287,11 +1266,11 @@ function bn(e, t) {
|
|
|
1287
1266
|
function xn(e) {
|
|
1288
1267
|
let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
|
|
1289
1268
|
for (let r of e) {
|
|
1290
|
-
let e =
|
|
1269
|
+
let e = it(r), i = [e];
|
|
1291
1270
|
/^\d/.test(r) || i.push(r);
|
|
1292
1271
|
let a = i.find((e) => !t.has(e));
|
|
1293
1272
|
for (let n = 2; a === void 0; n++) t.has(`${e}_${n}`) || (a = `${e}_${n}`);
|
|
1294
|
-
t.add(a), n.set(r,
|
|
1273
|
+
t.add(a), n.set(r, P(a));
|
|
1295
1274
|
}
|
|
1296
1275
|
return n;
|
|
1297
1276
|
}
|
|
@@ -1315,7 +1294,7 @@ var Sn = class {
|
|
|
1315
1294
|
}
|
|
1316
1295
|
process() {
|
|
1317
1296
|
let { schema: e } = this.model;
|
|
1318
|
-
return
|
|
1297
|
+
return x(e) ? this.processTypeAlias(e) : D(e) ? this.processEnum(e) : e.const !== void 0 || e.nullable && e.type || O(e) && (e.type || e.properties || e.required) ? this.processTypeAlias(e) : Ae(e) ? this.processInterface(e) : Ie(e) && typeof e.additionalProperties == "object" && !Re(e) && !e.required?.length ? this.processIndexSignature(e) : je(e) ? this.processArray(e) : O(e) ? this.processComposition(e) : this.processTypeAlias(e);
|
|
1319
1298
|
}
|
|
1320
1299
|
scope;
|
|
1321
1300
|
emit(e) {
|
|
@@ -1325,7 +1304,7 @@ var Sn = class {
|
|
|
1325
1304
|
return this.emit(Jt(e, this.scope));
|
|
1326
1305
|
}
|
|
1327
1306
|
processEnum(e) {
|
|
1328
|
-
let t =
|
|
1307
|
+
let t = ke(e);
|
|
1329
1308
|
if (t) {
|
|
1330
1309
|
let e = xn(Object.keys(t));
|
|
1331
1310
|
this.module.add({
|
|
@@ -1339,7 +1318,7 @@ var Sn = class {
|
|
|
1339
1318
|
});
|
|
1340
1319
|
}
|
|
1341
1320
|
let n = [...new Set(e.enum.filter((e) => typeof e == "string"))], r = xn(n);
|
|
1342
|
-
return
|
|
1321
|
+
return O(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,
|
|
@@ -1363,9 +1342,9 @@ var Sn = class {
|
|
|
1363
1342
|
}
|
|
1364
1343
|
addPropertyToInterface(e, t, n) {
|
|
1365
1344
|
let r = {
|
|
1366
|
-
name:
|
|
1345
|
+
name: P(t),
|
|
1367
1346
|
type: this.resolveType(n),
|
|
1368
|
-
isReadonly:
|
|
1347
|
+
isReadonly: ze(n)
|
|
1369
1348
|
};
|
|
1370
1349
|
(e.properties ??= []).push(r), kt(r, n);
|
|
1371
1350
|
}
|
|
@@ -1381,7 +1360,7 @@ var Sn = class {
|
|
|
1381
1360
|
this.addPropertyToInterface(n, e, t);
|
|
1382
1361
|
});
|
|
1383
1362
|
for (let n of e.required ?? []) Object.hasOwn(r, n) || t.push({
|
|
1384
|
-
name:
|
|
1363
|
+
name: P(n),
|
|
1385
1364
|
type: this.emit(Zt(e, this.scope))
|
|
1386
1365
|
});
|
|
1387
1366
|
return this.emit(Yt(e, this.scope)) && t.push(Ct(this.emit(Xt(e, this.scope)), ["Additional properties"])), n;
|
|
@@ -1391,7 +1370,7 @@ var Sn = class {
|
|
|
1391
1370
|
return this.module.add({
|
|
1392
1371
|
kind: o.TypeAlias,
|
|
1393
1372
|
name: this.modelInfo.name,
|
|
1394
|
-
type:
|
|
1373
|
+
type: Fe(t),
|
|
1395
1374
|
isExported: !0
|
|
1396
1375
|
});
|
|
1397
1376
|
}
|
|
@@ -1420,13 +1399,11 @@ var Sn = class {
|
|
|
1420
1399
|
});
|
|
1421
1400
|
}
|
|
1422
1401
|
};
|
|
1423
|
-
|
|
1424
|
-
//#region src/emitters/emit.ts
|
|
1402
|
+
// src/emitters/emit.ts
|
|
1425
1403
|
function Cn(e, t) {
|
|
1426
1404
|
e.models.forEach((e) => bn(e, t)), e.apiClients.forEach((e) => mn(e, t));
|
|
1427
1405
|
}
|
|
1428
|
-
|
|
1429
|
-
//#region src/emitters/indexFiles.ts
|
|
1406
|
+
// src/emitters/indexFiles.ts
|
|
1430
1407
|
function wn(e, t) {
|
|
1431
1408
|
let n = [];
|
|
1432
1409
|
return Tn(e, t, n), n;
|
|
@@ -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]) => T(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]) => ({
|
|
@@ -1475,8 +1452,7 @@ function Dn(e) {
|
|
|
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
|
-
//#region src/finalize/typeOnlyImports.ts
|
|
1455
|
+
// src/finalize/typeOnlyImports.ts
|
|
1480
1456
|
function On(e) {
|
|
1481
1457
|
let t = e;
|
|
1482
1458
|
for (let e = t.getParent(); e; t = e, e = e.getParent()) if (n.isQualifiedName(e)) {
|
|
@@ -1520,8 +1496,7 @@ function jn(e) {
|
|
|
1520
1496
|
let t = e.flatMap(kn);
|
|
1521
1497
|
for (let e of t) e();
|
|
1522
1498
|
}
|
|
1523
|
-
|
|
1524
|
-
//#region src/finalize/verification.ts
|
|
1499
|
+
// src/finalize/verification.ts
|
|
1525
1500
|
var Mn = /* @__PURE__ */ new Set([
|
|
1526
1501
|
2300,
|
|
1527
1502
|
2304,
|
|
@@ -1541,8 +1516,7 @@ function Nn(e) {
|
|
|
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
|
-
//#region src/finalize/finalize.ts
|
|
1519
|
+
// src/finalize/finalize.ts
|
|
1546
1520
|
var Pn = "// Code generated by wow-generator. DO NOT EDIT.\n\n", Fn = {
|
|
1547
1521
|
indentSize: 2,
|
|
1548
1522
|
tabSize: 2,
|
|
@@ -1556,8 +1530,7 @@ function In(e, t) {
|
|
|
1556
1530
|
}), jn(e), Nn(e);
|
|
1557
1531
|
for (let t of e) t.insertText(0, Pn);
|
|
1558
1532
|
}
|
|
1559
|
-
|
|
1560
|
-
//#region src/input/resources.ts
|
|
1533
|
+
// src/input/resources.ts
|
|
1561
1534
|
var Ln = 3e4;
|
|
1562
1535
|
function Rn(e) {
|
|
1563
1536
|
return /^https?:\/\//i.test(e);
|
|
@@ -1590,32 +1563,31 @@ function Vn(e) {
|
|
|
1590
1563
|
}
|
|
1591
1564
|
function Hn(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
|
-
//#region src/input/parsers.ts
|
|
1571
|
+
// src/input/parsers.ts
|
|
1600
1572
|
async function Un(e, t) {
|
|
1601
1573
|
let n;
|
|
1602
1574
|
try {
|
|
1603
1575
|
n = await zn(e, t);
|
|
1604
1576
|
} catch (t) {
|
|
1605
|
-
throw new
|
|
1577
|
+
throw new y("input", `Cannot read the OpenAPI document ${e}: ${b(t)}`, { cause: t });
|
|
1606
1578
|
}
|
|
1607
1579
|
try {
|
|
1608
1580
|
return Gn(n);
|
|
1609
1581
|
} catch (t) {
|
|
1610
|
-
throw new
|
|
1582
|
+
throw new y("input", `Cannot parse the OpenAPI document ${e}: ${b(t)}`, { cause: t });
|
|
1611
1583
|
}
|
|
1612
1584
|
}
|
|
1613
1585
|
function Wn(e, t) {
|
|
1614
|
-
if (typeof e != "object" || !e || Array.isArray(e)) throw new
|
|
1586
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw new y("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 y("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 y("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 y("input", `${t} is not a valid OpenAPI document: its "info" object is missing.`);
|
|
1619
1591
|
return {
|
|
1620
1592
|
...n,
|
|
1621
1593
|
paths: n.paths ?? {}
|
|
@@ -1624,7 +1596,7 @@ function Wn(e, t) {
|
|
|
1624
1596
|
function Gn(e) {
|
|
1625
1597
|
switch (Kn(e)) {
|
|
1626
1598
|
case "json": return JSON.parse(e);
|
|
1627
|
-
case "yaml": return
|
|
1599
|
+
case "yaml": return h(e);
|
|
1628
1600
|
}
|
|
1629
1601
|
}
|
|
1630
1602
|
function Kn(e) {
|
|
@@ -1638,18 +1610,17 @@ function Kn(e) {
|
|
|
1638
1610
|
}
|
|
1639
1611
|
throw Error("Unable to infer file format");
|
|
1640
1612
|
}
|
|
1641
|
-
|
|
1642
|
-
//#region src/input/configuration.ts
|
|
1613
|
+
// src/input/configuration.ts
|
|
1643
1614
|
async function qn(e, t, n) {
|
|
1644
1615
|
if (e !== void 0) return {
|
|
1645
1616
|
...await Xn({
|
|
1646
1617
|
path: e,
|
|
1647
1618
|
explicit: !0
|
|
1648
1619
|
}, t, n),
|
|
1649
|
-
origin:
|
|
1620
|
+
origin: Zn(e)
|
|
1650
1621
|
};
|
|
1651
1622
|
let r = await Xn({
|
|
1652
|
-
path:
|
|
1623
|
+
path: v,
|
|
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: Zn(v)
|
|
1661
1632
|
};
|
|
1662
1633
|
}
|
|
1663
1634
|
var Jn = ["apiClients"], Yn = ["ignorePathParameters", "methodNames"];
|
|
1664
1635
|
async function Xn(e, t, n) {
|
|
1665
|
-
let r =
|
|
1636
|
+
let r = Zn(e.path);
|
|
1666
1637
|
t.debug(`Reading configuration: ${r}`);
|
|
1667
1638
|
let i;
|
|
1668
1639
|
try {
|
|
1669
1640
|
i = await zn(e.path, n);
|
|
1670
1641
|
} catch (n) {
|
|
1671
|
-
if (!e.explicit &&
|
|
1642
|
+
if (!e.explicit && Qn(n)) {
|
|
1672
1643
|
t.debug(`No configuration file at ${r}`);
|
|
1673
1644
|
return;
|
|
1674
1645
|
}
|
|
1675
|
-
throw new
|
|
1646
|
+
throw new y("configuration", `Cannot read configuration ${r}: ${b(n)}`, { cause: n });
|
|
1676
1647
|
}
|
|
1677
1648
|
if (!i.trim()) return {
|
|
1678
1649
|
config: {},
|
|
@@ -1682,115 +1653,116 @@ async function Xn(e, t, n) {
|
|
|
1682
1653
|
try {
|
|
1683
1654
|
a = Gn(i);
|
|
1684
1655
|
} catch (e) {
|
|
1685
|
-
throw new
|
|
1656
|
+
throw new y("configuration", `Cannot parse configuration ${r}: ${b(e)}`, { cause: e });
|
|
1686
1657
|
}
|
|
1687
|
-
let o =
|
|
1688
|
-
return t.debug(`Configuration loaded from ${r}: ${
|
|
1658
|
+
let o = er(a, r);
|
|
1659
|
+
return t.debug(`Configuration loaded from ${r}: ${nr(o.config)}`), o;
|
|
1689
1660
|
}
|
|
1690
|
-
function
|
|
1661
|
+
function Zn(e) {
|
|
1691
1662
|
return Rn(e) || u(e) ? e : p(e);
|
|
1692
1663
|
}
|
|
1693
|
-
function
|
|
1664
|
+
function Qn(e) {
|
|
1694
1665
|
return typeof e == "object" && !!e && e.code === "ENOENT";
|
|
1695
1666
|
}
|
|
1696
|
-
function
|
|
1667
|
+
function U(e) {
|
|
1697
1668
|
return e === null ? "null" : Array.isArray(e) ? "an array" : `a ${typeof e}`;
|
|
1698
1669
|
}
|
|
1699
|
-
function
|
|
1670
|
+
function W(e) {
|
|
1700
1671
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1701
1672
|
}
|
|
1702
|
-
function
|
|
1673
|
+
function $n(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 er(e, t) {
|
|
1678
|
+
if (!W(e)) throw new y("configuration", `Configuration ${t} must be a JSON or YAML object, found ${U(e)}`);
|
|
1708
1679
|
let n = [];
|
|
1709
|
-
return
|
|
1680
|
+
return $n(n, t, "configuration", e, Jn), tr(e.apiClients, t, n), {
|
|
1710
1681
|
config: e,
|
|
1711
1682
|
warnings: n
|
|
1712
1683
|
};
|
|
1713
1684
|
}
|
|
1714
|
-
function
|
|
1685
|
+
function tr(e, t, n) {
|
|
1715
1686
|
if (e !== void 0) {
|
|
1716
|
-
if (!
|
|
1687
|
+
if (!W(e)) throw new y("configuration", `apiClients in ${t} must be an object keyed by tag name, found ${U(e)}`);
|
|
1717
1688
|
for (let [r, i] of Object.entries(e)) {
|
|
1718
|
-
if (!
|
|
1719
|
-
|
|
1689
|
+
if (!W(i)) throw new y("configuration", `apiClients["${r}"] in ${t} must be an object, found ${U(i)}`);
|
|
1690
|
+
$n(n, t, `apiClients["${r}"]`, i, Yn);
|
|
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 y("configuration", `apiClients["${r}"].ignorePathParameters in ${t} must be an array of strings, found ${U(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" || !
|
|
1695
|
+
if (!W(a)) throw new y("configuration", `apiClients["${r}"].methodNames in ${t} must be an object mapping operationIds to method names, found ${U(a)}`);
|
|
1696
|
+
for (let [e, n] of Object.entries(a)) if (typeof n != "string" || !k(n)) throw new y("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 nr(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 rr = /* @__PURE__ */ new Set(), ir = "#/$defs/";
|
|
1706
|
+
function G(e) {
|
|
1707
|
+
return e.startsWith(ir) ? e.slice(8) : void 0;
|
|
1737
1708
|
}
|
|
1738
|
-
function
|
|
1709
|
+
function ar(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 K(e) {
|
|
1744
1715
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1745
1716
|
}
|
|
1746
|
-
function
|
|
1717
|
+
function or(e, t) {
|
|
1747
1718
|
let n = e;
|
|
1748
|
-
if (n.format !== 1) throw new
|
|
1749
|
-
let r = [];
|
|
1719
|
+
if (n.format !== 1) throw new y("input", `${t} is a Wow Manifest of format ${n.format}; wow-generator reads format 1.`);
|
|
1720
|
+
let r = (n.requires ?? []).filter((e) => !rr.has(e));
|
|
1721
|
+
if (r.length > 0) throw new y("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
|
+
!K(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
|
+
!K(t) || typeof t.name != "string" ? i.push(`${r} has no name`) : !K(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 && !K(n.$defs) && i.push("$defs is not an object"), i.length > 0) throw new y("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 sr = /* @__PURE__ */ new Set([
|
|
1765
1737
|
"int64",
|
|
1766
1738
|
"bigint",
|
|
1767
1739
|
"decimal"
|
|
1768
|
-
]),
|
|
1740
|
+
]), cr = {
|
|
1769
1741
|
"wow.lifecycle.TransferOwner": "TransferOwner",
|
|
1770
1742
|
"wow.lifecycle.TransferSpace": "TransferSpace",
|
|
1771
1743
|
"wow.lifecycle.ApplyTags": "ApplyTags"
|
|
1772
|
-
},
|
|
1744
|
+
}, lr = /* @__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
|
+
]), ur = 4;
|
|
1751
|
+
function q(e) {
|
|
1780
1752
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
1781
1753
|
}
|
|
1782
|
-
function
|
|
1754
|
+
function J(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 dr(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
|
|
1791
|
-
return typeof e == "string" ?
|
|
1762
|
+
function fr(e) {
|
|
1763
|
+
return typeof e == "string" ? F(e) : JSON.stringify(e);
|
|
1792
1764
|
}
|
|
1793
|
-
var
|
|
1765
|
+
var pr = class {
|
|
1794
1766
|
defs;
|
|
1795
1767
|
names = /* @__PURE__ */ new Map();
|
|
1796
1768
|
warnings = [];
|
|
@@ -1805,7 +1777,7 @@ var dr = class {
|
|
|
1805
1777
|
for (let e = 0; t.size > 0; e++) {
|
|
1806
1778
|
let n = /* @__PURE__ */ new Map();
|
|
1807
1779
|
for (let r of t.keys()) {
|
|
1808
|
-
let t = r.split("."), i = t[t.length - 1].split("$"), a =
|
|
1780
|
+
let t = r.split("."), i = t[t.length - 1].split("$"), a = A([...t.slice(Math.max(0, t.length - 1 - e), t.length - 1), ...i].map((e) => /^[a-z]/.test(e) ? j(e) : e));
|
|
1809
1781
|
n.set(a, [...n.get(a) ?? [], r]);
|
|
1810
1782
|
}
|
|
1811
1783
|
let r = new Set(this.names.values());
|
|
@@ -1821,20 +1793,20 @@ var dr = class {
|
|
|
1821
1793
|
}
|
|
1822
1794
|
schemaOf(e) {
|
|
1823
1795
|
let t = this.defs[e];
|
|
1824
|
-
return
|
|
1796
|
+
return q(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 = G(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 (q(e)) for (let [n, r] of Object.entries(e)) if (n === "$ref" && typeof r == "string") {
|
|
1809
|
+
let e = G(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 (!q(e)) return "unknown";
|
|
1871
1843
|
if (typeof e.$ref == "string") {
|
|
1872
|
-
let n =
|
|
1844
|
+
let n = G(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 fr(e.const);
|
|
1848
|
+
if (Array.isArray(e.enum)) return e.enum.length === 0 ? "never" : dr(e.enum.map(fr), " | ");
|
|
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 dr(i.map((e) => this.type(e, t)), r);
|
|
1884
1856
|
}
|
|
1885
|
-
let n =
|
|
1886
|
-
return n.length === 0 ?
|
|
1857
|
+
let n = J(e);
|
|
1858
|
+
return n.length === 0 ? q(e.properties) ? this.objectType(e, t) : "unknown" : dr(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" && sr.has(t.format) ? "string" : "number";
|
|
1893
1865
|
case "boolean": return "boolean";
|
|
1894
1866
|
case "null": return "null";
|
|
1895
1867
|
case "array": {
|
|
@@ -1907,12 +1879,12 @@ 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 (!q(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 = q(r) ? r.description : void 0;
|
|
1914
1886
|
return {
|
|
1915
|
-
name:
|
|
1887
|
+
name: P(e),
|
|
1916
1888
|
type: this.type(r, `${t}.${e}`),
|
|
1917
1889
|
optional: !n.has(e),
|
|
1918
1890
|
...typeof i == "string" ? { description: i } : {}
|
|
@@ -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 = J(e);
|
|
1900
|
+
return q(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 (!q(e)) return;
|
|
1904
|
+
let n = typeof e.$ref == "string" ? G(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,72 @@ 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 = J(e);
|
|
1914
|
+
(i.includes("integer") || i.includes("number")) && typeof e.format == "string" && sr.has(e.format) && r.push(!0);
|
|
1943
1915
|
let a = {};
|
|
1944
|
-
if (
|
|
1916
|
+
if (q(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), mr(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" ? G(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 (!q(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 < ur && q(r) && (J(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 mr(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, mr(t)]));
|
|
1971
1943
|
}
|
|
1972
|
-
function
|
|
1944
|
+
function hr(e, t, n) {
|
|
1973
1945
|
if (t === void 0) return !0;
|
|
1974
|
-
let
|
|
1975
|
-
return !Array.isArray(
|
|
1946
|
+
let r = e.resolve(t);
|
|
1947
|
+
return !Array.isArray(r.required) || r.required.every((e) => e === n);
|
|
1948
|
+
}
|
|
1949
|
+
function gr(e, t, n) {
|
|
1950
|
+
if (t === void 0) return !1;
|
|
1951
|
+
let r = e.resolve(t).properties, i = q(r) ? r[n] : void 0;
|
|
1952
|
+
return q(i) && i.readOnly === !0;
|
|
1976
1953
|
}
|
|
1977
|
-
function
|
|
1954
|
+
function _r(e) {
|
|
1955
|
+
return (e.commands ?? []).filter((e) => e.system !== !0);
|
|
1956
|
+
}
|
|
1957
|
+
function vr(e) {
|
|
1958
|
+
return (e.commands ?? []).filter((e) => e.system === !0 && e.name.startsWith("wow.lifecycle."));
|
|
1959
|
+
}
|
|
1960
|
+
function yr(e, t) {
|
|
1978
1961
|
return [
|
|
1979
1962
|
t.state.schema,
|
|
1980
|
-
...(t
|
|
1963
|
+
..._r(t).map((e) => e.schema),
|
|
1981
1964
|
...(t.events ?? []).map((e) => e.schema)
|
|
1982
|
-
].map(
|
|
1965
|
+
].map(G).filter((e) => e !== void 0).concat(br(e, t));
|
|
1983
1966
|
}
|
|
1984
|
-
function
|
|
1985
|
-
return (t.
|
|
1967
|
+
function br(e, t) {
|
|
1968
|
+
return vr(t).map((e) => e.name).filter((t) => cr[t] !== void 0 && e.schemaOf(t));
|
|
1986
1969
|
}
|
|
1987
|
-
function
|
|
1988
|
-
let t = new
|
|
1970
|
+
function xr(e) {
|
|
1971
|
+
let t = new pr(e.$defs ?? {}), n = e.contexts, r = /* @__PURE__ */ new Map();
|
|
1989
1972
|
for (let e of n) {
|
|
1990
|
-
let n = (e.aggregates ?? []).flatMap((e) =>
|
|
1991
|
-
for (let i of t.closure(n).sort(
|
|
1973
|
+
let n = [...(e.aggregates ?? []).flatMap((e) => yr(t, e)), ...(e.routes ?? []).flatMap((e) => [...t.references(e.request), ...t.references(e.response)])];
|
|
1974
|
+
for (let i of t.closure(n).sort(T)) r.has(i) || r.set(i, e.name);
|
|
1992
1975
|
}
|
|
1993
1976
|
let i = [...r.keys()].filter((e) => t.schemaOf(e) && !t.inlined(e));
|
|
1994
|
-
t.name([...i].sort(
|
|
1995
|
-
let a = i.map((e) =>
|
|
1977
|
+
t.name([...i].sort(T));
|
|
1978
|
+
let a = i.map((e) => Sr(t, e, `${r.get(e)}/types.ts`)).sort((e, t) => T(e.file, t.file) || T(e.name, t.name)), o = n.map((e) => Cr(t, e));
|
|
1996
1979
|
return {
|
|
1997
1980
|
model: {
|
|
1998
1981
|
...e.service?.name ? { service: e.service.name } : {},
|
|
@@ -2002,13 +1985,13 @@ function gr(e) {
|
|
|
2002
1985
|
warnings: [...new Set(t.warnings)]
|
|
2003
1986
|
};
|
|
2004
1987
|
}
|
|
2005
|
-
function
|
|
1988
|
+
function Sr(e, t, n) {
|
|
2006
1989
|
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
1990
|
key: t,
|
|
2008
1991
|
name: i,
|
|
2009
1992
|
file: n,
|
|
2010
1993
|
...a === void 0 ? {} : { description: a },
|
|
2011
|
-
references: [...new Set(o)].sort(
|
|
1994
|
+
references: [...new Set(o)].sort(T)
|
|
2012
1995
|
};
|
|
2013
1996
|
if (e.isInterface(r)) {
|
|
2014
1997
|
let n = e.additional(r, t);
|
|
@@ -2023,111 +2006,135 @@ function _r(e, t, n) {
|
|
|
2023
2006
|
type: e.type(r, t)
|
|
2024
2007
|
};
|
|
2025
2008
|
}
|
|
2026
|
-
function
|
|
2027
|
-
let n = `${t.name}.`;
|
|
2009
|
+
function Cr(e, t) {
|
|
2028
2010
|
return {
|
|
2029
2011
|
name: t.name,
|
|
2030
2012
|
...t.description ? { description: t.description } : {},
|
|
2031
|
-
typeName:
|
|
2032
|
-
constantName:
|
|
2013
|
+
typeName: A(j(t.name)),
|
|
2014
|
+
constantName: N(t.name),
|
|
2033
2015
|
directory: t.name,
|
|
2034
2016
|
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
2017
|
code: e.code,
|
|
2037
2018
|
status: e.status,
|
|
2038
2019
|
...e.description ? { description: e.description } : {}
|
|
2039
2020
|
})),
|
|
2040
|
-
subscriptions: [...new Set((t.subscriptions ?? []).map((e) => e.name))].sort(
|
|
2041
|
-
aggregates: (t.aggregates ?? []).map((n) =>
|
|
2021
|
+
subscriptions: [...new Set((t.subscriptions ?? []).map((e) => e.name))].sort(T),
|
|
2022
|
+
aggregates: (t.aggregates ?? []).map((n) => Er(e, t, n)),
|
|
2023
|
+
routes: (t.routes ?? []).map((n) => {
|
|
2024
|
+
let r = `${t.name} route ${n.name}`;
|
|
2025
|
+
return {
|
|
2026
|
+
name: n.name,
|
|
2027
|
+
method: n.route.method,
|
|
2028
|
+
path: n.route.path,
|
|
2029
|
+
...n.description ? { description: n.description } : {},
|
|
2030
|
+
deprecated: n.deprecated === !0,
|
|
2031
|
+
parameters: (n.parameters ?? []).map((t) => ({
|
|
2032
|
+
name: t.name,
|
|
2033
|
+
location: t.in === "path" ? "path" : "query",
|
|
2034
|
+
type: e.type(t.schema, `${r} ${t.name}`),
|
|
2035
|
+
required: t.required
|
|
2036
|
+
})),
|
|
2037
|
+
...n.request === void 0 ? {} : { requestType: e.type(n.request, `${r} body`) },
|
|
2038
|
+
...n.response === void 0 ? {} : { responseType: e.type(n.response, `${r} answer`) }
|
|
2039
|
+
};
|
|
2040
|
+
})
|
|
2042
2041
|
};
|
|
2043
2042
|
}
|
|
2044
|
-
function
|
|
2045
|
-
|
|
2043
|
+
function wr(e) {
|
|
2044
|
+
return (e.routes ?? []).map((e) => ({
|
|
2045
|
+
method: e.method,
|
|
2046
|
+
path: e.path
|
|
2047
|
+
}));
|
|
2048
|
+
}
|
|
2049
|
+
function Tr(e, t, n) {
|
|
2050
|
+
let r = G(t);
|
|
2046
2051
|
return r === void 0 ? "unknown" : e.refType(r, n);
|
|
2047
2052
|
}
|
|
2048
|
-
function
|
|
2049
|
-
let r = `${t.name}.${n.name}`, i =
|
|
2050
|
-
let n = t.split(".").pop(),
|
|
2053
|
+
function Er(e, t, n) {
|
|
2054
|
+
let r = `${t.name}.${n.name}`, i = A(j(n.name)), a = n.idSource ?? "assigned", o = a === "owner", s = new Set(br(e, n)), c = vr(n).filter((e) => lr.has(e.name)).map((t) => {
|
|
2055
|
+
let n = t.name, i = n.split(".").pop(), a = e.schemaOf(n)?.description, c = $e(M(i)), l = o && (t.routes ?? []).some((e) => !e.path.includes("{id}"));
|
|
2051
2056
|
return {
|
|
2052
|
-
name:
|
|
2053
|
-
member:
|
|
2054
|
-
method:
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
+
name: n,
|
|
2058
|
+
member: N(i),
|
|
2059
|
+
method: c,
|
|
2060
|
+
routes: wr(t),
|
|
2061
|
+
...l ? { ownMethod: `${c}Own` } : {},
|
|
2062
|
+
...s.has(n) ? {
|
|
2063
|
+
bodyType: e.refType(n, r),
|
|
2057
2064
|
bodyGenerated: !0
|
|
2058
|
-
} :
|
|
2059
|
-
...typeof
|
|
2065
|
+
} : cr[n] ? { bodyType: cr[n] } : {},
|
|
2066
|
+
...typeof a == "string" ? { description: a } : {}
|
|
2060
2067
|
};
|
|
2061
|
-
}),
|
|
2062
|
-
let n =
|
|
2063
|
-
(
|
|
2064
|
-
let i =
|
|
2068
|
+
}), l = new Set(c.flatMap((e) => [e.method, e.ownMethod ?? e.method])), u = _r(n).map((t) => {
|
|
2069
|
+
let n = $e(M(t.name));
|
|
2070
|
+
(l.has(n) || n === "gateway") && (n = `${n}Command`), l.add(n);
|
|
2071
|
+
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;
|
|
2072
|
+
o && a && s && !(t.mounted ?? !1) && (c = `${n}Own`, l.has(c) && (c = `${c}Command`), l.add(c));
|
|
2073
|
+
let u = G(t.schema), d = u === void 0 ? void 0 : e.schemaOf(u), f = t.idProperty, p = f !== void 0 && gr(e, d, f);
|
|
2065
2074
|
return {
|
|
2066
2075
|
name: t.name,
|
|
2067
2076
|
method: n,
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
bodyOptional: pr(e, l === void 0 ? void 0 : e.schemaOf(l)),
|
|
2078
|
-
creation: t.creation ?? "NONE",
|
|
2077
|
+
routes: wr(t),
|
|
2078
|
+
...a ? { byIdPath: { path: a.path } } : {},
|
|
2079
|
+
...s ? { unaddressedPath: { path: s.path } } : {},
|
|
2080
|
+
...c === void 0 ? {} : { ownMethod: c },
|
|
2081
|
+
bodyType: Tr(e, t.schema, `${r}.${t.name}`),
|
|
2082
|
+
bodyOptional: hr(e, d, p ? f : void 0),
|
|
2083
|
+
...f === void 0 ? {} : { idProperty: f },
|
|
2084
|
+
...p ? { idComputed: p } : {},
|
|
2085
|
+
creation: t.creation ?? "none",
|
|
2079
2086
|
mounted: t.mounted ?? !1,
|
|
2080
2087
|
produces: t.produces ?? [],
|
|
2081
2088
|
...t.description ? { description: t.description } : {},
|
|
2082
2089
|
...e.textNumbers({ $ref: t.schema }) === void 0 ? {} : { bodyNumbers: !0 }
|
|
2083
2090
|
};
|
|
2084
|
-
}),
|
|
2091
|
+
}), d = e.textNumbers({ $ref: n.state.schema }), f = Object.fromEntries((n.events ?? []).flatMap((r) => {
|
|
2085
2092
|
let i = e.textNumbers({ $ref: r.schema });
|
|
2086
|
-
return i === void 0 ? [] : [[
|
|
2087
|
-
})),
|
|
2093
|
+
return i === void 0 ? [] : [[Dr(t, n, r.name), i]];
|
|
2094
|
+
})), p = Object.fromEntries(_r(n).flatMap((t) => {
|
|
2088
2095
|
let n = e.textNumbers({ $ref: t.schema });
|
|
2089
2096
|
return n === void 0 ? [] : [[t.name, n]];
|
|
2090
|
-
})),
|
|
2091
|
-
...
|
|
2092
|
-
...Object.keys(
|
|
2093
|
-
...Object.keys(
|
|
2094
|
-
},
|
|
2097
|
+
})), m = {
|
|
2098
|
+
...d === void 0 ? {} : { state: d },
|
|
2099
|
+
...Object.keys(f).length === 0 ? {} : { events: f },
|
|
2100
|
+
...Object.keys(p).length === 0 ? {} : { commands: p }
|
|
2101
|
+
}, h = G(n.state.schema), g = h === void 0 ? void 0 : e.schemaOf(h);
|
|
2095
2102
|
return {
|
|
2096
2103
|
context: t.name,
|
|
2097
2104
|
name: n.name,
|
|
2098
2105
|
...n.description ? { description: n.description } : {},
|
|
2099
2106
|
typeName: i,
|
|
2100
2107
|
directory: `${t.name}/${n.name}`,
|
|
2101
|
-
ownership: n.ownership ?? "
|
|
2108
|
+
ownership: n.ownership ?? "owner",
|
|
2109
|
+
idSource: a,
|
|
2102
2110
|
snapshot: n.snapshot?.enabled ?? !0,
|
|
2103
|
-
stateType:
|
|
2104
|
-
stateFields:
|
|
2105
|
-
commands:
|
|
2111
|
+
stateType: Tr(e, n.state.schema, `${r} state`),
|
|
2112
|
+
stateFields: g === void 0 ? [] : e.fields({ $ref: n.state.schema }, "state"),
|
|
2113
|
+
commands: u,
|
|
2106
2114
|
events: (n.events ?? []).map((i) => ({
|
|
2107
2115
|
name: i.name,
|
|
2108
|
-
wireName:
|
|
2116
|
+
wireName: Dr(t, n, i.name),
|
|
2109
2117
|
revision: i.revision ?? 1,
|
|
2110
|
-
type:
|
|
2118
|
+
type: Tr(e, i.schema, `${r}.${i.name}`)
|
|
2111
2119
|
})),
|
|
2112
|
-
lifecycle:
|
|
2120
|
+
lifecycle: c,
|
|
2113
2121
|
queryModels: (n.queries ?? []).map((e) => e.model),
|
|
2114
|
-
...Object.keys(
|
|
2122
|
+
...Object.keys(m).length === 0 ? {} : { textNumbers: m }
|
|
2115
2123
|
};
|
|
2116
2124
|
}
|
|
2117
|
-
function
|
|
2125
|
+
function Dr(e, t, n) {
|
|
2118
2126
|
return n.includes(".") ? n : `${e.name}.${t.name}.${n}`;
|
|
2119
2127
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
let n = e.filter((e) => typeof e == "string" && e !== "").flatMap((e) => Ot(e).split("\n"));
|
|
2128
|
+
// src/emitters/manifestClients.ts
|
|
2129
|
+
var Y = "@ahoo-wang/wow-client", Or = "@ahoo-wang/wow-client/routes";
|
|
2130
|
+
function X(e, t = "") {
|
|
2131
|
+
let n = e.filter((e) => typeof e == "string" && e !== "").flatMap((e) => Dt(e).split("\n"));
|
|
2125
2132
|
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
2133
|
}
|
|
2127
|
-
function
|
|
2134
|
+
function Z(e, t) {
|
|
2128
2135
|
e.add(`\n${t}`);
|
|
2129
2136
|
}
|
|
2130
|
-
function
|
|
2137
|
+
function Q(e) {
|
|
2131
2138
|
return e.length === 0 ? "never" : e.join(" | ");
|
|
2132
2139
|
}
|
|
2133
2140
|
function $(e, t, n, r, i) {
|
|
@@ -2136,44 +2143,106 @@ function $(e, t, n, r, i) {
|
|
|
2136
2143
|
let t = n.get(e);
|
|
2137
2144
|
t !== void 0 && t !== i && a.set(t, [...a.get(t) ?? [], e]);
|
|
2138
2145
|
}
|
|
2139
|
-
for (let [n, r] of a) e.imports.add(
|
|
2146
|
+
for (let [n, r] of a) e.imports.add(R(e.directoryPath, _(t, n)), r);
|
|
2140
2147
|
}
|
|
2141
|
-
function
|
|
2148
|
+
function kr(e, t, n) {
|
|
2142
2149
|
let r = new Map(e.types.map((e) => [e.name, e.file]));
|
|
2143
|
-
for (let i of e.types)
|
|
2150
|
+
for (let i of e.types) Ar(t.module(i.file), i, r, n);
|
|
2144
2151
|
for (let i of e.contexts) {
|
|
2145
|
-
|
|
2146
|
-
for (let e of i.aggregates)
|
|
2152
|
+
Nr(i, t, n);
|
|
2153
|
+
for (let e of i.aggregates) Br(e, i, t, r, n), Gr(e, i, t, r, n), Kr(e, t, r, n);
|
|
2154
|
+
Pr(i, t), Fr(i, t, r, n), Lr(i, t, n);
|
|
2147
2155
|
}
|
|
2148
2156
|
}
|
|
2149
|
-
function
|
|
2157
|
+
function Ar(e, t, n, r) {
|
|
2150
2158
|
$(e, r, n, t.references, t.file);
|
|
2151
|
-
let i =
|
|
2159
|
+
let i = X([t.description, `- key: \`${t.key}\``]);
|
|
2152
2160
|
if (t.properties === void 0) {
|
|
2153
|
-
|
|
2161
|
+
Z(e, `${i}export type ${t.name} = ${t.type};`);
|
|
2154
2162
|
return;
|
|
2155
2163
|
}
|
|
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;`);
|
|
2164
|
+
let a = t.properties.map((e) => `${X([e.description], " ")} ${e.name}${e.optional ? "?" : ""}: ${e.type};`);
|
|
2165
|
+
t.type !== void 0 && a.push(` [key: string]: ${t.type};`), Z(e, `${i}export interface ${t.name} {\n${a.join("\n")}\n}`);
|
|
2172
2166
|
}
|
|
2173
|
-
function
|
|
2174
|
-
|
|
2167
|
+
function jr(e, t) {
|
|
2168
|
+
let n = e.aggregates.map((t) => `${e.name}.${t.name}.`), r = t === void 0 ? `${e.name}.` : `${e.name}.${t.name}.`;
|
|
2169
|
+
return e.errors.filter((e) => t === void 0 ? !n.some((t) => e.code.startsWith(t)) : e.code.startsWith(r)).map((e) => ({
|
|
2170
|
+
member: N((e.code.startsWith(r) ? e.code.slice(r.length) : e.code).split(/[^A-Za-z0-9]+/)) || "ERROR",
|
|
2171
|
+
error: e
|
|
2172
|
+
}));
|
|
2173
|
+
}
|
|
2174
|
+
function Mr(e, t) {
|
|
2175
|
+
return e.length === 0 ? "" : `${t}Errors: {\n${e.map(({ member: e, error: n }) => `${X([`${n.status}: ${n.description ?? n.code}`], `${t} `)}${t} ${e}: ${F(n.code)},`).join("\n")}\n${t}},\n`;
|
|
2176
|
+
}
|
|
2177
|
+
function Nr(e, t, n) {
|
|
2178
|
+
let r = t.module(`${e.directory}/contract.ts`), i = `${e.typeName}Contract`;
|
|
2179
|
+
r.imports.add(Y, ["Hop", "wait"]);
|
|
2180
|
+
for (let t of e.aggregates) r.imports.add(R(r.directoryPath, _(n, t.directory, "aggregate.ts")), [`${t.typeName}Aggregate`]);
|
|
2181
|
+
let a = e.aggregates.map((e) => ` ${e.typeName}: ${e.typeName}Aggregate,\n`);
|
|
2182
|
+
Z(r, `${X([`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: ${F(e.name)},\n${Mr(jr(e), " ")}${a.join("")}} as const;`), Z(r, `${X([`An error code of \`${e.name}\`, of the context or of one of its aggregates.`])}export type ${e.typeName}ErrorCode = ${Q(e.errors.map((e) => F(e.code)))};`);
|
|
2183
|
+
let o = e.subscriptions.length > 0;
|
|
2184
|
+
o && Z(r, `${X([`The subscriptions of \`${e.name}\` a \`handled\` hop names.`])}export type ${e.typeName}Subscription = ${Q(e.subscriptions.map(F))};`);
|
|
2185
|
+
let s = `${i}.NAME`, c = [
|
|
2186
|
+
` /** Until a command of \`${e.name}\` passed admission. */\n accepted: (): Hop => wait.accepted(${s}),`,
|
|
2187
|
+
` /** Until a command's events are appended to the log of \`${e.name}\`. */\n committed: (): Hop => wait.committed(${s}),`,
|
|
2188
|
+
` /** Until the snapshot of \`${e.name}\` holds the commit. */\n snapshot: (): Hop => wait.snapshot(${s}),`
|
|
2189
|
+
];
|
|
2190
|
+
o && c.push(` /** Until a subscription of \`${e.name}\` handled the commit. */\n handled: (subscription: ${e.typeName}Subscription): Hop => wait.handled(subscription, ${s}),`), Z(r, `${X([`The hops of a wait chain (\`Wow-Wait\`) in \`${e.name}\`.`])}export const ${M(e.name)}Wait = {\n${c.join("\n")}\n} as const;`);
|
|
2191
|
+
}
|
|
2192
|
+
function Pr(e, t) {
|
|
2193
|
+
let n = t.module(`${e.directory}/manifest.ts`), r = `${e.typeName}Manifest`;
|
|
2194
|
+
n.imports.add(Y, ["MANIFEST_FORMAT", "RoutingManifest"]);
|
|
2195
|
+
let i = (e, t, n) => ` { name: ${F(e)}, routes: ${Hr(t)}${n === void 0 ? "" : `, idProperty: ${F(n)}`} },`, a = e.aggregates.map((e) => {
|
|
2196
|
+
let t = [...e.commands.filter((e) => e.routes.length > 0).map((e) => i(e.name, e.routes, e.idProperty)), ...e.lifecycle.map((e) => i(e.name, e.routes))];
|
|
2197
|
+
return ` {\n name: ${F(e.name)},\n commands: [\n${t.join("\n")}\n ],\n },`;
|
|
2198
|
+
}), o = e.routes.map((e) => ` { name: ${F(e.name)}, route: { method: ${F(e.method)}, path: ${F(e.path)} } },`), s = o.length === 0 ? "" : ` routes: [\n${o.join("\n")}\n ],\n`;
|
|
2199
|
+
Z(n, `${X([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: ${F(e.name)},\n aggregates: [\n${a.join("\n")}\n ],\n${s} },\n ],\n};`);
|
|
2200
|
+
}
|
|
2201
|
+
function Fr(e, t, n, r) {
|
|
2202
|
+
if (e.routes.length === 0) return;
|
|
2203
|
+
let i = t.module(`${e.directory}/routes.ts`), a = `${e.typeName}Routes`;
|
|
2204
|
+
i.imports.add(Y, ["RequestOptions", "WowClientOptions"]), i.imports.add(Or, ["ServiceRoutes"]), i.imports.add("./manifest.js", [`${e.typeName}Manifest`]), $(i, r, n, e.routes.flatMap((e) => [
|
|
2205
|
+
e.requestType,
|
|
2206
|
+
e.responseType,
|
|
2207
|
+
...e.parameters.map((e) => e.type)
|
|
2208
|
+
].filter((e) => e !== void 0).flatMap((e) => e.match(/[A-Za-z_$][A-Za-z0-9_$]*/g) ?? [])));
|
|
2209
|
+
let o = e.routes.map((t) => Ir(e, t));
|
|
2210
|
+
Z(i, `${X([`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}`);
|
|
2175
2211
|
}
|
|
2176
|
-
function
|
|
2212
|
+
function Ir(e, t) {
|
|
2213
|
+
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}`);
|
|
2214
|
+
if (t.requestType !== void 0 && i.push(`body: ${t.requestType}`), r.length > 0) {
|
|
2215
|
+
let e = r.map((e) => `readonly ${P(e.name)}${e.required ? "" : "?"}: ${e.type}`).join("; "), t = r.some((e) => e.required);
|
|
2216
|
+
i.push(`query${t ? "" : "?"}: { ${e} }`);
|
|
2217
|
+
}
|
|
2218
|
+
i.push("options?: RequestOptions");
|
|
2219
|
+
let a = t.responseType ?? "void", o = [
|
|
2220
|
+
...n.length === 0 ? [] : [`path: { ${n.map((e) => P(e.name)).join(", ")} }`],
|
|
2221
|
+
...t.requestType === void 0 ? [] : ["body"],
|
|
2222
|
+
...r.length === 0 ? [] : ["query"]
|
|
2223
|
+
];
|
|
2224
|
+
return `${X([
|
|
2225
|
+
t.description,
|
|
2226
|
+
`\`${t.method} ${t.path}\``,
|
|
2227
|
+
t.deprecated ? "@deprecated The service deprecates this route." : void 0
|
|
2228
|
+
], " ")} ${P(t.name)}(${i.join(", ")}): Promise<${a}> {\n return this.routes.call(${F(e.name)}, ${F(t.name)}, { ${o.join(", ")} }, options) as Promise<${a}>;\n }`;
|
|
2229
|
+
}
|
|
2230
|
+
function Lr(e, t, n) {
|
|
2231
|
+
let r = t.module(`${e.directory}/client.ts`), i = `${e.typeName}Client`;
|
|
2232
|
+
r.imports.add(Y, ["CommandClient", "WowClientOptions"]), r.imports.add("./manifest.js", [`${e.typeName}Manifest`]);
|
|
2233
|
+
let a = [], o = [];
|
|
2234
|
+
for (let t of e.aggregates) {
|
|
2235
|
+
let e = t.typeName, i = (e) => R(r.directoryPath, _(n, t.directory, e)), s = [["commands", `${e}CommandClient`]];
|
|
2236
|
+
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));
|
|
2237
|
+
let c = P(M(t.name));
|
|
2238
|
+
a.push(`${X([`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 };`);
|
|
2239
|
+
}
|
|
2240
|
+
e.routes.length > 0 && (r.imports.add("./routes.js", [`${e.typeName}Routes`]), a.push(`${X([`The service routes of \`${e.name}\`.`], " ")} readonly routes: ${e.typeName}Routes;`), o.push(` this.routes = new ${e.typeName}Routes(options);`)), Z(r, `${X([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}`);
|
|
2241
|
+
}
|
|
2242
|
+
function Rr(e) {
|
|
2243
|
+
return e === !0 ? "true" : `{ ${Object.entries(e).map(([e, t]) => `${P(e)}: ${Rr(t)}`).join(", ")} }`;
|
|
2244
|
+
}
|
|
2245
|
+
function zr(e) {
|
|
2177
2246
|
let t = e.textNumbers;
|
|
2178
2247
|
return t === void 0 ? "" : ` textNumbers: {\n${[
|
|
2179
2248
|
"state",
|
|
@@ -2181,61 +2250,74 @@ function Dr(e) {
|
|
|
2181
2250
|
"commands"
|
|
2182
2251
|
].flatMap((e) => {
|
|
2183
2252
|
let n = t[e];
|
|
2184
|
-
return n === void 0 ? [] : e === "state" ? [` state: ${
|
|
2253
|
+
return n === void 0 ? [] : e === "state" ? [` state: ${Rr(n)},`] : [` ${e}: {\n${Object.entries(n).map(([e, t]) => ` ${P(e)}: ${Rr(t)},`).join("\n")}\n },`];
|
|
2185
2254
|
}).join("\n")}\n },\n`;
|
|
2186
2255
|
}
|
|
2187
|
-
function
|
|
2256
|
+
function Br(e, t, n, r, i) {
|
|
2188
2257
|
let a = n.module(`${e.directory}/aggregate.ts`), o = e.typeName;
|
|
2189
|
-
|
|
2190
|
-
let s = e.events.map((e) => `
|
|
2191
|
-
a.imports.add(
|
|
2258
|
+
Z(a, `${X([`The aggregate \`${e.context}.${e.name}\`.`, e.description])}export const ${o}Aggregate = {\n context: ${F(t.name)},\n name: ${F(e.name)},\n path: ${F(`/${t.name}/${e.name}`)},\n ownership: ${F(e.ownership)},\n${e.idSource === "assigned" ? "" : ` idSource: ${F(e.idSource)},\n`} snapshot: ${e.snapshot},\n${zr(e)}${Mr(jr(t, e), " ")}} as const;`), Z(a, `${X([`The \`state.*\` paths of \`${e.name}\`'s snapshots a query filters, sorts and projects on.`])}export type ${o}StateField = ${Q(e.stateFields.map(F))};`);
|
|
2259
|
+
let s = e.events.map((e) => `CommittedEvent<${F(e.wireName)}, ${e.type}>`);
|
|
2260
|
+
a.imports.add(Y, s.length > 0 ? ["CommittedEvent", "SystemEvent"] : ["SystemEvent"]), Z(a, `${X([`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 = ${Q([...s, "SystemEvent"])};`), $(a, i, r, e.events.map((e) => e.type));
|
|
2192
2261
|
}
|
|
2193
|
-
function
|
|
2194
|
-
let
|
|
2195
|
-
return
|
|
2262
|
+
function Vr(e, t) {
|
|
2263
|
+
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;
|
|
2264
|
+
return X([
|
|
2196
2265
|
e.description,
|
|
2197
|
-
`\`${e.name}\`${e.mounted ? ", mounted (a transformer finds its aggregate)" : ""}: ${
|
|
2198
|
-
|
|
2266
|
+
`\`${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}.`,
|
|
2267
|
+
t === !1 ? "By id, for a caller with no owner; `" + e.ownMethod + "` sends it to the caller's own." : void 0,
|
|
2268
|
+
e.idProperty === void 0 ? void 0 : `Its body names its aggregate: \`${e.idProperty}\`${e.idComputed ? ", which the service computes from the fields given" : ""}.`,
|
|
2269
|
+
r,
|
|
2199
2270
|
e.produces.length > 0 ? `Produces ${e.produces.map((e) => `\`${e}\``).join(", ")}.` : void 0
|
|
2200
2271
|
], " ");
|
|
2201
2272
|
}
|
|
2202
|
-
function
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2273
|
+
function Hr(e) {
|
|
2274
|
+
return `[${e.map((e) => `{ method: ${F(e.method)}, path: ${F(e.path)} }`).join(", ")}]`;
|
|
2275
|
+
}
|
|
2276
|
+
function Ur(e, t, n, r) {
|
|
2277
|
+
let i = e.bodyType === "unknown" ? "object" : e.bodyType, a = e.idComputed ? `Omit<${i}, ${F(e.idProperty)}>` : i, o = e.bodyOptional ? `body: ${a} = {}` : `body: ${a}`, s = n ? "stream" : "wait", c = n ? "Promise<CommandResultStream>" : "Promise<CommandResult>", l = r === !0 ? e.ownMethod : e.method, u = n ? `${l}Stream` : l, d = n ? X([`\`${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), f = F(`${t.context}.${t.name}.${e.name}`), p = (e) => `{ ...options, command: ${f}, body${e} }`, m = r === void 0 ? e.byIdPath : !r, h = r === void 0 ? e.unaddressedPath : r, g = m && h ? "CreateCommandOptions" : "CommandOptions", _ = m && !h ? "id: string, " : "", v = p(m && !h ? ", id" : "");
|
|
2278
|
+
return n ? `${d} ${u}(${_}${o}, options?: ${g}): ${c} {\n return this.client.${s}(${v});\n }` : Wr(d, u, `${_}${o}`, g, v);
|
|
2279
|
+
}
|
|
2280
|
+
function Wr(e, t, n, r, i) {
|
|
2281
|
+
return `${e} ${t}(${n ? `${n}, ` : ""}options?: ${r}): Promise<CommandResult> {\n return this.client.wait(${i});\n }`;
|
|
2282
|
+
}
|
|
2283
|
+
function Gr(e, t, n, r, i) {
|
|
2284
|
+
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 ? [Ur(t, e, !1), Ur(t, e, !0)] : [!1, !0].flatMap((n) => [Ur(t, e, !1, n), Ur(t, e, !0, n)])), l = [
|
|
2285
|
+
"CommandClient",
|
|
2211
2286
|
"CommandResult",
|
|
2212
2287
|
"WowClientOptions"
|
|
2213
2288
|
];
|
|
2214
|
-
s.length > 0 &&
|
|
2289
|
+
s.length > 0 && l.push("CommandResultStream");
|
|
2290
|
+
let u = (e) => e.byIdPath !== void 0 && e.unaddressedPath !== void 0 && e.ownMethod === void 0;
|
|
2291
|
+
s.some(u) && l.push("CreateCommandOptions"), (s.some((e) => !u(e)) || e.lifecycle.length > 0) && l.push("CommandOptions");
|
|
2215
2292
|
let d = [];
|
|
2216
2293
|
for (let t of e.lifecycle) {
|
|
2217
|
-
|
|
2218
|
-
let
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2294
|
+
l.push("LifecycleCommands"), t.bodyType && (t.bodyGenerated ? d : l).push(t.bodyType);
|
|
2295
|
+
let n = t.bodyType ? `body: ${t.bodyType}` : "", r = (n) => `{ ...options, command: LifecycleCommands.${t.member}, type: { context: ${F(e.context)}, name: ${F(e.name)} }${n ? ", id" : ""}${t.bodyType ? ", body" : ""} }`;
|
|
2296
|
+
c.push(Wr(X([
|
|
2297
|
+
t.description,
|
|
2298
|
+
`The lifecycle command \`${t.name}\`.`,
|
|
2299
|
+
t.ownMethod === void 0 ? void 0 : `By id, for a caller with no owner; \`${t.ownMethod}\` sends it to the caller's own.`
|
|
2300
|
+
], " "), t.method, n ? `id: string, ${n}` : "id: string", "CommandOptions", r(!0))), t.ownMethod !== void 0 && c.push(Wr(X([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)));
|
|
2301
|
+
}
|
|
2302
|
+
let f = s.filter((e) => e.bodyNumbers);
|
|
2303
|
+
f.length > 0 && a.imports.add("./aggregate.js", [`${o}Aggregate`]);
|
|
2304
|
+
let p = f.length ? `, bodyNumbers: {\n${f.map((t) => ` ${F(`${e.context}.${e.name}.${t.name}`)}: ${o}Aggregate.textNumbers.commands.${P(t.name) === t.name ? t.name : `[${F(t.name)}]`},`).join("\n")}\n }` : "", m = `${t.typeName}Manifest`;
|
|
2305
|
+
a.imports.add(R(a.directoryPath, _(i, t.directory, "manifest.ts")), [m]), a.imports.add(Y, [...new Set(l)].sort()), $(a, i, r, [...s.map((e) => e.bodyType), ...d]), Z(a, `${X([`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}`);
|
|
2306
|
+
}
|
|
2307
|
+
function Kr(e, t, n, r) {
|
|
2308
|
+
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 }`;
|
|
2309
|
+
e.queryModels.includes("snapshot") && (l.push("SnapshotQueryClient"), u.push(`${a}StateField`), Z(i, `${X([`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"), Z(i, `${X([`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}`)), Z(i, `${X([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(Y, l.sort()), i.imports.add("./aggregate.js", u), $(i, r, n, [o]);
|
|
2310
|
+
}
|
|
2311
|
+
// src/openapi/document.ts
|
|
2312
|
+
function qr(e) {
|
|
2230
2313
|
return {
|
|
2231
2314
|
openAPI: e,
|
|
2232
2315
|
components: e.components,
|
|
2233
|
-
endpoints:
|
|
2316
|
+
endpoints: We(e.paths, e.components)
|
|
2234
2317
|
};
|
|
2235
2318
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
var Pr = ".wow-generator.json", Fr = class e {
|
|
2319
|
+
// src/output/outputStore.ts
|
|
2320
|
+
var Jr = ".wow-generator.json", Yr = class e {
|
|
2239
2321
|
project;
|
|
2240
2322
|
outputPath;
|
|
2241
2323
|
outputDir;
|
|
@@ -2248,12 +2330,12 @@ var Pr = ".wow-generator.json", Fr = class e {
|
|
|
2248
2330
|
static open(t, n, r) {
|
|
2249
2331
|
let i = t.getFileSystem(), a = n;
|
|
2250
2332
|
n = p(i.getCurrentDirectory(), n);
|
|
2251
|
-
let o = d(n,
|
|
2333
|
+
let o = d(n, Jr), s = /* @__PURE__ */ new Map();
|
|
2252
2334
|
if (i.fileExistsSync(o)) {
|
|
2253
|
-
let e =
|
|
2335
|
+
let e = Xr(o, i.readFileSync(o));
|
|
2254
2336
|
for (let [t, r] of Object.entries(e.files)) {
|
|
2255
2337
|
let e = p(n, t);
|
|
2256
|
-
if (
|
|
2338
|
+
if (ei(n, e), u(t) || !t.endsWith(".ts") || typeof r != "string" || !/^[a-f0-9]{64}$/.test(r)) throw new y("output", `Invalid generated file entry in ${o}: ${t}`);
|
|
2257
2339
|
s.set(e, r);
|
|
2258
2340
|
}
|
|
2259
2341
|
}
|
|
@@ -2265,8 +2347,8 @@ var Pr = ".wow-generator.json", Fr = class e {
|
|
|
2265
2347
|
return this.written;
|
|
2266
2348
|
}
|
|
2267
2349
|
claim(e, t = this.outputPath) {
|
|
2268
|
-
let n =
|
|
2269
|
-
|
|
2350
|
+
let n = ie(t, e);
|
|
2351
|
+
ei(t, n);
|
|
2270
2352
|
let r = this.project.getSourceFile(n) ?? this.project.createSourceFile(n, "", { overwrite: !0 }), i = r.getFilePath();
|
|
2271
2353
|
return this.written.has(i) || (r.removeText(), this.written.add(i)), r;
|
|
2272
2354
|
}
|
|
@@ -2277,65 +2359,64 @@ var Pr = ".wow-generator.json", Fr = class e {
|
|
|
2277
2359
|
async commit(e) {
|
|
2278
2360
|
e?.throwIfAborted();
|
|
2279
2361
|
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
|
|
2362
|
+
for (let e of this.stale) !this.written.has(e) && n.has(e.toLowerCase()) && this.isUnchanged(e, this.previous.get(e)) && (await $r("delete", e, () => t.delete(e)), this.stale.delete(e));
|
|
2281
2363
|
let r = [...this.written].sort().map((e) => this.project.getSourceFileOrThrow(e));
|
|
2282
2364
|
(await Promise.allSettled(r.map((e) => e.save()))).forEach((e, t) => {
|
|
2283
|
-
if (e.status === "rejected") throw
|
|
2365
|
+
if (e.status === "rejected") throw Qr("write", r[t].getFilePath(), e.reason);
|
|
2284
2366
|
}), 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,
|
|
2367
|
+
for (let e of this.stale) !this.written.has(e) && this.isUnchanged(e, this.previous.get(e)) && await $r("delete", e, () => t.delete(e));
|
|
2368
|
+
let i = d(this.outputDir, Jr), a = JSON.stringify({
|
|
2287
2369
|
version: 1,
|
|
2288
|
-
files: Object.fromEntries(r.map((e) => [f(this.outputDir, e.getFilePath()).split(m).join("/"),
|
|
2370
|
+
files: Object.fromEntries(r.map((e) => [f(this.outputDir, e.getFilePath()).split(m).join("/"), Zr(t.readFileSync(e.getFilePath()))]))
|
|
2289
2371
|
}, null, 2) + "\n";
|
|
2290
|
-
await
|
|
2372
|
+
await $r("write", i, async () => {
|
|
2291
2373
|
t.mkdirSync(this.outputDir), await t.writeFile(i, a);
|
|
2292
2374
|
});
|
|
2293
2375
|
}
|
|
2294
2376
|
isUnchanged(e, t) {
|
|
2295
2377
|
let n = this.project.getFileSystem();
|
|
2296
|
-
return n.fileExistsSync(e) ? (
|
|
2378
|
+
return n.fileExistsSync(e) ? (ei(n.realpathSync(this.outputDir), n.realpathSync(e)), Zr(n.readFileSync(e)) === t) : !1;
|
|
2297
2379
|
}
|
|
2298
2380
|
};
|
|
2299
|
-
function
|
|
2381
|
+
function Xr(e, t) {
|
|
2300
2382
|
let n = "delete it; without it this run cannot remove the stale files of the last run", r;
|
|
2301
2383
|
try {
|
|
2302
2384
|
r = JSON.parse(t);
|
|
2303
2385
|
} catch (t) {
|
|
2304
|
-
throw new
|
|
2386
|
+
throw new y("output", `Cannot parse the generation manifest ${e}: ${b(t)}. Resolve the merge conflict in it if it has one, or ${n}.`, { cause: t });
|
|
2305
2387
|
}
|
|
2306
2388
|
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
|
|
2389
|
+
if (typeof i == "number" && Number.isInteger(i) && i > 1) throw new y("output", `The generation manifest ${e} was written by a newer wow-generator (manifest version ${i}); this one reads version 1. Upgrade wow-generator.`);
|
|
2390
|
+
if (i !== 1 || !r.files || typeof r.files != "object" || Array.isArray(r.files)) throw new y("output", `Invalid generation manifest ${e}: expected "version": 1 and a "files" object. Restore it from version control, or ${n}.`);
|
|
2309
2391
|
return r;
|
|
2310
2392
|
}
|
|
2311
|
-
function
|
|
2393
|
+
function Zr(e) {
|
|
2312
2394
|
if (!l.sys.createSHA256Hash) throw Error("SHA-256 hashing is unavailable in this environment.");
|
|
2313
2395
|
return l.sys.createSHA256Hash(e);
|
|
2314
2396
|
}
|
|
2315
|
-
function
|
|
2316
|
-
return n instanceof
|
|
2397
|
+
function Qr(e, t, n) {
|
|
2398
|
+
return n instanceof y ? n : new y("output", `Cannot ${e} ${t}: ${b(n)}`, { cause: n });
|
|
2317
2399
|
}
|
|
2318
|
-
async function
|
|
2400
|
+
async function $r(e, t, n) {
|
|
2319
2401
|
try {
|
|
2320
2402
|
await n();
|
|
2321
2403
|
} catch (n) {
|
|
2322
|
-
throw
|
|
2404
|
+
throw Qr(e, t, n);
|
|
2323
2405
|
}
|
|
2324
2406
|
}
|
|
2325
|
-
function
|
|
2407
|
+
function ei(e, t) {
|
|
2326
2408
|
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
|
|
2409
|
+
if (a === "" || a.startsWith("..") || u(a)) throw new y("output", `Path traversal detected: "${t}" resolves outside the output directory "${e}".`);
|
|
2328
2410
|
}
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
var Vr = Symbol("project"), Hr = Symbol("signal"), Ur = class {
|
|
2411
|
+
// src/pipeline/seams.ts
|
|
2412
|
+
var ti = Symbol("project"), ni = Symbol("signal"), ri = class {
|
|
2332
2413
|
options;
|
|
2333
2414
|
project;
|
|
2334
2415
|
logger;
|
|
2335
2416
|
signal;
|
|
2336
2417
|
output;
|
|
2337
2418
|
constructor(e) {
|
|
2338
|
-
this.options = e, this.logger = e.logger ?? new
|
|
2419
|
+
this.options = e, this.logger = e.logger ?? new ne(), this.signal = e[ni], this.project = e[ti] ?? ii(e.tsConfigFilePath), this.project.manipulationSettings.set({
|
|
2339
2420
|
indentationText: t.TwoSpaces,
|
|
2340
2421
|
quoteKind: i.Single,
|
|
2341
2422
|
useTrailingCommas: !0
|
|
@@ -2353,12 +2434,12 @@ var Vr = Symbol("project"), Hr = Symbol("signal"), Ur = class {
|
|
|
2353
2434
|
}, o = await qn(n.configPath, e, a);
|
|
2354
2435
|
i(o.warnings), t?.throwIfAborted(), e.debug("Parsing the input document");
|
|
2355
2436
|
let s = await Un(n.inputPath, a);
|
|
2356
|
-
if (t?.throwIfAborted(),
|
|
2437
|
+
if (t?.throwIfAborted(), ar(s)) return this.generateFromManifest(or(s, n.inputPath), o.origin, i, () => r);
|
|
2357
2438
|
let c = Wn(s, n.inputPath);
|
|
2358
2439
|
e.debug("OpenAPI specification parsed successfully");
|
|
2359
|
-
let l =
|
|
2360
|
-
if (l.length > 0) throw new
|
|
2361
|
-
let u =
|
|
2440
|
+
let l = ce(c);
|
|
2441
|
+
if (l.length > 0) throw new y("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 ? ", …" : ""}`);
|
|
2442
|
+
let u = qr(c), d = Yr.open(this.project, n.outputDir, this.output);
|
|
2362
2443
|
this.output = d, e.debug("Analysing the document");
|
|
2363
2444
|
let f = _t(u, o.config);
|
|
2364
2445
|
i(f.warnings), e.debug("Writing generated modules");
|
|
@@ -2377,12 +2458,12 @@ var Vr = Symbol("project"), Hr = Symbol("signal"), Ur = class {
|
|
|
2377
2458
|
};
|
|
2378
2459
|
}
|
|
2379
2460
|
async generateFromManifest(e, t, n, r) {
|
|
2380
|
-
let { logger: i, signal: a, options: o } = this, s =
|
|
2461
|
+
let { logger: i, signal: a, options: o } = this, s = Yr.open(this.project, o.outputDir, this.output);
|
|
2381
2462
|
this.output = s, i.debug("Analysing the Manifest");
|
|
2382
|
-
let c =
|
|
2463
|
+
let c = xr(e);
|
|
2383
2464
|
n(c.warnings);
|
|
2384
2465
|
let l = new bt((e) => s.claim(e));
|
|
2385
|
-
|
|
2466
|
+
kr(c.model, l, o.outputDir), l.build(), s.forgetStale();
|
|
2386
2467
|
let u = this.project.getDirectory(o.outputDir);
|
|
2387
2468
|
return u && (n(wn(u, (e) => s.claim("index.ts", e))), In(u.getDescendantSourceFiles().filter((e) => s.files.has(e.getFilePath())), i)), await s.commit(a), i.debug("Code generation from the Manifest completed successfully"), {
|
|
2388
2469
|
files: [...s.files].sort(),
|
|
@@ -2391,17 +2472,16 @@ var Vr = Symbol("project"), Hr = Symbol("signal"), Ur = class {
|
|
|
2391
2472
|
};
|
|
2392
2473
|
}
|
|
2393
2474
|
};
|
|
2394
|
-
function
|
|
2475
|
+
function ii(e) {
|
|
2395
2476
|
try {
|
|
2396
2477
|
return new r({
|
|
2397
2478
|
tsConfigFilePath: e,
|
|
2398
2479
|
skipAddingFilesFromTsConfig: !0
|
|
2399
2480
|
});
|
|
2400
2481
|
} catch (t) {
|
|
2401
|
-
throw new
|
|
2482
|
+
throw new y("configuration", `Cannot read the TypeScript configuration ${e}: ${b(t)}`, { cause: t });
|
|
2402
2483
|
}
|
|
2403
2484
|
}
|
|
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 };
|
|
2485
|
+
export { re as a, v as c, ne as i, ni as n, ee as o, Ln as r, y as s, ri as t };
|
|
2406
2486
|
|
|
2407
|
-
//# sourceMappingURL=codeGenerator-
|
|
2487
|
+
//# sourceMappingURL=codeGenerator-Cxlr_VOh.js.map
|