kurrentdb
KurrentDB client core.
Types
Options for append_to_stream.
pub type AppendOptions {
AppendOptions(expected_revision: ExpectedRevision)
}
Constructors
-
AppendOptions(expected_revision: ExpectedRevision)
KurrentDB server connection. Created via new or from_connection_string.
pub type Client {
Client(endpoint: String, tls: Bool)
}
Constructors
-
Client(endpoint: String, tls: Bool)
Options for delete_stream.
pub type DeleteOptions {
DeleteOptions(expected_revision: ExpectedRevision)
}
Constructors
-
DeleteOptions(expected_revision: ExpectedRevision)
Read direction: forwards or backwards.
pub type Direction {
Forwards
Backwards
}
Constructors
-
Forwards -
Backwards
Domain errors returned by KurrentDB operations.
pub type Error {
HttpStatus(Int)
GrpcStatus(String)
UnknownGrpcStatus(status: String, message: String)
EmptyResponse
ManyResponses
FrameError(FrameError)
UnableToDecodeGrpcResponse(List(ProtobufDecodeError))
UnableToDecodeStreamMetadata(json.DecodeError)
AppendWrongExpectedVersion
ReadStreamNotFound(String)
StreamDeleted(String)
AccessDenied
NotAuthenticated
Unavailable
DeadlineExceeded
NotLeader(String)
UnableToBuildRequest
StreamFinished
}
Constructors
-
HttpStatus(Int) -
GrpcStatus(String) -
UnknownGrpcStatus(status: String, message: String) -
EmptyResponse -
ManyResponses -
FrameError(FrameError) -
UnableToDecodeGrpcResponse(List(ProtobufDecodeError)) -
UnableToDecodeStreamMetadata(json.DecodeError) -
AppendWrongExpectedVersion -
ReadStreamNotFound(String) -
StreamDeleted(String) -
AccessDenied -
NotAuthenticated -
Unavailable -
DeadlineExceeded -
NotLeader(String) -
UnableToBuildRequest -
StreamFinished
An event to be appended to a stream.
pub type Event {
Event(
id: String,
type_: String,
content_type: String,
data: BitArray,
metadata: BitArray,
)
}
Constructors
-
Event( id: String, type_: String, content_type: String, data: BitArray, metadata: BitArray, )
Expected stream revision for concurrency control.
pub type ExpectedRevision {
Revision(Int)
NoStream
Any
StreamExists
}
Constructors
-
Revision(Int) -
NoStream -
Any -
StreamExists
Window size strategy for filter results.
pub type FilterWindow {
FilterMax(Int)
FilterCount
}
Constructors
-
FilterMax(Int) -
FilterCount
Errors from decoding gRPC wire frames.
pub type FrameError {
IncompleteHeader
CompressedMessage
IncompleteMessage(expected_bytes: Int)
}
Constructors
-
IncompleteHeader -
CompressedMessage -
IncompleteMessage(expected_bytes: Int)
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)
Errors from decoding protocol buffer messages.
pub type ProtobufDecodeError {
DecodeError(
expected: String,
found: String,
path: List(String),
)
FieldNotFound(field_number: Int)
}
Constructors
-
DecodeError(expected: String, found: String, path: List(String)) -
FieldNotFound(field_number: Int)
Filter for server-side event filtering on $all.
pub type ReadAllFilter {
NoFilter
EventTypePrefix(prefixes: List(String), window: FilterWindow)
EventTypeRegex(regex: String, window: FilterWindow)
StreamNamePrefix(prefixes: List(String), window: FilterWindow)
StreamNameRegex(regex: String, window: FilterWindow)
}
Constructors
-
NoFilter -
EventTypePrefix(prefixes: List(String), window: FilterWindow) -
EventTypeRegex(regex: String, window: FilterWindow) -
StreamNamePrefix(prefixes: List(String), window: FilterWindow) -
StreamNameRegex(regex: String, window: FilterWindow)
Options for read_all_events and read_all.
pub type ReadAllOptions {
ReadAllOptions(
direction: Direction,
from_position: ReadAllPosition,
max_count: Int,
resolve_links: Bool,
filter: ReadAllFilter,
)
}
Constructors
-
ReadAllOptions( direction: Direction, from_position: ReadAllPosition, max_count: Int, resolve_links: Bool, filter: ReadAllFilter, )
Starting position when reading or subscribing to $all.
pub type ReadAllPosition {
ReadAllFromStart
ReadAllFromEnd
ReadAllFromPosition(
commit_position: Int,
prepare_position: Int,
)
}
Constructors
-
ReadAllFromStart -
ReadAllFromEnd -
ReadAllFromPosition(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)
A single message from a read or subscription 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)
Options for read_stream_events and read_stream_messages.
pub type ReadStreamOptions {
ReadStreamOptions(
direction: Direction,
from_revision: ReadRevision,
max_count: Int,
resolve_links: Bool,
)
}
Constructors
-
ReadStreamOptions( direction: Direction, from_revision: ReadRevision, max_count: Int, resolve_links: Bool, )
Sans-IO transport abstraction. Backends provide open/receive/close.
pub type ReadTransport(stream, transport_error) {
ReadTransport(
open: fn(request.Request(BitArray)) -> Result(
stream,
transport_error,
),
receive: fn(stream, Int) -> Result(
#(stream, ReadTransportMessage),
transport_error,
),
close: fn(stream) -> Nil,
)
}
Constructors
-
ReadTransport( open: fn(request.Request(BitArray)) -> Result( stream, transport_error, ), receive: fn(stream, Int) -> Result( #(stream, ReadTransportMessage), transport_error, ), close: fn(stream) -> Nil, )
Raw data or stream-finished signal from a ReadTransport.
pub type ReadTransportMessage {
ReadTransportMessage(BitArray)
ReadTransportFinished
}
Constructors
-
ReadTransportMessage(BitArray) -
ReadTransportFinished
A stored event with its metadata and data.
pub type RecordedEvent {
RecordedEvent(
id: String,
stream: String,
revision: Int,
prepare_position: Int,
commit_position: Int,
metadata: List(#(String, String)),
custom_metadata: BitArray,
data: BitArray,
)
}
Constructors
-
RecordedEvent( id: String, stream: String, revision: Int, prepare_position: Int, commit_position: Int, metadata: List(#(String, String)), custom_metadata: BitArray, data: BitArray, )
Options for set_stream_metadata.
pub type SetStreamMetadataOptions {
SetStreamMetadataOptions(expected_revision: ExpectedRevision)
}
Constructors
-
SetStreamMetadataOptions(expected_revision: ExpectedRevision)
ACL roles for stream access control.
pub type StreamAcl {
StreamAcl(
read_roles: List(String),
write_roles: List(String),
delete_roles: List(String),
meta_read_roles: List(String),
meta_write_roles: List(String),
)
}
Constructors
-
StreamAcl( read_roles: List(String), write_roles: List(String), delete_roles: List(String), meta_read_roles: List(String), meta_write_roles: List(String), )
Stream metadata: system fields and custom key-value pairs.
pub type StreamMetadata {
StreamMetadata(
max_count: option.Option(Int),
max_age: option.Option(Int),
truncate_before: option.Option(Int),
cache_control: option.Option(Int),
acl: option.Option(StreamAcl),
custom: List(#(String, json.Json)),
)
}
Constructors
-
StreamMetadata( max_count: option.Option(Int), max_age: option.Option(Int), truncate_before: option.Option(Int), cache_control: option.Option(Int), acl: option.Option(StreamAcl), custom: List(#(String, json.Json)), )
Options for subscribe_to_all.
pub type SubscribeToAllOptions {
SubscribeToAllOptions(
direction: Direction,
from_position: ReadAllPosition,
resolve_links: Bool,
filter: ReadAllFilter,
)
}
Constructors
-
SubscribeToAllOptions( direction: Direction, from_position: ReadAllPosition, resolve_links: Bool, filter: ReadAllFilter, )
Options for subscribe_to_stream.
pub type SubscribeToStreamOptions {
SubscribeToStreamOptions(
direction: Direction,
from_revision: ReadRevision,
resolve_links: Bool,
)
}
Constructors
-
SubscribeToStreamOptions( direction: Direction, from_revision: ReadRevision, resolve_links: Bool, )
An active subscription returned by subscribe_to_stream or subscribe_to_all.
pub type Subscription(stream, transport_error) {
Subscription(
stream: stream,
transport: ReadTransport(stream, transport_error),
)
}
Constructors
-
Subscription( stream: stream, transport: ReadTransport(stream, transport_error), )
Options for tombstone_stream.
pub type TombstoneOptions {
TombstoneOptions(expected_revision: ExpectedRevision)
}
Constructors
-
TombstoneOptions(expected_revision: ExpectedRevision)
Values
pub fn acl_delete_roles(
acl: StreamAcl,
roles: List(String),
) -> StreamAcl
Set the delete roles on an ACL.
pub fn acl_meta_read_roles(
acl: StreamAcl,
roles: List(String),
) -> StreamAcl
Set the metadata-read roles on an ACL.
pub fn acl_meta_write_roles(
acl: StreamAcl,
roles: List(String),
) -> StreamAcl
Set the metadata-write roles on an ACL.
pub fn acl_read_roles(
acl: StreamAcl,
roles: List(String),
) -> StreamAcl
Set the read roles on an ACL.
pub fn acl_write_roles(
acl: StreamAcl,
roles: List(String),
) -> StreamAcl
Set the write roles on an ACL.
pub fn append_to_stream(
client: Client,
stream stream: String,
events events: List(Event),
options options: AppendOptions,
using send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
send_error,
),
) -> Result(Append, OperationError(send_error))
Append events to a stream. Requires a send function from the transport backend.
pub fn binary_event(
uuid id: String,
type_ type_: String,
data data: BitArray,
) -> Event
Construct an Event with raw binary data and application/octet-stream content type.
pub fn close_subscription(
subscription: Subscription(stream, transport_error),
) -> Nil
Close a subscription and release its transport resources.
pub fn default_append_options() -> AppendOptions
Default append options with expected revision set to Any.
pub fn default_delete_options() -> DeleteOptions
Default delete options with expected revision set to Any.
pub fn default_read_all_options() -> ReadAllOptions
Default read-all options: forwards, from start, max 1000, no filter, no link resolution.
pub fn default_read_stream_options() -> ReadStreamOptions
Default read-stream options: forwards, from start, max 1000, no link resolution.
pub fn default_set_stream_metadata_options() -> SetStreamMetadataOptions
Default set-stream-metadata options with expected revision set to Any.
pub fn default_subscribe_to_all_options() -> SubscribeToAllOptions
Default subscribe-to-all options: forwards, from end, no filter, no link resolution.
pub fn default_subscribe_to_stream_options() -> SubscribeToStreamOptions
Default subscribe-to-stream options: forwards, from end, no link resolution.
pub fn default_tombstone_options() -> TombstoneOptions
Default tombstone options with expected revision set to Any.
pub fn delete_expected_revision(
options: DeleteOptions,
expected_revision: ExpectedRevision,
) -> DeleteOptions
Set the expected revision on delete options.
pub fn delete_stream(
client: Client,
stream stream_name: String,
options options: DeleteOptions,
using send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
send_error,
),
) -> Result(Delete, OperationError(send_error))
Soft-delete a stream. Requires a send function from the transport backend.
pub fn expected_revision(
options: AppendOptions,
expected_revision: ExpectedRevision,
) -> AppendOptions
Set the expected revision on append options.
pub fn from_connection_string(
connection_string: String,
) -> Result(Client, @internal Error)
Construct a Client from a connection string.
The connection string format is kurrentdb://host:port?tls=true|false.
pub fn get_stream_metadata(
client: Client,
stream stream_name: String,
using transport: ReadTransport(stream, transport_error),
within timeout: Int,
) -> Result(StreamMetadata, OperationError(transport_error))
Read stream metadata from the $$<stream> metadata stream.
pub fn json_event(
uuid id: String,
event_type type_: String,
data data: json.Json,
) -> Event
Construct an Event with JSON-encoded data and application/json content type.
pub fn metadata_acl(
metadata: StreamMetadata,
acl: StreamAcl,
) -> StreamMetadata
Set the ACL on stream metadata.
pub fn metadata_cache_control(
metadata: StreamMetadata,
cache_control: Int,
) -> StreamMetadata
Set $cacheControl (in seconds) on stream metadata.
pub fn metadata_custom(
metadata: StreamMetadata,
key: String,
value: json.Json,
) -> StreamMetadata
Add a custom key-value field to stream metadata.
pub fn metadata_expected_revision(
options: SetStreamMetadataOptions,
expected_revision: ExpectedRevision,
) -> SetStreamMetadataOptions
Set the expected revision on stream metadata options.
pub fn metadata_max_age(
metadata: StreamMetadata,
max_age: Int,
) -> StreamMetadata
Set $maxAge (in seconds) on stream metadata.
pub fn metadata_max_count(
metadata: StreamMetadata,
max_count: Int,
) -> StreamMetadata
Set $maxCount on stream metadata.
pub fn metadata_truncate_before(
metadata: StreamMetadata,
truncate_before: Int,
) -> StreamMetadata
Set $tb (truncate before) revision on stream metadata.
pub fn read_all(
client: Client,
options options: ReadAllOptions,
using transport: ReadTransport(stream, transport_error),
within timeout: Int,
) -> Result(List(ReadMessage), OperationError(transport_error))
Read all messages from $all, including checkpoints.
pub fn read_all_direction(
options: ReadAllOptions,
direction: Direction,
) -> ReadAllOptions
Set the read direction for reading $all.
pub fn read_all_events(
client: Client,
options options: ReadAllOptions,
using transport: ReadTransport(stream, transport_error),
within timeout: Int,
) -> Result(List(ReadEvent), OperationError(transport_error))
Read events from $all, returning only ReadEvent variants.
pub fn read_all_filter(
options: ReadAllOptions,
filter: ReadAllFilter,
) -> ReadAllOptions
Set the server-side filter when reading $all.
pub fn read_all_from_position(
options: ReadAllOptions,
position: ReadAllPosition,
) -> ReadAllOptions
Set the starting position for reading $all.
pub fn read_all_max_count(
options: ReadAllOptions,
max_count: Int,
) -> ReadAllOptions
Set the maximum number of events to read from $all.
pub fn read_all_resolve_links(
options: ReadAllOptions,
resolve_links: Bool,
) -> ReadAllOptions
Enable or disable link resolution when reading $all.
pub fn read_stream_events(
client: Client,
stream stream_name: String,
options options: ReadStreamOptions,
using transport: ReadTransport(stream, transport_error),
within timeout: Int,
) -> Result(List(ReadEvent), OperationError(transport_error))
Read events from a stream, returning only ReadEvent variants.
pub fn read_stream_from_revision(
options: ReadStreamOptions,
revision: ReadRevision,
) -> ReadStreamOptions
Set the revision to start reading from.
pub fn read_stream_max_count(
options: ReadStreamOptions,
max_count: Int,
) -> ReadStreamOptions
Set the maximum number of events to read.
pub fn read_stream_messages(
client: Client,
stream stream: String,
options options: ReadStreamOptions,
using transport: ReadTransport(stream, transport_error),
within timeout: Int,
) -> Result(List(ReadMessage), OperationError(transport_error))
Read all messages from a stream, including checkpoints and subscription lifecycle signals.
pub fn read_stream_read_direction(
options: ReadStreamOptions,
direction: Direction,
) -> ReadStreamOptions
Set the read direction for a stream read.
pub fn read_stream_resolve_links(
options: ReadStreamOptions,
resolve_links: Bool,
) -> ReadStreamOptions
Enable or disable link-to-event resolution.
pub fn receive_subscription_event(
subscription: Subscription(stream, transport_error),
within timeout: Int,
) -> Result(
#(Subscription(stream, transport_error), ReadEvent),
OperationError(transport_error),
)
Receive the next ReadEvent from a subscription, skipping other message types.
pub fn receive_subscription_message(
subscription: Subscription(stream, transport_error),
within timeout: Int,
) -> Result(
#(Subscription(stream, transport_error), ReadMessage),
OperationError(transport_error),
)
Receive the next message from a subscription, returning the updated subscription.
pub fn set_stream_metadata(
client: Client,
stream stream_name: String,
metadata metadata: StreamMetadata,
uuid id: String,
options options: SetStreamMetadataOptions,
using send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
send_error,
),
) -> Result(Append, OperationError(send_error))
Set stream metadata by writing a $metadata event. Requires a send function.
The id is a caller-supplied UUID string.
pub fn stream_metadata() -> StreamMetadata
Construct a StreamMetadata with all system fields absent.
pub fn subscribe_to_all(
client: Client,
options options: SubscribeToAllOptions,
using transport: ReadTransport(stream, transport_error),
) -> Result(
Subscription(stream, transport_error),
OperationError(transport_error),
)
Subscribe to $all, returning an active Subscription.
Use receive_subscription_message or receive_subscription_event to consume messages.
pub fn subscribe_to_all_direction(
options: SubscribeToAllOptions,
direction: Direction,
) -> SubscribeToAllOptions
Set the read direction for a subscription to $all.
pub fn subscribe_to_all_filter(
options: SubscribeToAllOptions,
filter: ReadAllFilter,
) -> SubscribeToAllOptions
Set the server-side filter for a subscription to $all.
pub fn subscribe_to_all_from_position(
options: SubscribeToAllOptions,
position: ReadAllPosition,
) -> SubscribeToAllOptions
Set the starting position for a subscription to $all.
pub fn subscribe_to_all_resolve_links(
options: SubscribeToAllOptions,
resolve_links: Bool,
) -> SubscribeToAllOptions
Enable or disable link resolution for a subscription to $all.
pub fn subscribe_to_stream(
client: Client,
stream stream_name: String,
options options: SubscribeToStreamOptions,
using transport: ReadTransport(stream, transport_error),
) -> Result(
Subscription(stream, transport_error),
OperationError(transport_error),
)
Subscribe to a single stream, returning an active Subscription.
The subscription is ready to use immediately. Call receive_subscription_message
or receive_subscription_event to consume the first message.
pub fn subscribe_to_stream_from_revision(
options: SubscribeToStreamOptions,
revision: ReadRevision,
) -> SubscribeToStreamOptions
Set the revision to subscribe from.
pub fn subscribe_to_stream_read_direction(
options: SubscribeToStreamOptions,
direction: Direction,
) -> SubscribeToStreamOptions
Set the read direction for a subscription.
pub fn subscribe_to_stream_resolve_links(
options: SubscribeToStreamOptions,
resolve_links: Bool,
) -> SubscribeToStreamOptions
Enable or disable link resolution for a subscription.
pub fn tombstone_expected_revision(
options: TombstoneOptions,
expected_revision: ExpectedRevision,
) -> TombstoneOptions
Set the expected revision on tombstone options.
pub fn tombstone_stream(
client: Client,
stream stream_name: String,
options options: TombstoneOptions,
using send: fn(request.Request(BitArray)) -> Result(
response.Response(BitArray),
send_error,
),
) -> Result(Tombstone, OperationError(send_error))
Permanently delete a stream (tombstone). Requires a send function.