Expand description
§kovlet
Kovlet’s portable sync client core (ADR 0017): sign-in, the WebSocket
session and catch-up, the per-field LWW merge, the outbox and acks,
reconnects, files and the app-scoped spaces API, for Rust and Tauri apps
directly, and for Swift and Kotlin through UniFFI (kovlet-ffi).
The app’s database stays the source of truth: implement store::DataStore
(one method, apply) or use the built-in store, and the core keeps only
its bookkeeping (clocks, outbox, cursor) in a store::SyncStore.
use kovlet::{col, Client, SignIn, Tables};
let kovlet = Client::builder("Todos").data_dir("/tmp/todos").build()?;
if !kovlet.signed_in() {
kovlet.sign_in(SignIn::device(|c| println!("Open {} and enter {}", c.verification_uri, c.user_code))).await?;
}
let space_id = kovlet.spaces().find_or_create("Todos").await?.id;
let space = kovlet.open_builtin(&space_id, Tables::new().table("todos", [("title", col::string()), ("done", col::boolean())]))?;
space.write("todos").upsert("t1", serde_json::json!({ "title": "Buy milk", "done": false }))?;
let mut status = kovlet.watch_status();
while status.changed().await.is_ok() { println!("{:?}", status.borrow().state); }Re-exports§
pub use auth::key::DeviceKey;pub use auth::key::KeyProvider;pub use auth::key::SoftwareKey;pub use auth::key::SoftwareKeyProvider;pub use auth::secrets::FileSecretStore;pub use auth::secrets::MemorySecretStore;pub use auth::secrets::SecretStore;pub use auth::DeviceCode;pub use auth::EndUser;pub use auth::EndUserOAuthRequest;pub use auth::EndUserSession;pub use auth::EndUserSignIn;pub use auth::PkceRequest;pub use auth::Session;pub use auth::SignIn;pub use engine::Blocked;pub use engine::Event;pub use engine::SpaceStatus;pub use engine::SubscriptionStatus;pub use engine::SyncState;pub use error::Error;pub use error::Result;pub use query::QueryResult;pub use schema::col;pub use schema::Tables;pub use store::Change;pub use store::ChangeBatch;pub use store::DataStore;pub use store::Origin;pub use store::Row;pub use serde_json;
Modules§
- auth
- Sign-in, session persistence and serialized refresh (PROTOCOL.md §2.2–2.7, ADR 0018).
- engine
- The sync engine: per-space merge state (
target) and the WebSocket sessions. - error
- One error type for the whole core. Every error carries a protocol-style
code(PROTOCOL.md §12, plus a few client-side codes), a message, and, where the server sent them,detailsand ahint. - hlc
- Hybrid logical clocks (PROTOCOL.md §5).
- protocol
- The wire format (PROTOCOL.md §4, and §17 for protocol 2): hand-written
serde types, checked against the shared golden fixtures
(
packages/protocol/testdata/frames). - query
- The query language (ADR 0021 §4, PROTOCOL.md §17.5): a JSON tree like InstantDB’s InstaQL.
- schema
- Declaring tables (
hello.schema):Tables::new().table("todos", [("title", col::string()), ("done", col::boolean())]). - spaces
- The app-scoped spaces API (PROTOCOL.md §2.8, ADR 0019): list, create, find-or-create, and grant requests for more spaces without signing in again.
- sqlite
- The SQLite store (feature
sqlite). - store
- The storage seams of ADR 0017 §2: the app owns values, Kovlet owns clocks.
- testing
kovlet::testing: checks that an app’sDataStoremeets the contract of ADR 0017 §2, without a server.- transport
- The
Transportseam (ADR 0017 §1): HTTP requests and one WebSocket.
Structs§
- Client
- A Kovlet client. Cheap to clone; every method is thread-safe.
- Client
Builder - Builds a
Client. - EndUser
Config GET /v1/eu/{space}/config: whether sign-in is on for this app, and how.- EndUser
Provider - A sign-in method the owner configured (
kind:email,oauthorid_token). - EndUsers
- End-user sign-in for one Data Space and app (
Client::end_users). - Files
space.files().- Live
Query - A query subscription (
Space::subscribe). Cheap to clone; dropping it keeps the subscription (it persists untilLiveQuery::unsubscribe). - Mirror
- A running file mirror. Cheap to clone; stops when the last clone is dropped.
- Mirror
Status - What a
Mirroris doing. - Space
- A handle to an open space. Cheap to clone.
- Status
- The client’s status: one shape on every platform.
- Subscription
- Unsubscribes when dropped.
- Sync
Summary - What
sync_oncedid. - Table
Reader space.table("todos"): reads from the built-in store.- Table
Writer space.write("todos").- Transaction
- An atomic batch (
Space::transact).
Enums§
- Local
Write - One write for
Space::queue. - Space
Store - Which store a space syncs into.
Constants§
- DEFAULT_
API_ URL - The hosted API (BORG-96): the default base URL.
- DEFAULT_
CONSOLE_ URL - The hosted console: consent,
/activate.