Git-like repository for in-memory object versioning
MIT License
An in-memory git-like repository for objects for when you need to keep the history around for a bit longer. The library uses json-patch RFC6902 for representing diffs.
⚠️ Currently with a workaround to adapt for setting a value for an undefined prop
{prop: undefined}
will result in thecompare
call as areplace
operation, but will be recorded by the observer as anadd
operation. Applying a patch like that will result in internal retry withadd
instead ofreplace
.See https://github.com/Starcounter-Jack/JSON-Patch/issues/280 for details
@dotinc/ogre-react
const repo = new Repository(new ComplexObject());
// apply changes
repo.data.name = "my name";
repo.data.description = "now we have a description";
// commit changes
const init = await repo.commit("initial commit", "author <[email protected]>");
// create a branch named savepoint pointing to the last commit
repo.createBranch("savepoint");
// switch to new branch
repo.checkout("add_details", true);
// apply changes
repo.data.name = "a fancier name";
// a) commit & merge
await repo.commit("change name", "author <[email protected]>");
repo.checkout("main");
repo.merge("add_details");
repo.tag("v1.0.0");
// or b) discard change and go back
// by using the branch name
repo.checkout("main");
// by using the commit hash in a detached state
repo.checkout(init);