JSPM

pouch-resolve-conflicts

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 326
  • Score
    100M100P100Q87558F
  • License MIT

Assist in CouchDB conflict resolving.

Package Exports

  • pouch-resolve-conflicts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pouch-resolve-conflicts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pouch-resolve-conflicts

Assist in PouchDB conflict resolving.

Build Status

Installation

pouch-resolve-conflicts is hosted on npm.

Node

Install via npm install pouch-resolve-conflicts

var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouch-resolve-conflicts'))

Browser

Use the browserified build.

<script src="pouchdb.js"></script>
<script src="pouch-resolve-conflicts.js"></script>

Usage

var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouch-resolve-conflicts'))

function resolveFun(a, b) {
  // cannot merge: return nothing
  if ('foo' in a && 'foo' in b) return
  
  // return one of the docs
  if ('foo' in a) return a
  if ('foo' in b) return b
  
  // return changed doc
  a.foo = 'bar'
  return a
}

var db = new PouchDB('mydb')

db
  // Lets have a conflict
  .bulkDocs({
    docs: [
      { _id: 'mydoc', _rev: '1-one', foo: 'bar' },
      { _id: 'mydoc', _rev: '1-two', bar: 'baz' }
    ],
    new_edits: false
  })
  // Query doc with `conflicts: true`
  .then(function(response) {
    return db.get('mydoc', { conflicts: true })
  })
  // And resolve it
  .then(function(doc) {
    return db.resolveConflicts(doc, resolveFun)
  })

Tests

npm test