@mauroandre/velojs 0.0.25 → 0.0.27
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 +121 -1
- package/dist/client.js +43 -16
- package/dist/events.d.ts +58 -3
- package/dist/events.js +174 -135
- package/dist/hooks.d.ts +56 -0
- package/dist/hooks.js +128 -68
- package/dist/index.d.ts +3 -2
- package/dist/server.js +180 -122
- package/dist/sockets.d.ts +94 -0
- package/dist/sockets.js +182 -0
- package/dist/static.js +9 -8
- package/dist/testing/index.js +453 -290
- package/dist/testing/socketSession.d.ts +13 -0
- package/dist/testing/types.d.ts +36 -0
- package/dist/types.d.ts +10 -1
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +339 -231
- package/package.json +6 -1
package/dist/hooks.js
CHANGED
|
@@ -1,116 +1,176 @@
|
|
|
1
|
-
import { signal as
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import { useLocation as
|
|
4
|
-
const
|
|
5
|
-
function
|
|
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
6
|
e.value !== null && typeof e.value == "object" && (e.value = { ...e.value });
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
const
|
|
8
|
+
function C(e) {
|
|
9
|
+
const c = g(!1);
|
|
10
10
|
if (typeof window > "u")
|
|
11
11
|
return { data: {
|
|
12
12
|
get value() {
|
|
13
13
|
return e ? globalThis.__veloServerData?.getStore?.()?.[e] ?? null : null;
|
|
14
14
|
}
|
|
15
|
-
}, loading:
|
|
15
|
+
}, loading: c };
|
|
16
16
|
const t = window.__PAGE_DATA__, r = e && t?.[e] ? t[e] : null;
|
|
17
|
-
return { data:
|
|
17
|
+
return { data: g(r), loading: c };
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function U(e, c) {
|
|
20
20
|
let t, r;
|
|
21
|
-
Array.isArray(e) ? r = e : (t = e, r =
|
|
22
|
-
let
|
|
21
|
+
Array.isArray(e) ? r = e : (t = e, r = c);
|
|
22
|
+
let a = null;
|
|
23
23
|
if (typeof window > "u" && t) {
|
|
24
|
-
const
|
|
25
|
-
|
|
24
|
+
const _ = globalThis.__veloServerData?.getStore?.();
|
|
25
|
+
_?.[t] && (a = _[t]);
|
|
26
26
|
}
|
|
27
27
|
if (typeof window < "u" && t) {
|
|
28
|
-
const
|
|
29
|
-
|
|
28
|
+
const n = window.__PAGE_DATA__;
|
|
29
|
+
n?.[t] && (a = n[t], delete n[t]);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const o = h(a), s = h(!1), f = () => {
|
|
32
32
|
if (typeof window > "u" || !t) return;
|
|
33
|
-
const
|
|
33
|
+
const n = window.location.pathname;
|
|
34
34
|
s.value = !0;
|
|
35
|
-
const
|
|
35
|
+
const p = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${n === "/" ? "" : n}/index.json` : (() => {
|
|
36
36
|
const l = new URLSearchParams(window.location.search);
|
|
37
|
-
return l.set("_data", "1"), `${
|
|
37
|
+
return l.set("_data", "1"), `${n}?${l.toString()}`;
|
|
38
38
|
})();
|
|
39
|
-
fetch(
|
|
40
|
-
typeof __VELO_BUILD_HASH__ < "u" && l.__buildHash && l.__buildHash !== __VELO_BUILD_HASH__ && (
|
|
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
41
|
}).catch(() => {
|
|
42
42
|
s.value = !1;
|
|
43
43
|
});
|
|
44
|
-
},
|
|
45
|
-
return
|
|
46
|
-
if (
|
|
47
|
-
|
|
44
|
+
}, y = E(a !== null);
|
|
45
|
+
return D(() => {
|
|
46
|
+
if (y.current) {
|
|
47
|
+
y.current = !1;
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
}, r ?? []), { data:
|
|
50
|
+
f();
|
|
51
|
+
}, r ?? []), { data: o, loading: s, refetch: f };
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const [, e] =
|
|
53
|
+
function k() {
|
|
54
|
+
const [, e] = L();
|
|
55
55
|
return e;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} :
|
|
57
|
+
function H() {
|
|
58
|
+
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : A();
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function R() {
|
|
61
61
|
if (typeof window > "u")
|
|
62
62
|
return globalThis.__veloServerData?.getStore?.()?.__query ?? {};
|
|
63
63
|
const e = window.__PAGE_DATA__;
|
|
64
64
|
if (e?.__query)
|
|
65
65
|
return e.__query;
|
|
66
|
-
const
|
|
67
|
-
return
|
|
68
|
-
t[
|
|
66
|
+
const c = new URLSearchParams(window.location.search), t = {};
|
|
67
|
+
return c.forEach((r, a) => {
|
|
68
|
+
t[a] = r;
|
|
69
69
|
}), t;
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (
|
|
71
|
+
function G() {
|
|
72
|
+
return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (L(), window.location.pathname);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const t =
|
|
76
|
-
return
|
|
77
|
-
if (typeof window > "u" || !
|
|
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;
|
|
78
78
|
if (!e.__path) {
|
|
79
79
|
console.warn("[velojs] useEventStream: stream has no __path");
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
t.value = null, r.value = null,
|
|
83
|
-
const
|
|
84
|
-
return
|
|
82
|
+
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", (_) => {
|
|
85
85
|
try {
|
|
86
|
-
r.value = JSON.parse(
|
|
87
|
-
} catch (
|
|
88
|
-
|
|
86
|
+
r.value = JSON.parse(_.data);
|
|
87
|
+
} catch (p) {
|
|
88
|
+
o.value = p;
|
|
89
89
|
}
|
|
90
|
-
}),
|
|
90
|
+
}), n.addEventListener("message", (_) => {
|
|
91
91
|
try {
|
|
92
|
-
t.value = JSON.parse(
|
|
93
|
-
} catch (
|
|
94
|
-
|
|
92
|
+
t.value = JSON.parse(_.data);
|
|
93
|
+
} catch (p) {
|
|
94
|
+
o.value = p;
|
|
95
95
|
}
|
|
96
|
-
}),
|
|
97
|
-
}),
|
|
98
|
-
|
|
99
|
-
}),
|
|
100
|
-
|
|
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);
|
|
101
|
+
}), () => {
|
|
102
|
+
n.close();
|
|
103
|
+
};
|
|
104
|
+
}, [e, s, f]), { data: t, snapshot: r, closed: a, error: o };
|
|
105
|
+
}
|
|
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;
|
|
110
|
+
if (!e.__path) {
|
|
111
|
+
console.warn("[velojs] useSocket: stub has no __path");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
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", () => {
|
|
117
|
+
t.value = "open";
|
|
118
|
+
const u = s.current;
|
|
119
|
+
s.current = [];
|
|
120
|
+
for (const S of u)
|
|
121
|
+
try {
|
|
122
|
+
d.send(S);
|
|
123
|
+
} catch {
|
|
124
|
+
}
|
|
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);
|
|
132
|
+
else
|
|
133
|
+
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);
|
|
101
139
|
}), () => {
|
|
102
|
-
|
|
140
|
+
o.current = null;
|
|
141
|
+
try {
|
|
142
|
+
(d.readyState === WebSocket.OPEN || d.readyState === WebSocket.CONNECTING) && d.close();
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
103
145
|
};
|
|
104
|
-
}, [e,
|
|
146
|
+
}, [e.__path, f, l]), { send: (w) => {
|
|
147
|
+
let v;
|
|
148
|
+
typeof w == "string" || w instanceof Uint8Array ? v = w : v = JSON.stringify(w);
|
|
149
|
+
const i = o.current;
|
|
150
|
+
if (i && i.readyState === WebSocket.OPEN)
|
|
151
|
+
try {
|
|
152
|
+
i.send(v);
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
else i && i.readyState === WebSocket.CONNECTING && s.current.push(v);
|
|
156
|
+
}, close: (w, v) => {
|
|
157
|
+
const i = o.current;
|
|
158
|
+
if (i)
|
|
159
|
+
try {
|
|
160
|
+
i.close(w, v);
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}, status: t, lastMessage: r, error: a };
|
|
105
164
|
}
|
|
106
165
|
export {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
116
176
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export type { AppRoutes, RouteNode, RouteModule, LoaderArgs, ActionArgs, Metadata, } from "./types.js";
|
|
1
|
+
export type { AppRoutes, RouteNode, RouteModule, LoaderArgs, ActionArgs, Metadata, HTTPMethod, EndpointHandler, EndpointHandlerArgs, } from "./types.js";
|
|
2
2
|
export type { VeloConfig } from "./config.js";
|
|
3
3
|
export { defineConfig } from "./config.js";
|
|
4
4
|
export { Scripts, Link } from "./components.js";
|
|
5
5
|
export { createEventStream, poll } from "./events.js";
|
|
6
|
-
export type { EventStream, EventStreamConfig, EmitFn, EmitOptions, SourceFn, PerChannelSourceFn, ChannelResolver, } from "./events.js";
|
|
6
|
+
export type { EventStream, EventStreamConfig, EmitFn, EmitOptions, SourceFn, PerChannelSourceFn, StreamPipeFn, StreamPipeArgs, ChannelResolver, } from "./events.js";
|
|
7
|
+
export type { SocketHandler, SocketHandlerArgs, SocketStub, } from "./sockets.js";
|
|
7
8
|
export type { Context, MiddlewareHandler, Next } from "hono";
|
package/dist/server.js
CHANGED
|
@@ -1,200 +1,258 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { Hono as
|
|
3
|
-
import { logger as
|
|
4
|
-
import { trimTrailingSlash as
|
|
5
|
-
import { render as
|
|
6
|
-
import { Router as
|
|
1
|
+
import { jsx as g } from "preact/jsx-runtime";
|
|
2
|
+
import { Hono as q } from "hono";
|
|
3
|
+
import { logger as T } from "hono/logger";
|
|
4
|
+
import { trimTrailingSlash as j } from "hono/trailing-slash";
|
|
5
|
+
import { render as k } from "preact-render-to-string";
|
|
6
|
+
import { Router as A } from "wouter-preact";
|
|
7
7
|
import { AsyncLocalStorage as C } from "node:async_hooks";
|
|
8
|
-
import { getAppContext as
|
|
9
|
-
import { flushPendingStreamRoutes as
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
import { getAppContext as v } from "./app-context.js";
|
|
9
|
+
import { flushPendingStreamRoutes as $, registerStreamHandler as D } from "./events.js";
|
|
10
|
+
import { registerSocketRoutes as I, injectWebSocketServer as y } from "./sockets.js";
|
|
11
|
+
const S = new C();
|
|
12
|
+
globalThis.__veloServerData = S;
|
|
13
|
+
let w = null;
|
|
14
|
+
function Y(e) {
|
|
15
|
+
if (w) {
|
|
16
|
+
e(w);
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
v().serverCallbacks.push(e);
|
|
19
20
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
const t =
|
|
21
|
+
function P(e) {
|
|
22
|
+
w = e;
|
|
23
|
+
const t = v();
|
|
23
24
|
for (const s of t.serverCallbacks) s(e);
|
|
24
25
|
t.serverCallbacks.length = 0;
|
|
25
26
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
27
|
+
function Z(e) {
|
|
28
|
+
v().pendingRoutes.push(e);
|
|
28
29
|
}
|
|
29
30
|
const N = (e, t, s) => {
|
|
30
31
|
if (e.req.query("_data") === "1") {
|
|
31
|
-
const
|
|
32
|
-
return e.json(
|
|
32
|
+
const r = globalThis.__veloBuildHash || void 0, i = s ? { ...s, __buildHash: r } : { __buildHash: r };
|
|
33
|
+
return e.json(i);
|
|
33
34
|
}
|
|
34
|
-
const
|
|
35
|
+
const a = e.req.path, o = S.run(
|
|
35
36
|
s ?? {},
|
|
36
|
-
() =>
|
|
37
|
+
() => k(/* @__PURE__ */ g(A, { ssrPath: a, children: t }))
|
|
37
38
|
);
|
|
38
39
|
if (e.header("Cache-Control", "no-cache"), !s)
|
|
39
40
|
return e.html(o);
|
|
40
|
-
const
|
|
41
|
+
const n = `<script>window.__PAGE_DATA__=${JSON.stringify(
|
|
41
42
|
s
|
|
42
43
|
)}<\/script>`;
|
|
43
|
-
return e.html(o.replace("</head>", `${
|
|
44
|
+
return e.html(o.replace("</head>", `${n}</head>`));
|
|
44
45
|
}, O = async (e, t) => {
|
|
45
|
-
const s = t.req.param(),
|
|
46
|
-
e.map(async (
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
return
|
|
46
|
+
const s = t.req.param(), a = t.req.query(), o = { params: s, query: a, c: t }, n = await Promise.all(
|
|
47
|
+
e.map(async (i) => {
|
|
48
|
+
if (!i.loader) return null;
|
|
49
|
+
const l = await i.loader(o), c = i.metadata?.moduleId;
|
|
50
|
+
return c ? { moduleId: c, loaderData: l } : null;
|
|
50
51
|
})
|
|
51
|
-
),
|
|
52
|
+
), r = {
|
|
52
53
|
__params: s,
|
|
53
|
-
__query:
|
|
54
|
+
__query: a,
|
|
54
55
|
__pathname: t.req.path
|
|
55
56
|
};
|
|
56
|
-
for (const
|
|
57
|
-
|
|
57
|
+
for (const i of n)
|
|
58
|
+
i && (r[i.moduleId] = i.loaderData);
|
|
58
59
|
return {
|
|
59
|
-
components: e.map((
|
|
60
|
-
data:
|
|
60
|
+
components: e.map((i) => i.Component),
|
|
61
|
+
data: r
|
|
61
62
|
};
|
|
62
|
-
},
|
|
63
|
+
}, G = (e) => {
|
|
63
64
|
if (e.length === 0) return null;
|
|
64
65
|
const t = e.filter(Boolean);
|
|
65
66
|
if (t.length === 0) return null;
|
|
66
67
|
if (t.length === 1) {
|
|
67
68
|
const o = t[0];
|
|
68
|
-
return /* @__PURE__ */
|
|
69
|
+
return /* @__PURE__ */ g(o, {});
|
|
69
70
|
}
|
|
70
71
|
const s = t[t.length - 1];
|
|
71
|
-
return t.slice(0, -1).reduceRight((o,
|
|
72
|
-
},
|
|
72
|
+
return t.slice(0, -1).reduceRight((o, n) => /* @__PURE__ */ g(n, { children: o }), /* @__PURE__ */ g(s, {}));
|
|
73
|
+
}, _ = (e, t, s = [], a = []) => {
|
|
73
74
|
for (const o of t) {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
if (o.handler && !o.module) {
|
|
76
|
+
o.children && _(
|
|
77
|
+
e,
|
|
78
|
+
o.children,
|
|
79
|
+
s,
|
|
80
|
+
[...a, ...o.middlewares || []]
|
|
81
|
+
);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const n = o.module ? [...s, o.module] : s, r = [
|
|
85
|
+
...a,
|
|
76
86
|
...o.middlewares || []
|
|
77
87
|
];
|
|
78
88
|
if (o.children)
|
|
79
|
-
|
|
89
|
+
_(
|
|
80
90
|
e,
|
|
81
91
|
o.children,
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
n,
|
|
93
|
+
r
|
|
84
94
|
);
|
|
85
|
-
else {
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
95
|
+
else if (o.module) {
|
|
96
|
+
const i = o.module.metadata?.fullPath;
|
|
97
|
+
if (!i) {
|
|
88
98
|
console.warn(
|
|
89
99
|
`Module ${o.module.metadata?.moduleId} has no fullPath`
|
|
90
100
|
);
|
|
91
101
|
continue;
|
|
92
102
|
}
|
|
93
|
-
const
|
|
94
|
-
const { components: u, data:
|
|
95
|
-
return N(
|
|
103
|
+
const l = async (c) => {
|
|
104
|
+
const { components: u, data: h } = await O(n, c), d = G(u);
|
|
105
|
+
return N(c, d, h);
|
|
96
106
|
};
|
|
97
|
-
|
|
98
|
-
}
|
|
107
|
+
r.length > 0 ? e.on(["GET"], [i], ...r, l) : e.on(["GET"], [i], l);
|
|
108
|
+
} else
|
|
109
|
+
continue;
|
|
99
110
|
}
|
|
100
|
-
},
|
|
101
|
-
for (const
|
|
102
|
-
const o =
|
|
111
|
+
}, E = (e, t, s = []) => {
|
|
112
|
+
for (const a of t) {
|
|
113
|
+
const o = a.module?.metadata?.moduleId, n = [
|
|
103
114
|
...s,
|
|
104
|
-
...
|
|
115
|
+
...a.middlewares || []
|
|
105
116
|
];
|
|
106
|
-
if (o) {
|
|
107
|
-
const
|
|
108
|
-
(
|
|
117
|
+
if (a.module && o) {
|
|
118
|
+
const r = Object.keys(a.module).filter(
|
|
119
|
+
(i) => i.startsWith("action_")
|
|
109
120
|
);
|
|
110
|
-
for (const
|
|
111
|
-
const
|
|
112
|
-
if (typeof
|
|
113
|
-
const u = `/_action/${o}/${
|
|
114
|
-
let
|
|
121
|
+
for (const i of r) {
|
|
122
|
+
const l = i.replace("action_", ""), c = a.module[i];
|
|
123
|
+
if (typeof c == "function") {
|
|
124
|
+
const u = `/_action/${o}/${l}`, h = async (d) => {
|
|
125
|
+
let m = {};
|
|
115
126
|
try {
|
|
116
|
-
|
|
127
|
+
m = await d.req.json();
|
|
117
128
|
} catch {
|
|
118
129
|
}
|
|
119
|
-
const
|
|
120
|
-
body:
|
|
121
|
-
params:
|
|
122
|
-
query:
|
|
123
|
-
c:
|
|
130
|
+
const f = {
|
|
131
|
+
body: m,
|
|
132
|
+
params: d.req.param(),
|
|
133
|
+
query: d.req.query(),
|
|
134
|
+
c: d
|
|
124
135
|
};
|
|
125
136
|
try {
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
} catch (
|
|
129
|
-
const
|
|
130
|
-
return
|
|
137
|
+
const p = await c(f);
|
|
138
|
+
return d.json(p ?? { ok: !0 });
|
|
139
|
+
} catch (p) {
|
|
140
|
+
const b = p instanceof Error ? p.message : "Action failed";
|
|
141
|
+
return d.json({ error: b }, 500);
|
|
131
142
|
}
|
|
132
143
|
};
|
|
133
|
-
|
|
144
|
+
n.length > 0 ? e.on(
|
|
134
145
|
["POST"],
|
|
135
146
|
[u],
|
|
136
|
-
...
|
|
137
|
-
|
|
138
|
-
) : e.on(["POST"], [u],
|
|
147
|
+
...n,
|
|
148
|
+
h
|
|
149
|
+
) : e.on(["POST"], [u], h);
|
|
139
150
|
}
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
|
-
|
|
153
|
+
a.children && E(e, a.children, n);
|
|
143
154
|
}
|
|
144
|
-
},
|
|
145
|
-
const
|
|
146
|
-
for (const
|
|
147
|
-
const
|
|
148
|
-
...
|
|
149
|
-
...
|
|
155
|
+
}, H = async (e, t, s = []) => {
|
|
156
|
+
const a = (o, n) => {
|
|
157
|
+
for (const r of o) {
|
|
158
|
+
const i = r.module?.metadata?.moduleId, l = [
|
|
159
|
+
...n,
|
|
160
|
+
...r.middlewares || []
|
|
150
161
|
];
|
|
151
|
-
if (r) {
|
|
152
|
-
const
|
|
162
|
+
if (r.module && i) {
|
|
163
|
+
const c = Object.keys(r.module).filter(
|
|
153
164
|
(u) => u.startsWith("stream_")
|
|
154
165
|
);
|
|
155
|
-
for (const u of
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
|
|
166
|
+
for (const u of c) {
|
|
167
|
+
const h = u.replace("stream_", ""), d = r.module[u];
|
|
168
|
+
if (d?.__isVeloEventStream) {
|
|
169
|
+
const m = `/_event/${i}/${h}`;
|
|
170
|
+
d.__path = m, D(
|
|
160
171
|
e,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
172
|
+
m,
|
|
173
|
+
d,
|
|
174
|
+
l
|
|
164
175
|
);
|
|
165
176
|
}
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
|
-
|
|
179
|
+
r.children && a(r.children, l);
|
|
169
180
|
}
|
|
170
181
|
};
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
const t = new
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
a(t, s);
|
|
183
|
+
}, x = (e, t) => t ? t.startsWith("/") ? e + t : e ? e + "/" + t : "/" + t : e || "", V = (e) => {
|
|
184
|
+
const t = /* @__PURE__ */ new Set(), s = (a) => {
|
|
185
|
+
for (const o of a) {
|
|
186
|
+
if (o.module && !o.children) {
|
|
187
|
+
const n = o.module.metadata?.fullPath;
|
|
188
|
+
n && t.add(n);
|
|
189
|
+
}
|
|
190
|
+
o.children && s(o.children);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
return s(e), t;
|
|
194
|
+
}, R = (e, t, s, a = "", o = []) => {
|
|
195
|
+
for (const n of t) {
|
|
196
|
+
const r = x(a, n.path), i = [
|
|
197
|
+
...o,
|
|
198
|
+
...n.middlewares || []
|
|
199
|
+
], l = !!n.handler, c = !!n.method;
|
|
200
|
+
if (l && !c ? console.warn(
|
|
201
|
+
`[velojs] invalid route at "${r || "/"}" — "handler" set without "method"; endpoint skipped`
|
|
202
|
+
) : c && !l ? console.warn(
|
|
203
|
+
`[velojs] invalid route at "${r || "/"}" — "method" set without "handler"; endpoint skipped`
|
|
204
|
+
) : l && n.module ? console.warn(
|
|
205
|
+
`[velojs] ambiguous route at "${r || "/"}" — both "module" and "handler" set; endpoint ignored, page kept`
|
|
206
|
+
) : l && n.isRoot && console.warn(
|
|
207
|
+
`[velojs] "isRoot" has no effect on endpoint at "${r || "/"}"; ignored`
|
|
208
|
+
), l && c && !n.module) {
|
|
209
|
+
const h = n.method;
|
|
210
|
+
h === "GET" && s.has(r) && console.warn(
|
|
211
|
+
`[velojs] path "${r}" has both a page GET and an endpoint GET; endpoint will win. Consider renaming one.`
|
|
212
|
+
);
|
|
213
|
+
const d = n.handler, m = async (f) => await d({
|
|
214
|
+
c: f,
|
|
215
|
+
params: f.req.param(),
|
|
216
|
+
query: f.req.query()
|
|
217
|
+
});
|
|
218
|
+
i.length > 0 ? e.on([h], [r], ...i, m) : e.on([h], [r], m);
|
|
219
|
+
}
|
|
220
|
+
n.children && R(
|
|
221
|
+
e,
|
|
222
|
+
n.children,
|
|
223
|
+
s,
|
|
224
|
+
r,
|
|
225
|
+
i
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}, W = async (e) => {
|
|
229
|
+
const t = new q();
|
|
230
|
+
t.use(j()), process.env.NODE_ENV !== "production" && t.use("*", T());
|
|
231
|
+
const a = v().pendingRoutes.splice(0);
|
|
232
|
+
for (const n of a)
|
|
233
|
+
await n(t);
|
|
234
|
+
_(t, e), E(t, e), await H(t, e);
|
|
235
|
+
const o = V(e);
|
|
236
|
+
if (R(t, e, o), await I(t, e), $(t), process.env.NODE_ENV !== "production" && !w) {
|
|
237
|
+
const n = globalThis.__veloDevServer;
|
|
238
|
+
n && (P(n), await y(t, n));
|
|
181
239
|
}
|
|
182
240
|
return t;
|
|
183
|
-
},
|
|
184
|
-
const { routes: t, port: s = Number(process.env.SERVER_PORT) || 3e3 } = e,
|
|
241
|
+
}, ee = async (e) => {
|
|
242
|
+
const { routes: t, port: s = Number(process.env.SERVER_PORT) || 3e3 } = e, a = await W(t);
|
|
185
243
|
if (process.env.NODE_ENV === "production" && !process.env.VELO_STATIC) {
|
|
186
|
-
const { serve: o } = await import("@hono/node-server"), { serveStatic:
|
|
187
|
-
(process.env.STATIC_BASE_URL || "").startsWith("http") ||
|
|
188
|
-
const
|
|
189
|
-
y(
|
|
244
|
+
const { serve: o } = await import("@hono/node-server"), { serveStatic: n } = await import("@hono/node-server/serve-static"), { join: r } = await import("node:path"), i = r(process.cwd(), "dist/client");
|
|
245
|
+
(process.env.STATIC_BASE_URL || "").startsWith("http") || a.use("/*", n({ root: i })), console.log(`Server running on http://localhost:${s}`);
|
|
246
|
+
const c = o({ fetch: a.fetch, port: s });
|
|
247
|
+
await y(a, c), P(c);
|
|
190
248
|
}
|
|
191
|
-
return
|
|
249
|
+
return a;
|
|
192
250
|
};
|
|
193
251
|
export {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
252
|
+
Z as addRoutes,
|
|
253
|
+
W as createApp,
|
|
254
|
+
W as default,
|
|
255
|
+
Y as onServer,
|
|
256
|
+
S as serverDataStorage,
|
|
257
|
+
ee as startServer
|
|
200
258
|
};
|