The records API is the primary surface for working with collections. Every hook and provider on this page is imported fromDocumentation Index
Fetch the complete documentation index at: https://docs.deep.space/llms.txt
Use this file to discover all available pages before exploring further.
deepspace.
Providers
<RecordProvider>
Initializes the WebSocket and in-memory record store. Required ancestor of every records hook.
| Prop | Type | Description |
|---|---|---|
roomId | string (optional) | Scope ID for the default room (usually app:<APP_NAME>). Omit for multi-scope mode and use <RecordScope> to mount scopes instead. |
schemas | CollectionSchema[] (optional) | All collections this provider tree may query. |
wsUrl | string (optional) | Override the WebSocket URL. Defaults to current origin. |
fetchUser | () => Promise<UserProfile | null> (optional) | Custom user-profile fetcher. Defaults to using the Better Auth session. |
allowAnonymous | boolean (optional) | Connect without a JWT (default false). Required for public pages. See authentication. |
getAuthToken | () => Promise<string | null> (optional) | Custom token fetcher. Defaults to the SDK’s. |
<RecordScope>
Mounts a specific scope (Durable Object instance). Nest for additional scopes.
| Prop | Type | Description |
|---|---|---|
roomId | string | Scope ID (e.g. app:my-app, conv:abc123). |
schemas | CollectionSchema[] | Collections in this scope. |
appId | string | App identifier - used for cross-app routing. |
sharedScopes | Array<{ roomId, schemas }> | Cross-app scopes to mount alongside the primary. See cross-app shared scopes. |
wsUrl | string (optional) | Override WebSocket URL. |
wsPathPrefix | string (optional) | Override path prefix (default /ws). |
isolated | boolean | If true, this scope’s store is independent of parent stores. |
<ScopeRegistryProvider>
Required once near the root if your app uses shared scopes via sharedScopes. Coordinates routing between cross-app and per-app DOs.
useQuery<T>(collection, options?)
Subscribes to a collection. Returns a reactive array of envelopes.
- Basic
- Filter
- Sort & limit
- Status
Subscribe to every record in a collection. The hook re-renders whenever any user mutates a record visible to the caller’s permissions.
useMutations<T>(collection)
Returns mutation functions for the given collection. Each mutation applies optimistically - the local store updates before the server confirms.
- Create
- Update
- Delete
- Confirmed variants
create takes the full row shape and returns the new recordId. The ID is generated on the client (timestamp + random suffix) before the write is sent, so the promise resolves with the ID immediately while the server processes the mutation in the background.createConfirmed instead - it awaits server acknowledgment:| Method | Semantics | Returns |
|---|---|---|
create | Optimistic | Promise<string> (client-generated recordId) |
put | Optimistic, merge | Promise<void> |
remove | Optimistic | Promise<void> |
createConfirmed | Waits for DO ack | Promise<string> |
putConfirmed | Waits for DO ack | Promise<void> |
removeConfirmed | Waits for DO ack | Promise<void> |
useUsers()
Returns the users collection with role-management helpers.
setRole accepts a free-form role string (e.g. 'admin', 'intern', or any value your schema understands) and dispatches the change without waiting for an ack. The Durable Object enforces who is allowed to call it. See permissions for how roles map onto collection RBAC rules.
useUserLookup()
O(1) wrapper around useUsers() for resolving userIds to display fields.
getRole or getImageUrl - read those off getUser(id)?.role or getUser(id)?.imageUrl.
useRecordContext()
Low-level access to the record-store context (WebSocket send/receive primitives, ready state, user profile, etc.). Useful for building custom hooks or imperative reads outside React’s render cycle. Most apps never need this.
See also
- Data storage guide - schemas, CRUD, and patterns.
- Data model - collections, envelopes, scopes.
- Permissions - RBAC rules and the
'own'/'shared'/'published'shortcuts. - Real-time sync - optimistic pipeline and consistency guarantees.
- Worker schemas reference - the
CollectionSchematype and drop-in collections.