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

@wixc3/isomorphic-worker

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/isomorphic-worker - npm Package Compare versions

Comparing version 1.2.5 to 2.0.0

4

dist/browser-worker-scope.d.ts

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

import type { MessageType, UniversalMessage, UniversalWorkerUserMethods } from './types';
import type { MessageType, UniversalMessage, UniversalWorkerUserMethods } from './types.js';
declare class UniversalWorkerUser implements UniversalWorkerUserMethods {

@@ -8,3 +8,3 @@ private self;

addEventListener(type: 'message' | 'error', callback: (message: UniversalMessage) => void): void;
removeEventListener(type: MessageType, callback: (message: UniversalMessage<unknown>) => void): void;
removeEventListener(type: MessageType, callback: (message: UniversalMessage) => void): void;
}

@@ -11,0 +11,0 @@ export declare const worker: UniversalWorkerUser;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.worker = void 0;
const getMessageData = (message) => {

@@ -11,5 +8,6 @@ if (message instanceof MessageEvent) {

class UniversalWorkerUser {
self;
messageHandlersMap = new Map();
constructor(self) {
this.self = self;
this.messageHandlersMap = new Map();
}

@@ -33,3 +31,3 @@ postMessage(message) {

}
exports.worker = new UniversalWorkerUser(self);
export const worker = new UniversalWorkerUser(self);
//# sourceMappingURL=browser-worker-scope.js.map

@@ -1,5 +0,3 @@

import './browser-polyfill/main-worker-host';
import './browser-polyfill/nested-worker-polyfill';
import type { UniversalWorkerConstructor } from './types';
import type { UniversalWorkerConstructor } from './types.js';
export declare const Worker: UniversalWorkerConstructor;
//# sourceMappingURL=browser-worker.d.ts.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Worker = void 0;
require("./browser-polyfill/main-worker-host");
require("./browser-polyfill/nested-worker-polyfill");
// globalThis in case of initial worker script inside a worker
exports.Worker = globalThis.Worker;
export const Worker = globalThis.Worker;
//# sourceMappingURL=browser-worker.js.map

@@ -1,12 +0,11 @@

/// <reference types="node" />
import { type MessagePort } from 'node:worker_threads';
import type { MessageType, UniversalMessage, UniversalWorkerUserMethods } from './types';
import type { MessageType, UniversalMessage, UniversalWorkerUserMethods } from './types.js';
declare class UniversalWorkerUser implements UniversalWorkerUserMethods {
private portOrWorkerSelf;
private messageHandlersMap;
workerData: any;
workerData: unknown;
constructor(portOrWorkerSelf: MessagePort);
postMessage(message: unknown): void;
addEventListener(type: 'message' | 'error', callback: (message: any) => void): void;
removeEventListener(type: MessageType, callback: (message: UniversalMessage<unknown>) => void): void;
addEventListener(type: 'message' | 'error', callback: (message: UniversalMessage) => void): void;
removeEventListener(type: MessageType, callback: (message: UniversalMessage) => void): void;
}

@@ -13,0 +12,0 @@ export declare const worker: UniversalWorkerUser;

@@ -1,16 +0,14 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.worker = void 0;
const node_worker_threads_1 = require("node:worker_threads");
import { parentPort, workerData } from 'node:worker_threads';
const port = (function getPort() {
if (!node_worker_threads_1.parentPort) {
if (!parentPort) {
throw new Error('parentPort required for worker processors');
}
return node_worker_threads_1.parentPort;
return parentPort;
})();
class UniversalWorkerUser {
portOrWorkerSelf;
messageHandlersMap = new Map();
workerData = workerData;
constructor(portOrWorkerSelf) {
this.portOrWorkerSelf = portOrWorkerSelf;
this.messageHandlersMap = new Map();
this.workerData = node_worker_threads_1.workerData;
}

@@ -35,3 +33,3 @@ postMessage(message) {

}
exports.worker = new UniversalWorkerUser(port);
export const worker = new UniversalWorkerUser(port);
//# sourceMappingURL=node-worker-scope.js.map

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

import type { MessageType, UniversalMessageHandler, UniversalWorker, UniversalWorkerOptions, WorkerScript } from './types';
import type { MessageType, UniversalMessageHandler, UniversalWorker, UniversalWorkerOptions, WorkerScript } from './types.js';
declare class NodeWorker implements UniversalWorker {

@@ -6,3 +6,3 @@ private worker;

constructor(url: WorkerScript, options?: UniversalWorkerOptions);
postMessage(message: any): void;
postMessage(message: unknown): void;
addEventListener(type: MessageType, callback: UniversalMessageHandler): void;

@@ -9,0 +9,0 @@ removeEventListener(type: MessageType, callback: UniversalMessageHandler): void;

@@ -1,9 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Worker = void 0;
const node_worker_threads_1 = require("node:worker_threads");
import { Worker } from 'node:worker_threads';
class NodeWorker {
worker;
messageHandlersMap = new Map();
constructor(url, options) {
this.messageHandlersMap = new Map();
this.worker = new node_worker_threads_1.Worker(url, options);
this.worker = new Worker(url, options);
}

@@ -29,3 +27,3 @@ postMessage(message) {

}
exports.Worker = NodeWorker;
export { NodeWorker as Worker };
//# sourceMappingURL=node-worker.js.map

@@ -13,3 +13,3 @@ export type MessageType = 'message' | 'error';

*/
workerData?: any;
workerData?: unknown;
}

@@ -24,7 +24,7 @@ export type UniversalWorkerOptions = WorkerOptions | undefined;

removeEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;
terminate: () => void;
terminate: () => Promise<number> | void;
}
export interface UniversalWorkerUserMethods {
postMessage: (message: unknown) => void;
addEventListener: (type: MessageType, callback: (message: any) => void) => void;
addEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;
removeEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;

@@ -36,4 +36,4 @@ }

}
export type UniversalMessageHandler = (message: UniversalMessage<unknown>) => void;
export type WorkerMessageHandler = (message: any) => void;
export type UniversalMessageHandler = (message: UniversalMessage) => void;
export type WorkerMessageHandler = (message: UniversalMessage) => void;
//# sourceMappingURL=types.d.ts.map

@@ -1,3 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=types.js.map
{
"name": "@wixc3/isomorphic-worker",
"version": "1.2.5",
"version": "2.0.0",
"type": "module",
"description": "simplified cross worker API for web workers and worker threads",
"homepage": "https://github.com/wixplosives/isomorphic-worker",
"scripts": {
"build": "tsc",
"watch": "tsc -w"
},
"exports": {

@@ -27,19 +24,8 @@ "./worker-scope": {

},
"./package": "./package.json",
"./package.json": "./package.json"
},
"browser": {
"./worker-scope.js": "./dist/browser-worker-scope.js",
"./worker.js": "./dist/browser-worker.js"
},
"files": [
"dist",
"src",
"!dist/tsconfig.tsbuildinfo",
"types.d.ts",
"types.js",
"worker-scope.d.ts",
"worker.d.ts",
"worker.js",
"worker-scope.js"
"!*/tsconfig.{json,tsbuildinfo}"
],

@@ -60,3 +46,4 @@ "keywords": [

"type": "git",
"url": "git+https://github.com/wixplosives/isomorphic-worker.git"
"url": "git+https://github.com/wixplosives/isomorphic-worker.git",
"directory": "packages/isomorphic-worker"
},

@@ -67,3 +54,4 @@ "author": "Wix.com",

"access": "public"
}
},
"sideEffects": false
}

@@ -7,3 +7,3 @@ import type {

WorkerMessageHandler,
} from './types';
} from './types.js';

@@ -28,3 +28,3 @@ const getMessageData = (message: unknown): unknown => {

public addEventListener(type: 'message' | 'error', callback: (message: UniversalMessage) => void) {
const handler = (e: any) =>
const handler: WorkerMessageHandler = (e) =>
callback({ data: 'data' in e ? e.data : undefined, error: 'error' in e ? e.error : undefined });

@@ -36,3 +36,3 @@ this.messageHandlersMap.set(callback, handler);

public removeEventListener(type: MessageType, callback: (message: UniversalMessage<unknown>) => void) {
public removeEventListener(type: MessageType, callback: (message: UniversalMessage) => void) {
const handler = this.messageHandlersMap.get(callback);

@@ -47,2 +47,2 @@ if (handler) {

export const worker = new UniversalWorkerUser(self as any);
export const worker = new UniversalWorkerUser(self as unknown as Worker);

@@ -1,6 +0,4 @@

import './browser-polyfill/main-worker-host';
import './browser-polyfill/nested-worker-polyfill';
import type { UniversalWorkerConstructor } from './types';
import type { UniversalWorkerConstructor } from './types.js';
// globalThis in case of initial worker script inside a worker
export const Worker = globalThis.Worker as UniversalWorkerConstructor;

@@ -8,3 +8,3 @@ import { parentPort, workerData, type MessagePort } from 'node:worker_threads';

WorkerMessageHandler,
} from './types';
} from './types.js';

@@ -20,3 +20,3 @@ const port = (function getPort() {

private messageHandlersMap = new Map<UniversalMessageHandler, WorkerMessageHandler>();
public workerData = workerData;
public workerData: unknown = workerData;
constructor(private portOrWorkerSelf: MessagePort) {}

@@ -28,7 +28,7 @@

addEventListener(type: 'message' | 'error', callback: (message: any) => void) {
const handler = (message: any) => callback({ data: message });
addEventListener(type: 'message' | 'error', callback: (message: UniversalMessage) => void) {
const handler: WorkerMessageHandler = (message) => callback({ data: message });
this.messageHandlersMap.set(callback, handler);
this.portOrWorkerSelf.on(type, function MessageFromNodeWorker(message) {
this.portOrWorkerSelf.on(type, function MessageFromNodeWorker(message: unknown) {
callback({ data: message });

@@ -38,3 +38,3 @@ });

public removeEventListener(type: MessageType, callback: (message: UniversalMessage<unknown>) => void) {
public removeEventListener(type: MessageType, callback: (message: UniversalMessage) => void) {
const handler = this.messageHandlersMap.get(callback);

@@ -41,0 +41,0 @@ if (handler) {

@@ -9,3 +9,3 @@ import { Worker } from 'node:worker_threads';

WorkerScript,
} from './types';
} from './types.js';

@@ -20,3 +20,3 @@ class NodeWorker implements UniversalWorker {

public postMessage(message: any) {
public postMessage(message: unknown) {
this.worker.postMessage(message);

@@ -26,3 +26,3 @@ }

public addEventListener(type: MessageType, callback: UniversalMessageHandler) {
const handler = (message: any) => callback({ data: message });
const handler: WorkerMessageHandler = (message) => callback({ data: message });
this.messageHandlersMap.set(callback, handler);

@@ -29,0 +29,0 @@

@@ -15,3 +15,3 @@ export type MessageType = 'message' | 'error';

*/
workerData?: any; // TODO: check if this can be standardized by query params
workerData?: unknown; // TODO: check if this can be standardized by query params
}

@@ -28,3 +28,3 @@

removeEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;
terminate: () => void;
terminate: () => Promise<number> | void;
}

@@ -34,3 +34,3 @@

postMessage: (message: unknown) => void;
addEventListener: (type: MessageType, callback: (message: any) => void) => void;
addEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;
removeEventListener: (type: MessageType, callback: (message: UniversalMessage) => void) => void;

@@ -44,3 +44,3 @@ }

export type UniversalMessageHandler = (message: UniversalMessage<unknown>) => void;
export type WorkerMessageHandler = (message: any) => void;
export type UniversalMessageHandler = (message: UniversalMessage) => void;
export type WorkerMessageHandler = (message: UniversalMessage) => void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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