pouchdb/pouchdb-validation

Name: pouchdb-validation

Owner: PouchDB

Description: A PouchDB plug-in that allows you to re-use your CouchDB validate_doc_update functions on the client side.

Created: 2015-08-19 08:43:26.0

Updated: 2018-05-22 07:07:58.0

Pushed: 2017-03-07 08:36:00.0

Homepage: null

Size: 31

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

pouchdb-validation

Build Status Dependency Status devDependency Status

A PouchDB plug-in that allows you to re-use your CouchDB validate_doc_update functions on the client side.

A browser version is available.

First, make sure you understand how validation functions work in CouchDB. A good start is the CouchDB guide entry on validation functions.

Usage

First, you need to register the plug-in with PouchDB. That can be done using the PouchDB.plugin() function. In NodeJS, you can just pass in the result of the require() function. In the browser, you pass in the browser object name given above.

An example (using the list plug-in):

deJS (and Browserify)
hDB.plugin(require("pouchdb-validation"));

owser - after the JavaScript file containing the plug-in has been
cluded via a script tag (or something similar).
hDB.plugin(Validation);

All functions have two ways of returning the output to the user. One is a callback parameter, which should have the signature (err, resp). The other is the Promise all functions return. PouchDB itself uses the same system.

db.validatingPut(doc[, options[, callback]])

Exactly the same as the db.put function, but checks with all validation functions ('validate_doc_update') in all design documents of the current database if it is ok to save doc. In short, this method acts more like its CouchDB equivalent than the original PouchDB version does. The only thing you get to see of it is a few extra errors, i.e. of the 'unauthorized' or the 'forbidden' type. It also has a few extra options (defaults are shown):

db.validatingPost(doc[, options[, callback]])

See the db.validatingPut() function.

db.validatingRemove(doc[, options[, callback]])

See the db.validatingPut() function.

db.validatingBulkDocs(bulkDocs[, options[, callback]])

See the db.validatingPut() function. Returns an array, like db.bulkDocs(). The all_or_nothing attribute on bulkDocs is unsupported. Also, the result array might not be in the same order as the passed in documents.

db.validatingPutAttachment(docId, attachmentId, rev, attachment, type[, options[, callback]])

See the db.validatingPut() function. Output is the same as db.putAttachment() (except for a few extra errors being possible.)

db.validatingRemoveAttachment(docId, attachmentId, rev[, options[, callback]])

See the db.validatingPut() function. Output is the same as db.removeAttachment() (except for a few extra errors being possible.)

db.installValidationMethods()

Installs the validation methods on this database. In other words, the db.* methods are replaced by their db.validating* counterparts. This method is always synchronous.

Throws: an error if the methods are already installed. Returns: nothing

db.uninstallValidationMethods()

Undoes what db.installValidationMethods did. This method is always synchronous.

Throws: an error if the methods aren't currently installed. Returns: nothing

License

Apache-2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.