jsonvc v0.0.0
jsonvc
jsonvc is a simple library for versioning JSON documents.
jsonvc is still an experimental library and unstable.
jsonvc is intended to be used in developing web applications which need simple document versioning, where
- NoSQL backend is used
- Many small updates are made on large documents
Examples
To create and initialize a versioned document:
var jsonvc = require('jsonvc');
// Create a new versioned document from a normal document
var vdoc = jsonvc.init({ a: 1 });
// Or from an existing versioned document
var doc = vdoc.dumpDoc();
var repository = vdoc.dump();
var vdoc2 = jsonvc.load(doc, repository);
To update the document:
// Create a new commit and update the document to { a: 1, b: 2 }
vdoc.update({ a: 1, b: 1 });
To restore the document by a commit ID:
var vdoc = jsonvc.init({ a: 1 });
// Remember the first commit ID
var firstCommitId = vdoc.head;
vdoc.update({ a: 1, b: 1 });
// Now, vdoc has two commits and the current document is { a: 1, b: 1 }
// Create a new commit from the latest commit to restore the first document
vdoc.restore(firstCommitId);
// Now, vdoc has three commits and the current document is { a: 1 }
Use .dump()
and .dumpDoc()
to output the repository and the document, respectively:
var vdoc = jsonvc.init({ a: 1 });
vdoc.dump(); // => internal object which represents the repository
vdoc.dumpDoc(); // => { a: 1 }
Installation
Node
Using npm:
npm install --save jsonvc
Browser
You can use Browserify or Webpack or whatever you want.
Contributing to jsonvc
Any ideas, feature requests, pull requests are welcomed.
Please add the relevant tests and ensure that it passes all the tests by executing
npm test
before submitting a pull request.
License
Copyright © 2015 Naoto Yokoyama
Distributed under the MIT license. See the LICENSE file for full details.
9 years ago