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 3.1.1 to 3.2.0

25

comlink.d.ts

@@ -19,5 +19,26 @@ /**

declare type Promisify<T> = T extends Promise<any> ? T : Promise<T>;
/**
* Symbol that gets added to objects by `Comlink.proxy()`.
*/
export declare const proxyValueSymbol: unique symbol;
/**
* Object that was wrapped with `Comlink.proxy()`.
*/
export interface ProxyValue {
[proxyValueSymbol]: true;
}
/** Helper that omits all keys K from object T */
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
/**
* `ProxiedObject<T>` is equivalent to `T`, except that all properties are now promises and
* all functions now return promises, except if they were wrapped with `Comlink.proxyValue()`.
* It effectively async-ifies an object.
*/
declare type ProxiedObject<T> = {
[P in keyof T]: T[P] extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : Promisify<T[P]>;
[P in keyof T]: T[P] extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : (T[P] extends ProxyValue ? ProxiedObject<Omit<T[P], keyof ProxyValue>> : Promisify<T[P]>);
};
/**
* ProxyResult<T> is an augmentation of ProxyObject<T> that also handles raw functions
* and classes correctly.
*/
export declare type ProxyResult<T> = ProxiedObject<T> & (T extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : unknown) & (T extends {

@@ -37,4 +58,4 @@ new (...args: infer ArgumentsType): infer InstanceType;

export declare function proxy<T = any>(endpoint: Endpoint | Window, target?: any): ProxyResult<T>;
export declare function proxyValue<T>(obj: T): T;
export declare function proxyValue<T>(obj: T): T & ProxyValue;
export declare function expose(rootObj: Exposable, endpoint: Endpoint | Window): void;
export {};

16

comlink.js

@@ -13,2 +13,10 @@ /**

*/
/**
* Symbol that gets added to objects by `Comlink.proxy()`.
*/
export const proxyValueSymbol = Symbol("comlinkProxyValue");
/**
* Returns true if the given value has the proxy value symbol added to it.
*/
const isProxyValue = (value) => !!value && value[proxyValueSymbol] === true;
const TRANSFERABLE_TYPES = ["ArrayBuffer", "MessagePort", "OffscreenCanvas"]

@@ -18,6 +26,5 @@ .filter(f => f in self)

const uid = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
const proxyValueSymbol = Symbol("proxyValue");
const throwSymbol = Symbol("throw");
const proxyTransferHandler = {
canHandle: (obj) => obj && obj[proxyValueSymbol],
canHandle: isProxyValue,
serialize: (obj) => {

@@ -64,4 +71,5 @@ const { port1, port2 } = new MessageChannel();

export function proxyValue(obj) {
obj[proxyValueSymbol] = true;
return obj;
const proxyVal = obj;
proxyVal[proxyValueSymbol] = true;
return proxyVal;
}

@@ -68,0 +76,0 @@ export function expose(rootObj, endpoint) {

@@ -20,4 +20,2 @@ /**

internalPort.onmessage = (event) => {
if (!id)
id = generateUID();
const msg = event.data;

@@ -43,2 +41,4 @@ const messageChannels = Array.from(findMessageChannels(event.data));

return;
if (!id && data.id)
return;
const mcs = data.messageChannels.map(messageChannel => {

@@ -45,0 +45,0 @@ const id = messageChannel.reduce((obj, key) => obj[key], data.msg);

{
"name": "comlinkjs",
"version": "3.1.1",
"version": "3.2.0",
"description": "",

@@ -9,5 +9,6 @@ "main": "comlink.js",

"scripts": {
"test": "npm run linter && npm run unittest && npm run build",
"test": "npm run linter && npm run dtslint && npm run unittest && npm run build",
"unittest": "karma start",
"linter": "prettier --write ./*.js ./docs/**/*.js ./tests/**/*.js ./**/*.ts ./**/*.md ./**/*.json",
"dtslint": "tslint --project tests/tsconfig.json --config tslint.json",
"watchtest": "karma start --no-single-run --browsers ChromeHeadless",

@@ -42,3 +43,4 @@ "watchtestharmony": "karma start --no-single-run --browsers ChromeCanaryHeadlessHarmony",

"chai": "4.2.0",
"karma": "3.1.3",
"karma": "4.0.0",
"dtslint": "0.4.9",
"karma-chai": "0.1.0",

@@ -49,8 +51,9 @@ "karma-chrome-launcher": "2.2.0",

"karma-safari-launcher": "1.0.0",
"karma-safaritechpreview-launcher": "1.0.0",
"mocha": "5.2.0",
"prettier": "1.15.3",
"typescript": "3.2.2"
"karma-safaritechpreview-launcher": "2.0.2",
"mocha": "6.0.1",
"prettier": "1.16.4",
"tslint": "5.12.1",
"typescript": "3.3.3333"
},
"dependencies": {}
}

@@ -59,3 +59,3 @@ # Comlink

```
https://cdn.jsdelivr.net/npm/comlinkjs@3.1.1/umd/comlink.js
https://cdn.jsdelivr.net/npm/comlinkjs@3.2.0/umd/comlink.js
```

@@ -62,0 +62,0 @@

@@ -19,5 +19,26 @@ /**

declare type Promisify<T> = T extends Promise<any> ? T : Promise<T>;
/**
* Symbol that gets added to objects by `Comlink.proxy()`.
*/
export declare const proxyValueSymbol: unique symbol;
/**
* Object that was wrapped with `Comlink.proxy()`.
*/
export interface ProxyValue {
[proxyValueSymbol]: true;
}
/** Helper that omits all keys K from object T */
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
/**
* `ProxiedObject<T>` is equivalent to `T`, except that all properties are now promises and
* all functions now return promises, except if they were wrapped with `Comlink.proxyValue()`.
* It effectively async-ifies an object.
*/
declare type ProxiedObject<T> = {
[P in keyof T]: T[P] extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : Promisify<T[P]>;
[P in keyof T]: T[P] extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : (T[P] extends ProxyValue ? ProxiedObject<Omit<T[P], keyof ProxyValue>> : Promisify<T[P]>);
};
/**
* ProxyResult<T> is an augmentation of ProxyObject<T> that also handles raw functions
* and classes correctly.
*/
export declare type ProxyResult<T> = ProxiedObject<T> & (T extends (...args: infer Arguments) => infer R ? (...args: Arguments) => Promisify<R> : unknown) & (T extends {

@@ -37,4 +58,4 @@ new (...args: infer ArgumentsType): infer InstanceType;

export declare function proxy<T = any>(endpoint: Endpoint | Window, target?: any): ProxyResult<T>;
export declare function proxyValue<T>(obj: T): T;
export declare function proxyValue<T>(obj: T): T & ProxyValue;
export declare function expose(rootObj: Exposable, endpoint: Endpoint | Window): void;
export {};

@@ -25,2 +25,10 @@ /**

Object.defineProperty(exports, "__esModule", { value: true });
/**
* Symbol that gets added to objects by `Comlink.proxy()`.
*/
exports.proxyValueSymbol = Symbol("comlinkProxyValue");
/**
* Returns true if the given value has the proxy value symbol added to it.
*/
const isProxyValue = (value) => !!value && value[exports.proxyValueSymbol] === true;
const TRANSFERABLE_TYPES = ["ArrayBuffer", "MessagePort", "OffscreenCanvas"]

@@ -30,6 +38,5 @@ .filter(f => f in self)

const uid = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
const proxyValueSymbol = Symbol("proxyValue");
const throwSymbol = Symbol("throw");
const proxyTransferHandler = {
canHandle: (obj) => obj && obj[proxyValueSymbol],
canHandle: isProxyValue,
serialize: (obj) => {

@@ -77,4 +84,5 @@ const { port1, port2 } = new MessageChannel();

function proxyValue(obj) {
obj[proxyValueSymbol] = true;
return obj;
const proxyVal = obj;
proxyVal[exports.proxyValueSymbol] = true;
return proxyVal;
}

@@ -81,0 +89,0 @@ exports.proxyValue = proxyValue;

@@ -21,3 +21,3 @@ /**

}
else {factory([], self.Comlink={});}
else {factory([], self.MessageChannelAdapter={});}
})(function (require, exports) {

@@ -34,4 +34,2 @@ "use strict";

internalPort.onmessage = (event) => {
if (!id)
id = generateUID();
const msg = event.data;

@@ -57,2 +55,4 @@ const messageChannels = Array.from(findMessageChannels(event.data));

return;
if (!id && data.id)
return;
const mcs = data.messageChannels.map(messageChannel => {

@@ -59,0 +59,0 @@ const id = messageChannel.reduce((obj, key) => obj[key], data.msg);

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