Store and read object patches (with metadata) in insert order
Store and read object patches (with metadata) in insert order. Based on level-patch-data.
var assert = require'assert'var Pouch = require'pouchdb'var Patch = require'pouchdb-patch-data'var db = Pouchdb'patch-test'var patch = Patchdbpatchadd'doc' a: 'a' user: 'lee'patchadd'doc' b: 'c' user: 'kara'patchget'doc'// body isuser: 'lee'namespace: 'doc'patch: a: 'a'// _id is namespaced and sorted by timestamp_id: 'a070646f6335007068786c38693434352e30366274390000'_rev: '1-92e0f5bd431fb35aef6dbcc509e07732'user: 'kara'namespace: 'doc'patch: b: 'c'_id: 'a070646f6335007068786c38693434352e30376c64690000'_rev: '1-66ca124e82aecce68d0a3a3a25ccb6d6'
See tests for more examples.
db: an instance of
pouchdbto store patches and data.
opts.namespaceField: the field to use to store the
opts.patchField: the field to use to store the
namespace: the string to identify this collections of patches. This module is designed for use with patcher patches for a single object per unique
patch: the object to store as the patch
meta: key/value pairs to store with this patch. Note: the keys
opts.patchFieldwill be overwritten if set.
callback: receives two arguments,
errwhich is only set if an error occurs and
commit, which is the patch and its metadata exactly as it was saved.
Callback is called with any error and a list of commits in insert order.
namespace: the collection of patches to read. patches will be streamed in the order inserted.
since: optional. pass the
_idof the commit to read commits since. The commit with
_id === sincewill not be returned, only all commits after it.