@dbcube/core 1.0.38 → 1.0.43

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
@@ -219,42 +219,59 @@ var Downloader = class {
219
219
  text: import_chalk.default.blue("Descargando binarios necesarios..."),
220
220
  spinner: "dots12"
221
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");
222
+ const binariesToDownload = [];
223
+ let existingCount = 0;
224
+ for (const prefix of binaries) {
225
+ const binaryInfo = this.get(prefix);
226
+ if (!binaryInfo.name || !binaryInfo.url) {
227
+ throw new Error(`Plataforma o arquitectura no soportada para ${prefix}`);
228
+ }
229
+ const finalBinaryPath = path.join(binDir, binaryInfo.name);
230
+ if (fs.existsSync(finalBinaryPath)) {
231
+ existingCount++;
232
+ continue;
233
+ }
234
+ binariesToDownload.push({
235
+ prefix,
236
+ binaryInfo,
237
+ tempZipPath: path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`),
238
+ finalBinaryPath
239
+ });
240
+ }
241
+ if (binariesToDownload.length === 0) {
242
+ this.mainSpinner.succeed(import_chalk.default.green("Todos los binarios ya est\xE1n descargados"));
243
+ return;
244
+ }
245
+ this.updateMainProgress("paralelo", existingCount, binaries.length, "downloading");
246
+ try {
247
+ await Promise.all(binariesToDownload.map(async (binary, index) => {
248
+ const maxRetries = 3;
249
+ let attempt = 0;
250
+ while (attempt <= maxRetries) {
251
+ try {
252
+ await this.downloadFileWithProgress(binary.binaryInfo.url, binary.tempZipPath, binary.prefix);
253
+ await this.extractBinary(binary.tempZipPath, binary.finalBinaryPath, binary.prefix);
254
+ const completed = existingCount + index + 1;
255
+ this.updateMainProgress(binary.prefix, completed, binaries.length, "completed");
236
256
  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;
257
+ } catch (error) {
258
+ const errorMessage = error instanceof Error ? error.message : "Error desconocido";
259
+ if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
260
+ attempt++;
261
+ this.updateMainProgress(binary.prefix, existingCount, binaries.length, "retrying", attempt);
262
+ await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
263
+ } else {
264
+ throw new Error(`Error descargando ${binary.prefix}: ${errorMessage}`);
265
+ }
253
266
  }
254
267
  }
255
- }
268
+ }));
269
+ this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
270
+ } catch (error) {
271
+ const errorMessage = error instanceof Error ? error.message : "Error desconocido";
272
+ this.mainSpinner.fail(import_chalk.default.red(`Error en descarga paralela: ${errorMessage}`));
273
+ throw error;
256
274
  }
257
- this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
258
275
  }
259
276
  static updateMainProgress(binary, current, total, status, attempt) {
260
277
  const progressBar = this.createProgressBar(current, total);
@@ -286,7 +303,7 @@ var Downloader = class {
286
303
  }
287
304
  static downloadFileWithProgress(url, outputPath, prefix) {
288
305
  return new Promise((resolve5, reject) => {
289
- const request = import_follow_redirects.https.get(url, { timeout: 6e4 }, (response) => {
306
+ const request = import_follow_redirects.https.get(url, { timeout: 0 }, (response) => {
290
307
  if (response.statusCode === 302 || response.statusCode === 301) {
291
308
  const redirectUrl = response.headers.location;
292
309
  if (redirectUrl) {
@@ -575,6 +592,7 @@ var Config = class {
575
592
 
576
593
  // src/lib/Engine.ts
577
594
  var import_child_process = require("child_process");
595
+ var import_module = require("module");
578
596
  var Engine = class {
579
597
  name;
580
598
  config;
@@ -629,12 +647,23 @@ var Engine = class {
629
647
  }
630
648
  setConfig(name) {
631
649
  const configInstance = new Config();
632
- const configFilePath = import_path.default.resolve(process.cwd(), "dbcube.config.js");
633
- const configFn = require(configFilePath);
634
- if (typeof configFn === "function") {
635
- configFn(configInstance);
636
- } else {
637
- console.error("\u274C El archivo dbcube.config.js no exporta una funci\xF3n.");
650
+ try {
651
+ const configFilePath = import_path.default.resolve(process.cwd(), "dbcube.config.js");
652
+ const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
653
+ const require2 = (0, import_module.createRequire)(requireUrl);
654
+ delete require2.cache[require2.resolve(configFilePath)];
655
+ const configModule = require2(configFilePath);
656
+ const configFn = configModule.default || configModule;
657
+ if (typeof configFn === "function") {
658
+ configFn(configInstance);
659
+ } else {
660
+ console.error("\u274C El archivo dbcube.config.js no exporta una funci\xF3n.");
661
+ }
662
+ } catch (error) {
663
+ console.error("\u274C Error loading config file:", error.message);
664
+ if (error.code === "MODULE_NOT_FOUND") {
665
+ console.error("\u274C Config file not found, please create a dbcube.config.js file");
666
+ }
638
667
  }
639
668
  return configInstance.getDatabase(name);
640
669
  }
@@ -735,6 +764,7 @@ var import_child_process2 = require("child_process");
735
764
  var path4 = __toESM(require("path"));
736
765
  var fs3 = __toESM(require("fs"));
737
766
  var import_util = require("util");
767
+ var import_module2 = require("module");
738
768
  var execAsync = (0, import_util.promisify)(import_child_process2.exec);
739
769
  var SqliteExecutor = class {
740
770
  binaryPath;
@@ -768,7 +798,13 @@ var SqliteExecutor = class {
768
798
  return path4.join(possibleDirs[0], binaryName);
769
799
  }
770
800
  async executeBinary(args) {
771
- const command = `"${this.binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
801
+ const escapedArgs = args.map((arg) => {
802
+ if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
803
+ return `"${arg.replace(/"/g, '\\"')}"`;
804
+ }
805
+ return arg;
806
+ });
807
+ const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
772
808
  try {
773
809
  const { stdout, stderr } = await execAsync(command, {
774
810
  maxBuffer: 10 * 1024 * 1024,
@@ -860,7 +896,9 @@ var SqliteExecutor = class {
860
896
  }
861
897
  // Para compatibilidad con better-sqlite3 API sincrona usando deasync si es necesario
862
898
  prepareSync(sql) {
863
- const deasync = require("deasync");
899
+ const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
900
+ const require2 = (0, import_module2.createRequire)(requireUrl);
901
+ const deasync = require2("deasync");
864
902
  return {
865
903
  all: (...params) => {
866
904
  let result;