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

worker-pouch

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-pouch - npm Package Compare versions

Comparing version 0.2.1 to 1.0.0

@@ -35,2 +35,4 @@ #!/usr/bin/env node

baseUrl = 'http://127.0.0.1:8000/test/index-suite4.html';
} else if (process.env.SUITE === '5') {
baseUrl = 'http://127.0.0.1:8000/test/index-suite5.html';
}

@@ -37,0 +39,0 @@ var testUrl = baseUrl + '?grep=3955%7Cclosure&invert=true';

@@ -9,3 +9,3 @@ 'use strict';

var preprocessAttachments = clientUtils.preprocessAttachments;
var stringifyArgs = clientUtils.stringifyArgs;
var encodeArgs = clientUtils.encodeArgs;
var adapterFun = clientUtils.adapterFun;

@@ -18,2 +18,7 @@ var isSupportedBrowser = require('./is-supported-browser');

worker = createWorker(require('../worker'));
worker.addEventListener('error', function (e) {
if ('console' in global && 'warn' in console) {
console.warn('worker threw an error', e.error);
}
});
} catch (e) {

@@ -102,3 +107,3 @@ if ('console' in global && 'info' in console) {

api._callbacks[messageId] = callback;
var stringArgs = stringifyArgs(args);
var encodedArgs = encodeArgs(args);
worker.postMessage({

@@ -108,3 +113,3 @@ id: api._instanceId,

messageId: messageId,
args: stringArgs
args: encodedArgs
});

@@ -116,3 +121,3 @@ log('message sent', api._instanceId, messageId);

log('send message', api._socketId, messageId, type, args);
var stringArgs = stringifyArgs(args);
var encodedArgs = encodeArgs(args);
worker.postMessage({

@@ -122,3 +127,3 @@ id: api._instanceId,

messageId: messageId,
args: stringArgs
args: encodedArgs
});

@@ -125,0 +130,0 @@ log('message sent', api._instanceId, messageId);

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

var isBrowser = typeof process === 'undefined' || process.browser;
var clone = require('../shared/pouchdb-clone');

@@ -31,22 +30,32 @@ exports.preprocessAttachments = function preprocessAttachments(doc) {

exports.stringifyArgs = function stringifyArgs(args) {
var funcArgs = ['filter', 'map', 'reduce'];
var funcsToRemove = ['onChange', 'processChange', 'complete'];
function encodeObjectArg(arg) {
// these can't be encoded by normal structured cloning
var funcKeys = ['filter', 'map', 'reduce'];
var keysToRemove = ['onChange', 'processChange', 'complete'];
var clonedArg = {};
Object.keys(arg).forEach(function (key) {
if (keysToRemove.indexOf(key) !== -1) {
return;
}
if (funcKeys.indexOf(key) !== -1 && typeof arg[key] === 'function') {
clonedArg[key] = {
type: 'func',
func: arg[key].toString()
};
} else {
clonedArg[key] = arg[key];
}
});
return clonedArg;
}
exports.encodeArgs = function encodeArgs(args) {
var result = [];
args.forEach(function (arg) {
arg = clone(arg);
if (arg !== null && typeof arg === 'object' && !Array.isArray(arg)) {
funcArgs.forEach(function (key) {
if (key in arg && typeof arg[key] === 'function') {
arg[key] = {
type: 'func',
func: arg[key].toString()
};
}
});
funcsToRemove.forEach(function (key) {
delete arg[key];
});
if (arg === null || typeof arg !== 'object' ||
Array.isArray(arg) || arg instanceof Blob || arg instanceof Date) {
result.push(arg);
} else {
result.push(encodeObjectArg(arg));
}
result.push(arg);
});

@@ -53,0 +62,0 @@ return result;

@@ -9,3 +9,3 @@ 'use strict';

var makePouchCreator = require('./make-pouch-creator');
var destringifyArgs = workerUtils.destringifyArgs;
var decodeArgs = workerUtils.decodeArgs;
var dbs = {};

@@ -234,11 +234,7 @@ var allChanges = {};

function parseMessage(message, clientId, pouchCreator) {
try {
var type = message.type;
var messageId = message.messageId;
var args = destringifyArgs(message.args);
onReceiveMessage(clientId, type, messageId, args, pouchCreator);
} catch (err) {
log('invalid message, ignoring', err);
}
function handleMessage(message, clientId, pouchCreator) {
var type = message.type;
var messageId = message.messageId;
var args = decodeArgs(message.args);
onReceiveMessage(clientId, type, messageId, args, pouchCreator);
}

@@ -255,4 +251,4 @@

} else {
parseMessage(event.data, clientId, pouchCreator);
handleMessage(event.data, clientId, pouchCreator);
}
};

@@ -30,3 +30,3 @@ 'use strict';

exports.destringifyArgs = function destringifyArgs(args) {
exports.decodeArgs = function decodeArgs(args) {
var funcArgs = ['filter', 'map', 'reduce'];

@@ -33,0 +33,0 @@ args.forEach(function (arg) {

{
"name": "worker-pouch",
"version": "0.2.1",
"version": "1.0.0",
"description": "PouchDB over a web worker",

@@ -40,3 +40,3 @@ "main": "lib/index.js",

"lie": "^2.6.0",
"pouchdb": "git://github.com/pouchdb/pouchdb#4402",
"pouchdb": "^5.0.0",
"pouchdb-binary-util": "^1.0.0",

@@ -43,0 +43,0 @@ "through2": "^2.0.0",

@@ -9,9 +9,9 @@ WorkerPouch (Beta) [![Build Status](https://travis-ci.org/nolanlawson/worker-pouch.svg)](https://travis-ci.org/nolanlawson/worker-pouch)

Plugin to use PouchDB over web workers. It transparently proxies all PouchDB API requests to a web worker, so that all IndexedDB and XHR operations are run in a separate thread. Supports Firefox and Chrome.
Plugin to use PouchDB over [web workers](https://developer.mozilla.org/en-US/docs/Web/API/Worker). Transparently proxies all PouchDB API requests to a web worker, so that the most expensive database operations are run in a separate thread. Supports Firefox and Chrome.
Basically, WorkerPouch allows you use the PouchDB API like you normally would, but your UI will experience less interruptions, because PouchDB's most expensive operations are run inside of a worker. You don't need to set up the worker yourself, because the script is loaded in a [Blob URL](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
Basically, WorkerPouch allows you use the PouchDB API like you normally would, but your UI will suffer fewer hiccups, because any blocking operations (such as IndexedDB, object cloning, or checksumming) are run inside of the worker. You don't even need to set up the worker yourself, because the script is loaded in a [Blob URL](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
WorkerPouch passes [the full PouchDB test suite](https://travis-ci.org/nolanlawson/socket-pouch). It requires PouchDB 5.0.0+.
IE, Edge, Safari, and iOS are not supported due to browser bugs. Luckily, Firefox and Chrome are the browsers that [benefit the most from web workers](http://nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/).
IE, Edge, Safari, and iOS are not supported due to browser bugs. Luckily, Firefox and Chrome are the browsers that [benefit the most from web workers](http://nolanlawson.com/2015/09/29/indexeddb-websql-localstorage-what-blocks-the-dom/). There is also an API to [detect browser support](#detecting-browser-support).

@@ -18,0 +18,0 @@ Usage

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 too big to display

Sorry, the diff of this file is too big to display

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 too big to display