satoridb 1.1.26 → 1.2.1
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 +134 -45
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -5,12 +5,15 @@ let os = require("os");
|
|
|
5
5
|
let fs = require("fs");
|
|
6
6
|
let { spawnSync } = require("child_process");
|
|
7
7
|
let readline = require("readline");
|
|
8
|
-
let {Satori} = require("satori-node");
|
|
8
|
+
let { Satori } = require("satori-node");
|
|
9
9
|
|
|
10
10
|
let binName = os.platform() === "win32" ? "satori.exe" : "satori";
|
|
11
11
|
let binPath = path.join(os.homedir(), ".satori", "bin", binName);
|
|
12
12
|
|
|
13
|
-
let satoriInstance =
|
|
13
|
+
let satoriInstance = new Satori();
|
|
14
|
+
let currentUser = null;
|
|
15
|
+
let currentPassword = null;
|
|
16
|
+
let currentMindspace = null;
|
|
14
17
|
|
|
15
18
|
// Function to parse arguments with quoted strings support
|
|
16
19
|
function parseArguments(line) {
|
|
@@ -18,22 +21,22 @@ function parseArguments(line) {
|
|
|
18
21
|
let current = '';
|
|
19
22
|
let inQuotes = false;
|
|
20
23
|
let quoteChar = '';
|
|
21
|
-
|
|
24
|
+
|
|
22
25
|
for (let i = 0; i < line.length; i++) {
|
|
23
26
|
let char = line[i];
|
|
24
|
-
|
|
27
|
+
|
|
25
28
|
if ((char === '"' || char === "'") && !inQuotes) {
|
|
26
29
|
inQuotes = true;
|
|
27
30
|
quoteChar = char;
|
|
28
31
|
continue;
|
|
29
32
|
}
|
|
30
|
-
|
|
33
|
+
|
|
31
34
|
if (char === quoteChar && inQuotes) {
|
|
32
35
|
inQuotes = false;
|
|
33
36
|
quoteChar = '';
|
|
34
37
|
continue;
|
|
35
38
|
}
|
|
36
|
-
|
|
39
|
+
|
|
37
40
|
if (char === ' ' && !inQuotes) {
|
|
38
41
|
if (current.trim()) {
|
|
39
42
|
args.push(current.trim());
|
|
@@ -41,14 +44,14 @@ function parseArguments(line) {
|
|
|
41
44
|
}
|
|
42
45
|
continue;
|
|
43
46
|
}
|
|
44
|
-
|
|
47
|
+
|
|
45
48
|
current += char;
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
|
|
48
51
|
if (current.trim()) {
|
|
49
52
|
args.push(current.trim());
|
|
50
53
|
}
|
|
51
|
-
|
|
54
|
+
|
|
52
55
|
return args;
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -73,18 +76,11 @@ function parseData(data) {
|
|
|
73
76
|
try {
|
|
74
77
|
return JSON.parse(trimmed);
|
|
75
78
|
} catch (e) {
|
|
76
|
-
// Intentar
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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");
|
|
79
|
+
// Intentar evaluar como objeto JavaScript literal
|
|
80
|
+
try {
|
|
81
|
+
return new Function('return (' + trimmed + ')')();
|
|
82
|
+
} catch (evalError) {
|
|
83
|
+
console.log("⚠️ Could not parse as JSON or JavaScript object, returning original string");
|
|
88
84
|
return data;
|
|
89
85
|
}
|
|
90
86
|
}
|
|
@@ -106,10 +102,24 @@ function run(args) {
|
|
|
106
102
|
}
|
|
107
103
|
}
|
|
108
104
|
|
|
105
|
+
// Helper function to add user and password to command parameters if defined
|
|
106
|
+
function addCredentials(params) {
|
|
107
|
+
if (currentUser !== null && currentUser !== undefined) {
|
|
108
|
+
params.username = currentUser;
|
|
109
|
+
}
|
|
110
|
+
if (currentPassword !== null && currentPassword !== undefined) {
|
|
111
|
+
params.password = currentPassword;
|
|
112
|
+
}
|
|
113
|
+
return params;
|
|
114
|
+
}
|
|
115
|
+
|
|
109
116
|
async function connectToSatori(host, user = null, password = null) {
|
|
110
117
|
try {
|
|
111
118
|
console.log(`🔗 Connecting to ${host}...`);
|
|
112
|
-
|
|
119
|
+
// Store credentials for use in all commands
|
|
120
|
+
currentUser = user;
|
|
121
|
+
currentPassword = password;
|
|
122
|
+
satoriInstance = new Satori({ host, user, password });
|
|
113
123
|
await satoriInstance.connect();
|
|
114
124
|
console.log("✅ Successfully connected to SatoriDB");
|
|
115
125
|
return true;
|
|
@@ -135,6 +145,13 @@ async function executeCommand(command, args) {
|
|
|
135
145
|
case "clear":
|
|
136
146
|
clearScreen();
|
|
137
147
|
return;
|
|
148
|
+
|
|
149
|
+
case "mindspace":
|
|
150
|
+
let cmd = args[0];
|
|
151
|
+
if (cmd == "select"){
|
|
152
|
+
let mId = args[1];
|
|
153
|
+
currentMindspace = mId;
|
|
154
|
+
}
|
|
138
155
|
}
|
|
139
156
|
|
|
140
157
|
// Commands that require connection
|
|
@@ -152,11 +169,11 @@ async function executeCommand(command, args) {
|
|
|
152
169
|
}
|
|
153
170
|
let key = args[0];
|
|
154
171
|
let data = args.slice(1).join(' '); // Unir todos los argumentos restantes
|
|
155
|
-
|
|
172
|
+
|
|
156
173
|
// Parsear JSON si es necesario
|
|
157
174
|
data = parseData(data);
|
|
158
|
-
|
|
159
|
-
await satoriInstance.set({key, data});
|
|
175
|
+
|
|
176
|
+
await satoriInstance.set(addCredentials({ key, data }));
|
|
160
177
|
console.log(`✅ Data saved in key: ${key}`);
|
|
161
178
|
break;
|
|
162
179
|
|
|
@@ -168,7 +185,7 @@ async function executeCommand(command, args) {
|
|
|
168
185
|
let [putKey, replaceField, replaceValue, encryption_key_put] = args;
|
|
169
186
|
// Parsear JSON en el valor si es necesario
|
|
170
187
|
replaceValue = parseData(replaceValue);
|
|
171
|
-
await satoriInstance.put({key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put});
|
|
188
|
+
await satoriInstance.put(addCredentials({ key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put }));
|
|
172
189
|
console.log(`✅ Field updated: ${putKey}.${replaceField} = ${replaceValue}`);
|
|
173
190
|
break;
|
|
174
191
|
|
|
@@ -176,15 +193,87 @@ async function executeCommand(command, args) {
|
|
|
176
193
|
if (args.length >= 1) {
|
|
177
194
|
let getKey = args[0];
|
|
178
195
|
let encryption_key_get = args[1] || null;
|
|
179
|
-
let result = await satoriInstance.get({key: getKey, encryption_key: encryption_key_get});
|
|
196
|
+
let result = await satoriInstance.get(addCredentials({ key: getKey, encryption_key: encryption_key_get }));
|
|
180
197
|
console.log(`📄 Data from ${getKey}:`, JSON.stringify(result, null, 2));
|
|
181
198
|
break;
|
|
182
|
-
}else{
|
|
183
|
-
let result = await satoriInstance.get();
|
|
199
|
+
} else {
|
|
200
|
+
let result = await satoriInstance.get(addCredentials({}));
|
|
184
201
|
console.log(`📄 Data from get:`, JSON.stringify(result, null, 2));
|
|
185
202
|
break;
|
|
186
203
|
}
|
|
187
|
-
|
|
204
|
+
|
|
205
|
+
case "set_mindspace":
|
|
206
|
+
if (args.length == 1) {
|
|
207
|
+
let profile = args[0];
|
|
208
|
+
let res = null;
|
|
209
|
+
if (currentMindspace != null){
|
|
210
|
+
|
|
211
|
+
res = await satoriInstance.setMindspace({
|
|
212
|
+
config: profile,
|
|
213
|
+
mindspace_id: currentMindspace
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
res = await satoriInstance.setMindspace({
|
|
218
|
+
config: profile
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
console.log(`✅ Mindspace set: ${res.data}`);
|
|
222
|
+
break;
|
|
223
|
+
} else if (args.length == 2) {
|
|
224
|
+
let profile = args[0];
|
|
225
|
+
let mindspace_id = args[1];
|
|
226
|
+
|
|
227
|
+
let res = await satoriInstance.setMindspace({
|
|
228
|
+
mindspace_id: mindspace_id,
|
|
229
|
+
config: profile
|
|
230
|
+
})
|
|
231
|
+
console.log(`✅ Mindspace set: ${res.data}`);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
case "delete_mindspace":
|
|
236
|
+
if (args.length == 1) {
|
|
237
|
+
let mid = args[0];
|
|
238
|
+
|
|
239
|
+
let res = await satoriInstance.deleteMindspace({
|
|
240
|
+
mindspace_id: mid
|
|
241
|
+
})
|
|
242
|
+
console.log(`✅ Mindspace deleted: ${mid}`);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
case "chat":
|
|
247
|
+
if (args.length == 1) {
|
|
248
|
+
if(currentMindspace == null){
|
|
249
|
+
console.log("Select a mindspace with: mindspace select <mindspace_id>")
|
|
250
|
+
}
|
|
251
|
+
let mid = currentMindspace;
|
|
252
|
+
let message = args[0]
|
|
253
|
+
|
|
254
|
+
let res = await satoriInstance.chatMindspace({
|
|
255
|
+
mindspace_id: mid,
|
|
256
|
+
message: message
|
|
257
|
+
})
|
|
258
|
+
console.log(`${res.data}`);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
case "lecture":
|
|
263
|
+
if(args == 1){
|
|
264
|
+
if(currentMindspace == null){
|
|
265
|
+
console.log("Select a mindspace with: mindspace select <mindspace_id>")
|
|
266
|
+
}
|
|
267
|
+
let mid = currentMindspace;
|
|
268
|
+
let message = args[0]
|
|
269
|
+
|
|
270
|
+
let res = await satoriInstance.lectureMindspace({
|
|
271
|
+
mindspace_id: mid,
|
|
272
|
+
corpus: message
|
|
273
|
+
})
|
|
274
|
+
console.log(`${res.data}`);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
188
277
|
|
|
189
278
|
case "delete":
|
|
190
279
|
if (args.length < 1) {
|
|
@@ -192,7 +281,7 @@ async function executeCommand(command, args) {
|
|
|
192
281
|
return;
|
|
193
282
|
}
|
|
194
283
|
let deleteKey = args[0];
|
|
195
|
-
await satoriInstance.delete({key: deleteKey});
|
|
284
|
+
await satoriInstance.delete(addCredentials({ key: deleteKey }));
|
|
196
285
|
console.log(`🗑️ Key deleted: ${deleteKey}`);
|
|
197
286
|
break;
|
|
198
287
|
|
|
@@ -203,7 +292,7 @@ async function executeCommand(command, args) {
|
|
|
203
292
|
}
|
|
204
293
|
let question = args[0];
|
|
205
294
|
let backend = args[1] || null;
|
|
206
|
-
let result = await satoriInstance.ask({question, backend});
|
|
295
|
+
let result = await satoriInstance.ask(addCredentials({ question, backend }));
|
|
207
296
|
console.log("🔍 Search results:", JSON.stringify(result, null, 2));
|
|
208
297
|
break;
|
|
209
298
|
|
|
@@ -214,7 +303,7 @@ async function executeCommand(command, args) {
|
|
|
214
303
|
}
|
|
215
304
|
let query = args[0];
|
|
216
305
|
let backend_q = args[1] || null;
|
|
217
|
-
let result_q = await satoriInstance.query({query, backend: backend_q});
|
|
306
|
+
let result_q = await satoriInstance.query(addCredentials({ query, backend: backend_q }));
|
|
218
307
|
console.log("🔍 Search results:", JSON.stringify(result_q, null, 2));
|
|
219
308
|
break;
|
|
220
309
|
|
|
@@ -226,7 +315,7 @@ async function executeCommand(command, args) {
|
|
|
226
315
|
let node = args[0];
|
|
227
316
|
let relation = args[1] || null;
|
|
228
317
|
let encryption_key = args[2] || null;
|
|
229
|
-
let result_dfs = await satoriInstance.dfs({node, relation, encryption_key});
|
|
318
|
+
let result_dfs = await satoriInstance.dfs(addCredentials({ node, relation, encryption_key }));
|
|
230
319
|
console.log("🔍 Search results:", JSON.stringify(result_dfs, null, 2));
|
|
231
320
|
break;
|
|
232
321
|
|
|
@@ -237,7 +326,7 @@ async function executeCommand(command, args) {
|
|
|
237
326
|
}
|
|
238
327
|
let key_encrypt = args[0];
|
|
239
328
|
let encryption_key_encrypt = args[1] || null;
|
|
240
|
-
let result_encrypt = await satoriInstance.encrypt({key: key_encrypt, encryption_key: encryption_key_encrypt});
|
|
329
|
+
let result_encrypt = await satoriInstance.encrypt(addCredentials({ key: key_encrypt, encryption_key: encryption_key_encrypt }));
|
|
241
330
|
console.log("🔍 Encryption results:", JSON.stringify(result_encrypt, null, 2));
|
|
242
331
|
break;
|
|
243
332
|
|
|
@@ -248,7 +337,7 @@ async function executeCommand(command, args) {
|
|
|
248
337
|
}
|
|
249
338
|
let key_decrypt = args[0];
|
|
250
339
|
let encryption_key_decrypt = args[1] || null;
|
|
251
|
-
let result_decrypt = await satoriInstance.decrypt({key: key_decrypt, encryption_key: encryption_key_decrypt});
|
|
340
|
+
let result_decrypt = await satoriInstance.decrypt(addCredentials({ key: key_decrypt, encryption_key: encryption_key_decrypt }));
|
|
252
341
|
console.log("🔍 Decryption results:", JSON.stringify(result_decrypt, null, 2));
|
|
253
342
|
break;
|
|
254
343
|
|
|
@@ -263,7 +352,7 @@ async function executeCommand(command, args) {
|
|
|
263
352
|
let encryption_key_push = args[3] || null;
|
|
264
353
|
// Parsear JSON en el valor si es necesario
|
|
265
354
|
value_push = parseData(value_push);
|
|
266
|
-
let result_push = await satoriInstance.push({key: key_push, array: array_push, value: value_push, encryption_key: encryption_key_push});
|
|
355
|
+
let result_push = await satoriInstance.push(addCredentials({ key: key_push, array: array_push, value: value_push, encryption_key: encryption_key_push }));
|
|
267
356
|
console.log("🔍 Insertion results:", JSON.stringify(result_push, null, 2));
|
|
268
357
|
break;
|
|
269
358
|
|
|
@@ -275,7 +364,7 @@ async function executeCommand(command, args) {
|
|
|
275
364
|
let key_pop = args[0];
|
|
276
365
|
let array_pop = args[1];
|
|
277
366
|
let encryption_key_pop = args[2] || null;
|
|
278
|
-
let result_pop = await satoriInstance.pop({key: key_pop, array: array_pop, encryption_key: encryption_key_pop});
|
|
367
|
+
let result_pop = await satoriInstance.pop(addCredentials({ key: key_pop, array: array_pop, encryption_key: encryption_key_pop }));
|
|
279
368
|
console.log("🔍 Removal results:", JSON.stringify(result_pop, null, 2));
|
|
280
369
|
break;
|
|
281
370
|
|
|
@@ -287,7 +376,7 @@ async function executeCommand(command, args) {
|
|
|
287
376
|
let key_splice = args[0];
|
|
288
377
|
let array_splice = args[1];
|
|
289
378
|
let encryption_key_splice = args[2] || null;
|
|
290
|
-
let result_splice = await satoriInstance.splice({key: key_splice, array: array_splice, encryption_key: encryption_key_splice});
|
|
379
|
+
let result_splice = await satoriInstance.splice(addCredentials({ key: key_splice, array: array_splice, encryption_key: encryption_key_splice }));
|
|
291
380
|
console.log("🔍 Insertion results:", JSON.stringify(result_splice, null, 2));
|
|
292
381
|
break;
|
|
293
382
|
|
|
@@ -302,7 +391,7 @@ async function executeCommand(command, args) {
|
|
|
302
391
|
let encryption_key_remove = args[3] || null;
|
|
303
392
|
// Parsear JSON en el valor si es necesario
|
|
304
393
|
value_remove = parseData(value_remove);
|
|
305
|
-
let result_remove = await satoriInstance.remove({key: key_remove, array: array_remove, value: value_remove, encryption_key: encryption_key_remove});
|
|
394
|
+
let result_remove = await satoriInstance.remove(addCredentials({ key: key_remove, array: array_remove, value: value_remove, encryption_key: encryption_key_remove }));
|
|
306
395
|
console.log("🔍 Removal results:", JSON.stringify(result_remove, null, 2));
|
|
307
396
|
break;
|
|
308
397
|
|
|
@@ -316,7 +405,7 @@ async function executeCommand(command, args) {
|
|
|
316
405
|
let encryption_key_set_vertex = args[2] || null;
|
|
317
406
|
// Parsear JSON en el vertex si es necesario
|
|
318
407
|
vertex_set_vertex = parseData(vertex_set_vertex);
|
|
319
|
-
let result_set_vertex = await satoriInstance.set_vertex({key: key_set_vertex, vertex: vertex_set_vertex, encryption_key: encryption_key_set_vertex});
|
|
408
|
+
let result_set_vertex = await satoriInstance.set_vertex(addCredentials({ key: key_set_vertex, vertex: vertex_set_vertex, encryption_key: encryption_key_set_vertex }));
|
|
320
409
|
console.log("🔍 Insertion results:", JSON.stringify(result_set_vertex, null, 2));
|
|
321
410
|
break;
|
|
322
411
|
|
|
@@ -327,7 +416,7 @@ async function executeCommand(command, args) {
|
|
|
327
416
|
}
|
|
328
417
|
let key_get_vertex = args[0];
|
|
329
418
|
let encryption_key_get_vertex = args[1] || null;
|
|
330
|
-
let result_get_vertex = await satoriInstance.get_vertex({key: key_get_vertex, encryption_key: encryption_key_get_vertex});
|
|
419
|
+
let result_get_vertex = await satoriInstance.get_vertex(addCredentials({ key: key_get_vertex, encryption_key: encryption_key_get_vertex }));
|
|
331
420
|
console.log("🔍 Insertion results:", JSON.stringify(result_get_vertex, null, 2));
|
|
332
421
|
break;
|
|
333
422
|
|
|
@@ -341,10 +430,10 @@ async function executeCommand(command, args) {
|
|
|
341
430
|
let encryption_key_delete_vertex = args[2] || null;
|
|
342
431
|
// Parsear JSON en el vertex si es necesario
|
|
343
432
|
vertex_delete_vertex = parseData(vertex_delete_vertex);
|
|
344
|
-
let result_delete_vertex = await satoriInstance.delete_vertex({key: key_delete_vertex, vertex: vertex_delete_vertex, encryption_key: encryption_key_delete_vertex});
|
|
433
|
+
let result_delete_vertex = await satoriInstance.delete_vertex(addCredentials({ key: key_delete_vertex, vertex: vertex_delete_vertex, encryption_key: encryption_key_delete_vertex }));
|
|
345
434
|
console.log("🔍 Removal results:", JSON.stringify(result_delete_vertex, null, 2));
|
|
346
435
|
break;
|
|
347
|
-
|
|
436
|
+
|
|
348
437
|
default:
|
|
349
438
|
console.log("❌ Command not recognized. Use 'help' to see available commands.");
|
|
350
439
|
}
|
|
@@ -399,7 +488,7 @@ async function startInteractiveCLI() {
|
|
|
399
488
|
|
|
400
489
|
rl.on('line', async (line) => {
|
|
401
490
|
let trimmedLine = line.trim();
|
|
402
|
-
|
|
491
|
+
|
|
403
492
|
if (trimmedLine === '') {
|
|
404
493
|
rl.prompt();
|
|
405
494
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "satoridb",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Install satori",
|
|
5
5
|
"bin": {
|
|
6
6
|
"satoridb": "./cli.js"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"adm-zip": "^0.5.16",
|
|
16
|
-
"satori-node": "^1.
|
|
16
|
+
"satori-node": "^1.1.13"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"postinstall.js",
|