@seip/bluebird-js 0.1.6 → 0.1.7
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/.vscode/extensions.json +7 -7
- package/.vscode/settings.json +10 -10
- package/AGENTS.md +620 -576
- package/README.md +607 -602
- package/app/routes/web.js +47 -47
- package/app/views/components/Header.jsx +42 -42
- package/app/views/components/LiveCounter.jsx +22 -21
- package/app/views/layouts/main/view.jsx +201 -201
- package/app/views/{dashboard.jsx → pages/dashboard.jsx} +278 -300
- package/app/views/{index.jsx → pages/index.jsx} +123 -123
- package/app/views/{login.jsx → pages/login.jsx} +141 -141
- package/core/actions.d.ts +1 -1
- package/core/actions.js +355 -329
- package/core/ai.d.ts +151 -151
- package/core/ai.js +1051 -1051
- package/core/app.js +10 -10
- package/core/cli/backup.js +167 -167
- package/core/cli/init.js +10 -10
- package/core/cli/view.js +161 -161
- package/core/database.js +460 -460
- package/core/index.d.ts +1470 -1431
- package/core/jsx.d.ts +38 -38
- package/core/jsx.js +1597 -1432
- package/core/render.js +736 -728
- package/core/view-loader.js +613 -529
- package/package.json +1 -1
- package/public/js/bluebird-client.js +3264 -3160
- /package/app/views/{about.jsx → pages/about.jsx} +0 -0
package/core/app.js
CHANGED
|
@@ -9,7 +9,7 @@ import Logger from "./logger.js";
|
|
|
9
9
|
import Debug from "./debug.js";
|
|
10
10
|
import WebSocketManager from "./ws.js";
|
|
11
11
|
import RateLimit from "./ratelimit.js";
|
|
12
|
-
import Seo from "./seo.js";
|
|
12
|
+
import Seo from "./seo.js";
|
|
13
13
|
import AI, { ai } from "./ai.js";
|
|
14
14
|
|
|
15
15
|
const props = Config.props();
|
|
@@ -763,15 +763,15 @@ class App {
|
|
|
763
763
|
* @param {Object} [options={}] - Rate limit options (windowMs, max, message, driver, keyGenerator).
|
|
764
764
|
* @returns {Function} Express middleware.
|
|
765
765
|
*/
|
|
766
|
-
/**
|
|
767
|
-
* Returns a new or default unified AI instance.
|
|
768
|
-
* @param {Object} [options={}] - AI configuration options.
|
|
769
|
-
* @returns {AI}
|
|
770
|
-
*/
|
|
771
|
-
static ai(options = {}) {
|
|
772
|
-
return Object.keys(options).length > 0 ? new AI(options) : ai;
|
|
773
|
-
}
|
|
774
|
-
|
|
766
|
+
/**
|
|
767
|
+
* Returns a new or default unified AI instance.
|
|
768
|
+
* @param {Object} [options={}] - AI configuration options.
|
|
769
|
+
* @returns {AI}
|
|
770
|
+
*/
|
|
771
|
+
static ai(options = {}) {
|
|
772
|
+
return Object.keys(options).length > 0 ? new AI(options) : ai;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
775
|
static rateLimit(options = {}) {
|
|
776
776
|
return RateLimit.middleware(options);
|
|
777
777
|
}
|
package/core/cli/backup.js
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import readline from "node:readline/promises";
|
|
6
|
-
import colors from "../util/colors.js";
|
|
7
|
-
import { Database, DB_TYPE } from "../database.js";
|
|
8
|
-
import Config from "../config.js";
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
process.loadEnvFile?.();
|
|
12
|
-
} catch {}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Prompts user for yes/no confirmation via CLI.
|
|
16
|
-
* @param {string} question
|
|
17
|
-
* @param {boolean} [defaultYes=false]
|
|
18
|
-
* @returns {Promise<boolean>}
|
|
19
|
-
*/
|
|
20
|
-
async function promptConfirm(question, defaultYes = false) {
|
|
21
|
-
if (!process.stdin.isTTY) {
|
|
22
|
-
return defaultYes;
|
|
23
|
-
}
|
|
24
|
-
const rl = readline.createInterface({
|
|
25
|
-
input: process.stdin,
|
|
26
|
-
output: process.stdout,
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
const answer = await rl.question(colors.cyan(question));
|
|
30
|
-
const trimmed = answer.trim().toLowerCase();
|
|
31
|
-
if (!trimmed) return defaultYes;
|
|
32
|
-
return ["y", "yes", "s", "si", "true", "1"].includes(trimmed);
|
|
33
|
-
} finally {
|
|
34
|
-
rl.close();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Formats byte size into human-readable string.
|
|
40
|
-
* @param {number} bytes
|
|
41
|
-
* @returns {string}
|
|
42
|
-
*/
|
|
43
|
-
function formatSize(bytes) {
|
|
44
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
45
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
46
|
-
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Executes database backup CLI command.
|
|
51
|
-
*/
|
|
52
|
-
export async function runBackup() {
|
|
53
|
-
const args = process.argv.slice(2);
|
|
54
|
-
let keep = 10;
|
|
55
|
-
let outDir = null;
|
|
56
|
-
let compress = true;
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < args.length; i++) {
|
|
59
|
-
if (args[i] === "--keep" && args[i + 1]) {
|
|
60
|
-
keep = parseInt(args[i + 1], 10) || 10;
|
|
61
|
-
i++;
|
|
62
|
-
} else if (args[i].startsWith("--keep=")) {
|
|
63
|
-
keep = parseInt(args[i].split("=")[1], 10) || 10;
|
|
64
|
-
} else if (args[i] === "--out" && args[i + 1]) {
|
|
65
|
-
outDir = args[i + 1];
|
|
66
|
-
i++;
|
|
67
|
-
} else if (args[i].startsWith("--out=")) {
|
|
68
|
-
outDir = args[i].split("=")[1];
|
|
69
|
-
} else if (args[i] === "--no-compress") {
|
|
70
|
-
compress = false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
console.log(colors.cyan(`[INFO] Creating atomic database backup (${DB_TYPE})...`));
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const result = await Database.backup({
|
|
78
|
-
out: outDir,
|
|
79
|
-
keep,
|
|
80
|
-
compress,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
console.log(colors.green(`[OK] Database backup created successfully:`));
|
|
84
|
-
console.log(` ${colors.bold("File:")} ${result.file}`);
|
|
85
|
-
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
86
|
-
console.log(` ${colors.bold("Type:")} ${result.dbType}`);
|
|
87
|
-
if (result.rotated > 0) {
|
|
88
|
-
console.log(` ${colors.bold("Rotated:")} ${result.rotated} older backup(s) purged (retention: ${keep})`);
|
|
89
|
-
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.error(colors.red(`[ERROR] Database backup failed:`), err.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Executes database restore CLI command.
|
|
98
|
-
*/
|
|
99
|
-
export async function runRestore() {
|
|
100
|
-
const args = process.argv.slice(2);
|
|
101
|
-
let targetFile = null;
|
|
102
|
-
let isAutoYes = false;
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < args.length; i++) {
|
|
105
|
-
const arg = args[i];
|
|
106
|
-
if (arg === "--yes" || arg === "-y") {
|
|
107
|
-
isAutoYes = true;
|
|
108
|
-
} else if (arg !== "db:restore" && arg !== "restore" && !arg.startsWith("--")) {
|
|
109
|
-
targetFile = arg;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!targetFile) {
|
|
114
|
-
const backupsDir = path.resolve(Config.userDataDir(), "database/backups");
|
|
115
|
-
console.log(colors.yellow("[WARN] No backup file specified."));
|
|
116
|
-
if (fs.existsSync(backupsDir)) {
|
|
117
|
-
const files = fs.readdirSync(backupsDir).filter((f) => !f.startsWith("."));
|
|
118
|
-
if (files.length > 0) {
|
|
119
|
-
console.log(colors.cyan("\nAvailable backups in database/backups:"));
|
|
120
|
-
for (const f of files.slice(0, 10)) {
|
|
121
|
-
console.log(` - ${f}`);
|
|
122
|
-
}
|
|
123
|
-
console.log(colors.gray("\nUsage: npx bluebird-js db:restore <filename> [--yes]"));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!isAutoYes) {
|
|
130
|
-
const confirmed = await promptConfirm(
|
|
131
|
-
`⚠️ WARNING: Restoring will overwrite the active database.\nA safety snapshot of the current database will be saved automatically.\nAre you sure you want to proceed? (y/N): `,
|
|
132
|
-
false
|
|
133
|
-
);
|
|
134
|
-
if (!confirmed) {
|
|
135
|
-
console.log(colors.yellow("[CANCELLED] Database restore cancelled by user."));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
console.log(colors.cyan(`[INFO] Restoring database from '${targetFile}'...`));
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const result = await Database.restore(targetFile, {
|
|
144
|
-
safetyBackup: true,
|
|
145
|
-
verify: true,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
console.log(colors.green(`[OK] Database restored successfully:`));
|
|
149
|
-
console.log(` ${colors.bold("Source:")} ${result.restoredFrom}`);
|
|
150
|
-
console.log(` ${colors.bold("Target:")} ${result.targetFile}`);
|
|
151
|
-
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
152
|
-
if (result.preRestoreBackup) {
|
|
153
|
-
console.log(` ${colors.bold("Snapshot:")} ${result.preRestoreBackup} (pre-restore safety backup)`);
|
|
154
|
-
}
|
|
155
|
-
} catch (err) {
|
|
156
|
-
console.error(colors.red(`[ERROR] Database restore failed:`), err.message);
|
|
157
|
-
process.exit(1);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const action = process.argv[2];
|
|
162
|
-
if (action === "db:restore" || action === "restore") {
|
|
163
|
-
runRestore();
|
|
164
|
-
} else {
|
|
165
|
-
runBackup();
|
|
166
|
-
}
|
|
167
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import colors from "../util/colors.js";
|
|
7
|
+
import { Database, DB_TYPE } from "../database.js";
|
|
8
|
+
import Config from "../config.js";
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
process.loadEnvFile?.();
|
|
12
|
+
} catch {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prompts user for yes/no confirmation via CLI.
|
|
16
|
+
* @param {string} question
|
|
17
|
+
* @param {boolean} [defaultYes=false]
|
|
18
|
+
* @returns {Promise<boolean>}
|
|
19
|
+
*/
|
|
20
|
+
async function promptConfirm(question, defaultYes = false) {
|
|
21
|
+
if (!process.stdin.isTTY) {
|
|
22
|
+
return defaultYes;
|
|
23
|
+
}
|
|
24
|
+
const rl = readline.createInterface({
|
|
25
|
+
input: process.stdin,
|
|
26
|
+
output: process.stdout,
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const answer = await rl.question(colors.cyan(question));
|
|
30
|
+
const trimmed = answer.trim().toLowerCase();
|
|
31
|
+
if (!trimmed) return defaultYes;
|
|
32
|
+
return ["y", "yes", "s", "si", "true", "1"].includes(trimmed);
|
|
33
|
+
} finally {
|
|
34
|
+
rl.close();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Formats byte size into human-readable string.
|
|
40
|
+
* @param {number} bytes
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
function formatSize(bytes) {
|
|
44
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
45
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
46
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Executes database backup CLI command.
|
|
51
|
+
*/
|
|
52
|
+
export async function runBackup() {
|
|
53
|
+
const args = process.argv.slice(2);
|
|
54
|
+
let keep = 10;
|
|
55
|
+
let outDir = null;
|
|
56
|
+
let compress = true;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < args.length; i++) {
|
|
59
|
+
if (args[i] === "--keep" && args[i + 1]) {
|
|
60
|
+
keep = parseInt(args[i + 1], 10) || 10;
|
|
61
|
+
i++;
|
|
62
|
+
} else if (args[i].startsWith("--keep=")) {
|
|
63
|
+
keep = parseInt(args[i].split("=")[1], 10) || 10;
|
|
64
|
+
} else if (args[i] === "--out" && args[i + 1]) {
|
|
65
|
+
outDir = args[i + 1];
|
|
66
|
+
i++;
|
|
67
|
+
} else if (args[i].startsWith("--out=")) {
|
|
68
|
+
outDir = args[i].split("=")[1];
|
|
69
|
+
} else if (args[i] === "--no-compress") {
|
|
70
|
+
compress = false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(colors.cyan(`[INFO] Creating atomic database backup (${DB_TYPE})...`));
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const result = await Database.backup({
|
|
78
|
+
out: outDir,
|
|
79
|
+
keep,
|
|
80
|
+
compress,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log(colors.green(`[OK] Database backup created successfully:`));
|
|
84
|
+
console.log(` ${colors.bold("File:")} ${result.file}`);
|
|
85
|
+
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
86
|
+
console.log(` ${colors.bold("Type:")} ${result.dbType}`);
|
|
87
|
+
if (result.rotated > 0) {
|
|
88
|
+
console.log(` ${colors.bold("Rotated:")} ${result.rotated} older backup(s) purged (retention: ${keep})`);
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(colors.red(`[ERROR] Database backup failed:`), err.message);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Executes database restore CLI command.
|
|
98
|
+
*/
|
|
99
|
+
export async function runRestore() {
|
|
100
|
+
const args = process.argv.slice(2);
|
|
101
|
+
let targetFile = null;
|
|
102
|
+
let isAutoYes = false;
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < args.length; i++) {
|
|
105
|
+
const arg = args[i];
|
|
106
|
+
if (arg === "--yes" || arg === "-y") {
|
|
107
|
+
isAutoYes = true;
|
|
108
|
+
} else if (arg !== "db:restore" && arg !== "restore" && !arg.startsWith("--")) {
|
|
109
|
+
targetFile = arg;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!targetFile) {
|
|
114
|
+
const backupsDir = path.resolve(Config.userDataDir(), "database/backups");
|
|
115
|
+
console.log(colors.yellow("[WARN] No backup file specified."));
|
|
116
|
+
if (fs.existsSync(backupsDir)) {
|
|
117
|
+
const files = fs.readdirSync(backupsDir).filter((f) => !f.startsWith("."));
|
|
118
|
+
if (files.length > 0) {
|
|
119
|
+
console.log(colors.cyan("\nAvailable backups in database/backups:"));
|
|
120
|
+
for (const f of files.slice(0, 10)) {
|
|
121
|
+
console.log(` - ${f}`);
|
|
122
|
+
}
|
|
123
|
+
console.log(colors.gray("\nUsage: npx bluebird-js db:restore <filename> [--yes]"));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!isAutoYes) {
|
|
130
|
+
const confirmed = await promptConfirm(
|
|
131
|
+
`⚠️ WARNING: Restoring will overwrite the active database.\nA safety snapshot of the current database will be saved automatically.\nAre you sure you want to proceed? (y/N): `,
|
|
132
|
+
false
|
|
133
|
+
);
|
|
134
|
+
if (!confirmed) {
|
|
135
|
+
console.log(colors.yellow("[CANCELLED] Database restore cancelled by user."));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log(colors.cyan(`[INFO] Restoring database from '${targetFile}'...`));
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const result = await Database.restore(targetFile, {
|
|
144
|
+
safetyBackup: true,
|
|
145
|
+
verify: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(colors.green(`[OK] Database restored successfully:`));
|
|
149
|
+
console.log(` ${colors.bold("Source:")} ${result.restoredFrom}`);
|
|
150
|
+
console.log(` ${colors.bold("Target:")} ${result.targetFile}`);
|
|
151
|
+
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
152
|
+
if (result.preRestoreBackup) {
|
|
153
|
+
console.log(` ${colors.bold("Snapshot:")} ${result.preRestoreBackup} (pre-restore safety backup)`);
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error(colors.red(`[ERROR] Database restore failed:`), err.message);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const action = process.argv[2];
|
|
162
|
+
if (action === "db:restore" || action === "restore") {
|
|
163
|
+
runRestore();
|
|
164
|
+
} else {
|
|
165
|
+
runBackup();
|
|
166
|
+
}
|
|
167
|
+
|
package/core/cli/init.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
@@ -876,8 +876,8 @@ function showHelp() {
|
|
|
876
876
|
console.log(` ${colors.green("npx bluebird-js migrate:status")} Displays applied migration batches`);
|
|
877
877
|
console.log(` ${colors.green("npx bluebird-js migrate:rollback")} Reverts the latest migration batch`);
|
|
878
878
|
console.log(` ${colors.green("npx bluebird-js make:seed <name>")} Creates a new database seed file`);
|
|
879
|
-
console.log(` ${colors.green("npx bluebird-js seed")} Executes all seed files`);
|
|
880
|
-
console.log(` ${colors.green("npx bluebird-js db:backup [--keep 10] [--out dir]")} Creates compressed WAL-safe database backup`);
|
|
879
|
+
console.log(` ${colors.green("npx bluebird-js seed")} Executes all seed files`);
|
|
880
|
+
console.log(` ${colors.green("npx bluebird-js db:backup [--keep 10] [--out dir]")} Creates compressed WAL-safe database backup`);
|
|
881
881
|
console.log(` ${colors.green("npx bluebird-js db:restore <file> [--yes]")} Safely restores database with pre-backup & verification`);
|
|
882
882
|
console.log(` ${colors.green("npx bluebird-js nginx:conf [domain] [port] [root]")} Generates Host Nginx reverse proxy`);
|
|
883
883
|
console.log(` ${colors.green("npx bluebird-js make:ecosystem [--start]")} Generates PM2 cluster config`);
|
|
@@ -917,13 +917,13 @@ if (command === "make:ecosystem" || command === "ecosystem") {
|
|
|
917
917
|
command === "make:seed"
|
|
918
918
|
) {
|
|
919
919
|
import("./migrate.js");
|
|
920
|
-
} else if (
|
|
921
|
-
command === "db:backup" ||
|
|
922
|
-
command === "backup" ||
|
|
923
|
-
command === "db:restore" ||
|
|
924
|
-
command === "restore"
|
|
925
|
-
) {
|
|
926
|
-
import("./backup.js");
|
|
920
|
+
} else if (
|
|
921
|
+
command === "db:backup" ||
|
|
922
|
+
command === "backup" ||
|
|
923
|
+
command === "db:restore" ||
|
|
924
|
+
command === "restore"
|
|
925
|
+
) {
|
|
926
|
+
import("./backup.js");
|
|
927
927
|
} else if (command === "swagger-install") {
|
|
928
928
|
addCommand("swagger");
|
|
929
929
|
} else if (command === "add") {
|