Capabilities
Reference for requirements and layer composition
Declaration and Access
import { Context } from "vibelang/context"
abstract class Service extends Context {
abstract operation(input: Input): Result<Output, ServiceError>
}
function run(): Result<Output, ServiceError> {
const service = Service.context()
return service.operation(input)
}The abstract class is both the service contract and nominal capability identity. Service.context() returns its instance and adds Service to the enclosing function's inferred requirement channel.
Multiple Requirements
function run() {
const db = Database.context()
const clock = Clock.context()
const log = Logger.context()
}The requirement set is Database | Clock | Logger; duplicate nominal identities collapse.
Layer Type
Layer<Provides, InitError, Requires>| Parameter | Meaning |
|---|---|
Provides | capabilities made available by the Layer |
InitError | Error union returned by acquisition |
Requires | capabilities needed to acquire the Layer |
Constructors
Layer.succeed(Service, implementation)
Layer.merge(left, right, ...rest)
Layer.provide(layer, callback)These names are API direction, not a stable published surface.
Composition Rules
mergeunions provided capabilities and acquisition Errors.- construction requirements propagate until another Layer satisfies them.
provideremoves satisfied requirements from the callback's requirement set.- acquisition Result errors enter the provided callback's Result contract.
- a missing capability is a compile error when the closure is statically known.
Provider composition is a library API from vibelang/provider; there is no special provider statement syntax.
Platform Services
Planned standard capabilities include FileSystem, HttpClient, Clock, Random, Environment, and Console. Targets provide live implementations; tests supply deterministic ones.
Open Lifecycle Semantics
Scoped acquisition/disposal, sharing, override precedence, cycle diagnostics, asynchronous acquisition, and finalizer failure policy remain to be specified.