@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/bin.cjs +50 -33
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +50 -33
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +80 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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:
|
|
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
|
|
720
|
+
binaryPath;
|
|
704
721
|
dbPath;
|
|
705
722
|
constructor(dbPath) {
|
|
706
723
|
this.dbPath = dbPath;
|
|
724
|
+
this.binaryPath = this.getBinaryPath();
|
|
707
725
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
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
|
-
|
|
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
|
|
732
|
-
|
|
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,
|