Open cinnamon-bun opened 4 years ago
The above idea is complex and there's an easier way to make immutable documents: just add an immutable
property. But let's look at the big picture first.
Immutable docs would be useful in some situations...
Sometimes we might want immutable docs to be deletable, and sometimes permanent. Deletable docs can be overwritten exactly once with an empty document. Permanent docs can not be overwritten with anything.
It should also be possible to combine this with ephemeral docs, to create immutable docs that expire and go away. After they go away you could write a new one to the same path, so it's only sort of temporarily immutable.
immutable
property on docsThis optional property would only be present on immutable docs. It might have two possible values: one for deletable immutable docs and another for non-deletable immutable docs.
{
path: '/my/path/here.txt'
immutable: true, // or maybe "deletable" | "nondeletable"
// ...other document properties...
}
Pro:
es.4
without breaking old dataCon:
Someone could put an immutable doc in the way of some other doc that you wanted to make, if it had a shared path (a path not owned by anyone).
Maybe we could require immutable docs to have something special in their path, similar to how ephemeral docs have !
in their path.
Or instead we could add an optional property called remainingEdits
which holds a small integer. Immutable docs have 0 remaining edits. The number counts down every time the doc is edited and it can't go below zero.
I'm not sure exactly what use cases this would allow, but apps might be able to do something clever with it. For example it could create a sort of scarcity if each person had a doc that they could only edit five times, meaning they would want to only use it in serious situations.
This idea is very old, please see the comments for newer ideas
Goal
Allow documents to be (optionally) immutable, meaning you can't overwrite them with newer versions.
How
Paths could contain a special marker which will be replaced with the document's hash:
Because it's hard/impossible to create hash collisions, nobody will be able to create another document version with the same hash, so this document version can never be overwritten with a newer one.
New concepts
This splits the idea of paths into two:
Documents that are being signed or sent across the wire only have Path Templates. The path templates are kept forever as part of the original item. They are not used for path lookups and queries (?)
Expanded paths are derived state, computed by the Storage when receiving documents. They are used for all kinds of path lookups and queries.
Details
We'll need to reserve a few characters for this, both for the Path Templates and the Expanded Paths.
You must not be able to create an Expanded Path directly, so in this example
#
would have to be disallowed from Path Templates.Tasks
Bonus
Once we have these two kinds of path, we can add another expansion which is a shorthand for the author's own key:
This is just an optimization to save space from repeating the author's full address all the time. It might not be worth the extra complexity.