@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.js CHANGED
@@ -182,42 +182,59 @@ var Downloader = class {
182
182
  text: chalk.blue("Descargando binarios necesarios..."),
183
183
  spinner: "dots12"
184
184
  }).start();
185
- for (let i = 0; i < binaries.length; i++) {
186
- const prefix = binaries[i];
187
- const maxRetries = 3;
188
- let attempt = 0;
189
- while (attempt <= maxRetries) {
190
- try {
191
- const binaryInfo = this.get(prefix);
192
- if (!binaryInfo.name || !binaryInfo.url) {
193
- throw new Error("Plataforma o arquitectura no soportada");
194
- }
195
- const tempZipPath = path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
196
- const finalBinaryPath = path.join(binDir, binaryInfo.name);
197
- if (fs.existsSync(finalBinaryPath)) {
198
- this.updateMainProgress(prefix, i + 1, binaries.length, "exists");
185
+ const binariesToDownload = [];
186
+ let existingCount = 0;
187
+ for (const prefix of binaries) {
188
+ const binaryInfo = this.get(prefix);
189
+ if (!binaryInfo.name || !binaryInfo.url) {
190
+ throw new Error(`Plataforma o arquitectura no soportada para ${prefix}`);
191
+ }
192
+ const finalBinaryPath = path.join(binDir, binaryInfo.name);
193
+ if (fs.existsSync(finalBinaryPath)) {
194
+ existingCount++;
195
+ continue;
196
+ }
197
+ binariesToDownload.push({
198
+ prefix,
199
+ binaryInfo,
200
+ tempZipPath: path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`),
201
+ finalBinaryPath
202
+ });
203
+ }
204
+ if (binariesToDownload.length === 0) {
205
+ this.mainSpinner.succeed(chalk.green("Todos los binarios ya est\xE1n descargados"));
206
+ return;
207
+ }
208
+ this.updateMainProgress("paralelo", existingCount, binaries.length, "downloading");
209
+ try {
210
+ await Promise.all(binariesToDownload.map(async (binary, index) => {
211
+ const maxRetries = 3;
212
+ let attempt = 0;
213
+ while (attempt <= maxRetries) {
214
+ try {
215
+ await this.downloadFileWithProgress(binary.binaryInfo.url, binary.tempZipPath, binary.prefix);
216
+ await this.extractBinary(binary.tempZipPath, binary.finalBinaryPath, binary.prefix);
217
+ const completed = existingCount + index + 1;
218
+ this.updateMainProgress(binary.prefix, completed, binaries.length, "completed");
199
219
  break;
200
- }
201
- this.updateMainProgress(prefix, i + 1, binaries.length, "downloading");
202
- await this.downloadFileWithProgress(binaryInfo.url, tempZipPath, prefix);
203
- this.updateMainProgress(prefix, i + 1, binaries.length, "extracting");
204
- await this.extractBinary(tempZipPath, finalBinaryPath, prefix);
205
- this.updateMainProgress(prefix, i + 1, binaries.length, "completed");
206
- break;
207
- } catch (error) {
208
- const errorMessage = error instanceof Error ? error.message : "Error desconocido";
209
- if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
210
- attempt++;
211
- this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
212
- await new Promise((resolve5) => setTimeout(resolve5, 2e3));
213
- } else {
214
- this.mainSpinner.fail(chalk.red(`Error descargando ${prefix}: ${errorMessage}`));
215
- throw error;
220
+ } catch (error) {
221
+ const errorMessage = error instanceof Error ? error.message : "Error desconocido";
222
+ if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
223
+ attempt++;
224
+ this.updateMainProgress(binary.prefix, existingCount, binaries.length, "retrying", attempt);
225
+ await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
226
+ } else {
227
+ throw new Error(`Error descargando ${binary.prefix}: ${errorMessage}`);
228
+ }
216
229
  }
217
230
  }
218
- }
231
+ }));
232
+ this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
233
+ } catch (error) {
234
+ const errorMessage = error instanceof Error ? error.message : "Error desconocido";
235
+ this.mainSpinner.fail(chalk.red(`Error en descarga paralela: ${errorMessage}`));
236
+ throw error;
219
237
  }
220
- this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
221
238
  }
222
239
  static updateMainProgress(binary, current, total, status, attempt) {
223
240
  const progressBar = this.createProgressBar(current, total);
@@ -249,7 +266,7 @@ var Downloader = class {
249
266
  }
250
267
  static downloadFileWithProgress(url, outputPath, prefix) {
251
268
  return new Promise((resolve5, reject) => {
252
- const request = https.get(url, { timeout: 6e4 }, (response) => {
269
+ const request = https.get(url, { timeout: 0 }, (response) => {
253
270
  if (response.statusCode === 302 || response.statusCode === 301) {
254
271
  const redirectUrl = response.headers.location;
255
272
  if (redirectUrl) {
@@ -700,36 +717,44 @@ import * as fs3 from "fs";
700
717
  import { promisify } from "util";
701
718
  var execAsync = promisify(exec);
702
719
  var SqliteExecutor = class {
703
- binaryPath = null;
720
+ binaryPath;
704
721
  dbPath;
705
722
  constructor(dbPath) {
706
723
  this.dbPath = dbPath;
724
+ this.binaryPath = this.getBinaryPath();
707
725
  }
708
- async getBinaryPath() {
709
- if (!this.binaryPath) {
710
- await Binary.ensureBinariesExist();
711
- const possibleDirs = [
712
- path4.resolve(process.cwd(), ".dbcube", "bin"),
713
- path4.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
714
- path4.resolve(__dirname, "..", "bin")
715
- ];
716
- let binDir = "";
717
- for (const dir of possibleDirs) {
718
- if (fs3.existsSync(dir)) {
719
- binDir = dir;
720
- break;
721
- }
726
+ getBinaryPath() {
727
+ const possibleDirs = [
728
+ path4.resolve(process.cwd(), ".dbcube", "bin"),
729
+ path4.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
730
+ path4.resolve(__dirname, "..", "bin")
731
+ ];
732
+ const platform2 = process.platform;
733
+ const extension = platform2 === "win32" ? ".exe" : "";
734
+ const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
735
+ for (const dir of possibleDirs) {
736
+ const fullPath = path4.join(dir, binaryName);
737
+ if (fs3.existsSync(fullPath)) {
738
+ return fullPath;
722
739
  }
723
- const platform2 = process.platform;
724
- const extension = platform2 === "win32" ? ".exe" : "";
725
- const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
726
- this.binaryPath = path4.join(binDir, binaryName);
727
740
  }
728
- return this.binaryPath;
741
+ const fallbackName = `sqlite-engine${extension}`;
742
+ for (const dir of possibleDirs) {
743
+ const fullPath = path4.join(dir, fallbackName);
744
+ if (fs3.existsSync(fullPath)) {
745
+ return fullPath;
746
+ }
747
+ }
748
+ return path4.join(possibleDirs[0], binaryName);
729
749
  }
730
750
  async executeBinary(args) {
731
- const binaryPath = await this.getBinaryPath();
732
- const command = `"${binaryPath}" ${args.map((arg) => `"${arg}"`).join(" ")}`;
751
+ const escapedArgs = args.map((arg) => {
752
+ if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
753
+ return `"${arg.replace(/"/g, '\\"')}"`;
754
+ }
755
+ return arg;
756
+ });
757
+ const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
733
758
  try {
734
759
  const { stdout, stderr } = await execAsync(command, {
735
760
  maxBuffer: 10 * 1024 * 1024,