bijection client kotlin generates a typed package from the app’s contract;
it depends on the runtime com.bijection:client-kotlin.
Install
Add the runtime and your generated package to the build:build.gradle.kts
kotlinx-coroutines-core and nothing else.
Generate a client
bijection.lock and refuses when its
contract line differs from the source’s: run bijection check --write-lock
and commit the lock first. The package holds:
Regenerate whenever the lock changes.
Connect
token is a fixed credential; pass tokenSource instead to be asked on every
request (TokenSource { refresh -> session.token(refresh) }). Leave both out to
call anonymously. The generated connect pins CONTRACT. An installation whose
contract differs refuses every call with Conflict, and the message starts
with ContractStale.
For a dynamic tool, pass ConnectOptions(discover = true) to the raw connector. A pinned client refuses a path absent from its contract map before sending it.
Calls
App.orders.place is place in the
orders module. A function without arguments takes Unit.
mutate takes once, the identity of one logical mutation. The same once and
arguments answer the original result; the same once with other arguments
refuses Invalid. Without one, the client mints one for the call. A result
Unknown means it may have happened: ask again with the same once.
An uncertain mutation carries its original request key in Refusal.once.
Frames
Each frame method returns a new client; the original is unchanged and both share one connection.
A committed mutation’s result carries its
version. Pass it as seen to read
your own write:
Results
Every call answers aResult: Result.Ok(value, version) or
Result.Refusal(code, message, guard). It never throws for a refusal.
code is one of the twelve host codes (HostCode.UNKNOWN, DISALLOWED,
FORBIDDEN, INVALID, ABSENT, EXISTS, CONFLICT, ERASED, EXPIRED,
WITHDRAWN, LIMIT, FAILED) or one of the codes the function declares in
refuses, exactly as it refused. Any other code from the host is folded into
its host code, with the original code as reason. A host code’s reason is
its precise cause (BudgetExhausted under Limit), or null; message never
starts with the code or the reason. On Forbidden, guard is the path of the
guard that refused.
Watch
watch returns a Flow of results: the current value, then each change. The
watch stops when collection ends.
in or at answers once. The JVM opens an HTTP event stream.
On Android, pass a LiveFactory over your HTTP library as ConnectOptions(live = ...).
Trial
trial runs a call in a discarded world and commits nothing:
trial.result is how the call would have ended; a guard’s refusal carries
guard. trial.validUntil is the instant the answer is valid until (a call at
the same version committed before it is decided the same way), or null when
nothing time-dependent bounds it.
Values
Change entries
A query returningselection.changes answers List<Change<Fact>>. Each
Change has key, before (null on an insert), after (null on a delete) and
version.
Android
An Android app uses the samecom.bijection:client-kotlin and the generated
connect. Calls go over HttpURLConnection; give watches a LiveFactory
(see Watch).
AuthProvider<T> and pass
SignIn(provider) as tokenSource; login, loginFromCache, logout and
authState drive it. A provider that shows UI holds its own Activity.
SignIn answers kotlin.Result; the client’s own result type is
com.bijection.client.Result, so qualify one of them where both are in
scope.