silt

silt / reference

silt/rest

The response shapes that expose git objects as git-compatible content-addressable storage over a REST API: JSON and URL builders for blob, tree, commit, ref, and commit-history responses. Owns no store — it takes a fetch when it must walk children.

import
import silt/rest

The fetch contract

type

Fetch

also on silt #
pub type Fetch =
  fn(String) -> Result(String, Nil)

Resolve an object body by its SHA. You supply it, closing over your own store and tenant, so response shaping stays backend-agnostic — silt never touches persistence itself.

Only the responses that walk children — recursive trees and commit history — ever call it. Flat responses ignore it.

Object responses

fn

object_response

also on silt #
pub fn object_response(
  base_url: String,
  tenant: String,
  kind: String,
  sha: String,
  body: String,
  recursive: Bool,
  fetch: Fetch,
) -> Result(json.Json, Nil)

Build the REST response for a stored object of kind ("blobs", "trees", or "commits"). Each response carries the object's sha, a canonical url, and the decoded fields for its kind.

When recursive is True, a tree response walks its children through fetch and flattens them with prefixed paths. An unknown kind is an Error(Nil).

fn

commit_details_response

#
pub fn commit_details_response(
  base_url: String,
  tenant: String,
  sha: String,
  body: String,
) -> Result(json.Json, Nil)

Build the detailed commit response for a single commit body — the nested commit object (author, committer, message, tree) the history endpoint returns per entry.

fn

commit_history_response

#
pub fn commit_history_response(
  base_url: String,
  tenant: String,
  sha: String,
  count: Int,
  fetch: Fetch,
) -> List(json.Json)

Walk first parents from sha, up to count commits, resolving each through fetch — the commit-history endpoint. Stops early at the root or when a body can't be resolved.

Refs

fn

ref_response

also on silt #
pub fn ref_response(
  base_url: String,
  tenant: String,
  ref: String,
  sha: String,
) -> json.Json

Build a ref response for ref pointing at commit sha — the ref name, its url, and the target commit object. The ref is normalized to its fully-qualified form first.

fn

normalize_ref

#
pub fn normalize_ref(ref: String) -> String

Normalize a ref to its fully-qualified refs/… form — a bare "heads/main" becomes "refs/heads/main", and an already-qualified ref is returned unchanged.