From 4d26c4035e0ad6e49c038dba94f03c9717960f80 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 21 Aug 2023 10:17:36 +0200 Subject: [PATCH] Use console.warn and console.error --- as.js | 4 +- axe.js | 2 +- examples/Main.js | 2 +- examples/react-native/src/extensions/sea.js | 2 +- examples/vanilla/video.html | 2 +- gun.js | 34 +++++----- gun.min.js | 2 +- lib/book.js | 2 +- lib/file.js | 4 +- 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 +- lib/utils.js | 2 +- nts.js | 2 +- sea.js | 70 ++++++++++----------- sea/auth.js | 6 +- sea/base64.js | 2 +- sea/certify.js | 8 +-- sea/create.js | 6 +- sea/decrypt.js | 4 +- sea/encrypt.js | 4 +- sea/pair.js | 8 +-- sea/sea.js | 2 +- sea/secret.js | 4 +- sea/share.js | 4 +- sea/shim.js | 2 +- sea/sign.js | 6 +- sea/verify.js | 8 +-- sea/work.js | 6 +- src/chain.js | 2 +- src/get.js | 4 +- src/localStorage.js | 4 +- src/map.js | 2 +- src/mesh.js | 10 +-- src/on.js | 2 +- src/root.js | 6 +- src/set.js | 2 +- test/common.js | 4 +- test/panic/scale.js | 2 +- test/panic/speak.js | 2 +- test/sea/sea.js | 2 +- test/trace.js | 2 +- 47 files changed, 149 insertions(+), 132 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/axe.js b/axe.js index 98b455725..b01b4590c 100644 --- a/axe.js +++ b/axe.js @@ -27,7 +27,7 @@ tmp = peers[id = 'http://localhost:8765/gun'] = peers[id] || {}; tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0; Gun.log.once("AXE", "AXE enabled: Trying to find network via (1) local peer (2) last used peers (3) a URL parameter, and last (4) hard coded peers."); - Gun.log.once("AXEWarn", "Warning: AXE is in alpha, use only for testing!"); + Gun.warn.once("AXEWarn", "AXE is in alpha, use only for testing!"); var last = lS.peers || ''; if(last){ last += ' ' } last += ((loc.search||'').split('peers=')[1]||'').split('&')[0]; diff --git a/examples/Main.js b/examples/Main.js index 7ea37fe71..0d7d97565 100644 --- a/examples/Main.js +++ b/examples/Main.js @@ -42,7 +42,7 @@ if (!isElectron && ('serviceWorker' in navigator)) { navigator.serviceWorker.register('iris/serviceworker.js') .catch(function(err) { // registration failed :( - console.log('ServiceWorker registration failed: ', err); + console.warn('ServiceWorker registration failed: ', err); }); }); } 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..745017b18 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}}}; }()); @@ -540,7 +540,11 @@ var obj_each = function(o,f){ Object.keys(o).forEach(f,o) }, text_rand = String.random, turn = setTimeout.turn, valid = Gun.valid, state_is = Gun.state.is, state_ify = Gun.state.ify, u, empty = {}, C; Gun.log = function(){ return (!Gun.log.off && C.log.apply(C, arguments)), [].slice.call(arguments).join(' ') }; + Gun.warn = function(){ return (!Gun.log.off && !Gun.warn.off && C.warn.apply(C, arguments)), [].slice.call(arguments).join(' ') }; + Gun.error = function(){ return (!Gun.log.off && !Gun.error.off && C.error.apply(C, arguments)), [].slice.call(arguments).join(' ') }; Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }; + Gun.warn.once = function(w,s,o){ return (o = Gun.warn.once)[w] = o[w] || 0, o[w]++ || Gun.warn(s) }; + Gun.error.once = function(w,s,o){ return (o = Gun.error.once)[w] = o[w] || 0, o[w]++ || Gun.error(s) }; if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window } try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){} @@ -696,7 +700,7 @@ var root = cat.root, gun = msg.$ || (msg.$ = cat.$), at = (gun||'')._ || empty, tmp = msg.put||'', soul = tmp['#'], key = tmp['.'], change = (u !== tmp['='])? tmp['='] : tmp[':'], state = tmp['>'] || -Infinity, sat; // eve = event, at = data at, cat = chain at, sat = sub at (children chains). if(u !== msg.put && (u === tmp['#'] || u === tmp['.'] || (u === tmp[':'] && u === tmp['=']) || u === tmp['>'])){ // convert from old format if(!valid(tmp)){ - if(!(soul = ((tmp||'')._||'')['#'])){ console.log("chain not yet supported for", tmp, '...', msg, cat); return; } + if(!(soul = ((tmp||'')._||'')['#'])){ console.warn("chain not yet supported for", tmp, '...', msg, cat); return; } gun = cat.root.$.get(soul); return setTimeout.each(Object.keys(tmp).sort(), function(k){ // TODO: .keys( is slow // BUG? ?Some re-in logic may depend on this being sync? if('_' == k || u === (state = state_is(tmp, k))){ return } @@ -852,7 +856,7 @@ var gun, tmp; if(typeof key === 'string'){ if(key.length == 0) { - (gun = this.chain())._.err = {err: Gun.log('0 length key!', key)}; + (gun = this.chain())._.err = {err: Gun.warn('0 length key!', key)}; if(cb){ cb.call(gun, gun._.err) } return gun; } @@ -943,7 +947,7 @@ gun = tmp(this, key); } if(!gun){ - (gun = this.chain())._.err = {err: Gun.log('Invalid get request!', key)}; // CLEAN UP + (gun = this.chain())._.err = {err: Gun.warn('Invalid get request!', key)}; // CLEAN UP if(cb){ cb.call(gun, gun._.err) } return gun; } @@ -1254,7 +1258,7 @@ return gun; } function none(gun,opt,chain){ - Gun.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."); + Gun.warn.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."); (chain = gun.chain())._.nix = gun.once(function(data, key){ chain._.on('in', this._) }); chain._.lex = gun._.lex; // TODO: Better approach in future? This is quick for now. return chain; @@ -1329,7 +1333,7 @@ gun.on('in', map, chain._); return chain; } - Gun.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."); + Gun.warn.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."); chain = gun.chain(); gun.map().on(function(data, key, msg, eve){ var next = (cb||noop).call(this, data, key, msg, eve); @@ -1366,7 +1370,7 @@ } gun.put(function(go){ item.get(function(soul, o, msg){ // TODO: BUG! We no longer have this option? & go error not handled? - if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + msg.put + '"!')}) } + if(!soul){ return cb.call(gun, {err: Gun.warn('Only a node can be linked! Not "' + msg.put + '"!')}) } (tmp = {})[soul] = {'#': soul}; go(tmp); },true); }) @@ -1380,12 +1384,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 +1625,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 +1673,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 } @@ -1708,7 +1714,7 @@ if(tmp = console.STAT){ tmp.peers = mesh.near } if(opt.super){ return } // temporary (?) until we have better fix/solution? var souls = Object.keys(root.next||''); // TODO: .keys( is slow - if(souls.length > 9999 && !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()`.") } + if(souls.length > 9999 && !console.SUBS){ console.warn(console.SUBS = "You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") } setTimeout.each(souls, function(soul){ var node = root.next[soul]; if(opt.super || (node.ask||'')['']){ mesh.say({get: {'#': soul}}, peer); return } setTimeout.each(Object.keys(node.ask||''), function(key){ if(!key){ return } @@ -1794,7 +1800,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]}}; } @@ -1841,7 +1847,7 @@ try{!err && store.setItem(opt.prefix, tmp); }catch(e){ err = stop = e || "localStorage failure" } if(err){ - Gun.log(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); + Gun.error(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); root.on('localStorage:error', {err: err, get: opt.prefix, put: disk}); } size = tmp.length; @@ -1862,7 +1868,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..629d85aa8 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})(j,"./state"),j(function(t){j("./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}})(j,"./dup"),j(function(t){j("./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)}})(j,"./ask"),j(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(){},j("./shim"),f.valid=j("./valid"),f.state=j("./state"),f.on=j("./onto"),f.dup=j("./dup"),f.ask=j("./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["#"],w(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 w(s);(p=y[h])?(v=p._)?h!==v["#"]?g=_+$(h)+"soul not same.":(d=v[">"])||(g=_+$(h)+"no state."):g=_+$(h)+"no meta.":g=_+$(h)+"no node.",l=Object.keys(p||{})}if(g)return a.err=s.err=g,void w(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=_+$(e)+"on"+$(h)+"no state.";break}if(!A(i)){g=_+$(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(uT?T: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),w(o),this.to.next(t)}function w(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,_="Error: Invalid graph!",$=function(t){return" '"+(""+t).slice(0,9)+"...' "},j=JSON.stringify,T=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.warn("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})(j,"./chain"),j(function(t){var g=j("./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.warn("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.warn("Invalid get request!",t)},n&&n.call(i,i._.err)),i};var v,a={},s=g.valid})(j,"./get"),j(function(t){var y=j("./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=w(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=w(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,w=y.state.ify})(j,"./put"),j(function(t){var n=j("./root");j("./chain"),j("./back"),j("./put"),j("./get"),t.exports=n})(j,"./index"),j(function(t){var g=j("./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.warn.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}})(j,"./on"),j(function(t){var s=j("./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.warn.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(){}})(j,"./map"),j(function(t){var s=j("./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.warn('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))}})(j,"./set"),j(function(t){j("./shim");function n(){}var r=JSON.parseAsync||function(t,n,e){var o=+new Date;try{n(void 0,JSON.parse(t,e),_.sucks(+new Date-o))}catch(t){n(t)}},_=JSON.stringifyAsync||function(t,n,e,o){var i=+new Date;try{n(void 0,JSON.stringify(t,e,o),_.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&&w(n,t)}}function w(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;_(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),w(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 _(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))}_(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){w(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.warn(console.SUBS="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}_.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 { try { - if(cb){ try{ cb() }catch(e){console.log(e)} } + if(cb){ try{ cb() }catch(e){console.warn(e)} } return; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -376,10 +376,10 @@ } dh = dh || {}; var r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -409,7 +409,7 @@ && u !== await SEA.verify(check, pair)){ // don't sign if we already signed it. var r = await S.parse(check); if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } var pub = pair.pub; @@ -421,10 +421,10 @@ var r = {m: json, s: shim.Buffer.from(sig, 'binary').toString(opt.encode || 'base64')} if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -445,7 +445,7 @@ var json = await S.parse(data); if(false === pair){ // don't verify! var raw = await S.parse(json.m); - if(cb){ try{ cb(raw) }catch(e){console.log(e)} } + if(cb){ try{ cb(raw) }catch(e){console.warn(e)} } return raw; } opt = opt || {}; @@ -465,10 +465,10 @@ } var r = check? await S.parse(json.m) : u; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); // mismatched owner FOR MARTTI + console.warn(e); // mismatched owner FOR MARTTI SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -508,7 +508,7 @@ } var r = check? await S.parse(json.m) : u; O.fall_soul = tmp['#']; O.fall_key = tmp['.']; O.fall_val = data; O.fall_state = tmp['>']; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } SEA.opt.fallback = 2; @@ -560,10 +560,10 @@ } if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -603,10 +603,10 @@ } } var r = await S.parse(new shim.TextDecoder('utf8').decode(ct)); - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -642,10 +642,10 @@ return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k); }) var r = derived; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -683,7 +683,7 @@ "cb": A callback function after all things are done. "opt": If opt.expiry (a timestamp) is set, SEA won't sync data after opt.expiry. If opt.block is set, SEA will look for block before syncing. */ - console.log('SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version.') + console.warn('SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version.') certificants = (() => { var data = [] @@ -704,7 +704,7 @@ return })() - if (!certificants) return console.log("No certificant found.") + if (!certificants) return console.warn("No certificant found.") const expiry = opt.expiry && (typeof opt.expiry === 'number' || typeof opt.expiry === 'string') ? parseFloat(opt.expiry) : null const readPolicy = (policy || {}).read ? policy.read : null @@ -715,7 +715,7 @@ const readBlock = block.read && (typeof block.read === 'string' || (block.read || {})['#']) ? block.read : null const writeBlock = typeof block === 'string' ? block : block.write && (typeof block.write === 'string' || block.write['#']) ? block.write : null - if (!readPolicy && !writePolicy) return console.log("No policy found.") + if (!readPolicy && !writePolicy) return console.warn("No policy found.") // reserved keys: c, e, r, w, rb, wb const data = JSON.stringify({ @@ -731,7 +731,7 @@ var r = certificate if(!opt.raw){ r = 'SEA'+JSON.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { SEA.err = e; @@ -782,7 +782,7 @@ const hash = shim.Buffer.from(sha1, 'binary') return hash.toString('hex', hash.length - 8) // 16-bit ID as hex } catch (e) { - console.log(e) + console.warn(e) throw e } }); @@ -873,12 +873,12 @@ if(!alias){ err = "No user." } if((pass||'').length < 8){ err = "Password too short!" } if(err){ - cb({err: Gun.log(err)}); + cb({err: Gun.error(err)}); return gun; } } if(cat.ing){ - (cb || noop)({err: Gun.log("User is already being created or authenticated!"), wait: true}); + (cb || noop)({err: Gun.error("User is already being created or authenticated!"), wait: true}); return gun; } cat.ing = true; @@ -887,7 +887,7 @@ act.pubs = pubs; if(pubs && !opt.already){ // If we can enforce that a user name is already taken, it might be nice to try, but this is not guaranteed. - var ack = {err: Gun.log('User already created!')}; + var ack = {err: Gun.error('User already created!')}; cat.ing = false; (cb || noop)(ack); gun.leave(); @@ -973,7 +973,7 @@ var gun = this, cat = (gun._), root = gun.back(-1); if(cat.ing){ - (cb || noop)({err: Gun.log("User is already being created or authenticated!"), wait: true}); + (cb || noop)({err: Gun.warn("User is already being created or authenticated!"), wait: true}); return gun; } cat.ing = true; @@ -1051,7 +1051,7 @@ } else { setTimeout(function(){ (root._).on('auth', at) },1) } // if not, hackily add a timeout. //at.on('auth', at) // Arrgh, this doesn't work without event "merge" code, but "merge" code causes stack overflow and crashes after logging in & trying to write data. }catch(e){ - Gun.log("Your 'auth' callback crashed with:", e); + Gun.warn("Your 'auth' callback crashed with:", e); } } act.h = function(data){ @@ -1087,7 +1087,7 @@ root.get('~'+act.pair.pub).get('auth').put(auth, cb || noop); } act.err = function(e){ - var ack = {err: Gun.log(e || 'User cannot be found!')}; + var ack = {err: Gun.error(e || 'User cannot be found!')}; cat.ing = false; (cb || noop)(ack); } @@ -1162,7 +1162,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!!!"); + console.warn("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){ @@ -1174,7 +1174,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/sea/auth.js b/sea/auth.js index cdbdaea5e..3d2812c9d 100644 --- a/sea/auth.js +++ b/sea/auth.js @@ -11,7 +11,7 @@ var gun = this, cat = (gun._), root = gun.back(-1); if(cat.ing){ - (cb || noop)({err: Gun.log("User is already being created or authenticated!"), wait: true}); + (cb || noop)({err: Gun.warn("User is already being created or authenticated!"), wait: true}); return gun; } cat.ing = true; @@ -85,7 +85,7 @@ } else { setTimeout(function(){ (root._).on('auth', at) },1) } // if not, hackily add a timeout. //at.on('auth', at) // Arrgh, this doesn't work without event "merge" code, but "merge" code causes stack overflow and crashes after logging in & trying to write data. }catch(e){ - Gun.log("Your 'auth' callback crashed with:", e); + Gun.warn("Your 'auth' callback crashed with:", e); } } act.h = function(data){ @@ -121,7 +121,7 @@ root.get('~'+act.pair.pub).get('auth').put(auth, cb || noop); } act.err = function(e){ - var ack = {err: Gun.log(e || 'User cannot be found!')}; + var ack = {err: Gun.error(e || 'User cannot be found!')}; cat.ing = false; (cb || noop)(ack); } diff --git a/sea/base64.js b/sea/base64.js index 5c4b4a1d4..4c332ed11 100644 --- a/sea/base64.js +++ b/sea/base64.js @@ -2,7 +2,7 @@ var u; if(u+''== typeof btoa){ if(u+'' == typeof Buffer){ - try{ global.Buffer = require("buffer", 1).Buffer }catch(e){ console.log("Please `npm install buffer` or add it to your package.json !") } + try{ global.Buffer = require("buffer", 1).Buffer }catch(e){ console.warn("Please `npm install buffer` or add it to your package.json !") } } global.btoa = function(data){ return Buffer.from(data, "binary").toString("base64") }; global.atob = function(data){ return Buffer.from(data, "base64").toString("binary") }; diff --git a/sea/certify.js b/sea/certify.js index b6145d011..86363bb3b 100644 --- a/sea/certify.js +++ b/sea/certify.js @@ -11,7 +11,7 @@ "cb": A callback function after all things are done. "opt": If opt.expiry (a timestamp) is set, SEA won't sync data after opt.expiry. If opt.block is set, SEA will look for block before syncing. */ - console.log('SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version.') + console.warn('SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version.') certificants = (() => { var data = [] @@ -32,7 +32,7 @@ return })() - if (!certificants) return console.log("No certificant found.") + if (!certificants) return console.warn("No certificant found.") const expiry = opt.expiry && (typeof opt.expiry === 'number' || typeof opt.expiry === 'string') ? parseFloat(opt.expiry) : null const readPolicy = (policy || {}).read ? policy.read : null @@ -43,7 +43,7 @@ const readBlock = block.read && (typeof block.read === 'string' || (block.read || {})['#']) ? block.read : null const writeBlock = typeof block === 'string' ? block : block.write && (typeof block.write === 'string' || block.write['#']) ? block.write : null - if (!readPolicy && !writePolicy) return console.log("No policy found.") + if (!readPolicy && !writePolicy) return console.warn("No policy found.") // reserved keys: c, e, r, w, rb, wb const data = JSON.stringify({ @@ -59,7 +59,7 @@ var r = certificate if(!opt.raw){ r = 'SEA'+JSON.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { SEA.err = e; diff --git a/sea/create.js b/sea/create.js index da3174814..874d6a165 100644 --- a/sea/create.js +++ b/sea/create.js @@ -17,12 +17,12 @@ if(!alias){ err = "No user." } if((pass||'').length < 8){ err = "Password too short!" } if(err){ - cb({err: Gun.log(err)}); + cb({err: Gun.error(err)}); return gun; } } if(cat.ing){ - (cb || noop)({err: Gun.log("User is already being created or authenticated!"), wait: true}); + (cb || noop)({err: Gun.error("User is already being created or authenticated!"), wait: true}); return gun; } cat.ing = true; @@ -31,7 +31,7 @@ act.pubs = pubs; if(pubs && !opt.already){ // If we can enforce that a user name is already taken, it might be nice to try, but this is not guaranteed. - var ack = {err: Gun.log('User already created!')}; + var ack = {err: Gun.error('User already created!')}; cat.ing = false; (cb || noop)(ack); gun.leave(); diff --git a/sea/decrypt.js b/sea/decrypt.js index 79fe6a90b..bb658273a 100644 --- a/sea/decrypt.js +++ b/sea/decrypt.js @@ -28,10 +28,10 @@ } } var r = await S.parse(new shim.TextDecoder('utf8').decode(ct)); - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/sea/encrypt.js b/sea/encrypt.js index 4f0b6c9a8..258011c83 100644 --- a/sea/encrypt.js +++ b/sea/encrypt.js @@ -26,10 +26,10 @@ } if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/sea/pair.js b/sea/pair.js index b01aad31a..99504d7f3 100644 --- a/sea/pair.js +++ b/sea/pair.js @@ -4,10 +4,10 @@ var S = require('./settings'); SEA.name = SEA.name || (async (cb, opt) => { try { - if(cb){ try{ cb() }catch(e){console.log(e)} } + if(cb){ try{ cb() }catch(e){console.warn(e)} } return; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -59,10 +59,10 @@ } dh = dh || {}; var r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/sea/sea.js b/sea/sea.js index c870ed3c3..4da2634d6 100644 --- a/sea/sea.js +++ b/sea/sea.js @@ -37,7 +37,7 @@ const hash = shim.Buffer.from(sha1, 'binary') return hash.toString('hex', hash.length - 8) // 16-bit ID as hex } catch (e) { - console.log(e) + console.warn(e) throw e } }); diff --git a/sea/secret.js b/sea/secret.js index 949ff398d..7c1d846a7 100644 --- a/sea/secret.js +++ b/sea/secret.js @@ -24,10 +24,10 @@ return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k); }) var r = derived; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/sea/share.js b/sea/share.js index 1fd24f82c..2b64bd747 100644 --- a/sea/share.js +++ b/sea/share.js @@ -10,7 +10,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!!!"); + console.warn("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){ @@ -22,7 +22,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/sea/shim.js b/sea/shim.js index e955e736e..185e5ebff 100644 --- a/sea/shim.js +++ b/sea/shim.js @@ -40,7 +40,7 @@ api.ossl = api.subtle = new WebCrypto({directory: 'ossl'}).subtle // ECDH } catch(e){ - console.log("Please `npm install @peculiar/webcrypto` or add it to your package.json !"); + console.warn("Please `npm install @peculiar/webcrypto` or add it to your package.json !"); }} module.exports = api diff --git a/sea/sign.js b/sea/sign.js index f286dd0ca..b9cdaacb3 100644 --- a/sea/sign.js +++ b/sea/sign.js @@ -18,7 +18,7 @@ && u !== await SEA.verify(check, pair)){ // don't sign if we already signed it. var r = await S.parse(check); if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } var pub = pair.pub; @@ -30,10 +30,10 @@ var r = {m: json, s: shim.Buffer.from(sig, 'binary').toString(opt.encode || 'base64')} if(!opt.raw){ r = 'SEA' + await shim.stringify(r) } - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/sea/verify.js b/sea/verify.js index b431badf5..d48ca10b2 100644 --- a/sea/verify.js +++ b/sea/verify.js @@ -9,7 +9,7 @@ var json = await S.parse(data); if(false === pair){ // don't verify! var raw = await S.parse(json.m); - if(cb){ try{ cb(raw) }catch(e){console.log(e)} } + if(cb){ try{ cb(raw) }catch(e){console.warn(e)} } return raw; } opt = opt || {}; @@ -29,10 +29,10 @@ } var r = check? await S.parse(json.m) : u; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); // mismatched owner FOR MARTTI + console.warn(e); // mismatched owner FOR MARTTI SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } @@ -72,7 +72,7 @@ } var r = check? await S.parse(json.m) : u; O.fall_soul = tmp['#']; O.fall_key = tmp['.']; O.fall_val = data; O.fall_state = tmp['>']; - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } SEA.opt.fallback = 2; diff --git a/sea/work.js b/sea/work.js index e6f68493a..df691ce3c 100644 --- a/sea/work.js +++ b/sea/work.js @@ -15,7 +15,7 @@ data = (typeof data == 'string')? data : await shim.stringify(data); if('sha' === (opt.name||'').toLowerCase().slice(0,3)){ var rsha = shim.Buffer.from(await sha(data, opt.name), 'binary').toString(opt.encode || 'base64') - if(cb){ try{ cb(rsha) }catch(e){console.log(e)} } + if(cb){ try{ cb(rsha) }catch(e){console.warn(e)} } return rsha; } salt = salt || shim.random(9); @@ -28,10 +28,10 @@ }, key, opt.length || (S.pbkdf2.ks * 8)) data = shim.random(data.length) // Erase data in case of passphrase var r = shim.Buffer.from(work, 'binary').toString(opt.encode || 'base64') - if(cb){ try{ cb(r) }catch(e){console.log(e)} } + if(cb){ try{ cb(r) }catch(e){console.warn(e)} } return r; } catch(e) { - console.log(e); + console.warn(e); SEA.err = e; if(SEA.throw){ throw e } if(cb){ cb() } diff --git a/src/chain.js b/src/chain.js index d8278984f..fa9a69c14 100644 --- a/src/chain.js +++ b/src/chain.js @@ -99,7 +99,7 @@ function input(msg, cat){ cat = cat || this.as; // TODO: V8 may not be able to o var root = cat.root, gun = msg.$ || (msg.$ = cat.$), at = (gun||'')._ || empty, tmp = msg.put||'', soul = tmp['#'], key = tmp['.'], change = (u !== tmp['='])? tmp['='] : tmp[':'], state = tmp['>'] || -Infinity, sat; // eve = event, at = data at, cat = chain at, sat = sub at (children chains). if(u !== msg.put && (u === tmp['#'] || u === tmp['.'] || (u === tmp[':'] && u === tmp['=']) || u === tmp['>'])){ // convert from old format if(!valid(tmp)){ - if(!(soul = ((tmp||'')._||'')['#'])){ console.log("chain not yet supported for", tmp, '...', msg, cat); return; } + if(!(soul = ((tmp||'')._||'')['#'])){ console.warn("chain not yet supported for", tmp, '...', msg, cat); return; } gun = cat.root.$.get(soul); return setTimeout.each(Object.keys(tmp).sort(), function(k){ // TODO: .keys( is slow // BUG? ?Some re-in logic may depend on this being sync? if('_' == k || u === (state = state_is(tmp, k))){ return } diff --git a/src/get.js b/src/get.js index a47f72eaf..659d5cc71 100644 --- a/src/get.js +++ b/src/get.js @@ -4,7 +4,7 @@ Gun.chain.get = function(key, cb, as){ var gun, tmp; if(typeof key === 'string'){ if(key.length == 0) { - (gun = this.chain())._.err = {err: Gun.log('0 length key!', key)}; + (gun = this.chain())._.err = {err: Gun.warn('0 length key!', key)}; if(cb){ cb.call(gun, gun._.err) } return gun; } @@ -95,7 +95,7 @@ Gun.chain.get = function(key, cb, as){ gun = tmp(this, key); } if(!gun){ - (gun = this.chain())._.err = {err: Gun.log('Invalid get request!', key)}; // CLEAN UP + (gun = this.chain())._.err = {err: Gun.warn('Invalid get request!', key)}; // CLEAN UP if(cb){ cb.call(gun, gun._.err) } return gun; } diff --git a/src/localStorage.js b/src/localStorage.js index ff966c907..f810f26f9 100644 --- a/src/localStorage.js +++ b/src/localStorage.js @@ -4,7 +4,7 @@ if(typeof Gun === 'undefined'){ return } 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]}}; } @@ -51,7 +51,7 @@ Gun.on('create', function lg(root){ try{!err && store.setItem(opt.prefix, tmp); }catch(e){ err = stop = e || "localStorage failure" } if(err){ - Gun.log(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); + Gun.error(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"); root.on('localStorage:error', {err: err, get: opt.prefix, put: disk}); } size = tmp.length; diff --git a/src/map.js b/src/map.js index f929c73e5..ddbf59409 100644 --- a/src/map.js +++ b/src/map.js @@ -22,7 +22,7 @@ Gun.chain.map = function(cb, opt, t){ gun.on('in', map, chain._); return chain; } - Gun.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."); + Gun.warn.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."); chain = gun.chain(); gun.map().on(function(data, key, msg, eve){ var next = (cb||noop).call(this, data, key, msg, eve); diff --git a/src/mesh.js b/src/mesh.js index dc0e53703..5fcdb35f5 100644 --- a/src/mesh.js +++ b/src/mesh.js @@ -4,12 +4,14 @@ require('./shim'); 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); @@ -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 } @@ -326,7 +328,7 @@ function Mesh(root){ if(tmp = console.STAT){ tmp.peers = mesh.near } if(opt.super){ return } // temporary (?) until we have better fix/solution? var souls = Object.keys(root.next||''); // TODO: .keys( is slow - if(souls.length > 9999 && !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()`.") } + if(souls.length > 9999 && !console.SUBS){ console.warn(console.SUBS = "You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.") } setTimeout.each(souls, function(soul){ var node = root.next[soul]; if(opt.super || (node.ask||'')['']){ mesh.say({get: {'#': soul}}, peer); return } setTimeout.each(Object.keys(node.ask||''), function(key){ if(!key){ return } diff --git a/src/on.js b/src/on.js index c2fc13865..79ffa3306 100644 --- a/src/on.js +++ b/src/on.js @@ -83,7 +83,7 @@ Gun.chain.once = function(cb, opt){ opt = opt || {}; // avoid rewriting return gun; } function none(gun,opt,chain){ - Gun.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."); + Gun.warn.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."); (chain = gun.chain())._.nix = gun.once(function(data, key){ chain._.on('in', this._) }); chain._.lex = gun._.lex; // TODO: Better approach in future? This is quick for now. return chain; diff --git a/src/root.js b/src/root.js index f0ef4c030..824faebae 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}}}; }()); @@ -290,7 +290,11 @@ Gun.ask = require('./ask'); var obj_each = function(o,f){ Object.keys(o).forEach(f,o) }, text_rand = String.random, turn = setTimeout.turn, valid = Gun.valid, state_is = Gun.state.is, state_ify = Gun.state.ify, u, empty = {}, C; Gun.log = function(){ return (!Gun.log.off && C.log.apply(C, arguments)), [].slice.call(arguments).join(' ') }; +Gun.warn = function(){ return (!Gun.log.off && !Gun.warn.off && C.warn.apply(C, arguments)), [].slice.call(arguments).join(' ') }; +Gun.error = function(){ return (!Gun.log.off && !Gun.error.off && C.error.apply(C, arguments)), [].slice.call(arguments).join(' ') }; Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }; +Gun.warn.once = function(w,s,o){ return (o = Gun.warn.once)[w] = o[w] || 0, o[w]++ || Gun.warn(s) }; +Gun.error.once = function(w,s,o){ return (o = Gun.error.once)[w] = o[w] || 0, o[w]++ || Gun.error(s) }; if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window } try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){} diff --git a/src/set.js b/src/set.js index 36a7cb255..1254de4c9 100644 --- a/src/set.js +++ b/src/set.js @@ -14,7 +14,7 @@ Gun.chain.set = function(item, cb, opt){ } gun.put(function(go){ item.get(function(soul, o, msg){ // TODO: BUG! We no longer have this option? & go error not handled? - if(!soul){ return cb.call(gun, {err: Gun.log('Only a node can be linked! Not "' + msg.put + '"!')}) } + if(!soul){ return cb.call(gun, {err: Gun.warn('Only a node can be linked! Not "' + msg.put + '"!')}) } (tmp = {})[soul] = {'#': soul}; go(tmp); },true); }) 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'; }