satoridb 1.1.13 → 1.1.14

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 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.");
@@ -54,15 +93,8 @@ async function executeCommand(command, args) {
54
93
  let key = args[0];
55
94
  let data = args.slice(1).join(' '); // Unir todos los argumentos restantes
56
95
 
57
- // Intentar parsear como JSON si es un string que parece JSON
58
- if (typeof data === 'string' && (data.startsWith('{') || data.startsWith('['))) {
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
- }
96
+ // Parsear JSON si es necesario
97
+ data = parseData(data);
66
98
 
67
99
  await satoriInstance.set({key, data});
68
100
  console.log(`✅ Datos guardados en clave: ${key}`);
@@ -74,6 +106,8 @@ async function executeCommand(command, args) {
74
106
  return;
75
107
  }
76
108
  let [putKey, replaceField, replaceValue, encryption_key_put] = args;
109
+ // Parsear JSON en el valor si es necesario
110
+ replaceValue = parseData(replaceValue);
77
111
  await satoriInstance.put({key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put});
78
112
  console.log(`✅ Campo actualizado: ${putKey}.${replaceField} = ${replaceValue}`);
79
113
  break;
@@ -167,6 +201,8 @@ async function executeCommand(command, args) {
167
201
  let array_push = args[1];
168
202
  let value_push = args[2];
169
203
  let encryption_key_push = args[3] || null;
204
+ // Parsear JSON en el valor si es necesario
205
+ value_push = parseData(value_push);
170
206
  let result_push = await satoriInstance.push({key: key_push, array: array_push, value: value_push, encryption_key: encryption_key_push});
171
207
  console.log("🔍 Resultados de inserción:", JSON.stringify(result_push, null, 2));
172
208
  break;
@@ -204,6 +240,8 @@ async function executeCommand(command, args) {
204
240
  let array_remove = args[1];
205
241
  let value_remove = args[2];
206
242
  let encryption_key_remove = args[3] || null;
243
+ // Parsear JSON en el valor si es necesario
244
+ value_remove = parseData(value_remove);
207
245
  let result_remove = await satoriInstance.remove({key: key_remove, array: array_remove, value: value_remove, encryption_key: encryption_key_remove});
208
246
  console.log("🔍 Resultados de eliminación:", JSON.stringify(result_remove, null, 2));
209
247
  break;
@@ -216,6 +254,8 @@ async function executeCommand(command, args) {
216
254
  let key_set_vertex = args[0];
217
255
  let vertex_set_vertex = args[1];
218
256
  let encryption_key_set_vertex = args[2] || null;
257
+ // Parsear JSON en el vertex si es necesario
258
+ vertex_set_vertex = parseData(vertex_set_vertex);
219
259
  let result_set_vertex = await satoriInstance.set_vertex({key: key_set_vertex, vertex: vertex_set_vertex, encryption_key: encryption_key_set_vertex});
220
260
  console.log("🔍 Resultados de inserción:", JSON.stringify(result_set_vertex, null, 2));
221
261
  break;
@@ -239,6 +279,8 @@ async function executeCommand(command, args) {
239
279
  let key_delete_vertex = args[0];
240
280
  let vertex_delete_vertex = args[1];
241
281
  let encryption_key_delete_vertex = args[2] || null;
282
+ // Parsear JSON en el vertex si es necesario
283
+ vertex_delete_vertex = parseData(vertex_delete_vertex);
242
284
  let result_delete_vertex = await satoriInstance.delete_vertex({key: key_delete_vertex, vertex: vertex_delete_vertex, encryption_key: encryption_key_delete_vertex});
243
285
  console.log("🔍 Resultados de eliminación:", JSON.stringify(result_delete_vertex, null, 2));
244
286
  break;
package/db/juan ADDED
@@ -0,0 +1 @@
1
+ {"key":"juan","data":"'{\"email\" : \"test@gmail.com\"}'","vertices":[],"class":"normal","expires":false,"is_encrypted":false,"expiration_time":-1,"encrypted_data":"","references":[],"timestamp":1754336798493,"last_accessed":1754336798493,"querys":0}
package/db/juanito ADDED
@@ -0,0 +1 @@
1
+ {"key":"juanito","data":{"amigos":"[1]","email":"xx","y":[1,"2"]},"vertices":[],"class":"normal","expires":false,"is_encrypted":false,"expiration_time":-1,"encrypted_data":"","references":[],"timestamp":1754351700562,"last_accessed":1754351725930,"querys":19}
package/db/rating.json ADDED
@@ -0,0 +1 @@
1
+ []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoridb",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "description": "Install satori",
5
5
  "bin": {
6
6
  "satoridb": "./cli.js"