@dbcube/core 1.0.24 → 1.0.28
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/bin.cjs +143 -120
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +143 -120
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +352 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +360 -60
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/install.cjs +0 -331
- package/dist/install.cjs.map +0 -1
- package/dist/install.d.mts +0 -2
- package/dist/install.d.ts +0 -2
- package/dist/install.js +0 -307
- package/dist/install.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -167,18 +167,314 @@ var Arquitecture = class {
|
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
+
// src/lib/Donwloader.ts
|
|
171
|
+
var fs = __toESM(require("fs"));
|
|
172
|
+
var path = __toESM(require("path"));
|
|
173
|
+
var os2 = __toESM(require("os"));
|
|
174
|
+
var import_follow_redirects = require("follow-redirects");
|
|
175
|
+
var unzipper = __toESM(require("unzipper"));
|
|
176
|
+
var Downloader = class {
|
|
177
|
+
static get(prefix) {
|
|
178
|
+
const arch2 = new Arquitecture();
|
|
179
|
+
const platform2 = arch2.getPlatform();
|
|
180
|
+
const architecture = arch2.getArchitecture();
|
|
181
|
+
const platformMap = {
|
|
182
|
+
windows: "windows",
|
|
183
|
+
linux: "linux",
|
|
184
|
+
darwin: "macos"
|
|
185
|
+
};
|
|
186
|
+
const archMap = {
|
|
187
|
+
x86_64: "x64",
|
|
188
|
+
aarch64: "arm64"
|
|
189
|
+
};
|
|
190
|
+
const plat = platformMap[platform2];
|
|
191
|
+
const archSuffix = archMap[architecture];
|
|
192
|
+
if (plat && archSuffix) {
|
|
193
|
+
const baseName = `${prefix}-engine-${plat}-${archSuffix}`;
|
|
194
|
+
const binaryName = platform2 === "windows" ? `${baseName}.exe` : baseName;
|
|
195
|
+
const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-latest-${plat}-${archSuffix}.zip`;
|
|
196
|
+
return {
|
|
197
|
+
name: binaryName,
|
|
198
|
+
url,
|
|
199
|
+
query_engine: binaryName,
|
|
200
|
+
schema_engine: `${prefix}-engine-${plat}-${archSuffix}${platform2 === "windows" ? ".exe" : ""}`
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
name: "",
|
|
205
|
+
url: "",
|
|
206
|
+
query_engine: "",
|
|
207
|
+
schema_engine: ""
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
static async download(targetDir) {
|
|
211
|
+
const binaries = ["schema", "query", "sqlite"];
|
|
212
|
+
const binDir = targetDir || this.getDefaultBinDir();
|
|
213
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
214
|
+
for (const prefix of binaries) {
|
|
215
|
+
const maxRetries = 3;
|
|
216
|
+
let attempt = 0;
|
|
217
|
+
while (attempt <= maxRetries) {
|
|
218
|
+
try {
|
|
219
|
+
console.log(`\u{1F4E5} Descargando ${prefix} (intento ${attempt + 1}/${maxRetries + 1})...`);
|
|
220
|
+
const binaryInfo = this.get(prefix);
|
|
221
|
+
if (!binaryInfo.name || !binaryInfo.url) {
|
|
222
|
+
throw new Error("Plataforma o arquitectura no soportada");
|
|
223
|
+
}
|
|
224
|
+
const tempZipPath = path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
|
|
225
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
226
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
227
|
+
console.log(`\u2705 ${prefix} ya existe, omitiendo`);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
await this.downloadFile(binaryInfo.url, tempZipPath, prefix);
|
|
231
|
+
await this.extractBinary(tempZipPath, finalBinaryPath, prefix);
|
|
232
|
+
console.log(`\u2705 ${prefix} descargado correctamente`);
|
|
233
|
+
break;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
236
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
237
|
+
console.warn(`\u26A0\uFE0F Error de red para ${prefix}: ${errorMessage}`);
|
|
238
|
+
console.log(`\u{1F504} Reintentando en 3 segundos...`);
|
|
239
|
+
attempt++;
|
|
240
|
+
await new Promise((resolve5) => setTimeout(resolve5, 3e3));
|
|
241
|
+
} else {
|
|
242
|
+
console.error(`\u274C Error final descargando ${prefix}:`, errorMessage);
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
static downloadFile(url, outputPath, prefix) {
|
|
250
|
+
return new Promise((resolve5, reject) => {
|
|
251
|
+
const request = import_follow_redirects.https.get(url, { timeout: 6e4 }, (response) => {
|
|
252
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
253
|
+
const redirectUrl = response.headers.location;
|
|
254
|
+
if (redirectUrl) {
|
|
255
|
+
return this.downloadFile(redirectUrl, outputPath, prefix).then(resolve5).catch(reject);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (response.statusCode !== 200) {
|
|
259
|
+
reject(new Error(`HTTP ${response.statusCode} para ${prefix}`));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const file = fs.createWriteStream(outputPath);
|
|
263
|
+
const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
264
|
+
let downloadedBytes = 0;
|
|
265
|
+
if (totalBytes > 0) {
|
|
266
|
+
console.log(`\u{1F4E6} Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB...`);
|
|
267
|
+
}
|
|
268
|
+
response.on("data", (chunk) => {
|
|
269
|
+
downloadedBytes += chunk.length;
|
|
270
|
+
file.write(chunk);
|
|
271
|
+
if (totalBytes > 0) {
|
|
272
|
+
const progress = (downloadedBytes / totalBytes * 100).toFixed(1);
|
|
273
|
+
process.stdout.write(`\r\u23F3 Progreso: ${progress}%`);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
response.on("end", () => {
|
|
277
|
+
file.end();
|
|
278
|
+
console.log(`
|
|
279
|
+
\u2705 Descarga de ${prefix} completada`);
|
|
280
|
+
resolve5();
|
|
281
|
+
});
|
|
282
|
+
response.on("error", (err) => {
|
|
283
|
+
file.close();
|
|
284
|
+
this.cleanupFile(outputPath);
|
|
285
|
+
reject(err);
|
|
286
|
+
});
|
|
287
|
+
file.on("error", (err) => {
|
|
288
|
+
file.close();
|
|
289
|
+
this.cleanupFile(outputPath);
|
|
290
|
+
reject(err);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
request.on("error", reject);
|
|
294
|
+
request.on("timeout", () => {
|
|
295
|
+
request.destroy();
|
|
296
|
+
reject(new Error(`Timeout descargando ${prefix}`));
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
static extractBinary(zipPath, outputPath, prefix) {
|
|
301
|
+
return new Promise((resolve5, reject) => {
|
|
302
|
+
let extracted = false;
|
|
303
|
+
fs.createReadStream(zipPath).pipe(unzipper.Parse()).on("entry", (entry) => {
|
|
304
|
+
if (entry.type === "File" && !extracted) {
|
|
305
|
+
extracted = true;
|
|
306
|
+
const writeStream = fs.createWriteStream(outputPath);
|
|
307
|
+
entry.pipe(writeStream);
|
|
308
|
+
writeStream.on("finish", () => {
|
|
309
|
+
if (process.platform !== "win32") {
|
|
310
|
+
fs.chmodSync(outputPath, 493);
|
|
311
|
+
}
|
|
312
|
+
this.cleanupFile(zipPath);
|
|
313
|
+
console.log(`\u{1F4C1} ${prefix} extra\xEDdo correctamente`);
|
|
314
|
+
resolve5();
|
|
315
|
+
});
|
|
316
|
+
writeStream.on("error", (err) => {
|
|
317
|
+
this.cleanupFile(zipPath);
|
|
318
|
+
reject(err);
|
|
319
|
+
});
|
|
320
|
+
} else {
|
|
321
|
+
entry.autodrain();
|
|
322
|
+
}
|
|
323
|
+
}).on("error", (err) => {
|
|
324
|
+
this.cleanupFile(zipPath);
|
|
325
|
+
reject(err);
|
|
326
|
+
}).on("close", () => {
|
|
327
|
+
if (!extracted) {
|
|
328
|
+
this.cleanupFile(zipPath);
|
|
329
|
+
reject(new Error(`No se encontr\xF3 archivo v\xE1lido en el ZIP para ${prefix}`));
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
static cleanupFile(filePath) {
|
|
335
|
+
try {
|
|
336
|
+
if (fs.existsSync(filePath)) {
|
|
337
|
+
fs.unlinkSync(filePath);
|
|
338
|
+
}
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
static getDefaultBinDir() {
|
|
343
|
+
const possibleDirs = [
|
|
344
|
+
path.resolve(process.cwd(), "bin"),
|
|
345
|
+
path.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
346
|
+
path.resolve(__dirname, "..", "bin")
|
|
347
|
+
];
|
|
348
|
+
for (const dir of possibleDirs) {
|
|
349
|
+
try {
|
|
350
|
+
if (!fs.existsSync(dir)) {
|
|
351
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
352
|
+
}
|
|
353
|
+
const testFile = path.join(dir, ".test");
|
|
354
|
+
fs.writeFileSync(testFile, "test");
|
|
355
|
+
fs.unlinkSync(testFile);
|
|
356
|
+
return dir;
|
|
357
|
+
} catch {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const tempDir = path.join(os2.tmpdir(), "dbcube-bin");
|
|
362
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
363
|
+
return tempDir;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
|
|
170
367
|
// src/lib/Binary.ts
|
|
368
|
+
var fs2 = __toESM(require("fs"));
|
|
369
|
+
var path2 = __toESM(require("path"));
|
|
171
370
|
var Binary = class {
|
|
172
|
-
static
|
|
371
|
+
static isDownloading = false;
|
|
372
|
+
static downloadPromise = null;
|
|
373
|
+
static async ensureBinariesExist() {
|
|
374
|
+
if (this.isDownloading && this.downloadPromise) {
|
|
375
|
+
await this.downloadPromise;
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
const binDir = this.getBinDir();
|
|
379
|
+
const binaries = ["schema", "query", "sqlite"];
|
|
380
|
+
const allExist = binaries.every((prefix) => {
|
|
381
|
+
const binaryInfo = Downloader.get(prefix);
|
|
382
|
+
if (!binaryInfo.name) return false;
|
|
383
|
+
const binaryPath = path2.join(binDir, binaryInfo.name);
|
|
384
|
+
return fs2.existsSync(binaryPath);
|
|
385
|
+
});
|
|
386
|
+
if (allExist) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (!this.isDownloading) {
|
|
390
|
+
this.isDownloading = true;
|
|
391
|
+
this.downloadPromise = this.downloadBinaries();
|
|
392
|
+
try {
|
|
393
|
+
await this.downloadPromise;
|
|
394
|
+
} finally {
|
|
395
|
+
this.isDownloading = false;
|
|
396
|
+
this.downloadPromise = null;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
static async downloadBinaries() {
|
|
401
|
+
console.log("\u{1F680} DBCube: Descargando binarios necesarios...");
|
|
402
|
+
try {
|
|
403
|
+
const binDir = this.getBinDir();
|
|
404
|
+
await Downloader.download(binDir);
|
|
405
|
+
console.log("\u2705 DBCube: Binarios descargados correctamente");
|
|
406
|
+
} catch (error) {
|
|
407
|
+
console.warn("\u26A0\uFE0F DBCube: Error descargando binarios:", error.message);
|
|
408
|
+
console.log("\u{1F527} Los binarios se intentar\xE1n descargar en la pr\xF3xima ejecuci\xF3n");
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
static getBinDir() {
|
|
412
|
+
const possibleDirs = [
|
|
413
|
+
path2.resolve(process.cwd(), "bin"),
|
|
414
|
+
path2.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
415
|
+
path2.resolve(__dirname, "..", "bin")
|
|
416
|
+
];
|
|
417
|
+
for (const dir of possibleDirs) {
|
|
418
|
+
try {
|
|
419
|
+
if (!fs2.existsSync(dir)) {
|
|
420
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
421
|
+
}
|
|
422
|
+
return dir;
|
|
423
|
+
} catch {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return process.cwd();
|
|
428
|
+
}
|
|
429
|
+
static async get() {
|
|
430
|
+
await this.ensureBinariesExist();
|
|
173
431
|
const arch2 = new Arquitecture();
|
|
174
432
|
const platform2 = arch2.getPlatform();
|
|
175
433
|
const architecture = arch2.getArchitecture();
|
|
434
|
+
const binDir = this.getBinDir();
|
|
435
|
+
const getFullPath = (binaryName) => {
|
|
436
|
+
return path2.join(binDir, binaryName);
|
|
437
|
+
};
|
|
176
438
|
switch (platform2) {
|
|
177
439
|
case "windows":
|
|
178
440
|
if (architecture == "x86_64") {
|
|
179
441
|
return {
|
|
180
|
-
query_engine: "query-engine-windows-x64.exe",
|
|
181
|
-
schema_engine: "schema-engine-windows-x64.exe"
|
|
442
|
+
query_engine: getFullPath("query-engine-windows-x64.exe"),
|
|
443
|
+
schema_engine: getFullPath("schema-engine-windows-x64.exe")
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
if (architecture == "aarch64") {
|
|
447
|
+
return {
|
|
448
|
+
query_engine: getFullPath("query-engine-windows-arm64.exe"),
|
|
449
|
+
schema_engine: getFullPath("schema-engine-windows-arm64.exe")
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
break;
|
|
453
|
+
case "linux":
|
|
454
|
+
if (architecture == "x86_64") {
|
|
455
|
+
return {
|
|
456
|
+
query_engine: getFullPath("query-engine-linux-x64"),
|
|
457
|
+
schema_engine: getFullPath("schema-engine-linux-x64")
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
if (architecture == "aarch64") {
|
|
461
|
+
return {
|
|
462
|
+
query_engine: getFullPath("query-engine-linux-arm64"),
|
|
463
|
+
schema_engine: getFullPath("schema-engine-linux-arm64")
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
case "macos":
|
|
468
|
+
if (architecture == "x86_64") {
|
|
469
|
+
return {
|
|
470
|
+
query_engine: getFullPath("query-engine-macos-x64"),
|
|
471
|
+
schema_engine: getFullPath("schema-engine-macos-x64")
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
if (architecture == "aarch64") {
|
|
475
|
+
return {
|
|
476
|
+
query_engine: getFullPath("query-engine-macos-arm64"),
|
|
477
|
+
schema_engine: getFullPath("schema-engine-macos-arm64")
|
|
182
478
|
};
|
|
183
479
|
}
|
|
184
480
|
break;
|
|
@@ -235,19 +531,19 @@ var Engine = class {
|
|
|
235
531
|
name;
|
|
236
532
|
config;
|
|
237
533
|
arguments;
|
|
238
|
-
binary;
|
|
534
|
+
binary = null;
|
|
239
535
|
timeout;
|
|
240
536
|
constructor(name, timeout = 3e4) {
|
|
241
537
|
this.name = name;
|
|
242
538
|
this.config = this.setConfig(name);
|
|
243
|
-
const binary = Binary.get();
|
|
244
|
-
this.binary = {
|
|
245
|
-
query_engine: import_path.default.resolve(__dirname, "../bin", binary.query_engine),
|
|
246
|
-
schema_engine: import_path.default.resolve(__dirname, "../bin", binary.schema_engine)
|
|
247
|
-
};
|
|
248
539
|
this.arguments = this.setArguments();
|
|
249
540
|
this.timeout = timeout;
|
|
250
541
|
}
|
|
542
|
+
async initializeBinary() {
|
|
543
|
+
if (!this.binary) {
|
|
544
|
+
this.binary = await Binary.get();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
251
547
|
setArguments() {
|
|
252
548
|
let args = [];
|
|
253
549
|
if (this.config.type == "sqlite") {
|
|
@@ -298,7 +594,11 @@ var Engine = class {
|
|
|
298
594
|
return this.config;
|
|
299
595
|
}
|
|
300
596
|
async run(binary, args) {
|
|
301
|
-
|
|
597
|
+
await this.initializeBinary();
|
|
598
|
+
if (!this.binary) {
|
|
599
|
+
throw new Error("Binary not initialized");
|
|
600
|
+
}
|
|
601
|
+
return new Promise((resolve5, reject) => {
|
|
302
602
|
const child = (0, import_child_process.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
303
603
|
let stdoutBuffer = "";
|
|
304
604
|
let stderrBuffer = "";
|
|
@@ -314,7 +614,7 @@ var Engine = class {
|
|
|
314
614
|
if (!isResolved) {
|
|
315
615
|
isResolved = true;
|
|
316
616
|
clearTimeout(timeoutId);
|
|
317
|
-
|
|
617
|
+
resolve5(response);
|
|
318
618
|
}
|
|
319
619
|
};
|
|
320
620
|
child.stdout.on("data", (data) => {
|
|
@@ -384,7 +684,7 @@ var Engine = class {
|
|
|
384
684
|
|
|
385
685
|
// src/lib/SqliteExecutor.ts
|
|
386
686
|
var import_child_process2 = require("child_process");
|
|
387
|
-
var
|
|
687
|
+
var path4 = __toESM(require("path"));
|
|
388
688
|
var import_util = require("util");
|
|
389
689
|
var execAsync = (0, import_util.promisify)(import_child_process2.exec);
|
|
390
690
|
var SqliteExecutor = class {
|
|
@@ -395,11 +695,11 @@ var SqliteExecutor = class {
|
|
|
395
695
|
this.binaryPath = this.getBinaryPath();
|
|
396
696
|
}
|
|
397
697
|
getBinaryPath() {
|
|
398
|
-
const binDir =
|
|
698
|
+
const binDir = path4.resolve(__dirname, "..", "bin");
|
|
399
699
|
const platform2 = process.platform;
|
|
400
700
|
const extension = platform2 === "win32" ? ".exe" : "";
|
|
401
701
|
const binaryName = `sqlite-engine${extension}`;
|
|
402
|
-
return
|
|
702
|
+
return path4.join(binDir, binaryName);
|
|
403
703
|
}
|
|
404
704
|
async executeBinary(args) {
|
|
405
705
|
const command = `"${this.binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
|
|
@@ -541,9 +841,9 @@ var SqliteExecutor = class {
|
|
|
541
841
|
};
|
|
542
842
|
|
|
543
843
|
// src/lib/DbConfig.ts
|
|
544
|
-
var
|
|
844
|
+
var path5 = __toESM(require("path"));
|
|
545
845
|
var import_fs = __toESM(require("fs"));
|
|
546
|
-
var rootPath =
|
|
846
|
+
var rootPath = path5.resolve(process.cwd(), ".dbcube");
|
|
547
847
|
var SQLite = class {
|
|
548
848
|
executor = null;
|
|
549
849
|
database;
|
|
@@ -553,7 +853,7 @@ var SQLite = class {
|
|
|
553
853
|
async ifExist() {
|
|
554
854
|
if (this.database) {
|
|
555
855
|
const dbPath = this.database || ":memory:";
|
|
556
|
-
const configPath =
|
|
856
|
+
const configPath = path5.join(rootPath, dbPath + ".db");
|
|
557
857
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
558
858
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
559
859
|
}
|
|
@@ -568,11 +868,11 @@ var SQLite = class {
|
|
|
568
868
|
return false;
|
|
569
869
|
}
|
|
570
870
|
async connect() {
|
|
571
|
-
return new Promise(async (
|
|
871
|
+
return new Promise(async (resolve5, reject) => {
|
|
572
872
|
try {
|
|
573
873
|
if (!this.executor) {
|
|
574
874
|
const dbPath = this.database || ":memory:";
|
|
575
|
-
const configPath =
|
|
875
|
+
const configPath = path5.join(rootPath, dbPath + ".db");
|
|
576
876
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
577
877
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
578
878
|
}
|
|
@@ -582,22 +882,22 @@ var SQLite = class {
|
|
|
582
882
|
throw new Error("Failed to connect to SQLite database");
|
|
583
883
|
}
|
|
584
884
|
}
|
|
585
|
-
|
|
885
|
+
resolve5(this.executor);
|
|
586
886
|
} catch (error) {
|
|
587
887
|
reject(error);
|
|
588
888
|
}
|
|
589
889
|
});
|
|
590
890
|
}
|
|
591
891
|
async disconnect() {
|
|
592
|
-
return new Promise((
|
|
892
|
+
return new Promise((resolve5) => {
|
|
593
893
|
if (this.executor) {
|
|
594
894
|
this.executor = null;
|
|
595
895
|
}
|
|
596
|
-
|
|
896
|
+
resolve5();
|
|
597
897
|
});
|
|
598
898
|
}
|
|
599
899
|
async query(sqlQuery) {
|
|
600
|
-
return new Promise(async (
|
|
900
|
+
return new Promise(async (resolve5) => {
|
|
601
901
|
try {
|
|
602
902
|
if (typeof sqlQuery !== "string") {
|
|
603
903
|
throw new Error("The SQL query must be a string.");
|
|
@@ -610,20 +910,20 @@ var SQLite = class {
|
|
|
610
910
|
}
|
|
611
911
|
const result = await this.executor.queryMultiple(sqlQuery);
|
|
612
912
|
if (result.status === "error") {
|
|
613
|
-
|
|
913
|
+
resolve5({
|
|
614
914
|
status: "error",
|
|
615
915
|
message: result.message,
|
|
616
916
|
data: null
|
|
617
917
|
});
|
|
618
918
|
} else {
|
|
619
|
-
|
|
919
|
+
resolve5({
|
|
620
920
|
status: "success",
|
|
621
921
|
message: "Query executed successfully",
|
|
622
922
|
data: result.data
|
|
623
923
|
});
|
|
624
924
|
}
|
|
625
925
|
} catch (error) {
|
|
626
|
-
|
|
926
|
+
resolve5({
|
|
627
927
|
status: "error",
|
|
628
928
|
message: error.message || "An error occurred while executing the query.",
|
|
629
929
|
data: null
|
|
@@ -632,7 +932,7 @@ var SQLite = class {
|
|
|
632
932
|
});
|
|
633
933
|
}
|
|
634
934
|
async queryWithParameters(sqlQuery, params = []) {
|
|
635
|
-
return new Promise(async (
|
|
935
|
+
return new Promise(async (resolve5) => {
|
|
636
936
|
try {
|
|
637
937
|
if (typeof sqlQuery !== "string") {
|
|
638
938
|
throw new Error("The SQL query must be a string.");
|
|
@@ -648,13 +948,13 @@ var SQLite = class {
|
|
|
648
948
|
}
|
|
649
949
|
const result = await this.executor.query(sqlQuery, params);
|
|
650
950
|
if (result.status === "error") {
|
|
651
|
-
|
|
951
|
+
resolve5({
|
|
652
952
|
status: "error",
|
|
653
953
|
message: result.message,
|
|
654
954
|
data: null
|
|
655
955
|
});
|
|
656
956
|
} else {
|
|
657
|
-
|
|
957
|
+
resolve5({
|
|
658
958
|
status: "success",
|
|
659
959
|
message: "Query executed successfully",
|
|
660
960
|
data: result.data
|
|
@@ -662,7 +962,7 @@ var SQLite = class {
|
|
|
662
962
|
}
|
|
663
963
|
} catch (error) {
|
|
664
964
|
console.log(error);
|
|
665
|
-
|
|
965
|
+
resolve5({
|
|
666
966
|
status: "error",
|
|
667
967
|
message: error.message || "An error occurred while executing the query.",
|
|
668
968
|
data: null
|
|
@@ -756,8 +1056,8 @@ var DbConfig = new SQLite({ DATABASE: "config" });
|
|
|
756
1056
|
var DbConfig_default = DbConfig;
|
|
757
1057
|
|
|
758
1058
|
// src/lib/FileLogger.ts
|
|
759
|
-
var
|
|
760
|
-
var
|
|
1059
|
+
var fs4 = __toESM(require("fs"));
|
|
1060
|
+
var path6 = __toESM(require("path"));
|
|
761
1061
|
var import_events = require("events");
|
|
762
1062
|
var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
763
1063
|
static watchers = /* @__PURE__ */ new Map();
|
|
@@ -772,9 +1072,9 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
772
1072
|
*/
|
|
773
1073
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
774
1074
|
try {
|
|
775
|
-
const dir =
|
|
776
|
-
if (!
|
|
777
|
-
|
|
1075
|
+
const dir = path6.dirname(filePath);
|
|
1076
|
+
if (!fs4.existsSync(dir)) {
|
|
1077
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
778
1078
|
}
|
|
779
1079
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
780
1080
|
const formattedMessage = `[${timestamp}] [${level}] ${message}
|
|
@@ -784,9 +1084,9 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
784
1084
|
return true;
|
|
785
1085
|
}
|
|
786
1086
|
if (append) {
|
|
787
|
-
await
|
|
1087
|
+
await fs4.promises.appendFile(filePath, formattedMessage, "utf8");
|
|
788
1088
|
} else {
|
|
789
|
-
await
|
|
1089
|
+
await fs4.promises.writeFile(filePath, formattedMessage, "utf8");
|
|
790
1090
|
}
|
|
791
1091
|
return true;
|
|
792
1092
|
} catch (error) {
|
|
@@ -811,12 +1111,12 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
811
1111
|
const buffer = _FileLogger.buffers.get(filePath);
|
|
812
1112
|
if (buffer && buffer.length > 0) {
|
|
813
1113
|
try {
|
|
814
|
-
const dir =
|
|
815
|
-
if (!
|
|
816
|
-
|
|
1114
|
+
const dir = path6.dirname(filePath);
|
|
1115
|
+
if (!fs4.existsSync(dir)) {
|
|
1116
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
817
1117
|
}
|
|
818
1118
|
const content = buffer.join("");
|
|
819
|
-
await
|
|
1119
|
+
await fs4.promises.appendFile(filePath, content, "utf8");
|
|
820
1120
|
_FileLogger.buffers.delete(filePath);
|
|
821
1121
|
return true;
|
|
822
1122
|
} catch (error) {
|
|
@@ -952,10 +1252,10 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
952
1252
|
// Si debe retornar como array de líneas
|
|
953
1253
|
} = options;
|
|
954
1254
|
try {
|
|
955
|
-
if (!
|
|
1255
|
+
if (!fs4.existsSync(filePath)) {
|
|
956
1256
|
return asArray ? [] : "";
|
|
957
1257
|
}
|
|
958
|
-
let content = await
|
|
1258
|
+
let content = await fs4.promises.readFile(filePath, "utf8");
|
|
959
1259
|
if (asArray) {
|
|
960
1260
|
let linesArray = content.split("\n").filter((line) => line.trim() !== "");
|
|
961
1261
|
if (lines !== null) {
|
|
@@ -998,15 +1298,15 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
998
1298
|
} = options;
|
|
999
1299
|
let lastSize = 0;
|
|
1000
1300
|
let lastPosition = 0;
|
|
1001
|
-
if (
|
|
1002
|
-
const stats =
|
|
1301
|
+
if (fs4.existsSync(filePath)) {
|
|
1302
|
+
const stats = fs4.statSync(filePath);
|
|
1003
1303
|
lastSize = stats.size;
|
|
1004
1304
|
lastPosition = fromEnd ? stats.size : 0;
|
|
1005
1305
|
}
|
|
1006
1306
|
const listener = async (curr, prev) => {
|
|
1007
1307
|
try {
|
|
1008
1308
|
if (curr.size > lastSize) {
|
|
1009
|
-
const stream =
|
|
1309
|
+
const stream = fs4.createReadStream(filePath, {
|
|
1010
1310
|
start: lastPosition,
|
|
1011
1311
|
end: curr.size - 1,
|
|
1012
1312
|
encoding: "utf8"
|
|
@@ -1034,7 +1334,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1034
1334
|
console.error("Error en watcher:", error);
|
|
1035
1335
|
}
|
|
1036
1336
|
};
|
|
1037
|
-
|
|
1337
|
+
fs4.watchFile(filePath, { persistent, interval }, listener);
|
|
1038
1338
|
const watcherId = `${filePath}_${Date.now()}`;
|
|
1039
1339
|
_FileLogger.watchers.set(watcherId, listener);
|
|
1040
1340
|
return {
|
|
@@ -1042,7 +1342,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1042
1342
|
stop: () => {
|
|
1043
1343
|
const storedListener = _FileLogger.watchers.get(watcherId);
|
|
1044
1344
|
if (storedListener) {
|
|
1045
|
-
|
|
1345
|
+
fs4.unwatchFile(filePath, storedListener);
|
|
1046
1346
|
_FileLogger.watchers.delete(watcherId);
|
|
1047
1347
|
}
|
|
1048
1348
|
},
|
|
@@ -1055,7 +1355,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1055
1355
|
static stopAllWatchers() {
|
|
1056
1356
|
for (const [watcherId] of _FileLogger.watchers) {
|
|
1057
1357
|
const filePath = watcherId.split("_")[0];
|
|
1058
|
-
|
|
1358
|
+
fs4.unwatchFile(filePath);
|
|
1059
1359
|
}
|
|
1060
1360
|
_FileLogger.watchers.clear();
|
|
1061
1361
|
}
|
|
@@ -1085,7 +1385,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1085
1385
|
if (lines.length > maxLines) {
|
|
1086
1386
|
const keepLines = lines.slice(-maxLines);
|
|
1087
1387
|
const content = keepLines.join("\n") + "\n";
|
|
1088
|
-
await
|
|
1388
|
+
await fs4.promises.writeFile(filePath, content, "utf8");
|
|
1089
1389
|
return lines.length - maxLines;
|
|
1090
1390
|
}
|
|
1091
1391
|
return 0;
|
|
@@ -1100,8 +1400,8 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1100
1400
|
*/
|
|
1101
1401
|
static async deleteLogFile(filePath) {
|
|
1102
1402
|
try {
|
|
1103
|
-
if (
|
|
1104
|
-
await
|
|
1403
|
+
if (fs4.existsSync(filePath)) {
|
|
1404
|
+
await fs4.promises.unlink(filePath);
|
|
1105
1405
|
return true;
|
|
1106
1406
|
}
|
|
1107
1407
|
return false;
|