mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
match update
This commit is contained in:
parent
a4924d85d0
commit
c03b7d4e1e
19
gun.js
19
gun.js
@ -1,5 +1,5 @@
|
||||
;(function(){
|
||||
|
||||
|
||||
function Gun(o){
|
||||
var gun = this;
|
||||
if(!Gun.is(gun)){ return new Gun(o) }
|
||||
@ -27,12 +27,21 @@
|
||||
}
|
||||
Type.text.match = function(t, o){ var r = false;
|
||||
t = t || '';
|
||||
o = o || {}; // {'=', '*', '<', '>', '+', '-', '?', '&'} // exactly equal, anything after, lexically larger, lexically lesser, added in, subtacted from, questionable fuzzy match, and ends with.
|
||||
o = o || {}; // {'~', '=', '*', '<', '>', '+', '-', '?', '!'} // ignore uppercase, exactly equal, anything after, lexically larger, lexically lesser, added in, subtacted from, questionable fuzzy match, and ends with.
|
||||
if(Type.obj.has(o,'~')){ t = t.toLowerCase() }
|
||||
if(Type.obj.has(o,'=')){ return t === o['='] }
|
||||
if(Type.obj.has(o,'*')){ if(t.slice(0, o['*'].length) === o['*']){ r = true; t = t.slice(o['*'].length) } else { return false }}
|
||||
if(Type.obj.has(o,'&')){ if(t.slice(-o['&'].length) === o['&']){ r = true } else { return false }}
|
||||
if(Type.obj.has(o,'+')){ if(t.indexOf(o['+']) >= 0){ r = true } else { return false }}
|
||||
if(Type.obj.has(o,'-')){ if(t.indexOf(o['-']) < 0){ r = true } else { return false }}
|
||||
if(Type.obj.has(o,'!')){ if(t.slice(-o['!'].length) === o['!']){ r = true } else { return false }}
|
||||
if(Type.obj.has(o,'+')){
|
||||
if(Type.list.map(Type.list.is(o['+'])? o['+'] : [o['+']], function(m){
|
||||
if(t.indexOf(m) >= 0){ r = true } else { return true }
|
||||
})){ return false }
|
||||
}
|
||||
if(Type.obj.has(o,'-')){
|
||||
if(Type.list.map(Type.list.is(o['-'])? o['-'] : [o['-']], function(m){
|
||||
if(t.indexOf(m) < 0){ r = true } else { return true }
|
||||
})){ return false }
|
||||
}
|
||||
if(Type.obj.has(o,'>')){ if(t > o['>']){ r = true } else { return false }}
|
||||
if(Type.obj.has(o,'<')){ if(t < o['<']){ r = true } else { return false }}
|
||||
function fuzzy(t,f){ var n = -1, i = 0, c; for(;c = f[i++];){ if(!~(n = t.indexOf(c, n+1))){ return false }} return true } // via http://stackoverflow.com/questions/9206013/javascript-fuzzy-search
|
||||
|
@ -171,7 +171,7 @@
|
||||
var reply = {headers: {'Content-Type': tran.json}};
|
||||
if(!req.body){ return cb({headers: reply.headers, body: {err: "No body"}}) }
|
||||
gun.wsp.on('network').emit(Gun.obj.copy(req));
|
||||
//console.log("tran.put", req.body);
|
||||
//console.log("\n\ntran.put ----------------->", 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(err){ return cb({headers: reply.headers, body: {err: err || "Union failed."}}) }
|
||||
@ -182,6 +182,7 @@
|
||||
(gun.__.opt.wire.put || function(g,cb){cb("No save.")})(ctx.graph, function(err, ok){
|
||||
if(err){ return cb({headers: reply.headers, body: {err: err || "Failed."}}) } // TODO: err should already be an error object?
|
||||
cb({headers: reply.headers, body: {ok: ok || "Persisted."}});
|
||||
//console.log("tran.put <------------------------", ok);
|
||||
});
|
||||
}).err){ cb({headers: reply.headers, body: {err: req.err || "Union failed."}}) }
|
||||
} else {
|
||||
|
@ -317,12 +317,20 @@ describe('Gun', function(){
|
||||
expect(Gun.text.match("user/amber/cazzell", {'*': 'user/', '?': 'm/n'})).to.not.be.ok();
|
||||
expect(Gun.text.match("user/mark/nadal", {'*': 'user/', '-': 'mad'})).to.be.ok();
|
||||
expect(Gun.text.match("user/mad/person", {'*': 'user/', '-': 'mad'})).to.not.be.ok();
|
||||
expect(Gun.text.match("user/mark/timothy/nadal", {'*': 'user/', '-': ['mark', 'nadal']})).to.not.be.ok();
|
||||
expect(Gun.text.match("user/amber/rachel/cazzell", {'*': 'user/', '-': ['mark', 'nadal']})).to.be.ok();
|
||||
expect(Gun.text.match("user/mark/nadal", {'*': 'user/', '+': 'ark'})).to.be.ok();
|
||||
expect(Gun.text.match("user/mad/person", {'*': 'user/', '+': 'ark'})).to.not.be.ok();
|
||||
expect(Gun.text.match("photo/kitten.jpg", {'*': 'photo/', '&': '.jpg'})).to.be.ok();
|
||||
expect(Gun.text.match("photo/kittens.gif", {'*': 'photo/', '&': '.jpg'})).to.not.be.ok();
|
||||
expect(Gun.text.match("user/mark/timothy/nadal", {'*': 'user/', '+': ['mark', 'nadal']})).to.be.ok();
|
||||
expect(Gun.text.match("user/mark/timothy/nadal", {'*': 'user/', '+': ['nadal', 'mark']})).to.be.ok();
|
||||
expect(Gun.text.match("user/mark/timothy/nadal", {'*': 'user/', '+': ['mark', 'amber']})).to.not.be.ok();
|
||||
expect(Gun.text.match("user/mark/rachel/nadal/cazzell", {'*': 'user/', '+': ['mark', 'cazzell'], '-': ['amber', 'timothy']})).to.be.ok();
|
||||
expect(Gun.text.match("user/mark/rachel/timothy/cazzell", {'*': 'user/', '+': ['mark', 'cazzell'], '-': ['amber', 'timothy']})).to.not.be.ok();
|
||||
expect(Gun.text.match("photo/kitten.jpg", {'*': 'photo/', '!': '.jpg'})).to.be.ok();
|
||||
expect(Gun.text.match("photo/kittens.gif", {'*': 'photo/', '!': '.jpg'})).to.not.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('List', function(){
|
||||
it('slit',function(){
|
||||
(function(){
|
||||
@ -484,7 +492,7 @@ describe('Gun', function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ify', function(){
|
||||
var test, gun = Gun();
|
||||
|
||||
@ -2295,6 +2303,55 @@ describe('Gun', function(){
|
||||
},1);
|
||||
});
|
||||
|
||||
it.skip('paths rel should not slowdown', function(done){ // TODO: NEED TO ADD THIS NEW TEST!
|
||||
this.timeout(5000);
|
||||
//this.timeout(60000);
|
||||
|
||||
//Gun.log.debug = 1; console.log("~~~~~ START ~~~~~~");
|
||||
var gun = Gun(gopt).put({
|
||||
history: {}
|
||||
});
|
||||
//console.log("-------- DATA SET UP -----------");
|
||||
var prev, diff, max = 100, total = 100, largest = -1, gone = {};
|
||||
gun.path('history').map(function(entry, index){
|
||||
//if(!entry){ return } // TODO: BUG! KNOWN BUG!!!!!!! FIX!!!!!
|
||||
//console.log("WAT", index, entry);
|
||||
//console.log("THE GRAPH\n", gun.__.graph);
|
||||
//expect(gone[index]).to.not.be.ok();
|
||||
gone[index] = diff;
|
||||
diff = Gun.time.is() - (entry.time || prev);
|
||||
largest = (largest < diff)? diff : largest;
|
||||
console.log('turn', turns, 'index', index, 'diff', diff, 'largest', largest);
|
||||
expect(diff > max).to.not.be.ok();
|
||||
});
|
||||
|
||||
var turns = 0;
|
||||
//console.log("------------ PATH MAP SET UP --------------");
|
||||
var many = setInterval(function(){
|
||||
if(turns > total || diff > (max + 5)){
|
||||
clearTimeout(many);
|
||||
expect(Gun.num.is(diff)).to.be.ok();
|
||||
if(done.c){ return } done(); done.c = 1;
|
||||
return;
|
||||
}
|
||||
prev = Gun.time.is();
|
||||
Gun.log.base = Gun.log.ref = Gun.log.fer = prev;
|
||||
//if(turns === 0){ Gun.log.debug = 1; console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); }
|
||||
//console.log("-------------- ", turns + 1, "-----------------");
|
||||
var val = {
|
||||
TURN: turns + 1,
|
||||
x: 1,
|
||||
y: 1,
|
||||
axis: 'y',
|
||||
direction: 1,
|
||||
time: prev
|
||||
}
|
||||
//var put = {}; put[turns += 1] = val;
|
||||
//gun.put({history: put});
|
||||
gun.path(['history', turns += 1]).put(val);
|
||||
},1);
|
||||
});
|
||||
|
||||
it('val path put val', function(done){
|
||||
var gun = Gun();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user