@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.cjs
CHANGED
|
@@ -465,9 +465,6 @@ var Binary = class {
|
|
|
465
465
|
if (!fs2.existsSync(dir)) {
|
|
466
466
|
fs2.mkdirSync(dir, { recursive: true });
|
|
467
467
|
}
|
|
468
|
-
if (dir.includes(path2.resolve(process.cwd(), ".dbcube"))) {
|
|
469
|
-
this.ensureGitIgnore(path2.resolve(process.cwd(), ".dbcube"));
|
|
470
|
-
}
|
|
471
468
|
return dir;
|
|
472
469
|
} catch {
|
|
473
470
|
continue;
|
|
@@ -477,21 +474,6 @@ var Binary = class {
|
|
|
477
474
|
fs2.mkdirSync(tempDir, { recursive: true });
|
|
478
475
|
return tempDir;
|
|
479
476
|
}
|
|
480
|
-
static ensureGitIgnore(dbcubeDir) {
|
|
481
|
-
try {
|
|
482
|
-
const gitignorePath = path2.join(dbcubeDir, ".gitignore");
|
|
483
|
-
if (!fs2.existsSync(gitignorePath)) {
|
|
484
|
-
const gitignoreContent = `# DBCube binaries
|
|
485
|
-
bin/
|
|
486
|
-
*.exe
|
|
487
|
-
*.log
|
|
488
|
-
*.tmp
|
|
489
|
-
`;
|
|
490
|
-
fs2.writeFileSync(gitignorePath, gitignoreContent);
|
|
491
|
-
}
|
|
492
|
-
} catch {
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
477
|
static async get() {
|
|
496
478
|
await this.ensureBinariesExist();
|
|
497
479
|
const arch2 = new Arquitecture();
|
|
@@ -751,24 +733,40 @@ var Engine = class {
|
|
|
751
733
|
// src/lib/SqliteExecutor.ts
|
|
752
734
|
var import_child_process2 = require("child_process");
|
|
753
735
|
var path4 = __toESM(require("path"));
|
|
736
|
+
var fs3 = __toESM(require("fs"));
|
|
754
737
|
var import_util = require("util");
|
|
755
738
|
var execAsync = (0, import_util.promisify)(import_child_process2.exec);
|
|
756
739
|
var SqliteExecutor = class {
|
|
757
|
-
binaryPath;
|
|
740
|
+
binaryPath = null;
|
|
758
741
|
dbPath;
|
|
759
742
|
constructor(dbPath) {
|
|
760
743
|
this.dbPath = dbPath;
|
|
761
|
-
this.binaryPath = this.getBinaryPath();
|
|
762
744
|
}
|
|
763
|
-
getBinaryPath() {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
745
|
+
async getBinaryPath() {
|
|
746
|
+
if (!this.binaryPath) {
|
|
747
|
+
await Binary.ensureBinariesExist();
|
|
748
|
+
const possibleDirs = [
|
|
749
|
+
path4.resolve(process.cwd(), ".dbcube", "bin"),
|
|
750
|
+
path4.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
751
|
+
path4.resolve(__dirname, "..", "bin")
|
|
752
|
+
];
|
|
753
|
+
let binDir = "";
|
|
754
|
+
for (const dir of possibleDirs) {
|
|
755
|
+
if (fs3.existsSync(dir)) {
|
|
756
|
+
binDir = dir;
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
const platform2 = process.platform;
|
|
761
|
+
const extension = platform2 === "win32" ? ".exe" : "";
|
|
762
|
+
const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
|
|
763
|
+
this.binaryPath = path4.join(binDir, binaryName);
|
|
764
|
+
}
|
|
765
|
+
return this.binaryPath;
|
|
769
766
|
}
|
|
770
767
|
async executeBinary(args) {
|
|
771
|
-
const
|
|
768
|
+
const binaryPath = await this.getBinaryPath();
|
|
769
|
+
const command = `"${binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
|
|
772
770
|
try {
|
|
773
771
|
const { stdout, stderr } = await execAsync(command, {
|
|
774
772
|
maxBuffer: 10 * 1024 * 1024,
|
|
@@ -1122,7 +1120,7 @@ var DbConfig = new SQLite({ DATABASE: "config" });
|
|
|
1122
1120
|
var DbConfig_default = DbConfig;
|
|
1123
1121
|
|
|
1124
1122
|
// src/lib/FileLogger.ts
|
|
1125
|
-
var
|
|
1123
|
+
var fs5 = __toESM(require("fs"));
|
|
1126
1124
|
var path6 = __toESM(require("path"));
|
|
1127
1125
|
var import_events = require("events");
|
|
1128
1126
|
var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
@@ -1139,8 +1137,8 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1139
1137
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
1140
1138
|
try {
|
|
1141
1139
|
const dir = path6.dirname(filePath);
|
|
1142
|
-
if (!
|
|
1143
|
-
|
|
1140
|
+
if (!fs5.existsSync(dir)) {
|
|
1141
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
1144
1142
|
}
|
|
1145
1143
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1146
1144
|
const formattedMessage = `[${timestamp}] [${level}] ${message}
|
|
@@ -1150,9 +1148,9 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1150
1148
|
return true;
|
|
1151
1149
|
}
|
|
1152
1150
|
if (append) {
|
|
1153
|
-
await
|
|
1151
|
+
await fs5.promises.appendFile(filePath, formattedMessage, "utf8");
|
|
1154
1152
|
} else {
|
|
1155
|
-
await
|
|
1153
|
+
await fs5.promises.writeFile(filePath, formattedMessage, "utf8");
|
|
1156
1154
|
}
|
|
1157
1155
|
return true;
|
|
1158
1156
|
} catch (error) {
|
|
@@ -1178,11 +1176,11 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1178
1176
|
if (buffer && buffer.length > 0) {
|
|
1179
1177
|
try {
|
|
1180
1178
|
const dir = path6.dirname(filePath);
|
|
1181
|
-
if (!
|
|
1182
|
-
|
|
1179
|
+
if (!fs5.existsSync(dir)) {
|
|
1180
|
+
fs5.mkdirSync(dir, { recursive: true });
|
|
1183
1181
|
}
|
|
1184
1182
|
const content = buffer.join("");
|
|
1185
|
-
await
|
|
1183
|
+
await fs5.promises.appendFile(filePath, content, "utf8");
|
|
1186
1184
|
_FileLogger.buffers.delete(filePath);
|
|
1187
1185
|
return true;
|
|
1188
1186
|
} catch (error) {
|
|
@@ -1318,10 +1316,10 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1318
1316
|
// Si debe retornar como array de líneas
|
|
1319
1317
|
} = options;
|
|
1320
1318
|
try {
|
|
1321
|
-
if (!
|
|
1319
|
+
if (!fs5.existsSync(filePath)) {
|
|
1322
1320
|
return asArray ? [] : "";
|
|
1323
1321
|
}
|
|
1324
|
-
let content = await
|
|
1322
|
+
let content = await fs5.promises.readFile(filePath, "utf8");
|
|
1325
1323
|
if (asArray) {
|
|
1326
1324
|
let linesArray = content.split("\n").filter((line) => line.trim() !== "");
|
|
1327
1325
|
if (lines !== null) {
|
|
@@ -1364,15 +1362,15 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1364
1362
|
} = options;
|
|
1365
1363
|
let lastSize = 0;
|
|
1366
1364
|
let lastPosition = 0;
|
|
1367
|
-
if (
|
|
1368
|
-
const stats =
|
|
1365
|
+
if (fs5.existsSync(filePath)) {
|
|
1366
|
+
const stats = fs5.statSync(filePath);
|
|
1369
1367
|
lastSize = stats.size;
|
|
1370
1368
|
lastPosition = fromEnd ? stats.size : 0;
|
|
1371
1369
|
}
|
|
1372
1370
|
const listener = async (curr, prev) => {
|
|
1373
1371
|
try {
|
|
1374
1372
|
if (curr.size > lastSize) {
|
|
1375
|
-
const stream =
|
|
1373
|
+
const stream = fs5.createReadStream(filePath, {
|
|
1376
1374
|
start: lastPosition,
|
|
1377
1375
|
end: curr.size - 1,
|
|
1378
1376
|
encoding: "utf8"
|
|
@@ -1400,7 +1398,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1400
1398
|
console.error("Error en watcher:", error);
|
|
1401
1399
|
}
|
|
1402
1400
|
};
|
|
1403
|
-
|
|
1401
|
+
fs5.watchFile(filePath, { persistent, interval }, listener);
|
|
1404
1402
|
const watcherId = `${filePath}_${Date.now()}`;
|
|
1405
1403
|
_FileLogger.watchers.set(watcherId, listener);
|
|
1406
1404
|
return {
|
|
@@ -1408,7 +1406,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1408
1406
|
stop: () => {
|
|
1409
1407
|
const storedListener = _FileLogger.watchers.get(watcherId);
|
|
1410
1408
|
if (storedListener) {
|
|
1411
|
-
|
|
1409
|
+
fs5.unwatchFile(filePath, storedListener);
|
|
1412
1410
|
_FileLogger.watchers.delete(watcherId);
|
|
1413
1411
|
}
|
|
1414
1412
|
},
|
|
@@ -1421,7 +1419,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1421
1419
|
static stopAllWatchers() {
|
|
1422
1420
|
for (const [watcherId] of _FileLogger.watchers) {
|
|
1423
1421
|
const filePath = watcherId.split("_")[0];
|
|
1424
|
-
|
|
1422
|
+
fs5.unwatchFile(filePath);
|
|
1425
1423
|
}
|
|
1426
1424
|
_FileLogger.watchers.clear();
|
|
1427
1425
|
}
|
|
@@ -1451,7 +1449,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1451
1449
|
if (lines.length > maxLines) {
|
|
1452
1450
|
const keepLines = lines.slice(-maxLines);
|
|
1453
1451
|
const content = keepLines.join("\n") + "\n";
|
|
1454
|
-
await
|
|
1452
|
+
await fs5.promises.writeFile(filePath, content, "utf8");
|
|
1455
1453
|
return lines.length - maxLines;
|
|
1456
1454
|
}
|
|
1457
1455
|
return 0;
|
|
@@ -1466,8 +1464,8 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1466
1464
|
*/
|
|
1467
1465
|
static async deleteLogFile(filePath) {
|
|
1468
1466
|
try {
|
|
1469
|
-
if (
|
|
1470
|
-
await
|
|
1467
|
+
if (fs5.existsSync(filePath)) {
|
|
1468
|
+
await fs5.promises.unlink(filePath);
|
|
1471
1469
|
return true;
|
|
1472
1470
|
}
|
|
1473
1471
|
return false;
|