Skip to content

Value Types

Value types wrap Effect schemas with the SpaceTimeDB type information needed for tables, call params, returns, declared errors, HTTP routes, and generated clients.

import * as Schema from "effect/Schema"
import * as Stdb from "effect-spacetimedb"
const UserId = Schema.String.pipe(Schema.brand("UserId"))
const user = Stdb.table("user", {
columns: {
id: Stdb.string(UserId).primaryKey(),
level: Stdb.u32(),
credits: Stdb.bigint(),
createdAt: Stdb.timestamp(),
},
})

Use namespace form for helpers, including Stdb.enum(...); enum cannot be a named import in JavaScript.

HelperAuthored TypeScript valueSATS loweringBounds / encoding
Stdb.string(schema?)string or branded stringstringOptional schema refines the authored value.
Stdb.bool(schema?)boolean or branded booleanboolOptional schema refines the authored value.
Stdb.u8() / u16() / u32()numberunsigned integer widthConstructor checks 0..2^8-1, 0..2^16-1, or 0..2^32-1.
Stdb.i8() / i16() / i32()numbersigned integer widthConstructor checks -(2^(n-1))..2^(n-1)-1.
Stdb.u64() / u128() / u256()bigintunsigned integer widthConstructor checks 0..2^n-1; DB and generated-client transports keep bigint.
Stdb.i64() / i128() / i256()bigintsigned integer widthConstructor checks -(2^(n-1))..2^(n-1)-1; DB and generated-client transports keep bigint.
Stdb.f32() / f64()numberf32 / f64DB and WebSocket profiles preserve NaN/Infinity; HTTP JSON rejects non-finite numbers.
Stdb.bigint()bigintstringJSON-safe arbitrary-size integer encoded through Schema.BigIntFromString.
Stdb.bytes()Uint8Arraybyte arrayHost and generated-client values are byte arrays.
Stdb.identity()spacetimedb.IdentityidentityNative identity object.
Stdb.connectionId()spacetimedb.ConnectionIdconnection idNative connection id object.
Stdb.timestamp()spacetimedb.TimestamptimestampNative timestamp object, microseconds since Unix epoch.
Stdb.timeDuration()spacetimedb.TimeDurationtime durationNative duration object, microseconds.
Stdb.scheduleAt()spacetimedb.ScheduleAtschedule-atScheduled-table scheduledAt value type.
Stdb.uuid()spacetimedb.UuidUUIDNative UUID object.
Stdb.unit()void / undefinedunitEmpty payload marker for sums, results, and scheduled procedure returns.

The five id-like natives — Stdb.identity(), Stdb.connectionId(), Stdb.timestamp(), Stdb.timeDuration(), and Stdb.uuid() — validate at construction: the SpacetimeDB constructors reject anything that is not a bigint, an integer number, or a well-formed string, and a blank string is not well-formed. Where such a value arrives from outside the process, that rejection is reported as a typed StdbDecodeError on the decode boundary, not as a defect, so a malformed __identity__ or __uuid__ in an HTTP body fails the call rather than killing the fiber.

Stdb.bigint() is not the same as the fixed-width integer helpers. Use Stdb.bigint() when the database column should be a SATS string carrying a JSON-safe arbitrary integer. Use i64/u64/i128/u128/i256/u256 when the database column should be a native integer width and the authored value should stay a bigint.

HelperAuthored TypeScript valueSATS loweringNotes
Stdb.array(T)ReadonlyArray<TypeOf<T>>array/listRecurses through the inner value type.
Stdb.option(T)TypeOf<T> or undefinedoption<T>Present field whose value can be absent.
Stdb.optional(T)optional struct fieldoption<T> in structsProduces an optional TypeScript property.
T.optional()optional table columnoption<T> columnColumn may be omitted on inserts.
Stdb.struct({ ... })objectSATS structUse for rows, params, returns, and declared-error payloads. Anonymous structs get a content-addressed name unless you set one with .named(...).
Stdb.sum({ Tag: Payload }){ tag, value? }SATS enum/sumUnit payloads omit value; payload variants require value. Anonymous sums get a content-addressed name unless you set one with .named(...).
Stdb.enum("A", "B") / enumType(...)tagged unit variantsSATS enumUnit-variant sums; prefer namespace form because enum cannot be named-imported.
Stdb.literal(...)string, number, or boolean literalstring literals -> enum; numbers -> f64; booleans -> boolString literal generated-client tags use SpaceTimeDB PascalCase. Numeric literals reject non-finite values and unsafe integers.
Stdb.result(Ok, Err)Effect-style result envelopeSATS resultNormalizes host { ok } / { err } envelopes.
Stdb.lazy(() => T)recursive valuelazy SATS typeUse for recursive structs or sums.
Stdb.custom(schema, { type })schema-authored valuelowering of typeKeep the SpaceTimeDB lowering explicit when wrapping custom schemas.

Stdb.sum(...) and Stdb.enum(...) columns are key- and index-capable. They key on the whole encoded value, so each payload of a variant is its own key. .autoInc() is not available on them. See Constraints and Indexes.

Anonymous Stdb.struct(...), Stdb.sum(...), and string-literal Stdb.literal(...) types have no author-given name, so their generated SATS/client type name is content-addressed: a stable hash of the shape such as EffectSpacetimeDbStruct.... The hash is deterministic and collision-free, but not readable.

Set a semantic name with .named(...):

Stdb.struct({ id: Stdb.string() }).named("UserView") // generated type: `UserView`

The identifier is emitted verbatim, so prefer PascalCase (MembershipView) — casing is not applied for you. JavaScript keywords, generated-client helper names (__*), and callable-local bindings (params, returnType) are reserved. When an anonymous value type is exported as a top-level reusable contract type, keep the .named(...) identifier equal to the exported const identifier, for example export const UserView = Stdb.struct(...).named("UserView"). Nested inline names can use their own semantic payload names.

table.row is already named: it carries the table’s PascalCase type name automatically and reuses the table’s single generated type, so a user table’s user.row lowers to the User type with no .named(...) needed. Return or nest it directly:

Stdb.option(user.row) // reuses the table's `User` type, not a duplicate

.named(...) is distinct from .name(...): .name(...) sets SpacetimeDB’s native builder column metadata and does not rename the generated type.

HelperProfileWhen to use
Stdb.dbCodec(T)SpaceTimeDB host / DB shapeLow-level host interop, table rows, reducer args, and generated server values.
Stdb.httpCodec(T)HTTP JSON shapeTyped HTTP request and response bodies. Rejects non-finite floating-point numbers because JSON cannot carry them.
Stdb.wsCodec(T)Generated WebSocket client shapeClient cache rows, subscription events, and callable payloads. Sum and string-literal tags are rewritten to the generated client’s PascalCase convention.

The public docs use this page as the helper catalog. See Value Representations for the transport profiles and Column Types for table-specific usage.