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 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 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 load(
  adapter: storage.StorageAdapter,
  ref: identity.DefinitionRef,
) -> Result(Namespace, String)
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 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