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.67 to 0.0.68

117

dist/arch-stream.js

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

/*! arch-stream v0.0.67 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! arch-stream v0.0.68 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! Link: MIT Lisence http://www.opensource.org/licenses/mit-license.php */

@@ -211,3 +211,2 @@ define = typeof define === 'function' && define.amd

var _this = this;
done = done || identity;
var msg = new Message();

@@ -231,3 +230,3 @@ this.child_ = void 0;

});
return msg.trans(done);
return msg.trans(done || identity);
};

@@ -880,9 +879,3 @@ return Message;

var event_1 = type;
if (typeof event_1.namespace === 'string') {
return event_1.namespace ? this.formatEventType_(event_1.namespace.toString().split(this.separator_).concat([event_1.type + ''])) : this.formatEventType_(event_1.type);
}
if (Array.isArray(event_1.namespace)) {
return event_1.namespace ? this.formatEventType_(event_1.namespace.concat([event_1.type])) : this.formatEventType_(event_1.type);
}
return [event_1.type];
return event_1.namespace ? this.formatEventType_(event_1.namespace).concat(this.formatEventType_(event_1.type)) : this.formatEventType_(event_1.type);
}

@@ -978,3 +971,3 @@ return this.separator_ && type ? this.formatEventType_(type.toString().split(this.separator_)) : this.formatEventType_([type]);

var q = queue.shift();
var collection = types.length > 0 ? this.cache_.get(types.join(UNIQUE_SEPARATOR)) || this.cache_.set(types.join(UNIQUE_SEPARATOR), this.collect_(this.seek_(this.node_, types))) : this.collect_(this.seek_(this.node_, types));
var collection = this.cache_.has([void 0].concat(types).join(UNIQUE_SEPARATOR)) ? this.cache_.get([void 0].concat(types).join(UNIQUE_SEPARATOR)) : this.cache_.set([void 0].concat(types).join(UNIQUE_SEPARATOR), this.collect_(this.seek_(this.node_, types)));
var results = [];

@@ -1006,3 +999,3 @@ try {

var _this = this;
void names.reduce(function (_, __, i, names) {
void [void 0].concat(names).reduce(function (_, __, i, names) {
return void _this.cache_.delete(names.slice(0, i + 1).join(UNIQUE_SEPARATOR));

@@ -1066,21 +1059,47 @@ }, void 0);

'use strict';
var AbstractWorkerCommand = function () {
function AbstractWorkerCommand() {
}
return AbstractWorkerCommand;
}();
var WorkerCommand_$Call = function (_super) {
__extends(WorkerCommand_$Call, _super);
function WorkerCommand_$Call(data) {
_super.call(this);
this.data = data;
}
return WorkerCommand_$Call;
}(AbstractWorkerCommand);
var WorkerCommand_$Exit = function (_super) {
__extends(WorkerCommand_$Exit, _super);
function WorkerCommand_$Exit(reason) {
_super.call(this);
this.reason = reason;
}
return WorkerCommand_$Exit;
}(AbstractWorkerCommand);
var Supervisor = function () {
function Supervisor() {
this.observer_ = new observable_1.Observable();
this.counter_ = 0;
this.monitor = new observable_1.Observable();
this.event = new observable_1.Observable();
this.children = new observable_1.Observable();
}
Supervisor.prototype.register = function (process, name) {
if (name === void 0) {
name = [];
}
Supervisor.prototype.register = function (name, process) {
var worker = new Worker(this, name.slice(), process);
void this.observer_.on(name, function (data) {
return worker.receive(data);
}, function (f) {
return f === process;
});
void this.children.on(name, worker.receive);
void this.monitor.emit('exec', [
name,
process,
void 0
]);
void this.event.emit(name, [
'exec',
name,
process,
void 0
]);
return worker.terminate.bind(worker);
};
Supervisor.prototype.call = function (name, data, callback) {
var results = this.observer_.reflect(name, data);
var results = this.children.reflect(name, new WorkerCommand_$Call(data));
if (results.length === 0)

@@ -1094,10 +1113,13 @@ throw new Error('ArchStream: Supervisor: Process does not exist in ' + name);

Supervisor.prototype.cast = function (name, data, callback) {
void this.observer_.emit(name, data, callback);
void this.children.emit(name, new WorkerCommand_$Call(data), function (_a, results) {
var data = _a.data;
return callback(data, results);
});
return this;
};
Supervisor.prototype.terminate = function (name, process) {
Supervisor.prototype.terminate = function (name, reason) {
if (name === void 0) {
name = [];
}
void this.observer_.off(name, process);
void this.children.emit(name, new WorkerCommand_$Exit(reason));
return this;

@@ -1113,18 +1135,37 @@ };

this.process = process;
this.receive = this.receive.bind(this);
}
Worker.prototype.receive = function (data) {
try {
var result = this.process(data);
if (thenable_2.isThenable(result)) {
var thenable = result;
void thenable.then(void 0, this.terminate.bind(this));
Worker.prototype.receive = function (cmd) {
if (cmd instanceof WorkerCommand_$Call) {
try {
var result = this.process(cmd.data);
if (thenable_2.isThenable(result)) {
var thenable = result;
void thenable.then(void 0, this.terminate.bind(this));
}
return result;
} catch (reason) {
void this.terminate(reason);
}
return result;
} catch (err) {
void this.terminate();
throw void 0;
}
if (cmd instanceof WorkerCommand_$Exit) {
void this.terminate(cmd.reason);
throw void 0;
}
throw new TypeError();
};
Worker.prototype.terminate = function () {
void this.parent.terminate(this.name, this.process);
Worker.prototype.terminate = function (reason) {
void this.parent.children.off(this.name, this.receive);
void this.parent.event.emit(this.name, [
'exit',
this.name,
this.process,
reason
]);
void this.parent.monitor.emit('exit', [
this.name,
this.process,
reason
]);
};

@@ -1131,0 +1172,0 @@ return Worker;

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

/*! arch-stream v0.0.67 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! arch-stream v0.0.68 https://github.com/falsandtru/arch-stream | (c) 2015, falsandtru | MIT Licence */
/*! Link: MIT Lisence http://www.opensource.org/licenses/mit-license.php */
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="arch-stream",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?window[i]=window[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||window[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)if(s)for(;2>o;)void Promise.resolve().then(r),void++o;else for(;o<u.length;)void setTimeout(r,u[o%u.length]),void++o}t.queue=e;var n=[],o=0,s="function"==typeof Promise,u=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/message",["require","exports","src/lib/thenable","src/lib/tick"],function(t,e,r,i){"use strict";function n(t){return t}var o=Object.create(null),s=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=o,this.collection_=[],this.transform_=!1,this.listeners_=[],t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){if(this.collection_.length>0)return this.collection_;var t=this,e=[];do void e.push(t);while(t=t.child_);return this.collection_=e},t.prototype.transport_=function(t,e){function i(t,i,u){function c(t){o=!0,i=u?t:i,s&&n.child_&&void n.child_.send(i,e)}return t.every(function(t){n=t,n.memory_=i;var e=n.listener(n.memory_);return r.isThenable(e)?(o=!1,void e.then(c,c),o):(i=u?e:i,!0)})}var n,o=!1,s=!1,u=i(this.collect_(),t,this.transform_);s=!0,u&&"function"==typeof e&&void e(t)},t.prototype.clone=function(){function e(r){return r.parent?new t(e(r.parent),r.listener):new t(void 0,r.listener)}return e(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e,r){switch(!0){case"function"==typeof e:return this.send(t,!1,e);case e===!0:return void i.Tick(this.transport_.bind(this,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;e=e||n;var o=new t;return this.child_=void 0,this.listener=n,this.listeners_.push(o),this.trans(function(t){var e=i.listeners_;i.listeners_=[],function r(){try{for(;e.length>0;)e.shift().send(t)}catch(i){void console.error(i),void r()}}()}),o.trans(e)},t}();e.Message=s}),define("src/lib/throttle",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return void this.processing_.push(t),void this.resolver_(t),!0;this.queue_.push(t);do void this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?void this.processing_.splice(e,1):void this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&void this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/stream/modular",["require","exports","src/lib/throttle","src/lib/tick","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,this.read=this.read.bind(this),this.write=this.write.bind(this),void i.Tick(function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}void this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){void--this.count,this.count<0&&void this.throwCountExceededError(),void this.compose_(),void this.last_.recv(t)},t.prototype.read=function(t){var e=this;void 0===t&&(t=n.noop);var r=!1;return void this.read_(function(n){e.flow_&&void i.Tick(function(){return void e.flow_.dequeue(n)}),r&&void t(n)}),r=!0,this},t.prototype.write_=function(t,e){void this.first_.send(t,e)},t.prototype.write=function(t,e){return this.flow_?void this.flow_.enqueue(t):void this.write_(t,e),this},t.prototype.flow=function(t,e,i){var n=this;return void 0===e&&(e=1/0),this.flow_=new r["default"],void this.flow_.flow(t,e,i),void this.flow_.register(function(t){return n.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();e.ModularStream=o}),define("src/stream/compose",["require","exports","src/stream/modular"],function(t,e,r){"use strict";var i=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){var e=this.procs_.length;return void t.reduceRight(function(t,r,i){return t[i+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var i=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return i.extract_(t)instanceof r?e(t):0})),void--e.count,e.count<0&&void e.throwCountExceededError(),void this.register(e.procs),this},t.prototype["export"]=function(t){return new r.ModularStream(this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(void--t.count,void this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(void--t.count,void this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();e.ComposeStream=i}),define("src/stream/transform",["require","exports","src/lib/message","src/stream/compose","src/stream/modular"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e){var i=this;void 0===e&&(e=new r.Message),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return i.proxy(function(){return e})},void 0)}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof n.ModularStream?(new i.ComposeStream)["import"](t,e):new i.ComposeStream(t)},t.prototype["export"]=function(t){return(new i.ComposeStream).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,i,n){function o(t){return Array.isArray(t)?t:[t]}var s=e.proxies_.filter(function(t){return"function"==typeof t[i]}).reduce(function(t,e){return o(e[i].apply(void 0,t)||t)},n),u="pipe";switch(i){case u:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[i]).call.apply(c,[r(e,u,s)].concat(n));default:return r(e,u,s)}var c}var i=this,n="function"==typeof e?e():e;return this.proxies_.push(n),void Object.keys(n).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof n[t]}).reduce(function(t,e){return i[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];return r(i,e,t)}},void 0),this},t}();e.ArchStream=o}),define("src/proxy/case",["require","exports"],function(t,e){"use strict";function r(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var n=+i[e(r)+""];n>-1&&n<t.length&&t[n](r)}}var i=Object.create(null);return void t.reduce(function(t,e,r){return i[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/proxy/hook",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),s(e)}})}var i=t.pre,n=void 0===i?r.noop:i,o=t.post,s=void 0===o?r.noop:o;return function(t){return{pipe:e}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/proxy/responsibility",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(){function t(t,i){return e.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r-0]=arguments[r];return e.map(function(e){return function(r){if(!(i(r)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity.\n "+i(r).constructor);e(r)}})},e["export"]=function(){return function(e){i(e)instanceof t&&void Object.freeze(i(e))}},r.noop}var e;return function(r){return e={rule:t}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/lib/proxy",["require","exports","src/proxy/case","src/proxy/hook","src/proxy/responsibility"],function(t,e,r,i,n){"use strict";e.Proxy={Case:r["default"],Hook:i["default"],Responsibility:n["default"]}}),define("src/lib/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,p=t.task,h=void 0===p?function(){}:p,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;i=0>i?-i:i,void setTimeout(function(){try{if(a()){var t=h();if(d())return void v(t)}}catch(e){return void y(e)}var n=u(i);return n>o?void b():void void r({precond:a,task:h,postcond:d,complete:v,timeout:b,begin:i+n,end:o-n,step:u})},i)}e.Timer=r}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("ArchStream: uuid: Invalid uuid dynamic seed.");return o.map(function(e){if("x"!==e&&"y"!==e)return e;var r=Math.random()*t%16|0,i="x"==e?r:3&r|8;return i.toString(16)}).join("").toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("ArchStream: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split(""),s=n;e.v4=i}),define("src/lib/map",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[t+""]},t.prototype.set=function(t,e){return this.type_||(this.type_=typeof t),void this.reset_(),this.map_[t+""]=e},t.prototype.has=function(t){return!!this.map_[t+""]||t+""in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[t+""],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["number"===t.type_?+e:e,t.map_[e]]})},t}();e.Map=r}),define("src/lib/observable",["require","exports","src/lib/map","src/lib/uuid","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=i.v4(),s=function(){function t(t){this.separator_=t,this.node_={map:Object.create(null),list:[]},this.cache_=new r.Map,this.emitId_=0,this.emitQueue_=[]}return t.prototype.formatEventType_=function(t){if(Array.isArray(t))return t;if(t instanceof Object){var e=t;return"string"==typeof e.namespace?e.namespace?this.formatEventType_(e.namespace.toString().split(this.separator_).concat([e.type+""])):this.formatEventType_(e.type):Array.isArray(e.namespace)?e.namespace?this.formatEventType_(e.namespace.concat([e.type])):this.formatEventType_(e.type):[e.type]}return this.separator_&&t?this.formatEventType_(t.toString().split(this.separator_)):this.formatEventType_([t])},t.prototype.on=function(t,e,r){void 0===r&&(r=function(t){return t===e});var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(this.node_,i).list.push([e,r,this.emitId_]),void this.drain_(i),this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seek_(this.node_,r).list.some(function(t,r,i){var n=t[1];if(!n(e))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_(this.node_,r);return i.map=Object.create(null),i.list=[],void this.cache_.clear(),this;default:throw this.throwTypeErrorIfInvalidSubscriber_(e,r)}},t.prototype.once=function(t,e){var r=this,i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),this.on(t,function(i){return void r.off(t,e),e(i)},function(t){return t===e})},t.prototype.emit=function(t,e,r){return void 0===e&&(e=n.noop),void 0===r&&(r=n.noop),t instanceof Object&&!Array.isArray(t)?this.emit_(this.formatEventType_(t),t,e):this.emit_(this.formatEventType_(t),e,r)},t.prototype.emit_=function(t,e,r){void 0===r&&(r=n.noop);var i=this.emitQueue_;return void i.push([++this.emitId_,e,r]),void this.drain_(t),this},t.prototype.drain_=function(t){for(var e=this.emitQueue_;e.length>0;){var r=e.shift(),i=t.length>0?this.cache_.get(t.join(o))||this.cache_.set(t.join(o),this.collect_(this.seek_(this.node_,t))):this.collect_(this.seek_(this.node_,t)),n=[];try{void i.reduce(function(t,e){var r=t[0],i=t[1],o=e[0],s=e[2];return s>=r?t:(e[2]=r,void n.push(o(i)),t)},r)}catch(s){void e.unshift(r),void 0!==s&&null!==s&&void console.error(s);continue}var u=r[1],c=r[2];void c(u,n)}return this.resetEmitIdIfPossible_(),this},t.prototype.seek_=function(t,e){function r(t,e){var r=t.map;return r[e+""]?r[e+""]:r[e+""]={map:Object.create(null),list:[]}}var i=this;return void e.reduce(function(t,e,r,n){return void i.cache_["delete"](n.slice(0,r+1).join(o))},void 0),e.reduce(r,t)},t.prototype.collect_=function(t){var e=this,r=t.map,i=t.list;return Object.keys(r).reduce(function(t,i){return void t.unshift.apply(t,e.collect_(r[i])),0===t.length&&delete r[i],t},i.slice())},t.prototype.resetEmitIdIfPossible_=function(){return this.emitId_<5e8||this.emitQueue_.length>0?this:(void this.collect_(this.node_).reduce(function(t,e){return e[2]=t},this.emitId_=0),this)},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("ArchStream: Observable: Invalid subscriber.\n "+t)}},t.prototype.reflect=function(t,e){var r;return void this.emit(t,e,function(t,e){return r=e}),r},t}();e.Observable=s}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/thenable"],function(t,e,r,i){"use strict";var n=function(){function t(){this.observer_=new r.Observable,this.counter_=0}return t.prototype.register=function(t,e){void 0===e&&(e=[]);var r=new o(this,e.slice(),t);return void this.observer_.on(e,function(t){return r.receive(t)},function(e){return e===t}),r.terminate.bind(r)},t.prototype.call=function(t,e,r){var i=this.observer_.reflect(t,e);if(0===i.length)throw new Error("ArchStream: Supervisor: Process does not exist in "+t);return r&&void r(e,i),this},t.prototype.cast=function(t,e,r){return void this.observer_.emit(t,e,r),this},t.prototype.terminate=function(t,e){return void 0===t&&(t=[]),void this.observer_.off(t,e),this},t}();e.Supervisor=n;var o=function(){function t(t,e,r){this.parent=t,this.name=e,this.process=r}return t.prototype.receive=function(t){try{var e=this.process(t);if(i.isThenable(e)){var r=e;void r.then(void 0,this.terminate.bind(this))}return e}catch(n){throw void void this.terminate()}},t.prototype.terminate=function(){void this.parent.terminate(this.name,this.process)},t}()}),define("src/lib/set",["require","exports","src/lib/map"],function(t,e,r){"use strict";var i=function(){function t(t){this.replacer_=t,this.map_=new r.Map}return t.prototype.get=function(t){return this.map_.get(t)},t.prototype.set=function(t,e){if(!this.has(t))return this.map_.set(t,e);if(!this.replacer_)throw new Error("Cannot overwrite value of set without replacer.");return this.map_.set(t,this.replacer_(this.get(t),e))},t.prototype.has=function(t){return this.map_.has(t)},t.prototype["delete"]=function(t){return void this.map_["delete"](t),this},t.prototype.clear=function(){return void this.map_.clear(),this},Object.defineProperty(t.prototype,"size",{get:function(){return this.map_.size},enumerable:!0,configurable:!0}),t.prototype.entries=function(){return this.map_.entries()},t}();e.Set=i}),define("src/lib/monad",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.extract=function(t){return this.evaluate().extract(t)},t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t.prototype.assert=function(t){return this},t}();e.Monad=r}),define("src/lib/maybe.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Maybe: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/maybe",["require","exports","src/lib/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/either.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Either: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/either",["require","exports","src/lib/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/export",["require","exports","src/stream/transform","src/lib/message","src/lib/proxy","src/lib/proxy","src/lib/tick","src/lib/timer","src/lib/fingerprint","src/lib/uuid","src/lib/observable","src/lib/supervisor","src/lib/map","src/lib/set","src/lib/maybe","src/lib/either","./typings/arch-stream.d"],function(t,e,r,i,n,o,s,u,c,a,p,h,f,d,l,v){"use strict";function _(){return new r.ArchStream}function y(){return new i.Message}e.Proxy=o.Proxy,e.Tick=s.Tick,e.Timer=u.Timer,e.FINGERPRINT=c.FINGERPRINT,e.uuid=a.v4,e.Observable=p.Observable,e.Supervisor=h.Supervisor,e.Map=f.Map,e.Set=d.Set,e.Maybe=l.Maybe,e.Just=l.Just,e.Nothing=l.Nothing,e.Either=v.Either,e.Left=v.Left,e.Right=v.Right;var m={Msg:y,Proxy:n.Proxy};Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=_;var _;!function(t){t.Msg=m.Msg,t.Proxy=m.Proxy}(_||(_={})),e.Msg=y}),define("arch-stream",["require","exports","src/export","src/export"],function(t,e,r,i){"use strict";function n(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}n(r),e["default"]=i["default"]});
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="arch-stream",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?window[i]=window[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||window[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)if(s)for(;2>o;)void Promise.resolve().then(r),void++o;else for(;o<u.length;)void setTimeout(r,u[o%u.length]),void++o}t.queue=e;var n=[],o=0,s="function"==typeof Promise,u=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/message",["require","exports","src/lib/thenable","src/lib/tick"],function(t,e,r,i){"use strict";function n(t){return t}var o=Object.create(null),s=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=o,this.collection_=[],this.transform_=!1,this.listeners_=[],t&&(this.parent.child_=this)}return t.prototype.root=function(){return this.parent?this.parent.root():this},t.prototype.collect_=function(){if(this.collection_.length>0)return this.collection_;var t=this,e=[];do void e.push(t);while(t=t.child_);return this.collection_=e},t.prototype.transport_=function(t,e){function i(t,i,u){function c(t){o=!0,i=u?t:i,s&&n.child_&&void n.child_.send(i,e)}return t.every(function(t){n=t,n.memory_=i;var e=n.listener(n.memory_);return r.isThenable(e)?(o=!1,void e.then(c,c),o):(i=u?e:i,!0)})}var n,o=!1,s=!1,u=i(this.collect_(),t,this.transform_);s=!0,u&&"function"==typeof e&&void e(t)},t.prototype.clone=function(){function e(r){return r.parent?new t(e(r.parent),r.listener):new t(void 0,r.listener)}return e(this)},t.prototype.connect=function(t){return this.parent.child_=t,t.parent=this.parent,this},t.prototype.send=function(t,e,r){switch(!0){case"function"==typeof e:return this.send(t,!1,e);case e===!0:return void i.Tick(this.transport_.bind(this,t,r)),this;case e===!1:default:return void this.transport_(t,r),this}},t.prototype.recv=function(e){var r=new t(this);return this.listener=e,this.collection_=[],this.memory_!==o&&void this.send(this.memory_),r},t.prototype.trans=function(t){return this.transform_=!0,this.recv(t)},t.prototype.then=function(e,r){var i=this,o=new t;return this.child_=void 0,this.listener=n,this.listeners_.push(o),this.trans(function(t){var e=i.listeners_;i.listeners_=[],function r(){try{for(;e.length>0;)e.shift().send(t)}catch(i){void console.error(i),void r()}}()}),o.trans(e||n)},t}();e.Message=s}),define("src/lib/throttle",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.queue_=[],this.processing_=[],this.limit_=1/0,this.volume_=1/0}return t.prototype.isDrainable_=function(){return this.processing_.length<this.volume_},t.prototype.discharger_=function(t,e){},t.prototype.flow=function(t,e,r){void 0===e&&(e=1/0),void 0===r&&(r=function(){return null}),this.volume_=t,this.limit_=e,this.discharger_=r},t.prototype.enqueue=function(t){if(this.isDrainable_())return void this.processing_.push(t),void this.resolver_(t),!0;this.queue_.push(t);do void this.discharger_(this.queue_,this.processing_);while(this.processing_.length+this.queue_.length>this.limit_);return!1},t.prototype.dequeue=function(t){var e=this.processing_.indexOf(t);e>0?void this.processing_.splice(e,1):void this.processing_.shift(),this.queue_.length>0&&this.isDrainable_()&&void this.enqueue(this.queue_.shift())},t.prototype.register=function(t){this.resolver_=t},t}();Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/stream/modular",["require","exports","src/lib/throttle","src/lib/tick","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,this.read=this.read.bind(this),this.write=this.write.bind(this),void i.Tick(function(t){return 0<n.count&&n.count<1/0&&n.throwCountDeprivedError()})}return t.prototype.compose_=function(){this.last_=this.procs.map(function(t){return t.clone()}).reduce(function(t,e){return t.connect(e.root())&&e}),this.first_=this.last_.root()},t.prototype.wrap=function(t){function e(e){return function(r){return t(r,e)}}void this.compose_();var r=this.last_;do r=r.parent,r.listener=e(r.listener);while(r.parent);return this.procs=[this.last_],this},t.prototype.read_=function(t){void--this.count,this.count<0&&void this.throwCountExceededError(),void this.compose_(),void this.last_.recv(t)},t.prototype.read=function(t){var e=this;void 0===t&&(t=n.noop);var r=!1;return void this.read_(function(n){e.flow_&&void i.Tick(function(){return void e.flow_.dequeue(n)}),r&&void t(n)}),r=!0,this},t.prototype.write_=function(t,e){void this.first_.send(t,e)},t.prototype.write=function(t,e){return this.flow_?void this.flow_.enqueue(t):void this.write_(t,e),this},t.prototype.flow=function(t,e,i){var n=this;return void 0===e&&(e=1/0),this.flow_=new r["default"],void this.flow_.flow(t,e,i),void this.flow_.register(function(t){return n.write_(t)}),this},t.prototype.throwCountExceededError=function(){throw new Error("ArchStream: Import and read counts are exeeded.")},t.prototype.throwCountDeprivedError=function(){throw this.count=0,new Error("ArchStream: Import and read counts are not deprived.")},t}();e.ModularStream=o}),define("src/stream/compose",["require","exports","src/stream/modular"],function(t,e,r){"use strict";var i=function(){function t(t){this.extract_=t,this.procs_=[],this.branched_=0}return t.prototype.register=function(t){var e=this.procs_.length;return void t.reduceRight(function(t,r,i){return t[i+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var i=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return i.extract_(t)instanceof r?e(t):0})),void--e.count,e.count<0&&void e.throwCountExceededError(),void this.register(e.procs),this},t.prototype["export"]=function(t){return new r.ModularStream(this.procs_,t,this.branched_)},t.prototype.throwErrorIfNotImportable_=function(t,e){e?((t.branched>0||this.branched_>1)&&(void--t.count,void this.throwConditionalImportError()),this.branched_=1):(t.branched>0&&this.branched_>0&&(void--t.count,void this.throwConditionalImportError()),this.branched_=t.branched>0?t.branched+1:t.branched)},t.prototype.throwConditionalImportError=function(){throw new Error("ArchStream: Conditional import cannot call from different streams.")},t}();e.ComposeStream=i}),define("src/stream/transform",["require","exports","src/lib/message","src/stream/compose","src/stream/modular"],function(t,e,r,i,n){"use strict";var o=function(){function t(t,e){var i=this;void 0===e&&(e=new r.Message),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return i.proxy(function(){return e})},void 0)}return t.prototype.pipe=function(e){return new t(this,this.message_.recv(e))},t.prototype["import"]=function(t,e){return t instanceof n.ModularStream?(new i.ComposeStream)["import"](t,e):new i.ComposeStream(t)},t.prototype["export"]=function(t){return(new i.ComposeStream).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,i,n){function o(t){return Array.isArray(t)?t:[t]}var s=e.proxies_.filter(function(t){return"function"==typeof t[i]}).reduce(function(t,e){return o(e[i].apply(void 0,t)||t)},n),u="pipe";switch(i){case u:return t.prototype[i].call(e,s[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[i]).call.apply(c,[r(e,u,s)].concat(n));default:return r(e,u,s)}var c}var i=this,n="function"==typeof e?e():e;return this.proxies_.push(n),void Object.keys(n).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof n[t]}).reduce(function(t,e){return i[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];return r(i,e,t)}},void 0),this},t}();e.ArchStream=o}),define("src/proxy/case",["require","exports"],function(t,e){"use strict";function r(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var n=+i[e(r)+""];n>-1&&n<t.length&&t[n](r)}}var i=Object.create(null);return void t.reduce(function(t,e,r){return i[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r}),define("src/proxy/hook",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(t){function e(){for(var t=[],e=0;e<arguments.length;e++)t[e-0]=arguments[e];return t.map(function(t){return function(e){n(e),t(e),s(e)}})}var i=t.pre,n=void 0===i?r.noop:i,o=t.post,s=void 0===o?r.noop:o;return function(t){return{pipe:e}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/proxy/responsibility",["require","exports","src/lib/noop"],function(t,e,r){"use strict";function i(){function t(t,i){return e.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r-0]=arguments[r];return e.map(function(e){return function(r){if(!(i(r)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity.\n "+i(r).constructor);e(r)}})},e["export"]=function(){return function(e){i(e)instanceof t&&void Object.freeze(i(e))}},r.noop}var e;return function(r){return e={rule:t}}}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}),define("src/lib/proxy",["require","exports","src/proxy/case","src/proxy/hook","src/proxy/responsibility"],function(t,e,r,i,n){"use strict";e.Proxy={Case:r["default"],Hook:i["default"],Responsibility:n["default"]}}),define("src/lib/timer",["require","exports"],function(t,e){"use strict";function r(t){var e=t.begin,i=void 0===e?0:e,n=t.end,o=void 0===n?864e5:n,s=t.step,u=void 0===s?function(t){return 3*(t||1)}:s,c=t.precond,a=void 0===c?function(){return!0}:c,h=t.task,p=void 0===h?function(){}:h,f=t.postcond,d=void 0===f?function(){return!0}:f,l=t.complete,v=void 0===l?function(){return 0}:l,_=t.error,y=void 0===_?function(){return 0}:_,m=t.timeout,b=void 0===m?function(){return 0}:m;i=0>i?-i:i,void setTimeout(function(){try{if(a()){var t=p();if(d())return void v(t)}}catch(e){return void y(e)}var n=u(i);return n>o?void b():void void r({precond:a,task:p,postcond:d,complete:v,timeout:b,begin:i+n,end:o-n,step:u})},i)}e.Timer=r}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("ArchStream: uuid: Invalid uuid dynamic seed.");return o.map(function(e){if("x"!==e&&"y"!==e)return e;var r=Math.random()*t%16|0,i="x"==e?r:3&r|8;return i.toString(16)}).join("").toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("ArchStream: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split(""),s=n;e.v4=i}),define("src/lib/map",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.map_=Object.create(null),this.type_="",void this.reset_()}return t.prototype.get=function(t){return this.map_[t+""]},t.prototype.set=function(t,e){return this.type_||(this.type_=typeof t),void this.reset_(),this.map_[t+""]=e},t.prototype.has=function(t){return!!this.map_[t+""]||t+""in this.map_},t.prototype["delete"]=function(t){return void this.reset_(),delete this.map_[t+""],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["number"===t.type_?+e:e,t.map_[e]]})},t}();e.Map=r}),define("src/lib/observable",["require","exports","src/lib/map","src/lib/uuid","src/lib/noop"],function(t,e,r,i,n){"use strict";var o=i.v4(),s=function(){function t(t){this.separator_=t,this.node_={map:Object.create(null),list:[]},this.cache_=new r.Map,this.emitId_=0,this.emitQueue_=[]}return t.prototype.formatEventType_=function(t){if(Array.isArray(t))return t;if(t instanceof Object){var e=t;return e.namespace?this.formatEventType_(e.namespace).concat(this.formatEventType_(e.type)):this.formatEventType_(e.type)}return this.separator_&&t?this.formatEventType_(t.toString().split(this.separator_)):this.formatEventType_([t])},t.prototype.on=function(t,e,r){void 0===r&&(r=function(t){return t===e});var i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),void this.seek_(this.node_,i).list.push([e,r,this.emitId_]),void this.drain_(i),this},t.prototype.off=function(t,e){var r=this.formatEventType_(t);switch(typeof e){case"function":return void this.seek_(this.node_,r).list.some(function(t,r,i){var n=t[1];if(!n(e))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_(this.node_,r);return i.map=Object.create(null),i.list=[],void this.cache_.clear(),this;default:throw this.throwTypeErrorIfInvalidSubscriber_(e,r)}},t.prototype.once=function(t,e){var r=this,i=this.formatEventType_(t);return void this.throwTypeErrorIfInvalidSubscriber_(e,i),this.on(t,function(i){return void r.off(t,e),e(i)},function(t){return t===e})},t.prototype.emit=function(t,e,r){return void 0===e&&(e=n.noop),void 0===r&&(r=n.noop),t instanceof Object&&!Array.isArray(t)?this.emit_(this.formatEventType_(t),t,e):this.emit_(this.formatEventType_(t),e,r)},t.prototype.emit_=function(t,e,r){void 0===r&&(r=n.noop);var i=this.emitQueue_;return void i.push([++this.emitId_,e,r]),void this.drain_(t),this},t.prototype.drain_=function(t){for(var e=this.emitQueue_;e.length>0;){var r=e.shift(),i=this.cache_.has([void 0].concat(t).join(o))?this.cache_.get([void 0].concat(t).join(o)):this.cache_.set([void 0].concat(t).join(o),this.collect_(this.seek_(this.node_,t))),n=[];try{void i.reduce(function(t,e){var r=t[0],i=t[1],o=e[0],s=e[2];return s>=r?t:(e[2]=r,void n.push(o(i)),t)},r)}catch(s){void e.unshift(r),void 0!==s&&null!==s&&void console.error(s);continue}var u=r[1],c=r[2];void c(u,n)}return this.resetEmitIdIfPossible_(),this},t.prototype.seek_=function(t,e){function r(t,e){var r=t.map;return r[e+""]?r[e+""]:r[e+""]={map:Object.create(null),list:[]}}var i=this;return void[void 0].concat(e).reduce(function(t,e,r,n){return void i.cache_["delete"](n.slice(0,r+1).join(o))},void 0),e.reduce(r,t)},t.prototype.collect_=function(t){var e=this,r=t.map,i=t.list;return Object.keys(r).reduce(function(t,i){return void t.unshift.apply(t,e.collect_(r[i])),0===t.length&&delete r[i],t},i.slice())},t.prototype.resetEmitIdIfPossible_=function(){return this.emitId_<5e8||this.emitQueue_.length>0?this:(void this.collect_(this.node_).reduce(function(t,e){return e[2]=t},this.emitId_=0),this)},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("ArchStream: Observable: Invalid subscriber.\n "+t)}},t.prototype.reflect=function(t,e){var r;return void this.emit(t,e,function(t,e){return r=e}),r},t}();e.Observable=s}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/thenable"],function(t,e,r,i){"use strict";var n=function(){function t(){}return t}(),o=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(n),s=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(n),u=function(){function t(){this.monitor=new r.Observable,this.event=new r.Observable,this.children=new r.Observable}return t.prototype.register=function(t,e){var r=new c(this,t.slice(),e);return void this.children.on(t,r.receive),void this.monitor.emit("exec",[t,e,void 0]),void this.event.emit(t,["exec",t,e,void 0]),r.terminate.bind(r)},t.prototype.call=function(t,e,r){var i=this.children.reflect(t,new o(e));if(0===i.length)throw new Error("ArchStream: Supervisor: Process does not exist in "+t);return r&&void r(e,i),this},t.prototype.cast=function(t,e,r){return void this.children.emit(t,new o(e),function(t,e){var i=t.data;return r(i,e)}),this},t.prototype.terminate=function(t,e){return void 0===t&&(t=[]),void this.children.emit(t,new s(e)),this},t}();e.Supervisor=u;var c=function(){function t(t,e,r){this.parent=t,this.name=e,this.process=r,this.receive=this.receive.bind(this)}return t.prototype.receive=function(t){if(t instanceof o){try{var e=this.process(t.data);if(i.isThenable(e)){var r=e;void r.then(void 0,this.terminate.bind(this))}return e}catch(n){void this.terminate(n)}throw void 0}if(t instanceof s)throw void void this.terminate(t.reason);throw new TypeError},t.prototype.terminate=function(t){void this.parent.children.off(this.name,this.receive),void this.parent.event.emit(this.name,["exit",this.name,this.process,t]),void this.parent.monitor.emit("exit",[this.name,this.process,t])},t}()}),define("src/lib/set",["require","exports","src/lib/map"],function(t,e,r){"use strict";var i=function(){function t(t){this.replacer_=t,this.map_=new r.Map}return t.prototype.get=function(t){return this.map_.get(t)},t.prototype.set=function(t,e){if(!this.has(t))return this.map_.set(t,e);if(!this.replacer_)throw new Error("Cannot overwrite value of set without replacer.");return this.map_.set(t,this.replacer_(this.get(t),e))},t.prototype.has=function(t){return this.map_.has(t)},t.prototype["delete"]=function(t){return void this.map_["delete"](t),this},t.prototype.clear=function(){return void this.map_.clear(),this},Object.defineProperty(t.prototype,"size",{get:function(){return this.map_.size},enumerable:!0,configurable:!0}),t.prototype.entries=function(){return this.map_.entries()},t}();e.Set=i}),define("src/lib/monad",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.extract=function(t){return this.evaluate().extract(t)},t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t.prototype.assert=function(t){return this},t}();e.Monad=r}),define("src/lib/maybe.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Maybe: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/maybe",["require","exports","src/lib/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/either.impl",["require","exports","src/lib/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("ArchStream: Either: Invalid monad value.\n "+i)})},e.prototype.extract=function(e){return t.prototype.extract.call(this,e)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/either",["require","exports","src/lib/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/export",["require","exports","src/stream/transform","src/lib/message","src/lib/proxy","src/lib/proxy","src/lib/tick","src/lib/timer","src/lib/fingerprint","src/lib/uuid","src/lib/observable","src/lib/supervisor","src/lib/map","src/lib/set","src/lib/maybe","src/lib/either","./typings/arch-stream.d"],function(t,e,r,i,n,o,s,u,c,a,h,p,f,d,l,v){"use strict";function _(){return new r.ArchStream}function y(){return new i.Message}e.Proxy=o.Proxy,e.Tick=s.Tick,e.Timer=u.Timer,e.FINGERPRINT=c.FINGERPRINT,e.uuid=a.v4,e.Observable=h.Observable,e.Supervisor=p.Supervisor,e.Map=f.Map,e.Set=d.Set,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"]});
{
"name": "arch-stream",
"version": "0.0.67",
"version": "0.0.68",
"description": "Pipeline stream for software architecture of Domain-Driven Design and Data-Oriented Design.",

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

@@ -148,3 +148,2 @@ import {Message as IMessage} from 'arch-stream';

public then<U>(done: (data: T) => U | PromiseLike<U>, _?: ICallback<any>): PromiseLike<U> {
done = done || identity;
const msg = new Message<T>();

@@ -171,3 +170,3 @@ this.child_ = void 0; // cannot use then method with recv/trans method in the same instance

return msg
.trans<U>(done);
.trans<U>(done || identity);
}

@@ -174,0 +173,0 @@

@@ -43,13 +43,5 @@ import {IObservableObserver, IObservableConsumer, IObservablePublisher} from 'arch-stream';

const event = <ObservableEvent<T, D>>type;
if (typeof event.namespace === 'string') {
return event.namespace
? this.formatEventType_(<any>(<T>event.namespace).toString().split(this.separator_).concat([event.type + '']))
: this.formatEventType_(event.type);
}
if (Array.isArray(event.namespace)) {
return event.namespace
? this.formatEventType_((<T[]>event.namespace).concat([event.type]))
: this.formatEventType_(event.type);
}
return [event.type];
return event.namespace
? this.formatEventType_(event.namespace).concat(this.formatEventType_(event.type))
: this.formatEventType_(event.type);
}

@@ -128,5 +120,5 @@ return this.separator_ && type

const q = queue.shift();
const collection = types.length > 0
? this.cache_.get(types.join(UNIQUE_SEPARATOR)) || this.cache_.set(types.join(UNIQUE_SEPARATOR), this.collect_(this.seek_(this.node_, types)))
: this.collect_(this.seek_(this.node_, types));
const collection = this.cache_.has([void 0].concat(types).join(UNIQUE_SEPARATOR))
? this.cache_.get([void 0].concat(types).join(UNIQUE_SEPARATOR))
: this.cache_.set([void 0].concat(types).join(UNIQUE_SEPARATOR), this.collect_(this.seek_(this.node_, types)));
var results: any[] = [];

@@ -158,3 +150,3 @@ try {

private seek_(node: SubscriberMapNode<D, R>, names: T[]): SubscriberMapNode<D, R> {
void names
void [void 0].concat(names)
//.reduceRight<T[][]>((acc, name) => [[name]].concat(acc.map(names => [name].concat(names))), [])

@@ -161,0 +153,0 @@ .reduce((_, __, i, names) => void this.cache_.delete(names.slice(0, i + 1).join(UNIQUE_SEPARATOR)), void 0);

@@ -13,6 +13,38 @@ import {Supervisor} from './supervisor';

let cnt = 0;
const sv = new Supervisor<number, number>();
const sv = new Supervisor<string, number, number>();
sv.monitor
.on('exec', ([name, process]) => {
assert.deepEqual(name, []);
assert(process instanceof Function);
assert(++cnt === 1);
})
.on('exit', ([name, process, reason]) => {
assert.deepEqual(name, []);
assert(process instanceof Function);
assert(reason instanceof Error);
assert(++cnt === 7);
});
sv.event
.on([], ([type, name, process, reason]) => {
assert.deepEqual(name, []);
assert(process instanceof Function);
switch (type) {
case 'exec': {
assert(reason === void 0);
assert(++cnt === 2);
return;
}
case 'exit': {
assert(reason instanceof Error);
assert(++cnt === 6);
return;
}
default: {
throw type;
}
}
});
sv
.register(n => {
assert(++cnt < 3);
.register([], n => {
assert(++cnt < 5);
return -n;

@@ -25,3 +57,3 @@ });

.cast([], 4, (_, r) => assert.deepEqual(r, []));
assert(cnt === 3);
assert(cnt === 7);
done();

@@ -28,0 +60,0 @@ });

@@ -5,14 +5,39 @@ import {Supervisor as ISupervisor} from 'arch-stream';

export class Supervisor<T, R> implements ISupervisor<T, R> {
private observer_ = new Observable<string, T, R>();
private counter_ = 0;
public register(process: (data: T) => R, name: string[] = []): () => void {
const worker = new Worker(this, name.slice(), process);
void this.observer_
.on(name, data => worker.receive(data), f => f === process);
type WorkerCommand<D>
= WorkerCommand_$Call<D>
| WorkerCommand_$Exit;
abstract class AbstractWorkerCommand {
private WORKER_COMMAND: void;
}
class WorkerCommand_$Call<D> extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public data: D) {
super();
}
}
class WorkerCommand_$Exit extends AbstractWorkerCommand {
private COMMAND: this;
constructor(public reason: any) {
super();
}
}
export class Supervisor<T extends string, D, R> implements ISupervisor<T, D, R> {
public monitor = new Observable<string, [T[], (data: D) => R, any], any>();
public event = new Observable<T, [string, T[], (data: D) => R, any], any>();
public children = new Observable<T, WorkerCommand<D>, R>();
public register(name: T[], process: (data: D) => R): (reason?: any) => void {
const worker = new Worker<T, D, R>(this, name.slice(), process);
void this.children
.on(name, worker.receive);
void this.monitor
.emit('exec', [name, process, void 0]);
void this.event
.emit(name, ['exec', name, process, void 0]);
return worker.terminate.bind(worker);
}
public call(name: string[], data: T, callback?: (data: T, results: R[]) => any): this {
const results = this.observer_
.reflect(name, data);
public call(name: T[], data: D, callback?: (data: D, results: R[]) => any): this {
const results = this.children
.reflect(name, new WorkerCommand_$Call(data));
if (results.length === 0) throw new Error(`ArchStream: Supervisor: Process does not exist in ${name}`);

@@ -24,10 +49,10 @@ if (callback) {

}
public cast(name: string[], data: T, callback?: (data: T, results: R[]) => any): this {
void this.observer_
.emit(name, data, callback);
public cast(name: T[], data: D, callback?: (data: D, results: R[]) => any): this {
void this.children
.emit(name, new WorkerCommand_$Call(data), ({data}: WorkerCommand_$Call<D>, results: R[]) => callback(data, results));
return this;
}
public terminate(name: string[] = [], process?: (data: T) => R): this {
void this.observer_
.off(name, process);
public terminate(name: T[] = [], reason?: any): this {
void this.children
.emit(name, new WorkerCommand_$Exit(reason));
return this;

@@ -37,26 +62,39 @@ }

class Worker<T, R> {
class Worker<T extends string, D, R> {
constructor(
private parent: Supervisor<T, R>,
public name: string[],
private process: (data: T) => R
private parent: Supervisor<T, D, R>,
public name: T[],
private process: (data: D) => R
) {
this.receive = this.receive.bind(this);
}
public receive(data: T): R {
try {
const result = this.process(data);
if (isThenable(result)) {
const thenable: PromiseLike<any> = <any>result;
void thenable.then(void 0, this.terminate.bind(this));
public receive(cmd: WorkerCommand<D>): R {
if (cmd instanceof WorkerCommand_$Call) {
try {
const result = this.process(cmd.data);
if (isThenable(result)) {
const thenable: PromiseLike<any> = <any>result;
void thenable.then(void 0, this.terminate.bind(this));
}
return result;
}
return result;
catch (reason) {
void this.terminate(reason);
}
throw void 0;
}
catch (err) {
void this.terminate();
if (cmd instanceof WorkerCommand_$Exit) {
void this.terminate(cmd.reason);
throw void 0;
}
throw new TypeError();
}
public terminate(): void {
void this.parent.terminate(this.name, this.process);
public terminate(reason?: any): void {
void this.parent.children
.off(this.name, this.receive);
void this.parent.event
.emit(this.name, ['exit', this.name, this.process, reason]);
void this.parent.monitor
.emit('exit', [this.name, this.process, reason]);
}
}

@@ -160,7 +160,9 @@ /**

export class Supervisor<T, R> {
public register(process: (data: T) => R, name?: string[]): () => void;
public call(name: string[], data: T, callback?: (data: T, results: R[]) => any): this;
public cast(name: string[], data: T, callback?: (data: T, results: R[]) => any): this;
public terminate(name?: string[], process?: (data: T) => R): this;
export class Supervisor<T extends string, D, R> {
public monitor: IObservableObserver<string, [string[], (data: D) => R, any], any>;
public event: IObservableObserver<T, [string, T[], (data: D) => R, any], any>;
public register(name: T[], process: (data: D) => R): (reason?: any) => void;
public call(name: T[], data: D, callback?: (data: D, results: R[]) => any): this;
public cast(name: T[], data: D, callback?: (data: D, results: R[]) => any): this;
public terminate(name?: T[]): this;
}

@@ -167,0 +169,0 @@

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