filter-pouch
Advanced tools
Comparing version 0.1.2 to 1.0.0
{ | ||
"name": "filter-pouch", | ||
"main": "dist/pouchdb.filter-pouch.js", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/nolanlawson/filter-pouch", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -5,2 +5,3 @@ ;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var utils = require('./pouch-utils'); | ||
var wrappers = require('pouchdb-wrappers'); | ||
@@ -16,6 +17,3 @@ function isUnfilterable(doc) { | ||
var incoming = function (doc) { | ||
if (isUnfilterable(doc)) { | ||
return doc; | ||
} | ||
if (config.incoming) { | ||
if (!isUnfilterable(doc) && config.incoming) { | ||
return config.incoming(utils.clone(doc)); | ||
@@ -26,6 +24,3 @@ } | ||
var outgoing = function (doc) { | ||
if (isUnfilterable(doc)) { | ||
return doc; | ||
} | ||
if (config.outgoing) { | ||
if (!isUnfilterable(doc) && config.outgoing) { | ||
return config.outgoing(utils.clone(doc)); | ||
@@ -36,30 +31,11 @@ } | ||
var handlers = {}; | ||
if (db.type() === 'http') { | ||
// | ||
// put | ||
// | ||
var origPut = db.put; | ||
db.put = utils.getArguments(function (args) { | ||
var doc = args[0]; | ||
doc = incoming(doc); | ||
args[0] = doc; | ||
return origPut.apply(db, args); | ||
}); | ||
// | ||
// query | ||
// | ||
var origQuery = db.query; | ||
db.query = utils.toPromise(function (fun, opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
/* istanbul ignore next */ | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.put = function (orig, args) { | ||
args.doc = incoming(args.doc); | ||
return orig(); | ||
}; | ||
handlers.query = function (orig) { | ||
return orig().then(function (res) { | ||
res.rows.forEach(function (row) { | ||
@@ -70,23 +46,10 @@ if (row.doc) { | ||
}); | ||
origCallback(null, res); | ||
}; | ||
origQuery.apply(db, [fun, opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
} | ||
// | ||
// get | ||
// | ||
var origGet = db.get; | ||
db.get = utils.toPromise(function (id, opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.get = function (orig) { | ||
return orig().then(function (res) { | ||
if (Array.isArray(res)) { | ||
@@ -102,41 +65,15 @@ // open_revs style, it's a list of docs | ||
} | ||
origCallback(null, res); | ||
}; | ||
origGet.apply(db, [id, opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
// | ||
// bulkDocs | ||
// | ||
var origBulkDocs = db.bulkDocs; | ||
db.bulkDocs = utils.getArguments(function (args) { | ||
var docsObj = args[0]; | ||
docsObj = Array.isArray(docsObj) ? docsObj.slice() : utils.clone(docsObj); | ||
var docs = Array.isArray(docsObj) ? docsObj : docsObj.docs; | ||
for (var i = 0; i < docs.length; i++) { | ||
docs[i] = incoming(docs[i]); | ||
handlers.bulkDocs = function (orig, args) { | ||
for (var i = 0; i < args.docs.length; i++) { | ||
args.docs[i] = incoming(args.docs[i]); | ||
} | ||
return orig(); | ||
}; | ||
args[0] = docsObj; | ||
return origBulkDocs.apply(db, args); | ||
}); | ||
// | ||
// allDocs | ||
// | ||
var origAllDocs = db.allDocs; | ||
db.allDocs = utils.toPromise(function (opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
/* istanbul ignore next */ | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.allDocs = function (orig) { | ||
return orig().then(function (res) { | ||
res.rows.forEach(function (row) { | ||
@@ -147,13 +84,7 @@ if (row.doc) { | ||
}); | ||
origCallback(null, res); | ||
}; | ||
origAllDocs.apply(db, [opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
// | ||
// changes | ||
// | ||
var origChanges = db.changes; | ||
db.changes = function (opts, callback) { | ||
handlers.changes = function (orig, args) { | ||
function modifyChange(change) { | ||
@@ -171,5 +102,5 @@ if (change.doc) { | ||
if (opts.complete) { | ||
var origComplete = opts.complete; | ||
opts.complete = function (err, res) { | ||
if (args.options.complete) { | ||
var origComplete = args.options.complete; | ||
args.options.complete = function (err, res) { | ||
/* istanbul ignore next */ | ||
@@ -183,4 +114,3 @@ if (err) { | ||
var changes = origChanges.apply(db, [opts, callback]); | ||
var changes = orig(); | ||
// override some events | ||
@@ -207,5 +137,5 @@ var origOn = changes.on; | ||
}; | ||
return changes; | ||
}; | ||
wrappers.installWrapperMethods(db, handlers); | ||
}; | ||
@@ -218,3 +148,3 @@ | ||
},{"./pouch-utils":23}],2:[function(require,module,exports){ | ||
},{"./pouch-utils":26,"pouchdb-wrappers":24}],2:[function(require,module,exports){ | ||
@@ -314,6 +244,6 @@ },{}],3:[function(require,module,exports){ | ||
var handlers = require('./handlers'); | ||
var noArray = reject(new TypeError('must be an array')); | ||
module.exports = function all(iterable) { | ||
module.exports = all; | ||
function all(iterable) { | ||
if (Object.prototype.toString.call(iterable) !== '[object Array]') { | ||
return noArray; | ||
return reject(new TypeError('must be an array')); | ||
} | ||
@@ -351,4 +281,4 @@ | ||
} | ||
}; | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":11,"./resolve":12}],7:[function(require,module,exports){ | ||
} | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":12,"./resolve":13}],7:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -399,3 +329,3 @@ var tryCatch = require('./tryCatch'); | ||
} | ||
},{"./resolveThenable":13,"./states":14,"./tryCatch":15}],8:[function(require,module,exports){ | ||
},{"./resolveThenable":14,"./states":15,"./tryCatch":16}],8:[function(require,module,exports){ | ||
module.exports = exports = require('./promise'); | ||
@@ -406,3 +336,4 @@ | ||
exports.all = require('./all'); | ||
},{"./all":6,"./promise":9,"./reject":11,"./resolve":12}],9:[function(require,module,exports){ | ||
exports.race = require('./race'); | ||
},{"./all":6,"./promise":9,"./race":11,"./reject":12,"./resolve":13}],9:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -453,3 +384,3 @@ | ||
},{"./INTERNAL":5,"./queueItem":10,"./resolveThenable":13,"./states":14,"./unwrap":16}],10:[function(require,module,exports){ | ||
},{"./INTERNAL":5,"./queueItem":10,"./resolveThenable":14,"./states":15,"./unwrap":17}],10:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -483,5 +414,46 @@ var handlers = require('./handlers'); | ||
}; | ||
},{"./handlers":7,"./unwrap":16}],11:[function(require,module,exports){ | ||
},{"./handlers":7,"./unwrap":17}],11:[function(require,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
var reject = require('./reject'); | ||
var resolve = require('./resolve'); | ||
var INTERNAL = require('./INTERNAL'); | ||
var handlers = require('./handlers'); | ||
module.exports = race; | ||
function race(iterable) { | ||
if (Object.prototype.toString.call(iterable) !== '[object Array]') { | ||
return reject(new TypeError('must be an array')); | ||
} | ||
var len = iterable.length; | ||
var called = false; | ||
if (!len) { | ||
return resolve([]); | ||
} | ||
var resolved = 0; | ||
var i = -1; | ||
var promise = new Promise(INTERNAL); | ||
while (++i < len) { | ||
resolver(iterable[i]); | ||
} | ||
return promise; | ||
function resolver(value) { | ||
resolve(value).then(function (response) { | ||
if (!called) { | ||
called = true; | ||
handlers.resolve(promise, response); | ||
} | ||
}, function (error) { | ||
if (!called) { | ||
called = true; | ||
handlers.reject(promise, error); | ||
} | ||
}); | ||
} | ||
} | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":12,"./resolve":13}],12:[function(require,module,exports){ | ||
'use strict'; | ||
var Promise = require('./promise'); | ||
@@ -496,3 +468,3 @@ var INTERNAL = require('./INTERNAL'); | ||
} | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9}],12:[function(require,module,exports){ | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9}],13:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -532,3 +504,3 @@ | ||
} | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9}],13:[function(require,module,exports){ | ||
},{"./INTERNAL":5,"./handlers":7,"./promise":9}],14:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -566,3 +538,3 @@ var handlers = require('./handlers'); | ||
exports.safely = safelyResolveThenable; | ||
},{"./handlers":7,"./tryCatch":15}],14:[function(require,module,exports){ | ||
},{"./handlers":7,"./tryCatch":16}],15:[function(require,module,exports){ | ||
// Lazy man's symbols for states | ||
@@ -573,3 +545,3 @@ | ||
exports.PENDING = ['PENDING']; | ||
},{}],15:[function(require,module,exports){ | ||
},{}],16:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -590,3 +562,3 @@ | ||
} | ||
},{}],16:[function(require,module,exports){ | ||
},{}],17:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -613,3 +585,3 @@ | ||
} | ||
},{"./handlers":7,"immediate":17}],17:[function(require,module,exports){ | ||
},{"./handlers":7,"immediate":18}],18:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -625,3 +597,4 @@ var types = [ | ||
var queue = []; | ||
function drainQueue() { | ||
//named nextTick for less confusing stack traces | ||
function nextTick() { | ||
draining = true; | ||
@@ -646,3 +619,3 @@ var i, oldQueue; | ||
if (types[i] && types[i].test && types[i].test()) { | ||
scheduleDrain = types[i].install(drainQueue); | ||
scheduleDrain = types[i].install(nextTick); | ||
break; | ||
@@ -657,3 +630,3 @@ } | ||
} | ||
},{"./messageChannel":18,"./mutation.js":19,"./nextTick":2,"./stateChange":20,"./timeout":21}],18:[function(require,module,exports){ | ||
},{"./messageChannel":19,"./mutation.js":20,"./nextTick":2,"./stateChange":21,"./timeout":22}],19:[function(require,module,exports){ | ||
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};'use strict'; | ||
@@ -677,3 +650,3 @@ | ||
}; | ||
},{}],19:[function(require,module,exports){ | ||
},{}],20:[function(require,module,exports){ | ||
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};'use strict'; | ||
@@ -701,3 +674,3 @@ //based off rsvp https://github.com/tildeio/rsvp.js | ||
}; | ||
},{}],20:[function(require,module,exports){ | ||
},{}],21:[function(require,module,exports){ | ||
var global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};'use strict'; | ||
@@ -727,3 +700,3 @@ | ||
}; | ||
},{}],21:[function(require,module,exports){ | ||
},{}],22:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -739,3 +712,3 @@ exports.test = function () { | ||
}; | ||
},{}],22:[function(require,module,exports){ | ||
},{}],23:[function(require,module,exports){ | ||
"use strict"; | ||
@@ -812,7 +785,29 @@ | ||
function extend() { | ||
// originally extend() was recursive, but this ended up giving us | ||
// "call stack exceeded", so it's been unrolled to use a literal stack | ||
// (see https://github.com/pouchdb/pouchdb/issues/2543) | ||
var stack = []; | ||
var i = -1; | ||
var len = arguments.length; | ||
var args = new Array(len); | ||
while (++i < len) { | ||
args[i] = arguments[i]; | ||
} | ||
var container = {}; | ||
stack.push({args: args, result: {container: container, key: 'key'}}); | ||
var next; | ||
while ((next = stack.pop())) { | ||
extendInner(stack, next.args, next.result); | ||
} | ||
return container.key; | ||
} | ||
function extendInner(stack, args, result) { | ||
var options, name, src, copy, copyIsArray, clone, | ||
target = arguments[0] || {}, | ||
target = args[0] || {}, | ||
i = 1, | ||
length = arguments.length, | ||
deep = false; | ||
length = args.length, | ||
deep = false, | ||
numericStringRegex = /\d+/, | ||
optionsIsArray; | ||
@@ -822,3 +817,3 @@ // Handle a deep copy situation | ||
deep = target; | ||
target = arguments[1] || {}; | ||
target = args[1] || {}; | ||
// skip the boolean and the target | ||
@@ -842,3 +837,4 @@ i = 2; | ||
// Only deal with non-null/undefined values | ||
if ((options = arguments[i]) != null) { | ||
if ((options = args[i]) != null) { | ||
optionsIsArray = isArray(options); | ||
// Extend the base object | ||
@@ -848,2 +844,5 @@ for (name in options) { | ||
if (!(name in Object.prototype)) { | ||
if (optionsIsArray && !numericStringRegex.test(name)) { | ||
continue; | ||
} | ||
@@ -870,3 +869,9 @@ src = target[name]; | ||
// Never move original objects, clone them | ||
target[name] = extend(deep, clone, copy); | ||
stack.push({ | ||
args: [deep, clone, copy], | ||
result: { | ||
container: target, | ||
key: name | ||
} | ||
}); | ||
@@ -884,4 +889,5 @@ // Don't bring in undefined values | ||
// Return the modified object | ||
return target; | ||
// "Return" the modified object by setting the key | ||
// on the given container | ||
result.container[result.key] = target; | ||
} | ||
@@ -894,3 +900,517 @@ | ||
},{}],23:[function(require,module,exports){ | ||
},{}],24:[function(require,module,exports){ | ||
/* | ||
Copyright 2014, Marten de Vries | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
"use strict"; | ||
var nodify = require("promise-nodify"); | ||
exports.installStaticWrapperMethods = function (PouchDB, handlers) { | ||
//set an 'alternative constructor' so the constructor can be easily | ||
//wrapped, since wrapping 'real' constructors is hard. | ||
PouchDB["new"] = PouchDB["new"] || function (name, options, callback) { | ||
return new PouchDB(name, options, callback); | ||
}; | ||
installWrappers(PouchDB, handlers, exports.createStaticWrapperMethod); | ||
}; | ||
exports.installWrapperMethods = function (db, handlers) { | ||
installWrappers(db, handlers, exports.createWrapperMethod); | ||
}; | ||
function installWrappers(base, handlers, createWrapperMethod) { | ||
for (var name in handlers) { | ||
if (!handlers.hasOwnProperty(name)) { | ||
continue; | ||
} | ||
var info = getBaseAndName(base, name); | ||
var original = info.base[info.name]; | ||
if (!original) { | ||
//no method to wrap | ||
continue; | ||
} | ||
if (original.hasOwnProperty("_handlers")) { | ||
if (original._handlers.indexOf(handlers[name]) !== -1) { | ||
throw new Error("Wrapper method for '" + name + "' already installed: " + handlers[name]); | ||
} | ||
original._handlers.push(handlers[name]); | ||
} else { | ||
info.base[info.name] = createWrapperMethod(name, original, handlers[name], base); | ||
} | ||
} | ||
} | ||
function getBaseAndName(base, name) { | ||
name = name.split("."); | ||
while (name.length > 1) { | ||
base = base[name.shift(0)]; | ||
} | ||
return { | ||
base: base, | ||
name: name[0] | ||
}; | ||
} | ||
exports.createStaticWrapperMethod = function (name, original, handler, PouchDB) { | ||
//PouchDB is optional | ||
return createWrapper(name, original, handler, staticWrapperBuilders, PouchDB); | ||
}; | ||
exports.createWrapperMethod = function (name, original, handler, db) { | ||
//db is optional | ||
return createWrapper(name, original, handler, wrapperBuilders, db); | ||
}; | ||
function createWrapper(name, original, handler, theWrapperBuilders, thisVal) { | ||
//thisVal is optional | ||
var buildWrapper = theWrapperBuilders[name]; | ||
if (typeof createWrapper === "undefined") { | ||
throw new Error("No known wrapper for method name: " + name); //coverage: ignore | ||
} | ||
var handlers = [handler]; | ||
var wrapper = buildWrapper(thisVal, original, handlers); | ||
wrapper._original = original; | ||
wrapper._handlers = handlers; | ||
return wrapper; | ||
} | ||
var wrapperBuilders = {}; | ||
wrapperBuilders.destroy = function (db, destroy, handlers) { | ||
return function (options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCall(destroy)); | ||
}; | ||
}; | ||
wrapperBuilders.put = function (db, put, handlers) { | ||
return function (doc, docId, docRev, options, callback) { | ||
var args = {}; | ||
args.base = db || this; | ||
args.db = db || this; //backwards compatibility | ||
var argsList = Array.prototype.slice.call(arguments); | ||
//parsing code borrowed from PouchDB (adapted). | ||
args.doc = argsList.shift(); | ||
var id = '_id' in args.doc; | ||
while (true) { | ||
var temp = argsList.shift(); | ||
var temptype = typeof temp; | ||
if (temptype === "string" && !id) { | ||
args.doc._id = temp; | ||
id = true; | ||
} else if (temptype === "string" && id && !('_rev' in args.doc)) { | ||
args.doc._rev = temp; | ||
} else if (temptype === "object") { | ||
args.options = temp; | ||
} else if (temptype === "function") { | ||
args.callback = temp; | ||
} | ||
if (!argsList.length) { | ||
break; | ||
} | ||
} | ||
args.options = args.options || {}; | ||
return callHandlers(handlers, args, function () { | ||
return put.call(this, args.doc, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.post = function (db, post, handlers) { | ||
return function (doc, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.doc = doc; | ||
return callHandlers(handlers, args, function () { | ||
return post.call(this, args.doc, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.get = function (db, get, handlers) { | ||
return function(docId, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.docId = docId; | ||
return callHandlers(handlers, args, function () { | ||
return get.call(this, args.docId, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.remove = function (db, remove, handlers) { | ||
return function (docOrId, optsOrRev, opts, callback) { | ||
var args; | ||
//originally borrowed from PouchDB | ||
if (typeof optsOrRev === 'string') { | ||
// id, rev, opts, callback style | ||
args = parseBaseArgs(db, this, opts, callback); | ||
args.doc = { | ||
_id: docOrId, | ||
_rev: optsOrRev | ||
}; | ||
} else { | ||
// doc, opts, callback style | ||
args = parseBaseArgs(db, this, optsOrRev, opts); | ||
args.doc = docOrId; | ||
} | ||
return callHandlers(handlers, args, function () { | ||
return remove.call(this, args.doc, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.bulkDocs = function (db, bulkDocs, handlers) { | ||
return function (docs, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
//support the deprecated signature. | ||
args.docs = docs.docs || docs; | ||
return callHandlers(handlers, args, function () { | ||
return bulkDocs.call(this, args.docs, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.allDocs = function (db, allDocs, handlers) { | ||
return function (options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCallWithOptions(allDocs, args)); | ||
}; | ||
}; | ||
wrapperBuilders.changes = function (db, changes, handlers) { | ||
return function (options, callback) { | ||
//the callback argument is no longer documented. (And deprecated?) | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCallWithOptions(changes, args)); | ||
}; | ||
}; | ||
wrapperBuilders.sync = function (db, replicate, handlers) { | ||
return function (url, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.url = url; | ||
return callHandlers(handlers, args, function () { | ||
return replicate.call(this, args.url, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders["replicate.from"] = wrapperBuilders.sync; | ||
wrapperBuilders["replicate.to"] = wrapperBuilders.sync; | ||
wrapperBuilders.putAttachment = function (db, putAttachment, handlers) { | ||
return function (docId, attachmentId, rev, doc, type, options, callback) { | ||
//options is not an 'official' argument. But some plug-ins need it | ||
//and maybe (?) also the http adapter. | ||
//valid calls: | ||
//- "id", "aid", "rev", new Blob(), "text/plain", {}, function () {} | ||
//- "id", "aid", new Blob(), "text/plain", {}, function () {} | ||
//- "id", "aid", new Blob(), "text/plain" | ||
var args; | ||
if (typeof type === "string") { | ||
//rev is specified | ||
args = parseBaseArgs(db, this, options, callback); | ||
args.rev = rev; | ||
args.doc = doc; | ||
args.type = type; | ||
} else { | ||
//rev is unspecified | ||
args = parseBaseArgs(db, this, type, options); | ||
args.rev = null; | ||
args.doc = rev; | ||
args.type = doc; | ||
} | ||
//fixed arguments | ||
args.docId = docId; | ||
args.attachmentId = attachmentId; | ||
return callHandlers(handlers, args, function () { | ||
return putAttachment.call(this, args.docId, args.attachmentId, args.rev, args.doc, args.type); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.getAttachment = function (db, getAttachment, handlers) { | ||
return function (docId, attachmentId, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.docId = docId; | ||
args.attachmentId = attachmentId; | ||
return callHandlers(handlers, args, function () { | ||
return getAttachment.call(this, args.docId, args.attachmentId, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.removeAttachment = function (db, removeAttachment, handlers) { | ||
return function (docId, attachmentId, rev, options, callback) { | ||
//see note on the options argument at putAttachment. | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.docId = docId; | ||
args.attachmentId = attachmentId; | ||
args.rev = rev; | ||
return callHandlers(handlers, args, function () { | ||
return removeAttachment.call(this, args.docId, args.attachmentId, args.rev); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.query = function (db, query, handlers) { | ||
return function (fun, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.fun = fun; | ||
return callHandlers(handlers, args, function () { | ||
return query.call(this, args.fun, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.viewCleanup = function (db, viewCleanup, handlers) { | ||
return function (options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCallWithOptions(viewCleanup, args)); | ||
}; | ||
}; | ||
wrapperBuilders.info = function (db, info, handlers) { | ||
return function (options, callback) { | ||
//see note on the options argument at putAttachment. | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCall(info)); | ||
}; | ||
}; | ||
wrapperBuilders.compact = function (db, compact, handlers) { | ||
return function (options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCallWithOptions(compact, args)); | ||
}; | ||
}; | ||
wrapperBuilders.revsDiff = function (db, revsDiff, handlers) { | ||
return function (diff, options, callback) { | ||
//see note on the options argument at putAttachment. | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.diff = diff; | ||
return callHandlers(handlers, args, function () { | ||
return revsDiff.call(this, args.diff); | ||
}); | ||
}; | ||
}; | ||
//Plug-in wrapperBuilders; only of the plug-ins for which a wrapper | ||
//has been necessary. | ||
wrapperBuilders.list = function (db, orig, handlers) { | ||
return function (path, options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.path = path; | ||
return callHandlers(handlers, args, function () { | ||
return orig.call(this, args.path, args.options); | ||
}); | ||
}; | ||
}; | ||
wrapperBuilders.rewriteResultRequestObject = wrapperBuilders.list; | ||
wrapperBuilders.show = wrapperBuilders.list; | ||
wrapperBuilders.update = wrapperBuilders.list; | ||
wrapperBuilders.getSecurity = function (db, getSecurity, handlers) { | ||
return function (options, callback) { | ||
var args = parseBaseArgs(db, this, options, callback); | ||
return callHandlers(handlers, args, makeCallWithOptions(getSecurity, args)); | ||
}; | ||
}; | ||
wrapperBuilders.putSecurity = function (db, putSecurity, handlers) { | ||
return function (secObj, options, callback) { | ||
//see note on the options argument at putAttachment. | ||
var args = parseBaseArgs(db, this, options, callback); | ||
args.secObj = secObj; | ||
return callHandlers(handlers, args, function () { | ||
return putSecurity.call(this, args.secObj); | ||
}); | ||
}; | ||
}; | ||
//static | ||
var staticWrapperBuilders = {}; | ||
staticWrapperBuilders["new"] = function (PouchDB, construct, handlers) { | ||
return function (name, options, callback) { | ||
var args; | ||
if (typeof name === "object") { | ||
args = parseBaseArgs(PouchDB, this, name, options); | ||
} else { | ||
args = parseBaseArgs(PouchDB, this, options, callback); | ||
args.options.name = name; | ||
} | ||
return callHandlers(handlers, args, function () { | ||
return construct.call(this, args.options); | ||
}); | ||
}; | ||
}; | ||
staticWrapperBuilders.destroy = function (PouchDB, destroy, handlers) { | ||
return function (name, options, callback) { | ||
var args; | ||
if (typeof name === "object") { | ||
args = parseBaseArgs(PouchDB, this, name, options); | ||
} else { | ||
args = parseBaseArgs(PouchDB, this, options, callback); | ||
args.options.name = name; | ||
} | ||
return callHandlers(handlers, args, function () { | ||
var name = args.options.name; | ||
delete args.options.name; | ||
return destroy.call(this, name, args.options); | ||
}); | ||
}; | ||
}; | ||
staticWrapperBuilders.replicate = function (PouchDB, replicate, handlers) { | ||
return function (source, target, options) { | ||
//no callback | ||
var args = parseBaseArgs(PouchDB, this, options); | ||
args.source = source; | ||
args.target = target; | ||
return callHandlers(handlers, args, function () { | ||
return replicate.call(this, args.source, args.target, args.options); | ||
}); | ||
}; | ||
}; | ||
//Wrap .plugin()? .on()? .defaults()? No use case yet, but it's | ||
//possible... | ||
function parseBaseArgs(thisVal1, thisVal2, options, callback) { | ||
if (typeof options === "function") { | ||
callback = options; | ||
options = {}; | ||
} | ||
return { | ||
base: thisVal1 || thisVal2, | ||
db: thisVal1 || thisVal2, //backwards compatibility | ||
options: options || {}, | ||
callback: callback | ||
}; | ||
} | ||
function callHandlers(handlers, args, method) { | ||
var callback = args.callback; | ||
delete args.callback; | ||
//build a chain of handlers: the bottom handler calls the 'real' | ||
//method, the other handlers call other handlers. | ||
method = method.bind(args.base); | ||
for (var i = handlers.length - 1; i >= 0; i -= 1) { | ||
method = handlers[i].bind(null, method, args); | ||
} | ||
//start running the chain. | ||
var promise = method(); | ||
nodify(promise, callback); | ||
return promise; | ||
} | ||
function makeCall(func) { | ||
return function () { | ||
return func.call(this); | ||
}; | ||
} | ||
function makeCallWithOptions(func, args) { | ||
return function () { | ||
return func.call(this, args.options); | ||
}; | ||
} | ||
exports.uninstallWrapperMethods = function (db, handlers) { | ||
uninstallWrappers(db, handlers); | ||
}; | ||
exports.uninstallStaticWrapperMethods = function (PouchDB, handlers) { | ||
uninstallWrappers(PouchDB, handlers); | ||
}; | ||
function uninstallWrappers(base, handlers) { | ||
for (var name in handlers) { | ||
if (!handlers.hasOwnProperty(name)) { | ||
continue; | ||
} | ||
var info = getBaseAndName(base, name); | ||
var wrapper = info.base[info.name]; | ||
if (typeof wrapper === "undefined") { | ||
//method doesn't exist, so was never wrapped in the first place. | ||
continue; | ||
} | ||
var idx; | ||
try { | ||
idx = wrapper._handlers.indexOf(handlers[name]); | ||
} catch (err) { | ||
idx = -1; | ||
} | ||
if (idx === -1) { | ||
throw new Error("Wrapper method for '" + name + "' not installed: " + handlers[name]); | ||
} | ||
wrapper._handlers.splice(idx, 1); | ||
if (!wrapper._handlers.length) { | ||
//fall back to the original on the prototype. | ||
delete info.base[info.name]; | ||
if (info.base[info.name] !== wrapper._original) { | ||
//nothing or something unexpected was on the prototype. (E.g. | ||
//replicate.to). Reset the original manually. | ||
info.base[info.name] = wrapper._original; | ||
} | ||
} | ||
} | ||
} | ||
},{"promise-nodify":25}],25:[function(require,module,exports){ | ||
/* | ||
Copyright 2013-2014, Marten de Vries | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
"use strict"; | ||
module.exports = function nodify(promise, callback) { | ||
if (typeof callback === "function") { | ||
promise.then(function (resp) { | ||
callback(null, resp); | ||
}, function (err) { | ||
callback(err, null); | ||
}); | ||
} | ||
}; | ||
},{}],26:[function(require,module,exports){ | ||
var process=require("__browserify_process"),global=typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};'use strict'; | ||
@@ -987,3 +1507,3 @@ | ||
}; | ||
},{"__browserify_process":3,"inherits":4,"lie":8,"pouchdb-extend":22}]},{},[1]) | ||
},{"__browserify_process":3,"inherits":4,"lie":8,"pouchdb-extend":23}]},{},[1]) | ||
; |
@@ -1,1 +0,1 @@ | ||
!function e(t,n,r){function o(u,c){if(!n[u]){if(!t[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=n[u]={exports:{}};t[u][0].call(a.exports,function(e){var n=t[u][1][e];return o(n?n:e)},a,a.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){"use strict";function r(e){var t="string"==typeof e._id&&o.isLocalId(e._id);return t||e._deleted}var o=e("./pouch-utils");n.filter=function(e){var t=this,n=function(t){return r(t)?t:e.incoming?e.incoming(o.clone(t)):t},i=function(t){return r(t)?t:e.outgoing?e.outgoing(o.clone(t)):t};if("http"===t.type()){var u=t.put;t.put=o.getArguments(function(e){var r=e[0];return r=n(r),e[0]=r,u.apply(t,e)});var c=t.query;t.query=o.toPromise(function(e,n,r){"function"==typeof n&&(r=n,n={});var o=function(e,t){return e?r(e):(t.rows.forEach(function(e){e.doc&&(e.doc=i(e.doc))}),void r(null,t))};c.apply(t,[e,n,o])})}var s=t.get;t.get=o.toPromise(function(e,n,r){"function"==typeof n&&(r=n,n={});var o=function(e,t){return e?r(e):(Array.isArray(t)?t.forEach(function(e){e.ok&&(e.ok=i(e.ok))}):t=i(t),void r(null,t))};s.apply(t,[e,n,o])});var a=t.bulkDocs;t.bulkDocs=o.getArguments(function(e){var r=e[0];r=Array.isArray(r)?r.slice():o.clone(r);for(var i=Array.isArray(r)?r:r.docs,u=0;u<i.length;u++)i[u]=n(i[u]);return e[0]=r,a.apply(t,e)});var f=t.allDocs;t.allDocs=o.toPromise(function(e,n){"function"==typeof e&&(n=e,e={});var r=function(e,t){return e?n(e):(t.rows.forEach(function(e){e.doc&&(e.doc=i(e.doc))}),void n(null,t))};f.apply(t,[e,r])});var l=t.changes;t.changes=function(e,n){function r(e){return e.doc&&(e.doc=i(e.doc)),e}function o(e){return e.results=e.results.map(r),e}if(e.complete){var u=e.complete;e.complete=function(e,t){return e?u(e):void u(null,o(t))}}var c=l.apply(t,[e,n]),s=c.on;c.on=function(e,t){return"change"===e?s.apply(c,[e,function(e){t(r(e))}]):"complete"===e?s.apply(c,[e,function(e){t(o(e))}]):s.apply(c,[e,t])};var a=c.then;return c.then=function(e,t){return a.apply(c,[function(t){e(o(t))},t])},c}},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{"./pouch-utils":23}],2:[function(){},{}],3:[function(e,t){var n=t.exports={};n.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(e,t){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],5:[function(e,t){"use strict";function n(){}t.exports=n},{}],6:[function(e,t){"use strict";var n=e("./promise"),r=e("./reject"),o=e("./resolve"),i=e("./INTERNAL"),u=e("./handlers"),c=r(new TypeError("must be an array"));t.exports=function(e){function t(e,t){function n(e){a[t]=e,++f===r&!s&&(s=!0,u.resolve(p,a))}o(e).then(n,function(e){s||(s=!0,u.reject(p,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return c;var r=e.length,s=!1;if(!r)return o([]);for(var a=new Array(r),f=0,l=-1,p=new n(i);++l<r;)t(e[l],l);return p}},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":11,"./resolve":12}],7:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e("./tryCatch"),i=e("./resolveThenable"),u=e("./states");n.resolve=function(e,t){var c=o(r,t);if("error"===c.status)return n.reject(e,c.value);var s=c.value;if(s)i.safely(e,s);else{e.state=u.FULFILLED,e.outcome=t;for(var a=-1,f=e.queue.length;++a<f;)e.queue[a].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{"./resolveThenable":13,"./states":14,"./tryCatch":15}],8:[function(e,t,n){t.exports=n=e("./promise"),n.resolve=e("./resolve"),n.reject=e("./reject"),n.all=e("./all")},{"./all":6,"./promise":9,"./reject":11,"./resolve":12}],9:[function(e,t){"use strict";function n(e){if(!(this instanceof n))return new n(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=u.PENDING,this.queue=[],this.outcome=void 0,e!==o&&i.safely(this,e)}var r=e("./unwrap"),o=e("./INTERNAL"),i=e("./resolveThenable"),u=e("./states"),c=e("./queueItem");t.exports=n,n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(e,t){if("function"!=typeof e&&this.state===u.FULFILLED||"function"!=typeof t&&this.state===u.REJECTED)return this;var i=new n(o);if(this.state!==u.PENDING){var s=this.state===u.FULFILLED?e:t;r(i,s,this.outcome)}else this.queue.push(new c(i,e,t));return i}},{"./INTERNAL":5,"./queueItem":10,"./resolveThenable":13,"./states":14,"./unwrap":16}],10:[function(e,t){"use strict";function n(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var r=e("./handlers"),o=e("./unwrap");t.exports=n,n.prototype.callFulfilled=function(e){r.resolve(this.promise,e)},n.prototype.otherCallFulfilled=function(e){o(this.promise,this.onFulfilled,e)},n.prototype.callRejected=function(e){r.reject(this.promise,e)},n.prototype.otherCallRejected=function(e){o(this.promise,this.onRejected,e)}},{"./handlers":7,"./unwrap":16}],11:[function(e,t){"use strict";function n(e){var t=new r(o);return i.reject(t,e)}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n},{"./INTERNAL":5,"./handlers":7,"./promise":9}],12:[function(e,t){"use strict";function n(e){if(e)return e instanceof r?e:i.resolve(new r(o),e);var t=typeof e;switch(t){case"boolean":return u;case"undefined":return s;case"object":return c;case"number":return a;case"string":return f}}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n;var u=i.resolve(new r(o),!1),c=i.resolve(new r(o),null),s=i.resolve(new r(o),void 0),a=i.resolve(new r(o),0),f=i.resolve(new r(o),"")},{"./INTERNAL":5,"./handlers":7,"./promise":9}],13:[function(e,t,n){"use strict";function r(e,t){function n(t){c||(c=!0,o.reject(e,t))}function r(t){c||(c=!0,o.resolve(e,t))}function u(){t(r,n)}var c=!1,s=i(u);"error"===s.status&&n(s.value)}var o=e("./handlers"),i=e("./tryCatch");n.safely=r},{"./handlers":7,"./tryCatch":15}],14:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],15:[function(e,t){"use strict";function n(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=n},{}],16:[function(e,t){"use strict";function n(e,t,n){r(function(){var r;try{r=t(n)}catch(i){return o.reject(e,i)}r===e?o.reject(e,new TypeError("Cannot resolve promise with itself")):o.resolve(e,r)})}var r=e("immediate"),o=e("./handlers");t.exports=n},{"./handlers":7,immediate:17}],17:[function(e,t){"use strict";function n(){o=!0;for(var e,t,n=c.length;n;){for(t=c,c=[],e=-1;++e<n;)t[e]();n=c.length}o=!1}function r(e){1!==c.push(e)||o||i()}for(var o,i,u=[e("./nextTick"),e("./mutation.js"),e("./messageChannel"),e("./stateChange"),e("./timeout")],c=[],s=-1,a=u.length;++s<a;)if(u[s]&&u[s].test&&u[s].test()){i=u[s].install(n);break}t.exports=r},{"./messageChannel":18,"./mutation.js":19,"./nextTick":2,"./stateChange":20,"./timeout":21}],18:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n.test=function(){return r.setImmediate?!1:"undefined"!=typeof r.MessageChannel},n.install=function(e){var t=new r.MessageChannel;return t.port1.onmessage=e,function(){t.port2.postMessage(0)}}},{}],19:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{},o=r.MutationObserver||r.WebKitMutationObserver;n.test=function(){return o},n.install=function(e){var t=0,n=new o(e),i=r.document.createTextNode("");return n.observe(i,{characterData:!0}),function(){i.data=t=++t%2}}},{}],20:[function(e,t,n){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};n.test=function(){return"document"in r&&"onreadystatechange"in r.document.createElement("script")},n.install=function(e){return function(){var t=r.document.createElement("script");return t.onreadystatechange=function(){e(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},r.document.documentElement.appendChild(t),e}}},{}],21:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],22:[function(e,t){"use strict";function n(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?c[l.call(e)]||"object":typeof e}function r(e){return null!==e&&e===e.window}function o(e){if(!e||"object"!==n(e)||e.nodeType||r(e))return!1;try{if(e.constructor&&!p.call(e,"constructor")&&!p.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var o;for(o in e);return void 0===o||p.call(e,o)}function i(e){return"function"===n(e)}function u(){var e,t,n,r,c,s,a=arguments[0]||{},f=1,l=arguments.length,p=!1;for("boolean"==typeof a&&(p=a,a=arguments[1]||{},f=2),"object"==typeof a||i(a)||(a={}),l===f&&(a=this,--f);l>f;f++)if(null!=(e=arguments[f]))for(t in e)if(!(t in Object.prototype)){if(n=a[t],r=e[t],a===r)continue;p&&r&&(o(r)||(c=d(r)))?(c?(c=!1,s=n&&d(n)?n:[]):s=n&&o(n)?n:{},a[t]=u(p,s,r)):void 0!==r&&(d(e)&&i(r)||(a[t]=r))}return a}for(var c={},s=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],a=0;a<s.length;a++){var f=s[a];c["[object "+f+"]"]=f.toLowerCase()}var l=c.toString,p=c.hasOwnProperty,d=Array.isArray||function(e){return"array"===n(e)};t.exports=u},{}],23:[function(e,t,n){var r,o=e("__browserify_process"),i="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};r="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof i.Promise?i.Promise:e("lie"),n.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw console.trace(),new Error("once called more than once");t=!0,e.apply(this,n)})},n.getArguments=function(e){return function(){for(var t=arguments.length,n=new Array(t),r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}},n.toPromise=function(e){return n.getArguments(function(t){var i,u=this,c="function"==typeof t[t.length-1]?t.pop():!1;c&&(i=function(e,t){o.nextTick(function(){c(e,t)})});var s=new r(function(r,o){try{var i=n.once(function(e,t){e?o(e):r(t)});t.push(i),e.apply(u,t)}catch(c){o(c)}});return i&&s.then(function(e){i(null,e)},i),s.cancel=function(){return this},s})},n.inherits=e("inherits"),n.Promise=r,n.extend=e("pouchdb-extend"),n.clone=function(e){return n.extend(!0,{},e)},n.isLocalId=function(e){return/^_local/.test(e)}},{__browserify_process:3,inherits:4,lie:8,"pouchdb-extend":22}]},{},[1]); | ||
!function t(n,e,r){function o(u,c){if(!e[u]){if(!n[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=e[u]={exports:{}};n[u][0].call(a.exports,function(t){var e=n[u][1][t];return o(e?e:t)},a,a.exports,t,n,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(t,n,e){"use strict";function r(t){var n="string"==typeof t._id&&o.isLocalId(t._id);return n||t._deleted}var o=t("./pouch-utils"),i=t("pouchdb-wrappers");e.filter=function(t){var n=this,e=function(n){return!r(n)&&t.incoming?t.incoming(o.clone(n)):n},u=function(n){return!r(n)&&t.outgoing?t.outgoing(o.clone(n)):n},c={};"http"===n.type()&&(c.put=function(t,n){return n.doc=e(n.doc),t()},c.query=function(t){return t().then(function(t){return t.rows.forEach(function(t){t.doc&&(t.doc=u(t.doc))}),t})}),c.get=function(t){return t().then(function(t){return Array.isArray(t)?t.forEach(function(t){t.ok&&(t.ok=u(t.ok))}):t=u(t),t})},c.bulkDocs=function(t,n){for(var r=0;r<n.docs.length;r++)n.docs[r]=e(n.docs[r]);return t()},c.allDocs=function(t){return t().then(function(t){return t.rows.forEach(function(t){t.doc&&(t.doc=u(t.doc))}),t})},c.changes=function(t,n){function e(t){return t.doc&&(t.doc=u(t.doc)),t}function r(t){return t.results=t.results.map(e),t}if(n.options.complete){var o=n.options.complete;n.options.complete=function(t,n){return t?o(t):void o(null,r(n))}}var i=t(),c=i.on;i.on=function(t,n){return"change"===t?c.apply(i,[t,function(t){n(e(t))}]):"complete"===t?c.apply(i,[t,function(t){n(r(t))}]):c.apply(i,[t,n])};var s=i.then;return i.then=function(t,n){return s.apply(i,[function(n){t(r(n))},n])},i},i.installWrapperMethods(n,c)},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(e)},{"./pouch-utils":26,"pouchdb-wrappers":24}],2:[function(){},{}],3:[function(t,n){var e=n.exports={};e.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(n){var e=[];return window.addEventListener("message",function(t){var n=t.source;if((n===window||null===n)&&"process-tick"===t.data&&(t.stopPropagation(),e.length>0)){var r=e.shift();r()}},!0),function(t){e.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.binding=function(){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(t,n){n.exports="function"==typeof Object.create?function(t,n){t.super_=n,t.prototype=Object.create(n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:function(t,n){t.super_=n;var e=function(){};e.prototype=n.prototype,t.prototype=new e,t.prototype.constructor=t}},{}],5:[function(t,n){"use strict";function e(){}n.exports=e},{}],6:[function(t,n){"use strict";function e(t){function n(t,n){function r(t){a[n]=t,++f===e&!s&&(s=!0,c.resolve(p,a))}i(t).then(r,function(t){s||(s=!0,c.reject(p,t))})}if("[object Array]"!==Object.prototype.toString.call(t))return o(new TypeError("must be an array"));var e=t.length,s=!1;if(!e)return i([]);for(var a=new Array(e),f=0,l=-1,p=new r(u);++l<e;)n(t[l],l);return p}var r=t("./promise"),o=t("./reject"),i=t("./resolve"),u=t("./INTERNAL"),c=t("./handlers");n.exports=e},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":12,"./resolve":13}],7:[function(t,n,e){"use strict";function r(t){var n=t&&t.then;return t&&"object"==typeof t&&"function"==typeof n?function(){n.apply(t,arguments)}:void 0}var o=t("./tryCatch"),i=t("./resolveThenable"),u=t("./states");e.resolve=function(t,n){var c=o(r,n);if("error"===c.status)return e.reject(t,c.value);var s=c.value;if(s)i.safely(t,s);else{t.state=u.FULFILLED,t.outcome=n;for(var a=-1,f=t.queue.length;++a<f;)t.queue[a].callFulfilled(n)}return t},e.reject=function(t,n){t.state=u.REJECTED,t.outcome=n;for(var e=-1,r=t.queue.length;++e<r;)t.queue[e].callRejected(n);return t}},{"./resolveThenable":14,"./states":15,"./tryCatch":16}],8:[function(t,n,e){n.exports=e=t("./promise"),e.resolve=t("./resolve"),e.reject=t("./reject"),e.all=t("./all"),e.race=t("./race")},{"./all":6,"./promise":9,"./race":11,"./reject":12,"./resolve":13}],9:[function(t,n){"use strict";function e(t){if(!(this instanceof e))return new e(t);if("function"!=typeof t)throw new TypeError("reslover must be a function");this.state=u.PENDING,this.queue=[],this.outcome=void 0,t!==o&&i.safely(this,t)}var r=t("./unwrap"),o=t("./INTERNAL"),i=t("./resolveThenable"),u=t("./states"),c=t("./queueItem");n.exports=e,e.prototype["catch"]=function(t){return this.then(null,t)},e.prototype.then=function(t,n){if("function"!=typeof t&&this.state===u.FULFILLED||"function"!=typeof n&&this.state===u.REJECTED)return this;var i=new e(o);if(this.state!==u.PENDING){var s=this.state===u.FULFILLED?t:n;r(i,s,this.outcome)}else this.queue.push(new c(i,t,n));return i}},{"./INTERNAL":5,"./queueItem":10,"./resolveThenable":14,"./states":15,"./unwrap":17}],10:[function(t,n){"use strict";function e(t,n,e){this.promise=t,"function"==typeof n&&(this.onFulfilled=n,this.callFulfilled=this.otherCallFulfilled),"function"==typeof e&&(this.onRejected=e,this.callRejected=this.otherCallRejected)}var r=t("./handlers"),o=t("./unwrap");n.exports=e,e.prototype.callFulfilled=function(t){r.resolve(this.promise,t)},e.prototype.otherCallFulfilled=function(t){o(this.promise,this.onFulfilled,t)},e.prototype.callRejected=function(t){r.reject(this.promise,t)},e.prototype.otherCallRejected=function(t){o(this.promise,this.onRejected,t)}},{"./handlers":7,"./unwrap":17}],11:[function(t,n){"use strict";function e(t){function n(t){i(t).then(function(t){s||(s=!0,c.resolve(f,t))},function(t){s||(s=!0,c.reject(f,t))})}if("[object Array]"!==Object.prototype.toString.call(t))return o(new TypeError("must be an array"));var e=t.length,s=!1;if(!e)return i([]);for(var a=-1,f=new r(u);++a<e;)n(t[a]);return f}var r=t("./promise"),o=t("./reject"),i=t("./resolve"),u=t("./INTERNAL"),c=t("./handlers");n.exports=e},{"./INTERNAL":5,"./handlers":7,"./promise":9,"./reject":12,"./resolve":13}],12:[function(t,n){"use strict";function e(t){var n=new r(o);return i.reject(n,t)}var r=t("./promise"),o=t("./INTERNAL"),i=t("./handlers");n.exports=e},{"./INTERNAL":5,"./handlers":7,"./promise":9}],13:[function(t,n){"use strict";function e(t){if(t)return t instanceof r?t:i.resolve(new r(o),t);var n=typeof t;switch(n){case"boolean":return u;case"undefined":return s;case"object":return c;case"number":return a;case"string":return f}}var r=t("./promise"),o=t("./INTERNAL"),i=t("./handlers");n.exports=e;var u=i.resolve(new r(o),!1),c=i.resolve(new r(o),null),s=i.resolve(new r(o),void 0),a=i.resolve(new r(o),0),f=i.resolve(new r(o),"")},{"./INTERNAL":5,"./handlers":7,"./promise":9}],14:[function(t,n,e){"use strict";function r(t,n){function e(n){c||(c=!0,o.reject(t,n))}function r(n){c||(c=!0,o.resolve(t,n))}function u(){n(r,e)}var c=!1,s=i(u);"error"===s.status&&e(s.value)}var o=t("./handlers"),i=t("./tryCatch");e.safely=r},{"./handlers":7,"./tryCatch":16}],15:[function(t,n,e){e.REJECTED=["REJECTED"],e.FULFILLED=["FULFILLED"],e.PENDING=["PENDING"]},{}],16:[function(t,n){"use strict";function e(t,n){var e={};try{e.value=t(n),e.status="success"}catch(r){e.status="error",e.value=r}return e}n.exports=e},{}],17:[function(t,n){"use strict";function e(t,n,e){r(function(){var r;try{r=n(e)}catch(i){return o.reject(t,i)}r===t?o.reject(t,new TypeError("Cannot resolve promise with itself")):o.resolve(t,r)})}var r=t("immediate"),o=t("./handlers");n.exports=e},{"./handlers":7,immediate:18}],18:[function(t,n){"use strict";function e(){o=!0;for(var t,n,e=c.length;e;){for(n=c,c=[],t=-1;++t<e;)n[t]();e=c.length}o=!1}function r(t){1!==c.push(t)||o||i()}for(var o,i,u=[t("./nextTick"),t("./mutation.js"),t("./messageChannel"),t("./stateChange"),t("./timeout")],c=[],s=-1,a=u.length;++s<a;)if(u[s]&&u[s].test&&u[s].test()){i=u[s].install(e);break}n.exports=r},{"./messageChannel":19,"./mutation.js":20,"./nextTick":2,"./stateChange":21,"./timeout":22}],19:[function(t,n,e){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};e.test=function(){return r.setImmediate?!1:"undefined"!=typeof r.MessageChannel},e.install=function(t){var n=new r.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}},{}],20:[function(t,n,e){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{},o=r.MutationObserver||r.WebKitMutationObserver;e.test=function(){return o},e.install=function(t){var n=0,e=new o(t),i=r.document.createTextNode("");return e.observe(i,{characterData:!0}),function(){i.data=n=++n%2}}},{}],21:[function(t,n,e){var r="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};e.test=function(){return"document"in r&&"onreadystatechange"in r.document.createElement("script")},e.install=function(t){return function(){var n=r.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},r.document.documentElement.appendChild(n),t}}},{}],22:[function(t,n,e){"use strict";e.test=function(){return!0},e.install=function(t){return function(){setTimeout(t,0)}}},{}],23:[function(t,n){"use strict";function e(t){return null===t?String(t):"object"==typeof t||"function"==typeof t?s[p.call(t)]||"object":typeof t}function r(t){return null!==t&&t===t.window}function o(t){if(!t||"object"!==e(t)||t.nodeType||r(t))return!1;try{if(t.constructor&&!d.call(t,"constructor")&&!d.call(t.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}var o;for(o in t);return void 0===o||d.call(t,o)}function i(t){return"function"===e(t)}function u(){for(var t=[],n=-1,e=arguments.length,r=new Array(e);++n<e;)r[n]=arguments[n];var o={};t.push({args:r,result:{container:o,key:"key"}});for(var i;i=t.pop();)c(t,i.args,i.result);return o.key}function c(t,n,e){var r,u,c,s,a,f,l,p=n[0]||{},d=1,v=n.length,y=!1,w=/\d+/;for("boolean"==typeof p&&(y=p,p=n[1]||{},d=2),"object"==typeof p||i(p)||(p={}),v===d&&(p=this,--d);v>d;d++)if(null!=(r=n[d])){l=h(r);for(u in r)if(!(u in Object.prototype)){if(l&&!w.test(u))continue;if(c=p[u],s=r[u],p===s)continue;y&&s&&(o(s)||(a=h(s)))?(a?(a=!1,f=c&&h(c)?c:[]):f=c&&o(c)?c:{},t.push({args:[y,f,s],result:{container:p,key:u}})):void 0!==s&&(h(r)&&i(s)||(p[u]=s))}}e.container[e.key]=p}for(var s={},a=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],f=0;f<a.length;f++){var l=a[f];s["[object "+l+"]"]=l.toLowerCase()}var p=s.toString,d=s.hasOwnProperty,h=Array.isArray||function(t){return"array"===e(t)};n.exports=u},{}],24:[function(t,n,e){"use strict";function r(t,n,e){for(var r in n)if(n.hasOwnProperty(r)){var i=o(t,r),u=i.base[i.name];if(u)if(u.hasOwnProperty("_handlers")){if(-1!==u._handlers.indexOf(n[r]))throw new Error("Wrapper method for '"+r+"' already installed: "+n[r]);u._handlers.push(n[r])}else i.base[i.name]=e(r,u,n[r],t)}}function o(t,n){for(n=n.split(".");n.length>1;)t=t[n.shift(0)];return{base:t,name:n[0]}}function i(t,n,e,r,o){var u=r[t];if("undefined"==typeof i)throw new Error("No known wrapper for method name: "+t);var c=[e],s=u(o,n,c);return s._original=n,s._handlers=c,s}function u(t,n,e,r){return"function"==typeof e&&(r=e,e={}),{base:t||n,db:t||n,options:e||{},callback:r}}function c(t,n,e){var r=n.callback;delete n.callback,e=e.bind(n.base);for(var o=t.length-1;o>=0;o-=1)e=t[o].bind(null,e,n);var i=e();return l(i,r),i}function s(t){return function(){return t.call(this)}}function a(t,n){return function(){return t.call(this,n.options)}}function f(t,n){for(var e in n)if(n.hasOwnProperty(e)){var r=o(t,e),i=r.base[r.name];if("undefined"!=typeof i){var u;try{u=i._handlers.indexOf(n[e])}catch(c){u=-1}if(-1===u)throw new Error("Wrapper method for '"+e+"' not installed: "+n[e]);i._handlers.splice(u,1),i._handlers.length||(delete r.base[r.name],r.base[r.name]!==i._original&&(r.base[r.name]=i._original))}}}var l=t("promise-nodify");e.installStaticWrapperMethods=function(t,n){t["new"]=t["new"]||function(n,e,r){return new t(n,e,r)},r(t,n,e.createStaticWrapperMethod)},e.installWrapperMethods=function(t,n){r(t,n,e.createWrapperMethod)},e.createStaticWrapperMethod=function(t,n,e,r){return i(t,n,e,d,r)},e.createWrapperMethod=function(t,n,e,r){return i(t,n,e,p,r)};var p={};p.destroy=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,s(n))}},p.put=function(t,n,e){return function(){var r={};r.base=t||this,r.db=t||this;var o=Array.prototype.slice.call(arguments);r.doc=o.shift();for(var i=("_id"in r.doc);;){var u=o.shift(),s=typeof u;if("string"!==s||i?"string"!==s||!i||"_rev"in r.doc?"object"===s?r.options=u:"function"===s&&(r.callback=u):r.doc._rev=u:(r.doc._id=u,i=!0),!o.length)break}return r.options=r.options||{},c(e,r,function(){return n.call(this,r.doc,r.options)})}},p.post=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.doc=r,c(e,s,function(){return n.call(this,s.doc,s.options)})}},p.get=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.docId=r,c(e,s,function(){return n.call(this,s.docId,s.options)})}},p.remove=function(t,n,e){return function(r,o,i,s){var a;return"string"==typeof o?(a=u(t,this,i,s),a.doc={_id:r,_rev:o}):(a=u(t,this,o,i),a.doc=r),c(e,a,function(){return n.call(this,a.doc,a.options)})}},p.bulkDocs=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.docs=r.docs||r,c(e,s,function(){return n.call(this,s.docs,s.options)})}},p.allDocs=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,a(n,i))}},p.changes=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,a(n,i))}},p.sync=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.url=r,c(e,s,function(){return n.call(this,s.url,s.options)})}},p["replicate.from"]=p.sync,p["replicate.to"]=p.sync,p.putAttachment=function(t,n,e){return function(r,o,i,s,a,f,l){var p;return"string"==typeof a?(p=u(t,this,f,l),p.rev=i,p.doc=s,p.type=a):(p=u(t,this,a,f),p.rev=null,p.doc=i,p.type=s),p.docId=r,p.attachmentId=o,c(e,p,function(){return n.call(this,p.docId,p.attachmentId,p.rev,p.doc,p.type)})}},p.getAttachment=function(t,n,e){return function(r,o,i,s){var a=u(t,this,i,s);return a.docId=r,a.attachmentId=o,c(e,a,function(){return n.call(this,a.docId,a.attachmentId,a.options)})}},p.removeAttachment=function(t,n,e){return function(r,o,i,s,a){var f=u(t,this,s,a);return f.docId=r,f.attachmentId=o,f.rev=i,c(e,f,function(){return n.call(this,f.docId,f.attachmentId,f.rev)})}},p.query=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.fun=r,c(e,s,function(){return n.call(this,s.fun,s.options)})}},p.viewCleanup=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,a(n,i))}},p.info=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,s(n))}},p.compact=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,a(n,i))}},p.revsDiff=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.diff=r,c(e,s,function(){return n.call(this,s.diff)})}},p.list=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.path=r,c(e,s,function(){return n.call(this,s.path,s.options)})}},p.rewriteResultRequestObject=p.list,p.show=p.list,p.update=p.list,p.getSecurity=function(t,n,e){return function(r,o){var i=u(t,this,r,o);return c(e,i,a(n,i))}},p.putSecurity=function(t,n,e){return function(r,o,i){var s=u(t,this,o,i);return s.secObj=r,c(e,s,function(){return n.call(this,s.secObj)})}};var d={};d["new"]=function(t,n,e){return function(r,o,i){var s;return"object"==typeof r?s=u(t,this,r,o):(s=u(t,this,o,i),s.options.name=r),c(e,s,function(){return n.call(this,s.options)})}},d.destroy=function(t,n,e){return function(r,o,i){var s;return"object"==typeof r?s=u(t,this,r,o):(s=u(t,this,o,i),s.options.name=r),c(e,s,function(){var t=s.options.name;return delete s.options.name,n.call(this,t,s.options)})}},d.replicate=function(t,n,e){return function(r,o,i){var s=u(t,this,i);return s.source=r,s.target=o,c(e,s,function(){return n.call(this,s.source,s.target,s.options)})}},e.uninstallWrapperMethods=function(t,n){f(t,n)},e.uninstallStaticWrapperMethods=function(t,n){f(t,n)}},{"promise-nodify":25}],25:[function(t,n){"use strict";n.exports=function(t,n){"function"==typeof n&&t.then(function(t){n(null,t)},function(t){n(t,null)})}},{}],26:[function(t,n,e){var r,o=t("__browserify_process"),i="undefined"!=typeof self?self:"undefined"!=typeof window?window:{};r="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof i.Promise?i.Promise:t("lie"),e.once=function(t){var n=!1;return e.getArguments(function(e){if(n)throw console.trace(),new Error("once called more than once");n=!0,t.apply(this,e)})},e.getArguments=function(t){return function(){for(var n=arguments.length,e=new Array(n),r=-1;++r<n;)e[r]=arguments[r];return t.call(this,e)}},e.toPromise=function(t){return e.getArguments(function(n){var i,u=this,c="function"==typeof n[n.length-1]?n.pop():!1;c&&(i=function(t,n){o.nextTick(function(){c(t,n)})});var s=new r(function(r,o){try{var i=e.once(function(t,n){t?o(t):r(n)});n.push(i),t.apply(u,n)}catch(c){o(c)}});return i&&s.then(function(t){i(null,t)},i),s.cancel=function(){return this},s})},e.inherits=t("inherits"),e.Promise=r,e.extend=t("pouchdb-extend"),e.clone=function(t){return e.extend(!0,{},t)},e.isLocalId=function(t){return/^_local/.test(t)}},{__browserify_process:3,inherits:4,lie:8,"pouchdb-extend":23}]},{},[1]); |
142
index.js
'use strict'; | ||
var utils = require('./pouch-utils'); | ||
var wrappers = require('pouchdb-wrappers'); | ||
@@ -14,6 +15,3 @@ function isUnfilterable(doc) { | ||
var incoming = function (doc) { | ||
if (isUnfilterable(doc)) { | ||
return doc; | ||
} | ||
if (config.incoming) { | ||
if (!isUnfilterable(doc) && config.incoming) { | ||
return config.incoming(utils.clone(doc)); | ||
@@ -24,6 +22,3 @@ } | ||
var outgoing = function (doc) { | ||
if (isUnfilterable(doc)) { | ||
return doc; | ||
} | ||
if (config.outgoing) { | ||
if (!isUnfilterable(doc) && config.outgoing) { | ||
return config.outgoing(utils.clone(doc)); | ||
@@ -34,30 +29,11 @@ } | ||
var handlers = {}; | ||
if (db.type() === 'http') { | ||
// | ||
// put | ||
// | ||
var origPut = db.put; | ||
db.put = utils.getArguments(function (args) { | ||
var doc = args[0]; | ||
doc = incoming(doc); | ||
args[0] = doc; | ||
return origPut.apply(db, args); | ||
}); | ||
// | ||
// query | ||
// | ||
var origQuery = db.query; | ||
db.query = utils.toPromise(function (fun, opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
/* istanbul ignore next */ | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.put = function (orig, args) { | ||
args.doc = incoming(args.doc); | ||
return orig(); | ||
}; | ||
handlers.query = function (orig) { | ||
return orig().then(function (res) { | ||
res.rows.forEach(function (row) { | ||
@@ -68,23 +44,10 @@ if (row.doc) { | ||
}); | ||
origCallback(null, res); | ||
}; | ||
origQuery.apply(db, [fun, opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
} | ||
// | ||
// get | ||
// | ||
var origGet = db.get; | ||
db.get = utils.toPromise(function (id, opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.get = function (orig) { | ||
return orig().then(function (res) { | ||
if (Array.isArray(res)) { | ||
@@ -100,41 +63,15 @@ // open_revs style, it's a list of docs | ||
} | ||
origCallback(null, res); | ||
}; | ||
origGet.apply(db, [id, opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
// | ||
// bulkDocs | ||
// | ||
var origBulkDocs = db.bulkDocs; | ||
db.bulkDocs = utils.getArguments(function (args) { | ||
var docsObj = args[0]; | ||
docsObj = Array.isArray(docsObj) ? docsObj.slice() : utils.clone(docsObj); | ||
var docs = Array.isArray(docsObj) ? docsObj : docsObj.docs; | ||
for (var i = 0; i < docs.length; i++) { | ||
docs[i] = incoming(docs[i]); | ||
handlers.bulkDocs = function (orig, args) { | ||
for (var i = 0; i < args.docs.length; i++) { | ||
args.docs[i] = incoming(args.docs[i]); | ||
} | ||
return orig(); | ||
}; | ||
args[0] = docsObj; | ||
return origBulkDocs.apply(db, args); | ||
}); | ||
// | ||
// allDocs | ||
// | ||
var origAllDocs = db.allDocs; | ||
db.allDocs = utils.toPromise(function (opts, origCallback) { | ||
if (typeof opts === 'function') { | ||
origCallback = opts; | ||
opts = {}; | ||
} | ||
var callback = function (err, res) { | ||
/* istanbul ignore next */ | ||
if (err) { | ||
return origCallback(err); | ||
} | ||
handlers.allDocs = function (orig) { | ||
return orig().then(function (res) { | ||
res.rows.forEach(function (row) { | ||
@@ -145,13 +82,7 @@ if (row.doc) { | ||
}); | ||
origCallback(null, res); | ||
}; | ||
origAllDocs.apply(db, [opts, callback]); | ||
}); | ||
return res; | ||
}); | ||
}; | ||
// | ||
// changes | ||
// | ||
var origChanges = db.changes; | ||
db.changes = function (opts, callback) { | ||
handlers.changes = function (orig, args) { | ||
function modifyChange(change) { | ||
@@ -169,5 +100,5 @@ if (change.doc) { | ||
if (opts.complete) { | ||
var origComplete = opts.complete; | ||
opts.complete = function (err, res) { | ||
if (args.options.complete) { | ||
var origComplete = args.options.complete; | ||
args.options.complete = function (err, res) { | ||
/* istanbul ignore next */ | ||
@@ -181,4 +112,3 @@ if (err) { | ||
var changes = origChanges.apply(db, [opts, callback]); | ||
var changes = orig(); | ||
// override some events | ||
@@ -205,5 +135,5 @@ var origOn = changes.on; | ||
}; | ||
return changes; | ||
}; | ||
wrappers.installWrapperMethods(db, handlers); | ||
}; | ||
@@ -210,0 +140,0 @@ |
{ | ||
"name": "filter-pouch", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Filter Pouch - a PouchDB plugin for filtering documents", | ||
@@ -39,3 +39,4 @@ "main": "index.js", | ||
"lie": "^2.6.0", | ||
"pouchdb-extend": "^0.1.0" | ||
"pouchdb-extend": "^0.1.0", | ||
"pouchdb-wrappers": "^1.2.0" | ||
}, | ||
@@ -42,0 +43,0 @@ "devDependencies": { |
@@ -8,7 +8,7 @@ Filter Pouch | ||
There are a few different use cases for this: | ||
This allows you to: | ||
* Encrypt and decrypt sensitive document fields | ||
* Compress and uncompress large content to avoid hitting storage limits | ||
* Remove fields, add fields, or massage user-provided fields | ||
* Remove or modify documents before storage, to avoid hitting [browser storage limits](http://pouchdb.com/faq.html#data_limits). | ||
@@ -74,3 +74,3 @@ Usage | ||
Using the Node.js crypto library (you would need something different in a browser), let's first set up our encrypt/decrypt functions: | ||
Using the Node.js crypto library (in a browser, you would need something like [Stanford Crypto](https://bitwiseshiftleft.github.io/sjcl/) or [WebCrypto](http://caniuse.com/#feat=cryptography)), let's first set up our encrypt/decrypt functions: | ||
@@ -118,2 +118,4 @@ ```js | ||
(`filter-pouch` will automatically ignore deleted documents, so you don't need to handle that case.) | ||
Now, the documents are encrypted whenever they're stored in the database. If you want to verify, try opening them with a `Pouch` where you haven't set up any `filters`. You'll see documents like: | ||
@@ -195,2 +197,2 @@ | ||
This will run the tests automatically and the process will exit with a 0 or a 1 when it's done. Firefox uses IndexedDB, and PhantomJS uses WebSQL. | ||
This will run the tests automatically and the process will exit with a 0 or a 1 when it's done. Firefox uses IndexedDB, and PhantomJS uses WebSQL. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
2
195
21
3
104548
6
17
2457
+ Addedpouchdb-wrappers@^1.2.0
+ Addedpouchdb-wrappers@1.3.6(transitive)
+ Addedpromise-nodify@1.0.2(transitive)