Skip to content

@typedblite/content-revision

Canonical state encoding and content-derived generation-digest revision identifiers (ADR-003 D3).

A thing’s revision is derived from its content, so two nodes that write the same state arrive at the same revision without talking to each other. canonical fixes what “the same state” means, as a byte string, and computeRevision hashes it with the revision before it. The runtime’s change log is built on these; they have no dependency of their own and run anywhere JavaScript does.

The state a revision covers, and its encoding as text that does not depend on the order things were written in.

Name Description
CanonicalAttribute One attribute of a thing. Values are TEXT in storage, so the encoding does not type them.
CanonicalRole One role a thing plays, naming the entity id of the player — never a local iid.
EntityState Everything about a thing that a revision covers: its type, its attributes and the roles it plays. What canonical encodes and computeRevision hashes.
canonical The canonical form. Deterministic for a given logical state and independent of the order the caller happened to collect attributes or roles in.

Deriving a revision identifier, reading one, and choosing between revisions that disagree.

Name Description
Leaf A leaf of an entity’s revision tree: a revision nothing has superseded, live or deleted.
RevisionInput What computeRevision derives a revision from.
Revision generation-digest, e.g. 2-9f86d081884c7d659a2feaa0c55ad015.
computeRevision Derives a revision from an entity’s state, its parent and whether it deletes it. The generation is the parent’s plus one (1 for the first revision), and the digest is a hash of the content, so the same edit on the same parent gives the same revision on every node.
conflicts Every leaf that is not the winner — the equivalent of CouchDB’s _conflicts.
digestOf The digest of a revision: everything after the first dash.
generationOf The generation of a revision: the number before the dash, 1 for an entity’s first revision.
latestOf The newest of a set of versioned rows, or undefined when there are none — winner()’s total order, applied to whatever a caller’s own row shape is, rather than each caller mapping to Leaf and finding its own row back by hand.
winner The winner among an entity’s leaves, per ADR-003 Decision 3. Total: live beats tombstone, then highest generation, then greatest digest. A tie at the last step would require equal digests, which by derivation means the same revision rather than two distinct ones.

TypeDBLite is an independent open-source project, built on TypeDB with thanks. It is not affiliated with, sponsored by, or endorsed by TypeDB Ltd. Released under the MPL-2.0 license.