diff --git a/docs/docs/00200-core-concepts/00100-databases/00600-submodules.md b/docs/docs/00200-core-concepts/00100-databases/00600-submodules.md index c7b39909143..1bfb9a2a3a4 100644 --- a/docs/docs/00200-core-concepts/00100-databases/00600-submodules.md +++ b/docs/docs/00200-core-concepts/00100-databases/00600-submodules.md @@ -23,7 +23,7 @@ A submodule is a regular SpacetimeDB module. Nothing special marks a module as a ```typescript // auth_lib/src/index.ts -import { schema, table, t, SyncResponse, Router } from 'spacetimedb/server'; +import { schema, table, t, SyncResponse, Router, type ReducerCtx } from 'spacetimedb/server'; const users = table( { name: 'users', public: true }, @@ -81,7 +81,7 @@ The consumer controls the namespace name. Pass the submodule's module-namespace ```typescript // my-database/src/index.ts -import { schema } from 'spacetimedb/server'; +import { schema, table } from 'spacetimedb/server'; import * as authLib from 'auth_lib'; const players = table({ name: 'players', public: true }, { /* ... */ }); @@ -140,7 +140,7 @@ Call a submodule reducer or a plain helper function typed against the submodule' ```typescript // auth_lib: plain helper function typed against the submodule's own schema -export function sessionCountHelper(ctx: ReducerContext): number { +export function sessionCountHelper(ctx: ReducerCtx): number { return ctx.db.sessions.count(); } @@ -155,7 +155,7 @@ export const onLogin = spacetimedb.reducer({ token: t.string() }, (ctx, { token }); ``` -`ctx.as.myauth` is a `ReducerContext` scoped to the `myauth` namespace. It shares the same sender, timestamp, and connectionId as the parent context, but its `ctx.db` points at `ctx.db.myauth`. +`ctx.as.myauth` is a `ReducerCtx` scoped to the `myauth` namespace. It shares the same sender, timestamp, and connectionId as the parent context, but its `ctx.db` points at `ctx.db.myauth`. For reducers registered through the submodule's own schema (via `schema.reducer(...)`), the host passes a scoped context automatically when invoked directly. `ctx.as` is only needed when the consumer calls a submodule function explicitly. @@ -167,7 +167,7 @@ For reducers registered through the submodule's own schema (via `schema.reducer( -Use `ctx.as.` to pass a submodule-scoped `ProcedureContext` to a submodule procedure. To call a submodule reducer from inside a procedure, open a transaction first with `ctx.withTx` and then narrow with `tx.as.`: +Use `ctx.as.` to pass a submodule-scoped `ProcedureCtx` to a submodule procedure. To call a submodule reducer from inside a procedure, open a transaction first with `ctx.withTx` and then narrow with `tx.as.`: ```typescript // call a submodule procedure @@ -182,7 +182,7 @@ export const transactAndCount = spacetimedb.procedure( t.u64(), (ctx, { token }) => { ctx.withTx(tx => { - // tx is a root ReducerContext; narrow to the submodule namespace + // tx is a root ReducerCtx; narrow to the submodule namespace authLib.verifyToken(tx.as.myauth, { token }); }); return authLib.sessionCount(ctx.as.myauth); @@ -271,7 +271,7 @@ conn.subscriptionBuilder().subscribe(tables => [ ## Calling Submodule Reducers and Procedures from the Client -Submodule reducers and procedures are identified by their fully-qualified name, using `/` as the separator between namespace and function name. +Submodule reducers and procedures are identified by their fully-qualified name, using `.` as the separator between namespace and function name. ### Client SDK @@ -322,16 +322,16 @@ conn.reducers.myauth.verifyToken({ token: 'abc123' }); ### HTTP API ``` -POST /v1/database/my-database/call/myauth/verify_token +POST /v1/database/my-database/call/myauth.verify_token ``` ### CLI ```bash -spacetime call my-database "myauth/verify_token" '{"token": "abc123"}' +spacetime call my-database "myauth.verify_token" '{"token": "abc123"}' ``` -The namespace prefix is the alias you chose, and the function name after `/` is the canonical +The namespace prefix is the alias you chose, and the function name after `.` is the canonical snake_case form of the submodule's export name -- `verifyToken` in TypeScript is `verify_token` on the wire. Generated client bindings expose the camelCase accessor instead, as shown above.