satoridb 1.1.27 → 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 +129 -33
- 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
|
|
|
@@ -99,10 +102,24 @@ function run(args) {
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
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
|
+
|
|
102
116
|
async function connectToSatori(host, user = null, password = null) {
|
|
103
117
|
try {
|
|
104
118
|
console.log(`🔗 Connecting to ${host}...`);
|
|
105
|
-
|
|
119
|
+
// Store credentials for use in all commands
|
|
120
|
+
currentUser = user;
|
|
121
|
+
currentPassword = password;
|
|
122
|
+
satoriInstance = new Satori({ host, user, password });
|
|
106
123
|
await satoriInstance.connect();
|
|
107
124
|
console.log("✅ Successfully connected to SatoriDB");
|
|
108
125
|
return true;
|
|
@@ -128,6 +145,13 @@ async function executeCommand(command, args) {
|
|
|
128
145
|
case "clear":
|
|
129
146
|
clearScreen();
|
|
130
147
|
return;
|
|
148
|
+
|
|
149
|
+
case "mindspace":
|
|
150
|
+
let cmd = args[0];
|
|
151
|
+
if (cmd == "select"){
|
|
152
|
+
let mId = args[1];
|
|
153
|
+
currentMindspace = mId;
|
|
154
|
+
}
|
|
131
155
|
}
|
|
132
156
|
|
|
133
157
|
// Commands that require connection
|
|
@@ -145,11 +169,11 @@ async function executeCommand(command, args) {
|
|
|
145
169
|
}
|
|
146
170
|
let key = args[0];
|
|
147
171
|
let data = args.slice(1).join(' '); // Unir todos los argumentos restantes
|
|
148
|
-
|
|
172
|
+
|
|
149
173
|
// Parsear JSON si es necesario
|
|
150
174
|
data = parseData(data);
|
|
151
|
-
|
|
152
|
-
await satoriInstance.set({key, data});
|
|
175
|
+
|
|
176
|
+
await satoriInstance.set(addCredentials({ key, data }));
|
|
153
177
|
console.log(`✅ Data saved in key: ${key}`);
|
|
154
178
|
break;
|
|
155
179
|
|
|
@@ -161,7 +185,7 @@ async function executeCommand(command, args) {
|
|
|
161
185
|
let [putKey, replaceField, replaceValue, encryption_key_put] = args;
|
|
162
186
|
// Parsear JSON en el valor si es necesario
|
|
163
187
|
replaceValue = parseData(replaceValue);
|
|
164
|
-
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 }));
|
|
165
189
|
console.log(`✅ Field updated: ${putKey}.${replaceField} = ${replaceValue}`);
|
|
166
190
|
break;
|
|
167
191
|
|
|
@@ -169,15 +193,87 @@ async function executeCommand(command, args) {
|
|
|
169
193
|
if (args.length >= 1) {
|
|
170
194
|
let getKey = args[0];
|
|
171
195
|
let encryption_key_get = args[1] || null;
|
|
172
|
-
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 }));
|
|
173
197
|
console.log(`📄 Data from ${getKey}:`, JSON.stringify(result, null, 2));
|
|
174
198
|
break;
|
|
175
|
-
}else{
|
|
176
|
-
let result = await satoriInstance.get();
|
|
199
|
+
} else {
|
|
200
|
+
let result = await satoriInstance.get(addCredentials({}));
|
|
177
201
|
console.log(`📄 Data from get:`, JSON.stringify(result, null, 2));
|
|
178
202
|
break;
|
|
179
203
|
}
|
|
180
|
-
|
|
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
|
+
}
|
|
181
277
|
|
|
182
278
|
case "delete":
|
|
183
279
|
if (args.length < 1) {
|
|
@@ -185,7 +281,7 @@ async function executeCommand(command, args) {
|
|
|
185
281
|
return;
|
|
186
282
|
}
|
|
187
283
|
let deleteKey = args[0];
|
|
188
|
-
await satoriInstance.delete({key: deleteKey});
|
|
284
|
+
await satoriInstance.delete(addCredentials({ key: deleteKey }));
|
|
189
285
|
console.log(`🗑️ Key deleted: ${deleteKey}`);
|
|
190
286
|
break;
|
|
191
287
|
|
|
@@ -196,7 +292,7 @@ async function executeCommand(command, args) {
|
|
|
196
292
|
}
|
|
197
293
|
let question = args[0];
|
|
198
294
|
let backend = args[1] || null;
|
|
199
|
-
let result = await satoriInstance.ask({question, backend});
|
|
295
|
+
let result = await satoriInstance.ask(addCredentials({ question, backend }));
|
|
200
296
|
console.log("🔍 Search results:", JSON.stringify(result, null, 2));
|
|
201
297
|
break;
|
|
202
298
|
|
|
@@ -207,7 +303,7 @@ async function executeCommand(command, args) {
|
|
|
207
303
|
}
|
|
208
304
|
let query = args[0];
|
|
209
305
|
let backend_q = args[1] || null;
|
|
210
|
-
let result_q = await satoriInstance.query({query, backend: backend_q});
|
|
306
|
+
let result_q = await satoriInstance.query(addCredentials({ query, backend: backend_q }));
|
|
211
307
|
console.log("🔍 Search results:", JSON.stringify(result_q, null, 2));
|
|
212
308
|
break;
|
|
213
309
|
|
|
@@ -219,7 +315,7 @@ async function executeCommand(command, args) {
|
|
|
219
315
|
let node = args[0];
|
|
220
316
|
let relation = args[1] || null;
|
|
221
317
|
let encryption_key = args[2] || null;
|
|
222
|
-
let result_dfs = await satoriInstance.dfs({node, relation, encryption_key});
|
|
318
|
+
let result_dfs = await satoriInstance.dfs(addCredentials({ node, relation, encryption_key }));
|
|
223
319
|
console.log("🔍 Search results:", JSON.stringify(result_dfs, null, 2));
|
|
224
320
|
break;
|
|
225
321
|
|
|
@@ -230,7 +326,7 @@ async function executeCommand(command, args) {
|
|
|
230
326
|
}
|
|
231
327
|
let key_encrypt = args[0];
|
|
232
328
|
let encryption_key_encrypt = args[1] || null;
|
|
233
|
-
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 }));
|
|
234
330
|
console.log("🔍 Encryption results:", JSON.stringify(result_encrypt, null, 2));
|
|
235
331
|
break;
|
|
236
332
|
|
|
@@ -241,7 +337,7 @@ async function executeCommand(command, args) {
|
|
|
241
337
|
}
|
|
242
338
|
let key_decrypt = args[0];
|
|
243
339
|
let encryption_key_decrypt = args[1] || null;
|
|
244
|
-
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 }));
|
|
245
341
|
console.log("🔍 Decryption results:", JSON.stringify(result_decrypt, null, 2));
|
|
246
342
|
break;
|
|
247
343
|
|
|
@@ -256,7 +352,7 @@ async function executeCommand(command, args) {
|
|
|
256
352
|
let encryption_key_push = args[3] || null;
|
|
257
353
|
// Parsear JSON en el valor si es necesario
|
|
258
354
|
value_push = parseData(value_push);
|
|
259
|
-
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 }));
|
|
260
356
|
console.log("🔍 Insertion results:", JSON.stringify(result_push, null, 2));
|
|
261
357
|
break;
|
|
262
358
|
|
|
@@ -268,7 +364,7 @@ async function executeCommand(command, args) {
|
|
|
268
364
|
let key_pop = args[0];
|
|
269
365
|
let array_pop = args[1];
|
|
270
366
|
let encryption_key_pop = args[2] || null;
|
|
271
|
-
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 }));
|
|
272
368
|
console.log("🔍 Removal results:", JSON.stringify(result_pop, null, 2));
|
|
273
369
|
break;
|
|
274
370
|
|
|
@@ -280,7 +376,7 @@ async function executeCommand(command, args) {
|
|
|
280
376
|
let key_splice = args[0];
|
|
281
377
|
let array_splice = args[1];
|
|
282
378
|
let encryption_key_splice = args[2] || null;
|
|
283
|
-
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 }));
|
|
284
380
|
console.log("🔍 Insertion results:", JSON.stringify(result_splice, null, 2));
|
|
285
381
|
break;
|
|
286
382
|
|
|
@@ -295,7 +391,7 @@ async function executeCommand(command, args) {
|
|
|
295
391
|
let encryption_key_remove = args[3] || null;
|
|
296
392
|
// Parsear JSON en el valor si es necesario
|
|
297
393
|
value_remove = parseData(value_remove);
|
|
298
|
-
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 }));
|
|
299
395
|
console.log("🔍 Removal results:", JSON.stringify(result_remove, null, 2));
|
|
300
396
|
break;
|
|
301
397
|
|
|
@@ -309,7 +405,7 @@ async function executeCommand(command, args) {
|
|
|
309
405
|
let encryption_key_set_vertex = args[2] || null;
|
|
310
406
|
// Parsear JSON en el vertex si es necesario
|
|
311
407
|
vertex_set_vertex = parseData(vertex_set_vertex);
|
|
312
|
-
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 }));
|
|
313
409
|
console.log("🔍 Insertion results:", JSON.stringify(result_set_vertex, null, 2));
|
|
314
410
|
break;
|
|
315
411
|
|
|
@@ -320,7 +416,7 @@ async function executeCommand(command, args) {
|
|
|
320
416
|
}
|
|
321
417
|
let key_get_vertex = args[0];
|
|
322
418
|
let encryption_key_get_vertex = args[1] || null;
|
|
323
|
-
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 }));
|
|
324
420
|
console.log("🔍 Insertion results:", JSON.stringify(result_get_vertex, null, 2));
|
|
325
421
|
break;
|
|
326
422
|
|
|
@@ -334,10 +430,10 @@ async function executeCommand(command, args) {
|
|
|
334
430
|
let encryption_key_delete_vertex = args[2] || null;
|
|
335
431
|
// Parsear JSON en el vertex si es necesario
|
|
336
432
|
vertex_delete_vertex = parseData(vertex_delete_vertex);
|
|
337
|
-
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 }));
|
|
338
434
|
console.log("🔍 Removal results:", JSON.stringify(result_delete_vertex, null, 2));
|
|
339
435
|
break;
|
|
340
|
-
|
|
436
|
+
|
|
341
437
|
default:
|
|
342
438
|
console.log("❌ Command not recognized. Use 'help' to see available commands.");
|
|
343
439
|
}
|
|
@@ -392,7 +488,7 @@ async function startInteractiveCLI() {
|
|
|
392
488
|
|
|
393
489
|
rl.on('line', async (line) => {
|
|
394
490
|
let trimmedLine = line.trim();
|
|
395
|
-
|
|
491
|
+
|
|
396
492
|
if (trimmedLine === '') {
|
|
397
493
|
rl.prompt();
|
|
398
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",
|