@scriptdb/client 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 +85 -0
- package/dist/index.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -302,6 +302,91 @@ npm run typecheck
|
|
|
302
302
|
npm run lint
|
|
303
303
|
```
|
|
304
304
|
|
|
305
|
+
## CLI Tool
|
|
306
|
+
|
|
307
|
+
ScriptDB also provides a CLI tool for server management:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Install CLI globally
|
|
311
|
+
npm install -g @scriptdb/cli
|
|
312
|
+
|
|
313
|
+
# Start server in foreground
|
|
314
|
+
scriptdb start
|
|
315
|
+
|
|
316
|
+
# Start server in background (daemon mode with PM2)
|
|
317
|
+
scriptdb start -d
|
|
318
|
+
|
|
319
|
+
# Check server status
|
|
320
|
+
scriptdb status
|
|
321
|
+
|
|
322
|
+
# View real-time logs
|
|
323
|
+
scriptdb logs
|
|
324
|
+
|
|
325
|
+
# Monitor performance
|
|
326
|
+
scriptdb monit
|
|
327
|
+
|
|
328
|
+
# Stop server
|
|
329
|
+
scriptdb stop
|
|
330
|
+
|
|
331
|
+
# Restart server
|
|
332
|
+
scriptdb restart -d
|
|
333
|
+
|
|
334
|
+
# Install packages to ScriptDB
|
|
335
|
+
scriptdb add lodash
|
|
336
|
+
scriptdb add axios express
|
|
337
|
+
|
|
338
|
+
# Install packages locally
|
|
339
|
+
scriptdb add --local lodash
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### CLI Commands
|
|
343
|
+
|
|
344
|
+
- `scriptdb start [-d]` - Start the ScriptDB server (`-d` for daemon mode)
|
|
345
|
+
- `scriptdb stop` - Stop the running server
|
|
346
|
+
- `scriptdb restart [-d]` - Restart the server
|
|
347
|
+
- `scriptdb status` - Check server status and view metrics
|
|
348
|
+
- `scriptdb logs` - View real-time logs
|
|
349
|
+
- `scriptdb monit` - Monitor performance (CPU, memory, uptime)
|
|
350
|
+
- `scriptdb shell` - Start interactive shell
|
|
351
|
+
- `scriptdb add <package> [--local]` - Install packages
|
|
352
|
+
- `scriptdb remove <package> [--local]` - Remove packages
|
|
353
|
+
|
|
354
|
+
### Configuration
|
|
355
|
+
|
|
356
|
+
The CLI reads configuration from `~/.scriptdb/config.json`:
|
|
357
|
+
|
|
358
|
+
```json
|
|
359
|
+
{
|
|
360
|
+
"host": "localhost",
|
|
361
|
+
"port": 1234,
|
|
362
|
+
"users": [
|
|
363
|
+
{
|
|
364
|
+
"username": "admin",
|
|
365
|
+
"password": "your-password",
|
|
366
|
+
"hash": false
|
|
367
|
+
}
|
|
368
|
+
],
|
|
369
|
+
"folder": "databases",
|
|
370
|
+
"secure": false
|
|
371
|
+
}
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## Changelog
|
|
375
|
+
|
|
376
|
+
### 1.0.9 (2025-01-16)
|
|
377
|
+
|
|
378
|
+
**Added**
|
|
379
|
+
- Native `scriptdb logs` command to view real-time logs
|
|
380
|
+
- Native `scriptdb monit` command to monitor performance
|
|
381
|
+
- Native `scriptdb restart` command to restart the server
|
|
382
|
+
- Native `scriptdb stop` command to stop the server
|
|
383
|
+
- Dynamic version reading from package.json
|
|
384
|
+
|
|
385
|
+
**Fixed**
|
|
386
|
+
- Fixed TypeScript module resolution errors
|
|
387
|
+
- Fixed test command to continue gracefully when packages have no tests
|
|
388
|
+
- Improved error handling and Windows compatibility
|
|
389
|
+
|
|
305
390
|
## License
|
|
306
391
|
|
|
307
392
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -116,7 +116,7 @@ class ScriptDBClient {
|
|
|
116
116
|
parsed.password = "";
|
|
117
117
|
this.uri = parsed.toString();
|
|
118
118
|
} catch (e) {
|
|
119
|
-
this.uri =
|
|
119
|
+
this.uri = uri;
|
|
120
120
|
}
|
|
121
121
|
this.host = parsed.hostname || "localhost";
|
|
122
122
|
this.port = parsed.port ? parseInt(parsed.port, 10) : 1234;
|
|
@@ -207,6 +207,12 @@ class ScriptDBClient {
|
|
|
207
207
|
this._connecting = null;
|
|
208
208
|
return reject(error);
|
|
209
209
|
}
|
|
210
|
+
if (!this.client) {
|
|
211
|
+
const error = new Error("Failed to create client socket");
|
|
212
|
+
this.logger?.error?.("Connection failed", error.message);
|
|
213
|
+
this._connecting = null;
|
|
214
|
+
return reject(error);
|
|
215
|
+
}
|
|
210
216
|
const onError = (err) => {
|
|
211
217
|
this.logger?.error?.("Client socket error:", err && err.message ? err.message : err);
|
|
212
218
|
this._handleDisconnect(err);
|
|
@@ -217,7 +223,7 @@ class ScriptDBClient {
|
|
|
217
223
|
};
|
|
218
224
|
this.client.on("error", onError);
|
|
219
225
|
this.client.on("close", onClose);
|
|
220
|
-
if (this.socketTimeout > 0) {
|
|
226
|
+
if (this.socketTimeout > 0 && this.client) {
|
|
221
227
|
this.client.setTimeout(this.socketTimeout);
|
|
222
228
|
this.client.on("timeout", () => {
|
|
223
229
|
this.logger?.warn?.("Socket timeout, destroying connection");
|