statebus 7.0.11 → 7.0.13
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 +19 -19
- package/package.json +1 -1
- package/server-library.js +7 -5
- package/statebus.js +1 -1
package/extras/tests.js
CHANGED
|
@@ -1122,22 +1122,22 @@ function setup_servers () {
|
|
|
1122
1122
|
c.ws_mount('/*', 'statei://localhost:' + port)
|
|
1123
1123
|
|
|
1124
1124
|
s.set({key: 'users',
|
|
1125
|
-
val: [ {link: '
|
|
1126
|
-
{link: '
|
|
1127
|
-
{link: '
|
|
1128
|
-
s.set({ key: '
|
|
1125
|
+
val: [ {link: '@1'},
|
|
1126
|
+
{link: '@2'},
|
|
1127
|
+
{link: '@3'} ] })
|
|
1128
|
+
s.set({ key: '@1', val: {
|
|
1129
1129
|
name: 'mike',
|
|
1130
1130
|
email: 'toomim@gmail.com',
|
|
1131
1131
|
admin: true,
|
|
1132
1132
|
pass: '$2a$10$Ti7BgAZS8sB0Z62o2NKsIuCdmU3q9xP7jexVccTcG19Y8qpBpl/1y'
|
|
1133
1133
|
}})
|
|
1134
|
-
s.set({ key: '
|
|
1134
|
+
s.set({ key: '@2', val: {
|
|
1135
1135
|
name: 'j',
|
|
1136
1136
|
email: 'jtoomim@gmail.com',
|
|
1137
1137
|
admin: true,
|
|
1138
1138
|
pass: '$2a$10$Ti7BgAZS8sB0Z62o2NKsIuCdmU3q9xP7jexVccTcG19Y8qpBpl/1y'
|
|
1139
1139
|
}})
|
|
1140
|
-
s.set({ key: '
|
|
1140
|
+
s.set({ key: '@3', val: {
|
|
1141
1141
|
name: 'boo',
|
|
1142
1142
|
email: 'boo@gmail.com',
|
|
1143
1143
|
admin: false,
|
|
@@ -1260,7 +1260,7 @@ test(function create_account (done) {
|
|
|
1260
1260
|
// Log out
|
|
1261
1261
|
delay(600, () => {
|
|
1262
1262
|
assert(cu.val.logged_in)
|
|
1263
|
-
assert(cu.val.user.link === '
|
|
1263
|
+
assert(cu.val.user.link === '/@bob')
|
|
1264
1264
|
|
|
1265
1265
|
log('Now let\'s log out!')
|
|
1266
1266
|
cu.val.logout = true; c.set(cu)
|
|
@@ -1276,7 +1276,7 @@ test(function create_account (done) {
|
|
|
1276
1276
|
|
|
1277
1277
|
delay(600, () => {
|
|
1278
1278
|
assert(cu.val.logged_in)
|
|
1279
|
-
assert(cu.val.user.link === '
|
|
1279
|
+
assert(cu.val.user.link === '/@bob')
|
|
1280
1280
|
done()
|
|
1281
1281
|
})
|
|
1282
1282
|
})
|
|
@@ -1521,7 +1521,7 @@ if (false) {
|
|
|
1521
1521
|
// Logged in as mike
|
|
1522
1522
|
[(u.logged_in
|
|
1523
1523
|
&& u.user.name === 'mike'
|
|
1524
|
-
&& u.user.key === '
|
|
1524
|
+
&& u.user.key === '/@1'
|
|
1525
1525
|
|
|
1526
1526
|
// We can see our email
|
|
1527
1527
|
&& u.user.email
|
|
@@ -1547,7 +1547,7 @@ if (false) {
|
|
|
1547
1547
|
// Logged in as j
|
|
1548
1548
|
[(u.logged_in
|
|
1549
1549
|
&& u.user.name === 'j'
|
|
1550
|
-
&& u.user.key === '
|
|
1550
|
+
&& u.user.key === '/@2'
|
|
1551
1551
|
|
|
1552
1552
|
// We can see j's email
|
|
1553
1553
|
&& u.user.email
|
|
@@ -1564,10 +1564,10 @@ if (false) {
|
|
|
1564
1564
|
c('/current_user').on_set = function (o) {
|
|
1565
1565
|
//if (o.user && o.user.name === 'j') {
|
|
1566
1566
|
// log(s.userbus.deps('/current_user'))
|
|
1567
|
-
// log(s.userbus.deps('
|
|
1567
|
+
// log(s.userbus.deps('/@2'))
|
|
1568
1568
|
//}
|
|
1569
1569
|
}
|
|
1570
|
-
c('
|
|
1570
|
+
c('/@*').on_set = function (o) {
|
|
1571
1571
|
//log('-> Got new', o.key, o.email ? 'with email' : '')
|
|
1572
1572
|
}
|
|
1573
1573
|
c('/current_user').on_set = function (o) {
|
|
@@ -1575,9 +1575,9 @@ if (false) {
|
|
|
1575
1575
|
}
|
|
1576
1576
|
c(function loop () {
|
|
1577
1577
|
u = c.get('/current_user')
|
|
1578
|
-
user1 = c.get('
|
|
1579
|
-
user2 = c.get('
|
|
1580
|
-
user3 = c.get('
|
|
1578
|
+
user1 = c.get('/@1')
|
|
1579
|
+
user2 = c.get('/@2')
|
|
1580
|
+
user3 = c.get('/@3')
|
|
1581
1581
|
var st = states()
|
|
1582
1582
|
|
|
1583
1583
|
if (phase===1)
|
|
@@ -1613,12 +1613,12 @@ if (false) {
|
|
|
1613
1613
|
var cu = c.get('/current_user')
|
|
1614
1614
|
c.set({key: '/current_user', val: {create_account: {name: 'a', pass: 'a'}}})
|
|
1615
1615
|
c.set({key: '/current_user', val: {login_as: {name: 'a', pass: 'a'}}})
|
|
1616
|
-
var a_closet = c.get('
|
|
1617
|
-
var a_private = c.get('
|
|
1616
|
+
var a_closet = c.get('/@a/foo')
|
|
1617
|
+
var a_private = c.get('/@a/private/foo')
|
|
1618
1618
|
|
|
1619
1619
|
delay(400, () => {
|
|
1620
|
-
c.set({key: '
|
|
1621
|
-
c.set({key: '
|
|
1620
|
+
c.set({key: '/@a/foo', _: 3})
|
|
1621
|
+
c.set({key: '/@a/private/foo', _: 4})
|
|
1622
1622
|
})
|
|
1623
1623
|
|
|
1624
1624
|
// User A can see it
|
package/package.json
CHANGED
package/server-library.js
CHANGED
|
@@ -2054,7 +2054,9 @@ function import_server (bus, make_statebus, options)
|
|
|
2054
2054
|
o.val.pass = o.val.pass && require('bcrypt-nodejs').hashSync(o.val.pass)
|
|
2055
2055
|
u.val.pass = o.val.pass || u.val.pass
|
|
2056
2056
|
|
|
2057
|
-
// //
|
|
2057
|
+
// // Allow clients to save a base64 image in the .pic field,
|
|
2058
|
+
// // which we'll convert into an image file here. (Note: removed.
|
|
2059
|
+
// // There are more elegant solutions possible now.)
|
|
2058
2060
|
// // Bug: if user changes name, this picture's url doesn't change.
|
|
2059
2061
|
// if (o.pic && o.pic.indexOf('data:image') > -1) {
|
|
2060
2062
|
// var img_type = o.pic.match(/^data:image\/(\w+);base64,/)[1]
|
|
@@ -2063,19 +2065,19 @@ function import_server (bus, make_statebus, options)
|
|
|
2063
2065
|
// // ensure that the uploads directory exists
|
|
2064
2066
|
// if (!fs.existsSync(upload_dir))
|
|
2065
2067
|
// fs.mkdirSync(upload_dir)
|
|
2066
|
-
|
|
2068
|
+
//
|
|
2067
2069
|
// // bug: users with the same name can overwrite each other's files
|
|
2068
2070
|
// u.pic = u.name + '.' + img_type
|
|
2069
2071
|
// fs.writeFile(upload_dir + u.pic, b64, {encoding: 'base64'})
|
|
2070
2072
|
// }
|
|
2071
2073
|
|
|
2072
2074
|
// For anything else, go ahead and add it to the user object
|
|
2073
|
-
var
|
|
2075
|
+
var reserved = {'key':true, 'name':true, 'pass':true}
|
|
2074
2076
|
for (var k in o.val)
|
|
2075
|
-
if (!
|
|
2077
|
+
if (!reserved.hasOwnProperty(k))
|
|
2076
2078
|
u.val[k] = o.val[k]
|
|
2077
2079
|
for (var k in u.val)
|
|
2078
|
-
if (!
|
|
2080
|
+
if (!reserved.hasOwnProperty(k) && !o.val.hasOwnProperty(k))
|
|
2079
2081
|
delete u.val[k]
|
|
2080
2082
|
|
|
2081
2083
|
master.set(u)
|
package/statebus.js
CHANGED
|
@@ -1673,7 +1673,7 @@
|
|
|
1673
1673
|
}
|
|
1674
1674
|
|
|
1675
1675
|
// Recurse through each property on objects
|
|
1676
|
-
else if (typeof input === 'object') {
|
|
1676
|
+
else if (typeof input === 'object' && input !== null) {
|
|
1677
1677
|
var new_obj = {}
|
|
1678
1678
|
for (var k in input)
|
|
1679
1679
|
new_obj[f(k, input)] = translate_fields(input[k], f)
|