New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pouchdb

Package Overview
Dependencies
Maintainers
3
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pouchdb - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.jshintrc

20

bin/dev-server.js
#!/usr/bin/env node
'use strict';
var cors_proxy = require("corsproxy");

@@ -9,5 +11,3 @@ var http_proxy = require("http-proxy");

program
.option('-r, --remote [url]', 'Specify the remote couch host')
.parse(process.argv);
var COUCH_HOST = process.env.COUCH_HOST || 'http://127.0.0.1:5984';

@@ -17,7 +17,13 @@ var HTTP_PORT = 8000;

var couchHost = program.remote || 'http://127.0.0.1:5984';
function startServers(couchHost) {
http_server.createServer().listen(HTTP_PORT);
cors_proxy.options = {target: couchHost || COUCH_HOST};
http_proxy.createServer(cors_proxy).listen(CORS_PORT);
}
http_server.createServer().listen(HTTP_PORT);
cors_proxy.options = {target: couchHost};
http_proxy.createServer(cors_proxy).listen(CORS_PORT);
if (require.main === module) {
startServers();
} else {
module.exports.start = startServers;
}
#!/usr/bin/env node
// This requires some setup, will attempt to remove steps needed
var path = require('path');
var spawn = require('child_process').spawn;
// You need to download and start selenium-server-standalone
// download from: https://code.google.com/p/selenium/downloads/list
// start with: java -jar ~/Downloads/selenium-server-standalone-2.37.0.jar
// You need chromedriver, download it @
// Download http://chromedriver.storage.googleapis.com/index.html?path=2.7/
// then add to your path
// If you are on OSX, you will need to ensure Firefox is on your path
// export PATH=/Applications/Firefox.app/Contents/MacOS/:$PATH
// Also needs $ npm run dev-server if run manually
var webdriverjs = require('webdriverjs');
var devserver = require('./dev-server.js');
var SELENIUM_PATH = '../node_modules/.bin/start-selenium';
var testUrl = 'http://127.0.0.1:8000/tests/test.html';

@@ -35,2 +25,22 @@ var testTimeout = 2 * 60 * 1000;

// Travis only has firefox
if (process.env.TRAVIS) {
browsers = ['firefox'];
}
function startServers(callback) {
// Starts the file and CORS proxy
devserver.start();
// Start selenium
var selenium = spawn(path.resolve(__dirname, SELENIUM_PATH));
selenium.stdout.on('data', function(data) {
if (/Started org.openqa.jetty.jetty/.test(data)) {
callback();
}
});
}
function testsComplete() {

@@ -85,2 +95,4 @@ var passed = Object.keys(results).every(function(x) {

startTest();
startServers(function() {
startTest();
});

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

'test.cors.js',
//no workers in node
'test.worker.js',
// Plugins currnetly arent tested (#1031)

@@ -17,10 +19,12 @@ 'test.gql.js',

var testFiles = fs.readdirSync("./tests").filter(function(name){
return (/^test\.([a-z0-9_])*\.js$/).test(name) &&
(excludedTests.indexOf(name) === -1);
});
var testFiles;
// If you want to test a single file, just do this for now, kinda ugly
// but will improve
//testFiles = ['test.basics.js'];
if (process.env.TEST_FILE) {
testFiles = [process.env.TEST_FILE];
} else {
testFiles = fs.readdirSync("./tests").filter(function(name){
return (/^test\.([a-z0-9_])*\.js$/).test(name) &&
(excludedTests.indexOf(name) === -1);
});
}

@@ -27,0 +31,0 @@ testrunner.setup({

{
"name": "pouchdb",
"version": "1.0.0",
"version": "1.1.0",
"description": "PouchDB is a pocket-sized database.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/daleharvey/pouchdb",

{
"name": "pouchdb",
"version": "1.0.0",
"version": "1.1.0",
"description": "PouchDB is a pocket-sized database.",

@@ -5,0 +5,0 @@ "repo": "daleharvey/pouchdb",

@@ -63,6 +63,4 @@ [PouchDB](http://pouchdb.com/) - The Javascript Database that Syncs

The PouchDB test suite expects an instance of CouchDB running in Admin Party on http://127.0.0.1:5984, you can override this by passing a flag with the CouchDB host (and basic auth credentials if needed)
The PouchDB test suite expects an instance of CouchDB running in Admin Party on http://127.0.0.1:5984, you can configure this by sending the `COUCH_HOST` env var when running the Node tests or the `dev-server`
$ ./bin/dev-server.js --remote=http://user:pass@myname.host.com
### Node Tests

@@ -72,11 +70,24 @@

$ npm test
$ npm run test-node
Run an indivitual test:
$ TEST_FILE=test.basics.js npm run test-node
### Browser Tests
$ npm build
Browser tests require a running HTTP server and a CORS proxy:
$ npm run dev-server
# or
$ COUCH_HOST=http://user:pass@myname.host.com npm run dev-server
Now visit http://127.0.0.1:8000/tests/test.html in your browser add ?testFiles=test.basics.js to run single test file. You do not need to manually rebuild PouchDB when you run the `dev-server` target, any changes you make to the source will automatically be built.
### All Tests
To run all tests:
$ npm test
Git Essentials

@@ -83,0 +94,0 @@ --------------------------------------

@@ -231,3 +231,3 @@ ---

A list of changes made to documents in the database, in the order they were made.
If `options.continuous` is set it returns object with one method `cancel` which you call if you don't want to listen to new changes anymore. `opttions.onChange` will be be called for each change that is encountered.
If `options.continuous` is set it returns object with one method `cancel` which you call if you don't want to listen to new changes anymore. `options.onChange` will be be called for each change that is encountered.

@@ -458,2 +458,4 @@ * `options.include_docs`: Include the associated document with each change

* `options.reduce`: Reduce function
* `options.key`: Only return rows matching key
* `options.startkey` & `options.endkey`: Get documents with keys in a certain range

@@ -460,0 +462,0 @@ #### Example Usage:

@@ -11,1 +11,5 @@ ---

Are you in private browsing mode? IndexedDB is [disabled in private browsing mode](https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB) of Firefox.
### Can't open second database on Android WebView/Cordova/Phone Gap
There is a limit of one database per app in Android Webview. Istall the [SQLite plugin](https://github.com/lite4cordova/Cordova-SQLitePlugin), PouchDB will use that if it is available.

@@ -26,4 +26,3 @@ ---

[Source](https://github.com/daleharvey/pouchdb/blob/master/src/plugins/pouchdb.spatial.js)
[Build](http://download.pouchdb.com/pouchdb.spatial-nightly.js)
[repo](https://github.com/pouchdb/geopouch)

@@ -35,3 +34,3 @@ ### GQL

[Documentation](http://pouchdb.com/gql.html)
[Build](http://download.pouchdb.com/pouchdb.gql-nightly.js)
[repo](https://github.com/pouchdb/GQL)

@@ -38,0 +37,0 @@ ### Backbone PouchDB

@@ -19,5 +19,4 @@ ---

* [Cloudant](https://cloudant.com/) - A cluster aware fork of CouchDB
* [Couchbase Sync Gateway](http://www.couchbase.com/communities/couchbase-sync-gateway) - A sync gateway for Couchbase
For CORS support PouchDB requires CouchDB > 1.3.0, however if you serve your web application from the same host as CouchDB (either via reverse proxy or CouchApps) then it should work with older versions.
### The web is nice, but I want to build a native app?

@@ -24,0 +23,0 @@

@@ -104,4 +104,4 @@ ---

// Show the current list of todos by reading them from the database
function addTodo() {
// We have to create a new todo document and enter it in the database
function addTodo(text) {
{% endhighlight %}

@@ -108,0 +108,0 @@

@@ -64,3 +64,3 @@ ---

{name!: "pencil", price: 2, discount: 0.7, vender: "store1"},
{name!: "pencil", price: 2, discount: 0.7, vendor: "store1"},
{name!: "pen", price:3, discount: 2, vendor: "store2"}

@@ -67,0 +67,0 @@

@@ -142,3 +142,3 @@ /*globals cordova */

}
if (!('_id' in doc)) {
if (!utils.isValidId(doc._id)) {
return call(callback, errors.MISSING_ID);

@@ -273,3 +273,3 @@ }

customApi._getRevisionTree(id, function (err, rev_tree) {
if (err && err.error === 'not_found' && err.reason === 'missing') {
if (err && err.name === 'not_found' && err.message === 'missing') {
missing[id] = {missing: req[id]};

@@ -399,3 +399,3 @@ } else if (err) {

if (!(typeof(l) === "string" && /^\d+-/.test(l))) {
return call(callback, utils.error(errors.BAD_REQUEST,
return call(callback, errors.error(errors.BAD_REQUEST,
"Invalid rev format"));

@@ -406,3 +406,3 @@ }

} else {
return call(callback, utils.error(errors.UNKNOWN_ERROR,
return call(callback, errors.error(errors.UNKNOWN_ERROR,
'function_clause'));

@@ -523,3 +523,3 @@ }

if ('startkey' in opts) {
call(callback, utils.error(errors.QUERY_PARSE_ERROR,
call(callback, errors.error(errors.QUERY_PARSE_ERROR,
'Query parameter `start_key` is not compatible with multi-get'

@@ -530,3 +530,3 @@ ));

if ('endkey' in opts) {
call(callback, utils.error(errors.QUERY_PARSE_ERROR,
call(callback, errors.error(errors.QUERY_PARSE_ERROR,
'Query parameter `end_key` is not compatible with multi-get'

@@ -544,2 +544,25 @@ ));

function processChange(doc, metadata, opts) {
var changeList = [{rev: doc._rev}];
if (opts.style === 'all_docs') {
changeList = merge.collectLeaves(metadata.rev_tree)
.map(function (x) { return {rev: x.rev}; });
}
var change = {
id: metadata.id,
changes: changeList,
doc: doc
};
if (utils.isDeleted(metadata, doc._rev)) {
change.deleted = true;
}
if (opts.conflicts) {
change.doc._conflicts = merge.collectConflicts(metadata);
if (!change.doc._conflicts.length) {
delete change.doc._conflicts;
}
}
return change;
}
api.changes = function (opts) {

@@ -561,2 +584,3 @@ if (!api.taskqueue.ready()) {

opts = utils.extend(true, {}, opts);
opts.processChange = processChange;

@@ -616,3 +640,3 @@ if (!opts.since) {

'missing json key: views';
err = err || utils.error(errors.MISSING_DOC, msg);
err = err || errors.error(errors.MISSING_DOC, msg);
utils.call(opts.complete, err);

@@ -622,3 +646,3 @@ }

} else {
var err = utils.error(errors.BAD_REQUEST,
var err = errors.error(errors.BAD_REQUEST,
'`view` filter parameter is not provided.');

@@ -642,3 +666,3 @@ utils.call(opts.complete, err);

: 'missing json key: filters';
err = err || utils.error(errors.MISSING_DOC, msg);
err = err || errors.error(errors.MISSING_DOC, msg);
utils.call(opts.complete, err);

@@ -645,0 +669,0 @@ }

@@ -5,3 +5,2 @@ "use strict";

var errors = require('../deps/errors');
var HTTP_TIMEOUT = 10000;

@@ -496,3 +495,3 @@ // parseUri 1.2.2

}
if (!('_id' in doc)) {
if (!utils.isValidId(doc._id)) {
return utils.call(callback, errors.MISSING_ID);

@@ -499,0 +498,0 @@ }

@@ -5,11 +5,6 @@ 'use strict';

var merge = require('../merge');
var errors = require('../deps/errors');
function idbError(callback) {
return function (event) {
utils.call(callback, {
status: 500,
error: event.type,
reason: event.target
});
utils.call(callback, errors.error(errors.IDB_ERROR, event.target, event.type));
};

@@ -212,3 +207,3 @@ }

} catch (e) {
var err = utils.error(errors.BAD_ARG,
var err = errors.error(errors.BAD_ARG,
"Attachments need to be base64 encoded");

@@ -428,3 +423,3 @@ return utils.call(callback, err);

if (utils.isDeleted(metadata) && !opts.rev) {
err = utils.error(errors.MISSING_DOC, "deleted");
err = errors.error(errors.MISSING_DOC, "deleted");
return finish();

@@ -709,20 +704,6 @@ }

delete doc['_doc_id_rev'];
var changeList = [{rev: mainRev}];
if (opts.style === 'all_docs') {
changeList = merge.collectLeaves(metadata.rev_tree)
.map(function (x) { return {rev: x.rev}; });
}
var change = {
id: metadata.id,
seq: cursor.key,
changes: changeList,
doc: doc
};
if (utils.isDeleted(metadata, mainRev)) {
change.deleted = true;
}
if (opts.conflicts) {
change.doc._conflicts = merge.collectConflicts(metadata);
}
doc._rev = mainRev;
var change = opts.processChange(doc, metadata, opts);
change.seq = cursor.key;

@@ -729,0 +710,0 @@ // Dedupe the changes feed

@@ -17,6 +17,5 @@ 'use strict';

return process.nextTick(function () {
callback({error: message});
callback(errors.error(errors.LDB_ERROR, message));
});
}
var DOC_STORE = 'document-store';

@@ -71,2 +70,34 @@ var BY_SEQ_STORE = 'by-sequence';

function closeStores(callback) {
var dbpath = path.resolve(opts.name);
var stores = [
path.join(dbpath, DOC_STORE),
path.join(dbpath, BY_SEQ_STORE),
path.join(dbpath, ATTACH_STORE),
path.join(dbpath, ATTACH_BINARY_STORE)
];
var closed = 0;
stores.map(function (path) {
var store = STORES[path];
if (store) {
store.close(function () {
delete STORES[path];
if (++closed >= stores.length) {
done();
}
});
}
else {
if (++closed >= stores.length) {
done();
}
}
});
function done() {
call(callback, null);
}
}
function initstore(store_name, encoding) {

@@ -83,2 +114,5 @@

if (stores.err) {
if (ldb) {
ldb.close();
}
return;

@@ -88,2 +122,3 @@ }

stores.err = err;
closeStores();
return call(callback, err);

@@ -186,2 +221,10 @@ }

function formatSeq(n) {
return ('0000000000000000' + n).slice(-16);
}
function parseSeq(s) {
return parseInt(s);
}
api._get = function (id, opts, callback) {

@@ -193,3 +236,3 @@ stores[DOC_STORE].get(id, function (err, metadata) {

if (utils.isDeleted(metadata) && !opts.rev) {
return call(callback, utils.extend({}, errors.MISSING_DOC, {reason: "deleted"}));
return call(callback, errors.error(errors.MISSING_DOC, "deleted"));
}

@@ -201,3 +244,3 @@

stores[BY_SEQ_STORE].get(seq, function (err, doc) {
stores[BY_SEQ_STORE].get(formatSeq(seq), function (err, doc) {
if (!doc) {

@@ -372,3 +415,3 @@ return call(callback, errors.MISSING_DOC);

stores[BY_SEQ_STORE].put(doc.metadata.seq, doc.data, function (err) {
stores[BY_SEQ_STORE].put(formatSeq(doc.metadata.seq), doc.data, function (err) {
stores[DOC_STORE].put(doc.metadata.id, doc.metadata, function (err) {

@@ -535,3 +578,3 @@ results.push(doc);

var seq = metadata.rev_map[merge.winningRev(metadata)];
stores[BY_SEQ_STORE].get(seq, function (err, data) {
stores[BY_SEQ_STORE].get(formatSeq(seq), function (err, data) {
allDocsInner(metadata, data);

@@ -587,3 +630,3 @@ });

if (!streamOpts.reverse) {
streamOpts.start = opts.since ? opts.since + 1 : 0;
streamOpts.start = formatSeq(opts.since ? opts.since + 1 : 0);
}

@@ -594,2 +637,5 @@

.on('data', function (data) {
if (opts.cancelled) {
return;
}
if (utils.isLocalId(data.key)) {

@@ -604,15 +650,6 @@ return;

var mainRev = merge.winningRev(metadata);
var changeList = [{rev: mainRev}];
if (opts.style === 'all_docs') {
changeList = merge.collectLeaves(metadata.rev_tree)
.map(function (x) { return {rev: x.rev}; });
}
var change = {
id: metadata.id,
seq: metadata.seq,
changes: changeList,
doc: data.value
};
change.doc._rev = mainRev;
var doc = data.value;
doc._rev = merge.winningRev(metadata);
var change = opts.processChange(doc, metadata, opts);
change.seq = metadata.seq;

@@ -622,11 +659,5 @@ if (last_seq < metadata.seq) {

}
if (utils.isDeleted(metadata, mainRev)) {
change.deleted = true;
}
if (opts.conflicts) {
change.doc._conflicts = merge.collectConflicts(metadata);
}
// Ensure duplicated dont overwrite winning rev
if (+data.key === metadata.rev_map[change.doc._rev]) {
if (parseSeq(data.key) === metadata.rev_map[change.doc._rev]) {
results.push(change);

@@ -643,2 +674,5 @@ }

.on('close', function () {
if (opts.cancelled) {
return;
}
var filter = utils.filterChange(opts);

@@ -673,3 +707,5 @@ changeListener = function (change) {

opts.cancelled = true;
change_emitter.removeListener('change', changeListener);
if (changeListener) {
change_emitter.removeListener('change', changeListener);
}
}

@@ -684,32 +720,3 @@ };

}
var dbpath = path.resolve(opts.name);
var stores = [
path.join(dbpath, DOC_STORE),
path.join(dbpath, BY_SEQ_STORE),
path.join(dbpath, ATTACH_STORE),
path.join(dbpath, ATTACH_BINARY_STORE)
];
var closed = 0;
stores.map(function (path) {
var store = STORES[path];
if (store) {
store.close(function () {
delete STORES[path];
if (++closed >= stores.length) {
done();
}
});
}
else {
if (++closed >= stores.length) {
done();
}
}
});
function done() {
call(callback, null);
}
closeStores(callback);
};

@@ -752,3 +759,3 @@

stores[BY_SEQ_STORE].del(seq, function (err) {
stores[BY_SEQ_STORE].del(formatSeq(seq), function (err) {
done();

@@ -755,0 +762,0 @@ });

@@ -10,2 +10,14 @@ 'use strict';

function openDB() {
if (typeof window !== 'undefined') {
if (window.navigator && window.navigator.sqlitePlugin && window.navigator.sqlitePlugin.openDatabase) {
return navigator.sqlitePlugin.openDatabase.apply(navigator.sqlitePlugin, arguments);
} else if (window.sqlitePlugin && window.sqlitePlugin.openDatabase) {
return window.sqlitePlugin.openDatabase.apply(window.sqlitePlugin, arguments);
} else {
return window.openDatabase.apply(window, arguments);
}
}
}
var POUCH_VERSION = 1;

@@ -33,3 +45,7 @@ var POUCH_SIZE = 5 * 1024 * 1024;

}
function idbError(callback) {
return function (event) {
utils.call(callback, errors.error(errors.WSQ_ERROR, event.target, event.type));
};
}
function webSqlPouch(opts, callback) {

@@ -41,3 +57,3 @@

var db = openDatabase(name, POUCH_VERSION, name, POUCH_SIZE);
var db = openDB(name, POUCH_VERSION, name, POUCH_SIZE);
if (!db) {

@@ -199,3 +215,3 @@ return utils.call(callback, errors.UNKNOWN_ERROR);

} catch (e) {
var err = utils.error(errors.BAD_ARG,
var err = errors.error(errors.BAD_ARG,
"Attachments need to be base64 encoded");

@@ -442,3 +458,3 @@ return utils.call(callback, err);

if (utils.isDeleted(metadata) && !opts.rev) {
err = utils.error(errors.MISSING_DOC, "deleted");
err = errors.error(errors.MISSING_DOC, "deleted");
return finish();

@@ -478,12 +494,16 @@ }

var sqlArgs = [];
if ('keys' in opts) {
sql += ' WHERE ' + DOC_STORE + '.id IN (' + opts.keys.map(function (key) {
return quote(key);
sql += ' WHERE ' + DOC_STORE + '.id IN (' + opts.keys.map(function () {
return '?';
}).join(',') + ')';
sqlArgs = sqlArgs.concat(opts.keys);
} else {
if (start) {
sql += ' WHERE ' + DOC_STORE + '.id >= "' + start + '"';
sql += ' WHERE ' + DOC_STORE + '.id >= ?';
sqlArgs.push(start);
}
if (end) {
sql += (start ? ' AND ' : ' WHERE ') + DOC_STORE + '.id <= "' + end + '"';
sql += (start ? ' AND ' : ' WHERE ') + DOC_STORE + '.id <= ?';
sqlArgs.push(end);
}

@@ -494,3 +514,3 @@ sql += ' ORDER BY ' + DOC_STORE + '.id ' + (descending ? 'DESC' : 'ASC');

db.transaction(function (tx) {
tx.executeSql(sql, [], function (tx, result) {
tx.executeSql(sql, sqlArgs, function (tx, result) {
for (var i = 0, l = result.rows.length; i < l; i++) {

@@ -556,6 +576,6 @@ var doc = result.rows.item(i);

//console.log(name + ': Start Changes Feed: continuous=' + opts.continuous);
if (opts.continuous) {

@@ -601,19 +621,5 @@ var id = name + ':' + utils.uuid();

var doc = JSON.parse(res.data);
var mainRev = doc._rev;
var changeList = [{rev: mainRev}];
if (opts.style === 'all_docs') {
changeList = makeRevs(merge.collectLeaves(metadata.rev_tree));
}
var change = {
id: metadata.id,
seq: res.seq,
changes: changeList,
doc: doc
};
if (utils.isDeleted(metadata, mainRev)) {
change.deleted = true;
}
if (opts.conflicts) {
change.doc._conflicts = merge.collectConflicts(metadata);
}
var change = opts.processChange(doc, metadata, opts);
change.seq = res.seq;
results.push(change);

@@ -694,7 +700,16 @@ }

webSqlPouch.valid = function () {
return typeof window !== 'undefined' && !!window.openDatabase;
if (typeof window !== 'undefined') {
if (window.navigator && window.navigator.sqlitePlugin && window.navigator.sqlitePlugin.openDatabase) {
return true;
} else if (window.sqlitePlugin && window.sqlitePlugin.openDatabase) {
return true;
} else if (window.openDatabase) {
return true;
}
}
return false;
};
webSqlPouch.destroy = function (name, opts, callback) {
var db = openDatabase(name, POUCH_VERSION, name, POUCH_SIZE);
var db = openDB(name, POUCH_VERSION, name, POUCH_SIZE);
db.transaction(function (tx) {

@@ -701,0 +716,0 @@ tx.executeSql('DROP TABLE IF EXISTS ' + DOC_STORE, []);

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

"use strict";
var request = require('request');
var extend = require('./extend.js');
var createBlob = require('./blob.js');
var errors = require('./errors');

@@ -13,2 +16,3 @@ function ajax(options, callback) {

function call(fun) {
/* jshint validthis: true */
var args = Array.prototype.slice.call(arguments, 1);

@@ -18,3 +22,3 @@ if (typeof fun === typeof Function) {

}
};
}

@@ -31,6 +35,5 @@ var defaultOptions = {

function onSuccess(obj, resp, cb){
function onSuccess(obj, resp, cb) {
if (!options.binary && !options.json && options.processData &&
typeof obj !== 'string') {
typeof obj !== 'string') {
obj = JSON.stringify(obj);

@@ -46,17 +49,41 @@ } else if (!options.binary && options.json && typeof obj === 'string') {

}
if (Array.isArray(obj)) {
obj = obj.map(function (v) {
var obj;
if (v.ok) {
return v;
} else if (v.error && v.error === 'conflict') {
obj = errors.REV_CONFLICT;
obj.id = v.id;
return obj;
} else if (v.missing) {
obj = errors.MISSING_DOC;
obj.missing = v.missing;
return obj;
}
});
}
call(cb, null, obj, resp);
};
}
function onError(err, cb){
var errParsed;
var errObj = {status: err.status};
function onError(err, cb) {
var errParsed, errObj, errType, key;
try {
errParsed = JSON.parse(err.responseText);
//would prefer not to have a try/catch clause
errObj = extend(true, {}, errObj, errParsed);
} catch(e) {}
for (key in errors) {
if (errors[key].name === errParsed.error) {
errType = errors[key];
break;
}
}
errType = errType || errors.UNKNOWN_ERROR;
errObj = errors.error(errType, errParsed.reason);
} catch (e) {
errObj = errors.error(errors.UNKNOWN_ERROR);
}
call(cb, errObj);
};
}
if (typeof window !== 'undefined' && window.XMLHttpRequest) {
if (process.browser && typeof XMLHttpRequest !== 'undefined') {
var timer, timedout = false;

@@ -81,12 +108,11 @@ var xhr = new XMLHttpRequest();

function createCookie(name,value,days) {
var createCookie = function (name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else {
var expires = "";
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name+"="+value+expires+"; path=/";
}
document.cookie = name + "=" + value + expires + "; path=/";
};

@@ -106,4 +132,4 @@ for (var key in options.headers) {

function abortReq() {
timedout=true;
var abortReq = function () {
timedout = true;
xhr.abort();

@@ -129,3 +155,3 @@ call(onError, xhr, callback);

} else {
call(onError, xhr, callback);
call(onError, xhr, callback);
}

@@ -136,5 +162,9 @@ };

timer = setTimeout(abortReq, options.timeout);
xhr.upload.onprogress = xhr.onprogress = function () {
clearTimeout(timer);
timer = setTimeout(abortReq, options.timeout);
};
}
xhr.send(options.body);
return {abort:abortReq};
return {abort: abortReq};

@@ -165,3 +195,3 @@ } else {

}
var error;
var content_type = response.headers['content-type'];

@@ -186,9 +216,18 @@ var data = (body || '');

}
data.status = response.statusCode;
call(callback, data);
if (data.reason === 'missing') {
error = errors.MISSING_DOC;
} else if (data.reason === 'no_db_file') {
error = errors.error(errors.DB_MISSING, data.reason);
} else if (data.error === 'conflict') {
error = errors.REV_CONFLICT;
} else {
error = errors.error(errors.UNKNOWN_ERROR, data.reason, data.error);
}
error.status = response.statusCode;
call(callback, error);
}
});
}
};
}
module.exports = ajax;

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

"use strict";
//Abstracts constructing a Blob object, so it also works in older

@@ -11,3 +13,3 @@ //browsers that don't support the native Blob constructor. (i.e.

if (e.name !== "TypeError") {
throw(e);
throw e;
}

@@ -21,6 +23,5 @@ var BlobBuilder = window.BlobBuilder || window.MSBlobBuilder || window.MozBlobBuilder || window.WebKitBlobBuilder;

}
};
}
module.exports = createBlob;

@@ -1,77 +0,111 @@

module.exports = {
MISSING_BULK_DOCS: {
status: 400,
error: 'bad_request',
reason: "Missing JSON list of 'docs'"
},
MISSING_DOC: {
status: 404,
error: 'not_found',
reason: 'missing'
},
REV_CONFLICT: {
status: 409,
error: 'conflict',
reason: 'Document update conflict'
},
INVALID_ID: {
status: 400,
error: 'invalid_id',
reason: '_id field must contain a string'
},
MISSING_ID: {
status: 412,
error: 'missing_id',
reason: '_id is required for puts'
},
RESERVED_ID: {
status: 400,
error: 'bad_request',
reason: 'Only reserved document ids may start with underscore.'
},
NOT_OPEN: {
status: 412,
error: 'precondition_failed',
reason: 'Database not open so cannot close'
},
UNKNOWN_ERROR: {
status: 500,
error: 'unknown_error',
reason: 'Database encountered an unknown error'
},
BAD_ARG: {
status: 500,
error: 'badarg',
reason: 'Some query argument is invalid'
},
INVALID_REQUEST: {
status: 400,
error: 'invalid_request',
reason: 'Request was invalid'
},
QUERY_PARSE_ERROR: {
status: 400,
error: 'query_parse_error',
reason: 'Some query parameter is invalid'
},
DOC_VALIDATION: {
status: 500,
error: 'doc_validation',
reason: 'Bad special document member'
},
BAD_REQUEST: {
status: 400,
error: 'bad_request',
reason: 'Something wrong with the request'
},
NOT_AN_OBJECT: {
status: 400,
error: 'bad_request',
reason: 'Document must be a JSON object'
},
DB_MISSING: {
status: 404,
error: 'not_found',
reason: 'Database not found'
"use strict";
function PouchError(opts) {
this.status = opts.status;
this.name = opts.error;
this.message = opts.reason;
this.error = true;
}
PouchError.prototype = new Error();
exports.MISSING_BULK_DOCS = new PouchError({
status: 400,
error: 'bad_request',
reason: "Missing JSON list of 'docs'"
});
exports.MISSING_DOC = new PouchError({
status: 404,
error: 'not_found',
reason: 'missing'
});
exports.REV_CONFLICT = new PouchError({
status: 409,
error: 'conflict',
reason: 'Document update conflict'
});
exports.INVALID_ID = new PouchError({
status: 400,
error: 'invalid_id',
reason: '_id field must contain a string'
});
exports.MISSING_ID = new PouchError({
status: 412,
error: 'missing_id',
reason: '_id is required for puts'
});
exports.RESERVED_ID = new PouchError({
status: 400,
error: 'bad_request',
reason: 'Only reserved document ids may start with underscore.'
});
exports.NOT_OPEN = new PouchError({
status: 412,
error: 'precondition_failed',
reason: 'Database not open so cannot close'
});
exports.UNKNOWN_ERROR = new PouchError({
status: 500,
error: 'unknown_error',
reason: 'Database encountered an unknown error'
});
exports.BAD_ARG = new PouchError({
status: 500,
error: 'badarg',
reason: 'Some query argument is invalid'
});
exports.INVALID_REQUEST = new PouchError({
status: 400,
error: 'invalid_request',
reason: 'Request was invalid'
});
exports.QUERY_PARSE_ERROR = new PouchError({
status: 400,
error: 'query_parse_error',
reason: 'Some query parameter is invalid'
});
exports.DOC_VALIDATION = new PouchError({
status: 500,
error: 'doc_validation',
reason: 'Bad special document member'
});
exports.BAD_REQUEST = new PouchError({
status: 400,
error: 'bad_request',
reason: 'Something wrong with the request'
});
exports.NOT_AN_OBJECT = new PouchError({
status: 400,
error: 'bad_request',
reason: 'Document must be a JSON object'
});
exports.DB_MISSING = new PouchError({
status: 404,
error: 'not_found',
reason: 'Database not found'
});
exports.IDB_ERROR = new PouchError({
status: 500,
error: 'indexed_db_went_bad',
reason: 'unknown'
});
exports.WSQ_ERROR = new PouchError({
status: 500,
error: 'web_sql_went_bad',
reason: 'unknown'
});
exports.LDB_ERROR = new PouchError({
status: 500,
error: 'levelDB_went_went_bad',
reason: 'unknown'
});
exports.error = function (error, reason, name) {
function CustomPouchError(msg) {
this.message = reason;
if (name) {
this.name = name;
}
}
CustomPouchError.prototype = error;
return new CustomPouchError(reason);
};

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

"use strict";
// Extends method

@@ -9,3 +11,3 @@ // (taken from http://code.jquery.com/jquery-1.9.0.js)

var typename = types[i];
class2type[ "[object " + typename + "]" ] = typename.toLowerCase();
class2type["[object " + typename + "]"] = typename.toLowerCase();
}

@@ -16,5 +18,5 @@

function type(obj) {
function type(obj) {
if (obj === null) {
return String( obj );
return String(obj);
}

@@ -24,3 +26,3 @@ return typeof obj === "object" || typeof obj === "function" ?

typeof obj;
};
}

@@ -31,7 +33,7 @@ function isWindow(obj) {

function isPlainObject( obj ) {
function isPlainObject(obj) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
if ( !obj || type(obj) !== "object" || obj.nodeType || isWindow( obj ) ) {
if (!obj || type(obj) !== "object" || obj.nodeType || isWindow(obj)) {
return false;

@@ -42,5 +44,5 @@ }

// Not own constructor property must be Object
if ( obj.constructor &&
if (obj.constructor &&
!core_hasOwn.call(obj, "constructor") &&
!core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
!core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
return false;

@@ -55,8 +57,7 @@ }

// if last one is own, then all properties are own.
var key;
for ( key in obj ) {}
for (key in obj) {}
return key === undefined || core_hasOwn.call( obj, key );
};
return key === undefined || core_hasOwn.call(obj, key);
}

@@ -66,3 +67,3 @@

return type(obj) === "function";
};
}

@@ -81,3 +82,3 @@ var isArray = Array.isArray || function (obj) {

// Handle a deep copy situation
if ( typeof target === "boolean" ) {
if (typeof target === "boolean") {
deep = target;

@@ -90,3 +91,3 @@ target = arguments[1] || {};

// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !isFunction (target) ) {
if (typeof target !== "object" && !isFunction(target)) {
target = {};

@@ -96,3 +97,4 @@ }

// extend jQuery itself if only one argument is passed
if ( length === i ) {
if (length === i) {
/* jshint validthis: true */
target = this;

@@ -102,12 +104,12 @@ --i;

for ( ; i < length; i++ ) {
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[ i ]) != null) {
if ((options = arguments[i]) != null) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if ( target === copy ) {
if (target === copy) {
continue;

@@ -117,4 +119,4 @@ }

// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( isPlainObject(copy) || (copyIsArray = isArray(copy)) ) ) {
if ( copyIsArray ) {
if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
if (copyIsArray) {
copyIsArray = false;

@@ -128,8 +130,8 @@ clone = src && isArray(src) ? src : [];

// Never move original objects, clone them
target[ name ] = extend( deep, clone, copy );
target[name] = extend(deep, clone, copy);
// Don't bring in undefined values
} else if ( copy !== undefined ) {
if (!(isArray(options) && isFunction (copy))) {
target[ name ] = copy;
} else if (copy !== undefined) {
if (!(isArray(options) && isFunction(copy))) {
target[name] = copy;
}

@@ -143,3 +145,3 @@ }

return target;
};
}

@@ -146,0 +148,0 @@

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

"use strict";
/**

@@ -14,12 +16,12 @@ *

exports.MD5 = function(string) {
exports.MD5 = function (string) {
if (!process.browser) {
return crypto.createHash('md5').update(string).digest('hex');
}
function RotateLeft(lValue, iShiftBits) {
return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
function rotateLeft(lValue, iShiftBits) {
return (lValue<<iShiftBits) | (lValue>>>(32 - iShiftBits));
}
function AddUnsigned(lX,lY) {
var lX4,lY4,lX8,lY8,lResult;
function addUnsigned(lX, lY) {
var lX4, lY4, lX8, lY8, lResult;
lX8 = (lX & 0x80000000);

@@ -29,3 +31,3 @@ lY8 = (lY & 0x80000000);

lY4 = (lY & 0x40000000);
lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
if (lX4 & lY4) {

@@ -45,148 +47,154 @@ return (lResult ^ 0x80000000 ^ lX8 ^ lY8);

function F(x,y,z) { return (x & y) | ((~x) & z); }
function G(x,y,z) { return (x & z) | (y & (~z)); }
function H(x,y,z) { return (x ^ y ^ z); }
function I(x,y,z) { return (y ^ (x | (~z))); }
function f(x, y, z) { return (x & y) | ((~x) & z); }
function g(x, y, z) { return (x & z) | (y & (~z)); }
function h(x, y, z) { return (x ^ y ^ z); }
function i(x, y, z) { return (y ^ (x | (~z))); }
function FF(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
};
function ff(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(f(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
}
function GG(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
};
function gg(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(g(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
}
function HH(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
};
function hh(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(h(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
}
function II(a,b,c,d,x,s,ac) {
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
return AddUnsigned(RotateLeft(a, s), b);
};
function ii(a, b, c, d, x, s, ac) {
a = addUnsigned(a, addUnsigned(addUnsigned(i(b, c, d), x), ac));
return addUnsigned(rotateLeft(a, s), b);
}
function ConvertToWordArray(string) {
function convertToWordArray(string) {
var lWordCount;
var lMessageLength = string.length;
var lNumberOfWords_temp1=lMessageLength + 8;
var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
var lWordArray=Array(lNumberOfWords-1);
var lNumberOfWords_temp1 = lMessageLength + 8;
var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
var lWordArray = new Array(lNumberOfWords - 1);
var lBytePosition = 0;
var lByteCount = 0;
while ( lByteCount < lMessageLength ) {
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
while (lByteCount < lMessageLength) {
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
lByteCount++;
}
lWordCount = (lByteCount-(lByteCount % 4))/4;
lBytePosition = (lByteCount % 4)*8;
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
lBytePosition = (lByteCount % 4) * 8;
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
lWordArray[lNumberOfWords-2] = lMessageLength<<3;
lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
lWordArray[lNumberOfWords - 2] = lMessageLength<<3;
lWordArray[lNumberOfWords - 1] = lMessageLength>>>29;
return lWordArray;
};
}
function WordToHex(lValue) {
var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
for (lCount = 0;lCount<=3;lCount++) {
lByte = (lValue>>>(lCount*8)) & 255;
WordToHexValue_temp = "0" + lByte.toString(16);
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
function wordToHex(lValue) {
var wordToHexValue = "", wordToHexValue_temp = "", lByte, lCount;
for (lCount = 0;lCount <= 3;lCount++) {
lByte = (lValue>>>(lCount * 8)) & 255;
wordToHexValue_temp = "0" + lByte.toString(16);
wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
}
return WordToHexValue;
};
return wordToHexValue;
}
//** function Utf8Encode(string) removed. Aready defined in pidcrypt_utils.js
var x=Array();
var k,AA,BB,CC,DD,a,b,c,d;
var S11=7, S12=12, S13=17, S14=22;
var S21=5, S22=9 , S23=14, S24=20;
var S31=4, S32=11, S33=16, S34=23;
var S41=6, S42=10, S43=15, S44=21;
var x = [];
var k, AA, BB, CC, DD, a, b, c, d;
var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
// string = Utf8Encode(string); #function call removed
x = ConvertToWordArray(string);
x = convertToWordArray(string);
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
a = 0x67452301;
b = 0xEFCDAB89;
c = 0x98BADCFE;
d = 0x10325476;
for (k=0;k<x.length;k+=16) {
AA=a; BB=b; CC=c; DD=d;
a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
d=GG(d,a,b,c,x[k+10],S22,0x2441453);
c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
a=II(a,b,c,d,x[k+0], S41,0xF4292244);
d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
c=II(c,d,a,b,x[k+6], S43,0xA3014314);
b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
a=AddUnsigned(a,AA);
b=AddUnsigned(b,BB);
c=AddUnsigned(c,CC);
d=AddUnsigned(d,DD);
for (k = 0;k < x.length;k += 16) {
AA = a;
BB = b;
CC = c;
DD = d;
a = ff(a, b, c, d, x[k + 0], S11, 0xD76AA478);
d = ff(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
c = ff(c, d, a, b, x[k + 2], S13, 0x242070DB);
b = ff(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
a = ff(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
d = ff(d, a, b, c, x[k + 5], S12, 0x4787C62A);
c = ff(c, d, a, b, x[k + 6], S13, 0xA8304613);
b = ff(b, c, d, a, x[k + 7], S14, 0xFD469501);
a = ff(a, b, c, d, x[k + 8], S11, 0x698098D8);
d = ff(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
c = ff(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
b = ff(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
a = ff(a, b, c, d, x[k + 12], S11, 0x6B901122);
d = ff(d, a, b, c, x[k + 13], S12, 0xFD987193);
c = ff(c, d, a, b, x[k + 14], S13, 0xA679438E);
b = ff(b, c, d, a, x[k + 15], S14, 0x49B40821);
a = gg(a, b, c, d, x[k + 1], S21, 0xF61E2562);
d = gg(d, a, b, c, x[k + 6], S22, 0xC040B340);
c = gg(c, d, a, b, x[k + 11], S23, 0x265E5A51);
b = gg(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
a = gg(a, b, c, d, x[k + 5], S21, 0xD62F105D);
d = gg(d, a, b, c, x[k + 10], S22, 0x2441453);
c = gg(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
b = gg(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
a = gg(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
d = gg(d, a, b, c, x[k + 14], S22, 0xC33707D6);
c = gg(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
b = gg(b, c, d, a, x[k + 8], S24, 0x455A14ED);
a = gg(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
d = gg(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
c = gg(c, d, a, b, x[k + 7], S23, 0x676F02D9);
b = gg(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
a = hh(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
d = hh(d, a, b, c, x[k + 8], S32, 0x8771F681);
c = hh(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
b = hh(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
a = hh(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
d = hh(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
c = hh(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
b = hh(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
a = hh(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
d = hh(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
c = hh(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
b = hh(b, c, d, a, x[k + 6], S34, 0x4881D05);
a = hh(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
d = hh(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
c = hh(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
b = hh(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
a = ii(a, b, c, d, x[k + 0], S41, 0xF4292244);
d = ii(d, a, b, c, x[k + 7], S42, 0x432AFF97);
c = ii(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
b = ii(b, c, d, a, x[k + 5], S44, 0xFC93A039);
a = ii(a, b, c, d, x[k + 12], S41, 0x655B59C3);
d = ii(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
c = ii(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
b = ii(b, c, d, a, x[k + 1], S44, 0x85845DD1);
a = ii(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
d = ii(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
c = ii(c, d, a, b, x[k + 6], S43, 0xA3014314);
b = ii(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
a = ii(a, b, c, d, x[k + 4], S41, 0xF7537E82);
d = ii(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
c = ii(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
b = ii(b, c, d, a, x[k + 9], S44, 0xEB86D391);
a = addUnsigned(a, AA);
b = addUnsigned(b, BB);
c = addUnsigned(c, CC);
d = addUnsigned(d, DD);
}
var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
return temp.toLowerCase();
};

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

"use strict";
// BEGIN Math.uuid.js

@@ -39,3 +41,3 @@

function uuid(len, radix) {
var chars = uuid.CHARS
var chars = uuid.CHARS;
var uuidInner = [];

@@ -48,3 +50,5 @@ var i;

// Compact form
for (i = 0; i < len; i++) uuidInner[i] = chars[0 | Math.random()*radix];
for (i = 0; i < len; i++) {
uuidInner[i] = chars[0 | Math.random() * radix];
}
} else {

@@ -62,4 +66,4 @@ // rfc4122, version 4 form

if (!uuidInner[i]) {
r = 0 | Math.random()*16;
uuidInner[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
r = 0 | Math.random() * 16;
uuidInner[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r];
}

@@ -70,3 +74,4 @@ }

return uuidInner.join('');
};
}
uuid.CHARS = (

@@ -73,0 +78,0 @@ '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' +

"use strict";
var PouchUtils = require('./utils');
var PouchAdapter = require('./adapter')(Pouch);
function Pouch(name, opts, callback) {
var PouchDB = require('./setup');
if (!(this instanceof Pouch)) {
return new Pouch(name, opts, callback);
}
module.exports = PouchDB;
if (typeof opts === 'function' || typeof opts === 'undefined') {
callback = opts;
opts = {};
}
if (typeof name === 'object') {
opts = name;
name = undefined;
}
if (typeof callback === 'undefined') {
callback = function () {};
}
var backend = Pouch.parseAdapter(opts.name || name);
opts.originalName = name;
opts.name = opts.name || backend.name;
opts.adapter = opts.adapter || backend.adapter;
if (!Pouch.adapters[opts.adapter]) {
throw 'Adapter is missing';
}
if (!Pouch.adapters[opts.adapter].valid()) {
throw 'Invalid Adapter';
}
var adapter = new PouchAdapter(opts, function (err, db) {
if (err) {
if (callback) {
callback(err);
}
return;
}
for (var plugin in Pouch.plugins) {
// In future these will likely need to be async to allow the plugin
// to initialise
var pluginObj = Pouch.plugins[plugin](db);
for (var api in pluginObj) {
// We let things like the http adapter use its own implementation
// as it shares a lot of code
if (!(api in db)) {
db[api] = pluginObj[api];
}
}
}
db.taskqueue.ready(true);
db.taskqueue.execute(db);
callback(null, db);
});
for (var j in adapter) {
this[j] = adapter[j];
}
for (var plugin in Pouch.plugins) {
// In future these will likely need to be async to allow the plugin
// to initialise
var pluginObj = Pouch.plugins[plugin](this);
for (var api in pluginObj) {
// We let things like the http adapter use its own implementation
// as it shares a lot of code
if (!(api in this)) {
this[api] = pluginObj[api];
}
}
}
}
Pouch.adapters = {};
Pouch.plugins = {};
Pouch.prefix = '_pouch_';
Pouch.parseAdapter = function (name) {
var match = name.match(/([a-z\-]*):\/\/(.*)/);
var adapter;
if (match) {
// the http adapter expects the fully qualified name
name = /http(s?)/.test(match[1]) ? match[1] + '://' + match[2] : match[2];
adapter = match[1];
if (!Pouch.adapters[adapter].valid()) {
throw 'Invalid adapter';
}
return {name: name, adapter: match[1]};
}
var preferredAdapters = ['idb', 'leveldb', 'websql'];
for (var i = 0; i < preferredAdapters.length; ++i) {
if (preferredAdapters[i] in Pouch.adapters) {
adapter = Pouch.adapters[preferredAdapters[i]];
var use_prefix = 'use_prefix' in adapter ? adapter.use_prefix : true;
return {
name: use_prefix ? Pouch.prefix + name : name,
adapter: preferredAdapters[i]
};
}
}
throw 'No valid adapter found';
};
Pouch.destroy = function (name, opts, callback) {
if (typeof opts === 'function' || typeof opts === 'undefined') {
callback = opts;
opts = {};
}
if (typeof name === 'object') {
opts = name;
name = undefined;
}
if (typeof callback === 'undefined') {
callback = function () {};
}
var backend = Pouch.parseAdapter(opts.name || name);
var cb = function (err, response) {
if (err) {
callback(err);
return;
}
for (var plugin in Pouch.plugins) {
Pouch.plugins[plugin]._delete(backend.name);
}
//console.log(backend.name + ': Delete Database');
// call destroy method of the particular adaptor
Pouch.adapters[backend.adapter].destroy(backend.name, opts, callback);
};
// remove Pouch from allDBs
Pouch.removeFromAllDbs(backend, cb);
};
Pouch.removeFromAllDbs = function (opts, callback) {
// Only execute function if flag is enabled
if (!Pouch.enableAllDbs) {
callback();
return;
}
// skip http and https adaptors for allDbs
var adapter = opts.adapter;
if (adapter === "http" || adapter === "https") {
callback();
return;
}
// remove db from Pouch.ALL_DBS
new Pouch(Pouch.allDBName(opts.adapter), function (err, db) {
if (err) {
// don't fail when allDbs fail
//console.error(err);
callback();
return;
}
// check if db has been registered in Pouch.ALL_DBS
var dbname = Pouch.dbName(opts.adapter, opts.name);
db.get(dbname, function (err, doc) {
if (err) {
callback();
} else {
db.remove(doc, function (err, response) {
if (err) {
//console.error(err);
}
callback();
});
}
});
});
};
Pouch.adapter = function (id, obj) {
if (obj.valid()) {
Pouch.adapters[id] = obj;
}
};
Pouch.plugin = function (id, obj) {
Pouch.plugins[id] = obj;
};
// flag to toggle allDbs (off by default)
Pouch.enableAllDbs = false;
// name of database used to keep track of databases
Pouch.ALL_DBS = "_allDbs";
Pouch.dbName = function (adapter, name) {
return [adapter, "-", name].join('');
};
Pouch.realDBName = function (adapter, name) {
return [adapter, "://", name].join('');
};
Pouch.allDBName = function (adapter) {
return [adapter, "://", Pouch.prefix + Pouch.ALL_DBS].join('');
};
Pouch.open = function (opts, callback) {
// Only register pouch with allDbs if flag is enabled
if (!Pouch.enableAllDbs) {
callback();
return;
}
var adapter = opts.adapter;
// skip http and https adaptors for allDbs
if (adapter === "http" || adapter === "https") {
callback();
return;
}
new Pouch(Pouch.allDBName(adapter), function (err, db) {
if (err) {
// don't fail when allDb registration fails
//console.error(err);
callback();
return;
}
// check if db has been registered in Pouch.ALL_DBS
var dbname = Pouch.dbName(adapter, opts.name);
db.get(dbname, function (err, response) {
if (err && err.status === 404) {
db.put({
_id: dbname,
dbname: opts.originalName
}, function (err) {
if (err) {
//console.error(err);
}
callback();
});
} else {
callback();
}
});
});
};
Pouch.allDbs = function (callback) {
var accumulate = function (adapters, all_dbs) {
if (adapters.length === 0) {
// remove duplicates
var result = [];
all_dbs.forEach(function (doc) {
var exists = result.some(function (db) {
return db.id === doc.id;
});
if (!exists) {
result.push(doc);
}
});
// return an array of dbname
callback(null, result.map(function (row) {
return row.doc.dbname;
}));
return;
}
var adapter = adapters.shift();
// skip http and https adaptors for allDbs
if (adapter === "http" || adapter === "https") {
accumulate(adapters, all_dbs);
return;
}
new Pouch(Pouch.allDBName(adapter), function (err, db) {
if (err) {
callback(err);
return;
}
db.allDocs({include_docs: true}, function (err, response) {
if (err) {
callback(err);
return;
}
// append from current adapter rows
all_dbs.unshift.apply(all_dbs, response.rows);
// code to clear allDbs.
// response.rows.forEach(function (row) {
// db.remove(row.doc, function () {
// //console.log(arguments);
// });
// });
// recurse
accumulate(adapters, all_dbs);
});
});
};
var adapters = Object.keys(Pouch.adapters);
accumulate(adapters, []);
};
// Enumerate errors, add the status code so we can reflect the HTTP api
// in future
module.exports = Pouch;
Pouch.ajax = require('./deps/ajax');
Pouch.extend = require('./deps/extend');
Pouch.utils = PouchUtils;
Pouch.Errors = require('./deps/errors');
Pouch.replicate = require('./replicate').replicate;
Pouch.version = require('./version');
PouchDB.ajax = require('./deps/ajax');
PouchDB.extend = require('./deps/extend');
PouchDB.utils = require('./utils');
PouchDB.Errors = require('./deps/errors');
PouchDB.replicate = require('./replicate').replicate;
PouchDB.version = require('./version');
var httpAdapter = require('./adapters/http');
Pouch.adapter('http', httpAdapter);
Pouch.adapter('https', httpAdapter);
PouchDB.adapter('http', httpAdapter);
PouchDB.adapter('https', httpAdapter);
Pouch.adapter('idb', require('./adapters/idb'));
Pouch.adapter('websql', require('./adapters/websql'));
Pouch.plugin('mapreduce', require('pouchdb-mapreduce'));
PouchDB.adapter('idb', require('./adapters/idb'));
PouchDB.adapter('websql', require('./adapters/websql'));
PouchDB.plugin('mapreduce', require('pouchdb-mapreduce'));
if (!process.browser) {
var ldbAdapter = require('./adapters/leveldb');
Pouch.adapter('ldb', ldbAdapter);
Pouch.adapter('leveldb', ldbAdapter);
PouchDB.adapter('ldb', ldbAdapter);
PouchDB.adapter('leveldb', ldbAdapter);
}

@@ -41,3 +41,5 @@ 'use strict';

var task = queue.shift();
task.fun.apply(null, task.args);
process.nextTick(function () {
task.fun.apply(null, task.args);
});
};

@@ -69,6 +71,10 @@

callback(null, 0);
} else if (err) {
callback(err);
} else {
src.get(id, function (err, sourceDoc) {
if (err && err.status === 404 || targetDoc.last_seq !== sourceDoc.last_seq) {
if (err && err.status === 404 || (!err && (targetDoc.last_seq !== sourceDoc.last_seq))) {
callback(null, 0);
} else if (err) {
callback(err);
} else {

@@ -75,0 +81,0 @@ callback(null, sourceDoc.last_seq);

@@ -13,5 +13,2 @@ /*jshint strict: false */

exports.error = function (error, reason) {
return exports.extend({}, error, {reason: reason});
};
// List of top level reserved words for doc

@@ -52,3 +49,6 @@ var reservedWords = [

// - any other string value is a valid id
function isValidId(id) {
exports.isValidId = function (id) {
if (!id || (typeof id !== 'string')) {
return false;
}
if (/^_/.test(id)) {

@@ -58,3 +58,3 @@ return (/^_(design|local)/).test(id);

return true;
}
};

@@ -203,3 +203,3 @@ function isChromeApp() {

}
else if (!isValidId(doc._id)) {
else if (!exports.isValidId(doc._id)) {
error = errors.RESERVED_ID;

@@ -206,0 +206,0 @@ }

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

module.exports = '1.0.0';
module.exports = '1.1.0';
{
"name": "pouchdb",
"version": "1.0.0",
"version": "1.1.0",
"description": "PouchDB is a pocket-sized database.",

@@ -23,3 +23,3 @@ "release": "nightly",

"request": "~2.28.0",
"pouchdb-mapreduce": "0.2.0"
"pouchdb-mapreduce": "0.3.1"
},

@@ -29,2 +29,3 @@ "devDependencies": {

"webdriverjs": "~0.7.14",
"selenium-standalone": "~2.38.0",
"watchify": "~0.4.1",

@@ -37,4 +38,4 @@ "uglify-js": "~2.4.6",

"qunit": "~0.5.17",
"browserify": "~2.36.1",
"tin": "~0.3.1"
"tin": "~0.3.1",
"browserify": "~3.14.1"
},

@@ -52,6 +53,6 @@ "maintainers": [

"scripts": {
"jshint": "jshint -c .jshintrc lib/*.js lib/adapters/*.js",
"build-js": "mkdir -p dist && browserify lib/index.js -s PouchDB -o dist/pouchdb-nightly.js",
"watch-js": "mkdir -p dist && watchify lib/index.js -s PouchDB -o dist/pouchdb-nightly.js",
"uglify": "uglifyjs dist/pouchdb-nightly.js -mc > dist/pouchdb-nightly.min.js",
"jshint": "./node_modules/.bin/jshint -c .jshintrc lib/*.js lib/adapters/*.js lib/deps/*.js",
"build-js": "mkdir -p dist && ./node_modules/.bin/browserify lib/index.js -s PouchDB -o dist/pouchdb-nightly.js",
"watch-js": "mkdir -p dist && ./node_modules/.bin/watchify lib/index.js -s PouchDB -o dist/pouchdb-nightly.js",
"uglify": "./node_modules/.bin/uglifyjs dist/pouchdb-nightly.js -mc > dist/pouchdb-nightly.min.js",
"build": "npm run build-js && npm run uglify",

@@ -61,3 +62,3 @@ "test-node": "./bin/test-node.js",

"dev-server": "npm run watch-js & ./bin/dev-server.js",
"test": "npm run jshint && npm run test-node"
"test": "npm run jshint && npm run test-node && npm run test-browser"
},

@@ -64,0 +65,0 @@ "browser": {

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

/*globals openTestDB: false */
"use strict";

@@ -13,3 +11,3 @@

asyncTest("Add a doc", 2, function() {
openTestDB(this.name, function(err, db) {
testUtils.openTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -16,0 +14,0 @@ db.post({test:"somestuff"}, function (err, info) {

@@ -1,20 +0,6 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
/*globals PouchDB: true, QUnit, uuid, asyncTest, ok, start*/
"use strict";
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -67,3 +53,3 @@

qunit('allDbs: ' + adapter, {
QUnit.module('allDbs: ' + adapter, {
setup: function() {

@@ -78,3 +64,3 @@ // enable allDbs

for (var i = 0; i < 5; i++) {
pouchName = 'testdb_' + uuid();
pouchName = 'testdb_' + testUtils.uuid();
this.pouchNames.push([adapter, "://", pouchName].join(''));

@@ -310,3 +296,3 @@ }

// 2. Otherwise, the dbname will just contain the dbname (without the adapter prefix)
qunit("allDbs return value", {
QUnit.module("allDbs return value", {
setup: function() {

@@ -327,3 +313,3 @@ // enable allDbs

pouchName = 'testdb_' + uuid();
pouchName = 'testdb_' + testUtils.uuid();
pouchNames.push([adapter, "://", pouchName].join(''));

@@ -334,3 +320,3 @@ });

for (var i = 0; i < 3; i++) {
pouchName = 'testdb_' + uuid();
pouchName = 'testdb_' + testUtils.uuid();
pouchNames.push(pouchName);

@@ -337,0 +323,0 @@ }

@@ -1,25 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false */
/*globals cleanupTestDatabases: false, writeDocs: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var LevelPouch;
var PouchDB;
var utils;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -29,8 +12,8 @@

qunit('all_docs: ' + adapter, {
QUnit.module('all_docs: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -46,4 +29,4 @@

asyncTest('Testing all docs', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
db.allDocs(function(err, result) {

@@ -89,4 +72,4 @@ var rows = result.rows;

asyncTest('Testing allDocs opts.keys', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
var keys = ["3", "1"];

@@ -139,4 +122,4 @@ db.allDocs({keys: keys}, function(err, result) {

asyncTest('Testing deleting in changes', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
db.get('1', function(err, doc) {

@@ -160,4 +143,4 @@ db.remove(doc, function(err, deleted) {

asyncTest('Testing updating in changes', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
db.get('3', function(err, doc) {

@@ -180,4 +163,4 @@ doc.updated = 'totally';

asyncTest('Testing include docs', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
db.changes({

@@ -195,4 +178,4 @@ include_docs: true,

asyncTest('Testing conflicts', function() {
initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {
// add conflicts

@@ -250,3 +233,3 @@ var conflictDoc1 = {

asyncTest('test basic collation', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = {docs: [{_id: "z", foo: "z"}, {_id: "a", foo: "a"}]};

@@ -263,3 +246,3 @@ db.bulkDocs(docs, function(err, res) {

asyncTest('test limit option and total_rows', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = {

@@ -281,2 +264,21 @@ docs: [

asyncTest('test escaped startkey/endkey', 1, function () {
testUtils.initTestDB(this.name, function (err, db) {
var id1 = "\"crazy id!\" a";
var id2 = "\"crazy id!\" z";
var docs = {
docs: [
{_id: id1, foo: "a"},
{_id: id2, foo: "z"}
]
};
db.bulkDocs(docs, function (err, res) {
db.allDocs({ startkey: id1, endkey: id2 }, function (err, res) {
equal(res.total_rows, 2, 'Accurately return total_rows count');
start();
});
});
});
});
});

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

/*globals initTestDB, emit: true, generateAdapterUrl, Pouch */
/*globals PERSIST_DATABASES, initDBPair, utils: true, strictEqual */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false */
/*globals readBlob: false, makeBlob: false, base64Blob: false */
/*globals cleanupTestDatabases: false */
"use strict";

@@ -14,28 +8,15 @@

['local-1', 'local-2']];
var qunit = module;
var LevelPouch;
var PouchUtils;
var utils;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
PouchUtils = require('../lib/utils');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
adapters.map(function(adapter) {
qunit('attachments: ' + adapter, {
QUnit.module('attachments: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -87,3 +68,3 @@

var db;
initTestDB(this.name, function(err, _db) {
testUtils.initTestDB(this.name, function(err, _db) {
db = _db;

@@ -98,7 +79,7 @@ db.put(binAttDoc, function(err, write) {

db.getAttachment('bin_doc', 'foo.txt', function(err, res) {
readBlob(res, function(data) {
testUtils.readBlob(res, function(data) {
strictEqual(data, 'This is a base64 encoded text', 'Correct data returned');
db.put(binAttDoc2, function(err, rev) {
db.getAttachment('bin_doc2', 'foo.txt', function(err, res, xhr) {
readBlob(res, function(data) {
testUtils.readBlob(res, function(data) {
strictEqual(data, '', 'Correct data returned');

@@ -116,6 +97,6 @@ moreTests(rev.rev);

function moreTests(rev) {
var blob = makeBlob('This is no base64 encoded text');
var blob = testUtils.makeBlob('This is no base64 encoded text');
db.putAttachment('bin_doc2', 'foo2.txt', rev, blob, 'text/plain', function(err, wtf) {
db.getAttachment('bin_doc2', 'foo2.txt', function(err, res, xhr) {
readBlob(res, function(data) {
testUtils.readBlob(res, function(data) {
ok(data, 'This is no base64 encoded text', 'Correct data returned');

@@ -139,7 +120,7 @@ db.get('bin_doc2', {attachments: true}, function(err, res, xhr) {

asyncTest("Test getAttachment", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put(binAttDoc, function(err, res) {
db.getAttachment('bin_doc', 'foo.txt', function(err, res) {
ok(!err, "Attachment read");
readBlob(res, function(data) {
testUtils.readBlob(res, function(data) {
strictEqual(data, "This is a base64 encoded text", "correct data");

@@ -154,3 +135,3 @@ start();

asyncTest("Test attachments in allDocs/changes", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -223,7 +204,7 @@ {

asyncTest("Test getAttachment with PNG", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put(pngAttDoc, function(err, res) {
db.getAttachment('png_doc', 'foo.png', function(err, res) {
ok(!err, "Attachment read");
base64Blob(res, function(data) {
testUtils.base64Blob(res, function(data) {
strictEqual(data, pngAttDoc._attachments['foo.png'].data,

@@ -240,3 +221,3 @@ "correct data");

var invalidDoc = {'_id': '_invalid', foo: 'bar'};
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [invalidDoc, binAttDoc]}, function(err, info) {

@@ -250,4 +231,4 @@ ok(err, 'bad request');

asyncTest("Test create attachment and doc in one go", function() {
initTestDB(this.name, function(err, db) {
var blob = makeBlob('Mytext');
testUtils.initTestDB(this.name, function(err, db) {
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('anotherdoc', 'mytext', blob, 'text/plain', function(err, res) {

@@ -261,3 +242,3 @@ ok(res.ok);

asyncTest("Test create attachment and doc in one go without callback", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var changes = db.changes({

@@ -279,3 +260,3 @@ continuous: true,

});
var blob = makeBlob('Mytext');
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('anotherdoc2', 'mytext', blob, 'text/plain');

@@ -286,3 +267,3 @@ });

asyncTest("Test create attachment without callback", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({ _id: 'anotherdoc3' }, function(err, resp) {

@@ -307,3 +288,3 @@ ok(!err, 'doc was saved');

});
var blob = makeBlob('Mytext');
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('anotherdoc3', 'mytext', resp.rev, blob, 'text/plain');

@@ -316,5 +297,5 @@ });

asyncTest("Test put attachment on a doc without attachments", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({ _id: 'mydoc' }, function(err, resp) {
var blob = makeBlob('Mytext');
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('mydoc', 'mytext', resp.rev, blob, 'text/plain', function(err, res) {

@@ -329,3 +310,3 @@ ok(res.ok);

asyncTest("Testing with invalid rev", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {_id: 'adoc'};

@@ -338,6 +319,6 @@ db.put(doc, function(err, resp) {

ok(!err, 'Doc has been updated');
var blob = makeBlob('bar');
var blob = testUtils.makeBlob('bar');
db.putAttachment('adoc', 'foo.txt', doc._rev, blob, 'text/plain', function(err) {
ok(err, 'Attachment has not been saved');
equal(err.error, 'conflict', 'error is a conflict');
equal(err.name, 'conflict', 'error is a conflict');
start();

@@ -351,3 +332,3 @@ });

asyncTest('Test get with attachments: true if empty attachments', function() {
initTestDB(this.name, function(erro, db) {
testUtils.initTestDB(this.name, function(erro, db) {
db.put({_id: 'foo', _attachments: {}}, function(err, resp) {

@@ -363,3 +344,3 @@ db.get('foo', {attachments: true}, function(err, res) {

asyncTest("Test delete attachment from a doc", function() {
initTestDB(this.name, function(erro, db) {
testUtils.initTestDB(this.name, function(erro, db) {
db.put({_id: 'mydoc', _attachments: {

@@ -399,3 +380,3 @@ 'mytext1': {

asyncTest("Test a document with a json string attachment", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put(jsonDoc, function(err, results) {

@@ -409,3 +390,3 @@ ok(!err, 'saved doc with attachment');

db.getAttachment(results.id, 'foo.json', function(err, attachment) {
readBlob(attachment, function(data) {
testUtils.readBlob(attachment, function(data) {
equal("eyJIZWxsbyI6IndvcmxkIn0=", jsonDoc._attachments['foo.json'].data,

@@ -422,5 +403,5 @@ 'correct data');

asyncTest("Test remove doc with attachment", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({ _id: 'mydoc' }, function(err, resp) {
var blob = makeBlob('Mytext');
var blob = testUtils.makeBlob('Mytext');
db.putAttachment('mydoc', 'mytext', resp.rev, blob, 'text/plain', function(err, res) {

@@ -439,3 +420,3 @@ db.get('mydoc',{attachments:false},function(err,doc){

asyncTest("Try to insert a doc with unencoded attachment", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {

@@ -453,3 +434,3 @@ _id: "foo",

strictEqual(err.status, 500, "correct error");
strictEqual(err.error, "badarg", "correct error");
strictEqual(err.name, "badarg", "correct error");
start();

@@ -461,3 +442,3 @@ });

asyncTest("Try to get attachment of unexistent doc", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.getAttachment('unexistent', 'attachment', function(err, res) {

@@ -487,3 +468,3 @@ ok(err, "Correctly returned error");

asyncTest("Test stubs", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.putAttachment('a', 'foo2.txt', '', '', 'text/plain', function(err) {

@@ -499,3 +480,3 @@ db.allDocs({include_docs: true}, function(err, docs) {

asyncTest("Try to get unexistent attachment of some doc", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id: "foo"}, function(err, res) {

@@ -515,6 +496,6 @@ ok(!err, "doc inserted");

qunit('replication: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('replication: ' + adapters[0] + ':' + adapters[1], {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.name = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
}

@@ -542,3 +523,3 @@ });

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs1}, function(err, info) {

@@ -545,0 +526,0 @@ var replicate = db.replicate.from(remote, function() {

@@ -1,26 +0,12 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false */
"use strict";
var remote = {
host: 'localhost:2020'
};
var remote = {host: 'localhost:2020'};
var local = 'test_suite_db';
var qunit = module;
if (typeof module !== undefined && module.exports) {
Pouch = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
Pouch.ajax = Pouch.utils.Pouch.ajax;
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
qunit('auth_replication', {
QUnit.module('auth_replication', {
setup: function () {

@@ -31,3 +17,3 @@ this.name = local;

teardown: function() {
if (!PERSIST_DATABASES) {
if (!testUtils.PERSIST_DATABASES) {
Pouch.destroy(this.name);

@@ -34,0 +20,0 @@ Pouch.destroy(this.remote);

@@ -1,22 +0,8 @@

/*globals initTestDB, openTestDB, emit, generateAdapterUrl, cleanupTestDatabases */
/*globals PERSIST_DATABASES, initDBPair, Pouch.ajax, strictEqual */
/*globals utils: true, LevelPouch: true */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var LevelPouch;
var utils;
var PouchDB;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -26,12 +12,12 @@

qunit("basics: " + adapter, {
QUnit.module("basics: " + adapter, {
setup: function() {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = false;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest("Create a pouch", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'created a pouch');

@@ -44,3 +30,3 @@ start();

var name = this.name;
initTestDB(name, function(err, db) {
testUtils.initTestDB(name, function(err, db) {
PouchDB.destroy(name, function(err, db) {

@@ -54,3 +40,3 @@ ok(!err);

asyncTest("Add a doc", 2, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -65,3 +51,3 @@ db.post({test:"somestuff"}, function (err, info) {

asyncTest("Modify a doc", 3, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -79,3 +65,3 @@ db.post({test: "somestuff"}, function (err, info) {

asyncTest("Read db id", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(typeof(db.id()) === 'string' && db.id() !== '', "got id");

@@ -87,3 +73,3 @@ start();

asyncTest("Close db", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.close(function(error){

@@ -98,6 +84,6 @@ ok(!err, 'close called back with an error');

var dbName = this.name;
initTestDB(dbName, function(err, db) {
testUtils.initTestDB(dbName, function(err, db) {
db.close(function(error){
ok(!err, 'close called back with an error');
openTestDB(dbName, function(err, db){
testUtils.openTestDB(dbName, function(err, db){
ok(typeof(db.id()) === 'string' && db.id() !== '', "got id");

@@ -111,3 +97,3 @@ start();

asyncTest("Modify a doc with incorrect rev", 3, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -125,14 +111,4 @@ db.post({test: "somestuff"}, function (err, info) {

// Documents with underscores in ids are valid in cloudant
// asyncTest("Add a doc with leading underscore in id", function() {
// initTestDB(this.name, function(err, db) {
// db.post({_id: '_testing', value: 42}, function(err, info) {
// ok(err);
// start();
// });
// });
// });
asyncTest("Remove doc", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function(err, info) {

@@ -150,3 +126,3 @@ db.remove({test:"somestuff", _id:info.id, _rev:info.rev}, function(doc) {

asyncTest("Doc removal leaves only stub", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id: "foo", value: "test"}, function(err, res) {

@@ -166,3 +142,3 @@ db.get("foo", function(err, doc) {

asyncTest("Remove doc twice with specified id", 4, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id:"specifiedId", test:"somestuff"}, function(err, info) {

@@ -189,3 +165,3 @@ db.get("specifiedId", function(err, doc) {

asyncTest("Remove doc, no callback", 2, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var changesCount = 2;

@@ -211,3 +187,3 @@ var changes = db.changes({

asyncTest("Delete document without id", 1, function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.remove({test:'ing'}, function(err) {

@@ -221,3 +197,3 @@ ok(err, 'failed to delete');

asyncTest("Bulk docs", 3, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -232,40 +208,4 @@ db.bulkDocs({docs: [{test:"somestuff"}, {test:"another"}]}, function(err, infos) {

/*
asyncTest("Sync a doc", 6, function() {
var couch = generateAdapterUrl('http-2');
initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');
initTestDB(couch, function(err, db2) {
ok(!err, 'opened the couch');
db.put({_id:"adoc", test:"somestuff"}, function (err, info) {
ok(!err, 'saved a doc with post');
db.replicate.to(couch, function(err, info) {
ok(!err, 'replicated pouch to couch');
db.replicate.from(couch, function(err, info) {
ok(!err, 'replicated couch back to pouch');
db.get("adoc", {conflicts:true}, function(err, doc) {
ok(!doc._conflicts, 'doc has no conflicts');
start();
});
});
});
});
})
});
});
*/
// From here we are copying over tests from CouchDB
// https://github.com/apache/couchdb/blob/master/share/www/script/test/basics.js
/*
asyncTest("Check database with slashes", 1, function() {
initTestDB('idb://test_suite_db%2Fwith_slashes', function(err, db) {
ok(!err, 'opened');
start();
});
});
*/
asyncTest("Basic checks", 8, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.info(function(err, info) {

@@ -303,6 +243,6 @@ var updateSeq = info.update_seq;

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: bad_docs}, function(err, res) {
strictEqual(err.status, 500);
strictEqual(err.error, 'doc_validation');
strictEqual(err.name, 'doc_validation');
start();

@@ -316,7 +256,8 @@ });

var docs = [{"id":"0"}, {"id":"1"}, {"id":"2"}, {"id":"3"}, {"id":"4"}, {"id":"5"}];
var docs = [{"id":"0"}, {"id":"1"}, {"id":"2"},
{"id":"3"}, {"id":"4"}, {"id":"5"}];
var x = 0;
var timer;
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var save = function() {

@@ -336,3 +277,3 @@ db.bulkDocs({docs: docs}, function(err, res) {

asyncTest("Testing valid id", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({'_id': 123, test: "somestuff"}, function (err, info) {

@@ -346,3 +287,3 @@ ok(err, 'id must be a string');

asyncTest("Put doc without _id should fail", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({test:"somestuff"}, function(err, info) {

@@ -357,3 +298,3 @@ ok(err, '_id is required');

var name = this.name;
initTestDB(name, function(err, db) {
testUtils.initTestDB(name, function(err, db) {
db.post({test:"somestuff"}, function (err, info) {

@@ -380,3 +321,3 @@ new PouchDB(name, function(err, db) {

}
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
writeAndDelete(db, function() {

@@ -396,3 +337,3 @@ writeAndDelete(db, function() {

asyncTest('Error when document is not an object', 5, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc1 = [{_id: 'foo'}, {_id: 'bar'}];

@@ -432,7 +373,46 @@ var doc2 = "this is not an object";

test('Error works', 1, function() {
deepEqual(PouchDB.utils.error(PouchDB.Errors.BAD_REQUEST, "love needs no reason"),
{status: 400, error: "bad_request", reason: "love needs no reason"},
"should be the same");
test('Error works', 3, function() {
var newError = PouchDB.Errors.error(PouchDB.Errors.BAD_REQUEST, "love needs no message");
ok(newError.status === 400);
ok(newError.name === 'bad_request');
ok(newError.message === "love needs no message");
});
asyncTest('Fail to fetch a doc after db was deleted', 2, function() {
var name = this.name;
testUtils.initTestDB(name, function(err, db) {
var doc = {_id: 'foodoc'};
var doc2 = {_id: 'foodoc2'};
var db2 = new PouchDB({name: name});
db.put(doc, function() {
db2.put(doc2, function() {
db.allDocs(function(err, docs) {
equal(docs.total_rows, 2, 'Wrote 2 documents');
PouchDB.destroy({name: name}, function() {
db2 = new PouchDB(name);
db2.get(doc._id, function(err, doc) {
equal(err.status, 404, 'doc is missing');
start();
});
});
});
});
});
});
});
asyncTest("Can't add docs with empty ids", 6, function() {
var docs = [{}, {_id : null}, {_id : undefined}, {_id : ''},
{_id : {}}, {_id : '_underscored_id'}];
testUtils.initTestDB(this.name, function(err, db) {
docs.forEach(function(doc) {
db.put(doc, function (err, info) {
ok(err, "didn't get an error for doc: " + JSON.stringify(doc) +
'; response was ' + JSON.stringify(info));
start();
});
});
});
});
});

@@ -1,25 +0,26 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false */
/*globals cleanupTestDatabases: false */
"use strict";
// Porting tests from Apache CouchDB bulk docs tests
// https://github.com/apache/couchdb/blob/master/share/www/script/test/bulk_docs.js
var adapters = ['local-1', 'http-1'];
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
for (var k in utils) {
global[k] = global[k] || utils[k];
function makeDocs(start, end, templateDoc) {
var templateDocSrc = templateDoc ? JSON.stringify(templateDoc) : "{}";
if (end === undefined) {
end = start;
start = 0;
}
qunit = QUnit.module;
var docs = [];
for (var i = start; i < end; i++) {
/*jshint evil:true */
var newDoc = eval("(" + templateDocSrc + ")");
newDoc._id = (i).toString();
newDoc.integer = i;
newDoc.string = (i).toString();
docs.push(newDoc);
}
return docs;
}

@@ -29,8 +30,8 @@

qunit('bulk_docs: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
QUnit.module('bulk_docs: ' + adapter, {
setup: function () {
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -46,3 +47,3 @@

asyncTest('Testing bulk docs', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = makeDocs(5);

@@ -68,3 +69,3 @@ db.bulkDocs({docs: docs}, function(err, results) {

db.bulkDocs({docs: docs}, function(err, results) {
ok(results[0].error === 'conflict', 'First doc should be in conflict');
ok(results[0].name === 'conflict', 'First doc should be in conflict');
ok(typeof results[0].rev === "undefined", 'no rev in conflict');

@@ -84,3 +85,3 @@ for (i = 1; i < 5; i++) {

asyncTest('No id in bulk docs', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var newdoc = {"_id": "foobar", "body": "baz"};

@@ -94,3 +95,3 @@ db.put(newdoc, function(err, doc) {

db.bulkDocs({docs: docs}, function(err, results) {
ok(results[0].error === 'conflict' || results[1].error === 'conflict');
ok(results[0].name === 'conflict' || results[1].name === 'conflict');
start();

@@ -103,3 +104,3 @@ });

asyncTest('No _rev and new_edits=false', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -119,5 +120,5 @@ {_id: "foo", integer: 1}

];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {
equal(err.error, 'bad_request', 'correct error returned');
equal(err.name, 'bad_request', 'correct error returned');
ok(!info, 'info is empty');

@@ -134,6 +135,6 @@ start();

];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {
equal(err.error, 'bad_request', 'correct error returned');
equal(err.reason, PouchDB.Errors.RESERVED_ID.reason, 'correct error message returned');
equal(err.name, 'bad_request', 'correct error returned');
equal(err.message, PouchDB.Errors.RESERVED_ID.message, 'correct error message returned');
ok(!info, 'info is empty');

@@ -146,7 +147,7 @@ start();

asyncTest('No docs', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({"doc": [{"foo":"bar"}]}, function(err, result) {
ok(err.status === 400);
ok(err.error === 'bad_request');
ok(err.reason === "Missing JSON list of 'docs'");
ok(err.name === 'bad_request');
ok(err.message === "Missing JSON list of 'docs'");
start();

@@ -158,3 +159,3 @@ });

asyncTest('Jira 911', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -168,4 +169,4 @@ {"_id":"0", "a" : 0},

ok(results[1].id === "1", 'check ordering');
ok(results[1].error === undefined, 'first id succeded');
ok(results[2].error === "conflict", 'second conflicted');
ok(results[1].name === undefined, 'first id succeded');
ok(results[2].name === "conflict", 'second conflicted');
ok(results.length === 4, 'got right amount of results');

@@ -178,3 +179,3 @@ start();

asyncTest('Test multiple bulkdocs', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: authors}, function (err, res) {

@@ -192,3 +193,3 @@ db.bulkDocs({docs: authors}, function (err, res) {

asyncTest('Bulk with new_edits=false', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -214,4 +215,5 @@ {"_id":"foo","_rev":"2-x","_revisions":

asyncTest('656 regression in handling deleted docs', function() {
initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{_id: "foo", _rev: "1-a", _deleted: true}]}, {new_edits: false}, function(err, res){
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{_id: "foo", _rev: "1-a", _deleted: true}]},
{new_edits: false}, function(err, res){
db.get("foo", function(err, res){

@@ -218,0 +220,0 @@ ok(err, "deleted");

@@ -1,23 +0,9 @@

/*globals initTestDB, emit: true, generateAdapterUrl */
/*globals PERSIST_DATABASES, initDBPair, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true, putTree, deepEqual */
/*globals cleanupTestDatabases, strictEqual, writeDocs, PouchDB */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var is_browser = true;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
is_browser = false;

@@ -30,10 +16,10 @@ }

setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest("All changes", function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function (err, info) {

@@ -56,8 +42,18 @@ db.changes({

{_id: "2", integer: 2},
{_id: "3", integer: 3}
{_id: "3", integer: 3},
{_id: "4", integer: 4},
{_id: "5", integer: 5},
{_id: "6", integer: 6},
{_id: "7", integer: 7},
{_id: "8", integer: 9},
{_id: "9", integer: 9},
{_id: "10", integer: 10},
{_id: "11", integer: 11},
{_id: "12", integer: 12},
{_id: "13", integer: 13}
];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {
db.changes({
since: 2,
since: 12,
complete: function(err, results) {

@@ -79,3 +75,3 @@ equal(results.results.length, 2, 'Partial results');

];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {

@@ -107,6 +103,6 @@ db.changes({

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
// we use writeDocs since bulkDocs looks to have undefined
// order of doing insertions
writeDocs(db, docs1, function(err, info) {
testUtils.writeDocs(db, docs1, function(err, info) {
docs2[0]._rev = info[2].rev;

@@ -156,4 +152,4 @@ docs2[1]._rev = info[3].rev;

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -165,3 +161,3 @@ filter: 'foo/odd',

equal(err.status, 404, 'correct error status');
equal(err.reason, 'missing json key: odd', 'correct error reason');
equal(err.message, 'missing json key: odd', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -192,4 +188,4 @@ start();

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -201,3 +197,3 @@ filter: 'foo/even',

equal(err.status, 404, 'correct error status');
equal(err.reason, 'missing json key: filters', 'correct error reason');
equal(err.message, 'missing json key: filters', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -226,4 +222,4 @@ start();

initTestDB(this.name, function(err, db) {
writeDocs(db, docs, function(err, info) {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, docs, function(err, info) {
db.changes({

@@ -260,4 +256,4 @@ filter: 'foo/even',

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -267,3 +263,3 @@ filter: 'foobar/odd',

equal(err.status, 404, 'correct error status');
equal(err.reason, 'missing', 'correct error reason');
equal(err.message, 'missing', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -294,4 +290,4 @@ start();

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -302,3 +298,3 @@ filter: '_view',

equal(err.status, 404, 'correct error status');
equal(err.reason, 'missing json key: odd', 'correct error reason');
equal(err.message, 'missing json key: odd', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -324,4 +320,4 @@ start();

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -332,3 +328,3 @@ filter: '_view',

equal(err.status, 404, 'correct error status');
equal(err.reason, 'missing json key: views', 'correct error reason');
equal(err.message, 'missing json key: views', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -359,4 +355,4 @@ start();

initTestDB(this.name, function (err, db) {
writeDocs(db, docs, function (err, info) {
testUtils.initTestDB(this.name, function (err, db) {
testUtils.writeDocs(db, docs, function (err, info) {
db.changes({

@@ -366,3 +362,3 @@ filter: '_view',

equal(err.status, 400, 'correct error status');
equal(err.reason, '`view` filter parameter is not provided.', 'correct error reason');
equal(err.message, '`view` filter parameter is not provided.', 'correct error reason');
equal(results, null, 'correct `results` object returned');

@@ -393,4 +389,4 @@ start();

initTestDB(this.name, function(err, db) {
writeDocs(db, docs, function(err, info) {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.writeDocs(db, docs, function(err, info) {
db.changes({

@@ -432,3 +428,3 @@ filter: '_view',

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.changes({

@@ -472,3 +468,3 @@ complete: function(err, results) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.changes({

@@ -517,4 +513,4 @@ complete: function(err, results) {

initTestDB(this.name, function(err, db) {
putTree(db, simpleTree, function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.putTree(db, simpleTree, function() {
db.changes({

@@ -556,3 +552,3 @@ // without specifying all_docs it should return only winning rev

];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {

@@ -573,3 +569,3 @@ db.changes({

asyncTest("Descending changes", function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({ _id: "0", test: "ing" }, function (err, res) {

@@ -597,3 +593,3 @@ db.post({ _id: "1", test: "ing" }, function (err, res) {

asyncTest("Changes doc", function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function (err, info) {

@@ -614,3 +610,3 @@ db.changes({

asyncTest("Continuous changes", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -632,3 +628,3 @@ var changes = db.changes({

asyncTest("Multiple watchers", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -672,3 +668,3 @@ function checkCount() {

'&testFiles=postTest.js&dbname=' + encodeURIComponent(this.name);
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -697,3 +693,3 @@ var tab;

asyncTest("Continuous changes doc", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var changes = db.changes({

@@ -714,3 +710,3 @@ onChange: function(change) {

asyncTest("Cancel changes", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -740,3 +736,3 @@ var changes = db.changes({

var name = this.name;
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -776,3 +772,3 @@ var changes = db.changes({

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -817,3 +813,3 @@ db.bulkDocs({docs: docs1}, function(err, info) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -852,3 +848,3 @@ db.bulkDocs({docs: docs1}, function(err, info) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs1}, function(err, info) {

@@ -882,3 +878,3 @@ db.changes({

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs1}, function(err, info) {

@@ -926,3 +922,3 @@ docs2[0]._rev = info[2].rev;

initDBPair(localname, remotename, function(localdb, remotedb) {
testUtils.initDBPair(localname, remotename, function(localdb, remotedb) {
localdb.bulkDocs({docs: docs1}, function(err, info) {

@@ -989,3 +985,3 @@ docs2[0]._rev = info[2].rev;

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs1}, function(err, info) {

@@ -1017,3 +1013,3 @@ var rev = info[3].rev;

}
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, function(err, info) {

@@ -1032,3 +1028,3 @@ db.changes({

expect(5);
initTestDB(this.name, function (err, db) {
testUtils.initTestDB(this.name, function (err, db) {
db.bulkDocs({docs: [

@@ -1066,1 +1062,20 @@ { foo: 'bar' }

});
asyncTest("Closing db dosent cause a crash if changes cancelled", function (){
testUtils.initTestDB(this.name, function (err, db) {
db.bulkDocs({docs: [
{ foo: 'bar' }
]}, function (err, data) {
ok(!err, 'bulked ok');
var changes = db.changes({
continuous: true,
onChange: function(){}
});
changes.cancel();
db.close(function(error){
ok(!error, 'closed ok');
start();
});
});
});
});

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

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true, putTree: false */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false, strictEqual: false */
/*globals cleanupTestDatabases: false */
"use strict";

@@ -11,30 +6,18 @@

var qunit = module;
var LevelPouch;
var utils;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
adapters.map(function(adapter) {
qunit('compaction: ' + adapter, {
QUnit.module('compaction: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest('Compation document with no revisions to remove', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {_id: "foo", value: "bar"};

@@ -54,3 +37,3 @@ db.put(doc, function(err, res) {

asyncTest('Compation on empty db', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.compact(function(){

@@ -64,3 +47,3 @@ ok(true, "compaction finished");

asyncTest('Compation on empty db with interval option', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.compact({interval: 199}, function(){

@@ -74,3 +57,3 @@ ok(true, "compaction finished");

asyncTest('Simple compation test', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {_id: "foo", value: "bar"};

@@ -87,3 +70,3 @@

db.get("foo", {rev: rev1}, function(err, doc){
ok(err.status === 404 && err.error === "not_found", "compacted document is missing");
ok(err.status === 404 && err.name === "not_found", "compacted document is missing");
db.get("foo", {rev: rev2}, function(err, doc){

@@ -170,4 +153,4 @@ ok(!err, "newest revision does not get compacted");

asyncTest('Compact more complicated tree', function() {
initTestDB(this.name, function(err, db) {
putTree(db, exampleTree, function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.putTree(db, exampleTree, function() {
db.compact(function() {

@@ -184,4 +167,4 @@ checkTree(db, exampleTree, function() {

asyncTest('Compact two times more complicated tree', function() {
initTestDB(this.name, function(err, db) {
putTree(db, exampleTree, function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.putTree(db, exampleTree, function() {
db.compact(function() {

@@ -200,5 +183,5 @@ db.compact(function() {

asyncTest('Compact database with at least two documents', function() {
initTestDB(this.name, function(err, db) {
putTree(db, exampleTree, function() {
putTree(db, exampleTree2, function() {
testUtils.initTestDB(this.name, function(err, db) {
testUtils.putTree(db, exampleTree, function() {
testUtils.putTree(db, exampleTree2, function() {
db.compact(function() {

@@ -218,3 +201,3 @@ checkTree(db, exampleTree, function() {

asyncTest('Compact deleted document', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id: "foo"}, function(err, res) {

@@ -226,3 +209,3 @@ var firstRev = res.rev;

ok(err, "got error");
strictEqual(err.reason, "missing", "correct reason");
strictEqual(err.message, "missing", "correct reason");
start();

@@ -238,3 +221,3 @@ });

asyncTest('Auto-compaction test', function() {
initTestDB(this.name, {auto_compaction: true}, function(err, db) {
testUtils.initTestDB(this.name, {auto_compaction: true}, function(err, db) {
var doc = {_id: "doc", val: "1"};

@@ -253,3 +236,3 @@ db.post(doc, function(err, res) {

strictEqual(err.status, 404, "compacted document is missing");
strictEqual(err.error, "not_found", "compacted document is missing");
strictEqual(err.name, "not_found", "compacted document is missing");
db.get("doc", {rev: rev2}, function(err, doc) {

@@ -256,0 +239,0 @@ ok(!err, "leaf's parent does not get compacted");

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -26,12 +12,12 @@

qunit('conflicts: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
QUnit.module('conflicts: ' + adapter, {
setup: function () {
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest('Testing conflicts', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {_id: 'foo', a:1, b: 1};

@@ -48,3 +34,3 @@ db.put(doc, function(err, res) {

db.put(doc2, function(err) {
ok(err.error === 'conflict', 'Put got a conflicts');
ok(err.name === 'conflict', 'Put got a conflicts');
db.changes({

@@ -55,3 +41,3 @@ complete: function(err, results) {

db.put(doc2, function(err) {
ok(err.error === 'conflict', 'Another conflict');
ok(err.name === 'conflict', 'Another conflict');
start();

@@ -70,3 +56,3 @@ });

var doc = {_id: 'fubar', a:1, b: 1};
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put(doc, function(err, ndoc) {

@@ -73,0 +59,0 @@ doc._rev = ndoc.rev;

@@ -1,25 +0,11 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, utils: true, Pouch.extend: true */
/*globals Pouch.ajax: true, strictEqual: false, Pouch: true */
/*globals cleanupTestDatabases: false, openTestDB: true, putAfter: false */
/*globals setupAdminAndMemberConfig:false, tearDownAdminAndMemberConfig:false */
/*globals cleanUpCors:false, enableCORS:false, enableCORSCredentials:false, call:false */
/*globals disableCORS: false, disableCORSCredentials: false, deleteCookieAuth:false */
'use strict';
var adapter = 'http-1';
var qunit = module;
if (typeof module !== undefined && module.exports) {
Pouch = require('../lib');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
qunit('cors-adapter:', {
QUnit.module('cors-adapter:', {
setup: function () {

@@ -296,2 +282,2 @@ this.name = generateAdapterUrl(adapter);

});
});
});

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['local-1', 'http-1'];
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -26,8 +12,8 @@

qunit("design_docs: " + adapter, {
QUnit.module("design_docs: " + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -49,3 +35,3 @@

asyncTest("Test writing design doc", function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post(doc, function (err, info) {

@@ -78,3 +64,3 @@ ok(!err, 'Wrote design doc');

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var count = 0;

@@ -109,3 +95,3 @@ db.bulkDocs({docs: docs1}, function(err, info) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs1}, function(err, info) {

@@ -124,3 +110,3 @@ db.query('foo/scores', {reduce: false}, function(err, result) {

asyncTest("Concurrent queries", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [doc, {_id: "dale", score: 3}]}, function(err, info) {

@@ -127,0 +113,0 @@ var cnt = 0;

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false, putTree: false, putBranch: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false, strictEqual: false, notStrictEqual: false */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -26,8 +12,8 @@

qunit('get: ' + adapter, {
QUnit.module('get: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -55,3 +41,3 @@

asyncTest("Get doc", 2, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function(err, info) {

@@ -61,3 +47,3 @@ db.get(info.id, function(err, doc) {

db.get(info.id+'asdf', function(err) {
ok(err.error);
ok(err.name);
start();

@@ -71,3 +57,3 @@ });

asyncTest("Get design doc", 2, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id: '_design/someid', test:"somestuff"}, function(err, info) {

@@ -77,3 +63,3 @@ db.get(info.id, function(err, doc) {

db.get(info.id+'asdf', function(err) {
ok(err.error);
ok(err.name);
start();

@@ -87,8 +73,8 @@ });

asyncTest("Check error of deleted document", 2, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function(err, info) {
db.remove({_id:info.id, _rev:info.rev}, function(err, res) {
db.get(info.id, function(err, res) {
strictEqual(err.error, "not_found", "correct error");
strictEqual(err.reason, "deleted", "correct reason");
strictEqual(err.name, "not_found", "correct error");
strictEqual(err.message, "deleted", "correct reason");
start();

@@ -102,3 +88,3 @@ });

asyncTest("Get local_seq of document", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function(err, info1) {

@@ -121,3 +107,3 @@ db.get(info1.id, {local_seq: true}, function(err, res) {

asyncTest("Get revisions of removed doc", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test:"somestuff"}, function(err, info) {

@@ -136,3 +122,3 @@ var rev = info.rev;

asyncTest('Testing get with rev', 10, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {

@@ -173,3 +159,3 @@ db.get("3", function(err, parent){

var revs = [];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test: "somestuff"}, function (err, info) {

@@ -193,3 +179,3 @@ revs.unshift(info.rev.split('-')[1]);

asyncTest("Test opts.revs=true with rev other than winning", 5, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -201,3 +187,3 @@ {_id: "foo", _rev: "1-a", value: "foo a"},

];
putBranch(db, docs, function() {
testUtils.putBranch(db, docs, function() {
db.get("foo", {rev: "3-c", revs: true}, function(err, doc) {

@@ -216,3 +202,3 @@ strictEqual(doc._revisions.ids.length, 3, "correct revisions length");

asyncTest("Test opts.revs=true return only winning branch", 6, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var simpleTree = [

@@ -231,3 +217,3 @@ [

];
putTree(db, simpleTree, function() {
testUtils.putTree(db, simpleTree, function() {
db.get("foo", {revs: true}, function(err, doc) {

@@ -247,3 +233,3 @@ strictEqual(doc._revisions.ids.length, 4, "correct revisions length");

asyncTest("Test get with simple revs_info", 1, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test: "somestuff"}, function (err, info) {

@@ -263,3 +249,3 @@ db.put({_id: info.id, _rev: info.rev, another: 'test'}, function(err, info) {

asyncTest("Test get with revs_info on tree", 4, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var simpleTree = [

@@ -277,3 +263,3 @@ [

];
putTree(db, simpleTree, function() {
testUtils.putTree(db, simpleTree, function() {
db.get("foo", {revs_info: true}, function(err, doc) {

@@ -292,3 +278,3 @@ var revs = doc._revs_info;

asyncTest("Test get with revs_info on compacted tree", 7, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var simpleTree = [

@@ -306,3 +292,3 @@ [

];
putTree(db, simpleTree, function() {
testUtils.putTree(db, simpleTree, function() {
db.compact(function(err, ok) {

@@ -327,3 +313,3 @@ db.get("foo", {revs_info: true}, function(err, doc) {

asyncTest("Test get with conflicts", 3, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var simpleTree = [

@@ -343,3 +329,3 @@ [

];
putTree(db, simpleTree, function() {
testUtils.putTree(db, simpleTree, function() {
db.get("foo", {conflicts: true}, function(err, doc) {

@@ -356,3 +342,3 @@ strictEqual(doc._rev, "2-c", "correct rev");

asyncTest("Retrieve old revision", 6, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -378,3 +364,3 @@ db.post({version: "first"}, function (err, info) {

asyncTest('Testing get open_revs="all"', 8, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {

@@ -416,3 +402,3 @@ db.get("3", function(err, parent){

asyncTest('Testing get with some open_revs', 11, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
writeDocs(db, JSON.parse(JSON.stringify(origDocs)), function() {

@@ -466,3 +452,3 @@ db.get("3", function(err, parent){

asyncTest('Testing get with open_revs and revs', 4, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -478,3 +464,3 @@ [

];
putTree(db, docs, function() {
testUtils.putTree(db, docs, function() {
db.get("foo", {open_revs: ["2-b"], revs: true}, function(err, res) {

@@ -493,3 +479,3 @@ var doc = res[0].ok;

asyncTest('Testing get with open_revs on nonexistent doc', 3, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.get("nonexistent", {open_revs: ["2-whatever"]}, function(err, res) {

@@ -508,11 +494,11 @@ strictEqual(res.length, 1, "just one result");

asyncTest('Testing get with open_revs with wrong params', 4, function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.put({_id: "foo"}, function(err, res) {
db.get("foo", {open_revs: {"whatever": "which is", "not an array": "or all string"}}, function(err, res) {
ok(err, "got error");
strictEqual(err.error, "unknown_error", "correct error"); // unfortunately!
strictEqual(err.name, "unknown_error", "correct error"); // unfortunately!
db.get("foo", {open_revs: ["1-almost", "2-correct", "keys"]}, function(err, res) {
ok(err, "got error");
strictEqual(err.error, "bad_request", "correct error");
strictEqual(err.name, "bad_request", "correct error");
start();

@@ -519,0 +505,0 @@ });

@@ -1,34 +0,21 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['local-1'];
var qunit = module;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
var Pouch = require('../lib'),
LevelPouch = require('../lib/adapters/leveldb'),
utils = require('./test.utils.js');
var testUtils = require('./test.utils.js');
}
for (var k in utils) {
global[k] = global[k] || utils[k];
}
adapters = ['leveldb-1', 'http-1'];
qunit = QUnit.module; }
adapters.map(function(adapter) {
qunit('gql: ' + adapter, {
QUnit.module('gql: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
Pouch.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest("Test select *", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz",

@@ -55,3 +42,3 @@ what: "test" }]},{},

asyncTest("Test select with one row", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz" }]},{},

@@ -75,3 +62,3 @@ function() {

asyncTest("Test select with two columns", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz" }]},{},

@@ -96,3 +83,3 @@ function() {

asyncTest("Test select with missing column", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz" }]},{},

@@ -120,3 +107,3 @@ function() {

asyncTest("Test select with parsing errors", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -137,3 +124,3 @@ {docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz" }]},{},

asyncTest("Test select with backquotes", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -165,3 +152,3 @@ {docs: [{"name!": "pencil", price: 2, discount: 0.7, vendor: "store1"},

asyncTest("Test not null and select *", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -192,3 +179,3 @@ {docs: [{name: "charmander", type: "Fire"},

asyncTest("Test unwrapped identifier in select", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -213,3 +200,3 @@ {docs: [{charizard: 50, dept: "eng", lunch:"2"}, {charizard: 40, lunch: "1", dept: "market"},

asyncTest("Test where with no results", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: "bar", what: "field"}, { _id: "volatile", foo: "baz" }]},{},

@@ -230,3 +217,3 @@ function() {

asyncTest("Test where boolean operators and precedence (no parenthesis)", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: false, charmander: true}, {charizard: true, charmeleon: true },

@@ -251,3 +238,3 @@ {charmeleon: true, charmander: true, charizard: false}]},{},

asyncTest("Test where boolean operators and precedence (with parenthesis)", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: false, charmander: true}, {charizard: true, charmeleon: true },

@@ -272,3 +259,3 @@ {charmeleon: true, charmander: true, charizard: false}]},{},

asyncTest("Test where boolean operators with not", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: false, charmander: true}, {charizard: true, charmeleon: false},

@@ -295,3 +282,3 @@ {charmeleon: true, charmander: false, charizard: true, bulbasaur: false},

asyncTest("Test where inequalities", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmander: 30, haunter: true}, {charizard: 40, charmander: 50},

@@ -316,3 +303,3 @@ {charizard: 700, charmander: 22}]},{},

asyncTest("Test where inequalities with strings", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmander: "porygon"}, {charizard: 40, charmander: "Zubat"}]},{},

@@ -336,3 +323,3 @@ function() {

asyncTest("Test where math", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmander: 24, charmeleon: 2, haunter:true},

@@ -358,3 +345,3 @@ {charizard: 40, charmeleon: 0.5, charmander: 50},

asyncTest("Test aggregation functions", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50}, {charizard: 40}, {charizard: 7}]},{},

@@ -381,3 +368,3 @@ function() {

asyncTest("Test null checker", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: null}, {charmander: 40}, {charizard: 7}, {charizard: false}]},{},

@@ -405,3 +392,3 @@ function() {

asyncTest("Test basic group by", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmander: 24, charmeleon: 2, haunter:true},

@@ -430,3 +417,3 @@ {charizard: 40, charmeleon: 2, charmander: 50}, {charizard: 7, charmeleon: 20, charmander: 15}]},{},

asyncTest("Test basic pivot", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmeleon: "hello"}, {charizard: 40, charmeleon: "hello"},

@@ -452,3 +439,3 @@ {charizard: 7, charmeleon: "world", charmander: 15}]},{},

asyncTest("Test double pivot", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{charizard: 50, charmeleon: "hello", abra: 2},

@@ -489,3 +476,3 @@ {charizard: 40, charmeleon: "hello", abra: 3},

asyncTest("Test pivot clause that shares identifiers with select", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -510,3 +497,3 @@ {docs: [{charizard: 50, dept: "eng", lunch:"2"}, {charizard: 40, lunch: "1", dept: "market"},

asyncTest("Test group by and pivot together", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -538,3 +525,3 @@ {docs: [{charizard: 50, dept: "eng", lunch:"2"}, {charizard: 40, lunch: "1", dept: "market"},

asyncTest("Test basic label", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs(

@@ -541,0 +528,0 @@ {docs: [{charizard: 50, dept: "eng", lunch:"2"}, {charizard: 40, lunch: "1", dept: "market"},

@@ -1,29 +0,16 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
"use strict";
var adapter = 'http-1';
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
qunit("http-adapter", {
QUnit.module("http-adapter", {
setup: function() {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
},
teardown: function() {
if (!PERSIST_DATABASES) {
if (!testUtils.PERSIST_DATABASES) {
PouchDB.destroy(this.name);

@@ -42,3 +29,3 @@ }

instantDB.post({test:"abc"}, function(err, info) {
ok(err && err.error === 'not_found', 'Skipped setup of database');
ok(err && err.name === 'not_found', 'Skipped setup of database');
start();

@@ -45,0 +32,0 @@ });

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

/*globals initTestDB: false, emit: true, generateAdapterUrl: false, strictEqual: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
/*globals cleanupTestDatabases: false */
"use strict";

@@ -14,15 +9,6 @@

];
var qunit = module;
var LevelPouch;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -32,9 +18,9 @@

qunit('replication + compaction: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('replication + compaction: ' + adapters[0] + ':' + adapters[1], {
setup: function() {
this.local = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.local = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -47,3 +33,3 @@

// Create databases.
initDBPair(self.local, self.remote, function(local, remote) {
testUtils.initDBPair(self.local, self.remote, function(local, remote) {
// Write a doc in CouchDB.

@@ -79,3 +65,3 @@ remote.put(doc, function(err, results) {

// Create databases.
initDBPair(self.local, self.remote, function(local, remote) {
testUtils.initDBPair(self.local, self.remote, function(local, remote) {
// Write a doc in CouchDB.

@@ -82,0 +68,0 @@ remote.put(doc, function(err, results) {

@@ -1,25 +0,10 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
"use strict";
var qunit = module;
var LevelPouch;
var utils;
var fs;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
utils = require('./test.utils.js');
fs = require('fs');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var utils = require('./test.utils.js');
var fs = require('fs');
}
qunit("Remove DB", {
QUnit.module("Remove DB", {
setup: function() {

@@ -30,4 +15,4 @@ //Create a dir

teardown: function() {
PouchDB.destroy('name');
fs.rmdirSync('veryimportantfiles');
PouchDB.destroy('name');
fs.rmdirSync('veryimportantfiles');
}

@@ -42,6 +27,6 @@ });

PouchDB.destroy('veryimportantfiles', function( error, response ) {
equal(error.reason, 'Database not found', 'should return Database not found error');
equal(fs.existsSync('veryimportantfiles'), true, 'veryimportantfiles was not removed');
start();
});
equal(error.message, 'Database not found', 'should return Database not found error');
equal(fs.existsSync('veryimportantfiles'), true, 'veryimportantfiles was not removed');
start();
});
});

@@ -48,0 +33,0 @@ });

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

/*globals initTestDB, emit, generateAdapterUrl, Pouch */
/*globals PERSIST_DATABASES, initDBPair, openTestDB, putAfter */
/*globals cleanupTestDatabases, strictEqual */
"use strict";

@@ -12,3 +8,2 @@

['local-1', 'local-2']];
var qunit = module;

@@ -19,13 +14,5 @@ var downAdapters = ['local-1'];

// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
var PouchDB = require('../lib');
var LevelPouch = require('../lib/adapters/leveldb');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var testUtils = require('./test.utils.js');
downAdapters = [];

@@ -36,9 +23,9 @@ }

qunit('replication: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('replication: ' + adapters[0] + ':' + adapters[1], {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.name = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -54,3 +41,3 @@

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -69,3 +56,3 @@ db.replicate.from(self.remote, function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -83,3 +70,3 @@ PouchDB.replicate(self.remote, self.name, {}, function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -97,3 +84,3 @@ PouchDB.replicate(self.remote, self.name, {complete: function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, _) {

@@ -114,3 +101,3 @@ db.bulkDocs({docs: docs}, {}, function(err, _) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -128,3 +115,3 @@ db.replicate.to(self.remote, function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs}, {}, function(err, _) {

@@ -143,3 +130,3 @@ db.replicate.to(self.remote, function(err, _) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
var doc1 = {_id: 'adoc', foo:'bar'};

@@ -163,3 +150,3 @@ db.put(doc1, function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -182,3 +169,3 @@ db.replicate.from(self.remote, function(err, result) {

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -207,3 +194,3 @@ var changeCount = docs.length;

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -233,3 +220,3 @@ var changeCount = docs.length;

var doc = {_id: "3", count: 0};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.put(doc, {}, function(err, results) {

@@ -259,3 +246,3 @@ db.replicate.from(self.remote, function(err, result) {

var doc = {_id: "3", count: 0};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.put(doc, {}, function(err, results) {

@@ -285,3 +272,3 @@ PouchDB.replicate(db, remote, {}, function(err, result) {

// we indeed needed replication to create failing test here!
initDBPair(this.name, this.remote, function(db1, db2) {
testUtils.initDBPair(this.name, this.remote, function(db1, db2) {
var doc = {

@@ -294,5 +281,5 @@ _id: "foo",

db2.put(doc, {new_edits: false}, function(err, res) {
putAfter(db2, {_id: "foo", _rev: "2-b", value: "db2"}, "1-a", function(err, res) {
putAfter(db1, {_id: "foo", _rev: "2-c", value: "whatever"}, "1-a", function(err,res) {
putAfter(db1, {_id: "foo", _rev: "3-c", value: "db1"}, "2-c", function(err, res) {
testUtils.putAfter(db2, {_id: "foo", _rev: "2-b", value: "db2"}, "1-a", function(err, res) {
testUtils.putAfter(db1, {_id: "foo", _rev: "2-c", value: "whatever"}, "1-a", function(err,res) {
testUtils.putAfter(db1, {_id: "foo", _rev: "3-c", value: "db1"}, "2-c", function(err, res) {
db1.get("foo", function(err, doc) {

@@ -338,3 +325,3 @@ ok(doc.value === "db1", "db1 has correct value (get)");

var doc2 = {_id: 'adoc', bar:'baz'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.put(doc1, function(err, localres) {

@@ -358,3 +345,3 @@ remote.put(doc2, function(err, remoteres) {

var doc2 = {_id: 'adoc', bar:'baz'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.put(doc1, function(err, localres) {

@@ -387,3 +374,3 @@ remote.put(doc2, function(err, remoteres) {

var doc1 = {_id: 'adoc', foo:'bar'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -414,3 +401,3 @@ var count = 0;

var doc1 = {_id: 'adoc', foo:'bar'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -442,3 +429,3 @@ var count = 0;

var doc2 = {_id: 'anotherdoc', foo:'baz'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -478,3 +465,3 @@ var count = 0;

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs1}, function(err, info) {

@@ -501,3 +488,3 @@ var replicate = db.replicate.from(remote, {

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, function(err, info) {

@@ -525,3 +512,3 @@ db.replicate.from(remote, {

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: thedocs}, function(err, info) {

@@ -544,3 +531,3 @@ db.replicate.from(remote, {

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, function(err, info) {

@@ -572,3 +559,3 @@ db.replicate.from(remote, {

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs1}, function(err, info) {

@@ -596,3 +583,3 @@ var replicate = db.replicate.from(remote, function() {

};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -608,3 +595,3 @@ db.replicate.from(self.remote, {onChange: onChange});

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.post(doc, function(err, resp) {

@@ -645,7 +632,7 @@ doc._rev = resp.rev;

db.put(doc, {new_edits: false}, function(err, res) {
putAfter(db, {_id: '789', _rev: '2-a', value: 'v1'}, '1-a',
testUtils.putAfter(db, {_id: '789', _rev: '2-a', value: 'v1'}, '1-a',
function(err, res) {
putAfter(db, {_id: '789', _rev: '2-b', value: 'v2'}, '1-a',
testUtils.putAfter(db, {_id: '789', _rev: '2-b', value: 'v2'}, '1-a',
function(err, res) {
putAfter(db, {_id: '789', _rev: '2-c', value: 'v3'}, '1-a',
testUtils.putAfter(db, {_id: '789', _rev: '2-c', value: 'v3'}, '1-a',
function(err, res) {

@@ -659,3 +646,3 @@ callback();

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
createConflicts(remote, function() {

@@ -680,3 +667,3 @@ db.replicate.from(remote, function(err, result) {

}
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, function(err, info) {

@@ -697,3 +684,3 @@ var replicate = db.replicate.from(remote, {}, function() {

var newdoc = {'_id' :'newdoc'};
initDBPair(this.name, this.remote, function(db1, db2) {
testUtils.initDBPair(this.name, this.remote, function(db1, db2) {
db1.post(adoc, function() {

@@ -731,3 +718,3 @@ PouchDB.replicate(db1, db2, {complete: function() {

docList = ['doc_33', 'doc_60', 'doc_90'];
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -748,6 +735,6 @@ db.replicate.from(self.remote, {continuous: false, doc_ids: docList}, function(err, result) {

deletedDocAdapters.map(function(adapters) {
qunit('replication: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('replication: ' + adapters[0] + ':' + adapters[1], {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.name = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
}

@@ -814,5 +801,5 @@ });

openTestDB(remote, function(err, dbr){
testUtils.openTestDB(remote, function(err, dbr){
rebuildDocuments(dbr, docs, function(){
openTestDB(name, function(err, db){
testUtils.openTestDB(name, function(err, db){
db.replicate.from(remote, function(err, result) {

@@ -834,3 +821,3 @@ db.query({map:map}, {reduce: false}, function (err, result) {

// new pouch and couch
initDBPair(self.name, self.remote, function(){
testUtils.initDBPair(self.name, self.remote, function(){
// Rinse, repeat our workflow...

@@ -844,3 +831,3 @@ workflow(self.name, self.remote, runs);

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, _){

@@ -862,3 +849,3 @@ db.replicate.from(self.remote, function(err, _){

var self = this;
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs}, {}, function(err, _) {

@@ -884,5 +871,5 @@ db.replicate.to(self.remote, function(err, result) {

qunit('replication: ' + adapter, {
QUnit.module('replication: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
}

@@ -893,3 +880,3 @@ });

expect(1);
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.replicate.to('http://infiniterequest.com', function (err, changes) {

@@ -905,6 +892,6 @@ ok(err);

interHTTPAdapters.map(function(adapters) {
qunit('server side replication: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('server side replication: ' + adapters[0] + ':' + adapters[1], {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.name = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
}

@@ -921,3 +908,3 @@ });

var self = this;
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -937,3 +924,3 @@ PouchDB.replicate(self.name, self.remote, {server: true}, function(err, result) {

var doc2 = {_id: 'anotherdoc', foo:'baz'};
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs}, {}, function(err, results) {

@@ -940,0 +927,0 @@ var count = 0;

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, putAfter */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
var LevelPouch;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
var PouchDB = require('../lib');
var LevelPouch = require('../lib/adapters/leveldb');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var testUtils = require('./test.utils.js');
}

@@ -26,8 +12,8 @@

qunit("revs diff:" + adapter, {
QUnit.module("revs diff:" + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -37,3 +23,3 @@

var revs = [];
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({test: "somestuff", _id: 'somestuff'}, function (err, info) {

@@ -59,3 +45,3 @@ revs.push(info.rev);

function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
// empty database

@@ -77,4 +63,4 @@ var revs = ['1-a', '2-a', '2-b'];

db.put(doc, {new_edits: false}, function(err, res) {
putAfter(db, {_id: '939', _rev: '2-a'}, '1-a', function(err, res) {
putAfter(db, {_id: '939', _rev: '2-b'}, '1-a', callback);
testUtils.putAfter(db, {_id: '939', _rev: '2-a'}, '1-a', function(err, res) {
testUtils.putAfter(db, {_id: '939', _rev: '2-b'}, '1-a', callback);
});

@@ -84,3 +70,3 @@ });

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
createConflicts(db, function() {

@@ -100,7 +86,7 @@ db.revsDiff({'939': ['1-a', '2-a', '2-b']}, function(err, results) {

db.put({_id: '935', _rev: '1-a'}, {new_edits: false}, function (err, info) {
putAfter(db, {_id: '935', _rev: '2-a', _deleted: true}, '1-a', callback);
testUtils.putAfter(db, {_id: '935', _rev: '2-a', _deleted: true}, '1-a', callback);
});
}
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
createDeletedRevision(db, function() {

@@ -107,0 +93,0 @@ db.revsDiff({'935': ['1-a', '2-a']}, function(err, results) {

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

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true, strictEqual: false */
/*globals Pouch.ajax: true, LevelPouch: true, makeDocs: false */
/*globals readBlob: false, makeBlob: false, base64Blob: false */
/*globals cleanupTestDatabases: false */
"use strict";

@@ -14,26 +8,15 @@

['local-1', 'local-2']];
var qunit = module;
var LevelPouch;
var PouchUtils;
var utils;
if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
LevelPouch = require('../lib/adapters/leveldb');
PouchUtils = require('../lib/utils');
utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}
adapters.map(function(adapter) {
qunit('functions with / in _id: ' + adapter, {
QUnit.module('functions with / in _id: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -52,3 +35,3 @@

asyncTest('Insert a doc, putAttachment and allDocs', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
ok(!err, 'opened the pouch');

@@ -58,3 +41,3 @@ var docId = 'doc/with/slashes';

var blobData = 'attachment content';
var blob = makeBlob(blobData);
var blob = testUtils.makeBlob(blobData);
var doc = {_id: docId, test: true};

@@ -66,3 +49,3 @@ db.put(doc, function(err, info) {

db.getAttachment(docId, attachmentId, function(err, res) {
readBlob(res, function(data) {
testUtils.readBlob(res, function(data) {
db.get(docId, function(err, res){

@@ -81,3 +64,3 @@ strictEqual(res._id, docId);

asyncTest('BulkDocs and changes', function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [

@@ -121,6 +104,6 @@ {_id: 'part/doc1', int: 1},

qunit('replication with / in _id: ' + adapters[0] + ':' + adapters[1], {
QUnit.module('replication with / in _id: ' + adapters[0] + ':' + adapters[1], {
setup : function () {
this.name = generateAdapterUrl(adapters[0]);
this.remote = generateAdapterUrl(adapters[1]);
this.name = testUtils.generateAdapterUrl(adapters[0]);
this.remote = testUtils.generateAdapterUrl(adapters[1]);
}

@@ -148,3 +131,3 @@ });

initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
remote.bulkDocs({docs: docs1}, function(err, info) {

@@ -151,0 +134,0 @@ var replicate = db.replicate.from(remote, function() {

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, Spatial: false */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['local-1', 'http-1'];
var qunit = module;
var LevelPouch;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
var Pouch = require('../lib');
var LevelPouch = require('../lib/adapters/leveldb');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var testUtils = require('./test.utils.js');
}

@@ -26,8 +12,8 @@

qunit('spatial: ' + adapter, {
QUnit.module('spatial: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
Pouch.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -118,3 +104,3 @@

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, {}, function() {

@@ -146,3 +132,3 @@ db.get('volatile', function(_, doc) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [designDoc, {key: [10, 100]},{key: [20, 200]},{key: [30, 300]},{key: [40, 400]},{key: [50, 500]}]}, {}, function() {

@@ -168,3 +154,3 @@ db.spatial('foo/test', {start_range: [21, 301], end_range: [49, 1000]}, function(_, res) {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = GEOJSON_GEOMS.map(function(x, i) {

@@ -240,3 +226,3 @@ return {_id: (i).toString(), geom: x};

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: docs}, {}, function() {

@@ -243,0 +229,0 @@ tests_with_geometry(db);

@@ -1,21 +0,8 @@

/*globals openTestAsyncDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals Pouch.ajax: true, LevelPouch: true */
/*globals Pouch: true, QUnit, uuid, asyncTest, ok, start*/
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['http-1', 'local-1'];
var qunit = module;
if (typeof module !== undefined && module.exports) {
var PouchDB = require('../lib');
var LevelPouch = require('../lib/adapters/leveldb');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var testUtils = require('./test.utils.js');
}

@@ -25,8 +12,8 @@

qunit("taskqueue: " + adapter, {
QUnit.module("taskqueue: " + adapter, {
setup: function() {
this.name = generateAdapterUrl(adapter);
this.name = testUtils.generateAdapterUrl(adapter);
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});

@@ -37,3 +24,3 @@

PouchDB.destroy(name, function() {
var db = openTestAsyncDB(name);
var db = testUtils.openTestAsyncDB(name);
db.post({test:"somestuff"}, function (err, info) {

@@ -49,3 +36,3 @@ ok(!err, 'saved a doc with post');

PouchDB.destroy(name, function() {
var db = openTestAsyncDB(name);
var db = testUtils.openTestAsyncDB(name);
var queryFun = {

@@ -64,3 +51,3 @@ map: function(doc) { }

PouchDB.destroy(name, function() {
var db = openTestAsyncDB(name);
var db = testUtils.openTestAsyncDB(name);

@@ -78,3 +65,3 @@ db.bulkDocs({docs: [{test:"somestuff"}, {test:"another"}]}, function(err, infos) {

PouchDB.destroy(name, function() {
var db = openTestAsyncDB(name);
var db = testUtils.openTestAsyncDB(name);

@@ -91,3 +78,3 @@ db.get('0', function(err, res) {

PouchDB.destroy(name, function() {
var db = openTestAsyncDB(name);
var db = testUtils.openTestAsyncDB(name);

@@ -94,0 +81,0 @@ db.info(function(err, info) {

@@ -1,10 +0,17 @@

/*globals PouchDB.extend: false, Buffer: false, PouchDB: true, PouchDB.ajax:false */
"use strict";
'use strict';
var PERSIST_DATABASES = false;
var testUtils = {};
Array.prototype.wtf = function() { };
testUtils.PERSIST_DATABASES = false;
function cleanupAllDbs() {
testUtils.couchHost = function() {
if (typeof module !== 'undefined' && module.exports) {
return process.env.COUCH_HOST || 'http://localhost:5984';
}
// In the browser we default to the CORS server, in future will change
return 'http://localhost:2020';
}
testUtils.cleanupAllDbs = function() {
var deleted = 0;

@@ -40,5 +47,5 @@ var adapters = Object.keys(PouchDB.adapters).filter(function(adapter) {

function cleanupTestDatabases(alreadyStopped_) {
testUtils.cleanupTestDatabases = function(alreadyStopped_) {
if (PERSIST_DATABASES) {
if (testUtils.PERSIST_DATABASES) {
return;

@@ -56,3 +63,3 @@ }

function finished() {
cleanupAllDbs();
testUtils.cleanupAllDbs();
}

@@ -77,3 +84,3 @@

function uuid() {
testUtils.uuid = function() {
var S4 = function() {

@@ -92,21 +99,3 @@ return Math.floor(Math.random() * 0x10000).toString(16);

function makeDocs(start, end, templateDoc) {
var templateDocSrc = templateDoc ? JSON.stringify(templateDoc) : "{}";
if (end === undefined) {
end = start;
start = 0;
}
var docs = [];
for (var i = start; i < end; i++) {
/*jshint evil:true */
var newDoc = eval("(" + templateDocSrc + ")");
newDoc._id = (i).toString();
newDoc.integer = i;
newDoc.string = (i).toString();
docs.push(newDoc);
}
return docs;
}
function makeBlob(data, type) {
testUtils.makeBlob = function(data, type) {
if (typeof module !== 'undefined' && module.exports) {

@@ -119,3 +108,3 @@ return new Buffer(data);

function readBlob(blob, callback) {
testUtils.readBlob = function(blob, callback) {
if (typeof module !== 'undefined' && module.exports) {

@@ -132,3 +121,3 @@ callback(blob.toString());

function base64Blob(blob, callback) {
testUtils.base64Blob = function(blob, callback) {
if (typeof module !== 'undefined' && module.exports) {

@@ -146,3 +135,3 @@ callback(blob.toString('base64'));

function openTestAsyncDB(name) {
testUtils.openTestAsyncDB = function(name) {
return new PouchDB(name, function(err,db) {

@@ -157,3 +146,3 @@ if (err) {

function openTestDB(name, opts, callback) {
testUtils.openTestDB = function(name, opts, callback) {
if (typeof opts === 'function') {

@@ -173,3 +162,3 @@ callback = opts;

function initTestDB(name, opts, callback) {
testUtils.initTestDB = function(name, opts, callback) {
// ignore errors, the database might not exist

@@ -182,9 +171,9 @@ PouchDB.destroy(name, function(err) {

}
openTestDB(name, opts, callback);
testUtils.openTestDB(name, opts, callback);
});
}
function initDBPair(local, remote, callback) {
initTestDB(local, function(err, localDb) {
initTestDB(remote, function(err, remoteDb) {
testUtils.initDBPair = function(local, remote, callback) {
testUtils.initTestDB(local, function(err, localDb) {
testUtils.initTestDB(remote, function(err, remoteDb) {
callback(localDb, remoteDb);

@@ -195,5 +184,5 @@ });

var testId = uuid();
var testId = testUtils.uuid();
function generateAdapterUrl(id) {
testUtils.generateAdapterUrl = function(id) {
var opt = id.split('-');

@@ -204,6 +193,3 @@ if (opt[0] === 'local') {

if (opt[0] === 'http') {
var host = (typeof module !== 'undefined' && module.exports) ?
process.env.COUCH_HOST || 'http://localhost:5984/' :
'http://localhost:2020/';
return host + 'testdb_' + testId + '_' + opt[1];
return testUtils.couchHost() + '/testdb_' + testId + '_' + opt[1];
}

@@ -215,3 +201,3 @@ }

// just insert doc with correct _rev (new_edits=false!)
function putAfter(db, doc, prevRev, callback){
testUtils.putAfter = function(db, doc, prevRev, callback){
var newDoc = PouchDB.extend({}, doc);

@@ -234,3 +220,3 @@ if (!prevRev) {

// starting from root
var putBranch = function(db, docs, callback) {
testUtils.putBranch = function(db, docs, callback) {
function insert(i) {

@@ -248,3 +234,3 @@ var doc = docs[i];

if(err){
putAfter(db, docs[i], prev, function(err, doc) {
testUtils.putAfter(db, docs[i], prev, function(err, doc) {
next();

@@ -261,6 +247,6 @@ });

var putTree = function(db, tree, callback) {
testUtils.putTree = function(db, tree, callback) {
function insert(i) {
var branch = tree[i];
putBranch(db, branch, function() {
testUtils.putBranch(db, branch, function() {
if (i < tree.length - 1) {

@@ -276,3 +262,3 @@ insert(i+1);

var writeDocs = function(db, docs, callback, res) {
testUtils.writeDocs = function(db, docs, callback, res) {
if (!res) {

@@ -285,6 +271,6 @@ res = [];

var doc = docs.shift();
db.put(doc, function(err, doc) {
ok(doc.ok, 'docwrite returned ok');
res.push(doc);
writeDocs(db, docs, callback, res);
db.put(doc, function(err, info) {
ok(info && info.ok, 'docwrite returned ok');
res.push(info);
testUtils.writeDocs(db, docs, callback, res);
});

@@ -295,3 +281,3 @@ };

// Borrowed from: http://stackoverflow.com/a/840849
function eliminateDuplicates(arr) {
testUtils.eliminateDuplicates = function(arr) {
var i, element,

@@ -315,3 +301,3 @@ len = arr.length,

//enable CORS on server
function enableCORS(dburl, callback) {
testUtils.enableCORS = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -329,3 +315,3 @@

//enable CORS Credentials on server
function enableCORSCredentials(dburl, callback) {
testUtils.enableCORSCredentials = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -340,3 +326,3 @@

//disable CORS
function disableCORS(dburl, callback) {
testUtils.disableCORS = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -362,3 +348,3 @@

//disable CORS Credentials
function disableCORSCredentials(dburl, callback) {
testUtils.disableCORSCredentials = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -377,3 +363,3 @@

//create admin user and member user
function setupAdminAndMemberConfig(dburl, callback) {
testUtils.setupAdminAndMemberConfig = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -392,3 +378,3 @@

//delete admin and member user
function tearDownAdminAndMemberConfig(dburl, callback) {
testUtils.tearDownAdminAndMemberConfig = function(dburl, callback) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -414,3 +400,3 @@ var headers = {};

function deleteCookieAuth(dburl, callback_) {
testUtils.deleteCookieAuth = function(dburl, callback_) {
var host = 'http://' + dburl.split('/')[2] + '/';

@@ -426,4 +412,4 @@

function cleanUpCors(dburl, callback_) {
if (PERSIST_DATABASES) {
testUtils.cleanUpCors = function(dburl, callback_) {
if (testUtils.PERSIST_DATABASES) {
return;

@@ -442,33 +428,6 @@ }

}
// ---- END CORS Specific Utils ---- //
if (typeof module !== 'undefined' && module.exports) {
PouchDB = require('../lib');
module.exports = {
uuid: uuid,
makeDocs: makeDocs,
makeBlob: makeBlob,
readBlob: readBlob,
base64Blob: base64Blob,
initTestDB: initTestDB,
initDBPair: initDBPair,
openTestDB: openTestDB,
openTestAsyncDB: openTestAsyncDB,
generateAdapterUrl: generateAdapterUrl,
putAfter: putAfter,
putBranch: putBranch,
putTree: putTree,
writeDocs: writeDocs,
cleanupTestDatabases: cleanupTestDatabases,
PERSIST_DATABASES: PERSIST_DATABASES,
eliminateDuplicates: eliminateDuplicates,
enableCORS: enableCORS,
enableCORSCredentials: enableCORSCredentials,
setupAdminAndMemberConfig: setupAdminAndMemberConfig,
tearDownAdminAndMemberConfig: tearDownAdminAndMemberConfig,
disableCORS: disableCORS,
disableCORSCredentials: disableCORSCredentials,
cleanUpCors: cleanUpCors,
deleteCookieAuth: deleteCookieAuth
};
module.exports = testUtils;
}

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

/*globals $, utils: true, eliminateDuplicates */
"use strict";

@@ -8,9 +6,4 @@

if (typeof module !== undefined && module.exports) {
PouchDB = require('../lib');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var PouchDB = require('../lib');
var testUtils = require('./test.utils.js');
}

@@ -38,3 +31,3 @@

equal(eliminateDuplicates(uuids).length, count,
equal(testUtils.eliminateDuplicates(uuids).length, count,
"Generated UUIDS are unique.");

@@ -48,3 +41,3 @@ });

var uuids = PouchDB.utils.uuids(count, {length: length});
equal(eliminateDuplicates(uuids).length, count,
equal(testUtils.eliminateDuplicates(uuids).length, count,
"Generated small UUIDS are unique.");

@@ -51,0 +44,0 @@ });

@@ -1,22 +0,8 @@

/*globals initTestDB: false, emit: true, generateAdapterUrl: false */
/*globals PERSIST_DATABASES: false, initDBPair: false, utils: true */
/*globals cleanupTestDatabases: false */
"use strict";
var adapters = ['local-1', 'http-1'];
var qunit = module;
var LevelPouch;
// if we are running under node.js, set things up
// a little differently, and only test the leveldb adapter
if (typeof module !== undefined && module.exports) {
var PouchDB = require('../lib');
var LevelPouch = require('../lib/adapters/leveldb');
var utils = require('./test.utils.js');
for (var k in utils) {
global[k] = global[k] || utils[k];
}
qunit = QUnit.module;
var testUtils = require('./test.utils.js');
}

@@ -26,13 +12,13 @@

qunit('views: ' + adapter, {
QUnit.module('views: ' + adapter, {
setup : function () {
this.name = generateAdapterUrl(adapter);
this.remote = generateAdapterUrl('local-2');
this.name = testUtils.generateAdapterUrl(adapter);
this.remote = testUtils.generateAdapterUrl('local-2');
PouchDB.enableAllDbs = true;
},
teardown: cleanupTestDatabases
teardown: testUtils.cleanupTestDatabases
});
asyncTest("Test basic view", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: 'bar'}, { _id: 'volatile', foo: 'baz' }]}, {}, function() {

@@ -64,3 +50,3 @@ var queryFun = {

asyncTest("Test passing just a function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{foo: 'bar'}, { _id: 'volatile', foo: 'baz' }]}, {}, function() {

@@ -89,3 +75,3 @@ var queryFun = function(doc) { emit(doc.foo, doc); };

asyncTest("Test opts.startkey/opts.endkey", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{key: 'key1'},{key: 'key2'},{key: 'key3'},{key: 'key4'},{key: 'key5'}]}, {}, function() {

@@ -113,3 +99,3 @@ var queryFun = {

asyncTest("Test opts.key", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{key: 'key1'},{key: 'key2'},{key: 'key3'},{key: 'key3'}]}, {}, function() {

@@ -177,3 +163,3 @@ var queryFun = {

initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var docs = values.map(function(x, i) {

@@ -203,3 +189,3 @@ return {_id: (i).toString(), foo: x};

asyncTest("Test joins", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({docs: [{_id: 'mydoc', foo: 'bar'}, { doc_id: 'mydoc' }]}, {}, function() {

@@ -223,3 +209,3 @@ var queryFun = {

asyncTest("No reduce function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({foo: 'bar'}, function(err, res) {

@@ -240,3 +226,3 @@ var queryFun = {

asyncTest("Built in _sum reduce function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -266,3 +252,3 @@ docs: [

asyncTest("Built in _count reduce function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -292,3 +278,3 @@ docs: [

asyncTest("Built in _stats reduce function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -321,3 +307,3 @@ docs: [

asyncTest("No reduce function, passing just a function", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.post({foo: 'bar'}, function(err, res) {

@@ -339,3 +325,3 @@ var queryFun = function(doc) { emit('key', 'val'); };

var queryFun = function(doc) { emit(doc._id, !!doc._conflicts); };
initDBPair(this.name, this.remote, function(db, remote) {
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.post(doc1, function(err, res) {

@@ -357,4 +343,39 @@ remote.post(doc2, function(err, res) {

asyncTest('Map only documents with _conflicts (#1000)', function() {
var self = this;
var docs1 = [
{_id: '1', foo: 'bar'},
{_id: '2', name: 'two'},
];
var doc2 = {_id: '1', foo: 'baz'};
var queryFun = function(doc) {
if (doc._conflicts) {
emit(doc._id, doc._conflicts);
}
};
testUtils.initDBPair(this.name, this.remote, function(db, remote) {
db.bulkDocs({docs: docs1}, function(err, res) {
var revId1 = res[0].rev;
remote.post(doc2, function(err, res) {
var revId2 = res.rev;
db.replicate.from(remote, function(err, res) {
db.get(docs1[0]._id, {conflicts: true}, function(err, res) {
var winner = res._rev;
var looser = winner === revId1 ? revId2 : revId1;
ok(res._conflicts,'Conflict exists in db');
db.query(queryFun, function(err, res) {
strictEqual(res.rows.length, 1, 'One doc with conflicts');
strictEqual(res.rows[0].key, '1', 'Correct document with conflicts.');
deepEqual(res.rows[0].value, [looser], 'Correct conflicts included.');
start();
});
});
});
});
});
});
});
asyncTest("Test view querying with limit option", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -383,3 +404,3 @@ docs: [

asyncTest("Query non existing view returns error", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
var doc = {

@@ -395,4 +416,8 @@ _id: '_design/barbar',

db.query('barbar/dontExist',{key: 'bar'}, function(err, res) {
equal(err.error, 'not_found');
equal(err.reason, 'missing_named_view');
if(!err.name){
err.name = err.error;
err.message = err.reason;
}
equal(err.name, 'not_found');
equal(err.message, 'missing_named_view');
start();

@@ -405,3 +430,3 @@ });

asyncTest("Special document member _doc_id_rev should never leak outside", function() {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -426,3 +451,3 @@ docs: [

asyncTest('If reduce function returns 0, resulting value should not be null', function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -449,3 +474,3 @@ docs: [

asyncTest('Testing skip with a view', function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -470,3 +495,3 @@ docs: [

asyncTest('Testing skip with allDocs', function () {
initTestDB(this.name, function(err, db) {
testUtils.initTestDB(this.name, function(err, db) {
db.bulkDocs({

@@ -488,2 +513,35 @@ docs: [

asyncTest('Map documents on 0/null/undefined/empty string', function() {
testUtils.initTestDB(this.name, function(err, db) {
var docs = [
{_id : 'doc0', num : 0},
{_id : 'doc1', num : 1},
{_id : 'doc2' /* num is undefined */},
{_id : 'doc3', num : null},
{_id : 'doc4', num : ''}
];
db.bulkDocs({docs: docs}, function(err){
var mapFunction =function(doc){emit(doc.num, null);};
db.query(mapFunction, {key : 0, include_docs : true}, function(err, data){
equal(data.rows.length, 1);
equal(data.rows[0].doc._id, 'doc0');
});
db.query(mapFunction, {key : null, include_docs : true}, function(err, data){
equal(data.rows.length, 2);
equal(data.rows[0].doc._id, 'doc2');
equal(data.rows[1].doc._id, 'doc3');
});
db.query(mapFunction, {key : '', include_docs : true}, function(err, data){
equal(data.rows.length, 1);
equal(data.rows[0].doc._id, 'doc4');
});
db.query(mapFunction, {key : undefined, include_docs : true}, function(err, data){
equal(data.rows.length, 5); // everything
start();
});
});
});
});
});

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

/*globals $:false, console: false */
"use strict";

@@ -11,18 +9,13 @@

if (!testFiles.length) {
// If you want to run performance tests, uncomment these tests
// and comment out the testFiles below
//testFiles = [
// 'perf.attachments.js'
//];
// Temporarily disable tests that can leave CouchDB in non Admin Party
// 'test.cors.js'
// 'test.auth_replication.js',
testFiles = ['test.basics.js', 'test.all_dbs.js', 'test.changes.js',
'test.bulk_docs.js', 'test.all_docs.js', 'test.conflicts.js',
'test.revs_diff.js',
'test.replication.js', 'test.views.js', 'test.taskqueue.js',
'test.design_docs.js', 'test.issue221.js', 'test.http.js',
'test.compaction.js', 'test.get.js',
'test.attachments.js', 'test.uuids.js', 'test.slash_id.js'];
testFiles = [
'test.setup.js',
'test.basics.js', 'test.all_dbs.js', 'test.changes.js',
'test.bulk_docs.js', 'test.all_docs.js', 'test.conflicts.js',
'test.revs_diff.js',
'test.replication.js', 'test.views.js', 'test.taskqueue.js',
'test.design_docs.js', 'test.issue221.js', 'test.http.js',
'test.compaction.js', 'test.get.js',
'test.attachments.js', 'test.uuids.js', 'test.slash_id.js',
'test.worker.js'
];
}

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

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