@scriptdb/server 1.1.1 → 1.1.2

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 CHANGED
@@ -468,7 +468,7 @@ PM2 files are stored in `~/.scriptdb/`:
468
468
 
469
469
  ## Changelog
470
470
 
471
- ### 1.1.1 (2025-01-16)
471
+ ### 1.1.2 (2025-01-16)
472
472
 
473
473
  **Added**
474
474
  - Native `scriptdb logs` command to view real-time logs
package/dist/index.js CHANGED
@@ -1579,7 +1579,7 @@ var import_node_child_process = require("child_process");
1579
1579
  var import_storage = __toESM(require("@scriptdb/storage"));
1580
1580
  var pkgData = `{
1581
1581
  "name": "scriptdb-workspace",
1582
- "version": "1.1.1",
1582
+ "version": "1.1.2",
1583
1583
  "description": "ScriptDB workspace for custom scripts, services, and databases",
1584
1584
  "private": true,
1585
1585
  "devDependencies": {
@@ -2618,7 +2618,33 @@ var ScriptDBClient = class {
2618
2618
  * Execute code in a database
2619
2619
  */
2620
2620
  async run(code, databaseName) {
2621
- return this.sendRequest("script-code", { code, databaseName });
2621
+ let stringCode;
2622
+ if (typeof code === "function") {
2623
+ const funcStr = code.toString();
2624
+ const arrowMatch = funcStr.match(/^[\s]*\(?\s*\)?\s*=>\s*{?/);
2625
+ const functionMatch = funcStr.match(/^[\s]*function\s*\(?[\w\s]*\)?\s*{/);
2626
+ const match = arrowMatch || functionMatch;
2627
+ const start = match ? match[0].length : 0;
2628
+ const end = funcStr.lastIndexOf("}");
2629
+ stringCode = funcStr.substring(start, end);
2630
+ stringCode = stringCode.replace(/^[\s\r\n]+/, "").replace(/[\s\r\n]+$/, "");
2631
+ stringCode = stringCode.replace(
2632
+ /import\s*\(\s*([^)]+?)\s*\)\s*\.from\s*\(\s*(['"])([^'"]+)\2\s*\)/g,
2633
+ (_, importArg, quote, modulePath) => {
2634
+ const trimmed = importArg.trim();
2635
+ if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
2636
+ const inner = trimmed.slice(1, -1).trim();
2637
+ return `import { ${inner} } from ${quote}${modulePath}${quote}`;
2638
+ } else {
2639
+ return `import ${trimmed} from ${quote}${modulePath}${quote}`;
2640
+ }
2641
+ }
2642
+ );
2643
+ stringCode = stringCode.split("\n").map((line) => line.trim()).join("\n").trim();
2644
+ } else {
2645
+ stringCode = code;
2646
+ }
2647
+ return this.sendRequest("script-code", { code: stringCode, databaseName });
2622
2648
  }
2623
2649
  /**
2624
2650
  * Save a database to disk