Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse Patch Elements #29

Open
4thex opened this issue Dec 11, 2020 · 0 comments
Open

Reverse Patch Elements #29

4thex opened this issue Dec 11, 2020 · 0 comments

Comments

@4thex
Copy link

4thex commented Dec 11, 2020

Summary

The current patch element does not contain enough information to reverse the operation.
In version control it is important to be able to make incremental changes to a document, but it is also important to maintain an audit trail and to be able to reverse patches that have previously been applied. I am therefore proposing a method for creating audit records from the patch elements and how to create the reverse patch actions from an audit record, so you can go back to any previous state.

Details

The format of an audit record will look like this:

{
  "timeStamp": "ISO 6801 timestamp for the action",
  "previous": "Properties from the document or the patch before applying the patch element to assist in creating the reverse audit record. See examples below.",
  "action": "The patch element"
}

For each operation, there is an equivalent reverse operation. This list below shows how they map:

  • add: remove
  • remove: add
  • replace: replace
  • move: move
  • copy: remove
  • test: test

Examples

For the examples, I will be using this document:

{
  "books": [
    {
      "title": "Insider Outsider",
      "isbn": "978-0310345039"
    },
    {
      "title": "Ender's Game",
      "isbn": "978-0765370624"
    },
    {
      "title": "Andersen's Fairy Tales",
      "isbn": "978-1420953626"
    }
  ]
}

add

The patch element:

{
  "op": "add",
  "path": "/books/3",
  "value": {
    {
      "title": "How JavaScript Works",
      "isbn": "978-1949815009"
    }
  }
}

Audit record:

{
  "timeStamp": "2020-12-11T11:17:21Z",
  "action": {
    "op": "add",
    "path": "/books/3",
    "value": {
      {
        "title": "How JavaScript Works",
        "isbn": "978-1949815009"
      }
    }
  }
}

Note: The "previous" property is not needed here.

Reverse patch element:

{
    "op": "remove",
    "path": "/books/3"
}

remove

The patch element:

{
  "op": "remove",
  "path": "/books/3",
}

Audit record:

{
  "timeStamp": "2020-12-11T11:17:22Z",
  "previous": {
  {
    "title": "How JavaScript Works",
    "isbn": "978-1949815009"
  },
  "action": {
    "op": "remove",
    "path": "/books/3"
  }
}

Reverse patch element:

{
  "op": "add",
  "path": "/books/3",
  "value": {
    {
      "title": "How JavaScript Works",
      "isbn": "978-1949815009"
    }
  }
}

replace

move

copy

test

@4thex 4thex closed this as completed Dec 11, 2020
@4thex 4thex reopened this Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant