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.73 to 0.0.74

4

dist/arch-stream.min.js

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

/*! arch-stream v0.0.73 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! arch-stream v0.0.74 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,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,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/observable",["require","exports","src/lib/noop"],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 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).registers.push([i,e,r,!0,!0]),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.seek_(i).registers.push([i,function(t){return e(t)},r,!0,!1]),this.mayHasSubscriber_=!0,this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seek_(r).registers.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.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 instanceof Object&&!Array.isArray(t)?this.drain_(this.formatEventType_(t),t,e):this.drain_(this.formatEventType_(t),e,r)},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,e,i){var n=this;void 0===i&&(i=r.noop);var o=this.seek_(t),s=[];return this.mayHasSubscriber_&&(this.mayHasSubscriber_=!1,void this.refsBelow_(o).reduce(function(t,r){n.mayHasSubscriber_=!0;var i=r[1],o=r[3],u=r[4];if(o&&!u){r[3]=!1;try{void s.push(i(e))}catch(c){void 0!==c&&null!==c&&void console.error(c,c+"")}r[3]=!0}},void 0)),this.mayHasMonitor_&&(this.mayHasMonitor_=!1,void this.refsAbove_(o).reduce(function(t,r){n.mayHasMonitor_=!0;var i=r[1],o=r[3],s=r[4];if(o&&s){r[3]=!1;try{void i(e)}catch(u){void 0!==u&&null!==u&&void console.error(u,u+"")}r[3]=!0}},void 0)),void i(e,s),this},t.prototype.refs=function(t){return this.refsBelow_(this.seek_(this.formatEventType_(t))).map(function(t){return[t[0],t[2],t[4]]})},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.seek_=function(t){for(var e=this.node_,r=0;r<t.length;++r){var i=e.childrenMap,n=t[r];i[n+""]||(e.childrenList=e.childrenList.concat([n+""]).sort(),i[n+""]={parent:e,childrenMap:Object.create(null),childrenList:[],registers:[]}),e=i[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/thenable","src/lib/set","src/lib/tick","src/lib/noop"],function(t,e,r,i,n,o,s){"use strict";var u=function(){function t(){}return t}(),c=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),h=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(u),p=0,f=0,d=function(){function t(t,e,i,o){var u=this;void 0===t&&(t="anonymous"),void 0===e&&(e=[]),void 0===i&&(i=0),void 0===o&&(o=s.noop),this.name=t,this.timeout=i,this.destructor=o,this.deps=new n.Set,this.events={exec:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.procs=new r.Observable,this.state=!0,this.queue=[],this.depsResolvedNamespaces=[],void e.reduce(function(t,e){var r=e[0],i=e[1];return void u.deps.set(r,i)},void 0),void++p}return Object.defineProperty(t,"count",{get:function(){return p},enumerable:!0,configurable:!0}),Object.defineProperty(t,"procs",{get:function(){return f},enumerable:!0,configurable:!0}),t.prototype.register=function(t,e,r){var i=this;void this.checkState(),t=t.slice();var n=new l(this,this.procs,t,e,r,this.deps.get(t)||[]);return void++f,void this.procs.on(t,n.receive),void this.events.exec.emit(t,[t,e]),void o.Tick(function(t){return i.drain()}),n.terminate},t.prototype.call=function(t,e,r,i){var n=this;void 0===r&&(r=s.noop),void 0===i&&(i=this.timeout),void this.checkState(),t=t.slice(),void this.queue.push([t,e,r,i,Date.now()]),void o.Tick(function(t){return n.drain()}),i>0&&void setTimeout(function(){return n.drain(t)},i+9)},t.prototype.cast=function(t,e){return this.procs.reflect(t,new a(e))},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){if(void this.checkState(),void this.procs.emit(t||[],new h(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.events.loss.emit(i,[i,void 0,n])}try{void this.destructor(e)}catch(o){void console.error(o,o+"")}void--p}},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],u=o[1],c=o[2],h=o[3],p=o[4],f=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new a(u)):[];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.events.loss.emit(s,[s,void 0,u]),void c(u,f),void(e=i))},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t}();e.Supervisor=d;var l=function(){function t(t,e,r,i,n,o){var s=this;this.sv=t,this.procs=e,this.namespace=r,this.process=i,this.parallel=n,this.dependencies=o,this.alive=!0;var u=this.receive;this.receive=function(t){return u.call(s,t)};var c=this.terminate;this.terminate=function(t){return c.call(s,t)},void this.clearCache()}return t.prototype.tryDependencyResolving=function(t){if(!this.receive(new c(this.namespace)))throw void void this.clearCache()},t.prototype.clearCache=function(){this.sv.depsResolvedNamespaces=[],this.sv.depsCachedRefs=void 0},t.prototype.receive=function(t){var e=this;if(!this.alive)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.");if(void 0===t)return this;if(t instanceof c)return t.namespace.length!==this.namespace.length?!1:this.sv.depsResolvedNamespaces.some(function(t){return t.length===e.namespace.length&&t.every(function(r,i){return t[i]===e.namespace[i]})})?!0:(void this.sv.depsResolvedNamespaces.push(this.namespace),this.dependencies.every(function(t){return(e.sv.depsCachedRefs=0===e.dependencies.length?[]:e.sv.depsCachedRefs||e.procs.refs([])).some(function(e){var r=e[0],i=e[1];return r.length==t.length&&r.every(function(e,i){return r[i]===t[i]})&&!!i(new c(t))})}));if(t instanceof a){if(this.parallel<0)throw void 0;void this.tryDependencyResolving(t);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 h)throw void void this.terminate(t.reason);throw new TypeError("ArchStream: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){if(!this.alive)throw new Error("ArchStream: Supervisor: Process "+this.namespace+"/"+this.process+" cannot terminate multiply with "+t+".");void--f,void this.clearCache(),this.alive=!1,void this.procs.off(this.namespace,this.receive),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,t])},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,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,y=t.error,m=void 0===y?function(){return 0}:y,_=t.timeout,b=void 0===_?function(){return 0}:_,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 m(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/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 y(){return new r.ArchStream}function m(){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 _={Msg:m,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=y;var y;!function(t){t.Msg=_.Msg,t.Proxy=_.Proxy}(y||(y={})),e.Msg=m}),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/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=[],void this.clearCache_(),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(a){void 0!==a&&null!==a&&void console.error(a,a+"")}},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 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/thenable","src/lib/set","src/lib/tick","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}(),a=function(t){function e(e){t.call(this),this.namespace=e}return __extends(e,t),e}(u),h=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,i=void 0===t?{}:t,o=i.name,c=void 0===o?"anonymous":o,u=i.dependencies,a=void 0===u?[]:u,h=i.retry,p=void 0===h?!1:h,d=i.timeout,l=void 0===d?0:d,v=i.destructor,_=void 0===v?s.noop:v;this.deps=new n.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.queue=[],this.depsResolvedNamespaces=[],this.name=c,void a.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.registerable=!1,this.procs.refs([]).length>0&&void this.terminate([],t),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.register=function(t,e,r){var i=this;if(void this.checkState(),!this.registerable)throw new Error("ArchStream: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");t=t.slice();var n=new v(this,this.procs,t,e,r,this.deps.get(t)||[]);return void o.Tick(function(t){return i.drain()}),n.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 o.Tick(function(t){return n.drain()}),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 h(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){void 0===t&&(t=[]);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],p=o[4],f=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new h(c)):[];if(0===f.length&&p+a>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.receive=function(e){return t.prototype.receive.call(c,e)},this.terminate=function(e){return t.prototype.terminate.call(c,e)},void++d,void this.clearCache(),void this.procs.on(i,this.receive),void this.sv.events.exec.emit(i,[i,n])}return t.prototype.destructor=function(t){void this.checkState(),void this.clearCache(),void this.procs.off(this.namespace,this.receive),this.alive=!1,void--d,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 a(this.namespace)))throw void void this.clearCache()},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 a){if(t.namespace.length!==this.namespace.length)return!1;for(var r=0,n=this.sv.depsResolvedNamespaces;r<n.length;++r)if(c(this.namespace,n[r]))return!0;return void this.sv.depsResolvedNamespaces.push(this.namespace),this.dependencies.every(function(t){return(e.sv.depsAllRefsCache=0===e.dependencies.length?[]:e.sv.depsAllRefsCache||e.procs.refs([])).some(function(e){var r=e[0],i=e[1];return c(r,t)&&!!i(new a(t))})})}if(t instanceof h){if(this.parallel<0)throw void 0;void this.tryDependencyResolving(t);try{var o=this.process(t.data);return i.isThenable(o)&&(void--this.parallel,void o.then(function(t){return e.alive?void++e.parallel:void 0},function(t){return e.alive&&e.terminate(t)})),o}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,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,_=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(a()){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: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/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,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=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.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"]});
# Note
ArchStreamはJavaScriptによるドメイン駆動設計(DDD)を取り入れたデータ指向設計のためのライブラリーである。
ArchStreamはJavaScriptによるドメイン駆動設計(DDD)およびデータ指向設計のためのライブラリである。
依存関係の事前条件への変換、依存関係の直列化および依存関係数制限によりシーケンスの依存関係が保証されたアーキテクチャを構築する。
ArchStreamが設計に代表される静的問題解決を担うほか、ジョブ・集合・コンポーネントの生成管理などの動的問題解決をSupervisorが担う。
このライブラリはストリーム以外にメッセージング、タイマー、バックグラウンドスレッド代用のSupervisorとObserverなどドメイン駆動設計に必要となる機能をまとめたDDD用ツールボックスとなっている。
入出力の調整など信号処理的な機能はlodashなどの外部のデータ処理系ライブラリに委ねている。

@@ -11,3 +14,2 @@ ## 性質

Stream APIやUnderscoreがデータ操作、RxJSがSmartUI(View)をターゲットにしているのに対して、ArchStreamはアーキテクチャ設計(Model)をターゲットにしている。
ArchStreamを使用した設計として、パイプラインで構成されたドメインレイヤーを持つドメイン駆動設計で構築されたモデルを持つMVC設計といった例が考えられる。

@@ -95,4 +97,4 @@ ## 用語

入出力を各1箇所に限定し、パイプラインがエンティティの種類ごとに構築するものである都合上、独立した多数の機能やアクセスポイントの提供を目的とするモデルへの適用は難しい。
アーキテクチャ設計のためのライブラリーではあるが、アーキテクチャ全体をストリームで構築する設計は適切でなく、ストリームが効果的に関与できる範囲は限定的であるため、ArchStreamの適用範囲は基本的に特にシーケンスに注目される部分(UMLならシーケンス図がある部分)のみとなる。
アプリケーションの目的がサービスの提供である場合、基本的に特定のユースケースのために作られるためパイプライン化しやすい。
目安として入力データが概ね情報量を減らさずにプログラムの大部分を通過するようなデータ処理的なプログラムに適しており、
反対に入力データを分解して浸透させるまたはプログラムを駆動させるような副作用を主体とするプログラムには適していない。

@@ -355,9 +357,9 @@ ### 運搬責務分離

- オブザーバーパターンのための出版購読オブジェクトを生成する。
- ストリームと対照的に動的な処理経路を構築できる。
- イベントの発行およびサブスクライバの追加削除の順序を完全に維持する。
- イベント発行中のサブスクライバのエラーを同期でリカバリする。
- イベントにオブジェクトが渡された場合このオブジェクトを不変化する。
- 初期化パラメータでセパレータを設定することでjQueryと同等のネームスペース機能を持つ。
- 出版購読モデルのメッセージングを行う。
- 同期メッセージングに特化しておりサブスクライバのエラーにより停止しない。
- 配列またはセパレータの設定によりjQueryと同等のネームスペースを使用できる。
メッセージを同期処理で即座に配信する。
サブスクライバをノードとして扱い動的な処理経路の構築や集合操作にも利用できる。
### Map/Set

@@ -364,0 +366,0 @@

{
"name": "arch-stream",
"version": "0.0.73",
"version": "0.0.74",
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.",

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

@@ -22,3 +22,3 @@ import {Observable} from './observable';

ob.monitor([], id);
assert.deepEqual(ob.refs([]), [
assert.deepEqual(ob.refs([]).map(reg => reg.slice(0, 3)), [
[[], id, false],

@@ -30,3 +30,3 @@ [[], id, true]

ob.monitor([''], id);
assert.deepEqual(ob.refs([]), [
assert.deepEqual(ob.refs([]).map(reg => reg.slice(0, 3)), [
[[], id, false],

@@ -43,3 +43,3 @@ [[], id, true],

ob.on([''], id);
assert.deepEqual(ob.refs([]), [
assert.deepEqual(ob.refs([]).map(reg => reg.slice(0, 3)), [
[[], id, false],

@@ -143,3 +143,3 @@ [[], id, true],

it('observe', function (done) {
it('monitor', function (done) {
let cnt = 0;

@@ -146,0 +146,0 @@ new Observable<string, number, void>()

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

@@ -20,8 +19,9 @@ type ObservableEvent<T, D> = D & {

Subscriber<D, R>,
Subscriber<D, R>,
boolean,
boolean
Subscriber<D, R>
];
type Subscriber<D, R> = (data: D) => R;
const CACHE_SIZE = 1e3;
export class Observable<T extends string | number, D, R>

@@ -32,5 +32,9 @@ implements IObservableObserver<T, D, R>, IObservableSubscriber<T, D, R>, IObservablePublisher<T, D, R> {

private formatEventType_(type: T | T[] | ObservableEvent<T, D>): T[] {
if (type instanceof Object) {
if (Array.isArray(type)) {
return type.slice();
if (type && typeof type === 'object') {
if (type['map'] === [].map) {
const copy: T[] = [];
for (let i = 0; i < (<T[]>type).length; ++i) {
copy[i] = type[i];
}
return copy;
}

@@ -52,4 +56,5 @@ else {

void this.throwTypeErrorIfInvalidSubscriber_(subscriber, types);
void this.seek_(types).registers.push([types, subscriber, identifier, true, true]);
void this.seekNode_(types).registers.push([types, identifier, true, subscriber]);
this.mayHasMonitor_ = true;
void this.rebuildCache_(types);
return this;

@@ -61,12 +66,14 @@ }

void this.throwTypeErrorIfInvalidSubscriber_(subscriber, types);
void this.seek_(types).registers.push([types, data => subscriber(data), identifier, true, false]);
void this.seekNode_(types).registers.push([types, identifier, false, data => subscriber(data)]);
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);
switch (typeof subscriber) {
case 'function': {
void this.seek_(types).registers
.some(([, , identifier], i, registers) => {
void this.seekNode_(types).registers
.some(([, identifier], i, registers) => {
if (subscriber !== identifier) return false;

@@ -86,9 +93,11 @@ switch (i) {

});
void this.rebuildCache_(types);
return this;
}
case 'undefined': {
const node = this.seek_(types);
const node = this.seekNode_(types);
node.childrenMap = Object.create(null);
node.childrenList = [];
node.registers = [];
void this.clearCache_();
return this;

@@ -112,3 +121,3 @@ }

public emit(type: T | T[] | ObservableEvent<T, D>, data: D | ((event: ObservableEvent<T, D>, results: R[]) => any), tracker?: (data: D, results: R[]) => any): this {
return type instanceof Object && !Array.isArray(type)
return type && typeof type === 'object' && type['map'] !== [].map
? this.drain_(this.formatEventType_(type), <ObservableEvent<T, D>>type, <(event: ObservableEvent<T, D>) => any>data)

@@ -121,3 +130,3 @@ : this.drain_(this.formatEventType_(type), <D>data, tracker);

let results: R[];
type instanceof Object && !Array.isArray(type)
type && typeof type === 'object' && type['map'] !== [].map
? void this.emit(this.formatEventType_(type), <ObservableEvent<T, D>>type, (_, r) => results = r)

@@ -128,15 +137,16 @@ : void this.emit(this.formatEventType_(type), <D>data, (_, r) => results = r);

}
private drain_(types: T[], data: D, tracker: (data: D, results: R[]) => any = noop): this {
const node = this.seek_(types);
private drain_(types: T[], data: D, tracker?: (data: D, results: R[]) => any): this {
const results: any[] = [];
if (this.mayHasSubscriber_) {
this.mayHasSubscriber_ = false;
void this.refsBelow_(node)
void this.refs_(types, this.refsBelowCache_)
.reduce((_, sub) => {
this.mayHasSubscriber_ = true;
const [, subscriber, , active, monitor] = sub;
if (!active || monitor) return;
sub[3] = false;
const [, , monitor, subscriber] = sub;
if (monitor) return;
try {
void results.push(subscriber(data));
const result = subscriber(data);
if (tracker) {
results[results.length] = result;
}
}

@@ -148,3 +158,2 @@ catch (err) {

}
sub[3] = true;
}, void 0);

@@ -154,8 +163,7 @@ }

this.mayHasMonitor_ = false;
void this.refsAbove_(node)
void this.refs_(types, this.refsAboveCache_)
.reduce((_, sub) => {
this.mayHasMonitor_ = true;
const [, subscriber, , active, monitor] = sub;
if (!active || !monitor) return;
sub[3] = false;
const [, , monitor, subscriber] = sub;
if (!monitor) return;
try {

@@ -169,12 +177,33 @@ void subscriber(data);

}
sub[3] = true;
}, void 0);
}
void tracker(data, results);
if (tracker) {
try {
void tracker(data, results);
}
catch (err) {
void console.error(err, err + '');
}
}
return this;
}
public refs(type: T | T[]): [T[], Subscriber<D, R>, boolean][] {
return this.refsBelow_(this.seek_(this.formatEventType_(type)))
.map<[T[], Subscriber<D, R>, boolean]>(set => [set[0], set[2], set[4]]);
return this.refs_(this.formatEventType_(type), this.refsBelowCache_);
}
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>[] {

@@ -208,3 +237,5 @@ registers = registers.slice();

};
private seek_(types: T[]): SubscriberMapNode<T, D, R> {
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_;

@@ -216,3 +247,4 @@ for (let i = 0; i < types.length; ++i) {

if (!childrenMap[name + '']) {
node.childrenList = node.childrenList.concat([name + '']).sort();
void node.childrenList.push(name + '');
node.childrenList = node.childrenList.sort();
childrenMap[name + ''] = {

@@ -229,2 +261,48 @@ parent: 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(() => 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 {

@@ -241,1 +319,10 @@ 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;
}

@@ -35,13 +35,16 @@ import {Supervisor} from './supervisor';

let cnt = 0;
const sv = new Supervisor<string, number, number>(void 0, [], 0, reason => {
assert(reason === void 0);
assert(++cnt === 11);
assert(Supervisor.count === 1);
assert(Supervisor.procs === 0);
Tick(() => {
assert(++cnt === 12);
assert(Supervisor.count === 0);
const sv = new Supervisor<string, number, number>({
name: void 0,
destructor: reason => {
assert(reason === void 0);
assert(++cnt === 11);
assert(Supervisor.count === 1);
assert(Supervisor.procs === 0);
done();
});
Tick(() => {
assert(++cnt === 12);
assert(Supervisor.count === 0);
assert(Supervisor.procs === 0);
done();
});
}
});

@@ -87,23 +90,9 @@ assert(sv.name === 'anonymous');

});
sv
.call([], 1, (_, r) => assert.deepEqual(r, [-1]) || assert(++cnt === 5));
sv.call([], 1, 0, (_, r) => assert.deepEqual(r, [-1]) || assert(++cnt === 5));
assert.deepEqual(sv.cast([], 2), [-2]);
sv
.call([], 3, (_, r) => assert.deepEqual(r, []) || assert(++cnt === 8) || assert(Supervisor.procs === 0));
sv
.call([], 4, (_, r) => assert.deepEqual(r, []) || assert(++cnt === 10) || assert(Supervisor.procs === 0) || sv.terminate());
sv.call([], 3, 0, (_, r) => assert.deepEqual(r, []) || assert(++cnt === 8) || assert(Supervisor.procs === 0));
sv.call([], 4, 0, (_, r) => assert.deepEqual(r, []) || assert(++cnt === 10) || assert(Supervisor.procs === 0) || sv.terminate());
assert(++cnt === 3);
});
it('async', function (done) {
assert(Supervisor.count === 0);
assert(Supervisor.procs === 0);
let cnt = 0;
const sv = new Supervisor<string, number, number>();
sv.register([], _ => ++cnt);
sv
.call([], 0, (_, r) => assert(cnt === 1) || sv.terminate() || done());
assert(cnt === 0);
});
it('dependencies', function (done) {

@@ -113,24 +102,27 @@ assert(Supervisor.count === 0);

let cnt = 0;
const sv = new Supervisor<string, number, number>('deps', [
[[], [
['a'],
['a', 'a'],
['b']
]],
[['a'], [
[],
['a', 'a'],
['b']
]],
[['a', 'a'], [
[],
['a'],
['b']
]],
[['b'], [
[],
['a'],
['a', 'a']
]]
]);
const sv = new Supervisor<string, number, number>({
name: 'deps',
dependencies: [
[[], [
['a'],
['a', 'a'],
['b']
]],
[['a'], [
[],
['a', 'a'],
['b']
]],
[['a', 'a'], [
[],
['a'],
['b']
]],
[['b'], [
[],
['a'],
['a', 'a']
]]
]
});

@@ -159,3 +151,3 @@ sv.register([], _ => ++cnt);

sv.call([], 0, (_, r) => {
sv.call([], 0, 0, (_, r) => {
assert(cnt === 8);

@@ -173,2 +165,32 @@ assert.deepEqual(r, [5, 6, 7, 8]);

it('retry', function (done) {
assert(Supervisor.count === 0);
assert(Supervisor.procs === 0);
let cnt = 0;
const sv = new Supervisor<string, number, number>();
sv.register([], _ => <any>assert(++cnt === 2) || cnt);
sv.events.exit.on([], ([name, proc, reason]) => reason && sv.register(name, proc));
assert.deepEqual(sv.cast([], 0, true), [2]);
sv.terminate();
done();
});
it('timeout', function (done) {
assert(Supervisor.count === 0);
assert(Supervisor.procs === 0);
let cnt = 0;
const sv = new Supervisor<string, number, number>();
sv.call([], 0, 0, (_, r) => assert(++cnt === 1 && r.length === 0) || sv.terminate() || Tick(done));
});
it('async', function (done) {
assert(Supervisor.count === 0);
assert(Supervisor.procs === 0);
let cnt = 0;
const sv = new Supervisor<string, number, number>();
sv.register([], _ => ++cnt);
sv.call([], 0, 0, (_, r) => assert(cnt === 1) || sv.terminate() || done());
assert(cnt === 0);
});
it('parallel', function (done) {

@@ -181,8 +203,5 @@ assert(Supervisor.count === 0);

sv.events.loss.on([], _ => void _);
sv
.call([], 0, (_, r) => assert(r.length === 1 && ++cnt === 1));
sv
.call([], 0, (_, r) => assert(r.length === 1 && ++cnt === 2));
sv
.call([], 0, (_, r) => assert(r.length === 0 && ++cnt === 3) || sv.terminate() || done());
sv.call([], 1, 0, (_, r) => assert(r.length === 1 && ++cnt === 1) || r[0].then(n => assert(n === 1 && ++cnt === 4)));
sv.call([], 2, 0, (_, r) => assert(r.length === 1 && ++cnt === 2) || r[0].then(n => assert(n === 2 && ++cnt === 5) || sv.terminate() || done()));
sv.call([], 3, 0, (_, r) => assert(r.length === 0 && ++cnt === 3));
});

@@ -194,7 +213,9 @@

let cnt = 0;
const sv = new Supervisor<string, number, number>('', [], 0, reason => {
assert(reason === void 0);
assert(Supervisor.count === 1);
assert(Supervisor.procs === 0);
++cnt;
const sv = new Supervisor<string, number, number>({
destructor: reason => {
assert(reason === void 0);
assert(Supervisor.count === 1);
assert(Supervisor.procs === 0);
++cnt;
}
});

@@ -201,0 +222,0 @@ sv.register([], _ => _);

@@ -1,2 +0,2 @@

import {Supervisor as ISupervisor} from 'arch-stream';
import {Supervisor as ISupervisor, SupervisorSettings} from 'arch-stream';
import {Observable} from './observable';

@@ -54,12 +54,41 @@ import {isThenable} from './thenable';

}
constructor(
public name = 'anonymous',
depss: [T[], T[][]][] = [],
private timeout: number = 0,
private destructor: (reason?: any) => any = noop
) {
void depss.reduce((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0);
constructor({
name = 'anonymous',
dependencies = [],
retry = false,
timeout = 0,
destructor = noop
}: SupervisorSettings<T> = {}) {
this.name = name;
void dependencies.reduce((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0);
this.retry = retry;
this.timeout = timeout;
this.destructor_ = destructor;
void ++SupervisorCounter;
}
private destructor(reason: any): void {
void this.checkState();
this.registerable = false;
if (this.procs.refs([]).length > 0) {
void this.terminate([], reason);
}
this.alive = false;
while (this.queue.length > 0) {
const [namespace, data] = this.queue.shift();
void this.events.loss.emit(namespace, [namespace, void 0, data]);
}
try {
void this.destructor_(reason);
}
catch (err) {
void console.error(err, err + '');
}
void --SupervisorCounter;
void Object.freeze(this);
}
public name: string;
private deps: Set<T, T[][]> = new Set<T, T[][]>();
private retry: boolean;
private timeout: number;
private destructor_: (reason?: any) => any;
public events = {

@@ -71,16 +100,13 @@ exec: new Observable<T, Supervisor.Event.Data.Exec<T, D, R>, any>(),

private procs: Observable<T, WorkerCommand<T, D>, R> = new Observable<T, WorkerCommand<T, D>, R>();
private state = true;
private alive = true;
private registerable = true;
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();
const worker = new Worker(this, this.procs, namespace, process, parallel, this.deps.get(namespace) || []);
void ++ProcessCounter;
void this.procs
.on(namespace, worker.receive);
void this.events.exec
.emit(namespace, [namespace, process]);
void Tick(_ => this.drain());
return worker.terminate;
}
public call(namespace: T[], data: D, callback: (data: D, results: R[]) => any = noop, timeout = this.timeout): void {
public call(namespace: T[], data: D, timeout = this.timeout, callback?: (data: D, results: R[]) => any): void {
void this.checkState();

@@ -94,4 +120,5 @@ namespace = namespace.slice();

}
public cast(namespace: T[], data: D): R[] {
return this.procs.reflect(namespace, new WorkerCommand_$Call(data));
public cast(namespace: T[], data: D, retry = this.retry): R[] {
const results = this.procs.reflect(namespace, new WorkerCommand_$Call(data));
return results.length > 0 || !retry ? results : this.cast(namespace, data, false);
}

@@ -111,22 +138,14 @@ public refs(namespace: T[]): [T[], (data: D) => R, (reason: any) => void][] {

void this.checkState();
if (namespace === void 0) {
this.registerable = false;
}
void this.procs
.emit(namespace || [], new WorkerCommand_$Exit(reason))
.off(namespace || []);
if (namespace) return;
this.state = false;
while (this.queue.length > 0) {
const [namespace, data] = this.queue.shift();
void this.events.loss.emit(namespace, [namespace, void 0, data]);
}
try {
if (namespace === void 0) {
void this.destructor(reason);
}
catch (err) {
void console.error(err, err + '');
}
void --SupervisorCounter;
}
private checkState(): void {
if (this.state) return;
throw new Error(`ArchStream: Supervisor: Supervisor ${this.name} already exited.`);
if (!this.alive) throw new Error(`ArchStream: Supervisor: Supervisor ${this.name} already exited.`);
}

@@ -148,7 +167,13 @@ private queue: [T[], D, (data: D, results: R[]) => any, number, number][] = [];

}
void callback(data, results);
if (!callback) continue;
try {
void callback(data, results);
}
catch (err) {
void console.error(err, err + '');
}
}
}
public depsResolvedNamespaces: T[][] = [];
public depsCachedRefs: [T[], (data: WorkerCommand<T, D>) => R, boolean][];
public depsAllRefsCache: [T[], (data: WorkerCommand<T, D>) => R, boolean][];
}

@@ -165,18 +190,32 @@

) {
const receive = this.receive;
this.receive = (cmd?: WorkerCommand<T, D>) => receive.call(this, cmd); // identifier
const terminate = this.terminate;
this.terminate = (reason: any) => terminate.call(this, reason);
this.receive = (cmd?: WorkerCommand<T, D>) => Worker.prototype.receive.call(this, cmd); // identifier
this.terminate = (reason: any) => Worker.prototype.terminate.call(this, reason);
void ++ProcessCounter;
void this.clearCache();
void this.procs
.on(namespace, this.receive);
void this.sv.events.exec
.emit(namespace, [namespace, process]);
}
private destructor(reason: any): void {
void this.checkState();
void this.clearCache();
void this.procs
.off(this.namespace, this.receive);
this.alive = false;
void --ProcessCounter;
void Object.freeze(this);
void this.sv.events.exit
.emit(this.namespace, [this.namespace, this.process, reason]);
}
private alive = true;
private tryDependencyResolving(cmd: WorkerCommand_$Call<D>): void {
if (!this.receive(new WorkerCommand_$Deps(this.namespace))) {
void this.clearCache();
throw void 0;
}
if (this.receive(new WorkerCommand_$Deps(this.namespace))) return;
void this.clearCache();
throw void 0;
}
private clearCache(): void {
this.sv.depsResolvedNamespaces = [];
this.sv.depsCachedRefs = void 0;
this.sv.depsAllRefsCache = void 0;
}

@@ -187,3 +226,3 @@ public receive(): Worker<T, D, R>

public receive(cmd?: WorkerCommand<T, D>): any {
if (!this.alive) throw new Error(`ArchStream: Supervisor: Process ${this.namespace}/${this.process} already exited.`);
void this.checkState();
if (cmd === void 0) {

@@ -194,12 +233,10 @@ return this;

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

@@ -214,3 +251,4 @@ }

void --this.parallel;
void (<PromiseLike<R>><any>result).then(_ => void ++this.parallel, reason => this.terminate(reason));
void (<PromiseLike<R>><any>result)
.then(_ => this.alive ? void ++this.parallel : void 0, reason => this.alive && this.terminate(reason));
}

@@ -231,11 +269,16 @@ return result;

public terminate(reason: any): void {
if (!this.alive) throw new Error(`ArchStream: Supervisor: Process ${this.namespace}/${this.process} cannot terminate multiply with ${reason}.`);
void --ProcessCounter;
void this.clearCache();
this.alive = false;
void this.procs
.off(this.namespace, this.receive);
void this.sv.events.exit
.emit(this.namespace, [this.namespace, this.process, reason]);
void this.destructor(reason);
}
private checkState(): void {
if (!this.alive) throw new Error(`ArchStream: Supervisor: Process ${this.namespace}/${this.process} already exited.`);
}
}
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,3 +6,3 @@ import A, {

Observable,
Supervisor,
Supervisor, SupervisorSettings,
Map, MultiMap,

@@ -9,0 +9,0 @@ Set, MultiSet,

@@ -92,8 +92,3 @@ /**

static procs: number;
constructor(
name?: string,
depss?: [T[], T[][]][],
timeout?: number,
destructor?: (reason?: any) => any
)
constructor(settings?: SupervisorSettings<T>)
name: string;

@@ -106,7 +101,14 @@ events: {

register(namespace: T[], process: (data: D) => R, parallel?: number): (reason?: any) => void;
call(namespace: T[], data: D, callback?: (data: D, results: R[]) => any, timeout?: number): void;
cast(namespace: T[], data: D): R[];
call(namespace: T[], data: D, timeout?: number, callback?: (data: D, results: R[]) => any): void;
cast(namespace: T[], data: D, retry?: boolean): R[];
refs(namespace: T[], data: D): [T[], (data: D) => R, (reason: any) => void][];
terminate(namespace?: T[], reason?: any): void;
}
export interface SupervisorSettings<T> {
name?: string;
dependencies?: [T[], T[][]][];
retry?: boolean;
timeout?: number;
destructor?: (reason?: any) => any;
}
export namespace Supervisor {

@@ -113,0 +115,0 @@ export namespace Event {

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