@dbcube/core 1.0.23 → 1.0.26
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 +375 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.mts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +352 -0
- package/dist/bin.js.map +1 -0
- package/dist/install.cjs +131 -88
- package/dist/install.cjs.map +1 -1
- package/dist/install.js +131 -88
- package/dist/install.js.map +1 -1
- package/package.json +4 -1
package/dist/bin.js
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/Arquitecture.ts
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
var Arquitecture = class {
|
|
6
|
+
systemInfo;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.systemInfo = this.detectSystemInfo();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Detecta información completa del sistema
|
|
12
|
+
*/
|
|
13
|
+
detectSystemInfo() {
|
|
14
|
+
return {
|
|
15
|
+
platform: os.platform(),
|
|
16
|
+
arch: os.arch(),
|
|
17
|
+
release: os.release(),
|
|
18
|
+
type: os.type(),
|
|
19
|
+
endianness: os.endianness(),
|
|
20
|
+
cpus: os.cpus().length
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Obtiene la plataforma normalizada
|
|
25
|
+
*/
|
|
26
|
+
getPlatform() {
|
|
27
|
+
const platform2 = this.systemInfo.platform;
|
|
28
|
+
switch (platform2) {
|
|
29
|
+
case "win32":
|
|
30
|
+
return "windows";
|
|
31
|
+
case "darwin":
|
|
32
|
+
return "macos";
|
|
33
|
+
case "linux":
|
|
34
|
+
return "linux";
|
|
35
|
+
case "freebsd":
|
|
36
|
+
return "freebsd";
|
|
37
|
+
case "openbsd":
|
|
38
|
+
return "openbsd";
|
|
39
|
+
case "sunos":
|
|
40
|
+
return "solaris";
|
|
41
|
+
default:
|
|
42
|
+
return platform2;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Obtiene la arquitectura normalizada
|
|
47
|
+
*/
|
|
48
|
+
getArchitecture() {
|
|
49
|
+
const arch2 = this.systemInfo.arch;
|
|
50
|
+
switch (arch2) {
|
|
51
|
+
case "x64":
|
|
52
|
+
return "x86_64";
|
|
53
|
+
case "x32":
|
|
54
|
+
case "ia32":
|
|
55
|
+
return "i686";
|
|
56
|
+
case "arm64":
|
|
57
|
+
return "aarch64";
|
|
58
|
+
case "arm":
|
|
59
|
+
return "armv7";
|
|
60
|
+
case "ppc64":
|
|
61
|
+
return "powerpc64";
|
|
62
|
+
case "ppc":
|
|
63
|
+
return "powerpc";
|
|
64
|
+
case "s390x":
|
|
65
|
+
return "s390x";
|
|
66
|
+
case "mips":
|
|
67
|
+
return "mips";
|
|
68
|
+
case "mipsel":
|
|
69
|
+
return "mipsel";
|
|
70
|
+
default:
|
|
71
|
+
return arch2;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Genera el nombre del binario basado en la arquitectura
|
|
76
|
+
*/
|
|
77
|
+
getBinaryName(baseName) {
|
|
78
|
+
const platform2 = this.getPlatform();
|
|
79
|
+
const arch2 = this.getArchitecture();
|
|
80
|
+
const extension = platform2 === "windows" ? ".exe" : "";
|
|
81
|
+
return `${baseName}-${platform2}-${arch2}${extension}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Obtiene información completa del sistema
|
|
85
|
+
*/
|
|
86
|
+
getSystemInfo() {
|
|
87
|
+
return { ...this.systemInfo };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Obtiene el triple de destino (target triple) para Rust
|
|
91
|
+
*/
|
|
92
|
+
getRustTargetTriple() {
|
|
93
|
+
const platform2 = this.getPlatform();
|
|
94
|
+
const arch2 = this.getArchitecture();
|
|
95
|
+
const targetMap = {
|
|
96
|
+
"linux-x86_64": "x86_64-unknown-linux-gnu",
|
|
97
|
+
"linux-i686": "i686-unknown-linux-gnu",
|
|
98
|
+
"linux-aarch64": "aarch64-unknown-linux-gnu",
|
|
99
|
+
"linux-armv7": "armv7-unknown-linux-gnueabihf",
|
|
100
|
+
"macos-x86_64": "x86_64-apple-darwin",
|
|
101
|
+
"macos-aarch64": "aarch64-apple-darwin",
|
|
102
|
+
"windows-x86_64": "x86_64-pc-windows-msvc",
|
|
103
|
+
"windows-i686": "i686-pc-windows-msvc",
|
|
104
|
+
"windows-aarch64": "aarch64-pc-windows-msvc",
|
|
105
|
+
"freebsd-x86_64": "x86_64-unknown-freebsd"
|
|
106
|
+
};
|
|
107
|
+
const key = `${platform2}-${arch2}`;
|
|
108
|
+
return targetMap[key] || `${arch2}-unknown-${platform2}`;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Muestra información detallada del sistema
|
|
112
|
+
*/
|
|
113
|
+
printSystemInfo() {
|
|
114
|
+
console.log("\u{1F5A5}\uFE0F System Information:");
|
|
115
|
+
console.log("\u251C\u2500 Platform:", this.getPlatform());
|
|
116
|
+
console.log("\u251C\u2500 Arquitecture:", this.getArchitecture());
|
|
117
|
+
console.log("\u251C\u2500 OS Type:", this.systemInfo.type);
|
|
118
|
+
console.log("\u251C\u2500 OS Release:", this.systemInfo.release);
|
|
119
|
+
console.log("\u251C\u2500 Endianness:", this.systemInfo.endianness);
|
|
120
|
+
console.log("\u251C\u2500 CPUs:", this.systemInfo.cpus);
|
|
121
|
+
console.log("\u2514\u2500 Rust Target:", this.getRustTargetTriple());
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/lib/Donwloader.ts
|
|
126
|
+
import * as fs from "fs";
|
|
127
|
+
import * as path from "path";
|
|
128
|
+
import * as os2 from "os";
|
|
129
|
+
import { https } from "follow-redirects";
|
|
130
|
+
import * as unzipper from "unzipper";
|
|
131
|
+
var Downloader = class {
|
|
132
|
+
static get(prefix) {
|
|
133
|
+
const arch2 = new Arquitecture();
|
|
134
|
+
const platform2 = arch2.getPlatform();
|
|
135
|
+
const architecture = arch2.getArchitecture();
|
|
136
|
+
const platformMap = {
|
|
137
|
+
windows: "windows",
|
|
138
|
+
linux: "linux",
|
|
139
|
+
darwin: "macos"
|
|
140
|
+
};
|
|
141
|
+
const archMap = {
|
|
142
|
+
x86_64: "x64",
|
|
143
|
+
arm64: "arm64"
|
|
144
|
+
};
|
|
145
|
+
const plat = platformMap[platform2];
|
|
146
|
+
const archSuffix = archMap[architecture];
|
|
147
|
+
if (plat && archSuffix) {
|
|
148
|
+
const baseName = `${prefix}-engine-${plat}-${archSuffix}`;
|
|
149
|
+
const binaryName = platform2 === "windows" ? `${baseName}.exe` : baseName;
|
|
150
|
+
const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-latest-${plat}-${archSuffix}.zip`;
|
|
151
|
+
return {
|
|
152
|
+
name: binaryName,
|
|
153
|
+
url,
|
|
154
|
+
query_engine: binaryName,
|
|
155
|
+
schema_engine: `${prefix}-engine-${plat}-${archSuffix}${platform2 === "windows" ? ".exe" : ""}`
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
name: "",
|
|
160
|
+
url: "",
|
|
161
|
+
query_engine: "",
|
|
162
|
+
schema_engine: ""
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
static async download() {
|
|
166
|
+
const binaries = ["schema", "query", "sqlite"];
|
|
167
|
+
const binDir = path.resolve(__dirname, "..", "bin");
|
|
168
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
169
|
+
for (const prefix of binaries) {
|
|
170
|
+
const maxRetries = 2;
|
|
171
|
+
let attempt = 0;
|
|
172
|
+
while (attempt <= maxRetries) {
|
|
173
|
+
try {
|
|
174
|
+
console.log(`==> Empezando descarga para: ${prefix} (intento ${attempt + 1}/${maxRetries + 1})`);
|
|
175
|
+
const binaryInfo = this.get(prefix);
|
|
176
|
+
console.log(`Descargando: ${binaryInfo.name}`);
|
|
177
|
+
console.log(`URL: ${binaryInfo.url}`);
|
|
178
|
+
if (!binaryInfo.name) {
|
|
179
|
+
throw new Error("Unsupported platform or architecture");
|
|
180
|
+
}
|
|
181
|
+
const tempZipPath = path.join(os2.tmpdir(), `binary-${prefix}-${Date.now()}.zip`);
|
|
182
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
183
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
184
|
+
console.log(`\u26A0\uFE0F El binario ya existe, omitiendo: ${finalBinaryPath}`);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
await new Promise((resolve2, reject) => {
|
|
188
|
+
console.log(`Iniciando descarga de ${prefix}...`);
|
|
189
|
+
const request = https.get(binaryInfo.url, (response) => {
|
|
190
|
+
console.log(`HTTP ${response.statusCode} para ${prefix}`);
|
|
191
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
192
|
+
const redirectUrl = response.headers.location;
|
|
193
|
+
if (redirectUrl) {
|
|
194
|
+
console.log(`Redirigiendo a: ${redirectUrl}`);
|
|
195
|
+
https.get(redirectUrl, handleResponse);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (response.statusCode !== 200) {
|
|
200
|
+
reject(new Error(`HTTP ${response.statusCode} para ${prefix}`));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
handleResponse(response);
|
|
204
|
+
});
|
|
205
|
+
function handleResponse(response) {
|
|
206
|
+
const file = fs.createWriteStream(tempZipPath);
|
|
207
|
+
const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
208
|
+
let downloadedBytes = 0;
|
|
209
|
+
console.log(`Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB para ${prefix}...`);
|
|
210
|
+
response.on("data", (chunk) => {
|
|
211
|
+
downloadedBytes += chunk.length;
|
|
212
|
+
file.write(chunk);
|
|
213
|
+
});
|
|
214
|
+
response.on("end", () => {
|
|
215
|
+
file.end();
|
|
216
|
+
console.log(`\u2705 Descarga completada para ${prefix}`);
|
|
217
|
+
resolve2();
|
|
218
|
+
});
|
|
219
|
+
response.on("error", (err) => {
|
|
220
|
+
file.close();
|
|
221
|
+
try {
|
|
222
|
+
fs.unlinkSync(tempZipPath);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
reject(err);
|
|
226
|
+
});
|
|
227
|
+
file.on("error", (err) => {
|
|
228
|
+
file.close();
|
|
229
|
+
try {
|
|
230
|
+
fs.unlinkSync(tempZipPath);
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
reject(err);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
request.on("error", (err) => {
|
|
237
|
+
reject(err);
|
|
238
|
+
});
|
|
239
|
+
request.setTimeout(12e4, () => {
|
|
240
|
+
request.destroy();
|
|
241
|
+
reject(new Error(`Timeout descargando ${prefix}`));
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
console.log(`Zip descargado para ${prefix}, extrayendo...`);
|
|
245
|
+
await new Promise((resolve2, reject) => {
|
|
246
|
+
let extracted = false;
|
|
247
|
+
fs.createReadStream(tempZipPath).pipe(unzipper.Parse()).on("entry", (entry) => {
|
|
248
|
+
const fileName = entry.path;
|
|
249
|
+
const type2 = entry.type;
|
|
250
|
+
console.log(`Encontrado en ZIP: ${fileName} (${type2})`);
|
|
251
|
+
if (type2 === "File" && !extracted) {
|
|
252
|
+
extracted = true;
|
|
253
|
+
const writeStream = fs.createWriteStream(finalBinaryPath);
|
|
254
|
+
entry.pipe(writeStream);
|
|
255
|
+
writeStream.on("finish", () => {
|
|
256
|
+
if (process.platform !== "win32") {
|
|
257
|
+
fs.chmodSync(finalBinaryPath, 493);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
fs.unlinkSync(tempZipPath);
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
console.log(`Binario extra\xEDdo y guardado: ${finalBinaryPath}`);
|
|
264
|
+
resolve2();
|
|
265
|
+
});
|
|
266
|
+
writeStream.on("error", (err) => {
|
|
267
|
+
try {
|
|
268
|
+
fs.unlinkSync(tempZipPath);
|
|
269
|
+
} catch {
|
|
270
|
+
}
|
|
271
|
+
reject(err);
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
entry.autodrain();
|
|
275
|
+
}
|
|
276
|
+
}).on("error", (err) => {
|
|
277
|
+
try {
|
|
278
|
+
fs.unlinkSync(tempZipPath);
|
|
279
|
+
} catch {
|
|
280
|
+
}
|
|
281
|
+
reject(err);
|
|
282
|
+
}).on("close", () => {
|
|
283
|
+
if (!extracted) {
|
|
284
|
+
try {
|
|
285
|
+
fs.unlinkSync(tempZipPath);
|
|
286
|
+
} catch {
|
|
287
|
+
}
|
|
288
|
+
reject(new Error(`No se encontr\xF3 ning\xFAn archivo v\xE1lido en el ZIP para ${prefix}`));
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
console.log(`==> Finaliz\xF3 descarga y extracci\xF3n para: ${prefix}`);
|
|
293
|
+
break;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
296
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout"))) {
|
|
297
|
+
console.warn(`\u26A0\uFE0F Error de conexi\xF3n para ${prefix}: ${errorMessage}`);
|
|
298
|
+
console.log(`\u{1F504} Reintentando en 2 segundos...`);
|
|
299
|
+
attempt++;
|
|
300
|
+
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
301
|
+
} else {
|
|
302
|
+
console.error(`\u274C Error final descargando ${prefix} despu\xE9s de ${attempt + 1} intentos:`, errorMessage);
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/bin.ts
|
|
312
|
+
async function main() {
|
|
313
|
+
const args = process.argv.slice(2);
|
|
314
|
+
const command = args[0];
|
|
315
|
+
switch (command) {
|
|
316
|
+
case "install":
|
|
317
|
+
case "download":
|
|
318
|
+
console.log("\u{1F680} Iniciando descarga de binarios DBCube...");
|
|
319
|
+
try {
|
|
320
|
+
await Downloader.download();
|
|
321
|
+
console.log("\u2705 \xA1Todos los binarios descargados exitosamente!");
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error("\u274C Error descargando binarios:", error);
|
|
324
|
+
process.exit(1);
|
|
325
|
+
}
|
|
326
|
+
break;
|
|
327
|
+
case "check":
|
|
328
|
+
console.log("\u{1F50D} Verificando binarios...");
|
|
329
|
+
const binaries = ["schema", "query", "sqlite"];
|
|
330
|
+
for (const prefix of binaries) {
|
|
331
|
+
const binary = Downloader.get(prefix);
|
|
332
|
+
console.log(`${prefix}-engine: ${binary.name}`);
|
|
333
|
+
console.log(` URL: ${binary.url}`);
|
|
334
|
+
}
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
console.log("DBCube Binary Manager");
|
|
338
|
+
console.log("");
|
|
339
|
+
console.log("Comandos disponibles:");
|
|
340
|
+
console.log(" install|download - Descargar todos los binarios");
|
|
341
|
+
console.log(" check - Verificar informaci\xF3n de binarios");
|
|
342
|
+
console.log("");
|
|
343
|
+
console.log("Uso:");
|
|
344
|
+
console.log(" npx @dbcube/core install");
|
|
345
|
+
console.log(" npx @dbcube/core check");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
main().catch((error) => {
|
|
349
|
+
console.error("Error:", error);
|
|
350
|
+
process.exit(1);
|
|
351
|
+
});
|
|
352
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/Arquitecture.ts","../src/lib/Donwloader.ts","../src/bin.ts"],"sourcesContent":["import * as os from 'os';\r\nimport * as path from 'path';\r\nimport * as fs from 'fs';\r\n\r\ninterface SystemInfo {\r\n platform: string;\r\n arch: string;\r\n release: string;\r\n type: string;\r\n endianness: string;\r\n cpus: number;\r\n}\r\n\r\ninterface BinaryInfo {\r\n name: string;\r\n path: string;\r\n exists: boolean;\r\n executable: boolean;\r\n}\r\n\r\nclass Arquitecture {\r\n private systemInfo: SystemInfo;\r\n\r\n constructor() {\r\n this.systemInfo = this.detectSystemInfo();\r\n }\r\n\r\n /**\r\n * Detecta información completa del sistema\r\n */\r\n private detectSystemInfo(): SystemInfo {\r\n return {\r\n platform: os.platform(),\r\n arch: os.arch(),\r\n release: os.release(),\r\n type: os.type(),\r\n endianness: os.endianness(),\r\n cpus: os.cpus().length\r\n };\r\n }\r\n\r\n /**\r\n * Obtiene la plataforma normalizada\r\n */\r\n getPlatform(): string {\r\n const platform = this.systemInfo.platform;\r\n \r\n switch (platform) {\r\n case 'win32':\r\n return 'windows';\r\n case 'darwin':\r\n return 'macos';\r\n case 'linux':\r\n return 'linux';\r\n case 'freebsd':\r\n return 'freebsd';\r\n case 'openbsd':\r\n return 'openbsd';\r\n case 'sunos':\r\n return 'solaris';\r\n default:\r\n return platform;\r\n }\r\n }\r\n\r\n /**\r\n * Obtiene la arquitectura normalizada\r\n */\r\n getArchitecture(): string {\r\n const arch = this.systemInfo.arch;\r\n \r\n switch (arch) {\r\n case 'x64':\r\n return 'x86_64';\r\n case 'x32':\r\n case 'ia32':\r\n return 'i686';\r\n case 'arm64':\r\n return 'aarch64';\r\n case 'arm':\r\n return 'armv7';\r\n case 'ppc64':\r\n return 'powerpc64';\r\n case 'ppc':\r\n return 'powerpc';\r\n case 's390x':\r\n return 's390x';\r\n case 'mips':\r\n return 'mips';\r\n case 'mipsel':\r\n return 'mipsel';\r\n default:\r\n return arch;\r\n }\r\n }\r\n\r\n /**\r\n * Genera el nombre del binario basado en la arquitectura\r\n */\r\n getBinaryName(baseName: string): string {\r\n const platform = this.getPlatform();\r\n const arch = this.getArchitecture();\r\n const extension = platform === 'windows' ? '.exe' : '';\r\n \r\n return `${baseName}-${platform}-${arch}${extension}`;\r\n }\r\n\r\n /**\r\n * Obtiene información completa del sistema\r\n */\r\n getSystemInfo(): SystemInfo {\r\n return { ...this.systemInfo };\r\n }\r\n\r\n /**\r\n * Obtiene el triple de destino (target triple) para Rust\r\n */\r\n getRustTargetTriple(): string {\r\n const platform = this.getPlatform();\r\n const arch = this.getArchitecture();\r\n \r\n // Mapeo de plataformas y arquitecturas a target triples de Rust\r\n const targetMap: { [key: string]: string } = {\r\n 'linux-x86_64': 'x86_64-unknown-linux-gnu',\r\n 'linux-i686': 'i686-unknown-linux-gnu',\r\n 'linux-aarch64': 'aarch64-unknown-linux-gnu',\r\n 'linux-armv7': 'armv7-unknown-linux-gnueabihf',\r\n 'macos-x86_64': 'x86_64-apple-darwin',\r\n 'macos-aarch64': 'aarch64-apple-darwin',\r\n 'windows-x86_64': 'x86_64-pc-windows-msvc',\r\n 'windows-i686': 'i686-pc-windows-msvc',\r\n 'windows-aarch64': 'aarch64-pc-windows-msvc',\r\n 'freebsd-x86_64': 'x86_64-unknown-freebsd',\r\n };\r\n \r\n const key = `${platform}-${arch}`;\r\n return targetMap[key] || `${arch}-unknown-${platform}`;\r\n }\r\n\r\n /**\r\n * Muestra información detallada del sistema\r\n */\r\n printSystemInfo(): void {\r\n console.log('🖥️ System Information:');\r\n console.log('├─ Platform:', this.getPlatform());\r\n console.log('├─ Arquitecture:', this.getArchitecture());\r\n console.log('├─ OS Type:', this.systemInfo.type);\r\n console.log('├─ OS Release:', this.systemInfo.release);\r\n console.log('├─ Endianness:', this.systemInfo.endianness);\r\n console.log('├─ CPUs:', this.systemInfo.cpus);\r\n console.log('└─ Rust Target:', this.getRustTargetTriple());\r\n }\r\n}\r\n\r\nexport { \r\n Arquitecture, \r\n SystemInfo,\r\n BinaryInfo\r\n};","import { BinaryType } from \"../@types/Binary\";\r\nimport { Arquitecture } from \"./Arquitecture\";\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport * as os from \"os\";\r\nimport { https } from 'follow-redirects';\r\nimport * as unzipper from \"unzipper\";\r\nimport { IncomingMessage } from 'http';\r\n\r\nclass Downloader {\r\n static get(prefix: string): BinaryType & { name: string; url: string } {\r\n const arch = new Arquitecture();\r\n const platform = arch.getPlatform();\r\n const architecture = arch.getArchitecture();\r\n \r\n const platformMap: Record<string, string> = {\r\n windows: \"windows\",\r\n linux: \"linux\",\r\n darwin: \"macos\"\r\n };\r\n \r\n const archMap: Record<string, string> = {\r\n x86_64: \"x64\",\r\n arm64: \"arm64\"\r\n };\r\n \r\n const plat = platformMap[platform];\r\n const archSuffix = archMap[architecture];\r\n \r\n if (plat && archSuffix) {\r\n const baseName = `${prefix}-engine-${plat}-${archSuffix}`;\r\n const binaryName = platform === \"windows\" ? `${baseName}.exe` : baseName;\r\n \r\n const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-latest-${plat}-${archSuffix}.zip`;\r\n return {\r\n name: binaryName,\r\n url,\r\n query_engine: binaryName,\r\n schema_engine: `${prefix}-engine-${plat}-${archSuffix}${platform === \"windows\" ? \".exe\" : \"\"}`\r\n };\r\n }\r\n \r\n return {\r\n name: \"\",\r\n url: \"\",\r\n query_engine: \"\",\r\n schema_engine: \"\"\r\n };\r\n }\r\n\r\n static async download(): Promise<void> {\r\n const binaries = ['schema', 'query', 'sqlite'];\r\n const binDir = path.resolve(__dirname, \"..\", \"bin\");\r\n fs.mkdirSync(binDir, { recursive: true });\r\n\r\n for (const prefix of binaries) {\r\n const maxRetries = 2;\r\n let attempt = 0;\r\n \r\n while (attempt <= maxRetries) {\r\n try {\r\n console.log(`==> Empezando descarga para: ${prefix} (intento ${attempt + 1}/${maxRetries + 1})`);\r\n const binaryInfo = this.get(prefix);\r\n console.log(`Descargando: ${binaryInfo.name}`);\r\n console.log(`URL: ${binaryInfo.url}`);\r\n\r\n if (!binaryInfo.name) {\r\n throw new Error(\"Unsupported platform or architecture\");\r\n }\r\n\r\n const tempZipPath = path.join(os.tmpdir(), `binary-${prefix}-${Date.now()}.zip`);\r\n const finalBinaryPath = path.join(binDir, binaryInfo.name);\r\n\r\n if (fs.existsSync(finalBinaryPath)) {\r\n console.log(`⚠️ El binario ya existe, omitiendo: ${finalBinaryPath}`);\r\n break;\r\n }\r\n\r\n // Descargar el archivo ZIP de forma más robusta\r\n await new Promise<void>((resolve, reject) => {\r\n console.log(`Iniciando descarga de ${prefix}...`);\r\n \r\n const request = https.get(binaryInfo.url, (response: IncomingMessage) => {\r\n console.log(`HTTP ${response.statusCode} para ${prefix}`);\r\n \r\n if (response.statusCode === 302 || response.statusCode === 301) {\r\n // Manejar redirección\r\n const redirectUrl = response.headers.location;\r\n if (redirectUrl) {\r\n console.log(`Redirigiendo a: ${redirectUrl}`);\r\n https.get(redirectUrl, handleResponse);\r\n return;\r\n }\r\n }\r\n \r\n if (response.statusCode !== 200) {\r\n reject(new Error(`HTTP ${response.statusCode} para ${prefix}`));\r\n return;\r\n }\r\n\r\n handleResponse(response);\r\n });\r\n\r\n function handleResponse(response: IncomingMessage) {\r\n const file = fs.createWriteStream(tempZipPath);\r\n const totalBytes = parseInt(response.headers['content-length'] || '0', 10);\r\n let downloadedBytes = 0;\r\n \r\n console.log(`Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB para ${prefix}...`);\r\n\r\n response.on('data', (chunk) => {\r\n downloadedBytes += chunk.length;\r\n file.write(chunk);\r\n });\r\n\r\n response.on('end', () => {\r\n file.end();\r\n console.log(`✅ Descarga completada para ${prefix}`);\r\n resolve();\r\n });\r\n\r\n response.on('error', (err) => {\r\n file.close();\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n reject(err);\r\n });\r\n\r\n file.on('error', (err) => {\r\n file.close();\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n reject(err);\r\n });\r\n }\r\n\r\n request.on('error', (err) => {\r\n reject(err);\r\n });\r\n\r\n // Timeout de 2 minutos\r\n request.setTimeout(120000, () => {\r\n request.destroy();\r\n reject(new Error(`Timeout descargando ${prefix}`));\r\n });\r\n });\r\n\r\n console.log(`Zip descargado para ${prefix}, extrayendo...`);\r\n\r\n // Extraer el archivo ZIP\r\n await new Promise<void>((resolve, reject) => {\r\n let extracted = false;\r\n \r\n fs.createReadStream(tempZipPath)\r\n .pipe(unzipper.Parse())\r\n .on('entry', (entry: unzipper.Entry) => {\r\n const fileName: string = entry.path;\r\n const type: string = entry.type;\r\n \r\n console.log(`Encontrado en ZIP: ${fileName} (${type})`);\r\n \r\n if (type === 'File' && !extracted) {\r\n extracted = true;\r\n const writeStream = fs.createWriteStream(finalBinaryPath);\r\n \r\n entry.pipe(writeStream);\r\n \r\n writeStream.on('finish', () => {\r\n // Hacer el archivo ejecutable en sistemas Unix\r\n if (process.platform !== 'win32') {\r\n fs.chmodSync(finalBinaryPath, 0o755);\r\n }\r\n \r\n // Limpiar archivo temporal\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n \r\n console.log(`Binario extraído y guardado: ${finalBinaryPath}`);\r\n resolve();\r\n });\r\n \r\n writeStream.on('error', (err: Error) => {\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n reject(err);\r\n });\r\n } else {\r\n entry.autodrain();\r\n }\r\n })\r\n .on('error', (err: Error) => {\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n reject(err);\r\n })\r\n .on('close', () => {\r\n if (!extracted) {\r\n try { fs.unlinkSync(tempZipPath); } catch {}\r\n reject(new Error(`No se encontró ningún archivo válido en el ZIP para ${prefix}`));\r\n }\r\n });\r\n });\r\n\r\n console.log(`==> Finalizó descarga y extracción para: ${prefix}`);\r\n break; // Éxito, salir del loop de reintentos\r\n\r\n } catch (error: unknown) {\r\n const errorMessage = error instanceof Error ? error.message : 'Error desconocido';\r\n \r\n if (attempt < maxRetries && (errorMessage.includes('ECONNRESET') || errorMessage.includes('timeout'))) {\r\n console.warn(`⚠️ Error de conexión para ${prefix}: ${errorMessage}`);\r\n console.log(`🔄 Reintentando en 2 segundos...`);\r\n attempt++;\r\n await new Promise(resolve => setTimeout(resolve, 2000));\r\n } else {\r\n console.error(`❌ Error final descargando ${prefix} después de ${attempt + 1} intentos:`, errorMessage);\r\n throw error; // Re-lanzar después de todos los intentos\r\n }\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport { Downloader };","#!/usr/bin/env node\r\n\r\nimport { Downloader } from \"./lib/Donwloader\";\r\n\r\n/**\r\n * Script CLI para descargar binarios manualmente\r\n */\r\nasync function main() {\r\n const args = process.argv.slice(2);\r\n const command = args[0];\r\n\r\n switch (command) {\r\n case 'install':\r\n case 'download':\r\n console.log('🚀 Iniciando descarga de binarios DBCube...');\r\n try {\r\n await Downloader.download();\r\n console.log('✅ ¡Todos los binarios descargados exitosamente!');\r\n } catch (error) {\r\n console.error('❌ Error descargando binarios:', error);\r\n process.exit(1);\r\n }\r\n break;\r\n \r\n case 'check':\r\n console.log('🔍 Verificando binarios...');\r\n const binaries = ['schema', 'query', 'sqlite'];\r\n for (const prefix of binaries) {\r\n const binary = Downloader.get(prefix);\r\n console.log(`${prefix}-engine: ${binary.name}`);\r\n console.log(` URL: ${binary.url}`);\r\n }\r\n break;\r\n \r\n default:\r\n console.log('DBCube Binary Manager');\r\n console.log('');\r\n console.log('Comandos disponibles:');\r\n console.log(' install|download - Descargar todos los binarios');\r\n console.log(' check - Verificar información de binarios');\r\n console.log('');\r\n console.log('Uso:');\r\n console.log(' npx @dbcube/core install');\r\n console.log(' npx @dbcube/core check');\r\n }\r\n}\r\n\r\nmain().catch(error => {\r\n console.error('Error:', error);\r\n process.exit(1);\r\n});"],"mappings":";;;AAAA,YAAY,QAAQ;AAoBpB,IAAM,eAAN,MAAmB;AAAA,EACP;AAAA,EAER,cAAc;AACV,SAAK,aAAa,KAAK,iBAAiB;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAA+B;AACnC,WA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MAAM,sCAAiC,KAAK;AACpD,gBAAQ,KAAK,CAAC;AAAA,MAClB;AACA;AAAA,IAEJ,KAAK;AACD,cAAQ,IAAI,mCAA4B;AACxC,YAAM,WAAW,CAAC,UAAU,SAAS,QAAQ;AAC7C,iBAAW,UAAU,UAAU;AAC3B,cAAM,SAAS,WAAW,IAAI,MAAM;AACpC,gBAAQ,IAAI,GAAG,MAAM,YAAY,OAAO,IAAI,EAAE;AAC9C,gBAAQ,IAAI,UAAU,OAAO,GAAG,EAAE;AAAA,MACtC;AACA;AAAA,IAEJ;AACI,cAAQ,IAAI,uBAAuB;AACnC,cAAQ,IAAI,EAAE;AACd,cAAQ,IAAI,uBAAuB;AACnC,cAAQ,IAAI,oDAAoD;AAChE,cAAQ,IAAI,2DAAwD;AACpE,cAAQ,IAAI,EAAE;AACd,cAAQ,IAAI,MAAM;AAClB,cAAQ,IAAI,4BAA4B;AACxC,cAAQ,IAAI,0BAA0B;AAAA,EAC9C;AACJ;AAEA,KAAK,EAAE,MAAM,WAAS;AAClB,UAAQ,MAAM,UAAU,KAAK;AAC7B,UAAQ,KAAK,CAAC;AAClB,CAAC;","names":["platform","arch","os","arch","platform","resolve","type"]}
|
package/dist/install.cjs
CHANGED
|
@@ -189,108 +189,142 @@ var Downloader = class {
|
|
|
189
189
|
const binDir = path.resolve(__dirname, "..", "bin");
|
|
190
190
|
fs.mkdirSync(binDir, { recursive: true });
|
|
191
191
|
for (const prefix of binaries) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
192
|
+
const maxRetries = 2;
|
|
193
|
+
let attempt = 0;
|
|
194
|
+
while (attempt <= maxRetries) {
|
|
195
|
+
try {
|
|
196
|
+
console.log(`==> Empezando descarga para: ${prefix} (intento ${attempt + 1}/${maxRetries + 1})`);
|
|
197
|
+
const binaryInfo = this.get(prefix);
|
|
198
|
+
console.log(`Descargando: ${binaryInfo.name}`);
|
|
199
|
+
console.log(`URL: ${binaryInfo.url}`);
|
|
200
|
+
if (!binaryInfo.name) {
|
|
201
|
+
throw new Error("Unsupported platform or architecture");
|
|
202
|
+
}
|
|
203
|
+
const tempZipPath = path.join(os2.tmpdir(), `binary-${prefix}-${Date.now()}.zip`);
|
|
204
|
+
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
205
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
206
|
+
console.log(`\u26A0\uFE0F El binario ya existe, omitiendo: ${finalBinaryPath}`);
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
await new Promise((resolve2, reject) => {
|
|
210
|
+
console.log(`Iniciando descarga de ${prefix}...`);
|
|
211
|
+
const request = import_follow_redirects.https.get(binaryInfo.url, (response) => {
|
|
212
|
+
console.log(`HTTP ${response.statusCode} para ${prefix}`);
|
|
213
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
214
|
+
const redirectUrl = response.headers.location;
|
|
215
|
+
if (redirectUrl) {
|
|
216
|
+
console.log(`Redirigiendo a: ${redirectUrl}`);
|
|
217
|
+
import_follow_redirects.https.get(redirectUrl, handleResponse);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
215
220
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
response.pipe(file);
|
|
220
|
-
file.on("finish", () => {
|
|
221
|
-
file.close();
|
|
222
|
-
resolve2();
|
|
223
|
-
});
|
|
224
|
-
file.on("error", (err) => {
|
|
225
|
-
file.close();
|
|
226
|
-
try {
|
|
227
|
-
fs.unlinkSync(tempZipPath);
|
|
228
|
-
} catch {
|
|
221
|
+
if (response.statusCode !== 200) {
|
|
222
|
+
reject(new Error(`HTTP ${response.statusCode} para ${prefix}`));
|
|
223
|
+
return;
|
|
229
224
|
}
|
|
230
|
-
|
|
225
|
+
handleResponse(response);
|
|
231
226
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (type2 === "File" && !extracted) {
|
|
249
|
-
extracted = true;
|
|
250
|
-
const writeStream = fs.createWriteStream(finalBinaryPath);
|
|
251
|
-
entry.pipe(writeStream);
|
|
252
|
-
writeStream.on("finish", () => {
|
|
253
|
-
if (process.platform !== "win32") {
|
|
254
|
-
fs.chmodSync(finalBinaryPath, 493);
|
|
255
|
-
}
|
|
227
|
+
function handleResponse(response) {
|
|
228
|
+
const file = fs.createWriteStream(tempZipPath);
|
|
229
|
+
const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
230
|
+
let downloadedBytes = 0;
|
|
231
|
+
console.log(`Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB para ${prefix}...`);
|
|
232
|
+
response.on("data", (chunk) => {
|
|
233
|
+
downloadedBytes += chunk.length;
|
|
234
|
+
file.write(chunk);
|
|
235
|
+
});
|
|
236
|
+
response.on("end", () => {
|
|
237
|
+
file.end();
|
|
238
|
+
console.log(`\u2705 Descarga completada para ${prefix}`);
|
|
239
|
+
resolve2();
|
|
240
|
+
});
|
|
241
|
+
response.on("error", (err) => {
|
|
242
|
+
file.close();
|
|
256
243
|
try {
|
|
257
244
|
fs.unlinkSync(tempZipPath);
|
|
258
245
|
} catch {
|
|
259
246
|
}
|
|
260
|
-
|
|
261
|
-
resolve2();
|
|
247
|
+
reject(err);
|
|
262
248
|
});
|
|
263
|
-
|
|
249
|
+
file.on("error", (err) => {
|
|
250
|
+
file.close();
|
|
264
251
|
try {
|
|
265
252
|
fs.unlinkSync(tempZipPath);
|
|
266
253
|
} catch {
|
|
267
254
|
}
|
|
268
255
|
reject(err);
|
|
269
256
|
});
|
|
270
|
-
} else {
|
|
271
|
-
entry.autodrain();
|
|
272
|
-
}
|
|
273
|
-
}).on("error", (err) => {
|
|
274
|
-
try {
|
|
275
|
-
fs.unlinkSync(tempZipPath);
|
|
276
|
-
} catch {
|
|
277
257
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
258
|
+
request.on("error", (err) => {
|
|
259
|
+
reject(err);
|
|
260
|
+
});
|
|
261
|
+
request.setTimeout(12e4, () => {
|
|
262
|
+
request.destroy();
|
|
263
|
+
reject(new Error(`Timeout descargando ${prefix}`));
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
console.log(`Zip descargado para ${prefix}, extrayendo...`);
|
|
267
|
+
await new Promise((resolve2, reject) => {
|
|
268
|
+
let extracted = false;
|
|
269
|
+
fs.createReadStream(tempZipPath).pipe(unzipper.Parse()).on("entry", (entry) => {
|
|
270
|
+
const fileName = entry.path;
|
|
271
|
+
const type2 = entry.type;
|
|
272
|
+
console.log(`Encontrado en ZIP: ${fileName} (${type2})`);
|
|
273
|
+
if (type2 === "File" && !extracted) {
|
|
274
|
+
extracted = true;
|
|
275
|
+
const writeStream = fs.createWriteStream(finalBinaryPath);
|
|
276
|
+
entry.pipe(writeStream);
|
|
277
|
+
writeStream.on("finish", () => {
|
|
278
|
+
if (process.platform !== "win32") {
|
|
279
|
+
fs.chmodSync(finalBinaryPath, 493);
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
fs.unlinkSync(tempZipPath);
|
|
283
|
+
} catch {
|
|
284
|
+
}
|
|
285
|
+
console.log(`Binario extra\xEDdo y guardado: ${finalBinaryPath}`);
|
|
286
|
+
resolve2();
|
|
287
|
+
});
|
|
288
|
+
writeStream.on("error", (err) => {
|
|
289
|
+
try {
|
|
290
|
+
fs.unlinkSync(tempZipPath);
|
|
291
|
+
} catch {
|
|
292
|
+
}
|
|
293
|
+
reject(err);
|
|
294
|
+
});
|
|
295
|
+
} else {
|
|
296
|
+
entry.autodrain();
|
|
297
|
+
}
|
|
298
|
+
}).on("error", (err) => {
|
|
281
299
|
try {
|
|
282
300
|
fs.unlinkSync(tempZipPath);
|
|
283
301
|
} catch {
|
|
284
302
|
}
|
|
285
|
-
reject(
|
|
286
|
-
}
|
|
303
|
+
reject(err);
|
|
304
|
+
}).on("close", () => {
|
|
305
|
+
if (!extracted) {
|
|
306
|
+
try {
|
|
307
|
+
fs.unlinkSync(tempZipPath);
|
|
308
|
+
} catch {
|
|
309
|
+
}
|
|
310
|
+
reject(new Error(`No se encontr\xF3 ning\xFAn archivo v\xE1lido en el ZIP para ${prefix}`));
|
|
311
|
+
}
|
|
312
|
+
});
|
|
287
313
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
314
|
+
console.log(`==> Finaliz\xF3 descarga y extracci\xF3n para: ${prefix}`);
|
|
315
|
+
break;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
318
|
+
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout"))) {
|
|
319
|
+
console.warn(`\u26A0\uFE0F Error de conexi\xF3n para ${prefix}: ${errorMessage}`);
|
|
320
|
+
console.log(`\u{1F504} Reintentando en 2 segundos...`);
|
|
321
|
+
attempt++;
|
|
322
|
+
await new Promise((resolve2) => setTimeout(resolve2, 2e3));
|
|
323
|
+
} else {
|
|
324
|
+
console.error(`\u274C Error final descargando ${prefix} despu\xE9s de ${attempt + 1} intentos:`, errorMessage);
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
294
328
|
}
|
|
295
329
|
}
|
|
296
330
|
}
|
|
@@ -298,12 +332,21 @@ var Downloader = class {
|
|
|
298
332
|
|
|
299
333
|
// src/install.ts
|
|
300
334
|
(async () => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
335
|
+
console.log("\u{1F680} DBCube: Instalando binarios...");
|
|
336
|
+
try {
|
|
337
|
+
const binaries = ["schema", "query", "sqlite"];
|
|
338
|
+
for (const prefix of binaries) {
|
|
339
|
+
const binary = Downloader.get(prefix);
|
|
340
|
+
console.log("Descargando:", binary.name);
|
|
341
|
+
console.log("URL:", binary.url);
|
|
342
|
+
}
|
|
343
|
+
await Downloader.download();
|
|
344
|
+
console.log("\u2705 DBCube: Todos los binarios instalados correctamente");
|
|
345
|
+
} catch (error) {
|
|
346
|
+
console.warn("\u26A0\uFE0F DBCube: Error instalando binarios:", error.message);
|
|
347
|
+
console.log("\u{1F4A1} Los binarios se pueden instalar m\xE1s tarde manualmente");
|
|
348
|
+
console.log("\u{1F527} DBCube funcionar\xE1 y descargar\xE1 los binarios cuando sea necesario");
|
|
349
|
+
console.log("\u2705 Instalaci\xF3n del paquete completada (binarios pendientes)");
|
|
306
350
|
}
|
|
307
|
-
await Downloader.download();
|
|
308
351
|
})();
|
|
309
352
|
//# sourceMappingURL=install.cjs.map
|