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