@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 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 { routes } from "../app/routes.js";
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 c } from "preact/jsx-runtime";
2
- import { hydrate as j } from "preact";
3
- import { Router as x, Route as p, Switch as $ } from "wouter-preact";
4
- const l = (t, e, n) => e ? n && e === "/" ? t || "/" : e.startsWith("/") ? t + e : t + "/" + e : t, b = (t) => t === "" ? "*" : `${t}/*?`, w = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), S = (t) => {
5
- let e = !1;
6
- t.endsWith("/*?") && (t = t.slice(0, -3), e = !0);
7
- const n = t.split("/").map((o) => o.startsWith(":") ? "[^/]+" : w(o)).join("/");
8
- return e ? `${n}(?:/.*)?` : n;
9
- }, a = (t, e) => {
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 o = l(e, t.path, !1);
13
- return (t.children ?? []).flatMap((i) => a(i, o));
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 [l(e, t.path, !0) || "/"];
18
+ return [s(n, t.path, !0) || "/"];
17
19
  if (t.path)
18
- return [`${l(e, t.path, !1)}/*?`];
19
- const n = l(e, t.path, !1);
20
- return (t.children ?? []).flatMap((o) => a(o, n));
21
- }, W = (t, e) => {
22
- const n = a(t, e);
23
- return new RegExp(`^(?:${n.map(S).join("|")})$`);
24
- }, y = (t) => {
25
- for (const e of t) {
26
- if (e.path === "*" && e.module) return e.module.Component;
27
- if (e.children) {
28
- const n = y(e.children);
29
- if (n) return n;
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
- }, R = (t, e) => e ? [...t, /* @__PURE__ */ c(p, { children: /* @__PURE__ */ c(e, {}) }, "__notfound")] : t, h = (t, e, n, o) => {
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], s = `${o}${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 = l(e, r.path, !1);
41
- i.push(...h(r.children, f, n, `${s}-`));
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 = l(e, r.path, !0) || "/";
49
+ const f = s(n, r.path, !0) || "/";
48
50
  i.push(
49
- /* @__PURE__ */ c(p, { path: f, children: /* @__PURE__ */ c(d, {}) }, s)
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__ */ c($, { children: R(
56
- h(r.children, "", n, `${s}-`),
57
- n
58
- ) }, s)
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 = l(e, r.path, !1), C = r.path ? b(m) : W(r, e);
64
+ const m = s(n, r.path, !1), C = r.path ? v(m) : _(r, n);
63
65
  i.push(
64
- /* @__PURE__ */ c(p, { path: C, children: /* @__PURE__ */ c(d, { children: /* @__PURE__ */ c($, { children: R(
65
- h(r.children, m, n, `${s}-`),
66
- n
67
- ) }) }) }, s)
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
- }, v = ({ routes: t }) => {
72
- const e = y(t), n = h(t, "", e, "");
73
- return /* @__PURE__ */ c(x, { children: n });
74
- }, q = (t) => {
75
- const { routes: e } = t, n = document.querySelector("body");
76
- n && j(/* @__PURE__ */ c(v, { routes: e }), n);
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
- v as ClientRoutes,
80
- q as startClient
90
+ k as ClientRoutes,
91
+ z as startClient
81
92
  };
@@ -1,56 +1,58 @@
1
- import { jsx as o, jsxs as p, Fragment as h } from "preact/jsx-runtime";
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 { __veloUpdatePending as C } from "./hooks.js";
4
- function k({ basePath: e, favicon: t = "/favicon.ico" } = {}) {
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__ */ p(h, { children: [
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__ */ p(h, { children: [
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 $(e, t) {
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 O({ to: e, params: t, search: n, absolute: r, ...i }) {
28
- const l = typeof e != "string", c = v(), f = l ? e.metadata?.fullPath ?? "/" : e, u = t ? $(f, t) : f, a = n ? `?${new URLSearchParams(n).toString()}` : "", g = `${u}${a}`;
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 ? $(s, t) : s}${a}`;
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: d, ...m } = i;
40
+ const { onClick: p, ...g } = i;
39
41
  return /* @__PURE__ */ o(
40
42
  "a",
41
43
  {
42
44
  href: _,
43
45
  onClick: (s) => {
44
- d && d(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
46
+ p && p(s), s.defaultPrevented || (s.preventDefault(), window.location.href = _);
45
47
  },
46
- ...m
48
+ ...g
47
49
  }
48
50
  );
49
51
  }
50
- return /* @__PURE__ */ o(L, { to: g, ...i });
52
+ return /* @__PURE__ */ o(L, { to: $, ...i });
51
53
  }
52
54
  export {
53
- O as Link,
54
- k as Scripts,
55
- $ as substituteParams
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
- export declare const __veloUpdatePending: Signal<boolean>;
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 g, useSignal as h } from "@preact/signals";
2
- import { useEffect as D, useRef as E } from "preact/hooks";
3
- import { useLocation as L, useParams as A } from "wouter-preact";
4
- const b = g(!1);
5
- function O(e) {
6
- e.value !== null && typeof e.value == "object" && (e.value = { ...e.value });
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 C(e) {
9
- const c = g(!1);
10
- if (typeof window > "u")
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
- }, loading: c };
16
- const t = window.__PAGE_DATA__, r = e && t?.[e] ? t[e] : null;
17
- return { data: g(r), loading: c };
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 U(e, c) {
27
+ function W(e, n) {
20
28
  let t, r;
21
- Array.isArray(e) ? r = e : (t = e, r = c);
22
- let a = null;
23
- if (typeof window > "u" && t) {
24
- const _ = globalThis.__veloServerData?.getStore?.();
25
- _?.[t] && (a = _[t]);
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
- f();
51
- }, r ?? []), { data: o, loading: s, refetch: f };
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 k() {
54
- const [, e] = L();
50
+ function q() {
51
+ const [, e] = b();
55
52
  return e;
56
53
  }
57
- function H() {
54
+ function j() {
58
55
  return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : A();
59
56
  }
60
- function R() {
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 c = new URLSearchParams(window.location.search), t = {};
67
- return c.forEach((r, a) => {
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 G() {
72
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (L(), window.location.pathname);
68
+ function J() {
69
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (b(), window.location.pathname);
73
70
  }
74
- function W(e, c = {}) {
75
- const t = h(null), r = h(null), a = h(!1), o = h(null), { channel: s, enabled: f = !0 } = c;
76
- return D(() => {
77
- if (typeof window > "u" || !f) return;
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 y = s ? `${e.__path}?channel=${encodeURIComponent(s)}` : e.__path, n = new EventSource(y);
84
- return n.addEventListener("snapshot", (_) => {
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(_.data);
87
- } catch (p) {
88
- o.value = p;
83
+ r.value = JSON.parse(h.data);
84
+ } catch (y) {
85
+ o.value = y;
89
86
  }
90
- }), n.addEventListener("message", (_) => {
87
+ }), s.addEventListener("message", (h) => {
91
88
  try {
92
- t.value = JSON.parse(_.data);
93
- } catch (p) {
94
- o.value = p;
89
+ t.value = JSON.parse(h.data);
90
+ } catch (y) {
91
+ o.value = y;
95
92
  }
96
- }), n.addEventListener("heartbeat", () => {
97
- }), n.addEventListener("close", () => {
98
- a.value = !0, n.close();
99
- }), n.addEventListener("error", () => {
100
- n.readyState === EventSource.CLOSED && (a.value = !0);
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
- n.close();
99
+ s.close();
103
100
  };
104
- }, [e, s, f]), { data: t, snapshot: r, closed: a, error: o };
101
+ }, [e, u, d]), { data: t, snapshot: r, closed: a, error: o };
105
102
  }
106
- function q(e, c = {}) {
107
- const t = h("connecting"), r = h(null), a = h(null), o = E(null), s = E([]), { channel: f, onMessage: y, onOpen: n, onClose: _, onError: p, enabled: l = !0 } = c;
108
- return D(() => {
109
- if (typeof window > "u" || !l) return;
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 = f ? `${v}${e.__path}?channel=${encodeURIComponent(f)}` : `${v}${e.__path}`, d = new WebSocket(i);
116
- return d.binaryType = "arraybuffer", o.current = d, d.addEventListener("open", () => {
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 u = s.current;
119
- s.current = [];
120
- for (const S of u)
115
+ const l = u.current;
116
+ u.current = [];
117
+ for (const g of l)
121
118
  try {
122
- d.send(S);
119
+ f.send(g);
123
120
  } catch {
124
121
  }
125
- n?.();
126
- }), d.addEventListener("message", (u) => {
127
- let S;
128
- if (typeof u.data == "string")
129
- S = u.data;
130
- else if (u.data instanceof ArrayBuffer)
131
- S = new Uint8Array(u.data);
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 = S, y?.(S);
135
- }), d.addEventListener("close", (u) => {
136
- t.value = "closed", o.current = null, _?.(u);
137
- }), d.addEventListener("error", (u) => {
138
- a.value = u, p?.(u);
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
- (d.readyState === WebSocket.OPEN || d.readyState === WebSocket.CONNECTING) && d.close();
139
+ (f.readyState === WebSocket.OPEN || f.readyState === WebSocket.CONNECTING) && f.close();
143
140
  } catch {
144
141
  }
145
142
  };
146
- }, [e.__path, f, l]), { send: (w) => {
143
+ }, [e.__path, d, D]), { send: (p) => {
147
144
  let v;
148
- typeof w == "string" || w instanceof Uint8Array ? v = w : v = JSON.stringify(w);
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 && s.current.push(v);
156
- }, close: (w, v) => {
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(w, v);
157
+ i.close(p, v);
161
158
  } catch {
162
159
  }
163
160
  }, status: t, lastMessage: r, error: a };
164
161
  }
165
162
  export {
166
- C as Loader,
167
- b as __veloUpdatePending,
168
- O as touch,
169
- W as useEventStream,
170
- U as useLoader,
171
- k as useNavigate,
172
- H as useParams,
173
- G as usePathname,
174
- R as useQuery,
175
- q as useSocket
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;