@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 +1 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1542,7 +1542,7 @@ import { spawn } from "child_process";
|
|
|
1542
1542
|
import Storage from "@scriptdb/storage";
|
|
1543
1543
|
var pkgData = `{
|
|
1544
1544
|
"name": "scriptdb-workspace",
|
|
1545
|
-
"version": "1.1.
|
|
1545
|
+
"version": "1.1.2",
|
|
1546
1546
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
1547
1547
|
"private": true,
|
|
1548
1548
|
"devDependencies": {
|
|
@@ -2581,7 +2581,33 @@ var ScriptDBClient = class {
|
|
|
2581
2581
|
* Execute code in a database
|
|
2582
2582
|
*/
|
|
2583
2583
|
async run(code, databaseName) {
|
|
2584
|
-
|
|
2584
|
+
let stringCode;
|
|
2585
|
+
if (typeof code === "function") {
|
|
2586
|
+
const funcStr = code.toString();
|
|
2587
|
+
const arrowMatch = funcStr.match(/^[\s]*\(?\s*\)?\s*=>\s*{?/);
|
|
2588
|
+
const functionMatch = funcStr.match(/^[\s]*function\s*\(?[\w\s]*\)?\s*{/);
|
|
2589
|
+
const match = arrowMatch || functionMatch;
|
|
2590
|
+
const start = match ? match[0].length : 0;
|
|
2591
|
+
const end = funcStr.lastIndexOf("}");
|
|
2592
|
+
stringCode = funcStr.substring(start, end);
|
|
2593
|
+
stringCode = stringCode.replace(/^[\s\r\n]+/, "").replace(/[\s\r\n]+$/, "");
|
|
2594
|
+
stringCode = stringCode.replace(
|
|
2595
|
+
/import\s*\(\s*([^)]+?)\s*\)\s*\.from\s*\(\s*(['"])([^'"]+)\2\s*\)/g,
|
|
2596
|
+
(_, importArg, quote, modulePath) => {
|
|
2597
|
+
const trimmed = importArg.trim();
|
|
2598
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
2599
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
2600
|
+
return `import { ${inner} } from ${quote}${modulePath}${quote}`;
|
|
2601
|
+
} else {
|
|
2602
|
+
return `import ${trimmed} from ${quote}${modulePath}${quote}`;
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
);
|
|
2606
|
+
stringCode = stringCode.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
2607
|
+
} else {
|
|
2608
|
+
stringCode = code;
|
|
2609
|
+
}
|
|
2610
|
+
return this.sendRequest("script-code", { code: stringCode, databaseName });
|
|
2585
2611
|
}
|
|
2586
2612
|
/**
|
|
2587
2613
|
* Save a database to disk
|