@seip/bluebird-js 0.0.1 → 0.1.0

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 (81) hide show
  1. package/.env_example +53 -53
  2. package/AGENTS.md +426 -403
  3. package/LICENSE +1 -1
  4. package/README.md +292 -285
  5. package/app/routes/api.js +50 -50
  6. package/app/routes/web.js +55 -53
  7. package/app/views/about.js +63 -0
  8. package/app/views/dashboard.js +147 -0
  9. package/app/views/index.js +80 -0
  10. package/app/views/layouts/main/view.js +81 -0
  11. package/app/views/legal/terms.html +19 -0
  12. package/app/views/login.js +80 -0
  13. package/core/app.d.ts +18 -18
  14. package/core/app.js +684 -644
  15. package/core/auth.d.ts +13 -13
  16. package/core/auth.js +326 -326
  17. package/core/cache.d.ts +17 -17
  18. package/core/cache.js +475 -475
  19. package/core/cli/doctor.js +287 -287
  20. package/core/cli/ecosystem.js +162 -162
  21. package/core/cli/init.js +779 -779
  22. package/core/cli/migrate.js +541 -541
  23. package/core/cli/model.js +66 -66
  24. package/core/cli/nginx.js +199 -199
  25. package/core/cli/route.js +120 -120
  26. package/core/cli/view.js +55 -36
  27. package/core/config.d.ts +3 -3
  28. package/core/config.js +111 -111
  29. package/core/csrf.d.ts +3 -3
  30. package/core/csrf.js +114 -114
  31. package/core/database.d.ts +15 -15
  32. package/core/database.js +636 -636
  33. package/core/debug.d.ts +3 -3
  34. package/core/debug.js +249 -249
  35. package/core/hash.d.ts +3 -3
  36. package/core/hash.js +194 -194
  37. package/core/html.d.ts +42 -0
  38. package/core/html.js +217 -0
  39. package/core/index.d.ts +1176 -1071
  40. package/core/logger.d.ts +3 -3
  41. package/core/logger.js +127 -124
  42. package/core/middleware.d.ts +3 -3
  43. package/core/middleware.js +28 -28
  44. package/core/model.d.ts +19 -19
  45. package/core/model.js +600 -600
  46. package/core/queue.d.ts +13 -13
  47. package/core/queue.js +172 -172
  48. package/core/ratelimit.d.ts +3 -3
  49. package/core/ratelimit.js +145 -145
  50. package/core/redis.d.ts +21 -21
  51. package/core/redis.js +230 -230
  52. package/core/render-cache.js +212 -0
  53. package/core/render.d.ts +3 -3
  54. package/core/render.js +199 -555
  55. package/core/router.d.ts +3 -3
  56. package/core/router.js +171 -171
  57. package/core/seo.d.ts +3 -3
  58. package/core/seo.js +106 -106
  59. package/core/swagger.d.ts +3 -3
  60. package/core/swagger.js +60 -60
  61. package/core/upload.d.ts +13 -13
  62. package/core/upload.js +102 -102
  63. package/core/util/colors.js +82 -82
  64. package/core/validate.d.ts +15 -15
  65. package/core/validate.js +364 -364
  66. package/core/view-loader.js +162 -0
  67. package/core/vite.d.ts +3 -3
  68. package/core/vite.js +145 -145
  69. package/core/ws.d.ts +13 -13
  70. package/core/ws.js +245 -245
  71. package/index.js +18 -18
  72. package/jsconfig.json +15 -15
  73. package/package.json +85 -86
  74. package/production.md +273 -273
  75. package/public/css/bluebird.min.css +1 -1
  76. package/public/js/bluebird-client.js +1780 -1662
  77. package/public/js/bluebird.min.js +1072 -1072
  78. package/app/views/about.html +0 -161
  79. package/app/views/dashboard.html +0 -140
  80. package/app/views/index.html +0 -150
  81. package/app/views/login.html +0 -144
package/core/debug.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Debug } from "./index.js";
2
- export default Debug;
3
- export { Debug };
1
+ import { Debug } from "./index.js";
2
+ export default Debug;
3
+ export { Debug };
package/core/debug.js CHANGED
@@ -1,250 +1,250 @@
1
- import Router from "./router.js";
2
-
3
- /**
4
- * Advanced Debug module for Blue Bird.
5
- * Provides metrics history, route statistics and live monitoring.
6
- */
7
- class Debug {
8
-
9
- constructor() {
10
- this.router = new Router("/debug");
11
- this.limit = 50;
12
- this.initStore();
13
- this.registerRoutes();
14
- }
15
-
16
- initStore() {
17
- if (!global.__bluebird_debug_store__) {
18
- global.__bluebird_debug_store__ = {
19
- requests: [],
20
- routes: {},
21
- errors4xx: 0,
22
- errors5xx: 0
23
- };
24
- }
25
- }
26
-
27
- static shouldTrack(req) {
28
- const url = req.originalUrl || "";
29
-
30
- if (url.startsWith("/debug")) return false;
31
-
32
- if (/\.(json|css|js|map|png|jpg|jpeg|gif|svg|ico|webp)$/i.test(url)) {
33
- return false;
34
- }
35
-
36
- if (req.method === "OPTIONS") return false;
37
-
38
- return true;
39
- }
40
-
41
- static middlewareMetrics(app) {
42
- app.use((req, res, next) => {
43
-
44
- if (!Debug.shouldTrack(req)) return next();
45
-
46
- const start = process.hrtime();
47
-
48
- res.on("finish", () => {
49
-
50
- const diff = process.hrtime(start);
51
- const responseTime = diff[0] * 1e3 + diff[1] / 1e6;
52
-
53
- const memory = process.memoryUsage();
54
- const ramUsedMB = memory.rss / 1024 / 1024;
55
-
56
- const cpuUsage = process.cpuUsage();
57
- const cpuUsedMS = (cpuUsage.user + cpuUsage.system) / 1000;
58
-
59
- const record = {
60
- method: req.method,
61
- url: req.originalUrl,
62
- status: res.statusCode,
63
- responseTime: Number(responseTime.toFixed(2)),
64
- ramUsedMB: Number(ramUsedMB.toFixed(2)),
65
- cpuUsedMS: Number(cpuUsedMS.toFixed(2)),
66
- date: new Date().toISOString()
67
- };
68
-
69
- const store = global.__bluebird_debug_store__;
70
-
71
- store.requests.unshift(record);
72
- if (store.requests.length > 50) store.requests.pop();
73
-
74
- const routeKey = `${req.method} ${req.route?.path || req.path}`;
75
-
76
- if (!store.routes[routeKey]) {
77
- store.routes[routeKey] = {
78
- count: 0,
79
- totalTime: 0
80
- };
81
- }
82
-
83
- store.routes[routeKey].count += 1;
84
- store.routes[routeKey].totalTime += record.responseTime;
85
-
86
- if (record.status >= 400 && record.status < 500) store.errors4xx++;
87
- if (record.status >= 500) store.errors5xx++;
88
- });
89
-
90
- next();
91
- });
92
- }
93
-
94
- registerRoutes() {
95
-
96
- this.router.get("/", (req, res) => {
97
-
98
- const store = global.__bluebird_debug_store__;
99
-
100
- if (req.query.fetch === "true") {
101
- return res.json(store);
102
- }
103
-
104
- if (req.query.reset === "true") {
105
- global.__bluebird_debug_store__ = {
106
- requests: [],
107
- routes: {},
108
- errors4xx: 0,
109
- errors5xx: 0
110
- };
111
- return res.json({ ok: true });
112
- }
113
-
114
- res.send(`
115
- <!DOCTYPE html>
116
- <html>
117
- <head>
118
- <script src="https://cdn.tailwindcss.com"></script>
119
- <title>Blue Bird Debug</title>
120
- </head>
121
- <body class="bg-gray-100 text-gray-800 p-10">
122
-
123
- <div class="max-w-7xl mx-auto">
124
-
125
- <div class="flex justify-between items-center mb-8">
126
- <h1 class="text-3xl font-bold text-blue-600">Blue Bird Debug Panel</h1>
127
- <button onclick="resetData()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg shadow">
128
- Reset
129
- </button>
130
- </div>
131
-
132
- <div class="grid grid-cols-3 gap-6 mb-8">
133
-
134
- <div class="bg-white p-6 rounded-xl shadow">
135
- <h3 class="text-gray-500 text-sm">Total Requests</h3>
136
- <p id="totalReq" class="text-2xl font-bold">0</p>
137
- </div>
138
-
139
- <div class="bg-yellow-100 p-6 rounded-xl shadow">
140
- <h3 class="text-yellow-600 text-sm">4xx Errors</h3>
141
- <p id="err4" class="text-2xl font-bold text-yellow-700">0</p>
142
- </div>
143
-
144
- <div class="bg-red-100 p-6 rounded-xl shadow">
145
- <h3 class="text-red-600 text-sm">5xx Errors</h3>
146
- <p id="err5" class="text-2xl font-bold text-red-700">0</p>
147
- </div>
148
-
149
- </div>
150
-
151
- <div class="grid grid-cols-2 gap-10">
152
-
153
- <div class="bg-white p-6 rounded-xl shadow">
154
- <h2 class="text-lg font-semibold mb-4">Route Stats</h2>
155
- <table class="table-fixed w-full text-sm">
156
- <thead>
157
- <tr class="border-b">
158
- <th class="text-left w-1/2 py-2">Route</th>
159
- <th class="text-left w-1/4">Hits</th>
160
- <th class="text-left w-1/4">Avg Time</th>
161
- </tr>
162
- </thead>
163
- <tbody id="routesBody"></tbody>
164
- </table>
165
- </div>
166
-
167
- <div class="bg-white p-6 rounded-xl shadow">
168
- <h2 class="text-lg font-semibold mb-4">Last Requests</h2>
169
- <table class="table-fixed w-full text-sm">
170
- <thead>
171
- <tr class="border-b">
172
- <th class="text-left w-1/2 py-2">URL</th>
173
- <th class="text-left w-1/6">Method</th>
174
- <th class="text-left w-1/6">Status</th>
175
- <th class="text-left w-1/6">Time</th>
176
- </tr>
177
- </thead>
178
- <tbody id="historyBody"></tbody>
179
- </table>
180
- </div>
181
-
182
- </div>
183
-
184
- </div>
185
-
186
- <script>
187
- async function loadData() {
188
- const res = await fetch('/debug?fetch=true');
189
- const data = await res.json();
190
-
191
- document.getElementById("totalReq").innerText = data.requests.length;
192
- document.getElementById("err4").innerText = data.errors4xx;
193
- document.getElementById("err5").innerText = data.errors5xx;
194
-
195
- const routesBody = document.getElementById("routesBody");
196
- const historyBody = document.getElementById("historyBody");
197
-
198
- routesBody.innerHTML = "";
199
- historyBody.innerHTML = "";
200
-
201
- Object.entries(data.routes).forEach(([key, value]) => {
202
- const avg = (value.totalTime / value.count).toFixed(2);
203
- let color = "";
204
- if (avg > 500) color = "text-red-600 font-semibold";
205
- else if (avg > 200) color = "text-yellow-600";
206
-
207
- routesBody.innerHTML += \`
208
- <tr class="border-b">
209
- <td class="py-1 truncate">\${key}</td>
210
- <td>\${value.count}</td>
211
- <td class="\${color}">\${avg} ms</td>
212
- </tr>\`;
213
- });
214
-
215
- data.requests.forEach(r => {
216
- historyBody.innerHTML += \`
217
- <tr class="border-b text-xs">
218
- <td class="truncate">\${r.url}</td>
219
- <td>\${r.method}</td>
220
- <td>\${r.status}</td>
221
- <td>\${r.responseTime} ms</td>
222
- </tr>\`;
223
- });
224
- }
225
-
226
- async function resetData() {
227
- await fetch('/debug?reset=true');
228
- loadData();
229
- }
230
-
231
- loadData();
232
- setInterval(loadData, 3000);
233
- </script>
234
-
235
- </body>
236
- </html>
237
- `);
238
- });
239
- }
240
-
241
- getRouter() {
242
- return {
243
- path: this.router.getPath(),
244
- router: this.router.getRouter()
245
- };
246
- }
247
- }
248
-
249
- export { Debug };
1
+ import Router from "./router.js";
2
+
3
+ /**
4
+ * Advanced Debug module for Blue Bird.
5
+ * Provides metrics history, route statistics and live monitoring.
6
+ */
7
+ class Debug {
8
+
9
+ constructor() {
10
+ this.router = new Router("/debug");
11
+ this.limit = 50;
12
+ this.initStore();
13
+ this.registerRoutes();
14
+ }
15
+
16
+ initStore() {
17
+ if (!global.__bluebird_debug_store__) {
18
+ global.__bluebird_debug_store__ = {
19
+ requests: [],
20
+ routes: {},
21
+ errors4xx: 0,
22
+ errors5xx: 0
23
+ };
24
+ }
25
+ }
26
+
27
+ static shouldTrack(req) {
28
+ const url = req.originalUrl || "";
29
+
30
+ if (url.startsWith("/debug")) return false;
31
+
32
+ if (/\.(json|css|js|map|png|jpg|jpeg|gif|svg|ico|webp)$/i.test(url)) {
33
+ return false;
34
+ }
35
+
36
+ if (req.method === "OPTIONS") return false;
37
+
38
+ return true;
39
+ }
40
+
41
+ static middlewareMetrics(app) {
42
+ app.use((req, res, next) => {
43
+
44
+ if (!Debug.shouldTrack(req)) return next();
45
+
46
+ const start = process.hrtime();
47
+
48
+ res.on("finish", () => {
49
+
50
+ const diff = process.hrtime(start);
51
+ const responseTime = diff[0] * 1e3 + diff[1] / 1e6;
52
+
53
+ const memory = process.memoryUsage();
54
+ const ramUsedMB = memory.rss / 1024 / 1024;
55
+
56
+ const cpuUsage = process.cpuUsage();
57
+ const cpuUsedMS = (cpuUsage.user + cpuUsage.system) / 1000;
58
+
59
+ const record = {
60
+ method: req.method,
61
+ url: req.originalUrl,
62
+ status: res.statusCode,
63
+ responseTime: Number(responseTime.toFixed(2)),
64
+ ramUsedMB: Number(ramUsedMB.toFixed(2)),
65
+ cpuUsedMS: Number(cpuUsedMS.toFixed(2)),
66
+ date: new Date().toISOString()
67
+ };
68
+
69
+ const store = global.__bluebird_debug_store__;
70
+
71
+ store.requests.unshift(record);
72
+ if (store.requests.length > 50) store.requests.pop();
73
+
74
+ const routeKey = `${req.method} ${req.route?.path || req.path}`;
75
+
76
+ if (!store.routes[routeKey]) {
77
+ store.routes[routeKey] = {
78
+ count: 0,
79
+ totalTime: 0
80
+ };
81
+ }
82
+
83
+ store.routes[routeKey].count += 1;
84
+ store.routes[routeKey].totalTime += record.responseTime;
85
+
86
+ if (record.status >= 400 && record.status < 500) store.errors4xx++;
87
+ if (record.status >= 500) store.errors5xx++;
88
+ });
89
+
90
+ next();
91
+ });
92
+ }
93
+
94
+ registerRoutes() {
95
+
96
+ this.router.get("/", (req, res) => {
97
+
98
+ const store = global.__bluebird_debug_store__;
99
+
100
+ if (req.query.fetch === "true") {
101
+ return res.json(store);
102
+ }
103
+
104
+ if (req.query.reset === "true") {
105
+ global.__bluebird_debug_store__ = {
106
+ requests: [],
107
+ routes: {},
108
+ errors4xx: 0,
109
+ errors5xx: 0
110
+ };
111
+ return res.json({ ok: true });
112
+ }
113
+
114
+ res.send(`
115
+ <!DOCTYPE html>
116
+ <html>
117
+ <head>
118
+ <script src="https://cdn.tailwindcss.com"></script>
119
+ <title>Blue Bird Debug</title>
120
+ </head>
121
+ <body class="bg-gray-100 text-gray-800 p-10">
122
+
123
+ <div class="max-w-7xl mx-auto">
124
+
125
+ <div class="flex justify-between items-center mb-8">
126
+ <h1 class="text-3xl font-bold text-blue-600">Blue Bird Debug Panel</h1>
127
+ <button onclick="resetData()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg shadow">
128
+ Reset
129
+ </button>
130
+ </div>
131
+
132
+ <div class="grid grid-cols-3 gap-6 mb-8">
133
+
134
+ <div class="bg-white p-6 rounded-xl shadow">
135
+ <h3 class="text-gray-500 text-sm">Total Requests</h3>
136
+ <p id="totalReq" class="text-2xl font-bold">0</p>
137
+ </div>
138
+
139
+ <div class="bg-yellow-100 p-6 rounded-xl shadow">
140
+ <h3 class="text-yellow-600 text-sm">4xx Errors</h3>
141
+ <p id="err4" class="text-2xl font-bold text-yellow-700">0</p>
142
+ </div>
143
+
144
+ <div class="bg-red-100 p-6 rounded-xl shadow">
145
+ <h3 class="text-red-600 text-sm">5xx Errors</h3>
146
+ <p id="err5" class="text-2xl font-bold text-red-700">0</p>
147
+ </div>
148
+
149
+ </div>
150
+
151
+ <div class="grid grid-cols-2 gap-10">
152
+
153
+ <div class="bg-white p-6 rounded-xl shadow">
154
+ <h2 class="text-lg font-semibold mb-4">Route Stats</h2>
155
+ <table class="table-fixed w-full text-sm">
156
+ <thead>
157
+ <tr class="border-b">
158
+ <th class="text-left w-1/2 py-2">Route</th>
159
+ <th class="text-left w-1/4">Hits</th>
160
+ <th class="text-left w-1/4">Avg Time</th>
161
+ </tr>
162
+ </thead>
163
+ <tbody id="routesBody"></tbody>
164
+ </table>
165
+ </div>
166
+
167
+ <div class="bg-white p-6 rounded-xl shadow">
168
+ <h2 class="text-lg font-semibold mb-4">Last Requests</h2>
169
+ <table class="table-fixed w-full text-sm">
170
+ <thead>
171
+ <tr class="border-b">
172
+ <th class="text-left w-1/2 py-2">URL</th>
173
+ <th class="text-left w-1/6">Method</th>
174
+ <th class="text-left w-1/6">Status</th>
175
+ <th class="text-left w-1/6">Time</th>
176
+ </tr>
177
+ </thead>
178
+ <tbody id="historyBody"></tbody>
179
+ </table>
180
+ </div>
181
+
182
+ </div>
183
+
184
+ </div>
185
+
186
+ <script>
187
+ async function loadData() {
188
+ const res = await fetch('/debug?fetch=true');
189
+ const data = await res.json();
190
+
191
+ document.getElementById("totalReq").innerText = data.requests.length;
192
+ document.getElementById("err4").innerText = data.errors4xx;
193
+ document.getElementById("err5").innerText = data.errors5xx;
194
+
195
+ const routesBody = document.getElementById("routesBody");
196
+ const historyBody = document.getElementById("historyBody");
197
+
198
+ routesBody.innerHTML = "";
199
+ historyBody.innerHTML = "";
200
+
201
+ Object.entries(data.routes).forEach(([key, value]) => {
202
+ const avg = (value.totalTime / value.count).toFixed(2);
203
+ let color = "";
204
+ if (avg > 500) color = "text-red-600 font-semibold";
205
+ else if (avg > 200) color = "text-yellow-600";
206
+
207
+ routesBody.innerHTML += \`
208
+ <tr class="border-b">
209
+ <td class="py-1 truncate">\${key}</td>
210
+ <td>\${value.count}</td>
211
+ <td class="\${color}">\${avg} ms</td>
212
+ </tr>\`;
213
+ });
214
+
215
+ data.requests.forEach(r => {
216
+ historyBody.innerHTML += \`
217
+ <tr class="border-b text-xs">
218
+ <td class="truncate">\${r.url}</td>
219
+ <td>\${r.method}</td>
220
+ <td>\${r.status}</td>
221
+ <td>\${r.responseTime} ms</td>
222
+ </tr>\`;
223
+ });
224
+ }
225
+
226
+ async function resetData() {
227
+ await fetch('/debug?reset=true');
228
+ loadData();
229
+ }
230
+
231
+ loadData();
232
+ setInterval(loadData, 3000);
233
+ </script>
234
+
235
+ </body>
236
+ </html>
237
+ `);
238
+ });
239
+ }
240
+
241
+ getRouter() {
242
+ return {
243
+ path: this.router.getPath(),
244
+ router: this.router.getRouter()
245
+ };
246
+ }
247
+ }
248
+
249
+ export { Debug };
250
250
  export default Debug;
package/core/hash.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Hash, HashMakeOptions } from "./index.js";
2
- export default Hash;
3
- export { Hash, HashMakeOptions };
1
+ import { Hash, HashMakeOptions } from "./index.js";
2
+ export default Hash;
3
+ export { Hash, HashMakeOptions };