JSON Diff and Patch: TerminusDB Patch Endpoint

The diff and patch functionality has a diff endpoint and a patch endpoint. The patch

I checked the source code for the client driver, and you would supply { patch, author, message } to the endpoint and patch is an array of patch with @id set.

Patch (with a before document): https://terminusdb.org/docs/javascript/#patchbeforepatch

PatchResource (patch a resource): https://terminusdb.org/docs/javascript/#patchresourcepatchmessage

The patch endpoint is used differently, with a before document and a patch, you apply a patch without id to a specific before document:{before, patch} (javascript syntax).

With the patch endpoint for a resource, you supply a list of patched with the @id field added to the patch. Unsure if you can patch multiple documents by supplying an array for the @id field, but can be worth trying if relevant to your use case.

Patching a terminusdb resource

[
  {
   "@id": "Obj/id1",
    "name": {
     "@op": "SwapValue",
      "@before": "foo",
      "@after": "bar"
    }
  },
 {
   "@id": "Obj/id2",
    "name": {
      "@op": "SwapValue",
      "@before": "foo",
     "@after": "bar"
    }
 }
]
client.db("mydb")
client.checkout("mybranch")
client.patchResource(patch,"apply patch to mybranch").then(patchResult=>{
 console.log(patchResult)
})
// result example
// ["Obj/id1",
// "Obj/id2"]
// or conflict error 409
// {
// "@type": "api:PatchError",
// "api:status": "api:conflict",
// "api:witnesses": [
//  {
//   "@op": "InsertConflict",
//    "@id_already_exists": "Person/Jane"
//  }
//]
//}