@scriptdb/server 1.0.7 → 1.0.9
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/README.md +87 -6
- package/dist/index.js +33 -9
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -394,13 +394,94 @@ npm run typecheck
|
|
|
394
394
|
npm run lint
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
##
|
|
397
|
+
## CLI Tool
|
|
398
398
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
399
|
+
ScriptDB provides a CLI tool for easy server management:
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
# Install CLI globally
|
|
403
|
+
npm install -g @scriptdb/cli
|
|
404
|
+
|
|
405
|
+
# Start server in foreground
|
|
406
|
+
scriptdb start
|
|
407
|
+
|
|
408
|
+
# Start server in background (daemon mode with PM2)
|
|
409
|
+
scriptdb start -d
|
|
410
|
+
|
|
411
|
+
# Check server status
|
|
412
|
+
scriptdb status
|
|
413
|
+
|
|
414
|
+
# View real-time logs
|
|
415
|
+
scriptdb logs
|
|
416
|
+
|
|
417
|
+
# Monitor performance
|
|
418
|
+
scriptdb monit
|
|
419
|
+
|
|
420
|
+
# Stop server
|
|
421
|
+
scriptdb stop
|
|
422
|
+
|
|
423
|
+
# Restart server
|
|
424
|
+
scriptdb restart -d
|
|
425
|
+
|
|
426
|
+
# Start interactive shell
|
|
427
|
+
scriptdb shell
|
|
428
|
+
|
|
429
|
+
# Install packages to ScriptDB
|
|
430
|
+
scriptdb add lodash
|
|
431
|
+
|
|
432
|
+
# Install packages locally
|
|
433
|
+
scriptdb add --local lodash
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### CLI Configuration
|
|
437
|
+
|
|
438
|
+
The CLI reads configuration from `~/.scriptdb/config.json`:
|
|
439
|
+
|
|
440
|
+
```json
|
|
441
|
+
{
|
|
442
|
+
"host": "localhost",
|
|
443
|
+
"port": 1234,
|
|
444
|
+
"users": [
|
|
445
|
+
{
|
|
446
|
+
"username": "admin",
|
|
447
|
+
"password": "your-password",
|
|
448
|
+
"hash": false
|
|
449
|
+
}
|
|
450
|
+
],
|
|
451
|
+
"folder": "databases",
|
|
452
|
+
"secure": false
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
### Process Management
|
|
457
|
+
|
|
458
|
+
The CLI uses PM2 for daemon mode, providing:
|
|
459
|
+
|
|
460
|
+
- Automatic restart on failure
|
|
461
|
+
- Log management
|
|
462
|
+
- Performance monitoring
|
|
463
|
+
- Cluster mode support
|
|
464
|
+
|
|
465
|
+
PM2 files are stored in `~/.scriptdb/`:
|
|
466
|
+
- `ecosystem.config.js` - PM2 configuration
|
|
467
|
+
- `pm2-*.log` - Log files
|
|
468
|
+
|
|
469
|
+
## Changelog
|
|
470
|
+
|
|
471
|
+
### 1.0.9 (2025-01-16)
|
|
472
|
+
|
|
473
|
+
**Added**
|
|
474
|
+
- Native `scriptdb logs` command to view real-time logs
|
|
475
|
+
- Native `scriptdb monit` command to monitor performance
|
|
476
|
+
- Native `scriptdb restart` command to restart the server
|
|
477
|
+
- Native `scriptdb stop` command to stop the server
|
|
478
|
+
- ESLint configuration for TypeScript linting
|
|
479
|
+
|
|
480
|
+
**Fixed**
|
|
481
|
+
- Fixed TypeScript type mismatch in users config normalization
|
|
482
|
+
- Fixed TypeScript "used before assigned" error for storage variable
|
|
483
|
+
- Fixed TypeScript module resolution errors
|
|
484
|
+
- Improved error handling and Windows compatibility
|
|
404
485
|
|
|
405
486
|
## License
|
|
406
487
|
|
package/dist/index.js
CHANGED
|
@@ -4313,9 +4313,8 @@ export const ${databaseName} = {};
|
|
|
4313
4313
|
if (this.users && Array.isArray(this.users) && this.users.length > 0) {
|
|
4314
4314
|
const u = this.users[0] || { username: "" };
|
|
4315
4315
|
const uname = u.username || null;
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
cred = encodeURIComponent(String(uname)) + ":" + encodeURIComponent(String(pwd)) + "@";
|
|
4316
|
+
if (uname && typeof u.password === "string" && u.password) {
|
|
4317
|
+
cred = encodeURIComponent(String(uname)) + ":" + "*****" + "@";
|
|
4319
4318
|
} else if (uname) {
|
|
4320
4319
|
cred = encodeURIComponent(String(uname)) + "@";
|
|
4321
4320
|
}
|
|
@@ -4356,7 +4355,7 @@ import { spawn } from "node:child_process";
|
|
|
4356
4355
|
import Storage from "@scriptdb/storage";
|
|
4357
4356
|
var pkgData = `{
|
|
4358
4357
|
"name": "scriptdb-workspace",
|
|
4359
|
-
"version": "1.0.
|
|
4358
|
+
"version": "1.0.9",
|
|
4360
4359
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
4361
4360
|
"private": true,
|
|
4362
4361
|
"devDependencies": {
|
|
@@ -4402,6 +4401,7 @@ var tsconfigData = `
|
|
|
4402
4401
|
var dotGitignoreData = `
|
|
4403
4402
|
# Ignore all files in this directory
|
|
4404
4403
|
node_modules/
|
|
4404
|
+
bin/
|
|
4405
4405
|
`;
|
|
4406
4406
|
var ecosystemData = `
|
|
4407
4407
|
module.exports = {
|
|
@@ -4705,7 +4705,7 @@ class ScriptDBClient {
|
|
|
4705
4705
|
parsed.password = "";
|
|
4706
4706
|
this.uri = parsed.toString();
|
|
4707
4707
|
} catch (e) {
|
|
4708
|
-
this.uri =
|
|
4708
|
+
this.uri = uri;
|
|
4709
4709
|
}
|
|
4710
4710
|
this.host = parsed.hostname || "localhost";
|
|
4711
4711
|
this.port = parsed.port ? parseInt(parsed.port, 10) : 1234;
|
|
@@ -4796,6 +4796,12 @@ class ScriptDBClient {
|
|
|
4796
4796
|
this._connecting = null;
|
|
4797
4797
|
return reject(error);
|
|
4798
4798
|
}
|
|
4799
|
+
if (!this.client) {
|
|
4800
|
+
const error = new Error("Failed to create client socket");
|
|
4801
|
+
this.logger?.error?.("Connection failed", error.message);
|
|
4802
|
+
this._connecting = null;
|
|
4803
|
+
return reject(error);
|
|
4804
|
+
}
|
|
4799
4805
|
const onError = (err) => {
|
|
4800
4806
|
this.logger?.error?.("Client socket error:", err && err.message ? err.message : err);
|
|
4801
4807
|
this._handleDisconnect(err);
|
|
@@ -4806,7 +4812,7 @@ class ScriptDBClient {
|
|
|
4806
4812
|
};
|
|
4807
4813
|
this.client.on("error", onError);
|
|
4808
4814
|
this.client.on("close", onClose);
|
|
4809
|
-
if (this.socketTimeout > 0) {
|
|
4815
|
+
if (this.socketTimeout > 0 && this.client) {
|
|
4810
4816
|
this.client.setTimeout(this.socketTimeout);
|
|
4811
4817
|
this.client.on("timeout", () => {
|
|
4812
4818
|
this.logger?.warn?.("Socket timeout, destroying connection");
|
|
@@ -5663,8 +5669,23 @@ async function server() {
|
|
|
5663
5669
|
allowed.host = parsedConfig.host;
|
|
5664
5670
|
if (parsedConfig.port !== undefined)
|
|
5665
5671
|
allowed.port = parsedConfig.port;
|
|
5666
|
-
if (parsedConfig.users !== undefined)
|
|
5667
|
-
|
|
5672
|
+
if (parsedConfig.users !== undefined) {
|
|
5673
|
+
if (Array.isArray(parsedConfig.users)) {
|
|
5674
|
+
if (parsedConfig.users.length === 0) {
|
|
5675
|
+
allowed.users = [];
|
|
5676
|
+
} else if (typeof parsedConfig.users[0] === "string") {
|
|
5677
|
+
allowed.users = parsedConfig.users.map((username) => ({
|
|
5678
|
+
username,
|
|
5679
|
+
password: "",
|
|
5680
|
+
hash: false
|
|
5681
|
+
}));
|
|
5682
|
+
} else {
|
|
5683
|
+
allowed.users = parsedConfig.users;
|
|
5684
|
+
}
|
|
5685
|
+
} else {
|
|
5686
|
+
allowed.users = [parsedConfig.users];
|
|
5687
|
+
}
|
|
5688
|
+
}
|
|
5668
5689
|
if (typeof parsedConfig.folder === "string")
|
|
5669
5690
|
allowed.folder = parsedConfig.folder;
|
|
5670
5691
|
if (typeof parsedConfig.secure === "boolean")
|
|
@@ -5731,7 +5752,7 @@ async function server() {
|
|
|
5731
5752
|
} catch (err) {
|
|
5732
5753
|
exitWithError("Failed to initialize VM", err);
|
|
5733
5754
|
}
|
|
5734
|
-
let storage;
|
|
5755
|
+
let storage = null;
|
|
5735
5756
|
try {
|
|
5736
5757
|
storage = new Storage2(baseDir, basePath);
|
|
5737
5758
|
await storage.initialize();
|
|
@@ -5739,6 +5760,9 @@ async function server() {
|
|
|
5739
5760
|
} catch (err) {
|
|
5740
5761
|
exitWithError("Failed to initialize Storage", err);
|
|
5741
5762
|
}
|
|
5763
|
+
if (!storage) {
|
|
5764
|
+
exitWithError("Storage was not initialized");
|
|
5765
|
+
}
|
|
5742
5766
|
let scriptDBServer;
|
|
5743
5767
|
try {
|
|
5744
5768
|
scriptDBServer = new Protocal({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scriptdb/server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "server module resolver for script database",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"typescript": "^5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@scriptdb/client": "^1.0.
|
|
45
|
-
"@scriptdb/storage": "^1.0.
|
|
46
|
-
"@scriptdb/system-modules": "^1.0.
|
|
47
|
-
"@scriptdb/vm": "^1.0.
|
|
44
|
+
"@scriptdb/client": "^1.0.9",
|
|
45
|
+
"@scriptdb/storage": "^1.0.9",
|
|
46
|
+
"@scriptdb/system-modules": "^1.0.9",
|
|
47
|
+
"@scriptdb/vm": "^1.0.9",
|
|
48
48
|
"@types/ws": "^8.18.1",
|
|
49
49
|
"bcryptjs": "^3.0.3",
|
|
50
50
|
"bottleneck": "^2.19.5",
|