Docs

registry

Source: crates/lvcs-doc/src/kinds/registry/mod.rs.

/// One workspace as the registry lists it: what `ws.fork` created it with,
/// every input of its id ([`WorkspaceId::of`]) but its creator, who signs
/// the entry. A workspace whose name another entry also has mirrors to
/// `.lvcs/ws/<name>-<first 6 characters of its id>/` (design §8).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WorkspaceEntry {
    pub name: String,
    pub base: WorkspaceBase,
    pub subtree: Option<String>,
    /// The forking request's `Origin.time_ms`, an input of the workspace id.
    pub created_ms: i64,
    /// The base's visible frontier id when the workspace was forked, an
    /// input of the workspace id (decisions 57 and 112).
    #[serde(with = "crate::cbor::fixed")]
    pub base_frontier: [u8; 32],
}

/// A merge record as the registry stores it: the canonical CBOR encoding
/// of an `lvcs_ws::merge::MergeRecord`, opaque here so `lvcs-doc` stays
/// independent of `lvcs-ws`, except for what a record's change is checked
/// against, which `lvcs-doc` reads from the record's `bundle`, `inputs`,
/// and `docs`: the change is authorized by `Write` on every document it
/// lists (decision 108), the keys of `docs`, the address of each; and it
/// is written only at the record's own key, by its merger: `bundle` is
/// its key in `/bundles` and the id of `inputs` ([`BundleId::of`]), and
/// `inputs.merger` signs the change. Serializes as a byte string.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct EncodedRecord(#[serde(with = "crate::cbor::bytes")] pub Vec<u8>);

/// The registry as its document holds it.
///
/// Layout: the genesis operations put `/workspaces` and `/bundles` as maps,
/// in that order, so every peer writes into the same two objects. A
/// workspace is the key `/workspaces/<ws-id>`, a map holding `name`, `base`
/// (`main`, or the base workspace id), and `subtree` (when there is one) as
/// strings, `created_ms` as an integer, and `base_frontier` as a 32-byte
/// byte string; a bundle is the key `/bundles/<bundle-id>`, holding its
/// [`EncodedRecord`] as a byte string. Ids in keys and values are in
/// `ID_ENCODING`. Each key is written once, by the peer that created the
/// workspace or merged the bundle: sync and the audit refuse a change that
/// writes a key holding a value at the change's dependencies, whatever
/// predecessors it names. A bundle's key is its merger's alone (see
/// [`EncodedRecord`]), and a workspace entry's key its creator's: sync and
/// the audit accept an entry only under the key
/// `WorkspaceId::of(name, signer, base_frontier, created_ms)` of its own
/// fields and its change's signer (decision 112), in a change that writes
/// nothing else, so an entry written at older dependencies, without seeing
/// an earlier one, names a workspace of its own signer's and never stands
/// beside another participant's.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Registry {
    pub workspaces: BTreeMap<WorkspaceId, WorkspaceEntry>,
    pub bundles: BTreeMap<BundleId, EncodedRecord>,
}

/// Record a new workspace (design §8), sent once by the forking daemon,
/// committed by `origin.author` at `origin.time_ms / 1000` seconds on the
/// live document, and signed by the workspace's creator: `id` is the
/// [`WorkspaceId::of`] the entry's fields and its creator's key, the only
/// key a peer accepts the entry at (decision 112). A registry that already
/// lists the id ignores it: each key is written once.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RegisterWorkspace {
    pub origin: Origin,
    pub id: WorkspaceId,
    pub entry: WorkspaceEntry,
}

/// Record a merge bundle's merge record (decision 48), sent once by the
/// merging workspace actor after every change of the bundle is applied,
/// committed by `origin.author` at `origin.time_ms / 1000` seconds on the
/// live document. Signed like every change (ChangeSig, M3), by the record's
/// merger (`inputs.merger`), the only signer whose record change a peer
/// accepts at `bundle`. A registry that already holds the bundle's record
/// ignores it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RecordBundle {
    pub origin: Origin,
    pub bundle: BundleId,
    pub record: EncodedRecord,
}

/// The registry document's state at `heads`, emitted after every applied
/// change and on `Render`. An entry whose id or fields are malformed is
/// left out.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RegistryRendered {
    #[serde(with = "crate::cbor::heads")]
    pub heads: Vec<ChangeHash>,
    pub registry: Registry,
}