@ahoo-wang/wow-generator 10.0.0-alpha.5 → 10.0.0-alpha.7

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