@seip/bluebird-js 0.1.1 → 0.1.4

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.
Files changed (49) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/settings.json +10 -0
  3. package/AGENTS.md +124 -64
  4. package/README.md +236 -103
  5. package/app/routes/web.js +47 -55
  6. package/app/views/about.jsx +98 -0
  7. package/app/views/components/Header.jsx +42 -0
  8. package/app/views/components/LiveCounter.jsx +67 -0
  9. package/app/views/dashboard.jsx +300 -0
  10. package/app/views/index.jsx +123 -0
  11. package/app/views/layouts/main/view.jsx +201 -0
  12. package/app/views/legal/terms.html +29 -19
  13. package/app/views/login.jsx +141 -0
  14. package/core/actions.d.ts +4 -0
  15. package/core/actions.js +329 -0
  16. package/core/app.js +129 -22
  17. package/core/auth.js +1 -1
  18. package/core/cli/doctor.js +3 -4
  19. package/core/cli/init.js +153 -6
  20. package/core/cli/migrate.js +418 -145
  21. package/core/cli/view.js +76 -11
  22. package/core/config.js +35 -5
  23. package/core/csrf.js +1 -1
  24. package/core/database.js +52 -17
  25. package/core/debug.js +1 -1
  26. package/core/html.d.ts +54 -42
  27. package/core/html.js +473 -217
  28. package/core/index.d.ts +187 -85
  29. package/core/jsx.d.ts +38 -0
  30. package/core/jsx.js +1180 -0
  31. package/core/model.js +282 -61
  32. package/core/queue.js +7 -4
  33. package/core/render-cache.js +212 -212
  34. package/core/render.d.ts +20 -2
  35. package/core/render.js +320 -43
  36. package/core/upload.js +7 -1
  37. package/core/validate.js +1 -1
  38. package/core/view-loader.js +341 -19
  39. package/core/vite.js +1 -1
  40. package/package.json +9 -3
  41. package/public/js/bluebird-client.js +2313 -1049
  42. package/public/js/tailwind.js +8 -0
  43. package/app/views/about.js +0 -63
  44. package/app/views/dashboard.js +0 -147
  45. package/app/views/index.js +0 -80
  46. package/app/views/layouts/main/view.js +0 -81
  47. package/app/views/login.js +0 -80
  48. package/public/css/bluebird.min.css +0 -2
  49. package/public/js/bluebird.min.js +0 -1073
package/core/render.js CHANGED
@@ -1,5 +1,14 @@
1
1
  import Config from "./config.js";
2
- import { html, SafeHtml, escapeHtml, safeJson } from "./html.js";
2
+ import { html, SafeHtml, escapeHtml, safeJson, isSafeHtml } from "./html.js";
3
+ import {
4
+ h,
5
+ Fragment,
6
+ Island,
7
+ Client,
8
+ isJsxElement,
9
+ renderJsxToString,
10
+ serializeStyle,
11
+ } from "./jsx.js";
3
12
  import RenderCache from "./render-cache.js";
4
13
  import ViewLoader from "./view-loader.js";
5
14
 
@@ -8,31 +17,99 @@ const DEBUG = props.debug;
8
17
  const RENDER_CACHE_TTL = parseInt(process.env.RENDER_CACHE_TTL || "300", 10);
9
18
 
10
19
  /**
11
- * Modern JavaScript HTML rendering engine for Bluebird.js.
12
- * Standardizes on zero-build JS view modules, SafeHtml tagged templates,
13
- * progressive layouts, client hydration, and multi-tier caching.
20
+ * Resolves any rendered output (JSX element tree, SafeHtml, Promise, or string) into an HTML string.
21
+ * Automatically prepends `<!DOCTYPE html>` when a JSX layout returns a root `<html>` element.
22
+ *
23
+ * @param {any} output
24
+ * @param {Object} [ctx={}]
25
+ * @returns {Promise<string>}
26
+ */
27
+ async function resolveOutputToHtml(output, ctx = {}) {
28
+ if (output === null || output === undefined || output === false) {
29
+ return "";
30
+ }
31
+ if (isSafeHtml(output)) {
32
+ return output.toString();
33
+ }
34
+ if (isJsxElement(output) || Array.isArray(output)) {
35
+ const isRootHtmlTag = isJsxElement(output) && output.type === "html";
36
+ const rendered = await renderJsxToString(output, ctx);
37
+ if (isRootHtmlTag && !rendered.trimStart().toLowerCase().startsWith("<!doctype")) {
38
+ return `<!DOCTYPE html>\n${rendered}`;
39
+ }
40
+ return rendered;
41
+ }
42
+ return String(output ?? "");
43
+ }
44
+
45
+ /**
46
+ * Modern JavaScript & React JSX HTML rendering engine for Bluebird.js.
47
+ * Standardizes on zero-build JSX and JS view modules, SafeHtml tagged templates,
48
+ * progressive layouts, client hydration with skeleton anti-CLS locking, and multi-tier caching.
14
49
  */
15
50
  export class Render {
16
51
  /**
17
- * Generates declarative HTML markup for client-side island hydration.
18
- * @param {string} name - Island component name.
19
- * @param {Object} [props={}] - Initial props passed to the component.
52
+ * Generates declarative HTML markup for client-side island hydration with optional
53
+ * skeleton fallback and anti-accordion dimension locking (`minHeight`, `minWidth`).
54
+ *
55
+ * @param {string|Function} name - Island component name or function.
56
+ * @param {Object} [islandProps={}] - Initial props passed to the component.
20
57
  * @param {Object} [options={}] - Island options.
21
58
  * @param {boolean} [options.persist=false] - Preserves island across View Transitions.
22
- * @param {string} [options.fallback=""] - Fallback HTML content.
59
+ * @param {string|SafeHtml|Object} [options.fallback=""] - Fallback or skeleton HTML/JSX content.
60
+ * @param {string|SafeHtml|Object} [options.skeleton] - Skeleton HTML/JSX content to prevent layout shift.
61
+ * @param {string|number} [options.minHeight] - CSS min-height to lock vertical space and prevent CLS.
62
+ * @param {string|number} [options.minWidth] - CSS min-width to lock horizontal space.
63
+ * @param {string} [options.className] - CSS class for the island wrapper.
64
+ * @param {Object|string} [options.style] - Inline styles for the island wrapper.
65
+ * @param {boolean} [options.ssr=false] - Whether to mark container for hydration of server-rendered markup.
23
66
  * @param {string} [options.tag="div"] - Container tag name.
24
67
  * @returns {string} Declarative HTML markup.
25
68
  */
26
- static island(name, props = {}, options = {}) {
69
+ static island(name, islandProps = {}, options = {}) {
27
70
  const tag = options.tag || "div";
71
+ const resolvedName =
72
+ typeof name === "function"
73
+ ? name.displayName || name.name || "Island"
74
+ : String(name);
28
75
  const persistAttr = options.persist ? ' data-persist="true"' : "";
29
- const serializedProps = escapeHtml(safeJson(props));
30
- const fallback = options.fallback || "";
31
- return `<${tag} data-island="${escapeHtml(name)}" data-props="${serializedProps}"${persistAttr}>${fallback}</${tag}>`;
76
+ const hydrateAttr = options.ssr ? ' data-hydrate="true"' : "";
77
+ const classAttr = options.className ? ` class="${escapeHtml(options.className)}"` : "";
78
+
79
+ const styleObj =
80
+ typeof options.style === "object" && options.style !== null
81
+ ? { ...options.style }
82
+ : {};
83
+ if (options.minHeight !== undefined) {
84
+ styleObj.minHeight =
85
+ typeof options.minHeight === "number" ? `${options.minHeight}px` : options.minHeight;
86
+ }
87
+ if (options.minWidth !== undefined) {
88
+ styleObj.minWidth =
89
+ typeof options.minWidth === "number" ? `${options.minWidth}px` : options.minWidth;
90
+ }
91
+ const styleStr =
92
+ typeof options.style === "string" ? options.style : serializeStyle(styleObj);
93
+ const styleAttr = styleStr ? ` style="${escapeHtml(styleStr)}"` : "";
94
+
95
+ const serializedProps = escapeHtml(safeJson(islandProps));
96
+ const rawFallback =
97
+ options.skeleton !== undefined
98
+ ? options.skeleton
99
+ : options.fallback !== undefined
100
+ ? options.fallback
101
+ : "";
102
+ const fallbackStr = isSafeHtml(rawFallback)
103
+ ? rawFallback.toString()
104
+ : typeof rawFallback === "string"
105
+ ? rawFallback
106
+ : "";
107
+
108
+ return `<${tag} data-island="${escapeHtml(resolvedName)}" data-props="${serializedProps}"${persistAttr}${hydrateAttr}${classAttr}${styleAttr}>${fallbackStr}</${tag}>`;
32
109
  }
33
110
 
34
111
  /**
35
- * Synchronously or asynchronously renders a component or view to a raw HTML string.
112
+ * Synchronously or asynchronously renders a component or view (`.jsx` or `.js`) to a raw HTML string.
36
113
  * @param {string} viewName - Component or view name.
37
114
  * @param {Object} [data={}] - Props and context.
38
115
  * @returns {Promise<string>}
@@ -41,11 +118,12 @@ export class Render {
41
118
  const view = await ViewLoader.load(viewName);
42
119
  if (!view) return "";
43
120
 
44
- if (view.type === "js") {
45
- const renderFn = typeof view.module.default === "function" ? view.module.default : view.module;
121
+ if (view.type === "js" || view.type === "jsx") {
122
+ const renderFn =
123
+ typeof view.module.default === "function" ? view.module.default : view.module;
46
124
  const ctx = { data };
47
125
  const output = await renderFn(data, ctx);
48
- return output instanceof SafeHtml ? output.toString() : String(output ?? "");
126
+ return resolveOutputToHtml(output, ctx);
49
127
  }
50
128
 
51
129
  return view.content || "";
@@ -87,7 +165,7 @@ export class Render {
87
165
  }
88
166
 
89
167
  /**
90
- * Sends a rendered HTML view response with full layout and head asset resolution.
168
+ * Sends a rendered HTML view response (`.jsx`, `.js`, or `.html`) with full layout and head asset resolution.
91
169
  *
92
170
  * @param {import('express').Response} res - Express response object.
93
171
  * @param {string} viewName - Logical view identifier.
@@ -103,6 +181,19 @@ export class Render {
103
181
  res.req?.headers?.["x-bluebird-partial"] === "1" ||
104
182
  res.req?.query?._partial === "1";
105
183
 
184
+ const cacheKey = `view:${isPartialRequest ? "partial:" : ""}${viewName}`;
185
+ if (ttl !== undefined && ttl > 0 && !DEBUG) {
186
+ const cached = await RenderCache.lookup(cacheKey);
187
+ if (cached) {
188
+ res.set("Content-Type", "text/html; charset=utf-8");
189
+ if (isPartialRequest) {
190
+ res.set("X-Bluebird-Partial", "1");
191
+ }
192
+ res.set("X-Bluebird-Cache", "HIT");
193
+ return res.send(cached);
194
+ }
195
+ }
196
+
106
197
  const view = await ViewLoader.load(viewName);
107
198
  if (!view) {
108
199
  return res.status(404).json({ message: `View '${viewName}' not found.` });
@@ -110,32 +201,62 @@ export class Render {
110
201
 
111
202
  let rendered = "";
112
203
 
113
- if (view.type === "js") {
204
+ if (view.type === "js" || view.type === "jsx") {
205
+ const viewData = { ...data };
206
+ let csrfToken =
207
+ locals.csrfToken ||
208
+ (typeof res.req?.csrfToken === "function" ? res.req.csrfToken() : "") ||
209
+ res.req?.cookies?.["_csrf"] ||
210
+ res.req?.session?.csrfToken ||
211
+ "";
212
+
213
+ if (!csrfToken && typeof res.cookie === "function") {
214
+ try {
215
+ const { Csrf } = await import("./csrf.js");
216
+ csrfToken = Csrf.generateToken();
217
+ res.cookie("_csrf", csrfToken, {
218
+ httpOnly: false,
219
+ sameSite: "lax",
220
+ secure: Config.isDesktop() ? false : Boolean(!DEBUG),
221
+ path: "/",
222
+ });
223
+ } catch {}
224
+ }
225
+ const flash =
226
+ locals.flash ||
227
+ (typeof res.req?.flash === "function" ? res.req.flash() : null) ||
228
+ null;
229
+
114
230
  const ctx = {
115
231
  req: res.req,
116
232
  res,
117
233
  user: res.req?.user,
234
+ csrfToken,
235
+ flash,
118
236
  locals,
119
237
  appLocals,
120
- data,
238
+ data: viewData,
121
239
  };
122
240
 
123
241
  if (typeof view.module.load === "function") {
124
242
  const loadedData = await view.module.load(ctx);
125
243
  if (loadedData && typeof loadedData === "object") {
126
- Object.assign(data, loadedData);
244
+ Object.assign(viewData, loadedData);
127
245
  }
128
246
  }
129
247
 
130
248
  const mergedData = {
131
249
  ...appLocals,
132
250
  ...locals,
133
- ...data,
251
+ csrfToken,
252
+ ...(flash ? { flash } : {}),
253
+ ...viewData,
134
254
  };
135
255
 
136
- const renderFn = typeof view.module.default === "function" ? view.module.default : view.module;
256
+ const renderFn =
257
+ typeof view.module.default === "function" ? view.module.default : view.module;
137
258
  const content = await renderFn(mergedData, ctx);
138
- const bodyHtml = content instanceof SafeHtml ? content.toString() : String(content ?? "");
259
+ const bodyHtml = await resolveOutputToHtml(content, ctx);
139
260
 
140
261
  const layoutName =
141
262
  data._layout !== undefined
@@ -148,7 +269,7 @@ export class Render {
148
269
  rendered = bodyHtml;
149
270
  } else {
150
271
  const layoutView = await ViewLoader.loadLayout(layoutName);
151
- if (layoutView && layoutView.type === "js") {
272
+ if (layoutView && (layoutView.type === "js" || layoutView.type === "jsx")) {
152
273
  let headData = { title: mergedData.title || "Bluebird App" };
153
274
  if (view.module.head) {
154
275
  headData =
@@ -162,15 +283,17 @@ export class Render {
162
283
  ? layoutView.module.default
163
284
  : layoutView.module;
164
285
 
286
+ const safeBody = html.raw(bodyHtml);
165
287
  const layoutOutput = await layoutFn({
166
- body: html.raw(bodyHtml),
167
- content: html.raw(bodyHtml),
288
+ body: safeBody,
289
+ content: safeBody,
290
+ children: safeBody,
168
291
  head: headData,
169
292
  ctx,
170
293
  data: mergedData,
171
294
  });
172
295
 
173
- rendered = layoutOutput instanceof SafeHtml ? layoutOutput.toString() : String(layoutOutput ?? "");
296
+ rendered = await resolveOutputToHtml(layoutOutput, ctx);
174
297
  } else {
175
298
  rendered = bodyHtml;
176
299
  }
@@ -180,7 +303,6 @@ export class Render {
180
303
  }
181
304
 
182
305
  if (ttl !== undefined && ttl > 0 && !DEBUG) {
183
- const cacheKey = `view:${viewName}`;
184
306
  await RenderCache.store(cacheKey, rendered, ttl);
185
307
  }
186
308
 
@@ -194,32 +316,47 @@ export class Render {
194
316
 
195
317
  /**
196
318
  * Express route handler generator.
319
+ * Supports static props object or a dynamic provider function (req, res) => Object | Promise<Object>.
197
320
  * @param {string} viewName - Logical view name.
198
- * @param {Object} [staticData={}] - Static props merged into data.
321
+ * @param {Object|Function} [dataOrFn={}] - Static props or dynamic provider function.
322
+ * @param {number} [ttl] - Optional route cache duration in seconds.
199
323
  * @returns {Function} Express route handler.
200
324
  */
201
- static view(viewName, staticData = {}) {
202
- return (req, res) => Render.send(res, viewName, staticData);
325
+ static view(viewName, dataOrFn = {}, ttl) {
326
+ return async (req, res) => {
327
+ const resolvedData = typeof dataOrFn === "function" ? await dataOrFn(req, res) : dataOrFn;
328
+ return Render.send(res, viewName, resolvedData, ttl);
329
+ };
203
330
  }
204
331
 
205
332
  /**
206
333
  * Express middleware that caches the rendered HTML response for GET requests.
207
334
  * Respects partial requests with dedicated cache partitions.
208
335
  * @param {number} [seconds] - Cache duration in seconds.
336
+ * @param {Object} [options={}]
337
+ * @param {boolean} [options.allowAuthenticated=false]
209
338
  * @returns {Function}
210
339
  */
211
- static cache(seconds) {
340
+ static cache(seconds, options = {}) {
212
341
  const ttl = seconds ?? RENDER_CACHE_TTL;
342
+ const allowAuthenticated = options.allowAuthenticated === true;
213
343
 
214
344
  return async (req, res, next) => {
215
345
  if (DEBUG || req.method !== "GET") return next();
216
346
 
347
+ if (!allowAuthenticated && (req.headers.authorization || req.cookies?.auth || req.user)) {
348
+ return next();
349
+ }
350
+
217
351
  const isPartial = req.headers?.["x-bluebird-partial"] === "1" || req.query?._partial === "1";
218
352
  const key = `route:${isPartial ? "partial:" : ""}${req.originalUrl}`;
219
353
  const cached = await RenderCache.lookup(key);
220
354
 
221
355
  if (cached) {
222
356
  res.set("Content-Type", "text/html; charset=utf-8");
357
+ if (isPartial) {
358
+ res.set("X-Bluebird-Partial", "1");
359
+ }
223
360
  res.set("X-Bluebird-Cache", "HIT");
224
361
  return res.send(cached);
225
362
  }
@@ -238,7 +375,25 @@ export class Render {
238
375
  }
239
376
 
240
377
  /**
241
- * Streams progressive HTML chunks with out-of-order deferred content resolution.
378
+ * Performs SPA-aware or standard HTTP redirect.
379
+ * @param {import('express').Request} req
380
+ * @param {import('express').Response} res
381
+ * @param {string} url
382
+ * @param {number} [status=302]
383
+ */
384
+ static redirect(req, res, url, status = 302) {
385
+ if (req.headers?.["x-bluebird-client-router"] === "1") {
386
+ res.set("X-Bluebird-Redirect", url);
387
+ return res.status(200).json({ redirect: url });
388
+ }
389
+ return res.redirect(status, url);
390
+ }
391
+
392
+ /**
393
+ * Streams progressive HTML chunks with out-of-order deferred content resolution,
394
+ * rendering inside the layout unless requested as a partial.
395
+ * Supports both `.jsx` and `.js` views and deferred promises.
396
+ *
242
397
  * @param {import('express').Response} res - Express response object.
243
398
  * @param {string} viewName - Logical view identifier.
244
399
  * @param {Object} [data={}] - Initial data and promises.
@@ -250,12 +405,13 @@ export class Render {
250
405
  res.setHeader("X-Content-Type-Options", "nosniff");
251
406
 
252
407
  const deferredTokens = [];
253
- const proxyData = new Proxy(data, {
408
+ const streamData = { ...data };
409
+ const proxyData = new Proxy(streamData, {
254
410
  get(target, prop) {
255
411
  const val = target[prop];
256
412
  if (val && typeof val === "object" && val.__bluebird_deferred__) {
257
- deferredTokens.push({ prop, ...val });
258
- return html.raw(`<div id="bb-defer-${prop}">${val.fallback}</div>`);
413
+ deferredTokens.push({ prop: String(prop), ...val });
414
+ return html.raw(`<div id="bb-defer-${String(prop)}">${val.fallback}</div>`);
259
415
  }
260
416
  return val;
261
417
  },
@@ -267,12 +423,82 @@ export class Render {
267
423
  return;
268
424
  }
269
425
 
426
+ const locals = res.locals || {};
427
+ const appLocals = res.req?.app?.locals || {};
428
+ const isPartialRequest =
429
+ data._layout === false ||
430
+ res.req?.headers?.["x-bluebird-partial"] === "1" ||
431
+ res.req?.query?._partial === "1";
432
+
270
433
  let initialHtml = "";
271
- if (view.type === "js") {
272
- const renderFn = typeof view.module.default === "function" ? view.module.default : view.module;
273
- const ctx = { req: res.req, res, user: res.req?.user, data: proxyData };
274
- const out = await renderFn(proxyData, ctx);
275
- initialHtml = out instanceof SafeHtml ? out.toString() : String(out ?? "");
434
+ if (view.type === "js" || view.type === "jsx") {
435
+ const ctx = {
436
+ req: res.req,
437
+ res,
438
+ user: res.req?.user,
439
+ locals,
440
+ appLocals,
441
+ data: proxyData,
442
+ };
443
+
444
+ if (typeof view.module.load === "function") {
445
+ const loadedData = await view.module.load(ctx);
446
+ if (loadedData && typeof loadedData === "object") {
447
+ Object.assign(streamData, loadedData);
448
+ }
449
+ }
450
+
451
+ const mergedData = {
452
+ ...appLocals,
453
+ ...locals,
454
+ ...proxyData,
455
+ };
456
+
457
+ const renderFn =
458
+ typeof view.module.default === "function" ? view.module.default : view.module;
459
+ const content = await renderFn(mergedData, ctx);
460
+ const bodyHtml = await resolveOutputToHtml(content, ctx);
461
+
462
+ const layoutName =
463
+ data._layout !== undefined
464
+ ? data._layout
465
+ : view.module.layout !== undefined
466
+ ? view.module.layout
467
+ : "main";
468
+
469
+ if (isPartialRequest || layoutName === false) {
470
+ initialHtml = bodyHtml;
471
+ } else {
472
+ const layoutView = await ViewLoader.loadLayout(layoutName);
473
+ if (layoutView && (layoutView.type === "js" || layoutView.type === "jsx")) {
474
+ let headData = { title: mergedData.title || "Bluebird App" };
475
+ if (view.module.head) {
476
+ headData =
477
+ typeof view.module.head === "function"
478
+ ? await view.module.head(mergedData, ctx)
479
+ : view.module.head;
480
+ }
481
+
482
+ const layoutFn =
483
+ typeof layoutView.module.default === "function"
484
+ ? layoutView.module.default
485
+ : layoutView.module;
486
+
487
+ const safeBody = html.raw(bodyHtml);
488
+ const layoutOutput = await layoutFn({
489
+ body: safeBody,
490
+ content: safeBody,
491
+ children: safeBody,
492
+ head: headData,
493
+ ctx,
494
+ data: mergedData,
495
+ });
496
+
497
+ initialHtml = await resolveOutputToHtml(layoutOutput, ctx);
498
+ } else {
499
+ initialHtml = bodyHtml;
500
+ }
501
+ }
276
502
  } else {
277
503
  initialHtml = view.content || "";
278
504
  }
@@ -285,8 +511,8 @@ export class Render {
285
511
  try {
286
512
  const resolved = await token.promise;
287
513
  const finalContent = await token.renderer(resolved);
288
- const strContent = finalContent instanceof SafeHtml ? finalContent.toString() : String(finalContent);
289
- const script = `<template id="bb-defer-tpl-${token.prop}">${strContent}</template><script>(function(){var el=document.getElementById("bb-defer-${token.prop}");var tpl=document.getElementById("bb-defer-tpl-${token.prop}");if(el&&tpl){el.innerHTML="";el.appendChild(tpl.content);tpl.remove();}})();</script>`;
514
+ const strContent = await resolveOutputToHtml(finalContent);
515
+ const script = `<template id="bb-defer-tpl-${token.prop}">${strContent}</template><script>(function(){var el=document.getElementById("bb-defer-${token.prop}");var tpl=document.getElementById("bb-defer-tpl-${token.prop}");if(el&&tpl){el.innerHTML="";el.appendChild(tpl.content);tpl.remove();if(window.Bluebird&&window.Bluebird.hydrate){window.Bluebird.hydrate(el);}}})();</script>`;
290
516
  res.write(script);
291
517
  } catch (err) {
292
518
  res.write(`<script>console.error("Deferred stream error on ${token.prop}:", ${safeJson(err.message)});</script>`);
@@ -315,6 +541,57 @@ export class Render {
315
541
  ViewLoader.clearCache();
316
542
  await RenderCache.invalidate(keys);
317
543
  }
544
+
545
+ /**
546
+ * Automatically discovers views in `app/views/` (ignoring `layouts`, `components`, `partials`, `islands`, and `api`)
547
+ * and mounts them as GET routes with their exported `route`, `cache`, `middlewares`, `seo`, and `layout` settings.
548
+ *
549
+ * @param {import('./router.js').Router} [targetRouter] - Optional Router instance to register routes on.
550
+ * @returns {Promise<Array<{viewName: string, routePath: string, cache: number, seo: boolean}>>}
551
+ */
552
+ static async autoRoutes(targetRouter) {
553
+ const discovered = await ViewLoader.discoverRoutes();
554
+ if (!targetRouter) return discovered;
555
+
556
+ const [{ Seo }, { Actions }] = await Promise.all([
557
+ import("./seo.js"),
558
+ import("./actions.js"),
559
+ ]);
560
+
561
+ for (const item of discovered) {
562
+ const handlers = [...item.middlewares];
563
+ if (item.cache > 0) {
564
+ handlers.push(Render.cache(item.cache));
565
+ }
566
+ handlers.push(
567
+ Render.view(item.viewName, (req) => ({
568
+ user: req.user,
569
+ params: req.params,
570
+ query: req.query,
571
+ }))
572
+ );
573
+
574
+ if (item.seo) {
575
+ Seo.registerRoute(targetRouter.path || "/", item.routePath, targetRouter._languages || []);
576
+ }
577
+
578
+ const prevSeo = targetRouter._seo;
579
+ targetRouter._seo = false;
580
+ targetRouter.get(item.routePath, ...handlers);
581
+ targetRouter._seo = prevSeo;
582
+
583
+ if (item.actions) {
584
+ const postHandlers = [
585
+ ...item.middlewares,
586
+ Actions.createDispatcher(item.viewName, item.actions),
587
+ ];
588
+ targetRouter.post(item.routePath, ...postHandlers);
589
+ }
590
+ }
591
+
592
+ return discovered;
593
+ }
318
594
  }
319
595
 
596
+ export { h, Fragment, Island, Client };
320
597
  export default Render;
package/core/upload.js CHANGED
@@ -28,6 +28,7 @@ class Upload {
28
28
 
29
29
  /**
30
30
  * Configures storage for uploaded files.
31
+ * In desktop mode, redirects destination to writable userDataDir() to avoid EROFS inside .asar archives.
31
32
  * @param {string} folder - The destination folder within the static path.
32
33
  * @returns {import('multer').StorageEngine}
33
34
  * @example
@@ -35,7 +36,12 @@ class Upload {
35
36
  */
36
37
  static storage(folder = "uploads") {
37
38
  this._ensureMulter();
38
- const dest = path.join(__dirname, props.static.path, folder);
39
+ const isDesktop = Config.isDesktop();
40
+ const dest = isDesktop
41
+ ? (folder.startsWith("uploads")
42
+ ? path.join(Config.userDataDir(), folder)
43
+ : path.join(Config.userDataDir(), "uploads", folder))
44
+ : path.resolve(Config.appDir(), props.static?.path || "public", folder);
39
45
 
40
46
  if (!fs.existsSync(dest)) {
41
47
  fs.mkdirSync(dest, { recursive: true });
package/core/validate.js CHANGED
@@ -215,7 +215,7 @@ class Validator {
215
215
  messages.push(errorMsg);
216
216
  errors.push({ field, message: errorMsg });
217
217
  }
218
- if (config.number && !validators.isNumeric(value)) {
218
+ if ((config.number || config.numeric) && !validators.isNumeric(value)) {
219
219
  const errorMsg = config.messages?.number || msg.number(field);
220
220
  messages.push(errorMsg);
221
221
  errors.push({ field, message: errorMsg });