spacedb-sdk
The developer's whole world — one surface over the entire SpaceDB stack.
This is the crate you add. It composes spacedb-crdt,
spacedb-access,
spacedb-consistency and
spacedb-meter into a single Database: offline-first,
schema-declared per field, mID-authorized, budget-bounded, and honest about what
every operation actually achieved.
Part of SpaceDB. Dual-licensed MIT OR Apache-2.0.
[]
= "0.1"
The whole model in one page
use ;
// 1. Open an offline-first local replica for this device.
let mut db = open;
// 2. Declare a schema — each field picks its CRDT type AND its consistency tier.
db.define;
// 3. The owner grants a capability — to a person or an AI agent.
let owner = generate?;
db.register_identity?;
db.set_clock;
let cap = grant?
.with_expiry
.with_budget; // micro-$MATA it may spend
let mut session = db.session;
// 4. Write offline. Every op returns the consistency it ACTUALLY achieved.
let outcome = db.put_register?;
assert_eq!; // durable here, converging outward
db.increment?;
db.append_text?;
// 5. Read it back — honest about freshness.
let = db.read_register?;
// 6. Strong tier when you mean it: globally unique, or it cleanly refuses.
match db.claim_unique?
# Ok::
open → schema → grant → write/read with honest state → strong when you mean it. No connection string, no server, no network required.
Sync two replicas (still no server)
let bytes = laptop.export; // CRDT state, content-addressed
phone.import?; // merges; conflicts resolve by CRDT rules
Export the collection after it has been written — exporting one that has never
taken a write produces an empty update that import rejects.
React to change
let watcher = db.watch;
// ... after any local or merged write:
if watcher.drain_changed
What the SDK enforces for you
- Schema.
require_fieldrejects an op whose field wasn't declared, or was declared as a different CRDT type —claim_uniqueon a non-Strongfield is an error, not a silent downgrade. - Authorization. Every op runs through the
spacedb-accesschokepoint with the session's capability. No capability, no write. - Budget. Each mutating op is charged at
write_cost(); a session that exhausts its budget stops rather than overdrawing.session.budget_remaining()reports it. - Honesty.
Outcome(Local/Committed{tier}/Stale{lag}/Unavailable{reason}) andStrongResultcome back from every op. Nothing is reported as durable that isn't. - Revocation.
db.revoke(capability_id)cuts off the bearer and everything delegated beneath it.
quorum_partition / quorum_heal let a test take strong-tier members offline
and prove the group fails safe instead of splitting.
Testing
The workspace defaults to wasm32; this crate is native. Test on your host
triple:
Suite: sdk.rs — the end-to-end developer path above.
License
MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.