rhizome-node/spec.md

4.3 KiB

  • A delta is an immutable atomic unit that relates one or more values in semantically meaningful ways as of some point in time. A delta can be thought of as both a CRDT and as a hyper-edge in the implicit hypergraph that makes up the rhizome. A delta contains one or more pointers.
  • A pointer is composed of at least two and possibly three fields. A delta contains a set of pointers. The fields of a pointer are:
    • name - identifies the meaning of the pointer from the perspective of the delta that contains it.
    • target - identifies a value to associate with the name.
    • context - optionally, when pointing at an object, the context identifies the field or property of that object with which this delta is associated.
  • A value is one of two kinds of primitive that can be referred to by a delta:
    • a reference is a UUID or other value understood to be pointing at either a delta or an object.
    • a primitive is a literal string, number or boolean value whose meaning is not tied up in its being a reference to a larger whole.
  • An object is a composite object whose entire existence is encoded as the set of deltas that reference it. An object is identified by a unique reference, and every delta that includes that reference is asserting a claim about some property of that object.
  • A negation is a specific kind of delta that includes a pointer with the name negates, a target reference to another delta, and a context called negated_by.
  • a schema represents a template by which an object can be compiled into a lossless view. A schema specifies which properties of that object are included, and it specifies schemas for the objects references by the deltas within those properties. A schema must terminate in primitive schemas to avoid an infinite regress.
    • For instance, a lossless view "User" of a user may include references to friends. If those friends are in turn encoded as instances of the "User" schema then all of their friends would be fully encoded, etc.
    • This could lead to circular references and arbitrarily deep nesting, which runs into the problem of "returning the entire graph". So our schema should specify, for instance, that the "friends" field apply the "Summary" schema to referenced users rather than the "User" schema, where the "Summary" schema simply resolves to username and photo.
  • A lossless view is a representation of an object that includes a full inventory of all of the deltas that compose that object. So for instance, a lossless view of the object representing the user "Alice" might include alice.name, which contains an array of all deltas with a pointer whose target is the ID of Alice and whose context is name. Such deltas would likely include a second pointer with the name name and the target a primitive string "Alice", for instance.
    • A lossless view may also include nested delta/object layering. Consider alice.friends, which would include all deltas asserting friendship between Alice and some other person. Each such delta would reference a different friend object. In a lossless view, these references would be expanded to contain lossless views of those friends. Schemas, as defined above, would be applied to constrain tree depth and avoid infinite regress.
  • A lossy view is a compression of a lossless view that removes delta information and flattens the structure into a standard domain object, typically in JSON. So instead of alice.name resolving to a list of deltas that assert the object's name it might simply resolve to "alice".
    • Note that in a lossless view any property of an object necessarily resolves to a set of deltas, even if it's an empty set, because we cannot anticipate how many deltas exist that assert values on that context.
  • In collapsing a lossless view into a lossy view we may specify resolution strategies on each field of the schema. A resolution strategy takes as input the set of all deltas targeting that context and returns as output the value in the lossy view. So if we have 15 deltas asserting the value for an object's name, our resolution strategy may simply say "return the target of the name pointer associated with the most recent delta", or it may say "return an array of names". If the value is numeric it may say "take the max" or "take the min" or "take the average".