Change an item's edges without losing changes
Change, remove or replace an item's edges so that no write undoes a link another app or agent made since you read them.
Another app, agent or device may add, change or remove an item's edges between your read and your write. An edge has a version of its own, and an item's version doesn't count its edges (Versions). To guard a link, name the versions of the edges you read. In the TypeScript examples, marfa is a client made as the TypeScript SDK shows.
Change or remove one edge
Update an edge names the version you read, and Delete an edge can too:
marfa edges delete <edge-id> --version 2If the edge changed since, Marfa keeps it and answers 409 version_conflict, with the edge in current. Without a version, the delete removes the edge as it stands, changed or not.
Replace an item's edges as you read them
Update an item can send edges, which replaces the item's outgoing edges of each type it names with edges to the items listed. On its own, it also removes an edge another writer drew since you read the list.
To prevent that, send read_edges: for each type in edges, the edges of that type you read, each by its id and version. List an item's edges answers both. An empty list means the item had none. The order doesn't matter.
PATCH /items/<id>
Authorization: Bearer <key>
Content-Type: application/json
{
"version": 3,
"edges": { "in-collection": ["01a1f139-e0a3-704f-8070-83f64acc3f15"] },
"read_edges": {
"in-collection": [{ "id": "01a1011c-5b2e-7c41-9a3d-2f6b8e4c1d07", "version": 1 }]
}
}If the item's edges of a type you listed are not the ones you read, Marfa writes nothing and answers 409 version_conflict, with the item in current. That holds even when the write would change nothing, and with conflict=auto. Read the edges again, decide which links to keep, and send the write again.
Every type in read_edges must also be in edges. A type that isn't is refused 400 validation_error, with read_edges.<type> in details.field. Only an update takes read_edges: a create and a bulk write don't.
The rules are in the contract's edges chapter.