fix depth put bug

This commit is contained in:
Mark Nadal 2017-12-31 15:45:08 -08:00
parent ca339ab80e
commit 3f70fa9782
7 changed files with 46 additions and 15 deletions

6
gun.js
View File

@ -1333,7 +1333,7 @@
for(i; i < l; i++){ for(i; i < l; i++){
ref = ref.get(path[i]); ref = ref.get(path[i]);
} }
if(as.not || Gun.node.soul(at.obj)){ if(Gun.node.soul(at.obj)){
var id = Gun.node.soul(at.obj) || (ref.back('opt.uuid') || Gun.text.random)(); var id = Gun.node.soul(at.obj) || (ref.back('opt.uuid') || Gun.text.random)();
if(!id){ // polyfill async uuid for SEA if(!id){ // polyfill async uuid for SEA
(as.stun = as.stun || {})[path] = true; // make DRY (as.stun = as.stun || {})[path] = true; // make DRY
@ -1363,7 +1363,7 @@
var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous? var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous?
if(!id){ // polyfill async uuid for SEA if(!id){ // polyfill async uuid for SEA
at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback
if(err){ return Gun.log(e) } // TODO: Handle error. if(err){ return Gun.log(err) } // TODO: Handle error.
solve(at, id, cat, as); solve(at, id, cat, as);
}); });
return; return;
@ -1418,7 +1418,7 @@
as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
} }
if(!as.soul){ // polyfill async uuid for SEA if(!as.soul){ // polyfill async uuid for SEA
ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
if(err){ return Gun.log(err) } // Handle error. if(err){ return Gun.log(err) } // Handle error.
as.ref.put(as.data, as.soul = soul, as); as.ref.put(as.data, as.soul = soul, as);
}); });

2
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "gun", "name": "gun",
"version": "0.9.5", "version": "0.9.6",
"description": "Graph engine", "description": "Graph engine",
"main": "index.js", "main": "index.js",
"browser": "gun.min.js", "browser": "gun.min.js",

22
sea.js
View File

@ -876,13 +876,13 @@
each.end({ok: 1}); each.end({ok: 1});
}); });
}; };
each.any = function(val, key, node, soul, user){ each.any = function(val, key, node, soul, user){ var tmp;
if(!user || !(user = user._) || !(user = user.sea)){ if(!user || !(user = user._) || !(user = user.sea)){
if(user = at.sea.own[soul]){ if(user = at.sea.own[soul]){
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
user = Gun.obj.map(user, function(a,b){ return b }); user = Gun.obj.map(user, function(a,b){ return b });
SEA.read(val, user, function(data){ var rel, tmp; SEA.read(val, user, function(data){ var rel;
if(!data){ return each.end({err: "Mismatched owner."}) } if(!data){ return each.end({err: "Mismatched owner on '" + key + "'.", }) }
if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){ if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){
SEA.verify(tmp[0], user, tmp[1], function(ok){ SEA.verify(tmp[0], user, tmp[1], function(ok){
if(!ok){ return each.end({err: "Signature did not match account."}) } if(!ok){ return each.end({err: "Signature did not match account."}) }
@ -905,11 +905,19 @@
//each.end({err: "Data cannot be modified."}); //each.end({err: "Data cannot be modified."});
return; return;
} }
if(!(tmp = soul.split('~')) || 2 !== tmp.length){
each.end({err: "Soul is not signed at '" + key + "'."})
return;
}
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
SEA.write(val, user, function(data){ SEA.verify(tmp[0], user.pub, tmp[1], function(ok){
node[key] = data; if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) }
check['any'+soul+key] = 0; (at.sea.own[soul] = at.sea.own[soul] || {})[user.pub] = true;
each.end({ok: 1}); SEA.write(val, user, function(data){
node[key] = data;
check['any'+soul+key] = 0;
each.end({ok: 1});
});
}); });
} }
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb? each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?

View File

@ -32,6 +32,9 @@ Gun.chain.back = function(n, opt){ var tmp;
&& !(yes = n(tmp, opt))){} && !(yes = n(tmp, opt))){}
return yes; return yes;
} }
if(Gun.num.is(n)){
return at.back.back(n - 1);
}
return this; return this;
} }
var empty = {}, u; var empty = {}, u;

View File

@ -116,7 +116,7 @@ function map(v,f,n, at){ var as = this;
for(i; i < l; i++){ for(i; i < l; i++){
ref = ref.get(path[i]); ref = ref.get(path[i]);
} }
if(as.not || Gun.node.soul(at.obj)){ if(Gun.node.soul(at.obj)){
var id = Gun.node.soul(at.obj) || (ref.back('opt.uuid') || Gun.text.random)(); var id = Gun.node.soul(at.obj) || (ref.back('opt.uuid') || Gun.text.random)();
if(!id){ // polyfill async uuid for SEA if(!id){ // polyfill async uuid for SEA
(as.stun = as.stun || {})[path] = true; // make DRY (as.stun = as.stun || {})[path] = true; // make DRY
@ -146,7 +146,7 @@ function soul(at, ev){ var as = this.as, cat = as.at; as = as.as;
var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous? var id = id || Gun.node.soul(cat.obj) || Gun.node.soul(at.put) || Gun.val.rel.is(at.put) || (as.gun.back('opt.uuid') || Gun.text.random)(); // TODO: BUG!? Do we really want the soul of the object given to us? Could that be dangerous?
if(!id){ // polyfill async uuid for SEA if(!id){ // polyfill async uuid for SEA
at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback at.gun.back('opt.uuid')(function(err, id){ // TODO: improve perf without anonymous callback
if(err){ return Gun.log(e) } // TODO: Handle error. if(err){ return Gun.log(err) } // TODO: Handle error.
solve(at, id, cat, as); solve(at, id, cat, as);
}); });
return; return;
@ -201,7 +201,7 @@ function any(at, ev){
as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)(); as.soul = at.soul || cat.soul || (opt.uuid || cat.root._.opt.uuid || Gun.text.random)();
} }
if(!as.soul){ // polyfill async uuid for SEA if(!as.soul){ // polyfill async uuid for SEA
ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback as.ref.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
if(err){ return Gun.log(err) } // Handle error. if(err){ return Gun.log(err) } // Handle error.
as.ref.put(as.data, as.soul = soul, as); as.ref.put(as.data, as.soul = soul, as);
}); });

View File

@ -3626,6 +3626,26 @@ describe('Gun', function(){
done(); done.c = 1; done(); done.c = 1;
}); });
}); });
it('Soul above but not beneath', function(done){
var gun = Gun();
var a = gun.get('sabnb');
a.get('profile').put({_:{'#': 'sabnbprofile'}, name: "Plum"});
setTimeout(function(){
a.get('profile').get('said').get('asdf').put('yes');
setTimeout(function(){
a.val(function(data){
expect(data.profile).to.be.eql({'#': 'sabnbprofile'});
if(done.c){ return } done.c = 1;
done();
})
}, 100);
}, 100);
});
return; return;
it('Nested listener should be called', function(done){ it('Nested listener should be called', function(done){