mirror of
https://github.com/amark/gun.git
synced 2025-06-13 01:26:44 +00:00
0.5 BETA TESTING
This commit is contained in:
parent
acc085a8ed
commit
fa3d3eeff4
20
lib/file.js
20
lib/file.js
@ -14,25 +14,31 @@ function writeFile(path, disk, at){
|
|||||||
fs.writeFile(String(path), Gun.text.ify(disk), function(err) {
|
fs.writeFile(String(path), Gun.text.ify(disk), function(err) {
|
||||||
var batch = queuedWrites.splice(0);
|
var batch = queuedWrites.splice(0);
|
||||||
isWriting = false;
|
isWriting = false;
|
||||||
at.cb(err);
|
//at.cb(err);
|
||||||
|
at.gun.Back(-1).on('in', {'@': at['#'], err: err, ok: err? false : 1});
|
||||||
if(batch.length){
|
if(batch.length){
|
||||||
writeFile(path, disk, {cb: function(err) {
|
writeFile(path, disk, {cb: function(err) {
|
||||||
batch.forEach( function(at) { at.cb(err); } )
|
batch.forEach( function(at) {
|
||||||
|
at.gun.Back(-1).on('in', {'@': at['#'], err: err, ok: err? false : 1});
|
||||||
|
} )
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Gun.on('put', function(at){
|
Gun.on('put', function(at){
|
||||||
var gun = at.gun, graph = at.graph, opt = at.opt;
|
var gun = at.gun, graph = at.put, opt = at.opt || {};
|
||||||
Gun.obj.map(gun.__.graph, function(node, soul){
|
var __ = gun._.root._;
|
||||||
file.disk.graph[soul] = gun.__.graph[soul] || graph[soul];
|
Gun.obj.map(graph, function(node, soul){
|
||||||
|
file.disk.graph[soul] = __.graph[soul] || graph[soul];
|
||||||
});
|
});
|
||||||
writeFile(opt.file || file.file, file.disk, at);
|
writeFile(opt.file || file.file, file.disk, at);
|
||||||
});
|
});
|
||||||
Gun.on('get', function(at){
|
Gun.on('get', function(at){
|
||||||
var gun = at.gun, lex = at.lex, opt = at.opt;
|
var gun = at.gun, lex = at.get, opt = at.opt;
|
||||||
at.cb(null, file.disk.graph[lex.soul]);
|
if(!lex){return}
|
||||||
|
gun.Back(-1).on('in', {'@': at['#'], put: Gun.graph.node(file.disk.graph[lex['#']])});
|
||||||
|
//at.cb(null, file.disk.graph[lex['#']]);
|
||||||
});
|
});
|
||||||
|
|
||||||
Gun.on('opt', function(at){
|
Gun.on('opt', function(at){
|
||||||
|
@ -18,7 +18,7 @@ module.exports = function(wss, server, opt){
|
|||||||
msg.method = msg.method || msg.body? 'put' : 'get';
|
msg.method = msg.method || msg.body? 'put' : 'get';
|
||||||
msg.headers = msg.headers || {};
|
msg.headers = msg.headers || {};
|
||||||
Gun.obj.map(opt.headers || req.headers, function(val, i){
|
Gun.obj.map(opt.headers || req.headers, function(val, i){
|
||||||
msg.headers[i] = msg.headers[i] || val; // reattach headers
|
msg.headers[i] = msg.headers[i]; // reattach headers
|
||||||
});
|
});
|
||||||
server.call(ws, msg, function(reply){
|
server.call(ws, msg, function(reply){
|
||||||
if(!ws || !ws.send || !ws._socket || !ws._socket.writable){ return }
|
if(!ws || !ws.send || !ws._socket || !ws._socket.writable){ return }
|
||||||
|
18
lib/wsp.js
18
lib/wsp.js
@ -20,6 +20,7 @@
|
|||||||
, url = require('url');
|
, url = require('url');
|
||||||
Gun.on('opt', function(at){
|
Gun.on('opt', function(at){
|
||||||
var gun = at.gun, opt = at.opt;
|
var gun = at.gun, opt = at.opt;
|
||||||
|
gun.__ = at.root._;
|
||||||
gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {};
|
gun.__.opt.ws = opt.ws = gun.__.opt.ws || opt.ws || {};
|
||||||
function start(server, port, app){
|
function start(server, port, app){
|
||||||
if(app && app.use){ app.use(gun.wsp.server) }
|
if(app && app.use){ app.use(gun.wsp.server) }
|
||||||
@ -138,15 +139,16 @@
|
|||||||
if(gun.wsp.msg(msg['#'])){ return }
|
if(gun.wsp.msg(msg['#'])){ return }
|
||||||
gun.wsp.on('network', Gun.obj.copy(req));
|
gun.wsp.on('network', Gun.obj.copy(req));
|
||||||
if(msg['@']){ return } // no need to process.
|
if(msg['@']){ return } // no need to process.
|
||||||
if(Gun.is.lex(msg['$'])){ return tran.get(req, res) }
|
if(msg['$'] && msg['$']['#']){ return tran.get(req, res) }
|
||||||
|
//if(Gun.is.lex(msg['$'])){ return tran.get(req, res) }
|
||||||
else { return tran.put(req, res) }
|
else { return tran.put(req, res) }
|
||||||
cb({body: {hello: 'world'}});
|
cb({body: {hello: 'world'}});
|
||||||
// TODO: BUG! server put should push.
|
// TODO: BUG! server put should push.
|
||||||
}
|
}
|
||||||
tran.get = function(req, cb){
|
tran.get = function(req, cb){
|
||||||
var body = req.body, lex = body['$'], reply = {headers: {'Content-Type': tran.json}}, opt;
|
var body = req.body, lex = body['$'], reply = {headers: {'Content-Type': tran.json}}, opt;
|
||||||
Gun.get(gun, lex, function(err, node){
|
gun.get(lex, function(err, node, key, at, ev){
|
||||||
//console.log("tran.get", lex, err, node);
|
ev.off();
|
||||||
return cb({headers: reply.headers, body: {
|
return cb({headers: reply.headers, body: {
|
||||||
'#': gun.wsp.msg(),
|
'#': gun.wsp.msg(),
|
||||||
'@': body['#'],
|
'@': body['#'],
|
||||||
@ -185,14 +187,16 @@
|
|||||||
// NOTE: It is highly recommended you do your own PUT/POSTs through your own API that then saves to gun manually.
|
// NOTE: It is highly recommended you do your own PUT/POSTs through your own API that then saves to gun manually.
|
||||||
// This will give you much more fine-grain control over security, transactions, and what not.
|
// This will give you much more fine-grain control over security, transactions, and what not.
|
||||||
var body = req.body, graph = body['$'], reply = {headers: {'Content-Type': tran.json}}, opt;
|
var body = req.body, graph = body['$'], reply = {headers: {'Content-Type': tran.json}}, opt;
|
||||||
Gun.put(gun, graph, function(err, ok){
|
gun.on('out', {gun: gun, put: graph, '#': Gun.on.ask(function(ack, ev){
|
||||||
|
//Gun.on('put', {gun: gun, put: graph, '#': Gun.on.ask(function(ack, ev){
|
||||||
|
ev.off();
|
||||||
return cb({headers: reply.headers, body: {
|
return cb({headers: reply.headers, body: {
|
||||||
'#': gun.wsp.msg(),
|
'#': gun.wsp.msg(),
|
||||||
'@': body['#'],
|
'@': body['#'],
|
||||||
'$': ok,
|
'$': ack,
|
||||||
'!': err
|
'!': ack.err
|
||||||
}});
|
}});
|
||||||
}, opt);
|
})});
|
||||||
return;
|
return;
|
||||||
if(Gun.is.graph(req.body)){
|
if(Gun.is.graph(req.body)){
|
||||||
if(req.err = Gun.union(gun, req.body, function(err, ctx){ // TODO: BUG? Probably should give me ctx.graph
|
if(req.err = Gun.union(gun, req.body, function(err, ctx){ // TODO: BUG? Probably should give me ctx.graph
|
||||||
|
628
test/common.js
628
test/common.js
@ -1453,6 +1453,634 @@ describe('Gun', function(){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('plural chains', function(){
|
||||||
|
|
||||||
|
it.only("get before put in memory", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/r').map().on(function(v,f){
|
||||||
|
check[f] = v;
|
||||||
|
console.log("***********", f,v);
|
||||||
|
if(check.alice && check.bob && check.alice.PhD){
|
||||||
|
expect(check.alice.age).to.be(24);
|
||||||
|
expect(check.bob.age).to.be(26);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.debug.i=1;console.log("-------------------");
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/r'},
|
||||||
|
alice: {_:{'#':'GALICE'},
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
console.log("~~~~~~~~~~~~~~~~~~");
|
||||||
|
gun.get('GALICE').put({PhD: true});
|
||||||
|
},300);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n'},
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n').map().on(function(v,f){
|
||||||
|
check[f] = v;
|
||||||
|
if(check.alice && check.bob){
|
||||||
|
expect(check.alice.age).to.be(24);
|
||||||
|
expect(check.bob.age).to.be(26);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
it("in memory get before map path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/p').map().path('name').on(function(v,f){
|
||||||
|
check[v] = f;
|
||||||
|
if(check.alice && check.bob){
|
||||||
|
expect(check.alice).to.be('name');
|
||||||
|
expect(check.bob).to.be('name');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/p'},
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after map path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/m/p'},
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/m/p').map().path('name').on(function(v,f){
|
||||||
|
check[v] = f;
|
||||||
|
if(check.alice && check.bob){
|
||||||
|
expect(check.alice).to.be('name');
|
||||||
|
expect(check.bob).to.be('name');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get before map path path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/p/p/p').map().path('spouse').path('work').on(function(v,f){
|
||||||
|
check[v.name] = f;
|
||||||
|
if(check['GUN INC'] && check['ACME INC']){
|
||||||
|
expect(check['GUN INC']).to.be('work');
|
||||||
|
expect(check['ACME INC']).to.be('work');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/p/p/p'},
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after map path path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/p/p/p/a'},
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25,
|
||||||
|
work: {
|
||||||
|
name: "GUN INC"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27,
|
||||||
|
work: {
|
||||||
|
name: "ACME INC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/p/p/p/a').map().path('spouse').path('work').on(function(v,f){
|
||||||
|
check[v.name] = f;
|
||||||
|
if(check['GUN INC'] && check['ACME INC']){
|
||||||
|
expect(check['GUN INC']).to.be('work');
|
||||||
|
expect(check['ACME INC']).to.be('work');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get before map map", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/a/m/m').map().map().on(function(v,f){
|
||||||
|
check[f] = v;
|
||||||
|
if(check.alice && check.bob && check.GUN && check.ACME){
|
||||||
|
expect(check.alice.name).to.be('alice');
|
||||||
|
expect(check.alice.age).to.be(24);
|
||||||
|
expect(Gun.val.rel.is(check.alice.spouse)).to.be.ok();
|
||||||
|
expect(check.bob.name).to.be('bob');
|
||||||
|
expect(check.bob.age).to.be(26);
|
||||||
|
expect(Gun.val.rel.is(check.bob.spouse)).to.be.ok();
|
||||||
|
expect(check.GUN.name).to.be('GUN');
|
||||||
|
expect(check.ACME.name).to.be('ACME');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/a/m/m'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN"
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after map map", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/m/m'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN"
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/m/m').map().map().on(function(v,f){
|
||||||
|
check[f] = v;
|
||||||
|
if(check.alice && check.bob && check.GUN && check.ACME){
|
||||||
|
expect(check.alice.name).to.be('alice');
|
||||||
|
expect(check.alice.age).to.be(24);
|
||||||
|
expect(Gun.val.rel.is(check.alice.spouse)).to.be.ok();
|
||||||
|
expect(check.bob.name).to.be('bob');
|
||||||
|
expect(check.bob.age).to.be(26);
|
||||||
|
expect(Gun.val.rel.is(check.bob.spouse)).to.be.ok();
|
||||||
|
expect(check.GUN.name).to.be('GUN');
|
||||||
|
expect(check.ACME.name).to.be('ACME');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get before map map path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/m/m/p').map().map().path('name').on(function(v,f){
|
||||||
|
check[v] = f;
|
||||||
|
if(check.alice && check.bob && check.GUN && check.ACME){
|
||||||
|
expect(check.alice).to.be('name');
|
||||||
|
expect(check.bob).to.be('name');
|
||||||
|
expect(check.GUN).to.be('name');
|
||||||
|
expect(check.ACME).to.be('name');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/m/m/p'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN"
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after map map path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/a/m/m/p'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN"
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.get('g/n/m/f/l/n/b/a/m/m/p').map().map().path('name').on(function(v,f){
|
||||||
|
check[v] = f;
|
||||||
|
if(check.alice && check.bob && check.GUN && check.ACME){
|
||||||
|
expect(check.alice).to.be('name');
|
||||||
|
expect(check.bob).to.be('name');
|
||||||
|
expect(check.GUN).to.be('name');
|
||||||
|
expect(check.ACME).to.be('name');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get before map map path path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/m/m/p/p').map().map().path('address').path('state').on(function(v,f){
|
||||||
|
check[v] = f;
|
||||||
|
if(check.QR && check.NY && check.CA && check.TX && check.MA){
|
||||||
|
expect(check.QR).to.be('state');
|
||||||
|
expect(check.NY).to.be('state');
|
||||||
|
expect(check.CA).to.be('state');
|
||||||
|
expect(check.TX).to.be('state');
|
||||||
|
expect(check.MA).to.be('state');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/m/m/p/p'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
address: {_:{'#':'QUANGO'},
|
||||||
|
state: "MA"
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
address: {_:{'#': 'DANDAO'},
|
||||||
|
state: "TX"
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN",
|
||||||
|
address: {
|
||||||
|
state: "CA"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME",
|
||||||
|
address: {
|
||||||
|
state: "NY"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
gun.get('QUANGO').put({state: 'QR'});
|
||||||
|
},300);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get after map map path path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/a/m/m/p/p'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
address: {_:{'#':'QUANGO'},
|
||||||
|
state: "MA"
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
address: {_:{'#': 'DANDAO'},
|
||||||
|
state: "TX"
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN",
|
||||||
|
address: {
|
||||||
|
state: "CA"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME",
|
||||||
|
address: {
|
||||||
|
state: "NY"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var check = {};
|
||||||
|
gun.get('g/n/m/f/l/n/b/a/m/m/p/p').map().map().path('address').path('state').on(function(v,f){
|
||||||
|
console.log("**********", f,v);
|
||||||
|
check[v] = f;
|
||||||
|
if(check.QR && check.NY && check.CA && check.TX && check.MA){
|
||||||
|
expect(check.QR).to.be('state');
|
||||||
|
expect(check.NY).to.be('state');
|
||||||
|
expect(check.CA).to.be('state');
|
||||||
|
expect(check.TX).to.be('state');
|
||||||
|
expect(check.MA).to.be('state');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
gun.get('QUANGO').put({state: 'QR'});
|
||||||
|
},300);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("in memory get before map map path path path", function(done){
|
||||||
|
var gun = Gun();
|
||||||
|
var check = {};
|
||||||
|
(window.STATE = gun.get('g/n/m/f/l/n/b/m/m/p/p/p').path('users').path('alice').path('address').path('state')).on(function(v,f){console.log("* * * * * * * *", f,v)});
|
||||||
|
gun.get('g/n/m/f/l/n/b/m/m/p/p/p').map().map().path('address').path('state')
|
||||||
|
//.path('code')
|
||||||
|
.on(function(v,f){
|
||||||
|
check[v.code] = f;
|
||||||
|
console.log("************", f,v);//return;
|
||||||
|
if(check.QR && check.NY && check.CA && check.TX && check.MA){
|
||||||
|
expect(check.QR).to.be('state');
|
||||||
|
expect(check.NY).to.be('state');
|
||||||
|
expect(check.CA).to.be('state');
|
||||||
|
expect(check.TX).to.be('state');
|
||||||
|
expect(check.MA).to.be('state');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
gun.put({_:{'#':'g/n/m/f/l/n/b/m/m/p/p/p'},
|
||||||
|
users: {
|
||||||
|
alice: {
|
||||||
|
name: "alice",
|
||||||
|
age: 24,
|
||||||
|
address: {_:{'#':'QUANGO'},
|
||||||
|
state: {_:{'#':'HIPPOM'},
|
||||||
|
code: "MA",
|
||||||
|
county: {
|
||||||
|
MA1: "First"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "carl",
|
||||||
|
age: 25
|
||||||
|
},
|
||||||
|
bout: {huh:1}
|
||||||
|
},
|
||||||
|
bob: {
|
||||||
|
name: "bob",
|
||||||
|
age: 26,
|
||||||
|
address: {_:{'#': 'DANDAO'},
|
||||||
|
state: {
|
||||||
|
code: "TX",
|
||||||
|
county: {
|
||||||
|
TX1: "First"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spouse: {
|
||||||
|
name: "diana",
|
||||||
|
age: 27
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
companies: {
|
||||||
|
GUN: {
|
||||||
|
name: "GUN",
|
||||||
|
address: {
|
||||||
|
state: {
|
||||||
|
code: "CA",
|
||||||
|
county: {
|
||||||
|
CA1: "First"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ACME: {
|
||||||
|
name: "ACME",
|
||||||
|
address: {
|
||||||
|
state: {
|
||||||
|
code: "NY",
|
||||||
|
county: {
|
||||||
|
NY1: "First"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(function(){
|
||||||
|
console.debug.i=1;console.log("-------------------");
|
||||||
|
gun.get('HIPPOM').put({code: 'QR'});
|
||||||
|
},300);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
return;
|
||||||
it('get get get any parallel', function(done){
|
it('get get get any parallel', function(done){
|
||||||
var s = Gun.state.map();s.soul = 'parallel';
|
var s = Gun.state.map();s.soul = 'parallel';
|
||||||
Gun.on('put', {gun: gun, put: Gun.graph.ify({
|
Gun.on('put', {gun: gun, put: Gun.graph.ify({
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
<script src="benchmark.js"></script>
|
<script src="benchmark.js"></script>
|
||||||
<script src="ptsd.js"></script>
|
<script src="ptsd.js"></script>
|
||||||
<script src="../../gun.js"></script>
|
<script src="../../gun.js"></script>
|
||||||
<script src="file:///Users/mark/Desktop/bigJSON.js"></script>
|
|
||||||
<script src="perf.js"></script>
|
<script src="perf.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user