@indra.ai/deva.data 0.0.122 → 0.0.124

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/index.js +22 -25
  2. 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
- 'devacore:question'(packet) {
53
- this.methods.echo(agent.key, 'q', packet);
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.lib.hash(data);
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,20 @@ 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.action('func', `insert:${opts.collection}:${opts.id}`);
87
+ this.action('func', `insert:${opts.collection}:${opts.data.id.uid}`);
94
88
  let result = false;
95
89
  try {
96
- this.state('insert', opts.collection);
97
- const {database} = this.services().personal.mongo;
90
+ this.state('insert', `${opts.collection}:${opts.data.id.uid}`);
91
+ const {database} = this.data().personal.mongo;
92
+
93
+ this.state('connect', `${opts.collection}:${opts.data.id.uid}`);
98
94
  await this.modules.client.connect(); // connect to the database client.
99
95
  const db = this.modules.client.db(database); // set the database to use
96
+
100
97
  result = await db.collection(opts.collection).insertOne(opts.data); // insert the data
101
98
  } finally {
102
99
  await this.modules.client.close(); // close the connection when done
103
- this.action('return', `insert:${opts.collection}:${opts.id}`);
100
+ this.action('return', `insert:${opts.collection}:${opts.data.id.uid}`);
104
101
  return result; // return the result to the requestor.
105
102
  }
106
103
  },
@@ -115,7 +112,7 @@ const DATA = new Deva({
115
112
  let result = false;
116
113
  try {
117
114
  this.state('update', opts.collection);
118
- const {database} = this.services().personal.mongo;
115
+ const {database} = this.data().personal.mongo;
119
116
  await this.modules.client.connect(); // connect to the database client.
120
117
  const db = this.modules.client.db(database); // set the database to use
121
118
  result = await db.collection(opts.collection).updateOne(
@@ -139,7 +136,7 @@ const DATA = new Deva({
139
136
  let result = false;
140
137
  const {collection,data} = opts;
141
138
  try {
142
- const {database} = this.services().personal.mongo;
139
+ const {database} = this.data().personal.mongo;
143
140
  await this.modules.client.connect();
144
141
  const db = this.modules.client.db(database);
145
142
  result = await db.collection(collection).find(data).sort({created:1}).toArray();
@@ -160,7 +157,7 @@ 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;
160
+ const {database} = this.data().personal.mongo;
164
161
  await this.modules.client.connect();
165
162
  const db = this.modules.client.db(database);
166
163
  const table = db.collection(collection);
@@ -199,7 +196,7 @@ const DATA = new Deva({
199
196
  const {collection,limit} = this.vars.memory;
200
197
  try {
201
198
  this.state('get', `memory`);
202
- const {database} = this.services().personal.mongo;
199
+ const {database} = this.data().personal.mongo;
203
200
  await this.modules.client.connect();
204
201
  const db = this.modules.client.db(database);
205
202
  const table = db.collection(collection);
@@ -239,7 +236,7 @@ const DATA = new Deva({
239
236
 
240
237
  try {
241
238
  this.state('get', 'knowledge');
242
- const {database} = this.services().personal.mongo;
239
+ const {database} = this.data().personal.mongo;
243
240
  await this.modules.client.connect();
244
241
  const db = this.modules.client.db(database);
245
242
  const table = db.collection(collection);
@@ -278,7 +275,7 @@ const DATA = new Deva({
278
275
  // get indexes
279
276
  try {
280
277
  this.state('get', `indexes`);
281
- const {database} = this.services().personal.mongo;
278
+ const {database} = this.data().personal.mongo;
282
279
  await this.modules.client.connect();
283
280
  const db = this.modules.client.db(database);
284
281
  result = await db.collection(opts.collection).listIndexes().toArray();
@@ -300,7 +297,7 @@ const DATA = new Deva({
300
297
  const {collection,limit} = this.vars.history;
301
298
  try {
302
299
  this.state('get', `history`);
303
- const {database} = this.services().personal.mongo;
300
+ const {database} = this.data().personal.mongo;
304
301
  await this.modules.client.connect();
305
302
  const db = this.modules.client.db(database);
306
303
  result = await db.collection(collection).find({}).sort({created:-1}).limit(limit).toArray();
@@ -319,20 +316,20 @@ const DATA = new Deva({
319
316
  describe: insert data into the data vault.
320
317
  ***************/
321
318
  insert(packet) {
322
- this.context('insert', `collection:${packet.q.meta.params[1]}`);
323
- this.action('method', `insert:${packet.q.meta.params[1]}`);
319
+ this.context('insert', `${packet.q.meta.params[1]}:${packet.id.uid}`);
320
+ this.action('method', `insert:${packet.q.meta.params[1]}:${packet.id.uid}`);
324
321
  return new Promise((resolve, reject) => {
325
322
  const {data, meta} = packet.q;
326
323
  const collection = meta.params[1];
327
324
  this.func.insert({collection,data}).then(ins => {
328
- this.state('resolve', `insert:${collection}:${insinsertedId}`)
325
+ this.action('resolve', `insert:${collection}:${insinsertedId}`)
329
326
  return resolve({
330
327
  text: `id:${insinsertedId}`,
331
328
  html: `id:${insinsertedId}`,
332
329
  data: ins,
333
330
  });
334
331
  }).catch(err => {
335
- this.state('reject', 'insert');
332
+ this.action('reject', 'insert');
336
333
  return this.error(packet, err, reject);
337
334
  });
338
335
  });
@@ -345,7 +342,7 @@ const DATA = new Deva({
345
342
  describe: get history
346
343
  ***************/
347
344
  history(packet) {
348
- this.context('history');
345
+ this.context('history', packet.id.uid);
349
346
  return new Promise((resolve, reject) => {
350
347
  this.func.history().then(history => {
351
348
  return resolve({
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.122",
4
+ "version": "0.0.124",
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.8.7",
59
+ "@indra.ai/deva": "^1.8.9",
60
60
  "mongodb": "^6.13.0"
61
61
  },
62
62
  "data": {