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