pouchdb-utils
Advanced tools
Comparing version 6.0.3 to 6.0.4
@@ -7,3 +7,3 @@ 'use strict'; | ||
var lie = _interopDefault(require('lie')); | ||
var Promise = _interopDefault(require('pouchdb-promise')); | ||
var getArguments = _interopDefault(require('argsarray')); | ||
@@ -13,6 +13,4 @@ var debug = _interopDefault(require('debug')); | ||
var inherits = _interopDefault(require('inherits')); | ||
var pouchdbErrors = require('pouchdb-errors'); | ||
/* istanbul ignore next */ | ||
var PouchPromise = typeof Promise === 'function' ? Promise : lie; | ||
function isBinaryObject(object) { | ||
@@ -144,3 +142,3 @@ return (typeof ArrayBuffer !== 'undefined' && object instanceof ArrayBuffer) || | ||
} | ||
var promise = new PouchPromise(function (fulfill, reject) { | ||
var promise = new Promise(function (fulfill, reject) { | ||
var resp; | ||
@@ -203,6 +201,6 @@ try { | ||
if (this._closed) { | ||
return PouchPromise.reject(new Error('database is closed')); | ||
return Promise.reject(new Error('database is closed')); | ||
} | ||
if (this._destroyed) { | ||
return PouchPromise.reject(new Error('database is destroyed')); | ||
return Promise.reject(new Error('database is destroyed')); | ||
} | ||
@@ -212,3 +210,3 @@ var self = this; | ||
if (!this.taskqueue.isReady) { | ||
return new PouchPromise(function (fulfill, reject) { | ||
return new Promise(function (fulfill, reject) { | ||
self.taskqueue.addTask(function (failed) { | ||
@@ -554,183 +552,2 @@ if (failed) { | ||
inherits(PouchError, Error); | ||
function PouchError(opts) { | ||
Error.call(this, opts.reason); | ||
this.status = opts.status; | ||
this.name = opts.error; | ||
this.message = opts.reason; | ||
this.error = true; | ||
} | ||
PouchError.prototype.toString = function () { | ||
return JSON.stringify({ | ||
status: this.status, | ||
name: this.name, | ||
message: this.message, | ||
reason: this.reason | ||
}); | ||
}; | ||
var UNAUTHORIZED = new PouchError({ | ||
status: 401, | ||
error: 'unauthorized', | ||
reason: "Name or password is incorrect." | ||
}); | ||
var MISSING_BULK_DOCS = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: "Missing JSON list of 'docs'" | ||
}); | ||
var MISSING_DOC = new PouchError({ | ||
status: 404, | ||
error: 'not_found', | ||
reason: 'missing' | ||
}); | ||
var REV_CONFLICT = new PouchError({ | ||
status: 409, | ||
error: 'conflict', | ||
reason: 'Document update conflict' | ||
}); | ||
var INVALID_ID = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: '_id field must contain a string' | ||
}); | ||
var MISSING_ID = new PouchError({ | ||
status: 412, | ||
error: 'missing_id', | ||
reason: '_id is required for puts' | ||
}); | ||
var RESERVED_ID = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Only reserved document ids may start with underscore.' | ||
}); | ||
var NOT_OPEN = new PouchError({ | ||
status: 412, | ||
error: 'precondition_failed', | ||
reason: 'Database not open' | ||
}); | ||
var UNKNOWN_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'unknown_error', | ||
reason: 'Database encountered an unknown error' | ||
}); | ||
var BAD_ARG = new PouchError({ | ||
status: 500, | ||
error: 'badarg', | ||
reason: 'Some query argument is invalid' | ||
}); | ||
var INVALID_REQUEST = new PouchError({ | ||
status: 400, | ||
error: 'invalid_request', | ||
reason: 'Request was invalid' | ||
}); | ||
var QUERY_PARSE_ERROR = new PouchError({ | ||
status: 400, | ||
error: 'query_parse_error', | ||
reason: 'Some query parameter is invalid' | ||
}); | ||
var DOC_VALIDATION = new PouchError({ | ||
status: 500, | ||
error: 'doc_validation', | ||
reason: 'Bad special document member' | ||
}); | ||
var BAD_REQUEST = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Something wrong with the request' | ||
}); | ||
var NOT_AN_OBJECT = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Document must be a JSON object' | ||
}); | ||
var DB_MISSING = new PouchError({ | ||
status: 404, | ||
error: 'not_found', | ||
reason: 'Database not found' | ||
}); | ||
var IDB_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'indexed_db_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var WSQ_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'web_sql_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var LDB_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'levelDB_went_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var FORBIDDEN = new PouchError({ | ||
status: 403, | ||
error: 'forbidden', | ||
reason: 'Forbidden by design doc validate_doc_update function' | ||
}); | ||
var INVALID_REV = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Invalid rev format' | ||
}); | ||
var FILE_EXISTS = new PouchError({ | ||
status: 412, | ||
error: 'file_exists', | ||
reason: 'The database could not be created, the file already exists.' | ||
}); | ||
var MISSING_STUB = new PouchError({ | ||
status: 412, | ||
error: 'missing_stub' | ||
}); | ||
var INVALID_URL = new PouchError({ | ||
status: 413, | ||
error: 'invalid_url', | ||
reason: 'Provided URL is invalid' | ||
}); | ||
function createError(error, reason) { | ||
function CustomPouchError(reason) { | ||
// inherit error properties from our parent error manually | ||
// so as to allow proper JSON parsing. | ||
/* jshint ignore:start */ | ||
for (var p in error) { | ||
if (typeof error[p] !== 'function') { | ||
this[p] = error[p]; | ||
} | ||
} | ||
/* jshint ignore:end */ | ||
if (reason !== undefined) { | ||
this.reason = reason; | ||
} | ||
} | ||
CustomPouchError.prototype = PouchError.prototype; | ||
return new CustomPouchError(reason); | ||
} | ||
function tryFilter(filter, doc, req) { | ||
@@ -741,3 +558,3 @@ try { | ||
var msg = 'Filter function threw: ' + err.toString(); | ||
return createError(BAD_REQUEST, msg); | ||
return pouchdbErrors.createError(pouchdbErrors.BAD_REQUEST, msg); | ||
} | ||
@@ -821,7 +638,7 @@ } | ||
if (!id) { | ||
err = createError(MISSING_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.MISSING_ID); | ||
} else if (typeof id !== 'string') { | ||
err = createError(INVALID_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.INVALID_ID); | ||
} else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) { | ||
err = createError(RESERVED_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.RESERVED_ID); | ||
} | ||
@@ -901,3 +718,3 @@ if (err) { | ||
function upsert(db, docId, diffFun) { | ||
return new PouchPromise(function (fulfill, reject) { | ||
return new Promise(function (fulfill, reject) { | ||
db.get(docId, function (err, doc) { | ||
@@ -904,0 +721,0 @@ if (err) { |
205
lib/index.js
@@ -7,3 +7,3 @@ 'use strict'; | ||
var lie = _interopDefault(require('lie')); | ||
var Promise = _interopDefault(require('pouchdb-promise')); | ||
var getArguments = _interopDefault(require('argsarray')); | ||
@@ -13,6 +13,4 @@ var debug = _interopDefault(require('debug')); | ||
var inherits = _interopDefault(require('inherits')); | ||
var pouchdbErrors = require('pouchdb-errors'); | ||
/* istanbul ignore next */ | ||
var PouchPromise = typeof Promise === 'function' ? Promise : lie; | ||
function isBinaryObject(object) { | ||
@@ -123,3 +121,3 @@ return object instanceof Buffer; | ||
} | ||
var promise = new PouchPromise(function (fulfill, reject) { | ||
var promise = new Promise(function (fulfill, reject) { | ||
var resp; | ||
@@ -182,6 +180,6 @@ try { | ||
if (this._closed) { | ||
return PouchPromise.reject(new Error('database is closed')); | ||
return Promise.reject(new Error('database is closed')); | ||
} | ||
if (this._destroyed) { | ||
return PouchPromise.reject(new Error('database is destroyed')); | ||
return Promise.reject(new Error('database is destroyed')); | ||
} | ||
@@ -191,3 +189,3 @@ var self = this; | ||
if (!this.taskqueue.isReady) { | ||
return new PouchPromise(function (fulfill, reject) { | ||
return new Promise(function (fulfill, reject) { | ||
self.taskqueue.addTask(function (failed) { | ||
@@ -517,183 +515,2 @@ if (failed) { | ||
inherits(PouchError, Error); | ||
function PouchError(opts) { | ||
Error.call(this, opts.reason); | ||
this.status = opts.status; | ||
this.name = opts.error; | ||
this.message = opts.reason; | ||
this.error = true; | ||
} | ||
PouchError.prototype.toString = function () { | ||
return JSON.stringify({ | ||
status: this.status, | ||
name: this.name, | ||
message: this.message, | ||
reason: this.reason | ||
}); | ||
}; | ||
var UNAUTHORIZED = new PouchError({ | ||
status: 401, | ||
error: 'unauthorized', | ||
reason: "Name or password is incorrect." | ||
}); | ||
var MISSING_BULK_DOCS = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: "Missing JSON list of 'docs'" | ||
}); | ||
var MISSING_DOC = new PouchError({ | ||
status: 404, | ||
error: 'not_found', | ||
reason: 'missing' | ||
}); | ||
var REV_CONFLICT = new PouchError({ | ||
status: 409, | ||
error: 'conflict', | ||
reason: 'Document update conflict' | ||
}); | ||
var INVALID_ID = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: '_id field must contain a string' | ||
}); | ||
var MISSING_ID = new PouchError({ | ||
status: 412, | ||
error: 'missing_id', | ||
reason: '_id is required for puts' | ||
}); | ||
var RESERVED_ID = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Only reserved document ids may start with underscore.' | ||
}); | ||
var NOT_OPEN = new PouchError({ | ||
status: 412, | ||
error: 'precondition_failed', | ||
reason: 'Database not open' | ||
}); | ||
var UNKNOWN_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'unknown_error', | ||
reason: 'Database encountered an unknown error' | ||
}); | ||
var BAD_ARG = new PouchError({ | ||
status: 500, | ||
error: 'badarg', | ||
reason: 'Some query argument is invalid' | ||
}); | ||
var INVALID_REQUEST = new PouchError({ | ||
status: 400, | ||
error: 'invalid_request', | ||
reason: 'Request was invalid' | ||
}); | ||
var QUERY_PARSE_ERROR = new PouchError({ | ||
status: 400, | ||
error: 'query_parse_error', | ||
reason: 'Some query parameter is invalid' | ||
}); | ||
var DOC_VALIDATION = new PouchError({ | ||
status: 500, | ||
error: 'doc_validation', | ||
reason: 'Bad special document member' | ||
}); | ||
var BAD_REQUEST = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Something wrong with the request' | ||
}); | ||
var NOT_AN_OBJECT = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Document must be a JSON object' | ||
}); | ||
var DB_MISSING = new PouchError({ | ||
status: 404, | ||
error: 'not_found', | ||
reason: 'Database not found' | ||
}); | ||
var IDB_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'indexed_db_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var WSQ_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'web_sql_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var LDB_ERROR = new PouchError({ | ||
status: 500, | ||
error: 'levelDB_went_went_bad', | ||
reason: 'unknown' | ||
}); | ||
var FORBIDDEN = new PouchError({ | ||
status: 403, | ||
error: 'forbidden', | ||
reason: 'Forbidden by design doc validate_doc_update function' | ||
}); | ||
var INVALID_REV = new PouchError({ | ||
status: 400, | ||
error: 'bad_request', | ||
reason: 'Invalid rev format' | ||
}); | ||
var FILE_EXISTS = new PouchError({ | ||
status: 412, | ||
error: 'file_exists', | ||
reason: 'The database could not be created, the file already exists.' | ||
}); | ||
var MISSING_STUB = new PouchError({ | ||
status: 412, | ||
error: 'missing_stub' | ||
}); | ||
var INVALID_URL = new PouchError({ | ||
status: 413, | ||
error: 'invalid_url', | ||
reason: 'Provided URL is invalid' | ||
}); | ||
function createError(error, reason) { | ||
function CustomPouchError(reason) { | ||
// inherit error properties from our parent error manually | ||
// so as to allow proper JSON parsing. | ||
/* jshint ignore:start */ | ||
for (var p in error) { | ||
if (typeof error[p] !== 'function') { | ||
this[p] = error[p]; | ||
} | ||
} | ||
/* jshint ignore:end */ | ||
if (reason !== undefined) { | ||
this.reason = reason; | ||
} | ||
} | ||
CustomPouchError.prototype = PouchError.prototype; | ||
return new CustomPouchError(reason); | ||
} | ||
function tryFilter(filter, doc, req) { | ||
@@ -704,3 +521,3 @@ try { | ||
var msg = 'Filter function threw: ' + err.toString(); | ||
return createError(BAD_REQUEST, msg); | ||
return pouchdbErrors.createError(pouchdbErrors.BAD_REQUEST, msg); | ||
} | ||
@@ -784,7 +601,7 @@ } | ||
if (!id) { | ||
err = createError(MISSING_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.MISSING_ID); | ||
} else if (typeof id !== 'string') { | ||
err = createError(INVALID_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.INVALID_ID); | ||
} else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) { | ||
err = createError(RESERVED_ID); | ||
err = pouchdbErrors.createError(pouchdbErrors.RESERVED_ID); | ||
} | ||
@@ -864,3 +681,3 @@ if (err) { | ||
function upsert(db, docId, diffFun) { | ||
return new PouchPromise(function (fulfill, reject) { | ||
return new Promise(function (fulfill, reject) { | ||
db.get(docId, function (err, doc) { | ||
@@ -867,0 +684,0 @@ if (err) { |
{ | ||
"name": "pouchdb-utils", | ||
"version": "6.0.3", | ||
"version": "6.0.4", | ||
"description": "Unassorted utilities used by PouchDB.", | ||
@@ -19,7 +19,7 @@ "main": "./lib/index.js", | ||
"inherits": "2.0.1", | ||
"pouchdb-collections": "6.0.3", | ||
"pouchdb-binary-utils": "6.0.3", | ||
"pouchdb-errors": "6.0.3", | ||
"pouchdb-md5": "6.0.3", | ||
"pouchdb-promise": "6.0.3" | ||
"pouchdb-collections": "6.0.4", | ||
"pouchdb-binary-utils": "6.0.4", | ||
"pouchdb-errors": "6.0.4", | ||
"pouchdb-md5": "6.0.4", | ||
"pouchdb-promise": "6.0.4" | ||
}, | ||
@@ -26,0 +26,0 @@ "browser": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80949
2291
+ Addedpouchdb-binary-utils@6.0.4(transitive)
+ Addedpouchdb-collections@6.0.4(transitive)
+ Addedpouchdb-errors@6.0.4(transitive)
+ Addedpouchdb-md5@6.0.4(transitive)
+ Addedpouchdb-promise@6.0.4(transitive)
- Removedpouchdb-binary-utils@6.0.3(transitive)
- Removedpouchdb-collections@6.0.3(transitive)
- Removedpouchdb-errors@6.0.3(transitive)
- Removedpouchdb-md5@6.0.3(transitive)
- Removedpouchdb-promise@6.0.3(transitive)
Updatedpouchdb-binary-utils@6.0.4
Updatedpouchdb-collections@6.0.4
Updatedpouchdb-errors@6.0.4
Updatedpouchdb-md5@6.0.4
Updatedpouchdb-promise@6.0.4