Rivet.DurableStream reference
DurableStream
Section titled “DurableStream”Source:
packages/rivet/src/DurableStream.ts
A Durable Stream: an append-only log with a durable, replayable history,
one per key, served by Rivet Services. Each stream is its own Rivet actor.
Declare it once with its message Schema; yield* it in any runtime for a
typed client that appends, reads, and follows each stream live.
The messages’ wire format is a Layer, StreamFormat.Json or another, so
a program only bundles the format it uses. It’s fixed when a stream is
created.
DurableStream: Declaring a stream
Section titled “DurableStream: Declaring a stream”import * as Rivet from "@alchemy.run/rivet";import * as Schema from "effect/Schema";
export const Message = Schema.Struct({ user: Schema.String, text: Schema.String });
export class ChatLog extends Rivet.DurableStream<ChatLog>()("ChatLog", { schema: Message, ttl: "7 days",}) {}DurableStream: Writing and reading
Section titled “DurableStream: Writing and reading”const log = yield* ChatLog;yield* log.append("lobby", { user: "sam", text: "hello" });const { messages, next } = yield* log.read("lobby");const live = log.tail("lobby", { from: next });DurableStream: Choosing a format
Section titled “DurableStream: Choosing a format”import * as StreamFormat from "@alchemy.run/rivet/StreamFormat";
Effect.provide(Layer.mergeAll(Default, Services, StreamFormat.Json));