elit 3.1.7 → 3.1.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/dist/build.d.mts +1 -1
- package/dist/cli.js +377 -26
- package/dist/database.d.mts +11 -2
- package/dist/database.d.ts +10 -1
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +369 -835
- package/dist/database.mjs +369 -843
- package/dist/http.d.mts +3 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +23 -0
- package/dist/http.mjs +23 -0
- package/dist/https.js +23 -0
- package/dist/https.mjs +23 -0
- package/dist/{server-R_AfcxRw.d.ts → server-BFOHbYb6.d.ts} +19 -14
- package/dist/{server-CRNme9Bc.d.mts → server-BPVoq5Xi.d.mts} +19 -14
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +18 -13
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +379 -51
- package/dist/server.mjs +379 -51
- package/dist/types.d.mts +21 -13
- package/dist/wss.js +23 -0
- package/dist/wss.mjs +23 -0
- package/package.json +1 -1
- package/src/database.ts +457 -26
- package/src/http.ts +26 -0
- package/src/server.ts +32 -47
package/dist/build.d.mts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1163,6 +1163,29 @@ var init_http = __esm({
|
|
|
1163
1163
|
_setResolver(resolve2) {
|
|
1164
1164
|
this._resolve = resolve2;
|
|
1165
1165
|
}
|
|
1166
|
+
// Express.js-like methods
|
|
1167
|
+
json(data, statusCode = 200) {
|
|
1168
|
+
if (!this.headersSent) {
|
|
1169
|
+
this.setHeader("Content-Type", "application/json");
|
|
1170
|
+
}
|
|
1171
|
+
this.statusCode = statusCode;
|
|
1172
|
+
this.end(JSON.stringify(data));
|
|
1173
|
+
return this;
|
|
1174
|
+
}
|
|
1175
|
+
send(data) {
|
|
1176
|
+
if (typeof data === "object") {
|
|
1177
|
+
return this.json(data);
|
|
1178
|
+
}
|
|
1179
|
+
if (!this.headersSent) {
|
|
1180
|
+
this.setHeader("Content-Type", "text/plain");
|
|
1181
|
+
}
|
|
1182
|
+
this.end(String(data));
|
|
1183
|
+
return this;
|
|
1184
|
+
}
|
|
1185
|
+
status(code) {
|
|
1186
|
+
this.statusCode = code;
|
|
1187
|
+
return this;
|
|
1188
|
+
}
|
|
1166
1189
|
};
|
|
1167
1190
|
Server = class extends import_node_events.EventEmitter {
|
|
1168
1191
|
constructor(requestListener) {
|
|
@@ -1412,7 +1435,7 @@ var require_package = __commonJS({
|
|
|
1412
1435
|
"package.json"(exports2, module2) {
|
|
1413
1436
|
module2.exports = {
|
|
1414
1437
|
name: "elit",
|
|
1415
|
-
version: "3.1.
|
|
1438
|
+
version: "3.1.9",
|
|
1416
1439
|
description: "Optimized lightweight library for creating DOM elements with reactive state",
|
|
1417
1440
|
main: "dist/index.js",
|
|
1418
1441
|
module: "dist/index.mjs",
|
|
@@ -3097,32 +3120,80 @@ var Database = class {
|
|
|
3097
3120
|
acc[type] = (...args) => logs.push({ type, args });
|
|
3098
3121
|
return acc;
|
|
3099
3122
|
}, {});
|
|
3123
|
+
const systemBase = {
|
|
3124
|
+
update,
|
|
3125
|
+
remove,
|
|
3126
|
+
rename: rename2,
|
|
3127
|
+
read,
|
|
3128
|
+
create,
|
|
3129
|
+
save
|
|
3130
|
+
};
|
|
3100
3131
|
this.register({
|
|
3101
|
-
|
|
3132
|
+
dbConsole: { ...customConsole, ...systemBase }
|
|
3102
3133
|
});
|
|
3103
3134
|
let stringCode;
|
|
3104
3135
|
if (typeof code === "function") {
|
|
3105
3136
|
const funcStr = code.toString();
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
const trimmed = importArg.trim();
|
|
3117
|
-
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
3118
|
-
const inner = trimmed.slice(1, -1).trim();
|
|
3119
|
-
return `import { ${inner} } from ${quote}${modulePath}${quote}`;
|
|
3120
|
-
} else {
|
|
3121
|
-
return `import ${trimmed} from ${quote}${modulePath}${quote}`;
|
|
3122
|
-
}
|
|
3137
|
+
if (funcStr.includes("=>")) {
|
|
3138
|
+
const arrowIndex = funcStr.indexOf("=>");
|
|
3139
|
+
let start = arrowIndex + 2;
|
|
3140
|
+
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3141
|
+
if (funcStr[start] === "{") start++;
|
|
3142
|
+
let end = funcStr.lastIndexOf("}");
|
|
3143
|
+
if (start < end) {
|
|
3144
|
+
stringCode = funcStr.substring(start, end);
|
|
3145
|
+
} else {
|
|
3146
|
+
stringCode = funcStr.substring(start);
|
|
3123
3147
|
}
|
|
3124
|
-
)
|
|
3125
|
-
|
|
3148
|
+
} else if (funcStr.includes("function")) {
|
|
3149
|
+
const funcIndex = funcStr.indexOf("function");
|
|
3150
|
+
let start = funcIndex + 8;
|
|
3151
|
+
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3152
|
+
if (funcStr[start] === "(") start++;
|
|
3153
|
+
if (start < funcStr.length && funcStr[start] !== "(") {
|
|
3154
|
+
while (start < funcStr.length && funcStr[start] !== " " && funcStr[start] !== "(") start++;
|
|
3155
|
+
}
|
|
3156
|
+
if (funcStr[start] === "(") start++;
|
|
3157
|
+
while (start < funcStr.length && funcStr[start] === " ") start++;
|
|
3158
|
+
if (funcStr[start] === "{") start++;
|
|
3159
|
+
const end = funcStr.lastIndexOf("}");
|
|
3160
|
+
if (start < end) {
|
|
3161
|
+
stringCode = funcStr.substring(start, end);
|
|
3162
|
+
} else {
|
|
3163
|
+
stringCode = funcStr.substring(start);
|
|
3164
|
+
}
|
|
3165
|
+
} else {
|
|
3166
|
+
stringCode = funcStr;
|
|
3167
|
+
}
|
|
3168
|
+
stringCode = stringCode.trim();
|
|
3169
|
+
let importPos = 0;
|
|
3170
|
+
while ((importPos = stringCode.indexOf("import(", importPos)) !== -1) {
|
|
3171
|
+
const fromPos = stringCode.indexOf(".from(", importPos);
|
|
3172
|
+
if (fromPos === -1) break;
|
|
3173
|
+
const quoteStart = stringCode.indexOf("(", fromPos + 7) + 1;
|
|
3174
|
+
if (quoteStart === -1) break;
|
|
3175
|
+
const quoteChar = stringCode[quoteStart];
|
|
3176
|
+
if (quoteChar !== '"' && quoteChar !== "'") break;
|
|
3177
|
+
const quoteEnd = stringCode.indexOf(quoteChar, quoteStart + 1);
|
|
3178
|
+
if (quoteEnd === -1) break;
|
|
3179
|
+
const modulePath = stringCode.substring(quoteStart + 1, quoteEnd);
|
|
3180
|
+
const importArgEnd = fromPos - 1;
|
|
3181
|
+
const importArgStart = importPos + 7;
|
|
3182
|
+
const trimmed = stringCode.substring(importArgStart, importArgEnd).trim();
|
|
3183
|
+
let replacement;
|
|
3184
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
3185
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
3186
|
+
replacement = `import { ${inner} } from "${modulePath}"`;
|
|
3187
|
+
} else {
|
|
3188
|
+
replacement = `import ${trimmed} from "${modulePath}"`;
|
|
3189
|
+
}
|
|
3190
|
+
const before = stringCode.substring(0, importPos);
|
|
3191
|
+
const after = stringCode.substring(quoteEnd + 2);
|
|
3192
|
+
stringCode = before + replacement + after;
|
|
3193
|
+
}
|
|
3194
|
+
const lines = stringCode.split("\n");
|
|
3195
|
+
const trimmedLines = lines.map((line) => line.trim());
|
|
3196
|
+
stringCode = trimmedLines.join("\n").trim();
|
|
3126
3197
|
} else {
|
|
3127
3198
|
stringCode = code;
|
|
3128
3199
|
}
|
|
@@ -3153,7 +3224,287 @@ var Database = class {
|
|
|
3153
3224
|
return await this.vmRun(code, options);
|
|
3154
3225
|
}
|
|
3155
3226
|
};
|
|
3156
|
-
|
|
3227
|
+
function create(dbName, code) {
|
|
3228
|
+
const DIR = "databases";
|
|
3229
|
+
const basePath = process.cwd();
|
|
3230
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3231
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3232
|
+
import_node_fs.default.appendFileSync(dbPath, code.toString(), "utf8");
|
|
3233
|
+
}
|
|
3234
|
+
function read(dbName) {
|
|
3235
|
+
const DIR = "databases";
|
|
3236
|
+
const basePath = process.cwd();
|
|
3237
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3238
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3239
|
+
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
3240
|
+
throw new Error(`Database '${dbName}' not found`);
|
|
3241
|
+
}
|
|
3242
|
+
return import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3243
|
+
}
|
|
3244
|
+
function remove(dbName, fnName) {
|
|
3245
|
+
const DIR = "databases";
|
|
3246
|
+
const basePath = process.cwd();
|
|
3247
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3248
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3249
|
+
if (!import_node_fs.default.existsSync(dbPath)) return false;
|
|
3250
|
+
if (!fnName) {
|
|
3251
|
+
const bak2 = `${dbPath}.bak`;
|
|
3252
|
+
try {
|
|
3253
|
+
import_node_fs.default.copyFileSync(dbPath, bak2);
|
|
3254
|
+
} catch (e) {
|
|
3255
|
+
}
|
|
3256
|
+
try {
|
|
3257
|
+
import_node_fs.default.unlinkSync(dbPath);
|
|
3258
|
+
return "Removed successfully";
|
|
3259
|
+
} catch (e) {
|
|
3260
|
+
return "Removed failed";
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
const bak = `${dbPath}.bak`;
|
|
3264
|
+
try {
|
|
3265
|
+
import_node_fs.default.copyFileSync(dbPath, bak);
|
|
3266
|
+
} catch (e) {
|
|
3267
|
+
}
|
|
3268
|
+
let src = import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3269
|
+
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
3270
|
+
const startRe = new RegExp(
|
|
3271
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
3272
|
+
"m"
|
|
3273
|
+
);
|
|
3274
|
+
const startMatch = src.match(startRe);
|
|
3275
|
+
if (startMatch) {
|
|
3276
|
+
const startIdx = startMatch.index;
|
|
3277
|
+
const len = src.length;
|
|
3278
|
+
const idxCurly = src.indexOf("{", startIdx);
|
|
3279
|
+
const idxBracket = src.indexOf("[", startIdx);
|
|
3280
|
+
let braceOpen = -1;
|
|
3281
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
3282
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
3283
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
3284
|
+
if (braceOpen !== -1) {
|
|
3285
|
+
const openingChar = src[braceOpen];
|
|
3286
|
+
const closingChar = openingChar === "[" ? "]" : "}";
|
|
3287
|
+
let i = braceOpen + 1;
|
|
3288
|
+
let depth = 1;
|
|
3289
|
+
while (i < len && depth > 0) {
|
|
3290
|
+
const ch = src[i];
|
|
3291
|
+
if (ch === openingChar) depth++;
|
|
3292
|
+
else if (ch === closingChar) depth--;
|
|
3293
|
+
i++;
|
|
3294
|
+
}
|
|
3295
|
+
let braceClose = i;
|
|
3296
|
+
let endIdx = braceClose;
|
|
3297
|
+
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
3298
|
+
endIdx = braceClose + 1;
|
|
3299
|
+
const before = src.slice(0, startIdx);
|
|
3300
|
+
const after = src.slice(endIdx);
|
|
3301
|
+
src = before + after;
|
|
3302
|
+
} else {
|
|
3303
|
+
const semi = src.indexOf(";", startIdx);
|
|
3304
|
+
let endIdx = semi !== -1 ? semi + 1 : src.indexOf("\n\n", startIdx);
|
|
3305
|
+
if (endIdx === -1) endIdx = len;
|
|
3306
|
+
src = src.slice(0, startIdx) + src.slice(endIdx);
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
const exportRe = new RegExp(
|
|
3310
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3311
|
+
"g"
|
|
3312
|
+
);
|
|
3313
|
+
src = src.replace(exportRe, "");
|
|
3314
|
+
src = src.replace(/\n{3,}/g, "\n\n");
|
|
3315
|
+
import_node_fs.default.writeFileSync(dbPath, src, "utf8");
|
|
3316
|
+
return `Removed ${fnName} from database ${dbName}.`;
|
|
3317
|
+
}
|
|
3318
|
+
function rename2(oldName, newName) {
|
|
3319
|
+
const DIR = "databases";
|
|
3320
|
+
const basePath = process.cwd();
|
|
3321
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3322
|
+
const oldPath = import_node_path.default.join(baseDir, `${oldName}.ts`);
|
|
3323
|
+
const newPath = import_node_path.default.join(baseDir, `${newName}.ts`);
|
|
3324
|
+
if (!import_node_fs.default.existsSync(oldPath)) {
|
|
3325
|
+
return `Error: File '${oldName}.ts' does not exist in the database`;
|
|
3326
|
+
}
|
|
3327
|
+
if (import_node_fs.default.existsSync(newPath)) {
|
|
3328
|
+
return `Error: File '${newName}.ts' already exists in the database`;
|
|
3329
|
+
}
|
|
3330
|
+
try {
|
|
3331
|
+
import_node_fs.default.renameSync(oldPath, newPath);
|
|
3332
|
+
return `Successfully renamed '${oldName}.ts' to '${newName}.ts'`;
|
|
3333
|
+
} catch (error) {
|
|
3334
|
+
return `Error renaming file: ${error instanceof Error ? error.message : String(error)}`;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
function save(dbName, code) {
|
|
3338
|
+
const DIR = "databases";
|
|
3339
|
+
const basePath = process.cwd();
|
|
3340
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3341
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3342
|
+
let fileContent = typeof code === "function" ? code.toString() : code;
|
|
3343
|
+
import_node_fs.default.writeFileSync(dbPath, fileContent, "utf8");
|
|
3344
|
+
}
|
|
3345
|
+
function update(dbName, fnName, code) {
|
|
3346
|
+
const DIR = "databases";
|
|
3347
|
+
const basePath = process.cwd();
|
|
3348
|
+
const baseDir = import_node_path.default.resolve(basePath, DIR);
|
|
3349
|
+
const dbPath = import_node_path.default.join(baseDir, `${dbName}.ts`);
|
|
3350
|
+
let src;
|
|
3351
|
+
if (!import_node_fs.default.existsSync(dbPath)) {
|
|
3352
|
+
try {
|
|
3353
|
+
import_node_fs.default.writeFileSync(dbPath, "", "utf8");
|
|
3354
|
+
return `Created new database file: ${dbPath}`;
|
|
3355
|
+
} catch (e) {
|
|
3356
|
+
return `Failed to create dbPath file: ${dbPath}`;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
src = import_node_fs.default.readFileSync(dbPath, "utf8");
|
|
3360
|
+
const originalSrc = src;
|
|
3361
|
+
const escaped = fnName.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
3362
|
+
const startRe = new RegExp(
|
|
3363
|
+
`function\\s+${escaped}\\s*\\(|\\bclass\\s+${escaped}\\b|\\b(?:const|let|var)\\s+${escaped}\\s*=\\s*(?:function\\b|class\\b|\\(|\\{|\\[)`,
|
|
3364
|
+
"m"
|
|
3365
|
+
);
|
|
3366
|
+
const startMatch = src.match(startRe);
|
|
3367
|
+
let declKind = null;
|
|
3368
|
+
if (startMatch) {
|
|
3369
|
+
let startIdx = startMatch.index;
|
|
3370
|
+
const snippet = src.slice(startIdx, startIdx + 80);
|
|
3371
|
+
if (/^function\b/.test(snippet)) declKind = "functionDecl";
|
|
3372
|
+
else if (/^class\b/.test(snippet)) declKind = "classDecl";
|
|
3373
|
+
else if (/^\b(?:const|let|var)\b/.test(snippet)) declKind = "varAssign";
|
|
3374
|
+
}
|
|
3375
|
+
let newCode;
|
|
3376
|
+
if (typeof code === "function") {
|
|
3377
|
+
const fnStr = code.toString();
|
|
3378
|
+
if (declKind === "functionDecl") {
|
|
3379
|
+
if (/^function\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
3380
|
+
else
|
|
3381
|
+
newCode = `function ${fnName}${fnStr.replace(
|
|
3382
|
+
/^function\s*\(/,
|
|
3383
|
+
"("
|
|
3384
|
+
)}`;
|
|
3385
|
+
} else if (declKind === "classDecl") {
|
|
3386
|
+
if (/^class\s+\w+/.test(fnStr)) newCode = fnStr;
|
|
3387
|
+
else if (/^class\s*\{/.test(fnStr))
|
|
3388
|
+
newCode = fnStr.replace(/^class\s*\{/, `class ${fnName} {`);
|
|
3389
|
+
else newCode = `const ${fnName} = ${fnStr};`;
|
|
3390
|
+
} else {
|
|
3391
|
+
newCode = `const ${fnName} = ${fnStr};`;
|
|
3392
|
+
}
|
|
3393
|
+
} else {
|
|
3394
|
+
newCode = `const ${fnName} = ${valueToCode(code, 0)};`;
|
|
3395
|
+
}
|
|
3396
|
+
if (startMatch) {
|
|
3397
|
+
const startIdx = startMatch.index;
|
|
3398
|
+
const idxCurly = src.indexOf("{", startIdx);
|
|
3399
|
+
const idxBracket = src.indexOf("[", startIdx);
|
|
3400
|
+
let braceOpen = -1;
|
|
3401
|
+
if (idxCurly === -1) braceOpen = idxBracket;
|
|
3402
|
+
else if (idxBracket === -1) braceOpen = idxCurly;
|
|
3403
|
+
else braceOpen = Math.min(idxCurly, idxBracket);
|
|
3404
|
+
if (braceOpen === -1) {
|
|
3405
|
+
const exportRe = new RegExp(
|
|
3406
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3407
|
+
"m"
|
|
3408
|
+
);
|
|
3409
|
+
if (exportRe.test(src)) {
|
|
3410
|
+
src = src.replace(
|
|
3411
|
+
exportRe,
|
|
3412
|
+
`${newCode}
|
|
3413
|
+
|
|
3414
|
+
export const ${fnName}: any = ${fnName};`
|
|
3415
|
+
);
|
|
3416
|
+
} else {
|
|
3417
|
+
src = src + `
|
|
3418
|
+
|
|
3419
|
+
${newCode}
|
|
3420
|
+
|
|
3421
|
+
export const ${fnName}: any = ${fnName};`;
|
|
3422
|
+
}
|
|
3423
|
+
} else {
|
|
3424
|
+
const openingChar = src[braceOpen];
|
|
3425
|
+
const closingChar = openingChar === "[" ? "]" : "}";
|
|
3426
|
+
let i = braceOpen + 1;
|
|
3427
|
+
let depth = 1;
|
|
3428
|
+
const len = src.length;
|
|
3429
|
+
while (i < len && depth > 0) {
|
|
3430
|
+
const ch = src[i];
|
|
3431
|
+
if (ch === openingChar) depth++;
|
|
3432
|
+
else if (ch === closingChar) depth--;
|
|
3433
|
+
i++;
|
|
3434
|
+
}
|
|
3435
|
+
let braceClose = i;
|
|
3436
|
+
let endIdx = braceClose;
|
|
3437
|
+
if (src.slice(braceClose, braceClose + 1) === ";")
|
|
3438
|
+
endIdx = braceClose + 1;
|
|
3439
|
+
const before = src.slice(0, startIdx);
|
|
3440
|
+
const after = src.slice(endIdx);
|
|
3441
|
+
src = before + newCode + after;
|
|
3442
|
+
}
|
|
3443
|
+
} else {
|
|
3444
|
+
const exportRe = new RegExp(
|
|
3445
|
+
`export\\s+const\\s+${escaped}\\s*:\\s*any\\s*=\\s*${escaped}\\s*;?`,
|
|
3446
|
+
"m"
|
|
3447
|
+
);
|
|
3448
|
+
if (exportRe.test(src)) {
|
|
3449
|
+
src = src.replace(
|
|
3450
|
+
exportRe,
|
|
3451
|
+
`${newCode}
|
|
3452
|
+
|
|
3453
|
+
export const ${fnName}: any = ${fnName};`
|
|
3454
|
+
);
|
|
3455
|
+
} else {
|
|
3456
|
+
src = src + `
|
|
3457
|
+
|
|
3458
|
+
${newCode}
|
|
3459
|
+
|
|
3460
|
+
export const ${fnName}: any = ${fnName};`;
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
import_node_fs.default.writeFileSync(dbPath, src, "utf8");
|
|
3464
|
+
if (src === originalSrc) {
|
|
3465
|
+
return `Saved ${fnName} to database ${dbName}.`;
|
|
3466
|
+
} else {
|
|
3467
|
+
return `Updated ${dbName} with ${fnName}.`;
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
function valueToCode(val, depth = 0) {
|
|
3471
|
+
const indentUnit = " ";
|
|
3472
|
+
const indent = indentUnit.repeat(depth);
|
|
3473
|
+
const indentInner = indentUnit.repeat(depth + 1);
|
|
3474
|
+
if (val === null) return "null";
|
|
3475
|
+
const t = typeof val;
|
|
3476
|
+
if (t === "string") return JSON.stringify(val);
|
|
3477
|
+
if (t === "number" || t === "boolean") return String(val);
|
|
3478
|
+
if (t === "function") return val.toString();
|
|
3479
|
+
if (Array.isArray(val)) {
|
|
3480
|
+
if (val.length === 0) return "[]";
|
|
3481
|
+
const items = val.map((v) => valueToCode(v, depth + 1));
|
|
3482
|
+
return "[\n" + items.map((it) => indentInner + it).join(",\n") + "\n" + indent + "]";
|
|
3483
|
+
}
|
|
3484
|
+
if (t === "object") {
|
|
3485
|
+
const keys = Object.keys(val);
|
|
3486
|
+
if (keys.length === 0) return "{}";
|
|
3487
|
+
const entries = keys.map((k) => {
|
|
3488
|
+
const keyPart = isIdentifier(k) ? k : JSON.stringify(k);
|
|
3489
|
+
const v = valueToCode(val[k], depth + 1);
|
|
3490
|
+
return indentInner + keyPart + ": " + v;
|
|
3491
|
+
});
|
|
3492
|
+
return "{\n" + entries.join(",\n") + "\n" + indent + "}";
|
|
3493
|
+
}
|
|
3494
|
+
return String(val);
|
|
3495
|
+
}
|
|
3496
|
+
function isIdentifier(key) {
|
|
3497
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key);
|
|
3498
|
+
}
|
|
3499
|
+
var dbConsole = {
|
|
3500
|
+
create,
|
|
3501
|
+
read,
|
|
3502
|
+
remove,
|
|
3503
|
+
rename: rename2,
|
|
3504
|
+
save,
|
|
3505
|
+
update,
|
|
3506
|
+
...console
|
|
3507
|
+
};
|
|
3157
3508
|
|
|
3158
3509
|
// src/server.ts
|
|
3159
3510
|
var ServerDatabase = class {
|
|
@@ -3168,7 +3519,7 @@ var ServerDatabase = class {
|
|
|
3168
3519
|
}
|
|
3169
3520
|
};
|
|
3170
3521
|
var serverDatabase = new ServerDatabase();
|
|
3171
|
-
var
|
|
3522
|
+
var database = serverDatabase.database;
|
|
3172
3523
|
var json = (res, data, status = 200) => (res.writeHead(status, { "Content-Type": "application/json" }), res.end(JSON.stringify(data)));
|
|
3173
3524
|
var sendError = (res, code, msg) => {
|
|
3174
3525
|
res.writeHead(code, { "Content-Type": "text/plain" });
|
|
@@ -3625,9 +3976,9 @@ function createDevServer(options) {
|
|
|
3625
3976
|
if (config.mode === "dev") {
|
|
3626
3977
|
clearImportMapCache();
|
|
3627
3978
|
}
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
}
|
|
3979
|
+
serverDatabase.initialize(config.database ? config.database : {
|
|
3980
|
+
dir: resolve(process.cwd(), "databases")
|
|
3981
|
+
});
|
|
3631
3982
|
const clientsToNormalize = config.clients?.length ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || "", index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, mode: config.mode }] : null;
|
|
3632
3983
|
if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
|
|
3633
3984
|
const normalizedClients = clientsToNormalize.map((client) => {
|
package/dist/database.d.mts
CHANGED
|
@@ -26,6 +26,15 @@ declare class Database {
|
|
|
26
26
|
logs: any[];
|
|
27
27
|
}>;
|
|
28
28
|
}
|
|
29
|
-
declare
|
|
29
|
+
declare function database(): Database;
|
|
30
|
+
interface DatabaseConsole extends Console {
|
|
31
|
+
create?(dbName: string, code: string | Function): void;
|
|
32
|
+
read(dbName: string): string;
|
|
33
|
+
remove(dbName: string, fnName: string): any;
|
|
34
|
+
rename(oldName: string, newName: string): string;
|
|
35
|
+
save(dbName: string, code: string | Function | any): void;
|
|
36
|
+
update(dbName: string, fnName: string, code: string | Function): any;
|
|
37
|
+
}
|
|
38
|
+
declare const dbConsole: DatabaseConsole;
|
|
30
39
|
|
|
31
|
-
export { Database, type DatabaseConfig, database, database as default };
|
|
40
|
+
export { Database, type DatabaseConfig, type DatabaseConsole, database, dbConsole, database as default };
|
package/dist/database.d.ts
CHANGED
|
@@ -25,6 +25,15 @@ export declare class Database {
|
|
|
25
25
|
logs: any[];
|
|
26
26
|
}>;
|
|
27
27
|
}
|
|
28
|
-
export declare
|
|
28
|
+
export declare function database(): Database;
|
|
29
|
+
export interface DatabaseConsole extends Console {
|
|
30
|
+
create?(dbName: string, code: string | Function): void;
|
|
31
|
+
read(dbName: string): string;
|
|
32
|
+
remove(dbName: string, fnName: string): any;
|
|
33
|
+
rename(oldName: string, newName: string): string;
|
|
34
|
+
save(dbName: string, code: string | Function | any): void;
|
|
35
|
+
update(dbName: string, fnName: string, code: string | Function): any;
|
|
36
|
+
}
|
|
37
|
+
export declare const dbConsole: DatabaseConsole;
|
|
29
38
|
export default database;
|
|
30
39
|
//# sourceMappingURL=database.d.ts.map
|
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAMzB,MAAM,WAAW,cAAc;IAC3B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;CAC5C;AAED,qBAAa,QAAQ;IACjB,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,OAAO,CAEb;gBAEU,MAAM,EAAE,cAAc;IAMlC,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,EAEhC;IAED,OAAO,CAAC,QAAQ;IAMhB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG;IAI7C,OAAO,CAAC,WAAW;YAwBL,YAAY;YA6BZ,KAAK;IAkJnB;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,kBAAkB,GAAG,MAAM;;;;CAIlF;AAkVD,wBAAgB,QAAQ,aAIvB;AAED,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC5C,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IACvD,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5C,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACjD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,GAAG,GAAG,IAAI,CAAC;IAC1D,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,GAAG,CAAC;CACxE;AAED,eAAO,MAAM,SAAS,EAAE,eAQvB,CAAA;AACD,eAAe,QAAQ,CAAC"}
|