arch-stream
Advanced tools
Comparing version 0.0.70 to 0.0.71
@@ -1,2 +0,2 @@ | ||
/*! arch-stream v0.0.70 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.71 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */ | ||
/*! Link: MIT Lisence http://www.opensource.org/licenses/mit-license.php */ | ||
@@ -265,3 +265,3 @@ define = typeof define === 'function' && define.amd | ||
discharger = function () { | ||
return null; | ||
return void 0; | ||
}; | ||
@@ -787,3 +787,3 @@ } | ||
}; | ||
Observable.prototype.observe = function (type, subscriber, identifier) { | ||
Observable.prototype.monitor = function (type, subscriber, identifier) { | ||
if (identifier === void 0) { | ||
@@ -894,4 +894,4 @@ identifier = subscriber; | ||
var emitId = pub[0], data = pub[1]; | ||
var subscriber = sub[1], emittedId = sub[3], observing = sub[4]; | ||
if (observing || emitId <= emittedId) | ||
var subscriber = sub[1], emittedId = sub[3], monitor = sub[4]; | ||
if (monitor || emitId <= emittedId) | ||
return pub; | ||
@@ -904,4 +904,4 @@ sub[3] = emitId; | ||
var emitId = pub[0], data = pub[1]; | ||
var subscriber = sub[1], emittedId = sub[3], observing = sub[4]; | ||
if (!observing || emitId <= emittedId) | ||
var subscriber = sub[1], emittedId = sub[3], monitor = sub[4]; | ||
if (!monitor || emitId <= emittedId) | ||
return pub; | ||
@@ -1142,3 +1142,3 @@ sub[3] = emitId; | ||
void this.checkState(); | ||
void this.children.emit(namespace || [], new WorkerCommand_$Exit(reason)); | ||
void this.children.emit(namespace || [], new WorkerCommand_$Exit(reason)).off(namespace || []); | ||
if (namespace) | ||
@@ -1145,0 +1145,0 @@ return; |
@@ -1,3 +0,3 @@ | ||
/*! arch-stream v0.0.70 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.71 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */ | ||
/*! Link: MIT Lisence http://www.opensource.org/licenses/mit-license.php */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="arch-stream",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?window[i]=window[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||window[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)if(s)for(;2>o;)void Promise.resolve().then(r),void++o;else for(;o<u.length;)void setTimeout(r,u[o%u.length]),void++o}t.queue=e;var n=[],o=0,s="function"==typeof Promise,u=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/message",["require","exports","src/lib/thenable","src/lib/tick"],function(t,e,r,i){"use strict";function n(t){return t}var o=Object.create(null),s=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=o,this.collection_=[],this.transform_=!1,this.listeners_=[],t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){if(this.collection_.length>0)return this.collection_;var t=this,e=[];do void e.push(t);while(t=t.child_);return this.collection_=e},t.prototype.transport_=function(t,e){function i(t,i,u){function c(t){o=!0,i=u?t:i,s&&n.child_&&void n.child_.send(i,e)}return t.every(function(t){n=t,n.memory_=i;var e=n.listener(n.memory_);return r.isThenable(e)?(o=!1,void e.then(c,c),o):(i=u?e:i,!0)})}var n,o=!1,s=!1,u=i(this.collect_(),t,this.transform_);s=!0,u&&"function"==typeof e&&void e(t)},t.prototype.clone=function(){function e(r){return r.parent?new t(e(r.parent),r.listener):new t(void 0,r.listener)}return e(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e,r){var n=this;switch(!0){case"function"==typeof e:return this.send(t,!1,e);case e===!0:return void i.Tick(function(){return n.transport_(t,r)}),this;case e===!1:default:return void this.transport_(t,r),this}},t.prototype.recv=function(e){var r=new t(this);return this.listener=e,this.collection_=[],this.memory_!==o&&void this.send(this.memory_),r},t.prototype.trans=function(t){return this.transform_=!0,this.recv(t)},t.prototype.then=function(e,r){var i=this,o=new t;return this.child_=void 0,this.listener=n,this.listeners_.push(o),this.trans(function(t){var e=i.listeners_;i.listeners_=[],function r(){try{for(;e.length>0;)e.shift().send(t)}catch(i){void console.error(i),void r()}}()}),o.trans(e||n)},t}();e.Message=s}),define("src/lib/throttle",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return void this.processing_.push(t),void this.resolver_(t),!0;this.queue_.push(t);do void this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?void this.processing_.splice(e,1):void this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&void this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/stream/modular",["require","exports","src/lib/throttle","src/lib/tick","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,this.read=this.read.bind(this),this.write=this.write.bind(this),void i.Tick(function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}void this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){void--this.count,this.count<0&&void this.throwCountExceededError(),void this.compose_(),void this.last_.recv(t)},t.prototype.read=function(t){var e=this;void 0===t&&(t=n.noop);var r=!1;return void this.read_(function(n){e.flow_&&void i.Tick(function(){return void e.flow_.dequeue(n)}),r&&void t(n)}),r=!0,this},t.prototype.write_=function(t,e){void this.first_.send(t,e)},t.prototype.write=function(t,e){return this.flow_?void this.flow_.enqueue(t):void this.write_(t,e),this},t.prototype.flow=function(t,e,i){var n=this;return void 0===e&&(e=1/0),this.flow_=new r["default"],void this.flow_.flow(t,e,i),void this.flow_.register(function(t){return n.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();e.ModularStream=o}),define("src/stream/compose",["require","exports","src/stream/modular"],function(t,e,r){"use strict";var i=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){var e=this.procs_.length;return void t.reduceRight(function(t,r,i){return t[i+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var i=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return i.extract_(t)instanceof r?e(t):0})),void--e.count,e.count<0&&void e.throwCountExceededError(),void this.register(e.procs),this},t.prototype["export"]=function(t){return new r.ModularStream(this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(void--t.count,void this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(void--t.count,void this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();e.ComposeStream=i}),define("src/stream/transform",["require","exports","src/lib/message","src/stream/compose","src/stream/modular"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e){var i=this;void 0===e&&(e=new r.Message),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return i.proxy(function(){return e})},void 0)}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof n.ModularStream?(new i.ComposeStream)["import"](t,e):new i.ComposeStream(t)},t.prototype["export"]=function(t){return(new i.ComposeStream).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,i,n){function o(t){return Array.isArray(t)?t:[t]}var s=e.proxies_.filter(function(t){return"function"==typeof t[i]}).reduce(function(t,e){return o(e[i].apply(void 0,t)||t)},n),u="pipe";switch(i){case u:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[i]).call.apply(c,[r(e,u,s)].concat(n));default:return r(e,u,s)}var c}var i=this,n="function"==typeof e?e():e;return this.proxies_.push(n),void Object.keys(n).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof n[t]}).reduce(function(t,e){return i[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];return r(i,e,t)}},void 0),this},t}();e.ArchStream=o}),define("src/proxy/case",["require","exports"],function(t,e){"use strict";function r(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var n=+i[e(r)+""];n>-1&&n<t.length&&t[n](r)}}var i=Object.create(null);return void t.reduce(function(t,e,r){return i[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/proxy/hook",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),s(e)}})}var i=t.pre,n=void 0===i?r.noop:i,o=t.post,s=void 0===o?r.noop:o;return function(t){return{pipe:e}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/proxy/responsibility",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(){function t(t,i){return e.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r-0]=arguments[r];return e.map(function(e){return function(r){if(!(i(r)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity.\n "+i(r).constructor);e(r)}})},e["export"]=function(){return function(e){i(e)instanceof t&&void Object.freeze(i(e))}},r.noop}var e;return function(r){return e={rule:t}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/lib/proxy",["require","exports","src/proxy/case","src/proxy/hook","src/proxy/responsibility"],function(t,e,r,i,n){"use strict";e.Proxy={Case:r["default"],Hook:i["default"],Responsibility:n["default"]}}),define("src/lib/map",["require","exports"],function(t,e){"use strict";function r(t,e){return e?0===t.length?"":"_"+t.join(n):t+""}function i(t,e,r){return void 0===r&&(r=""),e?""===t?[]:t.slice(1).split(n).map(function(t){return"number"===r?+t:t}):"number"===r?+t:t}var n="<\x00��>",o=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[r(t,this.multiKey_)]},t.prototype.set=function(t,e){return void 0===this.multiKey_&&(this.multiKey_=Array.isArray(t)),this.type_||(this.multiKey_?t.length>0&&(this.type_=typeof t[0]):this.type_=typeof t),void this.reset_(),this.map_[r(t,this.multiKey_)]=e},t.prototype.has=function(t){return!!this.map_[r(t,this.multiKey_)]||r(t,this.multiKey_)in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[r(t,this.multiKey_)],this},t.prototype.clear=function(){return void this.reset_(),this.map_=Object.create(null),this},t.prototype.reset_=function(){this.size_=NaN,this.entries_=void 0},Object.defineProperty(t.prototype,"size",{get:function(){return this.size_>=0?this.size_:this.size_=Object.keys(this.map_).length},enumerable:!0,configurable:!0}),t.prototype.entries=function(){var t=this;return this.entries_?this.entries_:this.entries_=Object.keys(this.map_).map(function(e){return[i(e,t.multiKey_,t.type_),t.get(i(e,t.multiKey_,t.type_))]})},t}();e.Map=o}),define("src/lib/observable",["require","exports","src/lib/map","src/lib/noop"],function(t,e,r,i){"use strict";var n=function(){function t(t){void 0===t&&(t="."),this.separator_=t,this.emitId_=0,this.emitQueue_=[],this.refsOverCache_=new r.Map,this.refsUnderCache_=new r.Map,this.node_={parent:void 0,children:Object.create(null),list:[]}}return t.prototype.formatEventType_=function(t){if(t instanceof Object){if(Array.isArray(t))return t.slice();var e=t;return e.namespace?this.formatEventType_(e.namespace).concat(e.type):[e.type]}return this.separator_&&t?(t+"").split(this.separator_):[t+""]},t.prototype.observe=function(t,e,r){void 0===r&&(r=e);var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(i).list.push([i,e,r,this.emitId_,!0]),this},t.prototype.on=function(t,e,r){void 0===r&&(r=e);var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(i).list.push([i,e,r,this.emitId_,!1]),void this.drain_(i),this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seek_(r).list.some(function(t,r,i){var n=t[2];if(e!==n)return!1;switch(r){case 0:return!void i.shift();case i.length-1:return!void i.pop();default:return!void i.splice(r,1)}}),this;case"undefined":var i=this.seek_(r);return i.children=Object.create(null),i.list=[],void this.refsOverCache_.clear(),void this.refsUnderCache_.clear(),this;default:throw this.throwTypeErrorIfInvalidSubscriber_(e,r)}},t.prototype.once=function(t,e){var r=this;return void this.throwTypeErrorIfInvalidSubscriber_(e,this.formatEventType_(t)),this.on(t,function(i){return void r.off(t,e),e(i)},e)},t.prototype.emit=function(t,e,r){return t instanceof Object&&!Array.isArray(t)?this.emit_(this.formatEventType_(t),t,e):this.emit_(this.formatEventType_(t),e,r)},t.prototype.emit_=function(t,e,r){return void 0===r&&(r=i.noop),void this.emitQueue_.push([++this.emitId_,e,r]),void this.drain_(t),this},t.prototype.reflect=function(t,e){var r;return t instanceof Object&&!Array.isArray(t)?void this.emit(this.formatEventType_(t),t,function(t,e){return r=e}):void this.emit(this.formatEventType_(t),e,function(t,e){return r=e}),r},t.prototype.drain_=function(t){for(var e=this.emitQueue_,r=function(){var r=e.shift(),n=[];try{void i.refs_(t).reduce(function(t,e){var r=t[0],i=t[1],o=e[1],s=e[3],u=e[4];return u||s>=r?t:(e[3]=r,void n.push(o(i)),t)},r),void i.refs_(t,!0).reduce(function(t,e){var r=t[0],i=t[1],n=e[1],o=e[3],s=e[4];return!s||o>=r?t:(e[3]=r,void n(i),t)},r)}catch(o){return void e.unshift(r),void 0!==o&&null!==o&&void console.error(o),"continue"}var s=r[1],u=r[2];void u(s,n)},i=this;e.length>0;){r()}return void this.resetEmitIdIfPossible_(),this},t.prototype.resetEmitIdIfPossible_=function(){this.emitId_<5e8||this.emitQueue_.length>0||void this.refs_([]).reduce(function(t,e){return e[3]=t},this.emitId_=0)},t.prototype.refs=function(t){return this.refs_(this.formatEventType_(t)).map(function(t){return[t[0],t[2],t[4]]})},t.prototype.refs_=function(t,e){function r(t){var e=t.parent,i=t.list;return e?i.concat(r(e)):i}function i(t){var e=t.children,r=t.list;return Object.keys(e).sort().reduce(function(t,r){return void t.push.apply(t,i(e[r])),0===t.length&&delete e[r],t},r.slice())}return void 0===e&&(e=!1),e?this.refsOverCache_.get(t)||this.refsOverCache_.set(t,r(this.seek_(t,!0))):this.refsUnderCache_.get(t)||this.refsUnderCache_.set(t,i(this.seek_(t,!0)))},t.prototype.seek_=function(t,e){function r(t,e){var r=t.children;return r[e+""]?r[e+""]:r[e+""]={parent:t,children:Object.create(null),list:[]}}var i=this;return void 0===e&&(e=!1),e||void[void 0].concat(t).reduce(function(t,e,r,n){void i.refsOverCache_["delete"](n.slice(1,r+1)),void i.refsUnderCache_["delete"](n.slice(1,r+1))},void 0),t.reduce(r,this.node_)},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("ArchStream: Observable: Invalid subscriber.\n "+t)}},t}();e.Observable=n}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/thenable","src/lib/tick","src/lib/noop"],function(t,e,r,i,n,o){"use strict";var s=function(){function t(){}return t}(),u=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(s),c=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(s),a=0,h=0,p=function(){function t(t,e){void 0===t&&(t="anonymous"),void 0===e&&(e=o.noop),this.name=t,this.destructor=e,this.monitor=new r.Observable,this.events={exec:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.children=new r.Observable,this.state=!0,this.queue=[],void++a}return Object.defineProperty(t,"count",{get:function(){return a},enumerable:!0,configurable:!0}),Object.defineProperty(t,"procs",{get:function(){return h},enumerable:!0,configurable:!0}),t.prototype.register=function(t,e,r){var i=this;void 0===r&&(r=0),void this.checkState(),t=t.slice();var o=new f(this,t,e,r);return void++h,void this.children.on(t,o.receive),void this.events.exec.emit(t,[t,e]),void this.monitor.emit("exec",[t,e,void 0]),void n.Tick(function(t){return i.drain()}),o.terminate},t.prototype.call=function(t,e,r,i){var s=this;return void 0===r&&(r=0),void 0===i&&(i=o.noop),void this.checkState(),t=t.slice(),void this.queue.push([t,e,i,r,Date.now()]),void n.Tick(function(t){return s.drain()}),r>0&&void setTimeout(function(){return s.drain(t)},r+9),this},t.prototype.cast=function(t,e,r){void 0===r&&(r=o.noop),void this.checkState();var i=this.children.reflect(t,new u(e));return void r(e,i),this},t.prototype.refs=function(t){return void this.checkState(),this.children.refs(t).map(function(t){var e=t[0],r=t[1];return[e,r(void 0).process,r(void 0).terminate]})},t.prototype.terminate=function(t,e){if(void this.checkState(),void this.children.emit(t||[],new c(e)),!t){for(this.state=!1;this.queue.length>0;){var r=this.queue.shift(),i=r[0],n=r[1];void this.loss(i,n)}try{void this.destructor(e)}catch(o){void console.error(o)}void--a}},t.prototype.checkState=function(){if(!this.state)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){void 0===t&&(t=[]);for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],a=o[2],h=o[3],p=o[4],f=t.every(function(t,e){return t===s[e]})?n.children.reflect(s,new u(c)):[];return 0===f.length&&p+h>r?(e=i,"continue"):(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===f.length&&void n.loss(s,c),void a(c,f),void(e=i))},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t.prototype.loss=function(t,e){var r=[this.events.loss.reflect(t,[t,void 0,e]).length,this.monitor.reflect("loss",[t,void 0,e]).length].reduce(function(t,e){return t+e},0);r>0||void console.error("Supervisor "+this.name,"loss",t,e)},t}();e.Supervisor=p;var f=function(){function t(t,e,r,i){var n=this;this.parent=t,this.namespace=e,this.process=r,this.parallel=i,this.state=!0;var o=this.receive;this.receive=function(t){return o.call(n,t)};var s=this.terminate;this.terminate=function(t){return s.call(n,t)}}return t.prototype.receive=function(t){var e=this;if(!this.state)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.");if(void 0===t)return this;if(t instanceof u){if(this.parallel<0)throw void 0;try{var r=this.process(t.data);return i.isThenable(r)&&(void--this.parallel,void r.then(function(t){return void++e.parallel},function(t){return e.terminate(t)})),r}catch(n){throw void void this.terminate(n)}}if(t instanceof c)throw void void this.terminate(t.reason);throw new TypeError("ArchStream: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){if(!this.state)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" cannot terminate multiply with "+t+".");void--h,this.state=!1,void this.parent.children.off(this.namespace,this.receive),void this.parent.events.exit.emit(this.namespace,[this.namespace,this.process,t]),void this.parent.monitor.emit("exit",[this.namespace,this.process,t])},t}()}),define("src/lib/set",["require","exports","src/lib/map"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this),this.replacer_=e}return __extends(e,t),e.prototype.set=function(e,r){if(!this.has(e))return t.prototype.set.call(this,e,r);if(!this.replacer_)throw new Error("Cannot overwrite value of set without replacer.");return t.prototype.set.call(this,e,this.replacer_(this.get(e),r))},e}(r.Map);e.Set=i}),define("src/lib/timer",["require","exports"],function(t,e){"use strict";function r(t){var e=t.begin,i=void 0===e?0:e,n=t.end,o=void 0===n?864e5:n,s=t.step,u=void 0===s?function(t){return 3*(t||1)}:s,c=t.precond,a=void 0===c?function(){return!0}:c,h=t.task,p=void 0===h?function(){}:h,f=t.postcond,d=void 0===f?function(){return!0}:f,l=t.complete,v=void 0===l?function(){return 0}:l,_=t.error,y=void 0===_?function(){return 0}:_,m=t.timeout,b=void 0===m?function(){return 0}:m,w=t.since,x=void 0===w?Date.now():w;i=0>i?0:i,void setTimeout(function(){try{if(a()){var t=p();if(d())return void v(t)}}catch(e){return void y(e)}var n=Date.now(),s=u(n-x);return 0>=o-(n-x)?void b():void void r({precond:a,task:p,postcond:d,complete:v,timeout:b,begin:i+s,end:o,step:u,since:x})},i)}e.Timer=r}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("ArchStream: uuid: Invalid uuid dynamic seed.");return o.map(function(e){if("x"!==e&&"y"!==e)return e;var r=Math.random()*t%16|0,i="x"==e?r:3&r|8;return i.toString(16)}).join("").toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("ArchStream: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split(""),s=n;e.v4=i}),define("src/lib/monad",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.extract=function(t){return this.evaluate().extract(t)},t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t.prototype.assert=function(t){return this},t}();e.Monad=r}),define("src/lib/maybe.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Maybe: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/maybe",["require","exports","src/lib/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/either.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Either: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/either",["require","exports","src/lib/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/export",["require","exports","src/stream/transform","src/lib/message","src/lib/proxy","src/lib/proxy","src/lib/supervisor","src/lib/observable","src/lib/map","src/lib/set","src/lib/tick","src/lib/timer","src/lib/fingerprint","src/lib/uuid","src/lib/maybe","src/lib/either","./typings/arch-stream.d"],function(t,e,r,i,n,o,s,u,c,a,h,p,f,d,l,v){"use strict";function _(){return new r.ArchStream}function y(){return new i.Message}e.Proxy=o.Proxy,e.Supervisor=s.Supervisor,e.Observable=u.Observable,e.Map=c.Map,e.MultiMap=c.Map,e.Set=a.Set,e.MultiSet=a.Set,e.Tick=h.Tick,e.Timer=p.Timer,e.FINGERPRINT=f.FINGERPRINT,e.uuid=d.v4,e.Maybe=l.Maybe,e.Just=l.Just,e.Nothing=l.Nothing,e.Either=v.Either,e.Left=v.Left,e.Right=v.Right;var m={Msg:y,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=_;var _;!function(t){t.Msg=m.Msg,t.Proxy=m.Proxy}(_||(_={})),e.Msg=y}),define("arch-stream",["require","exports","src/export","src/export"],function(t,e,r,i){"use strict";function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}n(r),e["default"]=i["default"]}); | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="arch-stream",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?window[i]=window[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||window[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)if(s)for(;2>o;)void Promise.resolve().then(r),void++o;else for(;o<u.length;)void setTimeout(r,u[o%u.length]),void++o}t.queue=e;var n=[],o=0,s="function"==typeof Promise,u=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/message",["require","exports","src/lib/thenable","src/lib/tick"],function(t,e,r,i){"use strict";function n(t){return t}var o=Object.create(null),s=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=o,this.collection_=[],this.transform_=!1,this.listeners_=[],t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){if(this.collection_.length>0)return this.collection_;var t=this,e=[];do void e.push(t);while(t=t.child_);return this.collection_=e},t.prototype.transport_=function(t,e){function i(t,i,u){function c(t){o=!0,i=u?t:i,s&&n.child_&&void n.child_.send(i,e)}return t.every(function(t){n=t,n.memory_=i;var e=n.listener(n.memory_);return r.isThenable(e)?(o=!1,void e.then(c,c),o):(i=u?e:i,!0)})}var n,o=!1,s=!1,u=i(this.collect_(),t,this.transform_);s=!0,u&&"function"==typeof e&&void e(t)},t.prototype.clone=function(){function e(r){return r.parent?new t(e(r.parent),r.listener):new t(void 0,r.listener)}return e(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e,r){var n=this;switch(!0){case"function"==typeof e:return this.send(t,!1,e);case e===!0:return void i.Tick(function(){return n.transport_(t,r)}),this;case e===!1:default:return void this.transport_(t,r),this}},t.prototype.recv=function(e){var r=new t(this);return this.listener=e,this.collection_=[],this.memory_!==o&&void this.send(this.memory_),r},t.prototype.trans=function(t){return this.transform_=!0,this.recv(t)},t.prototype.then=function(e,r){var i=this,o=new t;return this.child_=void 0,this.listener=n,this.listeners_.push(o),this.trans(function(t){var e=i.listeners_;i.listeners_=[],function r(){try{for(;e.length>0;)e.shift().send(t)}catch(i){void console.error(i),void r()}}()}),o.trans(e||n)},t}();e.Message=s}),define("src/lib/throttle",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return void this.processing_.push(t),void this.resolver_(t),!0;this.queue_.push(t);do void this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?void this.processing_.splice(e,1):void this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&void this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/stream/modular",["require","exports","src/lib/throttle","src/lib/tick","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,this.read=this.read.bind(this),this.write=this.write.bind(this),void i.Tick(function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}void this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){void--this.count,this.count<0&&void this.throwCountExceededError(),void this.compose_(),void this.last_.recv(t)},t.prototype.read=function(t){var e=this;void 0===t&&(t=n.noop);var r=!1;return void this.read_(function(n){e.flow_&&void i.Tick(function(){return void e.flow_.dequeue(n)}),r&&void t(n)}),r=!0,this},t.prototype.write_=function(t,e){void this.first_.send(t,e)},t.prototype.write=function(t,e){return this.flow_?void this.flow_.enqueue(t):void this.write_(t,e),this},t.prototype.flow=function(t,e,i){var n=this;return void 0===e&&(e=1/0),this.flow_=new r["default"],void this.flow_.flow(t,e,i),void this.flow_.register(function(t){return n.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();e.ModularStream=o}),define("src/stream/compose",["require","exports","src/stream/modular"],function(t,e,r){"use strict";var i=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){var e=this.procs_.length;return void t.reduceRight(function(t,r,i){return t[i+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var i=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return i.extract_(t)instanceof r?e(t):0})),void--e.count,e.count<0&&void e.throwCountExceededError(),void this.register(e.procs),this},t.prototype["export"]=function(t){return new r.ModularStream(this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(void--t.count,void this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(void--t.count,void this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();e.ComposeStream=i}),define("src/stream/transform",["require","exports","src/lib/message","src/stream/compose","src/stream/modular"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e){var i=this;void 0===e&&(e=new r.Message),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return i.proxy(function(){return e})},void 0)}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof n.ModularStream?(new i.ComposeStream)["import"](t,e):new i.ComposeStream(t)},t.prototype["export"]=function(t){return(new i.ComposeStream).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,i,n){function o(t){return Array.isArray(t)?t:[t]}var s=e.proxies_.filter(function(t){return"function"==typeof t[i]}).reduce(function(t,e){return o(e[i].apply(void 0,t)||t)},n),u="pipe";switch(i){case u:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[i]).call.apply(c,[r(e,u,s)].concat(n));default:return r(e,u,s)}var c}var i=this,n="function"==typeof e?e():e;return this.proxies_.push(n),void Object.keys(n).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof n[t]}).reduce(function(t,e){return i[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];return r(i,e,t)}},void 0),this},t}();e.ArchStream=o}),define("src/proxy/case",["require","exports"],function(t,e){"use strict";function r(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var n=+i[e(r)+""];n>-1&&n<t.length&&t[n](r)}}var i=Object.create(null);return void t.reduce(function(t,e,r){return i[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/proxy/hook",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),s(e)}})}var i=t.pre,n=void 0===i?r.noop:i,o=t.post,s=void 0===o?r.noop:o;return function(t){return{pipe:e}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/proxy/responsibility",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(){function t(t,i){return e.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r-0]=arguments[r];return e.map(function(e){return function(r){if(!(i(r)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity.\n "+i(r).constructor);e(r)}})},e["export"]=function(){return function(e){i(e)instanceof t&&void Object.freeze(i(e))}},r.noop}var e;return function(r){return e={rule:t}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/lib/proxy",["require","exports","src/proxy/case","src/proxy/hook","src/proxy/responsibility"],function(t,e,r,i,n){"use strict";e.Proxy={Case:r["default"],Hook:i["default"],Responsibility:n["default"]}}),define("src/lib/map",["require","exports"],function(t,e){"use strict";function r(t,e){return e?0===t.length?"":"_"+t.join(n):t+""}function i(t,e,r){return void 0===r&&(r=""),e?""===t?[]:t.slice(1).split(n).map(function(t){return"number"===r?+t:t}):"number"===r?+t:t}var n="<\x00��>",o=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[r(t,this.multiKey_)]},t.prototype.set=function(t,e){return void 0===this.multiKey_&&(this.multiKey_=Array.isArray(t)),this.type_||(this.multiKey_?t.length>0&&(this.type_=typeof t[0]):this.type_=typeof t),void this.reset_(),this.map_[r(t,this.multiKey_)]=e},t.prototype.has=function(t){return!!this.map_[r(t,this.multiKey_)]||r(t,this.multiKey_)in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[r(t,this.multiKey_)],this},t.prototype.clear=function(){return void this.reset_(),this.map_=Object.create(null),this},t.prototype.reset_=function(){this.size_=NaN,this.entries_=void 0},Object.defineProperty(t.prototype,"size",{get:function(){return this.size_>=0?this.size_:this.size_=Object.keys(this.map_).length},enumerable:!0,configurable:!0}),t.prototype.entries=function(){var t=this;return this.entries_?this.entries_:this.entries_=Object.keys(this.map_).map(function(e){return[i(e,t.multiKey_,t.type_),t.get(i(e,t.multiKey_,t.type_))]})},t}();e.Map=o}),define("src/lib/observable",["require","exports","src/lib/map","src/lib/noop"],function(t,e,r,i){"use strict";var n=function(){function t(t){void 0===t&&(t="."),this.separator_=t,this.emitId_=0,this.emitQueue_=[],this.refsOverCache_=new r.Map,this.refsUnderCache_=new r.Map,this.node_={parent:void 0,children:Object.create(null),list:[]}}return t.prototype.formatEventType_=function(t){if(t instanceof Object){if(Array.isArray(t))return t.slice();var e=t;return e.namespace?this.formatEventType_(e.namespace).concat(e.type):[e.type]}return this.separator_&&t?(t+"").split(this.separator_):[t+""]},t.prototype.monitor=function(t,e,r){void 0===r&&(r=e);var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(i).list.push([i,e,r,this.emitId_,!0]),this},t.prototype.on=function(t,e,r){void 0===r&&(r=e);var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(i).list.push([i,e,r,this.emitId_,!1]),void this.drain_(i),this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seek_(r).list.some(function(t,r,i){var n=t[2];if(e!==n)return!1;switch(r){case 0:return!void i.shift();case i.length-1:return!void i.pop();default:return!void i.splice(r,1)}}),this;case"undefined":var i=this.seek_(r);return i.children=Object.create(null),i.list=[],void this.refsOverCache_.clear(),void this.refsUnderCache_.clear(),this;default:throw this.throwTypeErrorIfInvalidSubscriber_(e,r)}},t.prototype.once=function(t,e){var r=this;return void this.throwTypeErrorIfInvalidSubscriber_(e,this.formatEventType_(t)),this.on(t,function(i){return void r.off(t,e),e(i)},e)},t.prototype.emit=function(t,e,r){return t instanceof Object&&!Array.isArray(t)?this.emit_(this.formatEventType_(t),t,e):this.emit_(this.formatEventType_(t),e,r)},t.prototype.emit_=function(t,e,r){return void 0===r&&(r=i.noop),void this.emitQueue_.push([++this.emitId_,e,r]),void this.drain_(t),this},t.prototype.reflect=function(t,e){var r;return t instanceof Object&&!Array.isArray(t)?void this.emit(this.formatEventType_(t),t,function(t,e){return r=e}):void this.emit(this.formatEventType_(t),e,function(t,e){return r=e}),r},t.prototype.drain_=function(t){for(var e=this.emitQueue_,r=function(){var r=e.shift(),n=[];try{void i.refs_(t).reduce(function(t,e){var r=t[0],i=t[1],o=e[1],s=e[3],u=e[4];return u||s>=r?t:(e[3]=r,void n.push(o(i)),t)},r),void i.refs_(t,!0).reduce(function(t,e){var r=t[0],i=t[1],n=e[1],o=e[3],s=e[4];return!s||o>=r?t:(e[3]=r,void n(i),t)},r)}catch(o){return void e.unshift(r),void 0!==o&&null!==o&&void console.error(o),"continue"}var s=r[1],u=r[2];void u(s,n)},i=this;e.length>0;){r()}return void this.resetEmitIdIfPossible_(),this},t.prototype.resetEmitIdIfPossible_=function(){this.emitId_<5e8||this.emitQueue_.length>0||void this.refs_([]).reduce(function(t,e){return e[3]=t},this.emitId_=0)},t.prototype.refs=function(t){return this.refs_(this.formatEventType_(t)).map(function(t){return[t[0],t[2],t[4]]})},t.prototype.refs_=function(t,e){function r(t){var e=t.parent,i=t.list;return e?i.concat(r(e)):i}function i(t){var e=t.children,r=t.list;return Object.keys(e).sort().reduce(function(t,r){return void t.push.apply(t,i(e[r])),0===t.length&&delete e[r],t},r.slice())}return void 0===e&&(e=!1),e?this.refsOverCache_.get(t)||this.refsOverCache_.set(t,r(this.seek_(t,!0))):this.refsUnderCache_.get(t)||this.refsUnderCache_.set(t,i(this.seek_(t,!0)))},t.prototype.seek_=function(t,e){function r(t,e){var r=t.children;return r[e+""]?r[e+""]:r[e+""]={parent:t,children:Object.create(null),list:[]}}var i=this;return void 0===e&&(e=!1),e||void[void 0].concat(t).reduce(function(t,e,r,n){void i.refsOverCache_["delete"](n.slice(1,r+1)),void i.refsUnderCache_["delete"](n.slice(1,r+1))},void 0),t.reduce(r,this.node_)},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("ArchStream: Observable: Invalid subscriber.\n "+t)}},t}();e.Observable=n}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/thenable","src/lib/tick","src/lib/noop"],function(t,e,r,i,n,o){"use strict";var s=function(){function t(){}return t}(),u=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(s),c=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(s),a=0,h=0,p=function(){function t(t,e){void 0===t&&(t="anonymous"),void 0===e&&(e=o.noop),this.name=t,this.destructor=e,this.monitor=new r.Observable,this.events={exec:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.children=new r.Observable,this.state=!0,this.queue=[],void++a}return Object.defineProperty(t,"count",{get:function(){return a},enumerable:!0,configurable:!0}),Object.defineProperty(t,"procs",{get:function(){return h},enumerable:!0,configurable:!0}),t.prototype.register=function(t,e,r){var i=this;void 0===r&&(r=0),void this.checkState(),t=t.slice();var o=new f(this,t,e,r);return void++h,void this.children.on(t,o.receive),void this.events.exec.emit(t,[t,e]),void this.monitor.emit("exec",[t,e,void 0]),void n.Tick(function(t){return i.drain()}),o.terminate},t.prototype.call=function(t,e,r,i){var s=this;return void 0===r&&(r=0),void 0===i&&(i=o.noop),void this.checkState(),t=t.slice(),void this.queue.push([t,e,i,r,Date.now()]),void n.Tick(function(t){return s.drain()}),r>0&&void setTimeout(function(){return s.drain(t)},r+9),this},t.prototype.cast=function(t,e,r){void 0===r&&(r=o.noop),void this.checkState();var i=this.children.reflect(t,new u(e));return void r(e,i),this},t.prototype.refs=function(t){return void this.checkState(),this.children.refs(t).map(function(t){var e=t[0],r=t[1];return[e,r(void 0).process,r(void 0).terminate]})},t.prototype.terminate=function(t,e){if(void this.checkState(),void this.children.emit(t||[],new c(e)).off(t||[]),!t){for(this.state=!1;this.queue.length>0;){var r=this.queue.shift(),i=r[0],n=r[1];void this.loss(i,n)}try{void this.destructor(e)}catch(o){void console.error(o)}void--a}},t.prototype.checkState=function(){if(!this.state)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){void 0===t&&(t=[]);for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],a=o[2],h=o[3],p=o[4],f=t.every(function(t,e){return t===s[e]})?n.children.reflect(s,new u(c)):[];return 0===f.length&&p+h>r?(e=i,"continue"):(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===f.length&&void n.loss(s,c),void a(c,f),void(e=i))},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t.prototype.loss=function(t,e){var r=[this.events.loss.reflect(t,[t,void 0,e]).length,this.monitor.reflect("loss",[t,void 0,e]).length].reduce(function(t,e){return t+e},0);r>0||void console.error("Supervisor "+this.name,"loss",t,e)},t}();e.Supervisor=p;var f=function(){function t(t,e,r,i){var n=this;this.parent=t,this.namespace=e,this.process=r,this.parallel=i,this.state=!0;var o=this.receive;this.receive=function(t){return o.call(n,t)};var s=this.terminate;this.terminate=function(t){return s.call(n,t)}}return t.prototype.receive=function(t){var e=this;if(!this.state)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.");if(void 0===t)return this;if(t instanceof u){if(this.parallel<0)throw void 0;try{var r=this.process(t.data);return i.isThenable(r)&&(void--this.parallel,void r.then(function(t){return void++e.parallel},function(t){return e.terminate(t)})),r}catch(n){throw void void this.terminate(n)}}if(t instanceof c)throw void void this.terminate(t.reason);throw new TypeError("ArchStream: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){if(!this.state)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" cannot terminate multiply with "+t+".");void--h,this.state=!1,void this.parent.children.off(this.namespace,this.receive),void this.parent.events.exit.emit(this.namespace,[this.namespace,this.process,t]),void this.parent.monitor.emit("exit",[this.namespace,this.process,t])},t}()}),define("src/lib/set",["require","exports","src/lib/map"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this),this.replacer_=e}return __extends(e,t),e.prototype.set=function(e,r){if(!this.has(e))return t.prototype.set.call(this,e,r);if(!this.replacer_)throw new Error("Cannot overwrite value of set without replacer.");return t.prototype.set.call(this,e,this.replacer_(this.get(e),r))},e}(r.Map);e.Set=i}),define("src/lib/timer",["require","exports"],function(t,e){"use strict";function r(t){var e=t.begin,i=void 0===e?0:e,n=t.end,o=void 0===n?864e5:n,s=t.step,u=void 0===s?function(t){return 3*(t||1)}:s,c=t.precond,a=void 0===c?function(){return!0}:c,h=t.task,p=void 0===h?function(){}:h,f=t.postcond,d=void 0===f?function(){return!0}:f,l=t.complete,v=void 0===l?function(){return 0}:l,_=t.error,y=void 0===_?function(){return 0}:_,m=t.timeout,b=void 0===m?function(){return 0}:m,w=t.since,x=void 0===w?Date.now():w;i=0>i?0:i,void setTimeout(function(){try{if(a()){var t=p();if(d())return void v(t)}}catch(e){return void y(e)}var n=Date.now(),s=u(n-x);return 0>=o-(n-x)?void b():void void r({precond:a,task:p,postcond:d,complete:v,timeout:b,begin:i+s,end:o,step:u,since:x})},i)}e.Timer=r}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("ArchStream: uuid: Invalid uuid dynamic seed.");return o.map(function(e){if("x"!==e&&"y"!==e)return e;var r=Math.random()*t%16|0,i="x"==e?r:3&r|8;return i.toString(16)}).join("").toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("ArchStream: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split(""),s=n;e.v4=i}),define("src/lib/monad",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.extract=function(t){return this.evaluate().extract(t)},t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t.prototype.assert=function(t){return this},t}();e.Monad=r}),define("src/lib/maybe.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Maybe: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/maybe",["require","exports","src/lib/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/either.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Either: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/either",["require","exports","src/lib/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/export",["require","exports","src/stream/transform","src/lib/message","src/lib/proxy","src/lib/proxy","src/lib/supervisor","src/lib/observable","src/lib/map","src/lib/set","src/lib/tick","src/lib/timer","src/lib/fingerprint","src/lib/uuid","src/lib/maybe","src/lib/either","./typings/arch-stream.d"],function(t,e,r,i,n,o,s,u,c,a,h,p,f,d,l,v){"use strict";function _(){return new r.ArchStream}function y(){return new i.Message}e.Proxy=o.Proxy,e.Supervisor=s.Supervisor,e.Observable=u.Observable,e.Map=c.Map,e.MultiMap=c.Map,e.Set=a.Set,e.MultiSet=a.Set,e.Tick=h.Tick,e.Timer=p.Timer,e.FINGERPRINT=f.FINGERPRINT,e.uuid=d.v4,e.Maybe=l.Maybe,e.Just=l.Just,e.Nothing=l.Nothing,e.Either=v.Either,e.Left=v.Left,e.Right=v.Right;var m={Msg:y,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=_;var _;!function(t){t.Msg=m.Msg,t.Proxy=m.Proxy}(_||(_={})),e.Msg=y}),define("arch-stream",["require","exports","src/export","src/export"],function(t,e,r,i){"use strict";function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}n(r),e["default"]=i["default"]}); |
@@ -341,2 +341,11 @@ # Note | ||
スーパーバイザはコンポーネントの管理に適しているが、コンポーネントの実装には向かない。 | ||
スーパーバイザは把握困難な無数の状態と不測の事態をクラッシュを制御下に収めることで制御可能にしようとするアプローチだが、 | ||
もともと少数の状態しか持たないか状態が無く例外に頼らず実装すべき機能やモジュールをスーパーバイザのエラー耐性に甘えて実装すると | ||
状態管理を放棄したバグありきの劣悪な実装になる。 | ||
よって個々の機能やモジュールはシーケンスを完全に制御する従来どおりの方法で実装し、 | ||
状態や経路が無数に生じる制御困難な問題に対してのみスーパーバイザで制御を試みることが望ましい。 | ||
設計および実装はスーパーバイザの使用の有無にかかわらず状態を収束させる方向に進まなければならない。 | ||
スーパーバイザの使用は状態を使用前より収束させるものでなければならず、発散させてはならない。 | ||
### Observable | ||
@@ -343,0 +352,0 @@ |
{ | ||
"name": "arch-stream", | ||
"version": "0.0.70", | ||
"version": "0.0.71", | ||
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -5,3 +5,3 @@ export abstract class Monad<T> { | ||
} | ||
public abstract bind<U>(f: (val: T) => U): U; | ||
public abstract bind<U>(f: (val: T) => Monad<U>): Monad<U>; | ||
public extract(): T | ||
@@ -8,0 +8,0 @@ public extract<U>(transform: (val: any) => U): T | U |
@@ -21,3 +21,3 @@ import {Observable} from './observable'; | ||
ob.on([], id); | ||
ob.observe([], id); | ||
ob.monitor([], id); | ||
assert.deepEqual(ob.refs([]), [ | ||
@@ -29,3 +29,3 @@ [[], id, false], | ||
ob.once([''], id); | ||
ob.observe([''], id); | ||
ob.monitor([''], id); | ||
assert.deepEqual(ob.refs([]), [ | ||
@@ -65,3 +65,3 @@ [[], id, false], | ||
ob.observe([], id); | ||
ob.monitor([], id); | ||
assert(ob.refs([]).length === 1); | ||
@@ -72,3 +72,3 @@ | ||
ob.observe([''], id); | ||
ob.monitor([''], id); | ||
ob.on([''], id); | ||
@@ -78,3 +78,3 @@ assert(ob.refs([]).length === 4); | ||
ob.observe(['', ''], id); | ||
ob.monitor(['', ''], id); | ||
ob.on(['', ''], id); | ||
@@ -148,4 +148,4 @@ assert(ob.refs([]).length === 6); | ||
new Observable<string, number, void>() | ||
.observe('test', data => assert(data === 0 && ++cnt === 1)) | ||
.observe('test', data => assert(data === 0 && ++cnt === 2)) | ||
.monitor('test', data => assert(data === 0 && ++cnt === 1)) | ||
.monitor('test', data => assert(data === 0 && ++cnt === 2)) | ||
.emit('test', 0, data => assert(data === 0 && ++cnt === 3) || done()); | ||
@@ -165,8 +165,8 @@ }); | ||
new Observable<string, number, void>() | ||
.observe('test', data => assert(data === 0 && ++cnt === 3)) | ||
.monitor('test', data => assert(data === 0 && ++cnt === 3)) | ||
.on('test', data => assert(data === 0 && ++cnt === 1)) | ||
.observe('test', throwError) | ||
.monitor('test', throwError) | ||
.on('test', throwError) | ||
.on('test', data => assert(data === 0 && ++cnt === 2)) | ||
.observe('test', data => assert(data === 0 && ++cnt === 4) || done()) | ||
.monitor('test', data => assert(data === 0 && ++cnt === 4) || done()) | ||
.off('test', throwError) | ||
@@ -181,3 +181,3 @@ .off('test', throwError) | ||
.on('test', throwError) | ||
.observe('test', throwError) | ||
.monitor('test', throwError) | ||
.on('test', throwError) | ||
@@ -232,8 +232,8 @@ .off('test') | ||
new Observable<string, number, void>('.') | ||
.observe('test', data => assert(data === 0 && ++cnt === 5) || Tick(done)) | ||
.monitor('test', data => assert(data === 0 && ++cnt === 5) || Tick(done)) | ||
.on('test', throwError) | ||
.observe('test.0', data => assert(data === 0 && ++cnt === 4)) | ||
.monitor('test.0', data => assert(data === 0 && ++cnt === 4)) | ||
.on('test.0', throwError) | ||
.on('test.0', data => assert(data === 0 && ++cnt === 1)) | ||
.observe('test.0.0', data => assert(data === 0 && ++cnt === 0)) | ||
.monitor('test.0.0', data => assert(data === 0 && ++cnt === 0)) | ||
.on('test.0.0', data => assert(data === 0 && ++cnt === 2)) | ||
@@ -266,3 +266,3 @@ .on('test.0.0.0', data => assert(data === 0 && ++cnt === 3)) | ||
}) | ||
.observe([], ({dom}) => { | ||
.monitor([], ({dom}) => { | ||
document.body.appendChild(dom); | ||
@@ -269,0 +269,0 @@ }); |
@@ -46,3 +46,3 @@ import {IObservableObserver, IObservableSubscriber, IObservablePublisher} from 'arch-stream'; | ||
} | ||
public observe(type: T | T[], subscriber: Subscriber<D, R>, identifier: Subscriber<D, R> = subscriber): this { | ||
public monitor(type: T | T[], subscriber: Subscriber<D, R>, identifier: Subscriber<D, R> = subscriber): this { | ||
const types = this.formatEventType_(type); | ||
@@ -136,4 +136,4 @@ void this.throwTypeErrorIfInvalidSubscriber_(subscriber, types); | ||
const [emitId, data] = pub; | ||
const [, subscriber, , emittedId, observing] = sub; | ||
if (observing || emitId <= emittedId) return pub; | ||
const [, subscriber, , emittedId, monitor] = sub; | ||
if (monitor || emitId <= emittedId) return pub; | ||
sub[3] = emitId; | ||
@@ -146,4 +146,4 @@ void results.push(subscriber(data)); | ||
const [emitId, data] = pub; | ||
const [, subscriber, , emittedId, observing] = sub; | ||
if (!observing || emitId <= emittedId) return pub; | ||
const [, subscriber, , emittedId, monitor] = sub; | ||
if (!monitor || emitId <= emittedId) return pub; | ||
sub[3] = emitId; | ||
@@ -150,0 +150,0 @@ void subscriber(data); |
@@ -153,3 +153,2 @@ import {Supervisor} from './supervisor'; | ||
const sv = new Supervisor<string, number, number>(); | ||
sv.register([], _ => 0); | ||
sv.terminate(); | ||
@@ -219,3 +218,3 @@ try { | ||
sv.events.exit | ||
.observe(['title'], ((last: number = 0) => | ||
.monitor(['title'], ((last: number = 0) => | ||
([namespace, process, reason]: Supervisor.Event.Data.Exit<string, ComponentState, any>) => { | ||
@@ -222,0 +221,0 @@ if (reason) { |
@@ -100,3 +100,4 @@ import {Supervisor as ISupervisor} from 'arch-stream'; | ||
void this.children | ||
.emit(namespace || [], new WorkerCommand_$Exit(reason)); | ||
.emit(namespace || [], new WorkerCommand_$Exit(reason)) | ||
.off(namespace || []); | ||
if (namespace) return; | ||
@@ -103,0 +104,0 @@ this.state = false; |
@@ -12,3 +12,3 @@ export default class Throttle<T> { | ||
} | ||
public flow(volume: number, limit: number = Infinity, discharger: (queue: T[], processing: T[]) => any = () => null): void { | ||
public flow(volume: number, limit: number = Infinity, discharger: (queue: T[], processing: T[]) => any = () => void 0): void { | ||
this.volume_ = volume; | ||
@@ -15,0 +15,0 @@ this.limit_ = limit; |
@@ -23,5 +23,3 @@ /** | ||
} | ||
export interface ICallback<T> { | ||
(entity: T): PromiseLike<T> | any; | ||
} | ||
export type ICallback<T> = (entity: T) => PromiseLike<T> | any; | ||
export const Proxy: { | ||
@@ -122,3 +120,3 @@ Case<T, U extends number | string>(index: U[], indexer: (entity: T) => U): <U>(shadow?: ITransformStream<T, U>) => CaseProxy<T, U>; | ||
constructor(separator?: string) | ||
observe(type: T | T[], subscriber: Subscriber<D, R>): this; | ||
monitor(type: T | T[], subscriber: Subscriber<D, R>): this; | ||
on(type: T | T[], subscriber: Subscriber<D, R>): this; | ||
@@ -138,3 +136,3 @@ off(type: T | T[], subscriber?: Subscriber<D, R>): this; | ||
export interface IObservableObserver<T extends string | number, D, R> extends IObservableSubscriber<T, D, R> { | ||
observe(type: T | T[], subscriber: Subscriber<D, R>): this; | ||
monitor(type: T | T[], subscriber: Subscriber<D, R>): this; | ||
refs(type: T | T[]): [T[], Subscriber<D, R>, boolean][]; | ||
@@ -219,3 +217,3 @@ } | ||
private MONAD: T; | ||
abstract bind<U>(f: (val: T) => U): U; | ||
abstract bind<U>(f: (val: T) => Monad<U>): Monad<U>; | ||
extract(): T; | ||
@@ -222,0 +220,0 @@ extract<U>(transform: () => U): T | U; |
261548
6102