Skip to content

Commit

Permalink
Cosmos: Add t:DateTimeOffset to unfolds
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Jan 20, 2020
1 parent 65d510d commit aa199f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ The `Unreleased` section name is replaced by the expected version of next releas
- `eqx dump` perf + logging improvements
- `eqx dump -P` turns off JSON pretty printing
- `Cosmos`: `Tip 200` now logs received `n` and `_etag` values
- `Cosmos`: Unfolds now write and return `t` (creation `DateTimeOffset.UtcNow`)
- `EventStore`: Add missing optional parameters for `Connector`: `gossipTimeout` and `clientConnectionTimeout` [#186](https://github.com/jet/equinox/pull/186) :pray: [@AndrewRublyov](https://github.com/AndrewRublyov)

### Changed

- `SqlStreamStore`.*: Target `SqlStreamStore` v `1.2.0-beta.8`
- Target `FsCodec` v `2.0.0-rc1`
- Target `Microsoft.SourceLink.GitHub`, `Microsoft.NETFramework.ReferenceAssemblies` v `1.0.0`
- Samples etc target `Argu` v `6.0.0`
- `eqx dump`'s `-J` switch now turns off JSON rendering
- `eqx -C dump` now renders Store `.Information` logs
- Samples consistently use `module Fold`, `(Events.ForX streamId)`, removed `(|Stream|)` [#174](https://github.com/jet/equinox/pull/174)
- Target `FsCodec` v `2.0.0-rc1`
- `SqlStreamStore`.*: Target `SqlStreamStore` v `1.2.0-beta.8`

### Removed

Expand Down
7 changes: 5 additions & 2 deletions src/Equinox.Cosmos/Cosmos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type Unfold =
{ /// Base: Stream Position (Version) of State from which this Unfold Event was generated
i: int64

/// Generation datetime
t: DateTimeOffset // ISO 8601 // Not written by versions <= 2.0.0-rc9

/// The Case (Event Type) of this compaction/snapshot, used to drive deserialization
c: string // required

Expand Down Expand Up @@ -199,7 +202,7 @@ type internal Enum() =
Enum.Events(b.i, b.e, startPos, direction)
|> if direction = Direction.Backward then System.Linq.Enumerable.Reverse else id
static member Unfolds(xs: Unfold[]) : ITimelineEvent<byte[]> seq = seq {
for x in xs -> FsCodec.Core.TimelineEvent.Create(x.i, x.c, x.d, x.m, null, null, DateTimeOffset.MinValue, isUnfold=true) }
for x in xs -> FsCodec.Core.TimelineEvent.Create(x.i, x.c, x.d, x.m, null, null, x.t, isUnfold=true) }
static member EventsAndUnfolds(x: Tip): ITimelineEvent<byte[]> seq =
Enum.Events x
|> Seq.append (Enum.Unfolds x.u)
Expand Down Expand Up @@ -503,7 +506,7 @@ function sync(req, expIndex, expEtag) {
e = [| for e in events -> { t = e.Timestamp; c = e.EventType; d = e.Data; m = e.Meta; correlationId = e.CorrelationId; causationId = e.CausationId } |]
u = Array.ofSeq unfolds }
let mkUnfold baseIndex (unfolds: IEventData<_> seq) : Unfold seq =
unfolds |> Seq.mapi (fun offset x -> { i = baseIndex + int64 offset; c = x.EventType; d = x.Data; m = x.Meta } : Unfold)
unfolds |> Seq.mapi (fun offset x -> { i = baseIndex + int64 offset; c = x.EventType; d = x.Data; m = x.Meta; t = DateTimeOffset.UtcNow } : Unfold)

module Initialization =
open System.Linq
Expand Down
6 changes: 4 additions & 2 deletions tests/Equinox.Cosmos.Integration/JsonConverterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type Base64ZipUtf8Tests() =
{ i = 42L
c = encoded.EventType
d = encoded.Data
m = null }
m = null
t = DateTimeOffset.MinValue }
let res = JsonConvert.SerializeObject e
test <@ res.Contains("\"d\":\"") && res.Length < 100 @>

Expand All @@ -42,7 +43,8 @@ type Base64ZipUtf8Tests() =
{ i = 42L
c = encoded.EventType
d = encoded.Data
m = null }
m = null
t = DateTimeOffset.MinValue }
let ser = JsonConvert.SerializeObject(e)
test <@ ser.Contains("\"d\":\"") @>
let des = JsonConvert.DeserializeObject<Store.Unfold>(ser)
Expand Down

0 comments on commit aa199f9

Please sign in to comment.