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.27 to 0.0.28

145

dist/arch-stream.js

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

/*! arch-stream v0.0.27 | (c) 2015, falsandtru | MIT Licence */
/*! arch-stream v0.0.28 | (c) 2015, falsandtru | MIT Licence */
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

@@ -14,12 +14,2 @@ 'use strict';

'use strict';
function clone(arr) {
var arr2 = [];
for (var i = 0; i < arr.length; ++i) {
arr2[i] = arr[i];
}
return arr2;
}
exports.clone = clone;
},{}],4:[function(_dereq_,module,exports){
'use strict';
var __decorate = this && this.__decorate || function (decorators, target, key, desc) {

@@ -56,2 +46,3 @@ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')

this.collection_ = [];
this.transform_ = false;
this.listeners_ = [];

@@ -75,16 +66,18 @@ if (parent) {

Message.prototype.transport_ = function (data, cb) {
var delayed = false, dmsg, called = false;
var cmpl = process(this.collect_());
var msg, called = false;
var delayed = false;
var complete = process(this.collect_(), data, this.transform_);
delayed = true;
if (cmpl && typeof cb === 'function') {
if (complete && typeof cb === 'function') {
void cb(data);
}
return;
function process(collection) {
return collection.every(function (msg) {
function process(collection, data, transform) {
return collection.every(function (msg_) {
msg = msg_;
msg.memory_ = data;
var result = msg.listener(data);
var result = msg.listener(msg.memory_);
data = transform ? result : data;
if (!thenable_1.isThenable(result))
return true;
dmsg = msg;
called = false;

@@ -94,7 +87,10 @@ void result.then(resume, resume);

});
}
function resume() {
called = true;
if (delayed && dmsg.child_) {
void dmsg.child_.send(data, cb);
function resume(result) {
called = true;
data = transform ? result : data;
if (!delayed)
return;
if (msg.child_) {
void msg.child_.send(data, cb);
}
}

@@ -119,8 +115,9 @@ }

}
case !async: {
void this.transport_(data, cb);
case async === true: {
void tick_1.default(this.transport_.bind(this, data, cb));
return this;
}
case async === false:
default: {
void tick_1.default(this.transport_.bind(this, data, cb));
void this.transport_(data, cb);
return this;

@@ -131,2 +128,3 @@ }

Message.prototype.recv = function (callback) {
var child = new Message(this);
this.listener = callback;

@@ -137,19 +135,55 @@ this.collection_ = [];

}
return new Message(this);
return child;
};
Message.prototype.trans = function (callback) {
this.transform_ = true;
return this.recv(callback);
};
Message.prototype.then = function (done, _) {
var listeners = this.listeners_;
listeners.push(done);
return this.recv(dispatch);
function dispatch(data) {
if (listeners.length === 0)
return;
tick_1.default(dispatch.bind(this, data));
while (listeners.length > 0) {
listeners.shift()(data);
var _this = this;
var msg = new Message();
this.listeners_.push(msg);
this.trans(function (data) {
var listeners = _this.listeners_;
_this.listeners_ = [];
for (var i = 0; i < listeners.length; ++i) {
listeners[i].send(data);
}
}
});
return msg.trans(done);
};
Message.all = function (thenables) {
return thenables.reduce(function (acc, thenable, i) {
return acc.then(resume, resume);
function resume(ps) {
return thenable_1.isThenable(thenable) ? thenable.then(function (v) {
return ps.concat([v]);
}) : ps.concat([thenable]);
}
}, new Message().send([]));
};
Message.race = function (thenables) {
var resolved = false;
return thenables.reduce(function (main, thenable) {
if (resolved)
return main;
if (thenable_1.isThenable(thenable)) {
thenable.then(resolve, resolve);
} else {
resolved = true;
main.send(thenable);
}
return main;
function resolve(v) {
if (resolved)
return;
resolved = true;
main.send(v);
}
}, new Message());
};
Object.defineProperty(Message.prototype, 'send', __decorate([decorator_1.bind], Message.prototype, 'send', Object.getOwnPropertyDescriptor(Message.prototype, 'send')));
Object.defineProperty(Message.prototype, 'recv', __decorate([decorator_1.bind], Message.prototype, 'recv', Object.getOwnPropertyDescriptor(Message.prototype, 'recv')));
Object.defineProperty(Message.prototype, 'trans', __decorate([decorator_1.bind], Message.prototype, 'trans', Object.getOwnPropertyDescriptor(Message.prototype, 'trans')));
Object.defineProperty(Message.prototype, 'then', __decorate([decorator_1.bind], Message.prototype, 'then', Object.getOwnPropertyDescriptor(Message.prototype, 'then')));
return Message;

@@ -162,3 +196,3 @@ }();

}
},{"../decorator":1,"../lib/thenable":8,"./tick":10}],5:[function(_dereq_,module,exports){
},{"../decorator":1,"../lib/thenable":7,"./tick":9}],4:[function(_dereq_,module,exports){
'use strict';

@@ -170,5 +204,4 @@ function noop() {

exports.default = noop;
},{}],6:[function(_dereq_,module,exports){
},{}],5:[function(_dereq_,module,exports){
'use strict';
var Array_ = _dereq_('./array');
var Observable = function () {

@@ -251,3 +284,3 @@ function Observable() {

return list;
}, Array_.clone(list));
}, list.slice());
}

@@ -259,3 +292,3 @@ };

exports.default = Observable;
},{"./array":3}],7:[function(_dereq_,module,exports){
},{}],6:[function(_dereq_,module,exports){
'use strict';

@@ -271,3 +304,3 @@ var case_1 = _dereq_('../proxy/case');

};
},{"../proxy/case":11,"../proxy/hook":12,"../proxy/responsibility":13}],8:[function(_dereq_,module,exports){
},{"../proxy/case":10,"../proxy/hook":11,"../proxy/responsibility":12}],7:[function(_dereq_,module,exports){
'use strict';

@@ -278,3 +311,3 @@ function isThenable(target) {

exports.isThenable = isThenable;
},{}],9:[function(_dereq_,module,exports){
},{}],8:[function(_dereq_,module,exports){
'use strict';

@@ -338,3 +371,3 @@ var Throttle = function () {

exports.default = Throttle;
},{}],10:[function(_dereq_,module,exports){
},{}],9:[function(_dereq_,module,exports){
'use strict';

@@ -385,3 +418,3 @@ var Tick;

exports.default = IS_NODE ? Function('return fn => process.nextTick(fn)')() : Tick.queue;
},{}],11:[function(_dereq_,module,exports){
},{}],10:[function(_dereq_,module,exports){
'use strict';

@@ -411,3 +444,3 @@ function default_1(index, indexer) {

exports.default = default_1;
},{}],12:[function(_dereq_,module,exports){
},{}],11:[function(_dereq_,module,exports){
'use strict';

@@ -436,3 +469,3 @@ var noop_1 = _dereq_('../lib/noop');

exports.default = default_1;
},{"../lib/noop":5}],13:[function(_dereq_,module,exports){
},{"../lib/noop":4}],12:[function(_dereq_,module,exports){
'use strict';

@@ -471,3 +504,3 @@ function default_1() {

exports.default = default_1;
},{}],14:[function(_dereq_,module,exports){
},{}],13:[function(_dereq_,module,exports){
'use strict';

@@ -529,3 +562,3 @@ var modular_1 = _dereq_('./modular');

exports.default = ComposeStream;
},{"./modular":15}],15:[function(_dereq_,module,exports){
},{"./modular":14}],14:[function(_dereq_,module,exports){
'use strict';

@@ -653,3 +686,3 @@ var __decorate = this && this.__decorate || function (decorators, target, key, desc) {

exports.default = ModularStream;
},{"../decorator":1,"../lib/noop":5,"../lib/throttle":9,"../lib/tick":10}],16:[function(_dereq_,module,exports){
},{"../decorator":1,"../lib/noop":4,"../lib/throttle":8,"../lib/tick":9}],15:[function(_dereq_,module,exports){
'use strict';

@@ -732,3 +765,3 @@ var message_1 = _dereq_('../lib/message');

exports.default = ArchStream;
},{"../lib/message":4,"./compose":14,"./modular":15}],"arch-stream":[function(_dereq_,module,exports){
},{"../lib/message":3,"./compose":13,"./modular":14}],"arch-stream":[function(_dereq_,module,exports){
'use strict';

@@ -765,3 +798,9 @@ var transform_1 = _dereq_('./stream/transform');

exports.Msg = Msg;
},{"./lib/message":4,"./lib/observable":6,"./lib/proxy":7,"./lib/tick":10,"./stream/transform":16}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14,15,16]);
var Msg;
(function (Msg) {
Msg.all = message_1.default.all;
Msg.race = message_1.default.race;
}(Msg || (Msg = {})));
exports.Msg = Msg;
},{"./lib/message":3,"./lib/observable":5,"./lib/proxy":6,"./lib/tick":9,"./stream/transform":15}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14,15]);
typeof module === "object" && module && "exports" in module && (module.exports = require("arch-stream"));

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

/*! arch-stream v0.0.27 | (c) 2015, falsandtru | MIT Licence */
require=function t(e,r,o){function n(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var f=r[u]={exports:{}};e[u][0].call(f.exports,function(t){var r=e[u][1][t];return n(r?r:t)},f,f.exports,t,e,r,o)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<o.length;u++)n(o[u]);return n}({1:[function(t,e,r){"use strict";var o=t("./decorator/bind");r.bind=o.bind},{"./decorator/bind":2}],2:[function(t,e,r){"use strict";function o(t,e,r){t[e]=t[e].bind(t)}r.bind=o},{}],3:[function(t,e,r){"use strict";function o(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e}r.clone=o},{}],4:[function(t,e,r){"use strict";function o(t){return t}var n=this&&this.__decorate||function(t,e,r,o){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,o);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,o){return void(o&&o(e,r))},void 0);case 4:return t.reduceRight(function(t,o){return o&&o(e,r,t)||t},o)}},i=t("../decorator"),u=t("../lib/thenable"),s=t("./tick"),c=Object.create(null),a=function(){function t(t,e){void 0===e&&(e=o),this.parent=t,this.listener=e,this.memory_=c,this.collection_=[],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 r(e){return e.every(function(e){e.memory_=t;var r=e.listener(t);return u.isThenable(r)?(n=e,s=!1,void r.then(o,o),s):!0})}function o(){s=!0,i&&n.child_&&void n.child_.send(t,e)}var n,i=!1,s=!1,c=r(this.collect_());i=!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){switch(!0){case"function"==typeof e:return this.send(t,!1,e);case!e:return void this.transport_(t,r),this;default:return void s["default"](this.transport_.bind(this,t,r)),this}},t.prototype.recv=function(e){return this.listener=e,this.collection_=[],this.memory_!==c&&void this.send(this.memory_),new t(this)},t.prototype.then=function(t,e){function r(t){if(0!==o.length)for(s["default"](r.bind(this,t));o.length>0;)o.shift()(t)}var o=this.listeners_;return o.push(t),this.recv(r)},Object.defineProperty(t.prototype,"send",n([i.bind],t.prototype,"send",Object.getOwnPropertyDescriptor(t.prototype,"send"))),Object.defineProperty(t.prototype,"recv",n([i.bind],t.prototype,"recv",Object.getOwnPropertyDescriptor(t.prototype,"recv"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=a},{"../decorator":1,"../lib/thenable":8,"./tick":10}],5:[function(t,e,r){"use strict";function o(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{}],6:[function(t,e,r){"use strict";var o=t("./array"),n=function(){function t(){this.separator_=".",this.map_=Object.create(null)}return t.prototype.seek_=function(t,e){function r(t,e){return t[e]&&t[e].map?t[e]:t[e]={map:Object.create(null),list:[]}}switch(e.length){case 0:throw new Error("ArchStream: Observable: Cannot use empty string for event type and namespace.");case 1:return r(t,e.shift());default:return this.seek_(r(t,e.shift()).map,e)}},t.prototype.on=function(t,e){return void this.seek_(this.map_,t.toString().split(this.separator_)).list.push(e),this},t.prototype.off=function(t,e){switch(typeof e){case"function":var r=this.seek_(this.map_,t.toString().split(this.separator_)).list,o=r.indexOf(e);switch(o){case-1:break;case 0:void r.shift();break;default:void r.splice(o,1)}return this;case"undefined":var n=this.seek_(this.map_,t.toString().split(this.separator_));return n.map=Object.create(null),n.list=[],this;default:throw new TypeError("ArchStream: Observable: Invalid type argument: "+e)}},t.prototype.once=function(t,e){var r=this,o=function(n){void r.off(t,o),void e(n)};return void this.on(t,o),this},t.prototype.emit=function(t,e){function r(t){var e=t.map,n=t.list;return Object.keys(e).reduce(function(t,o){return void t.unshift.apply(t,r(e[o])),t},o.clone(n))}return void r(this.seek_(this.map_,t.toString().split(this.separator_))).reduce(function(t,r){return r(e)},void 0),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"./array":3}],7:[function(t,e,r){"use strict";var o=t("../proxy/case"),n=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:o["default"],Hook:n["default"],Responsibility:i["default"]}},{"../proxy/case":11,"../proxy/hook":12,"../proxy/responsibility":13}],8:[function(t,e,r){"use strict";function o(t){return!!t&&"object"==typeof t&&!!t.then}r.isThenable=o},{}],9:[function(t,e,r){"use strict";var o=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(r,"__esModule",{value:!0}),r["default"]=o},{}],10:[function(t,e,r){"use strict";var o;!function(t){function e(t){void n.push(t),void o()}function r(){void--i,void o();for(var t=n.length;t-- >0;)void n.shift()()}function o(){if(0!==n.length)if(u)for(;2>i;)void Promise.resolve().then(r),void++i;else for(;i<s.length;)void setTimeout(r,s[i%s.length]),void++i}t.queue=e;var n=[],i=0,u="function"==typeof Promise,s=[0,4,10,20,25].reverse()}(o||(o={}));var n=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n?Function("return fn => process.nextTick(fn)")():o.queue},{}],11:[function(t,e,r){"use strict";function o(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var n=+o[e(r)+""];n>-1&&n<t.length&&t[n](r)}}var o=Object.create(null);return void t.reduce(function(t,e,r){return o[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{}],12:[function(t,e,r){"use strict";function o(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){o(e),t(e),u(e)}})}var r=t.pre,o=void 0===r?n["default"]:r,i=t.post,u=void 0===i?n["default"]:i;return function(t){return{pipe:e}}}var n=t("../lib/noop");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"../lib/noop":5}],13:[function(t,e,r){"use strict";function o(){function t(t,r){e.pipe=function(){for(var e=[],o=0;o<arguments.length;o++)e[o-0]=arguments[o];return e.map(function(e){return function(o){if(!(r(o)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity: "+r(o).constructor);e(o)}})},e["export"]=function(){return function(e){r(e)instanceof t&&void Object.freeze(r(e))}}}var e;return function(r){return e={rule:t}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{}],14:[function(t,e,r){"use strict";var o=t("./modular"),n=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,o){return t[o+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var o=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return o.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 o["default"](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}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"./modular":15}],15:[function(t,e,r){"use strict";var o=this&&this.__decorate||function(t,e,r,o){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,o);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,o){return void(o&&o(e,r))},void 0);case 4:return t.reduceRight(function(t,o){return o&&o(e,r,t)||t},o)}},n=t("../decorator"),i=t("../lib/throttle"),u=t("../lib/tick"),s=t("../lib/noop"),c=function(){function t(t,e,r){var o=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,void u["default"](function(t){return 0<o.count&&o.count<1/0&&o.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=s["default"]);var r=!1;return void this.read_(function(o){e.flow_&&void u["default"](function(){return void e.flow_.dequeue(o)}),r&&void t(o)}),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,r){var o=this;return void 0===e&&(e=1/0),this.flow_=new i["default"],void this.flow_.flow(t,e,r),void this.flow_.register(function(t){return o.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.")},Object.defineProperty(t.prototype,"read",o([n.bind],t.prototype,"read",Object.getOwnPropertyDescriptor(t.prototype,"read"))),Object.defineProperty(t.prototype,"write",o([n.bind],t.prototype,"write",Object.getOwnPropertyDescriptor(t.prototype,"write"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=c},{"../decorator":1,"../lib/noop":5,"../lib/throttle":9,"../lib/tick":10}],16:[function(t,e,r){"use strict";var o=t("../lib/message"),n=t("./compose"),i=t("./modular"),u=function(){function t(t,e){var r=this;void 0===e&&(e=new o["default"]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return r.proxy(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 i["default"]?(new n["default"])["import"](t,e):new n["default"](t)},t.prototype["export"]=function(t){return(new n["default"]).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,o,n){function i(t){return Array.isArray(t)?t:[t]}var u=e.proxies_.filter(function(t){return"function"==typeof t[o]}).reduce(function(t,e){return i(e[o].apply(void 0,t)||t)},n),s="pipe";switch(o){case s:return t.prototype[o].call(e,u[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[o]).call.apply(c,[r(e,s,u)].concat(n));default:return r(e,s,u)}var c}var o=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 o[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n-0]=arguments[n];return r(o,e,t)}},void 0),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/message":4,"./compose":14,"./modular":15}],"arch-stream":[function(t,e,r){"use strict";function o(){return new i["default"]}function n(){return new u["default"]}var i=t("./stream/transform");r.ArchStream=i["default"];var u=t("./lib/message");r.Message=u["default"];var s=t("./lib/proxy");r.Proxy=s["default"];var c=t("./lib/tick");r.Tick=c["default"];var a=t("./lib/observable");r.Observable=a["default"],Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o;var o,f={Msg:n,Proxy:s["default"],Tick:c["default"]};!function(t){t.Msg=f.Msg,t.Proxy=f.Proxy,t.Tick=f.Tick}(o||(o={})),r.Msg=n},{"./lib/message":4,"./lib/observable":6,"./lib/proxy":7,"./lib/tick":10,"./stream/transform":16}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14,15,16]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream"));
/*! arch-stream v0.0.28 | (c) 2015, falsandtru | MIT Licence */
require=function t(e,r,n){function o(u,s){if(!r[u]){if(!e[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var p=r[u]={exports:{}};e[u][0].call(p.exports,function(t){var r=e[u][1][t];return o(r?r:t)},p,p.exports,t,e,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(t,e,r){"use strict";var n=t("./decorator/bind");r.bind=n.bind},{"./decorator/bind":2}],2:[function(t,e,r){"use strict";function n(t,e,r){t[e]=t[e].bind(t)}r.bind=n},{}],3:[function(t,e,r){"use strict";function n(t){return t}var o=this&&this.__decorate||function(t,e,r,n){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,n);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,n){return void(n&&n(e,r))},void 0);case 4:return t.reduceRight(function(t,n){return n&&n(e,r,t)||t},n)}},i=t("../decorator"),u=t("../lib/thenable"),s=t("./tick"),c=Object.create(null),a=function(){function t(t,e){void 0===e&&(e=n),this.parent=t,this.listener=e,this.memory_=c,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 r(t,r,s){function c(t){o=!0,r=s?t:r,i&&n.child_&&void n.child_.send(r,e)}return t.every(function(t){n=t,n.memory_=r;var e=n.listener(n.memory_);return r=s?e:r,u.isThenable(e)?(o=!1,void e.then(c,c),o):!0})}var n,o=!1,i=!1,s=r(this.collect_(),t,this.transform_);i=!0,s&&"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 s["default"](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_!==c&&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 n=this,o=new t;return this.listeners_.push(o),this.trans(function(t){var e=n.listeners_;n.listeners_=[];for(var r=0;r<e.length;++r)e[r].send(t)}),o.trans(e)},t.all=function(e){return e.reduce(function(t,e,r){function n(t){return u.isThenable(e)?e.then(function(e){return t.concat([e])}):t.concat([e])}return t.then(n,n)},(new t).send([]))},t.race=function(e){var r=!1;return e.reduce(function(t,e){function n(e){r||(r=!0,t.send(e))}return r?t:(u.isThenable(e)?e.then(n,n):(r=!0,t.send(e)),t)},new t)},Object.defineProperty(t.prototype,"send",o([i.bind],t.prototype,"send",Object.getOwnPropertyDescriptor(t.prototype,"send"))),Object.defineProperty(t.prototype,"recv",o([i.bind],t.prototype,"recv",Object.getOwnPropertyDescriptor(t.prototype,"recv"))),Object.defineProperty(t.prototype,"trans",o([i.bind],t.prototype,"trans",Object.getOwnPropertyDescriptor(t.prototype,"trans"))),Object.defineProperty(t.prototype,"then",o([i.bind],t.prototype,"then",Object.getOwnPropertyDescriptor(t.prototype,"then"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=a},{"../decorator":1,"../lib/thenable":7,"./tick":9}],4:[function(t,e,r){"use strict";function n(){}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],5:[function(t,e,r){"use strict";var n=function(){function t(){this.separator_=".",this.map_=Object.create(null)}return t.prototype.seek_=function(t,e){function r(t,e){return t[e]&&t[e].map?t[e]:t[e]={map:Object.create(null),list:[]}}switch(e.length){case 0:throw new Error("ArchStream: Observable: Cannot use empty string for event type and namespace.");case 1:return r(t,e.shift());default:return this.seek_(r(t,e.shift()).map,e)}},t.prototype.on=function(t,e){return void this.seek_(this.map_,t.toString().split(this.separator_)).list.push(e),this},t.prototype.off=function(t,e){switch(typeof e){case"function":var r=this.seek_(this.map_,t.toString().split(this.separator_)).list,n=r.indexOf(e);switch(n){case-1:break;case 0:void r.shift();break;default:void r.splice(n,1)}return this;case"undefined":var o=this.seek_(this.map_,t.toString().split(this.separator_));return o.map=Object.create(null),o.list=[],this;default:throw new TypeError("ArchStream: Observable: Invalid type argument: "+e)}},t.prototype.once=function(t,e){var r=this,n=function(o){void r.off(t,n),void e(o)};return void this.on(t,n),this},t.prototype.emit=function(t,e){function r(t){var e=t.map,n=t.list;return Object.keys(e).reduce(function(t,n){return void t.unshift.apply(t,r(e[n])),t},n.slice())}return void r(this.seek_(this.map_,t.toString().split(this.separator_))).reduce(function(t,r){return r(e)},void 0),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],6:[function(t,e,r){"use strict";var n=t("../proxy/case"),o=t("../proxy/hook"),i=t("../proxy/responsibility");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]={Case:n["default"],Hook:o["default"],Responsibility:i["default"]}},{"../proxy/case":10,"../proxy/hook":11,"../proxy/responsibility":12}],7:[function(t,e,r){"use strict";function n(t){return!!t&&"object"==typeof t&&!!t.then}r.isThenable=n},{}],8:[function(t,e,r){"use strict";var n=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(r,"__esModule",{value:!0}),r["default"]=n},{}],9:[function(t,e,r){"use strict";var n;!function(t){function e(t){void o.push(t),void n()}function r(){void--i,void n();for(var t=o.length;t-- >0;)void o.shift()()}function n(){if(0!==o.length)if(u)for(;2>i;)void Promise.resolve().then(r),void++i;else for(;i<s.length;)void setTimeout(r,s[i%s.length]),void++i}t.queue=e;var o=[],i=0,u="function"==typeof Promise,s=[0,4,10,20,25].reverse()}(n||(n={}));var o=Function("return typeof process === 'object' && typeof window !== 'object'")();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o?Function("return fn => process.nextTick(fn)")():n.queue},{}],10:[function(t,e,r){"use strict";function n(t,e){function r(){for(var t=[],r=0;r<arguments.length;r++)t[r-0]=arguments[r];return function(r){var o=+n[e(r)+""];o>-1&&o<t.length&&t[o](r)}}var n=Object.create(null);return void t.reduce(function(t,e,r){return n[e+""]=r},void 0),function(t){return{pipe:r}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],11:[function(t,e,r){"use strict";function n(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),u(e)}})}var r=t.pre,n=void 0===r?o["default"]:r,i=t.post,u=void 0===i?o["default"]:i;return function(t){return{pipe:e}}}var o=t("../lib/noop");Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{"../lib/noop":4}],12:[function(t,e,r){"use strict";function n(){function t(t,r){e.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];return e.map(function(e){return function(n){if(!(r(n)instanceof t))throw TypeError("ArchStream: ResponsibilityProxy: Uncovered internal entity: "+r(n).constructor);e(n)}})},e["export"]=function(){return function(e){r(e)instanceof t&&void Object.freeze(r(e))}}}var e;return function(r){return e={rule:t}}}Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n},{}],13:[function(t,e,r){"use strict";var n=t("./modular"),o=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,n){return t[n+e]=r,t},this.procs_),this},t.prototype["import"]=function(e,r){var n=this;return void this.throwErrorIfNotImportable_(e,r),r&&(e=(new t)["import"](e)["export"]().wrap(function(t,e){return n.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 n["default"](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}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=o},{"./modular":14}],14:[function(t,e,r){"use strict";var n=this&&this.__decorate||function(t,e,r,n){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(t,e,r,n);switch(arguments.length){case 2:return t.reduceRight(function(t,e){return e&&e(t)||t},e);case 3:return t.reduceRight(function(t,n){return void(n&&n(e,r))},void 0);case 4:return t.reduceRight(function(t,n){return n&&n(e,r,t)||t},n)}},o=t("../decorator"),i=t("../lib/throttle"),u=t("../lib/tick"),s=t("../lib/noop"),c=function(){function t(t,e,r){var n=this;void 0===e&&(e=1),this.procs=t,this.count=e,this.branched=r,void u["default"](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=s["default"]);var r=!1;return void this.read_(function(n){e.flow_&&void u["default"](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,r){var n=this;return void 0===e&&(e=1/0),this.flow_=new i["default"],void this.flow_.flow(t,e,r),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.")},Object.defineProperty(t.prototype,"read",n([o.bind],t.prototype,"read",Object.getOwnPropertyDescriptor(t.prototype,"read"))),Object.defineProperty(t.prototype,"write",n([o.bind],t.prototype,"write",Object.getOwnPropertyDescriptor(t.prototype,"write"))),t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=c},{"../decorator":1,"../lib/noop":4,"../lib/throttle":8,"../lib/tick":9}],15:[function(t,e,r){"use strict";var n=t("../lib/message"),o=t("./compose"),i=t("./modular"),u=function(){function t(t,e){var r=this;void 0===e&&(e=new n["default"]),this.parent_=t,this.message_=e,this.proxies_=[],this.parent_&&void this.parent_.proxies_.reduce(function(t,e){return r.proxy(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 i["default"]?(new o["default"])["import"](t,e):new o["default"](t)},t.prototype["export"]=function(t){return(new o["default"]).register([this.message_])["export"](t)},t.prototype.proxy=function(e){function r(e,n,o){function i(t){return Array.isArray(t)?t:[t]}var u=e.proxies_.filter(function(t){return"function"==typeof t[n]}).reduce(function(t,e){return i(e[n].apply(void 0,t)||t)},o),s="pipe";switch(n){case s:return t.prototype[n].call(e,u[0]);case"import":throw new Error("ArchStream: `import` method cannot extend by proxy.");case"export":return(c=t.prototype[n]).call.apply(c,[r(e,s,u)].concat(o));default:return r(e,s,u)}var c}var n=this,o="function"==typeof e?e():e;return this.proxies_.push(o),void Object.keys(o).filter(function(t){return t.length>0&&"_"!==t[0]&&"_"!==t[t.length-1]}).filter(function(t){return"function"==typeof o[t]}).reduce(function(t,e){return n[e]=function(){for(var t=[],o=0;o<arguments.length;o++)t[o-0]=arguments[o];return r(n,e,t)}},void 0),this},t}();Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=u},{"../lib/message":3,"./compose":13,"./modular":14}],"arch-stream":[function(t,e,r){"use strict";function n(){return new i["default"]}function o(){return new u["default"]}var i=t("./stream/transform");r.ArchStream=i["default"];var u=t("./lib/message");r.Message=u["default"];var s=t("./lib/proxy");r.Proxy=s["default"];var c=t("./lib/tick");r.Tick=c["default"];var a=t("./lib/observable");r.Observable=a["default"],Object.defineProperty(r,"__esModule",{value:!0}),r["default"]=n;var n,p={Msg:o,Proxy:s["default"],Tick:c["default"]};!function(t){t.Msg=p.Msg,t.Proxy=p.Proxy,t.Tick=p.Tick}(n||(n={})),r.Msg=o;var o;!function(t){t.all=u["default"].all,t.race=u["default"].race}(o||(o={})),r.Msg=o},{"./lib/message":3,"./lib/observable":5,"./lib/proxy":6,"./lib/tick":9,"./stream/transform":15}]},{},[1,2,"arch-stream",3,4,5,6,7,8,9,10,11,12,13,14,15]),"object"==typeof module&&module&&"exports"in module&&(module.exports=require("arch-stream"));

@@ -17,8 +17,8 @@ {

"mocha/mocha.d.ts": {
"ref": "fc341765ebbb04b7109981a25dced01f488f4d94"
"ref": "16134c168d021351acb1673ee9659644fc58c424"
},
"power-assert/power-assert.d.ts": {
"ref": "fc341765ebbb04b7109981a25dced01f488f4d94"
"ref": "16134c168d021351acb1673ee9659644fc58c424"
}
}
}

@@ -290,2 +290,8 @@ # memo

#### #send
データを入力する。
第二引数に`true`を指定すると非同期処理となる。
第二引数または第三引数に関数を渡すと全処理の完了後に呼び出される。
#### #recv

@@ -295,7 +301,14 @@

#### #send
#### #trans
データを入力する。
第二引数に`true`を指定すると非同期処理となる。
出力を置換する。
#### .all
Promise.all代替。
#### .race
Promise.race代替。
### Proxy

@@ -302,0 +315,0 @@

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

@@ -67,7 +67,7 @@ "private": false,

"mocha": "^2.3.4",
"npm-check-updates": "^2.4.2",
"npm-check-updates": "^2.5.1",
"power-assert": "^1.2.0",
"run-sequence": "^1.1.4",
"strictify": "^0.2.0",
"tslint": "^2.5.1",
"tslint": "^3.0.0",
"typescript": "^1.6.2",

@@ -74,0 +74,0 @@ "unassertify": "^2.0.2",

@@ -32,1 +32,7 @@ /* tslint:disable:no-unused-variable */ // tslint bug. https://github.com/palantir/tslint/issues/684

exports.Msg = Msg;
var Msg;
(function (Msg) {
Msg.all = message_1.default.all;
Msg.race = message_1.default.race;
})(Msg || (Msg = {}));
exports.Msg = Msg;

@@ -34,1 +34,5 @@ /* tslint:disable:no-unused-variable */ // tslint bug. https://github.com/palantir/tslint/issues/684

}
namespace Msg {
export const all = Message.all;
export const race = Message.race;
}

@@ -26,2 +26,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

this.collection_ = [];
this.transform_ = false;
this.listeners_ = [];

@@ -48,26 +49,32 @@ if (parent) {

Message.prototype.transport_ = function (data, cb) {
var delayed = false, dmsg, called = false;
var cmpl = process(this.collect_());
var msg, called = false;
var delayed = false;
var complete = process(this.collect_(), data, this.transform_);
delayed = true;
if (cmpl && typeof cb === 'function') {
if (complete && typeof cb === 'function') {
void cb(data);
}
return;
function process(collection) {
function process(collection, data, transform) {
return collection
.every(function (msg) {
.every(function (msg_) {
msg = msg_;
msg.memory_ = data;
var result = msg.listener(data);
var result = msg.listener(msg.memory_);
data = transform ? result : data;
if (!thenable_1.isThenable(result))
return true;
dmsg = msg;
called = false;
void result.then(resume, resume);
void result
.then(resume, resume);
return called;
});
}
function resume() {
called = true;
if (delayed && dmsg.child_) {
void dmsg.child_.send(data, cb);
function resume(result) {
called = true;
data = transform ? result : data;
if (!delayed)
return;
if (msg.child_) {
void msg.child_.send(data, cb);
}
}

@@ -98,8 +105,9 @@ }

}
case !async: {
void this.transport_(data, cb);
case async === true: {
void tick_1.default(this.transport_.bind(this, data, cb));
return this;
}
case async === false:
default: {
void tick_1.default(this.transport_.bind(this, data, cb));
void this.transport_(data, cb);
return this;

@@ -113,2 +121,3 @@ }

assert(typeof callback === 'function');
var child = new Message(this);
this.listener = callback;

@@ -119,17 +128,57 @@ this.collection_ = [];

}
return new Message(this);
return child;
};
Message.prototype.trans = function (callback) {
this.transform_ = true;
return this.recv(callback);
};
Message.prototype.then = function (done, _) {
var listeners = this.listeners_;
listeners.push(done);
return this.recv(dispatch);
function dispatch(data) {
if (listeners.length === 0)
return;
tick_1.default(dispatch.bind(this, data));
while (listeners.length > 0) {
listeners.shift()(data);
var _this = this;
var msg = new Message();
this.listeners_.push(msg);
this
.trans(function (data) {
var listeners = _this.listeners_;
_this.listeners_ = [];
for (var i = 0; i < listeners.length; ++i) {
listeners[i].send(data);
}
}
});
return msg
.trans(done);
};
Message.all = function (thenables) {
return thenables
.reduce(function (acc, thenable, i) {
return acc.then(resume, resume);
function resume(ps) {
return thenable_1.isThenable(thenable)
? thenable.then(function (v) { return ps.concat([v]); })
: ps.concat([thenable]);
}
}, new Message().send([]));
};
Message.race = function (thenables) {
var resolved = false;
return thenables
.reduce(function (main, thenable) {
if (resolved)
return main;
if (thenable_1.isThenable(thenable)) {
thenable
.then(resolve, resolve);
}
else {
resolved = true;
main.send(thenable);
}
return main;
function resolve(v) {
if (resolved)
return;
resolved = true;
main.send(v);
}
}, new Message());
};
Object.defineProperty(Message.prototype, "send",

@@ -143,2 +192,10 @@ __decorate([

], Message.prototype, "recv", Object.getOwnPropertyDescriptor(Message.prototype, "recv")));
Object.defineProperty(Message.prototype, "trans",
__decorate([
decorator_1.bind
], Message.prototype, "trans", Object.getOwnPropertyDescriptor(Message.prototype, "trans")));
Object.defineProperty(Message.prototype, "then",
__decorate([
decorator_1.bind
], Message.prototype, "then", Object.getOwnPropertyDescriptor(Message.prototype, "then")));
return Message;

@@ -145,0 +202,0 @@ })();

import Message from './message';
import Tick from './tick';
declare const Promise;
interface Entity<T> {

@@ -9,2 +11,12 @@ val: T;

describe('default', function () {
it('trans', function (done) {
new Message<number>()
.send(0)
.trans(n => ++n)
.trans(n => new Message<number>().send(++n))
.trans(n => new Message<number>().send(++n, true))
.trans(n => ++n)
.recv(n => assert(n === 4) || done());
});
it('recv > send', function (done) {

@@ -57,13 +69,78 @@ const sender = new Message<Entity<number>>();

it('then', function (done) {
let cnt = 0;
new Message<number>()
.send(0, true)
.send(0, true)
.then(n => ++n)
.then(n => ++n)
.then(n => assert(n === 2 && ++cnt === 1) || Tick(_ => assert(cnt === 1) || done()));
});
it('all', function (done) {
Message.all<number>([
0,
new Message<number>().send(1),
new Message<number>().send(2, true),
new Message<number>().send(3),
4,
5
])
.then(ns => assert.deepEqual(ns, [0, 1, 2, 3, 4, 5]) || done());
});
it('race', function (done) {
Message.race<number>([
new Message<number>().send(2, true),
4,
5
])
.then(n => assert(n === 4));
Message.race<number>([
new Message<number>().send(2, true),
new Message<number>().send(3),
4,
5
])
.then(n => assert(n === 3) || done());
});
it('defer receive', function (done) {
new Message<Entity<number>>()
let cnt = 0;
const msg = new Message<Entity<number>>();
msg
.send({val: 0})
.recv(e => {
const msg = new Message<number>();
setTimeout(() => msg.send(++e.val), 1);
setTimeout(() => {
msg.send(++e.val);
}, 1);
return msg;
})
.recv(e => new Message<number>().send(++e.val))
.recv(e => typeof Promise === 'function' ? Promise.resolve(++e.val) : new Message<number>().send(++e.val))
.recv(e => new Message<number>().send(++e.val, true))
.recv(e => assert(e.val === 3) || done());
.recv(e => Message.all([
new Message<number>().send(++e.val)
]))
.recv(e => Message.all([
new Message<number>().send(++e.val, true)
]))
.recv(e => Message.all([
null,
void 0,
new Message<number>().send(++e.val, true),
null,
void 0,
new Message<number>().send(++e.val, true),
null,
void 0
]))
.recv(e => Message.all([
new Message<number>().send(++e.val),
new Message<number>().send(++e.val)
]))
.recv(e => assert(e.val === 9) || ++cnt === 2 && Tick(_ => assert(cnt === 2) || done()));
msg
.send({val: 0});
});

@@ -70,0 +147,0 @@

import {Message as IMessage} from 'arch-stream';
import {bind} from '../decorator';
import {Thenable, isThenable} from '../lib/thenable';
import {isThenable, IThenable} from '../lib/thenable';
import Tick from './tick';
interface Callback<T> {
interface ICallback<T> {
(entity: T): any;

@@ -12,3 +12,3 @@ }

export default class Message<T> implements IMessage<T>, Thenable<T> {
export default class Message<T> implements IMessage<T>, IThenable<T> {
constructor(

@@ -18,3 +18,3 @@ // immutable after assignment

// immutable after assignment
public listener: Callback<T> = identity
public listener: ICallback<T> = identity
) {

@@ -50,9 +50,9 @@ if (parent) {

private transport_(data: T, cb: Callback<T>): void {
let delayed = false,
dmsg: Message<T>,
private transport_(data: T, cb: ICallback<T>): void {
let msg: Message<T>,
called = false;
const cmpl = process(this.collect_());
let delayed = false;
const complete = process(this.collect_(), data, this.transform_);
delayed = true;
if (cmpl && typeof cb === 'function') {
if (complete && typeof cb === 'function') {
void cb(data);

@@ -62,20 +62,25 @@ }

function process(collection: Message<T>[]): boolean {
function process(collection: Message<T>[], data: T|IThenable<T>, transform: boolean): boolean {
return collection
.every(msg => {
msg.memory_ = data;
const result = msg.listener(data);
.every(msg_ => {
msg = msg_;
msg.memory_ = <T>data;
const result = msg.listener(msg.memory_);
data = transform ? result : data;
if (!isThenable(result)) return true;
dmsg = msg;
called = false;
void result.then(resume, resume);
void (<IThenable<T>>result)
.then(resume, resume);
return called;
});
}
function resume() {
called = true;
if (delayed && dmsg.child_) {
void dmsg.child_.send(data, cb);
function resume(result: T|IThenable<T>): void {
called = true;
data = transform ? result : data;
if (!delayed) return;
if (msg.child_) {
void msg.child_.send(<T>data, cb);
}
}

@@ -104,17 +109,18 @@ }

public send(data: T, cb?: Callback<T>): Message<T>
public send(data: T, async?: boolean, cb?: Callback<T>): Message<T>
public send(data: T, cb?: ICallback<T>): Message<T>
public send(data: T, async?: boolean, cb?: ICallback<T>): Message<T>
@bind
public send(data: T, async?: boolean|Callback<T>, cb?: Callback<T>): Message<T> {
public send(data: T, async?: boolean | ICallback<T>, cb?: ICallback<T>): Message<T> {
assert(typeof async === 'boolean' || typeof async === 'function' || async === void 0);
switch (true) {
case typeof async === 'function': {
return this.send(data, false, <Callback<T>>async);
return this.send(data, false, <ICallback<T>>async);
}
case !async: {
void this.transport_(data, cb);
case async === true: {
void Tick(this.transport_.bind(this, data, cb));
return this;
}
case async === false:
default: {
void Tick(this.transport_.bind(this, data, cb));
void this.transport_(data, cb);
return this;

@@ -127,5 +133,6 @@ }

@bind
public recv(callback: (data: T) => any): Message<T> {
public recv(callback: ICallback<T>): Message<T> {
assert(this.listener === identity);
assert(typeof callback === 'function');
const child = new Message<T>(this);
this.listener = callback;

@@ -136,20 +143,65 @@ this.collection_ = [];

}
return new Message<T>(this);
return child;
}
private listeners_: Callback<T>[] = [];
public then(done: Callback<T>, _?: Callback<T>): Message<T> {
const listeners = this.listeners_;
listeners.push(done);
return this.recv(dispatch);
function dispatch(data: T) {
if (listeners.length === 0) return;
Tick(dispatch.bind(this, data));
while (listeners.length > 0) {
listeners.shift()(data);
}
}
private transform_ = false;
@bind
public trans<U>(callback: (data: T) => U|IThenable<U>): Message<U> {
this.transform_ = true;
return <any>this.recv(callback);
}
private listeners_: Message<T>[] = [];
@bind
public then<U>(done: (data: T) => U|IThenable<U>, _?: ICallback<any>): IThenable<U> {
const msg = new Message<T>();
this.listeners_.push(msg);
this
.trans((data: T) => {
const listeners = this.listeners_;
this.listeners_ = [];
for (let i = 0; i < listeners.length; ++i) {
listeners[i].send(data);
}
});
return msg
.trans<U>(done);
}
public static all<T>(thenables: (IThenable<T>|T)[]): IThenable<T[]> {
return thenables
.reduce((acc, thenable, i) => {
return acc.then(resume, resume);
function resume(ps: T[]): IThenable<T[]>|T[] {
return isThenable(thenable)
? (<IThenable<T>>thenable).then(v => ps.concat([v]))
: ps.concat([<T>thenable]);
}
}, <IThenable<T[]>>new Message<T[]>().send([]));
}
public static race<T>(thenables: (IThenable<T>|T)[]): IThenable<T> {
let resolved = false;
return thenables
.reduce<Message<T>>((main, thenable) => {
if (resolved) return main;
if (isThenable(thenable)) {
(<IThenable<T>>thenable)
.then(resolve, resolve);
}
else {
resolved = true;
main.send(<T>thenable);
}
return main;
function resolve(v: T): void {
if (resolved) return;
resolved = true;
main.send(v);
}
}, new Message<T>());
}
}

@@ -156,0 +208,0 @@

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

var Array_ = require('./array');
var Observable = (function () {

@@ -86,3 +85,3 @@ function Observable() {

return list;
}, Array_.clone(list));
}, list.slice());
}

@@ -89,0 +88,0 @@ };

@@ -1,4 +0,1 @@

import {Observable as IObservable} from 'arch-stream';
import * as Array_ from './array';
interface ListenerMap<T> {

@@ -15,3 +12,3 @@ [ns: string]: ListenerSet<T>;

export default class Observable<S extends string|number, T> implements IObservable<S, T> {
export default class Observable<S extends string|number, T> {
private separator_ = '.';

@@ -99,5 +96,5 @@ private map_: ListenerMap<T> = Object.create(null);

return list;
}, Array_.clone(list));
}, list.slice());
}
}
}

@@ -1,4 +0,4 @@

export interface Thenable<T> {
then(done: (data: T) => T, fail?: (reason: any) => any): Thenable<T>;
then<U>(done: (data: T) => U, fail?: (reason: any) => any): Thenable<U>;
export interface IThenable<T> {
then(done: (data: T) => T|IThenable<T>, fail?: (reason: any) => any): IThenable<T>;
then<U>(done: (data: T) => U|IThenable<U>, fail?: (reason: any) => any): IThenable<U>;
}

@@ -5,0 +5,0 @@

@@ -1,5 +0,5 @@

import {Callback, TransformStream} from 'arch-stream';
import {ICallback, ITransformStream} from 'arch-stream';
interface CaseProxy<T, U> {
pipe(...callbacks: Callback<T>[]): U&CaseProxy<T, U>&TransformStream<T, U&CaseProxy<T, U>>;
pipe(...callbacks: ICallback<T>[]): U&CaseProxy<T, U>&ITransformStream<T, U&CaseProxy<T, U>>;
}

@@ -11,7 +11,7 @@

.reduce((_, method, i) => map[method + ''] = i, void 0);
return <U>(shadow?: TransformStream<T, U>) => <CaseProxy<T, U>>{
return <U>(shadow?: ITransformStream<T, U>) => <CaseProxy<T, U>>{
pipe: pipe
};
function pipe(...args: Callback<T>[]): Callback<T>|Callback<T>[]|CaseProxy<T, {}>&TransformStream<T, {}&CaseProxy<T, {}>> {
function pipe(...args: ICallback<T>[]): ICallback<T>|ICallback<T>[]|CaseProxy<T, {}>&ITransformStream<T, {}&CaseProxy<T, {}>> {
return (entity: T) => {

@@ -18,0 +18,0 @@ const i = +map[indexer(entity) + ''];

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

import {Callback, TransformStream} from 'arch-stream';
import {ICallback, ITransformStream} from 'arch-stream';
import noop from '../lib/noop';

@@ -7,8 +7,8 @@

export default function <T>({ pre = noop, post = noop }: { pre?: Callback<T>, post?: Callback<T> }) {
return <U>(shadow?: TransformStream<T, U>) => <HookProxy<T, U>>{
export default function <T>({ pre = noop, post = noop }: { pre?: ICallback<T>, post?: ICallback<T> }) {
return <U>(shadow?: ITransformStream<T, U>) => <HookProxy<T, U>>{
pipe: pipe
};
function pipe(...args: Callback<T>[]): Callback<T>|Callback<T>[]|TransformStream<T, {}> {
function pipe(...args: ICallback<T>[]): ICallback<T>|ICallback<T>[]|ITransformStream<T, {}> {
return args

@@ -15,0 +15,0 @@ .map(proc => (entity: T) => {

@@ -1,5 +0,5 @@

import {Callback, TransformStream} from 'arch-stream';
import {ICallback, ITransformStream} from 'arch-stream';
interface ResponsibilityProxy<T, U> {
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&TransformStream<T, U>;
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&ITransformStream<T, U>;
}

@@ -9,3 +9,3 @@

let proxy;
return <U>(shadow?: TransformStream<T, U>) => proxy = <ResponsibilityProxy<T, U>>{
return <U>(shadow?: ITransformStream<T, U>) => proxy = <ResponsibilityProxy<T, U>>{
rule: rule

@@ -15,3 +15,3 @@ };

function rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V) {
proxy.pipe = (...args: Callback<T>[]) =>
proxy.pipe = (...args: ICallback<T>[]) =>
args

@@ -18,0 +18,0 @@ .map(callback =>

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

import {ComposeStream as IComposeStream} from 'arch-stream';
import {IComposeStream} from 'arch-stream';
import ModularStream from './modular';

@@ -3,0 +3,0 @@ import Message from '../lib/message';

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

import {
ModularStream as IModularStream,
ModularReadableStream,
ModularWritableStream,
ModularWritableWithStream,
Callback
} from 'arch-stream';
import {IModularStream, IModularReadableStream, IModularWritableStream, IModularWritableWithStream, ICallback} from 'arch-stream';
import {bind} from '../decorator';

@@ -16,3 +10,3 @@ import Message from '../lib/message';

class ModularStream<T>
implements IModularStream<T>, ModularReadableStream<T>, ModularWritableStream<T>, ModularWritableWithStream<T> {
implements IModularStream<T>, IModularReadableStream<T>, IModularWritableStream<T>, IModularWritableWithStream<T> {
constructor(public procs: Message<T>[], public count: number = 1, public branched?: number) {

@@ -46,3 +40,3 @@ assert(procs instanceof Array);

}
private read_(callback: Callback<T>): void {
private read_(callback: ICallback<T>): void {
void --this.count;

@@ -53,6 +47,6 @@ if (this.count < 0) { void this.throwCountExceededError(); }

}
public read(callback: Callback<T>): ModularWritableStream<T>
public read(): ModularWritableWithStream<T>
public read(callback: ICallback<T>): IModularWritableStream<T>
public read(): IModularWritableWithStream<T>
@bind
public read(callback: Callback<T> = noop): any {
public read(callback: ICallback<T> = noop): any {
let active = false;

@@ -70,7 +64,7 @@ void this.read_((entity: T) => {

}
private write_(entity: T, cb?: Callback<T>): void {
private write_(entity: T, cb?: ICallback<T>): void {
void this.first_.send(entity, cb);
}
@bind
public write(entity: T, cb?: Callback<T>): ModularWritableStream<T> {
public write(entity: T, cb?: ICallback<T>): IModularWritableStream<T> {
if (this.flow_) {

@@ -85,3 +79,3 @@ void this.flow_.enqueue(entity);

private flow_: Throttle<T>;
public flow(volume: number, limit: number = Infinity, discharger?: (queue: T[], processing: T[]) => any): ModularReadableStream<T> {
public flow(volume: number, limit: number = Infinity, discharger?: (queue: T[], processing: T[]) => any): IModularReadableStream<T> {
this.flow_ = new Throttle<T>();

@@ -88,0 +82,0 @@ void this.flow_.flow(volume, limit, discharger);

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

import {ArchStream as IArchStream, TransformStream, Callback} from 'arch-stream';
import {ArchStream as IArchStream, ITransformStream, ICallback} from 'arch-stream';
import Message from '../lib/message';

@@ -6,4 +6,4 @@ import ComposeStream from './compose';

interface StreamProxy<T> {
[method: string]: (...args: Callback<T>[]) => void|Callback<T>|Callback<T>[];
interface IProxy<T> {
[method: string]: (...args: ICallback<T>[]) => void|ICallback<T>|ICallback<T>[];
}

@@ -23,3 +23,3 @@

}
public pipe(callback: Callback<T>): ArchStream<T> {
public pipe(callback: ICallback<T>): ArchStream<T> {
return new ArchStream(this, this.message_.recv(callback));

@@ -40,4 +40,4 @@ }

// mutable
private proxies_: StreamProxy<T>[] = [];
public proxy<S extends StreamProxy<T>>(gen: S|((shadow?: TransformStream<T, {}>) => S)): ArchStream<T>&S {
private proxies_: IProxy<T>[] = [];
public proxy<S extends IProxy<T>>(gen: S|((shadow?: ITransformStream<T, {}>) => S)): ArchStream<T>&S {
const proxy = typeof gen === 'function' ? (<() => S>gen)() : <S>gen;

@@ -51,7 +51,7 @@ this.proxies_.push(proxy);

function compose<S>(self: ArchStream<T>, method: string, args: Callback<T>[]): ArchStream<T> & S {
function compose<S>(self: ArchStream<T>, method: string, args: ICallback<T>[]): ArchStream<T> & S {
assert(self.proxies_.length > 0);
const params = self.proxies_
.filter(proxy => typeof proxy[method] === 'function')
.reduce((args, proxy) => toArray(<Callback<T> | Callback<T>[]>proxy[method].apply(void 0, args) || args), args);
.reduce((args, proxy) => toArray(<ICallback<T> | ICallback<T>[]>proxy[method].apply(void 0, args) || args), args);
const base = 'pipe';

@@ -58,0 +58,0 @@ switch (method) {

@@ -28,2 +28,10 @@ import A, {Msg, Proxy, Tick, Observable, ArchStream, Message} from 'arch-stream';

it('all', function () {
assert(Msg.all === Message.all);
});
it('race', function () {
assert(Msg.race === Message.race);
});
});

@@ -76,2 +84,10 @@

it('all', function () {
assert(typeof Message.all === 'function');
});
it('race', function () {
assert(typeof Message.race === 'function');
});
});

@@ -78,0 +94,0 @@

@@ -14,2 +14,6 @@ /**

export function Msg<T>(): Message<T>
export namespace Msg {
export const all: typeof Message.all;
export const race: typeof Message.race;
}
export const Proxy: Proxy;

@@ -19,23 +23,30 @@ export const Tick: Tick;

export function Msg<T>(): Message<T>
export namespace Msg {
export const all: typeof Message.all;
export const race: typeof Message.race;
}
export class ArchStream<T> implements Transform<T, TransformStream<T, {}>>, Importable<T, ComposeStream<T, void>, void> {
proxy<U extends StreamProxy<T, {}, {}>>(proxy: (shadow?: TransformStream<T, {}>) => U): U&TransformStream<T, U>;
pipe(callback: Callback<T>): TransformStream<T, {}>;
import(module: ModularStream<T>): ComposeStream<T, void>;
import<U>(extract: (entity: T) => U): ComposeStream<T, U>;
export class ArchStream<T> implements Transform<T, ITransformStream<T, {}>>, Importable<T, IComposeStream<T, void>, void> {
proxy<U extends IProxy<T, {}, {}>>(proxy: (shadow?: ITransformStream<T, {}>) => U): U&ITransformStream<T, U>;
pipe(callback: ICallback<T>): ITransformStream<T, {}>;
import(module: IModularStream<T>): IComposeStream<T, void>;
import<U>(extract: (entity: T) => U): IComposeStream<T, U>;
}
export interface Callback<T> {
(entity: T): any;
export interface ICallback<T> {
(entity: T): IThenable<T>|IThenable<T>[]|any;
}
export interface TransformStream<T, U extends {}> extends Transform<T, TransformStream<T, {}>>, Exportable<T, ModularStream<T>> {
proxy<V extends StreamProxy<T, U, {}>>(proxy: (shadow: TransformStream<T, U>) => V): U&V&TransformStream<T, U&V>;
pipe(callback: Callback<T>): U&TransformStream<T, U>;
export interface IThenable<T> {
then(done: ICallback<T>, fail?: ICallback<T>): IThenable<T>;
}
export interface ComposeStream<T, U> extends Importable<T, ComposeStream<T, U>, U>, Exportable<T, ModularStream<T>> {
export interface ITransformStream<T, U extends {}> extends Transform<T, ITransformStream<T, {}>>, Exportable<T, IModularStream<T>> {
proxy<V extends IProxy<T, U, {}>>(proxy: (shadow: ITransformStream<T, U>) => V): U&V&ITransformStream<T, U&V>;
pipe(callback: ICallback<T>): U&ITransformStream<T, U>;
}
export interface IComposeStream<T, U> extends Importable<T, IComposeStream<T, U>, U>, Exportable<T, IModularStream<T>> {
}
interface Transform<T, U> {
pipe(callback: Callback<T>): U;
pipe(callback: ICallback<T>): U;
}
interface Importable<T, U, V> {
import(module: ModularStream<T>, MethodEntity?: new (..._) => V): U;
import(module: IModularStream<T>, MethodEntity?: new (..._) => V): U;
}

@@ -45,10 +56,10 @@ interface Exportable<T, U> {

}
export interface ModularStream<T> extends ModularReadableStream<T>, ModularWritableStream<T> {
flow(volume: number, limit?: number, discharger?: (queue: T[], processing: T[]) => any): ModularReadableStream<T>;
export interface IModularStream<T> extends IModularReadableStream<T>, IModularWritableStream<T> {
flow(volume: number, limit?: number, discharger?: (queue: T[], processing: T[]) => any): IModularReadableStream<T>;
}
export interface ModularReadableStream<T> extends Readable<T, ModularWritableStream<T>, ModularWritableWithStream<T>> {
export interface IModularReadableStream<T> extends Readable<T, IModularWritableStream<T>, IModularWritableWithStream<T>> {
}
export interface ModularWritableStream<T> extends Writable<T, ModularWritableStream<T>> {
export interface IModularWritableStream<T> extends Writable<T, IModularWritableStream<T>> {
}
export interface ModularWritableWithStream<T> extends WritableWith<T, ModularWritableWithStream<T>> {
export interface IModularWritableWithStream<T> extends WritableWith<T, IModularWritableWithStream<T>> {
}

@@ -63,27 +74,30 @@ interface Readable<T, U, V> {

interface WritableWith<T, U> {
write(entity: T, callback: Callback<T>): U;
write(entity: T, callback: ICallback<T>): U;
}
export class Message<T> {
send(data: T, callback?: Callback<T>): Message<T>
send(data: T, async?: boolean, callback?: Callback<T>): Message<T>
recv(callback: (data: T) => any): Message<T>;
static all<T>(thenables: (IThenable<T>|T)[]): IThenable<T[]>;
static race<T>(thenables: (IThenable<T>|T)[]): IThenable<T>;
send(data: T, callback?: ICallback<T>): Message<T>;
send(data: T, async?: boolean, callback?: ICallback<T>): Message<T>;
recv(callback: ICallback<T>): Message<T>;
trans<U>(callback: (data: T) => U|IThenable<U>): Message<U>;
}
export const Proxy: {
Case<T, U extends number|string>(index: U[], indexer: (entity: T) => U): <U>(shadow?: TransformStream<T, U>) => CaseProxy<T, U>;
Hook<T>(hooks: { pre?: Callback<T>, post?: Callback<T> }): <U>(shadow?: TransformStream<T, U>) => HookProxy<T, U>;
Responsibility<T>(): <U>(shadow?: TransformStream<T, U>) => ResponsibilityProxy<T, U>;
Case<T, U extends number|string>(index: U[], indexer: (entity: T) => U): <U>(shadow?: ITransformStream<T, U>) => CaseProxy<T, U>;
Hook<T>(hooks: { pre?: ICallback<T>, post?: ICallback<T> }): <U>(shadow?: ITransformStream<T, U>) => HookProxy<T, U>;
Responsibility<T>(): <U>(shadow?: ITransformStream<T, U>) => ResponsibilityProxy<T, U>;
};
export type Proxy = typeof Proxy;
interface StreamProxy<T, U, V> {
[method: string]: (...args) => U&V&TransformStream<T, U&V>;
interface IProxy<T, U, V> {
[method: string]: (...args) => U&V&ITransformStream<T, U&V>;
}
interface CaseProxy<T, U> extends StreamProxy<T, U, CaseProxy<T, U>> {
pipe(...callbacks: Callback<T>[]): U&CaseProxy<T, U>&TransformStream<T, U&CaseProxy<T, U>>;
interface CaseProxy<T, U> extends IProxy<T, U, CaseProxy<T, U>> {
pipe(...callbacks: ICallback<T>[]): U&CaseProxy<T, U>&ITransformStream<T, U&CaseProxy<T, U>>;
}
interface HookProxy<T, U> extends StreamProxy<T, U, {}> {
interface HookProxy<T, U> extends IProxy<T, U, {}> {
}
interface ResponsibilityProxy<T, U> extends StreamProxy<T, U, {}> {
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&TransformStream<T, U>;
interface ResponsibilityProxy<T, U> extends IProxy<T, U, {}> {
rule<V>(LocalEntity: new (..._) => V, extract: (entity: T) => V): U&ITransformStream<T, U>;
}

@@ -100,4 +114,6 @@

}
interface Listener<T> extends Callback<T> {
interface Listener<T> {
(entity: T): any;
}
}
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