convoker 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/command.js CHANGED
@@ -1,88 +1,88 @@
1
- import { D as L, b, c as v, g as M } from "./chunks/color-CiruG_zQ.js";
2
- import { s as V } from "./chunks/index-G2nVXKup.js";
3
- import { m as q, i as O, b as W, a as j } from "./chunks/utils-DdmSEjLc.js";
4
- import { M as R, a as z, L as N, H as A, U as J } from "./chunks/error-Cj2qDfOl.js";
5
- import { P as B, c as K, O as H } from "./chunks/input-COjWPD53.js";
6
- async function G() {
7
- if (W && process.stdout?.writable) {
8
- const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
9
- return n.toWeb(process.stdout);
1
+ import { D as V, b, c as v, g as O } from "./chunks/color-CiruG_zQ.js";
2
+ import { s as R } from "./chunks/index-BluQjWvw.js";
3
+ import { m as z, i as A, b as j, a as P } from "./chunks/utils-DdmSEjLc.js";
4
+ import { M as U, a as J, T as N, C as K, H as L, U as x } from "./chunks/error-CyKscMUD.js";
5
+ import { P as q, c as G, O as F } from "./chunks/input-WNu16aNE.js";
6
+ async function Q() {
7
+ if (j && process.stdout?.writable) {
8
+ const { Writable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
9
+ return r.toWeb(process.stdout);
10
10
  }
11
- return O && Deno.stdout?.writable ? Deno.stdout.writable : j && Bun.stdout ? Bun.stdout : new WritableStream({
12
- write(n) {
13
- console.log(String(n));
11
+ return A && Deno.stdout?.writable ? Deno.stdout.writable : P && Bun.stdout ? Bun.stdout : new WritableStream({
12
+ write(r) {
13
+ console.log(String(r));
14
14
  }
15
15
  });
16
16
  }
17
- async function Q() {
18
- if (W && process.stderr?.writable) {
19
- const { Writable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
20
- return n.toWeb(process.stderr);
17
+ async function X() {
18
+ if (j && process.stderr?.writable) {
19
+ const { Writable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
20
+ return r.toWeb(process.stderr);
21
21
  }
22
- return O && Deno.stderr?.writable ? Deno.stderr.writable : j && Bun.stderr ? Bun.stderr : new WritableStream({
23
- write(n) {
24
- console.error(String(n));
22
+ return A && Deno.stderr?.writable ? Deno.stderr.writable : P && Bun.stderr ? Bun.stderr : new WritableStream({
23
+ write(r) {
24
+ console.error(String(r));
25
25
  }
26
26
  });
27
27
  }
28
- async function X() {
29
- if (W && process.stdin?.readable) {
30
- const { Readable: n } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
31
- return n.toWeb(process.stdin);
28
+ async function Y() {
29
+ if (j && process.stdin?.readable) {
30
+ const { Readable: r } = await import("./chunks/__vite-browser-external-DQYBmsno.js").then((t) => t._);
31
+ return r.toWeb(process.stdin);
32
32
  }
33
- return O && Deno.stdin?.readable ? Deno.stdin.readable : j ? Bun.stdin.stream() : new ReadableStream({
34
- start(n) {
35
- n.close();
33
+ return A && Deno.stdin?.readable ? Deno.stdin.readable : P ? Bun.stdin.stream() : new ReadableStream({
34
+ start(r) {
35
+ r.close();
36
36
  }
37
37
  });
38
38
  }
39
- let m = L, g;
40
- function I(n) {
41
- m = n;
39
+ let m = V, g;
40
+ function H(r) {
41
+ m = r;
42
42
  }
43
- async function T(n) {
44
- g = q(
43
+ async function _(r) {
44
+ g = z(
45
45
  {
46
46
  format: "text",
47
- stdout: await G(),
48
- stderr: await Q(),
49
- stdin: await X()
47
+ stdout: await Q(),
48
+ stderr: await X(),
49
+ stdin: await Y()
50
50
  },
51
- n
51
+ r
52
52
  );
53
53
  }
54
- async function Y() {
55
- await T({});
54
+ async function Z() {
55
+ await _({});
56
56
  }
57
- function S(n, ...t) {
58
- const e = (/* @__PURE__ */ new Date()).toISOString(), r = t.map((o) => typeof o == "string" ? o : JSON.stringify(o, null, 2)).join(" ");
57
+ function S(r, ...t) {
58
+ const e = (/* @__PURE__ */ new Date()).toISOString(), n = t.map((i) => typeof i == "string" ? i : JSON.stringify(i, null, 2)).join(" ");
59
59
  switch (g.format) {
60
60
  case "json":
61
- return JSON.stringify({ timestamp: e, level: n, message: r }) + `
61
+ return JSON.stringify({ timestamp: e, level: r, message: n }) + `
62
62
  `;
63
63
  case "xml":
64
64
  return `<log>
65
65
  <timestamp>${e}</timestamp>
66
- <level>${n}</level>
67
- <message>${r}</message>
66
+ <level>${r}</level>
67
+ <message>${n}</message>
68
68
  </log>
69
69
  `;
70
70
  case "yaml":
71
71
  return `- timestamp: ${e}
72
- level: ${n}
73
- message: "${r.replace(/"/g, '\\"')}"
72
+ level: ${r}
73
+ message: "${n.replace(/"/g, '\\"')}"
74
74
  `;
75
75
  case "csv":
76
- return `"${e}","${n}","${r.replace(/"/g, '""')}"
76
+ return `"${e}","${r}","${n.replace(/"/g, '""')}"
77
77
  `;
78
78
  case "text":
79
79
  default:
80
- return `[${e}] [${n.toUpperCase()}] ${r}
80
+ return `[${e}] [${r.toUpperCase()}] ${n}
81
81
  `;
82
82
  }
83
83
  }
84
- function E(n, t) {
85
- switch (n) {
84
+ function E(r, t) {
85
+ switch (r) {
86
86
  case "trace":
87
87
  return m.secondary ? m.secondary(t) : t;
88
88
  case "info":
@@ -97,54 +97,54 @@ function E(n, t) {
97
97
  return t;
98
98
  }
99
99
  }
100
- async function k(n, t) {
101
- const e = n.getWriter();
100
+ async function k(r, t) {
101
+ const e = r.getWriter();
102
102
  try {
103
103
  await e.write(t);
104
104
  } finally {
105
105
  e.releaseLock();
106
106
  }
107
107
  }
108
- async function Z(...n) {
109
- const t = S("trace", ...n), e = E("trace", t);
108
+ async function ee(...r) {
109
+ const t = S("trace", ...r), e = E("trace", t);
110
110
  await k(g.stdout, e);
111
111
  }
112
- async function x(...n) {
113
- const t = S("info", ...n), e = E("info", t);
112
+ async function te(...r) {
113
+ const t = S("info", ...r), e = E("info", t);
114
114
  await k(g.stdout, e);
115
115
  }
116
- async function tt(...n) {
117
- const t = S("warn", ...n), e = E("warn", t);
116
+ async function ne(...r) {
117
+ const t = S("warn", ...r), e = E("warn", t);
118
118
  await k(g.stdout, e);
119
119
  }
120
- async function et(...n) {
121
- const t = S("error", ...n), e = E("error", t);
120
+ async function re(...r) {
121
+ const t = S("error", ...r), e = E("error", t);
122
122
  await k(g.stderr, e);
123
123
  }
124
- async function nt(...n) {
125
- const t = S("fatal", ...n), e = E("fatal", t);
126
- await k(g.stderr, e), O ? Deno.exit(-1) : (W || j) && process.exit(-1);
124
+ async function se(...r) {
125
+ const t = S("fatal", ...r), e = E("fatal", t);
126
+ await k(g.stderr, e), A ? Deno.exit(-1) : (j || P) && process.exit(-1);
127
127
  }
128
- const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
128
+ const de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
129
129
  __proto__: null,
130
- error: et,
131
- fatal: nt,
132
- info: x,
133
- setConfig: T,
134
- setTheme: I,
135
- setup: Y,
136
- trace: Z,
137
- warn: tt
130
+ error: re,
131
+ fatal: se,
132
+ info: te,
133
+ setConfig: _,
134
+ setTheme: H,
135
+ setup: Z,
136
+ trace: ee,
137
+ warn: ne
138
138
  }, Symbol.toStringTag, { value: "Module" }));
139
- class F {
139
+ class B {
140
140
  /**
141
141
  * Creates a new command.
142
142
  * @param names The names (aliases).
143
143
  * @param desc The description.
144
144
  * @param version The version.
145
145
  */
146
- constructor(t, e, r) {
147
- this.$children = /* @__PURE__ */ new Map(), this.$allowUnknownOptions = !1, this.$input = {}, this.$fn = void 0, this.$errorFn = void 0, this.$names = Array.isArray(t) ? t : [t], this.$description = e, this.$version = r;
146
+ constructor(t, e, n) {
147
+ this.$children = /* @__PURE__ */ new Map(), this.$allowUnknownOptions = !1, this.$allowSurpassArgLimit = !1, this.$input = {}, this.$fn = void 0, this.$middlewares = [], this.$errorFn = void 0, this.$names = Array.isArray(t) ? t : [t], this.$description = e, this.$version = n;
148
148
  }
149
149
  /**
150
150
  * Adds a set of aliases to this command.
@@ -178,6 +178,14 @@ class F {
178
178
  input(t) {
179
179
  return this.$input = t, this;
180
180
  }
181
+ /**
182
+ * Adds a chain of middlewares.
183
+ * @param fns The middlewares to use.
184
+ * @returns this
185
+ */
186
+ use(...t) {
187
+ return this.$middlewares.push(...t), this;
188
+ }
181
189
  /**
182
190
  * Sets the action function for this command.
183
191
  * @param fn The action.
@@ -202,17 +210,17 @@ class F {
202
210
  add(t) {
203
211
  t.$parent = this;
204
212
  const e = { command: t, alias: t.$names[0] };
205
- for (let r = 0; r < t.$names.length; r++)
206
- r === 0 && this.$children.set(t.$names[r], { command: t }), this.$children.set(t.$names[r], e);
213
+ for (let n = 0; n < t.$names.length; n++)
214
+ n === 0 && this.$children.set(t.$names[n], { command: t }), this.$children.set(t.$names[n], e);
207
215
  return this;
208
216
  }
209
- subCommand(t, e, r) {
217
+ subCommand(t, e, n) {
210
218
  if (typeof e == "function") {
211
- const c = new F(t);
212
- return e(c), this.add(c), this;
219
+ const a = new B(t);
220
+ return e(a), this.add(a), this;
213
221
  }
214
- const o = new F(t, e, r);
215
- return this.add(o), o;
222
+ const i = new B(t, e, n);
223
+ return this.add(i), i;
216
224
  }
217
225
  /**
218
226
  * Allows unknown options.
@@ -227,81 +235,89 @@ class F {
227
235
  * @returns A parse result.
228
236
  */
229
237
  async parse(t) {
230
- let e = this, r = !1;
231
- const o = {}, c = [], d = {}, s = [], a = e.buildInputMap();
232
- function u(f, i) {
233
- const l = a.get(f);
234
- return l ? l.value : (!e.$allowUnknownOptions && !i && s.push(new J(e, f)), null);
238
+ let e = this, n = !1;
239
+ const i = {}, a = [], f = {}, s = [], c = e.buildInputMap();
240
+ function d(u, o) {
241
+ const l = c.get(u);
242
+ return l ? l.value : (!e.$allowUnknownOptions && !o && s.push(new x(e, u)), null);
235
243
  }
236
- function p(f, i, l) {
237
- i.$kind === "boolean" ? d[f] = "true" : l !== void 0 && (d[f] = l);
244
+ function h(u, o, l) {
245
+ o.$kind === "boolean" ? f[u] = "true" : l !== void 0 && (f[u] = l);
238
246
  }
239
- let h = !1, C = !1;
240
- for (let f = 0; f < t.length; f++) {
241
- const i = t[f];
242
- if (i.startsWith("--")) {
243
- const [l, w] = i.slice(2).split("=");
247
+ let p = !1, W = !1;
248
+ for (let u = 0; u < t.length; u++) {
249
+ const o = t[u];
250
+ if (o.startsWith("--")) {
251
+ const [l, w] = o.slice(2).split("=");
244
252
  let y = !1;
245
- l === "help" ? (C = !0, y = !0) : l === "version" && (h = !0, y = !0);
246
- const $ = u(l, y);
247
- $ && (w === void 0 ? p(
253
+ l === "help" ? (W = !0, y = !0) : l === "version" && (p = !0, y = !0);
254
+ const $ = d(l, y);
255
+ $ && (w === void 0 ? h(
248
256
  l,
249
257
  $,
250
- $.$kind === "boolean" ? void 0 : t[++f]
251
- ) : p(l, $, w));
252
- } else if (i.startsWith("-")) {
253
- const [l, w] = i.slice(1).split("="), y = l.split("");
258
+ $.$kind === "boolean" ? void 0 : t[++u]
259
+ ) : h(l, $, w));
260
+ } else if (o.startsWith("-")) {
261
+ const [l, w] = o.slice(1).split("="), y = l.split("");
254
262
  let $ = w;
255
263
  for (const D of y) {
256
- let U = !1;
257
- D === "h" ? (C = !0, U = !0) : D === "V" && (h = !0, U = !0);
258
- const P = u(D, U);
259
- P && (P.$kind !== "boolean" && $ === void 0 && ($ = t[++f]), p(D, P, $), $ = void 0);
264
+ let C = !1;
265
+ D === "h" ? (W = !0, C = !0) : D === "V" && (p = !0, C = !0);
266
+ const T = d(D, C);
267
+ T && (T.$kind !== "boolean" && $ === void 0 && ($ = t[++u]), h(D, T, $), $ = void 0);
260
268
  }
261
269
  } else
262
- e.$children.has(i) && !r ? (e = e.$children.get(i).command, e.$theme && (V(e.$theme), I(e.$theme))) : (r = !0, c.push(i));
270
+ e.$children.has(o) && !n ? (e = e.$children.get(o).command, e.$theme && (R(e.$theme), H(e.$theme))) : (n = !0, a.push(o));
263
271
  }
264
- let _ = 0;
265
- for (const f in e.$input) {
266
- const i = e.$input[f];
272
+ let M = 0;
273
+ for (const u in e.$input) {
274
+ const o = e.$input[u];
267
275
  let l;
268
- if (i instanceof B)
269
- l = c[_++];
276
+ if (o instanceof q)
277
+ o.$list ? (l = a.slice(M), M = a.length, !e.$allowSurpassArgLimit && l.length === 0 && o.$required && s.push(new U(e, u, o))) : (l = a[M++], l === void 0 && o.$required && s.push(new U(e, u, o)));
270
278
  else
271
- for (const w of i.$names)
272
- if (d[w] !== void 0) {
273
- l = d[w];
279
+ for (const w of o.$names)
280
+ if (f[w] !== void 0) {
281
+ l = o.$list ? f[w].split(o.$separator ?? ",") : f[w];
274
282
  break;
275
283
  }
276
- l !== void 0 ? o[f] = await K(i.$kind, l) : i.$default !== void 0 ? o[f] = i.$default : i.$required && (i instanceof H ? s.push(new R(e, f, i)) : s.push(new z(e, f, i)));
284
+ l !== void 0 ? i[u] = await G(o.$kind, l) : o.$default !== void 0 ? i[u] = o.$default : o.$required && (o instanceof F ? s.push(new J(e, u, o)) : s.push(new U(e, u, o)));
277
285
  }
278
- return {
279
- input: o,
286
+ const I = a.slice(M);
287
+ return !e.$allowSurpassArgLimit && I.length > 0 && s.push(new N(e)), {
288
+ input: i,
280
289
  command: e,
281
290
  errors: s,
282
- isVersion: h,
283
- isHelp: C
291
+ isVersion: p,
292
+ isHelp: W
284
293
  };
285
294
  }
286
295
  buildInputMap(t) {
287
296
  const e = /* @__PURE__ */ new Map();
288
- let r = 0;
289
- for (const o in this.$input) {
290
- const c = this.$input[o];
291
- if (c instanceof B)
292
- e.set(r++, { value: c, key: o });
297
+ let n = 0;
298
+ for (const i in this.$input) {
299
+ const a = this.$input[i];
300
+ if (a instanceof q)
301
+ e.set(n++, { value: a, key: i });
293
302
  else
294
- for (const d of c.$names)
295
- e.set(d, { value: c, key: o });
303
+ for (const f of a.$names)
304
+ e.set(f, { value: a, key: i });
296
305
  }
297
306
  if (!t)
298
- for (const [o, c] of this.$parent?.buildInputMap() ?? [])
299
- e.set(o, c);
300
- for (const [, { command: o }] of this.$children)
301
- for (const [c, d] of o.buildInputMap(!0))
302
- e.set(c, d);
307
+ for (const [i, a] of this.$parent?.buildInputMap() ?? [])
308
+ e.set(i, a);
309
+ for (const [, { command: i }] of this.$children)
310
+ for (const [a, f] of i.buildInputMap(!0))
311
+ e.set(a, f);
303
312
  return e;
304
313
  }
314
+ /**
315
+ * Allows surpassing the amount of arguments specified.
316
+ * @returns this
317
+ */
318
+ allowSurpassArgLimit() {
319
+ return this.$allowSurpassArgLimit = !0, this;
320
+ }
305
321
  /**
306
322
  * Gets the full command path (name including parents).
307
323
  * @returns The full command path.
@@ -319,51 +335,51 @@ class F {
319
335
  */
320
336
  defaultErrorScreen(t) {
321
337
  let e = !1;
322
- const r = [];
338
+ const n = [];
323
339
  for (const s of t)
324
- s instanceof N ? (s instanceof A || s.print(), e = !0) : r.push(s);
325
- if (r.length) throw r[0];
340
+ s instanceof K ? (s instanceof L || s.print(), e = !0) : n.push(s);
341
+ if (n.length) throw n[0];
326
342
  if (!e) return;
327
- const o = (s, a) => s.padEnd(a, " ");
343
+ const i = (s, c) => s.padEnd(c, " ");
328
344
  console.log(
329
- `${b("usage:")} ${v(this.fullCommandPath())} ${M("[options] [arguments]")}`
345
+ `${b("usage:")} ${v(this.fullCommandPath())} ${O("[options] [arguments]")}`
330
346
  ), this.$description && console.log(`${this.$description}`), this.$version && console.log(`${b("version")} ${this.$version}`);
331
- const c = Object.entries(this.$input).filter(([, s]) => s instanceof H).map(([s, a]) => ({ key: s, entry: a }));
332
- if (c.length > 0) {
347
+ const a = Object.entries(this.$input).filter(([, s]) => s instanceof F).map(([s, c]) => ({ key: s, entry: c }));
348
+ if (a.length > 0) {
333
349
  console.log(b("options:"));
334
350
  const s = Math.max(
335
- ...c.map(({ entry: a }) => a.$names.join(", ").length)
351
+ ...a.map(({ entry: c }) => c.$names.join(", ").length)
336
352
  );
337
- for (const { entry: a } of c) {
338
- const u = a.$names.map((h) => h.length === 1 ? `-${h}` : `--${h}`).join(", "), p = ` ${v(o(u, s + 4))}${M(a.$description ?? "")}`;
339
- console.log(p);
353
+ for (const { entry: c } of a) {
354
+ const d = c.$names.map((p) => p.length === 1 ? `-${p}` : `--${p}`).join(", "), h = ` ${v(i(d, s + 4))}${O(c.$description ?? "")}`;
355
+ console.log(h);
340
356
  }
341
357
  }
342
- const d = Object.entries(this.$input).filter(([, s]) => s instanceof B).map(([s, a]) => ({
358
+ const f = Object.entries(this.$input).filter(([, s]) => s instanceof q).map(([s, c]) => ({
343
359
  key: s,
344
- entry: a
360
+ entry: c
345
361
  }));
346
- if (d.length > 0) {
362
+ if (f.length > 0) {
347
363
  console.log(b("arguments:"));
348
- const s = Math.max(...d.map(({ key: a }) => a.length));
349
- for (const { key: a, entry: u } of d) {
350
- const p = u.$required ? `<${a}>` : `[${a}]`, h = ` ${v(o(p, s + 4))}${M(u.$description ?? "")}`;
351
- console.log(h);
364
+ const s = Math.max(...f.map(({ key: c }) => c.length));
365
+ for (const { key: c, entry: d } of f) {
366
+ const h = d.$required ? `<${c}>` : `[${c}]`, p = ` ${v(i(h, s + 4))}${O(d.$description ?? "")}`;
367
+ console.log(p);
352
368
  }
353
369
  }
354
370
  if (this.$children.size > 0) {
355
371
  console.log(b("sub commands:"));
356
372
  const s = Array.from(
357
373
  new Map(
358
- [...this.$children.values()].map((u) => [
359
- u.command.$names[0],
360
- u.command
374
+ [...this.$children.values()].map((d) => [
375
+ d.command.$names[0],
376
+ d.command
361
377
  ])
362
378
  ).values()
363
- ), a = Math.max(...s.map((u) => u.$names[0].length));
364
- for (const u of s) {
365
- const p = ` ${v(o(u.$names[0], a + 4))}${M(u.$description) ?? ""}`;
366
- console.log(p);
379
+ ), c = Math.max(...s.map((d) => d.$names[0].length));
380
+ for (const d of s) {
381
+ const h = ` ${v(i(d.$names[0], c + 4))}${O(d.$description) ?? ""}`;
382
+ console.log(h);
367
383
  }
368
384
  console.log(), console.log(
369
385
  `run '${v(`${this.fullCommandPath()} <command> --help`)}' for more info on a command.`
@@ -377,10 +393,10 @@ class F {
377
393
  * @returns this
378
394
  */
379
395
  async handleErrors(t, e) {
380
- let r = this;
381
- for (; !r.$errorFn && r.$parent; )
382
- r = r.$parent;
383
- return r.$errorFn ? await r.$errorFn(r, t, e ?? {}) : this.defaultErrorScreen(t), this;
396
+ let n = this;
397
+ for (; !n.$errorFn && n.$parent; )
398
+ n = n.$parent;
399
+ return n.$errorFn ? await n.$errorFn(n, t, e ?? {}) : this.defaultErrorScreen(t), this;
384
400
  }
385
401
  /**
386
402
  * Runs a command.
@@ -391,25 +407,60 @@ class F {
391
407
  t || (t = typeof Bun < "u" ? Bun.argv.slice(2) : typeof Deno < "u" ? Deno.args : process.argv.slice(2));
392
408
  const e = await this.parse(t);
393
409
  if (e.isHelp)
394
- return e.command.handleErrors([new A(e.command)]), this;
410
+ return e.command.handleErrors([new L(e.command)]), this;
395
411
  if (e.isVersion)
396
412
  return console.log(
397
413
  `${e.command.fullCommandPath()} version ${e.command.$version}`
398
414
  ), this;
399
415
  try {
400
- e.errors.length > 0 ? await e.command.handleErrors(e.errors, e.input) : e.command.$fn ? await e.command.$fn(e.input) : await e.command.handleErrors(
401
- [new A(e.command), ...e.errors],
402
- e.input
403
- );
404
- } catch (r) {
405
- r instanceof Error || console.warn(
406
- "[lunarcli] an error that is not instance of `Error` was thrown. this may cause undefined behavior."
407
- ), await e.command.handleErrors([r]);
416
+ if (e.errors.length > 0)
417
+ await e.command.handleErrors(e.errors, e.input);
418
+ else if (!e.command.$fn)
419
+ await e.command.handleErrors(
420
+ [new L(e.command), ...e.errors],
421
+ e.input
422
+ );
423
+ else {
424
+ const n = oe(e.command);
425
+ n.length > 0 ? await ie(n)(e.input, async () => {
426
+ await e.command.$fn?.(e.input);
427
+ }) : await e.command.$fn(e.input);
428
+ }
429
+ } catch (n) {
430
+ n instanceof Error || console.warn(
431
+ "[convoker] an error that is not instance of `Error` was thrown. this may cause undefined behavior."
432
+ ), await e.command.handleErrors([n]);
408
433
  }
409
434
  return this;
410
435
  }
411
436
  }
437
+ function oe(r) {
438
+ const t = [];
439
+ let e = r;
440
+ for (; e; )
441
+ e.$middlewares.length && t.unshift(...e.$middlewares), e = e.$parent;
442
+ return t;
443
+ }
444
+ function ie(r) {
445
+ return (t, e) => {
446
+ let n = -1;
447
+ const i = (a) => {
448
+ if (a <= n)
449
+ return Promise.reject(new Error("next() called multiple times"));
450
+ n = a;
451
+ const f = r[a];
452
+ if (!f)
453
+ return e ? e() : Promise.resolve();
454
+ try {
455
+ return Promise.resolve(f(t, () => i(a + 1)));
456
+ } catch (s) {
457
+ return Promise.reject(s);
458
+ }
459
+ };
460
+ return i(0);
461
+ };
462
+ }
412
463
  export {
413
- F as Command,
414
- ct as l
464
+ B as Command,
465
+ de as l
415
466
  };