@mauroandre/velojs 0.0.36 → 0.0.37
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 +1 -1
- package/dist/client.js +58 -47
- package/dist/components.js +18 -16
- package/dist/hooks.d.ts +3 -2
- package/dist/hooks.js +107 -110
- package/dist/loader-store.d.ts +49 -0
- package/dist/loader-store.js +103 -0
- package/dist/server.js +11 -11
- package/dist/testing/createTestApp.d.ts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/testing/types.d.ts +7 -3
- package/dist/vite.js +276 -277
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1314,7 +1314,7 @@ VeloJS ships a backend testing toolkit at `@mauroandre/velojs/testing`. Spin up
|
|
|
1314
1314
|
|
|
1315
1315
|
```typescript
|
|
1316
1316
|
import { createTestApp } from "@mauroandre/velojs/testing";
|
|
1317
|
-
import
|
|
1317
|
+
import routes from "../app/routes.js";
|
|
1318
1318
|
import { stream_progress } from "../app/Deploy.js";
|
|
1319
1319
|
import { action_startDeploy } from "../app/Deploy.js";
|
|
1320
1320
|
|
package/dist/client.js
CHANGED
|
@@ -1,81 +1,92 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { hydrate as
|
|
3
|
-
import { Router as x, Route as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { jsxs as j, jsx as o } from "preact/jsx-runtime";
|
|
2
|
+
import { hydrate as w } from "preact";
|
|
3
|
+
import { Router as x, Route as a, Switch as $, useLocation as S } from "wouter-preact";
|
|
4
|
+
import { useEffect as b } from "preact/hooks";
|
|
5
|
+
import { registerRoutePatterns as L, syncLocation as W } from "./loader-store.js";
|
|
6
|
+
const s = (t, n, e) => n ? e && n === "/" ? t || "/" : n.startsWith("/") ? t + n : t + "/" + n : t, v = (t) => t === "" ? "*" : `${t}/*?`, E = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), M = (t) => {
|
|
7
|
+
let n = !1;
|
|
8
|
+
t.endsWith("/*?") && (t = t.slice(0, -3), n = !0);
|
|
9
|
+
const e = t.split("/").map((c) => c.startsWith(":") ? "[^/]+" : E(c)).join("/");
|
|
10
|
+
return n ? `${e}(?:/.*)?` : e;
|
|
11
|
+
}, p = (t, n) => {
|
|
10
12
|
if (t.path === "*") return [];
|
|
11
13
|
if (!t.module) {
|
|
12
|
-
const
|
|
13
|
-
return (t.children ?? []).flatMap((i) =>
|
|
14
|
+
const c = s(n, t.path, !1);
|
|
15
|
+
return (t.children ?? []).flatMap((i) => p(i, c));
|
|
14
16
|
}
|
|
15
17
|
if (!t.children)
|
|
16
|
-
return [
|
|
18
|
+
return [s(n, t.path, !0) || "/"];
|
|
17
19
|
if (t.path)
|
|
18
|
-
return [`${
|
|
19
|
-
const
|
|
20
|
-
return (t.children ?? []).flatMap((
|
|
21
|
-
},
|
|
22
|
-
const
|
|
23
|
-
return new RegExp(`^(?:${
|
|
24
|
-
},
|
|
25
|
-
for (const
|
|
26
|
-
if (
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
20
|
+
return [`${s(n, t.path, !1)}/*?`];
|
|
21
|
+
const e = s(n, t.path, !1);
|
|
22
|
+
return (t.children ?? []).flatMap((c) => p(c, e));
|
|
23
|
+
}, _ = (t, n) => {
|
|
24
|
+
const e = p(t, n);
|
|
25
|
+
return new RegExp(`^(?:${e.map(M).join("|")})$`);
|
|
26
|
+
}, R = (t) => {
|
|
27
|
+
for (const n of t) {
|
|
28
|
+
if (n.path === "*" && n.module) return n.module.Component;
|
|
29
|
+
if (n.children) {
|
|
30
|
+
const e = R(n.children);
|
|
31
|
+
if (e) return e;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
return null;
|
|
33
|
-
},
|
|
35
|
+
}, y = (t, n) => n ? [...t, /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(n, {}) }, "__notfound")] : t, h = (t, n, e, c) => {
|
|
34
36
|
const i = [];
|
|
35
37
|
for (let u = 0; u < t.length; u++) {
|
|
36
|
-
const r = t[u],
|
|
38
|
+
const r = t[u], l = `${c}${u}`;
|
|
37
39
|
if (r.path === "*") continue;
|
|
38
40
|
if (!r.module) {
|
|
39
41
|
if (r.children) {
|
|
40
|
-
const f =
|
|
41
|
-
i.push(...h(r.children, f,
|
|
42
|
+
const f = s(n, r.path, !1);
|
|
43
|
+
i.push(...h(r.children, f, e, `${l}-`));
|
|
42
44
|
}
|
|
43
45
|
continue;
|
|
44
46
|
}
|
|
45
47
|
const d = r.module.Component;
|
|
46
48
|
if (!r.children) {
|
|
47
|
-
const f =
|
|
49
|
+
const f = s(n, r.path, !0) || "/";
|
|
48
50
|
i.push(
|
|
49
|
-
/* @__PURE__ */
|
|
51
|
+
/* @__PURE__ */ o(a, { path: f, children: /* @__PURE__ */ o(d, {}) }, l)
|
|
50
52
|
);
|
|
51
53
|
continue;
|
|
52
54
|
}
|
|
53
55
|
if (r.isRoot) {
|
|
54
56
|
i.push(
|
|
55
|
-
/* @__PURE__ */
|
|
56
|
-
h(r.children, "",
|
|
57
|
-
|
|
58
|
-
) },
|
|
57
|
+
/* @__PURE__ */ o($, { children: y(
|
|
58
|
+
h(r.children, "", e, `${l}-`),
|
|
59
|
+
e
|
|
60
|
+
) }, l)
|
|
59
61
|
);
|
|
60
62
|
continue;
|
|
61
63
|
}
|
|
62
|
-
const m =
|
|
64
|
+
const m = s(n, r.path, !1), C = r.path ? v(m) : _(r, n);
|
|
63
65
|
i.push(
|
|
64
|
-
/* @__PURE__ */
|
|
65
|
-
h(r.children, m,
|
|
66
|
-
|
|
67
|
-
) }) }) },
|
|
66
|
+
/* @__PURE__ */ o(a, { path: C, children: /* @__PURE__ */ o(d, { children: /* @__PURE__ */ o($, { children: y(
|
|
67
|
+
h(r.children, m, e, `${l}-`),
|
|
68
|
+
e
|
|
69
|
+
) }) }) }, l)
|
|
68
70
|
);
|
|
69
71
|
}
|
|
70
72
|
return i;
|
|
71
|
-
},
|
|
72
|
-
const
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
}, g = () => {
|
|
74
|
+
const [t] = S();
|
|
75
|
+
return b(() => {
|
|
76
|
+
W(window.location.pathname);
|
|
77
|
+
}, [t]), null;
|
|
78
|
+
}, k = ({ routes: t }) => {
|
|
79
|
+
L(t);
|
|
80
|
+
const n = R(t), e = h(t, "", n, "");
|
|
81
|
+
return /* @__PURE__ */ j(x, { children: [
|
|
82
|
+
/* @__PURE__ */ o(g, {}),
|
|
83
|
+
e
|
|
84
|
+
] });
|
|
85
|
+
}, z = (t) => {
|
|
86
|
+
const { routes: n } = t, e = document.querySelector("body");
|
|
87
|
+
e && w(/* @__PURE__ */ o(k, { routes: n }), e);
|
|
77
88
|
};
|
|
78
89
|
export {
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
k as ClientRoutes,
|
|
91
|
+
z as startClient
|
|
81
92
|
};
|
package/dist/components.js
CHANGED
|
@@ -1,56 +1,58 @@
|
|
|
1
|
-
import { jsx as o, jsxs as
|
|
1
|
+
import { jsx as o, jsxs as d, Fragment as m } from "preact/jsx-runtime";
|
|
2
2
|
import { useRouter as v, Link as L } from "wouter-preact";
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import "@preact/signals";
|
|
4
|
+
import "preact/hooks";
|
|
5
|
+
import { __veloUpdatePending as C } from "./loader-store.js";
|
|
6
|
+
function j({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
|
|
5
7
|
const n = process.env.NODE_ENV !== "production";
|
|
6
8
|
e = e || process.env.STATIC_BASE_URL || (process.env.VELO_STATIC ? "/client" : "");
|
|
7
9
|
const r = t === !1 ? void 0 : t.endsWith(".svg") ? "image/svg+xml" : t.endsWith(".png") ? "image/png" : "image/x-icon", i = t !== !1 && /* @__PURE__ */ o("link", { rel: "icon", href: `${e}${t}`, type: r });
|
|
8
10
|
if (n)
|
|
9
|
-
return /* @__PURE__ */
|
|
11
|
+
return /* @__PURE__ */ d(m, { children: [
|
|
10
12
|
i,
|
|
11
13
|
/* @__PURE__ */ o("script", { type: "module", src: "/@vite/client" }),
|
|
12
14
|
/* @__PURE__ */ o("script", { type: "module", src: "/__velo_client.js" })
|
|
13
15
|
] });
|
|
14
16
|
const l = globalThis.__veloClientJs || (typeof __VELO_CLIENT_JS__ < "u" ? __VELO_CLIENT_JS__ : "client.js"), c = globalThis.__veloClientCss || (typeof __VELO_CLIENT_CSS__ < "u" ? __VELO_CLIENT_CSS__ : "client.css");
|
|
15
|
-
return /* @__PURE__ */
|
|
17
|
+
return /* @__PURE__ */ d(m, { children: [
|
|
16
18
|
i,
|
|
17
19
|
/* @__PURE__ */ o("link", { rel: "stylesheet", href: `${e}/${c}` }),
|
|
18
20
|
/* @__PURE__ */ o("script", { type: "module", src: `${e}/${l}` })
|
|
19
21
|
] });
|
|
20
22
|
}
|
|
21
|
-
function
|
|
23
|
+
function h(e, t) {
|
|
22
24
|
let n = e;
|
|
23
25
|
for (const [r, i] of Object.entries(t))
|
|
24
26
|
n = n.replace(`:${r}`, i);
|
|
25
27
|
return n;
|
|
26
28
|
}
|
|
27
|
-
function
|
|
28
|
-
const l = typeof e != "string", c = v(), f = l ? e.metadata?.fullPath ?? "/" : e, u = t ?
|
|
29
|
+
function I({ to: e, params: t, search: n, absolute: r, ...i }) {
|
|
30
|
+
const l = typeof e != "string", c = v(), f = l ? e.metadata?.fullPath ?? "/" : e, u = t ? h(f, t) : f, a = n ? `?${new URLSearchParams(n).toString()}` : "", $ = `${u}${a}`;
|
|
29
31
|
if (typeof window < "u" && C.value) {
|
|
30
32
|
let _;
|
|
31
33
|
if (l) {
|
|
32
34
|
const s = e.metadata?.fullPath ?? f;
|
|
33
|
-
_ = `${t ?
|
|
35
|
+
_ = `${t ? h(s, t) : s}${a}`;
|
|
34
36
|
} else {
|
|
35
37
|
const s = u.replace(/^~/, "");
|
|
36
38
|
_ = `${!u.startsWith("~") && c.base ? c.base : ""}${s}${a}`;
|
|
37
39
|
}
|
|
38
|
-
const { onClick:
|
|
40
|
+
const { onClick: p, ...g } = i;
|
|
39
41
|
return /* @__PURE__ */ o(
|
|
40
42
|
"a",
|
|
41
43
|
{
|
|
42
44
|
href: _,
|
|
43
45
|
onClick: (s) => {
|
|
44
|
-
|
|
46
|
+
p && p(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
|
|
45
47
|
},
|
|
46
|
-
...
|
|
48
|
+
...g
|
|
47
49
|
}
|
|
48
50
|
);
|
|
49
51
|
}
|
|
50
|
-
return /* @__PURE__ */ o(L, { to:
|
|
52
|
+
return /* @__PURE__ */ o(L, { to: $, ...i });
|
|
51
53
|
}
|
|
52
54
|
export {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
I as Link,
|
|
56
|
+
j as Scripts,
|
|
57
|
+
h as substituteParams
|
|
56
58
|
};
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Signal } from "@preact/signals";
|
|
2
2
|
import type { EventStream } from "./events.js";
|
|
3
3
|
import type { SocketHandler, SocketStub } from "./sockets.js";
|
|
4
|
-
|
|
4
|
+
import { __veloUpdatePending } from "./loader-store.js";
|
|
5
|
+
export { __veloUpdatePending };
|
|
5
6
|
/**
|
|
6
7
|
* Força o signal a notificar mudanças após mutação de propriedades aninhadas
|
|
7
8
|
*
|
|
@@ -36,6 +37,7 @@ export declare function touch<T>(sig: Signal<T | null>): void;
|
|
|
36
37
|
export declare function Loader<T>(moduleId?: string): {
|
|
37
38
|
data: Signal<T | null>;
|
|
38
39
|
loading: Signal<boolean>;
|
|
40
|
+
refetch: () => void;
|
|
39
41
|
};
|
|
40
42
|
/**
|
|
41
43
|
* Hook para acessar dados do loader dentro de componentes
|
|
@@ -204,4 +206,3 @@ export interface UseSocketApi {
|
|
|
204
206
|
export declare function useSocket(stub: SocketHandler | SocketStub | {
|
|
205
207
|
__path: string;
|
|
206
208
|
}, options?: UseSocketOptions): UseSocketApi;
|
|
207
|
-
export {};
|
package/dist/hooks.js
CHANGED
|
@@ -1,176 +1,173 @@
|
|
|
1
|
-
import { signal as
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { signal as w, useSignal as c } from "@preact/signals";
|
|
2
|
+
import { useEffect as E, useRef as S } from "preact/hooks";
|
|
3
|
+
import { useLocation as b, useParams as A } from "wouter-preact";
|
|
4
|
+
import { refetchModule as m, loaderLoading as L, loaderEntry as N } from "./loader-store.js";
|
|
5
|
+
import { __veloUpdatePending as Q } from "./loader-store.js";
|
|
6
|
+
function R(e) {
|
|
7
|
+
const n = e.value;
|
|
8
|
+
n === null || typeof n != "object" || (e.value = Array.isArray(n) ? [...n] : { ...n });
|
|
7
9
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return { data: {
|
|
10
|
+
function U(e) {
|
|
11
|
+
return typeof window > "u" ? {
|
|
12
|
+
data: {
|
|
12
13
|
get value() {
|
|
13
14
|
return e ? globalThis.__veloServerData?.getStore?.()?.[e] ?? null : null;
|
|
14
15
|
}
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
},
|
|
17
|
+
loading: w(!1),
|
|
18
|
+
refetch: () => {
|
|
19
|
+
}
|
|
20
|
+
} : e ? {
|
|
21
|
+
data: N(e),
|
|
22
|
+
loading: L(e),
|
|
23
|
+
refetch: () => m(e)
|
|
24
|
+
} : { data: w(null), loading: w(!1), refetch: () => {
|
|
25
|
+
} };
|
|
18
26
|
}
|
|
19
|
-
function
|
|
27
|
+
function W(e, n) {
|
|
20
28
|
let t, r;
|
|
21
|
-
Array.isArray(e) ? r = e : (t = e, r =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (typeof window < "u" && t) {
|
|
28
|
-
const n = window.__PAGE_DATA__;
|
|
29
|
-
n?.[t] && (a = n[t], delete n[t]);
|
|
30
|
-
}
|
|
31
|
-
const o = h(a), s = h(!1), f = () => {
|
|
32
|
-
if (typeof window > "u" || !t) return;
|
|
33
|
-
const n = window.location.pathname;
|
|
34
|
-
s.value = !0;
|
|
35
|
-
const p = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${n === "/" ? "" : n}/index.json` : (() => {
|
|
36
|
-
const l = new URLSearchParams(window.location.search);
|
|
37
|
-
return l.set("_data", "1"), `${n}?${l.toString()}`;
|
|
38
|
-
})();
|
|
39
|
-
fetch(p, { cache: "no-cache" }).then((l) => l.json()).then((l) => {
|
|
40
|
-
typeof __VELO_BUILD_HASH__ < "u" && l.__buildHash && l.__buildHash !== __VELO_BUILD_HASH__ && (b.value = !0), o.value = l[t], s.value = !1;
|
|
41
|
-
}).catch(() => {
|
|
42
|
-
s.value = !1;
|
|
43
|
-
});
|
|
44
|
-
}, y = E(a !== null);
|
|
45
|
-
return D(() => {
|
|
46
|
-
if (y.current) {
|
|
47
|
-
y.current = !1;
|
|
48
|
-
return;
|
|
29
|
+
if (Array.isArray(e) ? r = e : (t = e, r = n), typeof window > "u") {
|
|
30
|
+
let _ = null;
|
|
31
|
+
if (t) {
|
|
32
|
+
const h = globalThis.__veloServerData?.getStore?.();
|
|
33
|
+
h?.[t] && (_ = h[t]);
|
|
49
34
|
}
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
return {
|
|
36
|
+
data: c(_),
|
|
37
|
+
loading: c(!1),
|
|
38
|
+
refetch: () => {
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (!t)
|
|
43
|
+
return { data: c(null), loading: c(!1), refetch: () => {
|
|
44
|
+
} };
|
|
45
|
+
const a = N(t), o = L(t), u = () => m(t), d = S(!0);
|
|
46
|
+
return E(() => {
|
|
47
|
+
d.current && (d.current = !1, a.value !== null) || u();
|
|
48
|
+
}, r ?? []), { data: a, loading: o, refetch: u };
|
|
52
49
|
}
|
|
53
|
-
function
|
|
54
|
-
const [, e] =
|
|
50
|
+
function q() {
|
|
51
|
+
const [, e] = b();
|
|
55
52
|
return e;
|
|
56
53
|
}
|
|
57
|
-
function
|
|
54
|
+
function j() {
|
|
58
55
|
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : A();
|
|
59
56
|
}
|
|
60
|
-
function
|
|
57
|
+
function G() {
|
|
61
58
|
if (typeof window > "u")
|
|
62
59
|
return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
|
|
63
60
|
const e = window.__PAGE_DATA__;
|
|
64
61
|
if (e?.__query)
|
|
65
62
|
return e.__query;
|
|
66
|
-
const
|
|
67
|
-
return
|
|
63
|
+
const n = new URLSearchParams(window.location.search), t = {};
|
|
64
|
+
return n.forEach((r, a) => {
|
|
68
65
|
t[a] = r;
|
|
69
66
|
}), t;
|
|
70
67
|
}
|
|
71
|
-
function
|
|
72
|
-
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (
|
|
68
|
+
function J() {
|
|
69
|
+
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (b(), window.location.pathname);
|
|
73
70
|
}
|
|
74
|
-
function
|
|
75
|
-
const t =
|
|
76
|
-
return
|
|
77
|
-
if (typeof window > "u" || !
|
|
71
|
+
function M(e, n = {}) {
|
|
72
|
+
const t = c(null), r = c(null), a = c(!1), o = c(null), { channel: u, enabled: d = !0 } = n;
|
|
73
|
+
return E(() => {
|
|
74
|
+
if (typeof window > "u" || !d) return;
|
|
78
75
|
if (!e.__path) {
|
|
79
76
|
console.warn("[velojs] useEventStream: stream has no __path");
|
|
80
77
|
return;
|
|
81
78
|
}
|
|
82
79
|
t.value = null, r.value = null, a.value = !1, o.value = null;
|
|
83
|
-
const
|
|
84
|
-
return
|
|
80
|
+
const _ = u ? `${e.__path}?channel=${encodeURIComponent(u)}` : e.__path, s = new EventSource(_);
|
|
81
|
+
return s.addEventListener("snapshot", (h) => {
|
|
85
82
|
try {
|
|
86
|
-
r.value = JSON.parse(
|
|
87
|
-
} catch (
|
|
88
|
-
o.value =
|
|
83
|
+
r.value = JSON.parse(h.data);
|
|
84
|
+
} catch (y) {
|
|
85
|
+
o.value = y;
|
|
89
86
|
}
|
|
90
|
-
}),
|
|
87
|
+
}), s.addEventListener("message", (h) => {
|
|
91
88
|
try {
|
|
92
|
-
t.value = JSON.parse(
|
|
93
|
-
} catch (
|
|
94
|
-
o.value =
|
|
89
|
+
t.value = JSON.parse(h.data);
|
|
90
|
+
} catch (y) {
|
|
91
|
+
o.value = y;
|
|
95
92
|
}
|
|
96
|
-
}),
|
|
97
|
-
}),
|
|
98
|
-
a.value = !0,
|
|
99
|
-
}),
|
|
100
|
-
|
|
93
|
+
}), s.addEventListener("heartbeat", () => {
|
|
94
|
+
}), s.addEventListener("close", () => {
|
|
95
|
+
a.value = !0, s.close();
|
|
96
|
+
}), s.addEventListener("error", () => {
|
|
97
|
+
s.readyState === EventSource.CLOSED && (a.value = !0);
|
|
101
98
|
}), () => {
|
|
102
|
-
|
|
99
|
+
s.close();
|
|
103
100
|
};
|
|
104
|
-
}, [e,
|
|
101
|
+
}, [e, u, d]), { data: t, snapshot: r, closed: a, error: o };
|
|
105
102
|
}
|
|
106
|
-
function
|
|
107
|
-
const t =
|
|
108
|
-
return
|
|
109
|
-
if (typeof window > "u" || !
|
|
103
|
+
function x(e, n = {}) {
|
|
104
|
+
const t = c("connecting"), r = c(null), a = c(null), o = S(null), u = S([]), { channel: d, onMessage: _, onOpen: s, onClose: h, onError: y, enabled: D = !0 } = n;
|
|
105
|
+
return E(() => {
|
|
106
|
+
if (typeof window > "u" || !D) return;
|
|
110
107
|
if (!e.__path) {
|
|
111
108
|
console.warn("[velojs] useSocket: stub has no __path");
|
|
112
109
|
return;
|
|
113
110
|
}
|
|
114
111
|
t.value = "connecting", r.value = null, a.value = null;
|
|
115
|
-
const v = `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}`, i =
|
|
116
|
-
return
|
|
112
|
+
const v = `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}`, i = d ? `${v}${e.__path}?channel=${encodeURIComponent(d)}` : `${v}${e.__path}`, f = new WebSocket(i);
|
|
113
|
+
return f.binaryType = "arraybuffer", o.current = f, f.addEventListener("open", () => {
|
|
117
114
|
t.value = "open";
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
for (const
|
|
115
|
+
const l = u.current;
|
|
116
|
+
u.current = [];
|
|
117
|
+
for (const g of l)
|
|
121
118
|
try {
|
|
122
|
-
|
|
119
|
+
f.send(g);
|
|
123
120
|
} catch {
|
|
124
121
|
}
|
|
125
|
-
|
|
126
|
-
}),
|
|
127
|
-
let
|
|
128
|
-
if (typeof
|
|
129
|
-
|
|
130
|
-
else if (
|
|
131
|
-
|
|
122
|
+
s?.();
|
|
123
|
+
}), f.addEventListener("message", (l) => {
|
|
124
|
+
let g;
|
|
125
|
+
if (typeof l.data == "string")
|
|
126
|
+
g = l.data;
|
|
127
|
+
else if (l.data instanceof ArrayBuffer)
|
|
128
|
+
g = new Uint8Array(l.data);
|
|
132
129
|
else
|
|
133
130
|
return;
|
|
134
|
-
r.value =
|
|
135
|
-
}),
|
|
136
|
-
t.value = "closed", o.current = null,
|
|
137
|
-
}),
|
|
138
|
-
a.value =
|
|
131
|
+
r.value = g, _?.(g);
|
|
132
|
+
}), f.addEventListener("close", (l) => {
|
|
133
|
+
t.value = "closed", o.current = null, h?.(l);
|
|
134
|
+
}), f.addEventListener("error", (l) => {
|
|
135
|
+
a.value = l, y?.(l);
|
|
139
136
|
}), () => {
|
|
140
137
|
o.current = null;
|
|
141
138
|
try {
|
|
142
|
-
(
|
|
139
|
+
(f.readyState === WebSocket.OPEN || f.readyState === WebSocket.CONNECTING) && f.close();
|
|
143
140
|
} catch {
|
|
144
141
|
}
|
|
145
142
|
};
|
|
146
|
-
}, [e.__path,
|
|
143
|
+
}, [e.__path, d, D]), { send: (p) => {
|
|
147
144
|
let v;
|
|
148
|
-
typeof
|
|
145
|
+
typeof p == "string" || p instanceof Uint8Array ? v = p : v = JSON.stringify(p);
|
|
149
146
|
const i = o.current;
|
|
150
147
|
if (i && i.readyState === WebSocket.OPEN)
|
|
151
148
|
try {
|
|
152
149
|
i.send(v);
|
|
153
150
|
} catch {
|
|
154
151
|
}
|
|
155
|
-
else i && i.readyState === WebSocket.CONNECTING &&
|
|
156
|
-
}, close: (
|
|
152
|
+
else i && i.readyState === WebSocket.CONNECTING && u.current.push(v);
|
|
153
|
+
}, close: (p, v) => {
|
|
157
154
|
const i = o.current;
|
|
158
155
|
if (i)
|
|
159
156
|
try {
|
|
160
|
-
i.close(
|
|
157
|
+
i.close(p, v);
|
|
161
158
|
} catch {
|
|
162
159
|
}
|
|
163
160
|
}, status: t, lastMessage: r, error: a };
|
|
164
161
|
}
|
|
165
162
|
export {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
U as Loader,
|
|
164
|
+
Q as __veloUpdatePending,
|
|
165
|
+
R as touch,
|
|
166
|
+
M as useEventStream,
|
|
167
|
+
W as useLoader,
|
|
168
|
+
q as useNavigate,
|
|
169
|
+
j as useParams,
|
|
170
|
+
J as usePathname,
|
|
171
|
+
G as useQuery,
|
|
172
|
+
x as useSocket
|
|
176
173
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side loader store.
|
|
3
|
+
*
|
|
4
|
+
* One signal per moduleId, shared by `Loader()` (import phase — the handle other
|
|
5
|
+
* modules import) and `useLoader()` (render phase — the driver with deps). A
|
|
6
|
+
* layout's data and a child's read of it are therefore the same instance, with
|
|
7
|
+
* no module-scope mirror to keep in sync.
|
|
8
|
+
*
|
|
9
|
+
* Invalidation follows the route tree: an entry is stale when the params its own
|
|
10
|
+
* route declares have changed. That is what the server already does — a loader
|
|
11
|
+
* re-runs when a request arrives with different params — so the client stops
|
|
12
|
+
* making the author restate it in `useLoader([params.id])`.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately NOT invalidated by:
|
|
15
|
+
* - a query-string change: `routes.tsx` declares path params, never `?x=`, so
|
|
16
|
+
* there is nothing for the framework to read. Use `useLoader([query.x])`.
|
|
17
|
+
* - another module's fetch: a `?_data=1` response carries every matched
|
|
18
|
+
* module's data, but writing all of it would clobber entries the client owns
|
|
19
|
+
* locally (a filtered list, an optimistic mutation). Only the entries this
|
|
20
|
+
* store decided were stale are written.
|
|
21
|
+
*
|
|
22
|
+
* Server-side this module is inert: `Loader` reads AsyncLocalStorage directly.
|
|
23
|
+
*/
|
|
24
|
+
import { type Signal } from "@preact/signals";
|
|
25
|
+
import type { AppRoutes } from "./types.js";
|
|
26
|
+
/** Set when the server reports a newer build than the one running. */
|
|
27
|
+
export declare const __veloUpdatePending: Signal<boolean>;
|
|
28
|
+
export declare function loaderEntry<T>(moduleId: string): Signal<T | null>;
|
|
29
|
+
export declare function loaderLoading(moduleId: string): Signal<boolean>;
|
|
30
|
+
/** Walk the route tree once, recording each module's declared route pattern. */
|
|
31
|
+
export declare function registerRoutePatterns(routes: AppRoutes): void;
|
|
32
|
+
/**
|
|
33
|
+
* Extract the params a pattern declares from a pathname. Layout patterns are
|
|
34
|
+
* prefixes of the URL (`/x/:id` covers `/x/1/tab`), mirroring how the client
|
|
35
|
+
* router matches them, so the match is prefix-tolerant.
|
|
36
|
+
*
|
|
37
|
+
* Returns null when the pattern does not cover the pathname at all.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractParams(pattern: string, pathname: string): Record<string, string> | null;
|
|
40
|
+
/**
|
|
41
|
+
* Called on every client navigation. Refetches exactly the entries whose
|
|
42
|
+
* declared params changed, in one coalesced request.
|
|
43
|
+
*/
|
|
44
|
+
export declare function syncLocation(pathname: string): void;
|
|
45
|
+
/** Explicit refresh. Never coalesced: a caller asking after a mutation must not
|
|
46
|
+
* be handed a response that started before it. */
|
|
47
|
+
export declare function refetchModule(moduleId: string): void;
|
|
48
|
+
/** Test-only. Drops every entry, pattern and in-flight request. */
|
|
49
|
+
export declare function __resetLoaderStore(): void;
|