@ahoo-wang/wow-generator 10.0.0-alpha.6 → 10.0.0-beta.1

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