@seip/bluebird-js 0.1.2 → 0.1.5

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 (43) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/settings.json +10 -0
  3. package/AGENTS.md +495 -454
  4. package/README.md +528 -353
  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 +66 -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 +38 -6
  17. package/core/cli/doctor.js +3 -4
  18. package/core/cli/init.js +20 -6
  19. package/core/cli/migrate.js +418 -145
  20. package/core/cli/view.js +76 -11
  21. package/core/database.js +6 -10
  22. package/core/debug.js +1 -1
  23. package/core/html.d.ts +54 -42
  24. package/core/html.js +473 -217
  25. package/core/index.d.ts +1385 -1190
  26. package/core/jsx.d.ts +38 -0
  27. package/core/jsx.js +1432 -0
  28. package/core/model.js +271 -61
  29. package/core/render-cache.js +212 -212
  30. package/core/render.d.ts +20 -2
  31. package/core/render.js +459 -51
  32. package/core/validate.js +1 -1
  33. package/core/view-loader.js +360 -24
  34. package/package.json +9 -3
  35. package/public/js/bluebird-client.js +3160 -1780
  36. package/public/js/tailwind.js +8 -0
  37. package/app/views/about.js +0 -63
  38. package/app/views/dashboard.js +0 -147
  39. package/app/views/index.js +0 -80
  40. package/app/views/layouts/main/view.js +0 -81
  41. package/app/views/login.js +0 -80
  42. package/public/css/bluebird.min.css +0 -2
  43. package/public/js/bluebird.min.js +0 -1073
package/core/cli/view.js CHANGED
@@ -12,10 +12,12 @@ const args = rawArgs.filter(
12
12
  );
13
13
  const viewName = args.find((a) => !a.startsWith("-"));
14
14
  const isHtml = rawArgs.some((a) => a === "--html");
15
+ const isJs = rawArgs.some((a) => a === "--js");
16
+ const isJsx = !isHtml && !isJs;
15
17
 
16
18
  if (!viewName) {
17
19
  console.log(colors.red("[ERROR] Missing view name."));
18
- console.log("Usage: npx bluebird-js make:view <name> [--html]");
20
+ console.log("Usage: npx bluebird-js make:view <name> [--jsx | --js | --html]");
19
21
  process.exit(1);
20
22
  }
21
23
 
@@ -34,14 +36,24 @@ if (isHtml) {
34
36
  }
35
37
 
36
38
  const rawHtml = `<!DOCTYPE html>
37
- <html lang="en" data-theme="dark">
39
+ <html lang="en" class="dark" data-theme="dark">
38
40
  <head>
39
41
  <meta charset="UTF-8" />
42
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
40
43
  <title>${titleCase}</title>
41
- <link rel="stylesheet" href="/css/bluebird.min.css" />
44
+ <link rel="preconnect" href="https://fonts.googleapis.com">
45
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
46
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
47
+ <script src="/js/tailwind.js"></script>
48
+ <style type="text/tailwindcss">
49
+ @custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *));
50
+ @theme {
51
+ --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
52
+ }
53
+ </style>
42
54
  </head>
43
- <body>
44
- <h1>${titleCase}</h1>
55
+ <body class="min-h-screen bg-slate-950 text-slate-100 font-sans p-8 max-w-4xl mx-auto">
56
+ <h1 class="text-3xl font-extrabold text-sky-400 mb-4">${titleCase}</h1>
45
57
  </body>
46
58
  </html>
47
59
  `;
@@ -52,6 +64,59 @@ if (isHtml) {
52
64
  process.exit(0);
53
65
  }
54
66
 
67
+ if (isJsx) {
68
+ const filePath = path.join(VIEWS_DIR, `${cleanName}.jsx`);
69
+ if (fs.existsSync(filePath)) {
70
+ console.log(colors.yellow(`[WARN] View '${cleanName}.jsx' already exists at app/views/${cleanName}.jsx`));
71
+ process.exit(0);
72
+ }
73
+
74
+ const jsxTemplate = `import { Client } from "@seip/bluebird-js/core/jsx.js";
75
+
76
+ export const layout = "main";
77
+
78
+ export const head = () => ({
79
+ title: "${titleCase} — Blue Bird",
80
+ description: "${titleCase} view rendered with Bluebird React SSR",
81
+ });
82
+
83
+ /**
84
+ * ${titleCase} React SSR view module.
85
+ * @param {Object} props
86
+ */
87
+ export default async function ${titleCase}View(props = {}) {
88
+ return (
89
+ <>
90
+ <section className="py-10 md:py-14 border-b border-slate-800/80">
91
+ <h1 className="text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 to-indigo-400 bg-clip-text text-transparent">
92
+ ${titleCase}
93
+ </h1>
94
+ <p className="mt-4 text-base md:text-lg text-slate-300">
95
+ Welcome to your new Bluebird React SSR view.
96
+ </p>
97
+ </section>
98
+
99
+ <div className="mt-8">
100
+ <article className="rounded-2xl border border-slate-800 bg-slate-900/60 p-6">
101
+ <p className="text-slate-300">
102
+ Rendered on the server with zero-build JSX and instant partial navigation.
103
+ </p>
104
+ </article>
105
+ </div>
106
+ </>
107
+ );
108
+ }
109
+ `;
110
+
111
+ fs.writeFileSync(filePath, jsxTemplate, "utf-8");
112
+ console.log(colors.green(`[OK] React JSX view created at app/views/${cleanName}.jsx`));
113
+ console.log("");
114
+ console.log(colors.cyan("To render this view in a route:"));
115
+ console.log(colors.gray(` import Render from "@seip/bluebird-js/core/render.js";`));
116
+ console.log(colors.gray(` routerWeb.get("/${cleanName}", Render.view("${cleanName}"));`));
117
+ process.exit(0);
118
+ }
119
+
55
120
  const filePath = path.join(VIEWS_DIR, `${cleanName}.js`);
56
121
  if (fs.existsSync(filePath)) {
57
122
  console.log(colors.yellow(`[WARN] View '${cleanName}.js' already exists at app/views/${cleanName}.js`));
@@ -74,14 +139,14 @@ export const head = () => ({
74
139
  */
75
140
  export default function ${titleCase}View(props = {}) {
76
141
  return html\`
77
- <section class="hero">
78
- <h1 class="text-gradient font-bold">${titleCase}</h1>
79
- <p class="lead">Welcome to your new Bluebird view.</p>
142
+ <section class="py-10 md:py-14 border-b border-slate-800/80">
143
+ <h1 class="text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 to-indigo-400 bg-clip-text text-transparent">${titleCase}</h1>
144
+ <p class="mt-4 text-base md:text-lg text-slate-300">Welcome to your new Bluebird view.</p>
80
145
  </section>
81
146
 
82
- <div class="mt-6">
83
- <article class="card">
84
- <p>Rendered with pure JavaScript ESM and zero build tools.</p>
147
+ <div class="mt-8">
148
+ <article class="rounded-2xl border border-slate-800 bg-slate-900/60 p-6">
149
+ <p class="text-slate-300">Rendered with pure JavaScript ESM and zero build tools.</p>
85
150
  </article>
86
151
  </div>
87
152
  \`;
package/core/database.js CHANGED
@@ -423,13 +423,11 @@ class Database {
423
423
 
424
424
  if (isSelect || hasReturning) {
425
425
  const rows = res.rows || [];
426
+ const result = queryOptions.return_row ? (rows.length > 0 ? rows[0] : null) : rows;
426
427
  if (cacheKey && cacheTtl > 0) {
427
- await Cache.set(cacheKey, rows, cacheTtl);
428
- }
429
- if (queryOptions.return_row) {
430
- return rows.length > 0 ? rows[0] : null;
428
+ await Cache.set(cacheKey, result, cacheTtl);
431
429
  }
432
- return rows;
430
+ return result;
433
431
  }
434
432
 
435
433
  if (isInsert) {
@@ -445,13 +443,11 @@ class Database {
445
443
 
446
444
  if (isSelect || hasReturning) {
447
445
  const rows = Array.isArray(results) ? results : [];
446
+ const result = queryOptions.return_row ? (rows.length > 0 ? rows[0] : null) : rows;
448
447
  if (cacheKey && cacheTtl > 0) {
449
- await Cache.set(cacheKey, rows, cacheTtl);
450
- }
451
- if (queryOptions.return_row) {
452
- return rows.length > 0 ? rows[0] : null;
448
+ await Cache.set(cacheKey, result, cacheTtl);
453
449
  }
454
- return rows;
450
+ return result;
455
451
  }
456
452
 
457
453
  if (isInsert) {
package/core/debug.js CHANGED
@@ -115,7 +115,7 @@ class Debug {
115
115
  <!DOCTYPE html>
116
116
  <html>
117
117
  <head>
118
- <script src="https://cdn.tailwindcss.com"></script>
118
+ <script src="/js/tailwind.js"></script>
119
119
  <title>Blue Bird Debug</title>
120
120
  </head>
121
121
  <body class="bg-gray-100 text-gray-800 p-10">
package/core/html.d.ts CHANGED
@@ -1,42 +1,54 @@
1
- export class SafeHtml {
2
- value: string;
3
- constructor(value: string);
4
- toString(): string;
5
- }
6
-
7
- export function isSafeHtml(val: any): val is SafeHtml;
8
-
9
- export function escapeHtml(value: any): string;
10
-
11
- export function safeJson(data: any): string;
12
-
13
- export interface HtmlTag {
14
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
15
- raw(str: string): SafeHtml;
16
- json(obj: any): SafeHtml;
17
- script: typeof script;
18
- }
19
-
20
- export const html: HtmlTag;
21
-
22
- export interface ScriptTag {
23
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
24
- (src: string): SafeHtml;
25
- (options: { src: string; defer?: boolean; module?: boolean }): SafeHtml;
26
- }
27
-
28
- export const script: ScriptTag;
29
-
30
- export function cached(
31
- key: string,
32
- options: number | { ttl?: number; vary?: string[] },
33
- renderFn: () => SafeHtml | string | Promise<SafeHtml | string>
34
- ): Promise<SafeHtml>;
35
-
36
- export function defer<T>(
37
- promise: Promise<T>,
38
- fallback: SafeHtml | string,
39
- renderer: (data: T) => SafeHtml | string | Promise<SafeHtml | string>
40
- ): { __bluebird_deferred__: true; promise: Promise<T>; fallback: string; renderer: Function };
41
-
42
- export default html;
1
+ export class SafeHtml {
2
+ value: string;
3
+ constructor(value: string);
4
+ toString(): string;
5
+ }
6
+
7
+ export function isSafeHtml(val: any): val is SafeHtml;
8
+
9
+ export function escapeHtml(value: any): string;
10
+
11
+ export function safeJson(data: any): string;
12
+
13
+ export function each<T>(
14
+ items: T[] | null | undefined,
15
+ renderFn: (item: T, index: number) => SafeHtml | string,
16
+ emptyFallback?: (() => SafeHtml | string) | SafeHtml | string
17
+ ): SafeHtml;
18
+
19
+ export interface HtmlTag {
20
+ (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
21
+ raw(str: string): SafeHtml;
22
+ json(obj: any): SafeHtml;
23
+ script: typeof script;
24
+ each: typeof each;
25
+ map: typeof each;
26
+ code(text: string, className?: string): SafeHtml;
27
+ register(map: Record<string, Function>): void;
28
+ getComponent(name: string): Function | undefined;
29
+ }
30
+
31
+ export const html: HtmlTag;
32
+
33
+ export interface ScriptTag {
34
+ (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
35
+ (src: string): SafeHtml;
36
+ (options: { src: string; defer?: boolean; module?: boolean }): SafeHtml;
37
+ (fn: Function, data?: any, options?: { onLoad?: boolean }): SafeHtml;
38
+ }
39
+
40
+ export const script: ScriptTag;
41
+
42
+ export function cached(
43
+ key: string,
44
+ options: number | { ttl?: number; vary?: string[] },
45
+ renderFn: () => SafeHtml | string | Promise<SafeHtml | string>
46
+ ): Promise<SafeHtml>;
47
+
48
+ export function defer<T>(
49
+ promise: Promise<T>,
50
+ fallback: SafeHtml | string,
51
+ renderer: (data: T) => SafeHtml | string | Promise<SafeHtml | string>
52
+ ): { __bluebird_deferred__: true; promise: Promise<T>; fallback: string; renderer: Function };
53
+
54
+ export default html;