Skip to content

Codegen

SpacetimeDB: Codegen ↗

effect-spacetimedb does not replace SpacetimeDB client generation. Build the module with the native CLI, then run spacetime generate against the built bundle.

{
"scripts": {
"build": "spacetime build --module-path .",
"generate-client": "spacetime generate --lang typescript --js-path ./dist/bundle.js --out-dir ./src/generated --yes"
}
}

Generated native bindings are used by effect-spacetimedb/client for WebSocket sessions:

import * as Stdb from "effect-spacetimedb"
import * as StdbClient from "effect-spacetimedb/client"
declare const DbConnection: StdbClient.GeneratedWsConnectionFactory<
Stdb.AnyModuleSpec,
unknown
>
const adapter = StdbClient.GeneratedWs.adapter({
DbConnection,
uri: "ws://localhost:3000",
databaseName: "example",
})

The Effect client projection is derived from Stdb.project(Module.spec), but the WebSocket transport still needs the native generated DbConnection.