From a65795592e55018ff342062036818c03b3c7ee98 Mon Sep 17 00:00:00 2001 From: dbaranov Date: Sat, 5 Feb 2022 14:34:42 +0300 Subject: [PATCH] LEX improvement --- gun.js | 48 ++++++++++++++++-------------------------------- gun.min.js | 2 +- lib/utils.js | 24 ++++++++---------------- src/shim.js | 24 ++++++++---------------- 4 files changed, 33 insertions(+), 65 deletions(-) diff --git a/gun.js b/gun.js index f5bbe2dd3..f4ec5d1ed 100644 --- a/gun.js +++ b/gun.js @@ -22,22 +22,14 @@ while(l-- > 0){ s += c.charAt(Math.floor(Math.random() * c.length)) } return s; } - String.match = function(t, o){ var tmp, u; - if('string' !== typeof t){ return false } - if('string' == typeof o){ o = {'=': o} } - o = o || {}; - tmp = (o['='] || o['*'] || o['>'] || o['<']); - if(t === tmp){ return true } - if(u !== o['=']){ return false } - tmp = (o['*'] || o['>']); - if(t.slice(0, (tmp||'').length) === tmp){ return true } - if(u !== o['*']){ return false } - if(u !== o['>'] && u !== o['<']){ - return (t >= o['>'] && t <= o['<'])? true : false; - } - if(u !== o['>'] && t >= o['>']){ return true } - if(u !== o['<'] && t <= o['<']){ return true } - return false; + String.match = function(t, o){ + return ( + ('string' === typeof t && (t === o || t === o['='])) || + (o['='] === undefined && + (o['>'] === undefined || t >= o['>']) && + (o['<'] === undefined || t <= o['<']) && + (o['*'] === undefined || t.slice(0, o['*'].length) === o['*'])) + ); } String.hash = function(s, c){ // via SO if(typeof s !== 'string'){ return } @@ -1799,22 +1791,14 @@ while(l > 0){ s += c.charAt(Math.floor(Math.random() * c.length)); l-- } return s; } - Type.text.match = Type.text.match || function(t, o){ var tmp, u; DEP('text.match'); - if('string' !== typeof t){ return false } - if('string' == typeof o){ o = {'=': o} } - o = o || {}; - tmp = (o['='] || o['*'] || o['>'] || o['<']); - if(t === tmp){ return true } - if(u !== o['=']){ return false } - tmp = (o['*'] || o['>'] || o['<']); - if(t.slice(0, (tmp||'').length) === tmp){ return true } - if(u !== o['*']){ return false } - if(u !== o['>'] && u !== o['<']){ - return (t >= o['>'] && t <= o['<'])? true : false; - } - if(u !== o['>'] && t >= o['>']){ return true } - if(u !== o['<'] && t <= o['<']){ return true } - return false; + Type.text.match = Type.text.match || function(t, o){ DEP('text.match'); + return ( + ('string' === typeof t && (t === o || t === o['='])) || + (o['='] === undefined && + (o['>'] === undefined || t >= o['>']) && + (o['<'] === undefined || t <= o['<']) && + (o['*'] === undefined || t.slice(0, o['*'].length) === o['*'])) + ); } Type.text.hash = Type.text.hash || function(s, c){ // via SO DEP('text.hash'); diff --git a/gun.min.js b/gun.min.js index e162d1bae..275f66636 100644 --- a/gun.min.js +++ b/gun.min.js @@ -1 +1 @@ -!function(){function f(e,t){return t?require(e):e.slice?f[o(e)]:function(t,n){e(t={exports:{}}),f[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var n=module;f(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"]||e;if(o)return"number"==typeof(o=o[n])?o:-1/0},n.ify=function(t,n,e,o,i){(t=t||{})._=t._||{},i&&(t._["#"]=i);var r=t._[">"]||(t._[">"]={});return void 0!==n&&"_"!==n&&("number"==typeof e&&(r[n]=e),void 0!==o&&(t[n]=o)),t},t.exports=n})(f,"./state"),f(function(t){f("./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){var n=r[t]||(r[t]={});return n.was=i.now=+new Date,i.to||(i.to=setTimeout(i.drop,o.age+9)),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}})(f,"./dup"),f(function(t){f("./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];if(!i)return;return n&&(i=this.on(o,n),clearTimeout(i.err),i.err=setTimeout(function(){i.off()},e)),!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)}})(f,"./ask"),f(function(t){function c(t){return t instanceof c?(this._={$:this}).$:this instanceof c?c.create(this._={$:this,opt:t}):new c(t)}function u(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++]);)O(r,n,m(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):T,$:p.$,_:o,DBG:u}),console.STAT&&console.STAT(s,+new Date-s,"got in"),e&&setTimeout.turn(t)}(),a||p.on("in",{"@":t["#"]})}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.202,(c.chain=c.prototype).toJSON=function(){},f("./shim"),c.valid=f("./valid"),c.state=f("./state"),c.on=f("./onto"),c.dup=f("./dup"),c.ask=f("./ask"),function(){function b(t){if(t)if(t.out!==b){var n,e=this.as,o=e.at||e,i=o.$,r=o.dup,a=t.DBG;if((n=t["#"])||(n=t["#"]=g(9)),!r.check(n)){if(r.track(n),n=t._,t._="function"==typeof n?n:function(){},t.$&&t.$===(t.$._||"").$||(t.$=i),t["@"]&&!t.put&&function(t){var n,e=t["@"]||"";if(!(n=e._))return;n.acks=(n.acks||0)+1,(n.err=t.err)&&(t["@"]=n["#"],$(n));n.stop||n.crack||(n.crack=n.match&&n.match.push(function(){u(n)}));u(n)}(t),!o.ask(t["@"],t)){if(a&&(a.u=+new Date),t.put)return void s(t);t.get&&c.on.get(t,i)}a&&(a.uc=+new Date),this.to.next(t),a&&(a.ua=+new Date),t.nts||t.NTS||(t.out=b,o.on("out",t),a&&(a.ue=+new Date))}}else this.to.next(t)}function s(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=a.put,c=s.DBG=a.DBG,f=+new Date;if(!u["#"]||!u["."]){c&&(c.p=f),s["#"]=a["#"],s.msg=a,s.all=0,s.stun=1;var l=Object.keys(u);console.STAT&&console.STAT(f,((c||s).pk=+new Date)-f,"put sort");var h,p,d,g,v,y,k,m=0;!function t(n){if(h!=m){if(!(d=l[h=m]))return console.STAT&&console.STAT(f,((c||s).pd=+new Date)-f,"put"),void $(s);(g=u[d])?(k=g._)?d!==k["#"]?y=w+j(d)+"soul not same.":(v=k[">"])||(y=w+j(d)+"no state."):y=w+j(d)+"no meta.":y=w+j(d)+"no node.",p=Object.keys(g||{})}if(y)return a.err=s.err=y,void $(s);var e,o=0;for(n=n||0;n++<9&&(e=p[o++]);)if("_"!==e){var i=g[e],r=v[e];if(T===r){y=w+j(e)+"on"+j(d)+"no state.";break}if(!S(i)){y=w+j(e)+"on"+j(d)+"bad "+typeof i+j(i);break}_(i,e,d,r,a)}(p=p.slice(o)).length?x(t):(++m,p=null,t(n))}()}}}function _(t,n,e,o,i){var r,a=i._||"",s=a.root,u=s.graph,c=u[e]||D,f=m(c,n,1),l=c[n],h=a.DBG;(r=console.STAT)&&(u[e]&&l||(r.has=(r.has||0)+1));var p=k();if(py?y:r),void(console.STAT&&console.STAT((h||a).Hf=+new Date,r,"future"));if((!(o":o},_:a})}}function e(t){var n;(n=(t._||"").DBG)&&(n.pa=+new Date,n.pm=n.pm||+new Date);var e,o=this.as,i=o.graph,r=t._,a=t.put,s=a["#"],u=a["."],c=a[":"],f=a[">"];t["#"];(e=r.msg)&&(e=e.put)&&(e=e[s])&&O(e,u,f,c,s),i[s]=O(i[s],u,f,c,s),(e=(o.next||"")[s])&&e.on("in",t),$(r),this.to.next(t)}function $(t,n){var e;if(!t.stop&&(t.err||!(0<--t.stun))&&(t.stop=1,e=t.root)){var o=t.match;o.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))}}function u(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?T:{"":1}}))}c.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||c.on,t.ask=t.ask||c.ask,t.dup=t.dup||c.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),c.on("create",t),t.on("create",t)),t.once=1,n},c.on.put=s,console.log("BEWARE: BETA VERSION OF NEW GUN! NOT ALL FEATURES FINISHED!");var w="Error: Invalid graph!",j=function(t){return" '"+(""+t).slice(0,9)+"...' "},v=JSON.stringify,y=2147483647,k=c.state}(),c.on.get=function(t,n){var e=n._,o=t.get,i=o["#"],r=e.graph[i],a=o["."],s=((e.next||(e.next={}))[i],(t._||{}).DBG=t.DBG);if(s&&(s.g=+new Date),!r)return e.on("get",t);if(a){if("string"!=typeof a||T===r[a])return e.on("get",t);r=O({},a,m(r,a),r[a],i)}r&&u(t,r),e.on("get",t)},c.on.get.ack=u,c.chain.opt=function(t){t=t||{};var e=this._,n=t.peers||t;return Object.plain(t)||(t={}),Object.plain(e.opt)||(e.opt=t),"string"==typeof n&&(n=[n]),n instanceof Array&&(Object.plain(e.opt.peers)||(e.opt.peers={}),n.forEach(function(t){var n={};n.id=n.url=t,e.opt.peers[t]=e.opt.peers[t]||n})),e.opt.peers=e.opt.peers||{},o(t,function t(n){var e=this[n];this&&this.hasOwnProperty(n)||"string"==typeof e||Object.empty(e)?this[n]=e:(!e||e.constructor===Object||e instanceof Array)&&o(e,t)}),c.on("opt",e),e.opt.uuid=e.opt.uuid||function(t){return c.state().toString(36).replace(".","")+String.random(t||12)},this};var T,e,o=function(t,n){Object.keys(t).forEach(n,t)},g=String.random,x=setTimeout.turn,S=c.valid,m=c.state.is,O=c.state.ify,D={};(c.log=function(){return c.log.off||e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=c.log.once)[t]=e[t]||0,e[t]++||c.log(n)},"undefined"!=typeof window&&((window.GUN=window.Gun=c).window=window);try{void 0!==n&&(n.exports=c)}catch(t){}((t.exports=c).window||{}).console=(c.window||{}).console||{log:function(){}},(e=console).only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},c.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!")})(f,"./root"),f(function(t){f("./root").chain.back=function(t,n){if(-1===(t=t||1)||1/0===t)return this._.root.$;if(1===t)return(this._.back||this._).$;var e=this._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){for(var o=0,i=t.length,r=e;o":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.$})},u.on.in=function(n,e){var t,o=(e=e||this.as).root,i=n.$||(n.$=e.$),r=(i||"")._||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||"")._||"")["#"])?(i=e.root.$.get(s),setTimeout.each(Object.keys(a).sort(),function(t){"_"!=t&&p!==(f=v(a,t))&&e.on("in",{$:i,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(o.graph[s],u)&&((a=o.$.get(s)._).put=y(a.put,u,f,c,s)),!r.soul&&f>=v(o.graph[s],u)&&(t=(o.$.get(s)._.next||"")[u])&&(t.put=c,"string"==typeof(a=g(c))&&(t.put=o.$.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))},u.on.link=l,u.on.unlink=h;var p,d={},s=String.random,g=u.valid,c=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},n=u.state,v=n.is,y=n.ify})(f,"./chain"),f(function(t){var g=f("./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){var e;n.map;if((e=this.seen||(this.seen={}))[t])return!0;e[t]=!0}}g.chain.get=function(t,n,e){var o,i;if("string"==typeof t){if(0==t.length)return(o=this.chain())._.err={err:g.log("0 length key!",t)},n&&n.call(o,o._.err),o;(o=((f=this._).next||a)[t])||(o=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)),o=o&&o.$}else{if("function"==typeof t){if(!0===n)return function(t,n,e,o){var a,s=t._,u=0;if(a=s.soul||s.link)return n(a,o,s);if(s.jam)return s.jam.push([n,o]);s.jam=[[n,o]],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,o=(o=t.$)&&o._||{},i=0;for(a=s.jam,delete s.jam;e=a[i++];){var r=e[0];e=e[1],r&&r(o.link||o.soul||g.valid(t.put)||((t.put||{})._||{})["#"],e,t,n)}}},{out:{get:{".":!0}}})}(this,t,0,e),this;var c,f=(o=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){if(p[i.$._.id])return;return 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,i=h.pass,(h.pass={})[c]=1,l.out=l.out||{get:{}},f.on("out",l.out),h.pass=i,o}if("number"==typeof t)return this.get(""+t,n,e);if("string"==typeof(i=s(t)))return this.get(i,n,e);(i=this.get.next)&&(o=i(this,t))}return o?n&&"function"==typeof n&&o.get(n,e):((o=this.chain())._.err={err:g.log("Invalid get request!",t)},n&&n.call(o,o._.err)),o};var v,a={},s=g.valid})(f,"./get"),f(function(t){var g=f("./root");function v(n,t){if(t){t=(t._||"").id||t;var e,o=n.root.stun||(n.root.stun={on:g.on}),i={};n.stun||(n.stun=o.on("stun",function(){})),(e=o.on(""+t))&&e.the.last.next(i),i.run>=n.run||o.on(""+t,function(t){if(n.stun.end)return this.off(),void this.to.next(t);t.run=t.run||n.run,t.stun=t.stun||n.stun})}}function s(n){if(n.err)s.end(n.stun,n.root);else if(!n.todo.length&&!n.end&&Object.empty(n.wait)){n.end=1;var t,e=n.$.back(-1)._,o=e.root,i=e.ask(function(t){o.on("ack",t),t.err&&g.log(t),++r>(n.acks||0)&&this.off(),n.ack&&n.ack(t,this)},n.opt),r=0,a=n.stun;(t=function(){a&&(s.end(a,o),setTimeout.each(Object.keys(a=a.add||""),function(t){(t=a[t])&&t()}))}).hatch=t,n.via._.on("out",{put:n.out=n.graph,opt:n.opt,"#":i,_:t})}}g.chain.put=function(t,n,p){var e=this,o=e._,i=o.root;(p=p||{}).root=o.root,p.run||(p.run=i.once),v(p,o.id),p.ack=p.ack||n,p.via=p.via||e,p.data=p.data||t,p.soul||(p.soul=o.soul||"string"==typeof n&&n);var d=p.state=p.state||g.state();return"function"==typeof t?t(function(t){p.data=t,e.put(void 0,void 0,p)}):p.soul?(p.$=i.$.get(p.soul),p.todo=[{it:p.data,ref:p.$}],p.turn=p.turn||r,p.ran=p.ran||s,function t(){var n,e,i,r,a,o=p.todo,s=o.pop(),u=s.it;s.ref&&s.ref._.id;if(v(p,s.ref),(r=s.todo)&&(u=u[e=r.pop()],r.length&&o.push(s)),e&&(o.path||(o.path=[])).push(e),!(n=k(u))&&!(a=g.is(u))){if(!Object.plain(u))return(p.ack||y).call(p,p.out={err:p.err=g.log("Invalid data: "+(u&&(r=u.constructor)&&r.name||typeof u)+" at "+(p.via.back(function(t){t.get&&r.push(t.get)},r=[])||r.join("."))+"."+(o.path||[]).join("."))}),void p.ran(p);for(var c=p.seen||(p.seen=[]),f=c.length;f--;)if(u===(r=c[f]).it){n=u=r.link;break}}if(e&&n)s.node=m(s.node,e,d,u);else{p.seen.push(i={it:u,link:{},todo:a?[]:Object.keys(u).sort().reverse(),path:(o.path||[]).slice(),up:s}),s.node=m(s.node,e,d,i.link),!a&&i.todo.length&&o.push(i);var l=p.seen.length;function h(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||v(p,t.$),o||s.link["#"]?(o||(o=[],(t.$$||t.$).back(function(t){if(r=t.soul||t.link)return o.push(r);o.push(t.get)}),o=o.reverse().join("/")),i.link["#"]=o,a||(((p.graph||(p.graph={}))[o]=i.node||(i.node={_:{}}))._["#"]=o),delete p.wait[l],i.wait&&setTimeout.each(i.wait,function(t){t&&t()}),p.ran(p)):(s.wait||(s.wait=[])).push(function(){h(t,n)})}(p.wait||(p.wait={}))[l]="",r=(i.ref=a?u:e?s.ref.get(e):s.ref)._,(r=u&&(u._||"")["#"]||r.soul||r.link)?h({soul:r}):i.ref.get(h,{run:p.run,v2020:1,out:{get:{".":" "}}})}if(!o.length)return p.ran(p);p.turn(t)}()):function(n){var e,t=n.via._;n.via=n.via.back(function(t){if(t.soul||!t.get)return t.$;e=n.data,(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)}(p),e},s.end=function(t,n){t.end=y,t.the.to===t&&t===t.the.last&&delete n.stun,t.off()};var y=function(){},r=setTimeout.turn,k=g.valid,m=g.state.ify})(f,"./put"),f(function(t){var n=f("./root");f("./chain"),f("./back"),f("./put"),f("./get"),t.exports=n})(f,"./index"),f(function(t){var d=f("./index");d.chain.on=function(t,n,e,o){var i,r=this._;r.root;if("string"==typeof t)return n?(i=r.on(t,n,e||r,o),e&&e.$&&(e.subs||(e.subs=[])).push(i),this):r.on(t);var a=n;(a=!0===a?{change:!0}:a||{}).not=1,a.on=1;return this.get(t,a),this},d.chain.once=function(u,c){if(c=c||{},!u)return function(t,n,e){return d.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}(this);var f,l=this._,h=l.root,p=(l.put,String.random(7));return this.get(function(t,n,e,o){var i=this,r=i._,a=r.one||(r.one={});function s(){r.has||r.soul||(r={put:t,get:n}),void 0===(f=r.put)&&(f=((e.$$||"")._||"").put),"string"==typeof d.valid(f)&&void 0===(f=h.$.get(f)._.put)||o.stun||""!==a[p]&&(a[p]="",(l.soul||l.has)&&o.off(),u.call(i,f,r.get))}o.stun||""!==a[p]&&(!0!==(f=d.valid(t))?"string"!=typeof f&&(clearTimeout(a[p]),a[p]=setTimeout(s,c.wait||99)):s())},{on:1}),this},d.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}})(f,"./on"),f(function(t){var u=f("./index"),o=u.chain.get.next;function r(t){this.to.next(t);var n,e=this.as,o=t.$._,i=t.put;(o.soul||t.$$)&&((n=e.lex)&&!String.match(t.get||(i||"")["."],n["."]||n["#"]||n)||u.on.link(t,e))}u.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)},u.chain.map=function(a,t,n){var e,s,o=this,i=o._;return Object.plain(a)&&(e=a["."]?a:{".":a},a=void 0),a?(u.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."),s=o.chain(),o.map().on(function(t,n,e,o){var i=(a||c).call(this,t,n,e,o);if(void 0!==i){if(t===i)return s._.on("in",e);if(u.is(i))return s._.on("in",i._);var r={};Object.keys(e.put).forEach(function(t){r[t]=e.put[t]},r),r["="]=i,s._.on("in",{get:n,put:r})}})):(s=i.each)||((i.each=s=o.chain())._.lex=e||s._.lex||i.lex,s._.nix=o.back("nix"),o.on("in",r,s._)),s};var c=function(){}})(f,"./map"),f(function(t){var s=f("./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){if(!t)return i.call(a,{err:s.log('Only a node can be linked! Not "'+e.put+'"!')});(r={})[t]={"#":t},o(r)},!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))}})(f,"./set"),f(function(t){f("./shim");var j;try{t.exports=function(u){var g=function(){},v=u.opt||{};v.log=v.log||console.log,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,i=JSON.parseAsync||function(t,n,e){try{n(void 0,JSON.parse(t,e))}catch(t){n(t)}},k=JSON.stringifyAsync||function(t,n,e,o){try{n(void 0,JSON.stringify(t,e,o))}catch(t){n(t)}},m=u.dup,b=m.check,_=m.track,s=(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&&(s.d+=t.length||0,++s.c);var n,e=a.SH=+new Date,o=t[0];return"["===o?(i(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},t._.yo={}),r=t.dam)return(r=g.hear[r])&&r(t,n,u),void _(o);e=+new Date;s&&(s.is=e),n.SI=o,u.on("in",g.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=_(o)).via=n,t.get&&(r.it=t),a&&_(a),g.leap=g.last=null}},s.c=s.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]}g.hash=function(i,r){var a,s,u,c=+new Date;k(i.put,function t(n,e){var o=(s=s||(u=e||"")).slice(0,32768);a=String.hash(o,a),(s=s.slice(32768))?y(t,0):(console.STAT&&console.STAT(c,+new Date-c,"say json+hash"),i._.$put=u,i["##"]=a,d(i,r),delete i._.$put)},t)};var d=g.say=function(r,t){var n;if((n=this)&&(n=n.to)&&n.next&&n.next(r),!r)return!1;var e,a,s=r["@"],u=r._||(r._=function(){}),o=r.DBG,i=+new Date;if(u.y=u.y||i,t||o&&(o.y=i),(e=r["#"])||(e=r["#"]=String.random(9)),h||_(e),r.put&&(r.err||(m.s[e]||"").err))return!1;if(r["##"]||j===r.put||u.via||!s){if(!t&&s&&(t=(n=m.s[s])&&(n.via||(n=n.it)&&(n=n._)&&n.via)||(n=g.last)&&s===n["#"]&&g.leap),!t&&s){if(m.s[s])return;return console.STAT&&console.STAT(+new Date,++p,"total no peer to ack to"),!1}if(!t&&g.way)return g.way(r);if(o&&(o.yh=+new Date),a=u.raw){if(o&&(o.yr=+new Date),!t||!t.id){if(!Object.plain(t||v.peers))return!1;i=+new Date,v.puff;var c=v.peers,f=Object.keys(t||v.peers||{});return console.STAT&&console.STAT(i,+new Date-i,"peer keys"),void function t(){var n=+new Date;h=1;var e=u.raw;u.raw=a;for(var o,i=0;i<9&&(o=(f||"")[i++]);)(o=c[o])&&d(r,o);u.raw=e,h=0,f=f.slice(i),console.STAT&&console.STAT(n,+new Date-n,"say loop"),f.length&&(y(t,0),s&&_(s))}()}if(!t.wire&&g.wire&&g.wire(t),e!==t.last){if(t.last=e,t===u.via)return!1;if((n=u.yo)&&(n[t.url]||n[t.pid]||n[t.id]))return!1;if(console.STAT&&console.STAT(i,((o||u).yp=+new Date)-(u.y||i),"say prep"),!h&&s&&_(s),t.batch){if(t.tail=(n=t.tail||0)+a.length,t.tail<=v.pack)return void(t.batch+=(n?",":"")+a);$(t)}t.batch="[";var l=+new Date;setTimeout(function(){console.STAT&&console.STAT(l,+new Date-l,"0ms TO"),$(t)},v.gap),w(a,t),console.STAT&&s===t.SI&&console.STAT(i,+new Date-t.SH,"say ack")}}else g.raw(r,t)}else g.hash(r,t)};g.say.c=g.say.d=0,g.raw=function(e,o){if(!e)return"";var i,r,a=e._||{};if(r=a.raw)return r;if("string"==typeof e)return e;var t=e["##"],n=e["@"];if(t&&n){if(!a.via&&b(n+t))return!1;if((r=(m.s[n]||"").it)||(r=g.last)&&n===r["#"]){if(t===r["##"])return!1;r["##"]||(r["##"]=t)}}if(!e.dam){var s=0,u=[];for(var c in r=v.peers){var f=r[c];if(u.push(f.url||f.pid||f.id),6<++s)break}1<"]=u.join())}if(i=a.$put)return r={},Object.keys(e).forEach(function(t){r[t]=e[t]}),r.put=":])([:",void k(r,function(t,n){if(!t){var e=+new Date;r=n.indexOf('"put":":])([:"'),l(j,n=n.slice(0,r+6)+i+n.slice(r+14)),console.STAT&&console.STAT(e,+new Date-e,"say slice")}});function l(t,n){t||(a.raw=n,d(e,o))}k(e,l)}}(),g.hi=function(n){var t=n.wire||{};n.id?v.peers[n.url||n.id]=n:(t=n.id=n.id||String.random(9),g.say({dam:"?",pid:u.opt.pid},v.peers[t]=n),delete m.s[n.last]),n.met=n.met||+new Date,t.hied||u.on(t.hied="hi",n),t=n.queue,n.queue=[],setTimeout.each(t||[],function(t){w(t,n)},0,9)},g.bye=function(t){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.log("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 m.s[n.last])},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 o={};return u.on("bye",function(t,n){this.to.next(t),(n=console.STAT)&&(n.peers=(n.peers||0)-1),(n=t.url)&&(o[n]=!0,setTimeout(function(){delete o[n]},v.lack||9e3))}),u.on("hi",function(n,e){this.to.next(n),(e=console.STAT)&&(e.peers=(e.peers||0)+1),(e=n.url)&&o[e]&&(delete o[e],v.super||setTimeout.each(Object.keys(u.next),function(t){u.next[t];(e={})[t]=u.graph[t],e=String.hash(e),g.say({"##":e,get:{"#":t}},n)}))}),g}}catch(t){}})(f,"./mesh"),f(function(t){var c=f("../index");c.Mesh=f("./mesh"),c.on("opt",function(t){if(this.to.next(t),!t.once){var o=t.opt;if(!1!==o.WebSocket){var n=c.window||{},e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||c.Mesh(t);i.wire||o.wire;i.wire=o.wire=s,setTimeout(function(){o.super||t.on("out",{dam:"hi"})},1);var r=1998,a=""+void 0!=typeof document&&document}}}function s(n){try{if(!n||!n.url)return e&&e(n);var t=n.url.replace(/^http/,"ws"),e=n.wire=new o.WebSocket(t);return e.onclose=function(){o.mesh.bye(n),u(n)},e.onerror=function(t){u(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function u(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry+1||60)-(-n.tried+(n.tried=+new Date)<4*r?1:0),n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);s(n)},r))}})})(f,"./websocket"),f(function(t){if("undefined"!=typeof Gun){var o;try{o=(Gun.window||function(){}).localStorage}catch(t){}o||(Gun.log("Warning: No localStorage exists to persist data to!"),o={setItem:function(t,n){this[t]=n},removeItem:function(t){delete this[t]},getItem:function(t){return this[t]}}),Gun.on("create",function n(e){this.to.next(e);var r,i,a=e.opt,s=(e.graph,[]);if(!1!==a.localStorage){a.prefix=a.file||"gun/";try{r=n[a.prefix]=n[a.prefix]||JSON.parse(o.getItem(a.prefix))||{}}catch(t){r=n[a.prefix]={}}e.on("get",function(t){this.to.next(t);var n,e,o,i=t.get;i&&(n=i["#"])&&((e=r[n]||void 0)&&(o=i["."])&&!Object.plain(o)&&(e=Gun.state.ify({},o,Gun.state.is(e,o),e[o],n)),Gun.on.get.ack(t,e))}),e.on("put",function(t){this.to.next(t);var n=t.put,e=n["#"],o=n["."];r[e]=Gun.state.ify(r[e],o,n[">"],n[":"],e),t["@"]||s.push(t["#"]),i=i||setTimeout(u,a.wait||1)})}function u(){var n,t=s;clearTimeout(i),i=!1,s=[];try{o.setItem(a.prefix,JSON.stringify(r))}catch(t){Gun.log((n=t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),e.on("localStorage:error",{err:n,get:a.prefix,put:r})}(n||Object.empty(a.peers))&&setTimeout.each(t,function(t){e.on("in",{"@":t,err:n,ok:0})})}})}})(f,"./localStorage")}(),function(){if(""+_!=typeof Gun){function l(t){console.log("Warning! Deprecated internal utility will break in next version:",t)}var n,h,p=Gun;p.fn=p.fn||{is:function(t){return l("fn"),!!t&&"function"==typeof t}},p.bi=p.bi||{is:function(t){return l("bi"),t instanceof Boolean||"boolean"==typeof t}},p.num=p.num||{is:function(t){return l("num"),!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},p.text=p.text||{is:function(t){return l("text"),"string"==typeof t}},p.text.ify=p.text.ify||function(t){return l("text.ify"),p.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},p.text.random=p.text.random||function(t,n){l("text.random");var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0"]||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["<"])))},p.text.hash=p.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"]||t>=n[">"])&&(void 0===n["<"]||t<=n["<"])&&(void 0===n["*"]||t.slice(0,n["*"].length)===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"]||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})(f,"./state"),f(function(t){f("./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}})(f,"./dup"),f(function(t){f("./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)}})(f,"./ask"),f(function(t){function c(t){return t instanceof c?(this._={$:this}).$:this instanceof c?c.create(this._={$:this,opt:t}):new c(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,A(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):S,$:p.$,_:o,DBG:u}),console.STAT&&console.STAT(s,+new Date-s,"got in"),e&&setTimeout.turn(t)}(),a||p.on("in",{"@":t["#"]})}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.202,(c.chain=c.prototype).toJSON=function(){},f("./shim"),c.valid=f("./valid"),c.state=f("./state"),c.on=f("./onto"),c.dup=f("./dup"),c.ask=f("./ask"),function(){function b(t){if(t)if(t.out!==b){var n,e=this.as,o=e.at||e,i=o.$,r=o.dup,a=t.DBG;if((e=t["#"])||(e=t["#"]=g(9)),!r.check(e)){if(r.track(e),e=t._,t._="function"==typeof e?e:function(){},t.$&&t.$===(t.$._||"").$||(t.$=i),t["@"]&&!t.put&&(e=(r=t)["@"]||"",(n=e._)&&(n.acks=(n.acks||0)+1,(n.err=r.err)&&(r["@"]=n["#"],_(n)),n.stop||n.crack||(n.crack=n.match&&n.match.push(function(){u(n)})),u(n))),!o.ask(t["@"],t)){if(a&&(a.u=+new Date),t.put)return void s(t);t.get&&c.on.get(t,i)}a&&(a.uc=+new Date),this.to.next(t),a&&(a.ua=+new Date),t.nts||t.NTS||(t.out=b,o.on("out",t),a&&(a.ue=+new Date))}}else this.to.next(t)}function s(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;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(S===r){g=w+$(e)+"on"+$(h)+"no state.";break}if(!D(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]||G,f=A(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},_:a})}(i,e,h,r,a)}(l=l.slice(o)).length?O(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))))}function u(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?S:{"":1}}))}c.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||c.on,t.ask=t.ask||c.ask,t.dup=t.dup||c.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),c.on("create",t),t.on("create",t)),t.once=1,n},c.on.put=s;var w="Error: Invalid graph!",$=function(t){return" '"+(""+t).slice(0,9)+"...' "},j=JSON.stringify,T=2147483647,x=c.state}(),c.on.get=function(t,n){var e=n._,o=t.get,i=o["#"],r=e.graph[i],n=o["."],o=((e.next||(e.next={}))[i],(t._||{}).DBG=t.DBG);if(o&&(o.g=+new Date),!r)return e.on("get",t);if(n){if("string"!=typeof n||S===r[n])return e.on("get",t);r=v({},n,A(r,n),r[n],i)}r&&a(t,r),e.on("get",t)},c.on.get.ack=a,c.chain.opt=function(t){var e=this._,n=(t=t||{}).peers||t;return Object.plain(t)||(t={}),Object.plain(e.opt)||(e.opt=t),(n="string"==typeof n?[n]:n)instanceof Array&&(Object.plain(e.opt.peers)||(e.opt.peers={}),n.forEach(function(t){var n={};n.id=n.url=t,e.opt.peers[t]=e.opt.peers[t]||n})),e.opt.peers=e.opt.peers||{},o(t,function t(n){var e=this[n];this&&this.hasOwnProperty(n)||"string"==typeof e||Object.empty(e)?this[n]=e:(!e||e.constructor===Object||e instanceof Array)&&o(e,t)}),c.on("opt",e),e.opt.uuid=e.opt.uuid||function(t){return c.state().toString(36).replace(".","")+String.random(t||12)},this};var S,e,o=function(t,n){Object.keys(t).forEach(n,t)},g=String.random,O=setTimeout.turn,D=c.valid,A=c.state.is,v=c.state.ify,G={};(c.log=function(){return c.log.off||e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=c.log.once)[t]=e[t]||0,e[t]++||c.log(n)},"undefined"!=typeof window&&((window.GUN=window.Gun=c).window=window);try{void 0!==n&&(n.exports=c)}catch(t){}((t.exports=c).window||{}).console=(c.window||{}).console||{log:function(){}},(e=console).only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},c.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!")})(f,"./root"),f(function(t){f("./root").chain.back=function(t,n){if(-1===(t=t||1)||1/0===t)return this._.root.$;if(1===t)return(this._.back||this._).$;var e=this._;if((t="string"==typeof t?t.split("."):t)instanceof Array){for(var o=0,i=t.length,r=e;o":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})(f,"./chain"),f(function(t){var g=f("./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})(f,"./get"),f(function(t){var y=f("./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&&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.via._.on("out",{put:n.out=n.graph,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})(f,"./put"),f(function(t){var n=f("./root");f("./chain"),f("./back"),f("./put"),f("./get"),t.exports=n})(f,"./index"),f(function(t){var g=f("./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}})(f,"./on"),f(function(t){var s=f("./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(){}})(f,"./map"),f(function(t){var s=f("./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))}})(f,"./set"),f(function(t){function n(u){var g=function(){},v=u.opt||{};v.log=v.log||console.log,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,i=JSON.parseAsync||function(t,n,e){try{n(void 0,JSON.parse(t,e))}catch(t){n(t)}},k=JSON.stringifyAsync||function(t,n,e,o){try{n(void 0,JSON.stringify(t,e,o))}catch(t){n(t)}},m=u.dup,b=m.check,_=m.track,s=(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&&(s.d+=t.length||0,++s.c);var n,e=a.SH=+new Date,o=t[0];if("["===o)return i(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},t._.yo={}),r=t.dam)return(r=g.hear[r])&&r(t,n,u),void _(o);e=+new Date;s&&(s.is=e),n.SI=o,u.on("in",g.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=_(o)).via=n,t.get&&(r.it=t),a&&_(a),g.leap=g.last=null}};function w(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.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),g.say.d+=n.length||0,++g.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}s.c=s.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]}g.hash=function(o,i){var r,a,s,u=+new Date;k(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,d(o,i),delete o._.$put)},t)};var d=g.say=function(r,t){var n;if((n=this)&&(n=n.to)&&n.next&&n.next(r),!r)return!1;var e,a,s=r["@"],u=r._||(r._=function(){}),o=r.DBG,i=+new Date;if(u.y=u.y||i,t||o&&(o.y=i),(e=r["#"])||(e=r["#"]=String.random(9)),h||_(e),r.put&&(r.err||(m.s[e]||"").err))return!1;if(r["##"]||j===r.put||u.via||!s){if(!(t=!t&&s?(n=m.s[s])&&(n.via||(n=n.it)&&(n=n._)&&n.via)||(n=g.last)&&s===n["#"]&&g.leap:t)&&s)return m.s[s]?void 0:(console.STAT&&console.STAT(+new Date,++p,"total no peer to ack to"),!1);if(!t&&g.way)return g.way(r);if(o&&(o.yh=+new Date),a=u.raw){if(o&&(o.yr=+new Date),!t||!t.id){if(!Object.plain(t||v.peers))return!1;var i=+new Date,c=(v.puff,v.peers),f=Object.keys(t||v.peers||{});return console.STAT&&console.STAT(i,+new Date-i,"peer keys"),void function t(){var n=+new Date;h=1;var e=u.raw;u.raw=a;for(var o,i=0;i<9&&(o=(f||"")[i++]);)(o=c[o])&&d(r,o);u.raw=e,h=0,f=f.slice(i),console.STAT&&console.STAT(n,+new Date-n,"say loop"),f.length&&(y(t,0),s&&_(s))}()}if(!t.wire&&g.wire&&g.wire(t),e!==t.last){if(t.last=e,t===u.via)return!1;if((n=u.yo)&&(n[t.url]||n[t.pid]||n[t.id]))return!1;if(console.STAT&&console.STAT(i,((o||u).yp=+new Date)-(u.y||i),"say prep"),!h&&s&&_(s),t.batch){if(t.tail=(n=t.tail||0)+a.length,t.tail<=v.pack)return void(t.batch+=(n?",":"")+a);w(t)}t.batch="[";var l=+new Date;setTimeout(function(){console.STAT&&console.STAT(l,+new Date-l,"0ms TO"),w(t)},v.gap),$(a,t),console.STAT&&s===t.SI&&console.STAT(i,+new Date-t.SH,"say ack")}}else g.raw(r,t)}else g.hash(r,t)};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&&b(n+t))return!1;if((s=(m.s[n]||"").it)||(s=g.last)&&n===s["#"]){if(t===s["##"])return!1;s["##"]||(s["##"]=t)}}if(!e.dam){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(i=r.$put)return s={},Object.keys(e).forEach(function(t){s[t]=e[t]}),s.put=":])([:",void k(s,function(t,n){t||(t=+new Date,s=n.indexOf('"put":":])([:"'),l(j,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(e,o))}k(e,l)}}(),g.hi=function(n){var t=n.wire||{};n.id?v.peers[n.url||n.id]=n:(t=n.id=n.id||String.random(9),g.say({dam:"?",pid:u.opt.pid},v.peers[t]=n),delete m.s[n.last]),n.met=n.met||+new Date,t.hied||u.on(t.hied="hi",n),t=n.queue,n.queue=[],setTimeout.each(t||[],function(t){$(t,n)},0,9)},g.bye=function(t){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.log("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 m.s[n.last])},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 o={};return u.on("bye",function(t,n){this.to.next(t),(n=console.STAT)&&(n.peers=(n.peers||0)-1),(n=t.url)&&(o[n]=!0,setTimeout(function(){delete o[n]},v.lack||9e3))}),u.on("hi",function(n,e){this.to.next(n),(e=console.STAT)&&(e.peers=(e.peers||0)+1),(e=n.url)&&o[e]&&(delete o[e],v.super||setTimeout.each(Object.keys(u.next),function(t){u.next[t];(e={})[t]=u.graph[t],e=String.hash(e),g.say({"##":e,get:{"#":t}},n)}))}),g}f("./shim");var j;try{t.exports=n}catch(t){}})(f,"./mesh"),f(function(t){var s=f("../index");s.Mesh=f("./mesh"),s.on("opt",function(t){var o,n,e,i;function r(n){try{if(!n||!n.url)return e&&e(n);var t=n.url.replace(/^http/,"ws"),e=n.wire=new o.WebSocket(t);return e.onclose=function(){o.mesh.bye(n),a(n)},e.onerror=function(t){a(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function a(n){clearTimeout(n.defer),i&&n.retry<=0||(n.retry=(n.retry||o.retry+1||60)-(-n.tried+(n.tried=+new Date)<4*e?1:0),n.defer=setTimeout(function t(){return i&&i.hidden?setTimeout(t,e):void r(n)},e))}this.to.next(t),t.once||!1!==(o=t.opt).WebSocket&&(n=s.window||{},(n=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket)&&(o.WebSocket=n,(n=o.mesh=o.mesh||s.Mesh(t)).wire||o.wire,n.wire=o.wire=r,setTimeout(function(){o.super||t.on("out",{dam:"hi"})},1),e=1998,i=""+void 0!=typeof document&&document))})})(f,"./websocket"),f(function(t){if("undefined"!=typeof Gun){var o;try{o=(Gun.window||function(){}).localStorage}catch(t){}o||(Gun.log("Warning: No localStorage exists to persist data to!"),o={setItem:function(t,n){this[t]=n},removeItem:function(t){delete this[t]},getItem:function(t){return this[t]}}),Gun.on("create",function n(e){this.to.next(e);var r,i,a=e.opt,s=(e.graph,[]);if(!1!==a.localStorage){a.prefix=a.file||"gun/";try{r=n[a.prefix]=n[a.prefix]||JSON.parse(o.getItem(a.prefix))||{}}catch(t){r=n[a.prefix]={}}e.on("get",function(t){this.to.next(t);var n,e,o,i=t.get;i&&(n=i["#"])&&((e=r[n]||void 0)&&(o=i["."])&&!Object.plain(o)&&(e=Gun.state.ify({},o,Gun.state.is(e,o),e[o],n)),Gun.on.get.ack(t,e))}),e.on("put",function(t){this.to.next(t);var n=t.put,e=n["#"],o=n["."];r[e]=Gun.state.ify(r[e],o,n[">"],n[":"],e),t["@"]||s.push(t["#"]),i=i||setTimeout(u,a.wait||1)})}function u(){var n,t=s;clearTimeout(i),i=!1,s=[];try{o.setItem(a.prefix,JSON.stringify(r))}catch(t){Gun.log((n=t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),e.on("localStorage:error",{err:n,get:a.prefix,put:r})}(n||Object.empty(a.peers))&&setTimeout.each(t,function(t){e.on("in",{"@":t,err:n,ok:0})})}})}})(f,"./localStorage")}(),function(){var l,h,n,p,d,s,e,o,i,u,r,a,c,f,g,v,y,t,k,m,b,_,w,$,j,T;function x(t,n){b(this,n)&&void 0!==this[n]||(this[n]=t)}function S(t,n){var e=this.n;if(!e||!(n===e||k(e)&&b(e,n)))return void 0!==n||void 0}function O(t,n){if(2===arguments.length)return O.r=O.r||{},void(O.r[t]=n);O.r=O.r||[],O.r.push(t)}function D(t,n){return!this.id&&n==e&&i(t)?void(this.id=t):this.id=!1}function A(t,n){if(n!==u._)return!s.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}function G(t,n){var e,o=this.o;o.map?void 0===(e=o.map.call(this.as,t,""+n,o.node))?m(o.node,n):o.node&&(o.node[n]=e):s.is(t)&&(o.node[n]=t)}function N(t,n){g!==n&&c.ify(this.o,n,this.s)}function J(t,n){if(!t||n!==u.soul(t)||!u.is(t,this.fn,this.as))return!0;this.cb&&(B.n=t,B.as=this.as,this.cb.call(B.as,t,n,B))}function B(t){t&&u.is(B.n,t,B.as)}function I(t,n){var e;return(e=function(t,n){var e,o=t.seen,i=o.length;for(;i--;)if(e=o[i],n.obj===e.obj)return e;o.push(n)}(t,n))?e:(n.env=t,n.soul=M,u.ify(n.obj,E,n)&&(n.link=n.link||s.link.ify(u.soul(n.node)),n.obj!==t.shell&&(t.graph[s.link.is(n.link)]=n.node)),n)}function E(t,n,e){var o,i,r=this,a=r.env;if(u._===n&&b(t,s.link._))return e._;if(o=W(t,n,e,r,a)){if(n||(r.node=r.node||e||{},b(t,u._)&&u.soul(t)&&(r.node._=j(t._)),r.node=u.soul.ify(r.node,s.link.is(r.link)),r.link=r.link||s.link.ify(u.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),b(e,n))){if(t=e[n],T===t)return void m(e,n);if(!(o=W(t,n,e,r,a)))return}return n?!0===o?t:(i=I(a,{obj:t,path:r.path.concat(n)})).node?i.link:void 0:r.node}}function M(t){var n=this,e=s.link.is(n.link),o=n.env.graph;n.link=n.link||s.link.ify(t),n.link[s.link._]=t,n.node&&n.node[u._]&&(n.node[u._][s.link._]=t),b(o,e)&&(o[t]=o[e],m(o,e))}function W(t,n,e,o,i){var r;return!!s.is(t)||(k(t)?1:(r=i.invalid)?W(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(h.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}function P(t,n){var e,o;if(u._===n)return _(t,s.link._)?void 0:void(this.obj[n]=j(t));(e=s.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=v.to(this.graph,e,this.opt):this.obj[n]=t}""+T!=typeof Gun&&(l=function(t){console.warn("Warning! Deprecated internal utility will break in next version:",t)},(h=Gun).fn=h.fn||{is:function(t){return l("fn"),!!t&&"function"==typeof t}},h.bi=h.bi||{is:function(t){return l("bi"),t instanceof Boolean||"boolean"==typeof t}},h.num=h.num||{is:function(t){return l("num"),!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},h.text=h.text||{is:function(t){return l("text"),"string"==typeof t}},h.text.ify=h.text.ify||function(t){return l("text.ify"),h.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},h.text.random=h.text.random||function(t,n){l("text.random");var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0"]||t>=n[">"])&&(void 0===n["<"]||t<=n["<"])&&(void 0===n["*"]||t.slice(0,n["*"].length)===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 0){ s += c.charAt(Math.floor(Math.random() * c.length)); l-- } return s; } - Type.text.match = Type.text.match || function(t, o){ var tmp, u; DEP('text.match'); - if('string' !== typeof t){ return false } - if('string' == typeof o){ o = {'=': o} } - o = o || {}; - tmp = (o['='] || o['*'] || o['>'] || o['<']); - if(t === tmp){ return true } - if(u !== o['=']){ return false } - tmp = (o['*'] || o['>'] || o['<']); - if(t.slice(0, (tmp||'').length) === tmp){ return true } - if(u !== o['*']){ return false } - if(u !== o['>'] && u !== o['<']){ - return (t >= o['>'] && t <= o['<'])? true : false; - } - if(u !== o['>'] && t >= o['>']){ return true } - if(u !== o['<'] && t <= o['<']){ return true } - return false; + Type.text.match = Type.text.match || function(t, o){ DEP('text.match'); + return ( + ('string' === typeof t && (t === o || t === o['='])) || + (o['='] === undefined && + (o['>'] === undefined || t >= o['>']) && + (o['<'] === undefined || t <= o['<']) && + (o['*'] === undefined || t.slice(0, o['*'].length) === o['*'])) + ); } Type.text.hash = Type.text.hash || function(s, c){ // via SO DEP('text.hash'); diff --git a/src/shim.js b/src/shim.js index 88a27f512..a7a597541 100644 --- a/src/shim.js +++ b/src/shim.js @@ -7,22 +7,14 @@ String.random = function(l, c){ while(l-- > 0){ s += c.charAt(Math.floor(Math.random() * c.length)) } return s; } -String.match = function(t, o){ var tmp, u; - if('string' !== typeof t){ return false } - if('string' == typeof o){ o = {'=': o} } - o = o || {}; - tmp = (o['='] || o['*'] || o['>'] || o['<']); - if(t === tmp){ return true } - if(u !== o['=']){ return false } - tmp = (o['*'] || o['>']); - if(t.slice(0, (tmp||'').length) === tmp){ return true } - if(u !== o['*']){ return false } - if(u !== o['>'] && u !== o['<']){ - return (t >= o['>'] && t <= o['<'])? true : false; - } - if(u !== o['>'] && t >= o['>']){ return true } - if(u !== o['<'] && t <= o['<']){ return true } - return false; +String.match = function(t, o){ + return ( + ('string' === typeof t && (t === o || t === o['='])) || + (o['='] === undefined && + (o['>'] === undefined || t >= o['>']) && + (o['<'] === undefined || t <= o['<']) && + (o['*'] === undefined || t.slice(0, o['*'].length) === o['*'])) + ); } String.hash = function(s, c){ // via SO if(typeof s !== 'string'){ return }