@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.
- package/README.md +126 -26
- package/agent/AGENTS.md +86 -17
- package/agent/skills/velojs-live-loader/SKILL.md +108 -25
- package/agent/skills/velojs-production-deploy/SKILL.md +7 -1
- package/dist/channels.d.ts +109 -28
- package/dist/channels.js +285 -192
- package/dist/client.js +8 -7
- package/dist/live-loader.d.ts +40 -7
- package/dist/live-loader.js +91 -81
- package/dist/server.d.ts +1 -1
- package/dist/server.js +94 -92
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +231 -228
- package/dist/testing/types.d.ts +21 -4
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getRegisteredStreams as W } from "../events.js";
|
|
2
|
-
import { trackSocketSession as L, getAppSockets as
|
|
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
|
|
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
|
|
17
|
-
|
|
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,
|
|
51
|
-
|
|
52
|
-
const n = V + "/_mock" + H(l),
|
|
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 ?
|
|
57
|
-
const
|
|
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:
|
|
61
|
-
url:
|
|
62
|
-
method:
|
|
63
|
-
param(
|
|
64
|
-
return
|
|
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(
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
66
|
+
query(r) {
|
|
67
|
+
if (r === void 0) {
|
|
68
|
+
const h = {};
|
|
69
69
|
for (const [v, j] of Object.entries(l))
|
|
70
|
-
|
|
71
|
-
return
|
|
70
|
+
h[v] = String(j);
|
|
71
|
+
return h;
|
|
72
72
|
}
|
|
73
|
-
return l[
|
|
73
|
+
return l[r];
|
|
74
74
|
},
|
|
75
|
-
queries(
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
return Array.isArray(
|
|
75
|
+
queries(r) {
|
|
76
|
+
const h = l[r];
|
|
77
|
+
if (h !== void 0)
|
|
78
|
+
return Array.isArray(h) ? h : [h];
|
|
79
79
|
},
|
|
80
|
-
header(
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
80
|
+
header(r) {
|
|
81
|
+
if (r === void 0) {
|
|
82
|
+
const h = {};
|
|
83
83
|
return o.forEach((v, j) => {
|
|
84
|
-
|
|
85
|
-
}),
|
|
84
|
+
h[j] = v;
|
|
85
|
+
}), h;
|
|
86
86
|
}
|
|
87
|
-
return o.get(
|
|
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(
|
|
104
|
-
return a.get(
|
|
103
|
+
get(r) {
|
|
104
|
+
return a.get(r);
|
|
105
105
|
},
|
|
106
|
-
set(
|
|
107
|
-
a.set(
|
|
106
|
+
set(r, h) {
|
|
107
|
+
a.set(r, h);
|
|
108
108
|
},
|
|
109
109
|
var: new Proxy({}, {
|
|
110
|
-
get(
|
|
111
|
-
return a.get(
|
|
110
|
+
get(r, h) {
|
|
111
|
+
return a.get(h);
|
|
112
112
|
}
|
|
113
113
|
}),
|
|
114
|
-
json(
|
|
115
|
-
return new Response(JSON.stringify(
|
|
116
|
-
status:
|
|
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(
|
|
121
|
-
return new Response(
|
|
120
|
+
text(r, h = 200) {
|
|
121
|
+
return new Response(r, { status: h });
|
|
122
122
|
},
|
|
123
|
-
html(
|
|
124
|
-
return new Response(
|
|
125
|
-
status:
|
|
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(
|
|
130
|
-
return new Response(
|
|
129
|
+
body(r, h = 200) {
|
|
130
|
+
return new Response(r, { status: h });
|
|
131
131
|
},
|
|
132
|
-
redirect(
|
|
133
|
-
return new Response(null, { status:
|
|
132
|
+
redirect(r, h = 302) {
|
|
133
|
+
return new Response(null, { status: h, headers: { location: r } });
|
|
134
134
|
},
|
|
135
|
-
header(
|
|
135
|
+
header(r, h) {
|
|
136
136
|
},
|
|
137
|
-
status(
|
|
137
|
+
status(r) {
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
function ee(e, s) {
|
|
142
142
|
if (typeof s == "string") {
|
|
143
|
-
const t =
|
|
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 =
|
|
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),
|
|
177
|
+
const u = D(f), p = [];
|
|
178
178
|
let o = null, n = !1;
|
|
179
|
-
const
|
|
179
|
+
const i = {
|
|
180
180
|
async *[Symbol.asyncIterator]() {
|
|
181
181
|
for (; ; ) {
|
|
182
|
-
for (;
|
|
183
|
-
yield
|
|
182
|
+
for (; p.length > 0; )
|
|
183
|
+
yield p.shift();
|
|
184
184
|
if (n) return;
|
|
185
|
-
await new Promise((
|
|
185
|
+
await new Promise((y) => o = y), o = null;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
},
|
|
189
|
-
n || (
|
|
188
|
+
}, d = (y) => {
|
|
189
|
+
n || (p.push(y), o?.());
|
|
190
190
|
}, a = () => {
|
|
191
191
|
n || (n = !0, o?.());
|
|
192
|
-
},
|
|
193
|
-
let
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
const P =
|
|
197
|
-
|
|
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
|
|
205
|
-
const k = (
|
|
206
|
-
g || (typeof
|
|
207
|
-
}, E = (
|
|
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
|
|
220
|
-
|
|
221
|
-
for (const P of
|
|
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:
|
|
227
|
+
incoming: i,
|
|
228
228
|
send: k,
|
|
229
229
|
close: E,
|
|
230
|
-
keepOpen:
|
|
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 (
|
|
242
|
-
console.error("[velojs/testing] socket handler threw:",
|
|
241
|
+
} catch (y) {
|
|
242
|
+
console.error("[velojs/testing] socket handler threw:", y);
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
})(), x = (
|
|
244
|
+
m || C();
|
|
245
|
+
})(), x = (y) => new Promise((P, R) => {
|
|
246
246
|
const $ = setTimeout(() => {
|
|
247
|
-
|
|
248
|
-
},
|
|
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
|
-
|
|
251
|
+
r.push(I);
|
|
252
252
|
});
|
|
253
253
|
let S = 0;
|
|
254
254
|
return {
|
|
255
|
-
send(
|
|
256
|
-
g || (typeof
|
|
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
|
|
259
|
+
return w;
|
|
260
260
|
},
|
|
261
261
|
get closed() {
|
|
262
262
|
return g;
|
|
263
263
|
},
|
|
264
|
-
async next(
|
|
265
|
-
for (; S >=
|
|
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(
|
|
268
|
+
await x(y.timeoutMs);
|
|
269
269
|
}
|
|
270
|
-
return
|
|
270
|
+
return w[S++];
|
|
271
271
|
},
|
|
272
|
-
async nextN(
|
|
272
|
+
async nextN(y, P) {
|
|
273
273
|
const R = Date.now() + P.timeoutMs, $ = [];
|
|
274
|
-
for (; $.length <
|
|
275
|
-
if (S <
|
|
276
|
-
$.push(
|
|
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(
|
|
291
|
-
|
|
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,
|
|
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
|
|
308
|
-
if (typeof
|
|
309
|
-
const
|
|
310
|
-
s.set(
|
|
311
|
-
name:
|
|
312
|
-
fn:
|
|
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}/${
|
|
314
|
+
url: `/_action/${u}/${d}`
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
const o = f.module.loader;
|
|
318
|
-
if (typeof o == "function" &&
|
|
318
|
+
if (typeof o == "function" && p) {
|
|
319
319
|
const n = t.get(o);
|
|
320
|
-
n ? n.paths.push(
|
|
320
|
+
n ? n.paths.push(p) : t.set(o, {
|
|
321
321
|
fn: o,
|
|
322
322
|
moduleId: u,
|
|
323
|
-
paths: [
|
|
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
|
|
386
|
-
|
|
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
|
|
394
|
-
const a = [],
|
|
395
|
-
let
|
|
396
|
-
const v = (
|
|
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
|
-
|
|
399
|
+
m ? g.reject(m) : g.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
400
400
|
}
|
|
401
|
-
for (;
|
|
402
|
-
const g =
|
|
403
|
-
|
|
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
|
-
|
|
408
|
-
const
|
|
409
|
-
|
|
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
|
|
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
|
|
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 || (
|
|
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 =
|
|
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(),
|
|
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
|
|
480
|
+
return p;
|
|
481
481
|
},
|
|
482
482
|
get closed() {
|
|
483
483
|
return o;
|
|
484
484
|
},
|
|
485
|
-
async next({ timeoutMs:
|
|
485
|
+
async next({ timeoutMs: m }) {
|
|
486
486
|
if (n) throw n;
|
|
487
|
-
if (f.length >
|
|
488
|
-
const g = f[
|
|
489
|
-
return
|
|
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 ===
|
|
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 ${
|
|
497
|
+
`[velojs/testing] timed out after ${m}ms waiting for next event`
|
|
498
498
|
));
|
|
499
|
-
},
|
|
500
|
-
clearTimeout(E),
|
|
501
|
-
},
|
|
499
|
+
}, m), _ = (b) => {
|
|
500
|
+
clearTimeout(E), i++, g(b);
|
|
501
|
+
}, C = (b) => {
|
|
502
502
|
clearTimeout(E), k(b);
|
|
503
503
|
};
|
|
504
|
-
a.push({ resolve:
|
|
504
|
+
a.push({ resolve: _, reject: C });
|
|
505
505
|
});
|
|
506
506
|
},
|
|
507
|
-
async nextEvent({ timeoutMs:
|
|
507
|
+
async nextEvent({ timeoutMs: m }) {
|
|
508
508
|
if (n) throw n;
|
|
509
|
-
if (u.length >
|
|
510
|
-
const g = u[
|
|
511
|
-
return
|
|
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 =
|
|
518
|
-
b !== -1 &&
|
|
519
|
-
`[velojs/testing] timed out after ${
|
|
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
|
-
},
|
|
522
|
-
clearTimeout(E),
|
|
523
|
-
},
|
|
521
|
+
}, m), _ = (b) => {
|
|
522
|
+
clearTimeout(E), d++, g(b);
|
|
523
|
+
}, C = (b) => {
|
|
524
524
|
clearTimeout(E), k(b);
|
|
525
525
|
};
|
|
526
|
-
|
|
526
|
+
w.push({ resolve: _, reject: C });
|
|
527
527
|
});
|
|
528
528
|
},
|
|
529
|
-
async nextN(
|
|
529
|
+
async nextN(m, { timeoutMs: g }) {
|
|
530
530
|
const k = Date.now(), E = [];
|
|
531
|
-
for (let
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
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 ${
|
|
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 (
|
|
542
|
+
if (r)
|
|
543
543
|
try {
|
|
544
|
-
await
|
|
544
|
+
await r.cancel();
|
|
545
545
|
} catch {
|
|
546
546
|
}
|
|
547
|
-
o = !0, v(), await
|
|
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
|
-
}),
|
|
573
|
+
}), p = /* @__PURE__ */ new Set();
|
|
574
574
|
u.on("connection", (a) => {
|
|
575
|
-
|
|
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,
|
|
578
|
-
let
|
|
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://${
|
|
581
|
+
url: `http://${i}:${n}`,
|
|
582
582
|
async close() {
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
const a = new Promise((
|
|
586
|
-
u.close(() =>
|
|
583
|
+
if (d) return;
|
|
584
|
+
d = !0;
|
|
585
|
+
const a = new Promise((w) => {
|
|
586
|
+
u.close(() => w());
|
|
587
587
|
});
|
|
588
|
-
for (const
|
|
589
|
-
|
|
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",
|
|
597
|
-
},
|
|
596
|
+
e.off("listening", p), e.off("error", o);
|
|
597
|
+
}, p = () => {
|
|
598
598
|
u(), l();
|
|
599
599
|
}, o = (n) => {
|
|
600
600
|
u();
|
|
601
|
-
const
|
|
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} — ${
|
|
603
|
+
`[velojs/testing] could not bind the test server on ${f} — ${i}`
|
|
604
604
|
));
|
|
605
605
|
};
|
|
606
|
-
e.once("listening",
|
|
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,
|
|
611
|
-
const a = O(
|
|
612
|
-
|
|
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 (
|
|
615
|
-
const k = Z(
|
|
616
|
-
v = k.body, 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:
|
|
618
|
+
const j = { method: n, headers: w };
|
|
619
619
|
v !== null && (j.body = v);
|
|
620
|
-
const
|
|
620
|
+
const m = new Request(a, j), g = await e.fetch(m);
|
|
621
621
|
return await le(g);
|
|
622
622
|
}
|
|
623
|
-
async function
|
|
624
|
-
const a = O(
|
|
625
|
-
...
|
|
626
|
-
...
|
|
627
|
-
}),
|
|
628
|
-
|
|
629
|
-
const v = new Request(a, { method: n, headers:
|
|
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,
|
|
639
|
-
post: (n,
|
|
640
|
-
put: (n,
|
|
641
|
-
patch: (n,
|
|
642
|
-
delete: (n,
|
|
643
|
-
async action(n,
|
|
644
|
-
const
|
|
645
|
-
return await u("POST",
|
|
646
|
-
...
|
|
647
|
-
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,
|
|
651
|
-
const
|
|
652
|
-
...
|
|
653
|
-
query: { ...
|
|
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
|
|
657
|
-
return
|
|
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,
|
|
660
|
-
const
|
|
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,
|
|
663
|
+
async channel(n, i, d = {}) {
|
|
664
664
|
const a = typeof n == "string" ? n : n?.metadata?.moduleId;
|
|
665
665
|
a || ue(n);
|
|
666
|
-
const
|
|
666
|
+
const w = d.params ? { _route: JSON.stringify(d.params) } : {}, r = await p(
|
|
667
667
|
"GET",
|
|
668
|
-
`/_channel/${a}/${
|
|
669
|
-
|
|
668
|
+
`/_channel/${a}/${i}`,
|
|
669
|
+
{
|
|
670
|
+
...d,
|
|
671
|
+
query: { ...d.query ?? {}, ...w }
|
|
672
|
+
}
|
|
670
673
|
);
|
|
671
674
|
return await J({
|
|
672
|
-
response:
|
|
675
|
+
response: r,
|
|
673
676
|
snapshotEvents: !0,
|
|
674
677
|
channelEvents: !0
|
|
675
678
|
});
|
|
676
679
|
},
|
|
677
|
-
async socket(n,
|
|
678
|
-
return await te(e, n,
|
|
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
|
|
693
|
-
const
|
|
694
|
-
const j = await
|
|
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
|
|
699
|
-
}),
|
|
700
|
-
const g = await
|
|
701
|
-
return await
|
|
702
|
-
...
|
|
703
|
-
cookies: { ...g, ...
|
|
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:
|
|
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 (
|
|
736
|
-
console.error("[velojs/testing] stream.__reset failed:",
|
|
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 (
|
|
746
|
-
console.error("[velojs/testing] disposer failed:",
|
|
748
|
+
} catch (i) {
|
|
749
|
+
console.error("[velojs/testing] disposer failed:", i);
|
|
747
750
|
}
|
|
748
751
|
s.disposers.clear(), await f?.close();
|
|
749
752
|
}
|