bothy-sdk
    Preparing search index...

    Class FileInboxStore

    The durable InboxStore: one JSON file per entry in a directory of mode 0700, each file of mode 0600, written to a temporary file, synced and renamed into place, so an entry is either the old or the new one after a crash. The jti store lives in the same directory.

    A file holds the event without invocation_token, the newest token, its iat and jti, the state, the delivery count and the arrival order; nothing else. The token is stored because the directory is the adapter's durable acceptance (docs/DECISIONS.md D-M2-29-9); it is never logged. One store object owns a directory: it reads the files once and keeps them in memory, and every write is durable when its promise resolves.

    The directory is created on first use; an existing directory or file that group or others can access, or a symbolic link in its place, is refused.

    const inbox = new FileInboxStore(join(stateDir, "inbox"));
    for (const entry of await inbox.inStates(EntryState.ACCEPTED)) await start(entry);

    Implements

    Index

    Constructors

    • Creates the store; the directory is opened on the first call.

      Parameters

      • directory: string

        The inbox directory, usually inbox in the adapter's state directory.

      Returns FileInboxStore

    Methods

    • Stores a new entry; durable when this resolves.

      Parameters

      Returns Promise<void>

      A promise that resolves when written.

      RangeError when the event is already stored, its ID is not a UUID or the envelope carries a token; Error when the write fails.

    • Waits for pending writes and refuses later calls; closing twice is harmless.

      Returns Promise<void>

      A promise that resolves when every pending write ended.

    • Returns the entries of a run in seq order (ephemeral entries last, in arrival order).

      Parameters

      • runId: string

        The run.

      Returns Promise<InboxEntry[]>

      The entries.

      Error when the directory cannot be opened or the store is closed.

    • Returns the entry of eventId.

      Parameters

      • eventId: string

        The envelope id.

      Returns Promise<InboxEntry | undefined>

      The entry, or undefined.

      Error when the directory cannot be opened or the store is closed.

    • Returns the entries in one of states in seq order (ephemeral entries last, in arrival order).

      Parameters

      Returns Promise<InboxEntry[]>

      The entries.

      Error when the directory cannot be opened or the store is closed.

    • Returns whether jti is remembered beyond nowMs.

      Parameters

      • jti: string

        The token ID.

      • nowMs: number

        The current wall time.

      Returns Promise<boolean>

      Whether the jti is still remembered.

      Error when the directory cannot be opened or the store is closed.

    • Drops the jti rows that expired at nowMs; inbox entries stay.

      Parameters

      • nowMs: number

        The current wall time.

      Returns Promise<void>

      A promise that resolves when written.

      Error when the write fails or the store is closed.

    • Counts a redelivery; see InboxStore.redelivered. Durable when this resolves.

      Parameters

      • eventId: string

        The envelope id.

      • token: Secret | undefined

        The token of the redelivery, if any.

      • iat: number | undefined

        Its iat.

      • jti: string | undefined

        Its jti.

      Returns Promise<InboxEntry>

      The entry after the update.

      RangeError when the event is not stored; Error when the write fails.

    • Remembers jti until untilMs (an earlier end never shortens a later one); durable when this resolves.

      Parameters

      • jti: string

        The token ID.

      • untilMs: number

        When the token cannot pass anymore (exp plus the leeway).

      Returns Promise<void>

      A promise that resolves when written.

      Error when the write fails or the store is closed.

    • Replaces the token unconditionally; durable when this resolves.

      Parameters

      • eventId: string

        The envelope id.

      • token: Secret

        The granted token.

      • iat: number

        Its iat.

      • jti: string

        Its jti.

      Returns Promise<void>

      A promise that resolves when written.

      RangeError when the event is not stored; Error when the write fails.

    • Sets the state of an entry; durable when this resolves.

      Parameters

      • eventId: string

        The envelope id.

      • state: EntryState

        The new state.

      Returns Promise<void>

      A promise that resolves when written.

      RangeError when the event is not stored; Error when the write fails.