worker-pouch
Advanced tools
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable and can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4418309
49
33961
2
0
2
24
+ Addedabbrev@1.1.1(transitive)
+ Addedabstract-leveldown@0.12.32.4.12.6.32.7.2(transitive)
+ Addedacorn@5.7.4(transitive)
+ Addedafter@0.8.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedansi@0.3.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedarray-index@1.0.0(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedast-types@0.9.6(transitive)
+ Addedasync@1.5.22.6.4(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.6.00.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbase62@1.2.8(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbindings@1.2.1(transitive)
+ Addedbl@1.1.21.2.33.0.1(transitive)
+ Addedblock-stream@0.0.9(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedbuffer-alloc@1.2.0(transitive)
+ Addedbuffer-alloc-unsafe@1.1.0(transitive)
+ Addedbuffer-fill@1.0.0(transitive)
+ Addedbuffer-from@0.1.2(transitive)
+ Addedcaseless@0.11.00.12.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedchownr@1.1.4(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcommoner@0.10.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addedd@1.0.2(transitive)
+ Addedd64@1.0.0(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.2.0(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddeferred-leveldown@1.2.2(transitive)
+ Addeddefined@1.0.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetective@4.7.1(transitive)
+ Addeddouble-ended-queue@2.0.0-0(transitive)
+ Addedduplexer2@0.0.2(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedend-stream@0.1.0(transitive)
+ Addederrno@0.1.40.1.8(transitive)
+ Addedes3ify@0.2.2(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-promise-pool@2.4.2(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedesprima@2.7.33.1.3(transitive)
+ Addedesprima-fb@15001.1.0-dev-harmony-fb(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedexecspawn@1.0.1(transitive)
+ Addedexpand-template@1.1.1(transitive)
+ Addedext@1.7.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-future@1.0.2(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@1.0.12.3.3(transitive)
+ Addedfruitdown@1.0.2(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedfunctional-red-black-tree@1.0.1(transitive)
+ Addedgauge@1.2.7(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedghreleases@1.0.7(transitive)
+ Addedghrepos@2.1.0(transitive)
+ Addedghutils@3.2.6(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedglob@5.0.157.2.3(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@2.0.65.1.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-localstorage@1.0.1(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.11.2.0(transitive)
+ Addedhumble-localstorage@1.4.2(transitive)
+ Addedhyperquest@2.1.3(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedimmediate@3.3.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.1(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjs-extend@0.0.1(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonist@2.1.2(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedjstransform@11.0.3(transitive)
+ Addedlevel-codec@6.1.0(transitive)
+ Addedlevel-errors@1.0.5(transitive)
+ Addedlevel-iterator-stream@1.3.1(transitive)
+ Addedlevel-write-stream@1.0.0(transitive)
+ Addedleveldown@1.4.6(transitive)
+ Addedlevelup@1.3.2(transitive)
+ Addedlie@3.0.4(transitive)
+ Addedlocalstorage-down@0.6.6(transitive)
+ Addedlocalstorage-memory@1.0.3(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.pad@4.5.1(transitive)
+ Addedlodash.padend@4.6.1(transitive)
+ Addedlodash.padstart@4.6.1(transitive)
+ Addedltgt@1.0.22.1.2(transitive)
+ Addedmemdown@1.1.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedms@0.7.1(transitive)
+ Addednan@2.3.52.7.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addednode-gyp@3.8.0(transitive)
+ Addednode-ninja@1.0.2(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addednoop-fn@1.0.0(transitive)
+ Addednoop-logger@0.1.1(transitive)
+ Addednopt@3.0.6(transitive)
+ Addednpmlog@2.0.4(transitive)
+ Addedoauth-sign@0.8.20.9.0(transitive)
+ Addedobject-assign@2.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedpath-array@1.0.1(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpouchdb@5.4.5(transitive)
+ Addedpouchdb-collate@1.2.0(transitive)
+ Addedpouchdb-collections@1.0.1(transitive)
+ Addedprebuild@4.5.0(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedprr@0.0.01.0.1(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpull-core@1.0.0(transitive)
+ Addedpull-stream@2.21.0(transitive)
+ Addedpump@1.0.3(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedq@1.5.1(transitive)
+ Addedqs@6.1.26.5.3(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@0.0.41.0.331.1.142.0.63.6.2(transitive)
+ Addedrecast@0.11.23(transitive)
+ Addedrequest@2.72.02.88.2(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedscope-eval@0.0.3(transitive)
+ Addedsemver@5.1.15.3.0(transitive)
+ Addedsimple-get@1.4.3(transitive)
+ Addedsimple-mime@0.1.0(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsource-map@0.4.4(transitive)
+ Addedspark-md5@2.0.2(transitive)
+ Addedsqlite3@3.1.13(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedsublevel-pouchdb@1.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtar@2.2.2(transitive)
+ Addedtar-fs@1.16.3(transitive)
+ Addedtar-stream@1.6.2(transitive)
+ Addedthrough2@2.0.1(transitive)
+ Addedtiny-queue@0.2.00.2.1(transitive)
+ Addedto-buffer@1.1.1(transitive)
+ Addedtough-cookie@2.2.22.5.0(transitive)
+ Addedtunnel-agent@0.4.30.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedunreachable-branch-transform@0.3.0(transitive)
+ Addedunzip-response@1.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedurl-template@2.0.8(transitive)
+ Addedutil-extend@1.0.3(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedvuvuzela@1.0.3(transitive)
+ Addedwebsql@0.4.4(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedwrite-stream@0.4.3(transitive)
+ Addedxtend@3.0.0(transitive)
Updatedpouchdb@^5.0.0