@scriptdb/server 1.0.6 → 1.0.8
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/dist/index.js +67 -9
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2890,8 +2890,6 @@ try {
|
|
|
2890
2890
|
if (fs2.existsSync(configPath)) {
|
|
2891
2891
|
const configContent = fs2.readFileSync(configPath, "utf8");
|
|
2892
2892
|
fileConfig = JSON.parse(configContent);
|
|
2893
|
-
console.log("Loaded config from:", configPath);
|
|
2894
|
-
console.log("Config users:", fileConfig.users);
|
|
2895
2893
|
} else {
|
|
2896
2894
|
console.log("No config file found at:", configPath, "- using defaults");
|
|
2897
2895
|
}
|
|
@@ -4358,7 +4356,7 @@ import { spawn } from "node:child_process";
|
|
|
4358
4356
|
import Storage from "@scriptdb/storage";
|
|
4359
4357
|
var pkgData = `{
|
|
4360
4358
|
"name": "scriptdb-workspace",
|
|
4361
|
-
"version": "1.0.
|
|
4359
|
+
"version": "1.0.8",
|
|
4362
4360
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
4363
4361
|
"private": true,
|
|
4364
4362
|
"devDependencies": {
|
|
@@ -4404,6 +4402,32 @@ var tsconfigData = `
|
|
|
4404
4402
|
var dotGitignoreData = `
|
|
4405
4403
|
# Ignore all files in this directory
|
|
4406
4404
|
node_modules/
|
|
4405
|
+
bin/
|
|
4406
|
+
`;
|
|
4407
|
+
var ecosystemData = `
|
|
4408
|
+
module.exports = {
|
|
4409
|
+
apps: [{
|
|
4410
|
+
name: 'scriptdb',
|
|
4411
|
+
script: process.platform === 'win32'
|
|
4412
|
+
? require('path').join(require('os').homedir(), '.scriptdb', 'bin', 'scriptdb.exe')
|
|
4413
|
+
: 'scriptdb',
|
|
4414
|
+
args: 'start --force',
|
|
4415
|
+
cwd: require('path').join(require('os').homedir(), '.scriptdb'),
|
|
4416
|
+
instances: 1,
|
|
4417
|
+
autorestart: true,
|
|
4418
|
+
watch: false,
|
|
4419
|
+
max_memory_restart: '1G',
|
|
4420
|
+
env: {
|
|
4421
|
+
NODE_ENV: 'production'
|
|
4422
|
+
},
|
|
4423
|
+
error_file: require('path').join(require('os').homedir(), '.scriptdb', 'pm2-error.log'),
|
|
4424
|
+
out_file: require('path').join(require('os').homedir(), '.scriptdb', 'pm2-out.log'),
|
|
4425
|
+
log_file: require('path').join(require('os').homedir(), '.scriptdb', 'pm2-combined.log'),
|
|
4426
|
+
time: true,
|
|
4427
|
+
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
|
|
4428
|
+
merge_logs: true
|
|
4429
|
+
}]
|
|
4430
|
+
};
|
|
4407
4431
|
`;
|
|
4408
4432
|
var configDefault = {
|
|
4409
4433
|
PORT: 3800,
|
|
@@ -4495,11 +4519,13 @@ async function setupDir() {
|
|
|
4495
4519
|
const databasesDir = path2.join(scriptdbDir, "databases");
|
|
4496
4520
|
const servicesDir = path2.join(scriptdbDir, "services");
|
|
4497
4521
|
const clientsDir = path2.join(scriptdbDir, "clients");
|
|
4522
|
+
const binDir = path2.join(scriptdbDir, "bin");
|
|
4498
4523
|
const configFile = path2.join(scriptdbDir, "config.json");
|
|
4499
4524
|
const gitignoreFile = path2.join(scriptdbDir, ".gitignore");
|
|
4500
4525
|
const packageJsonFile = path2.join(scriptdbDir, "package.json");
|
|
4501
4526
|
const tsconfigFile = path2.join(scriptdbDir, "tsconfig.json");
|
|
4502
|
-
const
|
|
4527
|
+
const ecosystemFile = path2.join(scriptdbDir, "ecosystem.config.js");
|
|
4528
|
+
const isFullySetup = fs3.existsSync(scriptdbDir) && fs3.existsSync(databasesDir) && fs3.existsSync(servicesDir) && fs3.existsSync(clientsDir) && fs3.existsSync(binDir) && fs3.existsSync(configFile) && fs3.existsSync(gitignoreFile) && fs3.existsSync(packageJsonFile) && fs3.existsSync(tsconfigFile) && fs3.existsSync(ecosystemFile);
|
|
4503
4529
|
if (isFullySetup) {
|
|
4504
4530
|
console.log("ScriptDB directory already fully configured:", scriptdbDir);
|
|
4505
4531
|
return;
|
|
@@ -4510,10 +4536,12 @@ async function setupDir() {
|
|
|
4510
4536
|
fs3.mkdirSync(databasesDir, { recursive: true });
|
|
4511
4537
|
fs3.mkdirSync(servicesDir, { recursive: true });
|
|
4512
4538
|
fs3.mkdirSync(clientsDir, { recursive: true });
|
|
4539
|
+
fs3.mkdirSync(binDir, { recursive: true });
|
|
4513
4540
|
fs3.writeFileSync(configFile, JSON.stringify(configDefault, null, 2), "utf8");
|
|
4514
4541
|
fs3.writeFileSync(gitignoreFile, dotGitignoreData, "utf8");
|
|
4515
4542
|
fs3.writeFileSync(packageJsonFile, pkgData, "utf8");
|
|
4516
4543
|
fs3.writeFileSync(tsconfigFile, tsconfigData, "utf8");
|
|
4544
|
+
fs3.writeFileSync(ecosystemFile, ecosystemData, "utf8");
|
|
4517
4545
|
console.log("Created:", scriptdbDir);
|
|
4518
4546
|
await installPackage(scriptdbDir);
|
|
4519
4547
|
await setupStorage(scriptdbDir);
|
|
@@ -4527,6 +4555,9 @@ async function setupDir() {
|
|
|
4527
4555
|
if (!fs3.existsSync(clientsDir)) {
|
|
4528
4556
|
fs3.mkdirSync(clientsDir, { recursive: true });
|
|
4529
4557
|
}
|
|
4558
|
+
if (!fs3.existsSync(binDir)) {
|
|
4559
|
+
fs3.mkdirSync(binDir, { recursive: true });
|
|
4560
|
+
}
|
|
4530
4561
|
if (!fs3.existsSync(configFile)) {
|
|
4531
4562
|
fs3.writeFileSync(configFile, JSON.stringify(configDefault, null, 2), "utf8");
|
|
4532
4563
|
}
|
|
@@ -4539,6 +4570,9 @@ async function setupDir() {
|
|
|
4539
4570
|
if (!fs3.existsSync(tsconfigFile)) {
|
|
4540
4571
|
fs3.writeFileSync(tsconfigFile, tsconfigData, "utf8");
|
|
4541
4572
|
}
|
|
4573
|
+
if (!fs3.existsSync(ecosystemFile)) {
|
|
4574
|
+
fs3.writeFileSync(ecosystemFile, ecosystemData, "utf8");
|
|
4575
|
+
}
|
|
4542
4576
|
if (!fs3.existsSync(path2.join(scriptdbDir, "node_modules"))) {
|
|
4543
4577
|
await installPackage(scriptdbDir);
|
|
4544
4578
|
}
|
|
@@ -4672,7 +4706,7 @@ class ScriptDBClient {
|
|
|
4672
4706
|
parsed.password = "";
|
|
4673
4707
|
this.uri = parsed.toString();
|
|
4674
4708
|
} catch (e) {
|
|
4675
|
-
this.uri =
|
|
4709
|
+
this.uri = uri;
|
|
4676
4710
|
}
|
|
4677
4711
|
this.host = parsed.hostname || "localhost";
|
|
4678
4712
|
this.port = parsed.port ? parseInt(parsed.port, 10) : 1234;
|
|
@@ -4763,6 +4797,12 @@ class ScriptDBClient {
|
|
|
4763
4797
|
this._connecting = null;
|
|
4764
4798
|
return reject(error);
|
|
4765
4799
|
}
|
|
4800
|
+
if (!this.client) {
|
|
4801
|
+
const error = new Error("Failed to create client socket");
|
|
4802
|
+
this.logger?.error?.("Connection failed", error.message);
|
|
4803
|
+
this._connecting = null;
|
|
4804
|
+
return reject(error);
|
|
4805
|
+
}
|
|
4766
4806
|
const onError = (err) => {
|
|
4767
4807
|
this.logger?.error?.("Client socket error:", err && err.message ? err.message : err);
|
|
4768
4808
|
this._handleDisconnect(err);
|
|
@@ -4773,7 +4813,7 @@ class ScriptDBClient {
|
|
|
4773
4813
|
};
|
|
4774
4814
|
this.client.on("error", onError);
|
|
4775
4815
|
this.client.on("close", onClose);
|
|
4776
|
-
if (this.socketTimeout > 0) {
|
|
4816
|
+
if (this.socketTimeout > 0 && this.client) {
|
|
4777
4817
|
this.client.setTimeout(this.socketTimeout);
|
|
4778
4818
|
this.client.on("timeout", () => {
|
|
4779
4819
|
this.logger?.warn?.("Socket timeout, destroying connection");
|
|
@@ -5630,8 +5670,23 @@ async function server() {
|
|
|
5630
5670
|
allowed.host = parsedConfig.host;
|
|
5631
5671
|
if (parsedConfig.port !== undefined)
|
|
5632
5672
|
allowed.port = parsedConfig.port;
|
|
5633
|
-
if (parsedConfig.users !== undefined)
|
|
5634
|
-
|
|
5673
|
+
if (parsedConfig.users !== undefined) {
|
|
5674
|
+
if (Array.isArray(parsedConfig.users)) {
|
|
5675
|
+
if (parsedConfig.users.length === 0) {
|
|
5676
|
+
allowed.users = [];
|
|
5677
|
+
} else if (typeof parsedConfig.users[0] === "string") {
|
|
5678
|
+
allowed.users = parsedConfig.users.map((username) => ({
|
|
5679
|
+
username,
|
|
5680
|
+
password: "",
|
|
5681
|
+
hash: false
|
|
5682
|
+
}));
|
|
5683
|
+
} else {
|
|
5684
|
+
allowed.users = parsedConfig.users;
|
|
5685
|
+
}
|
|
5686
|
+
} else {
|
|
5687
|
+
allowed.users = [parsedConfig.users];
|
|
5688
|
+
}
|
|
5689
|
+
}
|
|
5635
5690
|
if (typeof parsedConfig.folder === "string")
|
|
5636
5691
|
allowed.folder = parsedConfig.folder;
|
|
5637
5692
|
if (typeof parsedConfig.secure === "boolean")
|
|
@@ -5698,7 +5753,7 @@ async function server() {
|
|
|
5698
5753
|
} catch (err) {
|
|
5699
5754
|
exitWithError("Failed to initialize VM", err);
|
|
5700
5755
|
}
|
|
5701
|
-
let storage;
|
|
5756
|
+
let storage = null;
|
|
5702
5757
|
try {
|
|
5703
5758
|
storage = new Storage2(baseDir, basePath);
|
|
5704
5759
|
await storage.initialize();
|
|
@@ -5706,6 +5761,9 @@ async function server() {
|
|
|
5706
5761
|
} catch (err) {
|
|
5707
5762
|
exitWithError("Failed to initialize Storage", err);
|
|
5708
5763
|
}
|
|
5764
|
+
if (!storage) {
|
|
5765
|
+
exitWithError("Storage was not initialized");
|
|
5766
|
+
}
|
|
5709
5767
|
let scriptDBServer;
|
|
5710
5768
|
try {
|
|
5711
5769
|
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.8",
|
|
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.8",
|
|
45
|
+
"@scriptdb/storage": "^1.0.8",
|
|
46
|
+
"@scriptdb/system-modules": "^1.0.8",
|
|
47
|
+
"@scriptdb/vm": "^1.0.8",
|
|
48
48
|
"@types/ws": "^8.18.1",
|
|
49
49
|
"bcryptjs": "^3.0.3",
|
|
50
50
|
"bottleneck": "^2.19.5",
|