Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@scalecube/addressable

Package Overview
Dependencies
Maintainers
7
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scalecube/addressable - npm Package Compare versions

Comparing version 0.2.10-snapshot.feature-cluster-refactor.1598302712 to 0.2.10-snapshot.feature-remote-registry-size-limit.1612487477

9

dist/api.d.ts

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

export declare type Listener = (msg: any, port: MessagePort) => void;
export declare type listen = (addr: string, fn: Listener) => void;
declare type ListenerFn = (msg: any, port: MessagePort) => void;
export interface Listener extends ListenerFn {
cleanFns?: Array<() => void>;
}
declare type remove = () => void;
export declare type listen = (addr: string, fn: Listener) => remove;
export declare type connect = (addr: string, timeout?: number) => Promise<MessagePort>;
export {};

@@ -6,2 +6,3 @@ export declare const DEBUG = false;

registerAddress: string;
unregisterAddress: string;
connect: string;

@@ -8,0 +9,0 @@ incomingServerConnection: string;

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

var sc=function(e){"use strict";var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)},n=function(){function e(){this.values={},this.subscribers=[]}return e.prototype.next=function(e){this.values=t({},e),this.notify()},e.prototype.subscribe=function(e){var n=this;return this.subscribers.push(e),e(t({},this.values)),function(){n.subscribers=n.subscribers.filter((function(t){return t!==e}))}},e.prototype.notify=function(){for(var e=0,n=this.subscribers;e<n.length;e++){(0,n[e])(t({},this.values))}},e}();var r,s,o=function(){function e(){this.id=Math.random().toString()+"-"+Math.random().toString()+"-"+Math.random().toString()+"-"+Math.random().toString(),this.peers={},this.peers$=new n}return e.prototype.subscribe=function(e){return function(e,t){return{subscribe:function(n){return t.subscribe((function(t){n(e(t))}))}}}((function(e){return{id:e.key,port:e.value}}),(t=this.peers$,{subscribe:function(e){var n={},r=function(t){return e(t)};return t.subscribe((function(e){for(var t in e)n[t]&&n[t]===e[t]||r({key:t,value:e[t]});for(var t in n)e[t]||r({key:t,value:void 0});n=e}))}})).subscribe(e);var t},e.prototype.get=function(){return t({},this.peers)},e.prototype.add=function(e,t){this.peers[e]=t,this.peers$.next(this.peers)},e}(),a="addChannel",i="channelInit",d="registerAddress",c="connect",u="incomingServerConnection",p="incomingClientConnection";function f(){var e=new o,r={},s=new n;function f(o){var a,i;return o.data.type===c&&o.data.sourceNodeId&&o.data.remoteAddress&&(a=s,i=e,{subscribe:function(e){var t=new n,r=a.subscribe((function(e){return t.next(e)})),s=i.subscribe((function(e){return t.next(e)})),o=t.subscribe(e);return function(){r(),s(),o()}}}).subscribe((function(){var n=e.get();if(n[o.data.sourceNodeId]&&r[o.data.remoteAddress]){o.data.remoteAddress,o.data.sourceNodeId;var s=new MessageChannel,a={remoteAddress:o.data.remoteAddress,connectionId:o.data.connectionId,sourceNodeId:o.data.sourceNodeId};n[o.data.sourceNodeId].postMessage(t(t({},a),{type:p}),[s.port2]),n[r[o.data.remoteAddress]].postMessage(t(t({},a),{type:u}),[s.port1])}})),!1}function v(e){e&&e.data&&(f(e)||function(e){e.data.type===d&&e.data.address&&e.data.peerId&&(e.data.address,r[e.data.address]=e.data.peerId,s.next({address:e.data.address,peerId:e.data.peerId}))}(e))}var b=e.subscribe((function(e){e.port.addEventListener("message",v)}));return{channelHandler:function(t){t.data.type===a&&(e.add(t.data.nodeId,t.ports[0]),t.ports[0].start(),t.ports[0].postMessage({type:i,nodeId:t.data.nodeId}))},shutdown:function(){b();var t=e.get();for(var n in t)t[n].removeEventListener("message",v)}}}"undefined"!=typeof window&&(r=window),"undefined"!=typeof WorkerGlobalScope&&(s=self);var v=function(e,n){var r,s,p=f(),v=(r=new o,s={},r.subscribe((function(e){e.port.addEventListener("message",(function(e){e&&e.data&&e.data.type===u&&e.data.remoteAddress&&s[e.data.remoteAddress]&&e.ports[0]&&(e.ports[0].addEventListener("message",(function(t){e.data.remoteAddress,s[e.data.remoteAddress](t,e.ports[0])})),e.ports[0].start())}))})),{createChannel:function(e,t){void 0===t&&(t=5e3);var n=Date.now()+t;return new Promise((function(t,s){var o=function(){var d=new MessageChannel,c=setTimeout((function(){d.port1.close(),d.port2.close(),Date.now()<n?o():s()}),100);e({type:a,nodeId:r.id},[d.port1]),d.port2.addEventListener("message",(function(e){e.data.type===i&&(r.add(e.data.nodeId,d.port2),clearTimeout(c),t())})),d.port2.start()};o()}))},listen:function(e,t){s[e]=t,r.subscribe((function(t){t.port.postMessage({type:d,peerId:r.id,address:e})}))},connect:function(e,n){return void 0===n&&(n=5e3),new Promise((function(s,o){var a={remoteAddress:e,sourceNodeId:r.id,connectionId:Date.now()+"-"+Math.random()},i=function(){var e=r.get();for(var t in e)e[t].removeEventListener("message",u)},d=setTimeout((function(){p(),i(),o("connection timeout")}),n),u=function(e){e&&e.data&&e.data.connectionId===a.connectionId&&e.ports[0]&&(i(),clearTimeout(d),e.ports[0].start(),s(e.ports[0]))},p=r.subscribe((function(e){e.id;var n=e.port;n.addEventListener("message",u),n.postMessage(t(t({},a),{type:c}),[])}))}))}});if("undefined"!=typeof Worker){var b=Worker;Worker=function(e,t){void 0===t&&(t={});var n=new b(e,t);return n.addEventListener("message",p.channelHandler),n}}if(void 0!==n){var l=new MessageChannel;l.port1.start(),l.port2.start(),n.addEventListener("message",p.channelHandler),l.port2.addEventListener("message",p.channelHandler),v.createChannel(l.port1.postMessage.bind(l.port1)),v.createChannel(n.postMessage.bind(n))}else e&&e.top&&e.top!==e.self?(v.createChannel((function(t,n){return e.postMessage.bind(e)(t,"*",n)})),v.createChannel((function(t,n){return e.top.postMessage.bind(e.top)(t,"*",n)})),e.addEventListener("message",p.channelHandler)):(v.createChannel((function(t,n){return e.postMessage(t,"*",n)})),e.addEventListener("message",p.channelHandler));return v}(r,s),b=v.connect,l=v.listen;return e.connect=b,e.listen=l,e}({});
var sc=function(e){"use strict";var t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var s in t=arguments[n])Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e}).apply(this,arguments)},n=function(){function e(){this.values={},this.subscribers=[]}return e.prototype.next=function(e){this.values=t({},e),this.notify()},e.prototype.subscribe=function(e){var n=this;return this.subscribers.push(e),e(t({},this.values)),function(){n.subscribers=n.subscribers.filter((function(t){return t!==e}))}},e.prototype.notify=function(){for(var e=0,n=this.subscribers;e<n.length;e++){(0,n[e])(t({},this.values))}},e}();var r,s,a=function(){function e(){this.id=Math.random().toString()+"-"+Math.random().toString()+"-"+Math.random().toString()+"-"+Math.random().toString(),this.peers={},this.peers$=new n}return e.prototype.subscribe=function(e){return function(e,t){return{subscribe:function(n){return t.subscribe((function(t){n(e(t))}))}}}((function(e){return{id:e.key,port:e.value}}),(t=this.peers$,{subscribe:function(e){var n={},r=function(t){return e(t)};return t.subscribe((function(e){for(var t in e)n[t]&&n[t]===e[t]||r({key:t,value:e[t]});for(var t in n)e[t]||r({key:t,value:void 0});n=e}))}})).subscribe(e);var t},e.prototype.get=function(){return t({},this.peers)},e.prototype.add=function(e,t){this.peers[e]=t,this.peers$.next(this.peers)},e}(),o="addChannel",d="channelInit",i="registerAddress",c="unregisterAddress",u="connect",p="incomingServerConnection",f="incomingClientConnection";function v(){var e=new a,r={},s=new n;function v(a){return!(a.data.type!==u||!a.data.sourceNodeId||!a.data.remoteAddress)&&((o=s,d=e,{subscribe:function(e){var t=new n,r=o.subscribe((function(e){return t.next(e)})),s=d.subscribe((function(e){return t.next(e)})),a=t.subscribe(e);return function(){r(),s(),a()}}}).subscribe((function(){var n=e.get();if(n[a.data.sourceNodeId]&&r[a.data.remoteAddress]){a.data.remoteAddress,a.data.sourceNodeId;var s=new MessageChannel,o={remoteAddress:a.data.remoteAddress,connectionId:a.data.connectionId,sourceNodeId:a.data.sourceNodeId};n[a.data.sourceNodeId].postMessage(t(t({},o),{type:f}),[s.port2]),n[r[a.data.remoteAddress]].postMessage(t(t({},o),{type:p}),[s.port1])}})),!0);var o,d}function l(e){e&&e.data&&(v(e)||function(e){return!(e.data.type!==i||!e.data.address||!e.data.peerId)&&(e.data.address,r[e.data.address]=e.data.peerId,s.next({address:e.data.address,peerId:e.data.peerId}),!0)}(e)||function(e){!(e.data.type!==c||!e.data.address||!e.data.peerId)&&(e.data.address,delete r[e.data.address])}(e))}var h=e.subscribe((function(e){e.port.addEventListener("message",l)}));return{channelHandler:function(t){t.data.type===o&&(e.add(t.data.nodeId,t.ports[0]),t.ports[0].start(),t.ports[0].postMessage({type:d,nodeId:t.data.nodeId}))},shutdown:function(){h();var t=e.get();for(var n in t)t[n].removeEventListener("message",l)}}}"undefined"!=typeof window&&(r=window),"undefined"!=typeof WorkerGlobalScope&&(s=self);var l=function(e,n){var r,s,f=v(),l=(r=new a,s={},r.subscribe((function(e){e.port.addEventListener("message",(function(e){if(e&&e.data&&e.data.type===p&&e.data.remoteAddress&&s[e.data.remoteAddress]&&e.ports[0]){var t=function(t){e.data.remoteAddress,s[e.data.remoteAddress](t,e.ports[0])};e.ports[0].addEventListener("message",t),Array.isArray(s[e.data.remoteAddress].cleanFns)&&s[e.data.remoteAddress].cleanFns.push((function(){e.ports[0].removeEventListener("message",t),e.ports[0].close()})),e.ports[0].start()}}))})),{createChannel:function(e,t){void 0===t&&(t=5e3);var n=Date.now()+t;return new Promise((function(t,s){var a=function(){var i=new MessageChannel,c=setTimeout((function(){i.port1.close(),i.port2.close(),Date.now()<n?a():s()}),100);e({type:o,nodeId:r.id},[i.port1]),i.port2.addEventListener("message",(function(e){e.data.type===d&&(r.add(e.data.nodeId,i.port2),clearTimeout(c),t())})),i.port2.start()};a()}))},listen:function(e,t){s[e]=t,s[e].cleanFns=[];var n=r.subscribe((function(t){t.port.postMessage({type:i,peerId:r.id,address:e})}));return function(){n();for(var t=0,a=s[e].cleanFns||[];t<a.length;t++)(0,a[t])();delete s[e];var o=r.get();for(var d in o)o[d].postMessage({type:c,peerId:r.id,address:e})}},connect:function(e,n){return void 0===n&&(n=5e3),new Promise((function(s,a){var o={remoteAddress:e,sourceNodeId:r.id,connectionId:Date.now()+"-"+Math.random()},d=function(){var e=r.get();for(var t in e)e[t].removeEventListener("message",c)},i=setTimeout((function(){p(),d(),a("connection timeout")}),n),c=function(e){e&&e.data&&e.data.connectionId===o.connectionId&&e.ports[0]&&(d(),clearTimeout(i),e.ports[0].start(),s(e.ports[0]))},p=r.subscribe((function(e){e.id;var n=e.port;n.addEventListener("message",c),n.postMessage(t(t({},o),{type:u}),[])}))}))}});if("undefined"!=typeof Worker){var h=Worker;Worker=function(e,t){void 0===t&&(t={});var n=new h(e,t);return n.addEventListener("message",f.channelHandler),n}}if(void 0!==n){var b=new MessageChannel;b.port1.start(),b.port2.start(),n.addEventListener("message",f.channelHandler),b.port2.addEventListener("message",f.channelHandler),l.createChannel(b.port1.postMessage.bind(b.port1)).catch((function(){})),l.createChannel(n.postMessage.bind(n)).catch((function(){}))}else e&&e.top&&e.top!==e.self?(l.createChannel((function(t,n){return e.postMessage.bind(e)(t,"*",n)})).catch((function(){})),l.createChannel((function(t,n){return e.top.postMessage.bind(e.top)(t,"*",n)})).catch((function(){})),e.addEventListener("message",f.channelHandler)):(l.createChannel((function(t,n){return e.postMessage(t,"*",n)})).catch((function(){})),e.addEventListener("message",f.channelHandler));return l}(r,s),h=l.connect,b=l.listen;return e.connect=h,e.listen=b,e}({});

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

export declare type Listener = (msg: any, port: MessagePort) => void;
export declare type listen = (addr: string, fn: Listener) => void;
declare type ListenerFn = (msg: any, port: MessagePort) => void;
export interface Listener extends ListenerFn {
cleanFns?: Array<() => void>;
}
declare type remove = () => void;
export declare type listen = (addr: string, fn: Listener) => remove;
export declare type connect = (addr: string, timeout?: number) => Promise<MessagePort>;
export {};

@@ -25,9 +25,13 @@ import { createConnectionServer } from './ConnectionServer';

localChannel.port2.addEventListener('message', server.channelHandler);
client.createChannel(localChannel.port1.postMessage.bind(localChannel.port1));
client.createChannel(worker.postMessage.bind(worker));
client.createChannel(localChannel.port1.postMessage.bind(localChannel.port1)).catch(function () { });
client.createChannel(worker.postMessage.bind(worker)).catch(function () { });
// iframe
}
else if (window && window.top && window.top !== window.self) {
client.createChannel(function (msg, port) { return window.postMessage.bind(window)(msg, '*', port); });
client.createChannel(function (msg, port) { return window.top.postMessage.bind(window.top)(msg, '*', port); });
client
.createChannel(function (msg, port) { return window.postMessage.bind(window)(msg, '*', port); })
.catch(function () { });
client
.createChannel(function (msg, port) { return window.top.postMessage.bind(window.top)(msg, '*', port); })
.catch(function () { });
window.addEventListener('message', server.channelHandler);

@@ -37,3 +41,3 @@ }

else {
client.createChannel(function (msg, port) { return window.postMessage(msg, '*', port); });
client.createChannel(function (msg, port) { return window.postMessage(msg, '*', port); }).catch(function () { });
window.addEventListener('message', server.channelHandler);

@@ -40,0 +44,0 @@ }

@@ -42,6 +42,15 @@ var __assign = (this && this.__assign) || function () {

debug('incoming server connection');
e.ports[0].addEventListener('message', function (msg) {
var l_1 = function (msg) {
debug('invoke', e.data.remoteAddress);
listeners[e.data.remoteAddress](msg, e.ports[0]);
});
};
e.ports[0].addEventListener('message', l_1);
var clean = function () {
e.ports[0].removeEventListener('message', l_1);
e.ports[0].close();
};
if (Array.isArray(listeners[e.data.remoteAddress].cleanFns)) {
// @ts-ignore
listeners[e.data.remoteAddress].cleanFns.push(clean);
}
e.ports[0].start();

@@ -88,6 +97,19 @@ }

listeners[addr] = fn;
peer.subscribe(function (_a) {
listeners[addr].cleanFns = [];
var sub = peer.subscribe(function (_a) {
var port = _a.port;
port.postMessage({ type: EVENT.registerAddress, peerId: peer.id, address: addr });
});
return function () {
sub();
for (var _i = 0, _a = listeners[addr].cleanFns || []; _i < _a.length; _i++) {
var clean = _a[_i];
clean();
}
delete listeners[addr];
var peers = peer.get();
for (var p in peers) {
peers[p].postMessage({ type: EVENT.unregisterAddress, peerId: peer.id, address: addr });
}
};
},

@@ -94,0 +116,0 @@ connect: function (addr, to) {

@@ -35,2 +35,10 @@ var __assign = (this && this.__assign) || function () {

} : function () { };
function handleUnRegisterAddress(e) {
if (e.data.type === EVENT.unregisterAddress && e.data.address && e.data.peerId) {
debug('unregister address', e.data.address);
delete addresses[e.data.address];
return true;
}
return false;
}
function handleRegisterAddress(e) {

@@ -44,2 +52,3 @@ if (e.data.type === EVENT.registerAddress && e.data.address && e.data.peerId) {

});
return true;
}

@@ -66,2 +75,3 @@ return false;

});
return true;
}

@@ -72,3 +82,3 @@ return false;

if (e && e.data) {
handleConnect(e) || handleRegisterAddress(e);
handleConnect(e) || handleRegisterAddress(e) || handleUnRegisterAddress(e);
}

@@ -75,0 +85,0 @@ }

@@ -6,2 +6,3 @@ export declare const DEBUG = false;

registerAddress: string;
unregisterAddress: string;
connect: string;

@@ -8,0 +9,0 @@ incomingServerConnection: string;

@@ -6,2 +6,3 @@ export var DEBUG = false;

registerAddress: 'registerAddress',
unregisterAddress: 'unregisterAddress',
connect: 'connect',

@@ -8,0 +9,0 @@ incomingServerConnection: 'incomingServerConnection',

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

export declare type Listener = (msg: any, port: MessagePort) => void;
export declare type listen = (addr: string, fn: Listener) => void;
declare type ListenerFn = (msg: any, port: MessagePort) => void;
export interface Listener extends ListenerFn {
cleanFns?: Array<() => void>;
}
declare type remove = () => void;
export declare type listen = (addr: string, fn: Listener) => remove;
export declare type connect = (addr: string, timeout?: number) => Promise<MessagePort>;
export {};

@@ -6,2 +6,3 @@ export declare const DEBUG = false;

registerAddress: string;
unregisterAddress: string;
connect: string;

@@ -8,0 +9,0 @@ incomingServerConnection: string;

@@ -162,2 +162,3 @@ 'use strict';

registerAddress: 'registerAddress',
unregisterAddress: 'unregisterAddress',
connect: 'connect',

@@ -174,2 +175,10 @@ incomingServerConnection: 'incomingServerConnection',

var debug = function () { };
function handleUnRegisterAddress(e) {
if (e.data.type === EVENT.unregisterAddress && e.data.address && e.data.peerId) {
debug('unregister address', e.data.address);
delete addresses[e.data.address];
return true;
}
return false;
}
function handleRegisterAddress(e) {

@@ -183,2 +192,3 @@ if (e.data.type === EVENT.registerAddress && e.data.address && e.data.peerId) {

});
return true;
}

@@ -205,2 +215,3 @@ return false;

});
return true;
}

@@ -211,3 +222,3 @@ return false;

if (e && e.data) {
handleConnect(e) || handleRegisterAddress(e);
handleConnect(e) || handleRegisterAddress(e) || handleUnRegisterAddress(e);
}

@@ -259,6 +270,15 @@ }

e.ports[0]) {
e.ports[0].addEventListener('message', function (msg) {
var l_1 = function (msg) {
debug('invoke', e.data.remoteAddress);
listeners[e.data.remoteAddress](msg, e.ports[0]);
});
};
e.ports[0].addEventListener('message', l_1);
var clean = function () {
e.ports[0].removeEventListener('message', l_1);
e.ports[0].close();
};
if (Array.isArray(listeners[e.data.remoteAddress].cleanFns)) {
// @ts-ignore
listeners[e.data.remoteAddress].cleanFns.push(clean);
}
e.ports[0].start();

@@ -304,6 +324,19 @@ }

listeners[addr] = fn;
peer.subscribe(function (_a) {
listeners[addr].cleanFns = [];
var sub = peer.subscribe(function (_a) {
var port = _a.port;
port.postMessage({ type: EVENT.registerAddress, peerId: peer.id, address: addr });
});
return function () {
sub();
for (var _i = 0, _a = listeners[addr].cleanFns || []; _i < _a.length; _i++) {
var clean = _a[_i];
clean();
}
delete listeners[addr];
var peers = peer.get();
for (var p in peers) {
peers[p].postMessage({ type: EVENT.unregisterAddress, peerId: peer.id, address: addr });
}
};
},

@@ -369,9 +402,13 @@ connect: function (addr, to) {

localChannel.port2.addEventListener('message', server.channelHandler);
client.createChannel(localChannel.port1.postMessage.bind(localChannel.port1));
client.createChannel(worker.postMessage.bind(worker));
client.createChannel(localChannel.port1.postMessage.bind(localChannel.port1)).catch(function () { });
client.createChannel(worker.postMessage.bind(worker)).catch(function () { });
// iframe
}
else if (window && window.top && window.top !== window.self) {
client.createChannel(function (msg, port) { return window.postMessage.bind(window)(msg, '*', port); });
client.createChannel(function (msg, port) { return window.top.postMessage.bind(window.top)(msg, '*', port); });
client
.createChannel(function (msg, port) { return window.postMessage.bind(window)(msg, '*', port); })
.catch(function () { });
client
.createChannel(function (msg, port) { return window.top.postMessage.bind(window.top)(msg, '*', port); })
.catch(function () { });
window.addEventListener('message', server.channelHandler);

@@ -381,3 +418,3 @@ }

else {
client.createChannel(function (msg, port) { return window.postMessage(msg, '*', port); });
client.createChannel(function (msg, port) { return window.postMessage(msg, '*', port); }).catch(function () { });
window.addEventListener('message', server.channelHandler);

@@ -384,0 +421,0 @@ }

{
"name": "@scalecube/addressable",
"version": "0.2.10-snapshot.feature-cluster-refactor.1598302712",
"version": "0.2.10-snapshot.feature-remote-registry-size-limit.1612487477",
"private": false,

@@ -30,5 +30,8 @@ "unpkg": "dist/index.js",

"author": "Scalecube (https://github.com/scalecube/scalecube-js)",
"dependencies": {
"@babel/plugin-transform-runtime": "^7.11.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^5.0.2",
"@scalecube/utils": "^0.2.10-snapshot.feature-cluster-refactor.1598302712",
"@scalecube/utils": "^0.2.10-snapshot.feature-remote-registry-size-limit.1612487477",
"@types/expect-puppeteer": "^4.4.3",

@@ -53,3 +56,3 @@ "@types/jest-environment-puppeteer": "^4.3.2",

},
"gitHead": "590283ebb5b38b23c26347b105eb05febc93ae35"
"gitHead": "80cc9ae87d5e507c88a0a7b776db753d75ecdf39"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc