kurrentdb/operation/read_stream
Build read-stream requests and decode read messages.
This module contains the sans-IO pieces for KurrentDB’s Streams/Read
method when reading a single stream. It also defines the shared read
message types used by stream subscriptions.
Use request to build a finite read request, and decode_message to turn
each gRPC response frame into a typed ReadMessage.
Types
Configuration
opaqueConfiguration for a finite stream read.
pub opaque type Configuration
Direction in which events are read.
pub type Direction {
Forwards
Backwards
}
Constructors
-
ForwardsRead from lower revisions to higher revisions.
-
BackwardsRead from higher revisions to lower revisions.
A position in the KurrentDB transaction log.
pub type Position {
NoPositionReturned
Position(commit_position: Int, prepare_position: Int)
}
Constructors
-
NoPositionReturned -
Position(commit_position: Int, prepare_position: Int)
An event that was either recorded directly or resolved through a link.
pub type ReadEvent {
Recorded(RecordedEvent)
Resolved(link: RecordedEvent, event: RecordedEvent)
}
Constructors
-
Recorded(RecordedEvent) -
Resolved(link: RecordedEvent, event: RecordedEvent)
Message returned by a read or subscription stream.
KurrentDB can return data events, subscription lifecycle messages, checkpoints, and position metadata on the same gRPC stream.
pub type ReadMessage {
ReadEvent(ReadEvent)
SubscriptionConfirmed(String)
Checkpoint(Position)
CaughtUp(SubscriptionCheckpoint)
FellBehind(SubscriptionCheckpoint)
FirstStreamPosition(Int)
LastStreamPosition(Int)
LastAllStreamPosition(Position)
ReadIgnored
}
Constructors
-
ReadEvent(ReadEvent) -
SubscriptionConfirmed(String) -
Checkpoint(Position) -
CaughtUp(SubscriptionCheckpoint) -
FellBehind(SubscriptionCheckpoint) -
FirstStreamPosition(Int) -
LastStreamPosition(Int) -
LastAllStreamPosition(Position) -
ReadIgnored
Starting point for reading a stream.
pub type ReadRevision {
FromStart
FromEnd
FromRevision(Int)
}
Constructors
-
FromStart -
FromEnd -
FromRevision(Int)
A stored event with its metadata and data.
metadata contains KurrentDB system metadata entries such as event type and
content type. custom_metadata and data are the raw bytes written with the
event.
pub type RecordedEvent {
RecordedEvent(
id: uuid.Uuid,
stream: String,
revision: Int,
prepare_position: Int,
commit_position: Int,
metadata: List(#(String, String)),
custom_metadata: BitArray,
data: BitArray,
)
}
Constructors
-
RecordedEvent( id: uuid.Uuid, stream: String, revision: Int, prepare_position: Int, commit_position: Int, metadata: List(#(String, String)), custom_metadata: BitArray, data: BitArray, )
Errors that can occur while decoding a read message.
pub type ResponseError {
GrpcError(kurrentdb.GrpcError)
ReadStreamNotFound(String)
}
Constructors
-
GrpcError(kurrentdb.GrpcError) -
ReadStreamNotFound(String)
Values
pub fn configure() -> Configuration
Create read configuration with default values.
Defaults are forwards, from the start of the stream, at most 1000 events, and link resolution disabled.
pub fn decode_message(
message: BitArray,
) -> Result(ReadMessage, ResponseError)
Decode one gRPC read response message.
Backends call this for each decoded gRPC frame. Stream-not-found gRPC errors
are mapped to the operation-specific ReadStreamNotFound variant.
pub fn from_revision(
config: Configuration,
revision: ReadRevision,
) -> Configuration
Set the revision to start reading from.
pub fn max_count(
options: Configuration,
max_count: Int,
) -> Configuration
Set the maximum number of events to read.
This applies only to finite reads. Subscriptions use a separate configuration type and continue until closed.
pub fn read_direction(
config: Configuration,
direction: Direction,
) -> Configuration
Set the read direction for a stream read.
pub fn request(
client: kurrentdb.Client,
stream stream_name: String,
config config: Configuration,
) -> request.Request(BitArray)
Build a finite Streams/Read request for a single stream.
pub fn resolve_links(
options: Configuration,
resolve_links: Bool,
) -> Configuration
Enable or disable link-to-event resolution.