statebus 7.2.2 → 7.2.4

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/extras/tests.js CHANGED
@@ -1129,17 +1129,14 @@ test(function proxies (done) {
1129
1129
 
1130
1130
  state.foo = 3
1131
1131
  // This should set into _
1132
- console.assert(bus.validate(bus.cache.foo,
1133
- {key: 'foo', _: 3}))
1132
+ assert(bus.validate(bus.cache.foo, {key: 'foo', _: 3}))
1134
1133
 
1135
1134
 
1136
1135
  state.foo = {a: 5}
1137
1136
  // This should set directly on it
1138
- console.assert(bus.validate(bus.cache.foo,
1139
- {key: 'foo', a: 5}))
1137
+ assert(bus.validate(bus.cache.foo, {key: 'foo', a: 5}))
1140
1138
  state.foo.b = 6
1141
- console.assert(bus.validate(bus.cache.foo,
1142
- {key: 'foo', b: 6}))
1139
+ assert(bus.validate(bus.cache.foo, {key: 'foo', b: 6}))
1143
1140
 
1144
1141
  state.bar = [3]
1145
1142
  state.foo = {a: 3, bar: state.bar}
@@ -1158,6 +1155,23 @@ test(function proxies (done) {
1158
1155
  // Getting a normal property should do a get
1159
1156
  })
1160
1157
 
1158
+ test(function proxy_link_escaping (done) {
1159
+ var bus = require('../statebus')()
1160
+ var state = bus.state
1161
+
1162
+ // See that links get escaped
1163
+ state.foo = {link: "bar"}
1164
+ assert(bus.validate(bus.cache.foo,
1165
+ {key: "foo", val: {_link: "bar"}}))
1166
+
1167
+ // And unescaped
1168
+ // log("state.foo", state.foo)
1169
+ // log("state.foo", JSON.stringify(state.foo))
1170
+ assert(bus.validate(state.foo, {link: "bar"}))
1171
+
1172
+ done()
1173
+ })
1174
+
1161
1175
  test(function path_parts (done) {
1162
1176
  bus.honk = 3
1163
1177
  bus('path/:part1/:part2/stuff/:part3/more*').getter = function (key, path, t) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "7.2.2",
3
+ "version": "7.2.4",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/statebus.js CHANGED
@@ -1456,6 +1456,9 @@
1456
1456
  link: Symbol('link')
1457
1457
  }
1458
1458
 
1459
+ if (nodejs)
1460
+ var util = require('util')
1461
+
1459
1462
  // The top-level Proxy object holds HTTP resources
1460
1463
  var top_level_proxy = new Proxy(cache, {
1461
1464
  get: function get(o, k) {
@@ -1484,6 +1487,7 @@
1484
1487
  return true // Report success to Proxy
1485
1488
  }
1486
1489
  })
1490
+ bus.state = top_level_proxy
1487
1491
 
1488
1492
  // The proxy within; a recursive tree holds each piece of JSON in a resource
1489
1493
  function json_proxy (base, path, o) {
@@ -1530,6 +1534,8 @@
1530
1534
 
1531
1535
  var proxy = new Proxy(target, {
1532
1536
  get: function (o, k) {
1537
+ // console.log('proxy get:', o, k)
1538
+
1533
1539
  if (k === 'inspect' || k === 'valueOf')
1534
1540
  return undefined
1535
1541
  if (k === symbols.is_proxy)
@@ -1561,15 +1567,17 @@
1561
1567
  )
1562
1568
  return true
1563
1569
  },
1564
- // has: function (o, k) {
1565
- // return o.hasOwnProperty(escape_field_json_to_bus(k))
1566
- // },
1567
- // ownKeys: function () {
1568
- // return Object.keys(target).map(unescape_field_bus_to_json)
1569
- // },
1570
- // getOwnPropertyDescriptor: function (target, key) {
1571
- // return { enumerable: true, configurable: true, value: this.get(target, key) }
1572
- // },
1570
+ has: function (o, k) {
1571
+ return o.hasOwnProperty(escape_field_json_to_bus(k))
1572
+ },
1573
+ ownKeys: function () {
1574
+ return Object.keys(target).map(unescape_field_bus_to_json)
1575
+ },
1576
+ getOwnPropertyDescriptor: function (target, key) {
1577
+ return { enumerable: true, configurable: true,
1578
+ value: this.get(target, escape_field_json_to_bus(key))
1579
+ }
1580
+ },
1573
1581
  deleteProperty: function del (target, k) {
1574
1582
  var new_path = path + '[' + JSON.stringify(k) + ']'
1575
1583
  var escaped_key = escape_field_json_to_bus(k)
@@ -1589,8 +1597,6 @@
1589
1597
  return proxy
1590
1598
  }
1591
1599
 
1592
- bus.state = top_level_proxy
1593
-
1594
1600
  // This doesn't work because custom inspectors only work when the
1595
1601
  // util.inspect.custom symbol is defined on the "target" of the
1596
1602
  // proxy... which right now is `cache` for the top_level_proxy. I could
@@ -1609,20 +1615,22 @@
1609
1615
  // }
1610
1616
  // }
1611
1617
 
1612
- // This is temporary code to wrap the cache as a flat key/valuel store
1613
- // that returns raw objects, dereferencing .val. We can remove it once we
1614
- // remove the internal .val stuff from statebus.
1615
- function raw_proxy () {
1616
- return new Proxy(cache, {
1617
- get: function get(o, k) { return bus.cache[k].val },
1618
- set: function set(o, key, val) {
1619
- return false
1620
- },
1621
- deleteProperty: function del (o, k) {
1622
- return false
1623
- }
1624
- })
1625
- }
1618
+ // This is disabled because it's not being used.
1619
+ //
1620
+ // // This is temporary code to wrap the cache as a flat key/valuel store
1621
+ // // that returns raw objects, dereferencing .val. We can remove it once we
1622
+ // // remove the internal .val stuff from statebus.
1623
+ // function raw_proxy () {
1624
+ // return new Proxy(cache, {
1625
+ // get: function get(o, k) { return bus.cache[k].val },
1626
+ // set: function set(o, key, val) {
1627
+ // return false
1628
+ // },
1629
+ // deleteProperty: function del (o, k) {
1630
+ // return false
1631
+ // }
1632
+ // })
1633
+ // }
1626
1634
 
1627
1635
 
1628
1636
  // Old link code: