@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/dist/hooks.js CHANGED
@@ -1,116 +1,176 @@
1
- import { signal as v, useSignal as c } from "@preact/signals";
2
- import { useEffect as h, useRef as p } from "preact/hooks";
3
- import { useLocation as w, useParams as g } from "wouter-preact";
4
- const S = v(!1);
5
- function L(e) {
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 m(e) {
9
- const o = v(!1);
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: o };
15
+ }, loading: c };
16
16
  const t = window.__PAGE_DATA__, r = e && t?.[e] ? t[e] : null;
17
- return { data: v(r), loading: o };
17
+ return { data: g(r), loading: c };
18
18
  }
19
- function A(e, o) {
19
+ function U(e, c) {
20
20
  let t, r;
21
- Array.isArray(e) ? r = e : (t = e, r = o);
22
- let n = null;
21
+ Array.isArray(e) ? r = e : (t = e, r = c);
22
+ let a = null;
23
23
  if (typeof window > "u" && t) {
24
- const i = globalThis.__veloServerData?.getStore?.();
25
- i?.[t] && (n = i[t]);
24
+ const _ = globalThis.__veloServerData?.getStore?.();
25
+ _?.[t] && (a = _[t]);
26
26
  }
27
27
  if (typeof window < "u" && t) {
28
- const a = window.__PAGE_DATA__;
29
- a?.[t] && (n = a[t], delete a[t]);
28
+ const n = window.__PAGE_DATA__;
29
+ n?.[t] && (a = n[t], delete n[t]);
30
30
  }
31
- const u = c(n), s = c(!1), _ = () => {
31
+ const o = h(a), s = h(!1), f = () => {
32
32
  if (typeof window > "u" || !t) return;
33
- const a = window.location.pathname;
33
+ const n = window.location.pathname;
34
34
  s.value = !0;
35
- const f = typeof __VELO_STATIC__ < "u" && __VELO_STATIC__ ? `${a === "/" ? "" : a}/index.json` : (() => {
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"), `${a}?${l.toString()}`;
37
+ return l.set("_data", "1"), `${n}?${l.toString()}`;
38
38
  })();
39
- fetch(f, { cache: "no-cache" }).then((l) => l.json()).then((l) => {
40
- typeof __VELO_BUILD_HASH__ < "u" && l.__buildHash && l.__buildHash !== __VELO_BUILD_HASH__ && (S.value = !0), u.value = l[t], s.value = !1;
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
- }, d = p(n !== null);
45
- return h(() => {
46
- if (d.current) {
47
- d.current = !1;
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: u, loading: s, refetch: _ };
50
+ f();
51
+ }, r ?? []), { data: o, loading: s, refetch: f };
52
52
  }
53
- function P() {
54
- const [, e] = w();
53
+ function k() {
54
+ const [, e] = L();
55
55
  return e;
56
56
  }
57
- function T() {
58
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : g();
57
+ function H() {
58
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__params ?? {} : A();
59
59
  }
60
- function b() {
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 o = new URLSearchParams(window.location.search), t = {};
67
- return o.forEach((r, n) => {
68
- t[n] = r;
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 H() {
72
- return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (w(), window.location.pathname);
71
+ function G() {
72
+ return typeof window > "u" ? globalThis.__veloServerData?.getStore?.()?.__pathname ?? "/" : (L(), window.location.pathname);
73
73
  }
74
- function U(e, o = {}) {
75
- const t = c(null), r = c(null), n = c(!1), u = c(null), { channel: s, enabled: _ = !0 } = o;
76
- return h(() => {
77
- if (typeof window > "u" || !_) return;
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, n.value = !1, u.value = null;
83
- const d = s ? `${e.__path}?channel=${encodeURIComponent(s)}` : e.__path, a = new EventSource(d);
84
- return a.addEventListener("snapshot", (i) => {
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(i.data);
87
- } catch (f) {
88
- u.value = f;
86
+ r.value = JSON.parse(_.data);
87
+ } catch (p) {
88
+ o.value = p;
89
89
  }
90
- }), a.addEventListener("message", (i) => {
90
+ }), n.addEventListener("message", (_) => {
91
91
  try {
92
- t.value = JSON.parse(i.data);
93
- } catch (f) {
94
- u.value = f;
92
+ t.value = JSON.parse(_.data);
93
+ } catch (p) {
94
+ o.value = p;
95
95
  }
96
- }), a.addEventListener("heartbeat", () => {
97
- }), a.addEventListener("close", () => {
98
- n.value = !0, a.close();
99
- }), a.addEventListener("error", () => {
100
- a.readyState === EventSource.CLOSED && (n.value = !0);
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
- a.close();
140
+ o.current = null;
141
+ try {
142
+ (d.readyState === WebSocket.OPEN || d.readyState === WebSocket.CONNECTING) && d.close();
143
+ } catch {
144
+ }
103
145
  };
104
- }, [e, s, _]), { data: t, snapshot: r, closed: n, error: u };
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
- m as Loader,
108
- S as __veloUpdatePending,
109
- L as touch,
110
- U as useEventStream,
111
- A as useLoader,
112
- P as useNavigate,
113
- T as useParams,
114
- H as usePathname,
115
- b as useQuery
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 p } from "preact/jsx-runtime";
2
- import { Hono as b } from "hono";
3
- import { logger as q } from "hono/logger";
4
- import { trimTrailingSlash as T } from "hono/trailing-slash";
5
- import { render as A } from "preact-render-to-string";
6
- import { Router as R } from "wouter-preact";
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 g } from "./app-context.js";
9
- import { flushPendingStreamRoutes as D, registerStreamHandler as I } from "./events.js";
10
- const v = new C();
11
- globalThis.__veloServerData = v;
12
- let _ = null;
13
- function W(e) {
14
- if (_) {
15
- e(_);
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
- g().serverCallbacks.push(e);
19
+ v().serverCallbacks.push(e);
19
20
  }
20
- function y(e) {
21
- _ = e;
22
- const t = g();
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 J(e) {
27
- g().pendingRoutes.push(e);
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 a = globalThis.__veloBuildHash || void 0, r = s ? { ...s, __buildHash: a } : { __buildHash: a };
32
- return e.json(r);
32
+ const r = globalThis.__veloBuildHash || void 0, i = s ? { ...s, __buildHash: r } : { __buildHash: r };
33
+ return e.json(i);
33
34
  }
34
- const n = e.req.path, o = v.run(
35
+ const a = e.req.path, o = S.run(
35
36
  s ?? {},
36
- () => A(/* @__PURE__ */ p(R, { ssrPath: n, children: t }))
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 c = `<script>window.__PAGE_DATA__=${JSON.stringify(
41
+ const n = `<script>window.__PAGE_DATA__=${JSON.stringify(
41
42
  s
42
43
  )}<\/script>`;
43
- return e.html(o.replace("</head>", `${c}</head>`));
44
+ return e.html(o.replace("</head>", `${n}</head>`));
44
45
  }, O = async (e, t) => {
45
- const s = t.req.param(), n = t.req.query(), o = { params: s, query: n, c: t }, c = await Promise.all(
46
- e.map(async (r) => {
47
- if (!r.loader) return null;
48
- const d = await r.loader(o), i = r.metadata?.moduleId;
49
- return i ? { moduleId: i, loaderData: d } : null;
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
- ), a = {
52
+ ), r = {
52
53
  __params: s,
53
- __query: n,
54
+ __query: a,
54
55
  __pathname: t.req.path
55
56
  };
56
- for (const r of c)
57
- r && (a[r.moduleId] = r.loaderData);
57
+ for (const i of n)
58
+ i && (r[i.moduleId] = i.loaderData);
58
59
  return {
59
- components: e.map((r) => r.Component),
60
- data: a
60
+ components: e.map((i) => i.Component),
61
+ data: r
61
62
  };
62
- }, j = (e) => {
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__ */ p(o, {});
69
+ return /* @__PURE__ */ g(o, {});
69
70
  }
70
71
  const s = t[t.length - 1];
71
- return t.slice(0, -1).reduceRight((o, c) => /* @__PURE__ */ p(c, { children: o }), /* @__PURE__ */ p(s, {}));
72
- }, w = (e, t, s = [], n = []) => {
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
- const c = [...s, o.module], a = [
75
- ...n,
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
- w(
89
+ _(
80
90
  e,
81
91
  o.children,
82
- c,
83
- a
92
+ n,
93
+ r
84
94
  );
85
- else {
86
- const r = o.module.metadata?.fullPath;
87
- if (!r) {
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 d = async (i) => {
94
- const { components: u, data: m } = await O(c, i), l = j(u);
95
- return N(i, l, m);
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
- a.length > 0 ? e.on(["GET"], [r], ...a, d) : e.on(["GET"], [r], d);
98
- }
107
+ r.length > 0 ? e.on(["GET"], [i], ...r, l) : e.on(["GET"], [i], l);
108
+ } else
109
+ continue;
99
110
  }
100
- }, S = (e, t, s = []) => {
101
- for (const n of t) {
102
- const o = n.module.metadata?.moduleId, c = [
111
+ }, E = (e, t, s = []) => {
112
+ for (const a of t) {
113
+ const o = a.module?.metadata?.moduleId, n = [
103
114
  ...s,
104
- ...n.middlewares || []
115
+ ...a.middlewares || []
105
116
  ];
106
- if (o) {
107
- const a = Object.keys(n.module).filter(
108
- (r) => r.startsWith("action_")
117
+ if (a.module && o) {
118
+ const r = Object.keys(a.module).filter(
119
+ (i) => i.startsWith("action_")
109
120
  );
110
- for (const r of a) {
111
- const d = r.replace("action_", ""), i = n.module[r];
112
- if (typeof i == "function") {
113
- const u = `/_action/${o}/${d}`, m = async (l) => {
114
- let f = {};
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
- f = await l.req.json();
127
+ m = await d.req.json();
117
128
  } catch {
118
129
  }
119
- const P = {
120
- body: f,
121
- params: l.req.param(),
122
- query: l.req.query(),
123
- c: l
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 h = await i(P);
127
- return l.json(h ?? { ok: !0 });
128
- } catch (h) {
129
- const E = h instanceof Error ? h.message : "Action failed";
130
- return l.json({ error: E }, 500);
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
- c.length > 0 ? e.on(
144
+ n.length > 0 ? e.on(
134
145
  ["POST"],
135
146
  [u],
136
- ...c,
137
- m
138
- ) : e.on(["POST"], [u], m);
147
+ ...n,
148
+ h
149
+ ) : e.on(["POST"], [u], h);
139
150
  }
140
151
  }
141
152
  }
142
- n.children && S(e, n.children, c);
153
+ a.children && E(e, a.children, n);
143
154
  }
144
- }, $ = async (e, t, s = []) => {
145
- const n = (o, c) => {
146
- for (const a of o) {
147
- const r = a.module.metadata?.moduleId, d = [
148
- ...c,
149
- ...a.middlewares || []
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 i = Object.keys(a.module).filter(
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 i) {
156
- const m = u.replace("stream_", ""), l = a.module[u];
157
- if (l?.__isVeloEventStream) {
158
- const f = `/_event/${r}/${m}`;
159
- l.__path = f, I(
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
- f,
162
- l,
163
- d
172
+ m,
173
+ d,
174
+ l
164
175
  );
165
176
  }
166
177
  }
167
178
  }
168
- a.children && n(a.children, d);
179
+ r.children && a(r.children, l);
169
180
  }
170
181
  };
171
- n(t, s);
172
- }, k = async (e) => {
173
- const t = new b();
174
- t.use(T()), process.env.NODE_ENV !== "production" && t.use("*", q());
175
- const n = g().pendingRoutes.splice(0);
176
- for (const o of n)
177
- await o(t);
178
- if (w(t, e), S(t, e), await $(t, e), D(t), process.env.NODE_ENV !== "production" && !_) {
179
- const o = globalThis.__veloDevServer;
180
- o && y(o);
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
- }, z = async (e) => {
184
- const { routes: t, port: s = Number(process.env.SERVER_PORT) || 3e3 } = e, n = await k(t);
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: c } = await import("@hono/node-server/serve-static"), { join: a } = await import("node:path"), r = a(process.cwd(), "dist/client");
187
- (process.env.STATIC_BASE_URL || "").startsWith("http") || n.use("/*", c({ root: r })), console.log(`Server running on http://localhost:${s}`);
188
- const i = o({ fetch: n.fetch, port: s });
189
- y(i);
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 n;
249
+ return a;
192
250
  };
193
251
  export {
194
- J as addRoutes,
195
- k as createApp,
196
- k as default,
197
- W as onServer,
198
- v as serverDataStorage,
199
- z as startServer
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
  };