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.

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({ ... })objectcontent-addressed SATS structUse for rows, params, returns, and declared-error payloads.
Stdb.sum({ Tag: Payload }){ tag, value? }content-addressed SATS enum/sumUnit payloads omit value; payload variants require value.
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.
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.