@indra.ai/deva 1.6.95 → 1.6.97

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.
@@ -47,6 +47,7 @@
47
47
  "exit": "🚪 Exit",
48
48
  "method": "❤️‍🔥 Method",
49
49
  "func": "🔦 Func",
50
+ "onfunc": "🎚️ onFunction",
50
51
  "actions": "🏎️ Actions",
51
52
  "features": "🎥 Features",
52
53
  "contexts": "🌈 Contexts",
@@ -114,6 +114,7 @@
114
114
  "real": "😲 Real",
115
115
  "mature": "🧓 Mature",
116
116
  "immature": "🧒 Immature",
117
- "consent": "✍️ Consent"
117
+ "consent": "✍️ Consent",
118
+ "onfunc": "🎚️ onFunction"
118
119
  }
119
120
  }
package/index.js CHANGED
@@ -255,13 +255,13 @@ class Deva {
255
255
 
256
256
  _getFeature(key, value) {
257
257
  if (!this._active) return this._messages.offline; // check the active status
258
- this.zone(key);
259
258
  this.feature(key); // set the security state
259
+ this.zone(key);
260
260
  this.action(key);
261
261
  this.state(key);
262
262
  try {
263
263
  const data = this.lib.copy(value);
264
- this.state('return', key); // set the security state
264
+ this.action('return', key); // set the security state
265
265
  return data; // return the security feature
266
266
  } catch (e) {
267
267
  this.state('catch', key);
@@ -983,7 +983,7 @@ class Deva {
983
983
  }
984
984
 
985
985
  this.action('hash', `start:md5:${data.id.uid}`);
986
- data.md5 = this.hash(data);
986
+ data.md5 = this.hash(data, 'md5');
987
987
 
988
988
  this.action('hash', `start:sha256:${data.id.uid}`)
989
989
  data.sha256 = this.hash(data, 'sha256');
@@ -1055,7 +1055,10 @@ class Deva {
1055
1055
  return this.Done(resolve, reject);
1056
1056
  }).then(() => {
1057
1057
  const hasOnInit = this.onInit && typeof this.onInit === 'function';
1058
- if (hasOnInit) this.state('set', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1058
+ if (hasOnInit) {
1059
+ this.action('onfunc', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1060
+ this.state('onfunc', `hasOnInit:${data.id.uid}`); // state set to watch onInit
1061
+ }
1059
1062
  this.action('return', `init:${data.id.uid}`);
1060
1063
  return hasOnInit ? this.onInit(data, resolve) : this.start(data, resolve);
1061
1064
  }).catch(err => {
@@ -1093,7 +1096,7 @@ class Deva {
1093
1096
  data.value = 'start';
1094
1097
 
1095
1098
  this.action('hash', `start:md5:${data.id.uid}`);
1096
- data.md5 = this.hash(data);
1099
+ data.md5 = this.hash(data, 'md5');
1097
1100
  this.action('hash', `start:sha256:${data.id.uid}`)
1098
1101
  data.sha256 = this.hash(data, 'sha256');
1099
1102
  this.action('hash', `start:sha512:${data.id.uid}`)
@@ -1104,7 +1107,10 @@ class Deva {
1104
1107
  this.talk(this._events.start, data);
1105
1108
 
1106
1109
  const hasOnStart = this.onStart && typeof this.onStart === 'function' ? true : false;
1107
- if (hasOnStart) this.state('set', `hasOnStart:${data.id.uid}`); // state set to watch OnFinish
1110
+ if (hasOnStart) {
1111
+ this.action('onfunc', `hasOnStart:${data.id.uid}`); // set action to onfunc
1112
+ this.state('onfunc', `hasOnStart:${data.id.uid}`); // set state to onfunc
1113
+ }
1108
1114
 
1109
1115
  this.action('return', `start:${data.id.uid}`); // return action finish
1110
1116
  return hasOnStart ? this.onStart(data, resolve) : this.enter(data, resolve)
@@ -1139,7 +1145,7 @@ class Deva {
1139
1145
  data.value = 'enter';
1140
1146
 
1141
1147
  this.action('hash', `enter:md5:${data.id.uid}`);
1142
- data.md5 = this.hash(data);
1148
+ data.md5 = this.hash(data, 'md5');
1143
1149
  this.action('hash', `enter:sha256:${data.id.uid}`)
1144
1150
  data.sha256 = this.hash(data, 'sha256');
1145
1151
  this.action('hash', `enter:sha512:${data.id.uid}`)
@@ -1149,7 +1155,10 @@ class Deva {
1149
1155
  this.talk(this._events.enter, data);
1150
1156
 
1151
1157
  const hasOnEnter = this.onEnter && typeof this.onEnter === 'function' ? true : false;
1152
- if (hasOnEnter) this.state('set', `hasOnEnter:${data.id.uid}`); // state set to watch OnFinish
1158
+ if (hasOnEnter) {
1159
+ this.action('onfunc', `hasOnEnter:${data.id.uid}`); // action onfunc set
1160
+ this.state('onfunc', `hasOnEnter:${data.id.uid}`); // state onfunc set
1161
+ }
1153
1162
 
1154
1163
  this.action('return', `enter:${data.id.uid}`); // return action finish
1155
1164
  return hasOnEnter ? this.onEnter(data, resolve) : this.done(data, resolve)
@@ -1184,7 +1193,7 @@ class Deva {
1184
1193
  data.value = 'done';
1185
1194
 
1186
1195
  this.action('hash', `done:md5:${data.id.uid}`);
1187
- data.md5 = this.hash(data);
1196
+ data.md5 = this.hash(data, 'md5');
1188
1197
  this.action('hash', `done:sha256:${data.id.uid}`)
1189
1198
  data.sha256 = this.hash(data, 'sha256');
1190
1199
  this.action('hash', `done:sha512:${data.id.uid}`)
@@ -1194,7 +1203,10 @@ class Deva {
1194
1203
  this.talk(this._events.done, data);
1195
1204
 
1196
1205
  const hasOnDone = this.onDone && typeof this.onDone === 'function' ? true : false;
1197
- if (hasOnDone) this.state('set', `hasOnDone:${data.id.uid}`); // state set to watch OnFinish
1206
+ if (hasOnDone) {
1207
+ this.action('onfunc', `hasOnDone:${data.id.uid}`); // state onfunc
1208
+ this.state('onfunc', `hasOnDone:${data.id.uid}`); // state onfunc
1209
+ }
1198
1210
 
1199
1211
  this.action('return', `done:${data.id.uid}`); // return action finish
1200
1212
  return hasOnDone ? this.onDone(data, resolve) : this.ready(data, resolve);
@@ -1227,7 +1239,7 @@ class Deva {
1227
1239
  data.value = 'ready';
1228
1240
 
1229
1241
  this.action('hash', `ready:md5:${data.id.uid}`);
1230
- data.md5 = this.hash(data);
1242
+ data.md5 = this.hash(data, 'md5');
1231
1243
  this.action('hash', `ready:sha256:${data.id.uid}`)
1232
1244
  data.sha256 = this.hash(data, 'sha256');
1233
1245
  this.action('hash', `ready:sha512:${data.id.uid}`)
@@ -1237,7 +1249,10 @@ class Deva {
1237
1249
  this.talk(this._events.ready, data);
1238
1250
 
1239
1251
  const hasOnReady = this.onReady && typeof this.onReady === 'function';
1240
- if (hasOnReady) this.state('set', `hasOnReady:${data.id.uid}`); // state set to watch OnFinish
1252
+ if (hasOnReady) {
1253
+ this.action('onfunc', `hasOnReady:${data.id.uid}`); // action onfunc
1254
+ this.state('onfunc', `hasOnReady:${data.id.uid}`); // state onfunc
1255
+ }
1241
1256
 
1242
1257
  this.action('resolve', `ready:${data.id.uid}`); // return action ready
1243
1258
  return hasOnReady ? this.onReady(data, resolve) : resolve(data);
@@ -1269,7 +1284,7 @@ class Deva {
1269
1284
  this.state('set', `data:finish:${data.finish}:${data.id.uid}`)
1270
1285
 
1271
1286
  this.action('hash', `finish:md5:${data.id.uid}`);
1272
- data.md5 = this.hash(data);
1287
+ data.md5 = this.hash(data, 'md5');
1273
1288
  this.action('hash', `finish:sha256:${data.id.uid}`)
1274
1289
  data.sha256 = this.hash(data, 'sha256');
1275
1290
  this.action('hash', `finish:sha512:${data.id.uid}`)
@@ -1280,7 +1295,10 @@ class Deva {
1280
1295
  this.talk(this._events.finish, data);
1281
1296
 
1282
1297
  const hasOnFinish = this.onFinish && typeof this.onFinish === 'function';
1283
- if (hasOnFinish) this.state('set', `hasOnFinish:${data.id.uid}`); // state set to watch OnFinish
1298
+ if (hasOnFinish) {
1299
+ this.action('onfunc', `hasOnFinish:${data.id.uid}`); // action onfunc
1300
+ this.state('onfunc', `hasOnFinish:${data.id.uid}`); // state onfunc
1301
+ }
1284
1302
 
1285
1303
  this.action('return', `finish:${data.id.uid}`); // return action finish
1286
1304
  return hasOnFinish ? this.onFinish(data, resolve) : this.complete(data, resolve);
@@ -1296,7 +1314,7 @@ class Deva {
1296
1314
  usage: this.complete(data, resolve)
1297
1315
  ***************/
1298
1316
  complete(data, resolve) {
1299
- if (!this._active) return Promise.resolve(this._messages.offline);
1317
+ if (!this._active) return resolve(this._messages.offline);
1300
1318
  this.context('complete', data.id.uid);
1301
1319
  this.zone('complete', data.id.uid);
1302
1320
  this.action('complete', data.id.uid);
@@ -1313,7 +1331,7 @@ class Deva {
1313
1331
  this.state('set', `data:complete:${data.complete}:${data.id.uid}`)
1314
1332
 
1315
1333
  this.action('hash', `complete:md5:${data.id.uid}`);
1316
- data.md5 = this.hash(data);
1334
+ data.md5 = this.hash(data, 'md5');
1317
1335
  this.action('hash', `complete:sha256:${data.id.uid}`)
1318
1336
  data.sha256 = this.hash(data, 'sha256');
1319
1337
 
@@ -1326,7 +1344,10 @@ class Deva {
1326
1344
 
1327
1345
  // determine if there is an onComplete function for the entity.
1328
1346
  const hasOnComplete = this.onComplete && typeof this.onComplete === 'function';
1329
- if (hasOnComplete) this.state('set', `hasOnComplete:${data.id.uid}`); // state set to watch OnFinish
1347
+ if (hasOnComplete) {
1348
+ this.action('onfunc', `hasOnComplete:${data.id.uid}`); // action onfunc
1349
+ this.state('onfunc', `hasOnComplete:${data.id.uid}`); // state onfunc
1350
+ }
1330
1351
 
1331
1352
  this.action('return', `complete:${data.id.uid}`); // return action complete
1332
1353
  return hasOnComplete ? this.onComplete(data, resolve) : resolve(data);
@@ -1346,7 +1367,7 @@ class Deva {
1346
1367
  this.stop()
1347
1368
  ***************/
1348
1369
  stop() {
1349
- if (!this._active) return Promise.resolve(this._messages.offline);
1370
+ if (!this._active) return this._messages.offline;
1350
1371
  const id = this.uid();
1351
1372
  this.context('stop', id.uid);
1352
1373
  this.zone('stop', id.uid);
@@ -1370,7 +1391,7 @@ class Deva {
1370
1391
  }
1371
1392
 
1372
1393
  this.action('hash', `stop:md5:${data.id.uid}`);
1373
- data.md5 = this.hash(data);
1394
+ data.md5 = this.hash(data, 'md5');
1374
1395
  this.action('hash', `stop:sha256:${data.id.uid}`)
1375
1396
  data.sha256 = this.hash(data, 'sha256');
1376
1397
  this.action('hash', `stop:sha512:${data.id.uid}`)
@@ -1383,7 +1404,10 @@ class Deva {
1383
1404
 
1384
1405
  // determine if there is an onComplete function for the entity.
1385
1406
  const hasOnStop = this.onStop && typeof this.onStop === 'function';
1386
- if (hasOnStop) this.state('set', `hasOnStop:${data.id.uid}`); // state set to watch OnFinish
1407
+ if (hasOnStop) {
1408
+ this.action('onfunc', `hasOnStop:${data.id.uid}`); // action onfunc
1409
+ this.state('onfunc', `hasOnStop:${data.id.uid}`); // state onfunc
1410
+ }
1387
1411
  return hasOnStop ? this.onStop(data) : this.exit(data)
1388
1412
  }
1389
1413
 
@@ -1398,7 +1422,7 @@ class Deva {
1398
1422
  function.
1399
1423
  ***************/
1400
1424
  exit(data) {
1401
- if (!this._active) return Promise.resolve(this._messages.offline);
1425
+ if (!this._active) return this._messages.offline;
1402
1426
 
1403
1427
  this.context('exit', data.id.uid);
1404
1428
  this.zone('exit', data.id.uid);
@@ -1416,7 +1440,7 @@ class Deva {
1416
1440
  data.exit = Date.now();
1417
1441
 
1418
1442
  this.action('hash', `stop:md5:${data.id.uid}`);
1419
- data.md5 = this.hash(data);
1443
+ data.md5 = this.hash(data, 'md5');
1420
1444
  this.action('hash', `stop:sha256:${data.id.uid}`)
1421
1445
  data.sha256 = this.hash(data, 'sha256');
1422
1446
  this.action('hash', `stop:sha512:${data.id.uid}`)
@@ -1451,9 +1475,12 @@ class Deva {
1451
1475
  this.talk(this._events.exit, data);
1452
1476
 
1453
1477
  const hasOnExit = this.onExit && typeof this.onExit === 'function';
1454
- if (hasOnExit) this.state('set', `hasOnExit:${data.id.uid}`); // state set to watch OnFinish
1478
+ if (hasOnExit) {
1479
+ this.action('onfunc', `hasOnExit:${data.id.uid}`); // action onfunc
1480
+ this.state('onfunc', `hasOnExit:${data.id.uid}`); // state onfunc
1481
+ }
1455
1482
 
1456
- this.action('return', `exit:${data.uid}`);
1483
+ this.action('resolve', `exit:${data.uid}`);
1457
1484
  return hasOnExit ? this.onExit(data) : Promise.resolve(data)
1458
1485
  }
1459
1486
 
@@ -1464,29 +1491,32 @@ class Deva {
1464
1491
  func: state
1465
1492
  params:
1466
1493
  - value: The state value to set for the Deva that matches to this._states
1467
- - extra: any extra text to add ot the state change.
1494
+ - extra: any extra text to add to the state change.
1468
1495
  ***************/
1469
1496
  state(value=false, extra=false) {
1497
+ if (!this._active) return this._messages.offline;
1498
+ const id = this.uid();
1499
+ const key = 'state';
1470
1500
  try {
1471
1501
  if (!value || !this._states[value]) return; // return if no matching value
1472
1502
  this._state = value; // set the local state variable.
1473
1503
  const lookup = this._states[value]; // set the local states lookup
1474
1504
  const text = extra ? `${lookup} ${extra}` : lookup; // set text from lookup with extra
1475
1505
  const data = { // build the data object
1476
- id: this.uid(), // set the data id
1477
- agent: this.agent(), // set the agent
1478
- client: this.client(), // set the client
1479
- key: 'state', // set the key to state
1506
+ id, // set the data id
1507
+ key, // set the key to state
1480
1508
  value, // set the value to the passed in value
1481
1509
  text, // set the text value of the data
1510
+ agent: this.agent(), // set the agent
1511
+ client: this.client(), // set the client
1482
1512
  created: Date.now(), // set the data created date.
1483
1513
  };
1484
1514
 
1485
- data.md5 = this.hash(data);
1515
+ data.md5 = this.hash(data, 'md5');
1486
1516
  data.sha256 = this.hash(data, 'sha256');
1487
1517
  data.sha512 = this.hash(data, 'sha512');
1488
1518
 
1489
- this.talk(this._events.state, data); // broadcasat the state event
1519
+ this.talk(this._events.state, data); // broadcast the state event
1490
1520
  return data;
1491
1521
  } catch (e) { // catch any errors
1492
1522
  return this.err(e); // return if an error happens
@@ -1499,7 +1529,7 @@ class Deva {
1499
1529
  describe: returns the available states values.
1500
1530
  ***************/
1501
1531
  states() {
1502
- if (!this._active) return Promise.resolve(this._messages.offline);
1532
+ if (!this._active) return this._messages.offline;
1503
1533
  const id = this.uid();
1504
1534
  const key = 'states';
1505
1535
  this.action(key, id.uid);
@@ -1516,7 +1546,7 @@ class Deva {
1516
1546
  }
1517
1547
 
1518
1548
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1519
- data.md5 = this.hash(data);
1549
+ data.md5 = this.hash(data, 'md5');
1520
1550
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1521
1551
  data.sha256 = this.hash(data, 'sha256');
1522
1552
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
@@ -1533,7 +1563,9 @@ class Deva {
1533
1563
  describe
1534
1564
  ***************/
1535
1565
  zone(value=false, extra=false) {
1566
+ if (!this._active) return this._messages.offline;
1536
1567
  const id = this.uid();
1568
+ const key = 'zone';
1537
1569
  if (!value || !this._zones[value]) return;
1538
1570
 
1539
1571
  try {
@@ -1543,15 +1575,15 @@ class Deva {
1543
1575
 
1544
1576
  const data = { // build the zone data
1545
1577
  id, // set the packetid
1546
- agent: this.agent(),
1547
- client: this.client(),
1548
- key: 'zone',
1578
+ key,
1549
1579
  value,
1550
1580
  text,
1581
+ agent: this.agent(),
1582
+ client: this.client(),
1551
1583
  created: Date.now(),
1552
1584
  };
1553
1585
 
1554
- data.md5 = this.hash(data);
1586
+ data.md5 = this.hash(data, 'md5');
1555
1587
  data.sha256 = this.hash(data, 'sha256');
1556
1588
  data.sha512 = this.hash(data, 'sha512');
1557
1589
 
@@ -1568,7 +1600,7 @@ class Deva {
1568
1600
  describe: returns a listing of zones currently in the system.
1569
1601
  ***************/
1570
1602
  zones() {
1571
- if (!this._active) return Promise.resolve(this._messages.offline);
1603
+ if (!this._active) return this._messages.offline;
1572
1604
  const id = this.uid();
1573
1605
  const key = 'zones';
1574
1606
  this.action(key, id.uid);
@@ -1584,7 +1616,7 @@ class Deva {
1584
1616
  }
1585
1617
 
1586
1618
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1587
- data.md5 = this.hash(data);
1619
+ data.md5 = this.hash(data, 'md5');
1588
1620
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1589
1621
  data.sha256 = this.hash(data, 'sha256');
1590
1622
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
@@ -1602,7 +1634,9 @@ class Deva {
1602
1634
  describe
1603
1635
  ***************/
1604
1636
  action(value=false, extra=false) {
1637
+ if (!this._active) return this._messages.offline;
1605
1638
  const id = this.uid();
1639
+ const key = 'action'
1606
1640
  try {
1607
1641
  if (!value || !this._actions[value]) return;
1608
1642
  this._action = value; // set the local action variable
@@ -1615,22 +1649,22 @@ class Deva {
1615
1649
 
1616
1650
  const data = { // build the data object for the action.
1617
1651
  id, // generate a guid for the action transmitssion.
1618
- agent: this.agent(), // the agent data to send with the action
1619
- client: this.client(), // the client data to send with the action
1620
- key: 'action', // the key for event to transmit action type
1652
+ key, // the key for event to transmit action type
1621
1653
  value, // the value key which is the action passed
1622
1654
  text, // text of the action to send
1655
+ agent: this.agent(), // the agent data to send with the action
1656
+ client: this.client(), // the client data to send with the action
1623
1657
  created: Date.now(), // action time stamp
1624
1658
  };
1625
1659
 
1626
- data.md5 = this.hash(data);
1660
+ data.md5 = this.hash(data, 'md5');
1627
1661
  data.sha256 = this.hash(data, 'sha256');
1628
1662
  data.sha512 = this.hash(data, 'sha512');
1629
1663
 
1630
1664
  this.talk(this._events.action, data); // talk the core action event
1631
1665
  return data;
1632
1666
  } catch (e) { // catch any errors that occur
1633
- this.state('catch', `action:${value}:${id.uid}`);
1667
+ this.state('catch', `${key}:${id.uid}`);
1634
1668
  return this.err(e); // return error on error catch
1635
1669
  }
1636
1670
  }
@@ -1641,7 +1675,7 @@ class Deva {
1641
1675
  describe: Returns a list of available actions in the system.
1642
1676
  ***************/
1643
1677
  actions() {
1644
- if (!this._active) return Promise.resolve(this._messages.offline);
1678
+ if (!this._active) return this._messages.offline;
1645
1679
  const id = this.uid();
1646
1680
  const key = 'actions';
1647
1681
  this.action(key, id.uid);
@@ -1657,13 +1691,13 @@ class Deva {
1657
1691
  };
1658
1692
 
1659
1693
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1660
- data.md5 = this.hash(data);
1694
+ data.md5 = this.hash(data, 'md5');
1661
1695
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1662
1696
  data.sha256 = this.hash(data, 'sha256');
1663
1697
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1664
1698
  data.sha512 = this.hash(data, 'sha512');
1665
1699
 
1666
- this.state('return', `actions:${id.uid}`);
1700
+ this.state('return', `${key}:${id.uid}`);
1667
1701
  return data;
1668
1702
  }
1669
1703
 
@@ -1691,7 +1725,7 @@ class Deva {
1691
1725
  created: Date.now(), // set the creation date
1692
1726
  };
1693
1727
 
1694
- data.md5 = this.hash(data);
1728
+ data.md5 = this.hash(data, 'md5');
1695
1729
  data.sha256 = this.hash(data, 'sha256');
1696
1730
  data.sha512 = this.hash(data, 'sha512');
1697
1731
 
@@ -1711,21 +1745,27 @@ class Deva {
1711
1745
  features() {
1712
1746
  if (!this._active) return this._messages.offline; // check the active status
1713
1747
  const id = this.uid();
1714
- this.action('features', id.uid);
1748
+ const key = 'features';
1749
+ this.action(key, id.uid);
1750
+
1751
+ this.state('data', `${key}:${id.uid}`);
1715
1752
  const data = {
1716
1753
  id, // set the object id
1754
+ key, // set the key
1755
+ value: this._features, // set the value to the features list
1717
1756
  agent: this.agent(), // set the agent value.
1718
1757
  client: this.client(), // set the client value.
1719
- key: 'features', // set the key
1720
- value: this._features, // set the value to the features list
1721
1758
  created: Date.now(), // set the created date.
1722
1759
  };
1723
1760
 
1724
- data.md5 = this.hash(data);
1725
- data.sha256 = this.hash(data, 'sha256');
1761
+ this.action('hash', `${data.key}:md5:${data.id.uid}`);
1762
+ data.md5 = this.hash(data, 'md5');
1763
+ this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1764
+ data.sha256 = this.hash(data, 'sha256');
1765
+ this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1726
1766
  data.sha512 = this.hash(data, 'sha512');
1727
-
1728
- this.state('return', `features:${id.uid}`);
1767
+
1768
+ this.state('return', `${data.key}:${data.id.uid}`);
1729
1769
  return data;
1730
1770
  }
1731
1771
 
@@ -1755,7 +1795,7 @@ class Deva {
1755
1795
  created: Date.now(),
1756
1796
  };
1757
1797
 
1758
- data.md5 = this.hash(data);
1798
+ data.md5 = this.hash(data, 'md5');
1759
1799
  data.sha256 = this.hash(data, 'sha256');
1760
1800
  data.sha512 = this.hash(data, 'sha512');
1761
1801
 
@@ -1770,22 +1810,27 @@ class Deva {
1770
1810
  contexts() {
1771
1811
  if (!this._active) return this._messages.offline; // check the active status
1772
1812
  const id = this.uid();
1773
- this.action('contexts', id);
1774
- if (!this._active) return this._messages.offline; // check the active status
1813
+ const key = 'contexts';
1814
+ this.action(key, id.uid);
1815
+
1816
+ this.state('data', `${key}:${id.uid}`);
1775
1817
  const data = {
1776
1818
  id,
1819
+ key,
1820
+ value: this.vars.context || false,
1777
1821
  agent: this.agent(),
1778
1822
  client: this.client(),
1779
- key: 'contexts',
1780
- value: this.vars.context || false,
1781
1823
  created: Date.now(),
1782
1824
  };
1783
1825
 
1784
- data.md5 = this.hash(data);
1785
- data.sha256 = this.hash(data, 'sha256');
1826
+ this.action('hash', `${data.key}:md5:${data.id.uid}`);
1827
+ data.md5 = this.hash(data, 'md5');
1828
+ this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1829
+ data.sha256 = this.hash(data, 'sha256');
1830
+ this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1786
1831
  data.sha512 = this.hash(data, 'sha512');
1787
1832
 
1788
- this.state('return', `contexts:${id.uid}`);
1833
+ this.state('return', `${data.key}:${id.uid}`);
1789
1834
  return data;
1790
1835
  }
1791
1836
 
@@ -2084,17 +2129,23 @@ class Deva {
2084
2129
  describe: Unload a currently loaded Deva.
2085
2130
  ***************/
2086
2131
  unload(key) {
2087
- this.zone('unload', key);
2088
2132
  return new Promise((resolve, reject) => {
2133
+ if (!this._active) return resolve(this._messages.offline); // check the active status
2134
+ this.zone('unload', key);
2135
+ this.action('unload', key);
2136
+ this.state('unload', key);
2137
+
2138
+ this.state('try', `unload:${key}`);
2089
2139
  try {
2090
- this.action('unload', key);
2091
2140
  this.devas[key].stop().then(exit => {
2092
2141
  delete this.devas[key];
2142
+ this.action('talk', `${this._events.unload}:${key}`);
2093
2143
  this.talk(this._events.unload, key);
2094
2144
  });
2095
- this.state('unload', key);
2096
- return resolve(`${this._states.unload}:${key}`);
2145
+ this.action('resolve', `unload:${key}`);
2146
+ return resolve(exit);
2097
2147
  } catch (e) {
2148
+ this.state('catch', `unload:${key}`);
2098
2149
  return this.err(e, this.devas[key], reject)
2099
2150
  }
2100
2151
  });
@@ -2130,7 +2181,7 @@ class Deva {
2130
2181
  }
2131
2182
 
2132
2183
  this.action('hash', `${key}:${value}:md5:${data.id.uid}`);
2133
- data.md5 = this.hash(data); // md5 the data packet
2184
+ data.md5 = this.hash(data, 'md5'); // md5 the data packet
2134
2185
 
2135
2186
  this.action('hash', `${key}:${value}:sha256:${data.id.uid}`);
2136
2187
  data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
@@ -2204,7 +2255,7 @@ class Deva {
2204
2255
  data.id = id;
2205
2256
  data.created = Date.now();
2206
2257
 
2207
- data.md5 = this.hash(data);
2258
+ data.md5 = this.hash(data, 'md5');
2208
2259
  data.sha256 = this.hash(data, 'sha256');
2209
2260
  data.sha512 = this.hash(data, 'sha512');
2210
2261
 
@@ -2248,30 +2299,31 @@ class Deva {
2248
2299
  ***************/
2249
2300
  help(msg, help_dir) {
2250
2301
  return new Promise((resolve, reject) => {
2302
+ if (!this._active) return resolve(this._messages.offline);
2251
2303
  let helpDoc = false;
2252
2304
  const id = this.uid();
2253
- this.zone('help', id);
2254
- if (!this._active) return resolve(this._messages.offline);
2305
+ const key = 'help';
2306
+ this.zone(key, id);
2255
2307
 
2256
- this.feature('help', id.uid);
2257
- this.action('help', id.uid);
2258
- this.state('help', id.uid);
2259
- this.context('help', id.uid);
2308
+ this.feature(key, id.uid);
2309
+ this.action(key, id.uid);
2310
+ this.state(key, id.uid);
2311
+ this.context(key, id.uid);
2260
2312
  const params = msg.split(' '); // split the msg into an array by spaces.
2261
2313
 
2262
2314
  const splitText = params[0].split(':');
2263
2315
  const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
2264
2316
  const helpFile = splitText[0] ? splitText[0] : 'main';
2265
2317
 
2266
- const helpPath = this.lib.path.join(help_dir, 'help', `${helpFile}.feecting`);
2318
+ const helpPath = this.lib.path.join(help_dir, key, `${helpFile}.feecting`);
2267
2319
 
2268
2320
  try {
2269
- this.state('try', `help:${id.uid}`);
2321
+ this.state('try', `${key}:${id.uid}`);
2270
2322
 
2271
2323
  // check if help file exists first and resolve if no file
2272
2324
  const helpExists = this.lib.fs.existsSync(helpPath); // check if help file exists
2273
2325
  if (!helpExists) {
2274
- this.state('return', `${this._messages.help_not_found}:${id.uid}`);
2326
+ this.action('resolve', `${key}:not:found:${id.uid}`);
2275
2327
  return resolve(this._messages.help_not_found);
2276
2328
  }
2277
2329
 
@@ -2279,7 +2331,7 @@ class Deva {
2279
2331
  const helpFile = this.lib.fs.readFileSync(helpPath, 'utf8');
2280
2332
  const helpPart = helpFile.split(`::BEGIN:${part}`);
2281
2333
  if (!helpPart[1]) {
2282
- this.state('return', `${this._messages.help_not_found}:${id.uid}`);
2334
+ this.action('resolve', `${this._messages.help_not_found}:${id.uid}`);
2283
2335
  resolve(this._messages.help_not_found);
2284
2336
  }
2285
2337
 
@@ -2287,11 +2339,11 @@ class Deva {
2287
2339
  helpDoc = helpFile.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
2288
2340
  }
2289
2341
  catch(e) {
2290
- this.state('catch', `help:${id.uid}`);
2342
+ this.state('catch', `${key}:${id.uid}`);
2291
2343
  return this.err(e, msg, reject);
2292
2344
  }
2293
2345
  finally {
2294
- this.state('return', `help:${id.uid}`);
2346
+ this.action('resolve', `help:${id.uid}`);
2295
2347
  return resolve(helpDoc);
2296
2348
  }
2297
2349
  });
@@ -2309,18 +2361,20 @@ class Deva {
2309
2361
  ***************/
2310
2362
  err(err,packet,reject=false) {
2311
2363
  const id = this.uid();
2312
- this.zone('error', id.uid);
2313
- this.feature('error', id.uid);
2364
+ const key = 'error';
2365
+ this.context(key, id.uid);
2366
+ this.feature(key, id.uid);
2367
+ this.zone(key, id.uid);
2368
+ this.action(key, id.uid);
2369
+ this.state(key, id.uid);
2314
2370
 
2315
2371
  const agent = this.agent();
2316
2372
  const client = this.client();
2317
-
2318
- this.action('error', id.uid);
2319
- const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2320
-
2373
+
2374
+ this.state('data', `${key}:${id.uid}`);
2321
2375
  const data = {
2322
2376
  id,
2323
- key: 'error',
2377
+ key,
2324
2378
  value: agent.key,
2325
2379
  agent,
2326
2380
  client,
@@ -2332,17 +2386,33 @@ class Deva {
2332
2386
  packet,
2333
2387
  created: Date.now(),
2334
2388
  }
2335
- data.md5 = this.hash(data);
2336
- data.sha256 = this.hash(data, 'sha256');
2337
- data.sha512 = this.hash(data, 'sha512');
2389
+
2390
+ this.action('hash', `${data.key}:${data.value}:md5:${data.id.uid}`);
2391
+ data.md5 = this.hash(data, 'md5'); // md5 the data packet
2392
+
2393
+ this.action('hash', `${data.key}:${data.value}:sha256:${data.id.uid}`);
2394
+ data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
2395
+
2396
+
2397
+ this.action('hash', `${data.key}:${data.value}:sha512:${data.id.uid}`);
2398
+ data.sha512 = this.hash(data, 'sha512'); // sha512 the data packet
2338
2399
 
2400
+ // set the action to talk and emit the talk error.
2401
+ this.action('talk', `${this._events.error}:${data.id.uid}`);
2339
2402
  this.talk(this._events.error, this.lib.copy(data));
2340
2403
 
2341
- this.state('return', `error:${id.uid}`);
2342
- this.state('error', id.uid);
2343
- this.context('error', id.uid);
2344
- if (hasOnError) return this.onError(err, packet, reject);
2345
- else return reject ? reject(err) : Promise.reject(err);
2404
+ const hasOnError = this.onError && typeof this.onError === 'function' ? true : false;
2405
+ // if block handles returning the onError and setting the state to hasOnError
2406
+ if (hasOnError) {
2407
+ this.action('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
2408
+ this.state('onfunc', `hasOnError:${data.value}:${data.id.uid}`);
2409
+ return this.onError(err, packet, reject);
2410
+ }
2411
+ // else block handled the reject if there is no onError function.
2412
+ else {
2413
+ this.action('reject', `${data.value}:${id.uid}`);
2414
+ return reject ? reject(err) : Promise.reject(err);
2415
+ }
2346
2416
  }
2347
2417
 
2348
2418
  /**************
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "44091450722329207445",
3
3
  "name": "@indra.ai/deva",
4
- "version": "1.6.95",
4
+ "version": "1.6.97",
5
5
  "description": "Deva Core a Vedic-inspired Event Based Context Aware Feature, Zone, Action, and State Machine integrated Artificial Intelligence Framework",
6
6
  "main": "index.js",
7
7
  "license": "VLA:44091450722329207445 LICENSE.md",
package/tests/index.js CHANGED
@@ -168,9 +168,18 @@ const DevaTest = new Deva({
168
168
  return test;
169
169
  },
170
170
  },
171
+ onInit(data, resolve) {
172
+ return this.start(data, resolve);
173
+ },
174
+ onStart(data, resolve) {
175
+ return this.enter(data, resolve);
176
+ },
177
+ onEnter(data, resolve) {
178
+ return this.ready(data, resolve);
179
+ },
171
180
  onReady(data, resolve) {
172
181
  const test = this.methods.test(data);
173
- this.prompt(test.text);
182
+ this.prompt(this._messages.ready);
174
183
  return resolve(data);
175
184
  },
176
185
  onComplete(data, resolve) {