@scriptdb/server 1.0.3 → 1.0.5

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 +77 -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.3",
4361
+ "version": "1.0.5",
4362
4362
  "description": "ScriptDB workspace for custom scripts, services, and databases",
4363
4363
  "private": true,
4364
4364
  "devDependencies": {
@@ -4651,14 +4651,16 @@ class ScriptDBClient {
4651
4651
  this.retries = Number.isFinite(this.options.retries) ? this.options.retries : 3;
4652
4652
  this.retryDelay = Number.isFinite(this.options.retryDelay) ? this.options.retryDelay : 1000;
4653
4653
  this.frame = this.options.frame === "length-prefix" || this.options.preferLengthPrefix ? "length-prefix" : "ndjson";
4654
- const normalized = uri.replace(/^https?:\/\//i, "scriptdb://");
4655
4654
  let parsed;
4656
4655
  try {
4657
- parsed = new URL(normalized);
4656
+ parsed = new URL(uri);
4658
4657
  } catch (e) {
4659
4658
  throw new Error("Invalid uri");
4660
4659
  }
4661
- this.uri = normalized;
4660
+ if (parsed.protocol !== "scriptdb:") {
4661
+ throw new Error("URI must use scriptdb:// protocol");
4662
+ }
4663
+ this.uri = uri;
4662
4664
  this.protocolName = parsed.protocol ? parsed.protocol.replace(":", "") : "scriptdb";
4663
4665
  this.username = (typeof this.options.username === "string" ? this.options.username : parsed.username) || null;
4664
4666
  this.password = (typeof this.options.password === "string" ? this.options.password : parsed.password) || null;
@@ -4720,6 +4722,9 @@ class ScriptDBClient {
4720
4722
  });
4721
4723
  }
4722
4724
  }
4725
+ get connected() {
4726
+ return this._connected;
4727
+ }
4723
4728
  connect() {
4724
4729
  if (this._connecting)
4725
4730
  return this._connecting;
@@ -5242,10 +5247,52 @@ class ScriptDBClient {
5242
5247
  } catch (e) {}
5243
5248
  this.client = null;
5244
5249
  }
5250
+ disconnect() {
5251
+ this.close();
5252
+ }
5253
+ async sendRequest(action, data = {}) {
5254
+ return this.execute({ action, data });
5255
+ }
5256
+ async login(username, password) {
5257
+ return this.sendRequest("login", { username, password });
5258
+ }
5259
+ async logout() {
5260
+ return this.sendRequest("logout", {});
5261
+ }
5262
+ async listDatabases() {
5263
+ return this.sendRequest("list-dbs", {});
5264
+ }
5265
+ async createDatabase(name) {
5266
+ return this.sendRequest("create-db", { databaseName: name });
5267
+ }
5268
+ async removeDatabase(name) {
5269
+ return this.sendRequest("remove-db", { databaseName: name });
5270
+ }
5271
+ async renameDatabase(oldName, newName) {
5272
+ return this.sendRequest("rename-db", { databaseName: oldName, newName });
5273
+ }
5274
+ async run(code, databaseName) {
5275
+ return this.sendRequest("script-code", { code, databaseName });
5276
+ }
5277
+ async saveDatabase(databaseName) {
5278
+ return this.sendRequest("save-db", { databaseName });
5279
+ }
5280
+ async updateDatabase(databaseName, data) {
5281
+ return this.sendRequest("update-db", { databaseName, ...data });
5282
+ }
5283
+ async getInfo() {
5284
+ return this.sendRequest("get-info", {});
5285
+ }
5286
+ async executeShell(command) {
5287
+ return this.sendRequest("shell-command", { command });
5288
+ }
5245
5289
  }
5246
5290
  var src_default = ScriptDBClient;
5247
5291
 
5248
5292
  // src/wsProxy.ts
5293
+ import { exec } from "child_process";
5294
+ import { promisify } from "util";
5295
+ var execPromise = promisify(exec);
5249
5296
  var noopLogger2 = {
5250
5297
  debug: () => {},
5251
5298
  info: () => {},
@@ -5434,6 +5481,9 @@ class WebSocketProxy {
5434
5481
  case "get-info":
5435
5482
  result = await client.execute({ action: "get-info" });
5436
5483
  break;
5484
+ case "shell-command":
5485
+ result = await this.executeShellCommand(payload.command);
5486
+ break;
5437
5487
  default:
5438
5488
  throw new Error(`Unknown action: ${action}`);
5439
5489
  }
@@ -5473,6 +5523,29 @@ class WebSocketProxy {
5473
5523
  sendError(ws, id, error) {
5474
5524
  this.sendResponse(ws, id, "error", "ERROR", error);
5475
5525
  }
5526
+ async executeShellCommand(command) {
5527
+ try {
5528
+ this.logger.info?.(`Executing shell command: ${command}`);
5529
+ if (command.length > 1000) {
5530
+ throw new Error("Command too long");
5531
+ }
5532
+ const { stdout, stderr } = await execPromise(command, {
5533
+ timeout: 30000,
5534
+ maxBuffer: 1024 * 1024,
5535
+ cwd: process.cwd()
5536
+ });
5537
+ return {
5538
+ stdout: stdout || "",
5539
+ stderr: stderr || ""
5540
+ };
5541
+ } catch (error) {
5542
+ this.logger.error?.("Shell command failed:", error);
5543
+ return {
5544
+ stdout: "",
5545
+ stderr: error.message || String(error)
5546
+ };
5547
+ }
5548
+ }
5476
5549
  handleClose(session) {
5477
5550
  this.logger.info?.("WebSocket connection closed");
5478
5551
  if (session.client) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptdb/server",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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.3",
45
- "@scriptdb/storage": "^1.0.3",
46
- "@scriptdb/system-modules": "^1.0.3",
47
- "@scriptdb/vm": "^1.0.3",
44
+ "@scriptdb/client": "^1.0.5",
45
+ "@scriptdb/storage": "^1.0.5",
46
+ "@scriptdb/system-modules": "^1.0.5",
47
+ "@scriptdb/vm": "^1.0.5",
48
48
  "@types/ws": "^8.18.1",
49
49
  "bcryptjs": "^3.0.3",
50
50
  "bottleneck": "^2.19.5",