satoridb 1.1.24 → 1.1.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.
Files changed (2) hide show
  1. package/cli.js +79 -35
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  let path = require("path");
4
4
  let os = require("os");
@@ -12,39 +12,81 @@ let binPath = path.join(os.homedir(), ".satori", "bin", binName);
12
12
 
13
13
  let satoriInstance = null;
14
14
 
15
+ // Function to parse arguments with quoted strings support
16
+ function parseArguments(line) {
17
+ let args = [];
18
+ let current = '';
19
+ let inQuotes = false;
20
+ let quoteChar = '';
21
+
22
+ for (let i = 0; i < line.length; i++) {
23
+ let char = line[i];
24
+
25
+ if ((char === '"' || char === "'") && !inQuotes) {
26
+ inQuotes = true;
27
+ quoteChar = char;
28
+ continue;
29
+ }
30
+
31
+ if (char === quoteChar && inQuotes) {
32
+ inQuotes = false;
33
+ quoteChar = '';
34
+ continue;
35
+ }
36
+
37
+ if (char === ' ' && !inQuotes) {
38
+ if (current.trim()) {
39
+ args.push(current.trim());
40
+ current = '';
41
+ }
42
+ continue;
43
+ }
44
+
45
+ current += char;
46
+ }
47
+
48
+ if (current.trim()) {
49
+ args.push(current.trim());
50
+ }
51
+
52
+ return args;
53
+ }
54
+
15
55
  // Función helper para parsear JSON, arrays y tipos básicos
16
56
  function parseData(data) {
17
57
  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
58
+ let trimmed = data.trim();
59
+
60
+ // Intentar parsear como número
61
+ if (!isNaN(trimmed) && trimmed !== '') {
62
+ let numValue = Number(trimmed);
63
+ if (Number.isInteger(numValue)) return parseInt(trimmed);
26
64
  return numValue;
27
65
  }
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('[')) {
66
+
67
+ // Intentar parsear booleanos
68
+ if (trimmed.toLowerCase() === 'true') return true;
69
+ if (trimmed.toLowerCase() === 'false') return false;
70
+
71
+ // Intentar parsear JSON solo si empieza con { o [
72
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
35
73
  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);
74
+ return JSON.parse(trimmed);
43
75
  } catch (e) {
44
- // If cannot parse as JSON, keep as string
45
- console.log("⚠️ Could not parse as JSON, keeping as string");
46
- console.log("Error:", e.message);
47
- return data;
76
+ // Intentar quitar comillas externas simples y reintentar solo si las tiene
77
+ if ((trimmed.startsWith("'") && trimmed.endsWith("'")) ||
78
+ (trimmed.startsWith('"') && trimmed.endsWith('"'))) {
79
+ let withoutQuotes = trimmed.slice(1, -1);
80
+ try {
81
+ return JSON.parse(withoutQuotes);
82
+ } catch (e2) {
83
+ console.log("⚠️ Could not parse JSON after removing quotes, returning original string");
84
+ return data;
85
+ }
86
+ } else {
87
+ console.log("⚠️ Could not parse as JSON, returning original string");
88
+ return data;
89
+ }
48
90
  }
49
91
  }
50
92
  }
@@ -156,7 +198,7 @@ async function executeCommand(command, args) {
156
198
 
157
199
  case "ask":
158
200
  if (args.length < 1) {
159
- console.log("❌ Uso: ask <question> [backend]");
201
+ console.log("❌ Usage: ask \"<question>\" [backend]");
160
202
  return;
161
203
  }
162
204
  let question = args[0];
@@ -167,7 +209,7 @@ async function executeCommand(command, args) {
167
209
 
168
210
  case "query":
169
211
  if (args.length < 1) {
170
- console.log("❌ Uso: query <query> [backend]");
212
+ console.log("❌ Usage: query \"<query>\" [backend]");
171
213
  return;
172
214
  }
173
215
  let query = args[0];
@@ -323,15 +365,18 @@ function showHelp() {
323
365
  put <key> <field> <value> - Update a specific field
324
366
  get <key> - Get data from a key
325
367
  delete <key> - Delete a key
326
- ask <question> [backend] - Ask a question
327
- query <query> [backend] - Make a query
368
+ ask "<question>" [backend] - Ask a question
369
+ query "<query>" [backend] - Make a query
328
370
 
329
371
  🛠️ Others:
330
372
  help - Show this help
331
373
  exit / quit - Exit the CLI
332
374
  clear - Clear screen
333
375
 
334
- 💡 Example: set user:123 '{"name": "John", "age": 25}'
376
+ 💡 Examples:
377
+ set user:123 '{"name": "John", "age": 25}'
378
+ ask "What is the weather like today?"
379
+ query "Find all users with age > 25"
335
380
  `);
336
381
  }
337
382
 
@@ -360,9 +405,8 @@ async function startInteractiveCLI() {
360
405
  return;
361
406
  }
362
407
 
363
-
364
-
365
- let parts = trimmedLine.split(' ');
408
+ // Parse arguments with quoted strings support
409
+ let parts = parseArguments(trimmedLine);
366
410
  let command = parts[0];
367
411
  let args = parts.slice(1);
368
412
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoridb",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "description": "Install satori",
5
5
  "bin": {
6
6
  "satoridb": "./cli.js"