satoridb 1.1.13 → 1.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/cli.js +71 -25
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -12,6 +12,45 @@ let binPath = path.join(os.homedir(), ".satori", "bin", binName);
|
|
|
12
12
|
|
|
13
13
|
let satoriInstance = null;
|
|
14
14
|
|
|
15
|
+
// Función helper para parsear JSON, arrays y tipos básicos
|
|
16
|
+
function parseData(data) {
|
|
17
|
+
if (typeof data === 'string') {
|
|
18
|
+
// Intentar parsear como número primero
|
|
19
|
+
if (!isNaN(data) && data.trim() !== '') {
|
|
20
|
+
let numValue = Number(data);
|
|
21
|
+
// Si es un entero, retornarlo como entero
|
|
22
|
+
if (Number.isInteger(numValue)) {
|
|
23
|
+
return parseInt(data);
|
|
24
|
+
}
|
|
25
|
+
// Si es decimal, retornarlo como float
|
|
26
|
+
return numValue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Intentar parsear como boolean
|
|
30
|
+
if (data.toLowerCase() === 'true') return true;
|
|
31
|
+
if (data.toLowerCase() === 'false') return false;
|
|
32
|
+
|
|
33
|
+
// Intentar parsear como JSON si parece JSON
|
|
34
|
+
if (data.startsWith('{') || data.startsWith('[')) {
|
|
35
|
+
try {
|
|
36
|
+
// Limpiar el string de comillas externas si las tiene
|
|
37
|
+
let cleanData = data.trim();
|
|
38
|
+
if ((cleanData.startsWith("'") && cleanData.endsWith("'")) ||
|
|
39
|
+
(cleanData.startsWith('"') && cleanData.endsWith('"'))) {
|
|
40
|
+
cleanData = cleanData.slice(1, -1);
|
|
41
|
+
}
|
|
42
|
+
return JSON.parse(cleanData);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// Si no se puede parsear como JSON, mantener como string
|
|
45
|
+
console.log("⚠️ No se pudo parsear como JSON, manteniendo como string");
|
|
46
|
+
console.log("Error:", e.message);
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
15
54
|
function run(args) {
|
|
16
55
|
if (!fs.existsSync(binPath)) {
|
|
17
56
|
console.log("❌ Satori no está instalado. Intenta reinstalar el paquete.");
|
|
@@ -39,8 +78,26 @@ async function connectToSatori(host, user = null, password = null) {
|
|
|
39
78
|
}
|
|
40
79
|
|
|
41
80
|
async function executeCommand(command, args) {
|
|
81
|
+
// Comandos que no requieren conexión
|
|
82
|
+
switch (command) {
|
|
83
|
+
case "help":
|
|
84
|
+
showHelp();
|
|
85
|
+
return;
|
|
86
|
+
|
|
87
|
+
case "exit":
|
|
88
|
+
case "quit":
|
|
89
|
+
console.log("👋 ¡Hasta luego!");
|
|
90
|
+
process.exit(0);
|
|
91
|
+
return;
|
|
92
|
+
|
|
93
|
+
case "clear":
|
|
94
|
+
clearScreen();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Comandos que requieren conexión
|
|
42
99
|
if (!satoriInstance) {
|
|
43
|
-
console.log("❌ No hay conexión activa. Usa 'connect <host>
|
|
100
|
+
console.log("❌ No hay conexión activa. Usa 'connect <host> [user] [password]' primero.");
|
|
44
101
|
return;
|
|
45
102
|
}
|
|
46
103
|
|
|
@@ -54,15 +111,8 @@ async function executeCommand(command, args) {
|
|
|
54
111
|
let key = args[0];
|
|
55
112
|
let data = args.slice(1).join(' '); // Unir todos los argumentos restantes
|
|
56
113
|
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
data = JSON.parse(data);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
// Si no se puede parsear como JSON, mantener como string
|
|
63
|
-
console.log("⚠️ No se pudo parsear como JSON, guardando como string");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
114
|
+
// Parsear JSON si es necesario
|
|
115
|
+
data = parseData(data);
|
|
66
116
|
|
|
67
117
|
await satoriInstance.set({key, data});
|
|
68
118
|
console.log(`✅ Datos guardados en clave: ${key}`);
|
|
@@ -74,6 +124,8 @@ async function executeCommand(command, args) {
|
|
|
74
124
|
return;
|
|
75
125
|
}
|
|
76
126
|
let [putKey, replaceField, replaceValue, encryption_key_put] = args;
|
|
127
|
+
// Parsear JSON en el valor si es necesario
|
|
128
|
+
replaceValue = parseData(replaceValue);
|
|
77
129
|
await satoriInstance.put({key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put});
|
|
78
130
|
console.log(`✅ Campo actualizado: ${putKey}.${replaceField} = ${replaceValue}`);
|
|
79
131
|
break;
|
|
@@ -167,6 +219,8 @@ async function executeCommand(command, args) {
|
|
|
167
219
|
let array_push = args[1];
|
|
168
220
|
let value_push = args[2];
|
|
169
221
|
let encryption_key_push = args[3] || null;
|
|
222
|
+
// Parsear JSON en el valor si es necesario
|
|
223
|
+
value_push = parseData(value_push);
|
|
170
224
|
let result_push = await satoriInstance.push({key: key_push, array: array_push, value: value_push, encryption_key: encryption_key_push});
|
|
171
225
|
console.log("🔍 Resultados de inserción:", JSON.stringify(result_push, null, 2));
|
|
172
226
|
break;
|
|
@@ -204,6 +258,8 @@ async function executeCommand(command, args) {
|
|
|
204
258
|
let array_remove = args[1];
|
|
205
259
|
let value_remove = args[2];
|
|
206
260
|
let encryption_key_remove = args[3] || null;
|
|
261
|
+
// Parsear JSON en el valor si es necesario
|
|
262
|
+
value_remove = parseData(value_remove);
|
|
207
263
|
let result_remove = await satoriInstance.remove({key: key_remove, array: array_remove, value: value_remove, encryption_key: encryption_key_remove});
|
|
208
264
|
console.log("🔍 Resultados de eliminación:", JSON.stringify(result_remove, null, 2));
|
|
209
265
|
break;
|
|
@@ -216,6 +272,8 @@ async function executeCommand(command, args) {
|
|
|
216
272
|
let key_set_vertex = args[0];
|
|
217
273
|
let vertex_set_vertex = args[1];
|
|
218
274
|
let encryption_key_set_vertex = args[2] || null;
|
|
275
|
+
// Parsear JSON en el vertex si es necesario
|
|
276
|
+
vertex_set_vertex = parseData(vertex_set_vertex);
|
|
219
277
|
let result_set_vertex = await satoriInstance.set_vertex({key: key_set_vertex, vertex: vertex_set_vertex, encryption_key: encryption_key_set_vertex});
|
|
220
278
|
console.log("🔍 Resultados de inserción:", JSON.stringify(result_set_vertex, null, 2));
|
|
221
279
|
break;
|
|
@@ -239,20 +297,12 @@ async function executeCommand(command, args) {
|
|
|
239
297
|
let key_delete_vertex = args[0];
|
|
240
298
|
let vertex_delete_vertex = args[1];
|
|
241
299
|
let encryption_key_delete_vertex = args[2] || null;
|
|
300
|
+
// Parsear JSON en el vertex si es necesario
|
|
301
|
+
vertex_delete_vertex = parseData(vertex_delete_vertex);
|
|
242
302
|
let result_delete_vertex = await satoriInstance.delete_vertex({key: key_delete_vertex, vertex: vertex_delete_vertex, encryption_key: encryption_key_delete_vertex});
|
|
243
303
|
console.log("🔍 Resultados de eliminación:", JSON.stringify(result_delete_vertex, null, 2));
|
|
244
304
|
break;
|
|
245
305
|
|
|
246
|
-
case "help":
|
|
247
|
-
showHelp();
|
|
248
|
-
break;
|
|
249
|
-
|
|
250
|
-
case "exit":
|
|
251
|
-
case "quit":
|
|
252
|
-
console.log("👋 ¡Hasta luego!");
|
|
253
|
-
process.exit(0);
|
|
254
|
-
break;
|
|
255
|
-
|
|
256
306
|
default:
|
|
257
307
|
console.log("❌ Comando no reconocido. Usa 'help' para ver comandos disponibles.");
|
|
258
308
|
}
|
|
@@ -310,11 +360,7 @@ async function startInteractiveCLI() {
|
|
|
310
360
|
return;
|
|
311
361
|
}
|
|
312
362
|
|
|
313
|
-
|
|
314
|
-
clearScreen();
|
|
315
|
-
rl.prompt();
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
363
|
+
|
|
318
364
|
|
|
319
365
|
let parts = trimmedLine.split(' ');
|
|
320
366
|
let command = parts[0];
|