New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

arch-stream

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arch-stream - npm Package Compare versions

Comparing version 0.0.76 to 0.0.77

src/lib/assign.test.ts

4

dist/arch-stream.min.js

@@ -1,3 +0,3 @@

/*! arch-stream v0.0.76 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! arch-stream v0.0.77 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)for(;o<s.length;)void setTimeout(r,s[o%s.length]),void++o}t.queue=e;var n=[],o=0,s=[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,c){function u(t){o=!0,i=c?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(u,u),o):(i=c?e:i,!0)})}var n,o=!1,s=!1,c=i(this.collect_(),t,this.transform_);s=!0,c&&"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,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),c="pipe";switch(i){case c:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(u=t.prototype[i]).call.apply(u,[r(e,c,s)].concat(n));default:return r(e,c,s)}var u}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/observable",["require","exports"],function(t,e){"use strict";function r(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0}var i=1e3,n=function(){function t(t){void 0===t&&(t=""),this.separator_=t,this.mayHasMonitor_=!1,this.mayHasSubscriber_=!1,this.refsAboveCache_=[],this.refsBelowCache_=[],this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]},this.nodeCache_=[],this.useCache_=!0,this.cacheBreak_=[0,Date.now()]}return t.prototype.formatEventType_=function(t){if(t&&"object"==typeof t){if(t.map===[].map){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e}var i=t;return i.namespace?this.formatEventType_(i.namespace).concat(i.type):[i.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.seekNode_(i).registers.push([i,r,!0,e]),this.mayHasMonitor_=!0,void this.rebuildCache_(i),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.seekNode_(i).registers.push([i,r,!1,function(t){return e(t)}]),this.mayHasSubscriber_=!0,void this.rebuildCache_(i),this},t.prototype.off=function(t,e){void++this.cacheBreak_[0];var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seekNode_(r).registers.some(function(t,r,i){var n=t[1];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)}}),void this.rebuildCache_(r),this;case"undefined":var i=this.seekNode_(r);return i.childrenMap=Object.create(null),i.childrenList=[],i.registers=[],this.refsBelowCache_=[],void this.rebuildCache_(r),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&&"object"==typeof t&&t.map!==[].map?this.drain_(this.formatEventType_(t),t,e):this.drain_(this.formatEventType_(t),e,r)},t.prototype.reflect=function(t,e){var r;return t&&"object"==typeof t&&t.map!==[].map?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,e,r){var i=this,n=[];if(this.mayHasSubscriber_&&(this.mayHasSubscriber_=!1,void this.refs_(t,this.refsBelowCache_).reduce(function(t,o){i.mayHasSubscriber_=!0;var s=o[2],c=o[3];if(!s)try{var u=c(e);r&&(n[n.length]=u)}catch(h){void 0!==h&&null!==h&&void console.error(h,h+"")}},void 0)),this.mayHasMonitor_&&(this.mayHasMonitor_=!1,void this.refs_(t,this.refsAboveCache_).reduce(function(t,r){i.mayHasMonitor_=!0;var n=r[2],o=r[3];if(n)try{void o(e)}catch(s){void 0!==s&&null!==s&&void console.error(s,s+"")}},void 0)),r)try{void r(e,n)}catch(o){void console.error(o,o+"")}return this},t.prototype.refs=function(t){return this.refs_(this.formatEventType_(t),this.refsBelowCache_)},t.prototype.refs_=function(t,e){return this.isCacheActive()?this.refsCached_(t,e):e===this.refsAboveCache_?this.refsAbove_(this.seekNode_(t)):this.refsBelow_(this.seekNode_(t))},t.prototype.refsCached_=function(t,e){for(var n=0;n<e.length;++n)if(r(e[n][0],t))return e[n][1];return void e.unshift([t,e===this.refsAboveCache_?this.refsAbove_(this.seekNode_(t)):this.refsBelow_(this.seekNode_(t))]),e.length>i&&void e.pop(),e[0][1]},t.prototype.refsAbove_=function(t){var e=t.parent,r=t.registers;for(r=r.slice();e;)void r.push.apply(r,e.registers),e=e.parent;return r},t.prototype.refsBelow_=function(t){var e=t.childrenList,r=t.childrenMap,i=t.registers;i=i.slice();for(var n=0;n<e.length;++n){var o=e[n],s=this.refsBelow_(r[o]);void i.push.apply(i,s),0===s.length&&(delete r[o],void e.splice(e.indexOf(o),1),void--n)}return i},t.prototype.seekNode_=function(t){if(this.isCacheActive())return this.seekNodeCached_(t);for(var e=this.node_,r=0;r<t.length;++r){var i=e.childrenMap,n=t[r];i[n+""]||(void e.childrenList.push(n+""),e.childrenList=e.childrenList.sort(),i[n+""]={parent:e,childrenMap:Object.create(null),childrenList:[],registers:[]}),e=i[n+""]}return e},t.prototype.seekNodeCached_=function(t){for(var e=this.nodeCache_,n=0;n<e.length;++n)if(r(e[n][0],t))return e[n][1];return this.useCache_=!1,void e.unshift([t,this.seekNode_(t)]),this.useCache_=!0,e.length>i&&void e.pop(),e[0][1]},t.prototype.isCacheActive=function(){return this.useCache_?(void this.adjustCacheSettings_(),this.cacheBreak_[0]<9):!1},t.prototype.adjustCacheSettings_=function(){var t=this,e=this.cacheBreak_,r=e[0],i=e[1];if(!(9>r)){var n=Date.now();9>n-i?(void this.clearCache_(),this.useCache_=!1,void setTimeout(function(){return void t.adjustCacheSettings_()},1e3)):(this.useCache_=!0,this.cacheBreak_=[0,n])}},t.prototype.rebuildCache_=function(t){this.useCache_&&(this.nodeCache_=this.nodeCache_.filter(function(e){var r=e[0];return r.length<t.length}),this.refsAboveCache_=this.refsAboveCache_.filter(function(e){var r=e[0];return r.length<t.length}),this.refsBelowCache_=this.refsBelowCache_.filter(function(e){var r=e[0];return r.length>t.length}))},t.prototype.clearCache_=function(){this.useCache_&&(this.nodeCache_=[],this.refsAboveCache_=[],this.refsBelowCache_=[])},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/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/map",["require","exports","src/lib/uuid"],function(t,e,r){"use strict";function i(t,e){return e?0===t.length?"":"_"+t.join(o):t+""}function n(t,e,r){return void 0===r&&(r=""),e?""===t?[]:t.slice(1).split(o).map(function(t){return"number"===r?+t:t}):"number"===r?+t:t}var o=""+r.v4(),s=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[i(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_[i(t,this.multiKey_)]=e},t.prototype.has=function(t){return!!this.map_[i(t,this.multiKey_)]||i(t,this.multiKey_)in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[i(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[n(e,t.multiKey_,t.type_),t.get(n(e,t.multiKey_,t.type_))]})},t}();e.Map=s}),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/supervisor",["require","exports","src/lib/observable","src/lib/set","src/lib/tick","src/lib/thenable","src/lib/noop"],function(t,e,r,i,n,o,s){"use strict";function c(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0}var u=function(){function t(){}return t}(),h=function(t){function e(e){t.call(this),this.namespace=e}return __extends(e,t),e}(u),a=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(u),p=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(u),f=0,d=0,l=function(){function t(t){var e=this,n=void 0===t?{}:t,o=n.name,c=void 0===o?"anonymous":o,u=n.dependencies,h=void 0===u?[]:u,a=n.retry,p=void 0===a?!1:a,d=n.timeout,l=void 0===d?0:d,v=n.destructor,_=void 0===v?s.noop:v;this.deps=new i.Set,this.events={exec:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.procs=new r.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.queue=[],this.depsResolvedNamespaces=[],this.name=c,void h.reduce(function(t,r){var i=r[0],n=r[1];return void e.deps.set(i,n)},void 0),this.retry=p,this.timeout=l,this.destructor_=_,void++f}return Object.defineProperty(t,"count",{get:function(){return f},enumerable:!0,configurable:!0}),Object.defineProperty(t,"procs",{get:function(){return d},enumerable:!0,configurable:!0}),t.prototype.destructor=function(t){for(void this.checkState(),this.alive=!1;this.queue.length>0;){var e=this.queue.shift(),r=e[0],i=e[1];void this.events.loss.emit(r,[r,void 0,i])}try{void this.destructor_(t)}catch(n){void console.error(n,n+"")}void--f,void Object.freeze(this)},t.prototype.schedule=function(){var t=this;this.scheduled||(void n.Tick(function(e){t.alive&&(t.scheduled=!1,void t.drain())}),this.scheduled=!0)},t.prototype.register=function(t,e,r){if(void this.checkState(),!this.registerable)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return t=t.slice(),void this.schedule(),new v(this,this.procs,t,e,r,this.deps.get(t)||[]).terminate},t.prototype.call=function(t,e,r,i){var n=this;void 0===r&&(r=this.timeout),void this.checkState(),t=t.slice(),void this.queue.push([t,e,i,r,Date.now()]),void this.schedule(),r>0&&void setTimeout(function(){return n.drain(t)},r+9)},t.prototype.cast=function(t,e,r){void 0===r&&(r=this.retry);var i=this.procs.reflect(t,new a(e));return i.length>0||!r?i:this.cast(t,e,!1)},t.prototype.refs=function(t){return this.procs.refs(t).map(function(t){var e=(t[0],t[1]),r=e(void 0);return[r.namespace,r.process,r.terminate]})},t.prototype.terminate=function(t,e){void this.checkState(),void 0===t&&(this.registerable=!1),void this.procs.emit(t||[],new p(e)).off(t||[]),void 0===t&&void this.destructor(e)},t.prototype.checkState=function(){if(!this.alive)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){if(void 0===t&&(t=[]),this.alive)for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],u=o[2],h=o[3],p=o[4],f=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new a(c)):[];if(0===f.length&&p+h>r)return e=i,"continue";if(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===f.length&&void n.events.loss.emit(s,[s,void 0,c]),!u)return e=i,"continue";try{void u(c,f)}catch(d){void console.error(d,d+"")}e=i},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t}();e.Supervisor=l;var v=function(){function t(e,r,i,n,o,s){var c=this;this.sv=e,this.procs=r,this.namespace=i,this.process=n,this.parallel=o,this.dependencies=s,this.alive=!0,this.called=!1,this.receive=function(e){return t.prototype.receive.call(c,e)},this.terminate=function(e){return t.prototype.terminate.call(c,e)},void this.clearCache(),void++d,void this.procs.on(i,this.receive)}return t.prototype.destructor=function(t){void this.checkState(),void this.procs.off(this.namespace,this.receive),this.alive=!1,void--d,void this.clearCache(),void Object.freeze(this),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,t])},t.prototype.tryDependencyResolving=function(t){if(!this.receive(new h(this.namespace)))throw void(this.sv.depsResolvedNamespaces=[])},t.prototype.clearCache=function(){this.sv.depsResolvedNamespaces=[],this.sv.depsAllRefsCache=void 0},t.prototype.receive=function(t){var e=this;if(void this.checkState(),void 0===t)return this;if(t instanceof h){if(t.namespace.length!==this.namespace.length)return!1;for(var r=0,i=this.sv.depsResolvedNamespaces;r<i.length;++r)if(c(this.namespace,i[r]))return!0;return void this.sv.depsResolvedNamespaces.push(this.namespace),this.dependencies.every(function(t){return(e.sv.depsAllRefsCache=e.sv.depsAllRefsCache||e.procs.refs([])).some(function(e){var r=e[0],i=e[1];return c(r,t)&&!!i(new h(t))})})}if(t instanceof a){if(this.parallel<0)throw void 0;void this.tryDependencyResolving(t),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{var n=this.process(t.data);return o.isThenable(n)&&(void--this.parallel,void n.then(function(t){return e.alive?void++e.parallel:void 0},function(t){return e.alive&&e.terminate(t)})),n}catch(s){throw void void this.terminate(s)}}if(t instanceof p)throw void void this.terminate(t.reason);throw new TypeError("ArchStream: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){void this.destructor(t)},t.prototype.checkState=function(){if(!this.alive)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.")},t}()}),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,c=void 0===s?function(t){return 3*(t||1)}:s,u=t.precond,h=void 0===u?function(){return!0}:u,a=t.task,p=void 0===a?function(){}:a,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,g=void 0===w?Date.now():w;i=0>i?0:i,void setTimeout(function(){try{if(h()){var t=p();if(d())return void v(t)}}catch(e){return void y(e)}var n=Date.now(),s=c(n-g);return 0>=o-(n-g)?void b():void void r({precond:h,task:p,postcond:d,complete:v,timeout:b,begin:i+s,end:o,step:c,since:g})},i)}e.Timer=r}),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,c,u,h,a,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=c.Observable,e.Map=u.Map,e.MultiMap=u.Map,e.Set=h.Set,e.MultiSet=h.Set,e.Tick=a.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)for(;o<s.length;)void setTimeout(r,s[o%s.length]),void++o}t.queue=e;var n=[],o=0,s=[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,c){function u(t){o=!0,i=c?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(u,u),o):(i=c?e:i,!0)})}var n,o=!1,s=!1,c=i(this.collect_(),t,this.transform_);s=!0,c&&"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,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),c="pipe";switch(i){case c:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(u=t.prototype[i]).call.apply(u,[r(e,c,s)].concat(n));default:return r(e,c,s)}var u}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/concat",["require","exports"],function(t,e){"use strict";function r(t,e){for(var r=0,i=e.length,n=t.length;i>r;++r)t[r+n]=e[r];return t}e.concat=r}),define("src/lib/observable",["require","exports","src/lib/concat"],function(t,e,r){"use strict";var i=function(){function t(t){void 0===t&&(t=""),this.separator_=t,this.mayHasMonitor_=!1,this.mayHasSubscriber_=!1,this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return t.prototype.formatEventType_=function(t){if(t&&"object"==typeof t){if(t.map===[].map)return r.concat([],t);var e=t;return e.namespace?r.concat(this.formatEventType_(e.namespace),[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.seekNode_(i).registers.push([i,r,!0,e]),this.mayHasMonitor_=!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.seekNode_(i).registers.push([i,r,!1,function(t){return e(t)}]),this.mayHasSubscriber_=!0,this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seekNode_(r).registers.some(function(t,r,i){var n=t[1];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.seekNode_(r);return i.childrenMap=Object.create(null),i.childrenList=[],i.registers=[],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&&"object"==typeof t&&t.map!==[].map?this.drain_(this.formatEventType_(t),t,e):this.drain_(this.formatEventType_(t),e,r)},t.prototype.reflect=function(t,e){var r;return t&&"object"==typeof t&&t.map!==[].map?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,e,r){var i=this,n=[];if(this.mayHasSubscriber_&&(this.mayHasSubscriber_=!1,void this.refsBelow_(this.seekNode_(t)).reduce(function(t,o){i.mayHasSubscriber_=!0;var s=o[2],c=o[3];if(!s)try{var u=c(e);r&&(n[n.length]=u)}catch(a){void 0!==a&&null!==a&&void console.error(a,a+"")}},void 0)),this.mayHasMonitor_&&(this.mayHasMonitor_=!1,void this.refsAbove_(this.seekNode_(t)).reduce(function(t,r){i.mayHasMonitor_=!0;var n=r[2],o=r[3];if(n)try{void o(e)}catch(s){void 0!==s&&null!==s&&void console.error(s,s+"")}},void 0)),r)try{void r(e,n)}catch(o){void console.error(o,o+"")}return this},t.prototype.refs=function(t){return this.refsBelow_(this.seekNode_(this.formatEventType_(t)))},t.prototype.refsAbove_=function(t){var e=t.parent,i=t.registers;for(i=r.concat([],i);e;)void r.concat(i,e.registers),e=e.parent;return i},t.prototype.refsBelow_=function(t){var e=t.childrenList,i=t.childrenMap,n=t.registers;n=r.concat([],n);for(var o=0;o<e.length;++o){var s=e[o],c=this.refsBelow_(i[s]);void r.concat(n,c),0===c.length&&(delete i[s],void e.splice(e.indexOf(s),1),void--o)}return n},t.prototype.seekNode_=function(t){for(var e=this.node_,r=0,i=t;r<i.length;r++){var n=i[r],o=e.childrenMap;o[n+""]||(void e.childrenList.push(n+""),e.childrenList=e.childrenList.sort(),o[n+""]={parent:e,childrenMap:Object.create(null),childrenList:[],registers:[]}),e=o[n+""]}return e},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=i}),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/map",["require","exports","src/lib/uuid"],function(t,e,r){"use strict";function i(t,e){return e?0===t.length?"":"_"+t.join(o):t+""}function n(t,e,r){return void 0===r&&(r=""),e?""===t?[]:t.slice(1).split(o).map(function(t){return"number"===r?+t:t}):"number"===r?+t:t}var o=""+r.v4(),s=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[i(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_[i(t,this.multiKey_)]=e},t.prototype.has=function(t){return!!this.map_[i(t,this.multiKey_)]||i(t,this.multiKey_)in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[i(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[n(e,t.multiKey_,t.type_),t.get(n(e,t.multiKey_,t.type_))]})},t}();e.Map=s}),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/supervisor",["require","exports","src/lib/observable","src/lib/set","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(t,e,r,i,n,o,s,c){"use strict";function u(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0}var a=0,h=0,p=function(){function t(t){var e=this,n=void 0===t?{}:t,o=n.name,s=void 0===o?"anonymous":o,u=n.dependencies,h=void 0===u?[]:u,p=n.retry,f=void 0===p?!1:p,d=n.timeout,l=void 0===d?0:d,v=n.destructor,y=void 0===v?c.noop:v;this.deps=new i.Set,this.events={exec:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.procs=new r.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,resolvedDependencies:[]},this.queue=[],this.name=s,void h.reduce(function(t,r){var i=r[0],n=r[1];return void e.deps.set(i,n)},void 0),this.retry=f,this.timeout=l,this.destructor_=y,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.destructor=function(t){for(void this.checkState(),this.alive=!1;this.queue.length>0;){var e=this.queue.shift(),r=e[0],i=e[1];void this.events.loss.emit(r,[r,void 0,i])}try{void this.destructor_(t)}catch(n){void console.error(n,n+"")}void--a,void Object.freeze(this)},t.prototype.schedule=function(){var t=this;this.scheduled||(void n.Tick(function(e){t.alive&&(t.scheduled=!1,void t.drain())}),this.scheduled=!0)},t.prototype.register=function(t,e,r){if(void this.checkState(),!this.registerable)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return t=s.concat([],t),void this.schedule(),new y(this,this.workerSharedResource,t,e,r,this.deps.get(t)||[]).terminate},t.prototype.call=function(t,e,r,i){var n=this;void 0===r&&(r=this.timeout),void this.checkState(),t=s.concat([],t),void this.queue.push([t,e,i,r,Date.now()]),void this.schedule(),r>0&&void setTimeout(function(){return n.drain(t)},r+9)},t.prototype.cast=function(t,e,r){void 0===r&&(r=this.retry);var i=this.procs.reflect(t,new l(e));return i.length>0||!r?i:this.cast(t,e,!1)},t.prototype.refs=function(t){return this.procs.refs(t).map(function(t){var e=(t[0],t[1]),r=e(void 0);return[r.namespace,r.process,r.terminate]})},t.prototype.terminate=function(t,e){void this.checkState(),void 0===t&&(this.registerable=!1),void this.procs.emit(t||[],new v(e)).off(t||[]),void 0===t&&void this.destructor(e)},t.prototype.checkState=function(){if(!this.alive)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){if(void 0===t&&(t=[]),this.alive)for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],u=o[2],a=o[3],h=o[4],p=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new l(c)):[];if(0===p.length&&h+a>r)return e=i,"continue";if(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===p.length&&void n.events.loss.emit(s,[s,void 0,c]),!u)return e=i,"continue";try{void u(c,p)}catch(f){void console.error(f,f+"")}e=i},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t}();e.Supervisor=p;var f=function(){function t(){}return t}(),d=function(t){function e(e){t.call(this),this.namespace=e}return __extends(e,t),e}(f),l=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(f),v=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(f),y=function(){function t(e,r,i,n,o,s){var c=this;this.sv=e,this.sharedResource=r,this.namespace=i,this.process=n,this.parallel=o,this.dependencies=s,this.alive=!0,this.called=!1,this.receive=function(e){return t.prototype.receive.call(c,e)},this.terminate=function(e){return t.prototype.terminate.call(c,e)},this.sharedResource.allRefsCache=void 0,void++h,void this.sharedResource.procs.on(i,this.receive)}return t.prototype.destructor=function(t){void this.checkState(),void this.sharedResource.procs.off(this.namespace,this.receive),this.alive=!1,void--h,this.sharedResource.allRefsCache=void 0,this.sharedResource.resolvedDependencies=[],void Object.freeze(this),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,t])},t.prototype.tryDependencyResolving=function(t){if(!this.receive(new d(this.namespace)))throw void(this.sharedResource.resolvedDependencies=[])},t.prototype.receive=function(t){var e=this;if(void this.checkState(),void 0===t)return this;if(t instanceof d){if(t.namespace.length!==this.namespace.length)return!1;for(var r=0,i=this.sharedResource.resolvedDependencies;r<i.length;r++){var n=i[r];if(u(this.namespace,n))return!0}return void this.sharedResource.resolvedDependencies.push(this.namespace),this.dependencies.every(function(t){return(e.sharedResource.allRefsCache=e.sharedResource.allRefsCache||e.sharedResource.procs.refs([])).some(function(e){var r=e[0],i=e[1];return u(r,t)&&!!i(new d(t))})})}if(t instanceof l){if(this.parallel<0)throw void 0;void this.tryDependencyResolving(t),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{var s=this.process(t.data);return o.isThenable(s)&&(void--this.parallel,void s.then(function(t){return e.alive?void++e.parallel:void 0},function(t){return e.alive&&e.terminate(t)})),s}catch(c){throw void void this.terminate(c)}}if(t instanceof v)throw void void this.terminate(t.reason);throw new TypeError("ArchStream: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){void this.destructor(t)},t.prototype.checkState=function(){if(!this.alive)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.")},t}()}),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,c=void 0===s?function(t){return 3*(t||1)}:s,u=t.precond,a=void 0===u?function(){return!0}:u,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,y=t.error,m=void 0===y?function(){return 0}:y,_=t.timeout,b=void 0===_?function(){return 0}:_,w=t.since,g=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 m(e)}var n=Date.now(),s=c(n-g);return 0>=o-(n-g)?void b():void void r({precond:a,task:p,postcond:d,complete:v,timeout:b,begin:i+s,end:o,step:c,since:g})},i)}e.Timer=r}),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/lib/assign",["require","exports","src/lib/concat"],function(t,e,r){"use strict";function i(t,e){if(void 0===t||null===t)throw new TypeError("Cannot convert first argument to object");for(var o=Object(t),s=0;s<e.length;s++){var c=e[s];if(void 0!==c&&null!==c){c=Object(c);for(var u=0,a=Object.keys(Object(c));u<a.length;u++){var h=a[u],p=Object.getOwnPropertyDescriptor(c,h);if(void 0!==p&&p.enumerable){var f=c[h];switch(f&&typeof f){case"object":f.map===n?o[h]=r.concat([],f):o[h]=i(o[h],[f]);break;default:o[h]=f}}}}}return o}var n=[].map;e.assign=i}),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/maybe","src/lib/either","src/lib/fingerprint","src/lib/uuid","src/lib/assign","src/lib/concat","./typings/arch-stream.d"],function(t,e,r,i,n,o,s,c,u,a,h,p,f,d,l,v,y,m){"use strict";function _(){return new r.ArchStream}function b(){return new i.Message}e.Proxy=o.Proxy,e.Supervisor=s.Supervisor,e.Observable=c.Observable,e.Map=u.Map,e.MultiMap=u.Map,e.Set=a.Set,e.MultiSet=a.Set,e.Tick=h.Tick,e.Timer=p.Timer,e.Maybe=f.Maybe,e.Just=f.Just,e.Nothing=f.Nothing,e.Either=d.Either,e.Left=d.Left,e.Right=d.Right,e.FINGERPRINT=l.FINGERPRINT,e.uuid=v.v4,e.assign=y.assign,e.concat=m.concat;var w={Msg:b,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=_;var _;!function(t){t.Msg=w.Msg,t.Proxy=w.Proxy}(_||(_={})),e.Msg=b}),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"]});
{
"name": "arch-stream",
"version": "0.0.76",
"version": "0.0.77",
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.",

@@ -5,0 +5,0 @@ "private": false,

@@ -15,6 +15,8 @@ /* tslint:disable:no-unused-variable */ // tslint bug. https://github.com/palantir/tslint/issues/684

export {Timer} from './lib/timer';
export {Maybe, Just, Nothing} from './lib/maybe';
export {Either, Left, Right} from './lib/either';
export {FINGERPRINT} from './lib/fingerprint';
export {v4 as uuid} from './lib/uuid';
export {Maybe, Just, Nothing} from './lib/maybe';
export {Either, Left, Right} from './lib/either';
export {assign} from './lib/assign';
export {concat} from './lib/concat';

@@ -21,0 +23,0 @@ const Package = {

@@ -59,3 +59,3 @@ import {Message} from './message';

.send({ val: 1 }, e => assert(e.val === 1 && ++cnt === 2))
.send({ val: 0 }, _ => done());
.send({ val: 2 }, e => assert(e.val === 2 && ++cnt === 3) || done());
});

@@ -71,3 +71,3 @@

.send({ val: 3 }, e => assert(e.val === 3 && ++cnt === 2 && async === false))
.send({ val: 0 }, true, _ => done());
.send({ val: 3 }, true, e => assert(e.val === 3 && ++cnt === 5 && async === true) || done());
async = true;

@@ -74,0 +74,0 @@ });

import {IObservableObserver, IObservableSubscriber, IObservablePublisher} from 'arch-stream';
import {concat} from './concat';

@@ -24,3 +25,3 @@ type ObservableEvent<T, D> = D & {

const CACHE_SIZE = 1e3;
const CACHE_SIZE = 1e2;

@@ -34,7 +35,3 @@ export class Observable<T extends string | number, D, R>

if (type['map'] === [].map) {
const copy: T[] = [];
for (let i = 0; i < (<T[]>type).length; ++i) {
copy[i] = type[i];
}
return copy;
return concat([], <T[]>type);
}

@@ -44,3 +41,3 @@ else {

return event.namespace
? this.formatEventType_(event.namespace).concat(event.type)
? concat(this.formatEventType_(event.namespace), [event.type])
: [event.type];

@@ -59,3 +56,2 @@ }

this.mayHasMonitor_ = true;
void this.rebuildCache_(types);
return this;

@@ -69,7 +65,5 @@ }

this.mayHasSubscriber_ = true;
void this.rebuildCache_(types);
return this;
}
public off(type: T | T[], subscriber?: Subscriber<D, R>): this {
void ++this.cacheBreak_[0];
const types = this.formatEventType_(type);

@@ -94,3 +88,2 @@ switch (typeof subscriber) {

});
void this.rebuildCache_(types);
return this;

@@ -103,4 +96,2 @@ }

node.registers = [];
this.refsBelowCache_ = [];
void this.rebuildCache_(types);
return this;

@@ -142,3 +133,3 @@ }

this.mayHasSubscriber_ = false;
void this.refs_(types, this.refsBelowCache_)
void this.refsBelow_(this.seekNode_(types))
.reduce((_, sub) => {

@@ -163,3 +154,3 @@ this.mayHasSubscriber_ = true;

this.mayHasMonitor_ = false;
void this.refs_(types, this.refsAboveCache_)
void this.refsAbove_(this.seekNode_(types))
.reduce((_, sub) => {

@@ -190,24 +181,8 @@ this.mayHasMonitor_ = true;

public refs(type: T | T[]): [T[], Subscriber<D, R>, boolean][] {
return this.refs_(this.formatEventType_(type), this.refsBelowCache_);
return this.refsBelow_(this.seekNode_(this.formatEventType_(type)));
}
private refs_(types: T[], refsCache: [T[], Register<T, D, R>[]][]): Register<T, D, R>[] {
if (this.isCacheActive()) return this.refsCached_(types, refsCache);
return refsCache === this.refsAboveCache_ ? this.refsAbove_(this.seekNode_(types)) : this.refsBelow_(this.seekNode_(types));
}
private refsAboveCache_: [T[], Register<T, D, R>[]][] = [];
private refsBelowCache_: [T[], Register<T, D, R>[]][] = [];
private refsCached_(types: T[], refsCache: [T[], Register<T, D, R>[]][]): Register<T, D, R>[] {
for (let i = 0; i < refsCache.length; ++i) {
if (equal(refsCache[i][0], types)) return refsCache[i][1];
}
void refsCache.unshift([types, refsCache === this.refsAboveCache_ ? this.refsAbove_(this.seekNode_(types)) : this.refsBelow_(this.seekNode_(types))]);
if (refsCache.length > CACHE_SIZE) {
void refsCache.pop();
}
return refsCache[0][1];
}
private refsAbove_({parent, registers}: SubscriberMapNode<T, D, R>): Register<T, D, R>[] {
registers = registers.slice();
registers = concat([], registers);
while (parent) {
void registers.push(...parent.registers);
void concat(registers, parent.registers);
parent = parent.parent;

@@ -218,7 +193,7 @@ }

private refsBelow_({childrenList, childrenMap, registers}: SubscriberMapNode<T, D, R>): Register<T, D, R>[] {
registers = registers.slice();
registers = concat([], registers);
for (let i = 0; i < childrenList.length; ++i) {
const name = childrenList[i];
const below = this.refsBelow_(childrenMap[name]);
void registers.push(...below);
void concat(registers, below);
if (below.length === 0) {

@@ -238,14 +213,11 @@ delete childrenMap[name];

};
private nodeCache_: [T[], SubscriberMapNode<T, D, R>][] = [];
private seekNode_(types: T[]): SubscriberMapNode<T, D, R> {
if (this.isCacheActive()) return this.seekNodeCached_(types);
let node = this.node_;
for (let i = 0; i < types.length; ++i) {
for (const type of types) {
const {childrenMap} = node;
assert(childrenMap.constructor === void 0);
const name = types[i];
if (!childrenMap[name + '']) {
void node.childrenList.push(name + '');
if (!childrenMap[type + '']) {
void node.childrenList.push(type + '');
node.childrenList = node.childrenList.sort();
childrenMap[name + ''] = {
childrenMap[type + ''] = {
parent: node,

@@ -257,52 +229,6 @@ childrenMap: <SubscriberMap<T, D, R>>Object.create(null),

}
node = childrenMap[name + ''];
node = childrenMap[type + ''];
}
return node;
}
private seekNodeCached_(types: T[]): SubscriberMapNode<T, D, R> {
const nodeCache = this.nodeCache_;
for (let i = 0; i < nodeCache.length; ++i) {
if (equal(nodeCache[i][0], types)) return nodeCache[i][1];
}
this.useCache_ = false;
void nodeCache.unshift([types, this.seekNode_(types)]);
this.useCache_ = true;
if (nodeCache.length > CACHE_SIZE) {
void nodeCache.pop();
}
return nodeCache[0][1];
}
private useCache_ = true;
private cacheBreak_: [number, number] = [0, Date.now()];
private isCacheActive(): boolean {
if (!this.useCache_) return false; // required by adjustCacheSettings_
void this.adjustCacheSettings_();
return this.cacheBreak_[0] < 9;
}
private adjustCacheSettings_(): void {
const [count, since] = this.cacheBreak_;
if (count < 9) return;
const now = Date.now();
if (now - since < 9) {
void this.clearCache_();
this.useCache_ = false;
void setTimeout((): void => void this.adjustCacheSettings_(), 1e3);
}
else {
this.useCache_ = true;
this.cacheBreak_ = [0, now];
}
}
private rebuildCache_(types: T[]): void {
if (!this.useCache_) return;
this.nodeCache_ = this.nodeCache_.filter(([ts]) => ts.length < types.length);
this.refsAboveCache_ = this.refsAboveCache_.filter(([ts]) => ts.length < types.length);
this.refsBelowCache_ = this.refsBelowCache_.filter(([ts]) => ts.length > types.length);
}
private clearCache_(): void {
if (!this.useCache_) return;
this.nodeCache_ = [];
this.refsAboveCache_ = [];
this.refsBelowCache_ = [];
}
private throwTypeErrorIfInvalidSubscriber_(subscriber: Subscriber<D, R>, types: T[]): void {

@@ -319,10 +245,1 @@ switch (typeof subscriber) {

}
function equal<T>(a: T[], b: T[]): boolean {
if (a === b) return true;
if (a.length !== b.length) return false;
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}

@@ -6,34 +6,11 @@ import {Supervisor as ISupervisor, SupervisorSettings} from 'arch-stream';

import {isThenable} from './thenable';
import {concat} from './concat';
import {noop} from './noop';
type WorkerCommand<T, D>
= WorkerCommand_$Deps<T>
| WorkerCommand_$Call<D>
| WorkerCommand_$Exit;
abstract class AbstractWorkerCommand {
private WORKER_COMMAND: void;
interface WorkerSharedResources<T extends string | number, D, R> {
procs: Observable<T, WorkerCommand<T, D>, R>;
resolvedDependencies: T[][];
allRefsCache?: [T[], (data: WorkerCommand<T, D>) => R, boolean][];
}
class WorkerCommand_$Deps<T> extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public namespace: T[]) {
super();
}
}
class WorkerCommand_$Call<D> extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public data: D) {
super();
}
}
class WorkerCommand_$Exit extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public reason: any) {
super();
}
}
let SupervisorCounter = 0;
let ProcessCounter = 0;
export namespace Supervisor {

@@ -48,2 +25,6 @@ export namespace Event {

}
let SupervisorCounter = 0;
let ProcessCounter = 0;
export class Supervisor<T extends string, D, R> implements ISupervisor<T, D, R> {

@@ -111,12 +92,16 @@ public static get count(): number {

}
private workerSharedResource: WorkerSharedResources<T, D, R> = {
procs: this.procs,
resolvedDependencies: []
};
public register(namespace: T[], process: (data: D) => R, parallel?: number): (reason?: any) => void {
void this.checkState();
if (!this.registerable) throw new Error(`ArchStream: Supervisor: Supervisor ${this.name} cannot register process during the exiting.`);
namespace = namespace.slice();
namespace = concat([], namespace);
void this.schedule();
return new Worker(this, this.procs, namespace, process, parallel, this.deps.get(namespace) || []).terminate;
return new Worker(this, this.workerSharedResource, namespace, process, parallel, this.deps.get(namespace) || []).terminate;
}
public call(namespace: T[], data: D, timeout = this.timeout, callback?: (data: D, results: R[]) => any): void {
void this.checkState();
namespace = namespace.slice();
namespace = concat([], namespace);
void this.queue.push([namespace, data, callback, timeout, Date.now()]);

@@ -184,10 +169,35 @@ void this.schedule();

}
public depsResolvedNamespaces: T[][] = [];
public depsAllRefsCache: [T[], (data: WorkerCommand<T, D>) => R, boolean][];
}
type WorkerCommand<T, D>
= WorkerCommand_$Deps<T>
| WorkerCommand_$Call<D>
| WorkerCommand_$Exit;
abstract class AbstractWorkerCommand {
private WORKER_COMMAND: void;
}
class WorkerCommand_$Deps<T> extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public namespace: T[]) {
super();
}
}
class WorkerCommand_$Call<D> extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public data: D) {
super();
}
}
class WorkerCommand_$Exit extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public reason: any) {
super();
}
}
class Worker<T extends string, D, R> {
constructor(
private sv: Supervisor<T, D, R>,
private procs: Observable<T, WorkerCommand<T, D>, R>,
private sharedResource: WorkerSharedResources<T, D, R>,
public namespace: T[],

@@ -201,5 +211,5 @@ public process: (data: D) => R,

void this.clearCache();
this.sharedResource.allRefsCache = void 0;
void ++ProcessCounter;
void this.procs
void this.sharedResource.procs
.on(namespace, this.receive);

@@ -209,7 +219,8 @@ }

void this.checkState();
void this.procs
void this.sharedResource.procs
.off(this.namespace, this.receive);
this.alive = false;
void --ProcessCounter;
void this.clearCache();
this.sharedResource.allRefsCache = void 0;
this.sharedResource.resolvedDependencies = [];
void Object.freeze(this);

@@ -223,9 +234,5 @@ void this.sv.events.exit

if (this.receive(new WorkerCommand_$Deps(this.namespace))) return;
this.sv.depsResolvedNamespaces = [];
this.sharedResource.resolvedDependencies = [];
throw void 0;
}
private clearCache(): void {
this.sv.depsResolvedNamespaces = [];
this.sv.depsAllRefsCache = void 0;
}
public receive(): Worker<T, D, R>

@@ -241,9 +248,9 @@ public receive(cmd: WorkerCommand_$Deps<T>): boolean

if (cmd.namespace.length !== this.namespace.length) return false;
for (let i = 0, resolved = this.sv.depsResolvedNamespaces; i < resolved.length; ++i) {
if (equal(this.namespace, resolved[i])) return true;
for (const resolved of this.sharedResource.resolvedDependencies) {
if (equal(this.namespace, resolved)) return true;
}
void this.sv.depsResolvedNamespaces.push(this.namespace);
void this.sharedResource.resolvedDependencies.push(this.namespace);
return this.dependencies
.every(dep =>
(this.sv.depsAllRefsCache = this.sv.depsAllRefsCache || this.procs.refs([]))
(this.sharedResource.allRefsCache = this.sharedResource.allRefsCache || this.sharedResource.procs.refs([]))
.some(([ns, proc]) => equal(ns, dep) && !!proc(new WorkerCommand_$Deps(dep)))

@@ -250,0 +257,0 @@ );

@@ -50,3 +50,3 @@ import A, {Msg, Tick} from 'arch-stream';

.write({ val: 1 }, e => assert(e.val === 5 && ++cnt === 2))
.write({ val: 0 }, _ => assert(++cnt === 3) || done());
.write({ val: 2 }, e => assert(e.val === 6 && ++cnt === 3) || done());
});

@@ -53,0 +53,0 @@

@@ -14,3 +14,5 @@ import A, {

Maybe, Just, Nothing,
Either, Left, Right
Either, Left, Right,
assign,
concat
} from 'arch-stream';

@@ -110,21 +112,2 @@

describe('FINGERPRINT', function () {
it('FINGERPRINT', function () {
assert(typeof FINGERPRINT === 'number');
assert(!isNaN(FINGERPRINT));
assert(FINGERPRINT === parseInt(FINGERPRINT.toString()));
assert(0 < FINGERPRINT && FINGERPRINT < 1e15);
});
});
describe('uuid', function () {
it('uuid', function () {
assert(typeof uuid() === 'string');
assert(uuid().length === 36);
assert(uuid() !== uuid());
});
});
describe('Maybe', function () {

@@ -172,2 +155,26 @@ it('Maybe', function () {

describe('utils', function () {
it('FINGERPRINT', function () {
assert(typeof FINGERPRINT === 'number');
assert(!isNaN(FINGERPRINT));
assert(FINGERPRINT === parseInt(FINGERPRINT.toString()));
assert(0 < FINGERPRINT && FINGERPRINT < 1e15);
});
it('uuid', function () {
assert(typeof uuid() === 'string');
assert(uuid().length === 36);
assert(uuid() !== uuid());
});
it('assign', function () {
assert(typeof assign === 'function');
});
it('concat', function () {
assert(typeof concat === 'function');
});
});
describe('power-assert', function () {

@@ -174,0 +181,0 @@ it('assertion self-check', function (done) {

@@ -9,3 +9,5 @@ {

"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowUnreachableCode": true,
"allowUnusedLabels": true,
"preserveConstEnums": true,

@@ -12,0 +14,0 @@ "rootDir": "./",

@@ -215,5 +215,2 @@ /**

export const FINGERPRINT: number;
export function uuid(): string
abstract class Monad<T> {

@@ -320,2 +317,8 @@ private MONAD: T;

export const FINGERPRINT: number;
export function uuid(): string
export function assign<T extends Object>(target: T | {}, sources: T[]): T
export function concat<T>(target: T[], source: T[]): T[]
export function concat<T>(target: T[], source: { [index: number]: T; length: number; }): T[]
}

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc