Skip to main content

Module value

Module value 

Source
Expand description

The atproto data model: the values a record is made of.

atproto’s data model is the IPLD data model minus everything that would make a value ambiguous. There are no floats, no undefined, no maps keyed by anything but a string, and two kinds of value that JSON cannot hold at all — byte strings and links — which the JSON representation carries as one-key objects, $bytes and $link.

Value is that model, and the point of parsing into it rather than working from serde_json::Value directly is that it can only hold values that have an encoding. A f64 that is not an integer has nowhere to live here; a $link that is not a CID cannot be built. Everything that could fail fails in Value::from_json, which is why encode cannot.

§What is checked, and why more than a shape

Three of the model’s constructs are tagged: an object whose keys are exactly $link, exactly $bytes, or whose $type is blob. Each is checked whole rather than field by field, including refusing keys beyond the ones the construct defines. An object carrying $link alongside anything else is not a link with an extra field, it is a value with two readings — a link to one implementation and a plain object to another — and the upstream vectors refuse it for that reason.

This is deliberately the opposite posture to record validation, which preserves fields it does not recognise so that a newer client can write through an older server. The two do not conflict: a lexicon’s properties are an open set that grows, and these three constructs are closed shapes defined by the protocol itself. A $link with a second key is not a newer kind of link.

Structs§

DataError
Where in a value a problem was found, and what it was.

Enums§

ErrorKind
What was wrong at one point in a value.
Value
A value in the atproto data model.

Constants§

BLOB_KEYS 🔒
The four keys a blob has, and no others.
BLOB_TYPE
The $type that marks a blob rather than a record.
BYTES_KEY
The key naming a byte string in the JSON representation.
LINK_KEY
The key naming a link in the JSON representation.
TYPE_KEY
The key naming a value’s schema type.

Functions§

field 🔒
Extends a path with a map key.
index 🔒
Extends a path with a list index.
json_type 🔒
Names a JSON value’s type, for the top-level error message.
parse_blob 🔒
Parses {"$type": "blob", "ref": ..., "mimeType": ..., "size": ...}.
parse_bytes 🔒
Parses {"$bytes": "..."}.
parse_link 🔒
Parses {"$link": "..."}, and nothing that merely contains a $link.
parse_number 🔒
Parses a JSON number, which is an integer here or it is nothing.
parse_object 🔒
Parses a JSON object: a link, a byte string, a blob, or a plain map.