lightspeed/data/repository
Scoped data-access patterns with Gleam/Elixir interoperability adapters.
Types
Scoped access failures for authz-sensitive flows.
pub type AccessError {
NotFound(id: String)
Forbidden(actor_id: String, action: String, tenant_id: String)
}
Constructors
-
NotFound(id: String) -
Forbidden(actor_id: String, action: String, tenant_id: String)
Storage adapter profile used by one repository boundary.
pub type Adapter {
GleamInMemory
ElixirBridge(module: String)
MixedBridge(read_module: String, write_module: String)
}
Constructors
-
GleamInMemory -
ElixirBridge(module: String) -
MixedBridge(read_module: String, write_module: String)
One domain record persisted in a repository.
pub type Record {
Record(
id: String,
tenant_id: String,
owner_id: String,
resource: String,
payload: String,
)
}
Constructors
-
Record( id: String, tenant_id: String, owner_id: String, resource: String, payload: String, )
Repository
opaqueDeterministic repository state.
pub opaque type Repository
Tenant-scoped role for data access policies.
pub type Role {
Viewer
Editor
TenantAdmin
}
Constructors
-
Viewer -
Editor -
TenantAdmin
Values
pub fn adapter_label(adapter: Adapter) -> String
Stable adapter label for fixtures and migration signatures.
pub fn delete_by_id(
repository: Repository,
scope: Scope,
id: String,
) -> Result(Repository, AccessError)
Delete one row by id with scope validation.
pub fn fetch_by_id(
repository: Repository,
scope: Scope,
id: String,
) -> Result(Record, AccessError)
Fetch one row by id with scope validation.
pub fn list_by_tenant(
repository: Repository,
scope: Scope,
tenant_id: String,
) -> Result(List(Record), AccessError)
List rows by tenant with scope validation.
pub fn seed(adapter: Adapter, rows: List(Record)) -> Repository
Build repository with seeded records.
pub fn tenant_scope(
actor_id: String,
tenant_id: String,
role: Role,
) -> Scope
Build a tenant-scoped actor identity.
pub fn upsert(
repository: Repository,
scope: Scope,
row: Record,
) -> Result(Repository, AccessError)
Upsert one row with scope validation.