satoridb 1.1.27 → 1.2.2
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 +130 -32
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -5,12 +5,17 @@ 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 nl = true;
|
|
14
|
+
|
|
13
15
|
let satoriInstance = null;
|
|
16
|
+
let currentUser = null;
|
|
17
|
+
let currentPassword = null;
|
|
18
|
+
let currentMindspace = null;
|
|
14
19
|
|
|
15
20
|
// Function to parse arguments with quoted strings support
|
|
16
21
|
function parseArguments(line) {
|
|
@@ -18,22 +23,22 @@ function parseArguments(line) {
|
|
|
18
23
|
let current = '';
|
|
19
24
|
let inQuotes = false;
|
|
20
25
|
let quoteChar = '';
|
|
21
|
-
|
|
26
|
+
|
|
22
27
|
for (let i = 0; i < line.length; i++) {
|
|
23
28
|
let char = line[i];
|
|
24
|
-
|
|
29
|
+
|
|
25
30
|
if ((char === '"' || char === "'") && !inQuotes) {
|
|
26
31
|
inQuotes = true;
|
|
27
32
|
quoteChar = char;
|
|
28
33
|
continue;
|
|
29
34
|
}
|
|
30
|
-
|
|
35
|
+
|
|
31
36
|
if (char === quoteChar && inQuotes) {
|
|
32
37
|
inQuotes = false;
|
|
33
38
|
quoteChar = '';
|
|
34
39
|
continue;
|
|
35
40
|
}
|
|
36
|
-
|
|
41
|
+
|
|
37
42
|
if (char === ' ' && !inQuotes) {
|
|
38
43
|
if (current.trim()) {
|
|
39
44
|
args.push(current.trim());
|
|
@@ -41,14 +46,14 @@ function parseArguments(line) {
|
|
|
41
46
|
}
|
|
42
47
|
continue;
|
|
43
48
|
}
|
|
44
|
-
|
|
49
|
+
|
|
45
50
|
current += char;
|
|
46
51
|
}
|
|
47
|
-
|
|
52
|
+
|
|
48
53
|
if (current.trim()) {
|
|
49
54
|
args.push(current.trim());
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
|
|
52
57
|
return args;
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -99,10 +104,24 @@ function run(args) {
|
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
// Helper function to add user and password to command parameters if defined
|
|
108
|
+
function addCredentials(params) {
|
|
109
|
+
if (currentUser !== null && currentUser !== undefined) {
|
|
110
|
+
params.username = currentUser;
|
|
111
|
+
}
|
|
112
|
+
if (currentPassword !== null && currentPassword !== undefined) {
|
|
113
|
+
params.password = currentPassword;
|
|
114
|
+
}
|
|
115
|
+
return params;
|
|
116
|
+
}
|
|
117
|
+
|
|
102
118
|
async function connectToSatori(host, user = null, password = null) {
|
|
103
119
|
try {
|
|
104
120
|
console.log(`🔗 Connecting to ${host}...`);
|
|
105
|
-
|
|
121
|
+
// Store credentials for use in all commands
|
|
122
|
+
currentUser = user;
|
|
123
|
+
currentPassword = password;
|
|
124
|
+
satoriInstance = new Satori({ host, user, password });
|
|
106
125
|
await satoriInstance.connect();
|
|
107
126
|
console.log("✅ Successfully connected to SatoriDB");
|
|
108
127
|
return true;
|
|
@@ -128,6 +147,13 @@ async function executeCommand(command, args) {
|
|
|
128
147
|
case "clear":
|
|
129
148
|
clearScreen();
|
|
130
149
|
return;
|
|
150
|
+
|
|
151
|
+
case "mindspace":
|
|
152
|
+
let cmd = args[0];
|
|
153
|
+
if (cmd == "select"){
|
|
154
|
+
let mId = args[1];
|
|
155
|
+
currentMindspace = mId;
|
|
156
|
+
}
|
|
131
157
|
}
|
|
132
158
|
|
|
133
159
|
// Commands that require connection
|
|
@@ -145,11 +171,11 @@ async function executeCommand(command, args) {
|
|
|
145
171
|
}
|
|
146
172
|
let key = args[0];
|
|
147
173
|
let data = args.slice(1).join(' '); // Unir todos los argumentos restantes
|
|
148
|
-
|
|
174
|
+
|
|
149
175
|
// Parsear JSON si es necesario
|
|
150
176
|
data = parseData(data);
|
|
151
|
-
|
|
152
|
-
await satoriInstance.set({key, data});
|
|
177
|
+
|
|
178
|
+
await satoriInstance.set(addCredentials({ key, data }));
|
|
153
179
|
console.log(`✅ Data saved in key: ${key}`);
|
|
154
180
|
break;
|
|
155
181
|
|
|
@@ -161,7 +187,7 @@ async function executeCommand(command, args) {
|
|
|
161
187
|
let [putKey, replaceField, replaceValue, encryption_key_put] = args;
|
|
162
188
|
// Parsear JSON en el valor si es necesario
|
|
163
189
|
replaceValue = parseData(replaceValue);
|
|
164
|
-
await satoriInstance.put({key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put});
|
|
190
|
+
await satoriInstance.put(addCredentials({ key: putKey, replace_field: replaceField, replace_value: replaceValue, encryption_key: encryption_key_put }));
|
|
165
191
|
console.log(`✅ Field updated: ${putKey}.${replaceField} = ${replaceValue}`);
|
|
166
192
|
break;
|
|
167
193
|
|
|
@@ -169,15 +195,87 @@ async function executeCommand(command, args) {
|
|
|
169
195
|
if (args.length >= 1) {
|
|
170
196
|
let getKey = args[0];
|
|
171
197
|
let encryption_key_get = args[1] || null;
|
|
172
|
-
let result = await satoriInstance.get({key: getKey, encryption_key: encryption_key_get});
|
|
198
|
+
let result = await satoriInstance.get(addCredentials({ key: getKey, encryption_key: encryption_key_get }));
|
|
173
199
|
console.log(`📄 Data from ${getKey}:`, JSON.stringify(result, null, 2));
|
|
174
200
|
break;
|
|
175
|
-
}else{
|
|
176
|
-
let result = await satoriInstance.get();
|
|
201
|
+
} else {
|
|
202
|
+
let result = await satoriInstance.get(addCredentials({}));
|
|
177
203
|
console.log(`📄 Data from get:`, JSON.stringify(result, null, 2));
|
|
178
204
|
break;
|
|
179
205
|
}
|
|
180
|
-
|
|
206
|
+
|
|
207
|
+
case "set_mindspace":
|
|
208
|
+
if (args.length == 1) {
|
|
209
|
+
let profile = args[0];
|
|
210
|
+
let res = null;
|
|
211
|
+
if (currentMindspace != null){
|
|
212
|
+
|
|
213
|
+
res = await satoriInstance.setMindspace({
|
|
214
|
+
config: profile,
|
|
215
|
+
mindspace_id: currentMindspace
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
res = await satoriInstance.setMindspace({
|
|
220
|
+
config: profile
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
console.log(`✅ Mindspace set: ${res.data}`);
|
|
224
|
+
break;
|
|
225
|
+
} else if (args.length == 2) {
|
|
226
|
+
let profile = args[0];
|
|
227
|
+
let mindspace_id = args[1];
|
|
228
|
+
|
|
229
|
+
let res = await satoriInstance.setMindspace({
|
|
230
|
+
mindspace_id: mindspace_id,
|
|
231
|
+
config: profile
|
|
232
|
+
})
|
|
233
|
+
console.log(`✅ Mindspace set: ${res.data}`);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
case "delete_mindspace":
|
|
238
|
+
if (args.length == 1) {
|
|
239
|
+
let mid = args[0];
|
|
240
|
+
|
|
241
|
+
let res = await satoriInstance.deleteMindspace({
|
|
242
|
+
mindspace_id: mid
|
|
243
|
+
})
|
|
244
|
+
console.log(`✅ Mindspace deleted: ${mid}`);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
case "chat":
|
|
249
|
+
if (args.length == 1) {
|
|
250
|
+
if(currentMindspace == null){
|
|
251
|
+
console.log("Select a mindspace with: mindspace select <mindspace_id>")
|
|
252
|
+
}
|
|
253
|
+
let mid = currentMindspace;
|
|
254
|
+
let message = args[0]
|
|
255
|
+
|
|
256
|
+
let res = await satoriInstance.chatMindspace({
|
|
257
|
+
mindspace_id: mid,
|
|
258
|
+
message: message
|
|
259
|
+
})
|
|
260
|
+
console.log(`${res.data}`);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
case "lecture":
|
|
265
|
+
if(args == 1){
|
|
266
|
+
if(currentMindspace == null){
|
|
267
|
+
console.log("Select a mindspace with: mindspace select <mindspace_id>")
|
|
268
|
+
}
|
|
269
|
+
let mid = currentMindspace;
|
|
270
|
+
let message = args[0]
|
|
271
|
+
|
|
272
|
+
let res = await satoriInstance.lectureMindspace({
|
|
273
|
+
mindspace_id: mid,
|
|
274
|
+
corpus: message
|
|
275
|
+
})
|
|
276
|
+
console.log(`${res.data}`);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
181
279
|
|
|
182
280
|
case "delete":
|
|
183
281
|
if (args.length < 1) {
|
|
@@ -185,7 +283,7 @@ async function executeCommand(command, args) {
|
|
|
185
283
|
return;
|
|
186
284
|
}
|
|
187
285
|
let deleteKey = args[0];
|
|
188
|
-
await satoriInstance.delete({key: deleteKey});
|
|
286
|
+
await satoriInstance.delete(addCredentials({ key: deleteKey }));
|
|
189
287
|
console.log(`🗑️ Key deleted: ${deleteKey}`);
|
|
190
288
|
break;
|
|
191
289
|
|
|
@@ -196,7 +294,7 @@ async function executeCommand(command, args) {
|
|
|
196
294
|
}
|
|
197
295
|
let question = args[0];
|
|
198
296
|
let backend = args[1] || null;
|
|
199
|
-
let result = await satoriInstance.ask({question, backend});
|
|
297
|
+
let result = await satoriInstance.ask(addCredentials({ question, backend }));
|
|
200
298
|
console.log("🔍 Search results:", JSON.stringify(result, null, 2));
|
|
201
299
|
break;
|
|
202
300
|
|
|
@@ -207,7 +305,7 @@ async function executeCommand(command, args) {
|
|
|
207
305
|
}
|
|
208
306
|
let query = args[0];
|
|
209
307
|
let backend_q = args[1] || null;
|
|
210
|
-
let result_q = await satoriInstance.query({query, backend: backend_q});
|
|
308
|
+
let result_q = await satoriInstance.query(addCredentials({ query, backend: backend_q }));
|
|
211
309
|
console.log("🔍 Search results:", JSON.stringify(result_q, null, 2));
|
|
212
310
|
break;
|
|
213
311
|
|
|
@@ -219,7 +317,7 @@ async function executeCommand(command, args) {
|
|
|
219
317
|
let node = args[0];
|
|
220
318
|
let relation = args[1] || null;
|
|
221
319
|
let encryption_key = args[2] || null;
|
|
222
|
-
let result_dfs = await satoriInstance.dfs({node, relation, encryption_key});
|
|
320
|
+
let result_dfs = await satoriInstance.dfs(addCredentials({ node, relation, encryption_key }));
|
|
223
321
|
console.log("🔍 Search results:", JSON.stringify(result_dfs, null, 2));
|
|
224
322
|
break;
|
|
225
323
|
|
|
@@ -230,7 +328,7 @@ async function executeCommand(command, args) {
|
|
|
230
328
|
}
|
|
231
329
|
let key_encrypt = args[0];
|
|
232
330
|
let encryption_key_encrypt = args[1] || null;
|
|
233
|
-
let result_encrypt = await satoriInstance.encrypt({key: key_encrypt, encryption_key: encryption_key_encrypt});
|
|
331
|
+
let result_encrypt = await satoriInstance.encrypt(addCredentials({ key: key_encrypt, encryption_key: encryption_key_encrypt }));
|
|
234
332
|
console.log("🔍 Encryption results:", JSON.stringify(result_encrypt, null, 2));
|
|
235
333
|
break;
|
|
236
334
|
|
|
@@ -241,7 +339,7 @@ async function executeCommand(command, args) {
|
|
|
241
339
|
}
|
|
242
340
|
let key_decrypt = args[0];
|
|
243
341
|
let encryption_key_decrypt = args[1] || null;
|
|
244
|
-
let result_decrypt = await satoriInstance.decrypt({key: key_decrypt, encryption_key: encryption_key_decrypt});
|
|
342
|
+
let result_decrypt = await satoriInstance.decrypt(addCredentials({ key: key_decrypt, encryption_key: encryption_key_decrypt }));
|
|
245
343
|
console.log("🔍 Decryption results:", JSON.stringify(result_decrypt, null, 2));
|
|
246
344
|
break;
|
|
247
345
|
|
|
@@ -256,7 +354,7 @@ async function executeCommand(command, args) {
|
|
|
256
354
|
let encryption_key_push = args[3] || null;
|
|
257
355
|
// Parsear JSON en el valor si es necesario
|
|
258
356
|
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});
|
|
357
|
+
let result_push = await satoriInstance.push(addCredentials({ key: key_push, array: array_push, value: value_push, encryption_key: encryption_key_push }));
|
|
260
358
|
console.log("🔍 Insertion results:", JSON.stringify(result_push, null, 2));
|
|
261
359
|
break;
|
|
262
360
|
|
|
@@ -268,7 +366,7 @@ async function executeCommand(command, args) {
|
|
|
268
366
|
let key_pop = args[0];
|
|
269
367
|
let array_pop = args[1];
|
|
270
368
|
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});
|
|
369
|
+
let result_pop = await satoriInstance.pop(addCredentials({ key: key_pop, array: array_pop, encryption_key: encryption_key_pop }));
|
|
272
370
|
console.log("🔍 Removal results:", JSON.stringify(result_pop, null, 2));
|
|
273
371
|
break;
|
|
274
372
|
|
|
@@ -280,7 +378,7 @@ async function executeCommand(command, args) {
|
|
|
280
378
|
let key_splice = args[0];
|
|
281
379
|
let array_splice = args[1];
|
|
282
380
|
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});
|
|
381
|
+
let result_splice = await satoriInstance.splice(addCredentials({ key: key_splice, array: array_splice, encryption_key: encryption_key_splice }));
|
|
284
382
|
console.log("🔍 Insertion results:", JSON.stringify(result_splice, null, 2));
|
|
285
383
|
break;
|
|
286
384
|
|
|
@@ -295,7 +393,7 @@ async function executeCommand(command, args) {
|
|
|
295
393
|
let encryption_key_remove = args[3] || null;
|
|
296
394
|
// Parsear JSON en el valor si es necesario
|
|
297
395
|
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});
|
|
396
|
+
let result_remove = await satoriInstance.remove(addCredentials({ key: key_remove, array: array_remove, value: value_remove, encryption_key: encryption_key_remove }));
|
|
299
397
|
console.log("🔍 Removal results:", JSON.stringify(result_remove, null, 2));
|
|
300
398
|
break;
|
|
301
399
|
|
|
@@ -309,7 +407,7 @@ async function executeCommand(command, args) {
|
|
|
309
407
|
let encryption_key_set_vertex = args[2] || null;
|
|
310
408
|
// Parsear JSON en el vertex si es necesario
|
|
311
409
|
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});
|
|
410
|
+
let result_set_vertex = await satoriInstance.set_vertex(addCredentials({ key: key_set_vertex, vertex: vertex_set_vertex, encryption_key: encryption_key_set_vertex }));
|
|
313
411
|
console.log("🔍 Insertion results:", JSON.stringify(result_set_vertex, null, 2));
|
|
314
412
|
break;
|
|
315
413
|
|
|
@@ -320,7 +418,7 @@ async function executeCommand(command, args) {
|
|
|
320
418
|
}
|
|
321
419
|
let key_get_vertex = args[0];
|
|
322
420
|
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});
|
|
421
|
+
let result_get_vertex = await satoriInstance.get_vertex(addCredentials({ key: key_get_vertex, encryption_key: encryption_key_get_vertex }));
|
|
324
422
|
console.log("🔍 Insertion results:", JSON.stringify(result_get_vertex, null, 2));
|
|
325
423
|
break;
|
|
326
424
|
|
|
@@ -334,10 +432,10 @@ async function executeCommand(command, args) {
|
|
|
334
432
|
let encryption_key_delete_vertex = args[2] || null;
|
|
335
433
|
// Parsear JSON en el vertex si es necesario
|
|
336
434
|
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});
|
|
435
|
+
let result_delete_vertex = await satoriInstance.delete_vertex(addCredentials({ key: key_delete_vertex, vertex: vertex_delete_vertex, encryption_key: encryption_key_delete_vertex }));
|
|
338
436
|
console.log("🔍 Removal results:", JSON.stringify(result_delete_vertex, null, 2));
|
|
339
437
|
break;
|
|
340
|
-
|
|
438
|
+
|
|
341
439
|
default:
|
|
342
440
|
console.log("❌ Command not recognized. Use 'help' to see available commands.");
|
|
343
441
|
}
|
|
@@ -392,7 +490,7 @@ async function startInteractiveCLI() {
|
|
|
392
490
|
|
|
393
491
|
rl.on('line', async (line) => {
|
|
394
492
|
let trimmedLine = line.trim();
|
|
395
|
-
|
|
493
|
+
|
|
396
494
|
if (trimmedLine === '') {
|
|
397
495
|
rl.prompt();
|
|
398
496
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "satoridb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
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",
|