arch-stream
Advanced tools
Comparing version 0.0.77 to 0.0.78
@@ -1,3 +0,3 @@ | ||
/*! arch-stream v0.0.77 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */ | ||
/*! arch-stream v0.0.78 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/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"]}); | ||
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;)i=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]);n=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:[],rejectedDependencies:[],dependenciesStack:[]},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,this.sharedResource.rejectedDependencies=[],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)))return this.sharedResource.resolvedDependencies=s.concat(this.sharedResource.resolvedDependencies,this.sharedResource.dependenciesStack),void(this.sharedResource.dependenciesStack=[]);throw this.sharedResource.rejectedDependencies=s.concat(this.sharedResource.rejectedDependencies,this.sharedResource.dependenciesStack),void(this.sharedResource.dependenciesStack=[])},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}for(var s=0,c=this.sharedResource.rejectedDependencies;s<c.length;s++){var a=c[s];if(u(this.namespace,a))return!1}for(var h=0,p=this.sharedResource.dependenciesStack;h<p.length;h++){var f=p[h];if(u(this.namespace,f))return!0}return void this.sharedResource.dependenciesStack.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 y=this.process(t.data);return o.isThenable(y)&&(void--this.parallel,void y.then(function(t){return e.alive?void++e.parallel:void 0},function(t){return e.alive&&e.terminate(t)})),y}catch(m){throw void void this.terminate(m)}}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/sqid",["require","exports"],function(t,e){"use strict";function r(t){return void 0===t?(1e15+ ++i+"").slice(1):(1e15+t+"").slice(1)}var i=0;e.sqid=r}),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/sqid","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 b(){return new r.ArchStream}function w(){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.sqid=y.sqid,e.assign=m.assign,e.concat=_.concat;var g={Msg:w,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=b;var b;!function(t){t.Msg=g.Msg,t.Proxy=g.Proxy}(b||(b={})),e.Msg=w}),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"]}); |
43
note.md
@@ -5,2 +5,4 @@ # Note | ||
依存関係の事前条件への変換、依存関係の直列化および依存関係数制限によりシーケンスの依存関係が保証されたアーキテクチャを構築する。 | ||
モジュールの利用、実行時に参照する情報および情報の処理分担を宣言的に制約することで分割された各機能およびコンポーネントを保守拡張するために必要となる知識を当該箇所に局所化し最小化する。 | ||
ArchStreamが設計に代表される静的問題解決を担うほか、ジョブ・集合・コンポーネントの生成管理などの動的問題解決をSupervisorが担う。 | ||
@@ -28,3 +30,3 @@ このライブラリはストリーム以外にメッセージング、タイマー、バックグラウンドスレッド代用のSupervisorとObserverなどドメイン駆動設計に必要となる機能をまとめたDDD用ツールボックスとなっている。 | ||
インポート後エクスポート前のストリーム。 | ||
モジュラーストリームを合成可能なストリーム。 | ||
合成先となる唯一のストリーム。 | ||
@@ -34,3 +36,3 @@ ### モジュラーストリーム | ||
エクスポート後のストリーム。 | ||
合成可能な唯一のストリーム。 | ||
合成元となる唯一のストリーム。 | ||
入出力可能な唯一のストリーム。 | ||
@@ -54,3 +56,3 @@ | ||
具体的な処理を定義可能なストリーム。 | ||
具体的な処理を定義可能な前述のストリーム。 | ||
@@ -85,3 +87,3 @@ ### エンティティ | ||
### コマンドクエリ責務区分 | ||
### 実体定義区分 | ||
@@ -94,3 +96,3 @@ パイプラインに定義された関数部分。 | ||
ストリームによりエンティティを終端まで運び、経路の知識によりコマンドの実行またはクエリ結果の挿入を行う。 | ||
ストリームによりエンティティを終端まで運び、経路の知識によりコマンドの実行やクエリ結果の挿入といった処理を行う。 | ||
ストリームのエンティティの型は不変であり経路で型を変更できない。 | ||
@@ -102,4 +104,4 @@ ストリームのメソッドはコールバックの戻り値を無視し経路でエンティティの参照(実体の同一性)を変更できない。 | ||
入出力を各1箇所に限定し、パイプラインがエンティティの種類ごとに構築するものである都合上、独立した多数の機能やアクセスポイントの提供を目的とするモデルへの適用は難しい。 | ||
目安として入力データが概ね情報量を減らさずにプログラムの大部分を通過するようなデータ処理的なプログラムに適しており、 | ||
反対に入力データを分解して浸透させるまたはプログラムを駆動させるような副作用を主体とするプログラムには適していない。 | ||
目安として入力データが概ね情報量を減らさずに処理の大部分を通過するようなデータ処理的なレイヤーに適しており、 | ||
反対に入力データを分解して浸透させるまたは処理を駆動させるような副作用を主体とするレイヤーには適していない。 | ||
@@ -110,10 +112,8 @@ ### 運搬責務分離 | ||
それ以外の中継的な関数を最深部の関数までエンティティを運搬することにのみ責務を負わせて関数の責務を分離することで真に依存関係があり呼びだされる関数の数とその組み合わせサイズを最小化する。 | ||
これによりドメイン指向設計のレイヤー化アーキテクチャとCQRSによる構造分割をさらに進める。 | ||
CQRSが垂直方向の分離とすると運搬責務による分離は水平方向の分離となる。 | ||
依存関係を木構造で表すならば、ノードがモジュラーストリームのみ存在する運搬責務区分、リーフが具体的処理を行う関数とそれを追加するストリームのみ存在するコマンドクエリ責務区分に区分される。 | ||
さらに正確にはリーフをコマンドクエリ責務区分の依存関係の木構造に置き換えて運搬責務区分の木構造に接続した構造が適切である。 | ||
運搬責務区分の関数はパイプラインの安定的な静的構造を構築する以外の機能を持たないためコマンドクエリ責務区分である末端のモジュールに個別に関心を持つ限り上部のコマンドクエリ責務区分の中を見る必要がない。 | ||
依存関係を木構造で表すならば、ノードがモジュラーストリームのみ存在する運搬責務区分、リーフが具体的処理実体の定義である関数とそれを追加するストリームのみ存在する実体定義区分に区分される。 | ||
運搬責務区分の関数はパイプラインの安定的な静的構造を構築する以外の機能を持たないため実体定義区分である末端のモジュールに個別に関心を持つ際に上部の運搬責務区分の中を見る必要がない。 | ||
ストリームの実装においても末端の処理が集積されるルート以外のモジュラーストリームはパイプライン構築後の稼動時において何の機能も持たず実質的に空のストリームであり、 | ||
運搬責務区分の関数は構築時にしか使用されないため稼動時には実質的に消滅し、コマンドクエリ責務区分の関数だけが残る。 | ||
運搬責務区分の関数は構築時にしか使用されないため稼動時には実質的に消滅し、実体定義区分の関数だけが残る。 | ||
依存関係の木構造はディレクトリー構造と一致させると依存関係を管理しやすい。 | ||
@@ -138,3 +138,2 @@ | ||
こうした他のストリームへ分離隠蔽された依存関係の適用を自身のストリーム内で確認するには当該依存関係担当箇所のデータが要件を満たすことを事前条件として表明すれば足り、依存関係は各構造の最深部に分割して凝集隔離隠蔽される。 | ||
ストリームがデータの型が不変である型不変のストリームであることでストリーム全体に単一の運搬責務が設定可能となり、この変換により依存関係を削除できる範囲が最大化される。 | ||
@@ -145,13 +144,11 @@ ### 依存関係の直列化と保証 | ||
モジュラーストリームはデフォルトで1回しか合成できないため、このときパイプラインを構成するモジュールの依存関係がパイプライン内で完結密閉され外部に流失していないことも保証される。 | ||
複数回の合成においても合成回数を指定することで依存関係を意図せず拡散して張り巡らされないよう管理下に置く。 | ||
複数回の合成においても合成回数を指定することで依存関係を意図せず拡散して張り巡らされないよう管理下に置ける。 | ||
依存関係の構成要素であるモジュールを個別にテストする場合はテスト事項がモジュール内で完結しないため事後条件を使用するべきとなる。 | ||
ブラックボックステストにおいても事前条件を満たすエンティティの生成と依存するモジュールの仕様変更に伴うエンティティの修正といったコストが生じる。 | ||
このようにモジュールのブラックボックステストはコストが高いため、パイプラインのブラックボックステストとこれを構成するモジュールのホワイトボックステストを組み合わせるのが効率のよいアプローチとなる。 | ||
モジュールの順序が固定されるため、単純な事後条件を直後の依存関係の事前条件に代える最適化も検討できる。 | ||
依存関係の構成要素であるモジュールは合成回数の制約がある都合上個別にテストできない。 | ||
ストリームのテストはモジュール全体であるパイプラインのブラックボックステストとこれを構成する各モジュールのホワイトボックステストを組み合わせることになる。 | ||
### 複雑化の防止 | ||
APIをコマンドとクエリに変換し、入出力ともに1つに固定された単一のパイプラインの順次処理で表現することで各工程で必要な処理を明確化し、依存関係と分岐処理の組み合わせサイズの増大を抑える。 | ||
内部APIは使用される組み合わせがパイプラインにより固定されるため、テストにおいてAPIの組み合わせを網羅する必要がなく、パイプラインに対してユニットテストを行えば足りる。 | ||
入出力ともに1つに固定された単一のパイプラインの順次処理で表現することで各工程で必要な処理を明確化し、依存関係と分岐処理の組み合わせサイズの増大を抑える。 | ||
内部APIの使用される組み合わせがパイプラインにより固定されるため、テストにおいてAPIの組み合わせを網羅する必要がなく、パイプラインに対してユニットテストを行えば足りる。 | ||
モジュラーストリームは複雑化の回避のためデフォルトで1回しか合成できないよう制限されている。 | ||
@@ -174,3 +171,2 @@ | ||
- Nodeとブラウザーの両方で動作するがブラウザーアプリケーションをメインターゲットとする。 | ||
- 入出力ともに1つしか存在せず、APIはコマンドまたはクエリに変換しなければならない。 | ||
- 出力を読み込めるのは1関数のみで2つ以上の関数に出力することはできない。 | ||
@@ -394,2 +390,7 @@ - 入出力データにエンティティを使用することを前提としており、接続するすべてのストリームの型が同じでなければならない。 | ||
### sqid | ||
シーケンシャルなIDを生成する。 | ||
IDは1からインクリメントする数値を0パディングで15桁にそろえた文字列である。 | ||
### Maybe | ||
@@ -396,0 +397,0 @@ |
{ | ||
"name": "arch-stream", | ||
"version": "0.0.77", | ||
"version": "0.0.78", | ||
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.", | ||
@@ -44,3 +44,3 @@ "private": false, | ||
"extend": "^3.0.0", | ||
"gulp": "^3.9.0", | ||
"gulp": "^3.9.1", | ||
"gulp-cached": "^1.1.0", | ||
@@ -53,4 +53,4 @@ "gulp-footer": "^1.0.5", | ||
"gulp-tslint": "^4.3.1", | ||
"gulp-typescript": "^2.10.0", | ||
"gulp-uglify": "^1.5.1", | ||
"gulp-typescript": "^2.11.0", | ||
"gulp-uglify": "^1.5.2", | ||
"gulp-unassert": "^1.0.0", | ||
@@ -67,3 +67,3 @@ "intelli-espower-loader": "^1.0.1", | ||
"karma-mocha": "^0.2.1", | ||
"lodash": "^4.2.1", | ||
"lodash": "^4.3.0", | ||
"mocha": "^2.4.5", | ||
@@ -75,3 +75,3 @@ "npm-check-updates": "^2.5.8", | ||
"tslint": "^3.3.0", | ||
"typescript": "^1.9.0-dev.20160205" | ||
"typescript": "^1.9.0-dev.20160212" | ||
}, | ||
@@ -78,0 +78,0 @@ "engines": { |
@@ -103,2 +103,3 @@ # ArchStream | ||
- uuid | ||
- sqid | ||
- Maybe, Just, Nothing | ||
@@ -105,0 +106,0 @@ - Either, Left, Right |
@@ -19,2 +19,3 @@ /* tslint:disable:no-unused-variable */ // tslint bug. https://github.com/palantir/tslint/issues/684 | ||
export {v4 as uuid} from './lib/uuid'; | ||
export {sqid} from './lib/sqid'; | ||
export {assign} from './lib/assign'; | ||
@@ -25,3 +26,3 @@ export {concat} from './lib/concat'; | ||
Msg, | ||
Proxy: Proxy // tslint bug. https://github.com/palantir/tslint/issues/684 | ||
Proxy | ||
}; | ||
@@ -28,0 +29,0 @@ |
@@ -177,3 +177,3 @@ import {IObservableObserver, IObservableSubscriber, IObservablePublisher} from 'arch-stream'; | ||
while (parent) { | ||
void concat(registers, parent.registers); | ||
registers = concat(registers, parent.registers); | ||
parent = parent.parent; | ||
@@ -188,3 +188,3 @@ } | ||
const below = this.refsBelow_(childrenMap[name]); | ||
void concat(registers, below); | ||
registers = concat(registers, below); | ||
if (below.length === 0) { | ||
@@ -191,0 +191,0 @@ delete childrenMap[name]; |
@@ -12,2 +12,4 @@ import {Supervisor as ISupervisor, SupervisorSettings} from 'arch-stream'; | ||
resolvedDependencies: T[][]; | ||
rejectedDependencies: T[][]; | ||
dependenciesStack: T[][]; | ||
allRefsCache?: [T[], (data: WorkerCommand<T, D>) => R, boolean][]; | ||
@@ -93,3 +95,5 @@ } | ||
procs: this.procs, | ||
resolvedDependencies: [] | ||
resolvedDependencies: [], | ||
rejectedDependencies: [], | ||
dependenciesStack: [] | ||
}; | ||
@@ -210,2 +214,3 @@ public register(namespace: T[], process: (data: D) => R, parallel?: number): (reason?: any) => void { | ||
this.sharedResource.allRefsCache = void 0; | ||
this.sharedResource.rejectedDependencies = []; | ||
void ++ProcessCounter; | ||
@@ -230,5 +235,12 @@ void this.sharedResource.procs | ||
private tryDependencyResolving(cmd: WorkerCommand_$Call<D>): void { | ||
if (this.receive(new WorkerCommand_$Deps(this.namespace))) return; | ||
this.sharedResource.resolvedDependencies = []; | ||
throw void 0; | ||
if (this.receive(new WorkerCommand_$Deps(this.namespace))) { | ||
this.sharedResource.resolvedDependencies = concat(this.sharedResource.resolvedDependencies, this.sharedResource.dependenciesStack); | ||
this.sharedResource.dependenciesStack = []; | ||
return; | ||
} | ||
else { | ||
this.sharedResource.rejectedDependencies = concat(this.sharedResource.rejectedDependencies, this.sharedResource.dependenciesStack); | ||
this.sharedResource.dependenciesStack = []; | ||
throw void 0; | ||
} | ||
} | ||
@@ -248,3 +260,9 @@ public receive(): Worker<T, D, R> | ||
} | ||
void this.sharedResource.resolvedDependencies.push(this.namespace); | ||
for (const rejected of this.sharedResource.rejectedDependencies) { | ||
if (equal(this.namespace, rejected)) return false; | ||
} | ||
for (const stacked of this.sharedResource.dependenciesStack) { | ||
if (equal(this.namespace, stacked)) return true; | ||
} | ||
void this.sharedResource.dependenciesStack.push(this.namespace); | ||
return this.dependencies | ||
@@ -251,0 +269,0 @@ .every(dep => |
@@ -13,2 +13,3 @@ import A, { | ||
uuid, | ||
sqid, | ||
Maybe, Just, Nothing, | ||
@@ -163,7 +164,9 @@ Either, Left, Right, | ||
it('uuid', function () { | ||
assert(typeof uuid() === 'string'); | ||
assert(uuid().length === 36); | ||
assert(uuid() !== uuid()); | ||
assert(typeof uuid === 'function'); | ||
}); | ||
it('sqid', function () { | ||
assert(typeof sqid === 'function'); | ||
}); | ||
it('assign', function () { | ||
@@ -170,0 +173,0 @@ assert(typeof assign === 'function'); |
10
tsd.json
@@ -9,17 +9,17 @@ { | ||
"mocha/mocha.d.ts": { | ||
"commit": "c393f8974d44840a6c9cc6d5b5c0188a8f05143d" | ||
"commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" | ||
}, | ||
"empower/empower.d.ts": { | ||
"commit": "c393f8974d44840a6c9cc6d5b5c0188a8f05143d" | ||
"commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" | ||
}, | ||
"power-assert/power-assert.d.ts": { | ||
"commit": "c393f8974d44840a6c9cc6d5b5c0188a8f05143d" | ||
"commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" | ||
}, | ||
"power-assert-formatter/power-assert-formatter.d.ts": { | ||
"commit": "c393f8974d44840a6c9cc6d5b5c0188a8f05143d" | ||
"commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" | ||
}, | ||
"benchmark/benchmark.d.ts": { | ||
"commit": "c393f8974d44840a6c9cc6d5b5c0188a8f05143d" | ||
"commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4" | ||
} | ||
} | ||
} |
@@ -318,2 +318,3 @@ /** | ||
export function uuid(): string | ||
export function sqid(id?: number): string | ||
export function assign<T extends Object>(target: T | {}, sources: T[]): T | ||
@@ -320,0 +321,0 @@ export function concat<T>(target: T[], source: T[]): T[] |
Sorry, the diff of this file is too big to display
276326
73
6488
253