@scriptdb/server 1.0.2 → 1.0.4

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 (2) hide show
  1. package/dist/index.js +72 -4
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -4358,7 +4358,7 @@ import { spawn } from "node:child_process";
4358
4358
  import Storage from "@scriptdb/storage";
4359
4359
  var pkgData = `{
4360
4360
  "name": "scriptdb-workspace",
4361
- "version": "1.0.0",
4361
+ "version": "1.0.4",
4362
4362
  "description": "ScriptDB workspace for custom scripts, services, and databases",
4363
4363
  "private": true,
4364
4364
  "devDependencies": {
@@ -4370,9 +4370,6 @@ var pkgData = `{
4370
4370
  "eslint": "^8.0.0",
4371
4371
  "typescript": "^5.0.0"
4372
4372
  },
4373
- "peerDependencies": {
4374
- "typescript": "^5.0.0"
4375
- },
4376
4373
  "dependencies": {
4377
4374
  "lodash": "^4.17.21"
4378
4375
  }
@@ -4723,6 +4720,9 @@ class ScriptDBClient {
4723
4720
  });
4724
4721
  }
4725
4722
  }
4723
+ get connected() {
4724
+ return this._connected;
4725
+ }
4726
4726
  connect() {
4727
4727
  if (this._connecting)
4728
4728
  return this._connecting;
@@ -5245,10 +5245,52 @@ class ScriptDBClient {
5245
5245
  } catch (e) {}
5246
5246
  this.client = null;
5247
5247
  }
5248
+ disconnect() {
5249
+ this.close();
5250
+ }
5251
+ async sendRequest(action, data = {}) {
5252
+ return this.execute({ action, data });
5253
+ }
5254
+ async login(username, password) {
5255
+ return this.sendRequest("login", { username, password });
5256
+ }
5257
+ async logout() {
5258
+ return this.sendRequest("logout", {});
5259
+ }
5260
+ async listDatabases() {
5261
+ return this.sendRequest("list-dbs", {});
5262
+ }
5263
+ async createDatabase(name) {
5264
+ return this.sendRequest("create-db", { databaseName: name });
5265
+ }
5266
+ async removeDatabase(name) {
5267
+ return this.sendRequest("remove-db", { databaseName: name });
5268
+ }
5269
+ async renameDatabase(oldName, newName) {
5270
+ return this.sendRequest("rename-db", { databaseName: oldName, newName });
5271
+ }
5272
+ async run(code, databaseName) {
5273
+ return this.sendRequest("script-code", { code, databaseName });
5274
+ }
5275
+ async saveDatabase(databaseName) {
5276
+ return this.sendRequest("save-db", { databaseName });
5277
+ }
5278
+ async updateDatabase(databaseName, data) {
5279
+ return this.sendRequest("update-db", { databaseName, ...data });
5280
+ }
5281
+ async getInfo() {
5282
+ return this.sendRequest("get-info", {});
5283
+ }
5284
+ async executeShell(command) {
5285
+ return this.sendRequest("shell-command", { command });
5286
+ }
5248
5287
  }
5249
5288
  var src_default = ScriptDBClient;
5250
5289
 
5251
5290
  // src/wsProxy.ts
5291
+ import { exec } from "child_process";
5292
+ import { promisify } from "util";
5293
+ var execPromise = promisify(exec);
5252
5294
  var noopLogger2 = {
5253
5295
  debug: () => {},
5254
5296
  info: () => {},
@@ -5437,6 +5479,9 @@ class WebSocketProxy {
5437
5479
  case "get-info":
5438
5480
  result = await client.execute({ action: "get-info" });
5439
5481
  break;
5482
+ case "shell-command":
5483
+ result = await this.executeShellCommand(payload.command);
5484
+ break;
5440
5485
  default:
5441
5486
  throw new Error(`Unknown action: ${action}`);
5442
5487
  }
@@ -5476,6 +5521,29 @@ class WebSocketProxy {
5476
5521
  sendError(ws, id, error) {
5477
5522
  this.sendResponse(ws, id, "error", "ERROR", error);
5478
5523
  }
5524
+ async executeShellCommand(command) {
5525
+ try {
5526
+ this.logger.info?.(`Executing shell command: ${command}`);
5527
+ if (command.length > 1000) {
5528
+ throw new Error("Command too long");
5529
+ }
5530
+ const { stdout, stderr } = await execPromise(command, {
5531
+ timeout: 30000,
5532
+ maxBuffer: 1024 * 1024,
5533
+ cwd: process.cwd()
5534
+ });
5535
+ return {
5536
+ stdout: stdout || "",
5537
+ stderr: stderr || ""
5538
+ };
5539
+ } catch (error) {
5540
+ this.logger.error?.("Shell command failed:", error);
5541
+ return {
5542
+ stdout: "",
5543
+ stderr: error.message || String(error)
5544
+ };
5545
+ }
5546
+ }
5479
5547
  handleClose(session) {
5480
5548
  this.logger.info?.("WebSocket connection closed");
5481
5549
  if (session.client) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptdb/server",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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.2",
45
- "@scriptdb/storage": "^1.0.2",
46
- "@scriptdb/system-modules": "^1.0.2",
47
- "@scriptdb/vm": "^1.0.2",
44
+ "@scriptdb/client": "^1.0.4",
45
+ "@scriptdb/storage": "^1.0.4",
46
+ "@scriptdb/system-modules": "^1.0.4",
47
+ "@scriptdb/vm": "^1.0.4",
48
48
  "@types/ws": "^8.18.1",
49
49
  "bcryptjs": "^3.0.3",
50
50
  "bottleneck": "^2.19.5",