Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CosmosStore): Expose ISyncContext.SessionToken #195

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The `Unreleased` section name is replaced by the expected version of next releas
### Added

- now targets `Microsoft.Azure.Cosmos` v `3.1.1` (instead of `Microsoft.Azure.DocumentDB`[`.Core`] v 2.x) [#144](https://github.com/jet/equinox/pull/144)
- `Core.ISyncContext.SessionToken`: Allows one to inspect the `SessionToken` for relevant stores (i.e., `CosmosDB`), after loading and/or syncing has concluded [#195](https://github.com/jet/equinox/pull/195)

### Changed

Expand Down
5 changes: 3 additions & 2 deletions src/Equinox.Cosmos/Cosmos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,9 @@ module internal Tip =
type [<NoComparison>] Token = { container: Container; stream: string; pos: Position }
module Token =
let create (container,stream) pos : StreamToken =
{ value = box { container = container; stream = stream; pos = pos }
version = pos.index }
{ value = box { container = container; stream = stream; pos = pos }
version = pos.index
sessionToken = null }
let (|Unpack|) (token: StreamToken) : Container*string*Position = let t = unbox<Token> token.value in t.container,t.stream,t.pos
let supersedes (Unpack (_,_,currentPos)) (Unpack (_,_,xPos)) =
let currentVersion, newVersion = currentPos.index, xPos.index
Expand Down
1 change: 0 additions & 1 deletion src/Equinox.Cosmos/Equinox.Cosmos.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="2.0.0" PrivateAssets="All" />

Expand Down
3 changes: 2 additions & 1 deletion src/Equinox.EventStore/EventStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ module Token =
{ value = box {
stream = { name = streamName}
pos = { streamVersion = streamVersion; compactionEventNumber = compactionEventNumber; batchCapacityLimit = batchCapacityLimit } }
version = streamVersion }
version = streamVersion
sessionToken = null }

/// No batching / compaction; we only need to retain the StreamVersion
let ofNonCompacting streamName streamVersion : StreamToken =
Expand Down
3 changes: 2 additions & 1 deletion src/Equinox.MemoryStore/MemoryStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ module private Token =

let private streamTokenOfIndex streamName (streamVersion : int) : StreamToken =
{ value = box { streamName = streamName; streamVersion = streamVersion }
version = int64 streamVersion }
version = int64 streamVersion
sessionToken = null }
let (|Unpack|) (token: StreamToken) : Token = unbox<Token> token.value
/// Represent a stream known to be empty
let ofEmpty streamName initial = streamTokenOfIndex streamName -1, initial
Expand Down
3 changes: 2 additions & 1 deletion src/Equinox.SqlStreamStore/SqlStreamStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ module Token =
{ value = box {
stream = { name = streamName}
pos = { streamVersion = streamVersion; compactionEventNumber = compactionEventNumber; batchCapacityLimit = batchCapacityLimit } }
version = streamVersion }
version = streamVersion
sessionToken = null }
/// No batching / compaction; we only need to retain the StreamVersion
let ofNonCompacting streamName streamVersion : StreamToken =
create None None streamName streamVersion
Expand Down
7 changes: 6 additions & 1 deletion src/Equinox/Flow.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Serilog

/// Store-specific opaque token to be used for synchronization purposes
[<NoComparison>]
type StreamToken = { value : obj; version: int64 }
type StreamToken = { value : obj; version: int64; sessionToken : string }

/// Internal type used to represent the outcome of a TrySync operation
[<NoEquality; NoComparison; RequireQualifiedAccess>]
Expand Down Expand Up @@ -36,6 +36,10 @@ type ISyncContext<'state> =
/// Exposes the underlying Store's internal Version/Index (which, depending on the Codec, may or may not be reflected in the last event presented)
abstract member Version : int64

/// Exposes the underlying Store's internal SessionToken
// (relevant to CosmosDB)
abstract member SessionToken : string

/// The present State of the stream within the context of this Flow
abstract member State : 'state

Expand All @@ -61,6 +65,7 @@ module internal Flow =
member __.CreateMemento() = tokenAndState
member __.State = snd tokenAndState
member __.Version = (fst tokenAndState).version
member __.SessionToken = (fst tokenAndState).sessionToken

member __.TryWithoutResync(log : ILogger, events) : Async<bool> =
trySyncOr log events (fun _resync -> async { return false })
Expand Down