Skip to content

Session

The Session: one serialized commit line over a Storage, a cache of committed documents, and publication of committed changes.

Guarantees:

  • Every commit, document load, and watch attachment runs on one line, one at a time, first come first served.
  • A commit is all-or-nothing. Nothing is published before storage accepted it.
  • Once storage has admitted a batch, interrupting the caller cannot stop the commit, adoption, or publication.
  • StorageRejected rolls back. Any other storage failure, or a failure after admission, poisons the Session: memory may lag durable state, so every later operation fails with SessionPoisoned until it is reopened.

Since v0.0.0


Signature

type CommitChange = TableChange | DocumentChange

Source

Since v0.0.0

Signature

export interface CommitOptions {
/** Attribute every entry the commit appends to this task (`byTaskId`). */
readonly byTask?: TaskId
}

Source

Since v0.0.0

Every change of one successful commit. Change order is unspecified.

Signature

export interface CommitPublication {
readonly seq: Seq
readonly changes: ReadonlyArray<CommitChange>
}

Source

Since v0.0.0

Signature

declare const DocumentChange: DocumentChange

Source

Since v0.0.0

How many undelivered frames a watch keeps before collapsing them into one root replacement.

Signature

declare const MaxPendingWatchFrames: any

Source

Since v0.0.0

Signature

export interface Options {
/**
* Runs inside every transaction that creates a conversation, after its record is staged. A Harness stages its
* built-in documents here.
*/
readonly conversationCreated?: (record: ConversationRecord) => Effect.Effect<void, WriteError, Tx>
}

Source

Since v0.0.0

Signature

declare class Session

Source

Since v0.0.0

Signature

export interface SessionShape {
/**
* Run `body` as one atomic transaction on the commit line, with `Tx` provided. If the body fails, nothing is
* written. Interrupting the caller before storage admission abandons the commit; after admission it completes.
*/
readonly commit: <A, E, R>(
body: Effect.Effect<A, E, R>,
options?: CommitOptions
) => Effect.Effect<A, E | CommitError, Exclude<R, Tx>>
/** The committed value of a document; `None` when absent. Never creates. */
readonly snapshot: <A>(ref: State.Ref<A>) => Effect.Effect<Option.Option<A>, ReadError>
/**
* The value a rewindable conversation state had in the commit that wrote entry `at`, which must be visible from the
* conversation. An inherited entry reads the ancestor's state at that point. `None` when no incarnation existed.
*/
readonly snapshotAsOf: <A>(
ref: State.Ref<A>,
at: EntryId
) => Effect.Effect<Option.Option<A>, ReadError | EntryNotVisible>
/** Watch one existing document incarnation; see `State.watch`. */
readonly watch: <A>(ref: State.Ref<A>) => Effect.Effect<Option.Option<State.Watch<A>>, ReadError, Scope.Scope>
/**
* Observe every commit synchronously after adoption, while the line is still held. The listener must not throw or
* block. Registration lasts for the scope; `onClose` runs once if the Session closes first.
*/
readonly subscribeCommits: (
listener: (publication: CommitPublication) => void,
options?: { readonly onClose?: () => void }
) => Effect.Effect<void, never, Scope.Scope>
/** Run a read-only effect on the line, so several reads observe one committed state. */
readonly readOnLine: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | SessionPoisoned, R>
/** Committed reads. */
readonly storage: StorageShape
}

Source

Since v0.0.0

A committed table record.

Signature

type TableChange = Extract<StorageWrite, { readonly type: "conversation" | "entry" | "task" | "submission" }>

Source

Since v0.0.0

Run body as one atomic transaction; see SessionShape.commit.

Signature

declare const commit: <A, E, R>(
body: Effect.Effect<A, E, R>,
options?: CommitOptions
) => Effect.Effect<A, E | CommitError, Exclude<R, Tx> | Session>

Source

Since v0.0.0

A Session over the Storage in context. Closing the layer seals it: watches end and the in-flight commit settles.

Signature

declare const layer: (options?: Options) => Layer.Layer<Session, never, Storage>

Source

Since v0.0.0

Signature

declare const readOnLine: <A, E, R>(effect: Effect.Effect<A, E, R>) => any

Source

Since v0.0.0

Signature

declare const subscribeCommits: (
listener: (publication: CommitPublication) => void,
options?: { readonly onClose?: () => void }
) => any

Source

Since v0.0.0