douglance/spacetimedb/spacetimedb-typescript
Claude Code and agent skill by douglance/spacetimedb
- community
Checking that the SKILL.md file is still in the repository.
Build TypeScript clients for SpacetimeDB. Use when connecting to SpacetimeDB from web apps, Node.js, Deno, Bun, or other JavaScript runtimes.
Install
npx vskill@latest install douglance/spacetimedb/spacetimedb-typescriptSKILL.md
SpacetimeDB TypeScript SDK
Build real-time TypeScript clients that connect directly to SpacetimeDB modules. The SDK provides type-safe database access, automatic synchronization, and reactive updates for web apps, Node.js, Deno, Bun, and other JavaScript runtimes.
HALLUCINATED APIs — DO NOT USE
These APIs DO NOT EXIST. LLMs frequently hallucinate them.
CORRECT PATTERNS:
DO NOT:
- Invent hooks like
useItems(),useData()— useuseTable(tables.tableName) - Import from fake packages — only
spacetimedb,spacetimedb/react,./module_bindings
Common Mistakes Table
Server-side errors
| Wrong | Right | Error | |
|---|---|---|---|
Missing package.json | Create package.json | "could not detect language" | |
Missing tsconfig.json | Create tsconfig.json | "TsconfigNotFound" | |
Entrypoint not at src/index.ts | Use src/index.ts | Module won't bundle | |
indexes in COLUMNS (2nd arg) | indexes in OPTIONS (1st arg) | "reading 'tag'" error | |
Index without algorithm | algorithm: 'btree' | "reading 'tag'" error | |
filter({ ownerId }) | filter(ownerId) | "does not exist in type 'Range'" | |
.filter() on unique column | .find() on unique column | TypeError | |
insert({ ...without id }) | insert({ id: 0n, ... }) | "Property 'id' is missing" | |
const id = table.insert(...) | const row = table.insert(...) | .insert() returns ROW, not ID | |
.unique() + explicit index | Just use .unique() | "name is used for multiple entities" | |
| Import spacetimedb from index.ts | Import from schema.ts | "Cannot access before initialization" | |
Multi-column index .filter() | Use single-column index | PANIC or silent empty results | |
.iter() in views | Use index lookups only | Views can't scan tables | |
ctx.db in procedures | ctx.withTx(tx => tx.db...) | Procedures need explicit transactions | |
ctx.myTable in procedure tx | tx.db.myTable | Wrong context variable |
Client-side errors
| Wrong | Right | Error | |
|---|---|---|---|
@spacetimedb/sdk | spacetimedb | 404 / missing subpath | |
conn.reducers.foo("val") | conn.reducers.foo({ param: "val" }) | Wrong reducer syntax | |
Inline connectionBuilder | useMemo(() => ..., []) | Reconnects every render | |
const rows = useTable(table) | const [rows, isLoading] = useTable(table) | Tuple destructuring | |
| Optimistic UI updates | Let subscriptions drive state | Desync issues | |
<SpacetimeDBProvider builder={...}> | connectionBuilder={...} | Wrong prop name |
Hard Requirements
- DO NOT edit generated bindings — regenerate with
spacetime generate - Reducers are transactional — they do not return data
- Reducers must be deterministic — no filesystem, network, timers, random
- Reducer calls use object syntax —
{ param: 'value' }not positional args - Import `DbConnection` from `./module_bindings` — not from
spacetimedb - useTable returns a tuple —
const [rows, isLoading] = useTable(tables.myTable) - Memoize connectionBuilder — wrap in
useMemo(() => ..., [])to prevent reconnects - Views can only use index lookups —
.iter()is not allowed in views
Installation
For Node.js 18-21, install the undici peer dependency:
Node.js 22+ and browser environments work out of the box.
Generating Type Bindings
Before using the SDK, generate TypeScript bindings from your SpacetimeDB module:
This creates a module_bindings directory with:
index.ts- Main exports includingDbConnection,tables,reducers,query- Type definitions for each table (e.g.,
player_table.ts,user_table.ts) - Type definitions for each reducer (e.g.,
create_player_reducer.ts) - Custom type definitions (e.g.,
point_type.ts)
Basic Connection Setup
Connection Builder Options
Subscribing to Tables
Subscriptions sync table data to the client cache. Use SQL queries to filter what data you receive.
Basic Subscription
Multiple Queries
Typed Query Builder
Use the generated query object for type-safe queries:
Subscribe to All Tables
For development or small datasets:
Unsubscribing
Accessing Table Data
After subscription, access cached data through connection.db:
Table Event Callbacks
Listen for real-time changes to table data:
Event Context
Callbacks receive an EventContext with information about the event:
Calling Reducers
Reducers are server-side functions that modify the database. CRITICAL: Use object syntax, not positional arguments.
Snake_case to camelCase conversion
- Server:
spacetimedb.reducer('do_something', ...) - Client:
conn.reducers.doSomething({ ... })
Reducer Flags
Control how the server handles reducer calls:
Views
Views provide filtered access to private table data based on the connected user.
ViewContext vs AnonymousViewContext
CRITICAL: Views can only use index lookups
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/spacetimedb-typescript/SKILL.md
Popularity
- 7-day trend score
- 0
Refreshed 1 Apr 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/douglance/spacetimedb/spacetimedb-typescript)