Skip to content

Commit

Permalink
Rename Equinox.Cosmos.Core.Context -> EventsContext
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Sep 28, 2020
1 parent ac30f48 commit c581429
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The `Unreleased` section name is replaced by the expected version of next releas
- `Cosmos:` Removed [warmup call](https://github.com/Azure/azure-cosmos-dotnet-v3/issues/1436)
- Rename `Equinox.Cosmos` DLL and namespace to `Equinox.CosmosStore` [#243](https://github.com/jet/equinox/pull/243)
- Rename `Equinox.Cosmos.Store` -> `Equinox.CosmosStore.Core`
- Rename `Equinox.Cosmos.Core.Context` -> `Equinox.CosmosStore.Core.EventsContext`
- target `EventStore.Client` v `20.6` (instead of v `5.0.x`) [#224](https://github.com/jet/equinox/pull/224)
- Retarget `netcoreapp2.1` apps to `netcoreapp3.1` with `SystemTextJson`
- Retarget Todobackend to `aspnetcore` v `3.1`
Expand Down
2 changes: 1 addition & 1 deletion DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ let cnx =
// alternately use the overload that defers the mapping until the stream one is
// writing to becomes clear
let containerMap = Containers("databaseName", "containerName")
let ctx = Context(cnx, containerMap, gatewayLog)
let ctx = EventsContext(cnx, containerMap, gatewayLog)
//
// Write an event
Expand Down
18 changes: 9 additions & 9 deletions src/Equinox.CosmosStore/CosmosStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ type AppendResult<'t> =
| ConflictUnknown of index: 't

/// Encapsulates the core facilities Equinox.CosmosStore offers for operating directly on Events in Streams.
type Context
type EventsContext
( /// Connection to CosmosDb, includes defined Transient Read and Write Retry policies
conn : Connection,
/// Container selector, mapping Stream Categories to Containers
Expand Down Expand Up @@ -1421,49 +1421,49 @@ module Events =
/// reading in batches of the specified size.
/// Returns an empty sequence if the stream is empty or if the sequence number is larger than the largest
/// sequence number in the stream.
let getAll (ctx: Context) (streamName: string) (MinPosition index: int64) (batchSize: int): FSharp.Control.AsyncSeq<ITimelineEvent<byte[]>[]> =
let getAll (ctx: EventsContext) (streamName: string) (MinPosition index: int64) (batchSize: int): FSharp.Control.AsyncSeq<ITimelineEvent<byte[]>[]> =
ctx.Walk(ctx.CreateStream streamName, batchSize, ?position=index)

/// Returns an async array of events in the stream starting at the specified sequence number,
/// number of events to read is specified by batchSize
/// Returns an empty sequence if the stream is empty or if the sequence number is larger than the largest
/// sequence number in the stream.
let get (ctx: Context) (streamName: string) (MinPosition index: int64) (maxCount: int): Async<ITimelineEvent<byte[]>[]> =
let get (ctx: EventsContext) (streamName: string) (MinPosition index: int64) (maxCount: int): Async<ITimelineEvent<byte[]>[]> =
ctx.Read(ctx.CreateStream streamName, ?position=index, maxCount=maxCount) |> dropPosition

/// Appends a batch of events to a stream at the specified expected sequence number.
/// If the specified expected sequence number does not match the stream, the events are not appended
/// and a failure is returned.
let append (ctx: Context) (streamName: string) (index: int64) (events: IEventData<_>[]): Async<AppendResult<int64>> =
let append (ctx: EventsContext) (streamName: string) (index: int64) (events: IEventData<_>[]): Async<AppendResult<int64>> =
ctx.Sync(ctx.CreateStream streamName, Position.fromI index, events) |> stripSyncResult

/// Appends a batch of events to a stream at the the present Position without any conflict checks.
/// NB typically, it is recommended to ensure idempotency of operations by using the `append` and related API as
/// this facilitates ensuring consistency is maintained, and yields reduced latency and Request Charges impacts
/// (See equivalent APIs on `Context` that yield `Position` values)
let appendAtEnd (ctx: Context) (streamName: string) (events: IEventData<_>[]): Async<int64> =
let appendAtEnd (ctx: EventsContext) (streamName: string) (events: IEventData<_>[]): Async<int64> =
ctx.NonIdempotentAppend(ctx.CreateStream streamName, events) |> stripPosition

/// Requests deletion of events prior to the specified Index
/// Due to the need to preserve ordering of data in the stream, only full batches will be removed
/// Returns count of events deleted this time, events that could not be deleted due to partial batches, and the stream's lowest remaining sequence number
let prune (ctx: Context) (streamName: string) (beforeIndex: int64): Async<int * int * int64> =
let prune (ctx: EventsContext) (streamName: string) (beforeIndex: int64): Async<int * int * int64> =
ctx.Prune(ctx.CreateStream streamName, beforeIndex)

/// Returns an async sequence of events in the stream backwards starting from the specified sequence number,
/// reading in batches of the specified size.
/// Returns an empty sequence if the stream is empty or if the sequence number is smaller than the smallest
/// sequence number in the stream.
let getAllBackwards (ctx: Context) (streamName: string) (MaxPosition index: int64) (batchSize: int): AsyncSeq<ITimelineEvent<byte[]>[]> =
let getAllBackwards (ctx: EventsContext) (streamName: string) (MaxPosition index: int64) (batchSize: int): AsyncSeq<ITimelineEvent<byte[]>[]> =
ctx.Walk(ctx.CreateStream streamName, batchSize, ?position=index, direction=Direction.Backward)

/// Returns an async array of events in the stream backwards starting from the specified sequence number,
/// number of events to read is specified by batchSize
/// Returns an empty sequence if the stream is empty or if the sequence number is smaller than the smallest
/// sequence number in the stream.
let getBackwards (ctx: Context) (streamName: string) (MaxPosition index: int64) (maxCount: int): Async<ITimelineEvent<byte[]>[]> =
let getBackwards (ctx: EventsContext) (streamName: string) (MaxPosition index: int64) (maxCount: int): Async<ITimelineEvent<byte[]>[]> =
ctx.Read(ctx.CreateStream streamName, ?position=index, maxCount=maxCount, direction=Direction.Backward) |> dropPosition

/// Obtains the `index` from the current write Position
let getNextIndex (ctx: Context) (streamName: string) : Async<int64> =
let getNextIndex (ctx: EventsContext) (streamName: string) : Async<int64> =
ctx.Sync(ctx.CreateStream streamName) |> stripPosition
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Tests(testOutputHelper) =
incr testIterations
sprintf "events-%O-%i" name !testIterations
let mkContextWithItemLimit conn defaultBatchSize =
Context(conn,containers,log,?defaultMaxItems=defaultBatchSize)
EventsContext(conn,containers,log,?defaultMaxItems=defaultBatchSize)
let mkContext conn = mkContextWithItemLimit conn None

let verifyRequestChargesMax rus =
Expand Down

0 comments on commit c581429

Please sign in to comment.