@indra.ai/deva.data 0.0.123 → 0.0.125
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/index.js +26 -29
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -49,14 +49,8 @@ const DATA = new Deva({
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
listeners: {
|
|
52
|
-
'
|
|
53
|
-
this.
|
|
54
|
-
},
|
|
55
|
-
'devacore:answer'(packet) {
|
|
56
|
-
this.methods.echo(agent.key, 'a', packet);
|
|
57
|
-
},
|
|
58
|
-
'data:history'(packet) {
|
|
59
|
-
this.context('history');
|
|
52
|
+
async 'data:history'(packet) {
|
|
53
|
+
this.context('history', `${packet.a.agent.key}:${packet.id.uid}`);
|
|
60
54
|
// here we insert a history object into the database.
|
|
61
55
|
this.func.insert({
|
|
62
56
|
collection: 'history',
|
|
@@ -72,7 +66,7 @@ const DATA = new Deva({
|
|
|
72
66
|
a: this.utils.memory(packet.a),
|
|
73
67
|
created: Date.now(),
|
|
74
68
|
}
|
|
75
|
-
data.hash = this.
|
|
69
|
+
data.hash = this.hash(data);
|
|
76
70
|
await this.func.insert({
|
|
77
71
|
collection: `memory_${packet.agent.key}`,
|
|
78
72
|
data,
|
|
@@ -90,17 +84,22 @@ const DATA = new Deva({
|
|
|
90
84
|
describe: the insert function that inserts into the specified collection.
|
|
91
85
|
***************/
|
|
92
86
|
async insert(opts) {
|
|
93
|
-
this.
|
|
87
|
+
this.belief('data', `uid:${opts.data.id.uid}`);
|
|
88
|
+
this.action('func', `insert:${opts.collection}:${opts.data.id.uid}`);
|
|
94
89
|
let result = false;
|
|
95
90
|
try {
|
|
96
|
-
this.state('insert', opts.collection);
|
|
97
|
-
|
|
91
|
+
this.state('insert', `${opts.collection}:${opts.data.id.uid}`);
|
|
92
|
+
this.state('connect', `${opts.collection}:${opts.data.id.uid}`);
|
|
98
93
|
await this.modules.client.connect(); // connect to the database client.
|
|
99
|
-
const db = this.modules.client.db(database); // set the database to use
|
|
94
|
+
const db = this.modules.client.db(this.vars.database); // set the database to use
|
|
95
|
+
|
|
100
96
|
result = await db.collection(opts.collection).insertOne(opts.data); // insert the data
|
|
101
97
|
} finally {
|
|
102
98
|
await this.modules.client.close(); // close the connection when done
|
|
103
|
-
this.action('return', `insert:${opts.collection}:${opts.id}`);
|
|
99
|
+
this.action('return', `insert:${opts.collection}:${opts.data.id.uid}`);
|
|
100
|
+
this.state('valid', `insert:${opts.collection}:${opts.data.id.uid}`);
|
|
101
|
+
this.intent('good', `insert:${opts.collection}:${opts.data.id.uid}`);
|
|
102
|
+
this.belief('vedic', `uid:${opts.data.id.uid}`);
|
|
104
103
|
return result; // return the result to the requestor.
|
|
105
104
|
}
|
|
106
105
|
},
|
|
@@ -115,9 +114,8 @@ const DATA = new Deva({
|
|
|
115
114
|
let result = false;
|
|
116
115
|
try {
|
|
117
116
|
this.state('update', opts.collection);
|
|
118
|
-
const {database} = this.services().personal.mongo;
|
|
119
117
|
await this.modules.client.connect(); // connect to the database client.
|
|
120
|
-
const db = this.modules.client.db(database); // set the database to use
|
|
118
|
+
const db = this.modules.client.db(this.vars.database); // set the database to use
|
|
121
119
|
result = await db.collection(opts.collection).updateOne(
|
|
122
120
|
{ _id: new ObjectId(`${opts.id}`) },
|
|
123
121
|
{ $set: opts.data }
|
|
@@ -139,9 +137,8 @@ const DATA = new Deva({
|
|
|
139
137
|
let result = false;
|
|
140
138
|
const {collection,data} = opts;
|
|
141
139
|
try {
|
|
142
|
-
const {database} = this.services().personal.mongo;
|
|
143
140
|
await this.modules.client.connect();
|
|
144
|
-
const db = this.modules.client.db(database);
|
|
141
|
+
const db = this.modules.client.db(this.vars.database);
|
|
145
142
|
result = await db.collection(collection).find(data).sort({created:1}).toArray();
|
|
146
143
|
} finally {
|
|
147
144
|
await this.modules.client.close();
|
|
@@ -160,9 +157,8 @@ const DATA = new Deva({
|
|
|
160
157
|
try {
|
|
161
158
|
this.state('search', opts.text);
|
|
162
159
|
const {collection,limit} = this.vars.search;
|
|
163
|
-
const {database} = this.services().personal.mongo;
|
|
164
160
|
await this.modules.client.connect();
|
|
165
|
-
const db = this.modules.client.db(database);
|
|
161
|
+
const db = this.modules.client.db(this.vars.database);
|
|
166
162
|
const table = db.collection(collection);
|
|
167
163
|
|
|
168
164
|
// await table.dropIndex('a.text_1');
|
|
@@ -199,7 +195,7 @@ const DATA = new Deva({
|
|
|
199
195
|
const {collection,limit} = this.vars.memory;
|
|
200
196
|
try {
|
|
201
197
|
this.state('get', `memory`);
|
|
202
|
-
const {database} = this.
|
|
198
|
+
const {database} = this.data().personal.mongo;
|
|
203
199
|
await this.modules.client.connect();
|
|
204
200
|
const db = this.modules.client.db(database);
|
|
205
201
|
const table = db.collection(collection);
|
|
@@ -239,7 +235,7 @@ const DATA = new Deva({
|
|
|
239
235
|
|
|
240
236
|
try {
|
|
241
237
|
this.state('get', 'knowledge');
|
|
242
|
-
const {database} = this.
|
|
238
|
+
const {database} = this.data().personal.mongo;
|
|
243
239
|
await this.modules.client.connect();
|
|
244
240
|
const db = this.modules.client.db(database);
|
|
245
241
|
const table = db.collection(collection);
|
|
@@ -278,7 +274,7 @@ const DATA = new Deva({
|
|
|
278
274
|
// get indexes
|
|
279
275
|
try {
|
|
280
276
|
this.state('get', `indexes`);
|
|
281
|
-
const {database} = this.
|
|
277
|
+
const {database} = this.data().personal.mongo;
|
|
282
278
|
await this.modules.client.connect();
|
|
283
279
|
const db = this.modules.client.db(database);
|
|
284
280
|
result = await db.collection(opts.collection).listIndexes().toArray();
|
|
@@ -300,7 +296,7 @@ const DATA = new Deva({
|
|
|
300
296
|
const {collection,limit} = this.vars.history;
|
|
301
297
|
try {
|
|
302
298
|
this.state('get', `history`);
|
|
303
|
-
const {database} = this.
|
|
299
|
+
const {database} = this.data().personal.mongo;
|
|
304
300
|
await this.modules.client.connect();
|
|
305
301
|
const db = this.modules.client.db(database);
|
|
306
302
|
result = await db.collection(collection).find({}).sort({created:-1}).limit(limit).toArray();
|
|
@@ -319,20 +315,20 @@ const DATA = new Deva({
|
|
|
319
315
|
describe: insert data into the data vault.
|
|
320
316
|
***************/
|
|
321
317
|
insert(packet) {
|
|
322
|
-
this.context('insert',
|
|
323
|
-
this.action('method', `insert:${packet.q.meta.params[1]}`);
|
|
318
|
+
this.context('insert', `${packet.q.meta.params[1]}:${packet.id.uid}`);
|
|
319
|
+
this.action('method', `insert:${packet.q.meta.params[1]}:${packet.id.uid}`);
|
|
324
320
|
return new Promise((resolve, reject) => {
|
|
325
321
|
const {data, meta} = packet.q;
|
|
326
322
|
const collection = meta.params[1];
|
|
327
323
|
this.func.insert({collection,data}).then(ins => {
|
|
328
|
-
this.
|
|
324
|
+
this.action('resolve', `insert:${collection}:${insinsertedId}`)
|
|
329
325
|
return resolve({
|
|
330
326
|
text: `id:${insinsertedId}`,
|
|
331
327
|
html: `id:${insinsertedId}`,
|
|
332
328
|
data: ins,
|
|
333
329
|
});
|
|
334
330
|
}).catch(err => {
|
|
335
|
-
this.
|
|
331
|
+
this.action('reject', 'insert');
|
|
336
332
|
return this.error(packet, err, reject);
|
|
337
333
|
});
|
|
338
334
|
});
|
|
@@ -345,7 +341,7 @@ const DATA = new Deva({
|
|
|
345
341
|
describe: get history
|
|
346
342
|
***************/
|
|
347
343
|
history(packet) {
|
|
348
|
-
this.context('history');
|
|
344
|
+
this.context('history', packet.id.uid);
|
|
349
345
|
return new Promise((resolve, reject) => {
|
|
350
346
|
this.func.history().then(history => {
|
|
351
347
|
return resolve({
|
|
@@ -555,6 +551,7 @@ const DATA = new Deva({
|
|
|
555
551
|
onReady(data, resolve) {
|
|
556
552
|
const {VLA} = this.info();
|
|
557
553
|
const {mongo} = this.data().global;
|
|
554
|
+
this.vars.database = mongo.database;
|
|
558
555
|
this.modules.client = new MongoClient(mongo.uri);
|
|
559
556
|
this.prompt(`${this.vars.messages.ready} > VLA:${VLA.uid}`);
|
|
560
557
|
return resolve(data);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "65859204002504361305",
|
|
3
3
|
"name": "@indra.ai/deva.data",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.125",
|
|
5
5
|
"license": "VLA:65859204002504361305 LICENSE.md",
|
|
6
6
|
"VLA": {
|
|
7
7
|
"uid": "65859204002504361305",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"homepage": "https://indra.ai",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@indra.ai/deva": "^1.
|
|
59
|
+
"@indra.ai/deva": "^1.9.1",
|
|
60
60
|
"mongodb": "^6.13.0"
|
|
61
61
|
},
|
|
62
62
|
"data": {
|