@mauroandre/velojs 0.0.59 → 0.0.61
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 +182 -1
- package/agent/AGENTS.md +84 -0
- package/agent/skills/velojs-actions/SKILL.md +32 -0
- package/agent/skills/velojs-hooks/SKILL.md +26 -0
- package/agent/skills/velojs-live-actions/SKILL.md +211 -0
- package/agent/skills/velojs-telemetry/SKILL.md +6 -1
- package/agent/skills/velojs-type-reference/SKILL.md +1 -0
- package/agent/skills/velojs-vite-plugin/SKILL.md +51 -2
- package/dist/channels.d.ts +117 -11
- package/dist/channels.js +459 -284
- package/dist/config.d.ts +8 -0
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.js +34 -32
- package/dist/leak-diagnostic.d.ts +77 -0
- package/dist/leak-diagnostic.js +14 -0
- package/dist/live-action.d.ts +86 -0
- package/dist/live-action.js +52 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +165 -143
- package/dist/telemetry-cli.d.ts +1 -0
- package/dist/telemetry-cli.js +116 -113
- package/dist/telemetry.d.ts +3 -3
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/index.js +500 -453
- package/dist/testing/subscription.d.ts +7 -0
- package/dist/testing/types.d.ts +43 -2
- package/dist/types.d.ts +12 -0
- package/dist/vite.d.ts +47 -1
- package/dist/vite.js +869 -401
- package/package.json +1 -1
package/dist/testing/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { getRegisteredStreams as
|
|
2
|
-
import { trackSocketSession as
|
|
3
|
-
import { registerChannels as
|
|
1
|
+
import { getRegisteredStreams as U } from "../events.js";
|
|
2
|
+
import { trackSocketSession as W, getAppSockets as O, injectWebSocketServer as B, abortAllSocketSessions as G } from "../sockets.js";
|
|
3
|
+
import { registerChannels as M, getChannelMap as F, __resetChannels as z } from "../channels.js";
|
|
4
4
|
import { createIsolatedContext as Q, withAppContext as K } from "../app-context.js";
|
|
5
|
-
function
|
|
5
|
+
function N(e) {
|
|
6
6
|
if (!e) return;
|
|
7
7
|
const s = Object.entries(e);
|
|
8
8
|
if (s.length !== 0)
|
|
9
|
-
return s.map(([
|
|
9
|
+
return s.map(([n, f]) => `${encodeURIComponent(n)}=${encodeURIComponent(f)}`).join("; ");
|
|
10
10
|
}
|
|
11
11
|
function X(e) {
|
|
12
|
-
const s = {},
|
|
13
|
-
for (const
|
|
14
|
-
const c =
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
|
|
12
|
+
const s = {}, n = e.getSetCookie?.() ?? [];
|
|
13
|
+
for (const f of n) {
|
|
14
|
+
const c = f.indexOf(";"), h = c === -1 ? f : f.slice(0, c), l = h.indexOf("=");
|
|
15
|
+
if (l === -1) continue;
|
|
16
|
+
const w = h.slice(0, l).trim(), i = h.slice(l + 1).trim();
|
|
17
|
+
w && (s[w] = decodeURIComponent(i));
|
|
18
18
|
}
|
|
19
19
|
return s;
|
|
20
20
|
}
|
|
21
21
|
function H(e) {
|
|
22
22
|
if (!e) return "";
|
|
23
23
|
const s = new URLSearchParams();
|
|
24
|
-
for (const [
|
|
24
|
+
for (const [f, c] of Object.entries(e))
|
|
25
25
|
if (Array.isArray(c))
|
|
26
|
-
for (const
|
|
26
|
+
for (const h of c) s.append(f, h);
|
|
27
27
|
else
|
|
28
|
-
s.set(
|
|
29
|
-
const
|
|
30
|
-
return
|
|
28
|
+
s.set(f, c);
|
|
29
|
+
const n = s.toString();
|
|
30
|
+
return n ? `?${n}` : "";
|
|
31
31
|
}
|
|
32
32
|
function Y(e) {
|
|
33
33
|
const s = {};
|
|
34
|
-
return e.forEach((
|
|
35
|
-
s[
|
|
34
|
+
return e.forEach((n, f) => {
|
|
35
|
+
s[f] = n;
|
|
36
36
|
}), s;
|
|
37
37
|
}
|
|
38
38
|
function Z(e) {
|
|
@@ -42,49 +42,49 @@ function Z(e) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
const V = "http://velojs.test";
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
return e.startsWith("http://") || e.startsWith("https://") ? e +
|
|
45
|
+
function J(e, s) {
|
|
46
|
+
const n = H(s);
|
|
47
|
+
return e.startsWith("http://") || e.startsWith("https://") ? e + n : (e.startsWith("/") || (e = "/" + e), V + e + n);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
const { user: s, params:
|
|
51
|
-
|
|
52
|
-
const
|
|
49
|
+
function L(e = {}) {
|
|
50
|
+
const { user: s, params: n = {}, query: f = {}, body: c, headers: h = {}, cookies: l } = e, w = N(l), i = new Headers(h);
|
|
51
|
+
w && !i.has("cookie") && i.set("cookie", w);
|
|
52
|
+
const t = V + "/_mock" + H(f), r = {
|
|
53
53
|
method: c == null ? "GET" : "POST",
|
|
54
|
-
headers:
|
|
54
|
+
headers: i
|
|
55
55
|
};
|
|
56
|
-
c != null && (typeof c == "string" || c instanceof FormData || c instanceof Blob ?
|
|
57
|
-
const
|
|
58
|
-
return s !== void 0 &&
|
|
56
|
+
c != null && (typeof c == "string" || c instanceof FormData || c instanceof Blob ? r.body = c : (r.body = JSON.stringify(c), i.has("content-type") || i.set("content-type", "application/json")));
|
|
57
|
+
const a = new Request(t, r), u = /* @__PURE__ */ new Map();
|
|
58
|
+
return s !== void 0 && u.set("user", s), {
|
|
59
59
|
req: {
|
|
60
|
-
raw:
|
|
61
|
-
url:
|
|
62
|
-
method:
|
|
63
|
-
param(
|
|
64
|
-
return
|
|
60
|
+
raw: a,
|
|
61
|
+
url: a.url,
|
|
62
|
+
method: a.method,
|
|
63
|
+
param(o) {
|
|
64
|
+
return o === void 0 ? n : n[o];
|
|
65
65
|
},
|
|
66
|
-
query(
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
for (const [
|
|
70
|
-
|
|
71
|
-
return
|
|
66
|
+
query(o) {
|
|
67
|
+
if (o === void 0) {
|
|
68
|
+
const d = {};
|
|
69
|
+
for (const [k, b] of Object.entries(f))
|
|
70
|
+
d[k] = String(b);
|
|
71
|
+
return d;
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return f[o];
|
|
74
74
|
},
|
|
75
|
-
queries(
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
return Array.isArray(
|
|
75
|
+
queries(o) {
|
|
76
|
+
const d = f[o];
|
|
77
|
+
if (d !== void 0)
|
|
78
|
+
return Array.isArray(d) ? d : [d];
|
|
79
79
|
},
|
|
80
|
-
header(
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
}),
|
|
80
|
+
header(o) {
|
|
81
|
+
if (o === void 0) {
|
|
82
|
+
const d = {};
|
|
83
|
+
return i.forEach((k, b) => {
|
|
84
|
+
d[b] = k;
|
|
85
|
+
}), d;
|
|
86
86
|
}
|
|
87
|
-
return
|
|
87
|
+
return i.get(o) ?? void 0;
|
|
88
88
|
},
|
|
89
89
|
async json() {
|
|
90
90
|
return c == null ? null : typeof c == "object" ? c : JSON.parse(String(c));
|
|
@@ -100,257 +100,257 @@ function D(e = {}) {
|
|
|
100
100
|
res: void 0,
|
|
101
101
|
env: {},
|
|
102
102
|
finalized: !1,
|
|
103
|
-
get(
|
|
104
|
-
return
|
|
103
|
+
get(o) {
|
|
104
|
+
return u.get(o);
|
|
105
105
|
},
|
|
106
|
-
set(
|
|
107
|
-
|
|
106
|
+
set(o, d) {
|
|
107
|
+
u.set(o, d);
|
|
108
108
|
},
|
|
109
109
|
var: new Proxy({}, {
|
|
110
|
-
get(
|
|
111
|
-
return
|
|
110
|
+
get(o, d) {
|
|
111
|
+
return u.get(d);
|
|
112
112
|
}
|
|
113
113
|
}),
|
|
114
|
-
json(
|
|
115
|
-
return new Response(JSON.stringify(
|
|
116
|
-
status:
|
|
114
|
+
json(o, d = 200) {
|
|
115
|
+
return new Response(JSON.stringify(o), {
|
|
116
|
+
status: d,
|
|
117
117
|
headers: { "content-type": "application/json" }
|
|
118
118
|
});
|
|
119
119
|
},
|
|
120
|
-
text(
|
|
121
|
-
return new Response(
|
|
120
|
+
text(o, d = 200) {
|
|
121
|
+
return new Response(o, { status: d });
|
|
122
122
|
},
|
|
123
|
-
html(
|
|
124
|
-
return new Response(
|
|
125
|
-
status:
|
|
123
|
+
html(o, d = 200) {
|
|
124
|
+
return new Response(o, {
|
|
125
|
+
status: d,
|
|
126
126
|
headers: { "content-type": "text/html; charset=UTF-8" }
|
|
127
127
|
});
|
|
128
128
|
},
|
|
129
|
-
body(
|
|
130
|
-
return new Response(
|
|
129
|
+
body(o, d = 200) {
|
|
130
|
+
return new Response(o, { status: d });
|
|
131
131
|
},
|
|
132
|
-
redirect(
|
|
133
|
-
return new Response(null, { status:
|
|
132
|
+
redirect(o, d = 302) {
|
|
133
|
+
return new Response(null, { status: d, headers: { location: o } });
|
|
134
134
|
},
|
|
135
|
-
header(
|
|
135
|
+
header(o, d) {
|
|
136
136
|
},
|
|
137
|
-
status(
|
|
137
|
+
status(o) {
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
function ee(e, s) {
|
|
142
142
|
if (typeof s == "string") {
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
143
|
+
const n = O(e).get(s);
|
|
144
|
+
if (!n)
|
|
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.`
|
|
147
147
|
);
|
|
148
|
-
return { handler:
|
|
148
|
+
return { handler: n.handler, path: s };
|
|
149
149
|
}
|
|
150
150
|
if (typeof s == "function") {
|
|
151
|
-
const
|
|
152
|
-
if (!
|
|
151
|
+
const n = s.__path;
|
|
152
|
+
if (!n)
|
|
153
153
|
throw new Error(
|
|
154
154
|
"[velojs/testing] socket handler has no __path. Make sure your vitest.config.ts loads veloPlugin() and your routes are registered."
|
|
155
155
|
);
|
|
156
|
-
return { handler: s, path:
|
|
156
|
+
return { handler: s, path: n };
|
|
157
157
|
}
|
|
158
158
|
if (s && typeof s == "object" && typeof s.__path == "string") {
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
159
|
+
const n = s.__path, f = O(e).get(n);
|
|
160
|
+
if (!f)
|
|
161
161
|
throw new Error(
|
|
162
|
-
`[velojs/testing] stub with __path="${
|
|
162
|
+
`[velojs/testing] stub with __path="${n}" has no matching server handler.`
|
|
163
163
|
);
|
|
164
|
-
return { handler:
|
|
164
|
+
return { handler: f.handler, path: n };
|
|
165
165
|
}
|
|
166
166
|
throw new Error("[velojs/testing] socket(): unrecognized handler argument");
|
|
167
167
|
}
|
|
168
|
-
async function te(e, s,
|
|
169
|
-
const { handler:
|
|
170
|
-
params:
|
|
168
|
+
async function te(e, s, n = {}) {
|
|
169
|
+
const { handler: f, path: c } = ee(e, s), h = {
|
|
170
|
+
params: n.params ?? {},
|
|
171
171
|
query: {
|
|
172
|
-
...
|
|
173
|
-
...
|
|
172
|
+
...n.query,
|
|
173
|
+
...n.channel ? { channel: n.channel } : {}
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
let
|
|
179
|
-
const
|
|
176
|
+
n.user !== void 0 && (h.user = n.user), n.headers && (h.headers = n.headers), n.cookies && (h.cookies = n.cookies);
|
|
177
|
+
const l = L(h), w = [];
|
|
178
|
+
let i = null, t = !1;
|
|
179
|
+
const r = {
|
|
180
180
|
async *[Symbol.asyncIterator]() {
|
|
181
181
|
for (; ; ) {
|
|
182
|
-
for (;
|
|
183
|
-
yield
|
|
184
|
-
if (
|
|
185
|
-
await new Promise((
|
|
182
|
+
for (; w.length > 0; )
|
|
183
|
+
yield w.shift();
|
|
184
|
+
if (t) return;
|
|
185
|
+
await new Promise((p) => i = p), i = null;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
},
|
|
193
|
-
let
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
const P =
|
|
197
|
-
|
|
198
|
-
for (const
|
|
188
|
+
}, a = (p) => {
|
|
189
|
+
t || (w.push(p), i?.());
|
|
190
|
+
}, u = () => {
|
|
191
|
+
t || (t = !0, i?.());
|
|
192
|
+
}, g = [];
|
|
193
|
+
let o = [];
|
|
194
|
+
const d = (p) => {
|
|
195
|
+
g.push(p);
|
|
196
|
+
const P = o;
|
|
197
|
+
o = [];
|
|
198
|
+
for (const $ of P)
|
|
199
199
|
try {
|
|
200
|
-
|
|
200
|
+
$();
|
|
201
201
|
} catch {
|
|
202
202
|
}
|
|
203
|
-
},
|
|
204
|
-
let
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
}, _ = () => {
|
|
210
|
-
m = !0;
|
|
203
|
+
}, k = new AbortController(), b = W(e, k);
|
|
204
|
+
let x = !1, y = !1;
|
|
205
|
+
const m = (p) => {
|
|
206
|
+
y || (typeof p == "string" || p instanceof Uint8Array ? d(p) : d(JSON.stringify(p)));
|
|
207
|
+
}, S = (p, P) => {
|
|
208
|
+
E();
|
|
211
209
|
}, C = () => {
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
x = !0;
|
|
211
|
+
}, E = () => {
|
|
212
|
+
if (y) return;
|
|
213
|
+
if (y = !0, !k.signal.aborted)
|
|
214
214
|
try {
|
|
215
|
-
|
|
215
|
+
k.abort();
|
|
216
216
|
} catch {
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
for (const P of
|
|
218
|
+
b(), u();
|
|
219
|
+
const p = o;
|
|
220
|
+
o = [];
|
|
221
|
+
for (const P of p)
|
|
222
222
|
try {
|
|
223
223
|
P();
|
|
224
224
|
} catch {
|
|
225
225
|
}
|
|
226
|
-
},
|
|
227
|
-
incoming:
|
|
228
|
-
send:
|
|
229
|
-
close:
|
|
230
|
-
keepOpen:
|
|
231
|
-
abortSignal:
|
|
232
|
-
c:
|
|
233
|
-
params:
|
|
226
|
+
}, A = {
|
|
227
|
+
incoming: r,
|
|
228
|
+
send: m,
|
|
229
|
+
close: S,
|
|
230
|
+
keepOpen: C,
|
|
231
|
+
abortSignal: k.signal,
|
|
232
|
+
c: l,
|
|
233
|
+
params: n.params ?? {},
|
|
234
234
|
query: {
|
|
235
|
-
...
|
|
236
|
-
...
|
|
235
|
+
...n.query ?? {},
|
|
236
|
+
...n.channel ? { channel: n.channel } : {}
|
|
237
237
|
}
|
|
238
|
-
},
|
|
238
|
+
}, v = (async () => {
|
|
239
239
|
try {
|
|
240
|
-
await
|
|
241
|
-
} catch (
|
|
242
|
-
console.error("[velojs/testing] socket handler threw:",
|
|
240
|
+
await f(A);
|
|
241
|
+
} catch (p) {
|
|
242
|
+
console.error("[velojs/testing] socket handler threw:", p);
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
})(),
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
},
|
|
249
|
-
clearTimeout(
|
|
244
|
+
x || E();
|
|
245
|
+
})(), T = (p) => new Promise((P, $) => {
|
|
246
|
+
const I = setTimeout(() => {
|
|
247
|
+
o = o.filter((D) => D !== R), $(new Error(`[velojs/testing] socket.next() timed out after ${p}ms`));
|
|
248
|
+
}, p), R = () => {
|
|
249
|
+
clearTimeout(I), P();
|
|
250
250
|
};
|
|
251
|
-
|
|
251
|
+
o.push(R);
|
|
252
252
|
});
|
|
253
|
-
let
|
|
253
|
+
let j = 0;
|
|
254
254
|
return {
|
|
255
|
-
send(
|
|
256
|
-
|
|
255
|
+
send(p) {
|
|
256
|
+
y || (typeof p == "string" || p instanceof Uint8Array ? a(p) : a(JSON.stringify(p)));
|
|
257
257
|
},
|
|
258
258
|
get messages() {
|
|
259
|
-
return
|
|
259
|
+
return g;
|
|
260
260
|
},
|
|
261
261
|
get closed() {
|
|
262
|
-
return
|
|
262
|
+
return y;
|
|
263
263
|
},
|
|
264
|
-
async next(
|
|
265
|
-
for (;
|
|
266
|
-
if (
|
|
264
|
+
async next(p) {
|
|
265
|
+
for (; j >= g.length; ) {
|
|
266
|
+
if (y)
|
|
267
267
|
throw new Error("[velojs/testing] socket closed before next()");
|
|
268
|
-
await
|
|
268
|
+
await T(p.timeoutMs);
|
|
269
269
|
}
|
|
270
|
-
return
|
|
270
|
+
return g[j++];
|
|
271
271
|
},
|
|
272
|
-
async nextN(
|
|
273
|
-
const
|
|
274
|
-
for (;
|
|
275
|
-
if (
|
|
276
|
-
|
|
272
|
+
async nextN(p, P) {
|
|
273
|
+
const $ = Date.now() + P.timeoutMs, I = [];
|
|
274
|
+
for (; I.length < p; ) {
|
|
275
|
+
if (j < g.length) {
|
|
276
|
+
I.push(g[j++]);
|
|
277
277
|
continue;
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
279
|
+
if (y)
|
|
280
280
|
throw new Error("[velojs/testing] socket closed before nextN()");
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
281
|
+
const R = $ - Date.now();
|
|
282
|
+
if (R <= 0)
|
|
283
283
|
throw new Error(
|
|
284
284
|
`[velojs/testing] socket.nextN() timed out after ${P.timeoutMs}ms`
|
|
285
285
|
);
|
|
286
|
-
await
|
|
286
|
+
await T(R);
|
|
287
287
|
}
|
|
288
|
-
return
|
|
288
|
+
return I;
|
|
289
289
|
},
|
|
290
|
-
async close(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
new Promise((
|
|
290
|
+
async close(p, P) {
|
|
291
|
+
E(), await Promise.race([
|
|
292
|
+
v,
|
|
293
|
+
new Promise(($) => setTimeout($, 50))
|
|
294
294
|
]);
|
|
295
295
|
},
|
|
296
|
-
done:
|
|
296
|
+
done: v
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
299
|
function ne(e) {
|
|
300
|
-
const s = /* @__PURE__ */ new Map(),
|
|
301
|
-
function
|
|
302
|
-
for (const
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
for (const
|
|
306
|
-
if (!
|
|
307
|
-
const
|
|
308
|
-
if (typeof
|
|
309
|
-
const
|
|
310
|
-
s.set(
|
|
311
|
-
name:
|
|
312
|
-
fn:
|
|
313
|
-
moduleId:
|
|
314
|
-
url: `/_action/${
|
|
300
|
+
const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
301
|
+
function f(c) {
|
|
302
|
+
for (const h of c) {
|
|
303
|
+
const l = h.module?.metadata?.moduleId, w = h.module?.metadata?.fullPath;
|
|
304
|
+
if (h.module && l) {
|
|
305
|
+
for (const t of Object.keys(h.module)) {
|
|
306
|
+
if (!t.startsWith("action_")) continue;
|
|
307
|
+
const r = h.module[t];
|
|
308
|
+
if (typeof r != "function") continue;
|
|
309
|
+
const a = t.replace("action_", "");
|
|
310
|
+
s.set(r, {
|
|
311
|
+
name: a,
|
|
312
|
+
fn: r,
|
|
313
|
+
moduleId: l,
|
|
314
|
+
url: `/_action/${l}/${a}`
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
|
-
const
|
|
318
|
-
if (typeof
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
fn:
|
|
322
|
-
moduleId:
|
|
323
|
-
paths: [
|
|
317
|
+
const i = h.module.loader;
|
|
318
|
+
if (typeof i == "function" && w) {
|
|
319
|
+
const t = n.get(i);
|
|
320
|
+
t ? t.paths.push(w) : n.set(i, {
|
|
321
|
+
fn: i,
|
|
322
|
+
moduleId: l,
|
|
323
|
+
paths: [w]
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
h.children && f(h.children);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
return
|
|
330
|
+
return f(e), { actions: s, loaders: n };
|
|
331
331
|
}
|
|
332
332
|
function se(e, s) {
|
|
333
333
|
if (typeof s == "string") return s;
|
|
334
|
-
const
|
|
335
|
-
if (!
|
|
334
|
+
const n = e.actions.get(s);
|
|
335
|
+
if (!n)
|
|
336
336
|
throw new Error(
|
|
337
337
|
`[velojs/testing] action_* function was not found in the route tree.
|
|
338
338
|
Make sure your Vitest config loads the VeloJS Vite plugin so that metadata is injected. See https://github.com/mauro-andre/velojs#testing`
|
|
339
339
|
);
|
|
340
|
-
return
|
|
340
|
+
return n.url;
|
|
341
341
|
}
|
|
342
|
-
function oe(e, s,
|
|
342
|
+
function oe(e, s, n) {
|
|
343
343
|
if (typeof s == "string") return s;
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
344
|
+
const f = e.loaders.get(s);
|
|
345
|
+
if (!f)
|
|
346
346
|
throw new Error(
|
|
347
347
|
`[velojs/testing] loader function was not found in the route tree.
|
|
348
348
|
Make sure your Vitest config loads the VeloJS Vite plugin so that metadata is injected.`
|
|
349
349
|
);
|
|
350
|
-
let c =
|
|
351
|
-
if (
|
|
352
|
-
for (const [
|
|
353
|
-
c = c.replace(`:${
|
|
350
|
+
let c = f.paths[0];
|
|
351
|
+
if (n)
|
|
352
|
+
for (const [h, l] of Object.entries(n))
|
|
353
|
+
c = c.replace(`:${h}`, encodeURIComponent(l));
|
|
354
354
|
return c;
|
|
355
355
|
}
|
|
356
356
|
class re {
|
|
@@ -361,397 +361,438 @@ class re {
|
|
|
361
361
|
};
|
|
362
362
|
push(s) {
|
|
363
363
|
this.buffer += s;
|
|
364
|
-
const
|
|
365
|
-
let
|
|
366
|
-
for (; (
|
|
364
|
+
const n = [];
|
|
365
|
+
let f;
|
|
366
|
+
for (; (f = this.buffer.indexOf(`
|
|
367
367
|
`)) !== -1; ) {
|
|
368
|
-
const c = this.buffer.slice(0,
|
|
369
|
-
if (this.buffer = this.buffer.slice(
|
|
368
|
+
const c = this.buffer.slice(0, f);
|
|
369
|
+
if (this.buffer = this.buffer.slice(f + 1), c === "") {
|
|
370
370
|
if (this.current.data.length > 0 || this.current.event !== "message") {
|
|
371
|
-
const
|
|
371
|
+
const i = {
|
|
372
372
|
event: this.current.event,
|
|
373
373
|
data: this.current.data.join(`
|
|
374
374
|
`)
|
|
375
375
|
};
|
|
376
|
-
this.current.id !== void 0 && (
|
|
376
|
+
this.current.id !== void 0 && (i.id = this.current.id), n.push(i);
|
|
377
377
|
}
|
|
378
378
|
this.current = { event: "message", data: [] };
|
|
379
379
|
continue;
|
|
380
380
|
}
|
|
381
381
|
if (c.startsWith(":")) continue;
|
|
382
|
-
const
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
let
|
|
386
|
-
|
|
382
|
+
const h = c.indexOf(":");
|
|
383
|
+
if (h === -1) continue;
|
|
384
|
+
const l = c.slice(0, h);
|
|
385
|
+
let w = c.slice(h + 1);
|
|
386
|
+
w.startsWith(" ") && (w = w.slice(1)), l === "event" ? this.current.event = w : l === "data" ? this.current.data.push(w) : l === "id" && (this.current.id = w);
|
|
387
387
|
}
|
|
388
|
-
return
|
|
388
|
+
return n;
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
|
-
async function
|
|
392
|
-
const { response: s, snapshotEvents:
|
|
393
|
-
let
|
|
394
|
-
const
|
|
395
|
-
let
|
|
396
|
-
const
|
|
397
|
-
for (;
|
|
398
|
-
const
|
|
399
|
-
|
|
391
|
+
async function q(e) {
|
|
392
|
+
const { response: s, snapshotEvents: n = !1, channelEvents: f = !1, liveEvents: c = !1 } = e, h = s.status, l = [], w = [];
|
|
393
|
+
let i = null, t = !1, r = null, a = 0, u = 0;
|
|
394
|
+
const g = [], o = [];
|
|
395
|
+
let d = null, k = Promise.resolve(void 0);
|
|
396
|
+
const b = (y) => {
|
|
397
|
+
for (; g.length > 0; ) {
|
|
398
|
+
const m = g.shift();
|
|
399
|
+
y ? m.reject(y) : m.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
400
400
|
}
|
|
401
|
-
for (;
|
|
402
|
-
const
|
|
403
|
-
|
|
401
|
+
for (; o.length > 0; ) {
|
|
402
|
+
const m = o.shift();
|
|
403
|
+
y ? m.reject(y) : m.reject(new Error("[velojs/testing] subscription closed before next event"));
|
|
404
404
|
}
|
|
405
405
|
};
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
|
|
406
|
+
if (h >= 200 && h < 300 && s.body) {
|
|
407
|
+
d = s.body.getReader();
|
|
408
|
+
const y = new TextDecoder(), m = new re();
|
|
409
|
+
k = (async () => {
|
|
410
410
|
try {
|
|
411
411
|
for (; ; ) {
|
|
412
|
-
const { value:
|
|
413
|
-
if (
|
|
414
|
-
|
|
412
|
+
const { value: S, done: C } = await d.read();
|
|
413
|
+
if (C) {
|
|
414
|
+
t || (t = !0), b();
|
|
415
415
|
return;
|
|
416
416
|
}
|
|
417
|
-
const
|
|
418
|
-
for (const
|
|
419
|
-
const T =
|
|
420
|
-
if (
|
|
421
|
-
let
|
|
417
|
+
const E = y.decode(S, { stream: !0 }), A = m.push(E);
|
|
418
|
+
for (const v of A) {
|
|
419
|
+
const T = v.event === "slice";
|
|
420
|
+
if (v.event === "snapshot" || f && T) {
|
|
421
|
+
let j;
|
|
422
422
|
try {
|
|
423
|
-
|
|
424
|
-
} catch (
|
|
425
|
-
|
|
423
|
+
j = JSON.parse(v.data);
|
|
424
|
+
} catch (_) {
|
|
425
|
+
r = _;
|
|
426
426
|
}
|
|
427
|
-
if (
|
|
428
|
-
if (T || (
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
427
|
+
if (j !== void 0) {
|
|
428
|
+
if (T || (i = j), n || f && T) {
|
|
429
|
+
const _ = j;
|
|
430
|
+
l.push(_);
|
|
431
|
+
const p = g.shift();
|
|
432
|
+
p && p.resolve(_);
|
|
433
433
|
}
|
|
434
|
-
if (
|
|
435
|
-
const
|
|
434
|
+
if (f) {
|
|
435
|
+
const _ = {
|
|
436
436
|
type: T ? "slice" : "snapshot",
|
|
437
|
-
data:
|
|
437
|
+
data: j
|
|
438
438
|
};
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
439
|
+
w.push(_);
|
|
440
|
+
const p = o.shift();
|
|
441
|
+
p && p.resolve(_);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
continue;
|
|
445
445
|
}
|
|
446
|
-
if (
|
|
447
|
-
|
|
446
|
+
if (c && v.event === "error") {
|
|
447
|
+
let j;
|
|
448
|
+
try {
|
|
449
|
+
j = JSON.parse(v.data);
|
|
450
|
+
} catch {
|
|
451
|
+
j = { message: v.data };
|
|
452
|
+
}
|
|
453
|
+
const _ = {
|
|
454
|
+
type: "error",
|
|
455
|
+
data: j
|
|
456
|
+
};
|
|
457
|
+
w.push(_);
|
|
458
|
+
const p = o.shift();
|
|
459
|
+
p && p.resolve(_);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (v.event === "close") {
|
|
463
|
+
t = !0, b(), d.cancel().catch(() => {
|
|
448
464
|
});
|
|
449
465
|
return;
|
|
450
466
|
}
|
|
451
|
-
if (
|
|
467
|
+
if (v.event !== "heartbeat")
|
|
452
468
|
try {
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
} catch (
|
|
458
|
-
|
|
469
|
+
const j = JSON.parse(v.data);
|
|
470
|
+
l.push(j);
|
|
471
|
+
const _ = g.shift();
|
|
472
|
+
_ && _.resolve(j);
|
|
473
|
+
} catch (j) {
|
|
474
|
+
r = j;
|
|
459
475
|
}
|
|
460
476
|
}
|
|
461
477
|
}
|
|
462
|
-
} catch (
|
|
463
|
-
if (
|
|
464
|
-
|
|
478
|
+
} catch (S) {
|
|
479
|
+
if (S?.name === "AbortError") {
|
|
480
|
+
b();
|
|
465
481
|
return;
|
|
466
482
|
}
|
|
467
|
-
|
|
483
|
+
b(S);
|
|
468
484
|
}
|
|
469
485
|
})();
|
|
470
486
|
} else
|
|
471
|
-
await s.text().catch(() => ""),
|
|
472
|
-
const
|
|
487
|
+
await s.text().catch(() => ""), t = !0;
|
|
488
|
+
const x = {
|
|
473
489
|
get status() {
|
|
474
|
-
return
|
|
490
|
+
return h;
|
|
475
491
|
},
|
|
476
492
|
get events() {
|
|
477
|
-
return
|
|
493
|
+
return l;
|
|
478
494
|
},
|
|
479
495
|
get snapshot() {
|
|
480
|
-
return
|
|
496
|
+
return i;
|
|
481
497
|
},
|
|
482
498
|
get closed() {
|
|
483
|
-
return
|
|
499
|
+
return t;
|
|
484
500
|
},
|
|
485
|
-
async next({ timeoutMs:
|
|
486
|
-
if (
|
|
487
|
-
if (
|
|
488
|
-
const
|
|
489
|
-
return
|
|
501
|
+
async next({ timeoutMs: y }) {
|
|
502
|
+
if (r) throw r;
|
|
503
|
+
if (l.length > a) {
|
|
504
|
+
const m = l[a];
|
|
505
|
+
return a++, m;
|
|
490
506
|
}
|
|
491
|
-
if (
|
|
507
|
+
if (t)
|
|
492
508
|
throw new Error("[velojs/testing] subscription is closed");
|
|
493
|
-
return new Promise((
|
|
494
|
-
const
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
`[velojs/testing] timed out after ${
|
|
509
|
+
return new Promise((m, S) => {
|
|
510
|
+
const C = setTimeout(() => {
|
|
511
|
+
const v = g.findIndex((T) => T.resolve === E);
|
|
512
|
+
v !== -1 && g.splice(v, 1), S(new Error(
|
|
513
|
+
`[velojs/testing] timed out after ${y}ms waiting for next event`
|
|
498
514
|
));
|
|
499
|
-
},
|
|
500
|
-
clearTimeout(
|
|
501
|
-
},
|
|
502
|
-
clearTimeout(
|
|
515
|
+
}, y), E = (v) => {
|
|
516
|
+
clearTimeout(C), a++, m(v);
|
|
517
|
+
}, A = (v) => {
|
|
518
|
+
clearTimeout(C), S(v);
|
|
503
519
|
};
|
|
504
|
-
|
|
520
|
+
g.push({ resolve: E, reject: A });
|
|
505
521
|
});
|
|
506
522
|
},
|
|
507
|
-
async nextEvent({ timeoutMs:
|
|
508
|
-
if (
|
|
509
|
-
if (
|
|
510
|
-
const
|
|
511
|
-
return
|
|
523
|
+
async nextEvent({ timeoutMs: y }) {
|
|
524
|
+
if (r) throw r;
|
|
525
|
+
if (w.length > u) {
|
|
526
|
+
const m = w[u];
|
|
527
|
+
return u++, m;
|
|
512
528
|
}
|
|
513
|
-
if (
|
|
529
|
+
if (t)
|
|
514
530
|
throw new Error("[velojs/testing] subscription is closed");
|
|
515
|
-
return new Promise((
|
|
516
|
-
const
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
`[velojs/testing] timed out after ${
|
|
531
|
+
return new Promise((m, S) => {
|
|
532
|
+
const C = setTimeout(() => {
|
|
533
|
+
const v = o.findIndex((T) => T.resolve === E);
|
|
534
|
+
v !== -1 && o.splice(v, 1), S(new Error(
|
|
535
|
+
`[velojs/testing] timed out after ${y}ms waiting for next event`
|
|
520
536
|
));
|
|
521
|
-
},
|
|
522
|
-
clearTimeout(
|
|
523
|
-
},
|
|
524
|
-
clearTimeout(
|
|
537
|
+
}, y), E = (v) => {
|
|
538
|
+
clearTimeout(C), u++, m(v);
|
|
539
|
+
}, A = (v) => {
|
|
540
|
+
clearTimeout(C), S(v);
|
|
525
541
|
};
|
|
526
|
-
|
|
542
|
+
o.push({ resolve: E, reject: A });
|
|
527
543
|
});
|
|
528
544
|
},
|
|
529
|
-
async nextN(
|
|
530
|
-
const
|
|
531
|
-
for (let
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
545
|
+
async nextN(y, { timeoutMs: m }) {
|
|
546
|
+
const S = Date.now(), C = [];
|
|
547
|
+
for (let E = 0; E < y; E++) {
|
|
548
|
+
const A = m - (Date.now() - S);
|
|
549
|
+
if (A <= 0)
|
|
534
550
|
throw new Error(
|
|
535
|
-
`[velojs/testing] timed out after ${
|
|
551
|
+
`[velojs/testing] timed out after ${m}ms waiting for ${y} events (got ${C.length})`
|
|
536
552
|
);
|
|
537
|
-
|
|
553
|
+
C.push(await x.next({ timeoutMs: A }));
|
|
538
554
|
}
|
|
539
|
-
return
|
|
555
|
+
return C;
|
|
540
556
|
},
|
|
541
557
|
async close() {
|
|
542
|
-
if (
|
|
558
|
+
if (d)
|
|
543
559
|
try {
|
|
544
|
-
await
|
|
560
|
+
await d.cancel();
|
|
545
561
|
} catch {
|
|
546
562
|
}
|
|
547
|
-
|
|
563
|
+
t = !0, b(), await k.catch(() => {
|
|
548
564
|
});
|
|
549
565
|
}
|
|
550
566
|
};
|
|
551
|
-
return
|
|
567
|
+
return x;
|
|
552
568
|
}
|
|
553
|
-
async function
|
|
569
|
+
async function ye(e) {
|
|
554
570
|
const s = Q();
|
|
555
571
|
return await K(s, async () => {
|
|
556
572
|
e.bootstrap && await e.bootstrap();
|
|
557
|
-
const
|
|
573
|
+
const n = {
|
|
558
574
|
...e.channelOptions,
|
|
559
575
|
coalesceMs: e.channelOptions?.coalesceMs ?? 0,
|
|
560
576
|
idleMs: e.channelOptions?.idleMs ?? 0,
|
|
561
577
|
heartbeatMs: e.channelOptions?.heartbeatMs ?? 0
|
|
562
578
|
};
|
|
563
|
-
e.channels ?
|
|
564
|
-
const { createApp:
|
|
565
|
-
return
|
|
579
|
+
e.channels ? M(e.channels, n) : M(F(), n);
|
|
580
|
+
const { createApp: f } = await import("../server.js"), c = await f(e.routes), h = ne(e.routes), l = e.port !== void 0 ? await ie(c, e.port, e.hostname) : void 0;
|
|
581
|
+
return ce(c, s, h, e, void 0, l);
|
|
566
582
|
});
|
|
567
583
|
}
|
|
568
|
-
async function ie(e, s,
|
|
569
|
-
const { serve:
|
|
584
|
+
async function ie(e, s, n) {
|
|
585
|
+
const { serve: f } = await import("@hono/node-server"), { flushServerCallbacks: c, clearActiveServer: h } = await import("../server.js"), l = f({
|
|
570
586
|
fetch: e.fetch,
|
|
571
587
|
port: s,
|
|
572
|
-
...
|
|
573
|
-
}),
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}), await
|
|
577
|
-
const
|
|
578
|
-
let
|
|
588
|
+
...n ? { hostname: n } : {}
|
|
589
|
+
}), w = /* @__PURE__ */ new Set();
|
|
590
|
+
l.on("connection", (u) => {
|
|
591
|
+
w.add(u), u.on("close", () => w.delete(u));
|
|
592
|
+
}), await ae(l, s, n), await B(e, l), c(l);
|
|
593
|
+
const i = l.address(), t = i && typeof i == "object" ? i.port : s, r = n && n !== "0.0.0.0" && n !== "::" ? n : "localhost";
|
|
594
|
+
let a = !1;
|
|
579
595
|
return {
|
|
580
|
-
port:
|
|
581
|
-
url: `http://${
|
|
596
|
+
port: t,
|
|
597
|
+
url: `http://${r}:${t}`,
|
|
582
598
|
async close() {
|
|
583
|
-
if (
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
|
|
599
|
+
if (a) return;
|
|
600
|
+
a = !0;
|
|
601
|
+
const u = new Promise((g) => {
|
|
602
|
+
l.close(() => g());
|
|
587
603
|
});
|
|
588
|
-
for (const
|
|
589
|
-
|
|
604
|
+
for (const g of w) g.destroy();
|
|
605
|
+
w.clear(), l.closeAllConnections(), await u, h(l);
|
|
590
606
|
}
|
|
591
607
|
};
|
|
592
608
|
}
|
|
593
|
-
function
|
|
594
|
-
return e.listening ? Promise.resolve() : new Promise((
|
|
595
|
-
const
|
|
596
|
-
e.off("listening",
|
|
597
|
-
},
|
|
598
|
-
|
|
599
|
-
},
|
|
600
|
-
|
|
601
|
-
const
|
|
609
|
+
function ae(e, s, n) {
|
|
610
|
+
return e.listening ? Promise.resolve() : new Promise((f, c) => {
|
|
611
|
+
const h = `${n ?? "0.0.0.0"}:${s}`, l = () => {
|
|
612
|
+
e.off("listening", w), e.off("error", i);
|
|
613
|
+
}, w = () => {
|
|
614
|
+
l(), f();
|
|
615
|
+
}, i = (t) => {
|
|
616
|
+
l();
|
|
617
|
+
const r = t.code ? `${t.code}: ${t.message}` : t.message;
|
|
602
618
|
c(new Error(
|
|
603
|
-
`[velojs/testing] could not bind the test server on ${
|
|
619
|
+
`[velojs/testing] could not bind the test server on ${h} — ${r}`
|
|
604
620
|
));
|
|
605
621
|
};
|
|
606
|
-
e.once("listening",
|
|
622
|
+
e.once("listening", w), e.once("error", i);
|
|
607
623
|
});
|
|
608
624
|
}
|
|
609
|
-
function
|
|
610
|
-
async function
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
let
|
|
614
|
-
if (
|
|
615
|
-
const
|
|
616
|
-
|
|
625
|
+
function ce(e, s, n, f, c, h) {
|
|
626
|
+
async function l(t, r, a = {}) {
|
|
627
|
+
const u = J(r, a.query), g = new Headers(a.headers ?? {}), o = { ...a.cookies ?? {} }, d = N(o);
|
|
628
|
+
d && g.set("cookie", d);
|
|
629
|
+
let k = null;
|
|
630
|
+
if (a.body !== void 0) {
|
|
631
|
+
const m = Z(a.body);
|
|
632
|
+
k = m.body, m.contentType && !g.has("content-type") && g.set("content-type", m.contentType);
|
|
617
633
|
}
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
return await le(
|
|
634
|
+
const b = { method: t, headers: g };
|
|
635
|
+
k !== null && (b.body = k);
|
|
636
|
+
const x = new Request(u, b), y = await e.fetch(x);
|
|
637
|
+
return await le(y);
|
|
622
638
|
}
|
|
623
|
-
async function
|
|
624
|
-
const
|
|
625
|
-
...
|
|
626
|
-
...
|
|
627
|
-
}),
|
|
628
|
-
|
|
629
|
-
const
|
|
630
|
-
return await e.fetch(
|
|
639
|
+
async function w(t, r, a = {}) {
|
|
640
|
+
const u = J(r, {
|
|
641
|
+
...a.query ?? {},
|
|
642
|
+
...a.channel ? { channel: a.channel } : {}
|
|
643
|
+
}), g = new Headers(a.headers ?? {}), o = { ...a.cookies ?? {} }, d = N(o);
|
|
644
|
+
d && g.set("cookie", d);
|
|
645
|
+
const k = new Request(u, { method: t, headers: g });
|
|
646
|
+
return await e.fetch(k);
|
|
631
647
|
}
|
|
632
|
-
const
|
|
648
|
+
const i = {
|
|
633
649
|
hono: e,
|
|
634
650
|
// `undefined` unless `port` was passed — no listener, no behavior change.
|
|
635
|
-
port:
|
|
636
|
-
url:
|
|
651
|
+
port: h?.port,
|
|
652
|
+
url: h?.url,
|
|
637
653
|
// HTTP
|
|
638
|
-
get: (
|
|
639
|
-
post: (
|
|
640
|
-
put: (
|
|
641
|
-
patch: (
|
|
642
|
-
delete: (
|
|
643
|
-
async action(
|
|
644
|
-
const
|
|
645
|
-
return await
|
|
646
|
-
...
|
|
647
|
-
body:
|
|
654
|
+
get: (t, r) => l("GET", t, r ?? {}),
|
|
655
|
+
post: (t, r) => l("POST", t, r ?? {}),
|
|
656
|
+
put: (t, r) => l("PUT", t, r ?? {}),
|
|
657
|
+
patch: (t, r) => l("PATCH", t, r ?? {}),
|
|
658
|
+
delete: (t, r) => l("DELETE", t, r ?? {}),
|
|
659
|
+
async action(t, r = {}) {
|
|
660
|
+
const a = se(n, t);
|
|
661
|
+
return await l("POST", a, {
|
|
662
|
+
...r,
|
|
663
|
+
body: r.body ?? {}
|
|
648
664
|
});
|
|
649
665
|
},
|
|
650
|
-
async loader(
|
|
651
|
-
const
|
|
652
|
-
...
|
|
653
|
-
query: { ...
|
|
666
|
+
async loader(t, r = {}) {
|
|
667
|
+
const a = oe(n, t, r.params), u = await l("GET", a, {
|
|
668
|
+
...r,
|
|
669
|
+
query: { ...r.query ?? {}, _data: "1" }
|
|
654
670
|
});
|
|
655
|
-
if (
|
|
656
|
-
const
|
|
657
|
-
return
|
|
658
|
-
},
|
|
659
|
-
async subscribe(
|
|
660
|
-
const
|
|
661
|
-
return await
|
|
662
|
-
},
|
|
663
|
-
async channel(
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
const
|
|
671
|
+
if (u.status >= 300 && u.status < 400 || u.status >= 400) return u;
|
|
672
|
+
const g = typeof t == "function" ? n.loaders.get(t)?.moduleId : void 0, o = await u.json();
|
|
673
|
+
return g && o && typeof o == "object" && g in o ? o[g] : o;
|
|
674
|
+
},
|
|
675
|
+
async subscribe(t, r = {}) {
|
|
676
|
+
const a = typeof t == "string" ? t : t.__path ?? de(), u = await w("GET", a, r);
|
|
677
|
+
return await q({ response: u });
|
|
678
|
+
},
|
|
679
|
+
async channel(t, r, a = {}) {
|
|
680
|
+
const u = typeof t == "string" ? t : t?.metadata?.moduleId;
|
|
681
|
+
u || ue(t);
|
|
682
|
+
const g = a.params ? { _route: JSON.stringify(a.params) } : {}, o = await w(
|
|
667
683
|
"GET",
|
|
668
|
-
`/_channel/${
|
|
684
|
+
`/_channel/${u}/${r}`,
|
|
669
685
|
{
|
|
670
|
-
...
|
|
671
|
-
query: { ...
|
|
686
|
+
...a,
|
|
687
|
+
query: { ...a.query ?? {}, ...g }
|
|
672
688
|
}
|
|
673
689
|
);
|
|
674
|
-
return await
|
|
675
|
-
response:
|
|
690
|
+
return await q({
|
|
691
|
+
response: o,
|
|
676
692
|
snapshotEvents: !0,
|
|
677
693
|
channelEvents: !0
|
|
678
694
|
});
|
|
679
695
|
},
|
|
680
|
-
async
|
|
681
|
-
|
|
696
|
+
async liveAction(t, r, a = {}) {
|
|
697
|
+
const u = typeof t == "string" ? t : t?.metadata?.moduleId;
|
|
698
|
+
u || fe(t);
|
|
699
|
+
const g = a.args !== void 0 ? { _args: JSON.stringify(a.args) } : {}, o = await w(
|
|
700
|
+
"GET",
|
|
701
|
+
`/_live/${u}/${r}`,
|
|
702
|
+
{
|
|
703
|
+
...a,
|
|
704
|
+
query: { ...a.query ?? {}, ...g }
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
return await q({
|
|
708
|
+
response: o,
|
|
709
|
+
snapshotEvents: !0,
|
|
710
|
+
channelEvents: !0,
|
|
711
|
+
liveEvents: !0
|
|
712
|
+
});
|
|
682
713
|
},
|
|
683
|
-
async
|
|
684
|
-
|
|
714
|
+
async socket(t, r = {}) {
|
|
715
|
+
return await te(e, t, r);
|
|
716
|
+
},
|
|
717
|
+
async sessionCookies({ user: t }) {
|
|
718
|
+
if (!f.getSessionCookie)
|
|
685
719
|
throw new Error(
|
|
686
720
|
"[velojs/testing] sessionCookies/as requires `getSessionCookie` in createTestApp options."
|
|
687
721
|
);
|
|
688
|
-
return await
|
|
722
|
+
return await f.getSessionCookie({ user: t });
|
|
689
723
|
},
|
|
690
|
-
as({ user:
|
|
691
|
-
if (!
|
|
724
|
+
as({ user: t }) {
|
|
725
|
+
if (!f.getSessionCookie)
|
|
692
726
|
throw new Error(
|
|
693
727
|
"[velojs/testing] app.as() requires `getSessionCookie` in createTestApp options."
|
|
694
728
|
);
|
|
695
|
-
let
|
|
696
|
-
const
|
|
697
|
-
const
|
|
698
|
-
...
|
|
699
|
-
cookies: { ...
|
|
729
|
+
let r = null;
|
|
730
|
+
const a = () => (r || (r = Promise.resolve(f.getSessionCookie({ user: t }))), r), u = (k) => (async (...b) => {
|
|
731
|
+
const x = await a(), [y, m] = b, S = {
|
|
732
|
+
...m ?? {},
|
|
733
|
+
cookies: { ...x, ...m?.cookies ?? {} }
|
|
700
734
|
};
|
|
701
|
-
return await
|
|
702
|
-
}),
|
|
703
|
-
const
|
|
704
|
-
return await
|
|
705
|
-
...
|
|
706
|
-
cookies: { ...
|
|
735
|
+
return await k.call(i, y, S);
|
|
736
|
+
}), g = (k) => (async (b, x, y = {}) => {
|
|
737
|
+
const m = await a();
|
|
738
|
+
return await k.call(i, b, x, {
|
|
739
|
+
...y,
|
|
740
|
+
cookies: { ...m, ...y?.cookies ?? {} }
|
|
741
|
+
});
|
|
742
|
+
}), o = (k) => (async (b, x, y = {}) => {
|
|
743
|
+
const m = await a();
|
|
744
|
+
return await k.call(i, b, x, {
|
|
745
|
+
...y,
|
|
746
|
+
cookies: { ...m, ...y?.cookies ?? {} }
|
|
707
747
|
});
|
|
708
748
|
});
|
|
709
749
|
return {
|
|
710
750
|
hono: e,
|
|
711
|
-
port:
|
|
712
|
-
url:
|
|
713
|
-
get:
|
|
714
|
-
post:
|
|
715
|
-
put:
|
|
716
|
-
patch:
|
|
717
|
-
delete:
|
|
718
|
-
action:
|
|
719
|
-
loader:
|
|
720
|
-
subscribe:
|
|
721
|
-
channel:
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
751
|
+
port: i.port,
|
|
752
|
+
url: i.url,
|
|
753
|
+
get: u(i.get),
|
|
754
|
+
post: u(i.post),
|
|
755
|
+
put: u(i.put),
|
|
756
|
+
patch: u(i.patch),
|
|
757
|
+
delete: u(i.delete),
|
|
758
|
+
action: u(i.action),
|
|
759
|
+
loader: u(i.loader),
|
|
760
|
+
subscribe: u(i.subscribe),
|
|
761
|
+
channel: g(i.channel),
|
|
762
|
+
liveAction: o(i.liveAction),
|
|
763
|
+
socket: u(i.socket),
|
|
764
|
+
sessionCookies: i.sessionCookies,
|
|
765
|
+
as: i.as,
|
|
725
766
|
// chaining .as.as works — last wins
|
|
726
|
-
mockContext:
|
|
727
|
-
reset:
|
|
728
|
-
close:
|
|
767
|
+
mockContext: i.mockContext,
|
|
768
|
+
reset: i.reset,
|
|
769
|
+
close: i.close
|
|
729
770
|
};
|
|
730
771
|
},
|
|
731
|
-
mockContext(
|
|
732
|
-
return
|
|
772
|
+
mockContext(t = {}) {
|
|
773
|
+
return L(t);
|
|
733
774
|
},
|
|
734
775
|
async reset() {
|
|
735
|
-
for (const
|
|
776
|
+
for (const t of U())
|
|
736
777
|
try {
|
|
737
|
-
|
|
738
|
-
} catch (
|
|
739
|
-
console.error("[velojs/testing] stream.__reset failed:",
|
|
778
|
+
t.__reset();
|
|
779
|
+
} catch (r) {
|
|
780
|
+
console.error("[velojs/testing] stream.__reset failed:", r);
|
|
740
781
|
}
|
|
741
782
|
z();
|
|
742
783
|
},
|
|
743
784
|
async close() {
|
|
744
|
-
await
|
|
745
|
-
for (const
|
|
785
|
+
await i.reset(), G(e);
|
|
786
|
+
for (const t of s.disposers)
|
|
746
787
|
try {
|
|
747
|
-
|
|
748
|
-
} catch (
|
|
749
|
-
console.error("[velojs/testing] disposer failed:",
|
|
788
|
+
t();
|
|
789
|
+
} catch (r) {
|
|
790
|
+
console.error("[velojs/testing] disposer failed:", r);
|
|
750
791
|
}
|
|
751
|
-
s.disposers.clear(), await
|
|
792
|
+
s.disposers.clear(), await h?.close();
|
|
752
793
|
}
|
|
753
794
|
};
|
|
754
|
-
return
|
|
795
|
+
return i;
|
|
755
796
|
}
|
|
756
797
|
async function le(e) {
|
|
757
798
|
return {
|
|
@@ -771,10 +812,16 @@ function ue(e) {
|
|
|
771
812
|
);
|
|
772
813
|
}
|
|
773
814
|
function fe(e) {
|
|
815
|
+
const s = typeof e == "string" ? e : "(a module without metadata)";
|
|
816
|
+
throw new Error(
|
|
817
|
+
`[velojs/testing] liveAction(module, name) needs the module's metadata.moduleId — got ${s}. Pass the imported route module (the Vite plugin injects the metadata) or the moduleId string.`
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
function de(e) {
|
|
774
821
|
throw new Error(
|
|
775
822
|
"[velojs/testing] subscribe(stream) — stream has no __path. If this is a stream_* declaration, make sure your routes import is processed by the VeloJS Vite plugin (your vitest.config.ts must include `veloPlugin()`)."
|
|
776
823
|
);
|
|
777
824
|
}
|
|
778
825
|
export {
|
|
779
|
-
|
|
826
|
+
ye as createTestApp
|
|
780
827
|
};
|