@scriptdb/system-modules 1.1.0 → 1.1.1
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/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +162 -125
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +333 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +2 -5
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare function update$1(dbName: string, fnName: string, code: string | Function): string;
|
|
2
|
+
|
|
3
|
+
declare function remove$1(dbName: string, fnName: string): string | false;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new code snippet in the specified database file.
|
|
7
|
+
* @param dbName Name of the database file (without extension)
|
|
8
|
+
* @param code Code content of the snippet
|
|
9
|
+
*/
|
|
10
|
+
declare function create$1(dbName: string, code: string | Function): void;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Updates an existing code snippet in the specified database file.
|
|
14
|
+
* If the snippet does not exist, it will be created.
|
|
15
|
+
* @param dbFilePath Absolute path to the database file
|
|
16
|
+
* @param name Name of the snippet
|
|
17
|
+
* @param code New code content of the snippet
|
|
18
|
+
*/
|
|
19
|
+
declare function save$1(dbName: string, code: string | Function | any): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Read database file content
|
|
23
|
+
* @param dbName - Database name (without .ts extension)
|
|
24
|
+
* @returns File content as string
|
|
25
|
+
*/
|
|
26
|
+
declare function read$1(dbName: string): string;
|
|
27
|
+
|
|
28
|
+
declare const update: typeof update$1;
|
|
29
|
+
declare const remove: typeof remove$1;
|
|
30
|
+
declare const create: typeof create$1;
|
|
31
|
+
declare const save: typeof save$1;
|
|
32
|
+
declare const read: typeof read$1;
|
|
33
|
+
declare function SystemModuleResolver(): Promise<Record<string, any>>;
|
|
34
|
+
|
|
35
|
+
export { SystemModuleResolver, create, SystemModuleResolver as default, read, remove, save, update };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare function update$1(dbName: string, fnName: string, code: string | Function): string;
|
|
2
|
+
|
|
3
|
+
declare function remove$1(dbName: string, fnName: string): string | false;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new code snippet in the specified database file.
|
|
7
|
+
* @param dbName Name of the database file (without extension)
|
|
8
|
+
* @param code Code content of the snippet
|
|
9
|
+
*/
|
|
10
|
+
declare function create$1(dbName: string, code: string | Function): void;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Updates an existing code snippet in the specified database file.
|
|
14
|
+
* If the snippet does not exist, it will be created.
|
|
15
|
+
* @param dbFilePath Absolute path to the database file
|
|
16
|
+
* @param name Name of the snippet
|
|
17
|
+
* @param code New code content of the snippet
|
|
18
|
+
*/
|
|
19
|
+
declare function save$1(dbName: string, code: string | Function | any): void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Read database file content
|
|
23
|
+
* @param dbName - Database name (without .ts extension)
|
|
24
|
+
* @returns File content as string
|
|
25
|
+
*/
|
|
26
|
+
declare function read$1(dbName: string): string;
|
|
27
|
+
|
|
28
|
+
declare const update: typeof update$1;
|
|
29
|
+
declare const remove: typeof remove$1;
|
|
30
|
+
declare const create: typeof create$1;
|
|
31
|
+
declare const save: typeof save$1;
|
|
32
|
+
declare const read: typeof read$1;
|
|
33
|
+
declare function SystemModuleResolver(): Promise<Record<string, any>>;
|
|
34
|
+
|
|
35
|
+
export { SystemModuleResolver, create, SystemModuleResolver as default, read, remove, save, update };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SystemModuleResolver: () => SystemModuleResolver,
|
|
34
|
+
create: () => create2,
|
|
35
|
+
default: () => index_default,
|
|
36
|
+
read: () => read2,
|
|
37
|
+
remove: () => remove2,
|
|
38
|
+
save: () => save2,
|
|
39
|
+
update: () => update2
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
1
43
|
// src/modules/update.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
44
|
+
var import_node_path = __toESM(require("path"));
|
|
45
|
+
var import_node_fs = __toESM(require("fs"));
|
|
46
|
+
var os = __toESM(require("os"));
|
|
5
47
|
|
|
6
48
|
// src/utils/isIdentifier.ts
|
|
7
49
|
function isIdentifier(key) {
|
|
@@ -13,37 +55,25 @@ function valueToCode(val, depth = 0) {
|
|
|
13
55
|
const indentUnit = " ";
|
|
14
56
|
const indent = indentUnit.repeat(depth);
|
|
15
57
|
const indentInner = indentUnit.repeat(depth + 1);
|
|
16
|
-
if (val === null)
|
|
17
|
-
return "null";
|
|
58
|
+
if (val === null) return "null";
|
|
18
59
|
const t = typeof val;
|
|
19
|
-
if (t === "string")
|
|
20
|
-
|
|
21
|
-
if (t === "
|
|
22
|
-
return String(val);
|
|
23
|
-
if (t === "function")
|
|
24
|
-
return val.toString();
|
|
60
|
+
if (t === "string") return JSON.stringify(val);
|
|
61
|
+
if (t === "number" || t === "boolean") return String(val);
|
|
62
|
+
if (t === "function") return val.toString();
|
|
25
63
|
if (Array.isArray(val)) {
|
|
26
|
-
if (val.length === 0)
|
|
27
|
-
return "[]";
|
|
64
|
+
if (val.length === 0) return "[]";
|
|
28
65
|
const items = val.map((v) => valueToCode(v, depth + 1));
|
|
29
|
-
return
|
|
30
|
-
` + items.map((it) => indentInner + it).join(`,
|
|
31
|
-
`) + `
|
|
32
|
-
` + indent + "]";
|
|
66
|
+
return "[\n" + items.map((it) => indentInner + it).join(",\n") + "\n" + indent + "]";
|
|
33
67
|
}
|
|
34
68
|
if (t === "object") {
|
|
35
69
|
const keys = Object.keys(val);
|
|
36
|
-
if (keys.length === 0)
|
|
37
|
-
return "{}";
|
|
70
|
+
if (keys.length === 0) return "{}";
|
|
38
71
|
const entries = keys.map((k) => {
|
|
39
72
|
const keyPart = isIdentifier(k) ? k : JSON.stringify(k);
|
|
40
73
|
const v = valueToCode(val[k], depth + 1);
|
|
41
74
|
return indentInner + keyPart + ": " + v;
|
|
42
75
|
});
|
|
43
|
-
return
|
|
44
|
-
` + entries.join(`,
|
|
45
|
-
`) + `
|
|
46
|
-
` + indent + "}";
|
|
76
|
+
return "{\n" + entries.join(",\n") + "\n" + indent + "}";
|
|
47
77
|
}
|
|
48
78
|
return String(val);
|
|
49
79
|
}
|
|
@@ -51,49 +81,49 @@ function valueToCode(val, depth = 0) {
|
|
|
51
81
|
// src/modules/update.ts
|
|
52
82
|
function update(dbName, fnName, code) {
|
|
53
83
|
const DIR = "databases";
|
|
54
|
-
const basePath =
|
|
55
|
-
const baseDir =
|
|
56
|
-
const dbPath =
|
|
84
|
+
const basePath = import_node_path.default.join(os.homedir(), ".scriptdb");
|
|
85
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
86
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
57
87
|
let src;
|
|
58
|
-
if (!
|
|
88
|
+
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
59
89
|
try {
|
|
60
|
-
|
|
90
|
+
import_node_fs.default.writeFileSync(dbPath, "", "utf8");
|
|
61
91
|
return `Created new database file: ${dbPath}`;
|
|
62
92
|
} catch (e) {
|
|
63
93
|
return `Failed to create dbPath file: ${dbPath}`;
|
|
64
94
|
}
|
|
65
95
|
}
|
|
66
|
-
src =
|
|
96
|
+
src = import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
67
97
|
const originalSrc = src;
|
|
68
98
|
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
69
|
-
const startRe = new RegExp(
|
|
99
|
+
const startRe = new RegExp(
|
|
100
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
101
|
+
"m"
|
|
102
|
+
);
|
|
70
103
|
const startMatch = src.match(startRe);
|
|
71
104
|
let declKind = null;
|
|
72
105
|
if (startMatch) {
|
|
73
106
|
let startIdx = startMatch.index;
|
|
74
107
|
const snippet = src.slice(startIdx, startIdx + 80);
|
|
75
|
-
if (/^function\b/.test(snippet))
|
|
76
|
-
|
|
77
|
-
else if (
|
|
78
|
-
declKind = "classDecl";
|
|
79
|
-
else if (/^\b(?:const|let|var)\b/.test(snippet))
|
|
80
|
-
declKind = "varAssign";
|
|
108
|
+
if (/^function\b/.test(snippet)) declKind = "functionDecl";
|
|
109
|
+
else if (/^class\b/.test(snippet)) declKind = "classDecl";
|
|
110
|
+
else if (/^\b(?:const|let|var)\b/.test(snippet)) declKind = "varAssign";
|
|
81
111
|
}
|
|
82
112
|
let newCode;
|
|
83
113
|
if (typeof code === "function") {
|
|
84
114
|
const fnStr = code.toString();
|
|
85
115
|
if (declKind === "functionDecl") {
|
|
86
|
-
if (/^function\s+\w+/.test(fnStr))
|
|
87
|
-
newCode = fnStr;
|
|
116
|
+
if (/^function\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
88
117
|
else
|
|
89
|
-
newCode = `function ${fnName}${fnStr.replace(
|
|
118
|
+
newCode = `function ${fnName}${fnStr.replace(
|
|
119
|
+
/^function\s*\(/,
|
|
120
|
+
"("
|
|
121
|
+
)}`;
|
|
90
122
|
} else if (declKind === "classDecl") {
|
|
91
|
-
if (/^class\s+\w+/.test(fnStr))
|
|
92
|
-
newCode = fnStr;
|
|
123
|
+
if (/^class\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
93
124
|
else if (/^class\s*\{/.test(fnStr))
|
|
94
125
|
newCode = fnStr.replace(/^class\s*\{/, `class ${fnName} {`);
|
|
95
|
-
else
|
|
96
|
-
newCode = `const ${fnName} = ${fnStr};`;
|
|
126
|
+
else newCode = `const ${fnName} = ${fnStr};`;
|
|
97
127
|
} else {
|
|
98
128
|
newCode = `const ${fnName} = ${fnStr};`;
|
|
99
129
|
}
|
|
@@ -105,18 +135,21 @@ function update(dbName, fnName, code) {
|
|
|
105
135
|
const idxCurly = src.indexOf("{", startIdx);
|
|
106
136
|
const idxBracket = src.indexOf("[", startIdx);
|
|
107
137
|
let braceOpen = -1;
|
|
108
|
-
if (idxCurly === -1)
|
|
109
|
-
|
|
110
|
-
else
|
|
111
|
-
braceOpen = idxCurly;
|
|
112
|
-
else
|
|
113
|
-
braceOpen = Math.min(idxCurly, idxBracket);
|
|
138
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
139
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
140
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
114
141
|
if (braceOpen === -1) {
|
|
115
|
-
const exportRe = new RegExp(
|
|
142
|
+
const exportRe = new RegExp(
|
|
143
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
144
|
+
"m"
|
|
145
|
+
);
|
|
116
146
|
if (exportRe.test(src)) {
|
|
117
|
-
src = src.replace(
|
|
147
|
+
src = src.replace(
|
|
148
|
+
exportRe,
|
|
149
|
+
`${newCode}
|
|
118
150
|
|
|
119
|
-
export const ${fnName}: any = ${fnName};`
|
|
151
|
+
export const ${fnName}: any = ${fnName};`
|
|
152
|
+
);
|
|
120
153
|
} else {
|
|
121
154
|
src = src + `
|
|
122
155
|
|
|
@@ -132,10 +165,8 @@ export const ${fnName}: any = ${fnName};`;
|
|
|
132
165
|
const len = src.length;
|
|
133
166
|
while (i < len && depth > 0) {
|
|
134
167
|
const ch = src[i];
|
|
135
|
-
if (ch === openingChar)
|
|
136
|
-
|
|
137
|
-
else if (ch === closingChar)
|
|
138
|
-
depth--;
|
|
168
|
+
if (ch === openingChar) depth++;
|
|
169
|
+
else if (ch === closingChar) depth--;
|
|
139
170
|
i++;
|
|
140
171
|
}
|
|
141
172
|
let braceClose = i;
|
|
@@ -147,11 +178,17 @@ export const ${fnName}: any = ${fnName};`;
|
|
|
147
178
|
src = before + newCode + after;
|
|
148
179
|
}
|
|
149
180
|
} else {
|
|
150
|
-
const exportRe = new RegExp(
|
|
181
|
+
const exportRe = new RegExp(
|
|
182
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
183
|
+
"m"
|
|
184
|
+
);
|
|
151
185
|
if (exportRe.test(src)) {
|
|
152
|
-
src = src.replace(
|
|
186
|
+
src = src.replace(
|
|
187
|
+
exportRe,
|
|
188
|
+
`${newCode}
|
|
153
189
|
|
|
154
|
-
export const ${fnName}: any = ${fnName};`
|
|
190
|
+
export const ${fnName}: any = ${fnName};`
|
|
191
|
+
);
|
|
155
192
|
} else {
|
|
156
193
|
src = src + `
|
|
157
194
|
|
|
@@ -160,7 +197,7 @@ ${newCode}
|
|
|
160
197
|
export const ${fnName}: any = ${fnName};`;
|
|
161
198
|
}
|
|
162
199
|
}
|
|
163
|
-
|
|
200
|
+
import_node_fs.default.writeFileSync(dbPath, src, "utf8");
|
|
164
201
|
if (src === originalSrc) {
|
|
165
202
|
return `Saved ${fnName} to database ${dbName}.`;
|
|
166
203
|
} else {
|
|
@@ -169,23 +206,23 @@ export const ${fnName}: any = ${fnName};`;
|
|
|
169
206
|
}
|
|
170
207
|
|
|
171
208
|
// src/modules/remove.ts
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
209
|
+
var import_node_path2 = __toESM(require("path"));
|
|
210
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
211
|
+
var os2 = __toESM(require("os"));
|
|
175
212
|
function remove(dbName, fnName) {
|
|
176
213
|
const DIR = "databases";
|
|
177
|
-
const basePath =
|
|
178
|
-
const baseDir =
|
|
179
|
-
const dbPath =
|
|
180
|
-
if (!
|
|
181
|
-
return false;
|
|
214
|
+
const basePath = import_node_path2.default.join(os2.homedir(), ".scriptdb");
|
|
215
|
+
const baseDir = import_node_path2.default.resolve(basePath, DIR);
|
|
216
|
+
const dbPath = import_node_path2.default.join(baseDir, `${dbName}.ts`);
|
|
217
|
+
if (!import_node_fs2.default.existsSync(dbPath)) return false;
|
|
182
218
|
if (!fnName) {
|
|
183
219
|
const bak2 = `${dbPath}.bak`;
|
|
184
220
|
try {
|
|
185
|
-
|
|
186
|
-
} catch (e) {
|
|
221
|
+
import_node_fs2.default.copyFileSync(dbPath, bak2);
|
|
222
|
+
} catch (e) {
|
|
223
|
+
}
|
|
187
224
|
try {
|
|
188
|
-
|
|
225
|
+
import_node_fs2.default.unlinkSync(dbPath);
|
|
189
226
|
return "Removed successfully";
|
|
190
227
|
} catch (e) {
|
|
191
228
|
return "Removed failed";
|
|
@@ -193,11 +230,15 @@ function remove(dbName, fnName) {
|
|
|
193
230
|
}
|
|
194
231
|
const bak = `${dbPath}.bak`;
|
|
195
232
|
try {
|
|
196
|
-
|
|
197
|
-
} catch (e) {
|
|
198
|
-
|
|
233
|
+
import_node_fs2.default.copyFileSync(dbPath, bak);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
}
|
|
236
|
+
let src = import_node_fs2.default.readFileSync(dbPath, "utf8");
|
|
199
237
|
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
200
|
-
const startRe = new RegExp(
|
|
238
|
+
const startRe = new RegExp(
|
|
239
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
240
|
+
"m"
|
|
241
|
+
);
|
|
201
242
|
const startMatch = src.match(startRe);
|
|
202
243
|
if (startMatch) {
|
|
203
244
|
const startIdx = startMatch.index;
|
|
@@ -205,12 +246,9 @@ function remove(dbName, fnName) {
|
|
|
205
246
|
const idxCurly = src.indexOf("{", startIdx);
|
|
206
247
|
const idxBracket = src.indexOf("[", startIdx);
|
|
207
248
|
let braceOpen = -1;
|
|
208
|
-
if (idxCurly === -1)
|
|
209
|
-
|
|
210
|
-
else
|
|
211
|
-
braceOpen = idxCurly;
|
|
212
|
-
else
|
|
213
|
-
braceOpen = Math.min(idxCurly, idxBracket);
|
|
249
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
250
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
251
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
214
252
|
if (braceOpen !== -1) {
|
|
215
253
|
const openingChar = src[braceOpen];
|
|
216
254
|
const closingChar = openingChar === "[" ? "]" : "}";
|
|
@@ -218,10 +256,8 @@ function remove(dbName, fnName) {
|
|
|
218
256
|
let depth = 1;
|
|
219
257
|
while (i < len && depth > 0) {
|
|
220
258
|
const ch = src[i];
|
|
221
|
-
if (ch === openingChar)
|
|
222
|
-
|
|
223
|
-
else if (ch === closingChar)
|
|
224
|
-
depth--;
|
|
259
|
+
if (ch === openingChar) depth++;
|
|
260
|
+
else if (ch === closingChar) depth--;
|
|
225
261
|
i++;
|
|
226
262
|
}
|
|
227
263
|
let braceClose = i;
|
|
@@ -233,39 +269,37 @@ function remove(dbName, fnName) {
|
|
|
233
269
|
src = before + after;
|
|
234
270
|
} else {
|
|
235
271
|
const semi = src.indexOf(";", startIdx);
|
|
236
|
-
let endIdx = semi !== -1 ? semi + 1 : src.indexOf(
|
|
237
|
-
|
|
238
|
-
`, startIdx);
|
|
239
|
-
if (endIdx === -1)
|
|
240
|
-
endIdx = len;
|
|
272
|
+
let endIdx = semi !== -1 ? semi + 1 : src.indexOf("\n\n", startIdx);
|
|
273
|
+
if (endIdx === -1) endIdx = len;
|
|
241
274
|
src = src.slice(0, startIdx) + src.slice(endIdx);
|
|
242
275
|
}
|
|
243
276
|
}
|
|
244
|
-
const exportRe = new RegExp(
|
|
277
|
+
const exportRe = new RegExp(
|
|
278
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
279
|
+
"g"
|
|
280
|
+
);
|
|
245
281
|
src = src.replace(exportRe, "");
|
|
246
|
-
src = src.replace(/\n{3,}/g,
|
|
247
|
-
|
|
248
|
-
`);
|
|
249
|
-
fs2.writeFileSync(dbPath, src, "utf8");
|
|
282
|
+
src = src.replace(/\n{3,}/g, "\n\n");
|
|
283
|
+
import_node_fs2.default.writeFileSync(dbPath, src, "utf8");
|
|
250
284
|
return `Removed ${fnName} from database ${dbName}.`;
|
|
251
285
|
}
|
|
252
286
|
|
|
253
287
|
// src/modules/create.ts
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
288
|
+
var import_node_fs3 = __toESM(require("fs"));
|
|
289
|
+
var import_node_path3 = __toESM(require("path"));
|
|
290
|
+
var os3 = __toESM(require("os"));
|
|
257
291
|
function create(dbName, code) {
|
|
258
292
|
const DIR = "databases";
|
|
259
|
-
const basePath =
|
|
260
|
-
const baseDir =
|
|
261
|
-
const dbPath =
|
|
262
|
-
|
|
293
|
+
const basePath = import_node_path3.default.join(os3.homedir(), ".scriptdb");
|
|
294
|
+
const baseDir = import_node_path3.default.resolve(basePath, DIR);
|
|
295
|
+
const dbPath = import_node_path3.default.join(baseDir, `${dbName}.ts`);
|
|
296
|
+
import_node_fs3.default.appendFileSync(dbPath, code.toString(), "utf8");
|
|
263
297
|
}
|
|
264
298
|
|
|
265
299
|
// src/modules/save.ts
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
300
|
+
var fs4 = __toESM(require("fs"));
|
|
301
|
+
var path4 = __toESM(require("path"));
|
|
302
|
+
var os4 = __toESM(require("os"));
|
|
269
303
|
function save(dbName, code) {
|
|
270
304
|
const DIR = "databases";
|
|
271
305
|
const basePath = path4.join(os4.homedir(), ".scriptdb");
|
|
@@ -276,9 +310,9 @@ function save(dbName, code) {
|
|
|
276
310
|
}
|
|
277
311
|
|
|
278
312
|
// src/modules/read.ts
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
313
|
+
var fs5 = __toESM(require("fs"));
|
|
314
|
+
var path5 = __toESM(require("path"));
|
|
315
|
+
var os5 = __toESM(require("os"));
|
|
282
316
|
function read(dbName) {
|
|
283
317
|
const DIR = "databases";
|
|
284
318
|
const basePath = path5.join(os5.homedir(), ".scriptdb");
|
|
@@ -297,27 +331,29 @@ var create2 = create;
|
|
|
297
331
|
var save2 = save;
|
|
298
332
|
var read2 = read;
|
|
299
333
|
async function SystemModuleResolver() {
|
|
300
|
-
const moduleRegistry = new Map;
|
|
334
|
+
const moduleRegistry = /* @__PURE__ */ new Map();
|
|
301
335
|
moduleRegistry.set("update", update2);
|
|
302
336
|
moduleRegistry.set("remove", remove2);
|
|
303
337
|
moduleRegistry.set("create", create2);
|
|
304
338
|
moduleRegistry.set("save", save2);
|
|
305
339
|
moduleRegistry.set("read", read2);
|
|
306
340
|
const context = {
|
|
341
|
+
// Add require-like functionality
|
|
307
342
|
require: (moduleName) => {
|
|
308
|
-
const
|
|
309
|
-
if (!
|
|
343
|
+
const module2 = moduleRegistry.get(moduleName);
|
|
344
|
+
if (!module2) {
|
|
310
345
|
throw new Error(`Module '${moduleName}' not found`);
|
|
311
346
|
}
|
|
312
|
-
return
|
|
347
|
+
return module2.default || module2;
|
|
313
348
|
},
|
|
349
|
+
// Add import functionality (simulated)
|
|
314
350
|
import: async (moduleName) => {
|
|
315
|
-
const
|
|
316
|
-
if (!
|
|
351
|
+
const module2 = moduleRegistry.get(moduleName);
|
|
352
|
+
if (!module2) {
|
|
317
353
|
throw new Error(`Module '${moduleName}' not found`);
|
|
318
354
|
}
|
|
319
355
|
return {
|
|
320
|
-
default:
|
|
356
|
+
default: module2.default || module2
|
|
321
357
|
};
|
|
322
358
|
}
|
|
323
359
|
};
|
|
@@ -326,13 +362,14 @@ async function SystemModuleResolver() {
|
|
|
326
362
|
}
|
|
327
363
|
return context;
|
|
328
364
|
}
|
|
329
|
-
var
|
|
330
|
-
export
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
};
|
|
365
|
+
var index_default = SystemModuleResolver;
|
|
366
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
367
|
+
0 && (module.exports = {
|
|
368
|
+
SystemModuleResolver,
|
|
369
|
+
create,
|
|
370
|
+
read,
|
|
371
|
+
remove,
|
|
372
|
+
save,
|
|
373
|
+
update
|
|
374
|
+
});
|
|
375
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/modules/update.ts","../src/utils/isIdentifier.ts","../src/utils/valueToCode.ts","../src/modules/remove.ts","../src/modules/create.ts","../src/modules/save.ts","../src/modules/read.ts"],"sourcesContent":["import { update as updateModule } from './modules/update';\nimport { remove as removeModule } from './modules/remove';\nimport { create as createModule } from './modules/create';\nimport { save as createsaveModule } from './modules/save';\nimport { read as readModule } from './modules/read';\n\nexport const update = updateModule;\nexport const remove = removeModule;\nexport const create = createModule;\nexport const save = createsaveModule;\nexport const read = readModule;\n\nexport async function SystemModuleResolver() {\n\n const moduleRegistry = new Map<string, any>();\n\n moduleRegistry.set(\"update\", update);\n moduleRegistry.set(\"remove\", remove);\n moduleRegistry.set(\"create\", create);\n moduleRegistry.set(\"save\", save);\n moduleRegistry.set(\"read\", read);\n\n const context: Record<string, any> = {\n // Add require-like functionality\n require: (moduleName: string) => {\n const module = moduleRegistry.get(moduleName);\n if (!module) {\n throw new Error(`Module '${moduleName}' not found`);\n }\n // Return the default export if available, otherwise the module itself\n return module.default || module;\n },\n\n // Add import functionality (simulated)\n import: async (moduleName: string) => {\n const module = moduleRegistry.get(moduleName);\n if (!module) {\n throw new Error(`Module '${moduleName}' not found`);\n }\n return {\n default: module.default || module\n };\n }\n };\n\n for (const [name, moduleExports] of moduleRegistry) {\n context[name] = moduleExports.default || moduleExports;\n }\n\n return context;\n}\n\nexport default SystemModuleResolver;","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as os from \"os\";\nimport { valueToCode } from \"../utils/valueToCode\";\n\nexport function update(dbName: string, fnName: string, code: string | Function) {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต\n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n let src;\n\n if (!fs.existsSync(dbPath)) {\n // If dbPath doesn't exist, create an empty module file so we can insert into it.\n try {\n fs.writeFileSync(dbPath, \"\", \"utf8\");\n // console.log(\"Created new database file:\", dbPath);\n return `Created new database file: ${dbPath}`;\n } catch (e) {\n // console.error(\"Failed to create dbPath file:\", dbPath, e && e.message ? e.message : e);\n return `Failed to create dbPath file: ${dbPath}`;\n }\n }\n\n src = fs.readFileSync(dbPath, \"utf8\");\n\n const originalSrc = src;\n\n const escaped = fnName.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, \"\\\\$&\");\n const startRe = new RegExp(\n `function\\\\s+${escaped}\\\\s*\\\\(|\\\\bclass\\\\s+${escaped}\\\\b|\\\\b(?:const|let|var)\\\\s+${escaped}\\\\s*=\\\\s*(?:function\\\\b|class\\\\b|\\\\(|\\\\{|\\\\[)`,\n \"m\"\n );\n const startMatch = src.match(startRe);\n\n // determine declKind in the current file (if present)\n let declKind = null;\n\n if (startMatch) {\n let startIdx: any = startMatch.index;\n const snippet = src.slice(startIdx, startIdx + 80);\n if (/^function\\b/.test(snippet)) declKind = \"functionDecl\";\n else if (/^class\\b/.test(snippet)) declKind = \"classDecl\";\n else if (/^\\b(?:const|let|var)\\b/.test(snippet)) declKind = \"varAssign\";\n }\n\n // build replacement code for this value\n let newCode;\n if (typeof code === \"function\") {\n const fnStr = code.toString();\n // prefer const assignment for anonymous functions/classes or arrow functions\n if (declKind === \"functionDecl\") {\n if (/^function\\s+\\w+/.test(fnStr)) newCode = fnStr;\n else\n newCode = `function ${fnName}${fnStr.replace(\n /^function\\s*\\(/,\n \"(\"\n )}`;\n } else if (declKind === \"classDecl\") {\n if (/^class\\s+\\w+/.test(fnStr)) newCode = fnStr;\n else if (/^class\\s*\\{/.test(fnStr))\n newCode = fnStr.replace(/^class\\s*\\{/, `class ${fnName} {`);\n else newCode = `const ${fnName} = ${fnStr};`;\n } else {\n newCode = `const ${fnName} = ${fnStr};`;\n }\n } else {\n newCode = `const ${fnName} = ${valueToCode(code, 0)};`;\n }\n\n // replacement: if found startMatch, find block and replace between startIdx and endIdx\n if (startMatch) {\n const startIdx = startMatch.index;\n // find first '{' or '[' after startIdx\n const idxCurly = src.indexOf(\"{\", startIdx);\n const idxBracket = src.indexOf(\"[\", startIdx);\n let braceOpen = -1;\n if (idxCurly === -1) braceOpen = idxBracket;\n else if (idxBracket === -1) braceOpen = idxCurly;\n else braceOpen = Math.min(idxCurly, idxBracket);\n\n if (braceOpen === -1) {\n // no block — fallback: replace export or append\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"m\"\n );\n if (exportRe.test(src)) {\n src = src.replace(\n exportRe,\n `${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`\n );\n } else {\n src =\n src + `\\n\\n${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`;\n }\n } else {\n const openingChar = src[braceOpen];\n const closingChar = openingChar === \"[\" ? \"]\" : \"}\";\n let i = braceOpen + 1;\n let depth = 1;\n const len = src.length;\n while (i < len && depth > 0) {\n const ch = src[i];\n if (ch === openingChar) depth++;\n else if (ch === closingChar) depth--;\n i++;\n }\n let braceClose = i;\n let endIdx = braceClose;\n if (src.slice(braceClose, braceClose + 1) === \";\")\n endIdx = braceClose + 1;\n\n const before = src.slice(0, startIdx);\n const after = src.slice(endIdx);\n src = before + newCode + after;\n }\n } else {\n // not found — try to insert before existing export or append\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"m\"\n );\n if (exportRe.test(src)) {\n src = src.replace(\n exportRe,\n `${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`\n );\n } else {\n src =\n src + `\\n\\n${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`;\n }\n }\n\n fs.writeFileSync(dbPath, src, \"utf8\");\n\n if (src === originalSrc) {\n return `Saved ${fnName} to database ${dbName}.`;\n } else {\n return `Updated ${dbName} with ${fnName}.`;\n }\n}\n","export function isIdentifier(key: any) {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);\n}","import { isIdentifier } from \"./isIdentifier\";\n\nexport function valueToCode(val: any, depth: number = 0): string {\n const indentUnit = \" \";\n const indent = indentUnit.repeat(depth);\n const indentInner = indentUnit.repeat(depth + 1);\n\n if (val === null) return \"null\";\n const t = typeof val;\n if (t === \"string\") return JSON.stringify(val);\n if (t === \"number\" || t === \"boolean\") return String(val);\n if (t === \"function\") return val.toString();\n if (Array.isArray(val)) {\n if (val.length === 0) return \"[]\";\n const items = val.map((v) => valueToCode(v, depth + 1));\n return (\n \"[\\n\" +\n items.map((it) => indentInner + it).join(\",\\n\") +\n \"\\n\" +\n indent +\n \"]\"\n );\n }\n if (t === \"object\") {\n const keys = Object.keys(val);\n if (keys.length === 0) return \"{}\";\n const entries = keys.map((k) => {\n const keyPart = isIdentifier(k) ? k : JSON.stringify(k);\n const v = valueToCode(val[k], depth + 1);\n return indentInner + keyPart + \": \" + v;\n });\n return \"{\\n\" + entries.join(\",\\n\") + \"\\n\" + indent + \"}\";\n }\n return String(val);\n}","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as os from \"os\";\n\nexport function remove(dbName: string, fnName: string) {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n if (!fs.existsSync(dbPath)) return false;\n\n // if no functionName provided -> remove the whole file (after backup)\n if (!fnName) {\n const bak = `${dbPath}.bak`;\n try {\n fs.copyFileSync(dbPath, bak);\n } catch (e) {\n // ignore backup errors\n }\n try {\n fs.unlinkSync(dbPath);\n return \"Removed successfully\";\n } catch (e) {\n return \"Removed failed\";\n }\n }\n\n // create a backup before editing the file in-place\n const bak = `${dbPath}.bak`;\n try {\n fs.copyFileSync(dbPath, bak);\n } catch (e) {\n // ignore backup errors but continue carefully\n }\n\n let src = fs.readFileSync(dbPath, \"utf8\");\n const escaped = fnName.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, \"\\\\$&\");\n\n // regex to find a declaration of the named symbol (function, class, or var/const/let assignment)\n const startRe = new RegExp(\n `function\\\\s+${escaped}\\\\s*\\\\(|\\\\bclass\\\\s+${escaped}\\\\b|\\\\b(?:const|let|var)\\\\s+${escaped}\\\\s*=\\\\s*(?:function\\\\b|class\\\\b|\\\\(|\\\\{|\\\\[)`,\n \"m\"\n );\n\n const startMatch = src.match(startRe);\n\n if (startMatch) {\n const startIdx = startMatch.index;\n\n // find the first meaningful character after startIdx: {, [, or ; or newline\n const len = src.length;\n const idxCurly = src.indexOf(\"{\", startIdx);\n const idxBracket = src.indexOf(\"[\", startIdx);\n let braceOpen = -1;\n if (idxCurly === -1) braceOpen = idxBracket;\n else if (idxBracket === -1) braceOpen = idxCurly;\n else braceOpen = Math.min(idxCurly, idxBracket);\n\n if (braceOpen !== -1) {\n const openingChar = src[braceOpen];\n const closingChar = openingChar === \"[\" ? \"]\" : \"}\";\n let i = braceOpen + 1;\n let depth = 1;\n while (i < len && depth > 0) {\n const ch = src[i];\n if (ch === openingChar) depth++;\n else if (ch === closingChar) depth--;\n i++;\n }\n let braceClose = i;\n let endIdx = braceClose;\n if (src.slice(braceClose, braceClose + 1) === \";\")\n endIdx = braceClose + 1;\n\n const before = src.slice(0, startIdx);\n const after = src.slice(endIdx);\n src = before + after;\n } else {\n // fallback: remove until next semicolon or a blank line\n const semi = src.indexOf(\";\", startIdx);\n let endIdx = semi !== -1 ? semi + 1 : src.indexOf(\"\\n\\n\", startIdx);\n if (endIdx === -1) endIdx = len;\n src = src.slice(0, startIdx) + src.slice(endIdx);\n }\n }\n\n // remove any export const <name>: any = <name>; lines\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"g\"\n );\n src = src.replace(exportRe, \"\");\n\n // tidy up multiple blank lines\n src = src.replace(/\\n{3,}/g, \"\\n\\n\");\n\n fs.writeFileSync(dbPath, src, \"utf8\");\n\n return `Removed ${fnName} from database ${dbName}.`;\n}","// create.ts\n// Module for creating new code snippets in the system-modules database\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport * as os from \"os\";\n/**\n * Creates a new code snippet in the specified database file.\n * @param dbName Name of the database file (without extension)\n * @param code Code content of the snippet\n */\nexport function create(dbName: string, code: string | Function): void {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n // Prepare the export line\n fs.appendFileSync(dbPath, code.toString(), 'utf8');\n}\n\n/**\n * Example usage:\n * create('myDatabase', 'function myFunc() { return 42; }');\n */\n","// update.ts\n// Module for updating existing code snippets in the system-modules database\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from \"os\";\n\n/**\n * Updates an existing code snippet in the specified database file.\n * If the snippet does not exist, it will be created.\n * @param dbFilePath Absolute path to the database file\n * @param name Name of the snippet\n * @param code New code content of the snippet\n */\nexport function save(dbName: string, code: string | Function | any): void {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n let fileContent = typeof code === 'function' ? code.toString() : code;\n\n fs.writeFileSync(dbPath, fileContent, 'utf8');\n}\n\n/**\n * Example usage:\n * updateSnippet('path/to/db.ts', 'myFunc', 'function myFunc() { return 99; }');\n */\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\n\n/**\n * Read database file content\n * @param dbName - Database name (without .ts extension)\n * @returns File content as string\n */\nexport function read(dbName: string): string {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR);\n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n if (!fs.existsSync(dbPath)) {\n throw new Error(`Database '${dbName}' not found`);\n }\n\n return fs.readFileSync(dbPath, 'utf8');\n}\n\nexport default read;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA,cAAAC;AAAA,EAAA,cAAAC;AAAA,EAAA,YAAAC;AAAA,EAAA,cAAAC;AAAA;AAAA;;;ACAA,uBAAiB;AACjB,qBAAe;AACf,SAAoB;;;ACFb,SAAS,aAAa,KAAU;AACnC,SAAO,6BAA6B,KAAK,GAAG;AAChD;;;ACAO,SAAS,YAAY,KAAU,QAAgB,GAAW;AAC7D,QAAM,aAAa;AACnB,QAAM,SAAS,WAAW,OAAO,KAAK;AACtC,QAAM,cAAc,WAAW,OAAO,QAAQ,CAAC;AAE/C,MAAI,QAAQ,KAAM,QAAO;AACzB,QAAM,IAAI,OAAO;AACjB,MAAI,MAAM,SAAU,QAAO,KAAK,UAAU,GAAG;AAC7C,MAAI,MAAM,YAAY,MAAM,UAAW,QAAO,OAAO,GAAG;AACxD,MAAI,MAAM,WAAY,QAAO,IAAI,SAAS;AAC1C,MAAI,MAAM,QAAQ,GAAG,GAAG;AACpB,QAAI,IAAI,WAAW,EAAG,QAAO;AAC7B,UAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,CAAC;AACtD,WACI,QACA,MAAM,IAAI,CAAC,OAAO,cAAc,EAAE,EAAE,KAAK,KAAK,IAC9C,OACA,SACA;AAAA,EAER;AACA,MAAI,MAAM,UAAU;AAChB,UAAM,OAAO,OAAO,KAAK,GAAG;AAC5B,QAAI,KAAK,WAAW,EAAG,QAAO;AAC9B,UAAM,UAAU,KAAK,IAAI,CAAC,MAAM;AAC5B,YAAM,UAAU,aAAa,CAAC,IAAI,IAAI,KAAK,UAAU,CA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tD;AACA,aAAO;AAAA,QACH,SAASA,QAAO,WAAWA;AAAA,MAC/B;AAAA,IACJ;AAAA,EACJ;AAEA,aAAW,CAAC,MAAM,aAAa,KAAK,gBAAgB;AAChD,YAAQ,IAAI,IAAI,cAAc,WAAW;AAAA,EAC7C;AAEA,SAAO;AACX;AAEA,IAAO,gBAAQ;","names":["create","read","remove","save","update","path","fs","import_node_path","import_node_fs","os","path","fs","bak","import_node_fs","import_node_path","os","path","fs","fs","path","os","fs","path","os","update","remove","create","save","read","module"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// src/modules/update.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
|
|
6
|
+
// src/utils/isIdentifier.ts
|
|
7
|
+
function isIdentifier(key) {
|
|
8
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/utils/valueToCode.ts
|
|
12
|
+
function valueToCode(val, depth = 0) {
|
|
13
|
+
const indentUnit = " ";
|
|
14
|
+
const indent = indentUnit.repeat(depth);
|
|
15
|
+
const indentInner = indentUnit.repeat(depth + 1);
|
|
16
|
+
if (val === null) return "null";
|
|
17
|
+
const t = typeof val;
|
|
18
|
+
if (t === "string") return JSON.stringify(val);
|
|
19
|
+
if (t === "number" || t === "boolean") return String(val);
|
|
20
|
+
if (t === "function") return val.toString();
|
|
21
|
+
if (Array.isArray(val)) {
|
|
22
|
+
if (val.length === 0) return "[]";
|
|
23
|
+
const items = val.map((v) => valueToCode(v, depth + 1));
|
|
24
|
+
return "[\n" + items.map((it) => indentInner + it).join(",\n") + "\n" + indent + "]";
|
|
25
|
+
}
|
|
26
|
+
if (t === "object") {
|
|
27
|
+
const keys = Object.keys(val);
|
|
28
|
+
if (keys.length === 0) return "{}";
|
|
29
|
+
const entries = keys.map((k) => {
|
|
30
|
+
const keyPart = isIdentifier(k) ? k : JSON.stringify(k);
|
|
31
|
+
const v = valueToCode(val[k], depth + 1);
|
|
32
|
+
return indentInner + keyPart + ": " + v;
|
|
33
|
+
});
|
|
34
|
+
return "{\n" + entries.join(",\n") + "\n" + indent + "}";
|
|
35
|
+
}
|
|
36
|
+
return String(val);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/modules/update.ts
|
|
40
|
+
function update(dbName, fnName, code) {
|
|
41
|
+
const DIR = "databases";
|
|
42
|
+
const basePath = path.join(os.homedir(), ".scriptdb");
|
|
43
|
+
const baseDir = path.resolve(basePath, DIR);
|
|
44
|
+
const dbPath = path.join(baseDir, `${dbName}.ts`);
|
|
45
|
+
let src;
|
|
46
|
+
if (!fs.existsSync(dbPath)) {
|
|
47
|
+
try {
|
|
48
|
+
fs.writeFileSync(dbPath, "", "utf8");
|
|
49
|
+
return `Created new database file: ${dbPath}`;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return `Failed to create dbPath file: ${dbPath}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
src = fs.readFileSync(dbPath, "utf8");
|
|
55
|
+
const originalSrc = src;
|
|
56
|
+
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
57
|
+
const startRe = new RegExp(
|
|
58
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
59
|
+
"m"
|
|
60
|
+
);
|
|
61
|
+
const startMatch = src.match(startRe);
|
|
62
|
+
let declKind = null;
|
|
63
|
+
if (startMatch) {
|
|
64
|
+
let startIdx = startMatch.index;
|
|
65
|
+
const snippet = src.slice(startIdx, startIdx + 80);
|
|
66
|
+
if (/^function\b/.test(snippet)) declKind = "functionDecl";
|
|
67
|
+
else if (/^class\b/.test(snippet)) declKind = "classDecl";
|
|
68
|
+
else if (/^\b(?:const|let|var)\b/.test(snippet)) declKind = "varAssign";
|
|
69
|
+
}
|
|
70
|
+
let newCode;
|
|
71
|
+
if (typeof code === "function") {
|
|
72
|
+
const fnStr = code.toString();
|
|
73
|
+
if (declKind === "functionDecl") {
|
|
74
|
+
if (/^function\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
75
|
+
else
|
|
76
|
+
newCode = `function ${fnName}${fnStr.replace(
|
|
77
|
+
/^function\s*\(/,
|
|
78
|
+
"("
|
|
79
|
+
)}`;
|
|
80
|
+
} else if (declKind === "classDecl") {
|
|
81
|
+
if (/^class\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
82
|
+
else if (/^class\s*\{/.test(fnStr))
|
|
83
|
+
newCode = fnStr.replace(/^class\s*\{/, `class ${fnName} {`);
|
|
84
|
+
else newCode = `const ${fnName} = ${fnStr};`;
|
|
85
|
+
} else {
|
|
86
|
+
newCode = `const ${fnName} = ${fnStr};`;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
newCode = `const ${fnName} = ${valueToCode(code, 0)};`;
|
|
90
|
+
}
|
|
91
|
+
if (startMatch) {
|
|
92
|
+
const startIdx = startMatch.index;
|
|
93
|
+
const idxCurly = src.indexOf("{", startIdx);
|
|
94
|
+
const idxBracket = src.indexOf("[", startIdx);
|
|
95
|
+
let braceOpen = -1;
|
|
96
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
97
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
98
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
99
|
+
if (braceOpen === -1) {
|
|
100
|
+
const exportRe = new RegExp(
|
|
101
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
102
|
+
"m"
|
|
103
|
+
);
|
|
104
|
+
if (exportRe.test(src)) {
|
|
105
|
+
src = src.replace(
|
|
106
|
+
exportRe,
|
|
107
|
+
`${newCode}
|
|
108
|
+
|
|
109
|
+
export const ${fnName}: any = ${fnName};`
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
src = src + `
|
|
113
|
+
|
|
114
|
+
${newCode}
|
|
115
|
+
|
|
116
|
+
export const ${fnName}: any = ${fnName};`;
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
const openingChar = src[braceOpen];
|
|
120
|
+
const closingChar = openingChar === "[" ? "]" : "}";
|
|
121
|
+
let i = braceOpen + 1;
|
|
122
|
+
let depth = 1;
|
|
123
|
+
const len = src.length;
|
|
124
|
+
while (i < len && depth > 0) {
|
|
125
|
+
const ch = src[i];
|
|
126
|
+
if (ch === openingChar) depth++;
|
|
127
|
+
else if (ch === closingChar) depth--;
|
|
128
|
+
i++;
|
|
129
|
+
}
|
|
130
|
+
let braceClose = i;
|
|
131
|
+
let endIdx = braceClose;
|
|
132
|
+
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
133
|
+
endIdx = braceClose + 1;
|
|
134
|
+
const before = src.slice(0, startIdx);
|
|
135
|
+
const after = src.slice(endIdx);
|
|
136
|
+
src = before + newCode + after;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
const exportRe = new RegExp(
|
|
140
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
141
|
+
"m"
|
|
142
|
+
);
|
|
143
|
+
if (exportRe.test(src)) {
|
|
144
|
+
src = src.replace(
|
|
145
|
+
exportRe,
|
|
146
|
+
`${newCode}
|
|
147
|
+
|
|
148
|
+
export const ${fnName}: any = ${fnName};`
|
|
149
|
+
);
|
|
150
|
+
} else {
|
|
151
|
+
src = src + `
|
|
152
|
+
|
|
153
|
+
${newCode}
|
|
154
|
+
|
|
155
|
+
export const ${fnName}: any = ${fnName};`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
fs.writeFileSync(dbPath, src, "utf8");
|
|
159
|
+
if (src === originalSrc) {
|
|
160
|
+
return `Saved ${fnName} to database ${dbName}.`;
|
|
161
|
+
} else {
|
|
162
|
+
return `Updated ${dbName} with ${fnName}.`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/modules/remove.ts
|
|
167
|
+
import path2 from "path";
|
|
168
|
+
import fs2 from "fs";
|
|
169
|
+
import * as os2 from "os";
|
|
170
|
+
function remove(dbName, fnName) {
|
|
171
|
+
const DIR = "databases";
|
|
172
|
+
const basePath = path2.join(os2.homedir(), ".scriptdb");
|
|
173
|
+
const baseDir = path2.resolve(basePath, DIR);
|
|
174
|
+
const dbPath = path2.join(baseDir, `${dbName}.ts`);
|
|
175
|
+
if (!fs2.existsSync(dbPath)) return false;
|
|
176
|
+
if (!fnName) {
|
|
177
|
+
const bak2 = `${dbPath}.bak`;
|
|
178
|
+
try {
|
|
179
|
+
fs2.copyFileSync(dbPath, bak2);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
fs2.unlinkSync(dbPath);
|
|
184
|
+
return "Removed successfully";
|
|
185
|
+
} catch (e) {
|
|
186
|
+
return "Removed failed";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const bak = `${dbPath}.bak`;
|
|
190
|
+
try {
|
|
191
|
+
fs2.copyFileSync(dbPath, bak);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
}
|
|
194
|
+
let src = fs2.readFileSync(dbPath, "utf8");
|
|
195
|
+
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
196
|
+
const startRe = new RegExp(
|
|
197
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
198
|
+
"m"
|
|
199
|
+
);
|
|
200
|
+
const startMatch = src.match(startRe);
|
|
201
|
+
if (startMatch) {
|
|
202
|
+
const startIdx = startMatch.index;
|
|
203
|
+
const len = src.length;
|
|
204
|
+
const idxCurly = src.indexOf("{", startIdx);
|
|
205
|
+
const idxBracket = src.indexOf("[", startIdx);
|
|
206
|
+
let braceOpen = -1;
|
|
207
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
208
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
209
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
210
|
+
if (braceOpen !== -1) {
|
|
211
|
+
const openingChar = src[braceOpen];
|
|
212
|
+
const closingChar = openingChar === "[" ? "]" : "}";
|
|
213
|
+
let i = braceOpen + 1;
|
|
214
|
+
let depth = 1;
|
|
215
|
+
while (i < len && depth > 0) {
|
|
216
|
+
const ch = src[i];
|
|
217
|
+
if (ch === openingChar) depth++;
|
|
218
|
+
else if (ch === closingChar) depth--;
|
|
219
|
+
i++;
|
|
220
|
+
}
|
|
221
|
+
let braceClose = i;
|
|
222
|
+
let endIdx = braceClose;
|
|
223
|
+
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
224
|
+
endIdx = braceClose + 1;
|
|
225
|
+
const before = src.slice(0, startIdx);
|
|
226
|
+
const after = src.slice(endIdx);
|
|
227
|
+
src = before + after;
|
|
228
|
+
} else {
|
|
229
|
+
const semi = src.indexOf(";", startIdx);
|
|
230
|
+
let endIdx = semi !== -1 ? semi + 1 : src.indexOf("\n\n", startIdx);
|
|
231
|
+
if (endIdx === -1) endIdx = len;
|
|
232
|
+
src = src.slice(0, startIdx) + src.slice(endIdx);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const exportRe = new RegExp(
|
|
236
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
237
|
+
"g"
|
|
238
|
+
);
|
|
239
|
+
src = src.replace(exportRe, "");
|
|
240
|
+
src = src.replace(/\n{3,}/g, "\n\n");
|
|
241
|
+
fs2.writeFileSync(dbPath, src, "utf8");
|
|
242
|
+
return `Removed ${fnName} from database ${dbName}.`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// src/modules/create.ts
|
|
246
|
+
import fs3 from "fs";
|
|
247
|
+
import path3 from "path";
|
|
248
|
+
import * as os3 from "os";
|
|
249
|
+
function create(dbName, code) {
|
|
250
|
+
const DIR = "databases";
|
|
251
|
+
const basePath = path3.join(os3.homedir(), ".scriptdb");
|
|
252
|
+
const baseDir = path3.resolve(basePath, DIR);
|
|
253
|
+
const dbPath = path3.join(baseDir, `${dbName}.ts`);
|
|
254
|
+
fs3.appendFileSync(dbPath, code.toString(), "utf8");
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/modules/save.ts
|
|
258
|
+
import * as fs4 from "fs";
|
|
259
|
+
import * as path4 from "path";
|
|
260
|
+
import * as os4 from "os";
|
|
261
|
+
function save(dbName, code) {
|
|
262
|
+
const DIR = "databases";
|
|
263
|
+
const basePath = path4.join(os4.homedir(), ".scriptdb");
|
|
264
|
+
const baseDir = path4.resolve(basePath, DIR);
|
|
265
|
+
const dbPath = path4.join(baseDir, `${dbName}.ts`);
|
|
266
|
+
let fileContent = typeof code === "function" ? code.toString() : code;
|
|
267
|
+
fs4.writeFileSync(dbPath, fileContent, "utf8");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/modules/read.ts
|
|
271
|
+
import * as fs5 from "fs";
|
|
272
|
+
import * as path5 from "path";
|
|
273
|
+
import * as os5 from "os";
|
|
274
|
+
function read(dbName) {
|
|
275
|
+
const DIR = "databases";
|
|
276
|
+
const basePath = path5.join(os5.homedir(), ".scriptdb");
|
|
277
|
+
const baseDir = path5.resolve(basePath, DIR);
|
|
278
|
+
const dbPath = path5.join(baseDir, `${dbName}.ts`);
|
|
279
|
+
if (!fs5.existsSync(dbPath)) {
|
|
280
|
+
throw new Error(`Database '${dbName}' not found`);
|
|
281
|
+
}
|
|
282
|
+
return fs5.readFileSync(dbPath, "utf8");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/index.ts
|
|
286
|
+
var update2 = update;
|
|
287
|
+
var remove2 = remove;
|
|
288
|
+
var create2 = create;
|
|
289
|
+
var save2 = save;
|
|
290
|
+
var read2 = read;
|
|
291
|
+
async function SystemModuleResolver() {
|
|
292
|
+
const moduleRegistry = /* @__PURE__ */ new Map();
|
|
293
|
+
moduleRegistry.set("update", update2);
|
|
294
|
+
moduleRegistry.set("remove", remove2);
|
|
295
|
+
moduleRegistry.set("create", create2);
|
|
296
|
+
moduleRegistry.set("save", save2);
|
|
297
|
+
moduleRegistry.set("read", read2);
|
|
298
|
+
const context = {
|
|
299
|
+
// Add require-like functionality
|
|
300
|
+
require: (moduleName) => {
|
|
301
|
+
const module = moduleRegistry.get(moduleName);
|
|
302
|
+
if (!module) {
|
|
303
|
+
throw new Error(`Module '${moduleName}' not found`);
|
|
304
|
+
}
|
|
305
|
+
return module.default || module;
|
|
306
|
+
},
|
|
307
|
+
// Add import functionality (simulated)
|
|
308
|
+
import: async (moduleName) => {
|
|
309
|
+
const module = moduleRegistry.get(moduleName);
|
|
310
|
+
if (!module) {
|
|
311
|
+
throw new Error(`Module '${moduleName}' not found`);
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
default: module.default || module
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
for (const [name, moduleExports] of moduleRegistry) {
|
|
319
|
+
context[name] = moduleExports.default || moduleExports;
|
|
320
|
+
}
|
|
321
|
+
return context;
|
|
322
|
+
}
|
|
323
|
+
var index_default = SystemModuleResolver;
|
|
324
|
+
export {
|
|
325
|
+
SystemModuleResolver,
|
|
326
|
+
create2 as create,
|
|
327
|
+
index_default as default,
|
|
328
|
+
read2 as read,
|
|
329
|
+
remove2 as remove,
|
|
330
|
+
save2 as save,
|
|
331
|
+
update2 as update
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/modules/update.ts","../src/utils/isIdentifier.ts","../src/utils/valueToCode.ts","../src/modules/remove.ts","../src/modules/create.ts","../src/modules/save.ts","../src/modules/read.ts","../src/index.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as os from \"os\";\nimport { valueToCode } from \"../utils/valueToCode\";\n\nexport function update(dbName: string, fnName: string, code: string | Function) {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต\n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n let src;\n\n if (!fs.existsSync(dbPath)) {\n // If dbPath doesn't exist, create an empty module file so we can insert into it.\n try {\n fs.writeFileSync(dbPath, \"\", \"utf8\");\n // console.log(\"Created new database file:\", dbPath);\n return `Created new database file: ${dbPath}`;\n } catch (e) {\n // console.error(\"Failed to create dbPath file:\", dbPath, e && e.message ? e.message : e);\n return `Failed to create dbPath file: ${dbPath}`;\n }\n }\n\n src = fs.readFileSync(dbPath, \"utf8\");\n\n const originalSrc = src;\n\n const escaped = fnName.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, \"\\\\$&\");\n const startRe = new RegExp(\n `function\\\\s+${escaped}\\\\s*\\\\(|\\\\bclass\\\\s+${escaped}\\\\b|\\\\b(?:const|let|var)\\\\s+${escaped}\\\\s*=\\\\s*(?:function\\\\b|class\\\\b|\\\\(|\\\\{|\\\\[)`,\n \"m\"\n );\n const startMatch = src.match(startRe);\n\n // determine declKind in the current file (if present)\n let declKind = null;\n\n if (startMatch) {\n let startIdx: any = startMatch.index;\n const snippet = src.slice(startIdx, startIdx + 80);\n if (/^function\\b/.test(snippet)) declKind = \"functionDecl\";\n else if (/^class\\b/.test(snippet)) declKind = \"classDecl\";\n else if (/^\\b(?:const|let|var)\\b/.test(snippet)) declKind = \"varAssign\";\n }\n\n // build replacement code for this value\n let newCode;\n if (typeof code === \"function\") {\n const fnStr = code.toString();\n // prefer const assignment for anonymous functions/classes or arrow functions\n if (declKind === \"functionDecl\") {\n if (/^function\\s+\\w+/.test(fnStr)) newCode = fnStr;\n else\n newCode = `function ${fnName}${fnStr.replace(\n /^function\\s*\\(/,\n \"(\"\n )}`;\n } else if (declKind === \"classDecl\") {\n if (/^class\\s+\\w+/.test(fnStr)) newCode = fnStr;\n else if (/^class\\s*\\{/.test(fnStr))\n newCode = fnStr.replace(/^class\\s*\\{/, `class ${fnName} {`);\n else newCode = `const ${fnName} = ${fnStr};`;\n } else {\n newCode = `const ${fnName} = ${fnStr};`;\n }\n } else {\n newCode = `const ${fnName} = ${valueToCode(code, 0)};`;\n }\n\n // replacement: if found startMatch, find block and replace between startIdx and endIdx\n if (startMatch) {\n const startIdx = startMatch.index;\n // find first '{' or '[' after startIdx\n const idxCurly = src.indexOf(\"{\", startIdx);\n const idxBracket = src.indexOf(\"[\", startIdx);\n let braceOpen = -1;\n if (idxCurly === -1) braceOpen = idxBracket;\n else if (idxBracket === -1) braceOpen = idxCurly;\n else braceOpen = Math.min(idxCurly, idxBracket);\n\n if (braceOpen === -1) {\n // no block — fallback: replace export or append\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"m\"\n );\n if (exportRe.test(src)) {\n src = src.replace(\n exportRe,\n `${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`\n );\n } else {\n src =\n src + `\\n\\n${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`;\n }\n } else {\n const openingChar = src[braceOpen];\n const closingChar = openingChar === \"[\" ? \"]\" : \"}\";\n let i = braceOpen + 1;\n let depth = 1;\n const len = src.length;\n while (i < len && depth > 0) {\n const ch = src[i];\n if (ch === openingChar) depth++;\n else if (ch === closingChar) depth--;\n i++;\n }\n let braceClose = i;\n let endIdx = braceClose;\n if (src.slice(braceClose, braceClose + 1) === \";\")\n endIdx = braceClose + 1;\n\n const before = src.slice(0, startIdx);\n const after = src.slice(endIdx);\n src = before + newCode + after;\n }\n } else {\n // not found — try to insert before existing export or append\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"m\"\n );\n if (exportRe.test(src)) {\n src = src.replace(\n exportRe,\n `${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`\n );\n } else {\n src =\n src + `\\n\\n${newCode}\\n\\nexport const ${fnName}: any = ${fnName};`;\n }\n }\n\n fs.writeFileSync(dbPath, src, \"utf8\");\n\n if (src === originalSrc) {\n return `Saved ${fnName} to database ${dbName}.`;\n } else {\n return `Updated ${dbName} with ${fnName}.`;\n }\n}\n","export function isIdentifier(key: any) {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);\n}","import { isIdentifier } from \"./isIdentifier\";\n\nexport function valueToCode(val: any, depth: number = 0): string {\n const indentUnit = \" \";\n const indent = indentUnit.repeat(depth);\n const indentInner = indentUnit.repeat(depth + 1);\n\n if (val === null) return \"null\";\n const t = typeof val;\n if (t === \"string\") return JSON.stringify(val);\n if (t === \"number\" || t === \"boolean\") return String(val);\n if (t === \"function\") return val.toString();\n if (Array.isArray(val)) {\n if (val.length === 0) return \"[]\";\n const items = val.map((v) => valueToCode(v, depth + 1));\n return (\n \"[\\n\" +\n items.map((it) => indentInner + it).join(\",\\n\") +\n \"\\n\" +\n indent +\n \"]\"\n );\n }\n if (t === \"object\") {\n const keys = Object.keys(val);\n if (keys.length === 0) return \"{}\";\n const entries = keys.map((k) => {\n const keyPart = isIdentifier(k) ? k : JSON.stringify(k);\n const v = valueToCode(val[k], depth + 1);\n return indentInner + keyPart + \": \" + v;\n });\n return \"{\\n\" + entries.join(\",\\n\") + \"\\n\" + indent + \"}\";\n }\n return String(val);\n}","import path from \"node:path\";\nimport fs from \"node:fs\";\nimport * as os from \"os\";\n\nexport function remove(dbName: string, fnName: string) {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n if (!fs.existsSync(dbPath)) return false;\n\n // if no functionName provided -> remove the whole file (after backup)\n if (!fnName) {\n const bak = `${dbPath}.bak`;\n try {\n fs.copyFileSync(dbPath, bak);\n } catch (e) {\n // ignore backup errors\n }\n try {\n fs.unlinkSync(dbPath);\n return \"Removed successfully\";\n } catch (e) {\n return \"Removed failed\";\n }\n }\n\n // create a backup before editing the file in-place\n const bak = `${dbPath}.bak`;\n try {\n fs.copyFileSync(dbPath, bak);\n } catch (e) {\n // ignore backup errors but continue carefully\n }\n\n let src = fs.readFileSync(dbPath, \"utf8\");\n const escaped = fnName.replace(/[-/\\\\^$*+?.()|[\\]{}]/g, \"\\\\$&\");\n\n // regex to find a declaration of the named symbol (function, class, or var/const/let assignment)\n const startRe = new RegExp(\n `function\\\\s+${escaped}\\\\s*\\\\(|\\\\bclass\\\\s+${escaped}\\\\b|\\\\b(?:const|let|var)\\\\s+${escaped}\\\\s*=\\\\s*(?:function\\\\b|class\\\\b|\\\\(|\\\\{|\\\\[)`,\n \"m\"\n );\n\n const startMatch = src.match(startRe);\n\n if (startMatch) {\n const startIdx = startMatch.index;\n\n // find the first meaningful character after startIdx: {, [, or ; or newline\n const len = src.length;\n const idxCurly = src.indexOf(\"{\", startIdx);\n const idxBracket = src.indexOf(\"[\", startIdx);\n let braceOpen = -1;\n if (idxCurly === -1) braceOpen = idxBracket;\n else if (idxBracket === -1) braceOpen = idxCurly;\n else braceOpen = Math.min(idxCurly, idxBracket);\n\n if (braceOpen !== -1) {\n const openingChar = src[braceOpen];\n const closingChar = openingChar === \"[\" ? \"]\" : \"}\";\n let i = braceOpen + 1;\n let depth = 1;\n while (i < len && depth > 0) {\n const ch = src[i];\n if (ch === openingChar) depth++;\n else if (ch === closingChar) depth--;\n i++;\n }\n let braceClose = i;\n let endIdx = braceClose;\n if (src.slice(braceClose, braceClose + 1) === \";\")\n endIdx = braceClose + 1;\n\n const before = src.slice(0, startIdx);\n const after = src.slice(endIdx);\n src = before + after;\n } else {\n // fallback: remove until next semicolon or a blank line\n const semi = src.indexOf(\";\", startIdx);\n let endIdx = semi !== -1 ? semi + 1 : src.indexOf(\"\\n\\n\", startIdx);\n if (endIdx === -1) endIdx = len;\n src = src.slice(0, startIdx) + src.slice(endIdx);\n }\n }\n\n // remove any export const <name>: any = <name>; lines\n const exportRe = new RegExp(\n `export\\\\s+const\\\\s+${escaped}\\\\s*:\\\\s*any\\\\s*=\\\\s*${escaped}\\\\s*;?`,\n \"g\"\n );\n src = src.replace(exportRe, \"\");\n\n // tidy up multiple blank lines\n src = src.replace(/\\n{3,}/g, \"\\n\\n\");\n\n fs.writeFileSync(dbPath, src, \"utf8\");\n\n return `Removed ${fnName} from database ${dbName}.`;\n}","// create.ts\n// Module for creating new code snippets in the system-modules database\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport * as os from \"os\";\n/**\n * Creates a new code snippet in the specified database file.\n * @param dbName Name of the database file (without extension)\n * @param code Code content of the snippet\n */\nexport function create(dbName: string, code: string | Function): void {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n // Prepare the export line\n fs.appendFileSync(dbPath, code.toString(), 'utf8');\n}\n\n/**\n * Example usage:\n * create('myDatabase', 'function myFunc() { return 42; }');\n */\n","// update.ts\n// Module for updating existing code snippets in the system-modules database\n\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from \"os\";\n\n/**\n * Updates an existing code snippet in the specified database file.\n * If the snippet does not exist, it will be created.\n * @param dbFilePath Absolute path to the database file\n * @param name Name of the snippet\n * @param code New code content of the snippet\n */\nexport function save(dbName: string, code: string | Function | any): void {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR); // โฟลเดอร์ที่อนุญาต \n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n let fileContent = typeof code === 'function' ? code.toString() : code;\n\n fs.writeFileSync(dbPath, fileContent, 'utf8');\n}\n\n/**\n * Example usage:\n * updateSnippet('path/to/db.ts', 'myFunc', 'function myFunc() { return 99; }');\n */\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\n\n/**\n * Read database file content\n * @param dbName - Database name (without .ts extension)\n * @returns File content as string\n */\nexport function read(dbName: string): string {\n const DIR = \"databases\";\n const basePath = path.join(os.homedir(), '.scriptdb');\n const baseDir: string = path.resolve(basePath, DIR);\n const dbPath = path.join(baseDir, `${dbName}.ts`);\n\n if (!fs.existsSync(dbPath)) {\n throw new Error(`Database '${dbName}' not found`);\n }\n\n return fs.readFileSync(dbPath, 'utf8');\n}\n\nexport default read;\n","import { update as updateModule } from './modules/update';\nimport { remove as removeModule } from './modules/remove';\nimport { create as createModule } from './modules/create';\nimport { save as createsaveModule } from './modules/save';\nimport { read as readModule } from './modules/read';\n\nexport const update = updateModule;\nexport const remove = removeModule;\nexport const create = createModule;\nexport const save = createsaveModule;\nexport const read = readModule;\n\nexport async function SystemModuleResolver() {\n\n const moduleRegistry = new Map<string, any>();\n\n moduleRegistry.set(\"update\", update);\n moduleRegistry.set(\"remove\", remove);\n moduleRegistry.set(\"create\", create);\n moduleRegistry.set(\"save\", save);\n moduleRegistry.set(\"read\", read);\n\n const context: Record<string, any> = {\n // Add require-like functionality\n require: (moduleName: string) => {\n const module = moduleRegistry.get(moduleName);\n if (!module) {\n throw new Error(`Module '${moduleName}' not found`);\n }\n // Return the default export if available, otherwise the module itself\n return module.default || module;\n },\n\n // Add import functionality (simulated)\n import: async (moduleName: string) => {\n const module = moduleRegistry.get(moduleName);\n if (!module) {\n throw new Error(`Module '${moduleName}' not found`);\n }\n return {\n default: module.default || module\n };\n }\n };\n\n for (const [name, moduleExports] of moduleRegistry) {\n context[name] = moduleExports.default || moduleExports;\n }\n\n return context;\n}\n\nexport default SystemModuleResolver;"],"mappings":";AAAA,OA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AAI,MAAM,aAAa,MAAM,aAAa;AAAA,EACpD;AAEA,SAAU,iBAAa,QAAQ,MAAM;AACzC;;;ACdO,IAAMC,UAAS;AACf,IAAMC,UAAS;AACf,IAAMC,UAAS;AACf,IAAMC,QAAO;AACb,IAAMC,QAAO;AAEpB,eAAsB,uBAAuB;AAEzC,QAAM,iBAAiB,oBAAI,IAAiB;AAE5C,iBAAe,IAAI,UAAUJ,OAAM;AACnC,iBAAe,IAAI,UAAUC,OAAM;AACnC,iBAAe,IAAI,UAAUC,OAAM;AACnC,iBAAe,IAAI,QAAQC,KAAI;AAC/B,iBAAe,IAAI,QAAQC,KAAI;AAE/B,QAAM,UAA+B;AAAA;AAAA,IAEjC,SAAS,CAAC,eAAuB;AAC7B,YAAM,SAAS,eAAe,IAAI,UAAU;AAC5C,UAAI,CAAC,QAAQ;AACT,cAAM,IAAI,MAAM,WAAW,UAAU,aAAa;AAAA,MACtD;AAEA,aAAO,OAAO,WAAW;AAAA,IAC7B;AAAA;AAAA,IAGA,QAAQ,OAAO,eAAuB;AAClC,YAAM,SAAS,eAAe,IAAI,UAAU;AAC5C,UAAI,CAAC,QAAQ;AACT,cAAM,IAAI,MAAM,WAAW,UAAU,aAAa;AAAA,MACtD;AACA,aAAO;AAAA,QACH,SAAS,OAAO,WAAW;AAAA,MAC/B;AAAA,IACJ;AAAA,EACJ;AAEA,aAAW,CAAC,MAAM,aAAa,KAAK,gBAAgB;AAChD,YAAQ,IAAI,IAAI,cAAc,WAAW;AAAA,EAC7C;AAEA,SAAO;AACX;AAEA,IAAO,gBAAQ;","names":["path","fs","os","bak","fs","path","os","fs","path","os","fs","path","os","update","remove","create","save","read"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scriptdb/system-modules",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "System module resolver for script database",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"dev": "bun --watch src/index.ts",
|
|
20
|
-
"build": "
|
|
21
|
-
"build:cjs": "bun build src/index.ts --outdir dist --target node --format cjs --outfile dist/index.js",
|
|
22
|
-
"build:types": "tsc --emitDeclarationOnly",
|
|
23
|
-
"build:all": "bun run build && bun run build:cjs && bun run build:types",
|
|
20
|
+
"build": "tsup",
|
|
24
21
|
"test": "bun test",
|
|
25
22
|
"lint": "bun run lint:src",
|
|
26
23
|
"lint:src": "eslint src --ext .ts,.tsx",
|