gleamunison/codebase

Types

pub opaque type Codebase
pub type InsertError {
  HashMismatch(
    hash_expected: identity.Hash,
    hash_got: identity.Hash,
  )
  DuplicateDef(
    existing: identity.DefinitionRef,
    incoming: identity.DefinitionRef,
  )
  StorageFailure(storage.StorageError)
}

Constructors

pub type ReadError {
  NotFound(identity.DefinitionRef)
  StoreFailure(storage.StorageError)
  Corrupt(ref: identity.DefinitionRef, reason: String)
  DecodeFailed(ref: identity.DefinitionRef, reason: String)
}

Constructors

Values

pub fn describe_insert_error(error: InsertError) -> String

The one place an InsertError becomes a user sentence. Rendering belongs here, with the type, rather than at each call site — inspect output is a debug rendering and must never reach a user.

pub fn describe_read_error(error: ReadError) -> String

The one place a ReadError becomes a user sentence. Same rule as describe_insert_error: rendering belongs with the type, and inspect output must never reach a user. NotFound carries no sentence here — callers with a “missing” vocabulary of their own name it there.

pub fn empty() -> Codebase
pub fn get(
  codebase: Codebase,
  ref: identity.DefinitionRef,
) -> Result(ast.Definition, ReadError)

The read half of the store. Identity is the ref, so a stored payload is re-verified before it is decoded: a store that disagrees with its own keys must not be able to hand a different definition to the loader.

pub fn get_adapter(codebase: Codebase) -> storage.StorageAdapter
pub fn hash_of_definition(def: ast.Definition) -> identity.Hash
pub fn insert(
  codebase: Codebase,
  unit: ast.Unit,
) -> Result(Codebase, InsertError)
pub fn insert_raw_checked(
  codebase: Codebase,
  ref: identity.DefinitionRef,
  bytes: BitArray,
) -> Result(Codebase, InsertError)
pub fn with_adapter(adapter: storage.StorageAdapter) -> Codebase

A codebase over a caller-chosen adapter (dets for persistence, mnesia for replication). Sync and CLI paths need real storage, not inmemory.

✨ Search Document