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

@grapes-agency/apollo-link-webworker

Package Overview
Dependencies
Maintainers
6
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grapes-agency/apollo-link-webworker - npm Package Compare versions

Comparing version 1.0.0-alpha.7 to 1.0.0-alpha.9

22

CHANGELOG.md

@@ -6,2 +6,24 @@ # Change Log

# [1.0.0-alpha.9](https://github.com/grapes-agency/graphql/compare/@grapes-agency/apollo-link-webworker@1.0.0-alpha.8...@grapes-agency/apollo-link-webworker@1.0.0-alpha.9) (2021-08-27)
### Bug Fixes
* **apollo-link-webworker:** Ensure __DEV__ is always set ([c477c3c](https://github.com/grapes-agency/graphql/commit/c477c3cb51857ca73f65a7722155ed1774e794f5))
# [1.0.0-alpha.8](https://github.com/grapes-agency/graphql/compare/@grapes-agency/apollo-link-webworker@1.0.0-alpha.7...@grapes-agency/apollo-link-webworker@1.0.0-alpha.8) (2021-08-27)
### Bug Fixes
* **apollo-link-webworker:** Removed side effects ([94b3561](https://github.com/grapes-agency/graphql/commit/94b35611d0be2e60f8387cd3237e34ada2cf6101))
# [1.0.0-alpha.7](https://github.com/grapes-agency/graphql/compare/@grapes-agency/apollo-link-webworker@1.0.0-alpha.6...@grapes-agency/apollo-link-webworker@1.0.0-alpha.7) (2021-08-18)

@@ -8,0 +30,0 @@

2

dist/ApolloWebWorkerLink.d.ts
/// <reference types="zen-observable" />
import type { FetchResult, NextLink, Operation } from '@apollo/client';
import { ApolloLink, Observable } from '@apollo/client';
import './RemoteObservable';
import './RemoteOperation';
export declare class ApolloWebWorkerLink<Options = Record<string, any>> extends ApolloLink {

@@ -7,0 +5,0 @@ private apolloWorker;

import { ApolloLink, Observable } from '@apollo/client';
import { wrap, proxy } from 'comlink';
import './RemoteObservable.js';
import './RemoteOperation.js';
import { setupRemoteObservable } from './RemoteObservable.js';
import { setupRemoteOperation } from './RemoteOperation.js';
setupRemoteObservable();
setupRemoteOperation();
class ApolloWebWorkerLink extends ApolloLink {

@@ -7,0 +9,0 @@ constructor(webWorker, options) {

/// <reference types="zen-observable" />
import type { FetchResult, NextLink, Operation } from '@apollo/client';
import { ApolloLink, Observable } from '@apollo/client';
import './RemoteObservable';
import './RemoteOperation';
declare type RemoteRequestHandler = (operation: Operation, forward?: NextLink) => Promise<Observable<FetchResult> | null>;

@@ -7,0 +5,0 @@ export interface ApolloWorker {

import { ApolloLink, Observable } from '@apollo/client';
import { expose } from 'comlink';
import './RemoteObservable.js';
import './RemoteOperation.js';
import { setupRemoteObservable } from './RemoteObservable.js';
import { setupRemoteOperation } from './RemoteOperation.js';
setupRemoteObservable();
setupRemoteOperation();
const createAsyncLink = () => {

@@ -26,3 +28,15 @@ let release = null;

};
const maybeFixDev = () => {
const anyGlobal = global;
if (!('__DEV__' in anyGlobal)) {
try {
anyGlobal.__DEV__ = process.env.NODE_ENV !== 'production';
}
catch (_a) {
anyGlobal.__DEV__ = false;
}
}
};
const createApolloWorker = (apolloLink) => {
maybeFixDev();
const link = createAsyncLink();

@@ -29,0 +43,0 @@ if (apolloLink instanceof ApolloLink) {

@@ -34,51 +34,53 @@ 'use strict';

const objectifyError = (error) => Object.fromEntries(Object.getOwnPropertyNames(error).map(propertyName => [propertyName, error[propertyName]]));
Comlink__namespace.transferHandlers.set('OBSERVABLE', {
canHandle: (obj) => obj instanceof client.Observable,
serialize: (observable) => {
const { port1, port2 } = new MessageChannel();
port1.start();
port1.addEventListener('message', event => {
if (!(event.data === 'subscribe' && event.ports)) {
return;
}
const [port] = event.ports;
port.start();
const subscription = observable.subscribe({
next: next => { var _a; return port.postMessage({ next: Object.assign(Object.assign({}, next), { errors: ((_a = next.errors) === null || _a === void 0 ? void 0 : _a.map(objectifyError)) || undefined }) }); },
error: (error) => port.postMessage({ error }),
complete: () => port.postMessage({ complete: true }),
});
port.addEventListener('message', ({ data }) => {
if (data === 'unsubscribe') {
subscription.unsubscribe();
}
});
});
return [port2, [port2]];
},
deserialize: (port) => {
port.start();
return new client.Observable(observer => {
const setupRemoteObservable = () => {
Comlink__namespace.transferHandlers.set('OBSERVABLE', {
canHandle: (obj) => obj instanceof client.Observable,
serialize: (observable) => {
const { port1, port2 } = new MessageChannel();
port1.start();
port.postMessage('subscribe', [port2]);
const handleMessage = ({ data }) => {
if (data.next) {
observer.next(data.next);
port1.addEventListener('message', event => {
if (!(event.data === 'subscribe' && event.ports)) {
return;
}
else if (data.error) {
observer.error(data.error);
}
else if (data.complete) {
observer.complete();
}
};
port1.addEventListener('message', handleMessage);
return () => {
port1.removeEventListener('message', handleMessage);
port1.postMessage('unsubscribe');
};
});
},
});
const [port] = event.ports;
port.start();
const subscription = observable.subscribe({
next: next => { var _a; return port.postMessage({ next: Object.assign(Object.assign({}, next), { errors: ((_a = next.errors) === null || _a === void 0 ? void 0 : _a.map(objectifyError)) || undefined }) }); },
error: (error) => port.postMessage({ error }),
complete: () => port.postMessage({ complete: true }),
});
port.addEventListener('message', ({ data }) => {
if (data === 'unsubscribe') {
subscription.unsubscribe();
}
});
});
return [port2, [port2]];
},
deserialize: (port) => {
port.start();
return new client.Observable(observer => {
const { port1, port2 } = new MessageChannel();
port1.start();
port.postMessage('subscribe', [port2]);
const handleMessage = ({ data }) => {
if (data.next) {
observer.next(data.next);
}
else if (data.error) {
observer.error(data.error);
}
else if (data.complete) {
observer.complete();
}
};
port1.addEventListener('message', handleMessage);
return () => {
port1.removeEventListener('message', handleMessage);
port1.postMessage('unsubscribe');
};
});
},
});
};

@@ -101,4 +103,8 @@ const operationStorage = new Map();

};
Comlink__namespace.transferHandlers.set('OPERATION', operationTransferHandler);
const setupRemoteOperation = () => {
Comlink__namespace.transferHandlers.set('OPERATION', operationTransferHandler);
};
setupRemoteObservable();
setupRemoteOperation();
class ApolloWebWorkerLink extends client.ApolloLink {

@@ -138,2 +144,4 @@ constructor(webWorker, options) {

setupRemoteObservable();
setupRemoteOperation();
const createAsyncLink = () => {

@@ -159,3 +167,15 @@ let release = null;

};
const maybeFixDev = () => {
const anyGlobal = global;
if (!('__DEV__' in anyGlobal)) {
try {
anyGlobal.__DEV__ = process.env.NODE_ENV !== 'production';
}
catch (_a) {
anyGlobal.__DEV__ = false;
}
}
};
const createApolloWorker = (apolloLink) => {
maybeFixDev();
const link = createAsyncLink();

@@ -162,0 +182,0 @@ if (apolloLink instanceof client.ApolloLink) {

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

import { Observable } from '@apollo/client';
export { Observable };
export declare const setupRemoteObservable: () => void;
import { Observable } from '@apollo/client';
export { Observable } from '@apollo/client';
import * as Comlink from 'comlink';

@@ -7,51 +6,55 @@

const objectifyError = (error) => Object.fromEntries(Object.getOwnPropertyNames(error).map(propertyName => [propertyName, error[propertyName]]));
Comlink.transferHandlers.set('OBSERVABLE', {
canHandle: (obj) => obj instanceof Observable,
serialize: (observable) => {
const { port1, port2 } = new MessageChannel();
port1.start();
port1.addEventListener('message', event => {
if (!(event.data === 'subscribe' && event.ports)) {
return;
}
const [port] = event.ports;
port.start();
const subscription = observable.subscribe({
next: next => { var _a; return port.postMessage({ next: Object.assign(Object.assign({}, next), { errors: ((_a = next.errors) === null || _a === void 0 ? void 0 : _a.map(objectifyError)) || undefined }) }); },
error: (error) => port.postMessage({ error }),
complete: () => port.postMessage({ complete: true }),
});
port.addEventListener('message', ({ data }) => {
if (data === 'unsubscribe') {
subscription.unsubscribe();
}
});
});
return [port2, [port2]];
},
deserialize: (port) => {
port.start();
return new Observable(observer => {
const setupRemoteObservable = () => {
Comlink.transferHandlers.set('OBSERVABLE', {
canHandle: (obj) => obj instanceof Observable,
serialize: (observable) => {
const { port1, port2 } = new MessageChannel();
port1.start();
port.postMessage('subscribe', [port2]);
const handleMessage = ({ data }) => {
if (data.next) {
observer.next(data.next);
port1.addEventListener('message', event => {
if (!(event.data === 'subscribe' && event.ports)) {
return;
}
else if (data.error) {
observer.error(data.error);
}
else if (data.complete) {
observer.complete();
}
};
port1.addEventListener('message', handleMessage);
return () => {
port1.removeEventListener('message', handleMessage);
port1.postMessage('unsubscribe');
};
});
},
});
const [port] = event.ports;
port.start();
const subscription = observable.subscribe({
next: next => { var _a; return port.postMessage({ next: Object.assign(Object.assign({}, next), { errors: ((_a = next.errors) === null || _a === void 0 ? void 0 : _a.map(objectifyError)) || undefined }) }); },
error: (error) => port.postMessage({ error }),
complete: () => port.postMessage({ complete: true }),
});
port.addEventListener('message', ({ data }) => {
if (data === 'unsubscribe') {
subscription.unsubscribe();
}
});
});
return [port2, [port2]];
},
deserialize: (port) => {
port.start();
return new Observable(observer => {
const { port1, port2 } = new MessageChannel();
port1.start();
port.postMessage('subscribe', [port2]);
const handleMessage = ({ data }) => {
if (data.next) {
observer.next(data.next);
}
else if (data.error) {
observer.error(data.error);
}
else if (data.complete) {
observer.complete();
}
};
port1.addEventListener('message', handleMessage);
return () => {
port1.removeEventListener('message', handleMessage);
port1.postMessage('unsubscribe');
};
});
},
});
};
export { setupRemoteObservable };
//# sourceMappingURL=RemoteObservable.js.map

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

export {};
export declare const setupRemoteOperation: () => void;

@@ -21,3 +21,7 @@ import { __rest } from 'tslib';

};
Comlink.transferHandlers.set('OPERATION', operationTransferHandler);
const setupRemoteOperation = () => {
Comlink.transferHandlers.set('OPERATION', operationTransferHandler);
};
export { setupRemoteOperation };
//# sourceMappingURL=RemoteOperation.js.map
{
"name": "@grapes-agency/apollo-link-webworker",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.9",
"description": "WebWorker for @apollo/client",

@@ -25,3 +25,3 @@ "main": "./dist/index.cjs.js",

},
"gitHead": "0aa9731f1e54b6eca1e7102a2ac009ee5d7d9d28"
"gitHead": "3d03e4e6cdd59fe4a3fcaf7f95441a7a63045e14"
}

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