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.
StorageRejectedrolls back. Any other storage failure, or a failure after admission, poisons the Session: memory may lag durable state, so every later operation fails withSessionPoisoneduntil it is reopened.
Since v0.0.0
CommitChange (type alias)
Section titled “CommitChange (type alias)”Signature
type CommitChange = TableChange | DocumentChangeSince v0.0.0
CommitOptions (interface)
Section titled “CommitOptions (interface)”Signature
export interface CommitOptions { /** Attribute every entry the commit appends to this task (`byTaskId`). */ readonly byTask?: TaskId}Since v0.0.0
CommitPublication (interface)
Section titled “CommitPublication (interface)”Every change of one successful commit. Change order is unspecified.
Signature
export interface CommitPublication { readonly seq: Seq readonly changes: ReadonlyArray<CommitChange>}Since v0.0.0
DocumentChange
Section titled “DocumentChange”Signature
declare const DocumentChange: DocumentChangeSince v0.0.0
MaxPendingWatchFrames
Section titled “MaxPendingWatchFrames”How many undelivered frames a watch keeps before collapsing them into one root replacement.
Signature
declare const MaxPendingWatchFrames: anySince v0.0.0
Options (interface)
Section titled “Options (interface)”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>}Since v0.0.0
Session (class)
Section titled “Session (class)”Signature
declare class SessionSince v0.0.0
SessionShape (interface)
Section titled “SessionShape (interface)”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}Since v0.0.0
TableChange (type alias)
Section titled “TableChange (type alias)”A committed table record.
Signature
type TableChange = Extract<StorageWrite, { readonly type: "conversation" | "entry" | "task" | "submission" }>Since v0.0.0
commit
Section titled “commit”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>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>Since v0.0.0
readOnLine
Section titled “readOnLine”Signature
declare const readOnLine: <A, E, R>(effect: Effect.Effect<A, E, R>) => anySince v0.0.0
subscribeCommits
Section titled “subscribeCommits”Signature
declare const subscribeCommits: ( listener: (publication: CommitPublication) => void, options?: { readonly onClose?: () => void }) => anySince v0.0.0