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

comlinkjs

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comlinkjs - npm Package Compare versions

Comparing version 2.3.2 to 2.3.3

6

comlink.es6.js

@@ -125,3 +125,3 @@ /**

type: key,
value: item.value,
value: transferHandler.serialize(item.value),
},

@@ -132,2 +132,6 @@ });

}
for (const wrappedChild of wrappedChildren) {
const container = wrappedChild.path.slice(0, -1).reduce((obj, key) => obj[key], arg);
container[wrappedChild.path[wrappedChild.path.length - 1]] = null;
}
return {

@@ -134,0 +138,0 @@ type: 'RAW',

2

comlink.es6.min.js

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

export const Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return j(a),p(async(b)=>{let c=[];('APPLY'===b.type||'CONSTRUCT'===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(('APPLY'===f.type||'CONSTRUCT'===f.type)&&(j=f.argumentsList.map(e)),'APPLY'===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if('CONSTRUCT'===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return'SET'===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:c.value}});return{type:'RAW',value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join('.')}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return'RAW'===a.type}function h(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function i(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener('message',b)}function l(a,b){a.removeEventListener('message',b)}function m(a){return'MessagePort'===a.constructor.name}function n(a){return['window','length','location','parent','opener'].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:'CONSTRUCT',callPath:b,argumentsList:d})},apply(c,d,e){return'bind'===b[b.length-1]?p(a,b.slice(0,-1)):a({type:'APPLY',callPath:b,argumentsList:e})},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if('then'===d){const c=a({type:'GET',callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:'SET',callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&'string'!=typeof a){'object'==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:'RAW',value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol('proxyValue'),x=Symbol('throw'),y=new Map([['PROXY',{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>{return a(b)}}],['THROW',{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+'\n'+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}();
export const Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return j(a),p(async(b)=>{let c=[];('APPLY'===b.type||'CONSTRUCT'===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(('APPLY'===f.type||'CONSTRUCT'===f.type)&&(j=f.argumentsList.map(e)),'APPLY'===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if('CONSTRUCT'===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return'SET'===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:d.serialize(c.value)}});for(const c of b){const b=c.path.slice(0,-1).reduce((a,b)=>a[b],a);b[c.path[c.path.length-1]]=null}return{type:'RAW',value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join('.')}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return'RAW'===a.type}function h(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function i(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener('message',b)}function l(a,b){a.removeEventListener('message',b)}function m(a){return'MessagePort'===a.constructor.name}function n(a){return['window','length','location','parent','opener'].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:'CONSTRUCT',callPath:b,argumentsList:d})},apply(c,d,e){return'bind'===b[b.length-1]?p(a,b.slice(0,-1)):a({type:'APPLY',callPath:b,argumentsList:e})},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if('then'===d){const c=a({type:'GET',callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:'SET',callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&'string'!=typeof a){'object'==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:'RAW',value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol('proxyValue'),x=Symbol('throw'),y=new Map([['PROXY',{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>a(b)}],['THROW',{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+'\n'+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}();

@@ -127,3 +127,3 @@ "use strict";

type: key,
value: item.value,
value: transferHandler.serialize(item.value),
},

@@ -134,2 +134,6 @@ });

}
for (const wrappedChild of wrappedChildren) {
const container = wrappedChild.path.slice(0, -1).reduce((obj, key) => obj[key], arg);
container[wrappedChild.path[wrappedChild.path.length - 1]] = null;
}
return {

@@ -136,0 +140,0 @@ type: 'RAW',

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

'use strict';self.Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return j(a),p(async(b)=>{let c=[];('APPLY'===b.type||'CONSTRUCT'===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(('APPLY'===f.type||'CONSTRUCT'===f.type)&&(j=f.argumentsList.map(e)),'APPLY'===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if('CONSTRUCT'===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return'SET'===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:c.value}});return{type:'RAW',value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join('.')}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return'RAW'===a.type}function h(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function i(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener('message',b)}function l(a,b){a.removeEventListener('message',b)}function m(a){return'MessagePort'===a.constructor.name}function n(a){return['window','length','location','parent','opener'].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:'CONSTRUCT',callPath:b,argumentsList:d})},apply(c,d,e){return'bind'===b[b.length-1]?p(a,b.slice(0,-1)):a({type:'APPLY',callPath:b,argumentsList:e})},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if('then'===d){const c=a({type:'GET',callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:'SET',callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&'string'!=typeof a){'object'==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:'RAW',value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol('proxyValue'),x=Symbol('throw'),y=new Map([['PROXY',{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>{return a(b)}}],['THROW',{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+'\n'+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}();
'use strict';self.Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return j(a),p(async(b)=>{let c=[];('APPLY'===b.type||'CONSTRUCT'===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(('APPLY'===f.type||'CONSTRUCT'===f.type)&&(j=f.argumentsList.map(e)),'APPLY'===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if('CONSTRUCT'===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return'SET'===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:d.serialize(c.value)}});for(const c of b){const b=c.path.slice(0,-1).reduce((a,b)=>a[b],a);b[c.path[c.path.length-1]]=null}return{type:'RAW',value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join('.')}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return'RAW'===a.type}function h(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function i(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener('message',b)}function l(a,b){a.removeEventListener('message',b)}function m(a){return'MessagePort'===a.constructor.name}function n(a){return['window','length','location','parent','opener'].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:'CONSTRUCT',callPath:b,argumentsList:d})},apply(c,d,e){return'bind'===b[b.length-1]?p(a,b.slice(0,-1)):a({type:'APPLY',callPath:b,argumentsList:e})},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if('then'===d){const c=a({type:'GET',callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:'SET',callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&'string'!=typeof a){'object'==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:'RAW',value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol('proxyValue'),x=Symbol('throw'),y=new Map([['PROXY',{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>a(b)}],['THROW',{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+'\n'+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}();

@@ -136,3 +136,3 @@ /**

type: key,
value: item.value,
value: transferHandler.serialize(item.value),
},

@@ -143,2 +143,6 @@ });

}
for (const wrappedChild of wrappedChildren) {
const container = wrappedChild.path.slice(0, -1).reduce((obj, key) => obj[key], arg);
container[wrappedChild.path[wrappedChild.path.length - 1]] = null;
}
return {

@@ -145,0 +149,0 @@ type: 'RAW',

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

(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");return j(a),p(async(b)=>{let c=[];("APPLY"===b.type||"CONSTRUCT"===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(("APPLY"===f.type||"CONSTRUCT"===f.type)&&(j=f.argumentsList.map(e)),"APPLY"===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if("CONSTRUCT"===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return"SET"===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:c.value}});return{type:"RAW",value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join(".")}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return"RAW"===a.type}function h(a){if("Window"!==self.constructor.name)throw Error("self is not a window");return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,"*",c)}}function i(a){return"addEventListener"in a&&"removeEventListener"in a&&"postMessage"in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener("message",b)}function l(a,b){a.removeEventListener("message",b)}function m(a){return"MessagePort"===a.constructor.name}function n(a){return["window","length","location","parent","opener"].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:"CONSTRUCT",callPath:b,argumentsList:d})},apply(c,d,e){return"bind"===b[b.length-1]?p(a,b.slice(0,-1)):a({type:"APPLY",callPath:b,argumentsList:e})},get(c,d,e){if("then"===d&&0===b.length)return{then:()=>e};if("then"===d){const c=a({type:"GET",callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:"SET",callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&"string"!=typeof a){"object"==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:"RAW",value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol("proxyValue"),x=Symbol("throw"),y=new Map([["PROXY",{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>{return a(b)}}],["THROW",{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+"\n"+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}()});
(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.Comlink=function(){function a(a){if(n(a)&&(a=h(a)),!i(a))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");return j(a),p(async(b)=>{let c=[];("APPLY"===b.type||"CONSTRUCT"===b.type)&&(c=b.argumentsList.map(d));const f=await o(a,Object.assign({},b,{argumentsList:c}),r(c)),g=f.data;return e(g.value)})}function b(a){return a[w]=!0,a}function c(a,c){if(n(c)&&(c=h(c)),!i(c))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");j(c),k(c,async function(d){if(!d.data.id)return;const f=d.data;let g=await f.callPath.slice(0,-1).reduce((a,b)=>a[b],a),h=await f.callPath.reduce((a,b)=>a[b],a),i=h,j=[];if(("APPLY"===f.type||"CONSTRUCT"===f.type)&&(j=f.argumentsList.map(e)),"APPLY"===f.type)try{i=await h.apply(g,j)}catch(a){i=a,i[x]=!0}if("CONSTRUCT"===f.type)try{i=new h(...j),i=b(i)}catch(a){i=a,i[x]=!0}return"SET"===f.type&&(h[f.property]=f.value,i=!0),i=t(i),i.id=f.id,c.postMessage(i,r([i]))})}function d(a){for(const[b,c]of y.entries())if(c.canHandle(a))return{type:b,value:c.serialize(a)};let b=[];for(const c of s(a))for(const[a,d]of y.entries())d.canHandle(c.value)&&b.push({path:c.path,wrappedValue:{type:a,value:d.serialize(c.value)}});for(const c of b){const b=c.path.slice(0,-1).reduce((a,b)=>a[b],a);b[c.path[c.path.length-1]]=null}return{type:"RAW",value:a,wrappedChildren:b}}function e(a){if(y.has(a.type)){const b=y.get(a.type);return b.deserialize(a.value)}if(g(a)){for(const b of a.wrappedChildren||[]){if(!y.has(b.wrappedValue.type))throw Error(`Unknown value type "${a.type}" at ${b.path.join(".")}`);const c=y.get(b.wrappedValue.type),d=c.deserialize(b.wrappedValue.value);f(a.value,b.path,d)}return a.value}throw Error(`Unknown value type "${a.type}"`)}function f(a,b,c){const d=b.slice(-1)[0],e=b.slice(0,-1).reduce((a,b)=>a[b],a);e[d]=c}function g(a){return"RAW"===a.type}function h(a){if("Window"!==self.constructor.name)throw Error("self is not a window");return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,"*",c)}}function i(a){return"addEventListener"in a&&"removeEventListener"in a&&"postMessage"in a}function j(a){m(a)&&a.start()}function k(a,b){a.addEventListener("message",b)}function l(a,b){a.removeEventListener("message",b)}function m(a){return"MessagePort"===a.constructor.name}function n(a){return["window","length","location","parent","opener"].every((b)=>b in a)}function o(a,b,c){const d=`${v}-${z++}`;return new Promise((e)=>{k(a,function b(c){c.data.id!==d||(l(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function p(a,b=[]){return new Proxy(function(){},{construct(c,d){return a({type:"CONSTRUCT",callPath:b,argumentsList:d})},apply(c,d,e){return"bind"===b[b.length-1]?p(a,b.slice(0,-1)):a({type:"APPLY",callPath:b,argumentsList:e})},get(c,d,e){if("then"===d&&0===b.length)return{then:()=>e};if("then"===d){const c=a({type:"GET",callPath:b});return Promise.resolve(c).then.bind(c)}return p(a,b.concat(d))},set(c,d,e){return a({type:"SET",callPath:b,property:d,value:e})}})}function q(a){return u.some((b)=>a instanceof b)}function*s(a,b=[],c=null){if(a&&(c||(c=new WeakSet),!c.has(a))&&"string"!=typeof a){"object"==typeof a&&c.add(a),yield{value:a,path:b};let d=Object.keys(a);for(const e of d)yield*s(a[e],[...b,e],c)}}function r(a){const b=[];for(const c of s(a))q(c.value)&&b.push(c.value);return b}function t(a){for(const[b,c]of y.entries())if(c.canHandle(a)){const d=c.serialize(a);return{value:{type:b,value:d}}}return{value:{type:"RAW",value:a}}}const u=[ArrayBuffer,MessagePort],v=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),w=Symbol("proxyValue"),x=Symbol("throw"),y=new Map([["PROXY",{canHandle:(a)=>a&&a[w],serialize:(a)=>{const{port1:b,port2:d}=new MessageChannel;return c(a,b),d},deserialize:(b)=>a(b)}],["THROW",{canHandle:(a)=>a&&a[x],serialize:(a)=>a.toString()+"\n"+a.stack,deserialize:(a)=>{throw Error(a)}}]]);let z=0;return{proxy:a,proxyValue:b,transferHandlers:y,expose:c}}()});

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

export const MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener('message',(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&'string'!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join('')}const g=128;return{wrap:a}}();
export const MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener('message',(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&'string'!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join('')}const g=128;return{wrap:a}}();

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

'use strict';self.MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener('message',(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&'string'!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join('')}const g=128;return{wrap:a}}();
'use strict';self.MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener('message',(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&'string'!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join('')}const g=128;return{wrap:a}}();

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

(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener("message",(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&"string"!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join("")}const g=128;return{wrap:a}}()});
(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.MessageChannelAdapter=function(){function a(a,c=null){const{port1:d,port2:e}=new MessageChannel;return b(e,a,c),d}function b(e,g,h=null){e.onmessage=(a)=>{h||(h=f());const e=a.data,i=Array.from(d(a.data));for(const d of i){const a=f(),h=c(e,d,a);b(h,g,a)}const j=JSON.stringify({id:h,msg:e,messageChannels:i});g.send(j)},g.addEventListener("message",(b)=>{const d=JSON.parse(b.data);if(h||(h=d.id),h===d.id){const b=d.messageChannels.map((b)=>{const e=b.reduce((a,b)=>a[b],d.msg),f=a(g,e);return c(d.msg,b,f),f});e.postMessage(d.msg,b)}})}function c(a,b,c){for(const d of b.slice(0,-1))a=a[d];const d=b[b.length-1],e=a[d];return a[d]=c,e}function*d(a,b=[]){if(a&&"string"!=typeof a){if(a instanceof MessagePort)return void(yield b.slice());for(const c of Object.keys(a))b.push(c),yield*d(a[c],b),b.pop()}}function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function f(){return Array(g/16).fill(0).map(()=>e()).join("")}const g=128;return{wrap:a}}()});
{
"name": "comlinkjs",
"version": "2.3.2",
"version": "2.3.3",
"description": "",

@@ -19,3 +19,3 @@ "main": "comlink.umd.js",

"mangle_global": "sed -i.bak -e 's!exports.Comlink!self.Comlink!' dist/comlink.global.js && sed -i.bak 's!^.*\"__esModule\".*$!!' dist/comlink.global.js && sed -i.bak -e 's!exports.MessageChannelAdapter!self.MessageChannelAdapter!' dist/messagechanneladapter.global.js && sed -i.bak -e 's!^.*\"__esModule\".*$!!' dist/messagechanneladapter.global.js",
"minify": "babili -o dist/comlink.global.{min.,}js && babili -o dist/comlink.es6.{min.,}js && babili -o dist/comlink.umd.{min.,}js && babili -o dist/messagechanneladapter.global.{min.,}js && babili -o dist/messagechanneladapter.es6.{min.,}js && babili -o dist/messagechanneladapter.umd.{min.,}js"
"minify": "babel-minify --mangle -o dist/comlink.global.{min.,}js && babel-minify --mangle -o dist/comlink.es6.{min.,}js && babel-minify --mangle -o dist/comlink.umd.{min.,}js && babel-minify --mangle -o dist/messagechanneladapter.global.{min.,}js && babel-minify --mangle -o dist/messagechanneladapter.es6.{min.,}js && babel-minify --mangle -o dist/messagechanneladapter.umd.{min.,}js"
},

@@ -39,5 +39,5 @@ "keywords": [],

"devDependencies": {
"babili": "0.1.4",
"babel-minify": "^0.3.0",
"chai": "4.1.2",
"eslint": "4.18.0",
"eslint": "4.18.1",
"eslint-config-google": "0.9.1",

@@ -53,5 +53,5 @@ "karma": "2.0.0",

"typescript": "2.7.2",
"typescript-eslint-parser": "13.0.0"
"typescript-eslint-parser": "14.0.0"
},
"dependencies": {}
}
# Comlink
Comlink’s goal is to make [WebWorkers][WebWorker] enjoyable. Instead of using `postMessage` to send messages back and forth, Comlink allows you to invoke functions, pass callbacks, add event listeners and create new instances of classes.
> Note: Comlink’s goal is to be a building-block for higher-level abstraction libraries. For example, take a look at [Clooney].
```js

@@ -121,2 +123,3 @@ // main.js

[Clooney]: https://github.com/GoogleChromeLabs/clooney
[WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API

@@ -123,0 +126,0 @@ [UMD]: https://github.com/umdjs/umd

Sorry, the diff of this file is not supported yet

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