@scriptdb/cli 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 +29 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -6037,7 +6037,7 @@ import fs5 from "fs";
|
|
|
6037
6037
|
import { spawn } from "child_process";
|
|
6038
6038
|
var pkgData = `{
|
|
6039
6039
|
"name": "scriptdb-workspace",
|
|
6040
|
-
"version": "1.1.
|
|
6040
|
+
"version": "1.1.2",
|
|
6041
6041
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
6042
6042
|
"private": true,
|
|
6043
6043
|
"devDependencies": {
|
|
@@ -7082,7 +7082,33 @@ var ScriptDBClient = class {
|
|
|
7082
7082
|
* Execute code in a database
|
|
7083
7083
|
*/
|
|
7084
7084
|
async run(code, databaseName) {
|
|
7085
|
-
|
|
7085
|
+
let stringCode;
|
|
7086
|
+
if (typeof code === "function") {
|
|
7087
|
+
const funcStr = code.toString();
|
|
7088
|
+
const arrowMatch = funcStr.match(/^[\s]*\(?\s*\)?\s*=>\s*{?/);
|
|
7089
|
+
const functionMatch = funcStr.match(/^[\s]*function\s*\(?[\w\s]*\)?\s*{/);
|
|
7090
|
+
const match = arrowMatch || functionMatch;
|
|
7091
|
+
const start = match ? match[0].length : 0;
|
|
7092
|
+
const end = funcStr.lastIndexOf("}");
|
|
7093
|
+
stringCode = funcStr.substring(start, end);
|
|
7094
|
+
stringCode = stringCode.replace(/^[\s\r\n]+/, "").replace(/[\s\r\n]+$/, "");
|
|
7095
|
+
stringCode = stringCode.replace(
|
|
7096
|
+
/import\s*\(\s*([^)]+?)\s*\)\s*\.from\s*\(\s*(['"])([^'"]+)\2\s*\)/g,
|
|
7097
|
+
(_, importArg, quote, modulePath) => {
|
|
7098
|
+
const trimmed = importArg.trim();
|
|
7099
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
7100
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
7101
|
+
return `import { ${inner} } from ${quote}${modulePath}${quote}`;
|
|
7102
|
+
} else {
|
|
7103
|
+
return `import ${trimmed} from ${quote}${modulePath}${quote}`;
|
|
7104
|
+
}
|
|
7105
|
+
}
|
|
7106
|
+
);
|
|
7107
|
+
stringCode = stringCode.split("\n").map((line) => line.trim()).join("\n").trim();
|
|
7108
|
+
} else {
|
|
7109
|
+
stringCode = code;
|
|
7110
|
+
}
|
|
7111
|
+
return this.sendRequest("script-code", { code: stringCode, databaseName });
|
|
7086
7112
|
}
|
|
7087
7113
|
/**
|
|
7088
7114
|
* Save a database to disk
|
|
@@ -8525,7 +8551,7 @@ function ensureScriptDBDir() {
|
|
|
8525
8551
|
if (!existsSync5(PACKAGE_JSON)) {
|
|
8526
8552
|
const packageJsonContent = {
|
|
8527
8553
|
"name": "scriptdb-workspace",
|
|
8528
|
-
"version": "1.1.
|
|
8554
|
+
"version": "1.1.2",
|
|
8529
8555
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
8530
8556
|
"private": true,
|
|
8531
8557
|
"devDependencies": {
|