typescript-server

Write SpacetimeDB server modules with TypeScript tables, reducers, views, and procedures.

25.1k|1.1k|Updated Jun 17, 2023
One-click install
npx skills add https://github.com/clockworklabs/SpacetimeDB --skill typescript-server
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-server
Source: https://github.com/clockworklabs/SpacetimeDB/tree/main/codex-plugin/plugins/spacetimedb/skills/typescript-server
Command: npx skills add https://github.com/clockworklabs/SpacetimeDB --skill typescript-server

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires spacetimedb.

What problem does it solve?

Writing SpacetimeDB server modules in TypeScript requires precise knowledge of the SDK's schema builders, reducer context API, and export conventions, and small mistakes like wrong imports or missing exports silently break modules.

Core Features & Use Cases

  • Schema and Table Definitions: Build tables with table() and schema(), apply column types, primary keys, indexes, and scheduled tables using correct snake_case conventions.
  • Reducers and Lifecycle Hooks: Implement reducers, init/connect/disconnect hooks, and database operations like insert, find, filter, update, and delete through ctx.db accessors.
  • Views, Procedures, and HTTP: Create per-user and anonymous views, query-builder semijoins, synchronous procedures, and inbound/outbound HTTP handlers.
  • Use Case: When building a real-time game backend, use this reference to correctly define a scheduled tick reducer, per-player visibility views, and bigint-safe column types without trial-and-error.

Quick Start

Ask the AI to write a SpacetimeDB TypeScript module with a table and reducer following this SDK reference.

Frequently Asked Questions about typescript-server

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define tables and reducers in a SpacetimeDB TypeScript module?

Define tables with `table({ name, public }, columns)` and register them via `schema({...})` exported as default. Create reducers with `spacetimedb.reducer(args, callback)` as named exports, and mutate data through `ctx.db` accessors matching the schema keys.

How do I create indexes in SpacetimeDB TypeScript tables?

Use inline `.index('btree')` on a column for single-column indexes, or an `indexes` array entry with `accessor`, `algorithm`, and `columns` for named or multi-column indexes. Access them via `ctx.db.table.accessor.filter(value)`.

Why is my SpacetimeDB lifecycle hook not running?

Lifecycle hooks must be declared as `export const` using `spacetimedb.init(...)`, `spacetimedb.clientConnected(...)`, or `spacetimedb.clientDisconnected(...)`. Bare calls without export are silently ignored by the module runtime.

Can I use async/await in SpacetimeDB TypeScript procedures?

No, procedure callbacks are synchronous and must return the declared value directly without `async` or `await`. Perform network I/O with `ctx.http.fetch` before opening a database transaction via `ctx.withTx`.

How do I handle bigint columns in SpacetimeDB TypeScript?

Types like `t.u64()`, `t.i64()`, and `t.u128()` map to JavaScript `bigint`, so use `0n` literals for inserts and `BigInt()` conversions for computed values. Avoid annotating context as `any`, which can cause bigint expressions to infer as `number`.