@dbcube/core 1.0.26 → 1.0.30

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 CHANGED
@@ -167,18 +167,359 @@ 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 import_ora = __toESM(require("ora"));
177
+ var import_chalk = __toESM(require("chalk"));
178
+ var Downloader = class {
179
+ static mainSpinner = null;
180
+ static currentSpinner = null;
181
+ static get(prefix) {
182
+ const arch2 = new Arquitecture();
183
+ const platform2 = arch2.getPlatform();
184
+ const architecture = arch2.getArchitecture();
185
+ const platformMap = {
186
+ windows: "windows",
187
+ linux: "linux",
188
+ darwin: "macos"
189
+ };
190
+ const archMap = {
191
+ x86_64: "x64",
192
+ aarch64: "arm64"
193
+ };
194
+ const plat = platformMap[platform2];
195
+ const archSuffix = archMap[architecture];
196
+ if (plat && archSuffix) {
197
+ const baseName = `${prefix}-engine-${plat}-${archSuffix}`;
198
+ const binaryName = platform2 === "windows" ? `${baseName}.exe` : baseName;
199
+ const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-latest-${plat}-${archSuffix}.zip`;
200
+ return {
201
+ name: binaryName,
202
+ url,
203
+ query_engine: binaryName,
204
+ schema_engine: `${prefix}-engine-${plat}-${archSuffix}${platform2 === "windows" ? ".exe" : ""}`
205
+ };
206
+ }
207
+ return {
208
+ name: "",
209
+ url: "",
210
+ query_engine: "",
211
+ schema_engine: ""
212
+ };
213
+ }
214
+ static async download(targetDir) {
215
+ const binaries = ["schema", "query", "sqlite"];
216
+ const binDir = targetDir || this.getDefaultBinDir();
217
+ fs.mkdirSync(binDir, { recursive: true });
218
+ this.mainSpinner = (0, import_ora.default)({
219
+ text: import_chalk.default.blue("Descargando binarios necesarios..."),
220
+ spinner: "dots12"
221
+ }).start();
222
+ for (let i = 0; i < binaries.length; i++) {
223
+ const prefix = binaries[i];
224
+ const maxRetries = 3;
225
+ let attempt = 0;
226
+ while (attempt <= maxRetries) {
227
+ try {
228
+ const binaryInfo = this.get(prefix);
229
+ if (!binaryInfo.name || !binaryInfo.url) {
230
+ throw new Error("Plataforma o arquitectura no soportada");
231
+ }
232
+ const tempZipPath = path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
233
+ const finalBinaryPath = path.join(binDir, binaryInfo.name);
234
+ if (fs.existsSync(finalBinaryPath)) {
235
+ this.updateMainProgress(prefix, i + 1, binaries.length, "exists");
236
+ break;
237
+ }
238
+ this.updateMainProgress(prefix, i + 1, binaries.length, "downloading");
239
+ await this.downloadFileWithProgress(binaryInfo.url, tempZipPath, prefix);
240
+ this.updateMainProgress(prefix, i + 1, binaries.length, "extracting");
241
+ await this.extractBinary(tempZipPath, finalBinaryPath, prefix);
242
+ this.updateMainProgress(prefix, i + 1, binaries.length, "completed");
243
+ break;
244
+ } catch (error) {
245
+ const errorMessage = error instanceof Error ? error.message : "Error desconocido";
246
+ if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
247
+ attempt++;
248
+ this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
249
+ await new Promise((resolve5) => setTimeout(resolve5, 2e3));
250
+ } else {
251
+ this.mainSpinner.fail(import_chalk.default.red(`Error descargando ${prefix}: ${errorMessage}`));
252
+ throw error;
253
+ }
254
+ }
255
+ }
256
+ }
257
+ this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
258
+ }
259
+ static updateMainProgress(binary, current, total, status, attempt) {
260
+ const progressBar = this.createProgressBar(current, total);
261
+ const statusEmojis = {
262
+ downloading: "\u{1F4E5}",
263
+ extracting: "\u{1F4E6}",
264
+ completed: "\u2705",
265
+ exists: "\u2705",
266
+ retrying: "\u{1F504}"
267
+ };
268
+ const statusMessages = {
269
+ downloading: import_chalk.default.blue("descargando"),
270
+ extracting: import_chalk.default.yellow("extrayendo"),
271
+ completed: import_chalk.default.green("completado"),
272
+ exists: import_chalk.default.gray("existe"),
273
+ retrying: import_chalk.default.orange(`reintentando (${attempt}/${3})`)
274
+ };
275
+ const emoji = statusEmojis[status] || "\u{1F4E5}";
276
+ const message = statusMessages[status] || status;
277
+ this.mainSpinner.text = `${progressBar} ${emoji} ${import_chalk.default.bold(binary)} - ${message}`;
278
+ }
279
+ static createProgressBar(current, total, width = 20) {
280
+ const filled = Math.round(current / total * width);
281
+ const empty = width - filled;
282
+ const filledBar = import_chalk.default.green("\u2588".repeat(filled));
283
+ const emptyBar = import_chalk.default.gray("\u2591".repeat(empty));
284
+ const percentage = import_chalk.default.bold(`${current}/${total}`);
285
+ return `[${filledBar}${emptyBar}] ${percentage}`;
286
+ }
287
+ static downloadFileWithProgress(url, outputPath, prefix) {
288
+ return new Promise((resolve5, reject) => {
289
+ const request = import_follow_redirects.https.get(url, { timeout: 6e4 }, (response) => {
290
+ if (response.statusCode === 302 || response.statusCode === 301) {
291
+ const redirectUrl = response.headers.location;
292
+ if (redirectUrl) {
293
+ return this.downloadFileWithProgress(redirectUrl, outputPath, prefix).then(resolve5).catch(reject);
294
+ }
295
+ }
296
+ if (response.statusCode !== 200) {
297
+ reject(new Error(`HTTP ${response.statusCode} para ${prefix}`));
298
+ return;
299
+ }
300
+ const file = fs.createWriteStream(outputPath);
301
+ const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
302
+ let downloadedBytes = 0;
303
+ response.on("data", (chunk) => {
304
+ downloadedBytes += chunk.length;
305
+ file.write(chunk);
306
+ if (totalBytes > 0) {
307
+ const progress = {
308
+ downloaded: downloadedBytes,
309
+ total: totalBytes,
310
+ percentage: downloadedBytes / totalBytes * 100
311
+ };
312
+ this.updateDownloadProgress(prefix, progress);
313
+ }
314
+ });
315
+ response.on("end", () => {
316
+ file.end();
317
+ resolve5();
318
+ });
319
+ response.on("error", (err) => {
320
+ file.close();
321
+ this.cleanupFile(outputPath);
322
+ reject(err);
323
+ });
324
+ file.on("error", (err) => {
325
+ file.close();
326
+ this.cleanupFile(outputPath);
327
+ reject(err);
328
+ });
329
+ });
330
+ request.on("error", reject);
331
+ request.on("timeout", () => {
332
+ request.destroy();
333
+ reject(new Error(`Timeout descargando ${prefix}`));
334
+ });
335
+ });
336
+ }
337
+ static updateDownloadProgress(binary, progress) {
338
+ const percentage = progress.percentage.toFixed(1);
339
+ const downloaded = (progress.downloaded / 1024 / 1024).toFixed(1);
340
+ const total = (progress.total / 1024 / 1024).toFixed(1);
341
+ const barWidth = 15;
342
+ const filled = Math.round(progress.percentage / 100 * barWidth);
343
+ const empty = barWidth - filled;
344
+ const progressBar = import_chalk.default.green("\u2588".repeat(filled)) + import_chalk.default.gray("\u2591".repeat(empty));
345
+ const progressText = `[${progressBar}] ${percentage}% (${downloaded}/${total}MB)`;
346
+ this.mainSpinner.text = `\u{1F4E5} ${import_chalk.default.bold(binary)} - ${progressText}`;
347
+ }
348
+ static extractBinary(zipPath, outputPath, prefix) {
349
+ return new Promise((resolve5, reject) => {
350
+ let extracted = false;
351
+ fs.createReadStream(zipPath).pipe(unzipper.Parse()).on("entry", (entry) => {
352
+ if (entry.type === "File" && !extracted) {
353
+ extracted = true;
354
+ const writeStream = fs.createWriteStream(outputPath);
355
+ entry.pipe(writeStream);
356
+ writeStream.on("finish", () => {
357
+ if (process.platform !== "win32") {
358
+ fs.chmodSync(outputPath, 493);
359
+ }
360
+ this.cleanupFile(zipPath);
361
+ resolve5();
362
+ });
363
+ writeStream.on("error", (err) => {
364
+ this.cleanupFile(zipPath);
365
+ reject(err);
366
+ });
367
+ } else {
368
+ entry.autodrain();
369
+ }
370
+ }).on("error", (err) => {
371
+ this.cleanupFile(zipPath);
372
+ reject(err);
373
+ }).on("close", () => {
374
+ if (!extracted) {
375
+ this.cleanupFile(zipPath);
376
+ reject(new Error(`No se encontr\xF3 archivo v\xE1lido en el ZIP para ${prefix}`));
377
+ }
378
+ });
379
+ });
380
+ }
381
+ static cleanupFile(filePath) {
382
+ try {
383
+ if (fs.existsSync(filePath)) {
384
+ fs.unlinkSync(filePath);
385
+ }
386
+ } catch {
387
+ }
388
+ }
389
+ static getDefaultBinDir() {
390
+ const possibleDirs = [
391
+ path.resolve(process.cwd(), "bin"),
392
+ path.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
393
+ path.resolve(__dirname, "..", "bin")
394
+ ];
395
+ for (const dir of possibleDirs) {
396
+ try {
397
+ if (!fs.existsSync(dir)) {
398
+ fs.mkdirSync(dir, { recursive: true });
399
+ }
400
+ const testFile = path.join(dir, ".test");
401
+ fs.writeFileSync(testFile, "test");
402
+ fs.unlinkSync(testFile);
403
+ return dir;
404
+ } catch {
405
+ continue;
406
+ }
407
+ }
408
+ const tempDir = path.join(os2.tmpdir(), "dbcube-bin");
409
+ fs.mkdirSync(tempDir, { recursive: true });
410
+ return tempDir;
411
+ }
412
+ };
413
+
170
414
  // src/lib/Binary.ts
415
+ var fs2 = __toESM(require("fs"));
416
+ var path2 = __toESM(require("path"));
171
417
  var Binary = class {
172
- static get() {
418
+ static isDownloading = false;
419
+ static downloadPromise = null;
420
+ static async ensureBinariesExist() {
421
+ if (this.isDownloading && this.downloadPromise) {
422
+ await this.downloadPromise;
423
+ return;
424
+ }
425
+ const binDir = this.getBinDir();
426
+ const binaries = ["schema", "query", "sqlite"];
427
+ const allExist = binaries.every((prefix) => {
428
+ const binaryInfo = Downloader.get(prefix);
429
+ if (!binaryInfo.name) return false;
430
+ const binaryPath = path2.join(binDir, binaryInfo.name);
431
+ return fs2.existsSync(binaryPath);
432
+ });
433
+ if (allExist) {
434
+ return;
435
+ }
436
+ if (!this.isDownloading) {
437
+ this.isDownloading = true;
438
+ this.downloadPromise = this.downloadBinaries();
439
+ try {
440
+ await this.downloadPromise;
441
+ } finally {
442
+ this.isDownloading = false;
443
+ this.downloadPromise = null;
444
+ }
445
+ }
446
+ }
447
+ static async downloadBinaries() {
448
+ try {
449
+ const binDir = this.getBinDir();
450
+ await Downloader.download(binDir);
451
+ } catch (error) {
452
+ console.warn("\u26A0\uFE0F DBCube: Error descargando binarios:", error.message);
453
+ console.log("\u{1F527} Los binarios se intentar\xE1n descargar en la pr\xF3xima ejecuci\xF3n");
454
+ }
455
+ }
456
+ static getBinDir() {
457
+ const possibleDirs = [
458
+ path2.resolve(process.cwd(), "bin"),
459
+ path2.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
460
+ path2.resolve(__dirname, "..", "bin")
461
+ ];
462
+ for (const dir of possibleDirs) {
463
+ try {
464
+ if (!fs2.existsSync(dir)) {
465
+ fs2.mkdirSync(dir, { recursive: true });
466
+ }
467
+ return dir;
468
+ } catch {
469
+ continue;
470
+ }
471
+ }
472
+ return process.cwd();
473
+ }
474
+ static async get() {
475
+ await this.ensureBinariesExist();
173
476
  const arch2 = new Arquitecture();
174
477
  const platform2 = arch2.getPlatform();
175
478
  const architecture = arch2.getArchitecture();
479
+ const binDir = this.getBinDir();
480
+ const getFullPath = (binaryName) => {
481
+ return path2.join(binDir, binaryName);
482
+ };
176
483
  switch (platform2) {
177
484
  case "windows":
178
485
  if (architecture == "x86_64") {
179
486
  return {
180
- query_engine: "query-engine-windows-x64.exe",
181
- schema_engine: "schema-engine-windows-x64.exe"
487
+ query_engine: getFullPath("query-engine-windows-x64.exe"),
488
+ schema_engine: getFullPath("schema-engine-windows-x64.exe")
489
+ };
490
+ }
491
+ if (architecture == "aarch64") {
492
+ return {
493
+ query_engine: getFullPath("query-engine-windows-arm64.exe"),
494
+ schema_engine: getFullPath("schema-engine-windows-arm64.exe")
495
+ };
496
+ }
497
+ break;
498
+ case "linux":
499
+ if (architecture == "x86_64") {
500
+ return {
501
+ query_engine: getFullPath("query-engine-linux-x64"),
502
+ schema_engine: getFullPath("schema-engine-linux-x64")
503
+ };
504
+ }
505
+ if (architecture == "aarch64") {
506
+ return {
507
+ query_engine: getFullPath("query-engine-linux-arm64"),
508
+ schema_engine: getFullPath("schema-engine-linux-arm64")
509
+ };
510
+ }
511
+ break;
512
+ case "macos":
513
+ if (architecture == "x86_64") {
514
+ return {
515
+ query_engine: getFullPath("query-engine-macos-x64"),
516
+ schema_engine: getFullPath("schema-engine-macos-x64")
517
+ };
518
+ }
519
+ if (architecture == "aarch64") {
520
+ return {
521
+ query_engine: getFullPath("query-engine-macos-arm64"),
522
+ schema_engine: getFullPath("schema-engine-macos-arm64")
182
523
  };
183
524
  }
184
525
  break;
@@ -235,19 +576,19 @@ var Engine = class {
235
576
  name;
236
577
  config;
237
578
  arguments;
238
- binary;
579
+ binary = null;
239
580
  timeout;
240
581
  constructor(name, timeout = 3e4) {
241
582
  this.name = name;
242
583
  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
584
  this.arguments = this.setArguments();
249
585
  this.timeout = timeout;
250
586
  }
587
+ async initializeBinary() {
588
+ if (!this.binary) {
589
+ this.binary = await Binary.get();
590
+ }
591
+ }
251
592
  setArguments() {
252
593
  let args = [];
253
594
  if (this.config.type == "sqlite") {
@@ -298,7 +639,11 @@ var Engine = class {
298
639
  return this.config;
299
640
  }
300
641
  async run(binary, args) {
301
- return new Promise((resolve3, reject) => {
642
+ await this.initializeBinary();
643
+ if (!this.binary) {
644
+ throw new Error("Binary not initialized");
645
+ }
646
+ return new Promise((resolve5, reject) => {
302
647
  const child = (0, import_child_process.spawn)(this.binary[binary], [...this.arguments, ...args]);
303
648
  let stdoutBuffer = "";
304
649
  let stderrBuffer = "";
@@ -314,7 +659,7 @@ var Engine = class {
314
659
  if (!isResolved) {
315
660
  isResolved = true;
316
661
  clearTimeout(timeoutId);
317
- resolve3(response);
662
+ resolve5(response);
318
663
  }
319
664
  };
320
665
  child.stdout.on("data", (data) => {
@@ -384,7 +729,7 @@ var Engine = class {
384
729
 
385
730
  // src/lib/SqliteExecutor.ts
386
731
  var import_child_process2 = require("child_process");
387
- var path2 = __toESM(require("path"));
732
+ var path4 = __toESM(require("path"));
388
733
  var import_util = require("util");
389
734
  var execAsync = (0, import_util.promisify)(import_child_process2.exec);
390
735
  var SqliteExecutor = class {
@@ -395,11 +740,11 @@ var SqliteExecutor = class {
395
740
  this.binaryPath = this.getBinaryPath();
396
741
  }
397
742
  getBinaryPath() {
398
- const binDir = path2.resolve(__dirname, "..", "bin");
743
+ const binDir = path4.resolve(__dirname, "..", "bin");
399
744
  const platform2 = process.platform;
400
745
  const extension = platform2 === "win32" ? ".exe" : "";
401
746
  const binaryName = `sqlite-engine${extension}`;
402
- return path2.join(binDir, binaryName);
747
+ return path4.join(binDir, binaryName);
403
748
  }
404
749
  async executeBinary(args) {
405
750
  const command = `"${this.binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
@@ -541,9 +886,9 @@ var SqliteExecutor = class {
541
886
  };
542
887
 
543
888
  // src/lib/DbConfig.ts
544
- var path3 = __toESM(require("path"));
889
+ var path5 = __toESM(require("path"));
545
890
  var import_fs = __toESM(require("fs"));
546
- var rootPath = path3.resolve(process.cwd(), ".dbcube");
891
+ var rootPath = path5.resolve(process.cwd(), ".dbcube");
547
892
  var SQLite = class {
548
893
  executor = null;
549
894
  database;
@@ -553,7 +898,7 @@ var SQLite = class {
553
898
  async ifExist() {
554
899
  if (this.database) {
555
900
  const dbPath = this.database || ":memory:";
556
- const configPath = path3.join(rootPath, dbPath + ".db");
901
+ const configPath = path5.join(rootPath, dbPath + ".db");
557
902
  if (!import_fs.default.existsSync(rootPath)) {
558
903
  import_fs.default.mkdirSync(rootPath, { recursive: true });
559
904
  }
@@ -568,11 +913,11 @@ var SQLite = class {
568
913
  return false;
569
914
  }
570
915
  async connect() {
571
- return new Promise(async (resolve3, reject) => {
916
+ return new Promise(async (resolve5, reject) => {
572
917
  try {
573
918
  if (!this.executor) {
574
919
  const dbPath = this.database || ":memory:";
575
- const configPath = path3.join(rootPath, dbPath + ".db");
920
+ const configPath = path5.join(rootPath, dbPath + ".db");
576
921
  if (!import_fs.default.existsSync(rootPath)) {
577
922
  import_fs.default.mkdirSync(rootPath, { recursive: true });
578
923
  }
@@ -582,22 +927,22 @@ var SQLite = class {
582
927
  throw new Error("Failed to connect to SQLite database");
583
928
  }
584
929
  }
585
- resolve3(this.executor);
930
+ resolve5(this.executor);
586
931
  } catch (error) {
587
932
  reject(error);
588
933
  }
589
934
  });
590
935
  }
591
936
  async disconnect() {
592
- return new Promise((resolve3) => {
937
+ return new Promise((resolve5) => {
593
938
  if (this.executor) {
594
939
  this.executor = null;
595
940
  }
596
- resolve3();
941
+ resolve5();
597
942
  });
598
943
  }
599
944
  async query(sqlQuery) {
600
- return new Promise(async (resolve3) => {
945
+ return new Promise(async (resolve5) => {
601
946
  try {
602
947
  if (typeof sqlQuery !== "string") {
603
948
  throw new Error("The SQL query must be a string.");
@@ -610,20 +955,20 @@ var SQLite = class {
610
955
  }
611
956
  const result = await this.executor.queryMultiple(sqlQuery);
612
957
  if (result.status === "error") {
613
- resolve3({
958
+ resolve5({
614
959
  status: "error",
615
960
  message: result.message,
616
961
  data: null
617
962
  });
618
963
  } else {
619
- resolve3({
964
+ resolve5({
620
965
  status: "success",
621
966
  message: "Query executed successfully",
622
967
  data: result.data
623
968
  });
624
969
  }
625
970
  } catch (error) {
626
- resolve3({
971
+ resolve5({
627
972
  status: "error",
628
973
  message: error.message || "An error occurred while executing the query.",
629
974
  data: null
@@ -632,7 +977,7 @@ var SQLite = class {
632
977
  });
633
978
  }
634
979
  async queryWithParameters(sqlQuery, params = []) {
635
- return new Promise(async (resolve3) => {
980
+ return new Promise(async (resolve5) => {
636
981
  try {
637
982
  if (typeof sqlQuery !== "string") {
638
983
  throw new Error("The SQL query must be a string.");
@@ -648,13 +993,13 @@ var SQLite = class {
648
993
  }
649
994
  const result = await this.executor.query(sqlQuery, params);
650
995
  if (result.status === "error") {
651
- resolve3({
996
+ resolve5({
652
997
  status: "error",
653
998
  message: result.message,
654
999
  data: null
655
1000
  });
656
1001
  } else {
657
- resolve3({
1002
+ resolve5({
658
1003
  status: "success",
659
1004
  message: "Query executed successfully",
660
1005
  data: result.data
@@ -662,7 +1007,7 @@ var SQLite = class {
662
1007
  }
663
1008
  } catch (error) {
664
1009
  console.log(error);
665
- resolve3({
1010
+ resolve5({
666
1011
  status: "error",
667
1012
  message: error.message || "An error occurred while executing the query.",
668
1013
  data: null
@@ -756,8 +1101,8 @@ var DbConfig = new SQLite({ DATABASE: "config" });
756
1101
  var DbConfig_default = DbConfig;
757
1102
 
758
1103
  // src/lib/FileLogger.ts
759
- var fs2 = __toESM(require("fs"));
760
- var path4 = __toESM(require("path"));
1104
+ var fs4 = __toESM(require("fs"));
1105
+ var path6 = __toESM(require("path"));
761
1106
  var import_events = require("events");
762
1107
  var FileLogger = class _FileLogger extends import_events.EventEmitter {
763
1108
  static watchers = /* @__PURE__ */ new Map();
@@ -772,9 +1117,9 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
772
1117
  */
773
1118
  static async write(filePath, message, level = "INFO", append = true) {
774
1119
  try {
775
- const dir = path4.dirname(filePath);
776
- if (!fs2.existsSync(dir)) {
777
- fs2.mkdirSync(dir, { recursive: true });
1120
+ const dir = path6.dirname(filePath);
1121
+ if (!fs4.existsSync(dir)) {
1122
+ fs4.mkdirSync(dir, { recursive: true });
778
1123
  }
779
1124
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
780
1125
  const formattedMessage = `[${timestamp}] [${level}] ${message}
@@ -784,9 +1129,9 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
784
1129
  return true;
785
1130
  }
786
1131
  if (append) {
787
- await fs2.promises.appendFile(filePath, formattedMessage, "utf8");
1132
+ await fs4.promises.appendFile(filePath, formattedMessage, "utf8");
788
1133
  } else {
789
- await fs2.promises.writeFile(filePath, formattedMessage, "utf8");
1134
+ await fs4.promises.writeFile(filePath, formattedMessage, "utf8");
790
1135
  }
791
1136
  return true;
792
1137
  } catch (error) {
@@ -811,12 +1156,12 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
811
1156
  const buffer = _FileLogger.buffers.get(filePath);
812
1157
  if (buffer && buffer.length > 0) {
813
1158
  try {
814
- const dir = path4.dirname(filePath);
815
- if (!fs2.existsSync(dir)) {
816
- fs2.mkdirSync(dir, { recursive: true });
1159
+ const dir = path6.dirname(filePath);
1160
+ if (!fs4.existsSync(dir)) {
1161
+ fs4.mkdirSync(dir, { recursive: true });
817
1162
  }
818
1163
  const content = buffer.join("");
819
- await fs2.promises.appendFile(filePath, content, "utf8");
1164
+ await fs4.promises.appendFile(filePath, content, "utf8");
820
1165
  _FileLogger.buffers.delete(filePath);
821
1166
  return true;
822
1167
  } catch (error) {
@@ -952,10 +1297,10 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
952
1297
  // Si debe retornar como array de líneas
953
1298
  } = options;
954
1299
  try {
955
- if (!fs2.existsSync(filePath)) {
1300
+ if (!fs4.existsSync(filePath)) {
956
1301
  return asArray ? [] : "";
957
1302
  }
958
- let content = await fs2.promises.readFile(filePath, "utf8");
1303
+ let content = await fs4.promises.readFile(filePath, "utf8");
959
1304
  if (asArray) {
960
1305
  let linesArray = content.split("\n").filter((line) => line.trim() !== "");
961
1306
  if (lines !== null) {
@@ -998,15 +1343,15 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
998
1343
  } = options;
999
1344
  let lastSize = 0;
1000
1345
  let lastPosition = 0;
1001
- if (fs2.existsSync(filePath)) {
1002
- const stats = fs2.statSync(filePath);
1346
+ if (fs4.existsSync(filePath)) {
1347
+ const stats = fs4.statSync(filePath);
1003
1348
  lastSize = stats.size;
1004
1349
  lastPosition = fromEnd ? stats.size : 0;
1005
1350
  }
1006
1351
  const listener = async (curr, prev) => {
1007
1352
  try {
1008
1353
  if (curr.size > lastSize) {
1009
- const stream = fs2.createReadStream(filePath, {
1354
+ const stream = fs4.createReadStream(filePath, {
1010
1355
  start: lastPosition,
1011
1356
  end: curr.size - 1,
1012
1357
  encoding: "utf8"
@@ -1034,7 +1379,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
1034
1379
  console.error("Error en watcher:", error);
1035
1380
  }
1036
1381
  };
1037
- fs2.watchFile(filePath, { persistent, interval }, listener);
1382
+ fs4.watchFile(filePath, { persistent, interval }, listener);
1038
1383
  const watcherId = `${filePath}_${Date.now()}`;
1039
1384
  _FileLogger.watchers.set(watcherId, listener);
1040
1385
  return {
@@ -1042,7 +1387,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
1042
1387
  stop: () => {
1043
1388
  const storedListener = _FileLogger.watchers.get(watcherId);
1044
1389
  if (storedListener) {
1045
- fs2.unwatchFile(filePath, storedListener);
1390
+ fs4.unwatchFile(filePath, storedListener);
1046
1391
  _FileLogger.watchers.delete(watcherId);
1047
1392
  }
1048
1393
  },
@@ -1055,7 +1400,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
1055
1400
  static stopAllWatchers() {
1056
1401
  for (const [watcherId] of _FileLogger.watchers) {
1057
1402
  const filePath = watcherId.split("_")[0];
1058
- fs2.unwatchFile(filePath);
1403
+ fs4.unwatchFile(filePath);
1059
1404
  }
1060
1405
  _FileLogger.watchers.clear();
1061
1406
  }
@@ -1085,7 +1430,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
1085
1430
  if (lines.length > maxLines) {
1086
1431
  const keepLines = lines.slice(-maxLines);
1087
1432
  const content = keepLines.join("\n") + "\n";
1088
- await fs2.promises.writeFile(filePath, content, "utf8");
1433
+ await fs4.promises.writeFile(filePath, content, "utf8");
1089
1434
  return lines.length - maxLines;
1090
1435
  }
1091
1436
  return 0;
@@ -1100,8 +1445,8 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
1100
1445
  */
1101
1446
  static async deleteLogFile(filePath) {
1102
1447
  try {
1103
- if (fs2.existsSync(filePath)) {
1104
- await fs2.promises.unlink(filePath);
1448
+ if (fs4.existsSync(filePath)) {
1449
+ await fs4.promises.unlink(filePath);
1105
1450
  return true;
1106
1451
  }
1107
1452
  return false;