From aa199f97932827e9aefbf5cf3d3b34af1fb79086 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sat, 18 Jan 2020 10:17:12 +0000 Subject: [PATCH] Cosmos: Add t:DateTimeOffset to unfolds --- CHANGELOG.md | 5 +++-- src/Equinox.Cosmos/Cosmos.fs | 7 +++++-- tests/Equinox.Cosmos.Integration/JsonConverterTests.fs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78c3355c5..ae8bc1a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Equinox.Cosmos/Cosmos.fs b/src/Equinox.Cosmos/Cosmos.fs index 74fbdd742..870a3ffc0 100644 --- a/src/Equinox.Cosmos/Cosmos.fs +++ b/src/Equinox.Cosmos/Cosmos.fs @@ -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 @@ -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 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 seq = Enum.Events x |> Seq.append (Enum.Unfolds x.u) @@ -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 diff --git a/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs b/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs index 2674c3384..59b6e8867 100644 --- a/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs +++ b/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs @@ -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 @> @@ -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(ser)