From cc38e510ebfb386aeec626b49af4073c2a0e31ef Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 21 Aug 2023 10:17:36 +0200 Subject: [PATCH] Use console.warn, console.error --- as.js | 4 ++-- examples/react-native/src/extensions/sea.js | 2 +- examples/vanilla/video.html | 2 +- gun.js | 14 ++++++++------ gun.min.js | 2 +- lib/book.js | 2 +- lib/radisk.js | 10 ++++++---- lib/radisk2.js | 10 ++++++---- lib/radisk3.js | 2 +- lib/radmigtmp.js | 2 +- lib/rfs.js | 5 +++-- lib/rindexed.js | 6 +++--- lib/rs3.js | 2 +- lib/super.js | 2 +- src/localStorage.js | 2 +- src/mesh.js | 8 +++++--- src/root.js | 15 +++++++++++---- test/common.js | 4 ++-- test/panic/scale.js | 2 +- test/panic/speak.js | 2 +- test/sea/sea.js | 2 +- test/trace.js | 2 +- 22 files changed, 59 insertions(+), 43 deletions(-) diff --git a/as.js b/as.js index 9be7c337f..407a1e18d 100644 --- a/as.js +++ b/as.js @@ -211,7 +211,7 @@ $.as.route(location.hash.slice(1)); $(JOY.start = JOY.start || function(){ $.as(document, gun, null, JOY.opt) }); - if($('body').attr('peers')){ (console.warn || console.log)('Warning: Please upgrade to https://github.com/eraeco/joydb#peers !') } + if($('body').attr('peers')){ console.warn('Please upgrade to https://github.com/eraeco/joydb#peers !') } }); ;(function(){ // need to isolate into separate module! @@ -228,7 +228,7 @@ var opt = joy.opt = window.CONFIG || {}, peers; $('link[type=peer]').each(function(){ (peers || (peers = [])).push($(this).attr('href')) }); !window.gun && (opt.peers = opt.peers || peers || (function(){ - (console.warn || console.log)('Warning: No peer provided, defaulting to DEMO peer. Do not run in production, or your data will be regularly wiped, reset, or deleted. For more info, check https://github.com/eraeco/joydb#peers !'); + console.warn('No peer provided, defaulting to DEMO peer. Do not run in production, or your data will be regularly wiped, reset, or deleted. For more info, check https://github.com/eraeco/joydb#peers !'); return ['https://gunjs.herokuapp.com/gun']; }())); window.gun = window.gun || Gun(opt); diff --git a/examples/react-native/src/extensions/sea.js b/examples/react-native/src/extensions/sea.js index b99397d9b..0949052bb 100644 --- a/examples/react-native/src/extensions/sea.js +++ b/examples/react-native/src/extensions/sea.js @@ -894,7 +894,7 @@ (cb || noop)({ok: 0}); }); } catch (e) { - Gun.log('User.delete failed! Error:', e); + Gun.error('User.delete failed! Error:', e); } return gun; } diff --git a/examples/vanilla/video.html b/examples/vanilla/video.html index 261aae44d..07aad2116 100644 --- a/examples/vanilla/video.html +++ b/examples/vanilla/video.html @@ -37,7 +37,7 @@ record.ing.start() } - function error(err) { console.log(err) } + function error(err) { console.error(err) } if (type === 'Camera') { navigator.getMedia({ video: true, audio: true }, load, error) diff --git a/gun.js b/gun.js index b1f3680e6..bf6c386aa 100644 --- a/gun.js +++ b/gun.js @@ -436,7 +436,7 @@ var ERR = "Error: Invalid graph!"; var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " } var L = JSON.stringify, MD = 2147483647, State = Gun.state; - var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; + var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; }()); @@ -1380,12 +1380,14 @@ var noop = function(){} var parse = JSON.parseAsync || function(t,cb,r){ var u, d = +new Date; try{ cb(u, JSON.parse(t,r), json.sucks(+new Date - d)) }catch(e){ cb(e) } } var json = JSON.stringifyAsync || function(v,cb,r,s){ var u, d = +new Date; try{ cb(u, JSON.stringify(v,r,s), json.sucks(+new Date - d)) }catch(e){ cb(e) } } - json.sucks = function(d){ if(d > 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } + json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } function Mesh(root){ var mesh = function(){}; var opt = root.opt || {}; opt.log = opt.log || console.log; + opt.warn = opt.warn || console.warn; + opt.error = opt.error || console.error; opt.gap = opt.gap || opt.wait || 0; opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; opt.pack = opt.pack || (opt.max * 0.01 * 0.01); @@ -1619,7 +1621,7 @@ if(!tmp){ return } if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^ if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); - }catch(e){return opt.log('DAM JSON stringify error', e)}} + }catch(e){return opt.error('DAM JSON stringify error', e)}} if(!tmp){ return } send(tmp, peer); } @@ -1667,7 +1669,7 @@ var tmp = +(new Date); tmp = (tmp - (peer.met||tmp)); mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2; } - mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } + mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) } mesh.hear['?'] = function(msg, peer){ if(msg.pid){ if(!peer.pid){ peer.pid = msg.pid } @@ -1794,7 +1796,7 @@ var noop = function(){}, store, u; try{store = (Gun.window||noop).localStorage}catch(e){} if(!store){ - Gun.log("Warning: No localStorage exists to persist data to!"); + Gun.warn("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]}}; } @@ -1862,7 +1864,7 @@ ;(function(){ var u; if(''+u == typeof Gun){ return } - var DEP = function(n){ console.warn("Warning! Deprecated internal utility will break in next version:", n) } + var DEP = function(n){ console.warn("Deprecated internal utility will break in next version:", n) } // Generic javascript utilities. var Type = Gun; //Type.fns = Type.fn = {is: function(fn){ return (!!fn && fn instanceof Function) }} diff --git a/gun.min.js b/gun.min.js index 83be95946..bf24ea357 100644 --- a/gun.min.js +++ b/gun.min.js @@ -1 +1 @@ -!function(){function T(e,t){return t?require(e):e.slice?T[o(e)]:function(t,n){e(t={exports:{}}),T[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}var n;"undefined"!=typeof module&&(n=module),T(function(t){String.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},String.hash=function(t,n){if("string"==typeof t){if(n=n||0,!t.length)return n;for(var e=0,o=t.length;e=s.now()-i&&r++<3333?t():a(function(){i=s.now(),t()},r=0)},g=setTimeout,f=(c=g.turn=g.turn||function(t){1==f.push(t)&&l(p)}).s=[],l=g.poll,h=0,p=function(){(u=f[h++])&&u(),h!=f.length&&99!=h||(f=c.s=f.slice(h),h=0),f.length&&l(p)},g=setTimeout,v=g.turn,(g.each=g.each||function(r,a,s,u){u=u||9,function t(n,e,o){if(e=(n=(r||[]).splice(0,u)).length){for(var i=0;i"]||e;if(e)return"number"==typeof(e=e[n])?e:-1/0},n.ify=function(t,n,e,o,i){(t=t||{})._=t._||{},i&&(t._["#"]=i);i=t._[">"]||(t._[">"]={});return void 0!==n&&"_"!==n&&("number"==typeof e&&(i[n]=e),void 0!==o&&(t[n]=o)),t},t.exports=n})(T,"./state"),T(function(t){T("./shim"),t.exports=function(o){var i={s:{}},r=i.s;o=o||{max:999,age:9e3},i.check=function(t){return!!r[t]&&n(t)};var n=i.track=function(t){t=r[t]||(r[t]={});return t.was=i.now=+new Date,i.to||(i.to=setTimeout(i.drop,o.age+9)),t};return i.drop=function(e){i.to=null,i.now=+new Date;var t=Object.keys(r);console.STAT&&console.STAT(i.now,+new Date-i.now,"dup drop keys"),setTimeout.each(t,function(t){var n=r[t];n&&(e||o.age)>i.now-n.was||delete r[t]},0,99)},i}})(T,"./dup"),T(function(t){T("./onto"),t.exports=function(t,n){if(this.on){var e=(this.opt||{}).lack||9e3;if("function"!=typeof t){if(!t)return;var o=t["#"]||t,i=(this.tag||"")[o];return i?(n&&(i=this.on(o,n),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},e)),!0):void 0}o=n&&n["#"]||a(9);if(!t)return o;var r=this.on(o,t,n);return r.err=r.err||setTimeout(function(){r.off(),r.next({err:"Error: No ACK yet.",lack:!0})},e),o}};var a=String.random||function(){return Math.random().toString(36).slice(2)}})(T,"./ask"),T(function(t){function f(t){return t instanceof f?(this._={$:this}).$:this instanceof f?f.create(this._={$:this,opt:t}):new f(t)}function a(t,a){var s=+new Date,n=t._||{},u=n.DBG=t.DBG,c=t["#"],f=g(9),l=Object.keys(a||"").sort(),h=((a||"")._||"")["#"],p=(l.length,t.$._.root),d=a===p.graph[h];console.STAT&&console.STAT(s,((u||n).gk=+new Date)-s,"got keys"),a&&function t(){s=+new Date;for(var n,e,o,i=0,r={};i<9&&(n=l[i++]);)v(r,n,G(a,n),a[n],h);l=l.slice(i),(e={})[h]=r,r=e,d&&((o=function(){}).ram=o.faith=!0),e=l.length,console.STAT&&console.STAT(s,-(s-(s=+new Date)),"got copied some"),u&&(u.ga=+new Date),p.on("in",{"@":c,"#":f,put:r,"%":e?f=g(9):O,$:p.$,_:o,DBG:u}),console.STAT&&console.STAT(s,+new Date-s,"got in"),e&&setTimeout.turn(t)}(),a||p.on("in",{"@":t["#"]})}f.is=function(t){return t instanceof f||t&&t._&&t===t._.$||!1},f.version=.202,(f.chain=f.prototype).toJSON=function(){},T("./shim"),f.valid=T("./valid"),f.state=T("./state"),f.on=T("./onto"),f.dup=T("./dup"),f.ask=T("./ask"),function(){function b(t){if(t)if(t.out!==b){var n,e,o=this.as,i=o.at||o,r=i.$,a=i.dup,s=t.DBG;if((e=t["#"])||(e=t["#"]=g(9)),!a.check(e)){if(a.track(e),e=t._,t._="function"==typeof e?e:function(){},t.$&&t.$===(t.$._||"").$||(t.$=r),t["@"]&&!t.put&&(a=(o=t)["@"]||"",(n=a._)?(n.acks=(n.acks||0)+1,(n.err=o.err)&&(o["@"]=n["#"],_(n)),n.ok=o.ok||n.ok,n.stop||n.crack||(n.crack=n.match&&n.match.push(function(){c(n)})),c(n)):(e=(e=(e=o.$)&&(e=e._)&&(e=e.root)&&e.dup).check(a))&&(o["@"]=e["#"]||o["@"])),!i.ask(t["@"],t)){if(s&&(s.u=+new Date),t.put)return void u(t);t.get&&f.on.get(t,r)}s&&(s.uc=+new Date),this.to.next(t),s&&(s.ua=+new Date),t.nts||t.NTS||(t.out=b,i.on("out",t),s&&(s.ue=+new Date))}}else this.to.next(t)}function u(a){if(a){var s=a._||"",t=s.root=((s.$=a.$||"")._||"").root;if(a["@"]&&s.faith&&!s.miss)return a.out=b,void t.on("out",a);s.latch=t.hatch,s.match=t.hatch=[];var u,c,f,l,h,p,d,g,v,y=a.put,k=s.DBG=a.DBG,m=+new Date;n=n||m,y["#"]&&y["."]||(k&&(k.p=m),s["#"]=a["#"],s.msg=a,s.all=0,s.stun=1,u=Object.keys(y),console.STAT&&console.STAT(m,((k||s).pk=+new Date)-m,"put sort"),c=0,function t(n){if(f!=c){if(!(h=u[f=c]))return console.STAT&&console.STAT(m,((k||s).pd=+new Date)-m,"put"),void _(s);(p=y[h])?(v=p._)?h!==v["#"]?g=w+$(h)+"soul not same.":(d=v[">"])||(g=w+$(h)+"no state."):g=w+$(h)+"no meta.":g=w+$(h)+"no node.",l=Object.keys(p||{})}if(g)return a.err=s.err=g,void _(s);var e,o=0;for(n=n||0;n++<9&&(e=l[o++]);)if("_"!==e){var i=p[e],r=d[e];if(O===r){g=w+$(e)+"on"+$(h)+"no state.";break}if(!A(i)){g=w+$(e)+"on"+$(h)+"bad "+typeof i+$(i);break}!function t(n,e,o,i,r){var a=r._||"",s=a.root,u=s.graph;var c=u[o]||N,f=G(c,e,1),l=c[e];var h=a.DBG;(c=console.STAT)&&(u[o]&&l||(c.has=(c.has||0)+1));u=x();if(uj?j:c),void(console.STAT&&console.STAT((h||a).Hf=+new Date,c,"future"));if(i":i},ok:r.ok,_:a})}(i,e,h,r,a),++S}(l=l.slice(o)).length?D(t):(++c,l=null,t(n))}())}}function e(t){(u=(t._||"").DBG)&&(u.pa=+new Date,u.pm=u.pm||+new Date);var n=this.as,e=n.graph,o=t._,i=t.put,r=i["#"],a=i["."],s=i[":"],u=i[">"];t["#"];(i=o.msg)&&(i=i.put)&&(i=i[r])&&v(i,a,u,s,r),e[r]=v(e[r],a,u,s,r),(i=(n.next||"")[r])&&i.on("in",t),_(o),this.to.next(t)}function _(t,n){var e,o;t.stop||!t.err&&0<--t.stun||(t.stop=1,(e=t.root)&&((o=t.match).end=1,o===e.hatch&&(!(o=t.latch)||o.end?delete e.hatch:e.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,function(t){t&&t()}),!(n=t.msg)||t.err||n.err||(n.out=b,t.root.on("out",n),i())))}function c(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?O:t.ok||{"":1}}))}f.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||f.on,t.ask=t.ask||f.ask,t.dup=t.dup||f.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",b,t),t.on("out",b,t),t.on("put",e,t),f.on("create",t),t.on("create",t)),t.once=1,n},f.on.put=u;var n,w="Error: Invalid graph!",$=function(t){return" '"+(""+t).slice(0,9)+"...' "},T=JSON.stringify,j=2147483647,x=f.state,S=0,i=function(){999":v(r.graph[i.soul],n)}}),e))return}else{if(e=i.ask&&i.ask[""],(i.ask||(i.ask={}))[""]=i,p!==i.put&&(i.on("in",i),e))return;t.$=i.$}return r.ask(a,t),r.on("in",t)}if(n["."])return o.get?(t={get:{".":o.get},$:o.$},(i.ask||(i.ask={}))[o.get]=t.$._):t={get:o.lex?t.get:{},$:o.$},i.on("out",t);if(((o.ask||(o.ask={}))[""]=o).get)return n["."]=o.get,(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)}return i.on("out",t)}o.on("in",{put:o.put=p,$:o.$})},r.on.in=function(n,e){var o,t,i=(e=e||this.as).root,r=((o=n.$||(n.$=e.$))||"")._||d,a=n.put||"",s=a["#"],u=a["."],c=p!==a["="]?a["="]:a[":"],f=a[">"]||-1/0;if(p!==n.put&&(p===a["#"]||p===a["."]||p===a[":"]&&p===a["="]||p===a[">"]))return g(a)?void e.on("in",{$:r.back.$,put:{"#":s=r.back.soul,".":u=r.has||r.get,"=":a,">":v(r.back.put,u)},via:n}):(s=((a||"")._||"")["#"])?(o=e.root.$.get(s),setTimeout.each(Object.keys(a).sort(),function(t){"_"!=t&&p!==(f=v(a,t))&&e.on("in",{$:o,put:{"#":s,".":t,"=":a[t],">":f},VIA:n})})):void console.log("chain not yet supported for",a,"...",n,e);(n.seen||"")[e.id]||(((n.seen||(n.seen=function(){}))[e.id]=e)!==r&&(Object.keys(n).forEach(function(t){a[t]=n[t]},a={}),a.get=e.get||a.get,e.soul||e.has?r.soul&&(a.$=e.$,a.$$=a.$$||r.$):a.$$$=a.$$$||e.$,n=a),h(n,e),(e.soul||n.$$)&&f>=v(i.graph[s],u)&&((a=i.$.get(s)._).put=y(a.put,u,f,c,s)),!r.soul&&f>=v(i.graph[s],u)&&(t=(i.$.get(s)._.next||"")[u])&&(t.put=c,"string"==typeof(a=g(c))&&(t.put=i.$.get(a)._.put||c)),this.to&&this.to.next(n),e.any&&setTimeout.each(Object.keys(e.any),function(t){(t=e.any[t])&&t(n)},0,99),e.echo&&setTimeout.each(Object.keys(e.echo),function(t){(t=e.echo[t])&&t.on("in",n)},0,99),((n.$$||"")._||r).soul&&(t=e.next)&&(t=t[u])&&(a={},Object.keys(n).forEach(function(t){a[t]=n[t]}),a.$=(n.$$||n.$).get(a.get=u),delete a.$$,delete a.$$$,t.on("in",a)),l(n,e))},r.on.link=l,r.on.unlink=h;var p,d={},s=String.random,g=r.valid,u=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n=r.state,v=n.is,y=n.ify})(T,"./chain"),T(function(t){var g=T("./root");function r(t){var n=this.at||this.on;if(!t||n.soul||n.has)return this.off();if(t=(t=(t=t.$||t)._||t).id){n.map;if((n=this.seen||(this.seen={}))[t])return!0;n[t]=!0}}g.chain.get=function(t,n,e){var o;if("string"==typeof t){if(0==t.length)return(i=this.chain())._.err={err:g.log("0 length key!",t)},n&&n.call(i,i._.err),i;var i=(i=!(i=((f=this._).next||a)[t])?t&&function(t,n){var e=n._,o=e.next,i=n.chain()._;o=o||(e.next={});o[i.get=t]=i,n===e.root.$?i.soul=t:(e.soul||e.has)&&(i.has=t);return i}(t,this):i)&&i.$}else{if("function"==typeof t){if(!0===n)return function(t,n,e){var a,s=t._,u=0;if(a=s.soul||s.link)return n(a,e,s);if(s.jam)return s.jam.push([n,e]);s.jam=[[n,e]],t.get(function(t,n){if(!(v===t.put&&!s.root.opt.super&&(a=Object.keys(s.root.opt.peers).length)&&++u<=a)){n.rid(t);var e=(e=t.$)&&e._||{},o=0;for(a=s.jam,delete s.jam;r=a[o++];){var i=r[0],r=r[1];i&&i(e.link||e.soul||g.valid(t.put)||((t.put||{})._||{})["#"],r,t,n)}}},{out:{get:{".":!0}}})}(this,t,e),this;var c,f=(i=this)._,l=n||{},h=f.root;l.at=f,l.ok=t;var p={};function d(n,t,e){if(!d.stun&&(!(o=h.pass)||o[c])){var o,i=n.$._,r=(n.$$||"")._,a=(r||i).put,s=!i.has&&!i.soul,u={};if(!s&&v!==a||(a=v===((o=n.put)||"")["="]?v===(o||"")[":"]?o:o[":"]:o["="]),"string"==typeof(o=g.valid(a))&&(a=v===(o=h.$.get(o)._.put)?l.not?v:a:o),!l.not||v!==a){if(v===l.stun){if((o=h.stun)&&o.on&&(f.$.back(function(t){if(o.on(""+t.id,u={}),(u.run||0)u.run&&(u.stun&&!u.stun.end||(u.stun=o.on("stun"),u.stun=u.stun&&u.stun.last),u.stun&&!u.stun.end)))return void((u.stun.add||(u.stun.add={}))[c]=function(){d(n,t,1)});if(v===a&&(e=0),(o=h.hatch)&&!o.end&&v===l.hatch&&!e)return p[i.$._.id]?void 0:(p[i.$._.id]=1,void o.push(function(){d(n,t,1)}));p={}}if(h.pass){if(h.pass[c+i.id])return;h.pass[c+i.id]=1}l.on?l.ok.call(i.$,a,i.get,n,t||d):l.v2020?l.ok(n,t||d):(Object.keys(n).forEach(function(t){o[t]=n[t]},o={}),(n=o).put=a,l.ok.call(l.as,n,t||d))}}}return(((d.at=f).any||(f.any={}))[c=String.random(7)]=d).off=function(){d.stun=1,f.any&&delete f.any[c]},d.rid=r,d.id=l.run||++h.once,o=h.pass,(h.pass={})[c]=1,l.out=l.out||{get:{}},f.on("out",l.out),h.pass=o,i}if("number"==typeof t)return this.get(""+t,n,e);if("string"==typeof(o=s(t)))return this.get(o,n,e);(o=this.get.next)&&(i=o(this,t))}return i?n&&"function"==typeof n&&i.get(n,e):((i=this.chain())._.err={err:g.log("Invalid get request!",t)},n&&n.call(i,i._.err)),i};var v,a={},s=g.valid})(T,"./get"),T(function(t){var y=T("./root");function k(n,t){var e,o,i;t&&(t=(t._||"").id||t,e=n.root.stun||(n.root.stun={on:y.on}),o={},n.stun||(n.stun=e.on("stun",function(){})),(i=e.on(""+t))&&i.the.last.next(o),o.run>=n.run||e.on(""+t,function(t){return n.stun.end?(this.off(),void this.to.next(t)):(t.run=t.run||n.run,void(t.stun=t.stun||n.stun))}))}function m(n){var e,t,o,i,r;n.err?m.end(n.stun,n.root):n.todo.length||n.end||!Object.empty(n.wait)||(n.end=1,r=n.$.back(-1)._,e=r.root,t=r.ask(function(t){e.on("ack",t),t.err&&!t.lack&&y.log(t),++o>(n.acks||0)&&this.off(),n.ack&&n.ack(t,this)},n.opt),o=0,i=n.stun,(r=function(){i&&(m.end(i,e),setTimeout.each(Object.keys(i=i.add||""),function(t){(t=i[t])&&t()}))}).hatch=r,n.ack&&!n.ok&&(n.ok=n.acks||9),n.via._.on("out",{put:n.out=n.graph,ok:n.ok&&{"@":n.ok+1},opt:n.opt,"#":t,_:r}))}y.chain.put=function(t,n,g){var e=this,o=e._,i=o.root;(g=g||{}).root=o.root,g.run||(g.run=i.once),k(g,o.id),g.ack=g.ack||n,g.via=g.via||e,g.data=g.data||t,g.soul||(g.soul=o.soul||"string"==typeof n&&n);var v=g.state=g.state||y.state();return"function"==typeof t?t(function(t){g.data=t,e.put(void 0,void 0,g)}):g.soul?(g.$=i.$.get(g.soul),g.todo=[{it:g.data,ref:g.$}],g.turn=g.turn||r,g.ran=g.ran||m,function t(){var n,e,i,r,a,o,s,u=g.todo,c=u.pop(),f=c.it;c.ref&&c.ref._.id;if(k(g,c.ref),(r=c.todo)&&(f=f[e=r.pop()],r.length&&u.push(c)),e&&(u.path||(u.path=[])).push(e),!(n=b(f))&&!(a=y.is(f))){if(!Object.plain(f))return void m.err(g,"Invalid data: "+((o=f)&&(s=o.constructor)&&s.name||typeof o)+" at "+(g.via.back(function(t){t.get&&r.push(t.get)},r=[])||r.join("."))+"."+(u.path||[]).join("."));for(var l=g.seen||(g.seen=[]),h=l.length;h--;)if(f===(r=l[h]).it){n=f=r.link;break}}if(e&&n)c.node=_(c.node,e,v,f);else{if(!g.seen)return void m.err(g,"Data at root of graph must be a node (an object).");g.seen.push(i={it:f,link:{},todo:a?[]:Object.keys(f).sort().reverse(),path:(u.path||[]).slice(),up:c}),c.node=_(c.node,e,v,i.link),!a&&i.todo.length&&u.push(i);var p=g.seen.length;function d(t,n){var e=i.link["#"];n&&(n.off(),n.rid(t));var o=e||t.soul||(r=(t.$$||t.$)._||"").soul||r.link||((r=r.put||"")._||"")["#"]||r["#"]||((r=t.put||"")&&t.$$?r:r["="]||r[":"]||"")["#"];e||k(g,t.$),o||c.link["#"]?(o||(o=[],(t.$$||t.$).back(function(t){return(r=t.soul||t.link)?o.push(r):void o.push(t.get)}),o=o.reverse().join("/")),i.link["#"]=o,a||(((g.graph||(g.graph={}))[o]=i.node||(i.node={_:{}}))._["#"]=o),delete g.wait[p],i.wait&&setTimeout.each(i.wait,function(t){t&&t()}),g.ran(g)):(c.wait||(c.wait=[])).push(function(){d(t,n)})}(g.wait||(g.wait={}))[p]="",r=(i.ref=a?f:e?c.ref.get(e):c.ref)._,(r=f&&(f._||"")["#"]||r.soul||r.link)?d({soul:r}):i.ref.get(d,{run:g.run,v2020:1,out:{get:{".":" "}}})}if(!u.length)return g.ran(g);g.turn(t)}()):function(n){var e,t=n.via._;n.via=n.via.back(function(t){return t.soul||!t.get?t.$:(e=n.data,void((n.data={})[t.get]=e))}),n.via&&n.via._.soul||(n.via=t.root.$.get(((n.data||"")._||"")["#"]||t.$.back("opt.uuid")()));n.via.put(n.data,n.ack,n)}(g),e},m.end=function(t,n){t.end=e,t.the.to===t&&t===t.the.last&&delete n.stun,t.off()},m.err=function(t,n){(t.ack||e).call(t,t.out={err:t.err=y.log(n)}),t.ran(t)};var e=function(){},r=setTimeout.turn,b=y.valid,_=y.state.ify})(T,"./put"),T(function(t){var n=T("./root");T("./chain"),T("./back"),T("./put"),T("./get"),t.exports=n})(T,"./index"),T(function(t){var g=T("./index");g.chain.on=function(t,n,e,o){var i=this._;i.root;if("string"==typeof t)return n?(o=i.on(t,n,e||i,o),e&&e.$&&(e.subs||(e.subs=[])).push(o),this):i.on(t);(n=!0===n?{change:!0}:n||{}).not=1,n.on=1;return this.get(t,n),this},g.chain.once=function(c,f){if(f=f||{},!c)return t=this,g.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(e=t.chain())._.nix=t.once(function(t,n){e._.on("in",this._)}),e._.lex=t._.lex,e;var t,e,l,h=this._,p=h.root,d=(h.put,String.random(7));return this.get(function(n,e,o,i){var r=this,a=r._,s=a.one||(a.one={});function u(t){a.has||a.soul||(a={put:n,get:e}),void 0===(l=a.put)&&(l=((o.$$||"")._||"").put),"string"!=typeof g.valid(l)||void 0!==(l=p.$.get(l)._.put)||t?i.stun||""!==s[d]&&(s[d]="",(h.soul||h.has)&&i.off(),c.call(r,l,a.get),clearTimeout(s[d])):s[d]=setTimeout(function(){u(1)},f.wait||99)}i.stun||""!==s[d]&&(!0!==(l=g.valid(n))?"string"!=typeof l&&(clearTimeout((h.one||"")[d]),clearTimeout(s[d]),s[d]=setTimeout(u,f.wait||99)):u())},{on:1}),this},g.chain.off=function(){var e,t=this._,o=t.back;if(o)return t.ack=0,(e=o.next)&&e[t.get]&&delete e[t.get],(e=o.ask)&&delete e[t.get],(e=o.put)&&delete e[t.get],(e=t.soul)&&delete o.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,n){(n=e[t]).link&&o.root.$.get(n.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(T,"./on"),T(function(t){var s=T("./index"),o=s.chain.get.next;function u(t){this.to.next(t);var n=this.as,e=t.$._,o=t.put;(e.soul||t.$$)&&((e=n.lex)&&!String.match(t.get||(o||"")["."],e["."]||e["#"]||e)||s.on.link(t,n))}s.chain.get.next=function(t,n){var e;return Object.plain(n)?(e=((e=n["#"])||"")["="]||e)?t.get(e):((e=t.chain()._).lex=n,t.on("in",function(t){String.match(t.get||(t.put||"")["."],n["."]||n["#"]||n)&&e.on("in",t),this.to.next(t)}),e.$):(o||c)(t,n)},s.chain.map=function(r,t,n){var e,a,o=this,i=o._;return Object.plain(r)&&(e=r["."]?r:{".":r},r=void 0),r?(s.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),a=o.chain(),o.map().on(function(t,n,e,o){o=(r||c).call(this,t,n,e,o);if(void 0!==o){if(t===o)return a._.on("in",e);if(s.is(o))return a._.on("in",o._);var i={};Object.keys(e.put).forEach(function(t){i[t]=e.put[t]},i),i["="]=o,a._.on("in",{get:n,put:i})}})):(a=i.each)||((i.each=a=o.chain())._.lex=e||a._.lex||i.lex,a._.nix=o.back("nix"),o.on("in",u,a._)),a};var c=function(){}})(T,"./map"),T(function(t){var s=T("./index");s.chain.set=function(t,i,n){var e,r,a=this,o=a.back(-1);return i=i||function(){},(n=n||{}).item=n.item||t,(e=((t||"")._||"")["#"])&&((t={})["#"]=e),"string"==typeof(r=s.valid(t))?a.get(e=r).put(t,i,n):s.is(t)?(a.put(function(o){t.get(function(t,n,e){return t?((r={})[t]={"#":t},void o(r)):i.call(a,{err:s.log('Only a node can be linked! Not "'+e.put+'"!')})},!0)}),t):(Object.plain(t)&&(t=o.get(e=a.back("opt.uuid")()).put(t)),a.get(e||o.back("opt.uuid")(7)).put(t,i,n))}})(T,"./set"),T(function(t){T("./shim");function n(){}var r=JSON.parseAsync||function(t,n,e){var o=+new Date;try{n(void 0,JSON.parse(t,e),w.sucks(+new Date-o))}catch(t){n(t)}},w=JSON.stringifyAsync||function(t,n,e,o){var i=+new Date;try{n(void 0,JSON.stringify(t,e,o),w.sucks(+new Date-i))}catch(t){n(t)}};function e(u){var d=function(){},g=u.opt||{};g.log=g.log||console.log,g.gap=g.gap||g.wait||0,g.max=g.max||.3*(g.memory?999*g.memory*999:3e8),g.pack=g.pack||.01*g.max*.01,g.puff=g.puff||9;var v=setTimeout.turn||setTimeout,y=u.dup,k=y.check,m=y.track,i=(new Date,d.hear=function(t,a){if(t){if(g.max<=t.length)return d.say({dam:"!",err:"Message too big!"},a);d===this&&(i.d+=t.length||0,++i.c);var n,e=a.SH=+new Date,o=t[0];if("["===o)return r(t,function(t,i){if(t||!i)return d.say({dam:"!",err:"DAM JSON parse error."},a);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var r=g.puff;!function t(){for(var n,e=+new Date,o=0;o<"])&&"string"==typeof r&&r.slice(0,99).split(",").forEach(function(t){this[t]=1},t._.yo={}),r=t.dam)return(r=d.hear[r])&&r(t,n,u),void m(o);(r=t.ok)&&(t._.near=r["/"]);e=+new Date;s&&(s.is=e),n.SI=o,u.on("in",d.last=t),s&&(s.hd=+new Date),console.STAT&&console.STAT(e,+new Date-e,t.get?"msg get":t.put?"msg put":"msg"),(r=m(o)).via=n,t.get&&(r.it=t),a&&m(a),d.leap=d.last=null}};function b(t){var n=t.batch,e="string"==typeof n;if(e&&(n+="]"),t.batch=t.tail=null,n&&(e?!(n.length<3):n.length)){if(!e)try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return g.log("DAM JSON stringify error",t)}n&&_(n,t)}}function _(n,e){try{var t=e.wire;e.say?e.say(n):t.send&&t.send(n),d.say.d+=n.length||0,++d.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}i.c=i.d=0,function(){var h,p=0;function t(t,n){var e;return n instanceof Object?(Object.keys(n).sort().forEach(o,{to:e={},on:n}),e):n}function o(t){this.to[t]=this.on[t]}d.hash=function(o,i){var r,a,s,u=+new Date;w(o.put,function t(n,e){e=(a=a||(s=e||"")).slice(0,32768);r=String.hash(e,r),(a=a.slice(32768))?v(t,0):(console.STAT&&console.STAT(u,+new Date-u,"say json+hash"),o._.$put=s,o["##"]=r,d.say(o,i),delete o._.$put)},t)};d.say=function(r,a){var t;if((t=this)&&(t=t.to)&&t.next&&t.next(r),!r)return!1;var n,s,u=r["@"],c=r._||(r._=function(){}),e=r.DBG,o=+new Date;if(c.y=c.y||o,a||e&&(e.y=o),(n=r["#"])||(n=r["#"]=String.random(9)),h||m(n),r["##"]||$===r.put||c.via||!u){if(!(a=!a&&u?(t=y.s[u])&&(t.via||(t=t.it)&&(t=t._)&&t.via)||(t=d.last)&&u===t["#"]&&d.leap:a)&&u)return y.s[u]?void 0:(console.STAT&&console.STAT(+new Date,++p,"total no peer to ack to"),!1);if(!a&&d.way)return d.way(r);if(e&&(e.yh=+new Date),s=c.raw){if(e&&(e.yr=+new Date),!a||!a.id){if(!Object.plain(a||g.peers))return!1;var o=+new Date,f=(g.puff,g.peers),l=Object.keys(a||g.peers||{});return console.STAT&&console.STAT(o,+new Date-o,"peer keys"),void function t(){var n=+new Date;h=1;var e=c.raw;c.raw=s;for(var o,i=0;i<9&&(o=(l||"")[i++]);)(o=f[o]||(a||"")[o])&&d.say(r,o);c.raw=e,h=0,l=l.slice(i),console.STAT&&console.STAT(n,+new Date-n,"say loop"),l.length&&(v(t,0),u&&m(u))}()}if(!a.wire&&d.wire&&d.wire(a),n!==a.last){if(a.last=n,a===c.via)return!1;if((t=c.yo)&&(t[a.url]||t[a.pid]||t[a.id]))return!1;if(console.STAT&&console.STAT(o,((e||c).yp=+new Date)-(c.y||o),"say prep"),!h&&u&&m(u),a.batch){if(a.tail=(t=a.tail||0)+s.length,a.tail<=g.pack)return void(a.batch+=(t?",":"")+s);b(a)}a.batch="[";var i=+new Date;setTimeout(function(){console.STAT&&console.STAT(i,+new Date-i,"0ms TO"),b(a)},g.gap),_(s,a),console.STAT&&u===a.SI&&console.STAT(o,+new Date-a.SH,"say ack")}}else d.raw(r,a)}else d.hash(r,a)};d.say.c=d.say.d=0,d.raw=function(e,o){if(!e)return"";var i,r=e._||{};if(s=r.raw)return s;if("string"==typeof e)return e;var t=e["##"],n=e["@"];if(t&&n){if(!r.via&&k(n+t))return!1;if((s=(y.s[n]||"").it)||(s=d.last)&&n===s["#"]){if(t===s["##"])return!1;s["##"]||(s["##"]=t)}}if(!e.dam&&!e["@"]){var a,s,u=0,c=[];for(a in s=g.peers){var f=s[a];if(c.push(f.url||f.pid||f.id),6<++u)break}1<"]=c.join())}if(e.put&&(s=e.ok)&&(e.ok={"@":(s["@"]||1)-1,"/":s["/"]==e._.near?d.near:s["/"]}),i=r.$put)return s={},Object.keys(e).forEach(function(t){s[t]=e[t]}),s.put=":])([:",void w(s,function(t,n){t||(t=+new Date,s=n.indexOf('"put":":])([:"'),l($,n=n.slice(0,s+6)+i+n.slice(s+14)),console.STAT&&console.STAT(t,+new Date-t,"say slice"))});function l(t,n){t||(r.raw=n,d.say(e,o))}w(e,l)}}(),d.near=0,d.hi=function(n){var t;n.wire?(n.id?g.peers[n.url||n.id]=n:(t=n.id=n.id||n.url||String.random(9),d.say({dam:"?",pid:u.opt.pid},g.peers[t]=n),delete y.s[n.last]),n.met||(d.near++,n.met=+new Date,u.on("hi",n)),t=n.queue,n.queue=[],setTimeout.each(t||[],function(t){_(t,n)},0,9)):d.wire(n.length?{url:n,id:n}:n)},d.bye=function(t){t.met&&--d.near,delete t.met,u.on("bye",t);var n=+new Date;n-=t.met||n,d.bye.time=((d.bye.time||n)+n)/2},d.hear["!"]=function(t,n){g.log("Error:",t.err)},d.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(d.say({dam:"?",pid:g.pid,"@":t["#"]},n),delete y.s[n.last])},d.hear.mob=function(t,n){!t.peers||(t=(t=Object.keys(t.peers))[Math.random()*t.length>>0])&&(d.bye(n),d.hi(t))},u.on("create",function(t){t.opt.pid=t.opt.pid||String.random(9),this.to.next(t),t.on("out",d.say)}),u.on("bye",function(t,n){t=g.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),delete g.peers[t.id],t.wire=null});var e={};return u.on("bye",function(t,n){this.to.next(t),(n=console.STAT)&&(n.peers=d.near),(n=t.url)&&(e[n]=!0,setTimeout(function(){delete e[n]},g.lack||9e3))}),u.on("hi",function(e,t){this.to.next(e),(t=console.STAT)&&(t.peers=d.near),g.super||(9999<(t=Object.keys(u.next||"")).length&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(t,function(n){var t=u.next[n];g.super||(t.ask||"")[""]?d.say({get:{"#":n}},e):setTimeout.each(Object.keys(t.ask||""),function(t){t&&d.say({"##":String.hash((u.graph[n]||"")[t]),get:{"#":n,".":t}},e)})}))}),d}w.sucks=function(t){99"],n[":"],e),f&&4999880"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"]||n["<"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},h.text.hash=h.text.hash||function(t,n){if(l("text.hash"),"string"==typeof t){if(n=n||0,!t.length)return n;for(var e=0,o=t.length;e"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},String.hash=function(t,n){if("string"==typeof t){if(n=n||0,!t.length)return n;for(var e=0,o=t.length;e=s.now()-i&&r++<3333?t():a(function(){i=s.now(),t()},r=0)},g=setTimeout,f=(c=g.turn=g.turn||function(t){1==f.push(t)&&l(p)}).s=[],l=g.poll,h=0,p=function(){(u=f[h++])&&u(),h!=f.length&&99!=h||(f=c.s=f.slice(h),h=0),f.length&&l(p)},g=setTimeout,v=g.turn,(g.each=g.each||function(r,a,s,u){u=u||9,function t(n,e,o){if(e=(n=(r||[]).splice(0,u)).length){for(var i=0;i"]||e;if(e)return"number"==typeof(e=e[n])?e:-1/0},n.ify=function(t,n,e,o,i){(t=t||{})._=t._||{},i&&(t._["#"]=i);i=t._[">"]||(t._[">"]={});return void 0!==n&&"_"!==n&&("number"==typeof e&&(i[n]=e),void 0!==o&&(t[n]=o)),t},t.exports=n})(T,"./state"),T(function(t){T("./shim"),t.exports=function(o){var i={s:{}},r=i.s;o=o||{max:999,age:9e3},i.check=function(t){return!!r[t]&&e(t)};var e=i.track=function(t){var n=r[t]||(r[t]={});return n.was=i.now=+new Date,i.to||(i.to=setTimeout(i.drop,o.age+9)),e.ed&&e.ed(t),n};return i.drop=function(e){i.to=null,i.now=+new Date;var t=Object.keys(r);console.STAT&&console.STAT(i.now,+new Date-i.now,"dup drop keys"),setTimeout.each(t,function(t){var n=r[t];n&&(e||o.age)>i.now-n.was||delete r[t]},0,99)},i}})(T,"./dup"),T(function(t){T("./onto"),t.exports=function(t,n){if(this.on){var e=(this.opt||{}).lack||9e3;if("function"!=typeof t){if(!t)return;var o=t["#"]||t,i=(this.tag||"")[o];return i?(n&&(i=this.on(o,n),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},e)),!0):void 0}o=n&&n["#"]||a(9);if(!t)return o;var r=this.on(o,t,n);return r.err=r.err||setTimeout(function(){r.off(),r.next({err:"Error: No ACK yet.",lack:!0})},e),o}};var a=String.random||function(){return Math.random().toString(36).slice(2)}})(T,"./ask"),T(function(t){function f(t){return t instanceof f?(this._={$:this}).$:this instanceof f?f.create(this._={$:this,opt:t}):new f(t)}function s(t,a){var s=+new Date,n=t._||{},u=n.DBG=t.DBG,c=t["#"],f=g(9),l=Object.keys(a||"").sort(),h=((a||"")._||"")["#"],p=(l.length,t.$._.root),d=a===p.graph[h];console.STAT&&console.STAT(s,((u||n).gk=+new Date)-s,"got keys"),a&&function t(){s=+new Date;for(var n,e,o,i=0,r={};i<9&&(n=l[i++]);)v(r,n,G(a,n),a[n],h);l=l.slice(i),(e={})[h]=r,r=e,d&&((o=function(){}).ram=o.faith=!0),e=l.length,console.STAT&&console.STAT(s,-(s-(s=+new Date)),"got copied some"),u&&(u.ga=+new Date),p.on("in",{"@":c,"#":f,put:r,"%":e?f=g(9):O,$:p.$,_:o,DBG:u,FOO:1}),console.STAT&&console.STAT(s,+new Date-s,"got in"),e&&setTimeout.turn(t)}(),a||p.on("in",{"@":t["#"]})}f.is=function(t){return t instanceof f||t&&t._&&t===t._.$||!1},f.version=.202,(f.chain=f.prototype).toJSON=function(){},T("./shim"),f.valid=T("./valid"),f.state=T("./state"),f.on=T("./onto"),f.dup=T("./dup"),f.ask=T("./ask"),function(){function b(t){if(t)if(t.out!==b){var n,e,o=this.as,i=o.at||o,r=i.$,a=i.dup,s=t.DBG;if((e=t["#"])||(e=t["#"]=g(9)),!a.check(e)){if(a.track(e),e=t._,t._="function"==typeof e?e:function(){},t.$&&t.$===(t.$._||"").$||(t.$=r),t["@"]&&!t.put&&(a=(o=t)["@"]||"",(n=a._)?(n.acks=(n.acks||0)+1,(n.err=o.err)&&(o["@"]=n["#"],_(n)),n.ok=o.ok||n.ok,n.stop||n.crack||(n.crack=n.match&&n.match.push(function(){c(n)})),c(n)):(e=(e=(e=o.$)&&(e=e._)&&(e=e.root)&&e.dup).check(a))&&(o["@"]=e["#"]||o["@"])),!i.ask(t["@"],t)){if(s&&(s.u=+new Date),t.put)return void u(t);t.get&&f.on.get(t,r)}s&&(s.uc=+new Date),this.to.next(t),s&&(s.ua=+new Date),t.nts||t.NTS||(t.out=b,i.on("out",t),s&&(s.ue=+new Date))}}else this.to.next(t)}function u(a){if(a){var s=a._||"",t=s.root=((s.$=a.$||"")._||"").root;if(a["@"]&&s.faith&&!s.miss)return a.out=b,void t.on("out",a);s.latch=t.hatch,s.match=t.hatch=[];var u,c,f,l,h,p,d,g,v,y=a.put,k=s.DBG=a.DBG,m=+new Date;n=n||m,y["#"]&&y["."]||(k&&(k.p=m),s["#"]=a["#"],s.msg=a,s.all=0,s.stun=1,u=Object.keys(y),console.STAT&&console.STAT(m,((k||s).pk=+new Date)-m,"put sort"),c=0,function t(n){if(f!=c){if(!(h=u[f=c]))return console.STAT&&console.STAT(m,((k||s).pd=+new Date)-m,"put"),void _(s);(p=y[h])?(v=p._)?h!==v["#"]?g=w+$(h)+"soul not same.":(d=v[">"])||(g=w+$(h)+"no state."):g=w+$(h)+"no meta.":g=w+$(h)+"no node.",l=Object.keys(p||{})}if(g)return a.err=s.err=g,void _(s);var e,o=0;for(n=n||0;n++<9&&(e=l[o++]);)if("_"!==e){var i=p[e],r=d[e];if(O===r){g=w+$(e)+"on"+$(h)+"no state.";break}if(!A(i)){g=w+$(e)+"on"+$(h)+"bad "+typeof i+$(i);break}!function t(n,e,o,i,r){var a=r._||"",s=a.root,u=s.graph;var c=u[o]||N,f=G(c,e,1),l=c[e];var h=a.DBG;(c=console.STAT)&&(u[o]&&l||(c.has=(c.has||0)+1));u=x();if(uj?j:c),void(console.STAT&&console.STAT((h||a).Hf=+new Date,c,"future"));if(i":i},ok:r.ok,_:a})}(i,e,h,r,a),++S}(l=l.slice(o)).length?D(t):(++c,l=null,t(n))}())}}function e(t){(u=(t._||"").DBG)&&(u.pa=+new Date,u.pm=u.pm||+new Date);var n=this.as,e=n.graph,o=t._,i=t.put,r=i["#"],a=i["."],s=i[":"],u=i[">"];t["#"];(i=o.msg)&&(i=i.put)&&(i=i[r])&&v(i,a,u,s,r),e[r]=v(e[r],a,u,s,r),(i=(n.next||"")[r])&&i.on("in",t),_(o),this.to.next(t)}function _(t,n){var e,o;t.stop||!t.err&&0<--t.stun||(t.stop=1,(e=t.root)&&((o=t.match).end=1,o===e.hatch&&(!(o=t.latch)||o.end?delete e.hatch:e.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,function(t){t&&t()}),!(n=t.msg)||t.err||n.err||(n.out=b,t.root.on("out",n),i())))}function c(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?O:t.ok||{"":1}}))}f.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||f.on,t.ask=t.ask||f.ask,t.dup=t.dup||f.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",b,t),t.on("out",b,t),t.on("put",e,t),f.on("create",t),t.on("create",t)),t.once=1,n},f.on.put=u;var n,w="Error: Invalid graph!",$=function(t){return" '"+(""+t).slice(0,9)+"...' "},T=JSON.stringify,j=2147483647,x=f.state,S=0,i=function(){999":v(r.graph[i.soul],n)}}),e))return}else{if(e=i.ask&&i.ask[""],(i.ask||(i.ask={}))[""]=i,p!==i.put&&(i.on("in",i),e))return;t.$=i.$}return r.ask(a,t),r.on("in",t)}if(n["."])return o.get?(t={get:{".":o.get},$:o.$},(i.ask||(i.ask={}))[o.get]=t.$._):t={get:o.lex?t.get:{},$:o.$},i.on("out",t);if(((o.ask||(o.ask={}))[""]=o).get)return n["."]=o.get,(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)}return i.on("out",t)}o.on("in",{put:o.put=p,$:o.$})},r.on.in=function(n,e){var o,t,i=(e=e||this.as).root,r=((o=n.$||(n.$=e.$))||"")._||d,a=n.put||"",s=a["#"],u=a["."],c=p!==a["="]?a["="]:a[":"],f=a[">"]||-1/0;if(p!==n.put&&(p===a["#"]||p===a["."]||p===a[":"]&&p===a["="]||p===a[">"]))return g(a)?void e.on("in",{$:r.back.$,put:{"#":s=r.back.soul,".":u=r.has||r.get,"=":a,">":v(r.back.put,u)},via:n}):(s=((a||"")._||"")["#"])?(o=e.root.$.get(s),setTimeout.each(Object.keys(a).sort(),function(t){"_"!=t&&p!==(f=v(a,t))&&e.on("in",{$:o,put:{"#":s,".":t,"=":a[t],">":f},VIA:n})})):void console.log("chain not yet supported for",a,"...",n,e);(n.seen||"")[e.id]||(((n.seen||(n.seen=function(){}))[e.id]=e)!==r&&(Object.keys(n).forEach(function(t){a[t]=n[t]},a={}),a.get=e.get||a.get,e.soul||e.has?r.soul&&(a.$=e.$,a.$$=a.$$||r.$):a.$$$=a.$$$||e.$,n=a),h(n,e),(e.soul||n.$$)&&f>=v(i.graph[s],u)&&((a=i.$.get(s)._).put=y(a.put,u,f,c,s)),!r.soul&&f>=v(i.graph[s],u)&&(t=(i.$.get(s)._.next||"")[u])&&(t.put=c,"string"==typeof(a=g(c))&&(t.put=i.$.get(a)._.put||c)),this.to&&this.to.next(n),e.any&&setTimeout.each(Object.keys(e.any),function(t){(t=e.any[t])&&t(n)},0,99),e.echo&&setTimeout.each(Object.keys(e.echo),function(t){(t=e.echo[t])&&t.on("in",n)},0,99),((n.$$||"")._||r).soul&&(t=e.next)&&(t=t[u])&&(a={},Object.keys(n).forEach(function(t){a[t]=n[t]}),a.$=(n.$$||n.$).get(a.get=u),delete a.$$,delete a.$$$,t.on("in",a)),l(n,e))},r.on.link=l,r.on.unlink=h;var p,d={},s=String.random,g=r.valid,u=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n=r.state,v=n.is,y=n.ify})(T,"./chain"),T(function(t){var g=T("./root");function r(t){var n=this.at||this.on;if(!t||n.soul||n.has)return this.off();if(t=(t=(t=t.$||t)._||t).id){n.map;if((n=this.seen||(this.seen={}))[t])return!0;n[t]=!0}}g.chain.get=function(t,n,e){var o;if("string"==typeof t){if(0==t.length)return(i=this.chain())._.err={err:g.log("0 length key!",t)},n&&n.call(i,i._.err),i;var i=(i=!(i=((f=this._).next||a)[t])?t&&function(t,n){var e=n._,o=e.next,i=n.chain()._;o=o||(e.next={});o[i.get=t]=i,n===e.root.$?i.soul=t:(e.soul||e.has)&&(i.has=t);return i}(t,this):i)&&i.$}else{if("function"==typeof t){if(!0===n)return function(t,n,e){var a,s=t._,u=0;if(a=s.soul||s.link)return n(a,e,s);if(s.jam)return s.jam.push([n,e]);s.jam=[[n,e]],t.get(function(t,n){if(!(v===t.put&&!s.root.opt.super&&(a=Object.keys(s.root.opt.peers).length)&&++u<=a)){n.rid(t);var e=(e=t.$)&&e._||{},o=0;for(a=s.jam,delete s.jam;r=a[o++];){var i=r[0],r=r[1];i&&i(e.link||e.soul||g.valid(t.put)||((t.put||{})._||{})["#"],r,t,n)}}},{out:{get:{".":!0}}})}(this,t,e),this;var c,f=(i=this)._,l=n||{},h=f.root;l.at=f,l.ok=t;var p={};function d(n,t,e){if(!d.stun&&(!(o=h.pass)||o[c])){var o,i=n.$._,r=(n.$$||"")._,a=(r||i).put,s=!i.has&&!i.soul,u={};if(!s&&v!==a||(a=v===((o=n.put)||"")["="]?v===(o||"")[":"]?o:o[":"]:o["="]),"string"==typeof(o=g.valid(a))&&(a=v===(o=h.$.get(o)._.put)?l.not?v:a:o),!l.not||v!==a){if(v===l.stun){if((o=h.stun)&&o.on&&(f.$.back(function(t){if(o.on(""+t.id,u={}),(u.run||0)u.run&&(u.stun&&!u.stun.end||(u.stun=o.on("stun"),u.stun=u.stun&&u.stun.last),u.stun&&!u.stun.end)))return void((u.stun.add||(u.stun.add={}))[c]=function(){d(n,t,1)});if(v===a&&(e=0),(o=h.hatch)&&!o.end&&v===l.hatch&&!e)return p[i.$._.id]?void 0:(p[i.$._.id]=1,void o.push(function(){d(n,t,1)}));p={}}if(h.pass){if(h.pass[c+i.id])return;h.pass[c+i.id]=1}l.on?l.ok.call(i.$,a,i.get,n,t||d):l.v2020?l.ok(n,t||d):(Object.keys(n).forEach(function(t){o[t]=n[t]},o={}),(n=o).put=a,l.ok.call(l.as,n,t||d))}}}return(((d.at=f).any||(f.any={}))[c=String.random(7)]=d).off=function(){d.stun=1,f.any&&delete f.any[c]},d.rid=r,d.id=l.run||++h.once,o=h.pass,(h.pass={})[c]=1,l.out=l.out||{get:{}},f.on("out",l.out),h.pass=o,i}if("number"==typeof t)return this.get(""+t,n,e);if("string"==typeof(o=s(t)))return this.get(o,n,e);(o=this.get.next)&&(i=o(this,t))}return i?n&&"function"==typeof n&&i.get(n,e):((i=this.chain())._.err={err:g.log("Invalid get request!",t)},n&&n.call(i,i._.err)),i};var v,a={},s=g.valid})(T,"./get"),T(function(t){var y=T("./root");function k(n,t){var e,o,i;t&&(t=(t._||"").id||t,e=n.root.stun||(n.root.stun={on:y.on}),o={},n.stun||(n.stun=e.on("stun",function(){})),(i=e.on(""+t))&&i.the.last.next(o),o.run>=n.run||e.on(""+t,function(t){return n.stun.end?(this.off(),void this.to.next(t)):(t.run=t.run||n.run,void(t.stun=t.stun||n.stun))}))}function m(n){var e,t,o,i,r;n.err?m.end(n.stun,n.root):n.todo.length||n.end||!Object.empty(n.wait)||(n.end=1,r=n.$.back(-1)._,e=r.root,t=r.ask(function(t){e.on("ack",t),t.err&&!t.lack&&y.log(t),++o>(n.acks||0)&&this.off(),n.ack&&n.ack(t,this)},n.opt),o=0,i=n.stun,(r=function(){i&&(m.end(i,e),setTimeout.each(Object.keys(i=i.add||""),function(t){(t=i[t])&&t()}))}).hatch=r,n.ack&&!n.ok&&(n.ok=n.acks||9),n.via._.on("out",{put:n.out=n.graph,ok:n.ok&&{"@":n.ok+1},opt:n.opt,"#":t,_:r}))}y.chain.put=function(t,n,g){var e=this,o=e._,i=o.root;(g=g||{}).root=o.root,g.run||(g.run=i.once),k(g,o.id),g.ack=g.ack||n,g.via=g.via||e,g.data=g.data||t,g.soul||(g.soul=o.soul||"string"==typeof n&&n);var v=g.state=g.state||y.state();return"function"==typeof t?t(function(t){g.data=t,e.put(void 0,void 0,g)}):g.soul?(g.$=i.$.get(g.soul),g.todo=[{it:g.data,ref:g.$}],g.turn=g.turn||r,g.ran=g.ran||m,function t(){var n,e,i,r,a,o,s,u=g.todo,c=u.pop(),f=c.it;c.ref&&c.ref._.id;if(k(g,c.ref),(r=c.todo)&&(f=f[e=r.pop()],r.length&&u.push(c)),e&&(u.path||(u.path=[])).push(e),!(n=b(f))&&!(a=y.is(f))){if(!Object.plain(f))return void m.err(g,"Invalid data: "+((o=f)&&(s=o.constructor)&&s.name||typeof o)+" at "+(g.via.back(function(t){t.get&&r.push(t.get)},r=[])||r.join("."))+"."+(u.path||[]).join("."));for(var l=g.seen||(g.seen=[]),h=l.length;h--;)if(f===(r=l[h]).it){n=f=r.link;break}}if(e&&n)c.node=_(c.node,e,v,f);else{if(!g.seen)return void m.err(g,"Data at root of graph must be a node (an object).");g.seen.push(i={it:f,link:{},todo:a?[]:Object.keys(f).sort().reverse(),path:(u.path||[]).slice(),up:c}),c.node=_(c.node,e,v,i.link),!a&&i.todo.length&&u.push(i);var p=g.seen.length;function d(t,n){var e=i.link["#"];n&&(n.off(),n.rid(t));var o=e||t.soul||(r=(t.$$||t.$)._||"").soul||r.link||((r=r.put||"")._||"")["#"]||r["#"]||((r=t.put||"")&&t.$$?r:r["="]||r[":"]||"")["#"];e||k(g,t.$),o||c.link["#"]?(o||(o=[],(t.$$||t.$).back(function(t){return(r=t.soul||t.link)?o.push(r):void o.push(t.get)}),o=o.reverse().join("/")),i.link["#"]=o,a||(((g.graph||(g.graph={}))[o]=i.node||(i.node={_:{}}))._["#"]=o),delete g.wait[p],i.wait&&setTimeout.each(i.wait,function(t){t&&t()}),g.ran(g)):(c.wait||(c.wait=[])).push(function(){d(t,n)})}(g.wait||(g.wait={}))[p]="",r=(i.ref=a?f:e?c.ref.get(e):c.ref)._,(r=f&&(f._||"")["#"]||r.soul||r.link)?d({soul:r}):i.ref.get(d,{run:g.run,v2020:1,out:{get:{".":" "}}})}if(!u.length)return g.ran(g);g.turn(t)}()):function(n){var e,t=n.via._;n.via=n.via.back(function(t){return t.soul||!t.get?t.$:(e=n.data,void((n.data={})[t.get]=e))}),n.via&&n.via._.soul||(n.via=t.root.$.get(((n.data||"")._||"")["#"]||t.$.back("opt.uuid")()));n.via.put(n.data,n.ack,n)}(g),e},m.end=function(t,n){t.end=e,t.the.to===t&&t===t.the.last&&delete n.stun,t.off()},m.err=function(t,n){(t.ack||e).call(t,t.out={err:t.err=y.log(n)}),t.ran(t)};var e=function(){},r=setTimeout.turn,b=y.valid,_=y.state.ify})(T,"./put"),T(function(t){var n=T("./root");T("./chain"),T("./back"),T("./put"),T("./get"),t.exports=n})(T,"./index"),T(function(t){var g=T("./index");g.chain.on=function(t,n,e,o){var i=this._;i.root;if("string"==typeof t)return n?(o=i.on(t,n,e||i,o),e&&e.$&&(e.subs||(e.subs=[])).push(o),this):i.on(t);(n=!0===n?{change:!0}:n||{}).not=1,n.on=1;return this.get(t,n),this},g.chain.once=function(c,f){if(f=f||{},!c)return t=this,g.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(e=t.chain())._.nix=t.once(function(t,n){e._.on("in",this._)}),e._.lex=t._.lex,e;var t,e,l,h=this._,p=h.root,d=(h.put,String.random(7));return this.get(function(n,e,o,i){var r=this,a=r._,s=a.one||(a.one={});function u(t){a.has||a.soul||(a={put:n,get:e}),void 0===(l=a.put)&&(l=((o.$$||"")._||"").put),"string"!=typeof g.valid(l)||void 0!==(l=p.$.get(l)._.put)||t?i.stun||""!==s[d]&&(s[d]="",(h.soul||h.has)&&i.off(),c.call(r,l,a.get),clearTimeout(s[d])):s[d]=setTimeout(function(){u(1)},f.wait||99)}i.stun||""!==s[d]&&(!0!==(l=g.valid(n))?"string"!=typeof l&&(clearTimeout((h.one||"")[d]),clearTimeout(s[d]),s[d]=setTimeout(u,f.wait||99)):u())},{on:1}),this},g.chain.off=function(){var e,t=this._,o=t.back;if(o)return t.ack=0,(e=o.next)&&e[t.get]&&delete e[t.get],(e=o.any)&&(delete o.any,o.any={}),(e=o.ask)&&delete e[t.get],(e=o.put)&&delete e[t.get],(e=t.soul)&&delete o.root.graph[e],(e=t.map)&&Object.keys(e).forEach(function(t,n){(n=e[t]).link&&o.root.$.get(n.link).off()}),(e=t.next)&&Object.keys(e).forEach(function(t,n){e[t].$.off()}),t.on("off",{}),this}})(T,"./on"),T(function(t){var s=T("./index"),o=s.chain.get.next;function u(t){this.to.next(t);var n=this.as,e=t.$._,o=t.put;(e.soul||t.$$)&&((e=n.lex)&&!String.match(t.get||(o||"")["."],e["."]||e["#"]||e)||s.on.link(t,n))}s.chain.get.next=function(t,n){var e;return Object.plain(n)?(e=((e=n["#"])||"")["="]||e)?t.get(e):((e=t.chain()._).lex=n,t.on("in",function(t){String.match(t.get||(t.put||"")["."],n["."]||n["#"]||n)&&e.on("in",t),this.to.next(t)}),e.$):(o||c)(t,n)},s.chain.map=function(r,t,n){var e,a,o=this,i=o._;return Object.plain(r)&&(e=r["."]?r:{".":r},r=void 0),r?(s.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),a=o.chain(),o.map().on(function(t,n,e,o){o=(r||c).call(this,t,n,e,o);if(void 0!==o){if(t===o)return a._.on("in",e);if(s.is(o))return a._.on("in",o._);var i={};Object.keys(e.put).forEach(function(t){i[t]=e.put[t]},i),i["="]=o,a._.on("in",{get:n,put:i})}})):(a=i.each)||((i.each=a=o.chain())._.lex=e||a._.lex||i.lex,a._.nix=o.back("nix"),o.on("in",u,a._)),a};var c=function(){}})(T,"./map"),T(function(t){var s=T("./index");s.chain.set=function(t,i,n){var e,r,a=this,o=a.back(-1);return i=i||function(){},(n=n||{}).item=n.item||t,(e=((t||"")._||"")["#"])&&((t={})["#"]=e),"string"==typeof(r=s.valid(t))?a.get(e=r).put(t,i,n):s.is(t)?(a.put(function(o){t.get(function(t,n,e){return t?((r={})[t]={"#":t},void o(r)):i.call(a,{err:s.log('Only a node can be linked! Not "'+e.put+'"!')})},!0)}),t):(Object.plain(t)&&(t=o.get(e=a.back("opt.uuid")()).put(t)),a.get(e||o.back("opt.uuid")(7)).put(t,i,n))}})(T,"./set"),T(function(t){T("./shim");function n(){}var r=JSON.parseAsync||function(t,n,e){var o=+new Date;try{n(void 0,JSON.parse(t,e),w.sucks(+new Date-o))}catch(t){n(t)}},w=JSON.stringifyAsync||function(t,n,e,o){var i=+new Date;try{n(void 0,JSON.stringify(t,e,o),w.sucks(+new Date-i))}catch(t){n(t)}};function e(u){var g=function(){},v=u.opt||{};v.log=v.log||console.log,v.warn=v.warn||console.warn,v.error=v.error||console.error,v.gap=v.gap||v.wait||0,v.max=v.max||.3*(v.memory?999*v.memory*999:3e8),v.pack=v.pack||.01*v.max*.01,v.puff=v.puff||9;var y=setTimeout.turn||setTimeout,k=u.dup,h=k.check,m=k.track,i=(new Date,g.hear=function(t,a){if(t){if(v.max<=t.length)return g.say({dam:"!",err:"Message too big!"},a);g===this&&(i.d+=t.length||0,++i.c);var n,e=a.SH=+new Date,o=t[0];if("["===o)return r(t,function(t,i){if(t||!i)return g.say({dam:"!",err:"DAM JSON parse error."},a);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var r=v.puff;!function t(){for(var n,e=+new Date,o=0;o<"])&&"string"==typeof r&&r.slice(0,99).split(",").forEach(function(t){this[t]=1},n._.yo={}),r=n.dam)return(r=g.hear[r])&&r(n,e,u),void m(o);(r=n.ok)&&(n._.near=r["/"]);t=+new Date;s&&(s.is=t),e.SI=o,m.ed=function(t){o===t&&(m.ed=0,(t=k.s[o])&&(t.via=e,n.get&&(t.it=n)))},u.on("in",g.last=n),s&&(s.hd=+new Date),console.STAT&&console.STAT(t,+new Date-t,n.get?"msg get":n.put?"msg put":"msg"),m(o),a&&m(a),g.leap=g.last=null}};function b(t){var n=t.batch,e="string"==typeof n;if(e&&(n+="]"),t.batch=t.tail=null,n&&(e?!(n.length<3):n.length)){if(!e)try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return v.error("DAM JSON stringify error",t)}n&&_(n,t)}}function _(n,e){try{var t=e.wire;e.say?e.say(n):t.send&&t.send(n),g.say.d+=n.length||0,++g.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}i.c=i.d=0,function(){var p,d=0;function t(t,n){var e;return n instanceof Object?(Object.keys(n).sort().forEach(o,{to:e={},on:n}),e):n}function o(t){this.to[t]=this.on[t]}g.hash=function(o,i){var r,a,s,u=+new Date;w(o.put,function t(n,e){e=(a=a||(s=e||"")).slice(0,32768);r=String.hash(e,r),(a=a.slice(32768))?y(t,0):(console.STAT&&console.STAT(u,+new Date-u,"say json+hash"),o._.$put=s,o["##"]=r,g.say(o,i),delete o._.$put)},t)};g.say=function(r,a){var t;if((t=this)&&(t=t.to)&&t.next&&t.next(r),!r)return!1;var n,e,s,u=r["@"],c=r._||(r._=function(){}),o=r.DBG,i=+new Date;if(c.y=c.y||i,a||o&&(o.y=i),(n=r["#"])||(n=r["#"]=String.random(9)),p||m(n),(e=r["##"])||$===r.put||c.via||!u){if(!(a=!a&&u?(t=k.s[u])&&(t.via||(t=t.it)&&(t=t._)&&t.via)||(t=g.last)&&u===t["#"]&&g.leap:a)&&u)return k.s[u]?void 0:(console.STAT&&console.STAT(+new Date,++d,"total no peer to ack to"),!1);if(u&&!r.put&&!e&&((k.s[u]||"").it||"")["##"])return!1;if(!a&&g.way)return g.way(r);if(o&&(o.yh=+new Date),s=c.raw){if(o&&(o.yr=+new Date),!a||!a.id){if(!Object.plain(a||v.peers))return!1;var i=+new Date,f=(v.puff,v.peers),l=Object.keys(a||v.peers||{});return console.STAT&&console.STAT(i,+new Date-i,"peer keys"),void function t(){var n=+new Date;p=1;var e=c.raw;c.raw=s;for(var o,i=0;i<9&&(o=(l||"")[i++]);)(o=f[o]||(a||"")[o])&&g.say(r,o);c.raw=e,p=0,l=l.slice(i),console.STAT&&console.STAT(n,+new Date-n,"say loop"),l.length&&(y(t,0),u&&m(u))}()}if(!a.wire&&g.wire&&g.wire(a),n!==a.last){if(a.last=n,a===c.via)return!1;if((t=c.yo)&&(t[a.url]||t[a.pid]||t[a.id]))return!1;if(console.STAT&&console.STAT(i,((o||c).yp=+new Date)-(c.y||i),"say prep"),!p&&u&&m(u),a.batch){if(a.tail=(t=a.tail||0)+s.length,a.tail<=v.pack)return void(a.batch+=(t?",":"")+s);b(a)}a.batch="[";var h=+new Date;setTimeout(function(){console.STAT&&console.STAT(h,+new Date-h,"0ms TO"),b(a)},v.gap),_(s,a),console.STAT&&u===a.SI&&console.STAT(i,+new Date-a.SH,"say ack")}}else g.raw(r,a)}else g.hash(r,a)};g.say.c=g.say.d=0,g.raw=function(e,o){if(!e)return"";var i,r=e._||{};if(s=r.raw)return s;if("string"==typeof e)return e;var t=e["##"],n=e["@"];if(t&&n){if(!r.via&&h(n+t))return!1;if(s=(k.s[n]||"").it){if(t===s["##"])return!1;s["##"]||(s["##"]=t)}}if(!e.dam&&!e["@"]){var a,s,u=0,c=[];for(a in s=v.peers){var f=s[a];if(c.push(f.url||f.pid||f.id),6<++u)break}1<"]=c.join())}if(e.put&&(s=e.ok)&&(e.ok={"@":(s["@"]||1)-1,"/":s["/"]==e._.near?g.near:s["/"]}),i=r.$put)return s={},Object.keys(e).forEach(function(t){s[t]=e[t]}),s.put=":])([:",void w(s,function(t,n){t||(t=+new Date,s=n.indexOf('"put":":])([:"'),l($,n=n.slice(0,s+6)+i+n.slice(s+14)),console.STAT&&console.STAT(t,+new Date-t,"say slice"))});function l(t,n){t||(r.raw=n,g.say(e,o))}w(e,l)}}(),g.near=0,g.hi=function(n){var t;n.wire?(n.id?v.peers[n.url||n.id]=n:(t=n.id=n.id||n.url||String.random(9),g.say({dam:"?",pid:u.opt.pid},v.peers[t]=n),delete k.s[n.last]),n.met||(g.near++,n.met=+new Date,u.on("hi",n)),t=n.queue,n.queue=[],setTimeout.each(t||[],function(t){_(t,n)},0,9)):g.wire(n.length?{url:n,id:n}:n)},g.bye=function(t){t.met&&--g.near,delete t.met,u.on("bye",t);var n=+new Date;n-=t.met||n,g.bye.time=((g.bye.time||n)+n)/2},g.hear["!"]=function(t,n){v.error("Error:",t.err)},g.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(g.say({dam:"?",pid:v.pid,"@":t["#"]},n),delete k.s[n.last])},g.hear.mob=function(t,n){!t.peers||(t=(t=Object.keys(t.peers))[Math.random()*t.length>>0])&&(g.bye(n),g.hi(t))},u.on("create",function(t){t.opt.pid=t.opt.pid||String.random(9),this.to.next(t),t.on("out",g.say)}),u.on("bye",function(t,n){t=v.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),delete v.peers[t.id],t.wire=null});var e={};return u.on("bye",function(t,n){this.to.next(t),(n=console.STAT)&&(n.peers=g.near),(n=t.url)&&(e[n]=!0,setTimeout(function(){delete e[n]},v.lack||9e3))}),u.on("hi",function(e,t){this.to.next(e),(t=console.STAT)&&(t.peers=g.near),v.super||(9999<(t=Object.keys(u.next||"")).length&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(t,function(n){var t=u.next[n];v.super||(t.ask||"")[""]?g.say({get:{"#":n}},e):setTimeout.each(Object.keys(t.ask||""),function(t){t&&g.say({"##":String.hash((u.graph[n]||"")[t]),get:{"#":n,".":t}},e)})}))}),g}w.sucks=function(t){99"],n[":"],e),f&&4999880"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"]||n["<"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},h.text.hash=h.text.hash||function(t,n){if(l("text.hash"),"string"==typeof t){if(n=n||0,!t.length)return n;for(var e=0,o=t.length;e 99){ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } +json.sucks = function(d){ if(d > 99){ console.warn("JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."); json.sucks = noop } } function Mesh(root){ var mesh = function(){}; var opt = root.opt || {}; opt.log = opt.log || console.log; + opt.warn = opt.warn || console.warn; + opt.error = opt.error || console.error; opt.gap = opt.gap || opt.wait || 0; opt.max = opt.max || (opt.memory? (opt.memory * 999 * 999) : 300000000) * 0.3; opt.pack = opt.pack || (opt.max * 0.01 * 0.01); @@ -237,7 +239,7 @@ function Mesh(root){ if(!tmp){ return } if(t? 3 > tmp.length : !tmp.length){ return } // TODO: ^ if(!t){try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); - }catch(e){return opt.log('DAM JSON stringify error', e)}} + }catch(e){return opt.error('DAM JSON stringify error', e)}} if(!tmp){ return } send(tmp, peer); } @@ -285,7 +287,7 @@ function Mesh(root){ var tmp = +(new Date); tmp = (tmp - (peer.met||tmp)); mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2; } - mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } + mesh.hear['!'] = function(msg, peer){ opt.error('Error:', msg.err) } mesh.hear['?'] = function(msg, peer){ if(msg.pid){ if(!peer.pid){ peer.pid = msg.pid } diff --git a/src/root.js b/src/root.js index f0ef4c030..9fbe9cfe2 100644 --- a/src/root.js +++ b/src/root.js @@ -193,7 +193,7 @@ Gun.ask = require('./ask'); var ERR = "Error: Invalid graph!"; var cut = function(s){ return " '"+(''+s).slice(0,9)+"...' " } var L = JSON.stringify, MD = 2147483647, State = Gun.state; - var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; + var C = 0, CT, CF = function(){if(C>999 && (C/-(CT - (CT = +new Date))>1)){Gun.window && console.warn("You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");CF=function(){C=0}}}; }()); @@ -201,6 +201,9 @@ Gun.ask = require('./ask'); Gun.on.get = function(msg, gun){ var root = gun._, get = msg.get, soul = get['#'], node = root.graph[soul], has = get['.']; var next = root.next || (root.next = {}), at = next[soul]; + + // TODO: Azarattum bug, what is in graph is not same as what is in next. Fix! + // queue concurrent GETs? // TODO: consider tagging original message into dup for DAM. // TODO: ^ above? In chat app, 12 messages resulted in same peer asking for `#user.pub` 12 times. (same with #user GET too, yipes!) // DAM note: This also resulted in 12 replies from 1 peer which all had same ##hash but none of them deduped because each get was different. @@ -221,10 +224,14 @@ Gun.ask = require('./ask'); }*/ var ctx = msg._||{}, DBG = ctx.DBG = msg.DBG; DBG && (DBG.g = +new Date); - //console.log("GET:", get, node, has); + //console.log("GET:", get, node, has, at); + //if(!node && !at){ return root.on('get', msg) } + //if(has && node){ // replace 2 below lines to continue dev? if(!node){ return root.on('get', msg) } if(has){ - if('string' != typeof has || u === node[has]){ return root.on('get', msg) } + if('string' != typeof has || u === node[has]){ + if(!((at||'').next||'')[has]){ root.on('get', msg); return } + } node = state_ify({}, has, state_is(node, has), node[has], soul); // If we have a key in-memory, do we really need to fetch? // Maybe... in case the in-memory key we have is a local write @@ -251,7 +258,7 @@ Gun.ask = require('./ask'); tmp = keys.length; console.STAT && console.STAT(S, -(S - (S = +new Date)), 'got copied some'); DBG && (DBG.ga = +new Date); - root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG}); + root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG, FOO: 1}); console.STAT && console.STAT(S, +new Date - S, 'got in'); if(!tmp){ return } setTimeout.turn(go); diff --git a/test/common.js b/test/common.js index f17837e67..a62f92462 100644 --- a/test/common.js +++ b/test/common.js @@ -4001,7 +4001,7 @@ describe('Gun', function(){ } return false; } else { - console.warn('filter should be an Array'); + console.warn('Filter should be an Array'); return false; } } @@ -7490,7 +7490,7 @@ describe('Gun', function(){ return cb.call(gun, null, data); }, opt); } else { - //console.Log("Warning! You have no persistence layer to save to!"); + //console.warn("You have no persistence layer to save to!"); cb.call(gun, null); // This is in memory success, hardly "success" at all. } }); diff --git a/test/panic/scale.js b/test/panic/scale.js index 33ed3d9d3..83ca9751e 100644 --- a/test/panic/scale.js +++ b/test/panic/scale.js @@ -69,7 +69,7 @@ describe("Stress test GUN with SEA users causing PANIC!", function(){ // As a result, we have to manually pass it scope. test.async(); // Clean up from previous test. - try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.log("!!! WARNING !!!! MUST MANUALLY REMOVE OLD DATA!!!!, e") } + try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.warn("MUST MANUALLY REMOVE OLD DATA!!!!, e") } var purl = 'https://'+env.config.IP+':'+env.config.port; require('gun/test/https/test')(env.config.port + env.i, env.i+'data', function(){ // This server peer is now done with the test! diff --git a/test/panic/speak.js b/test/panic/speak.js index 94a7bde5d..26bc16a67 100644 --- a/test/panic/speak.js +++ b/test/panic/speak.js @@ -71,7 +71,7 @@ describe("Stress test GUN with SEA users causing PANIC!", function(){ test.async(); //setInterval(function(){ var u, t; u = process.memoryUsage().heapUsed; t = require('os').totalmem(); console.log((u/t).toFixed(2)) }, 1000) // Clean up from previous test. - try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.log("!!! WARNING !!!! MUST MANUALLY REMOVE OLD DATA!!!!, e") } + try{ require('fs').unlinkSync(env.i+'data') }catch(e){ console.warn("MUST MANUALLY REMOVE OLD DATA!!!!, e") } var purl = 'https://'+env.config.IP+':'+env.config.port; require('gun/test/https/test')(env.config.port + env.i, env.i+'data', function(){ // This server peer is now done with the test! diff --git a/test/sea/sea.js b/test/sea/sea.js index ed090db0d..33a2c128b 100755 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -50,7 +50,7 @@ describe('SEA', function(){ indexedDB.deleteDatabase('radatatest').onsuccess = function(e){ done() } }); /*it('generates aeskey from jwk', function(done) { // DEPRECATED!!! - console.log("WARNING: THIS DOES NOT WORK IN BROWSER!!!! NEEDS FIX"); + console.warn("THIS DOES NOT WORK IN BROWSER!!!! NEEDS FIX"); SEA.opt.aeskey('x','x').then(k => { //console.log("DATA", k.data); expect(k.data.toString('base64')).to.be('Xd6JaIf2dUybFb/jpEGuSAbfL96UABMR4IvxEGIuC74=') diff --git a/test/trace.js b/test/trace.js index 240080aba..3472f48ac 100644 --- a/test/trace.js +++ b/test/trace.js @@ -11,7 +11,7 @@ Trace.log = function(evname, msg) { // Trace.on('trace.end', {code: Trace.traces.join('\n')}); // }, 1000); if (!msg) { - //console.log('WARN, empty message: ',msg); + //console.warn('Empty message: ',msg); // msg=evname; // evname = 'GUN'; }