Socket
Socket
Sign inDemoInstall

pouchdb-utils

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pouchdb-utils - npm Package Compare versions

Comparing version 6.0.2 to 6.0.3

205

lib/index-browser.js

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

var Promise = _interopDefault(require('pouchdb-promise'));
var lie = _interopDefault(require('lie'));
var getArguments = _interopDefault(require('argsarray'));

@@ -13,4 +13,6 @@ 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) {

@@ -142,3 +144,3 @@ return (typeof ArrayBuffer !== 'undefined' && object instanceof ArrayBuffer) ||

}
var promise = new Promise(function (fulfill, reject) {
var promise = new PouchPromise(function (fulfill, reject) {
var resp;

@@ -201,6 +203,6 @@ try {

if (this._closed) {
return Promise.reject(new Error('database is closed'));
return PouchPromise.reject(new Error('database is closed'));
}
if (this._destroyed) {
return Promise.reject(new Error('database is destroyed'));
return PouchPromise.reject(new Error('database is destroyed'));
}

@@ -210,3 +212,3 @@ var self = this;

if (!this.taskqueue.isReady) {
return new Promise(function (fulfill, reject) {
return new PouchPromise(function (fulfill, reject) {
self.taskqueue.addTask(function (failed) {

@@ -552,2 +554,183 @@ 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) {

@@ -558,3 +741,3 @@ try {

var msg = 'Filter function threw: ' + err.toString();
return pouchdbErrors.createError(pouchdbErrors.BAD_REQUEST, msg);
return createError(BAD_REQUEST, msg);
}

@@ -638,7 +821,7 @@ }

if (!id) {
err = pouchdbErrors.createError(pouchdbErrors.MISSING_ID);
err = createError(MISSING_ID);
} else if (typeof id !== 'string') {
err = pouchdbErrors.createError(pouchdbErrors.INVALID_ID);
err = createError(INVALID_ID);
} else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) {
err = pouchdbErrors.createError(pouchdbErrors.RESERVED_ID);
err = createError(RESERVED_ID);
}

@@ -718,3 +901,3 @@ if (err) {

function upsert(db, docId, diffFun) {
return new Promise(function (fulfill, reject) {
return new PouchPromise(function (fulfill, reject) {
db.get(docId, function (err, doc) {

@@ -721,0 +904,0 @@ if (err) {

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

var Promise = _interopDefault(require('pouchdb-promise'));
var lie = _interopDefault(require('lie'));
var getArguments = _interopDefault(require('argsarray'));

@@ -13,4 +13,6 @@ 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) {

@@ -121,3 +123,3 @@ return object instanceof Buffer;

}
var promise = new Promise(function (fulfill, reject) {
var promise = new PouchPromise(function (fulfill, reject) {
var resp;

@@ -180,6 +182,6 @@ try {

if (this._closed) {
return Promise.reject(new Error('database is closed'));
return PouchPromise.reject(new Error('database is closed'));
}
if (this._destroyed) {
return Promise.reject(new Error('database is destroyed'));
return PouchPromise.reject(new Error('database is destroyed'));
}

@@ -189,3 +191,3 @@ var self = this;

if (!this.taskqueue.isReady) {
return new Promise(function (fulfill, reject) {
return new PouchPromise(function (fulfill, reject) {
self.taskqueue.addTask(function (failed) {

@@ -515,2 +517,183 @@ 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) {

@@ -521,3 +704,3 @@ try {

var msg = 'Filter function threw: ' + err.toString();
return pouchdbErrors.createError(pouchdbErrors.BAD_REQUEST, msg);
return createError(BAD_REQUEST, msg);
}

@@ -601,7 +784,7 @@ }

if (!id) {
err = pouchdbErrors.createError(pouchdbErrors.MISSING_ID);
err = createError(MISSING_ID);
} else if (typeof id !== 'string') {
err = pouchdbErrors.createError(pouchdbErrors.INVALID_ID);
err = createError(INVALID_ID);
} else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) {
err = pouchdbErrors.createError(pouchdbErrors.RESERVED_ID);
err = createError(RESERVED_ID);
}

@@ -681,3 +864,3 @@ if (err) {

function upsert(db, docId, diffFun) {
return new Promise(function (fulfill, reject) {
return new PouchPromise(function (fulfill, reject) {
db.get(docId, function (err, doc) {

@@ -684,0 +867,0 @@ if (err) {

12

package.json
{
"name": "pouchdb-utils",
"version": "6.0.2",
"version": "6.0.3",
"description": "Unassorted utilities used by PouchDB.",

@@ -19,7 +19,7 @@ "main": "./lib/index.js",

"inherits": "2.0.1",
"pouchdb-collections": "6.0.2",
"pouchdb-binary-utils": "6.0.2",
"pouchdb-errors": "6.0.2",
"pouchdb-md5": "6.0.2",
"pouchdb-promise": "6.0.2"
"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"
},

@@ -26,0 +26,0 @@ "browser": {

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