@mauroandre/velojs 0.0.56 → 0.0.58

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,8 +1,8 @@
1
1
  import { getRegisteredStreams as W } from "../events.js";
2
- import { trackSocketSession as L, getAppSockets as q, injectWebSocketServer as B, abortAllSocketSessions as F } from "../sockets.js";
2
+ import { trackSocketSession as L, getAppSockets as M, injectWebSocketServer as B, abortAllSocketSessions as F } from "../sockets.js";
3
3
  import { registerChannels as N, getChannelMap as G, __resetChannels as z } from "../channels.js";
4
4
  import { createIsolatedContext as Q, withAppContext as K } from "../app-context.js";
5
- function M(e) {
5
+ function q(e) {
6
6
  if (!e) return;
7
7
  const s = Object.entries(e);
8
8
  if (s.length !== 0)
@@ -13,8 +13,8 @@ function X(e) {
13
13
  for (const l of t) {
14
14
  const c = l.indexOf(";"), f = c === -1 ? l : l.slice(0, c), u = f.indexOf("=");
15
15
  if (u === -1) continue;
16
- const w = f.slice(0, u).trim(), o = f.slice(u + 1).trim();
17
- w && (s[w] = decodeURIComponent(o));
16
+ const p = f.slice(0, u).trim(), o = f.slice(u + 1).trim();
17
+ p && (s[p] = decodeURIComponent(o));
18
18
  }
19
19
  return s;
20
20
  }
@@ -47,44 +47,44 @@ function O(e, s) {
47
47
  return e.startsWith("http://") || e.startsWith("https://") ? e + t : (e.startsWith("/") || (e = "/" + e), V + e + t);
48
48
  }
49
49
  function D(e = {}) {
50
- const { user: s, params: t = {}, query: l = {}, body: c, headers: f = {}, cookies: u } = e, w = M(u), o = new Headers(f);
51
- w && !o.has("cookie") && o.set("cookie", w);
52
- const n = V + "/_mock" + H(l), r = {
50
+ const { user: s, params: t = {}, query: l = {}, body: c, headers: f = {}, cookies: u } = e, p = q(u), o = new Headers(f);
51
+ p && !o.has("cookie") && o.set("cookie", p);
52
+ const n = V + "/_mock" + H(l), i = {
53
53
  method: c == null ? "GET" : "POST",
54
54
  headers: o
55
55
  };
56
- c != null && (typeof c == "string" || c instanceof FormData || c instanceof Blob ? r.body = c : (r.body = JSON.stringify(c), o.has("content-type") || o.set("content-type", "application/json")));
57
- const h = new Request(n, r), a = /* @__PURE__ */ new Map();
56
+ c != null && (typeof c == "string" || c instanceof FormData || c instanceof Blob ? i.body = c : (i.body = JSON.stringify(c), o.has("content-type") || o.set("content-type", "application/json")));
57
+ const d = new Request(n, i), a = /* @__PURE__ */ new Map();
58
58
  return s !== void 0 && a.set("user", s), {
59
59
  req: {
60
- raw: h,
61
- url: h.url,
62
- method: h.method,
63
- param(i) {
64
- return i === void 0 ? t : t[i];
60
+ raw: d,
61
+ url: d.url,
62
+ method: d.method,
63
+ param(r) {
64
+ return r === void 0 ? t : t[r];
65
65
  },
66
- query(i) {
67
- if (i === void 0) {
68
- const d = {};
66
+ query(r) {
67
+ if (r === void 0) {
68
+ const h = {};
69
69
  for (const [v, j] of Object.entries(l))
70
- d[v] = String(j);
71
- return d;
70
+ h[v] = String(j);
71
+ return h;
72
72
  }
73
- return l[i];
73
+ return l[r];
74
74
  },
75
- queries(i) {
76
- const d = l[i];
77
- if (d !== void 0)
78
- return Array.isArray(d) ? d : [d];
75
+ queries(r) {
76
+ const h = l[r];
77
+ if (h !== void 0)
78
+ return Array.isArray(h) ? h : [h];
79
79
  },
80
- header(i) {
81
- if (i === void 0) {
82
- const d = {};
80
+ header(r) {
81
+ if (r === void 0) {
82
+ const h = {};
83
83
  return o.forEach((v, j) => {
84
- d[j] = v;
85
- }), d;
84
+ h[j] = v;
85
+ }), h;
86
86
  }
87
- return o.get(i) ?? void 0;
87
+ return o.get(r) ?? void 0;
88
88
  },
89
89
  async json() {
90
90
  return c == null ? null : typeof c == "object" ? c : JSON.parse(String(c));
@@ -100,47 +100,47 @@ function D(e = {}) {
100
100
  res: void 0,
101
101
  env: {},
102
102
  finalized: !1,
103
- get(i) {
104
- return a.get(i);
103
+ get(r) {
104
+ return a.get(r);
105
105
  },
106
- set(i, d) {
107
- a.set(i, d);
106
+ set(r, h) {
107
+ a.set(r, h);
108
108
  },
109
109
  var: new Proxy({}, {
110
- get(i, d) {
111
- return a.get(d);
110
+ get(r, h) {
111
+ return a.get(h);
112
112
  }
113
113
  }),
114
- json(i, d = 200) {
115
- return new Response(JSON.stringify(i), {
116
- status: d,
114
+ json(r, h = 200) {
115
+ return new Response(JSON.stringify(r), {
116
+ status: h,
117
117
  headers: { "content-type": "application/json" }
118
118
  });
119
119
  },
120
- text(i, d = 200) {
121
- return new Response(i, { status: d });
120
+ text(r, h = 200) {
121
+ return new Response(r, { status: h });
122
122
  },
123
- html(i, d = 200) {
124
- return new Response(i, {
125
- status: d,
123
+ html(r, h = 200) {
124
+ return new Response(r, {
125
+ status: h,
126
126
  headers: { "content-type": "text/html; charset=UTF-8" }
127
127
  });
128
128
  },
129
- body(i, d = 200) {
130
- return new Response(i, { status: d });
129
+ body(r, h = 200) {
130
+ return new Response(r, { status: h });
131
131
  },
132
- redirect(i, d = 302) {
133
- return new Response(null, { status: d, headers: { location: i } });
132
+ redirect(r, h = 302) {
133
+ return new Response(null, { status: h, headers: { location: r } });
134
134
  },
135
- header(i, d) {
135
+ header(r, h) {
136
136
  },
137
- status(i) {
137
+ status(r) {
138
138
  }
139
139
  };
140
140
  }
141
141
  function ee(e, s) {
142
142
  if (typeof s == "string") {
143
- const t = q(e).get(s);
143
+ const t = M(e).get(s);
144
144
  if (!t)
145
145
  throw new Error(
146
146
  `[velojs/testing] no socket handler registered at "${s}". Make sure the route exports a socket_* handler and routes are wired.`
@@ -156,7 +156,7 @@ function ee(e, s) {
156
156
  return { handler: s, path: t };
157
157
  }
158
158
  if (s && typeof s == "object" && typeof s.__path == "string") {
159
- const t = s.__path, l = q(e).get(t);
159
+ const t = s.__path, l = M(e).get(t);
160
160
  if (!l)
161
161
  throw new Error(
162
162
  `[velojs/testing] stub with __path="${t}" has no matching server handler.`
@@ -174,41 +174,41 @@ async function te(e, s, t = {}) {
174
174
  }
175
175
  };
176
176
  t.user !== void 0 && (f.user = t.user), t.headers && (f.headers = t.headers), t.cookies && (f.cookies = t.cookies);
177
- const u = D(f), w = [];
177
+ const u = D(f), p = [];
178
178
  let o = null, n = !1;
179
- const r = {
179
+ const i = {
180
180
  async *[Symbol.asyncIterator]() {
181
181
  for (; ; ) {
182
- for (; w.length > 0; )
183
- yield w.shift();
182
+ for (; p.length > 0; )
183
+ yield p.shift();
184
184
  if (n) return;
185
- await new Promise((m) => o = m), o = null;
185
+ await new Promise((y) => o = y), o = null;
186
186
  }
187
187
  }
188
- }, h = (m) => {
189
- n || (w.push(m), o?.());
188
+ }, d = (y) => {
189
+ n || (p.push(y), o?.());
190
190
  }, a = () => {
191
191
  n || (n = !0, o?.());
192
- }, p = [];
193
- let i = [];
194
- const d = (m) => {
195
- p.push(m);
196
- const P = i;
197
- i = [];
192
+ }, w = [];
193
+ let r = [];
194
+ const h = (y) => {
195
+ w.push(y);
196
+ const P = r;
197
+ r = [];
198
198
  for (const R of P)
199
199
  try {
200
200
  R();
201
201
  } catch {
202
202
  }
203
203
  }, v = new AbortController(), j = L(e, v);
204
- let y = !1, g = !1;
205
- const k = (m) => {
206
- g || (typeof m == "string" || m instanceof Uint8Array ? d(m) : d(JSON.stringify(m)));
207
- }, E = (m, P) => {
208
- _();
209
- }, C = () => {
210
- y = !0;
204
+ let m = !1, g = !1;
205
+ const k = (y) => {
206
+ g || (typeof y == "string" || y instanceof Uint8Array ? h(y) : h(JSON.stringify(y)));
207
+ }, E = (y, P) => {
208
+ C();
211
209
  }, _ = () => {
210
+ m = !0;
211
+ }, C = () => {
212
212
  if (g) return;
213
213
  if (g = !0, !v.signal.aborted)
214
214
  try {
@@ -216,18 +216,18 @@ async function te(e, s, t = {}) {
216
216
  } catch {
217
217
  }
218
218
  j(), a();
219
- const m = i;
220
- i = [];
221
- for (const P of m)
219
+ const y = r;
220
+ r = [];
221
+ for (const P of y)
222
222
  try {
223
223
  P();
224
224
  } catch {
225
225
  }
226
226
  }, b = {
227
- incoming: r,
227
+ incoming: i,
228
228
  send: k,
229
229
  close: E,
230
- keepOpen: C,
230
+ keepOpen: _,
231
231
  abortSignal: v.signal,
232
232
  c: u,
233
233
  params: t.params ?? {},
@@ -238,42 +238,42 @@ async function te(e, s, t = {}) {
238
238
  }, T = (async () => {
239
239
  try {
240
240
  await l(b);
241
- } catch (m) {
242
- console.error("[velojs/testing] socket handler threw:", m);
241
+ } catch (y) {
242
+ console.error("[velojs/testing] socket handler threw:", y);
243
243
  }
244
- y || _();
245
- })(), x = (m) => new Promise((P, R) => {
244
+ m || C();
245
+ })(), x = (y) => new Promise((P, R) => {
246
246
  const $ = setTimeout(() => {
247
- i = i.filter((U) => U !== I), R(new Error(`[velojs/testing] socket.next() timed out after ${m}ms`));
248
- }, m), I = () => {
247
+ r = r.filter((U) => U !== I), R(new Error(`[velojs/testing] socket.next() timed out after ${y}ms`));
248
+ }, y), I = () => {
249
249
  clearTimeout($), P();
250
250
  };
251
- i.push(I);
251
+ r.push(I);
252
252
  });
253
253
  let S = 0;
254
254
  return {
255
- send(m) {
256
- g || (typeof m == "string" || m instanceof Uint8Array ? h(m) : h(JSON.stringify(m)));
255
+ send(y) {
256
+ g || (typeof y == "string" || y instanceof Uint8Array ? d(y) : d(JSON.stringify(y)));
257
257
  },
258
258
  get messages() {
259
- return p;
259
+ return w;
260
260
  },
261
261
  get closed() {
262
262
  return g;
263
263
  },
264
- async next(m) {
265
- for (; S >= p.length; ) {
264
+ async next(y) {
265
+ for (; S >= w.length; ) {
266
266
  if (g)
267
267
  throw new Error("[velojs/testing] socket closed before next()");
268
- await x(m.timeoutMs);
268
+ await x(y.timeoutMs);
269
269
  }
270
- return p[S++];
270
+ return w[S++];
271
271
  },
272
- async nextN(m, P) {
272
+ async nextN(y, P) {
273
273
  const R = Date.now() + P.timeoutMs, $ = [];
274
- for (; $.length < m; ) {
275
- if (S < p.length) {
276
- $.push(p[S++]);
274
+ for (; $.length < y; ) {
275
+ if (S < w.length) {
276
+ $.push(w[S++]);
277
277
  continue;
278
278
  }
279
279
  if (g)
@@ -287,8 +287,8 @@ async function te(e, s, t = {}) {
287
287
  }
288
288
  return $;
289
289
  },
290
- async close(m, P) {
291
- _(), await Promise.race([
290
+ async close(y, P) {
291
+ C(), await Promise.race([
292
292
  T,
293
293
  new Promise((R) => setTimeout(R, 50))
294
294
  ]);
@@ -300,27 +300,27 @@ function ne(e) {
300
300
  const s = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
301
301
  function l(c) {
302
302
  for (const f of c) {
303
- const u = f.module?.metadata?.moduleId, w = f.module?.metadata?.fullPath;
303
+ const u = f.module?.metadata?.moduleId, p = f.module?.metadata?.fullPath;
304
304
  if (f.module && u) {
305
305
  for (const n of Object.keys(f.module)) {
306
306
  if (!n.startsWith("action_")) continue;
307
- const r = f.module[n];
308
- if (typeof r != "function") continue;
309
- const h = n.replace("action_", "");
310
- s.set(r, {
311
- name: h,
312
- fn: r,
307
+ const i = f.module[n];
308
+ if (typeof i != "function") continue;
309
+ const d = n.replace("action_", "");
310
+ s.set(i, {
311
+ name: d,
312
+ fn: i,
313
313
  moduleId: u,
314
- url: `/_action/${u}/${h}`
314
+ url: `/_action/${u}/${d}`
315
315
  });
316
316
  }
317
317
  const o = f.module.loader;
318
- if (typeof o == "function" && w) {
318
+ if (typeof o == "function" && p) {
319
319
  const n = t.get(o);
320
- n ? n.paths.push(w) : t.set(o, {
320
+ n ? n.paths.push(p) : t.set(o, {
321
321
  fn: o,
322
322
  moduleId: u,
323
- paths: [w]
323
+ paths: [p]
324
324
  });
325
325
  }
326
326
  }
@@ -382,40 +382,40 @@ class re {
382
382
  const f = c.indexOf(":");
383
383
  if (f === -1) continue;
384
384
  const u = c.slice(0, f);
385
- let w = c.slice(f + 1);
386
- w.startsWith(" ") && (w = w.slice(1)), u === "event" ? this.current.event = w : u === "data" ? this.current.data.push(w) : u === "id" && (this.current.id = w);
385
+ let p = c.slice(f + 1);
386
+ p.startsWith(" ") && (p = p.slice(1)), u === "event" ? this.current.event = p : u === "data" ? this.current.data.push(p) : u === "id" && (this.current.id = p);
387
387
  }
388
388
  return t;
389
389
  }
390
390
  }
391
391
  async function J(e) {
392
392
  const { response: s, snapshotEvents: t = !1, channelEvents: l = !1 } = e, c = s.status, f = [], u = [];
393
- let w = null, o = !1, n = null, r = 0, h = 0;
394
- const a = [], p = [];
395
- let i = null, d = Promise.resolve(void 0);
396
- const v = (y) => {
393
+ let p = null, o = !1, n = null, i = 0, d = 0;
394
+ const a = [], w = [];
395
+ let r = null, h = Promise.resolve(void 0);
396
+ const v = (m) => {
397
397
  for (; a.length > 0; ) {
398
398
  const g = a.shift();
399
- y ? g.reject(y) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
399
+ m ? g.reject(m) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
400
400
  }
401
- for (; p.length > 0; ) {
402
- const g = p.shift();
403
- y ? g.reject(y) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
401
+ for (; w.length > 0; ) {
402
+ const g = w.shift();
403
+ m ? g.reject(m) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
404
404
  }
405
405
  };
406
406
  if (c >= 200 && c < 300 && s.body) {
407
- i = s.body.getReader();
408
- const y = new TextDecoder(), g = new re();
409
- d = (async () => {
407
+ r = s.body.getReader();
408
+ const m = new TextDecoder(), g = new re();
409
+ h = (async () => {
410
410
  try {
411
411
  for (; ; ) {
412
- const { value: k, done: E } = await i.read();
412
+ const { value: k, done: E } = await r.read();
413
413
  if (E) {
414
414
  o || (o = !0), v();
415
415
  return;
416
416
  }
417
- const C = y.decode(k, { stream: !0 }), _ = g.push(C);
418
- for (const b of _) {
417
+ const _ = m.decode(k, { stream: !0 }), C = g.push(_);
418
+ for (const b of C) {
419
419
  const T = b.event === "slice";
420
420
  if (b.event === "snapshot" || l && T) {
421
421
  let x;
@@ -425,7 +425,7 @@ async function J(e) {
425
425
  n = S;
426
426
  }
427
427
  if (x !== void 0) {
428
- if (T || (w = x), t || l && T) {
428
+ if (T || (p = x), t || l && T) {
429
429
  const S = x;
430
430
  f.push(S);
431
431
  const A = a.shift();
@@ -437,14 +437,14 @@ async function J(e) {
437
437
  data: x
438
438
  };
439
439
  u.push(S);
440
- const A = p.shift();
440
+ const A = w.shift();
441
441
  A && A.resolve(S);
442
442
  }
443
443
  }
444
444
  continue;
445
445
  }
446
446
  if (b.event === "close") {
447
- o = !0, v(), i.cancel().catch(() => {
447
+ o = !0, v(), r.cancel().catch(() => {
448
448
  });
449
449
  return;
450
450
  }
@@ -477,74 +477,74 @@ async function J(e) {
477
477
  return f;
478
478
  },
479
479
  get snapshot() {
480
- return w;
480
+ return p;
481
481
  },
482
482
  get closed() {
483
483
  return o;
484
484
  },
485
- async next({ timeoutMs: y }) {
485
+ async next({ timeoutMs: m }) {
486
486
  if (n) throw n;
487
- if (f.length > r) {
488
- const g = f[r];
489
- return r++, g;
487
+ if (f.length > i) {
488
+ const g = f[i];
489
+ return i++, g;
490
490
  }
491
491
  if (o)
492
492
  throw new Error("[velojs/testing] subscription is closed");
493
493
  return new Promise((g, k) => {
494
494
  const E = setTimeout(() => {
495
- const b = a.findIndex((T) => T.resolve === C);
495
+ const b = a.findIndex((T) => T.resolve === _);
496
496
  b !== -1 && a.splice(b, 1), k(new Error(
497
- `[velojs/testing] timed out after ${y}ms waiting for next event`
497
+ `[velojs/testing] timed out after ${m}ms waiting for next event`
498
498
  ));
499
- }, y), C = (b) => {
500
- clearTimeout(E), r++, g(b);
501
- }, _ = (b) => {
499
+ }, m), _ = (b) => {
500
+ clearTimeout(E), i++, g(b);
501
+ }, C = (b) => {
502
502
  clearTimeout(E), k(b);
503
503
  };
504
- a.push({ resolve: C, reject: _ });
504
+ a.push({ resolve: _, reject: C });
505
505
  });
506
506
  },
507
- async nextEvent({ timeoutMs: y }) {
507
+ async nextEvent({ timeoutMs: m }) {
508
508
  if (n) throw n;
509
- if (u.length > h) {
510
- const g = u[h];
511
- return h++, g;
509
+ if (u.length > d) {
510
+ const g = u[d];
511
+ return d++, g;
512
512
  }
513
513
  if (o)
514
514
  throw new Error("[velojs/testing] subscription is closed");
515
515
  return new Promise((g, k) => {
516
516
  const E = setTimeout(() => {
517
- const b = p.findIndex((T) => T.resolve === C);
518
- b !== -1 && p.splice(b, 1), k(new Error(
519
- `[velojs/testing] timed out after ${y}ms waiting for next event`
517
+ const b = w.findIndex((T) => T.resolve === _);
518
+ b !== -1 && w.splice(b, 1), k(new Error(
519
+ `[velojs/testing] timed out after ${m}ms waiting for next event`
520
520
  ));
521
- }, y), C = (b) => {
522
- clearTimeout(E), h++, g(b);
523
- }, _ = (b) => {
521
+ }, m), _ = (b) => {
522
+ clearTimeout(E), d++, g(b);
523
+ }, C = (b) => {
524
524
  clearTimeout(E), k(b);
525
525
  };
526
- p.push({ resolve: C, reject: _ });
526
+ w.push({ resolve: _, reject: C });
527
527
  });
528
528
  },
529
- async nextN(y, { timeoutMs: g }) {
529
+ async nextN(m, { timeoutMs: g }) {
530
530
  const k = Date.now(), E = [];
531
- for (let C = 0; C < y; C++) {
532
- const _ = g - (Date.now() - k);
533
- if (_ <= 0)
531
+ for (let _ = 0; _ < m; _++) {
532
+ const C = g - (Date.now() - k);
533
+ if (C <= 0)
534
534
  throw new Error(
535
- `[velojs/testing] timed out after ${g}ms waiting for ${y} events (got ${E.length})`
535
+ `[velojs/testing] timed out after ${g}ms waiting for ${m} events (got ${E.length})`
536
536
  );
537
- E.push(await j.next({ timeoutMs: _ }));
537
+ E.push(await j.next({ timeoutMs: C }));
538
538
  }
539
539
  return E;
540
540
  },
541
541
  async close() {
542
- if (i)
542
+ if (r)
543
543
  try {
544
- await i.cancel();
544
+ await r.cancel();
545
545
  } catch {
546
546
  }
547
- o = !0, v(), await d.catch(() => {
547
+ o = !0, v(), await h.catch(() => {
548
548
  });
549
549
  }
550
550
  };
@@ -570,63 +570,63 @@ async function ie(e, s, t) {
570
570
  fetch: e.fetch,
571
571
  port: s,
572
572
  ...t ? { hostname: t } : {}
573
- }), w = /* @__PURE__ */ new Set();
573
+ }), p = /* @__PURE__ */ new Set();
574
574
  u.on("connection", (a) => {
575
- w.add(a), a.on("close", () => w.delete(a));
575
+ p.add(a), a.on("close", () => p.delete(a));
576
576
  }), await ce(u, s, t), await B(e, u), c(u);
577
- const o = u.address(), n = o && typeof o == "object" ? o.port : s, r = t && t !== "0.0.0.0" && t !== "::" ? t : "localhost";
578
- let h = !1;
577
+ const o = u.address(), n = o && typeof o == "object" ? o.port : s, i = t && t !== "0.0.0.0" && t !== "::" ? t : "localhost";
578
+ let d = !1;
579
579
  return {
580
580
  port: n,
581
- url: `http://${r}:${n}`,
581
+ url: `http://${i}:${n}`,
582
582
  async close() {
583
- if (h) return;
584
- h = !0;
585
- const a = new Promise((p) => {
586
- u.close(() => p());
583
+ if (d) return;
584
+ d = !0;
585
+ const a = new Promise((w) => {
586
+ u.close(() => w());
587
587
  });
588
- for (const p of w) p.destroy();
589
- w.clear(), u.closeAllConnections(), await a, f(u);
588
+ for (const w of p) w.destroy();
589
+ p.clear(), u.closeAllConnections(), await a, f(u);
590
590
  }
591
591
  };
592
592
  }
593
593
  function ce(e, s, t) {
594
594
  return e.listening ? Promise.resolve() : new Promise((l, c) => {
595
595
  const f = `${t ?? "0.0.0.0"}:${s}`, u = () => {
596
- e.off("listening", w), e.off("error", o);
597
- }, w = () => {
596
+ e.off("listening", p), e.off("error", o);
597
+ }, p = () => {
598
598
  u(), l();
599
599
  }, o = (n) => {
600
600
  u();
601
- const r = n.code ? `${n.code}: ${n.message}` : n.message;
601
+ const i = n.code ? `${n.code}: ${n.message}` : n.message;
602
602
  c(new Error(
603
- `[velojs/testing] could not bind the test server on ${f} — ${r}`
603
+ `[velojs/testing] could not bind the test server on ${f} — ${i}`
604
604
  ));
605
605
  };
606
- e.once("listening", w), e.once("error", o);
606
+ e.once("listening", p), e.once("error", o);
607
607
  });
608
608
  }
609
609
  function ae(e, s, t, l, c, f) {
610
- async function u(n, r, h = {}) {
611
- const a = O(r, h.query), p = new Headers(h.headers ?? {}), i = { ...h.cookies ?? {} }, d = M(i);
612
- d && p.set("cookie", d);
610
+ async function u(n, i, d = {}) {
611
+ const a = O(i, d.query), w = new Headers(d.headers ?? {}), r = { ...d.cookies ?? {} }, h = q(r);
612
+ h && w.set("cookie", h);
613
613
  let v = null;
614
- if (h.body !== void 0) {
615
- const k = Z(h.body);
616
- v = k.body, k.contentType && !p.has("content-type") && p.set("content-type", k.contentType);
614
+ if (d.body !== void 0) {
615
+ const k = Z(d.body);
616
+ v = k.body, k.contentType && !w.has("content-type") && w.set("content-type", k.contentType);
617
617
  }
618
- const j = { method: n, headers: p };
618
+ const j = { method: n, headers: w };
619
619
  v !== null && (j.body = v);
620
- const y = new Request(a, j), g = await e.fetch(y);
620
+ const m = new Request(a, j), g = await e.fetch(m);
621
621
  return await le(g);
622
622
  }
623
- async function w(n, r, h = {}) {
624
- const a = O(r, {
625
- ...h.query ?? {},
626
- ...h.channel ? { channel: h.channel } : {}
627
- }), p = new Headers(h.headers ?? {}), i = { ...h.cookies ?? {} }, d = M(i);
628
- d && p.set("cookie", d);
629
- const v = new Request(a, { method: n, headers: p });
623
+ async function p(n, i, d = {}) {
624
+ const a = O(i, {
625
+ ...d.query ?? {},
626
+ ...d.channel ? { channel: d.channel } : {}
627
+ }), w = new Headers(d.headers ?? {}), r = { ...d.cookies ?? {} }, h = q(r);
628
+ h && w.set("cookie", h);
629
+ const v = new Request(a, { method: n, headers: w });
630
630
  return await e.fetch(v);
631
631
  }
632
632
  const o = {
@@ -635,47 +635,50 @@ function ae(e, s, t, l, c, f) {
635
635
  port: f?.port,
636
636
  url: f?.url,
637
637
  // HTTP
638
- get: (n, r) => u("GET", n, r ?? {}),
639
- post: (n, r) => u("POST", n, r ?? {}),
640
- put: (n, r) => u("PUT", n, r ?? {}),
641
- patch: (n, r) => u("PATCH", n, r ?? {}),
642
- delete: (n, r) => u("DELETE", n, r ?? {}),
643
- async action(n, r = {}) {
644
- const h = se(t, n);
645
- return await u("POST", h, {
646
- ...r,
647
- body: r.body ?? {}
638
+ get: (n, i) => u("GET", n, i ?? {}),
639
+ post: (n, i) => u("POST", n, i ?? {}),
640
+ put: (n, i) => u("PUT", n, i ?? {}),
641
+ patch: (n, i) => u("PATCH", n, i ?? {}),
642
+ delete: (n, i) => u("DELETE", n, i ?? {}),
643
+ async action(n, i = {}) {
644
+ const d = se(t, n);
645
+ return await u("POST", d, {
646
+ ...i,
647
+ body: i.body ?? {}
648
648
  });
649
649
  },
650
- async loader(n, r = {}) {
651
- const h = oe(t, n, r.params), a = await u("GET", h, {
652
- ...r,
653
- query: { ...r.query ?? {}, _data: "1" }
650
+ async loader(n, i = {}) {
651
+ const d = oe(t, n, i.params), a = await u("GET", d, {
652
+ ...i,
653
+ query: { ...i.query ?? {}, _data: "1" }
654
654
  });
655
655
  if (a.status >= 300 && a.status < 400 || a.status >= 400) return a;
656
- const p = typeof n == "function" ? t.loaders.get(n)?.moduleId : void 0, i = await a.json();
657
- return p && i && typeof i == "object" && p in i ? i[p] : i;
656
+ const w = typeof n == "function" ? t.loaders.get(n)?.moduleId : void 0, r = await a.json();
657
+ return w && r && typeof r == "object" && w in r ? r[w] : r;
658
658
  },
659
- async subscribe(n, r = {}) {
660
- const h = typeof n == "string" ? n : n.__path ?? fe(), a = await w("GET", h, r);
659
+ async subscribe(n, i = {}) {
660
+ const d = typeof n == "string" ? n : n.__path ?? fe(), a = await p("GET", d, i);
661
661
  return await J({ response: a });
662
662
  },
663
- async channel(n, r, h = {}) {
663
+ async channel(n, i, d = {}) {
664
664
  const a = typeof n == "string" ? n : n?.metadata?.moduleId;
665
665
  a || ue(n);
666
- const p = await w(
666
+ const w = d.params ? { _route: JSON.stringify(d.params) } : {}, r = await p(
667
667
  "GET",
668
- `/_channel/${a}/${r}`,
669
- h
668
+ `/_channel/${a}/${i}`,
669
+ {
670
+ ...d,
671
+ query: { ...d.query ?? {}, ...w }
672
+ }
670
673
  );
671
674
  return await J({
672
- response: p,
675
+ response: r,
673
676
  snapshotEvents: !0,
674
677
  channelEvents: !0
675
678
  });
676
679
  },
677
- async socket(n, r = {}) {
678
- return await te(e, n, r);
680
+ async socket(n, i = {}) {
681
+ return await te(e, n, i);
679
682
  },
680
683
  async sessionCookies({ user: n }) {
681
684
  if (!l.getSessionCookie)
@@ -689,18 +692,18 @@ function ae(e, s, t, l, c, f) {
689
692
  throw new Error(
690
693
  "[velojs/testing] app.as() requires `getSessionCookie` in createTestApp options."
691
694
  );
692
- let r = null;
693
- const h = () => (r || (r = Promise.resolve(l.getSessionCookie({ user: n }))), r), a = (d) => (async (...v) => {
694
- const j = await h(), [y, g] = v, k = {
695
+ let i = null;
696
+ const d = () => (i || (i = Promise.resolve(l.getSessionCookie({ user: n }))), i), a = (h) => (async (...v) => {
697
+ const j = await d(), [m, g] = v, k = {
695
698
  ...g ?? {},
696
699
  cookies: { ...j, ...g?.cookies ?? {} }
697
700
  };
698
- return await d.call(o, y, k);
699
- }), p = (d) => (async (v, j, y = {}) => {
700
- const g = await h();
701
- return await d.call(o, v, j, {
702
- ...y,
703
- cookies: { ...g, ...y?.cookies ?? {} }
701
+ return await h.call(o, m, k);
702
+ }), w = (h) => (async (v, j, m = {}) => {
703
+ const g = await d();
704
+ return await h.call(o, v, j, {
705
+ ...m,
706
+ cookies: { ...g, ...m?.cookies ?? {} }
704
707
  });
705
708
  });
706
709
  return {
@@ -715,7 +718,7 @@ function ae(e, s, t, l, c, f) {
715
718
  action: a(o.action),
716
719
  loader: a(o.loader),
717
720
  subscribe: a(o.subscribe),
718
- channel: p(o.channel),
721
+ channel: w(o.channel),
719
722
  socket: a(o.socket),
720
723
  sessionCookies: o.sessionCookies,
721
724
  as: o.as,
@@ -732,8 +735,8 @@ function ae(e, s, t, l, c, f) {
732
735
  for (const n of W())
733
736
  try {
734
737
  n.__reset();
735
- } catch (r) {
736
- console.error("[velojs/testing] stream.__reset failed:", r);
738
+ } catch (i) {
739
+ console.error("[velojs/testing] stream.__reset failed:", i);
737
740
  }
738
741
  z();
739
742
  },
@@ -742,8 +745,8 @@ function ae(e, s, t, l, c, f) {
742
745
  for (const n of s.disposers)
743
746
  try {
744
747
  n();
745
- } catch (r) {
746
- console.error("[velojs/testing] disposer failed:", r);
748
+ } catch (i) {
749
+ console.error("[velojs/testing] disposer failed:", i);
747
750
  }
748
751
  s.disposers.clear(), await f?.close();
749
752
  }