@s2-dev/streamstore - v0.26.1
    Preparing search index...

    Interface ReadSession<Format>

    Public-facing read session interface.

    Yields records directly (as an async iterable or ReadableStream) and translates transport errors into thrown exceptions. Track progress using ReadSession.nextReadPosition / ReadSession.lastObservedTail.

    const session = await stream.readSession({
    start: { from: { tailOffset: 50 } },
    stop: { wait: 15 },
    });

    for await (const record of session) {
    console.log(record.seqNum, record.body);
    }
    interface ReadSession<Format extends "string" | "bytes" = "string"> {
        locked: boolean;
        "[asyncDispose]"(): PromiseLike<void>;
        "[asyncIterator]"(): AsyncIterator<ReadRecord<Format>, any, any>;
        cancel(reason?: any): Promise<void>;
        caughtUp(): Promise<StreamPosition>;
        getReader(options: { mode: "byob" }): ReadableStreamBYOBReader;
        getReader(): ReadableStreamDefaultReader<ReadRecord<Format>>;
        getReader(
            options?: ReadableStreamGetReaderOptions,
        ): ReadableStreamReader<ReadRecord<Format>>;
        isCaughtUp(): boolean;
        lastObservedTail(): StreamPosition;
        nextReadPosition(): StreamPosition;
        pipeThrough<T>(
            transform: ReadableWritablePair<T, ReadRecord<Format>>,
            options?: StreamPipeOptions,
        ): ReadableStream<T>;
        pipeTo(
            destination: WritableStream<ReadRecord<Format>>,
            options?: StreamPipeOptions,
        ): Promise<void>;
        tee(): [
            ReadableStream<ReadRecord<Format>>,
            ReadableStream<ReadRecord<Format>>,
        ];
    }

    Type Parameters

    • Format extends "string" | "bytes" = "string"

    Hierarchy

    Index

    Properties

    locked: boolean

    The locked read-only property of the ReadableStream interface returns whether or not the readable stream is locked to a reader.

    MDN Reference

    Methods

    • Returns PromiseLike<void>

    • Returns AsyncIterator<ReadRecord<Format>, any, any>

    • The cancel() method of the ReadableStream interface returns a Promise that resolves when the stream is canceled.

      MDN Reference

      Parameters

      • Optionalreason: any

      Returns Promise<void>

    • Returns a promise for the next caught-up state. Resolves immediately if the session is already caught up. Remains pending across reconnects. Call again after the session falls behind. Continue reading records while the promise is pending.

      Resolves with the tail captured for that state. Rejects with the read error or SESSION_CLOSED if the session ends first.

      Returns Promise<StreamPosition>

    • The getReader() method of the ReadableStream interface creates a reader and locks the stream to it.

      MDN Reference

      Parameters

      • options: { mode: "byob" }

      Returns ReadableStreamBYOBReader

    • Returns ReadableStreamDefaultReader<ReadRecord<Format>>

    • Parameters

      • Optionaloptions: ReadableStreamGetReaderOptions

      Returns ReadableStreamReader<ReadRecord<Format>>

    • Reports whether the session has read through its latest reported tail. Returns false while records remain before the reported tail, after a batch without a tail, or after a reconnect. Ignored command records count toward progress. Use S2Stream.checkTail for the current stream tail.

      Returns boolean

    • The pipeThrough() method of the ReadableStream interface provides a chainable way of piping the current stream through a transform stream or any other writable/readable pair.

      MDN Reference

      Type Parameters

      • T

      Parameters

      • transform: ReadableWritablePair<T, ReadRecord<Format>>
      • Optionaloptions: StreamPipeOptions

      Returns ReadableStream<T>

    • The pipeTo() method of the ReadableStream interface pipes the current ReadableStream to a given WritableStream and returns a Promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.

      MDN Reference

      Parameters

      • destination: WritableStream<ReadRecord<Format>>
      • Optionaloptions: StreamPipeOptions

      Returns Promise<void>