From a111e20f271c011b4c0c739b8c4f41d0605fb8ca Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Sat, 27 Apr 2019 15:06:00 -0700 Subject: [PATCH] fix Lex lookups --- gun.js | 18 ++++++++++-------- package.json | 2 +- src/adapters/mesh.js | 3 ++- src/chain.js | 12 +++++++----- src/type.js | 6 +++--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/gun.js b/gun.js index 99a0fe278..0be1772fe 100644 --- a/gun.js +++ b/gun.js @@ -49,10 +49,10 @@ if(t.slice(0, (tmp||'').length) === tmp){ return true } if(u !== o['*']){ return false } if(u !== o['>'] && u !== o['<']){ - return (t > o['>'] && t < o['<'])? true : false; + return (t >= o['>'] && t <= o['<'])? true : false; } - if(u !== o['>'] && t > o['>']){ return true } - if(u !== o['<'] && t < o['<']){ return true } + if(u !== o['>'] && t >= o['>']){ return true } + if(u !== o['<'] && t <= o['<']){ return true } return false; } Type.list = {is: function(l){ return (l instanceof Array) }} @@ -958,7 +958,7 @@ if(tmp){ return } msg.$ = back.$; } else - if(obj_has(back.put, get)){ + if(obj_has(back.put, get)){ // TODO: support #LEX ! put = (back.$.get(get)._); if(!(tmp = put.ack)){ put.ack = -1 } back.on('in', { @@ -1178,14 +1178,16 @@ }); } function ask(at, soul){ - var tmp = (at.root.$.get(soul)._); - if(at.ack){ - tmp.on('out', {get: {'#': soul}}); + var tmp = (at.root.$.get(soul)._), lex = at.lex; + if(at.ack || lex){ + (lex = lex||{})['#'] = soul; + tmp.on('out', {get: lex}); if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way? } tmp = at.ask; Gun.obj.del(at, 'ask'); obj_map(tmp || at.next, function(neat, key){ - neat.on('out', {get: {'#': soul, '.': key}}); + var lex = neat.lex || {}; lex['#'] = soul; lex['.'] = lex['.'] || key; + neat.on('out', {get: lex}); }); Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way? } diff --git a/package.json b/package.json index ce42e8599..54c3faa79 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.2019.427", + "version": "0.2019.428", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "main": "index.js", "browser": "gun.js", diff --git a/src/adapters/mesh.js b/src/adapters/mesh.js index d198f766d..3904cd727 100644 --- a/src/adapters/mesh.js +++ b/src/adapters/mesh.js @@ -49,7 +49,7 @@ function Mesh(ctx){ } (msg._ = function(){}).via = peer; if((tmp = msg['><'])){ - (msg._).to = Type.obj.map(tmp.split(','), function(k,i,m){m(k,true)}); + (msg._).to = Type.obj.map(tmp.split(','), tomap); } if(msg.dam){ if(tmp = mesh.hear[msg.dam]){ @@ -72,6 +72,7 @@ function Mesh(ctx){ return; } } + var tomap = function(k,i,m){m(k,true)}; ;(function(){ mesh.say = function(msg, peer, o){ diff --git a/src/chain.js b/src/chain.js index 181044811..1864ac1f3 100644 --- a/src/chain.js +++ b/src/chain.js @@ -37,7 +37,7 @@ function output(msg){ if(tmp){ return } msg.$ = back.$; } else - if(obj_has(back.put, get)){ + if(obj_has(back.put, get)){ // TODO: support #LEX ! put = (back.$.get(get)._); if(!(tmp = put.ack)){ put.ack = -1 } back.on('in', { @@ -257,14 +257,16 @@ function not(at, msg){ }); } function ask(at, soul){ - var tmp = (at.root.$.get(soul)._); - if(at.ack){ - tmp.on('out', {get: {'#': soul}}); + var tmp = (at.root.$.get(soul)._), lex = at.lex; + if(at.ack || lex){ + (lex = lex||{})['#'] = soul; + tmp.on('out', {get: lex}); if(!at.ask){ return } // TODO: PERFORMANCE? More elegant way? } tmp = at.ask; Gun.obj.del(at, 'ask'); obj_map(tmp || at.next, function(neat, key){ - neat.on('out', {get: {'#': soul, '.': key}}); + var lex = neat.lex || {}; lex['#'] = soul; lex['.'] = lex['.'] || key; + neat.on('out', {get: lex}); }); Gun.obj.del(at, 'ask'); // TODO: PERFORMANCE? More elegant way? } diff --git a/src/type.js b/src/type.js index 82be63d42..caf5ab378 100644 --- a/src/type.js +++ b/src/type.js @@ -29,10 +29,10 @@ Type.text.match = function(t, o){ var tmp, u; if(t.slice(0, (tmp||'').length) === tmp){ return true } if(u !== o['*']){ return false } if(u !== o['>'] && u !== o['<']){ - return (t > o['>'] && t < o['<'])? true : false; + return (t >= o['>'] && t <= o['<'])? true : false; } - if(u !== o['>'] && t > o['>']){ return true } - if(u !== o['<'] && t < o['<']){ return true } + if(u !== o['>'] && t >= o['>']){ return true } + if(u !== o['<'] && t <= o['<']){ return true } return false; } Type.list = {is: function(l){ return (l instanceof Array) }}