@dbcube/cli 4.1.14 → 4.1.15

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/bun.lock CHANGED
@@ -4,7 +4,7 @@
4
4
  "": {
5
5
  "name": "@dbcube/cli",
6
6
  "dependencies": {
7
- "@dbcube/schema-builder": "^4.1.14",
7
+ "@dbcube/schema-builder": "^4.1.15",
8
8
  "@inquirer/prompts": "^8.2.0",
9
9
  "alwait": "^1.0.0",
10
10
  "chalk": "^5.6.2",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  },
19
19
  "packages": {
20
- "@dbcube/core": ["@dbcube/core@4.1.17", "", { "dependencies": { "chalk": "^5.6.2", "deasync": "^0.1.31", "follow-redirects": "^1.15.11", "ora": "^9.1.0", "unzipper": "^0.12.3" }, "bin": { "dbcube-core": "dist/bin.cjs" } }, "sha512-UxjGi5veeiwejk+pDc4+IWXNAOpRm6wcb8DATEq+EgEi2Zt4zTyn6eQ6wNcfVg2bIPa+GbbWNAIA1sjIjsVt4w=="],
20
+ "@dbcube/core": ["@dbcube/core@4.1.18", "", { "dependencies": { "chalk": "^5.6.2", "deasync": "^0.1.31", "follow-redirects": "^1.15.11", "ora": "^9.1.0", "unzipper": "^0.12.3" }, "bin": { "dbcube-core": "dist/bin.cjs" } }, "sha512-2043Nbx8LyMWxp7QNi3kg4w5F35RXgGu5I/GDQX3kbvFFUNqyH3ic1+GNhLjteoldp1DnIwEa56rcnKxJi1p5g=="],
21
21
 
22
- "@dbcube/schema-builder": ["@dbcube/schema-builder@4.1.14", "", { "dependencies": { "@dbcube/core": "^4.1.17", "chalk": "^5.6.2", "ora": "^9.1.0" } }, "sha512-MEFhciGdqrtAqmG9sM93K9evgKhtUt+xNa2mFP3ADtp88gIRSofDY64Y032k7vzba6EkXWH4gNx7F/oKWNyNrQ=="],
22
+ "@dbcube/schema-builder": ["@dbcube/schema-builder@4.1.15", "", { "dependencies": { "@dbcube/core": "^4.1.18", "chalk": "^5.6.2", "ora": "^9.1.0" } }, "sha512-Q72NaOo3Xn9ObDQYIZjNAUqNVUvMhAO96wNkjMT3glMvGunrq70AFH11yI8WuJMZPw6aWyIqAqxRkxxraNKxFg=="],
23
23
 
24
24
  "@inquirer/ansi": ["@inquirer/ansi@2.0.3", "", {}, "sha512-g44zhR3NIKVs0zUesa4iMzExmZpLUdTLRMCStqX3GE5NT6VkPcxQGJ+uC8tDgBUC/vB1rUhUd55cOf++4NZcmw=="],
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcube/cli",
3
- "version": "4.1.14",
3
+ "version": "4.1.15",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "dbcube": "node src/index.js"
@@ -13,7 +13,7 @@
13
13
  "license": "ISC",
14
14
  "description": "",
15
15
  "dependencies": {
16
- "@dbcube/schema-builder": "^4.1.14",
16
+ "@dbcube/schema-builder": "^4.1.15",
17
17
  "@inquirer/prompts": "^8.2.0",
18
18
  "alwait": "^1.0.0",
19
19
  "chalk": "^5.6.2",
@@ -1,417 +0,0 @@
1
- #!/usr/bin/env node
2
- const chalk = require('chalk');
3
- const ora = require('ora');
4
- const path = require('path');
5
- const fs = require('fs');
6
- const https = require('https');
7
- const os = require('os');
8
- const unzipper = require('unzipper');
9
-
10
- const VERSION_URLS = {
11
- 'query-engine': 'https://raw.githubusercontent.com/Dbcube/binaries/main/query-engines.json',
12
- 'schema-engine': 'https://raw.githubusercontent.com/Dbcube/binaries/main/schema-engines.json',
13
- 'sqlite-engine': 'https://raw.githubusercontent.com/Dbcube/binaries/main/sqlite-engines.json'
14
- };
15
-
16
- const BINARY_PREFIX_MAP = {
17
- 'query-engine': 'query',
18
- 'schema-engine': 'schema',
19
- 'sqlite-engine': 'sqlite'
20
- };
21
-
22
- const PLATFORM_MAP = {
23
- win32: 'windows',
24
- linux: 'linux',
25
- darwin: 'macos'
26
- };
27
-
28
- const ARCH_MAP = {
29
- x64: 'x64',
30
- arm64: 'arm64'
31
- };
32
-
33
- function getPlatformInfo() {
34
- const platform = PLATFORM_MAP[process.platform];
35
- const arch = ARCH_MAP[process.arch];
36
-
37
- if (!platform || !arch) {
38
- throw new Error(`Plataforma no soportada: ${process.platform} ${process.arch}`);
39
- }
40
-
41
- return { platform, arch };
42
- }
43
-
44
- function getBinDir() {
45
- const possibleDirs = [
46
- path.resolve(process.cwd(), '.dbcube', 'bin'),
47
- path.resolve(process.cwd(), 'node_modules', '.dbcube', 'bin'),
48
- ];
49
-
50
- for (const dir of possibleDirs) {
51
- try {
52
- if (!fs.existsSync(dir)) {
53
- fs.mkdirSync(dir, { recursive: true });
54
- }
55
- return dir;
56
- } catch {
57
- continue;
58
- }
59
- }
60
-
61
- const tempDir = path.join(os.tmpdir(), '.dbcube', 'bin');
62
- fs.mkdirSync(tempDir, { recursive: true });
63
- return tempDir;
64
- }
65
-
66
- /**
67
- * Fetch latest version from GitHub
68
- */
69
- function fetchLatestVersion(engineType) {
70
- const url = VERSION_URLS[engineType];
71
-
72
- return new Promise((resolve, reject) => {
73
- https.get(url, (response) => {
74
- let data = '';
75
-
76
- response.on('data', (chunk) => {
77
- data += chunk;
78
- });
79
-
80
- response.on('end', () => {
81
- try {
82
- const versions = JSON.parse(data);
83
- if (versions && versions.length > 0) {
84
- // Get the latest version (first in array)
85
- resolve(versions[0].version);
86
- } else {
87
- reject(new Error('No versions found'));
88
- }
89
- } catch (error) {
90
- reject(error);
91
- }
92
- });
93
-
94
- response.on('error', reject);
95
- }).on('error', reject);
96
- });
97
- }
98
-
99
- /**
100
- * Extract version from binary filename
101
- * Example: schema-engine-v1.0.0-windows-x64.exe -> v1.0.0
102
- */
103
- function extractVersionFromFilename(filename) {
104
- const match = filename.match(/-(v\d+\.\d+\.\d+)-/);
105
- return match ? match[1] : null;
106
- }
107
-
108
- /**
109
- * Get local version of installed binary
110
- */
111
- function getLocalVersion(binDir, prefix) {
112
- try {
113
- const files = fs.readdirSync(binDir);
114
- const binaryPattern = new RegExp(`^${prefix}-engine-v`);
115
- const binaryFile = files.find(f => binaryPattern.test(f));
116
-
117
- if (binaryFile) {
118
- return extractVersionFromFilename(binaryFile);
119
- }
120
- } catch (error) {
121
- // Directory doesn't exist or can't read
122
- }
123
- return null;
124
- }
125
-
126
- /**
127
- * Compare versions (returns true if remote is newer)
128
- */
129
- function isNewerVersion(localVersion, remoteVersion) {
130
- if (!localVersion) return true; // No local version, download
131
-
132
- // Remove 'v' prefix if exists
133
- const cleanLocal = localVersion.replace(/^v/, '');
134
- const cleanRemote = remoteVersion.replace(/^v/, '');
135
-
136
- const localParts = cleanLocal.split('.').map(Number);
137
- const remoteParts = cleanRemote.split('.').map(Number);
138
-
139
- for (let i = 0; i < 3; i++) {
140
- if (remoteParts[i] > localParts[i]) return true;
141
- if (remoteParts[i] < localParts[i]) return false;
142
- }
143
-
144
- return false; // Versions are equal
145
- }
146
-
147
- /**
148
- * Delete old binary files
149
- */
150
- function deleteOldBinary(binDir, prefix) {
151
- try {
152
- const files = fs.readdirSync(binDir);
153
- const binaryPattern = new RegExp(`^${prefix}-engine-`);
154
-
155
- files.forEach(file => {
156
- if (binaryPattern.test(file)) {
157
- const filePath = path.join(binDir, file);
158
- try {
159
- fs.unlinkSync(filePath);
160
- console.log(chalk.gray(` šŸ—‘ļø Deleted: ${file}`));
161
- } catch (err) {
162
- console.warn(chalk.yellow(` āš ļø Could not delete: ${file}`));
163
- }
164
- }
165
- });
166
- } catch (error) {
167
- // Ignore errors
168
- }
169
- }
170
-
171
- async function updateBinary(engineType, localVersion, remoteVersion) {
172
- const spinner = ora(`Updating ${engineType}...`).start();
173
-
174
- try {
175
- const { platform, arch } = getPlatformInfo();
176
- const prefix = BINARY_PREFIX_MAP[engineType];
177
-
178
- if (!prefix) {
179
- throw new Error(`Tipo de binario no soportado: ${engineType}`);
180
- }
181
-
182
- const baseName = `${prefix}-engine-${remoteVersion}-${platform}-${arch}`;
183
- const binaryName = platform === 'windows' ? `${baseName}.exe` : baseName;
184
-
185
- // Build download URL
186
- const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-${remoteVersion}-${platform}-${arch}.zip`;
187
-
188
- const binDir = getBinDir();
189
- const finalBinaryPath = path.join(binDir, binaryName);
190
-
191
- spinner.text = `Deleting old ${engineType} (${localVersion || 'none'})...`;
192
-
193
- // Delete old binary first
194
- deleteOldBinary(binDir, prefix);
195
-
196
- const tempZipPath = path.join(os.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
197
-
198
- spinner.text = `Downloading ${engineType} ${remoteVersion}...`;
199
-
200
- // Download
201
- await downloadFile(url, tempZipPath, (progress) => {
202
- const percentage = progress.percentage.toFixed(1);
203
- const downloaded = (progress.downloaded / 1024 / 1024).toFixed(1);
204
- const total = (progress.total / 1024 / 1024).toFixed(1);
205
- spinner.text = `Downloading ${chalk.cyan(engineType)} ${chalk.yellow(remoteVersion)}: ${percentage}% (${downloaded}/${total}MB)`;
206
- });
207
-
208
- spinner.text = `Extracting ${engineType}...`;
209
-
210
- // Extract
211
- await extractBinary(tempZipPath, finalBinaryPath);
212
-
213
- // Cleanup
214
- cleanupFile(tempZipPath);
215
-
216
- spinner.succeed(chalk.green(`āœ“ ${engineType} updated: ${localVersion || 'none'} → ${remoteVersion}`));
217
- console.log(chalk.gray(` Location: ${finalBinaryPath}`));
218
-
219
- return true;
220
-
221
- } catch (error) {
222
- spinner.fail(chalk.red(`āœ— Error updating ${engineType}`));
223
- console.error(chalk.red(` ${error.message}`));
224
- return false;
225
- }
226
- }
227
-
228
- function downloadFile(url, outputPath, onProgress) {
229
- return new Promise((resolve, reject) => {
230
- https.get(url, { timeout: 30000 }, (response) => {
231
- // Handle redirects
232
- if (response.statusCode === 302 || response.statusCode === 301) {
233
- const redirectUrl = response.headers.location;
234
- if (redirectUrl) {
235
- return downloadFile(redirectUrl, outputPath, onProgress).then(resolve).catch(reject);
236
- }
237
- }
238
-
239
- if (response.statusCode !== 200) {
240
- reject(new Error(`HTTP ${response.statusCode}: Binary not found for this version`));
241
- return;
242
- }
243
-
244
- const file = fs.createWriteStream(outputPath);
245
- const totalBytes = parseInt(response.headers['content-length'] || '0', 10);
246
- let downloadedBytes = 0;
247
-
248
- response.on('data', (chunk) => {
249
- downloadedBytes += chunk.length;
250
- file.write(chunk);
251
-
252
- if (totalBytes > 0 && onProgress) {
253
- onProgress({
254
- downloaded: downloadedBytes,
255
- total: totalBytes,
256
- percentage: (downloadedBytes / totalBytes) * 100
257
- });
258
- }
259
- });
260
-
261
- response.on('end', () => {
262
- file.end();
263
- resolve();
264
- });
265
-
266
- response.on('error', (err) => {
267
- file.close();
268
- cleanupFile(outputPath);
269
- reject(err);
270
- });
271
-
272
- file.on('error', (err) => {
273
- file.close();
274
- cleanupFile(outputPath);
275
- reject(err);
276
- });
277
- }).on('error', reject).on('timeout', () => {
278
- reject(new Error('Download timeout'));
279
- });
280
- });
281
- }
282
-
283
- function extractBinary(zipPath, outputPath) {
284
- return new Promise((resolve, reject) => {
285
- let extracted = false;
286
-
287
- fs.createReadStream(zipPath)
288
- .pipe(unzipper.Parse())
289
- .on('entry', (entry) => {
290
- if (entry.type === 'File' && !extracted) {
291
- extracted = true;
292
- const writeStream = fs.createWriteStream(outputPath);
293
-
294
- entry.pipe(writeStream);
295
-
296
- writeStream.on('finish', () => {
297
- if (process.platform !== 'win32') {
298
- fs.chmodSync(outputPath, 0o755);
299
- }
300
- resolve();
301
- });
302
-
303
- writeStream.on('error', (err) => {
304
- reject(err);
305
- });
306
- } else {
307
- entry.autodrain();
308
- }
309
- })
310
- .on('error', (err) => {
311
- reject(err);
312
- })
313
- .on('close', () => {
314
- if (!extracted) {
315
- reject(new Error('No valid file found in ZIP'));
316
- }
317
- });
318
- });
319
- }
320
-
321
- function cleanupFile(filePath) {
322
- try {
323
- if (fs.existsSync(filePath)) {
324
- fs.unlinkSync(filePath);
325
- }
326
- } catch {
327
- // Ignore cleanup errors
328
- }
329
- }
330
-
331
- async function main() {
332
- console.log(chalk.blue('\nšŸ”„ Dbcube Update - Check and Update Binaries\n'));
333
-
334
- const binDir = getBinDir();
335
- const binaries = ['query-engine', 'schema-engine', 'sqlite-engine'];
336
-
337
- const spinner = ora('Checking versions...').start();
338
-
339
- const updates = [];
340
-
341
- // Check all binaries
342
- for (const engineType of binaries) {
343
- try {
344
- const prefix = BINARY_PREFIX_MAP[engineType];
345
- const localVersion = getLocalVersion(binDir, prefix);
346
- const remoteVersion = await fetchLatestVersion(engineType);
347
- const needsUpdate = isNewerVersion(localVersion, remoteVersion);
348
-
349
- updates.push({
350
- engineType,
351
- localVersion,
352
- remoteVersion,
353
- needsUpdate
354
- });
355
-
356
- } catch (error) {
357
- console.warn(chalk.yellow(`\nāš ļø Could not check ${engineType}: ${error.message}`));
358
- }
359
- }
360
-
361
- spinner.stop();
362
-
363
- // Show status
364
- console.log(chalk.cyan('šŸ“Š Version Status:\n'));
365
-
366
- let updatesAvailable = 0;
367
-
368
- for (const update of updates) {
369
- if (update.needsUpdate) {
370
- console.log(chalk.yellow(` šŸ“¦ ${update.engineType}: ${update.localVersion || 'not installed'} → ${update.remoteVersion}`));
371
- updatesAvailable++;
372
- } else if (update.localVersion) {
373
- console.log(chalk.green(` āœ… ${update.engineType}: ${update.localVersion} (up to date)`));
374
- } else {
375
- console.log(chalk.gray(` ā„¹ļø ${update.engineType}: not installed`));
376
- }
377
- }
378
-
379
- if (updatesAvailable === 0) {
380
- console.log(chalk.green('\n✨ All binaries are up to date!\n'));
381
- return;
382
- }
383
-
384
- console.log(chalk.cyan(`\nšŸ”„ Updating ${updatesAvailable} binary(ies)...\n`));
385
-
386
- // Update binaries
387
- let successCount = 0;
388
- let failCount = 0;
389
-
390
- for (const update of updates) {
391
- if (update.needsUpdate) {
392
- const success = await updateBinary(update.engineType, update.localVersion, update.remoteVersion);
393
- if (success) {
394
- successCount++;
395
- } else {
396
- failCount++;
397
- }
398
- }
399
- }
400
-
401
- // Summary
402
- console.log('');
403
- if (failCount === 0) {
404
- console.log(chalk.green.bold(`āœ… All binaries (${successCount}/${updatesAvailable}) updated successfully!\n`));
405
- } else if (successCount > 0) {
406
- console.log(chalk.yellow.bold(`āš ļø Partial update: ${successCount}/${updatesAvailable} binaries updated\n`));
407
- process.exit(1);
408
- } else {
409
- console.log(chalk.red.bold(`āŒ No binaries were updated\n`));
410
- process.exit(1);
411
- }
412
- }
413
-
414
- main().catch(err => {
415
- console.error(chalk.red('\nāŒ Unexpected error:'), err.message);
416
- process.exit(1);
417
- });