Explorar el Código

update gundb to 0.2019.1211

Nikolay Suslov hace 5 años
padre
commit
a68af3879e

+ 28 - 1
public/lib/gundb/axe.js

@@ -60,6 +60,20 @@
 			// with one common superpeer (with ready failovers)
 			// in case the p2p linear latency is high.
 			// Or there could be plenty of other better options.
+
+			/*
+				AXE should have a couple of threshold items...
+				let's pretend there is a variable max peers connected
+				mob = 10000
+				if we get more peers than that...
+				we should start sending those peers a remote command
+				that they should connect to this or that other peer
+				and then once they (or before they do?) drop them from us.
+				sake of the test... gonna set that peer number to 1.
+				The mob threshold might be determined by other factors,
+				like how much RAM or CPU stress we have.
+			*/
+			opt.mob = opt.mob || Infinity;
 			var mesh = opt.mesh = opt.mesh || Gun.Mesh(at);
 			console.log("AXE enabled.");
 
@@ -256,7 +270,7 @@
 				this.to.next(peer);
 				if(!peer.url){ return }
 				axe.up[peer.id] = peer;
-			})
+			});
 			at.on('bye', function(peer){ this.to.next(peer);
 				if(peer.url){ delete axe.up[peer.id] }
 				Gun.obj.map(peer.routes, function(route, hash){
@@ -266,6 +280,19 @@
 					}
 				});
 			});
+
+			// handle rebalancing a mob of peers:
+			at.on('hi', function(peer){
+				this.to.next(peer);
+				if(peer.url){ return } // I am assuming that if we are wanting to make an outbound connection to them, that we don't ever want to drop them unless our actual config settings change.
+				var count = Object.keys(opt.peers).length;
+				if(opt.mob >= count){ return }  // TODO: Make dynamic based on RAM/CPU also. Or possibly even weird stuff like opt.mob / axe.up length?
+				mesh.say({dam: 'mob', mob: count, peers: Object.keys(axe.up)}, peer);
+				//setTimeout(function(){ mesh.bye(peer) }, 9); // something with better perf? // UNCOMMENT WHEN WE ACTIVATE THIS FEATURE
+			});
+			at.on('bye', function(peer){
+				this.to.next(peer);
+			});
 		}
 
 		function joindht(dht, soul, pids) {

+ 21 - 26
public/lib/gundb/gun.js

@@ -811,20 +811,16 @@
 					// Maybe... in case the in-memory key we have is a local write
 					// we still need to trigger a pull/merge from peers.
 				} else {
-					//var S = +new Date;
 					node = Gun.obj.copy(node);
-					//console.log(+new Date - S, 'copy node');
 				}
 				node = Gun.graph.node(node);
 				tmp = (at||empty).ack;
-				//var S = +new Date;
 				root.on('in', {
 					'@': msg['#'],
 					how: 'mem',
 					put: node,
 					$: gun
 				});
-				//console.log(+new Date - S, 'root got send');
 				//if(0 < tmp){ return }
 				root.on('get', msg);
 			}
@@ -965,7 +961,7 @@
 						if(obj_has(back, 'put')){
 							back.on('in', back);
 						}
-						if(tmp){ return }
+						if(tmp && u !== back.put){ return } //if(tmp){ return }
 						msg.$ = back.$;
 					} else
 					if(obj_has(back.put, get)){ // TODO: support #LEX !
@@ -1178,7 +1174,7 @@
 				if(u === tmp && u !== at.put){ return true }
 				neat.put = u;
 				if(neat.ack){
-					neat.ack = -1; // TODO: BUG? Should this be 0?
+					neat.ack = -1; // Shouldn't this be reset to 0? If we do that, SEA test `set user ref should be found` fails, odd.
 				}
 				neat.on('in', {
 					get: key,
@@ -1317,7 +1313,6 @@
 		function use(msg){
 			var eve = this, as = eve.as, cat = as.at, root = cat.root, gun = msg.$, at = (gun||{})._ || {}, data = msg.put || at.put, tmp;
 			if((tmp = root.now) && eve !== tmp[as.now]){ return eve.to.next(msg) }
-			//console.log("USE:", cat.id, cat.soul, cat.has, cat.get, msg, root.mum);
 			//if(at.async && msg.root){ return }
 			//if(at.async === 1 && cat.async !== true){ return }
 			//if(root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true);
@@ -1545,7 +1540,7 @@
 			as = as.as;
 			if(!msg.$ || !msg.$._){ return } // TODO: Handle
 			if(msg.err){ // TODO: Handle
-				console.log("Please report this as an issue! Put.any.err");
+				Gun.log("Please report this as an issue! Put.any.err");
 				return;
 			}
 			var at = (msg.$._), data = at.put, opt = as.opt||{}, root, tmp;
@@ -1554,7 +1549,7 @@
 			if(as.ref !== as.$){
 				tmp = (as.$._).get || at.get;
 				if(!tmp){ // TODO: Handle
-					console.log("Please report this as an issue! Put.no.get"); // TODO: BUG!??
+					Gun.log("Please report this as an issue! Put.no.get"); // TODO: BUG!??
 					return;
 				}
 				as.data = obj_put({}, tmp, as.data);
@@ -1814,7 +1809,7 @@
 		var root, noop = function(){}, store, u;
 		try{store = (Gun.window||noop).localStorage}catch(e){}
 		if(!store){
-			console.log("Warning: No localStorage exists to persist data to!");
+			Gun.log("Warning: No localStorage exists to persist data to!");
 			store = {setItem: function(k,v){this[k]=v}, removeItem: function(k){delete this[k]}, getItem: function(k){return this[k]}};
 		}
 		/*
@@ -1920,7 +1915,6 @@
 					data = Gun.state.to(data, has);
 				}
 				//if(!data && !Gun.obj.empty(opt.peers)){ return } // if data not found, don't ack if there are peers. // Hmm, what if we have peers but we are disconnected?
-				//console.log("lS get", lex, data);
 				root.on('in', {'@': msg['#'], put: Gun.graph.node(data), how: 'lS', lS: msg.$});// || root.$});
 				};
 				Gun.debug? setTimeout(to,1) : to();
@@ -1976,15 +1970,14 @@
 				if('[' === tmp){
 					try{msg = JSON.parse(raw);}catch(e){opt.log('DAM JSON parse error', e)}
 					if(!msg){ return }
-					//console.log('hear batch length of', msg.length);
+					LOG && opt.log(+new Date, msg.length, 'in hear batch');
 					(function go(){
-						var S = +new Date; // STATS!
+						var S; LOG && (S = +new Date); // STATS!
 						var m, c = 100; // hardcoded for now?
 						while(c-- && (m = msg.shift())){
 							mesh.hear(m, peer);
 						}
-						//console.log(+new Date - S, 'hear batch');
-						(mesh.hear.long || (mesh.hear.long = [])).push(+new Date - S);
+						LOG && opt.log(S, +new Date - S, 'batch heard');
 						if(!msg.length){ return }
 						puff(go, 0);
 					}());
@@ -1995,7 +1988,7 @@
 					}catch(e){return opt.log('DAM JSON parse error', e)}
 					if(!msg){ return }
 					if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) }
-					if(msg.DBG_s){ console.log(+new Date - msg.DBG_s, 'to hear', id) }
+					if(msg.DBG_s){ opt.log(+new Date - msg.DBG_s, 'to hear', id) }
 					if(dup.check(id)){ return }
 					dup.track(id, true).it = msg; // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore?
 					if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) }
@@ -2011,9 +2004,9 @@
 						}
 						return;
 					}
-					//var S = +new Date;
+					var S; LOG && (S = +new Date);
 					root.on('in', msg);
-					//!msg.nts && console.log(+new Date - S, 'msg', msg['#']);
+					LOG && !msg.nts && opt.log(S, +new Date - S, 'msg', msg['#']);
 					return;
 				}
 			}
@@ -2027,7 +2020,7 @@
 					if(this.to){ this.to.next(msg) } // compatible with middleware adapters.
 					if(!msg){ return false }
 					var id, hash, tmp, raw;
-					//var S = +new Date; //msg.DBG_s = msg.DBG_s || +new Date;
+					var S; LOG && (S = +new Date); //msg.DBG_s = msg.DBG_s || +new Date;
 					var meta = msg._||(msg._=function(){});
 					if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) }
 					if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) }
@@ -2041,15 +2034,15 @@
 							}
 						}
 					}
-					//console.log(+new Date - S, 'mesh say prep');
+					LOG && opt.log(S, +new Date - S, 'say prep');
 					dup.track(id).it = msg; // track for 9 seconds, default. Earth<->Mars would need more!
 					if(!peer){ peer = (tmp = dup.s[msg['@']]) && (tmp = tmp.it) && (tmp = tmp._) && (tmp = tmp.via) }
 					if(!peer && mesh.way){ return mesh.way(msg) }
 					if(!peer || !peer.id){ message = msg;
 						if(!Type.obj.is(peer || opt.peers)){ return false }
-						//var S = +new Date;
+						var S; LOG && (S = +new Date);
 						Type.obj.map(peer || opt.peers, each); // in case peer is a peer list.
-						//console.log(+new Date - S, 'mesh say loop');
+						LOG && opt.log(S, +new Date - S, 'say loop');
 						return;
 					}
 					if(!peer.wire && mesh.wire){ mesh.wire(peer) }
@@ -2073,10 +2066,10 @@
 					peer.batch = peer.tail = null;
 					if(!tmp){ return }
 					if(!tmp.length){ return } // if(3 > tmp.length){ return } // TODO: ^
-					//var S = +new Date;
+					var S; LOG && (S = +new Date);
 					try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp));
 					}catch(e){return opt.log('DAM JSON stringify error', e)}
-					//console.log(+new Date - S, 'mesh flush', tmp.length);
+					LOG && opt.log(S, +new Date - S, 'say stringify', tmp.length);
 					if(!tmp){ return }
 					send(tmp, peer);
 				}
@@ -2086,14 +2079,14 @@
 			// for now - find better place later.
 			function send(raw, peer){ try{
 				var wire = peer.wire;
-				//var S = +new Date;
+				var S; LOG && (S = +new Date);
 				if(peer.say){
 					peer.say(raw);
 				} else
 				if(wire.send){
 					wire.send(raw);
 				}
-				//console.log(+new Date - S, 'wire send', raw.length);
+				LOG && opt.log(S, +new Date - S, 'wire send', raw.length);
 				mesh.say.d += raw.length||0; ++mesh.say.c; // STATS!
 			}catch(e){
 				(peer.queue = peer.queue || []).push(raw);
@@ -2143,6 +2136,7 @@
 				root.on('bye', peer);
 				var tmp = +(new Date); tmp = (tmp - (peer.met||tmp));
 				mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
+				LOG = console.LOG; // dirty place to cheaply update LOG settings over time.
 			}
 			mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
 			mesh.hear['?'] = function(msg, peer){
@@ -2223,6 +2217,7 @@
 		}());
 
 	  var empty = {}, ok = true, u;
+		var LOG = console.LOG;
 
 	  try{ module.exports = Mesh }catch(e){}
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
public/lib/gundb/gun.min.js


+ 250 - 162
public/lib/gundb/lib/meta.js

@@ -1,155 +1,190 @@
 ;(function(){
-	var noop = function(){}, u;
-	var m = window.meta = {edit:[]};
-	var k = m.key = {};
-	k.meta = {17:17, 91:17, 93:17, 224:17};
-	k.down = function(eve){
-		if(eve.repeat){ return }
-		var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
-		if(!eve.fake && key === k.last){ return } k.last = key;
-		if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
-			if(k.meta[key]){ k.down.meta = key = -1 }
-			if(!k.down.meta){ return }
+  var root;
+  if(typeof window !== "undefined"){ root = window }
+  if(typeof global !== "undefined"){ root = global }
+  root = root || {};
+  var console = root.console || {log: function(){}};
+  function USE(arg, req){
+    return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){
+      arg(mod = {exports: {}});
+      USE[R(path)] = mod.exports;
+    }
+    function R(p){
+      return p.split('/').slice(-1).toString().replace('.js','');
+    }
+  }
+  if(typeof module !== "undefined"){ var common = module }
+
+	/* UNBUILD */
+	;USE(function(module){
+
+		var noop = function(){}, u;
+		$.fn.or = function(s){ return this.length ? this : $(s||'body') };
+		var m = window.meta = {edit:[]};
+		var k = m.key = {};
+		k.meta = {17:17, 91:17, 93:17, 224:17}; // ctrl met
+
+		function withMeta(eve){ return eve.metaKey || eve.ctrlKey }
+
+		k.down = function(eve){
+		  if(eve.repeat){ return }
+			var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
+
+			// ADDED
+			//if(!m.flip.is() && !k.meta[key]){ return } // cancel non-open events when closed TODO make optional
+			if(!k.meta[key] && withMeta(eve) && !k.at[key]) { return m.flip(false) } // cancel and close when no action and "meta key" held down (e.g. ctrl+c)
+
+			if(!eve.fake && key === k.last){ return }; k.last = key; // jussi: polyfilling eve.repeat?
+			if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length && !$(eve.target).closest('#meta').length){
+				if(!meta.flip.is() && !withMeta(eve)){ // cancel meta/hud during text input UNLESS hud is open OR cmd key is held down.
+					return;
+				}
+				//if(k.meta[key]){ k.down.meta = key = -1 }
+				//if(!k.down.meta){ return }
+				// hmmm?
+				//if(!k.meta[key] && !meta.flip.is()) return // aserwed
+			}
+			m.check('on', key, k.at || (k.at = m.edit));
+			if(k.meta[key]){
+		//		m.list(k.at.back || m.edit);
+		//		if(k.at){ m.flip() } //  && !k.at.back
+				m.flip()
+			}
 		}
-		(k.combo || (k.combo = [])).push(key);
-		m.check('on', key, k.at || (k.at = m.edit));
-		if(k.meta[key]){
-			m.list(k.at.back || m.edit);
-			if(k.at && !k.at.back){ m.flip() }
+		k.up = function(eve){ var tmp;
+			var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
+			//if(!m.flip.is() && !k.meta[key]){ return } // ADDED cancel non-open events when closed TODO make optional
+		//	if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
+		//		if(k.meta[key]){
+		//			k.down.meta = null;
+		//			key = -1;
+		//		} else
+		//		if(!k.down.meta){ return }
+		//	}
+			k.last = null;
+		//	if($(':focus').closest('#meta').length){ return }
+			m.check('up', key);
+			if(27 === eve.which){ k.wipe() } // -1 === key ||
 		}
-	}
-	k.up = function(eve){ var tmp;
-		var key = (k.eve = m.eve = eve).which = eve.which || eve.fake || eve.keyCode;
-		if(!eve.fake && $(eve.target).closest('input, textarea, [contenteditable=true]').length){
-			if(k.meta[key]){
-				k.down.meta = null;
-				key = -1;
-			} else
-			if(!k.down.meta){ return }
+		m.flip = function(tmp){
+			var board = $('#meta .meta-menu');
+			((tmp === false) || (!tmp && board.is(':visible')))?
+				board.addClass('meta-none')
+			: board.removeClass('meta-none');
 		}
-		k.last = null;
-		if($(':focus').closest('#meta').length){ return }
-		m.check('up', key);
-		if(-1 === key || 27 === eve.which){ k.wipe() }
-	}
-	m.flip = function(tmp){
-		var board = $('#meta .meta-menu');
-		((tmp === false) || (!tmp && board.is(':visible')))? 
-			board.addClass('meta-none')
-		: board.removeClass('meta-none');
-	}
-	m.flip.is = function(){
-		return $('#meta .meta-menu').is(':visible');
-	}
-	m.flip.wait = 500;
-	m.check = function(how, key, at){
-		at = k.at || m.edit;
-		var edit = at[key];
-		if(!edit){ return }
-		var tmp = k.eve || noop;
-		if(tmp.preventDefault){ tmp.preventDefault() }
-		if(edit[how]){
-			if(tmp.fake && !edit.fake){
-				m.tap.edit = edit;
-			} else {
-				edit[how](m.eve);
-				/*if(k.at !== m.edit && 'up' === how){
-					if(k.down.meta){ m.list(k.at = m.edit) }
-					else { k.wipe() }
-				}*/
+		m.flip.is = function(){
+			return $('#meta .meta-menu').is(':visible');
+		}
+		m.flip.wait = 500;
+		m.check = function(how, key, at){
+			at = k.at || m.edit;
+			var next = at[key];
+			if(!next){ return }
+			var tmp = k.eve || noop;
+			if(tmp.preventDefault){ tmp.preventDefault()} // prevent typing (etc) when action found
+			if(next[how]){
+				//if(tmp.fake && !next.fake){
+					//m.tap.next = next;
+				//} else {
+					next[how](m.eve);
+					meta.ui.blink()
+					/*if(k.at !== m.next && 'up' === how){
+						if(k.down.meta){ m.list(k.at = m.next) }
+						else { k.wipe() }
+					}*/
+				//}
 			}
+			if('up' == how){ return }
+			if(at != next){ next.back = at }
+			(k.combo || (k.combo = [])).push(key);
+			m.list(next, true);
 		}
-		if('up' != how){ return }
-		if(at != edit){ edit.back = at }
-		m.list(edit, true);
-	}
-	m.list = function(at, opt){
-		if(!at){ return m.flip(false) }
-		var l = [];
-		$.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) });
-		if(!l.length){ return }
-		k.at = at;
-		l = l.sort(function(a,b){
-			a = a.combo.slice(-1)[0] || 0;
-			if(a.length){ a = a.toUpperCase().charCodeAt(0) }
-			b = b.combo.slice(-1)[0] || 0;
-			if(b.length){ b = b.toUpperCase().charCodeAt(0) }
-			return (a < b)? -1 : 1;
-		});
-		var $ul = $('#meta .meta-menu ul')
-		$ul.children('li').addClass('meta-none').hide(); setTimeout(function(){ $ul.children('.meta-none').remove() },250); // necessary fix for weird bug glitch
-		$.each(l, function(i, k){
-			$ul.append($('<li>').text(k.name));
-		});
-		if(opt){ m.flip(true) }
-		$ul.append($('<li>').html('&larr;').one('click', function(){
-			m.list(k.at = at.back);
-		}));
-	}
-	m.ask = function(help, cb){
-		var $ul = $('#meta .meta-menu ul').empty();
-		var $put = $('<input>').attr('id', 'meta-ask').attr('placeholder', help);
-		var $form = $('<form>').append($put).on('submit', function(eve){ 
-			eve.preventDefault();
-			cb($put.val());
-			$li.remove();
-			k.wipe();
-		});
-		var $li = $('<li>').append($form);
-		$ul.append($li);
-		m.flip(true);
-		$put.focus();
-	}
-	k.wipe = function(opt){
-		k.down.meta = false;
-		k.combo = [];
-		if(!opt){ m.flip(false) }
-		m.list(k.at = m.edit);
-	};
-	m.tap = function(){
-		var on = $('.meta-on')
-			.or($($(document.querySelectorAll(':hover')).get().reverse()).first())
-			.or($(document.elementFromPoint(meta.tap.x, meta.tap.y)));
-		return on;
-	}
-	$(window).on('blur', k.wipe).on('focus', k.wipe);
-	$(document).on('mousedown mousemove mouseup', function(eve){
-		m.tap.eve = eve;
-		m.tap.x = eve.pageX||0;
-		m.tap.y = eve.pageY||0;
-		m.tap.on = $(eve.target);
-	}).on('mousedown touchstart', function(eve){
-		var tmp = m.tap.edit;
-		if(!tmp || !tmp.on){ return }
-		tmp.on(eve);
-		m.tap.edit = null;
-	});
-	$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true });
-	$(document).on('click', '#meta .meta-menu li', function(eve){
-		if(m.tap.stun){ return m.tap.stun = false }
-		if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return }
-		eve.tap = true;
-		k.down(eve);
-		k.up(eve);
-	});
-	$(document).on('keydown', k.down).on('keyup', k.up);
-	meta.edit = function(edit){
-		var tmp = edit.combow = [];
-		$.each(edit.combo || (edit.combo = []), function(i,k){
-			if(!k || !k.length){ if('number' == typeof k){ tmp.push(k) } return }
-			tmp.push(k.toUpperCase().charCodeAt(0));
-		});
-		var at = meta.edit, l = edit.combo.length;
-		$.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} });
-		edit.combow = edit.combow.join(',');
-		m.list(meta.edit);
-	}
-	$.fn.or = function(s){ return this.length ? this : $(s||'body') };
-	;(function(){try{
+		m.list = function(at, opt){
+			if(!at){ return m.flip(false) }
+		//	m.ui.depth(m.key.combo ? m.key.combo.length : 0)
+			var l = [];
+			$.each(at, function(i,k){ 'back' != i && k.combo && k.name && l.push(k) });
+			if(!l.length){ return }
+			k.at = at;
+			l = l.sort(function(a,b){
+				a = a.combo.slice(-1)[0] || 0;
+				if(a.length){ a = a.toUpperCase().charCodeAt(0) }
+				b = b.combo.slice(-1)[0] || 0;
+				if(b.length){ b = b.toUpperCase().charCodeAt(0) }
+				return (a < b)? -1 : 1;
+			});
+			var $ul = $('#meta .meta-menu ul')
+			$ul.children('li').addClass('meta-none').hide(); setTimeout(function(){ $ul.children('.meta-none').remove() },250); // necessary fix for weird bug glitch
+			$.each(l, function(i, k){
+				$ul.append($('<li>').text(k.name).data(k));
+			});
+			if(opt){ m.flip(true) }
+			$ul.append($('<li>').html('&larr;').on('click', function(){
+		//	  m.key.combo.pop()
+				m.list(at.back);
+			}));
+		}
+		m.ask = function(help, cb){
+			var $ul = $('#meta .meta-menu ul').empty();
+			var $put = $('<input>').attr('id', 'meta-ask').attr('placeholder', help);
+			var $form = $('<form>').append($put).on('submit', function(eve){
+				eve.preventDefault();
+				cb($put.val());
+				$li.remove();
+				//k.wipe();
+				m.list(k.at);
+			});
+			var $li = $('<li>').append($form);
+			$ul.append($li);
+			m.flip(true);
+			$put.focus();
+		}
+		k.wipe = function(opt){
+		//	k.down.meta = false;
+			k.combo = [];
+			if(!opt){ m.flip(false) }
+			m.list(k.at = m.edit);
+		};
+		m.tap = function(){
+			var on = $('.meta-on')
+				.or($($(document.querySelectorAll(':hover')).get().reverse()).first())
+				.or($(document.elementFromPoint(meta.tap.x||0, meta.tap.y||0)));
+			return on;
+		}
+		meta.edit = function(edit){
+			var tmp = edit.combow = [];
+			$.each(edit.combo || (edit.combo = []), function(i,k){
+				if(!k || !k.length){ if('number' == typeof k){ tmp.push(k) } return }
+				tmp.push(k.toUpperCase().charCodeAt(0));
+			});
+			var at = meta.edit, l = edit.combo.length;
+			$.each(tmp, function(i,k){ at = at[k] = (++i >= l)? edit : at[k] || {} });
+			edit.combow = edit.combow.join(',');
+			m.list(k.at || meta.edit);
+		}
+
+
+	})(USE, './metaCore');
+	;USE(function(module){
 		/* UI */
-		if(meta.css){ return }
+		meta.ui = {
+			blink: function(){ // hint visually that action has happened
+				$('#meta').css('transition', 'none').css('background', 'none')
+				setTimeout(function(){
+					$('#meta')[0].style.transition = null
+					$('#meta')[0].style.background = null
+				})
+			},
+			depth: function(n){
+			  if (n) {
+					$('#meta').css('background', 'hsl(60, 100%,'+(85-(n*10))+'%)');
+				} else {
+					$('#meta')[0].style.background = null
+				}
+			}
+		}
 		var $m = $('<div>').attr('id', 'meta');
-		$m.append($('<span>').text('+').addClass('meta-start'));
+		$m.append($('<span>').html('&#9776;').addClass('meta-start'));
 		$m.append($('<div>').addClass('meta-menu meta-none').append('<ul>'));
 		$(document.body).append($m);
 		css({
@@ -161,7 +196,7 @@
 				background: 'white',
 				'font-size': '18pt',
 				'font-family': 'Tahoma, arial',
-				'box-shadow': '0px 0px 1px #000044',
+				//'box-shadow': '0px 0px 1px #000044',
 				'border-radius': '1em',
 				'text-align': 'center',
 				'z-index': 999999,
@@ -202,25 +237,26 @@
 				'border-radius': '1em',
 				'margin-left': '0.25em',
 				'margin-top': '0.25em',
-				'float': 'right'
+				'float': 'right',
+				'cursor':  'pointer'
 			},
 			'#meta a': {color: 'black'},
-			'#meta:hover': {opacity: 1},
+		//	'#meta:hover': {opacity: 1},
 			'#meta .meta-menu ul:before': {
 				content: "' '",
 				display: 'block',
 				'min-height': '15em',
 				height: '50vh'
 			},
-			'#meta li': {
-				background: 'white',
-				padding: '0.5em 1em',
-				'border-radius': '1em',
-				'margin-left': '0.25em',
-				'margin-top': '0.25em',
-				'float': 'right'
-			},
-			'#meta:hover .meta-menu': {display: 'block'}
+		//	'#meta li': {
+		//		background: 'white',
+		//		padding: '0.5em 1em',
+		//		'border-radius': '1em',
+		//		'margin-left': '0.25em',
+		//		'margin-top': '0.25em',
+		//		'float': 'right'
+		//	},
+		//	'#meta:hover .meta-menu': {display: 'block'}
 		});
 		function css(css){
 			var tmp = '';
@@ -233,10 +269,14 @@
 			});
 			var tag = document.createElement('style');
 			tag.innerHTML = tmp;
-			document.body.appendChild(tag);
+			$m.append(tag)
 		}
-	}catch(e){}}());
-	;(function(){
+		//}catch(e){}
+
+
+	})(USE, './metaUI');
+	;USE(function(module){
+
 		// include basic text editing by default.
 		var monotype = window.monotype || function(){console.log("monotype needed")};
 		var m = meta;
@@ -256,7 +296,6 @@
 			return ((tmp = window.getSelection) && tmp().toString()) ||
 				((tmp = document.selection) && tmp.createRange().text) || '';
 		}
-		$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
 		m.text.editor = function(opt, as){ var tmp;
 			if(!opt){ return }
 			opt = (typeof opt == 'string')? {edit: opt} : opt.tag? opt : {tag: opt};
@@ -266,7 +305,7 @@
 				r.restore();
 				if(document.execCommand(cmd, null, as||null)){
 					if(m.text.range){ m.text.range = monotype() }
-					return;
+					return meta.flip(false); // ADDED meta.flip
 				}
 			}
 			if(!opt.tag){ return }
@@ -379,5 +418,54 @@
 			on: function(eve){ meta.text.editor('fontSize', 7) },
 			up: function(){}
 		});
-	}());
+
+
+	})(USE, './metaText');
+	;USE(function(module){
+		var m = meta, k = m.key;
+		$(window).on('focus', k.wipe.bind(null, false)); // .on('blur', k.wipe.bind(null, false))
+		$(document).on('mousedown mousemove mouseup', function(eve){
+			m.tap.eve = eve;
+			m.tap.x = eve.pageX||0;
+			m.tap.y = eve.pageY||0;
+			m.tap.on = $(eve.target);
+		})
+		// Setting m.tap.edit has been commented, so should never end up here?
+		//.on('mousedown touchstart', function(eve){
+		//	var tmp = m.tap.edit;
+		//	if(!tmp || !tmp.on){ return }
+		//	tmp.on(eve);
+		//	m.tap.edit = null;
+		//});
+
+		//$(document).on('touchstart', '#meta .meta-start', function(eve){ m.tap.stun = true });
+
+		var [start, end] = 'ontouchstart' in window
+												? ['touchstart', 'touchend']
+												: ['mousedown', 'mouseup']
+
+		$(document).on(start, '#meta .meta-menu li', function(eve){
+			var combo = $(this).data().combo;
+			eve.fake = eve.which = combo && combo.slice(-1)[0].charCodeAt(0);
+			eve.tap = true;
+			k.down(eve);
+			$(document).one(end, () => k.up(eve))
+		return;
+		//	if(m.tap.stun){ return m.tap.stun = false }
+		//	if(!(eve.fake = eve.which = (($(this).text().match(/[A-Z]/)||{})[0]||'').toUpperCase().charCodeAt(0))){ return }
+		//	eve.tap = true;
+		//	k.down(eve);
+		//	k.up(eve);
+		});
+		$(document).on('keydown', k.down).on('keyup', k.up);
+
+		$('#meta').on('click', function(ev) {
+		  if (ev.target.tagName == 'LI' || ev.target.tagName == 'UL') return
+			meta.flip()
+		})
+
+		//$(document).on('select contextmenu keyup mouseup', '[contenteditable=true]', m.text.on);
+
+
+	})(USE, './metaEvents');
 }());

+ 5 - 1
public/lib/gundb/lib/multicast.js

@@ -19,7 +19,11 @@ Gun.on('create', function(root){
 
   try{ dgram = require("dgram") }catch(e){ return }
   var socket = dgram.createSocket({type: "udp4", reuseAddr: true});
-  socket.bind(udp.port);
+  socket.bind({port: udp.port, exclusive: true}, function(){
+    socket.setBroadcast(true);
+    socket.setMulticastTTL(128);
+    try{ socket.addMembership(udp.address); }catch(e){}
+  });
 
   socket.on("listening", function(){
     try { socket.addMembership(udp.address) }catch(e){ return }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 290 - 0
public/lib/gundb/lib/music.js


+ 2 - 1
public/lib/gundb/lib/normalize.js

@@ -1,7 +1,8 @@
 (function(){
 
   $.normalize = function(html, customOpt){
-    var html, root$, wrapped, opt;
+    html = html || '';
+    var root$, wrapped, opt;
     opt = html.opt || (customOpt ? prepareOptTags($.extend(true, baseOpt, customOpt))
                                  : defaultOpt);
     if(!html.opt){

+ 4 - 0
public/lib/gundb/lib/promise.js

@@ -11,6 +11,10 @@
 * Author: Jachen Duschletta / 2019
 */
 
+// Get window or node Gun instance
+
+var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
+
 /*
 * Function promOnce
 * @param limit - due to promises resolving too fast if we do not set a timer

+ 17 - 16
public/lib/gundb/lib/radisk.js

@@ -19,7 +19,7 @@
 		function ename(t){ return encodeURIComponent(t).replace(/\*/g, '%2A') }
 		function atomic(v){ return u !== v && (!v || 'object' != typeof v) }
 		var map = Gun.obj.map;
-		var LOG = false;
+		var LOG = console.LOG;
 
 		if(!opt.store){
 			return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
@@ -46,7 +46,7 @@
 				cb = val;
 				var S; LOG && (S = +new Date);
 				val = r.batch(key);
-				LOG && console.log(+new Date - S, 'rad mem');
+				LOG && opt.log(S, +new Date - S, 'rad mem');
 				if(u !== val){
 					cb(u, r.range(val, o), o);
 					if(atomic(val)){ return }
@@ -77,6 +77,7 @@
 		r.thrash = function(){
 			var thrash = r.thrash;
 			if(thrash.ing){ return thrash.more = true }
+			LOG = console.LOG; // dirty place to cheaply update LOG settings over time.
 			thrash.more = false;
 			thrash.ing = true;
 			var batch = thrash.at = r.batch, i = 0;
@@ -174,9 +175,9 @@
 			}
 			f.write = function(){
 				var tmp = ename(file);
-				var start; LOG && (start = +new Date); // comment this out!
+				var S; LOG && (S = +new Date);
 				opt.store.put(tmp, f.text, function(err){
-					LOG && console.log("wrote to disk in", (+new Date) - start, tmp); // comment this out!
+					LOG && opt.log(S, +new Date - S, "wrote disk", tmp);
 					if(err){ return cb(err) }
 					r.list.add(tmp, cb);
 				});
@@ -205,10 +206,10 @@
 
 		r.write.jsonify = function(f, file, rad, cb, o){
 			var raw;
-			var start; LOG && (start = +new Date); // comment this out!
+			var S; LOG && (S = +new Date);
 			try{raw = JSON.stringify(rad.$);
 			}catch(e){ return cb("Record too big!") }
-			LOG && console.log("stringified JSON in", +new Date - start); // comment this out!
+			LOG && opt.log(S, +new Date - S, "rad stringified JSON");
 			if(opt.chunk < raw.length && !o.force){
 				if(Radix.map(rad, f.each, true)){ return }
 			}
@@ -234,7 +235,7 @@
 				if(RAD && !o.next){ // cache
 					var S; LOG && (S = +new Date);
 					var val = RAD(key);
-					LOG && console.log(+new Date - S, 'rad cached');
+					LOG && opt.log(S, +new Date - S, 'rad cached');
 					//if(u !== val){
 						//cb(u, val, o);
 						if(atomic(val)){ cb(u, val, o); return }
@@ -247,7 +248,7 @@
 					file = (u === file)? u : decodeURIComponent(file);
 					tmp = o.next || key || (o.reverse? o.end || '\uffff' : o.start || '');
 					if(!file || (o.reverse? file < tmp : file > tmp)){
-						LOG && console.log(+new Date - S, 'rad read lex'); S = +new Date;
+						LOG && opt.log(S, +new Date - S, 'rad read lex'); S = +new Date;
 						if(o.next || o.reverse){ g.file = file }
 						if(tmp = Q[g.file]){
 							tmp.push({key: key, ack: cb, file: g.file, opt: o});
@@ -268,9 +269,9 @@
 					g.info = info;
 					if(disk){ RAD = g.disk = disk }
 					disk = Q[g.file]; delete Q[g.file];
-					LOG && console.log(+new Date - S, 'rad read it in, now ack to:', disk.length); S = +new Date;
+					LOG && opt.log(S, +new Date - S, 'rad read in, ack', disk.length); S = +new Date;
 					map(disk, g.ack);
-					LOG && console.log(+new Date - S, 'rad read acked');
+					LOG && opt.log(S, +new Date - S, 'rad read acked');
 				}
 				g.ack = function(as){
 					if(!as.ack){ return }
@@ -315,7 +316,7 @@
 				var p = function Parse(){}, info = {};
 				p.disk = Radix();
 				p.read = function(err, data){ var tmp;
-					LOG && console.log('read disk in', +new Date - S, ename(file)); // keep this commented out in 
+					LOG && opt.log(S, +new Date - S, 'read disk', ename(file));
 					delete Q[file];
 					if((p.err = err) || (p.not = !data)){
 						return map(q, p.ack);
@@ -332,12 +333,12 @@
 					}
 					info.parsed = data.length;
 
-					LOG && (S = +new Date); // keep this commented out in production!
+					LOG && (S = +new Date);
 					if(opt.jsonify || '{' === data[0]){ // temporary testing idea
 						try{
 							var json = JSON.parse(data);
 							p.disk.$ = json;
-							LOG && console.log('parsed JSON in', +new Date - S); // keep this commented out in production!
+							LOG && opt.log(S, +new Date - S, 'rad parsed JSON');
 							map(q, p.ack);
 							return;
 						}catch(e){ tmp = e }
@@ -346,7 +347,7 @@
 							return map(q, p.ack);
 						}
 					}
-					LOG && (S = +new Date); // keep this commented out in production!
+					LOG && (S = +new Date);
 					var tmp = p.split(data), pre = [], i, k, v;
 					if(!tmp || 0 !== tmp[1]){
 						p.err = "File '"+file+"' does not have root radix! ";
@@ -369,7 +370,7 @@
 						if(u !== k && u !== v){ p.disk(pre.join(''), v) }
 						tmp = p.split(tmp[2]);
 					}
-					LOG && console.log('parsed RAD in', +new Date - S); // keep this commented out in production!
+					LOG && opt.log(S, +new Date - S, 'parsed RAD');
 					//cb(err, p.disk);
 					map(q, p.ack);
 				};
@@ -389,7 +390,7 @@
 					if(p.err || p.not){ return cb(p.err, u, info) }
 					cb(u, p.disk, info);
 				}
-				var S; LOG && (S = +new Date); // keep this commented out in production!
+				var S; LOG && (S = +new Date);
 				if(raw){ return p.read(null, raw) }
 				opt.store.get(ename(file), p.read);
 			}

+ 2 - 0
public/lib/gundb/lib/server.js

@@ -2,10 +2,12 @@
 	var Gun = require('../gun'), u;
 	Gun.serve = require('./serve');
 	//process.env.GUN_ENV = process.env.GUN_ENV || 'debug';
+	console.LOG = true; // only temporarily, REVERT THIS IN FUTURE!
 	Gun.on('opt', function(root){
 		if(u === root.opt.super){
 			root.opt.super = true;
 		}
+		root.opt.log = root.opt.log || Gun.log;
 		this.to.next(root);
 	})
 	require('../nts');

+ 13 - 0
public/lib/gundb/lib/stats.js

@@ -5,6 +5,7 @@ Gun.on('opt', function(root){
 	if(root.once){ return }
 	if(typeof process === 'undefined'){ return }
 	if(typeof require === 'undefined'){ return }
+	if(false === root.opt.stats){ return }
 	var noop = function(){};
 	var os = require('os') || {};
 	var fs = require('fs') || {};
@@ -39,6 +40,7 @@ Gun.on('opt', function(root){
 		stats.peers.count = Object.keys(root.opt.peers||{}).length;
 		stats.node = {};
 		stats.node.count = Object.keys(root.graph||{}).length;
+		stats.all = all;
 		var dam = root.opt.mesh;
 		if(dam){
 			stats.dam = {'in': {count: dam.hear.c, done: dam.hear.d, long: dam.hear.long}, 'out': {count: dam.say.c, done: dam.say.d}};
@@ -57,3 +59,14 @@ Gun.on('opt', function(root){
 	}, 1000 * 15);
 	Object.keys = Object.keys || function(o){ return Gun.obj.map(o, function(v,k,t){t(k)}) }
 });
+
+
+var log = Gun.log, all = {}, max = 1000;
+Gun.log = function(a,b,c,d){
+	if('number' == typeof a && 'number' == typeof b && 'string' == typeof c){
+		var tmp = (all[c] || (all[c] = []));
+		if(max < tmp.push([a,b])){ all[c] = [] } // reset
+		//return;
+	}
+	return log.apply(Gun, arguments);
+}

+ 17 - 12
public/lib/gundb/lib/store.js

@@ -1,5 +1,5 @@
 var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
- 
+
 Gun.on('create', function(root){
     if(Gun.TESTING){ root.opt.file = 'radatatest' }
     this.to.next(root);
@@ -7,6 +7,7 @@ Gun.on('create', function(root){
     if(false === opt.radisk){ return }
     var Radisk = (Gun.window && Gun.window.Radisk) || require('./radisk');
     var Radix = Radisk.Radix;
+    var LOG = console.LOG;
  
     opt.store = opt.store || (!Gun.window && require('./rfs')(opt));
     var rad = Radisk(opt), esc = String.fromCharCode(27);
@@ -30,12 +31,12 @@ Gun.on('create', function(root){
             val = Radisk.encode(val, null, esc)+'>'+Radisk.encode(Gun.state.is(node, key), null, esc);
             rad(soul+esc+key, val, (track? ack : u));
         });
-        //console.log(+new Date - S, 'put loop');
+        LOG && Gun.log(S, +new Date - S, 'put loop');
         function ack(err, ok){
             acks--;
             if(ack.err){ return }
             if(ack.err = err){
-                try{opt.store.stats.put.err = err}catch(e){} // STATS!
+                //Gun.log(); //try{opt.store.stats.put.err = err}catch(e){} // STATS!
                 root.on('in', {'@': id, err: err});
                 return;
             }
@@ -45,7 +46,7 @@ Gun.on('create', function(root){
             }catch(e){} // STATS!
             //console.log(+new Date - S, 'put'); S = +new Date;
             root.on('in', {'@': id, ok: 1});
-            //console.log(+new Date - S, 'put sent');
+            //console.log(S, +new Date - S, 'put sent');
         }
     });
  
@@ -77,10 +78,14 @@ Gun.on('create', function(root){
             o.limit = (tmp <= (o.pack || (1000 * 100)))? tmp : 1;
         }
         if(has['-'] || (soul||{})['-']){ o.reverse = true }
-        if(tmp = (root.next||empty)[soul]){
-            if(tmp && tmp.rad){ return }
-            if(o.atom){ tmp = (tmp.next||empty)[o.atom] }
-            if(tmp && tmp.rad){ return }
+        if((tmp = (root.next||empty)[soul]) && tmp.put){
+            if(o.atom){
+                tmp = (tmp.next||empty)[o.atom] ;
+                if(tmp && tmp.rad){ return }
+            } else
+            if(tmp && tmp.rad){
+                return;
+            }
         }
         var S = (+new Date); // STATS!
         rad(key||'', function(err, data, o){
@@ -89,7 +94,7 @@ Gun.on('create', function(root){
                 if(err){ opt.store.stats.get.err = err }
             }catch(e){} // STATS!
             //if(u === data && o.chunks > 1){ return } // if we already sent a chunk, ignore ending empty responses. // this causes tests to fail.
-            //console.log(+new Date - S, 'got'); S = +new Date;
+            LOG && Gun.log(S, +new Date - S, 'got'); S = +new Date; // MARK RETURN HERE!!!! Gun.log will always log unless off :/ switch to something like LOG && whatever?
             if(data){
                 if(typeof data !== 'string'){
                     if(o.atom){
@@ -100,11 +105,10 @@ Gun.on('create', function(root){
                 }
                 if(!graph && data){ each(data, '') }
             }
-            //console.log(+new Date - S, 'got prep'); S = +new Date;
+            LOG && Gun.log(S, +new Date - S, 'got prep');
             root.on('in', {'@': id, put: graph, '%': o.more? 1 : u, err: err? err : u, _: each});
-            //console.log(+new Date - S, 'got sent');
         }, o);
-        //console.log(+new Date - S, 'get call');
+        LOG && Gun.log(S, +new Date - S, 'get call');
         function each(val, has, a,b){
             if(!val){ return }
             has = (key+has).split(esc);
@@ -118,6 +122,7 @@ Gun.on('create', function(root){
             if(o.limit && o.limit <= o.count){ return true }
         }
         each.rad = get;
+        LOG = console.LOG;
     });
     opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // STATS!
     var statg = 0, statp = 0; // STATS!

+ 0 - 272
public/lib/gundb/lib/tmp.test.sql.js

@@ -1,272 +0,0 @@
-(function(){
-	if(!this.Gun){ return }
-	function Test(o){
-		var test = this;
-		if(!(test instanceof Test)){ return new Test(o) }
-		test._ = {};
-		test._.stack = [];
-		return test;
-	}
-	Test.chain = Test.prototype;
-	Test.chain.run = function(fn){
-		var test = this;
-		var e = test._.i, i = 0;
-		var stack = test._.stack;
-		stack.push(fn);
-		//var to = setInterval(function(){ if(++i >= e){ return clearTimeout(to) }
-		var start = Gun.time.is();
-		while(++i <= e){
-			Gun.list.map(stack, function(fn){ (fn||function(){})(i) })
-		}
-		console.log((Gun.time.is() - start) / 1000);
-		//},0);
-		return test;
-	}
-	Test.chain.it = function(i){
-		var test = this;
-		test._.i = i || 1000;
-		return test;
-	}
-	Test.chain.gen = function(fn){
-		var test = this;
-		test._.stack.push(fn);
-		return test;
-	}
-	var gun = window.gun = Gun();
-	window.SPAM = function(read){ // TODO: BUG? gun-sid in transport layer not correct?
-		//localStorage.clear();
-		var start = Gun.time.is();
-		/*var mark = {
-			name: "Mark Nadal"
-		};
-		var amber = {
-			name: "Amber Nadal",
-			spouse: mark
-		}
-		mark.spouse = amber;
-		amber.pet = {
-			name: "Fluffy",
-			slave: mark
-		}
-		Test().it(read).gen(function(i){
-			Gun.ify(mark);
-		}).run();return;*/
-		Test().it(read).gen(function(i){
-			gun.get('users').path(i).path('where').put({lat: Math.random(), lng: Math.random(),i:i});
-		}).run();return;
-		Test().it(read === true? 1 : read || 1000).gen(function(i){
-			if(read === true){
-				gun.get('users').map().path('where').on(function(node){
-					console.log("node:", node);
-					if(node.i === (1000)){
-						console.log("total:", Gun.time.is() - start);
-						start = Gun.time.is();
-					}
-				});
-				return;
-			}
-			// PUT, GET, PATH, ON
-			var now = Gun.time.is();
-			/*var obj = {'i': i, 'v': Gun.text.random(100)};
-			gun.put(obj, function(err, ok){
-				//console.log("put done", i, 'in', Gun.time.is() - now);//, i % 1000);
-				if(i % (1000) === 0){
-					console.log("total:", Gun.time.is() - start);
-					start = Gun.time.is();
-				}
-			});return;*/
-			gun.get('users').path(i).path('where').put({
-				lat: Math.random(),lng: Math.random(),i: i
-				//lol: i / 2
-			}, function(err, ok){
-				console.log("put done", i, 'in', Gun.time.is() - now);//, i % 1000);
-				if(i % (1000) === 0){
-					console.log("total:", Gun.time.is() - start);
-					start = Gun.time.is();
-				}
-			});return;
-		}).run(function(){});
-	}
-	//window.SPAM(1000000);
-}());
-/* EXTRA GUN UTILITY FUNCTIONS I MIGHT WANT TO KEEP
-(function(){
-	Gun().get('chat').path('messages').since(Gun().get('me').path('last')).map().val(function(msg){
-
-	});
-	Gun().get('chat').path('messages').last(100).map().val(function(msg){
-	});
-
-var peers = [
-    peer1,
-    peer2
-];
-
-Gun.on('put').event(function(graph, cb, opt){
-	Gun.is.graph(graph, function(node, soul){
-		localStorage[soul] = node;
-	});
-});
-Gun.on('put').event(function(graph, cb, opt){
-	Peers(opt.peers).send({
-		id: MsgID,
-    value: data,
-    from: myPeerID
-  }, cb);
-});
-
-Gun.on('get').event(function(lex, cb, opt){
-	Peers(opt.peers || peers).send({
-    '#': MsgID,
-    '$': lex,
-    '~': myPeerID
-  }, cb);
-});
-
-Peers.server(function(req, res){
-	if(Msg.IDs[req.id]){ return } // throttle
-	// auth
-	Peers(peers).send(req); // relay
-	// auth
-	if(req.rid){ return } // ignore
-	if(req.put && opt.everything || graph[for soul in req.body]){ // process
-		Gun.put(gun, req.body, REPLY);
-	}
-});
-
-// TODO: MARK / JESSE need to solve infinite circular loop on get flushing and put flushing.
-
-GUN = {'#': 'soul', '.': 'field', '=': 'value', '>': 'state'}
-MSG = {'#': 'id', '$': 'body', '@': 'to'}
-
-Gun.wire = function(data){
-
-}
-Gun.get.wire = function(lex, cb, opt){ return Gun.text.is(lex)? Gun.get.wire.from(lex, cb, opt) : Gun.get.wire.to(lex, cb, opt) }
-Gun.get.wire.to = function(lex, cb, opt){
-	var t = '';
-	Gun.obj.map(lex, function(v,f){
-		if(!v){ return }
-		Gun.list.map(Gun.list.is(v)? v : [v], function(v){
-			t += f + "'" + Gun.put.wire.ify(v) + "'";
-		});
-	});
-	return t + '?';
-}
-Gun.get.wire.from = function(t, cb, opt){
-	if(!t){ return null }
-	var a = Gun.put.wire.from.parse(t), lex = {};
-	Gun.list.map([Gun._.soul, Gun._.field, Gun._.value, Gun._.state], function(sym, i){
-		if(!(i = a.indexOf(sym) + 1)){ return }
-		lex[sym] = Gun.put.wire.type(a[i]);
-	});
-	return lex;
-}
-// #soul.field
-// "#soul.field=value>state"
-// #messages>>1234567890 //{soul: 'messages', state: {'>': 1234567890}}
-// #id$"msg"~who@to
-
-Gun.put.wire = function(n, cb, opt){ return Gun.text.is(n)? Gun.put.wire.from(n, cb, opt) : Gun.put.wire.to(n, cb, opt) }
-Gun.put.wire.ify = function(s){ var tmp;
-	if(Infinity === s || -Infinity === s){ return s }
-	if(tmp = Gun.is.rel(s)){ return '#' + JSON.stringify(tmp) }
-	return JSON.stringify(s)
-}
-Gun.put.wire.type = function(s){ var tmp;
-	if(Gun._.soul === s.charAt(0)){ return Gun.is.rel.ify(JSON.parse(s.slice(1))) }
-	if(String(Infinity) === s){ return Infinity }
-	if(String(-Infinity) === s){ return -Infinity }
-	return JSON.parse(s) 
-}
-Gun.put.wire.to = function(n, cb, opt){ var t, b;
-	if(!n || !(t = Gun.is.node.soul(n))){ return null }
-	cb = cb || function(){};
-	t = (b = "#'" + Gun.put.wire.ify(t) + "'");
-	var val = function(v,f, nv,nf){
-		var w = '', s = Gun.is.node.state(n,f), sw = '';
-		if(!s){ return }
-		w += ".'" + Gun.put.wire.ify(f) + "'";
-		console.log("yeah value?", v, Gun.put.wire.ify(v));
-		w += "='" + Gun.put.wire.ify(v) + "'";
-		if(s !== Gun.is.node.state(n,nf)){
-			w += ">'" + Gun.put.wire.ify(s) + "'";
-		} else {
-			sw = ">'" + Gun.put.wire.ify(s) + "'";
-		}
-		t += w;
-		w = b + w + sw;
-		cb(null, w);
-	}
-	var next = function(v,f){ // TODO: BUG! Missing adding meta data.
-		if(Gun._.meta === f){ return }
-		if(next.f){ 
-			val(next.v, next.f, v,f);
-		}
-		next.f = f;
-		next.v = v;
-	}
-	Gun.obj.map(n, next);
-	next();
-	return t;
-}
-Gun.put.wire.from = function(t, cb, opt){
-	if(!t){ return null }
-	var a = Gun.put.wire.from.parse(t);
-	Gun.list.map(a, function(v, i){
-		if(Gun._.soul === v){
-			Gun.is.node.soul.ify(n, Gun.put.wire.type(a[i]));
-			return;
-		}
-		if(Gun._.field === v){
-			var val = a.indexOf(Gun._.value,i), state = a.indexOf(Gun._.state,i);	
-			Gun.is.node.state.ify([n], Gun.put.wire.type(a[i]), Gun.put.wire.type(a[val+1]), Gun.put.wire.type(a[state+1]));
-			return;
-		}
-	})
-	return n;
-}
-Gun.put.wire.from.parse = function(t){
-	var a = [], s = -1, e = 0, end = 1, n = {};
-	while((e = t.indexOf("'", s + 1)) >= 0){
-		if(s === e || '\\' === t.charAt(e-1)){}else{
-			a.push(t.slice(s + 1,e));
-			s = e;
-		}
-	}
-	return a;
-}
-}());
-*/
-
-;(function(){ // make as separate module!
-	function SQL(){}
-	SQL.select = function(sel){
-		this._.sql.select = sel;
-		return this;
-	}
-	SQL.from = function(from){
-		this._.sql.from = from;
-		//this.get(from).map();
-		return this;
-	}
-	SQL.where = function(where){
-		this._.sql.where = where;
-		return this;
-	}
-	Gun.chain.sql = function(sql){
-		var gun = this;//.chain();
-		sql = gun._.sql = sql || {};
-		gun.select = SQL.select;
-		gun.from = SQL.from;
-		gun.where = SQL.where;
-		return gun;
-	}
-
-	Gun.on('chain').event(function(gun, at){
-		console.log("sql stuff?", gun._, at.node);
-		var query = gun._.sql;
-		if(!query){ return }
-		var node = at.node;
-	});
-}());

+ 15 - 6
public/lib/gundb/sea.js

@@ -190,8 +190,8 @@
         //console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
       //}
     }catch(e){
-      console.log("node-webcrypto-ossl and text-encoding may not be included by default, please add it to your package.json!");
-      OSSL_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED;
+      console.log("text-encoding and @peculiar/webcrypto may not be included by default, please add it to your package.json!");
+      TEXT_ENCODING_OR_PECULIAR_WEBCRYPTO_NOT_INSTALLED;
     }}
 
     module.exports = api
@@ -964,6 +964,7 @@
     }
     // If authenticated user wants to delete his/her account, let's support it!
     User.prototype.delete = async function(alias, pass, cb){
+      console.log("user.delete() IS DEPRECATED AND WILL BE MOVED TO A MODULE!!!");
       var gun = this, root = gun.back(-1), user = gun.back('user');
       try {
         user.auth(alias, pass, function(ack){
@@ -1005,6 +1006,7 @@
       return gun;
     }
     User.prototype.alive = async function(){
+      console.log("user.alive() IS DEPRECATED!!!");
       const gunRoot = this.back(-1)
       try {
         // All is good. Should we do something more with actual recalled data?
@@ -1024,25 +1026,32 @@
           console.log(ctx, ev)
         })
       }
+      user.get('trust').get(path).put(theirPubkey);
+
+      // do a lookup on this gun chain directly (that gets bob's copy of the data)
+      // do a lookup on the metadata trust table for this path (that gets all the pubkeys allowed to write on this path)
+      // do a lookup on each of those pubKeys ON the path (to get the collab data "layers")
+      // THEN you perform Jachen's mix operation
+      // and return the result of that to...
     }
     User.prototype.grant = function(to, cb){
       console.log("`.grant` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");
-      var gun = this, user = gun.back(-1).user(), pair = user.pair(), path = '';
+      var gun = this, user = gun.back(-1).user(), pair = user._.sea, path = '';
       gun.back(function(at){ if(at.is){ return } path += (at.get||'') });
       (async function(){
-      var enc, sec = await user.get('trust').get(pair.pub).get(path).then();
+      var enc, sec = await user.get('grant').get(pair.pub).get(path).then();
       sec = await SEA.decrypt(sec, pair);
       if(!sec){
         sec = SEA.random(16).toString();
         enc = await SEA.encrypt(sec, pair);
-        user.get('trust').get(pair.pub).get(path).put(enc);
+        user.get('grant').get(pair.pub).get(path).put(enc);
       }
       var pub = to.get('pub').then();
       var epub = to.get('epub').then();
       pub = await pub; epub = await epub;
       var dh = await SEA.secret(epub, pair);
       enc = await SEA.encrypt(sec, dh);
-      user.get('trust').get(pub).get(path).put(enc, cb);
+      user.get('grant').get(pub).get(path).put(enc, cb);
       }());
       return gun;
     }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio