@dbcube/core 1.0.36 → 1.0.40

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) {
@@ -737,36 +754,44 @@ var fs3 = __toESM(require("fs"));
737
754
  var import_util = require("util");
738
755
  var execAsync = (0, import_util.promisify)(import_child_process2.exec);
739
756
  var SqliteExecutor = class {
740
- binaryPath = null;
757
+ binaryPath;
741
758
  dbPath;
742
759
  constructor(dbPath) {
743
760
  this.dbPath = dbPath;
761
+ this.binaryPath = this.getBinaryPath();
744
762
  }
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
- }
763
+ getBinaryPath() {
764
+ const possibleDirs = [
765
+ path4.resolve(process.cwd(), ".dbcube", "bin"),
766
+ path4.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
767
+ path4.resolve(__dirname, "..", "bin")
768
+ ];
769
+ const platform2 = process.platform;
770
+ const extension = platform2 === "win32" ? ".exe" : "";
771
+ const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
772
+ for (const dir of possibleDirs) {
773
+ const fullPath = path4.join(dir, binaryName);
774
+ if (fs3.existsSync(fullPath)) {
775
+ return fullPath;
759
776
  }
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
777
  }
765
- return this.binaryPath;
778
+ const fallbackName = `sqlite-engine${extension}`;
779
+ for (const dir of possibleDirs) {
780
+ const fullPath = path4.join(dir, fallbackName);
781
+ if (fs3.existsSync(fullPath)) {
782
+ return fullPath;
783
+ }
784
+ }
785
+ return path4.join(possibleDirs[0], binaryName);
766
786
  }
767
787
  async executeBinary(args) {
768
- const binaryPath = await this.getBinaryPath();
769
- const command = `"${binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
788
+ const escapedArgs = args.map((arg) => {
789
+ if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
790
+ return `"${arg.replace(/"/g, '\\"')}"`;
791
+ }
792
+ return arg;
793
+ });
794
+ const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
770
795
  try {
771
796
  const { stdout, stderr } = await execAsync(command, {
772
797
  maxBuffer: 10 * 1024 * 1024,