@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/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 +79 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -48
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src/lib/Engine.ts
|
|
9
2
|
import path3 from "path";
|
|
10
3
|
|
|
@@ -182,42 +175,59 @@ var Downloader = class {
|
|
|
182
175
|
text: chalk.blue("Descargando binarios necesarios..."),
|
|
183
176
|
spinner: "dots12"
|
|
184
177
|
}).start();
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
const binariesToDownload = [];
|
|
179
|
+
let existingCount = 0;
|
|
180
|
+
for (const prefix of binaries) {
|
|
181
|
+
const binaryInfo = this.get(prefix);
|
|
182
|
+
if (!binaryInfo.name || !binaryInfo.url) {
|
|
183
|
+
throw new Error(`Plataforma o arquitectura no soportada para ${prefix}`);
|
|
184
|
+
}
|
|
185
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
186
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
187
|
+
existingCount++;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
binariesToDownload.push({
|
|
191
|
+
prefix,
|
|
192
|
+
binaryInfo,
|
|
193
|
+
tempZipPath: path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`),
|
|
194
|
+
finalBinaryPath
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (binariesToDownload.length === 0) {
|
|
198
|
+
this.mainSpinner.succeed(chalk.green("Todos los binarios ya est\xE1n descargados"));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
this.updateMainProgress("paralelo", existingCount, binaries.length, "downloading");
|
|
202
|
+
try {
|
|
203
|
+
await Promise.all(binariesToDownload.map(async (binary, index) => {
|
|
204
|
+
const maxRetries = 3;
|
|
205
|
+
let attempt = 0;
|
|
206
|
+
while (attempt <= maxRetries) {
|
|
207
|
+
try {
|
|
208
|
+
await this.downloadFileWithProgress(binary.binaryInfo.url, binary.tempZipPath, binary.prefix);
|
|
209
|
+
await this.extractBinary(binary.tempZipPath, binary.finalBinaryPath, binary.prefix);
|
|
210
|
+
const completed = existingCount + index + 1;
|
|
211
|
+
this.updateMainProgress(binary.prefix, completed, binaries.length, "completed");
|
|
199
212
|
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;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
215
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
216
|
+
attempt++;
|
|
217
|
+
this.updateMainProgress(binary.prefix, existingCount, binaries.length, "retrying", attempt);
|
|
218
|
+
await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
|
|
219
|
+
} else {
|
|
220
|
+
throw new Error(`Error descargando ${binary.prefix}: ${errorMessage}`);
|
|
221
|
+
}
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
|
-
}
|
|
224
|
+
}));
|
|
225
|
+
this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
|
|
226
|
+
} catch (error) {
|
|
227
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
228
|
+
this.mainSpinner.fail(chalk.red(`Error en descarga paralela: ${errorMessage}`));
|
|
229
|
+
throw error;
|
|
219
230
|
}
|
|
220
|
-
this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
|
|
221
231
|
}
|
|
222
232
|
static updateMainProgress(binary, current, total, status, attempt) {
|
|
223
233
|
const progressBar = this.createProgressBar(current, total);
|
|
@@ -249,7 +259,7 @@ var Downloader = class {
|
|
|
249
259
|
}
|
|
250
260
|
static downloadFileWithProgress(url, outputPath, prefix) {
|
|
251
261
|
return new Promise((resolve5, reject) => {
|
|
252
|
-
const request = https.get(url, { timeout:
|
|
262
|
+
const request = https.get(url, { timeout: 0 }, (response) => {
|
|
253
263
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
254
264
|
const redirectUrl = response.headers.location;
|
|
255
265
|
if (redirectUrl) {
|
|
@@ -538,6 +548,7 @@ var Config = class {
|
|
|
538
548
|
|
|
539
549
|
// src/lib/Engine.ts
|
|
540
550
|
import { spawn } from "child_process";
|
|
551
|
+
import { createRequire } from "module";
|
|
541
552
|
var Engine = class {
|
|
542
553
|
name;
|
|
543
554
|
config;
|
|
@@ -592,12 +603,23 @@ var Engine = class {
|
|
|
592
603
|
}
|
|
593
604
|
setConfig(name) {
|
|
594
605
|
const configInstance = new Config();
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
606
|
+
try {
|
|
607
|
+
const configFilePath = path3.resolve(process.cwd(), "dbcube.config.js");
|
|
608
|
+
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
609
|
+
const require2 = createRequire(requireUrl);
|
|
610
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
611
|
+
const configModule = require2(configFilePath);
|
|
612
|
+
const configFn = configModule.default || configModule;
|
|
613
|
+
if (typeof configFn === "function") {
|
|
614
|
+
configFn(configInstance);
|
|
615
|
+
} else {
|
|
616
|
+
console.error("\u274C El archivo dbcube.config.js no exporta una funci\xF3n.");
|
|
617
|
+
}
|
|
618
|
+
} catch (error) {
|
|
619
|
+
console.error("\u274C Error loading config file:", error.message);
|
|
620
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
621
|
+
console.error("\u274C Config file not found, please create a dbcube.config.js file");
|
|
622
|
+
}
|
|
601
623
|
}
|
|
602
624
|
return configInstance.getDatabase(name);
|
|
603
625
|
}
|
|
@@ -698,6 +720,7 @@ import { exec } from "child_process";
|
|
|
698
720
|
import * as path4 from "path";
|
|
699
721
|
import * as fs3 from "fs";
|
|
700
722
|
import { promisify } from "util";
|
|
723
|
+
import { createRequire as createRequire2 } from "module";
|
|
701
724
|
var execAsync = promisify(exec);
|
|
702
725
|
var SqliteExecutor = class {
|
|
703
726
|
binaryPath;
|
|
@@ -731,7 +754,13 @@ var SqliteExecutor = class {
|
|
|
731
754
|
return path4.join(possibleDirs[0], binaryName);
|
|
732
755
|
}
|
|
733
756
|
async executeBinary(args) {
|
|
734
|
-
const
|
|
757
|
+
const escapedArgs = args.map((arg) => {
|
|
758
|
+
if (arg.includes(" ") || arg.includes('"') || arg.includes("(") || arg.includes(")")) {
|
|
759
|
+
return `"${arg.replace(/"/g, '\\"')}"`;
|
|
760
|
+
}
|
|
761
|
+
return arg;
|
|
762
|
+
});
|
|
763
|
+
const command = `"${this.binaryPath}" ${escapedArgs.join(" ")}`;
|
|
735
764
|
try {
|
|
736
765
|
const { stdout, stderr } = await execAsync(command, {
|
|
737
766
|
maxBuffer: 10 * 1024 * 1024,
|
|
@@ -823,7 +852,9 @@ var SqliteExecutor = class {
|
|
|
823
852
|
}
|
|
824
853
|
// Para compatibilidad con better-sqlite3 API sincrona usando deasync si es necesario
|
|
825
854
|
prepareSync(sql) {
|
|
826
|
-
const
|
|
855
|
+
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
856
|
+
const require2 = createRequire2(requireUrl);
|
|
857
|
+
const deasync = require2("deasync");
|
|
827
858
|
return {
|
|
828
859
|
all: (...params) => {
|
|
829
860
|
let result;
|