@scriptdb/client 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 +47 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -95,14 +95,16 @@ class ScriptDBClient {
95
95
  this.retries = Number.isFinite(this.options.retries) ? this.options.retries : 3;
96
96
  this.retryDelay = Number.isFinite(this.options.retryDelay) ? this.options.retryDelay : 1000;
97
97
  this.frame = this.options.frame === "length-prefix" || this.options.preferLengthPrefix ? "length-prefix" : "ndjson";
98
- const normalized = uri.replace(/^https?:\/\//i, "scriptdb://");
99
98
  let parsed;
100
99
  try {
101
- parsed = new URL(normalized);
100
+ parsed = new URL(uri);
102
101
  } catch (e) {
103
102
  throw new Error("Invalid uri");
104
103
  }
105
- this.uri = normalized;
104
+ if (parsed.protocol !== "scriptdb:") {
105
+ throw new Error("URI must use scriptdb:// protocol");
106
+ }
107
+ this.uri = uri;
106
108
  this.protocolName = parsed.protocol ? parsed.protocol.replace(":", "") : "scriptdb";
107
109
  this.username = (typeof this.options.username === "string" ? this.options.username : parsed.username) || null;
108
110
  this.password = (typeof this.options.password === "string" ? this.options.password : parsed.password) || null;
@@ -164,6 +166,9 @@ class ScriptDBClient {
164
166
  });
165
167
  }
166
168
  }
169
+ get connected() {
170
+ return this._connected;
171
+ }
167
172
  connect() {
168
173
  if (this._connecting)
169
174
  return this._connecting;
@@ -686,6 +691,45 @@ class ScriptDBClient {
686
691
  } catch (e) {}
687
692
  this.client = null;
688
693
  }
694
+ disconnect() {
695
+ this.close();
696
+ }
697
+ async sendRequest(action, data = {}) {
698
+ return this.execute({ action, data });
699
+ }
700
+ async login(username, password) {
701
+ return this.sendRequest("login", { username, password });
702
+ }
703
+ async logout() {
704
+ return this.sendRequest("logout", {});
705
+ }
706
+ async listDatabases() {
707
+ return this.sendRequest("list-dbs", {});
708
+ }
709
+ async createDatabase(name) {
710
+ return this.sendRequest("create-db", { databaseName: name });
711
+ }
712
+ async removeDatabase(name) {
713
+ return this.sendRequest("remove-db", { databaseName: name });
714
+ }
715
+ async renameDatabase(oldName, newName) {
716
+ return this.sendRequest("rename-db", { databaseName: oldName, newName });
717
+ }
718
+ async run(code, databaseName) {
719
+ return this.sendRequest("script-code", { code, databaseName });
720
+ }
721
+ async saveDatabase(databaseName) {
722
+ return this.sendRequest("save-db", { databaseName });
723
+ }
724
+ async updateDatabase(databaseName, data) {
725
+ return this.sendRequest("update-db", { databaseName, ...data });
726
+ }
727
+ async getInfo() {
728
+ return this.sendRequest("get-info", {});
729
+ }
730
+ async executeShell(command) {
731
+ return this.sendRequest("shell-command", { command });
732
+ }
689
733
  }
690
734
  var src_default = ScriptDBClient;
691
735
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptdb/client",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Client module resolver for script database",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",