diff --git a/gun.min.js b/gun.min.js index 1eb09d40..41456ee7 100644 --- a/gun.min.js +++ b/gun.min.js @@ -1 +1 @@ -!function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var e=(t=t||{}).console||{log:function(){}};function j(e,t){return t?require(e):e.slice?j[o(e)]:function(t,n){e(t={exports:{}}),j[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var $=module;j(function(t){var n,c,l={};function e(t,n){v(this,n)&&void 0!==this[n]||(this[n]=t)}function o(t,n){var e=this.n;if(!e||!(n===e||g(e)&&v(e,n)))return!!n||void 0}function p(t,n){2!==arguments.length?(p.r=p.r||[]).push(t):(p.r=p.r||{})[t]=n}l.fn={is:function(t){return!!t&&"function"==typeof t}},l.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},l.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},l.text={is:function(t){return"string"==typeof t}},l.text.ify=function(t){return l.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},l.text.random=function(t,n){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["<"])))},l.list={is:function(t){return t instanceof Array}},l.list.slit=Array.prototype.slice,l.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n",u.drift=0,u.is=function(t,n,e){var o=n&&t&&t[k]&&t[k][u._]||e;if(o)return v(o=o[n])?o:-1/0},u.lex=function(){return u().toString(36).replace(".","")},u.ify=function(t,n,e,o,i){if(!t||!t[k]){if(!i)return;t=a.soul.ify(t,i)}var r=l(t[k],u._);return void 0!==n&&n!==k&&(v(e)&&(r[n]=e),void 0!==o&&(t[n]=o)),t},u.to=function(t,n,e){var o=(t||{})[n];return h(o)&&(o=g(o)),u.ify(e,n,u.is(t,n),o,a.soul(t))},u.map=function(i,r,a){var t=h(t=i||r)?t:null;return i=m(i=i||r)?i:null,t&&!i?(r=v(r)?r:u(),t[k]=t[k]||{},d(t,f,{o:t,s:r}),t):(a=a||h(r)?r:void 0,r=v(r)?r:u(),function(t,n,e,o){if(!i)return f.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),p(e,n)&&void 0===e[n]||f.call({o:e,s:r},t,n)})};var c=n.obj,l=c.as,p=c.has,h=c.is,d=c.map,g=c.copy,v=n.num.is,m=n.fn.is,k=a._;t.exports=u})(j,"./state"),j(function(t){var a=j("./type"),u=j("./val"),s=j("./node"),i={};function r(t,n){if(!t||n!==s.soul(t)||!s.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&s.is(e.n,t,e.as)}function f(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=c,s.ify(n.obj,o,n)&&(n.link=n.link||u.link.ify(s.soul(n.node)),n.obj!==t.shell&&(t.graph[u.link.is(n.link)]=n.node)),n)}function o(t,n,e){var o,i,r=this,a=r.env;if(s._===n&&g(t,u.link._))return e._;if(o=l(t,n,e,r,a)){if(n||(r.node=r.node||e||{},g(t,s._)&&s.soul(t)&&(r.node._=b(t._)),r.node=s.soul.ify(r.node,u.link.is(r.link)),r.link=r.link||u.link.ify(s.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),g(e,n))){if(void 0===(t=e[n]))return void d(e,n);if(!(o=l(t,n,e,r,a)))return}if(!n)return r.node;if(!0===o)return t;if((i=f(a,{obj:t,path:r.path.concat(n)})).node)return i.link}}function c(t){var n=this,e=u.link.is(n.link),o=n.env.graph;n.link=n.link||u.link.ify(t),n.link[u.link._]=t,n.node&&n.node[s._]&&(n.node[s._][u.link._]=t),g(o,e)&&(o[t]=o[e],d(o,e))}function l(t,n,e,o,i){var r;return!!u.is(t)||(h(t)?1:(r=i.invalid)?l(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}function p(t,n){var e,o;if(s._!==n)(e=u.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=i.to(this.graph,e,this.opt):this.obj[n]=t;else{if(v(t,u.link._))return;this.obj[n]=b(t)}}i.is=function(t,n,e,o){return!(!t||!h(t)||v(t)||k(t,r,{cb:n,fn:e,as:o}))},i.ify=function(t,n,e){var o={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(o.link=u.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,f(n,o),n.root=o.node,n.graph},i.node=function(t){var n=s.soul(t);if(n)return m({},n,t)},i.to=function(t,n,e){if(t){var o={};return e=e||{seen:{}},k(t[n],p,{obj:o,graph:t,opt:e}),o}};a.fn.is;var n=a.obj,h=n.is,d=n.del,g=n.has,v=n.empty,m=n.put,k=n.map,b=n.copy;t.exports=i})(j,"./graph"),j(function(t){j("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||empty)[e];if(!o)return;return o=this.on(e,n),clearTimeout(o.err),!0}e=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return e;var i=this.on(e,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(j,"./ask"),j(function(t){var r=j("./type");var a=r.time.is;t.exports=function(o){var i={s:{}};return o=o||{max:1e3,age:9e3},i.check=function(t){var n;return!!(n=i.s[t])&&(n.pass?n.pass=!1:i.track(t))},i.track=function(t,n){var e=i.s[t]||(i.s[t]={});return e.was=a(),n&&(e.pass=!0),i.to||(i.to=setTimeout(function(){var e=a();r.obj.map(i.s,function(t,n){t&&o.age>e-t.was||r.obj.del(i.s,n)}),i.to=null},o.age+9)),e},i}})(j,"./dup"),j(function(t){function c(t){return t instanceof c?(this._={gun:this,$:this}).$:this instanceof c?c.create(this._={gun:this,$:this,opt:t}):new c(t)}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.9,(c.chain=c.prototype).toJSON=function(){};var n=j("./type");function a(t){var n,e,o=this.as,i=o.at||o,r=i.$;(e=t["#"])||(e=t["#"]=h(9)),(n=i.dup).check(e)?o.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(e),i.ask(t["@"],t)||(t.get&&c.on.get(t,r),t.put&&c.on.put(t,r)),this.to.next(t),o.out||(t.out=a,i.on("out",t)))}function i(t,n,e,o){var i=this,r=c.state.is(e,n);if(!r)return i.err="Error: No state on '"+n+"' in node '"+o+"'!";var a=i.graph[o]||x,u=c.state.is(a,n,!0),s=a[n],f=c.HAM(i.machine,r,u,t,s);f.incoming?(i.put[o]=c.state.to(e,n,i.put[o]),(i.diff||(i.diff={}))[o]=c.state.to(e,n,i.diff[o]),i.souls[o]=!0):f.defer&&(i.defer=r<(i.defer||1/0)?r:i.defer)}function r(t,n){var e=this,o=e.$._,i=(o.next||x)[n];if(!i){if(!(o.opt||x).super)return void(e.souls[n]=!1);i=e.$.get(n)._}var r=e.map[n]={put:t,get:n,$:i.$},a={ctx:e,msg:r};e.async=!!o.tag.node,e.ack&&(r["@"]=e.ack),k(t,u,a),e.async&&(e.and||o.on("node",function(t){this.to.next(t),t===e.map[t.get]&&(e.souls[t.get]=!1,k(t.put,s,t),k(e.souls,function(t){if(t)return t})||e.c||(e.c=1,this.off(),k(e.map,f,e)))}),e.and=!0,o.on("node",r))}function u(t,n){var e=this.ctx,o=e.graph,i=this.msg,r=i.get,a=i.put,u=i.$._;o[r]=c.state.to(a,n,o[r]),e.async||(u.put=c.state.to(a,n,u.put))}function s(t,n){var e=this.put,o=this.$._;o.put=c.state.to(e,n,o.put)}function f(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}n.obj.to(n,c),c.HAM=j("./HAM"),c.val=j("./val"),c.node=j("./node"),c.state=j("./state"),c.graph=j("./graph"),c.on=j("./onto"),c.ask=j("./ask"),c.dup=j("./dup"),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",a,t),t.on("out",a,{at:t,out:a}),c.on("create",t),t.on("create",t)),t.once=1,n},c.on.put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:c.state(),ack:t["@"],cat:e,stop:{}};if(c.graph.is(t.put,null,i,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:c.log(o.err)});k(o.put,r,o),o.async||k(o.map,f,o),void 0!==o.defer&&setTimeout(function(){c.on.put(t,n)},o.defer-o.machine),o.diff&&e.on("put",m(t,{put:o.diff}))},c.on.get=function(t,n){var e=n._,o=t.get,i=o[y],r=e.graph[i],a=o[_],u=(e.next||(e.next={}))[i];if(!r)return e.on("get",t);if(a){if("string"!=typeof a||!v(r,a))return e.on("get",t);r=c.state.to(r,a)}else r=c.obj.copy(r);r=c.graph.node(r),(u||x).ack,e.on("in",{"@":t["#"],how:"mem",put:r,$:n}),e.on("get",t)},c.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return g(t)||(t={}),g(n.opt)||(n.opt=t),p(e)&&(e=[e]),o(e)&&(e=k(e,function(t,n,e){(n={}).id=n.url=t,e(t,n)}),g(n.opt.peers)||(n.opt.peers={}),n.opt.peers=m(e,n.opt.peers)),n.opt.peers=n.opt.peers||{},k(t,function t(n,e){!v(this,e)||l.is(n)||d.empty(n)?this[e]=n:n&&n.constructor!==Object&&!o(n)||k(n,t,this[e])},n.opt),c.on("opt",n),n.opt.uuid=n.opt.uuid||function(){return b()+h(12)},this};var o=c.list.is,l=c.text,p=l.is,h=l.random,d=c.obj,g=d.is,v=d.has,m=d.to,k=d.map,b=(d.copy,c.state.lex),y=c.val.link._,_=".",x=(c.node._,c.val.link.is,{});e.only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},(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)},c.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&((window.GUN=window.Gun=c).window=window);try{void 0!==$&&($.exports=c)}catch(t){}t.exports=c})(j,"./root"),j(function(t){var u=j("./root");u.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(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;h.del(n.root,"now");var i=n.root.mum;n.root.mum={},r.ref._.on("out",{$:r.ref,put:r.out=r.env.graph,opt:r.opt,"#":t}),n.root.mum=i?h.to(i,n.root.mum):i,n.root.now=o},r),r.res&&r.res())}function n(t,n){if(t)return!0}function c(r,t,n,a){var u=this,s=f.is(r);!t&&a.path.length&&(u.res||o)(function(){for(var t=a.path,n=u.ref,e=(u.opt,0),o=t.length;e .once, apologies unexpected."),this.once(t,n)},f.chain.once=function(t,n){var e=this,o=e._,i=o.put;if(0=(o.batch||1e3))return f();i=i||setTimeout(f,o.wait||1)}),a.on("get",function(n){this.to.next(n);var e,o,i,r=n.get;function t(){if(r&&(e=r["#"])){var t=r["."];(o=s[e]||i)&&t&&(o=Gun.state.to(o,t)),a.on("in",{"@":n["#"],put:Gun.graph.node(o),how:"lS",lS:n.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,e,o){s[o]=Gun.state.to(e,n,s[o])},f=function(t){var e;u=0,clearTimeout(i),i=!1;var n=r;r={},t&&(s=t);try{p.setItem(o.prefix,JSON.stringify(s))}catch(t){Gun.log(e=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),a.on("localStorage:error",{err:e,file:o.prefix,flush:s,retry:f})}(e||Gun.obj.empty(o.peers))&&Gun.obj.map(n,function(t,n){a.on("in",{"@":n,err:e,ok:0})})}}})}})(j,"./adapters/localStorage"),j(function(t){var v=j("../type"),m="undefined"!=typeof setImmediate?setImmediate:setTimeout;!function(){v.text.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var e=0,o=t.length;e<"])&&(r._.to=v.obj.map(o.split(","),p)),r.dam?void((o=s.hear[r.dam])&&o(r,i,u)):(k&&(a=+new Date),u.on("in",r),void(k&&!r.nts&&f.log(+new Date-a,"msg",r["#"])));var a}}};var l,p=function(t,n,e){e(t,!0)};function h(t){s.say(l,t)}function d(t){var n=t.batch;if(t.batch=t.tail=null,n&&n.length){var e;k&&(e=+new Date);try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return f.log("DAM JSON stringify error",t)}k&&f.log(+new Date-e,"say stringify",n.length),n&&g(n,t)}}function g(n,e){try{var t,o=e.wire;k&&(t=+new Date),e.say?e.say(n):o.send&&o.send(n),k&&f.log(+new Date-t,"wire send",n.length),s.say.d+=n.length||0,++s.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}s.hear.c=s.hear.d=0,s.say=function(t,n){if(this.to&&this.to.next(t),!t)return!1;var e,o,i,r;k&&(a=+new Date);var a,u=t._||(t._=function(){});if((e=t["#"])||(e=t["#"]=v.text.random(9)),(o=t["##"])||void 0===t.put||(o=t["##"]=v.obj.hash(t.put)),!(r=u.raw)&&(r=u.raw=s.raw(t),o&&(i=t["@"])&&(c.track(i+o).it=t,i=(c.s[i]||!0).it))){if(o===i["##"])return!1;i["##"]=o}if(k&&f.log(+new Date-a,"say prep"),c.track(e).it=t,!(n=n||(i=c.s[t["@"]])&&(i=i.it)&&(i=i._)&&(i=i.via))&&s.way)return s.way(t);if(!n||!n.id)return l=t,!!v.obj.is(n||f.peers)&&(k&&(a=+new Date),v.obj.map(n||f.peers,h),void(k&&f.log(+new Date-a,"say loop")));if(!n.wire&&s.wire&&s.wire(n),e!==n.last){if(n.last=e,n===u.via)return!1;if((i=u.to)&&(i[n.url]||i[n.pid]||i[n.id]))return!1;if(n.batch){if(n.tail=(i=n.tail||0)+r.length,n.tail<=f.pack)return void n.batch.push(r);d(n)}n.batch=[],setTimeout(function(){d(n)},f.gap),g(r,n)}},s.say.c=s.say.d=0,function(){s.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;if(!t.dam){var o=0,i=[];v.obj.map(f.peers,function(t){if(i.push(t.url||t.pid||t.id),9<++o)return!0}),1<"]=i.join())}var r=a(t);return e&&(e.raw=r),r};var a=JSON.stringify}(),s.hi=function(n){var t=n.wire||{};n.id?f.peers[n.url||n.id]=n:(t=n.id=n.id||v.text.random(9),s.say({dam:"?"},f.peers[t]=n)),n.met=n.met||+new Date,t.hied||u.on(t.hied="hi",n),t=n.queue,n.queue=[],v.obj.map(t,function(t){g(t,n)})},s.bye=function(t){u.on("bye",t);var n=+new Date;n-=t.met||n,s.bye.time=((s.bye.time||n)+n)/2,k=e.LOG},s.hear["!"]=function(t,n){f.log("Error:",t.err)},s.hear["?"]=function(t,n){t.pid?n.pid||(n.pid=t.pid):s.say({dam:"?",pid:f.pid,"@":t["#"]},n)},u.on("create",function(t){t.opt.pid=t.opt.pid||v.text.random(9),this.to.next(t),t.on("out",s.say)}),u.on("bye",function(t,n){t=f.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),v.obj.del(f.peers,t.id),t.wire=null});var i={};return u.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},f.lack||9e3))}),u.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],v.obj.map(u.next,function(t,n){(o={})[n]=u.graph[n],s.say({"##":v.obj.hash(o),get:{"#":n}},e)}))}),s}}catch(t){}})(j,"./adapters/mesh"),j(function(t){var f=j("../index");f.Mesh=j("./mesh"),f.on("opt",function(t){this.to.next(t);var o=t.opt;if(!t.once&&!1!==o.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||f.Mesh(t);i.wire||o.wire;i.wire=o.wire=u,setTimeout(function(){t.on("out",{dam:"hi"})},1);var r=2e3,a="undefined"!=typeof document&&document}}function u(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),s(n)},e.onerror=function(t){s(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function s(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry||60)-1,n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);u(n)},r))}})})(j,"./adapters/websocket")}(); \ No newline at end of file +!function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var e=(t=t||{}).console||{log:function(){}};function _(e,t){return t?require(e):e.slice?_[o(e)]:function(t,n){e(t={exports:{}}),_[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var m=module;_(function(t){var p={fn:{is:function(t){return!!t&&"function"==typeof t}}};p.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},p.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},p.text={is:function(t){return"string"==typeof t}},p.text.ify=function(t){return p.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},p.text.random=function(t,n){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.list={is:function(t){return t instanceof Array}},p.list.slit=Array.prototype.slice,p.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n",s.drift=0,s.is=function(t,n,e){var o=n&&t&&t[m]&&t[m][s._]||e;if(o)return g(o=o[n])?o:-1/0},s.lex=function(){return s().toString(36).replace(".","")},s.ify=function(t,n,e,o,i){if(!t||!t[m]){if(!i)return;t=a.soul.ify(t,i)}var r=c(t[m],s._);return void 0!==n&&n!==m&&(g(e)&&(r[n]=e),void 0!==o&&(t[n]=o)),t},s.to=function(t,n,e){var o=(t||{})[n];return p(o)&&(o=d(o)),s.ify(e,n,s.is(t,n),o,a.soul(t))},function(){function u(t,n){m!==n&&s.ify(this.o,n,this.s)}s.map=function(i,r,a){var t=p(t=i||r)?t:null;return i=v(i=i||r)?i:null,t&&!i?(r=g(r)?r:s(),t[m]=t[m]||{},h(t,u,{o:t,s:r}),t):(a=a||p(r)?r:void 0,r=g(r)?r:s(),function(t,n,e,o){if(!i)return u.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),l(e,n)&&void 0===e[n]||u.call({o:e,s:r},t,n)})}}();var f=n.obj,c=f.as,l=f.has,p=f.is,h=f.map,d=f.copy,g=n.num.is,v=n.fn.is,m=a._;t.exports=s})(_,"./state"),_(function(t){var a=_("./type"),f=_("./val"),c=_("./node"),r={};!function(){function i(t,n){if(!t||n!==c.soul(t)||!c.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&c.is(e.n,t,e.as)}r.is=function(t,n,e,o){return!(!t||!l(t)||u(t))&&!s(t,i,{cb:n,fn:e,as:o})}}(),function(){function u(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=i,c.ify(n.obj,o,n)&&(n.link=n.link||f.link.ify(c.soul(n.node)),n.obj!==t.shell&&(t.graph[f.link.is(n.link)]=n.node)),n)}function o(t,n,e){var o,i,r=this,a=r.env;if(c._===n&&h(t,f.link._))return e._;if(o=s(t,n,e,r,a)){if(n||(r.node=r.node||e||{},h(t,c._)&&c.soul(t)&&(r.node._=d(t._)),r.node=c.soul.ify(r.node,f.link.is(r.link)),r.link=r.link||f.link.ify(c.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),h(e,n))){if(void 0===(t=e[n]))return void p(e,n);if(!(o=s(t,n,e,r,a)))return}if(!n)return r.node;if(!0===o)return t;if((i=u(a,{obj:t,path:r.path.concat(n)})).node)return i.link}}function i(t){var n=this,e=f.link.is(n.link),o=n.env.graph;n.link=n.link||f.link.ify(t),n.link[f.link._]=t,n.node&&n.node[c._]&&(n.node[c._][f.link._]=t),h(o,e)&&(o[t]=o[e],p(o,e))}function s(t,n,e,o,i){var r;return!!f.is(t)||(l(t)?1:(r=i.invalid)?s(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}r.ify=function(t,n,e){var o={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(o.link=f.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,u(n,o),n.root=o.node,n.graph}}(),r.node=function(t){var n=c.soul(t);if(n)return e({},n,t)},function(){function i(t,n){var e,o;if(c._!==n)(e=f.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=r.to(this.graph,e,this.opt):this.obj[n]=t;else{if(u(t,f.link._))return;this.obj[n]=d(t)}}r.to=function(t,n,e){if(t){var o={};return e=e||{seen:{}},s(t[n],i,{obj:o,graph:t,opt:e}),o}}}();a.fn.is;var n=a.obj,l=n.is,p=n.del,h=n.has,u=n.empty,e=n.put,s=n.map,d=n.copy;t.exports=r})(_,"./graph"),_(function(t){_("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||empty)[e];if(!o)return;return o=this.on(e,n),clearTimeout(o.err),!0}e=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return e;var i=this.on(e,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(_,"./ask"),_(function(t){var r=_("./type");var a=r.time.is;t.exports=function(o){var i={s:{}};return o=o||{max:1e3,age:9e3},i.check=function(t){var n;return!!(n=i.s[t])&&(n.pass?n.pass=!1:i.track(t))},i.track=function(t,n){var e=i.s[t]||(i.s[t]={});return e.was=a(),n&&(e.pass=!0),i.to||(i.to=setTimeout(function(){var e=a();r.obj.map(i.s,function(t,n){t&&o.age>e-t.was||r.obj.del(i.s,n)}),i.to=null},o.age+9)),e},i}})(_,"./dup"),_(function(t){function c(t){return t instanceof c?(this._={gun:this,$:this}).$:this instanceof c?c.create(this._={gun:this,$:this,opt:t}):new c(t)}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.9,(c.chain=c.prototype).toJSON=function(){};var n=_("./type");n.obj.to(n,c),c.HAM=_("./HAM"),c.val=_("./val"),c.node=_("./node"),c.state=_("./state"),c.graph=_("./graph"),c.on=_("./onto"),c.ask=_("./ask"),c.dup=_("./dup"),function(){function a(t){var n,e,o=this.as,i=o.at||o,r=i.$;(e=t["#"])||(e=t["#"]=u(9)),(n=i.dup).check(e)?o.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(e),i.ask(t["@"],t)||(t.get&&c.on.get(t,r),t.put&&c.on.put(t,r)),this.to.next(t),o.out||(t.out=a,i.on("out",t)))}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",a,t),t.on("out",a,{at:t,out:a}),c.on("create",t),t.on("create",t)),t.once=1,n}}(),function(){function i(t,n,e,o){var i=this,r=c.state.is(e,n);if(!r)return i.err="Error: No state on '"+n+"' in node '"+o+"'!";var a=i.graph[o]||v,u=c.state.is(a,n,!0),s=a[n],f=c.HAM(i.machine,r,u,t,s);f.incoming?(i.put[o]=c.state.to(e,n,i.put[o]),(i.diff||(i.diff={}))[o]=c.state.to(e,n,i.diff[o]),i.souls[o]=!0):f.defer&&(i.defer=r<(i.defer||1/0)?r:i.defer)}function r(t,n){var e=this,o=e.$._,i=(o.next||v)[n];if(!i){if(!(o.opt||v).super)return void(e.souls[n]=!1);i=e.$.get(n)._}var r=e.map[n]={put:t,get:n,$:i.$},a={ctx:e,msg:r};e.async=!!o.tag.node,e.ack&&(r["@"]=e.ack),h(t,u,a),e.async&&(e.and||o.on("node",function(t){this.to.next(t),t===e.map[t.get]&&(e.souls[t.get]=!1,h(t.put,s,t),h(e.souls,function(t){if(t)return t})||e.c||(e.c=1,this.off(),h(e.map,f,e)))}),e.and=!0,o.on("node",r))}function u(t,n){var e=this.ctx,o=e.graph,i=this.msg,r=i.get,a=i.put,u=i.$._;o[r]=c.state.to(a,n,o[r]),e.async||(u.put=c.state.to(a,n,u.put))}function s(t,n){var e=this.put,o=this.$._;o.put=c.state.to(e,n,o.put)}function f(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}c.on.put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:c.state(),ack:t["@"],cat:e,stop:{}};if(c.graph.is(t.put,null,i,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:c.log(o.err)});h(o.put,r,o),o.async||h(o.map,f,o),void 0!==o.defer&&setTimeout(function(){c.on.put(t,n)},o.defer-o.machine),o.diff&&e.on("put",p(t,{put:o.diff}))},c.on.get=function(t,n){var e=n._,o=t.get,i=o[d],r=e.graph[i],a=o[g],u=(e.next||(e.next={}))[i];if(!r)return e.on("get",t);if(a){if("string"!=typeof a||!l(r,a))return e.on("get",t);r=c.state.to(r,a)}else r=c.obj.copy(r);r=c.graph.node(r),(u||v).ack,e.on("in",{"@":t["#"],how:"mem",put:r,$:n}),e.on("get",t)}}(),c.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return s(t)||(t={}),s(n.opt)||(n.opt=t),r(e)&&(e=[e]),o(e)&&(e=h(e,function(t,n,e){(n={}).id=n.url=t,e(t,n)}),s(n.opt.peers)||(n.opt.peers={}),n.opt.peers=p(e,n.opt.peers)),n.opt.peers=n.opt.peers||{},h(t,function t(n,e){!l(this,e)||i.is(n)||a.empty(n)?this[e]=n:n&&n.constructor!==Object&&!o(n)||h(n,t,this[e])},n.opt),c.on("opt",n),n.opt.uuid=n.opt.uuid||function(){return f()+u(12)},this};var o=c.list.is,i=c.text,r=i.is,u=i.random,a=c.obj,s=a.is,l=a.has,p=a.to,h=a.map,f=(a.copy,c.state.lex),d=c.val.link._,g=".",v=(c.node._,c.val.link.is,{});e.only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},(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)},c.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&((window.GUN=window.Gun=c).window=window);try{void 0!==m&&(m.exports=c)}catch(t){}t.exports=c})(_,"./root"),_(function(t){var u=_("./root");u.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(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;h.del(n.root,"now");var i=n.root.mum;n.root.mum={},r.ref._.on("out",{$:r.ref,put:r.out=r.env.graph,opt:r.opt,"#":t}),n.root.mum=i?h.to(i,n.root.mum):i,n.root.now=o},r),r.res&&r.res())}function n(t,n){if(t)return!0}function c(r,t,n,a){var u=this,s=f.is(r);!t&&a.path.length&&(u.res||o)(function(){for(var t=a.path,n=u.ref,e=(u.opt,0),o=t.length;e .once, apologies unexpected."),this.once(t,n)},f.chain.once=function(t,n){var e=this,o=e._,i=o.put;if(0=(o.batch||1e3))return f();i||(i=setTimeout(f,o.wait||1))}),r.on("get",function(n){this.to.next(n);var e,o,i=n.get;function t(){if(i&&(e=i["#"])){var t=i["."];(o=s[e]||void 0)&&t&&(o=Gun.state.to(o,t)),r.on("in",{"@":n["#"],put:Gun.graph.node(o),how:"lS",lS:n.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,e,o){s[o]=Gun.state.to(e,n,s[o])},f=function(t){var e;u=0,clearTimeout(i),i=!1;var n=a;a={},t&&(s=t);try{p.setItem(o.prefix,JSON.stringify(s))}catch(t){Gun.log(e=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),r.on("localStorage:error",{err:e,file:o.prefix,flush:s,retry:f})}(e||Gun.obj.empty(o.peers))&&Gun.obj.map(n,function(t,n){r.on("in",{"@":n,err:e,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var g=_("../type"),f="undefined"!=typeof setImmediate?setImmediate:setTimeout;!function(){g.text.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var e=0,o=t.length;e<"])&&(r._.to=g.obj.map(o.split(","),s)),r.dam?void((o=l.hear[r.dam])&&o(r,i,u)):(v&&(a=+new Date),u.on("in",r),void(v&&!r.nts&&p.log(a,+new Date-a,"msg",r["#"])));var a}}};var s=function(t,n,e){e(t,!0)};function d(n,e){try{var t,o=e.wire;v&&(t=+new Date),e.say?e.say(n):o.send&&o.send(n),v&&p.log(t,+new Date-t,"wire send",n.length),l.say.d+=n.length||0,++l.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}l.hear.c=l.hear.d=0,function(){var s;function f(t){l.say(s,t)}function c(t){var n=t.batch;if(t.batch=t.tail=null,n&&n.length){var e;v&&(e=+new Date);try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return p.log("DAM JSON stringify error",t)}v&&p.log(e,+new Date-e,"say stringify",n.length),n&&d(n,t)}}l.say=function(t,n){if(this.to&&this.to.next(t),!t)return!1;var e,o,i,r;v&&(a=+new Date);var a,u=t._||(t._=function(){});if((e=t["#"])||(e=t["#"]=g.text.random(9)),(o=t["##"])||void 0===t.put||(o=t["##"]=g.obj.hash(t.put)),!(r=u.raw)&&(r=u.raw=l.raw(t),o&&(i=t["@"])&&(h.track(i+o).it=t,i=(h.s[i]||!0).it))){if(o===i["##"])return!1;i["##"]=o}if(v&&p.log(a,+new Date-a,"say prep"),h.track(e).it=t,n||(n=(i=h.s[t["@"]])&&(i=i.it)&&(i=i._)&&(i=i.via)),!n&&l.way)return l.way(t);if(!n||!n.id)return s=t,!!g.obj.is(n||p.peers)&&(v&&(a=+new Date),g.obj.map(n||p.peers,f),void(v&&p.log(a,+new Date-a,"say loop")));if(!n.wire&&l.wire&&l.wire(n),e!==n.last){if(n.last=e,n===u.via)return!1;if((i=u.to)&&(i[n.url]||i[n.pid]||i[n.id]))return!1;if(n.batch){if(n.tail=(i=n.tail||0)+r.length,n.tail<=p.pack)return void n.batch.push(r);c(n)}n.batch=[],setTimeout(function(){c(n)},p.gap),d(r,n)}},l.say.c=l.say.d=0}(),function(){l.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;if(!t.dam){var o=0,i=[];g.obj.map(p.peers,function(t){if(i.push(t.url||t.pid||t.id),9<++o)return!0}),1<"]=i.join())}var r=a(t);return e&&(e.raw=r),r};var a=JSON.stringify}(),l.hi=function(n){var t=n.wire||{};n.id?p.peers[n.url||n.id]=n:(t=n.id=n.id||g.text.random(9),l.say({dam:"?",pid:u.opt.pid},p.peers[t]=n),delete h.s[n.last]),n.met=n.met||+new Date,t.hied||u.on(t.hied="hi",n),t=n.queue,n.queue=[],g.obj.map(t,function(t){d(t,n)})},l.bye=function(t){u.on("bye",t);var n=+new Date;n-=t.met||n,l.bye.time=((l.bye.time||n)+n)/2,v=e.LOG},l.hear["!"]=function(t,n){p.log("Error:",t.err)},l.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(l.say({dam:"?",pid:p.pid,"@":t["#"]},n),delete h.s[n.last])},u.on("create",function(t){t.opt.pid=t.opt.pid||g.text.random(9),this.to.next(t),t.on("out",l.say)}),u.on("bye",function(t,n){t=p.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),g.obj.del(p.peers,t.id),t.wire=null});var i={};return u.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},p.lack||9e3))}),u.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],g.obj.map(u.next,function(t,n){(o={})[n]=u.graph[n],l.say({"##":g.obj.hash(o),get:{"#":n}},e)}))}),l}}catch(t){}})(_,"./adapters/mesh"),_(function(t){var f=_("../index");f.Mesh=_("./mesh"),f.on("opt",function(t){this.to.next(t);var o=t.opt;if(!t.once&&!1!==o.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||f.Mesh(t);i.wire||o.wire;i.wire=o.wire=u,setTimeout(function(){t.on("out",{dam:"hi"})},1);var r=2e3,a="undefined"!=typeof document&&document}}function u(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),s(n)},e.onerror=function(t){s(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function s(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry||60)-1,n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);u(n)},r))}})})(_,"./adapters/websocket")}(); \ No newline at end of file diff --git a/package.json b/package.json index 5c1da0d5..5f4babb0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.2019.1211", + "version": "0.2019.1228", "description": "A realtime, decentralized, offline-first, graph data synchronization engine.", "main": "index.js", "browser": "gun.js", diff --git a/src/adapters/mesh.js b/src/adapters/mesh.js index 0c4ca13e..9e52f427 100644 --- a/src/adapters/mesh.js +++ b/src/adapters/mesh.js @@ -19,14 +19,14 @@ function Mesh(root){ if('[' === tmp){ try{msg = JSON.parse(raw);}catch(e){opt.log('DAM JSON parse error', e)} if(!msg){ return } - LOG && opt.log(msg.length, 'in hear batch'); + LOG && opt.log(+new Date, msg.length, 'in hear batch'); (function go(){ var S; LOG && (S = +new Date); // STATS! var m, c = 100; // hardcoded for now? while(c-- && (m = msg.shift())){ mesh.hear(m, peer); } - LOG && opt.log(+new Date - S, 'batch heard'); + LOG && opt.log(S, +new Date - S, 'batch heard'); if(!msg.length){ return } puff(go, 0); }()); @@ -55,7 +55,7 @@ function Mesh(root){ } var S; LOG && (S = +new Date); root.on('in', msg); - LOG && !msg.nts && opt.log(+new Date - S, 'msg', msg['#']); + LOG && !msg.nts && opt.log(S, +new Date - S, 'msg', msg['#']); return; } } @@ -83,7 +83,7 @@ function Mesh(root){ } } } - LOG && opt.log(+new Date - S, 'say prep'); + LOG && opt.log(S, +new Date - S, 'say prep'); dup.track(id).it = msg; // track for 9 seconds, default. Earth<->Mars would need more! if(!peer){ peer = (tmp = dup.s[msg['@']]) && (tmp = tmp.it) && (tmp = tmp._) && (tmp = tmp.via) } if(!peer && mesh.way){ return mesh.way(msg) } @@ -91,7 +91,7 @@ function Mesh(root){ if(!Type.obj.is(peer || opt.peers)){ return false } var S; LOG && (S = +new Date); Type.obj.map(peer || opt.peers, each); // in case peer is a peer list. - LOG && opt.log(+new Date - S, 'say loop'); + LOG && opt.log(S, +new Date - S, 'say loop'); return; } if(!peer.wire && mesh.wire){ mesh.wire(peer) } @@ -118,7 +118,7 @@ function Mesh(root){ var S; LOG && (S = +new Date); try{tmp = (1 === tmp.length? tmp[0] : JSON.stringify(tmp)); }catch(e){return opt.log('DAM JSON stringify error', e)} - LOG && opt.log(+new Date - S, 'say stringify', tmp.length); + LOG && opt.log(S, +new Date - S, 'say stringify', tmp.length); if(!tmp){ return } send(tmp, peer); } @@ -135,7 +135,7 @@ function Mesh(root){ if(wire.send){ wire.send(raw); } - LOG && opt.log(+new Date - S, 'wire send', raw.length); + LOG && opt.log(S, +new Date - S, 'wire send', raw.length); mesh.say.d += raw.length||0; ++mesh.say.c; // STATS! }catch(e){ (peer.queue = peer.queue || []).push(raw); @@ -171,7 +171,8 @@ function Mesh(root){ opt.peers[peer.url || peer.id] = peer; } else { tmp = peer.id = peer.id || Type.text.random(9); - mesh.say({dam: '?'}, opt.peers[tmp] = peer); + mesh.say({dam: '?', pid: root.opt.pid}, opt.peers[tmp] = peer); + delete dup.s[peer.last]; // IMPORTANT: see https://gun.eco/docs/DAM#self } peer.met = peer.met || +(new Date); if(!tmp.hied){ root.on(tmp.hied = 'hi', peer) } @@ -189,18 +190,12 @@ function Mesh(root){ } mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } mesh.hear['?'] = function(msg, peer){ - if(!msg.pid){ - mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer); - // @rogowski I want to re-enable this AXE logic with some fix/merge later. - /* var tmp = peer.queue; peer.queue = []; - Type.obj.map(tmp, function(msg){ - mesh.say(msg, peer); - }); */ - // @rogowski 2: I think with my PID fix we can delete this and use the original. - return; + if(msg.pid){ + if(!peer.pid){ peer.pid = msg.pid } + if(msg['@']){ return } } - if(peer.pid){ return } - peer.pid = msg.pid; + mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer); + delete dup.s[peer.last]; // IMPORTANT: see https://gun.eco/docs/DAM#self } root.on('create', function(root){ diff --git a/src/chain.js b/src/chain.js index 68be3de3..834f13c6 100644 --- a/src/chain.js +++ b/src/chain.js @@ -34,7 +34,7 @@ function output(msg){ if(obj_has(back, 'put')){ back.on('in', back); } - if(tmp){ return } + if(tmp && u !== back.put){ return } //if(tmp){ return } msg.$ = back.$; } else if(obj_has(back.put, get)){ // TODO: support #LEX ! @@ -247,7 +247,7 @@ function not(at, msg){ if(u === tmp && u !== at.put){ return true } neat.put = u; if(neat.ack){ - neat.ack = -1; // TODO: BUG? Should this be 0? + neat.ack = -1; // Shouldn't this be reset to 0? If we do that, SEA test `set user ref should be found` fails, odd. } neat.on('in', { get: key,