diff --git a/dist/mesh.js b/dist/mesh.js index 07b1f12..199f728 100644 --- a/dist/mesh.js +++ b/dist/mesh.js @@ -33,24 +33,34 @@ module.exports = { * responses */ - Response: require(25), - EmptyResponse: require(23), - ErrorResponse: require(24), - BufferedResponse: require(22), - NodeStreamResponse: require(26), + Response: require(27), + EmptyResponse: require(25), + ErrorResponse: require(26), + BufferedResponse: require(24), + NodeStreamResponse: require(28), /** */ - WritableStream: require(29) + WritableStream: require(31) }; -},{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"2":2,"22":22,"23":23,"24":24,"25":25,"26":26,"29":29,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}],2:[function(require,module,exports){ +if (typeof window !== "undefined") { + + module.exports.noConflict = function () { + delete window.mesh; + return module.exports; + }; + + window.mesh = module.exports; +} + +},{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"2":2,"24":24,"25":25,"26":26,"27":27,"28":28,"3":3,"31":31,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}],2:[function(require,module,exports){ 'use strict'; var Bus = require(4); var NoopBus = require(10); -var Response = require(25); +var Response = require(27); /** */ @@ -98,7 +108,7 @@ Bus.extend(AcceptBus, { module.exports = AcceptBus; -},{"10":10,"25":25,"4":4}],3:[function(require,module,exports){ +},{"10":10,"27":27,"4":4}],3:[function(require,module,exports){ 'use strict'; var Bus = require(4); @@ -142,7 +152,7 @@ module.exports = AttachDefaultsBus; },{"4":4}],4:[function(require,module,exports){ 'use strict'; -var extend = require(21); +var extend = require(22); /** */ @@ -165,7 +175,7 @@ extend(Bus, { /** */ -Bus.create = require(20); +Bus.create = require(21); Bus.extend = extend; /** @@ -173,11 +183,11 @@ Bus.extend = extend; module.exports = Bus; -},{"20":20,"21":21}],5:[function(require,module,exports){ +},{"21":21,"22":22}],5:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var BufferedResponse = require(22); +var BufferedResponse = require(24); /** */ @@ -205,11 +215,11 @@ Bus.extend(BufferedBus, { module.exports = BufferedBus; -},{"22":22,"4":4}],6:[function(require,module,exports){ +},{"24":24,"4":4}],6:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -257,11 +267,11 @@ Bus.extend(CatchErrorBus, { module.exports = CatchErrorBus; -},{"25":25,"4":4}],7:[function(require,module,exports){ +},{"27":27,"4":4}],7:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -291,11 +301,11 @@ Bus.extend(DelayedBus, { module.exports = DelayedBus; -},{"25":25,"4":4}],8:[function(require,module,exports){ +},{"27":27,"4":4}],8:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -346,11 +356,11 @@ Bus.extend(FallbackBus, { module.exports = FallbackBus; -},{"25":25,"4":4}],9:[function(require,module,exports){ +},{"27":27,"4":4}],9:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -396,11 +406,11 @@ Bus.extend(MapBus, { module.exports = MapBus; -},{"25":25,"4":4}],10:[function(require,module,exports){ +},{"27":27,"4":4}],10:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var EmptyResponse = require(23); +var EmptyResponse = require(25); /** */ @@ -425,11 +435,11 @@ Bus.extend(NoopBus, { module.exports = NoopBus; -},{"23":23,"4":4}],11:[function(require,module,exports){ +},{"25":25,"4":4}],11:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -470,11 +480,11 @@ Bus.extend(ParallelBus, { module.exports = ParallelBus; -},{"25":25,"4":4}],12:[function(require,module,exports){ +},{"27":27,"4":4}],12:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -524,7 +534,7 @@ Bus.extend(RaceBus, { module.exports = RaceBus; -},{"25":25,"4":4}],13:[function(require,module,exports){ +},{"27":27,"4":4}],13:[function(require,module,exports){ 'use strict'; var Bus = require(4); @@ -580,7 +590,7 @@ module.exports = RejectBus; 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -642,7 +652,7 @@ Bus.extend(RetryBus, { module.exports = RetryBus; -},{"25":25,"4":4}],16:[function(require,module,exports){ +},{"27":27,"4":4}],16:[function(require,module,exports){ 'use strict'; var Bus = require(4); @@ -679,7 +689,7 @@ module.exports = RoundRobinBus; 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -723,11 +733,11 @@ Bus.extend(SequenceBus, { module.exports = SequenceBus; -},{"25":25,"4":4}],18:[function(require,module,exports){ +},{"27":27,"4":4}],18:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var Response = require(25); +var Response = require(27); /** */ @@ -779,13 +789,13 @@ Bus.extend(TailableBus, { module.exports = TailableBus; -},{"25":25,"4":4}],19:[function(require,module,exports){ +},{"27":27,"4":4}],19:[function(require,module,exports){ 'use strict'; var Bus = require(4); -var extend = require(21); -var Response = require(25); -var BufferedResponse = require(22); +var extend = require(22); +var Response = require(27); +var BufferedResponse = require(24); /** */ @@ -835,7 +845,21 @@ extend(Bus, WrapBus, { module.exports = WrapBus; -},{"21":21,"22":22,"25":25,"4":4}],20:[function(require,module,exports){ +},{"22":22,"24":24,"27":27,"4":4}],20:[function(require,module,exports){ +"use strict"; + +module.exports = function (to) { + var fromObjects = Array.prototype.slice.call(arguments, 1); + for (var i = 0, n = fromObjects.length; i < n; i++) { + var fm = fromObjects[i]; + for (var key in fm) { + to[key] = fm[key]; + } + } + return to; +}; + +},{}],21:[function(require,module,exports){ "use strict"; module.exports = function () { @@ -844,14 +868,15 @@ module.exports = function () { return object; }; -},{}],21:[function(require,module,exports){ +},{}],22:[function(require,module,exports){ +'use strict'; + +var copy = require(20); /** * IE8+ compatible subclassing. See https://babeljs.io/docs/advanced/caveats/ */ -'use strict'; - module.exports = function (parent, child) { var props; @@ -880,20 +905,28 @@ module.exports = function (parent, child) { this.constructor = c; } - Object.assign(c, p); // copy static props + copy(c, p); // copy static props ctor.prototype = p.prototype; c.prototype = new ctor(); - Object.assign(c.prototype, Object.assign.apply(Object, [{}].concat(props))); + copy(c.prototype, copy.apply(Object, [{}].concat(props))); return c; }; -},{}],22:[function(require,module,exports){ +},{"20":20}],23:[function(require,module,exports){ +"use strict"; + +module.exports = function (target) { + return Object.prototype.toString.call(target) === "[object Array]"; +}; + +},{}],24:[function(require,module,exports){ 'use strict'; -var Response = require(25); +var Response = require(27); +var isArray = require(23); /** */ @@ -901,7 +934,7 @@ var Response = require(25); function BufferedResponse(error, chunkValues) { Response.call(this, function (writable) { if (error) writable.abort(error); - chunkValues = Array.isArray(chunkValues) ? chunkValues : chunkValues != void 0 ? [chunkValues] : []; + chunkValues = isArray(chunkValues) ? chunkValues : chunkValues != void 0 ? [chunkValues] : []; chunkValues.forEach(writable.write.bind(writable)); writable.close(); }); @@ -917,11 +950,11 @@ Response.extend(BufferedResponse); module.exports = BufferedResponse; -},{"25":25}],23:[function(require,module,exports){ +},{"23":23,"27":27}],25:[function(require,module,exports){ 'use strict'; -var BufferedResponse = require(22); -var extend = require(21); +var BufferedResponse = require(24); +var extend = require(22); /** */ @@ -940,10 +973,10 @@ BufferedResponse.extend(EmptyResponse); module.exports = EmptyResponse; -},{"21":21,"22":22}],24:[function(require,module,exports){ +},{"22":22,"24":24}],26:[function(require,module,exports){ 'use strict'; -var BufferedResponse = require(22); +var BufferedResponse = require(24); /** */ @@ -962,11 +995,11 @@ BufferedResponse.extend(ErrorResponse); module.exports = ErrorResponse; -},{"22":22}],25:[function(require,module,exports){ +},{"24":24}],27:[function(require,module,exports){ 'use strict'; -var WritableStream = require(29); -var extend = require(21); +var WritableStream = require(31); +var extend = require(22); /** * Creates a new Streamed response @@ -1035,7 +1068,7 @@ extend(Response, { /** */ -Response.create = require(20); +Response.create = require(21); Response.extend = extend; /** @@ -1043,10 +1076,10 @@ Response.extend = extend; module.exports = Response; -},{"20":20,"21":21,"29":29}],26:[function(require,module,exports){ +},{"21":21,"22":22,"31":31}],28:[function(require,module,exports){ 'use strict'; -var Response = require(25); +var Response = require(27); /** */ @@ -1085,10 +1118,10 @@ Response.extend(NodeStreamResponse); module.exports = NodeStreamResponse; -},{"25":25}],27:[function(require,module,exports){ +},{"27":27}],29:[function(require,module,exports){ 'use strict'; -var extend = require(21); +var extend = require(22); /** */ @@ -1195,17 +1228,17 @@ extend(PassThrough, { /** */ -PassThrough.create = require(20); +PassThrough.create = require(21); /** */ module.exports = PassThrough; -},{"20":20,"21":21}],28:[function(require,module,exports){ +},{"21":21,"22":22}],30:[function(require,module,exports){ 'use strict'; -var extend = require(21); +var extend = require(22); /** */ @@ -1258,19 +1291,19 @@ extend(ReadableStream, { /** */ -ReadableStream.create = require(20); +ReadableStream.create = require(21); /** */ module.exports = ReadableStream; -},{"20":20,"21":21}],29:[function(require,module,exports){ +},{"21":21,"22":22}],31:[function(require,module,exports){ 'use strict'; -var extend = require(21); -var PassThrough = require(27); -var ReadableStream = require(28); +var extend = require(22); +var PassThrough = require(29); +var ReadableStream = require(30); /** */ @@ -1331,12 +1364,12 @@ extend(WritableStream, { /** */ -WritableStream.create = require(20); -WritableStream.extend = require(21); +WritableStream.create = require(21); +WritableStream.extend = require(22); /** */ module.exports = WritableStream; -},{"20":20,"21":21,"27":27,"28":28}]},{},[1]); +},{"21":21,"22":22,"29":29,"30":30}]},{},[1]); diff --git a/dist/mesh.min.js b/dist/mesh.min.js index 151f51b..e02111c 100644 --- a/dist/mesh.min.js +++ b/dist/mesh.min.js @@ -1 +1 @@ -!function t(e,n,r){function i(o,u){if(!n[o]){if(!e[o]){var c="function"==typeof require&&require;if(!u&&c)return c(o,!0);if(s)return s(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var f=n[o]={exports:{}};e[o][0].call(f.exports,function(t){var n=e[o][1][t];return i(n?n:t)},f,f.exports,t,e,n,r)}return n[o].exports}for(var s="function"==typeof require&&require,o=0;on;n++){var i=e[n];for(var s in i)void 0==t[s]&&(t[s]=i[s])}return t}function i(t,e){this._properties=t,this._bus=e}var s=t(4);s.extend(i,{execute:function(t){return this._bus.execute(r(t,this._properties))}}),e.exports=i},{4:4}],4:[function(t,e,n){"use strict";function r(){}var i=t(21);i(r,{execute:function(t){}}),r.create=t(20),r.extend=i,e.exports=r},{20:20,21:21}],5:[function(t,e,n){"use strict";function r(t,e){this._error=t,this._chunkValues=e}var i=t(4),s=t(22);i.extend(r,{execute:function(t){return s.create(this._error,this._chunkValues)}}),e.exports=r},{22:22,4:4}],6:[function(t,e,n){"use strict";function r(t,e){this._bus=t,this._catchError=e}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){e._bus.execute(t).pipeTo({write:function(t){n.write(t)},close:function(){n.close()},abort:function(r){try{e._catchError(r,t);n.close()}catch(i){n.abort(i)}}})})}}),e.exports=r},{25:25,4:4}],7:[function(t,e,n){"use strict";function r(t,e){this._ms=e,this._bus=t}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){setTimeout(function(){e._bus.execute(t).pipeTo(n)},e._ms)})}}),e.exports=r},{25:25,4:4}],8:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=function s(e){if(e===r.length)return n.close();var i=r[e].execute(t),o=!1;i.pipeTo({write:function(t){o=!0,n.write(t)},close:function(){o?n.close():s(e+1)},abort:n.abort.bind(n)})};i(0)})}}),e.exports=r},{25:25,4:4}],9:[function(t,e,n){"use strict";function r(t,e){this._bus=t,this._map=e}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){e._bus.execute(t).pipeTo({write:function(r){try{e._map(r,n,t)}catch(i){return n.abort(i),Promise.reject(i)}},close:function(){n.close()},abort:n.abort.bind(n)})})}}),e.exports=r},{25:25,4:4}],10:[function(t,e,n){"use strict";function r(){}var i=t(4),s=t(23);i.extend(r,{execute:function(t){return s.create()}}),e.exports=r},{23:23,4:4}],11:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=r.length;r.forEach(function(e){var r=e.execute(t);r.pipeTo(n,{preventClose:!0}),r.then(function(){--i||n.close()})})})}}),e.exports=r},{25:25,4:4}],12:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=r.length,s=-1;r.forEach(function(e,r){var o=e.execute(t);o.pipeTo({write:function(t){~s&&s!==r||(s=r,n.write(t))},close:function(){(~s&&s===r||0===--i)&&n.close()},abort:n.abort.bind(n)})})})}}),e.exports=r},{25:25,4:4}],13:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4);i.extend(r,{execute:function(t){return this._busses[Math.floor(Math.random()*this._busses.length)].execute(t)}}),e.exports=r},{4:4}],14:[function(t,e,n){"use strict";function r(t,e,n){i.call(this,t,n,e)}var i=t(2);i.extend(r),e.exports=r},{2:2}],15:[function(t,e,n){"use strict";function r(t,e,n){2===arguments.length&&(n=e,e=function(t,e){return!0}),this._maxRetries=t,this._bus=n,this._errorFilter=e}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r,i=!1,s=function o(s){if(!s)return n.abort(r);var u=e._bus.execute(t);u.pipeTo({write:function(t){i=!0,n.write(t)},close:function(){n.close()},abort:function(t){r=t,o(s-1)}})};s(e._maxRetries)})}}),e.exports=r},{25:25,4:4}],16:[function(t,e,n){"use strict";function r(t){this._busses=t,this._i=0}var i=t(4);i.extend(r,{execute:function(t){var e=this._busses[this._i].execute(t);return this._i=(this._i+1)%this._busses.length,e}}),e.exports=r},{4:4}],17:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(25);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=function s(e){if(e===r.length)return n.close();var i=r[e].execute(t);i.pipeTo(n,{preventClose:!0}),i.then(function(){return s(e+1)})};i(0)})}}),e.exports=r},{25:25,4:4}],18:[function(t,e,n){"use strict";function r(t){this._bus=t,this._tails=[]}var i=t(4),s=t(25);i.extend(r,{addTail:function(t){var e=this;return s.create(function(t){e._tails.push(t),t.then(function(){e._tails.splice(e._tails.indexOf(t),1)})})},execute:function(t){var e=this,n=this._bus.execute(t);return n.then(function(){e._tails.forEach(function(e){e.write(t)})}),n}}),e.exports=r},{25:25,4:4}],19:[function(t,e,n){"use strict";function r(t){t.length>=2?this._execute=function(e){return new Promise(function(n,r){t(e,function(t,e){return t?r(t):void n.apply(this,Array.prototype.slice.call(arguments,1))})})}:this._execute=t}var i=t(4),s=t(21),o=t(25),u=t(22);s(i,r,{execute:function(t){var e=this._execute(t);return e&&e.read?e:e&&e.then?e.then?o.create(function(t){e.then(function(e){void 0!=e&&t.write(e),t.close()},t.abort.bind(t))}):void 0:u.create(void 0,e)}}),e.exports=r},{21:21,22:22,25:25,4:4}],20:[function(t,e,n){"use strict";e.exports=function(){var t=Object.create(this.prototype);return this.apply(t,arguments),t}},{}],21:[function(t,e,n){"use strict";e.exports=function(t,e){function n(){this.constructor=s}var r,i,s=e,o=t;return"function"==typeof s?i=2:("object"==typeof o?(s=function(){},i=0):(s=o||function(){},i=1),o="function"==typeof this?this:Object),r=Array.prototype.slice.call(arguments,i),Object.assign(s,o),n.prototype=o.prototype,s.prototype=new n,Object.assign(s.prototype,Object.assign.apply(Object,[{}].concat(r))),s}},{}],22:[function(t,e,n){"use strict";function r(t,e){i.call(this,function(n){t&&n.abort(t),e=Array.isArray(e)?e:void 0!=e?[e]:[],e.forEach(n.write.bind(n)),n.close()})}var i=t(25);i.extend(r),e.exports=r},{25:25}],23:[function(t,e,n){"use strict";function r(){i.call(this)}var i=t(22);t(21);i.extend(r),e.exports=r},{21:21,22:22}],24:[function(t,e,n){"use strict";function r(t){i.call(this,t)}var i=t(22);i.extend(r),e.exports=r},{22:22}],25:[function(t,e,n){"use strict";function r(t){var e=this._writer=i.create();if(this._reader=e.getReader(),t){var n=t(e);n&&n.then&&n.then(function(){e.close()},e.abort.bind(e))}}var i=t(29),s=t(21);s(r,{then:function(t,e){return this._writer.then(t,e)},"catch":function(t){return this._writer["catch"](t)},read:function(){return this._reader.read()},pipeTo:function(t,e){return this._reader.pipeTo(t,e)},cancel:function(){return this._reader.cancel()}}),r.create=t(20),r.extend=s,e.exports=r},{20:20,21:21,29:29}],26:[function(t,e,n){"use strict";function r(t){i.call(this,function(e){if(!t)return e.close();var n=function i(){t.resume(),t.once("data",function(n){t.pause(),e.write(n).then(i)})},r=function(){e.close()};t.once("end",r).once("error",e.abort.bind(e)),n()})}var i=t(25);i.extend(r),e.exports=r},{25:25}],27:[function(t,e,n){"use strict";function r(){var t=this;this._values=[],this._promise=new Promise(function(e,n){t._resolve=e,t._reject=n})}var i=t(21);i(r,{then:function(t,e){return this._promise.then(t,e)},__signalWrite:function(){},__signalRead:function(){},write:function(t){var e=this;return this._closed?Promise.reject(new Error("cannot write to a closed stream")):(this._values.push(t),this.__signalWrite(),new Promise(function(t,n){e.__signalRead=function(){e.__signalRead=function(){},t()}}))},read:function(){var t=this;return this.__signalRead(),this._error?(this._reject(this._error),Promise.reject(this._error)):this._values.length?Promise.resolve({value:this._values.shift(),done:!1}):this._closed?(this._resolve(),Promise.resolve({value:void 0,done:!0})):new Promise(function(e,n){t.__signalWrite=function(){t.__signalWrite=function(){},t.read().then(e,n)}})},abort:function(t){this._error=t,this.__signalWrite()},close:function(){this._closed=!0,this.__signalWrite()}}),r.create=t(20),e.exports=r},{20:20,21:21}],28:[function(t,e,n){"use strict";function r(t){this._passThrough=t}var i=t(21);i(r,{read:function(){return this._passThrough.read()},pipeTo:function(t,e){var n=this;e||(e={});var r=function i(){n.read().then(function(n){n.done?e.preventClose||t.close():(t.write(n.value),i())},e.preventAbort?void 0:t.abort.bind(t))};return r(),t},cancel:function(){return this._passThrough.close()}}),r.create=t(20),e.exports=r},{20:20,21:21}],29:[function(t,e,n){"use strict";function r(t){this._passThrough=s.create(),this._reader=o.create(this._passThrough)}var i=t(21),s=t(27),o=t(28);i(r,{then:function(t,e){return this._passThrough.then(t,e)},"catch":function(t){return this.then(void 0,t)},write:function(t){return this._passThrough.write(t)},abort:function(t){this._passThrough.abort(t)},close:function(){this._passThrough.close()},getReader:function(){return this._reader}}),r.create=t(20),r.extend=t(21),e.exports=r},{20:20,21:21,27:27,28:28}]},{},[1]); \ No newline at end of file +!function t(e,n,r){function i(o,u){if(!n[o]){if(!e[o]){var c="function"==typeof require&&require;if(!u&&c)return c(o,!0);if(s)return s(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var f=n[o]={exports:{}};e[o][0].call(f.exports,function(t){var n=e[o][1][t];return i(n?n:t)},f,f.exports,t,e,n,r)}return n[o].exports}for(var s="function"==typeof require&&require,o=0;on;n++){var i=e[n];for(var s in i)void 0==t[s]&&(t[s]=i[s])}return t}function i(t,e){this._properties=t,this._bus=e}var s=t(4);s.extend(i,{execute:function(t){return this._bus.execute(r(t,this._properties))}}),e.exports=i},{4:4}],4:[function(t,e,n){"use strict";function r(){}var i=t(22);i(r,{execute:function(t){}}),r.create=t(21),r.extend=i,e.exports=r},{21:21,22:22}],5:[function(t,e,n){"use strict";function r(t,e){this._error=t,this._chunkValues=e}var i=t(4),s=t(24);i.extend(r,{execute:function(t){return s.create(this._error,this._chunkValues)}}),e.exports=r},{24:24,4:4}],6:[function(t,e,n){"use strict";function r(t,e){this._bus=t,this._catchError=e}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){e._bus.execute(t).pipeTo({write:function(t){n.write(t)},close:function(){n.close()},abort:function(r){try{e._catchError(r,t);n.close()}catch(i){n.abort(i)}}})})}}),e.exports=r},{27:27,4:4}],7:[function(t,e,n){"use strict";function r(t,e){this._ms=e,this._bus=t}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){setTimeout(function(){e._bus.execute(t).pipeTo(n)},e._ms)})}}),e.exports=r},{27:27,4:4}],8:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=function s(e){if(e===r.length)return n.close();var i=r[e].execute(t),o=!1;i.pipeTo({write:function(t){o=!0,n.write(t)},close:function(){o?n.close():s(e+1)},abort:n.abort.bind(n)})};i(0)})}}),e.exports=r},{27:27,4:4}],9:[function(t,e,n){"use strict";function r(t,e){this._bus=t,this._map=e}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){e._bus.execute(t).pipeTo({write:function(r){try{e._map(r,n,t)}catch(i){return n.abort(i),Promise.reject(i)}},close:function(){n.close()},abort:n.abort.bind(n)})})}}),e.exports=r},{27:27,4:4}],10:[function(t,e,n){"use strict";function r(){}var i=t(4),s=t(25);i.extend(r,{execute:function(t){return s.create()}}),e.exports=r},{25:25,4:4}],11:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=r.length;r.forEach(function(e){var r=e.execute(t);r.pipeTo(n,{preventClose:!0}),r.then(function(){--i||n.close()})})})}}),e.exports=r},{27:27,4:4}],12:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=r.length,s=-1;r.forEach(function(e,r){var o=e.execute(t);o.pipeTo({write:function(t){~s&&s!==r||(s=r,n.write(t))},close:function(){(~s&&s===r||0===--i)&&n.close()},abort:n.abort.bind(n)})})})}}),e.exports=r},{27:27,4:4}],13:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4);i.extend(r,{execute:function(t){return this._busses[Math.floor(Math.random()*this._busses.length)].execute(t)}}),e.exports=r},{4:4}],14:[function(t,e,n){"use strict";function r(t,e,n){i.call(this,t,n,e)}var i=t(2);i.extend(r),e.exports=r},{2:2}],15:[function(t,e,n){"use strict";function r(t,e,n){2===arguments.length&&(n=e,e=function(t,e){return!0}),this._maxRetries=t,this._bus=n,this._errorFilter=e}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r,i=!1,s=function o(s){if(!s)return n.abort(r);var u=e._bus.execute(t);u.pipeTo({write:function(t){i=!0,n.write(t)},close:function(){n.close()},abort:function(t){r=t,o(s-1)}})};s(e._maxRetries)})}}),e.exports=r},{27:27,4:4}],16:[function(t,e,n){"use strict";function r(t){this._busses=t,this._i=0}var i=t(4);i.extend(r,{execute:function(t){var e=this._busses[this._i].execute(t);return this._i=(this._i+1)%this._busses.length,e}}),e.exports=r},{4:4}],17:[function(t,e,n){"use strict";function r(t){this._busses=t}var i=t(4),s=t(27);i.extend(r,{execute:function(t){var e=this;return s.create(function(n){var r=e._busses.concat(),i=function s(e){if(e===r.length)return n.close();var i=r[e].execute(t);i.pipeTo(n,{preventClose:!0}),i.then(function(){return s(e+1)})};i(0)})}}),e.exports=r},{27:27,4:4}],18:[function(t,e,n){"use strict";function r(t){this._bus=t,this._tails=[]}var i=t(4),s=t(27);i.extend(r,{addTail:function(t){var e=this;return s.create(function(t){e._tails.push(t),t.then(function(){e._tails.splice(e._tails.indexOf(t),1)})})},execute:function(t){var e=this,n=this._bus.execute(t);return n.then(function(){e._tails.forEach(function(e){e.write(t)})}),n}}),e.exports=r},{27:27,4:4}],19:[function(t,e,n){"use strict";function r(t){t.length>=2?this._execute=function(e){return new Promise(function(n,r){t(e,function(t,e){return t?r(t):void n.apply(this,Array.prototype.slice.call(arguments,1))})})}:this._execute=t}var i=t(4),s=t(22),o=t(27),u=t(24);s(i,r,{execute:function(t){var e=this._execute(t);return e&&e.read?e:e&&e.then?e.then?o.create(function(t){e.then(function(e){void 0!=e&&t.write(e),t.close()},t.abort.bind(t))}):void 0:u.create(void 0,e)}}),e.exports=r},{22:22,24:24,27:27,4:4}],20:[function(t,e,n){"use strict";e.exports=function(t){for(var e=Array.prototype.slice.call(arguments,1),n=0,r=e.length;r>n;n++){var i=e[n];for(var s in i)t[s]=i[s]}return t}},{}],21:[function(t,e,n){"use strict";e.exports=function(){var t=Object.create(this.prototype);return this.apply(t,arguments),t}},{}],22:[function(t,e,n){"use strict";var r=t(20);e.exports=function(t,e){function n(){this.constructor=o}var i,s,o=e,u=t;return"function"==typeof o?s=2:("object"==typeof u?(o=function(){},s=0):(o=u||function(){},s=1),u="function"==typeof this?this:Object),i=Array.prototype.slice.call(arguments,s),r(o,u),n.prototype=u.prototype,o.prototype=new n,r(o.prototype,r.apply(Object,[{}].concat(i))),o}},{20:20}],23:[function(t,e,n){"use strict";e.exports=function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],24:[function(t,e,n){"use strict";function r(t,e){i.call(this,function(n){t&&n.abort(t),e=s(e)?e:void 0!=e?[e]:[],e.forEach(n.write.bind(n)),n.close()})}var i=t(27),s=t(23);i.extend(r),e.exports=r},{23:23,27:27}],25:[function(t,e,n){"use strict";function r(){i.call(this)}var i=t(24);t(22);i.extend(r),e.exports=r},{22:22,24:24}],26:[function(t,e,n){"use strict";function r(t){i.call(this,t)}var i=t(24);i.extend(r),e.exports=r},{24:24}],27:[function(t,e,n){"use strict";function r(t){var e=this._writer=i.create();if(this._reader=e.getReader(),t){var n=t(e);n&&n.then&&n.then(function(){e.close()},e.abort.bind(e))}}var i=t(31),s=t(22);s(r,{then:function(t,e){return this._writer.then(t,e)},"catch":function(t){return this._writer["catch"](t)},read:function(){return this._reader.read()},pipeTo:function(t,e){return this._reader.pipeTo(t,e)},cancel:function(){return this._reader.cancel()}}),r.create=t(21),r.extend=s,e.exports=r},{21:21,22:22,31:31}],28:[function(t,e,n){"use strict";function r(t){i.call(this,function(e){if(!t)return e.close();var n=function i(){t.resume(),t.once("data",function(n){t.pause(),e.write(n).then(i)})},r=function(){e.close()};t.once("end",r).once("error",e.abort.bind(e)),n()})}var i=t(27);i.extend(r),e.exports=r},{27:27}],29:[function(t,e,n){"use strict";function r(){var t=this;this._values=[],this._promise=new Promise(function(e,n){t._resolve=e,t._reject=n})}var i=t(22);i(r,{then:function(t,e){return this._promise.then(t,e)},__signalWrite:function(){},__signalRead:function(){},write:function(t){var e=this;return this._closed?Promise.reject(new Error("cannot write to a closed stream")):(this._values.push(t),this.__signalWrite(),new Promise(function(t,n){e.__signalRead=function(){e.__signalRead=function(){},t()}}))},read:function(){var t=this;return this.__signalRead(),this._error?(this._reject(this._error),Promise.reject(this._error)):this._values.length?Promise.resolve({value:this._values.shift(),done:!1}):this._closed?(this._resolve(),Promise.resolve({value:void 0,done:!0})):new Promise(function(e,n){t.__signalWrite=function(){t.__signalWrite=function(){},t.read().then(e,n)}})},abort:function(t){this._error=t,this.__signalWrite()},close:function(){this._closed=!0,this.__signalWrite()}}),r.create=t(21),e.exports=r},{21:21,22:22}],30:[function(t,e,n){"use strict";function r(t){this._passThrough=t}var i=t(22);i(r,{read:function(){return this._passThrough.read()},pipeTo:function(t,e){var n=this;e||(e={});var r=function i(){n.read().then(function(n){n.done?e.preventClose||t.close():(t.write(n.value),i())},e.preventAbort?void 0:t.abort.bind(t))};return r(),t},cancel:function(){return this._passThrough.close()}}),r.create=t(21),e.exports=r},{21:21,22:22}],31:[function(t,e,n){"use strict";function r(t){this._passThrough=s.create(),this._reader=o.create(this._passThrough)}var i=t(22),s=t(29),o=t(30);i(r,{then:function(t,e){return this._passThrough.then(t,e)},"catch":function(t){return this.then(void 0,t)},write:function(t){return this._passThrough.write(t)},abort:function(t){this._passThrough.abort(t)},close:function(){this._passThrough.close()},getReader:function(){return this._reader}}),r.create=t(21),r.extend=t(22),e.exports=r},{21:21,22:22,29:29,30:30}]},{},[1]); \ No newline at end of file diff --git a/index.js b/index.js index becf928..6d12cfe 100644 --- a/index.js +++ b/index.js @@ -41,4 +41,14 @@ module.exports = { */ WritableStream : require('./stream/writable') +}; + +if (typeof window !== "undefined") { + + module.exports.noConflict = function() { + delete window.mesh; + return module.exports; + }; + + window.mesh = module.exports } diff --git a/internal/copy.js b/internal/copy.js new file mode 100644 index 0000000..c62cec2 --- /dev/null +++ b/internal/copy.js @@ -0,0 +1,10 @@ +module.exports = function(to) { + var fromObjects = Array.prototype.slice.call(arguments, 1); + for (var i = 0, n = fromObjects.length; i < n; i++) { + var fm = fromObjects[i]; + for (var key in fm) { + to[key] = fm[key]; + } + } + return to; +} diff --git a/internal/extend.js b/internal/extend.js index e6971d7..064c87f 100644 --- a/internal/extend.js +++ b/internal/extend.js @@ -1,3 +1,4 @@ +var copy = require("./copy"); /** * IE8+ compatible subclassing. See https://babeljs.io/docs/advanced/caveats/ @@ -31,12 +32,12 @@ module.exports = function(parent, child) { this.constructor = c; } - Object.assign(c, p); // copy static props + copy(c, p); // copy static props ctor.prototype = p.prototype; c.prototype = new ctor(); - Object.assign(c.prototype, Object.assign.apply(Object, [{}].concat(props))); + copy(c.prototype, copy.apply(Object, [{}].concat(props))); return c; }; diff --git a/internal/is-array.js b/internal/is-array.js new file mode 100644 index 0000000..1f1a773 --- /dev/null +++ b/internal/is-array.js @@ -0,0 +1,3 @@ +module.exports = function(target) { + return Object.prototype.toString.call(target) === "[object Array]"; +}; diff --git a/old/buffered.js b/old/buffered.js deleted file mode 100644 index d69f636..0000000 --- a/old/buffered.js +++ /dev/null @@ -1,23 +0,0 @@ -var Response = require('./index'); - -/** - */ - -function BufferedResponse(error, chunkValues) { - Response.call(this, function(writable) { - if (error) writable.abort(error); - chunkValues = Array.isArray(chunkValues) ? chunkValues : chunkValues != void 0 ? [chunkValues] : []; - chunkValues.forEach(writable.write.bind(writable)); - writable.end(); - }); -} - -/** - */ - -Response.extend(BufferedResponse); - -/** - */ - -module.exports = BufferedResponse; diff --git a/old/cases/README.md b/old/cases/README.md deleted file mode 100644 index 9e72c95..0000000 --- a/old/cases/README.md +++ /dev/null @@ -1,22 +0,0 @@ -various test cases you should run if you plan on creating a mesh adapter. - -# Database test cases - -Docs can be [viewed here](http://mesh.mojojs.com/docs/database-adapters). - -Test case usage: - -```javascript -var createDBCases = require("mesh/test-cases/database"); -var memory = require("mesh-memory"); - -describe("in-memory-adapter#", function() { - - // createCases(createBus) - var cases = createDBCases(function(options) { - return memory(options); - }); - - for (var name in cases) it(name, cases[name]); -}); -``` diff --git a/old/cases/database/index-test.js b/old/cases/database/index-test.js deleted file mode 100644 index 3f27223..0000000 --- a/old/cases/database/index-test.js +++ /dev/null @@ -1,12 +0,0 @@ -var expect = require("expect.js"); -var createCases = require("./index"); -var memory = require("mesh-memory"); - -describe(__filename + "#", function() { - - var cases = createCases(function(options) { - return memory(options); - }); - - for (var name in cases) it(name, cases[name]); -}); diff --git a/old/cases/database/index.js b/old/cases/database/index.js deleted file mode 100644 index b8895b8..0000000 --- a/old/cases/database/index.js +++ /dev/null @@ -1,184 +0,0 @@ -var mesh = require("../../.."); -var expect = require("expect.js"); -var _ = require("highland"); - -module.exports = function(createDb) { - - var cases = {}; - var db; - - function it(description, run) { - cases[description] = function(next) { - if (!next) next = function() { }; - db = mesh.limit(1, createDb()); - run(next); - }; - return cases[description]; - } - - function xit() { - - } - - var insertOneItem = it("can insert one item", function(next) { - db({ name: "insert", collection: "items", data: { name: "a" }}).on("data", function(data) { - expect(data.name).to.be("a"); - next(); - }); - }); - - var insertMultipleItems = it("can insert multiple items", function(next) { - db(mesh.op("insert", { - collection: "items", - data: [ - { name: "a", count: 1 }, - { name: "b", count: 1 }, - { name: "c", count: 2 } - ] - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(3); - next(); - }); - }); - - it("can load one item", function(next) { - insertOneItem(); - db(mesh.op("load", { - collection: "items", - query: { name: "a" } - })).on("data", function(data) { - expect(data.name).to.be("a"); - next(); - }); - }); - - it("can load multiple items", function(next) { - insertMultipleItems(); - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 1 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can load all items", function(next) { - insertMultipleItems(); - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(3); - next(); - }); - }); - - xit("can load no items", function() { - - }); - - xit("emits an error if collection is missing", function(next) { - // var db = mesh.clean(lokidb()); - db("insert", { data: { name: "abba" }}).on("error", function() { - next(); - }); - }); - - xit("ignores operations that are not supported", function(next) { - db(mesh.op("afdfsfsd", { collection: "people", data: { name: "a"}})).on("end", function() { - next(); - }); - }); - - it("can update one item", function(next) { - insertMultipleItems(); - - db(mesh.op("update", { - collection: "items", - query: { count: 1 }, - data: { count: 3 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 3 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(1); - next(); - }); - }); - - it("can update multiple items", function(next) { - insertMultipleItems(); - - db(mesh.op("update", { - collection: "items", - query: { count: 1 }, - multi: true, - data: { count: 3 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 3 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can remove one item", function(next) { - insertMultipleItems(); - - db(mesh.op("remove", { - collection: "items", - query: { count: 1 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can remove multiple items", function(next) { - insertMultipleItems(); - - db(mesh.op("remove", { - collection: "items", - multi: true, - query: { count: 1 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(1); - next(); - }); - }); - - return cases; -}; diff --git a/old/examples/api/README.md b/old/examples/api/README.md deleted file mode 100644 index e890dda..0000000 --- a/old/examples/api/README.md +++ /dev/null @@ -1,28 +0,0 @@ -A more elaborate example demonstrating how you can use mesh to build a system that's decoupled from data -sources. It also happens to be isomorphic, and is setup to support realtime data in the future. - -#### Usage - -First run the server: - -``` -node server -``` - -Then run the client: - -``` -node client -``` - -#### Features - -- Client-side caching for server requests. -- Models & bus logic can run on any platform. -- Client-side operations are normalized to a semi-funky API (see [routes file here](./bus/api/routes/index.js)). -- Demonstrates how to `tail` operations. - -#### TODO - -- [ ] realtime data -- [ ] demo swapping out memory db with mongodb diff --git a/old/examples/api/bus/api/index-test.js b/old/examples/api/bus/api/index-test.js deleted file mode 100644 index c4a0e3b..0000000 --- a/old/examples/api/bus/api/index-test.js +++ /dev/null @@ -1,132 +0,0 @@ -var api = require("./index"); -var expect = require("expect.js"); -var mesh = require("../../../.."); - -describe(__filename + "#", function() { - - var bus; - var requestOptions; - - beforeEach(function() { - bus = api({ - request: function(options, next) { - requestOptions = options; - next(); - } - }); - }); - - describe("threads#", function() { - - it("ca load all threads", function(next) { - bus({ name: "load", collection: "threads", multi: true }).on("end", function() { - expect(requestOptions.uri).to.be("/getThreads"); - next(); - }); - }); - - it("ca add a new thread", function(next) { - bus({ name: "insert", collection: "threads", data: { userId: "user1", title: "thread1" } }).on("end", function() { - expect(requestOptions.uri).to.be("/addThread"); - expect(requestOptions.method).to.be("POST"); - expect(requestOptions.data.title).to.be("thread1"); - next(); - }); - }); - }); - - describe("messages#", function() { - - it("ca load all messages in a thread", function(next) { - bus({ name: "load", collection: "messages", multi: true, query: { threadId: "thread1" }}).on("end", function() { - expect(requestOptions.uri).to.be("/getMessages"); - expect(requestOptions.query.threadId).to.be("thread1"); - next(); - }); - }); - - it("ca add a new thread", function(next) { - bus({ name: "insert", collection: "messages", data: { threadId: "thread1", text: "texttt" } }).on("end", function() { - expect(requestOptions.uri).to.be("/addMessage"); - expect(requestOptions.method).to.be("POST"); - expect(requestOptions.data.threadId).to.be("thread1"); - expect(requestOptions.data.text).to.be("texttt"); - next(); - }); - }); - }); - - describe("caching#", function() { - - var cachedBus; - var cachedRequestOps; - - beforeEach(function() { - - cachedRequestOps = []; - - cachedBus = api({ - request: function(options, next) { - cachedRequestOps.push(options); - next(); - } - }); - - cachedBus = mesh.limit(1, cachedBus); - }); - - it("caches all GET requests", function(next) { - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/baab" }); - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/baab" }); - cachedBus({ method: "GET", path: "/abba" }).on("end", function() { - expect(cachedRequestOps.length).to.be(2); - next(); - }); - }); - - it("busts cached requests when POST is executed", function(next) { - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "POST", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }).on("end", function() { - expect(cachedRequestOps.length).to.be(2); - next(); - }); - }); - - it("busts cached requests when DELETE is executed", function(next) { - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "DELETE", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }).on("end", function() { - expect(cachedRequestOps.length).to.be(2); - next(); - }); - }); - - it("busts cached requests when UPDATE is executed", function(next) { - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "UPDATE", path: "/abba" }); - cachedBus({ method: "GET", path: "/abba" }).on("end", function() { - expect(cachedRequestOps.length).to.be(2); - next(); - }); - }); - - it("only busts cache for a given path", function(next) { - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "GET", path: "/baab" }); - cachedBus({ method: "GET", path: "/baab" }); - cachedBus({ method: "GET", path: "/abba" }); - cachedBus({ method: "UPDATE", path: "/abba" }); - cachedBus({ method: "GET", path: "/baab" }); - cachedBus({ method: "GET", path: "/abba" }).on("end", function() { - expect(cachedRequestOps.length).to.be(3); - next(); - }); - }); - }); -}); diff --git a/old/examples/api/bus/api/index.js b/old/examples/api/bus/api/index.js deleted file mode 100644 index f45ce31..0000000 --- a/old/examples/api/bus/api/index.js +++ /dev/null @@ -1,61 +0,0 @@ -var http = require("mesh-http"); -var cache = require("../../../../extra/cache"); -var routes = require("./routes"); -var sift = require("sift"); -var mesh = require("../../../.."); -var memory = require("mesh-memory"); - -/** - */ - -module.exports = function(options) { - - var bus = http(options); - - // cache HTTP requests - bus = _cache(bus); - - // map operations to HTTP requests - bus = _routes(routes, bus); - - return bus; -}; - -/** - */ - -function _cache(bus) { - return cache(bus, { - storage: memory(), - bust: function(operation) { - return /UPDATE|POST|REMOVE/.test(operation.name) ? { - path: operation.path - } : void 0; - }, - test: function(operation) { - return operation.name === "GET"; - } - }); -} - -/** - */ - -function _routes(routes, bus) { - - var handlers = []; - - for (var i = 0, n = routes.length; i < n; i += 2) { - handlers.push({ - test : sift(routes[i]), - bus : mesh.attach(routes[i + 1], bus) - }); - } - - return function(operation) { - for (var i = 0, n = handlers.length; i < n; i++) { - if (handlers[i].test(operation)) return handlers[i].bus(operation); - } - return bus(operation); - }; -} diff --git a/old/examples/api/bus/api/routes/index.js b/old/examples/api/bus/api/routes/index.js deleted file mode 100644 index 190a5fe..0000000 --- a/old/examples/api/bus/api/routes/index.js +++ /dev/null @@ -1,48 +0,0 @@ -module.exports = [ - - /** - * threads - */ - - { name: "load", collection: "threads", multi: true }, function(operation) { - return { - path: "/getThreads", - method: "GET" - }; - }, - - { name: "insert", collection: "threads" }, function(operation) { - return { - path: "/addThread", - data: { - title: operation.data.title - }, - method: "POST" - }; - }, - - /** - */ - - { name: "load", collection: "messages", multi: true }, function(operation) { - return { - path: "/getMessages", - query: { - threadId: operation.query.threadId - }, - method: "GET" - }; - }, - - { name: "insert", collection: "messages" }, function(operation) { - return { - path: "/addMessage", - data: { - threadId: operation.data.threadId, - text: operation.data.text - }, - method: "POST" - }; - } - -]; diff --git a/old/examples/api/bus/index.js b/old/examples/api/bus/index.js deleted file mode 100644 index 62735e8..0000000 --- a/old/examples/api/bus/index.js +++ /dev/null @@ -1,20 +0,0 @@ -var api = require("./api"); -var join = require("../../../extra/join"); -var spy = require("./spy"); - -module.exports = function(options, bus) { - - // main bus - if (!bus) { - bus = api(options); - } - - // abiilty to spy on opeations & streams - bus = spy(bus, function(spy, operation) { - return spy.collection === operation.collection; - }); - - bus = join(bus); - - return bus; -}; diff --git a/old/examples/api/bus/spy/index-test.js b/old/examples/api/bus/spy/index-test.js deleted file mode 100644 index d227265..0000000 --- a/old/examples/api/bus/spy/index-test.js +++ /dev/null @@ -1,49 +0,0 @@ -var spy = require("./index"); -var mesh = require("../../../.."); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - it("can spy on all streams", function(next) { - - var bus = mesh.noop; - bus = spy(bus); - bus = mesh.reject("spy", mesh.limit(1, bus), bus); - - var ops = []; - - bus({ name: "spy" }).on("data", function(operation) { - ops.push(operation); - }); - - bus({ name: "insert" }); - bus({ name: "remove" }); - bus({ name: "insert" }).on("end", function() { - expect(ops.length).to.be(3); - expect(ops[0].stream).not.to.be(void 0); - next(); - }); - }); - - it("can spy on a stream based on the query", function(next) { - - var bus = mesh.noop; - bus = spy(bus, function(spy, operation) { - return spy.query.name === operation.name; - }); - bus = mesh.reject("spy", mesh.limit(1, bus), bus); - - var ops = []; - - bus({ name: "spy", query: { name: "insert"} }).on("data", function(operation) { - ops.push(operation); - }); - - bus({ name: "insert" }); - bus({ name: "remove" }); - bus({ name: "insert" }).on("end", function() { - expect(ops.length).to.be(2); - expect(ops[0].stream).not.to.be(void 0); - next(); - }); - }); -}); diff --git a/old/examples/api/bus/spy/index.js b/old/examples/api/bus/spy/index.js deleted file mode 100644 index 22d3727..0000000 --- a/old/examples/api/bus/spy/index.js +++ /dev/null @@ -1,36 +0,0 @@ -var mesh = require("../../../.."); -var stream = require("obj-stream"); -var sift = require("sift"); - -module.exports = function(bus, tester) { - - if (!tester) tester = function(spy, op) { - return true; - }; - - var spies = []; - - return function(operation) { - - var s; - - if (operation.name === "spy") { - s = operation.stream = new stream.Stream(); - spies.push(operation); - s.once("end", function() { - spies.splice(spies.indexOf(operation), 1); - }); - } else { - - s = operation.stream = bus(operation); - - spies.forEach(function(spy) { - if (tester(spy, operation)) { - spy.stream.write(operation); - } - }); - } - - return s; - }; -}; diff --git a/old/examples/api/client.js b/old/examples/api/client.js deleted file mode 100644 index 9ce27cb..0000000 --- a/old/examples/api/client.js +++ /dev/null @@ -1,32 +0,0 @@ -var createBus = require("./bus"); -var models = require("./models"); -var mesh = require("../.."); - -var bus = createBus({ - prefix: "http://127.0.0.1:8080" -}); - -// "spy" is a command executed by collections. Basically a fancier "tail" method -bus = mesh.reject("spy", mesh.limit(1, bus), bus); - -// create a new thread -var thread = new models.Thread({ - bus: mesh.attach({ collection: "threads" }, bus) -}); - -// this should run POST /addThread -thread.save(function() { - - // we can add messages here in a synchronous fashion since we - // set the limit above to 1 - thread.addMessage("hello world"); - thread.addMessage("mmmm donuts"); - thread.addMessage("how much wood would a wood chuck chuck?"); - thread.addMessage("there are 160,934.4 cm in a mile"); - - // this will get executed after all messages are persisted and - // stored in the server db - thread.getMessages(function(err, messages) { - console.log(messages.toJSON()); - }); -}); diff --git a/old/examples/api/index.js b/old/examples/api/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/old/examples/api/models/base/collection-test.js b/old/examples/api/models/base/collection-test.js deleted file mode 100644 index 619bdf0..0000000 --- a/old/examples/api/models/base/collection-test.js +++ /dev/null @@ -1,68 +0,0 @@ -var Collection = require("./collection"); -var mesh = require("../../../.."); -var expect = require("expect.js"); -var extend = require("xtend/mutable"); -var createBus = require("../../bus"); -var memory = require("mesh-memory"); - -describe(__filename + "#", function() { - - var fakeBus; - var ops; - - beforeEach(function() { - ops = []; - fakeBus = mesh.wrap(function(operation, next) { - ops.push(operation); - next.apply(this, operation.yields || []); - }); - }); - - it("can be created", function() { - new Collection(); - }); - - it("can load data into the collection", function(next) { - var c = new Collection({ - bus: mesh.attach({ yields: [ - void 0, - [{name:"a"}, {name:"b"}, {name:"c"}] - ]}, fakeBus) - }); - - c.load(function() { - expect(c.length).to.be(3); - expect(c.at(0).name).to.be("a"); - next(); - }); - }); - - it("properly diffs the collection when data changes", function() { - var c = new Collection({ - data: [{ id: 1, name: "a" }, { id: 2, name: "b" }] - }); - - var m = c.at(0); - expect(m.name).to.be("a"); - - c._onData([{ id: 1, name: "c" }]); - expect(c.length).to.be(1); - expect(c.at(0)).to.be(m); - expect(m.name).to.be("c"); - }); - - it("properly spies & inserts a new item", function(next) { - - var b = createBus({}, memory()); - - var c = new Collection({ - bus: mesh.attach({ collection: "items" }, b) - }); - - c.createModel({name:"blarg"}).insert(function() { - expect(c.length).to.be(1); - expect(c.at(0).name).to.be("blarg"); - next(); - }); - }); -}); diff --git a/old/examples/api/models/base/collection.js b/old/examples/api/models/base/collection.js deleted file mode 100644 index ddc9378..0000000 --- a/old/examples/api/models/base/collection.js +++ /dev/null @@ -1,163 +0,0 @@ -var extend = require("xtend/mutable"); -var _ = require("highland"); -var Watchable = require("./watchable"); -var watchProperty = require("./watch-property"); - -/** - */ - -function Collection(properties) { - this.source = []; - Watchable.call(this, properties); - if (this.data) this._onData(this.data); - watchProperty(this, "data", this._onData.bind(this)); - this._spyOnBus(); -} - -/** - */ - -extend(Collection.prototype, Watchable.prototype, { - - /** - */ - - length: 0, - - /** - */ - - modelClass: require("./model"), - - /** - */ - - createModel: function(properties) { - return new this.modelClass(extend({ bus: this.bus }, properties || {})); - }, - - /** - */ - - find: function(model) { - for (var i = this.length; i--;) { - if (this.at(i).equals(model)) return this.at(i); - } - }, - - /** - */ - - at: function(index) { - return this.source[index]; - }, - - /** - */ - - indexOf: function(item) { - return this.source.indexOf(item); - }, - - /** - */ - - load: function(onLoad) { - this - .bus({ name: "load", multi: true }) - .pipe(_.pipeline(_.collect)) - .on("data", this._onData.bind(this)) - .once("error", onLoad) - .once("end", onLoad.bind(this, void 0, this)); - }, - - /** - */ - - toJSON: function() { - return this.source.map(function(model) { - return model.toJSON(); - }); - }, - - /** - */ - - _onData: function(data) { - this._diff(data.map(this.createModel.bind(this))); - }, - - /** - */ - - _diff: function(nsource) { - - var msource = nsource.concat(); - var csource = this.source || []; - - for (var i = nsource.length; i--;) { - var amodel = nsource[i]; - - var emodel = this.find(amodel); - if (emodel) { - emodel.setProperties({ data: amodel.toJSON() }); - msource.splice(i, 1, emodel); // use existing model - resort - break; - } - } - - this.source = msource; - - this._changed(); - }, - - /** - * Spies on the bus for operations specific to this collection. We could further - * customize this spying function to specific features such as pagination. - */ - - _spyOnBus: function() { - if (!this.bus) return; - this._spy = this.bus({ name: "spy" }).on("data", this._onSpiedOperation.bind(this)); - // TODO - this.on("dispose", this._spy.dispose.bind(this._spy)) - }, - - /** - */ - - _onSpiedOperation: function(operation) { - if (operation.name === "insert") this._onSpiedInsert(operation); - - // TODO - // if (operation.name === "update") this._onSpiedUpdate(operation); - // if (operation.name === "remove") this._onSpiedRemove(operation); - }, - - /** - */ - - _onSpiedInsert: function(operation) { - operation.stream.on("data", function(data) { - this.push(this.createModel({ data: data })); - }.bind(this)); - }, - - /** - */ - - _changed: function() { - this.length = this.source.length; - this.emit("change"); - } -}); - -["concat", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "splice", "unshift"].forEach(function(methodName) { - var fn = Array.prototype[methodName]; - Collection.prototype[methodName] = function() { - var ret = fn.apply(this.source, arguments); - this._changed(); - return ret; - }; -}); - -module.exports = Collection; diff --git a/old/examples/api/models/base/model-test.js b/old/examples/api/models/base/model-test.js deleted file mode 100644 index 10da449..0000000 --- a/old/examples/api/models/base/model-test.js +++ /dev/null @@ -1,90 +0,0 @@ -var BaseModel = require("./model"); -var mesh = require("../../../.."); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - - var fakeBus; - var ops; - - beforeEach(function() { - ops = []; - fakeBus = mesh.wrap(function(operation, next) { - ops.push(operation); - next.apply(this, operation.yields || []); - }); - }); - - it("can be created", function() { - new BaseModel(); - }); - - it("can load data into the model from a bus", function(next) { - var m = new BaseModel({ - bus: mesh.attach({ yields: [void 0, { name: "a", last: "b" }]}, fakeBus) - }); - - m.load(function() { - expect(m.name).to.be("a"); - expect(m.last).to.be("b"); - next(); - }); - }); - - it("inserts the model if ID is not present", function(next) { - var m = new BaseModel({ - bus: fakeBus, - name: "a" - }); - - m.save(function() { - expect(ops[0].name).to.be("insert"); - expect(ops[0].data.name).to.be("a"); - next(); - }); - }); - - it("updates the model if ID is present", function(next) { - var m = new BaseModel({ - bus: fakeBus, - id: "m1", - name: "a" - }); - - m.save(function() { - expect(ops[0].name).to.be("update"); - expect(ops[0].data.name).to.be("a"); - expect(ops[0].data.id).to.be("m1"); - expect(ops[0].query.id).to.be("m1"); - next(); - }); - }); - - it("can remove a model", function(next) { - var m = new BaseModel({ - bus: fakeBus, - id: "m1" - }); - - m.remove(function() { - expect(ops[0].name).to.be("remove"); - expect(ops[0].query.id).to.be("m1"); - next(); - }); - }); - - it("emits a change event when loading data", function(next) { - var m = new BaseModel({ - bus: mesh.attach({ yields: [void 0, { name: "a", last: "b" }]}, fakeBus), - id: "m1" - }); - var i = 0; - m.once("change", function() { - i++; - }); - m.load(function() { - expect(i).not.to.be(0); - next(); - }); - }); -}); diff --git a/old/examples/api/models/base/model.js b/old/examples/api/models/base/model.js deleted file mode 100644 index 5f6b109..0000000 --- a/old/examples/api/models/base/model.js +++ /dev/null @@ -1,108 +0,0 @@ -var extend = require("xtend/mutable"); -var Watchable = require("./watchable"); -var watchProperty = require("./watch-property"); - -/** - */ - -function BaseModel(properties) { - Watchable.call(this, properties); - if (this.data) this._onData(this.data); - watchProperty(this, "data", this._onData.bind(this)); -} - -/** - */ - -extend(BaseModel.prototype, Watchable.prototype, { - - /** - */ - - load: function(onLoad) { - return this._run({ name: "load", query: { id: this.id } }, onLoad); - }, - - /** - */ - - save: function(onSave) { - return this.id ? this.update(onSave) : this.insert(onSave); - }, - - /** - */ - - insert: function(onInsert) { - return this._run({ name: "insert", data: this.toJSON() }, onInsert); - }, - - /** - */ - - remove: function(onInsert) { - return this._run({ name: "remove", query: { id: this.id } }, onInsert); - }, - - /** - */ - - update: function(onInsert) { - return this._run({ name: "update", data: this.toJSON(), query: { id: this.id } }, onInsert); - }, - - /** - */ - - toJSON: function() { - var props = {}; - for (var key in this) { - if (key.charAt(0) === "_") continue; - var v = this[key]; - if (/string|boolean|number/.test(typeof v)) { - props[key] = v; - } - } - return props; - }, - - /** - */ - - _run: function(operation, next) { - if (!next) next = function() { }; - this - .bus(operation) - .on("data", this._onData.bind(this)) - .once("error", next) - .once("end", next.bind(this, void 0, this)); - return this; - }, - - /** - */ - - _onData: function(data) { - this.setProperties(this.fromData(this.data = data)); - }, - - /** - * deserialize - */ - - fromData: function(data) { - return data; - }, - - /** - */ - - equals: function(model) { - return this.id === model.id; - } -}); - -/** - */ - -module.exports = BaseModel; diff --git a/old/examples/api/models/base/watch-property.js b/old/examples/api/models/base/watch-property.js deleted file mode 100644 index 6859727..0000000 --- a/old/examples/api/models/base/watch-property.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = function(target, property, listener) { - var currentValue = target[property]; - target.on("change", function() { - if (target[property] !== currentValue) { - return listener(currentValue = target[property]); - } - }); -}; diff --git a/old/examples/api/models/base/watchable.js b/old/examples/api/models/base/watchable.js deleted file mode 100644 index a91a072..0000000 --- a/old/examples/api/models/base/watchable.js +++ /dev/null @@ -1,39 +0,0 @@ -var extend = require("xtend/mutable"); -var EventEmitter = require("events").EventEmitter; - -/** - */ - -function WatchableObject(properties) { - extend(this, properties || {}); - EventEmitter.call(this); -} - -/** - */ - -extend(WatchableObject.prototype, EventEmitter.prototype, { - - /** - */ - - setProperties: function(properties) { - extend(this, properties || {}); - this.emit("change"); - }, - - /** - */ - - watch: function(listener) { - this.on("change", listener); - return { - dispose: this.removeListener.bind(this, "change", listener) - }; - } -}); - -/** - */ - -module.exports = WatchableObject; diff --git a/old/examples/api/models/index.js b/old/examples/api/models/index.js deleted file mode 100644 index 79c5e6e..0000000 --- a/old/examples/api/models/index.js +++ /dev/null @@ -1,7 +0,0 @@ - -module.exports = { - Thread : require("./thread"), - Threads : require("./threads"), - Message : require("./message"), - Messages : require("./messages") -}; diff --git a/old/examples/api/models/message.js b/old/examples/api/models/message.js deleted file mode 100644 index 9a8c350..0000000 --- a/old/examples/api/models/message.js +++ /dev/null @@ -1,18 +0,0 @@ -var Model = require("./base/model"); -var extend = require("xtend/mutable"); - -/** - */ - -function Message(properties) { - Model.call(this, properties); -} - -/** - */ - -extend(Message.prototype, Model.prototype, { - -}); - -module.exports = Message; diff --git a/old/examples/api/models/messages.js b/old/examples/api/models/messages.js deleted file mode 100644 index 346c8ed..0000000 --- a/old/examples/api/models/messages.js +++ /dev/null @@ -1,27 +0,0 @@ -var Collection = require("./base/collection"); -var Message = require("./message"); -var mesh = require("../../.."); -var extend = require("xtend/mutable"); - -/** - */ - -function Messages(properties) { - Collection.call(this, properties); -} - -/** - */ - -extend(Messages.prototype, Collection.prototype, { - - /** - */ - - modelClass: Message -}); - -/** - */ - -module.exports = Messages; diff --git a/old/examples/api/models/thread.js b/old/examples/api/models/thread.js deleted file mode 100644 index 41eaa5a..0000000 --- a/old/examples/api/models/thread.js +++ /dev/null @@ -1,38 +0,0 @@ -var Model = require("./base/model"); -var Messages = require("./messages"); -var Message = require("./message"); -var mesh = require("../../.."); -var extend = require("xtend/mutable"); - -/** - */ - -function Thread(properties) { - Model.call(this, properties); -} - -/** - */ - -extend(Thread.prototype, Model.prototype, { - - /** - */ - - addMessage: function(text, onInsert) { - return new Message({ - bus: mesh.attach({ collection: "messages", data: { threadId: this.id, text: text }}, this.bus) - }).insert(onInsert); - }, - - /** - */ - - getMessages: function(onLoad) { - return new Messages({ - bus: mesh.attach({ collection: "messages", query: { threadId: this.id } }, this.bus) - }).load(onLoad); - } -}); - -module.exports = Thread; diff --git a/old/examples/api/models/threads.js b/old/examples/api/models/threads.js deleted file mode 100644 index f27b70b..0000000 --- a/old/examples/api/models/threads.js +++ /dev/null @@ -1,34 +0,0 @@ -var Collection = require("./base/collection"); -var mesh = require("../../.."); -var Thread = require("./thread"); -var extend = require("xtend/mutable"); - -/** - */ - -function Threads(properties) { - Collection.call(this, properties); -} - -/** - */ - -extend(Threads.prototype, Collection.prototype, { - - /** - */ - - modelClass: Thread, - - /** - */ - - create: function(onCreate) { - return this.createModel().insert(onCreate); - } -}); - -/** - */ - -module.exports = Threads; diff --git a/old/examples/api/server.js b/old/examples/api/server.js deleted file mode 100644 index 455f698..0000000 --- a/old/examples/api/server.js +++ /dev/null @@ -1,102 +0,0 @@ -var express = require("express"); -var mesh = require("../.."); -var memory = require("mesh-memory"); -var _ = require("highland"); -var models = require("./models"); -var createBus = require("./bus"); -var JSONStream = require("JSONStream"); -var stream = require("obj-stream"); -var bodyParser = require("body-parser"); - -// this can be swapped out for mongodb assuming you -// create another transformation step that takes id properties -// and prepends an _ character. -var db = memory(); - -var _id = 0; - -// specific to the memory db since it doesn't support this kinda thing. -// Just add an ID whenever a new item is added to any collection -var bus = mesh.accept("insert", function(operation) { - operation.data.id = operation.collection + (++_id); - return db(operation); -}, db); - -// setup the bus that's used on ALL clients. Except use the db (second param) -// as the main data source where data is persisted to. -bus = createBus({}, bus); - -// create an alias for the collections we wanna save to -bus.threads = mesh.attach({ collection: "threads" }, bus); -bus.messages = mesh.attach({ collection: "messages" }, bus); - -var server = express(); -server.use(bodyParser.json()); - -// transforms objects into a stream of data that is compatible -// with JSONStream -function objToKeyStream() { - return stream.through(function(data, next) { - for (var key in data) this.push([key, data[key]]); - next(); - }); -} - -// Route stuff. All the models here just contain business logic. DB stuff is passed -// as bus property, so that means models / collections are isomorphic. They can run on any -// platform. -server.get("/getThreads", function(req, res) { - - var m = new models.Threads({ - bus : bus.threads - }); - - m.load(function() { - res.send(m.toJSON()); - }); -}); - -server.post("/addThread", function(req, res) { - - var m = new models.Thread({ - bus : bus.threads, - title : req.body.title - }); - - m.insert(function() { - res.send(m.toJSON()); - }); -}); - -// messages - -server.get("/getMessages", function(req, res) { - - var m = new models.Messages({ - bus : mesh.attach({ query: { threadId: req.query.threadId } }, bus.messages) - }); - - m.load(function() { - console.log(m); - res.send(m.toJSON()); - }); -}); - -server.post("/addMessage", function(req, res) { - - var m = new models.Message({ - bus : bus.messages, - threadId : req.body.threadId, - text : req.body.text - }); - - m.insert(function() { - res.send(m.toJSON()); - }); -}); - -var port = process.env.PORT || 8080; - -console.log("listening on port %d", port); - -server.listen(port); diff --git a/old/examples/database-adapter/README.md b/old/examples/database-adapter/README.md deleted file mode 100644 index 616e776..0000000 --- a/old/examples/database-adapter/README.md +++ /dev/null @@ -1,2 +0,0 @@ - -Basic in-memory database adapter. Checkout the docs [here](http://mesh.mojojs.com/docs/database-adapters) to create your own. diff --git a/old/examples/database-adapter/database-test.js b/old/examples/database-adapter/database-test.js deleted file mode 100644 index b7f99a8..0000000 --- a/old/examples/database-adapter/database-test.js +++ /dev/null @@ -1,8 +0,0 @@ -var expect = require("expect.js"); -var createCases = require("../../test/cases/database"); -var createDb = require("./database"); - -describe(__filename + "#", function() { - var cases = createCases(createDb); - for (var name in cases) it(name, cases[name]); -}); diff --git a/old/examples/database-adapter/database.js b/old/examples/database-adapter/database.js deleted file mode 100644 index b0df754..0000000 --- a/old/examples/database-adapter/database.js +++ /dev/null @@ -1,66 +0,0 @@ -var mesh = require("../.."); - -module.exports = function(options) { - - var db = {}; - - function _find(operation) { - var query = operation.query || {}; - var found = _collection(operation).filter(function(data) { - for (var key in query) { - if (data[key] !== query[key]) return false; - } - return true; - }); - return operation.multi ? found : _toArray(found.shift()); - } - - function _collection(operation) { - return db[operation.collection] || (db[operation.collection] = []); - } - - function _toArray(value) { - if (value == void 0) return []; - return Object.prototype.toString.call(value) === "[object Array]" ? value : [value]; - } - - function _return(data, stream) { - _toArray(data).forEach(function(data) { - stream.write(data); - }); - stream.end(); - } - - var handlers = { - insert: function(operation, stream) { - var c = _collection(operation); - c.push.apply(c, _toArray(operation.data)); - _return(operation.data, stream); - }, - update: function(operation, stream) { - var results = _find(operation); - results.forEach(function(data) { - for (var key in operation.data) { - data[key] = operation.data[key]; - } - }); - stream.end(); - }, - remove: function(operation, stream) { - var c = _collection(operation); - _find(operation).forEach(function(data) { - c.splice(c.indexOf(data), 1); - }); - stream.end(); - }, - load: function(operation, stream) { - _return(_find(operation), stream); - } - }; - - return mesh.stream(function(operation, stream) { - var handler = handlers[operation.name]; - if (!handler) return stream.end(); - handler(operation, stream); - }); -}; diff --git a/old/examples/distributed-network/README.md b/old/examples/distributed-network/README.md deleted file mode 100644 index 1e50fff..0000000 --- a/old/examples/distributed-network/README.md +++ /dev/null @@ -1,60 +0,0 @@ -Sample server demonstrating how you can use mesh to create a distributed, fault tolerant network. This -example supports `round robin`, `least connection`, and `random` load balancing algorithms. - -This command line utility supports inline javascript. See below for details. - -### Usage - -First spin up some workers: - -``` -cd examples/network; node . -for (var i = 10; i--;) exec({ name: "startWorker" }); -``` - -next, run the command: - -``` -exec({ name: "ping" }); -``` - -This will execute a `ping` operation against all running workers. - -## Supported operations - -Below are a list of sample operations you can execute in the command line utility - -#### { name: "startWorker" [, count: number ] } - -starts a new worker - -```javascript -exec({ name: "startWorker" }); // start 1 worker -exec({ name: "startWorker", count: 10 }); // start 10 workers -``` - -#### { name: "ping", dist: dist } - -pings workers using the `dist` method. `dist` can be `rotate`, `least`, `random`, `sequence`, -or `parallel`. - -```javascript -exec({ name: "ping" }); // start 1 worker -exec({ name: "ping", dist: "sequence" }); // ping all workers one after the other -exec({ name: "ping", dist: "random" }); // ping one random worker -exec({ name: "ping", dist: "rotate" }); // ping one worker, round-robin style -exec({ name: "ping", dist: "least" }); // ping the worker with the fewest running operations -``` - -#### { name: "trace", count: countdown, dist: dist } - -runs `trace` operation against workers using the `dist` distribution type until `count` is 0. This -is a recursive operation. - -```javascript -exec({ name: "ping", dist: "random", count 10 }); // ping one random worker until count is 0 -``` - -#### { name: "error", message: message, dist: dist } - -Demonstrates how the `master` server continues to re-execute an operation after it's failed diff --git a/old/examples/distributed-network/bus/common/socket-bus/index.js b/old/examples/distributed-network/bus/common/socket-bus/index.js deleted file mode 100644 index 5605d82..0000000 --- a/old/examples/distributed-network/bus/common/socket-bus/index.js +++ /dev/null @@ -1,17 +0,0 @@ -var ros = require("ros"); - -/** - */ - -module.exports = function(client, bus) { - return ros(function(onMessage) { - client.on("data", function(data) { - String(data).split("|||||").forEach(function(chunk) { - if (chunk === "") return; - onMessage(JSON.parse(chunk)); - }); - }); - }, function send(payload) { - client.write(JSON.stringify(payload) + "|||||"); - }, bus); -}; diff --git a/old/examples/distributed-network/bus/master/index.js b/old/examples/distributed-network/bus/master/index.js deleted file mode 100644 index d610113..0000000 --- a/old/examples/distributed-network/bus/master/index.js +++ /dev/null @@ -1,89 +0,0 @@ -var mesh = require("../../../.."); -var commands = require("../../../../extra/commands"); -var fs = require("fs"); -var path = require("path"); -var balance = require("mesh-balance"); -var net = require("net"); -var ros = require("ros"); -var socketBus = require("../common/socket-bus"); -var startWorker = require("./start-worker"); -var stopWorker = require("./stop-worker"); - -/** - */ - -module.exports = function(config) { - - if (!config) { - config = {}; - } - - if (!config.workers) config.workers = []; - - if (!config.log) { - config.log = console.log.bind(console); - } - - // capture all operations and distrubite them - var bus = _distribute(config, bus); - - // commands - bus = _commands(config, bus); - - // setup the server - take any commands and execute - _server(config, bus); - - return bus; -}; - -/** - * commands for the - */ - -function _commands(config, bus) { - return commands({ - startWorker: startWorker(config), - stopWorker : stopWorker(config) - }, bus); -} - -/** - */ - -function _distribute(config, bus) { - - var dists = { - parallel : mesh.parallel(config.workers), - sequence : mesh.sequence(config.workers), - rotate : mesh.retry(config.retryCount, balance.rotate(config.workers)), - random : mesh.retry(config.retryCount, balance.random(config.workers)), - least : mesh.retry(config.retryCount, balance.least(config.workers)) - }; - - return function(operation) { - var distBus = dists[operation.dist] || dists.sequence; - return distBus(operation); - }; -} - -/** - */ - -function _server(config, bus) { - - var server = net.createServer(function(connection) { - - var workerBus = socketBus(connection, bus); - config.workers.push(workerBus); - - connection.once("close", function() { - config.workers.splice(config.workers.indexOf(workerBus), 1); - }); - }); - - config.log("master server listener on port %d", config.port); - - server.listen(config.port); - - return bus; -} diff --git a/old/examples/distributed-network/bus/master/start-worker.js b/old/examples/distributed-network/bus/master/start-worker.js deleted file mode 100644 index abcbcb8..0000000 --- a/old/examples/distributed-network/bus/master/start-worker.js +++ /dev/null @@ -1,33 +0,0 @@ -var childProcess = require("child_process"); -var spawn = childProcess.spawn; -var extend = require("xtend/mutable"); -var EventEmitter = require("events").EventEmitter; -var commands = require("snippets/commands"); -var mesh = require("../../../.."); -var ros = require("ros"); - -var _idCount = 0; - -/** - */ - -module.exports = function(config) { - return function(operation, next) { - - var count = Number(operation.count || 1); - config.log("spawning %d workers...", count); - - for (var i = count; i--;) { - spawn("/usr/local/bin/node", [config.workerPath], { - stdio: "inherit", - cwd: process.cwd, - env: { - MASTER_PORT : config.port, - ID : (++_idCount) - } - }); - } - - next(); - }; -}; diff --git a/old/examples/distributed-network/bus/master/stop-worker.js b/old/examples/distributed-network/bus/master/stop-worker.js deleted file mode 100644 index 5e2f125..0000000 --- a/old/examples/distributed-network/bus/master/stop-worker.js +++ /dev/null @@ -1,19 +0,0 @@ -var childProcess = require("child_process"); -var spawn = childProcess.spawn; -var extend = require("xtend/mutable"); -var EventEmitter = require("events").EventEmitter; -var commands = require("snippets/commands"); -var mesh = require("../../../.."); -var ros = require("ros"); - -var _idCount = 0; - -/** - */ - -module.exports = function(config) { - return function(operation, next) { - config.log("TODO"); // find index of worker - next(); - }; -}; diff --git a/old/examples/distributed-network/bus/worker/index.js b/old/examples/distributed-network/bus/worker/index.js deleted file mode 100644 index e03a55d..0000000 --- a/old/examples/distributed-network/bus/worker/index.js +++ /dev/null @@ -1,29 +0,0 @@ -var ros = require("ros"); -var commands = require("../../../../extra/commands"); -var net = require("net"); -var mesh = require("../../../.."); -var socketBus = require("../common/socket-bus"); - -/** - */ - -module.exports = function(config) { - - var bus = mesh.noop; - bus = commands(config.commands, bus); - bus = _client(config, bus); - - return bus; -}; - -/** - */ - -function _client(config, bus) { - - var client = new net.Socket(); - client.connect(config.masterPort, "127.0.0.1", function() { - }); - - return socketBus(client, bus); -} diff --git a/old/examples/distributed-network/index.js b/old/examples/distributed-network/index.js deleted file mode 100644 index 311b05f..0000000 --- a/old/examples/distributed-network/index.js +++ /dev/null @@ -1,61 +0,0 @@ -var readline = require("readline"); -var createServerBus = require("./bus/master"); -var path = require("path"); - -/** - */ - -var bus = createServerBus({ - - /** - */ - - workerPath : path.join(__dirname, "worker.js"), - - /** - */ - - port : process.env.PORT || 1337, - - /** - * number of times to retry executing an operation before returning an error - */ - - retryCount : 5 -}); - -/** - */ - -var rl = readline.createInterface({ - input : process.stdin, - output : process.stdout -}); - -/** - */ - -function exec(complete, command, dist) { - if (typeof command === "string") command = { name: command }; - if (dist) command.dist = dist; - bus(command).on("data", function(data) { - console.log(JSON.stringify(data, null, 2)); - }).once("error", complete).once("end", complete); -} - -/** - */ - -function captureOperation(error) { - if (error) console.error(error.message); - rl.question("", function(command) { - try { - new Function("exec", command)(exec.bind(void 0, captureOperation)); - } catch (e) { - console.error(e); - captureOperation(); - } - }); -} - -captureOperation(); diff --git a/old/examples/distributed-network/worker.js b/old/examples/distributed-network/worker.js deleted file mode 100644 index 87c8b88..0000000 --- a/old/examples/distributed-network/worker.js +++ /dev/null @@ -1,56 +0,0 @@ -var createWorkerBus = require("./bus/worker"); -var id = process.env.ID; - -console.log("starting worker %d", id); -var bus = createWorkerBus({ - - /** - */ - - masterPort: process.env.MASTER_PORT, - - /** - */ - - log: function() { - var args = Array.prototype.slice.call(arguments); - console.log.apply(console, ["worker %s:", id].concat(args)); - }, - - /** - */ - - commands: { - - /** - * simple ping-pong - */ - - ping: function(operation, next) { - next(void 0, "worker " + id + " pong"); - }, - - /** - * recursively runs trace until count is 0. Note that - * the trace operation gets sent back to the server. - */ - - trace: function(operation) { - console.log("worker %s trace %s %d", id, operation.dist, operation.count || 0); - if (operation.count) { - return bus({ name: "trace", dist: operation.dist, count: operation.count - 1 }); - } else { - return bus({ name: "ping", dist: operation.dist }); - } - }, - - /** - * sample error handler - */ - - error: function(operation, next) { - console.log("worker %s return error", id); - next(new Error(operation.message || "some error")); - } - } -}); diff --git a/old/examples/react/README.md b/old/examples/react/README.md deleted file mode 100644 index 1776596..0000000 --- a/old/examples/react/README.md +++ /dev/null @@ -1,7 +0,0 @@ -Simple todo list demonstration of how you can use `mesh` with ReactJS as an event bus. - -#### Features - -- Uses local storage. Easily swap data source out for something else such a s a REST adapter. -- Similar flux philosophy. Data is loaded only in the root component. -- Setup to support realtime data. diff --git a/old/examples/react/bus/index.js b/old/examples/react/bus/index.js deleted file mode 100644 index 744d743..0000000 --- a/old/examples/react/bus/index.js +++ /dev/null @@ -1,43 +0,0 @@ -var mesh = require("mesh"); -// var storage = require("mesh-memory"); -var storage = require("mesh-local-storage"); -var extend = require("extend"); - -module.exports = function() { - - var bus = storage(); - - bus = mesh.tailable(bus, function(tail, operation) { - return /insert|remove|update/.test(operation.name); - }); - - bus = attachInsertId(bus); - - bus = aliases({ - addItem : { name: "insert", collection: "items" }, - getItems : { name: "load", collection: "items", multi: true }, - removeItem : { name: "remove", collection: "items" } - }, bus); - - return bus; -}; - -function aliases(als, bus) { - return function(operation) { - var properties = als[operation.name] || {}; - return bus(extend({}, operation, properties)); - }; -} - -var _ref = 0; - -function attachInsertId(bus) { - return mesh.accept("insert", function(operation) { - operation.data.id = ++_ref; - return bus(operation); - }, bus); -} - -function alias(properties, bus) { - return mesh.attach(properties, bus); -} diff --git a/old/examples/react/components/_loadState.js b/old/examples/react/components/_loadState.js deleted file mode 100644 index bd8cacb..0000000 --- a/old/examples/react/components/_loadState.js +++ /dev/null @@ -1,22 +0,0 @@ -var async = require("async"); -var _ = require("highland"); - -module.exports = function(operations, bus, complete) { - var opsAsArray = []; - var results = {}; - Object.keys(operations).forEach(function(key) { - opsAsArray.push({ key: key, op: operations[key] }); - }); - - async.each(opsAsArray, function(info, next) { - bus(info.op) - .pipe(_.pipeline(_.collect)) - .on("data", function(result) { - if (!info.op.multi) result = result[0]; - results[info.key] = result; - }) - .once("end", next); - }, function() { - complete(void 0, results); - }); -}; diff --git a/old/examples/react/components/header.js b/old/examples/react/components/header.js deleted file mode 100644 index d792880..0000000 --- a/old/examples/react/components/header.js +++ /dev/null @@ -1,23 +0,0 @@ -var React = require("react"); - -var Item = React.createClass({ - addItem: function(event) { - event.preventDefault(); - var ref = React.findDOMNode(this.refs.textInput); - var text = ref.value; - ref.value = ""; - this.props.bus({ - name: "addItem", - data: { text: text } - }); - }, - render: function() { - return React.createElement("div", void 0, - React.createElement("form", { onSubmit: this.addItem }, - React.createElement("input", { ref: "textInput", name: "item", className: "form-control" }) - ) - ); - } -}); - -module.exports = Item; diff --git a/old/examples/react/components/item.js b/old/examples/react/components/item.js deleted file mode 100644 index f8d801e..0000000 --- a/old/examples/react/components/item.js +++ /dev/null @@ -1,16 +0,0 @@ -var React = require("react"); - -var Item = React.createClass({ - removeItem: function(event) { - event.preventDefault(); - this.props.bus({ name: "removeItem", query: { id: this.props.item.id } }); - }, - render: function() { - return React.createElement("li", void 0, - React.createElement("button", { onClick: this.removeItem }, "x"), - " " + this.props.item.text - ); - } -}); - -module.exports = Item; diff --git a/old/examples/react/components/items.js b/old/examples/react/components/items.js deleted file mode 100644 index c383bd1..0000000 --- a/old/examples/react/components/items.js +++ /dev/null @@ -1,15 +0,0 @@ -var React = require("react"); -var Item = require("./item"); -var extend = require("extend"); - -var Items = React.createClass({ - render: function() { - return React.createElement("ul", { className: "item" }, - this.props.items.map(function(item) { - return React.createElement(Item, extend({ item: item }, this.props)); - }.bind(this)) - ); - } -}); - -module.exports = Items; diff --git a/old/examples/react/components/main.js b/old/examples/react/components/main.js deleted file mode 100644 index 3ec9416..0000000 --- a/old/examples/react/components/main.js +++ /dev/null @@ -1,36 +0,0 @@ -var React = require("react"); -var Header = require("./header"); -var Items = require("./items"); -var loadState = require("./_loadState"); -var extend = require("extend"); - -var Main = React.createClass({ - componentDidMount: function() { - this._load(); - - // wait for operations to finish, then reload the root - this.props.bus({ name: "tail" }).on("data", this._load.bind(this)); - }, - getInitialState: function() { - return { - items: [] - }; - }, - _load: function() { - loadState({ - items: { name: "getItems", multi: true } - }, this.props.bus, function(err, state) { - this.setState(state); - }.bind(this)); - }, - render: function() { - return React.createElement("div", { className: "row" }, - React.createElement("div", { className: "col-sm-12" }, - React.createElement(Header, this.props), - React.createElement(Items, extend({}, this.state, this.props)) - ) - ); - } -}); - -module.exports = Main; diff --git a/old/examples/react/index.js b/old/examples/react/index.js deleted file mode 100644 index 7f689a9..0000000 --- a/old/examples/react/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var React = require("react"); -var Main = require("./components/main"); -var createBus = require("./bus"); - -var bus = createBus(); - -React.render(React.createElement(Main, { bus: bus }), preview.element); diff --git a/old/lib/_async.js b/old/lib/_async.js deleted file mode 100644 index 2a37094..0000000 --- a/old/lib/_async.js +++ /dev/null @@ -1,16 +0,0 @@ -var Stream = require("obj-stream").Stream; - -/** - */ - -module.exports = function(fn) { - var stream = new Stream(); - - process.nextTick(function() { - fn(stream); - }); - - stream.reader = stream; - - return stream; -}; diff --git a/old/lib/_eachParallel.js b/old/lib/_eachParallel.js deleted file mode 100644 index 76a90cb..0000000 --- a/old/lib/_eachParallel.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = function(items, each, complete) { - var i = 0; - var completed = false; - - function done() { - if (completed) return; - completed = true; - return complete.apply(this, arguments); - } - - items.forEach(function(item) { - each(item, function(err, item) { - if (err) return done(err); - if (++i >= items.length) return done(); - }); - }); - - if (!items.length) done(); -}; diff --git a/old/lib/_eachSeries.js b/old/lib/_eachSeries.js deleted file mode 100644 index 57475f6..0000000 --- a/old/lib/_eachSeries.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(items, each, complete) { - var i = 0; - - function run() { - if (i >= items.length) return complete(); - each(items[i++], function(err, item) { - if (err) return complete(err); - run(); - }); - } - - run(); -}; diff --git a/old/lib/_equals.js b/old/lib/_equals.js deleted file mode 100644 index 490d9e0..0000000 --- a/old/lib/_equals.js +++ /dev/null @@ -1,20 +0,0 @@ - -function _equals(a, b) { - - var toa = typeof a; - var tob = typeof b; - - if (toa !== tob) return false; - - if (toa === "object") { - for (var k in a) { - if (!_equals(a[k], b[k])) return false; - } - - return true; - } - - return a === b; -} - -module.exports = _equals; diff --git a/old/lib/_getFilter.js b/old/lib/_getFilter.js deleted file mode 100644 index 801962f..0000000 --- a/old/lib/_getFilter.js +++ /dev/null @@ -1,23 +0,0 @@ - -module.exports = function(match) { - - if (match instanceof RegExp) { - return function(operation) { - return match.test(operation.name); - }; - } else if (match.test) { - return function(operation) { - return match.test(operation); - }; - } else if (typeof match === "function") { - return match; - } else { - return function(operation) { - return operation.name === match; - }; - } - - return function() { - return false; - }; -}; diff --git a/old/lib/_group.js b/old/lib/_group.js deleted file mode 100644 index c71702f..0000000 --- a/old/lib/_group.js +++ /dev/null @@ -1,12 +0,0 @@ -var _isArray = require("./_isArray"); - -module.exports = function(targetBus) { - return function(/* ... */ busses) { - - busses = _isArray(busses) ? busses : Array.prototype.slice.call(arguments); - - return function(operation) { - return targetBus(operation, busses); - }; - }; -}; diff --git a/old/lib/_isArray.js b/old/lib/_isArray.js deleted file mode 100644 index 4a3e0ae..0000000 --- a/old/lib/_isArray.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function(data) { - return Object.prototype.toString.call(data) === "[object Array]"; -}; diff --git a/old/lib/_merge.js b/old/lib/_merge.js deleted file mode 100644 index c3fe695..0000000 --- a/old/lib/_merge.js +++ /dev/null @@ -1,14 +0,0 @@ -var _group = require("./_group"); -var _async = require("./_async"); - -module.exports = function(iterator) { - return _group(function(operation, busses) { - return _async(function(stream) { - iterator(busses, function(bus, complete) { - bus(operation).once("error", complete).once("end", complete).pipe(stream, { end: false }); - }, function(err) { - if (!err) stream.end(); - }); - }); - }); -}; diff --git a/old/lib/_pickOne.js b/old/lib/_pickOne.js deleted file mode 100644 index cc68530..0000000 --- a/old/lib/_pickOne.js +++ /dev/null @@ -1,45 +0,0 @@ -var Writable = require("obj-stream").Writable; -var _async = require("./_async"); -var _eachSeries = require("./_eachSeries"); -var _group = require("./_group"); -var through = require("obj-stream").through; - -/** - */ - -module.exports = function(iterator) { - return _group(function(operation, busses) { - return _async(function(stream) { - - var found; - var i = 0; - - iterator(busses, function(bus, next) { - var index = ++i; - var bs; - - // TODO - duplex this - - (bs = bus(operation)).pipe(through(function(data, next) { - if (!found || found === index) { - found = index; - this.push(data); - } - next(); - })).once("end", function() { - if (found) { - stream.end(); - } else { - next(); - } - }).pipe(stream, { end: false }); - - if (bs.writable) { - stream.once("end", bs.end.bind(bs)); - } - }, function() { - stream.end(); - }); - }); - }); -}; diff --git a/old/lib/_toArray.js b/old/lib/_toArray.js deleted file mode 100644 index bdc77db..0000000 --- a/old/lib/_toArray.js +++ /dev/null @@ -1,6 +0,0 @@ -var _isArray = require("./_isArray"); - -module.exports = function(data) { - if (data == void 0) return []; - return _isArray(data) ? data : [data]; -}; diff --git a/old/lib/accept.js b/old/lib/accept.js deleted file mode 100644 index 481c695..0000000 --- a/old/lib/accept.js +++ /dev/null @@ -1,15 +0,0 @@ -var _async = require("./_async"); -var _getFilter = require("./_getFilter"); -var noop = require("./noop"); - -module.exports = function(accept, bus, elseBus) { - - var filter = _getFilter(accept); - - if (!elseBus) elseBus = noop; - - return function(operation) { - if (filter(operation)) return bus(operation); - return elseBus(operation); - }; -}; diff --git a/old/lib/attach.js b/old/lib/attach.js deleted file mode 100644 index 17d524d..0000000 --- a/old/lib/attach.js +++ /dev/null @@ -1,28 +0,0 @@ -var createOperation = require("./operation"); -var extend = require("xtend/mutable"); - -// TODO - check if bus is a child. If so, grab target & options and return that instead -module.exports = function(options, bus) { - - if (typeof options === "string") { - var prop = options; - options = function(operation) { - return operation[prop]; - }; - } - - if (bus.__attached && typeof bus.options !== "function" && typeof options !== "function") { - options = extend({}, bus.options, options); - bus = bus.target; - } - - function ret(operation) { - return bus(extend({}, operation, typeof options === "function" ? options(operation) : options)); - } - - ret.__attached = true; - ret.options = options; - ret.target = bus; - - return ret; -}; diff --git a/old/lib/buffer.js b/old/lib/buffer.js deleted file mode 100644 index 5be57a9..0000000 --- a/old/lib/buffer.js +++ /dev/null @@ -1,20 +0,0 @@ -var stream = require("./stream"); - -module.exports = function(bus) { - return stream(function(operation, stream) { - var buffer = []; - var error; - bus(operation) - .on("error", function(err) { - error = err; - stream.emit("error", err); - }) - .on("data", buffer.push.bind(buffer)) - .on("end", function() { - if (!error) { - buffer.forEach(stream.write.bind(stream)); - } - stream.end(); - }); - }); -}; diff --git a/old/lib/catch.js b/old/lib/catch.js deleted file mode 100644 index 6ee0bba..0000000 --- a/old/lib/catch.js +++ /dev/null @@ -1,6 +0,0 @@ -var stream = require("./stream"); -module.exports = function(bus, handler) { - return stream(function(operation, stream) { - bus(operation).on("error", handler).pipe(stream); - }); -}; diff --git a/old/lib/defaults.js b/old/lib/defaults.js deleted file mode 100644 index e307cde..0000000 --- a/old/lib/defaults.js +++ /dev/null @@ -1,23 +0,0 @@ -var noop = require("./noop"); - -function _defaults(from, to) { - for (var key in from) { - if (to[key] == void 0) to[key] = from[key]; - } - return to; -} - -module.exports = function(properties, bus) { - - if (bus.__defaults && typeof bus.__defaults !== "function") { - bus.__defaults = _defaults(properties, bus.__defaults); - } - - var ret = function(operation) { - return bus(_defaults(typeof ret.__defaults === "function" ? ret.__defaults(operation) : ret.__defaults, operation)); - }; - - ret.__defaults = typeof properties === "function" ? properties : _defaults(properties, {}); - - return ret; -}; diff --git a/old/lib/fallback.js b/old/lib/fallback.js deleted file mode 100644 index 929a0d9..0000000 --- a/old/lib/fallback.js +++ /dev/null @@ -1,7 +0,0 @@ -var _eachSeries = require("./_eachSeries"); -var _pickOne = require("./_pickOne"); - -/** - */ - -module.exports = _pickOne(_eachSeries); diff --git a/old/lib/index.js b/old/lib/index.js deleted file mode 100644 index 195223b..0000000 --- a/old/lib/index.js +++ /dev/null @@ -1,32 +0,0 @@ - -/** - */ - -module.exports = { - parallel : require("./parallel"), - sequence : require("./sequence"), - first : require("./fallback"), - fallback : require("./fallback"), - race : require("./race"), - operation : require("./operation"), - op : require("./operation"), - attach : require("./attach"), - defaults : require("./defaults"), - retry : require("./retry"), - run : require("./run"), - map : require("./map"), - noop : require("./noop"), - reduce : require("./reduce"), - catchError : require("./catch"), - timeout : require("./timeout"), - wrap : require("./wrap"), - stream : require("./stream"), - wait : require("./wait"), - open : require("./open"), - tailable : require("./tailable"), - accept : require("./accept"), - reject : require("./reject"), - limit : require("./limit"), - yields : require("./yields"), - buffer : require("./buffer") -}; diff --git a/old/lib/limit.js b/old/lib/limit.js deleted file mode 100644 index 4021e0a..0000000 --- a/old/lib/limit.js +++ /dev/null @@ -1,24 +0,0 @@ -var stream = require("./stream"); - -module.exports = function(count, bus) { - - var numRunning = 0; - var queue = []; - - function dequeue() { - if (--numRunning < count && !!queue.length) run.apply(void 0, queue.shift()); - } - - function run(operation, writer) { - numRunning++; - bus(operation).once("error", dequeue).once("end", dequeue).pipe(writer); - } - - return stream(function(operation, writer) { - if (numRunning >= count) { - queue.push([operation, writer]); - } else { - run(operation, writer); - } - }); -}; diff --git a/old/lib/map.js b/old/lib/map.js deleted file mode 100644 index 014442b..0000000 --- a/old/lib/map.js +++ /dev/null @@ -1,16 +0,0 @@ -var s = require("obj-stream"); -var stream = require("./stream"); -var through = s.through; - -module.exports = function(bus, map) { - return stream(function(operation, writable) { - bus(operation).pipe(through(function(data, next) { - var mapper = s.stream(); - mapper.pipe(writable, { end: false }); - mapper.once("end", next); - map(operation, data, mapper); - })).on("data", function() { }). - once("error", writable.emit.bind(writable, "error")). - once("end", writable.end.bind(writable)); - }); -}; diff --git a/old/lib/noop.js b/old/lib/noop.js deleted file mode 100644 index 46fe2fc..0000000 --- a/old/lib/noop.js +++ /dev/null @@ -1,5 +0,0 @@ -var stream = require("./stream"); - -module.exports = stream(function(operation, stream) { - stream.end(); -}); diff --git a/old/lib/open.js b/old/lib/open.js deleted file mode 100644 index a09b90d..0000000 --- a/old/lib/open.js +++ /dev/null @@ -1,10 +0,0 @@ -var through = require("obj-stream").through; - -module.exports = function(bus) { - return through(function(operation, next) { - var self = this; - bus(operation).on("data", function(data) { - self.push(data); - }).on("end", next); - }); -}; diff --git a/old/lib/operation.js b/old/lib/operation.js deleted file mode 100644 index 4a98c7d..0000000 --- a/old/lib/operation.js +++ /dev/null @@ -1,17 +0,0 @@ -var extend = require("xtend/mutable"); - -/** - */ - -function Operation(name, options) { - if (!options) options = {}; - extend(this, options); - this.name = name; -} - -/** - */ - -module.exports = function(name, options) { - return new Operation(name, options); -}; diff --git a/old/lib/parallel.js b/old/lib/parallel.js deleted file mode 100644 index c85bd56..0000000 --- a/old/lib/parallel.js +++ /dev/null @@ -1,7 +0,0 @@ -var _eachParallel = require("./_eachParallel"); -var _merge = require("./_merge"); - -/** - */ - -module.exports = _merge(_eachParallel); diff --git a/old/lib/race.js b/old/lib/race.js deleted file mode 100644 index a054a1c..0000000 --- a/old/lib/race.js +++ /dev/null @@ -1,7 +0,0 @@ -var _eachParallel = require("./_eachParallel"); -var _pickOne = require("./_pickOne"); - -/** - */ - -module.exports = _pickOne(_eachParallel); diff --git a/old/lib/reduce.js b/old/lib/reduce.js deleted file mode 100644 index 290481e..0000000 --- a/old/lib/reduce.js +++ /dev/null @@ -1,20 +0,0 @@ -var stream = require("./stream"); -var through = require("obj-stream").through; - -module.exports = function(bus, reduce) { - return stream(function(operation, writable) { - var buffer; - bus(operation).pipe(through(function(data, next) { - - if (buffer) { - buffer = reduce(operation, buffer, data); - } else { - buffer = data; - } - - next(); - }, function() { - this.push(buffer); - })).pipe(writable); - }); -}; diff --git a/old/lib/reject.js b/old/lib/reject.js deleted file mode 100644 index 58e8c8a..0000000 --- a/old/lib/reject.js +++ /dev/null @@ -1,9 +0,0 @@ -var _getFilter = require("./_getFilter"); -var accept = require("./accept"); - -module.exports = function(reject, bus, elseBus) { - var filter = _getFilter(reject); - return accept(function(operation) { - return !filter(operation); - }, bus, elseBus); -}; diff --git a/old/lib/retry.js b/old/lib/retry.js deleted file mode 100644 index 1ee4426..0000000 --- a/old/lib/retry.js +++ /dev/null @@ -1,43 +0,0 @@ -var stream = require("./stream"); - -module.exports = function(count, errorFilter, bus) { - - if (arguments.length === 2) { - bus = errorFilter; - errorFilter = void 0; - } - - if (!errorFilter) { - errorFilter = function(operation, error) { - return true; - }; - } - - return stream(function(operation, stream) { - - var retryCountdown = count; - - function run(error) { - - if (error) { - if (!errorFilter(error) || retryCountdown <= 0) { - return stream.emit("error", error); - } - } - - retryCountdown--; - - bus(operation) - .on("data", function(data) { - retryCountdown = 0; - stream.write(data); - }) - .on("error", run) - .on("end", function() { - stream.end(); - }); - } - - run(); - }); -}; diff --git a/old/lib/run.js b/old/lib/run.js deleted file mode 100644 index 1737c49..0000000 --- a/old/lib/run.js +++ /dev/null @@ -1,24 +0,0 @@ -var operation = require("./operation"); - -module.exports = function(bus, operationName, options, onRun) { - var buffer = []; - - if (typeof options === "function") { - onRun = options; - options = {}; - } - - // TODO - use through here - bus(operation(operationName, options)). - on("data", function(data) { - buffer.push(data); - }). - on("error", onRun). - on("end", function() { - if (options.multi) { - return onRun(void 0, buffer); - } else { - return onRun(void 0, buffer.length ? buffer[0] : void 0); - } - }); -}; diff --git a/old/lib/sequence.js b/old/lib/sequence.js deleted file mode 100644 index 9d125d1..0000000 --- a/old/lib/sequence.js +++ /dev/null @@ -1,7 +0,0 @@ -var _eachSeries = require("./_eachSeries"); -var _merge = require("./_merge"); - -/** - */ - -module.exports = _merge(_eachSeries); diff --git a/old/lib/stream.js b/old/lib/stream.js deleted file mode 100644 index afc33d5..0000000 --- a/old/lib/stream.js +++ /dev/null @@ -1,9 +0,0 @@ -var _async = require("./_async"); - -module.exports = function(fn) { - return function(operation) { - return _async(function(writable) { - return fn(operation, writable); - }); - }; -}; diff --git a/old/lib/tailable.js b/old/lib/tailable.js deleted file mode 100644 index d46f6de..0000000 --- a/old/lib/tailable.js +++ /dev/null @@ -1,45 +0,0 @@ -var fallback = require("./fallback"); -var sequence = require("./sequence"); -var accept = require("./accept"); -var stream = require("./stream"); -var _equals = require("./_equals"); -var extend = require("xtend/mutable"); - -module.exports = function(bus, compare) { - - if (!compare) { - compare = _equals; - } - - var listeners = []; - var testOps = {}; - - return fallback( - accept("tail", stream(function(a, writable) { - - a = extend({}, a); - delete a.name; - - writable.test = function(b) { - return compare(a, b); - }; - - listeners.push(writable); - writable.once("end", function() { - listeners.splice(listeners.indexOf(writable), 1); - }); - })), - sequence( - bus, - stream(function(operation, stream) { - for (var i = listeners.length; i--;) { - var listener = listeners[i]; - if (listener.test(operation)) { - listeners[i].write(operation); - } - } - stream.end(); - }) - ) - ); -}; diff --git a/old/lib/timeout.js b/old/lib/timeout.js deleted file mode 100644 index 2bf8ee7..0000000 --- a/old/lib/timeout.js +++ /dev/null @@ -1,20 +0,0 @@ -var stream = require("./stream"); - -module.exports = function(ms, bus) { - return stream(function(operation, response) { - - bus(operation).pipe(response); - - var timer = setTimeout(function() { - response.emit("error", new Error("timeout")); - }, ms); - - function clearTimer() { - if (timer) clearTimeout(timer); - timer = void 0; - } - - response.once("data", clearTimer); - response.once("end", clearTimer); - }); -}; diff --git a/old/lib/wait.js b/old/lib/wait.js deleted file mode 100644 index 1c08504..0000000 --- a/old/lib/wait.js +++ /dev/null @@ -1,10 +0,0 @@ -var stream = require("./stream"); - -module.exports = function(wait, bus) { - return stream(function(operation, stream) { - wait(function(error) { - if (error) return stream.emit("error", error); - bus(operation).pipe(stream); - }); - }); -}; diff --git a/old/lib/wrap.js b/old/lib/wrap.js deleted file mode 100644 index 79cc675..0000000 --- a/old/lib/wrap.js +++ /dev/null @@ -1,18 +0,0 @@ -var _toArray = require("./_toArray"); -var stream = require("./stream"); - -module.exports = function(callback) { - return stream(function(operation, stream) { - callback(operation, function(err, data) { - if (err) return stream.emit("error", err); - - var items = _toArray(data); - - _toArray(data).forEach(function(data) { - stream.write(data); - }); - - stream.end(); - }); - }); -}; diff --git a/old/test2/accept-test.js b/old/test2/accept-test.js deleted file mode 100644 index e5a5914..0000000 --- a/old/test2/accept-test.js +++ /dev/null @@ -1,83 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can accept operations", function(next) { - - var bus = function(operation) { - return _([operation]); - }; - - bus = mesh.accept("a", bus); - bus({name:"a"}).pipe(_.pipeline(_.collect)).on("data", function(items) { - expect(items.length).to.be(1); - next(); - }); - }); - - it("can reject operations", function(next) { - var bus = function() { - return _([operation]); - }; - - bus = mesh.accept("a", bus); - bus({name:"c"}).pipe(_.pipeline(_.collect)).on("data", function(items) { - expect(items.length).to.be(0); - next(); - }); - }); - - it("accepts functions for the first arg", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, { name: "a" }); - }); - - bus = mesh.accept(function(operation) { - return operation.name === "a"; - }, bus); - - bus(mesh.op("a")).on("data", function() { - next(); - }); - }); - - it("can accept regexp", function(next) { - var i = 0; - var bus = mesh.accept(/a|b/, mesh.wrap(function(op, next) { - i++; - next(); - })); - - bus(mesh.op("a")).on("end", function() { - bus(mesh.op("b")).on("end", function() { - bus(mesh.op("c")).on("end", function() { - expect(i).to.be(2); - next(); - }); - }); - }); - }); - - it("can have an 'else' bus", function(next) { - var abus = mesh.wrap(function(op, next) { - next(void 0, "a"); - }); - - var bbus = mesh.wrap(function(op, next) { - next(void 0, "b"); - }); - - var cbus = mesh.accept("a", abus, bbus); - - cbus(mesh.op("a")).on("data", function(data) { - expect(data).to.be("a"); - cbus(mesh.op("b")).on("data", function(data) { - expect(data).to.be("b"); - next(); - }); - }); - }); -}); diff --git a/old/test2/attach-test.js b/old/test2/attach-test.js deleted file mode 100644 index 2aa940a..0000000 --- a/old/test2/attach-test.js +++ /dev/null @@ -1,125 +0,0 @@ -var mesh = require("../"); -var through = require("through2"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can be created", function(next) { - - function bus(operation) { - return _([operation]); - } - - var child = mesh.attach({ a: 1 }, bus); - - child({ name:"insert", b: 2 }).once("data", function(data) { - expect(data.a).to.be(1); - expect(data.b).to.be(2); - next(); - }); - }); - - it("copies configs over from a previously decorated bus", function() { - - function bus(operation) { - return _([operation]); - } - - var child = mesh.attach({ a: 1 }, bus); - expect(child.options.a).to.be(1); - expect(child.target).to.be(bus); - child = mesh.attach({ b: 1 }, child); - expect(child.options.a).to.be(1); - expect(child.options.b).to.be(1); - expect(child.target).to.be(bus); - // expect(child.) - }); - - it("can override a previously decorated prop", function() { - - function bus(operation) { - return _([operation]); - } - - var child = mesh.attach({ a: 1 }, bus); - expect(child.options.a).to.be(1); - expect(child.target).to.be(bus); - child = mesh.attach({ a: 2 }, child); - expect(child.options.a).to.be(2); - expect(child.target).to.be(bus); - }); - - it("doesn't set props on the original operation", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, 1); - }); - - bus = mesh.attach({ a: 1 }, bus); - var op = mesh.op("load"); - bus(op).on("end", function() { - expect(op.a).to.be(void 0); - next(); - }); - }); - - it("can use a function to attach props", function(next) { - var bus = mesh.wrap(function(operation, next) { - expect(operation.b).to.be(1); - next(void 0, 1); - }); - - bus = mesh.attach(function(operation) { - return { - b: operation.a - }; - }, bus); - var op = mesh.op("load", { a: 1 }); - bus(op).on("end", function() { - next(); - }); - }); - - it("can use a function to attach props", function(next) { - var bus = mesh.wrap(function(operation, next) { - expect(operation.b).to.be(1); - expect(operation.a).to.be(2); - next(void 0, 1); - }); - - bus = mesh.attach(function(operation) { - return { - b: 1 - }; - }, bus); - - bus = mesh.attach({ a: 2 }, bus); - - var op = mesh.op("load"); - bus(op).on("end", function() { - next(); - }); - }); - - it("can attach properties from the operation into the op", function(next) { - var bus = mesh.wrap(function(operation, next) { - expect(operation.b).to.be(2); - next(void 0, 1); - }); - - bus = mesh.attach("a", bus); - var op = mesh.op("load", { a: { b: 2 } }); - bus(op).on("end", function() { - next(); - }); - }); - - it("attach properties override operation properties", function(next) { - var bus = mesh.attach({ name: "b" }, mesh.wrap(function(operation) { - expect(operation.name).to.be("b"); - next(); - })); - bus({ name: "a" }); - }); -}); diff --git a/old/test2/buffer-test.js b/old/test2/buffer-test.js deleted file mode 100644 index ea0e44e..0000000 --- a/old/test2/buffer-test.js +++ /dev/null @@ -1,40 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - - it("can buffer a stream of data, then re-emit that data when the stream has ended", function(next) { - var buffer = []; - - var bus = mesh.buffer(mesh.stream(function(operation, stream) { - stream.write("two"); - stream.write("chunks"); - stream.end(); - })); - - bus({}) - .on("data", buffer.push.bind(buffer)) - .on("end", function() { - expect(buffer.join(" ")).to.be("two chunks"); - next(); - }); - }); - - it("fails if a stream emits an error after data is emitted", function(next) { - var buffer = []; - - var bus = mesh.buffer(mesh.stream(function(operation, stream) { - stream.write("two"); - stream.write("chunks"); - stream.emit("error", new Error("failed")); - })); - - bus({}) - .on("data", buffer.push.bind(buffer)) - .on("error", function(error) { - expect(buffer.join(" ")).to.be(""); - expect(error.message).to.be("failed"); - next(); - }); - }); -}); diff --git a/old/test2/cases/README.md b/old/test2/cases/README.md deleted file mode 100644 index 9e72c95..0000000 --- a/old/test2/cases/README.md +++ /dev/null @@ -1,22 +0,0 @@ -various test cases you should run if you plan on creating a mesh adapter. - -# Database test cases - -Docs can be [viewed here](http://mesh.mojojs.com/docs/database-adapters). - -Test case usage: - -```javascript -var createDBCases = require("mesh/test-cases/database"); -var memory = require("mesh-memory"); - -describe("in-memory-adapter#", function() { - - // createCases(createBus) - var cases = createDBCases(function(options) { - return memory(options); - }); - - for (var name in cases) it(name, cases[name]); -}); -``` diff --git a/old/test2/cases/database/index-test.js b/old/test2/cases/database/index-test.js deleted file mode 100644 index 3f27223..0000000 --- a/old/test2/cases/database/index-test.js +++ /dev/null @@ -1,12 +0,0 @@ -var expect = require("expect.js"); -var createCases = require("./index"); -var memory = require("mesh-memory"); - -describe(__filename + "#", function() { - - var cases = createCases(function(options) { - return memory(options); - }); - - for (var name in cases) it(name, cases[name]); -}); diff --git a/old/test2/cases/database/index.js b/old/test2/cases/database/index.js deleted file mode 100644 index b8895b8..0000000 --- a/old/test2/cases/database/index.js +++ /dev/null @@ -1,184 +0,0 @@ -var mesh = require("../../.."); -var expect = require("expect.js"); -var _ = require("highland"); - -module.exports = function(createDb) { - - var cases = {}; - var db; - - function it(description, run) { - cases[description] = function(next) { - if (!next) next = function() { }; - db = mesh.limit(1, createDb()); - run(next); - }; - return cases[description]; - } - - function xit() { - - } - - var insertOneItem = it("can insert one item", function(next) { - db({ name: "insert", collection: "items", data: { name: "a" }}).on("data", function(data) { - expect(data.name).to.be("a"); - next(); - }); - }); - - var insertMultipleItems = it("can insert multiple items", function(next) { - db(mesh.op("insert", { - collection: "items", - data: [ - { name: "a", count: 1 }, - { name: "b", count: 1 }, - { name: "c", count: 2 } - ] - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(3); - next(); - }); - }); - - it("can load one item", function(next) { - insertOneItem(); - db(mesh.op("load", { - collection: "items", - query: { name: "a" } - })).on("data", function(data) { - expect(data.name).to.be("a"); - next(); - }); - }); - - it("can load multiple items", function(next) { - insertMultipleItems(); - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 1 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can load all items", function(next) { - insertMultipleItems(); - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(3); - next(); - }); - }); - - xit("can load no items", function() { - - }); - - xit("emits an error if collection is missing", function(next) { - // var db = mesh.clean(lokidb()); - db("insert", { data: { name: "abba" }}).on("error", function() { - next(); - }); - }); - - xit("ignores operations that are not supported", function(next) { - db(mesh.op("afdfsfsd", { collection: "people", data: { name: "a"}})).on("end", function() { - next(); - }); - }); - - it("can update one item", function(next) { - insertMultipleItems(); - - db(mesh.op("update", { - collection: "items", - query: { count: 1 }, - data: { count: 3 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 3 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(1); - next(); - }); - }); - - it("can update multiple items", function(next) { - insertMultipleItems(); - - db(mesh.op("update", { - collection: "items", - query: { count: 1 }, - multi: true, - data: { count: 3 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true, - query: { count: 3 } - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can remove one item", function(next) { - insertMultipleItems(); - - db(mesh.op("remove", { - collection: "items", - query: { count: 1 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - next(); - }); - }); - - it("can remove multiple items", function(next) { - insertMultipleItems(); - - db(mesh.op("remove", { - collection: "items", - multi: true, - query: { count: 1 } - })); - - db(mesh.op("load", { - collection: "items", - multi: true - })). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(1); - next(); - }); - }); - - return cases; -}; diff --git a/old/test2/catch-test.js b/old/test2/catch-test.js deleted file mode 100644 index 4795b64..0000000 --- a/old/test2/catch-test.js +++ /dev/null @@ -1,19 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can be run", function(next) { - var bus = mesh.wrap(function(operation, callback) { - callback(new Error("error!")); - }); - - bus = mesh.catchError(bus, function(err) { - expect(err.message).to.be("error!"); - next(); - }); - - bus(mesh.op("blah")).on("error", function() { }); - }); -}); diff --git a/old/test2/defaults-test.js b/old/test2/defaults-test.js deleted file mode 100644 index 4ec1619..0000000 --- a/old/test2/defaults-test.js +++ /dev/null @@ -1,46 +0,0 @@ -var mesh = require(".."); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - - it("can set default properties on the operation", function(next) { - var bus = mesh.defaults({name:"op"}, mesh.wrap(function(operation) { - expect(operation.name).to.be("op"); - next(); - })); - bus({}); - }); - - it("does not override existing properties", function(next) { - var bus = mesh.defaults({name:"op2", key:"value"}, mesh.wrap(function(operation) { - expect(operation.name).to.be("op"); - expect(operation.key).to.be("value"); - next(); - })); - bus({name:"op"}); - }); - - it("can set defaults multiple times", function(next) { - var bus = mesh.defaults({name:"op2", age:12, key:"val"}, mesh.wrap(function(operation) { - expect(operation.name).to.be("op"); - expect(operation.key).to.be("value"); - expect(operation.age).to.be(12); - next(); - })); - - bus = mesh.defaults({key:"value"}, bus); - bus({name:"op"}); - }); - - it("can define defaults as a function", function(next) { - var bus = mesh.defaults(function(operation) { - return { name: "op2", key: "value" }; - }, mesh.wrap(function(operation) { - expect(operation.name).to.be("op"); - expect(operation.key).to.be("value"); - next(); - })); - - bus({name:"op"}); - }); -}); diff --git a/old/test2/fallback-test.js b/old/test2/fallback-test.js deleted file mode 100644 index 893c34e..0000000 --- a/old/test2/fallback-test.js +++ /dev/null @@ -1,47 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var stream = require("obj-stream"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can be run", function(next) { - - var i = 0; - var j = 0; - - var startTime = Date.now(); - - var bus = function() { - i++; - return _([1]); - }; - - bus = mesh.first(bus, bus); - bus({name:"insert"}).on("end", function() { - expect(i).to.be(1); - next(); - }); - }); - - it("works with readable stream", function(next) { - var bus = function(operation) { - var writable = stream.writable(); - process.nextTick(function() { - writable.end(operation.name); - }); - return writable.reader; - }; - - bus = mesh.fallback(bus, bus); - - bus(mesh.op("load")).on("data", function(data) { - expect(data).to.be("load"); - next(); - }); - }); - - xit("can run without any args", function(next) { - var bus = mesh.fallback(); - bus(mesh.op("insert")).on("end", next); - }); -}); diff --git a/old/test2/group-test.js b/old/test2/group-test.js deleted file mode 100644 index eb6d546..0000000 --- a/old/test2/group-test.js +++ /dev/null @@ -1,142 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("accepts arrays", function(next) { - - var source = [ - mesh.wrap(function(o, n) { - n(void 0, 1); - }), - mesh.wrap(function(o, n) { - n(void 0, 2); - }) - ]; - - var bus = mesh.parallel(source); - - bus(mesh.op("a")). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - next(); - }); - }); - - it("can push a new event bus handler at the end", function(next) { - - var source = [ - mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 1); - })) - ]; - - var bus = mesh.first(source); - - source.push(mesh.accept("b", mesh.wrap(function(operation, next) { - next(void 0, 2); - }))); - - source.push(mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 2); - }))); - - bus(mesh.op("a")).on("data", function(data) { - expect(data).to.be(1); - bus(mesh.op("b")).on("data", function(data) { - expect(data).to.be(2); - next(); - }); - }); - }); - - it("can remove a bus", function(next) { - - var source = [ - mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 1); - })) - ]; - - var bus = mesh.first(source); - - var a2 = mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 2); - })); - - source.unshift(a2); - - bus(mesh.op("a")).on("data", function(data) { - expect(data).to.be(2); - source.splice(0, 1); - bus(mesh.op("a")).on("data", function(data) { - expect(data).to.be(1); - next(); - }); - }); - }); - - it("can add multiple busses", function(next) { - - var source = []; - - var bus = mesh.parallel(source); - - source.push( - mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 1); - })), - mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 2); - })) - ); - - bus(mesh.op("a")). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - next(); - }); - }); - - it("can push a new event bus handler at the beginning", function(next) { - - var source = [ - mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 1); - })) - ]; - - var bus = mesh.first(source); - - source.unshift(mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 2); - }))); - - bus(mesh.op("a")).on("data", function(data) { - expect(data).to.be(2); - next(); - }); - }); - - it("accepts sources as a function", function(next) { - - var source = function(operation) { - return mesh.accept("a", mesh.wrap(function(operation, next) { - next(void 0, 1); - }))(operation); - }; - - var bus = mesh.first(source); - - bus(mesh.op("a")).on("data", function(data) { - expect(data).to.be(1); - next(); - }); - }); -}); diff --git a/old/test2/limit-test.js b/old/test2/limit-test.js deleted file mode 100644 index e14c79a..0000000 --- a/old/test2/limit-test.js +++ /dev/null @@ -1,102 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can limit to 1 operation at a time", function(next) { - - var i = 0; - - var busA = mesh.wrap(function(operation, next) { - i++; - setTimeout(next, 10); - }); - - var bus = mesh.limit(1, busA); - bus(mesh.op({ name: "run" })); - bus(mesh.op({ name: "run" })); - bus(mesh.op({ name: "run" })); - bus(mesh.op({ name: "run" })); - setTimeout(function() { - expect(i).to.be(1); - next(); - }, 1); - }); - - it("properly executes all ops in sequence", function(next) { - - var i = 0; - var j = 0; - - var busA = mesh.wrap(function(operation, next) { - i++; - setTimeout(next, 1); - }); - - var bus = mesh.limit(1, busA); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(1); - expect(i).to.be(1); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(2); - expect(i).to.be(2); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(3); - expect(i).to.be(3); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - expect(j).to.be(3); - expect(i).to.be(4); - next(); - }); - }); - - it("run multiple ops at the same time", function(next) { - - var i = 0; - var j = 0; - - var busA = mesh.wrap(function(operation, next) { - i++; - setTimeout(next, 1); - }); - - var bus = mesh.limit(2, busA); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(1); - expect(i).to.be(2); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(2); - expect(i).to.be(2); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - j++; - expect(j).to.be(3); - expect(i).to.be(4); - }); - bus(mesh.op({ name: "run" })).on("end", function() { - expect(j).to.be(3); - expect(i).to.be(4); - next(); - }); - }); - - it("can pass an error down and still work", function(next) { - var bus = mesh.limit(1, mesh.yields(new Error("error"))); - bus(mesh.op("error")).on("error", function() { }); - bus(mesh.op("error")).on("error", function() { }); - bus(mesh.op("error")).on("error", function() { - next(); - }); - }); -}); diff --git a/old/test2/map-test.js b/old/test2/map-test.js deleted file mode 100644 index 3cb12f4..0000000 --- a/old/test2/map-test.js +++ /dev/null @@ -1,62 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can map data into something else", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, operation.name); - }); - - bus = mesh.map(bus, function(operation, data, stream) { - data.split("").forEach(stream.write.bind(stream)); - stream.end(); - }); - - bus(mesh.op("hello")) - .pipe(_.pipeline(_.collect)) - .on("data", function(data) { - expect(data.length).to.be(5); - expect(data[0]).to.be("h"); - expect(data[1]).to.be("e"); - expect(data[2]).to.be("l"); - expect(data[3]).to.be("l"); - expect(data[4]).to.be("o"); - next(); - }); - }); - - it("passes errors downstream", function(next) { - var bus = mesh.yields(new Error("blah!")) ; - bus = mesh.map(bus, function() { - - }); - bus({}).on("error", function(error) { - next(); - }); - }); - - it("doesn't end the parent stream", function(next) { - var bus = mesh.stream(function(operation, stream) { - stream.write("ab"); - stream.end("cd"); - }); - - bus = mesh.map(bus, function(operation, data, stream) { - data.split("").forEach(stream.write.bind(stream)); - stream.end(); - }); - - bus(mesh.op("hello")) - .pipe(_.pipeline(_.collect)) - .on("data", function(data) { - expect(data.length).to.be(4); - expect(data[0]).to.be("a"); - expect(data[1]).to.be("b"); - expect(data[2]).to.be("c"); - expect(data[3]).to.be("d"); - next(); - }); - }); -}); diff --git a/old/test2/mesh-test.js b/old/test2/mesh-test.js deleted file mode 100644 index 4b891d6..0000000 --- a/old/test2/mesh-test.js +++ /dev/null @@ -1,57 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); -var ss = require("obj-stream"); - -describe(__filename + "#", function() { - - it("passes a new operation to the data source in the mesh", function(next) { - - function bus(operation) { - expect(operation.data).to.be("a"); - return _([]); - } - - bus({name:"fdsfs", data: "a" }).on("data", function() { }).on("end", next); - }); - - it("can properly handle errors", function(next) { - function bus(operation) { - var stream = ss.writable(); - process.nextTick(function() { - stream.reader.emit("error", new Error("err")); - }); - return stream.reader; - } - - bus(mesh.op("insert")).pipe(_.pipeline(_.collect)).on("error", function() { - next(); - }); - }); - - it("can write data to the stream", function(next) { - function bus(operation) { - return _([{a:1}]); - } - - bus({name:"insert"}).on("data", function(data) { - expect(data.a).to.be(1); - }).on("end", next); - }); - - it("emits an error if the next param gets an error", function(next) { - function bus(operation) { - var writer = ss.writable(); - process.nextTick(function() { - writer.reader.emit("error", new Error("abba")); - }); - return writer.reader; - } - - bus(mesh.operation("insert")).once("error", function(err) { - expect(err.message).to.be("abba"); - next(); - }); - }); -}); diff --git a/old/test2/operation-test.js b/old/test2/operation-test.js deleted file mode 100644 index ae6868f..0000000 --- a/old/test2/operation-test.js +++ /dev/null @@ -1,10 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - it("can be created", function() { - var op = mesh.operation("insert", { collection: "blarg" }); - expect(op.name).to.be("insert"); - expect(op.collection).to.be("blarg"); - }); -}); diff --git a/old/test2/parallel-test.js b/old/test2/parallel-test.js deleted file mode 100644 index 09319ba..0000000 --- a/old/test2/parallel-test.js +++ /dev/null @@ -1,67 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can be run", function(next) { - - var i = 0; - var j = 0; - - var startTime = Date.now(); - - var db1 = function(name, properties) { - i++; - expect(Date.now() - startTime).to.be.lessThan(5); - return _([{ name: "a"}, { name: "a"}, { name: "a" }]).pipe(through.obj(function(data, enc, next) { - this.push(data); - setTimeout(next, 3); - })); - }; - - var db2 = function() { - i++; - expect(Date.now() - startTime).to.be.lessThan(5); - return _([{ name: "a"}, { name: "a"}, { name: "a" }]).pipe(through.obj(function(data, enc, next) { - this.push(data); - setTimeout(next, 3); - })); - }; - - var db3 = mesh.parallel(db1, db2); - db3("insert").on("data", function() { - j++; - }).on("end", function() { - expect(i).to.be(2); - expect(j).to.be(6); - next(); - }); - }); - - it("can run without any args", function(next) { - var bus = mesh.parallel(); - bus(mesh.op("insert")).on("end", next); - }); - - it("can handle an error", function(next) { - - var busA = mesh.yields(new Error("done")); - var busB = mesh.yields(void 0, 1); - - var bus = mesh.parallel(busA, busB); - var i = 0; - var j = 0; - bus(mesh.op("done")).on("error", function() { - j++; - }).on("end", function() { - i++; - }); - - setTimeout(function() { - expect(i).to.be(0); - expect(j).to.be(1); - next(); - }, 10); - }); -}); diff --git a/old/test2/race-test.js b/old/test2/race-test.js deleted file mode 100644 index d2c1a38..0000000 --- a/old/test2/race-test.js +++ /dev/null @@ -1,47 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can be run once", function(next) { - - var i = 0; - - var bus = mesh.wrap(function(operation, next) { - i++; - - setTimeout(next, 1, void 0, 1); - }); - - bus = mesh.race(bus, bus); - bus(mesh.op("mesh")).on("data", function() { - expect(i).to.be(2); - next(); - }); - }); - - it("picks the fastest stream", function(next) { - var i = 0; - - var busA = mesh.wrap(function(operation, next) { - setTimeout(next, 0, void 0, 1); - }); - - var busB = mesh.wrap(function(operation, next) { - setTimeout(next, 10, void 0, 4); - }); - - bus = mesh.race(busA, busB); - bus(mesh.op("test")).on("data", function(data) { - expect(data).to.be(1); - next(); - }); - }); - - it("can run without any args", function(next) { - var bus = mesh.race(); - bus(mesh.op("insert")).on("end", next); - }); -}); diff --git a/old/test2/recipes-test.js b/old/test2/recipes-test.js deleted file mode 100644 index ed7851a..0000000 --- a/old/test2/recipes-test.js +++ /dev/null @@ -1,25 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can map data to another value", function(next) { - - function bus(name, props) { - return _([{ name: "a" }, { name: "b" }]); - } - - bus(). - pipe(_.pipeline( - _.map(function(d) { return d.name; }), - _.collect - )). - on("data", function(items) { - expect(items[0]).to.be("a"); - expect(items[1]).to.be("b"); - next(); - }); - }); -}); diff --git a/old/test2/reduce-test.js b/old/test2/reduce-test.js deleted file mode 100644 index f4deeb6..0000000 --- a/old/test2/reduce-test.js +++ /dev/null @@ -1,30 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can reduce operation data", function(next) { - - var bus = function(operation) { - return _(operation.name.split("")); - }; - - bus = mesh.reduce(bus, function(op, pv, nv) { - return nv + pv; - }); - - var op = bus(mesh.op("hello", { multi: true })); - - op.on("data", function(message) { - expect(message).to.be("olleh"); - next(); - }); - }); - - it("can handle errors", function(next) { - var bus = mesh.reduce(mesh.yields(new Error("err")), function() { - - }); - bus(mesh.op("a")).on("error", next.bind(void 0, void 0)); - }); -}); diff --git a/old/test2/reject-test.js b/old/test2/reject-test.js deleted file mode 100644 index 634c10f..0000000 --- a/old/test2/reject-test.js +++ /dev/null @@ -1,66 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can accept operations", function(next) { - - var bus = function(name, properties) { - return _([properties]); - }; - - bus = mesh.reject("a" , bus); - bus({name:"c"}).pipe(_.pipeline(_.collect)).on("data", function(items) { - expect(items.length).to.be(1); - next(); - }); - }); - - it("can reject operations", function(next) { - var bus = function(name, properties) { - return _([properties]); - }; - - bus = mesh.reject("a", bus); - bus({name:"a"}).pipe(_.pipeline(_.collect)).on("data", function(items) { - expect(items.length).to.be(0); - next(); - }); - }); - - it("reject functions for the first arg", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, { name: "a" }); - }); - - bus = mesh.reject(function(operation) { - return operation.name === "a"; - }, bus); - - bus(mesh.op("b")).on("data", function() { - next(); - }); - }); - - it("can have an 'else' bus", function(next) { - var abus = mesh.wrap(function(op, next) { - next(void 0, "a"); - }); - - var bbus = mesh.wrap(function(op, next) { - next(void 0, "b"); - }); - - var cbus = mesh.reject("a", abus, bbus); - - cbus(mesh.op("a")).on("data", function(data) { - expect(data).to.be("b"); - cbus(mesh.op("b")).on("data", function(data) { - expect(data).to.be("a"); - next(); - }); - }); - }); -}); diff --git a/old/test2/retry-test.js b/old/test2/retry-test.js deleted file mode 100644 index f84f253..0000000 --- a/old/test2/retry-test.js +++ /dev/null @@ -1,61 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - - it("can retry a bus twice if an operation fails", function(next) { - var tryCount = 0; - - var bus = mesh.retry(2, mesh.wrap(function(operation, next) { - tryCount++; - next(new Error("fail")); - })); - - bus({}).on("error", function(err) { - expect(tryCount).to.be(2); - next(); - }); - }); - - it("doesn't retry a bus if data is emitted before an error", function(next) { - - var tryCount = 0; - - var bus = mesh.retry(5, mesh.stream(function(operation, stream) { - tryCount++; - stream.write("data"); - stream.emit("error", new Error("error!")); - stream.end(); - })); - - var chunk; - - bus({}) - .on("data", function(data) { - chunk = data; - }) - .on("error", function(err) { - expect(chunk).to.be("data"); - expect(tryCount).to.be(1); - next(); - }); - }); - - it("can setup a condition for errors before retrying", function(next) { - var tryCount = 0; - function testError(error) { - return error.message !== "count 2"; - } - - var bus = mesh.retry(10, testError, mesh.wrap(function(operation, next) { - tryCount++; - next(new Error("count " + tryCount)); - })); - - bus({}) - .on("error", function(err) { - expect(tryCount).to.be(2); - next(); - }); - }); -}); diff --git a/old/test2/run-test.js b/old/test2/run-test.js deleted file mode 100644 index 2ac026c..0000000 --- a/old/test2/run-test.js +++ /dev/null @@ -1,64 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); -var ss = require("obj-stream"); - -describe(__filename + "#", function() { - - it("can run a bus operation", function(next) { - - function bus(operation) { - expect(operation.data.a).to.be(1); - return _([1, 2]); - } - - mesh.run(bus, "insert", { data: { a: 1}}, function(err, data) { - expect(data).to.be(1); - next(); - }); - }); - - it("can run a bus operation and load multiple items", function(next) { - - function bus(operation) { - expect(operation.data.a).to.be(1); - return _([1, 2]); - } - - mesh.run(bus, "insert", { multi: true, data: { a: 1}}, function(err, data) { - expect(data.length).to.be(2); - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - next(); - }); - }); - - it("can run a bus operation and handle an error", function(next) { - - function bus(operation) { - var stream = ss.writable(); - process.nextTick(function() { - stream.reader.emit("error", new Error("err")); - }); - return stream.reader; - } - - mesh.run(bus, "insert", { multi: true, data: { a: 1}}, function(err, data) { - expect(err.message).to.be("err"); - next(); - }); - }); - - it("can run operations without options", function(next) { - var bus = mesh.wrap(function(operation, next) { - next(void 0, operation.name); - }); - - mesh.run(bus, "insert", function(err, data) { - expect(data).to.be("insert"); - next(); - }); - }); - -}); diff --git a/old/test2/sequence-test.js b/old/test2/sequence-test.js deleted file mode 100644 index 32d8d99..0000000 --- a/old/test2/sequence-test.js +++ /dev/null @@ -1,46 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var through = require("through2"); -var _ = require("highland"); - -describe(__filename + "#", function() { - it("can be run", function(next) { - - var i = 0; - var j = 0; - - var startTime = Date.now(); - - var db1 = function(name, properties) { - i++; - expect(Date.now() - startTime).to.be.lessThan(5); - return _([{ name: "a"}, { name: "a"}, { name: "a" }]).pipe(through.obj(function(data, enc, next) { - this.push(data); - setTimeout(next, 50); - })); - }; - - var db2 = function() { - i++; - expect(Date.now() - startTime).to.be.greaterThan(50); - return _([{ name: "a"}, { name: "a"}, { name: "a" }]).pipe(through.obj(function(data, enc, next) { - this.push(data); - setTimeout(next, 50); - })); - }; - - var db3 = mesh.sequence(db1, db2); - db3(mesh.op("insert")).on("data", function() { - j++; - }).on("end", function() { - expect(i).to.be(2); - expect(j).to.be(6); - next(); - }); - }); - - it("can run without any args", function(next) { - var bus = mesh.sequence(); - bus(mesh.op("insert")).on("end", next); - }); -}); diff --git a/old/test2/stream-test.js b/old/test2/stream-test.js deleted file mode 100644 index 8ad380d..0000000 --- a/old/test2/stream-test.js +++ /dev/null @@ -1,31 +0,0 @@ -var mesh = require("../"); -var through = require("through2"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can write a stream of operations", function(next) { - var results = []; - - function bus(operation) { - return _([operation]); - } - - var stream = mesh.open(bus); - stream.on("data", function(data) { - results.push(data); - }); - - stream.on("end", function() { - expect(results[0].name).to.be("insert"); - expect(results[1].name).to.be("load"); - expect(results[2].name).to.be("remove"); - next(); - }); - - stream.write(mesh.operation("insert")); - stream.write(mesh.operation("load")); - stream.end(mesh.operation("remove")); - }); -}); diff --git a/old/test2/tailable-test.js b/old/test2/tailable-test.js deleted file mode 100644 index a012b59..0000000 --- a/old/test2/tailable-test.js +++ /dev/null @@ -1,110 +0,0 @@ -var mesh = require("../"); -var through = require("through2"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can tail a bus", function(next) { - - var bus = function(name, properties) { - return _([]); - }; - - bus = mesh.tailable(bus); - - bus({name:"tail"}).on("data", function(operation) { - expect(operation.name).to.be("insert"); - next(); - }); - - bus(mesh.op("insert")); - }); - - it("emits multiple operations", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, operation.name); - }); - - bus = mesh.tailable(mesh.limit(1, bus)); - var i = 0; - - var tail = bus(mesh.op("tail")).on("data", function() { - i++; - }); - - bus(mesh.op("hello2")); - bus(mesh.op("hello2")); - bus(mesh.op("hello2")).on("end", function() { - expect(i).to.be(3); - next(); - }); - }); - - it("can end a tail", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, operation.name); - }); - - bus = mesh.tailable(mesh.limit(1, bus)); - var i = 0; - - var tail = bus(mesh.op("tail")).on("data", function() { - i++; - }); - - bus(mesh.op("hello")).on("end", tail.end.bind(tail)); - bus(mesh.op("hello2")); - bus(mesh.op("hello3")); - bus(mesh.op("hello2")).on("end", function() { - expect(i).to.be(1); - next(); - }); - }); - - it("only emits operations that match the tail props", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, operation.name); - }); - - bus = mesh.tailable(bus); - var i = 0; - - var tail = bus(mesh.op("tail", { collection: "blarg" })).on("data", function() { - i++; - }); - - bus(mesh.op("hello2", { collection: "blarg" })); - bus(mesh.op("hello2")); - bus(mesh.op("hello2", { collection: "blarg" })).on("end", function() { - expect(i).to.be(2); - next(); - }); - }); - - it("can accept a custom filter", function(next) { - var i = 0; - - var bus = mesh.wrap(function(operation, next) { - next(); - }); - - bus = mesh.tailable(bus, function(a, b) { - return b.collection === a.collection; - }); - - bus(mesh.op("tail", { collection: "a" })).on("data", function() { - i++; - }); - - bus(mesh.op("insert", { collection: "a" })).on("end", function() { - bus(mesh.op("insert", { collection: "b" })).on("end", function() { - expect(i).to.be(1); - next(); - }); - }); - }); -}); diff --git a/old/test2/timeout-test.js b/old/test2/timeout-test.js deleted file mode 100644 index a736f4f..0000000 --- a/old/test2/timeout-test.js +++ /dev/null @@ -1,59 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - - it("can timeout a bus after N ms", function() { - var bus = mesh.timeout(10, mesh.wrap(function(operation, next) { - setTimeout(next, 100); - })); - - bus({}).on("error", function(error) { - expect(error.message).to.contain("timeout"); - }); - }); - - it("stops the timer if a bus emits data before timeout", function(next) { - - var bus = mesh.timeout(10, mesh.stream(function(operation, stream) { - stream.write("data"); - })); - - var chunk; - var error; - - bus({}) - .on("data", function(data) { - chunk = data; - }) - .on("error", function(err) { - error = err; - }); - - setTimeout(function() { - expect(chunk).to.be("data"); - expect(error).to.be(void 0); - next(); - }, 100); - }); - - it("stops the timer if a bus emits end before timeout", function(next) { - - var bus = mesh.timeout(10, mesh.stream(function(operation, stream) { - stream.end(); - })); - - var chunk; - var error; - - bus({}) - .on("error", function(err) { - error = err; - }); - - setTimeout(function() { - expect(error).to.be(void 0); - next(); - }, 100); - }); -}); diff --git a/old/test2/wait-test.js b/old/test2/wait-test.js deleted file mode 100644 index a600865..0000000 --- a/old/test2/wait-test.js +++ /dev/null @@ -1,44 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); - -describe(__filename + "#", function() { - it("can wait for a callback before passing an operation to a bus", function(next) { - - var waitCount = 0; - - var bus = mesh.wait(function(next) { - waitCount++; - setTimeout(next, 10); - }, mesh.wrap(function(operation, next) { - expect(waitCount).to.be(1); - next(void 0, "data"); - })); - - bus({}) - .on("data", function(data) { - expect(data).to.be("data"); - next(); - }); - }); - - it("ends the stream if the wait function errors", function(next) { - - var busHandleCount = 0; - - var bus = mesh.wait(function(next) { - next(new Error("error!")); - }, mesh.wrap(function(operation, next) { - busHandleCount++; - next(); - })); - - bus({}) - .on("error", function(error) { - setTimeout(function() { - expect(error.message).to.be("error!"); - expect(busHandleCount).to.be(0); - next(); - }, 50); - }); - }); -}); diff --git a/old/test2/wrap-callback-test.js b/old/test2/wrap-callback-test.js deleted file mode 100644 index 6c075ed..0000000 --- a/old/test2/wrap-callback-test.js +++ /dev/null @@ -1,41 +0,0 @@ -var mesh = require("../"); -var expect = require("expect.js"); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can run operations", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(void 0, "a"); - }); - - bus(mesh.op("insert")).on("data", function() { - next(); - }); - }); - - it("can handle errors", function(next) { - - var bus = mesh.wrap(function(operation, next) { - next(new Error("a")); - }); - - bus(mesh.op("insert")).on("error", function() { - next(); - }); - }); - - it("emits multiple values if the returned value is an array and multi=true", function(next) { - var bus = mesh.wrap(function(operation, next) { - next(void 0, [1, 2]); - }); - - bus(mesh.op("insert", { multi: true })).pipe(_.pipeline(_.collect)).on("data", function(data) { - expect(data.length).to.be(2); - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - next(); - }); - }); -}); diff --git a/old/test2/yields-test.js b/old/test2/yields-test.js deleted file mode 100644 index 0a00d53..0000000 --- a/old/test2/yields-test.js +++ /dev/null @@ -1,70 +0,0 @@ -var expect = require("expect.js"); -var mesh = require(".."); -var _ = require("highland"); - -describe(__filename + "#", function() { - - it("can yield plain data", function(next) { - var bus = mesh.yields(void 0, { name: "aa" }); - bus(mesh.op("a")).on("data", function(data) { - expect(data.name).to.be("aa"); - next(); - }); - }); - - it("can yield multiple data", function(next) { - var bus = mesh.yields(void 0, [1, 2]); - bus(mesh.op("a")). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(2); - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - next(); - }); - }); - - it("can use a fn", function(next) { - var bus = mesh.yields(void 0, function(op) { - return op.name; - }); - bus(mesh.op("a")). - on("data", function(data) { - expect(data).to.be("a"); - next(); - }); - }); - - it("can return an array in a fn", function(next) { - var bus = mesh.yields(void 0, function(op) { - return [1, 2, 3]; - }); - bus(mesh.op("a")). - pipe(_.pipeline(_.collect)). - on("data", function(data) { - expect(data.length).to.be(3); - expect(data[0]).to.be(1); - expect(data[1]).to.be(2); - expect(data[2]).to.be(3); - next(); - }); - }); - - it("can yield an error", function(next) { - var bus = mesh.yields(new Error("err")); - bus(mesh.op("d")).on("error", function(error) { - expect(error.message).to.be("err"); - next(); - }); - }); - - it("can yield an error in a fn", function(next) { - var bus = mesh.yields(function(operation) { - return new Error(operation.name); - }); - bus(mesh.op("d")).on("error", function(error) { - expect(error.message).to.be("d"); - next(); - }); - }); -}); diff --git a/package.json b/package.json index 7ce9230..f2f2814 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mesh", - "version": "5.0.14", + "version": "5.0.15", "tag": "trunk", "description": "data synchronization library", "main": "./lib/index.js", diff --git a/response/buffered.js b/response/buffered.js index 6815444..1ead298 100644 --- a/response/buffered.js +++ b/response/buffered.js @@ -1,4 +1,5 @@ var Response = require('./index'); +var isArray = require('../internal/is-array'); /** */ @@ -6,7 +7,7 @@ var Response = require('./index'); function BufferedResponse(error, chunkValues) { Response.call(this, function(writable) { if (error) writable.abort(error); - chunkValues = Array.isArray(chunkValues) ? chunkValues : chunkValues != void 0 ? [chunkValues] : []; + chunkValues = isArray(chunkValues) ? chunkValues : chunkValues != void 0 ? [chunkValues] : []; chunkValues.forEach(writable.write.bind(writable)); writable.close(); });