gleamunison/namespace

Types

pub type Diff {
  Diff(
    added: List(String),
    removed: List(String),
    changed: List(String),
  )
}

Constructors

  • Diff(
      added: List(String),
      removed: List(String),
      changed: List(String),
    )

The name layer as data. A namespace maps names to definition refs; namespaces are stored content-addressed, branches are named pointers to namespace heads with a causal history chain. The branch pointer cell is the ONLY mutable datum here: namespaces and head chunks are immutable CAS.

pub type Namespace {
  Namespace(bindings: dict.Dict(String, identity.DefinitionRef))
}

Constructors

Values

pub fn branch_head(
  adapter: storage.StorageAdapter,
  branch: String,
) -> Result(#(Int, identity.DefinitionRef), String)

Current head of a branch: #(sequence number, namespace ref).

pub fn branch_pointer_ref(
  branch: String,
) -> identity.DefinitionRef
pub fn commit(
  adapter: storage.StorageAdapter,
  branch: String,
  ns: Namespace,
) -> Result(identity.DefinitionRef, String)

Point branch at ns (stored if needed), recording the causal link to the previous head. Returns the new head’s content ref.

pub fn diff(before: Namespace, after: Namespace) -> Diff
pub fn empty() -> Namespace
pub fn export_branch(
  adapter: storage.StorageAdapter,
  branch: String,
) -> Result(List(#(String, BitArray)), String)

Every chunk a branch needs to travel: content chunks first (ns snapshots and head chain, each verified by content hash), the pointer cell last (verified by parsing — its ref is name-derived, not content-derived).

pub fn get(
  ns: Namespace,
  name: String,
) -> Result(identity.DefinitionRef, Nil)
pub fn history(
  adapter: storage.StorageAdapter,
  branch: String,
) -> List(#(Int, identity.DefinitionRef))

Walk the head chain newest-first: #(seq, namespace ref) entries.

pub fn import_branch(
  adapter: storage.StorageAdapter,
  chunks: List(#(String, BitArray)),
) -> Result(Nil, String)

Import a branch chunk set. Content chunks are verified against their hash before insert; the pointer chunk must parse as a head. A tampered chunk is refused — nothing partial lands.

pub fn load(
  adapter: storage.StorageAdapter,
  ref: identity.DefinitionRef,
) -> Result(Namespace, String)
pub fn load_current(
  adapter: storage.StorageAdapter,
  branch: String,
) -> Result(Namespace, String)

Load the namespace a branch currently points at.

pub fn merge(
  a: Namespace,
  b: Namespace,
) -> Result(Namespace, List(String))

Union of two namespaces. Conflict when the same name maps to different refs on each side; agreeing bindings merge clean.

pub fn names(ns: Namespace) -> List(String)
pub fn parse_head_hexes(
  bytes: BitArray,
) -> Result(#(String, String, option.Option(String)), String)

Parse a head chunk into the refs it points at: its namespace snapshot and its predecessor (hex), so a puller can keep walking. The chunk’s own content key is included for the import set.

pub fn pointer_ref_hex(branch: String) -> String

The pointer ref as hex: the id a peer requests to start a branch pull.

pub fn remove(ns: Namespace, name: String) -> Namespace
pub fn save(
  adapter: storage.StorageAdapter,
  ns: Namespace,
) -> Result(identity.DefinitionRef, String)
pub fn set(
  ns: Namespace,
  name: String,
  ref: identity.DefinitionRef,
) -> Namespace
✨ Search Document