@dbcube/core 1.0.34 → 1.0.36
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.cjs +44 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +50 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -428,9 +428,6 @@ var Binary = class {
|
|
|
428
428
|
if (!fs2.existsSync(dir)) {
|
|
429
429
|
fs2.mkdirSync(dir, { recursive: true });
|
|
430
430
|
}
|
|
431
|
-
if (dir.includes(path2.resolve(process.cwd(), ".dbcube"))) {
|
|
432
|
-
this.ensureGitIgnore(path2.resolve(process.cwd(), ".dbcube"));
|
|
433
|
-
}
|
|
434
431
|
return dir;
|
|
435
432
|
} catch {
|
|
436
433
|
continue;
|
|
@@ -440,21 +437,6 @@ var Binary = class {
|
|
|
440
437
|
fs2.mkdirSync(tempDir, { recursive: true });
|
|
441
438
|
return tempDir;
|
|
442
439
|
}
|
|
443
|
-
static ensureGitIgnore(dbcubeDir) {
|
|
444
|
-
try {
|
|
445
|
-
const gitignorePath = path2.join(dbcubeDir, ".gitignore");
|
|
446
|
-
if (!fs2.existsSync(gitignorePath)) {
|
|
447
|
-
const gitignoreContent = `# DBCube binaries
|
|
448
|
-
bin/
|
|
449
|
-
*.exe
|
|
450
|
-
*.log
|
|
451
|
-
*.tmp
|
|
452
|
-
`;
|
|
453
|
-
fs2.writeFileSync(gitignorePath, gitignoreContent);
|
|
454
|
-
}
|
|
455
|
-
} catch {
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
440
|
static async get() {
|
|
459
441
|
await this.ensureBinariesExist();
|
|
460
442
|
const arch2 = new Arquitecture();
|
|
@@ -714,24 +696,40 @@ var Engine = class {
|
|
|
714
696
|
// src/lib/SqliteExecutor.ts
|
|
715
697
|
import { exec } from "child_process";
|
|
716
698
|
import * as path4 from "path";
|
|
699
|
+
import * as fs3 from "fs";
|
|
717
700
|
import { promisify } from "util";
|
|
718
701
|
var execAsync = promisify(exec);
|
|
719
702
|
var SqliteExecutor = class {
|
|
720
|
-
binaryPath;
|
|
703
|
+
binaryPath = null;
|
|
721
704
|
dbPath;
|
|
722
705
|
constructor(dbPath) {
|
|
723
706
|
this.dbPath = dbPath;
|
|
724
|
-
this.binaryPath = this.getBinaryPath();
|
|
725
707
|
}
|
|
726
|
-
getBinaryPath() {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
708
|
+
async getBinaryPath() {
|
|
709
|
+
if (!this.binaryPath) {
|
|
710
|
+
await Binary.ensureBinariesExist();
|
|
711
|
+
const possibleDirs = [
|
|
712
|
+
path4.resolve(process.cwd(), ".dbcube", "bin"),
|
|
713
|
+
path4.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
714
|
+
path4.resolve(__dirname, "..", "bin")
|
|
715
|
+
];
|
|
716
|
+
let binDir = "";
|
|
717
|
+
for (const dir of possibleDirs) {
|
|
718
|
+
if (fs3.existsSync(dir)) {
|
|
719
|
+
binDir = dir;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const platform2 = process.platform;
|
|
724
|
+
const extension = platform2 === "win32" ? ".exe" : "";
|
|
725
|
+
const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
|
|
726
|
+
this.binaryPath = path4.join(binDir, binaryName);
|
|
727
|
+
}
|
|
728
|
+
return this.binaryPath;
|
|
732
729
|
}
|
|
733
730
|
async executeBinary(args) {
|
|
734
|
-
const
|
|
731
|
+
const binaryPath = await this.getBinaryPath();
|
|
732
|
+
const command = `"${binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
|
|
735
733
|
try {
|
|
736
734
|
const { stdout, stderr } = await execAsync(command, {
|
|
737
735
|
maxBuffer: 10 * 1024 * 1024,
|
|
@@ -871,7 +869,7 @@ var SqliteExecutor = class {
|
|
|
871
869
|
|
|
872
870
|
// src/lib/DbConfig.ts
|
|
873
871
|
import * as path5 from "path";
|
|
874
|
-
import
|
|
872
|
+
import fs4 from "fs";
|
|
875
873
|
var rootPath = path5.resolve(process.cwd(), ".dbcube");
|
|
876
874
|
var SQLite = class {
|
|
877
875
|
executor = null;
|
|
@@ -883,10 +881,10 @@ var SQLite = class {
|
|
|
883
881
|
if (this.database) {
|
|
884
882
|
const dbPath = this.database || ":memory:";
|
|
885
883
|
const configPath = path5.join(rootPath, dbPath + ".db");
|
|
886
|
-
if (!
|
|
887
|
-
|
|
884
|
+
if (!fs4.existsSync(rootPath)) {
|
|
885
|
+
fs4.mkdirSync(rootPath, { recursive: true });
|
|
888
886
|
}
|
|
889
|
-
if (
|
|
887
|
+
if (fs4.existsSync(configPath)) {
|
|
890
888
|
return true;
|
|
891
889
|
}
|
|
892
890
|
if (!this.executor) {
|
|
@@ -902,8 +900,8 @@ var SQLite = class {
|
|
|
902
900
|
if (!this.executor) {
|
|
903
901
|
const dbPath = this.database || ":memory:";
|
|
904
902
|
const configPath = path5.join(rootPath, dbPath + ".db");
|
|
905
|
-
if (!
|
|
906
|
-
|
|
903
|
+
if (!fs4.existsSync(rootPath)) {
|
|
904
|
+
fs4.mkdirSync(rootPath, { recursive: true });
|
|
907
905
|
}
|
|
908
906
|
this.executor = new SqliteExecutor(configPath);
|
|
909
907
|
const connected = await this.executor.connect();
|
|
@@ -1085,7 +1083,7 @@ var DbConfig = new SQLite({ DATABASE: "config" });
|
|
|
1085
1083
|
var DbConfig_default = DbConfig;
|
|
1086
1084
|
|
|
1087
1085
|
// src/lib/FileLogger.ts
|
|
1088
|
-
import * as
|
|
1086
|
+
import * as fs5 from "fs";
|
|
1089
1087
|
import * as path6 from "path";
|
|
1090
1088
|
import { EventEmitter } from "events";
|
|
1091
1089
|
var FileLogger = class _FileLogger extends EventEmitter {
|
|
@@ -1102,8 +1100,8 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1102
1100
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
1103
1101
|
try {
|
|
1104
1102
|
const dir = path6.dirname(filePath);
|
|
1105
|
-
if (!
|
|
1106
|
-
|
|
1103
|
+
if (!fs5.existsSync(dir)) {
|
|
1104
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
1107
1105
|
}
|
|
1108
1106
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1109
1107
|
const formattedMessage = `[${timestamp}] [${level}] ${message}
|
|
@@ -1113,9 +1111,9 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1113
1111
|
return true;
|
|
1114
1112
|
}
|
|
1115
1113
|
if (append) {
|
|
1116
|
-
await
|
|
1114
|
+
await fs5.promises.appendFile(filePath, formattedMessage, "utf8");
|
|
1117
1115
|
} else {
|
|
1118
|
-
await
|
|
1116
|
+
await fs5.promises.writeFile(filePath, formattedMessage, "utf8");
|
|
1119
1117
|
}
|
|
1120
1118
|
return true;
|
|
1121
1119
|
} catch (error) {
|
|
@@ -1141,11 +1139,11 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1141
1139
|
if (buffer && buffer.length > 0) {
|
|
1142
1140
|
try {
|
|
1143
1141
|
const dir = path6.dirname(filePath);
|
|
1144
|
-
if (!
|
|
1145
|
-
|
|
1142
|
+
if (!fs5.existsSync(dir)) {
|
|
1143
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
1146
1144
|
}
|
|
1147
1145
|
const content = buffer.join("");
|
|
1148
|
-
await
|
|
1146
|
+
await fs5.promises.appendFile(filePath, content, "utf8");
|
|
1149
1147
|
_FileLogger.buffers.delete(filePath);
|
|
1150
1148
|
return true;
|
|
1151
1149
|
} catch (error) {
|
|
@@ -1281,10 +1279,10 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1281
1279
|
// Si debe retornar como array de líneas
|
|
1282
1280
|
} = options;
|
|
1283
1281
|
try {
|
|
1284
|
-
if (!
|
|
1282
|
+
if (!fs5.existsSync(filePath)) {
|
|
1285
1283
|
return asArray ? [] : "";
|
|
1286
1284
|
}
|
|
1287
|
-
let content = await
|
|
1285
|
+
let content = await fs5.promises.readFile(filePath, "utf8");
|
|
1288
1286
|
if (asArray) {
|
|
1289
1287
|
let linesArray = content.split("\n").filter((line) => line.trim() !== "");
|
|
1290
1288
|
if (lines !== null) {
|
|
@@ -1327,15 +1325,15 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1327
1325
|
} = options;
|
|
1328
1326
|
let lastSize = 0;
|
|
1329
1327
|
let lastPosition = 0;
|
|
1330
|
-
if (
|
|
1331
|
-
const stats =
|
|
1328
|
+
if (fs5.existsSync(filePath)) {
|
|
1329
|
+
const stats = fs5.statSync(filePath);
|
|
1332
1330
|
lastSize = stats.size;
|
|
1333
1331
|
lastPosition = fromEnd ? stats.size : 0;
|
|
1334
1332
|
}
|
|
1335
1333
|
const listener = async (curr, prev) => {
|
|
1336
1334
|
try {
|
|
1337
1335
|
if (curr.size > lastSize) {
|
|
1338
|
-
const stream =
|
|
1336
|
+
const stream = fs5.createReadStream(filePath, {
|
|
1339
1337
|
start: lastPosition,
|
|
1340
1338
|
end: curr.size - 1,
|
|
1341
1339
|
encoding: "utf8"
|
|
@@ -1363,7 +1361,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1363
1361
|
console.error("Error en watcher:", error);
|
|
1364
1362
|
}
|
|
1365
1363
|
};
|
|
1366
|
-
|
|
1364
|
+
fs5.watchFile(filePath, { persistent, interval }, listener);
|
|
1367
1365
|
const watcherId = `${filePath}_${Date.now()}`;
|
|
1368
1366
|
_FileLogger.watchers.set(watcherId, listener);
|
|
1369
1367
|
return {
|
|
@@ -1371,7 +1369,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1371
1369
|
stop: () => {
|
|
1372
1370
|
const storedListener = _FileLogger.watchers.get(watcherId);
|
|
1373
1371
|
if (storedListener) {
|
|
1374
|
-
|
|
1372
|
+
fs5.unwatchFile(filePath, storedListener);
|
|
1375
1373
|
_FileLogger.watchers.delete(watcherId);
|
|
1376
1374
|
}
|
|
1377
1375
|
},
|
|
@@ -1384,7 +1382,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1384
1382
|
static stopAllWatchers() {
|
|
1385
1383
|
for (const [watcherId] of _FileLogger.watchers) {
|
|
1386
1384
|
const filePath = watcherId.split("_")[0];
|
|
1387
|
-
|
|
1385
|
+
fs5.unwatchFile(filePath);
|
|
1388
1386
|
}
|
|
1389
1387
|
_FileLogger.watchers.clear();
|
|
1390
1388
|
}
|
|
@@ -1414,7 +1412,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1414
1412
|
if (lines.length > maxLines) {
|
|
1415
1413
|
const keepLines = lines.slice(-maxLines);
|
|
1416
1414
|
const content = keepLines.join("\n") + "\n";
|
|
1417
|
-
await
|
|
1415
|
+
await fs5.promises.writeFile(filePath, content, "utf8");
|
|
1418
1416
|
return lines.length - maxLines;
|
|
1419
1417
|
}
|
|
1420
1418
|
return 0;
|
|
@@ -1429,8 +1427,8 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1429
1427
|
*/
|
|
1430
1428
|
static async deleteLogFile(filePath) {
|
|
1431
1429
|
try {
|
|
1432
|
-
if (
|
|
1433
|
-
await
|
|
1430
|
+
if (fs5.existsSync(filePath)) {
|
|
1431
|
+
await fs5.promises.unlink(filePath);
|
|
1434
1432
|
return true;
|
|
1435
1433
|
}
|
|
1436
1434
|
return false;
|