ts-event-bus
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)t.d(r,a,function(n){return e[n]}.bind(null,a));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=4)}([function(e,n,t){"use strict";function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(n,"__esModule",{value:!0});var o=t(1),i=t(2),c=function(){throw new Error("Slot not connected")},s=Object.assign(function(){return c()},{on:c,lazy:c,slotName:"Not connected"}),u="LOCAL_TRANSPORT",l=function(e,n){return Object.keys(n).reduce(function(t,r){return t.concat(n[r][e]||[])},[])},f=function(e){return Object.keys(e).reduce(function(n,t){var r=e[t],o=Object.keys(r).filter(function(e){return(r[e]||[]).length>0}),i=[].concat(a(n),a(o));return[].concat(a(new Set(i)))},[])};n.slot=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{noBuffer:!1};return Object.assign(s,e)},n.connectSlot=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},c=n.reduce(function(e,n,t){return Object.assign({},e,r({},t,{}))},r({},u,{})),s=n.reduce(function(e,n,t){return Object.assign({},e,r({},t,{}))},{}),h=function(e,n){var t=function(){},r=new Promise(function(e){return t=e});s[e][n]={registered:r,onRegister:t}},d=[],_=[],v=function(e){return d.forEach(function(n){return n(e)})},p=function(e){return _.forEach(function(n){return n(e)})};return n.forEach(function(n,t){n.addRemoteHandlerRegistrationCallback(e,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.DEFAULT_PARAM,n=arguments[1],r=c[t][e]||[];c[t][e]=r.concat(n),1===l(e,c).length&&v(e),s[t][e]||h(String(t),e),s[t][e].onRegister()}),n.addRemoteHandlerUnregistrationCallback(e,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.DEFAULT_PARAM,n=arguments[1],r=(c[t][e]||[]).indexOf(n);r>-1&&c[t][e].splice(r,1),0===l(e,c).length&&p(e),h(String(t),e)})}),Object.assign(function(e,r){var u=2===arguments.length,f=u?r:e,d=u?e:i.DEFAULT_PARAM;if(t.noBuffer||0===n.length){var _=l(d,c);return o.callHandlers(f,_)}n.forEach(function(e,n){s[n][d]||h(String(n),d)});var v=n.reduce(function(e,n,t){return[].concat(a(e),[s[t][d].registered])},[]);return Promise.all(v).then(function(){var e=l(d,c);return o.callHandlers(f,e)})},{on:function(t,r){var a="",o=function(){return new Promise(function(e){return e()})};return"string"==typeof t?(a=t,o=r||o):(a=i.DEFAULT_PARAM,o=t),n.forEach(function(n){return n.registerHandler(e,a,o)}),c[u][a]=(c[u][a]||[]).concat(o),1===l(a,c).length&&v(a),function(){n.forEach(function(n){return n.unregisterHandler(e,a,o)});var t=(c[u][a]||[]).indexOf(o);-1!==t&&c[u][a].splice(t,1),0===l(a,c).length&&p(a)}},lazy:function(e,n){return d.push(e),_.push(n),f(c).forEach(e),function(){f(c).forEach(n);var t=d.indexOf(e);t>-1&&d.splice(t,1);var r=_.indexOf(n);r>-1&&_.splice(r,1)}},config:t,slotName:e})}},function(e,n,t){"use strict";function r(e,n){var t=null;try{t=e(n)}catch(e){return Promise.reject(e)}return t&&t.then?t:Promise.resolve(t)}Object.defineProperty(n,"__esModule",{value:!0}),n.callHandlers=function(e,n){return n&&0!==n.length?1===n.length?r(n[0],e):Promise.all(n.map(function(n){return r(n,e)})):new Promise(function(e){})}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.DEFAULT_PARAM="$_DEFAULT_$"},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();Object.defineProperty(n,"__esModule",{value:!0});var a=5e3,o=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:a;!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this._timeout=n,this._onMessageCallbacks=[],this._onConnectCallbacks=[],this._onDisconnectCallbacks=[],this._onErrorCallbacks=[],this._ready=!1}return r(e,[{key:"onData",value:function(e){-1===this._onMessageCallbacks.indexOf(e)&&this._onMessageCallbacks.push(e)}},{key:"onConnect",value:function(e){this._ready&&e(),this._onConnectCallbacks.push(e)}},{key:"onDisconnect",value:function(e){this._onDisconnectCallbacks.push(e)}},{key:"onError",value:function(e){this._onErrorCallbacks.push(e)}},{key:"_messageReceived",value:function(e){this._onMessageCallbacks.forEach(function(n){return n(e)})}},{key:"_error",value:function(e){this._onErrorCallbacks.forEach(function(n){return n(e)})}},{key:"_connected",value:function(){this._ready=!0,this._onConnectCallbacks.forEach(function(e){return e()})}},{key:"_disconnected",value:function(){this._ready=!1,this._onDisconnectCallbacks.forEach(function(e){return e()})}},{key:"timeout",get:function(){return this._timeout}}]),e}();n.GenericChannel=o},function(e,n,t){e.exports=t(5)},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(0);n.slot=r.slot;var a=t(6);n.combineEvents=a.combineEvents,n.createEventBus=a.createEventBus;var o=t(3);n.GenericChannel=o.GenericChannel;var i=t(8);n.ChunkedChannel=i.ChunkedChannel;var c=t(2);n.DEFAULT_PARAM=c.DEFAULT_PARAM},function(e,n,t){"use strict";function r(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(n,"__esModule",{value:!0});var a=t(0),o=t(7);n.combineEvents=function(e,n,t,a,o,i,c,s,u,l,f,h,d,_,v,p,g,y,b,k,m,O,E,R){var C=Array.from(arguments),A=C.reduce(function(e,n){return[].concat(r(e),r(Object.keys(n)))},[]),w=[].concat(r(new Set(A)));if(A.length>w.length)throw new Error("ts-event-bus: duplicate slots encountered in combineEvents.");return Object.assign.apply(Object,[{}].concat(r(C)))},n.createEventBus=function(e){var n=(e.channels||[]).map(function(e){return new o.Transport(e)});return Object.keys(e.events).reduce(function(t,r){var o=e.events[r].config;return t[r]=a.connectSlot(r,n,o),t},{})}},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),o=0,i=function(e){throw new Error("Should not happen: "+e)},c={TIMED_OUT:"TIMED_OUT",REMOTE_CONNECTION_CLOSED:"REMOTE_CONNECTION_CLOSED",CHANNEL_NOT_READY:"CHANNEL_NOT_READY"},s=function(){function e(n){var t=this;!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this._channel=n,this._localHandlers={},this._localHandlerRegistrations={},this._remoteHandlers={},this._remoteHandlerRegistrationCallbacks={},this._remoteHandlerDeletionCallbacks={},this._pendingRequests={},this._channelReady=!1,this._channel.onData(function(e){switch(e.type){case"request":return t._requestReceived(e);case"response":return t._responseReceived(e);case"handler_registered":return t._registerRemoteHandler(e);case"handler_unregistered":return t._unregisterRemoteHandler(e);case"error":return t._errorReceived(e);default:i(e)}}),this._channel.onConnect(function(){t._channelReady=!0,Object.keys(t._localHandlerRegistrations).forEach(function(e){t._localHandlerRegistrations[e].forEach(function(e){t._channel.send(e)})})}),this._channel.onDisconnect(function(){t._channelReady=!1,t._unregisterAllRemoteHandlers(),t._rejectAllPendingRequests(new Error(""+c.REMOTE_CONNECTION_CLOSED))}),this._channel.onError(function(e){return t._rejectAllPendingRequests(e)})}return r(e,[{key:"_requestReceived",value:function(e){var n=this,t=e.slotName,r=e.data,o=e.id,i=e.param,c=this._localHandlers[t];if(c){var s=c[i];s&&a.callHandlers(r,s).then(function(e){return n._channel.send({type:"response",slotName:t,id:o,data:e,param:i})}).catch(function(e){return n._channel.send({id:o,message:""+e,param:i,slotName:t,stack:e.stack||"",type:"error"})})}}},{key:"_responseReceived",value:function(e){var n=e.slotName,t=e.data,r=e.id,a=e.param,o=this._pendingRequests[n];o&&o[a]&&o[a][r]&&(o[a][r].resolve(t),delete o[a][r])}},{key:"_errorReceived",value:function(e){var n=e.slotName,t=e.id,r=e.message,a=e.stack,o=e.param,i=this._pendingRequests[n];if(i&&i[o]&&i[o][t]){var c=new Error(r+" on "+n+" with param "+o);c.stack=a||c.stack,this._pendingRequests[n][o][t].reject(c),delete this._pendingRequests[n][o][t]}}},{key:"_registerRemoteHandler",value:function(e){var n=this,t=e.slotName,r=e.param,a=this._remoteHandlerRegistrationCallbacks[t];if(a){var i=this._remoteHandlers[t];if(!i||!i[r]){var s=function(e){return new Promise(function(a,i){if(!n._channelReady)return i(new Error(c.CHANNEL_NOT_READY+" on "+t));var s=""+o++;n._pendingRequests[t]=n._pendingRequests[t]||{},n._pendingRequests[t][r]=n._pendingRequests[t][r]||{},n._pendingRequests[t][r][s]={resolve:a,reject:i},n._channel.send({type:"request",id:s,slotName:t,param:r,data:e}),setTimeout(function(){var e=((n._pendingRequests[t]||{})[r]||{})[s];if(e){var a=new Error(c.TIMED_OUT+" on "+t+" with param "+r);e.reject(a),delete n._pendingRequests[t][r][s]}},n._channel.timeout)})};this._remoteHandlers[t]=this._remoteHandlers[t]||{},this._remoteHandlers[t][r]=s,a(r,s)}}}},{key:"_unregisterRemoteHandler",value:function(e){var n=e.slotName,t=e.param,r=this._remoteHandlerDeletionCallbacks[n],a=this._remoteHandlers[n];if(a){var o=a[t];o&&r&&(r(t,o),delete this._remoteHandlers[n][t])}}},{key:"_unregisterAllRemoteHandlers",value:function(){var e=this;Object.keys(this._remoteHandlerDeletionCallbacks).forEach(function(n){var t=e._remoteHandlers[n];t&&Object.keys(t).filter(function(e){return t[e]}).forEach(function(t){return e._unregisterRemoteHandler({slotName:n,param:t})})})}},{key:"_rejectAllPendingRequests",value:function(e){var n=this;Object.keys(this._pendingRequests).forEach(function(t){Object.keys(n._pendingRequests[t]).forEach(function(r){Object.keys(n._pendingRequests[t][r]).forEach(function(a){n._pendingRequests[t][r][a].reject(e)})}),n._pendingRequests[t]={}})}},{key:"addRemoteHandlerRegistrationCallback",value:function(e,n){this._remoteHandlerRegistrationCallbacks[e]||(this._remoteHandlerRegistrationCallbacks[e]=n)}},{key:"addRemoteHandlerUnregistrationCallback",value:function(e,n){this._remoteHandlerDeletionCallbacks[e]||(this._remoteHandlerDeletionCallbacks[e]=n)}},{key:"registerHandler",value:function(e,n,t){if(this._localHandlers[e]=this._localHandlers[e]||{},this._localHandlers[e][n]=this._localHandlers[e][n]||[],this._localHandlers[e][n].push(t),1===this._localHandlers[e][n].length){var r={type:"handler_registered",param:n,slotName:e};this._localHandlerRegistrations[n]=this._localHandlerRegistrations[n]||[],this._localHandlerRegistrations[n].push(r),this._channelReady&&this._channel.send(r)}}},{key:"unregisterHandler",value:function(e,n,t){var r=this._localHandlers[e];if(r&&r[n]){var a=r[n].indexOf(t);if(a>-1&&(r[n].splice(a,1),0===r[n].length)){var o={type:"handler_unregistered",param:n,slotName:e};this._channelReady&&this._channel.send(o)}}}}]),e}();n.Transport=s},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),a=function e(n,t,r){null===n&&(n=Function.prototype);var a=Object.getOwnPropertyDescriptor(n,t);if(void 0===a){var o=Object.getPrototypeOf(n);return null===o?void 0:e(o,t,r)}if("value"in a)return a.value;var i=a.get;return void 0!==i?i.call(r):void 0};Object.defineProperty(n,"__esModule",{value:!0});var o=t(3),i=t(9),c=function(){return[].concat(function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}(Array(30))).map(function(){return Math.random().toString(36)[3]}).join("")},s=function(e){for(var n=new Uint16Array(e.length),t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return n},u=function(e,n){if(-1===n)return String.fromCharCode.apply(null,e);for(var t="",r=0;r<e.length;r+=n)r+n>e.length?t+=String.fromCharCode.apply(null,e.subarray(r)):t+=String.fromCharCode.apply(null,e.subarray(r,r+n));return t},l=function(e){if(!e.chunkId)throw new Error("ChunkedMessage did not have a chunkId: "+JSON.stringify(e))},f=function(e){function n(e){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var t=function(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e.timeout));return t._buffer={},t._chunkSize=e.chunkSize,t._sender=e.sender,t._maxStringAlloc=e.maxStringAlloc||-1,t}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}(n,o.GenericChannel),r(n,[{key:"send",value:function(e){var n=this,t=JSON.stringify(e);if(t.length<=this._chunkSize)this._sender(e);else{var r=s(t),a=c();this._sender({type:"chunk_start",chunkId:a,size:t.length});!function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,o=r.slice(t,t+n._chunkSize);o.length&&(n._sender({type:"chunk_data",chunkId:a,data:Array.from(o)}),e(t+n._chunkSize))}(),this._sender({type:"chunk_end",chunkId:a})}}},{key:"_messageReceived",value:function(e){switch(e.type){case"chunk_start":this._receiveNewChunk(e);break;case"chunk_data":this._receiveChunkData(e);break;case"chunk_end":var t=this._mergeChunks(e);a(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_messageReceived",this).call(this,t);break;default:a(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_messageReceived",this).call(this,e)}}},{key:"_receiveNewChunk",value:function(e){if(l(e),this._buffer[e.chunkId])throw new Error("There was already an entry in the buffer for chunkId "+e.chunkId);this._buffer[e.chunkId]={id:e.chunkId,chunks:[],size:e.size}}},{key:"_receiveChunkData",value:function(e){if(l(e),!this._buffer[e.chunkId])throw new Error("ChunkId "+e.chunkId+" was not found in the buffer");this._buffer[e.chunkId].chunks.push(e.data)}},{key:"_mergeChunks",value:function(e){if(l(e),!this._buffer[e.chunkId])throw new Error("ChunkId "+e.chunkId+" was not found in the buffer");var n=this._buffer[e.chunkId].chunks.reduce(function(e,n,t){return n.forEach(function(n,t){return e.uintArray[e.currentIx+t]=n}),e.currentIx+=n.length,e},{uintArray:new Uint16Array(this._buffer[e.chunkId].size),currentIx:0}),t=void 0,r=u(n.uintArray,this._maxStringAlloc);try{t=JSON.parse(r)}catch(e){throw new Error("Not a valid JSON string: "+r)}if(!i.isTransportMessage(t))throw new Error("Not a transport message: "+JSON.stringify(t));return t}}]),n}();n.ChunkedChannel=f},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.isTransportMessage=function(e){switch(e.type){case"request":case"response":case"error":case"handler_unregistered":case"handler_registered":return!0;default:return!1}}}]); | ||
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var a in e)t.d(r,a,function(n){return e[n]}.bind(null,a));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=4)}([function(e,n,t){"use strict";function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(n,"__esModule",{value:!0});var o=t(1),i=t(2),c=function(){throw new Error("Slot not connected")};n.defaultSlotConfig={noBuffer:!1};var u=function(e){return Object.assign((function(){return c()}),{config:e,lazy:function(){return c},on:function(){return c},slotName:"Not connected"})},s=function(e,n){return Object.keys(n).reduce((function(t,r){return t.concat(n[r][e]||[])}),[])},l=function(e){return Object.keys(e).reduce((function(n,t){var r=e[t],o=Object.keys(r).filter((function(e){return(r[e]||[]).length>0})),i=[].concat(a(n),a(o));return[].concat(a(new Set(i)))}),[])};n.slot=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.defaultSlotConfig;return u(e)},n.connectSlot=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},c=n.reduce((function(e,n,t){return Object.assign({},e,r({},t,{}))}),r({},"LOCAL_TRANSPORT",{})),u=n.reduce((function(e,n,t){return Object.assign({},e,r({},t,{}))}),{}),f=function(e,n){var t=function(){},r=new Promise((function(e){return t=e}));u[e][n]={registered:r,onRegister:t}},h=[],d=[],_=function(e){return h.forEach((function(n){return n(e)}))},v=function(e){return d.forEach((function(n){return n(e)}))};function p(e,r){var l=2===arguments.length,h=l?r:e,d=l?e:i.DEFAULT_PARAM;if(t.noBuffer||0===n.length){var _=s(d,c);return o.callHandlers(h,_)}n.forEach((function(e,n){u[n][d]||f(String(n),d)}));var v=n.reduce((function(e,n,t){return[].concat(a(e),[u[t][d].registered])}),[]);return Promise.all(v).then((function(){var e=s(d,c);return o.callHandlers(h,e)}))}function g(e,n){return h.push(e),d.push(n),l(c).forEach(e),function(){l(c).forEach(n);var t=h.indexOf(e);t>-1&&h.splice(t,1);var r=d.indexOf(n);r>-1&&d.splice(r,1)}}function y(t,r){var a="",o=function(){return new Promise((function(e){return e()}))};return"string"==typeof t?(a=t,o=r||o):(a=i.DEFAULT_PARAM,o=t),n.forEach((function(n){return n.registerHandler(e,a,o)})),c.LOCAL_TRANSPORT[a]=(c.LOCAL_TRANSPORT[a]||[]).concat(o),1===s(a,c).length&&_(a),function(){n.forEach((function(n){return n.unregisterHandler(e,a,o)}));var t=(c.LOCAL_TRANSPORT[a]||[]).indexOf(o);-1!==t&&c.LOCAL_TRANSPORT[a].splice(t,1),0===s(a,c).length&&v(a)}}return n.forEach((function(n,t){n.addRemoteHandlerRegistrationCallback(e,(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.DEFAULT_PARAM,n=arguments[1],r=c[t][e]||[];c[t][e]=r.concat(n),1===s(e,c).length&&_(e),u[t][e]||f(String(t),e),u[t][e].onRegister()})),n.addRemoteHandlerUnregistrationCallback(e,(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.DEFAULT_PARAM,n=arguments[1],r=c[t][e]||[],a=r.indexOf(n);a>-1&&c[t][e].splice(a,1),0===s(e,c).length&&v(e),f(String(t),e)}))})),Object.assign(p,{on:y,lazy:g,config:t,slotName:e})}},function(e,n,t){"use strict";function r(e,n){var t=null;try{t=e(n)}catch(e){return Promise.reject(e)}return t&&t.then?t:Promise.resolve(t)}Object.defineProperty(n,"__esModule",{value:!0}),n.callHandlers=function(e,n){return n&&0!==n.length?1===n.length?r(n[0],e):Promise.all(n.map((function(n){return r(n,e)}))):new Promise((function(e){}))}},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.DEFAULT_PARAM="$_DEFAULT_$"},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();function a(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;a(this,e),this._timeout=n,this._onMessageCallbacks=[],this._onConnectCallbacks=[],this._onDisconnectCallbacks=[],this._onErrorCallbacks=[],this._ready=!1}return r(e,[{key:"onData",value:function(e){-1===this._onMessageCallbacks.indexOf(e)&&this._onMessageCallbacks.push(e)}},{key:"onConnect",value:function(e){this._ready&&e(),this._onConnectCallbacks.push(e)}},{key:"onDisconnect",value:function(e){this._onDisconnectCallbacks.push(e)}},{key:"onError",value:function(e){this._onErrorCallbacks.push(e)}},{key:"_messageReceived",value:function(e){this._onMessageCallbacks.forEach((function(n){return n(e)}))}},{key:"_error",value:function(e){this._onErrorCallbacks.forEach((function(n){return n(e)}))}},{key:"_connected",value:function(){this._ready=!0,this._onConnectCallbacks.forEach((function(e){return e()}))}},{key:"_disconnected",value:function(){this._ready=!1,this._onDisconnectCallbacks.forEach((function(e){return e()}))}},{key:"timeout",get:function(){return this._timeout}}]),e}();n.GenericChannel=o},function(e,n,t){e.exports=t(5)},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t(0);n.slot=r.slot;var a=t(6);n.combineEvents=a.combineEvents,n.createEventBus=a.createEventBus;var o=t(3);n.GenericChannel=o.GenericChannel;var i=t(8);n.ChunkedChannel=i.ChunkedChannel;var c=t(2);n.DEFAULT_PARAM=c.DEFAULT_PARAM},function(e,n,t){"use strict";function r(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}Object.defineProperty(n,"__esModule",{value:!0});var a=t(0),o=t(7);n.combineEvents=function(e,n,t,a,o,i,c,u,s,l,f,h,d,_,v,p,g,y,b,k,m,R,O,C){var E=Array.from(arguments),A=E.reduce((function(e,n){return[].concat(r(e),r(Object.keys(n)))}),[]),w=[].concat(r(new Set(A)));if(A.length>w.length)throw new Error("ts-event-bus: duplicate slots encountered in combineEvents.");return Object.assign.apply(Object,[{}].concat(r(E)))},n.createEventBus=function(e){var n=(e.channels||[]).map((function(e){return new o.Transport(e)}));return Object.keys(e.events).reduce((function(t,r){var o=e.events[r].config;return t[r]=a.connectSlot(r,n,o),t}),{})}},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}();Object.defineProperty(n,"__esModule",{value:!0});var a=t(1),o=0,i="TIMED_OUT",c="REMOTE_CONNECTION_CLOSED",u="CHANNEL_NOT_READY",s=function(){function e(n){var t=this;!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this._channel=n,this._localHandlers={},this._localHandlerRegistrations={},this._remoteHandlers={},this._remoteHandlerRegistrationCallbacks={},this._remoteHandlerDeletionCallbacks={},this._pendingRequests={},this._channelReady=!1,this._channel.onData((function(e){switch(e.type){case"request":return t._requestReceived(e);case"response":return t._responseReceived(e);case"handler_registered":return t._registerRemoteHandler(e);case"handler_unregistered":return t._unregisterRemoteHandler(e);case"error":return t._errorReceived(e);default:!function(e){throw new Error("Should not happen: "+e)}(e)}})),this._channel.onConnect((function(){t._channelReady=!0,Object.keys(t._localHandlerRegistrations).forEach((function(e){t._localHandlerRegistrations[e].forEach((function(e){t._channel.send(e)}))}))})),this._channel.onDisconnect((function(){t._channelReady=!1,t._unregisterAllRemoteHandlers(),t._rejectAllPendingRequests(new Error(""+c))})),this._channel.onError((function(e){return t._rejectAllPendingRequests(e)}))}return r(e,[{key:"_requestReceived",value:function(e){var n=this,t=e.slotName,r=e.data,o=e.id,i=e.param,c=this._localHandlers[t];if(c){var u=c[i];u&&a.callHandlers(r,u).then((function(e){return n._channel.send({type:"response",slotName:t,id:o,data:e,param:i})})).catch((function(e){return n._channel.send({id:o,message:""+e,param:i,slotName:t,stack:e.stack||"",type:"error"})}))}}},{key:"_responseReceived",value:function(e){var n=e.slotName,t=e.data,r=e.id,a=e.param,o=this._pendingRequests[n];o&&o[a]&&o[a][r]&&(o[a][r].resolve(t),delete o[a][r])}},{key:"_errorReceived",value:function(e){var n=e.slotName,t=e.id,r=e.message,a=e.stack,o=e.param,i=this._pendingRequests[n];if(i&&i[o]&&i[o][t]){var c=new Error(r+" on "+n+" with param "+o);c.stack=a||c.stack,this._pendingRequests[n][o][t].reject(c),delete this._pendingRequests[n][o][t]}}},{key:"_registerRemoteHandler",value:function(e){var n=this,t=e.slotName,r=e.param,a=this._remoteHandlerRegistrationCallbacks[t];if(a){var c=this._remoteHandlers[t];if(!c||!c[r]){var s=function(e){return new Promise((function(a,c){if(!n._channelReady)return c(new Error(u+" on "+t));var s=""+o++;n._pendingRequests[t]=n._pendingRequests[t]||{},n._pendingRequests[t][r]=n._pendingRequests[t][r]||{},n._pendingRequests[t][r][s]={resolve:a,reject:c},n._channel.send({type:"request",id:s,slotName:t,param:r,data:e}),setTimeout((function(){var e=((n._pendingRequests[t]||{})[r]||{})[s];if(e){var a=new Error(i+" on "+t+" with param "+r);e.reject(a),delete n._pendingRequests[t][r][s]}}),n._channel.timeout)}))};this._remoteHandlers[t]=this._remoteHandlers[t]||{},this._remoteHandlers[t][r]=s,a(r,s)}}}},{key:"_unregisterRemoteHandler",value:function(e){var n=e.slotName,t=e.param,r=this._remoteHandlerDeletionCallbacks[n],a=this._remoteHandlers[n];if(a){var o=a[t];o&&r&&(r(t,o),delete this._remoteHandlers[n][t])}}},{key:"_unregisterAllRemoteHandlers",value:function(){var e=this;Object.keys(this._remoteHandlerDeletionCallbacks).forEach((function(n){var t=e._remoteHandlers[n];t&&Object.keys(t).filter((function(e){return t[e]})).forEach((function(t){return e._unregisterRemoteHandler({slotName:n,param:t})}))}))}},{key:"_rejectAllPendingRequests",value:function(e){var n=this;Object.keys(this._pendingRequests).forEach((function(t){Object.keys(n._pendingRequests[t]).forEach((function(r){Object.keys(n._pendingRequests[t][r]).forEach((function(a){n._pendingRequests[t][r][a].reject(e)}))})),n._pendingRequests[t]={}}))}},{key:"addRemoteHandlerRegistrationCallback",value:function(e,n){this._remoteHandlerRegistrationCallbacks[e]||(this._remoteHandlerRegistrationCallbacks[e]=n)}},{key:"addRemoteHandlerUnregistrationCallback",value:function(e,n){this._remoteHandlerDeletionCallbacks[e]||(this._remoteHandlerDeletionCallbacks[e]=n)}},{key:"registerHandler",value:function(e,n,t){if(this._localHandlers[e]=this._localHandlers[e]||{},this._localHandlers[e][n]=this._localHandlers[e][n]||[],this._localHandlers[e][n].push(t),1===this._localHandlers[e][n].length){var r={type:"handler_registered",param:n,slotName:e};this._localHandlerRegistrations[n]=this._localHandlerRegistrations[n]||[],this._localHandlerRegistrations[n].push(r),this._channelReady&&this._channel.send(r)}}},{key:"unregisterHandler",value:function(e,n,t){var r=this._localHandlers[e];if(r&&r[n]){var a=r[n].indexOf(t);if(a>-1&&(r[n].splice(a,1),0===r[n].length)){var o={type:"handler_unregistered",param:n,slotName:e};this._channelReady&&this._channel.send(o)}}}}]),e}();n.Transport=s},function(e,n,t){"use strict";var r=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),a=function e(n,t,r){null===n&&(n=Function.prototype);var a=Object.getOwnPropertyDescriptor(n,t);if(void 0===a){var o=Object.getPrototypeOf(n);return null===o?void 0:e(o,t,r)}if("value"in a)return a.value;var i=a.get;return void 0!==i?i.call(r):void 0};Object.defineProperty(n,"__esModule",{value:!0});var o=t(3),i=t(9),c=function(){return[].concat(function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)}(Array(30))).map((function(){return Math.random().toString(36)[3]})).join("")},u=function(e){for(var n=new Uint16Array(e.length),t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return n},s=function(e,n){if(-1===n)return String.fromCharCode.apply(null,e);for(var t="",r=0;r<e.length;r+=n)r+n>e.length?t+=String.fromCharCode.apply(null,e.subarray(r)):t+=String.fromCharCode.apply(null,e.subarray(r,r+n));return t},l=function(e){if(!e.chunkId)throw new Error("ChunkedMessage did not have a chunkId: "+JSON.stringify(e))},f=function(e){function n(e){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,n);var t=function(e,n){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!n||"object"!=typeof n&&"function"!=typeof n?e:n}(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e.timeout));return t._buffer={},t._chunkSize=e.chunkSize,t._sender=e.sender,t._maxStringAlloc=e.maxStringAlloc||-1,t}return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function, not "+typeof n);e.prototype=Object.create(n&&n.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),n&&(Object.setPrototypeOf?Object.setPrototypeOf(e,n):e.__proto__=n)}(n,e),r(n,[{key:"send",value:function(e){var n=this,t=JSON.stringify(e);if(t.length<=this._chunkSize)this._sender(e);else{var r=u(t),a=c();this._sender({type:"chunk_start",chunkId:a,size:t.length});!function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,o=r.slice(t,t+n._chunkSize);o.length&&(n._sender({type:"chunk_data",chunkId:a,data:Array.from(o)}),e(t+n._chunkSize))}(),this._sender({type:"chunk_end",chunkId:a})}}},{key:"_messageReceived",value:function(e){switch(e.type){case"chunk_start":this._receiveNewChunk(e);break;case"chunk_data":this._receiveChunkData(e);break;case"chunk_end":var t=this._mergeChunks(e);a(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_messageReceived",this).call(this,t);break;default:a(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_messageReceived",this).call(this,e)}}},{key:"_receiveNewChunk",value:function(e){if(l(e),this._buffer[e.chunkId])throw new Error("There was already an entry in the buffer for chunkId "+e.chunkId);this._buffer[e.chunkId]={id:e.chunkId,chunks:[],size:e.size}}},{key:"_receiveChunkData",value:function(e){if(l(e),!this._buffer[e.chunkId])throw new Error("ChunkId "+e.chunkId+" was not found in the buffer");this._buffer[e.chunkId].chunks.push(e.data)}},{key:"_mergeChunks",value:function(e){if(l(e),!this._buffer[e.chunkId])throw new Error("ChunkId "+e.chunkId+" was not found in the buffer");var n=this._buffer[e.chunkId].chunks.reduce((function(e,n,t){return n.forEach((function(n,t){return e.uintArray[e.currentIx+t]=n})),e.currentIx+=n.length,e}),{uintArray:new Uint16Array(this._buffer[e.chunkId].size),currentIx:0}),t=void 0,r=s(n.uintArray,this._maxStringAlloc);try{t=JSON.parse(r)}catch(e){throw new Error("Not a valid JSON string: "+r)}if(!i.isTransportMessage(t))throw new Error("Not a transport message: "+JSON.stringify(t));return t}}]),n}(o.GenericChannel);n.ChunkedChannel=f},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.isTransportMessage=function(e){switch(e.type){case"request":case"response":case"error":case"handler_unregistered":case"handler_registered":return!0;default:return!1}}}]); |
import { Transport } from './Transport'; | ||
import { Handler } from './Handler'; | ||
export declare type LazyCallback = (param: string) => void; | ||
export declare type Unsubscribe = () => void; | ||
interface SlotConfig { | ||
noBuffer?: boolean; | ||
} | ||
export declare const defaultSlotConfig: { | ||
noBuffer: boolean; | ||
}; | ||
export declare type LazyCallback = (param: string) => void; | ||
export declare type Unsubscribe = () => void; | ||
export interface Slot<RequestData = null, ResponseData = void> { | ||
@@ -9,0 +12,0 @@ (param: string, requestData: RequestData): Promise<ResponseData>; |
{ | ||
"name": "ts-event-bus", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Distributed messaging in Typescript", | ||
@@ -73,5 +73,7 @@ "main": "build/index.js", | ||
"mixin-deep": ">=1.3.2 <2.0.0 || >=2.0.1", | ||
"set-value": ">=2.0.1 <3.0.0 || >=3.0.1" | ||
"set-value": ">=2.0.1 <3.0.0 || >=3.0.1", | ||
"minimist": ">=0.2.1 <1.0.0 || >=1.2.3", | ||
"just-extend": ">=4.0.0" | ||
}, | ||
"license": "Apache-2.0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
44544
180
0