@indra.ai/deva 1.6.95 → 1.6.96

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 +86 -62
  2. package/package.json +1 -1
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');
@@ -1093,7 +1093,7 @@ class Deva {
1093
1093
  data.value = 'start';
1094
1094
 
1095
1095
  this.action('hash', `start:md5:${data.id.uid}`);
1096
- data.md5 = this.hash(data);
1096
+ data.md5 = this.hash(data, 'md5');
1097
1097
  this.action('hash', `start:sha256:${data.id.uid}`)
1098
1098
  data.sha256 = this.hash(data, 'sha256');
1099
1099
  this.action('hash', `start:sha512:${data.id.uid}`)
@@ -1139,7 +1139,7 @@ class Deva {
1139
1139
  data.value = 'enter';
1140
1140
 
1141
1141
  this.action('hash', `enter:md5:${data.id.uid}`);
1142
- data.md5 = this.hash(data);
1142
+ data.md5 = this.hash(data, 'md5');
1143
1143
  this.action('hash', `enter:sha256:${data.id.uid}`)
1144
1144
  data.sha256 = this.hash(data, 'sha256');
1145
1145
  this.action('hash', `enter:sha512:${data.id.uid}`)
@@ -1184,7 +1184,7 @@ class Deva {
1184
1184
  data.value = 'done';
1185
1185
 
1186
1186
  this.action('hash', `done:md5:${data.id.uid}`);
1187
- data.md5 = this.hash(data);
1187
+ data.md5 = this.hash(data, 'md5');
1188
1188
  this.action('hash', `done:sha256:${data.id.uid}`)
1189
1189
  data.sha256 = this.hash(data, 'sha256');
1190
1190
  this.action('hash', `done:sha512:${data.id.uid}`)
@@ -1227,7 +1227,7 @@ class Deva {
1227
1227
  data.value = 'ready';
1228
1228
 
1229
1229
  this.action('hash', `ready:md5:${data.id.uid}`);
1230
- data.md5 = this.hash(data);
1230
+ data.md5 = this.hash(data, 'md5');
1231
1231
  this.action('hash', `ready:sha256:${data.id.uid}`)
1232
1232
  data.sha256 = this.hash(data, 'sha256');
1233
1233
  this.action('hash', `ready:sha512:${data.id.uid}`)
@@ -1269,7 +1269,7 @@ class Deva {
1269
1269
  this.state('set', `data:finish:${data.finish}:${data.id.uid}`)
1270
1270
 
1271
1271
  this.action('hash', `finish:md5:${data.id.uid}`);
1272
- data.md5 = this.hash(data);
1272
+ data.md5 = this.hash(data, 'md5');
1273
1273
  this.action('hash', `finish:sha256:${data.id.uid}`)
1274
1274
  data.sha256 = this.hash(data, 'sha256');
1275
1275
  this.action('hash', `finish:sha512:${data.id.uid}`)
@@ -1296,7 +1296,7 @@ class Deva {
1296
1296
  usage: this.complete(data, resolve)
1297
1297
  ***************/
1298
1298
  complete(data, resolve) {
1299
- if (!this._active) return Promise.resolve(this._messages.offline);
1299
+ if (!this._active) return resolve(this._messages.offline);
1300
1300
  this.context('complete', data.id.uid);
1301
1301
  this.zone('complete', data.id.uid);
1302
1302
  this.action('complete', data.id.uid);
@@ -1313,7 +1313,7 @@ class Deva {
1313
1313
  this.state('set', `data:complete:${data.complete}:${data.id.uid}`)
1314
1314
 
1315
1315
  this.action('hash', `complete:md5:${data.id.uid}`);
1316
- data.md5 = this.hash(data);
1316
+ data.md5 = this.hash(data, 'md5');
1317
1317
  this.action('hash', `complete:sha256:${data.id.uid}`)
1318
1318
  data.sha256 = this.hash(data, 'sha256');
1319
1319
 
@@ -1346,7 +1346,7 @@ class Deva {
1346
1346
  this.stop()
1347
1347
  ***************/
1348
1348
  stop() {
1349
- if (!this._active) return Promise.resolve(this._messages.offline);
1349
+ if (!this._active) return this._messages.offline;
1350
1350
  const id = this.uid();
1351
1351
  this.context('stop', id.uid);
1352
1352
  this.zone('stop', id.uid);
@@ -1370,7 +1370,7 @@ class Deva {
1370
1370
  }
1371
1371
 
1372
1372
  this.action('hash', `stop:md5:${data.id.uid}`);
1373
- data.md5 = this.hash(data);
1373
+ data.md5 = this.hash(data, 'md5');
1374
1374
  this.action('hash', `stop:sha256:${data.id.uid}`)
1375
1375
  data.sha256 = this.hash(data, 'sha256');
1376
1376
  this.action('hash', `stop:sha512:${data.id.uid}`)
@@ -1398,7 +1398,7 @@ class Deva {
1398
1398
  function.
1399
1399
  ***************/
1400
1400
  exit(data) {
1401
- if (!this._active) return Promise.resolve(this._messages.offline);
1401
+ if (!this._active) return this._messages.offline;
1402
1402
 
1403
1403
  this.context('exit', data.id.uid);
1404
1404
  this.zone('exit', data.id.uid);
@@ -1416,7 +1416,7 @@ class Deva {
1416
1416
  data.exit = Date.now();
1417
1417
 
1418
1418
  this.action('hash', `stop:md5:${data.id.uid}`);
1419
- data.md5 = this.hash(data);
1419
+ data.md5 = this.hash(data, 'md5');
1420
1420
  this.action('hash', `stop:sha256:${data.id.uid}`)
1421
1421
  data.sha256 = this.hash(data, 'sha256');
1422
1422
  this.action('hash', `stop:sha512:${data.id.uid}`)
@@ -1453,7 +1453,7 @@ class Deva {
1453
1453
  const hasOnExit = this.onExit && typeof this.onExit === 'function';
1454
1454
  if (hasOnExit) this.state('set', `hasOnExit:${data.id.uid}`); // state set to watch OnFinish
1455
1455
 
1456
- this.action('return', `exit:${data.uid}`);
1456
+ this.action('resolve', `exit:${data.uid}`);
1457
1457
  return hasOnExit ? this.onExit(data) : Promise.resolve(data)
1458
1458
  }
1459
1459
 
@@ -1464,29 +1464,32 @@ class Deva {
1464
1464
  func: state
1465
1465
  params:
1466
1466
  - 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.
1467
+ - extra: any extra text to add to the state change.
1468
1468
  ***************/
1469
1469
  state(value=false, extra=false) {
1470
+ if (!this._active) return this._messages.offline;
1471
+ const id = this.uid();
1472
+ const key = 'state';
1470
1473
  try {
1471
1474
  if (!value || !this._states[value]) return; // return if no matching value
1472
1475
  this._state = value; // set the local state variable.
1473
1476
  const lookup = this._states[value]; // set the local states lookup
1474
1477
  const text = extra ? `${lookup} ${extra}` : lookup; // set text from lookup with extra
1475
1478
  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
1479
+ id, // set the data id
1480
+ key, // set the key to state
1480
1481
  value, // set the value to the passed in value
1481
1482
  text, // set the text value of the data
1483
+ agent: this.agent(), // set the agent
1484
+ client: this.client(), // set the client
1482
1485
  created: Date.now(), // set the data created date.
1483
1486
  };
1484
1487
 
1485
- data.md5 = this.hash(data);
1488
+ data.md5 = this.hash(data, 'md5');
1486
1489
  data.sha256 = this.hash(data, 'sha256');
1487
1490
  data.sha512 = this.hash(data, 'sha512');
1488
1491
 
1489
- this.talk(this._events.state, data); // broadcasat the state event
1492
+ this.talk(this._events.state, data); // broadcast the state event
1490
1493
  return data;
1491
1494
  } catch (e) { // catch any errors
1492
1495
  return this.err(e); // return if an error happens
@@ -1499,7 +1502,7 @@ class Deva {
1499
1502
  describe: returns the available states values.
1500
1503
  ***************/
1501
1504
  states() {
1502
- if (!this._active) return Promise.resolve(this._messages.offline);
1505
+ if (!this._active) return this._messages.offline;
1503
1506
  const id = this.uid();
1504
1507
  const key = 'states';
1505
1508
  this.action(key, id.uid);
@@ -1516,7 +1519,7 @@ class Deva {
1516
1519
  }
1517
1520
 
1518
1521
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1519
- data.md5 = this.hash(data);
1522
+ data.md5 = this.hash(data, 'md5');
1520
1523
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1521
1524
  data.sha256 = this.hash(data, 'sha256');
1522
1525
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
@@ -1533,7 +1536,9 @@ class Deva {
1533
1536
  describe
1534
1537
  ***************/
1535
1538
  zone(value=false, extra=false) {
1539
+ if (!this._active) return this._messages.offline;
1536
1540
  const id = this.uid();
1541
+ const key = 'zone';
1537
1542
  if (!value || !this._zones[value]) return;
1538
1543
 
1539
1544
  try {
@@ -1543,15 +1548,15 @@ class Deva {
1543
1548
 
1544
1549
  const data = { // build the zone data
1545
1550
  id, // set the packetid
1546
- agent: this.agent(),
1547
- client: this.client(),
1548
- key: 'zone',
1551
+ key,
1549
1552
  value,
1550
1553
  text,
1554
+ agent: this.agent(),
1555
+ client: this.client(),
1551
1556
  created: Date.now(),
1552
1557
  };
1553
1558
 
1554
- data.md5 = this.hash(data);
1559
+ data.md5 = this.hash(data, 'md5');
1555
1560
  data.sha256 = this.hash(data, 'sha256');
1556
1561
  data.sha512 = this.hash(data, 'sha512');
1557
1562
 
@@ -1568,7 +1573,7 @@ class Deva {
1568
1573
  describe: returns a listing of zones currently in the system.
1569
1574
  ***************/
1570
1575
  zones() {
1571
- if (!this._active) return Promise.resolve(this._messages.offline);
1576
+ if (!this._active) return this._messages.offline;
1572
1577
  const id = this.uid();
1573
1578
  const key = 'zones';
1574
1579
  this.action(key, id.uid);
@@ -1584,7 +1589,7 @@ class Deva {
1584
1589
  }
1585
1590
 
1586
1591
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1587
- data.md5 = this.hash(data);
1592
+ data.md5 = this.hash(data, 'md5');
1588
1593
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1589
1594
  data.sha256 = this.hash(data, 'sha256');
1590
1595
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
@@ -1602,7 +1607,9 @@ class Deva {
1602
1607
  describe
1603
1608
  ***************/
1604
1609
  action(value=false, extra=false) {
1610
+ if (!this._active) return this._messages.offline;
1605
1611
  const id = this.uid();
1612
+ const key = 'action'
1606
1613
  try {
1607
1614
  if (!value || !this._actions[value]) return;
1608
1615
  this._action = value; // set the local action variable
@@ -1615,22 +1622,22 @@ class Deva {
1615
1622
 
1616
1623
  const data = { // build the data object for the action.
1617
1624
  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
1625
+ key, // the key for event to transmit action type
1621
1626
  value, // the value key which is the action passed
1622
1627
  text, // text of the action to send
1628
+ agent: this.agent(), // the agent data to send with the action
1629
+ client: this.client(), // the client data to send with the action
1623
1630
  created: Date.now(), // action time stamp
1624
1631
  };
1625
1632
 
1626
- data.md5 = this.hash(data);
1633
+ data.md5 = this.hash(data, 'md5');
1627
1634
  data.sha256 = this.hash(data, 'sha256');
1628
1635
  data.sha512 = this.hash(data, 'sha512');
1629
1636
 
1630
1637
  this.talk(this._events.action, data); // talk the core action event
1631
1638
  return data;
1632
1639
  } catch (e) { // catch any errors that occur
1633
- this.state('catch', `action:${value}:${id.uid}`);
1640
+ this.state('catch', `${key}:${id.uid}`);
1634
1641
  return this.err(e); // return error on error catch
1635
1642
  }
1636
1643
  }
@@ -1641,7 +1648,7 @@ class Deva {
1641
1648
  describe: Returns a list of available actions in the system.
1642
1649
  ***************/
1643
1650
  actions() {
1644
- if (!this._active) return Promise.resolve(this._messages.offline);
1651
+ if (!this._active) return this._messages.offline;
1645
1652
  const id = this.uid();
1646
1653
  const key = 'actions';
1647
1654
  this.action(key, id.uid);
@@ -1657,13 +1664,13 @@ class Deva {
1657
1664
  };
1658
1665
 
1659
1666
  this.action('hash', `${data.key}:md5:${data.id.uid}`);
1660
- data.md5 = this.hash(data);
1667
+ data.md5 = this.hash(data, 'md5');
1661
1668
  this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1662
1669
  data.sha256 = this.hash(data, 'sha256');
1663
1670
  this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1664
1671
  data.sha512 = this.hash(data, 'sha512');
1665
1672
 
1666
- this.state('return', `actions:${id.uid}`);
1673
+ this.state('return', `${key}:${id.uid}`);
1667
1674
  return data;
1668
1675
  }
1669
1676
 
@@ -1691,7 +1698,7 @@ class Deva {
1691
1698
  created: Date.now(), // set the creation date
1692
1699
  };
1693
1700
 
1694
- data.md5 = this.hash(data);
1701
+ data.md5 = this.hash(data, 'md5');
1695
1702
  data.sha256 = this.hash(data, 'sha256');
1696
1703
  data.sha512 = this.hash(data, 'sha512');
1697
1704
 
@@ -1711,21 +1718,27 @@ class Deva {
1711
1718
  features() {
1712
1719
  if (!this._active) return this._messages.offline; // check the active status
1713
1720
  const id = this.uid();
1714
- this.action('features', id.uid);
1721
+ const key = 'features';
1722
+ this.action(key, id.uid);
1723
+
1724
+ this.state('data', `${key}:${id.uid}`);
1715
1725
  const data = {
1716
1726
  id, // set the object id
1727
+ key, // set the key
1728
+ value: this._features, // set the value to the features list
1717
1729
  agent: this.agent(), // set the agent value.
1718
1730
  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
1731
  created: Date.now(), // set the created date.
1722
1732
  };
1723
1733
 
1724
- data.md5 = this.hash(data);
1725
- data.sha256 = this.hash(data, 'sha256');
1734
+ this.action('hash', `${data.key}:md5:${data.id.uid}`);
1735
+ data.md5 = this.hash(data, 'md5');
1736
+ this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1737
+ data.sha256 = this.hash(data, 'sha256');
1738
+ this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1726
1739
  data.sha512 = this.hash(data, 'sha512');
1727
-
1728
- this.state('return', `features:${id.uid}`);
1740
+
1741
+ this.state('return', `${data.key}:${data.id.uid}`);
1729
1742
  return data;
1730
1743
  }
1731
1744
 
@@ -1755,7 +1768,7 @@ class Deva {
1755
1768
  created: Date.now(),
1756
1769
  };
1757
1770
 
1758
- data.md5 = this.hash(data);
1771
+ data.md5 = this.hash(data, 'md5');
1759
1772
  data.sha256 = this.hash(data, 'sha256');
1760
1773
  data.sha512 = this.hash(data, 'sha512');
1761
1774
 
@@ -1770,22 +1783,27 @@ class Deva {
1770
1783
  contexts() {
1771
1784
  if (!this._active) return this._messages.offline; // check the active status
1772
1785
  const id = this.uid();
1773
- this.action('contexts', id);
1774
- if (!this._active) return this._messages.offline; // check the active status
1786
+ const key = 'contexts';
1787
+ this.action(key, id.uid);
1788
+
1789
+ this.state('data', `${key}:${id.uid}`);
1775
1790
  const data = {
1776
1791
  id,
1792
+ key,
1793
+ value: this.vars.context || false,
1777
1794
  agent: this.agent(),
1778
1795
  client: this.client(),
1779
- key: 'contexts',
1780
- value: this.vars.context || false,
1781
1796
  created: Date.now(),
1782
1797
  };
1783
1798
 
1784
- data.md5 = this.hash(data);
1785
- data.sha256 = this.hash(data, 'sha256');
1799
+ this.action('hash', `${data.key}:md5:${data.id.uid}`);
1800
+ data.md5 = this.hash(data, 'md5');
1801
+ this.action('hash', `${data.key}:sha256:${data.id.uid}`);
1802
+ data.sha256 = this.hash(data, 'sha256');
1803
+ this.action('hash', `${data.key}:sha512:${data.id.uid}`);
1786
1804
  data.sha512 = this.hash(data, 'sha512');
1787
1805
 
1788
- this.state('return', `contexts:${id.uid}`);
1806
+ this.state('return', `${data.key}:${id.uid}`);
1789
1807
  return data;
1790
1808
  }
1791
1809
 
@@ -2084,17 +2102,23 @@ class Deva {
2084
2102
  describe: Unload a currently loaded Deva.
2085
2103
  ***************/
2086
2104
  unload(key) {
2087
- this.zone('unload', key);
2088
2105
  return new Promise((resolve, reject) => {
2106
+ if (!this._active) return resolve(this._messages.offline); // check the active status
2107
+ this.zone('unload', key);
2108
+ this.action('unload', key);
2109
+ this.state('unload', key);
2110
+
2111
+ this.state('try', `unload:${key}`);
2089
2112
  try {
2090
- this.action('unload', key);
2091
2113
  this.devas[key].stop().then(exit => {
2092
2114
  delete this.devas[key];
2115
+ this.action('talk', `${this._events.unload}:${key}`);
2093
2116
  this.talk(this._events.unload, key);
2094
2117
  });
2095
- this.state('unload', key);
2096
- return resolve(`${this._states.unload}:${key}`);
2118
+ this.action('resolve', `unload:${key}`);
2119
+ return resolve(exit);
2097
2120
  } catch (e) {
2121
+ this.state('catch', `unload:${key}`);
2098
2122
  return this.err(e, this.devas[key], reject)
2099
2123
  }
2100
2124
  });
@@ -2130,7 +2154,7 @@ class Deva {
2130
2154
  }
2131
2155
 
2132
2156
  this.action('hash', `${key}:${value}:md5:${data.id.uid}`);
2133
- data.md5 = this.hash(data); // md5 the data packet
2157
+ data.md5 = this.hash(data, 'md5'); // md5 the data packet
2134
2158
 
2135
2159
  this.action('hash', `${key}:${value}:sha256:${data.id.uid}`);
2136
2160
  data.sha256 = this.hash(data, 'sha256'); // sha256 the data packet
@@ -2204,7 +2228,7 @@ class Deva {
2204
2228
  data.id = id;
2205
2229
  data.created = Date.now();
2206
2230
 
2207
- data.md5 = this.hash(data);
2231
+ data.md5 = this.hash(data, 'md5');
2208
2232
  data.sha256 = this.hash(data, 'sha256');
2209
2233
  data.sha512 = this.hash(data, 'sha512');
2210
2234
 
@@ -2248,10 +2272,10 @@ class Deva {
2248
2272
  ***************/
2249
2273
  help(msg, help_dir) {
2250
2274
  return new Promise((resolve, reject) => {
2275
+ if (!this._active) return resolve(this._messages.offline);
2251
2276
  let helpDoc = false;
2252
2277
  const id = this.uid();
2253
2278
  this.zone('help', id);
2254
- if (!this._active) return resolve(this._messages.offline);
2255
2279
 
2256
2280
  this.feature('help', id.uid);
2257
2281
  this.action('help', id.uid);
@@ -2332,7 +2356,7 @@ class Deva {
2332
2356
  packet,
2333
2357
  created: Date.now(),
2334
2358
  }
2335
- data.md5 = this.hash(data);
2359
+ data.md5 = this.hash(data, 'md5');
2336
2360
  data.sha256 = this.hash(data, 'sha256');
2337
2361
  data.sha512 = this.hash(data, 'sha512');
2338
2362
 
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.96",
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",