Repository navigation
somnia v0.8.0
Completes the P3 roadmap tier: typed authentication, live queries, full-text /
vector search helpers, and SurrealDB 3.x type-system surface (closures,
REFERENCEs, union / literal types). Two small breaking changes: a new
SomniaError::Auth variant (breaks exhaustive matches on SomniaError), and
DefineIndex::search() / #[index(search = …)] now emit FULLTEXT ANALYZER …
instead of the pre-3.x SEARCH ANALYZER … (changed output, same API). Bump your
dependency to somnia = "0.8".
Added
-
Authentication (P3). The client grows a typed auth surface beyond
root-only signin. ACredentialsenum (Root/Namespace/Database/
Token, each with an ergonomic constructor) drives the new
SomniaClient::connect_with(endpoint, ns, db, creds), and
connect_anonymous(endpoint, ns, db)connects without signing in (for
embedded engines or deferred auth). On an existing connection:
signin(&creds), record/scope auth viasignin_record/signup_record
(params are anySerializevalue, flattened into the access method's
$params),authenticate(token)to attach a pre-issued JWT, and
invalidate()to clear the session. Signin/signup/record calls return the
issued access token. Auth failures surface as a newSomniaError::Auth
variant. Verified end-to-end against the live in-memory engine (record
signup → signin → invalidate, wrong-password rejection). -
Live queries (P3).
SomniaClient::live_select::<T>()starts aLIVE SELECTonT's table and returns aLiveQueryStream<T>— afutures
StreamofNotification<T>carrying the changeAction
(Create/Update/Delete), the originatingquery_id, and the deserialized
record. Dropping the stream issuesKILLserver-side (no explicit teardown).
Works on the embedded (mem://) engine and overws://. Verified live
(create → update → delete notifications with the decoded record). -
Vector / full-text query helpers (P3).
Table::search(field, query) → Search<T>builds full-textWHERE field @@ 'query'selects with optional
search::scoreprojection / relevance ordering;Table::nearest(field, vec) → VectorSearch<T>builds vector KNN selects (<|k,ef|>HNSW or<|k,METRIC|>
brute force) withvector::distance::knn()projection / nearest-first
ordering. New composable expression nodesMatchesExpr(@@) andKnnExpr
(<|…|>), plusColumn::matches. Both renderto_surrealql[_with_params]and
are verified live (ranked full-text search, HNSW nearest-neighbour ordering). -
SurrealDB 3.x type-system (P3). A typed
Closureexpression node renders
anonymous functions (|$x: int| -> int $x * 2) for higher-order calls /
computed values. The derive gains#[field(reference)]/
#[field(reference = "cascade")]to emit recordREFERENCE [ON DELETE …].
Union (#[field(ty = "int | string")]) and literal
(#[field(ty = "'a' | 'b'")]) field types are confirmed end-to-end.future<T>
is intentionally omitted — the keyword no longer exists in SurrealDB 3.x.
Changed
-
(Fix)
DefineIndex::search()/#[index(search = …)]now emitFULLTEXT ANALYZER …instead of the pre-3.xSEARCH ANALYZER …, which SurrealDB 3.x
rejects as a parse error. The method/attribute names are unchanged; only the
emitted keyword. Needed for the new full-text query helpers to run against a
real index. -
README — expanded the terse "More query power" block into descriptive,
per-feature sections (Parameters &LET, Transactions, Subqueries &IN,
SELECTmodifiers, Control flow, advanced schema DDL, graph edges), each with a
worked sample and the rendered SurrealQL shown inline.