pub struct Store { /* private fields */ }Expand description
The embedded store: a thin typed repository over an embedded SurrealDB instance. Cloning
yields another handle to the same database (the inner client is a shared handle).
Implementations§
Source§impl Store
impl Store
Sourcepub async fn open(path: &Path) -> Res<Self>
pub async fn open(path: &Path) -> Res<Self>
Opens (or creates) a persistent store rooted at path using the SurrealKV backend.
§Errors
Returns an error if the backend cannot be opened or the schema cannot be applied.
Sourcepub async fn open_in_memory() -> Res<Self>
pub async fn open_in_memory() -> Res<Self>
Opens an ephemeral in-memory store (for tests).
§Errors
Returns an error if the in-memory backend cannot be initialized.
Sourcepub async fn create_user(&self, username: &str) -> Res<UserRecord>
pub async fn create_user(&self, username: &str) -> Res<UserRecord>
Creates a user, enforcing the unique-username constraint.
§Errors
Returns an error if the username is already taken or the write fails.
Sourcepub async fn create_machine(
&self,
user: &str,
name: &str,
pubkey_base64: &str,
) -> Res<MachineRecord>
pub async fn create_machine( &self, user: &str, name: &str, pubkey_base64: &str, ) -> Res<MachineRecord>
Enrolls a machine, enforcing the globally-unique pubkey and per-user-unique name constraints.
§Errors
Returns an error if the pubkey is already enrolled, the name collides within the user, or the write fails.
Sourcepub async fn get_machine_by_pubkey(
&self,
pubkey_base64: &str,
) -> Res<Option<MachineRecord>>
pub async fn get_machine_by_pubkey( &self, pubkey_base64: &str, ) -> Res<Option<MachineRecord>>
Sourcepub async fn list_machines(&self, user: &str) -> Res<Vec<MachineRecord>>
pub async fn list_machines(&self, user: &str) -> Res<Vec<MachineRecord>>
Sourcepub async fn delete_machine(&self, user: &str, name: &str) -> Void
pub async fn delete_machine(&self, user: &str, name: &str) -> Void
Sourcepub async fn create_channel(
&self,
name: &str,
visibility: Visibility,
created_by: &str,
) -> Res<ChannelRecord>
pub async fn create_channel( &self, name: &str, visibility: Visibility, created_by: &str, ) -> Res<ChannelRecord>
Creates a channel, enforcing the unique-name constraint.
§Errors
Returns an error if the name is already taken or the write fails.
Sourcepub async fn get_channel(&self, name: &str) -> Res<Option<ChannelRecord>>
pub async fn get_channel(&self, name: &str) -> Res<Option<ChannelRecord>>
Sourcepub async fn create_invite(
&self,
channel: &str,
token: &str,
uses_remaining: Option<i64>,
expires_at: Option<String>,
created_by: &str,
) -> Res<InviteRecord>
pub async fn create_invite( &self, channel: &str, token: &str, uses_remaining: Option<i64>, expires_at: Option<String>, created_by: &str, ) -> Res<InviteRecord>
Creates an invite token, enforcing the unique-token constraint.
§Errors
Returns an error if the token already exists or the write fails.
Sourcepub async fn get_invite(&self, token: &str) -> Res<Option<InviteRecord>>
pub async fn get_invite(&self, token: &str) -> Res<Option<InviteRecord>>
Sourcepub async fn list_invites(&self, channel: &str) -> Res<Vec<InviteRecord>>
pub async fn list_invites(&self, channel: &str) -> Res<Vec<InviteRecord>>
The outstanding invites for one channel (the channel-admin audit view).
§Errors
Returns an error if the query fails.
Sourcepub async fn list_channels(&self) -> Res<Vec<ChannelRecord>>
pub async fn list_channels(&self) -> Res<Vec<ChannelRecord>>
Lists every channel; the caller applies visibility / membership gating (DESIGN.md §6).
§Errors
Returns an error if the query fails.
Sourcepub async fn add_channel_member(&self, channel: &str, user: &str) -> Void
pub async fn add_channel_member(&self, channel: &str, user: &str) -> Void
Adds user to a channel’s membership (its ACL), idempotently. Each membership is its own
record under the unique (channel, user) index, so concurrent adds of different users write
distinct keys and never contend on a shared row (PRD-0007 T-003); a conflict on the same pair
is retried per SurrealDB’s optimistic-concurrency contract.
§Errors
Returns an error if the write keeps conflicting past the retry cap or otherwise fails.
Sourcepub async fn remove_channel_member(&self, channel: &str, user: &str) -> Void
pub async fn remove_channel_member(&self, channel: &str, user: &str) -> Void
Removes user from a channel’s membership; idempotent (removing a non-member is a no-op).
§Errors
Returns an error if the delete keeps conflicting past the retry cap or otherwise fails.
Sourcepub async fn list_user_memberships(&self, user: &str) -> Res<Vec<String>>
pub async fn list_user_memberships(&self, user: &str) -> Res<Vec<String>>
The channels user is a member of (for discovery gating, DESIGN.md §6).
§Errors
Returns an error if the query fails.
Sourcepub async fn add_ban(&self, channel: &str, user: &str) -> Void
pub async fn add_ban(&self, channel: &str, user: &str) -> Void
Records a channel ban for user; idempotent (banning twice is a no-op). Durable so bans
survive a server restart; the hub mirrors them in memory for its lock-guarded checks.
§Errors
Returns an error if the insert keeps conflicting past the retry cap or otherwise fails.
Sourcepub async fn remove_ban(&self, channel: &str, user: &str) -> Void
pub async fn remove_ban(&self, channel: &str, user: &str) -> Void
Lifts a channel ban; idempotent (removing an absent ban is a no-op).
§Errors
Returns an error if the delete keeps conflicting past the retry cap or otherwise fails.
Sourcepub async fn list_bans(&self) -> Res<Vec<(String, String)>>
pub async fn list_bans(&self) -> Res<Vec<(String, String)>>
Every persisted (channel, user) ban, for loading the hub’s in-memory view at startup.
§Errors
Returns an error if the query fails.
Sourcepub async fn list_channel_bans(&self, channel: &str) -> Res<Vec<String>>
pub async fn list_channel_bans(&self, channel: &str) -> Res<Vec<String>>
The users banned from one channel (the channel-admin audit view).
§Errors
Returns an error if the query fails.
Sourcepub async fn list_channels_created_by(&self, user: &str) -> Res<Vec<String>>
pub async fn list_channels_created_by(&self, user: &str) -> Res<Vec<String>>
The names of the channels created (and administered) by user.
§Errors
Returns an error if the query fails.
Sourcepub async fn delete_user_memberships(&self, user: &str) -> Void
pub async fn delete_user_memberships(&self, user: &str) -> Void
Removes every membership held by user (used when a user is removed, DESIGN.md §7).
§Errors
Returns an error if the delete fails.
Sourcepub async fn set_channel_visibility(
&self,
name: &str,
visibility: Visibility,
) -> Void
pub async fn set_channel_visibility( &self, name: &str, visibility: Visibility, ) -> Void
Sourcepub async fn rename_channel(&self, old: &str, new: &str) -> Void
pub async fn rename_channel(&self, old: &str, new: &str) -> Void
Renames a channel, enforcing the unique-name constraint on the new name.
§Errors
Returns an error if the new name is already taken or the update fails.
Sourcepub async fn delete_channel(&self, name: &str) -> Void
pub async fn delete_channel(&self, name: &str) -> Void
Sourcepub async fn set_invite_uses(&self, token: &str, uses_remaining: i64) -> Void
pub async fn set_invite_uses(&self, token: &str, uses_remaining: i64) -> Void
Sets an invite’s remaining redemptions (used when redeeming a limited-use token).
§Errors
Returns an error if the update fails.
Sourcepub async fn try_consume_invite_use(&self, token: &str) -> Res<bool>
pub async fn try_consume_invite_use(&self, token: &str) -> Res<bool>
Atomically consumes one redemption of a limited-use invite: decrements uses_remaining only
while it is positive, returning whether a use was claimed. The guarded single-statement update
(retried on an optimistic-concurrency conflict) makes concurrent redeemers of the last use
mutually exclusive, so a single-use token admits exactly one (PRD-0007 T-003). The caller
handles unlimited (None) tokens and expiry; an exhausted token is deleted.
§Errors
Returns an error if the update keeps conflicting past the retry cap or otherwise fails.
Sourcepub async fn delete_invite(&self, token: &str) -> Void
pub async fn delete_invite(&self, token: &str) -> Void
Deletes an invite token (on revoke or when an exhausted token is redeemed).
§Errors
Returns an error if the delete fails.
Sourcepub async fn list_users(&self) -> Res<Vec<UserRecord>>
pub async fn list_users(&self) -> Res<Vec<UserRecord>>
Sourcepub async fn delete_user(&self, username: &str) -> Void
pub async fn delete_user(&self, username: &str) -> Void
Deletes a user (server-admin user remove); the caller also revokes the user’s machines.
§Errors
Returns an error if the delete fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Store
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
impl UnwindSafe for Store
Blanket Implementations§
impl<T> AsyncFriendly for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request