Skip to content

Commit 9869cb9

Browse files
authored
CosmosStore: Switch to JsonElement bodies (#305)
1 parent 0b1304a commit 9869cb9

24 files changed

Lines changed: 156 additions & 121 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ The `Unreleased` section name is replaced by the expected version of next releas
1313

1414
- `eqx`/`Equinox.Tool`: Flip `-P` option to opt _in_ to pretty printing [#313](https://github.com/jet/equinox/pull/313)
1515
- `CosmosStore`: Require `Microsoft.Azure.Cosmos` v `3.0.25` [#310](https://github.com/jet/equinox/pull/310)
16+
- `CosmosStore`: Switch to natively using `JsonElement` event bodies [#305](https://github.com/jet/equinox/pull/305) :pray: [@ylibrach](https://github.com/ylibrach)
17+
- `CosmosStore`: Switch to natively using `System.Text.Json` for serialization of all `Microsoft.Azure.Cosmos` round-trips [#305](https://github.com/jet/equinox/pull/305) :pray: [@ylibrach](https://github.com/ylibrach)
18+
- `CosmosStore`: Only log `bytes` when log level is `Debug` [#305](https://github.com/jet/equinox/pull/305)
1619
- `SqlStreamStore`.*: Target `SqlStreamStore` v `1.2.0` (`Postgres` remains at `1.2.0-beta.8` as that's the last released version) [#227](https://github.com/jet/equinox/pull/227) :pray: [@rajivhost](https://github.com/rajivhost)
1720
- Update all non-Client dependencies except `FSharp.Core`, `FSharp.Control.AsyncSeq` [#310](https://github.com/jet/equinox/pull/310)
1821

azure-pipelines.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
name: $(Rev:r)
2-
trigger:
3-
- master
4-
- main
5-
- refs/tags/*
62
jobs:
73
- job: Windows
84
pool:

samples/Infrastructure/Services.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Samples.Infrastructure.Services
22

33
open Domain
4+
open FsCodec.SystemTextJson
45
open Microsoft.Extensions.DependencyInjection
56
open System
67

@@ -13,7 +14,7 @@ type StreamResolver(storage) =
1314
match storage with
1415
| Storage.StorageConfig.Cosmos (store, caching, unfolds) ->
1516
let accessStrategy = if unfolds then Equinox.CosmosStore.AccessStrategy.Snapshot snapshot else Equinox.CosmosStore.AccessStrategy.Unoptimized
16-
Equinox.CosmosStore.CosmosStoreCategory<'event,'state,_>(store, codec, fold, initial, caching, accessStrategy).Resolve
17+
Equinox.CosmosStore.CosmosStoreCategory<'event,'state,_>(store, codec.ToJsonElementCodec(), fold, initial, caching, accessStrategy).Resolve
1718
| Storage.StorageConfig.Es (context, caching, unfolds) ->
1819
let accessStrategy = if unfolds then Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot |> Some else None
1920
Equinox.EventStore.EventStoreCategory<'event,'state,_>(context, codec, fold, initial, ?caching = caching, ?access = accessStrategy).Resolve

samples/Store/Domain/Cart.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Events =
2525
| ItemPropertiesChanged of ItemPropertiesChangedInfo
2626
interface TypeShape.UnionContract.IUnionContract
2727
let codec = FsCodec.NewtonsoftJson.Codec.Create<Event>()
28+
let codecStj = FsCodec.SystemTextJson.Codec.Create<Event>()
2829

2930
module Fold =
3031

samples/Store/Domain/ContactPreferences.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Events =
1313
| [<System.Runtime.Serialization.DataMember(Name = "contactPreferencesChanged")>]Updated of Value
1414
interface TypeShape.UnionContract.IUnionContract
1515
let codec = FsCodec.NewtonsoftJson.Codec.Create<Event>()
16+
let codecStj = FsCodec.SystemTextJson.Codec.Create<Event>()
1617

1718
module Fold =
1819

samples/Store/Domain/Domain.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<PackageReference Include="FSharp.Core" Version="4.3.4" />
2323

2424
<PackageReference Include="FsCodec.NewtonsoftJson" Version="2.3.1" />
25+
<PackageReference Include="FsCodec.SystemTextJson" Version="2.3.1" />
2526

2627
<ProjectReference Include="..\..\..\src\Equinox\Equinox.fsproj" />
2728
</ItemGroup>

samples/Store/Domain/Favorites.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Events =
1515
| Unfavorited of Unfavorited
1616
interface TypeShape.UnionContract.IUnionContract
1717
let codec = FsCodec.NewtonsoftJson.Codec.Create<Event>()
18+
let codecStj = FsCodec.SystemTextJson.Codec.Create<Event>()
1819

1920
module Fold =
2021

samples/Store/Domain/Infrastructure.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Guid =
3232
/// - Ensures canonical rendering without dashes via ToString + Newtonsoft.Json
3333
/// - Guards against XSS by only permitting initialization based on Guid.Parse
3434
/// - Implements comparison/equality solely to enable tests to leverage structural equality
35-
[<Sealed; AutoSerializable(false); JsonConverter(typeof<SkuIdJsonConverter>)>]
35+
[<Sealed; AutoSerializable(false); JsonConverter(typeof<SkuIdJsonConverter>); System.Text.Json.Serialization.JsonConverter(typeof<SkuIdJsonConverterStj>)>]
3636
type SkuId private (id : string) =
3737
inherit StringId<SkuId>(id)
3838
new(value : Guid) = SkuId(value.ToString "N")
@@ -45,6 +45,10 @@ and private SkuIdJsonConverter() =
4545
override __.Pickle value = string value
4646
/// Input must be a `Guid.Parse`able value
4747
override __.UnPickle input = Guid.Parse input |> SkuId
48+
and private SkuIdJsonConverterStj() =
49+
inherit FsCodec.SystemTextJson.JsonIsomorphism<SkuId, string>()
50+
override _.Pickle value = string value
51+
override _.UnPickle input = Guid.Parse input |> SkuId
4852

4953
/// RequestId strongly typed id, represented internally as a string
5054
/// - Ensures canonical rendering without dashes via ToString, Newtonsoft.Json, sprintf "%s" etc

samples/Store/Integration/CartIntegration.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ let createServiceMemory log store =
1515
Cart.create log (fun (id,opt) -> MemoryStore.MemoryStoreCategory(store, Domain.Cart.Events.codec, fold, initial).Resolve(id,?option=opt))
1616

1717
let codec = Cart.Events.codec
18+
let codecStj = Cart.Events.codecStj
1819

1920
let resolveGesStreamWithRollingSnapshots context =
2021
fun (id,opt) -> EventStore.EventStoreCategory(context, codec, fold, initial, access = EventStore.AccessStrategy.RollingSnapshots snapshot).Resolve(id,?option=opt)
2122
let resolveGesStreamWithoutCustomAccessStrategy context =
2223
fun (id,opt) -> EventStore.EventStoreCategory(context, codec, fold, initial).Resolve(id,?option=opt)
2324

2425
let resolveCosmosStreamWithSnapshotStrategy context =
25-
fun (id,opt) -> CosmosStore.CosmosStoreCategory(context, codec, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Snapshot snapshot).Resolve(id,?option=opt)
26+
fun (id,opt) -> CosmosStore.CosmosStoreCategory(context, codecStj, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Snapshot snapshot).Resolve(id,?option=opt)
2627
let resolveCosmosStreamWithoutCustomAccessStrategy context =
27-
fun (id,opt) -> CosmosStore.CosmosStoreCategory(context, codec, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Unoptimized).Resolve(id,?option=opt)
28+
fun (id,opt) -> CosmosStore.CosmosStoreCategory(context, codecStj, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Unoptimized).Resolve(id,?option=opt)
2829

2930
let addAndThenRemoveItemsManyTimesExceptTheLastOne context cartId skuId (service: Cart.Service) count =
3031
service.ExecuteManyAsync(cartId, false, seq {

samples/Store/Integration/ContactPreferencesIntegration.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ let createServiceMemory log store =
1414
ContactPreferences.create log (MemoryStore.MemoryStoreCategory(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve)
1515

1616
let codec = ContactPreferences.Events.codec
17+
let codecStj = ContactPreferences.Events.codecStj
1718
let resolveStreamGesWithOptimizedStorageSemantics context =
1819
EventStore.EventStoreCategory(context 1, codec, fold, initial, access = EventStore.AccessStrategy.LatestKnownEvent).Resolve
1920
let resolveStreamGesWithoutAccessStrategy context =
2021
EventStore.EventStoreCategory(context defaultBatchSize, codec, fold, initial).Resolve
2122

2223
let resolveStreamCosmosWithLatestKnownEventSemantics context =
23-
CosmosStore.CosmosStoreCategory(context, codec, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.LatestKnownEvent).Resolve
24+
CosmosStore.CosmosStoreCategory(context, codecStj, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.LatestKnownEvent).Resolve
2425
let resolveStreamCosmosUnoptimized context =
25-
CosmosStore.CosmosStoreCategory(context, codec, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Unoptimized).Resolve
26+
CosmosStore.CosmosStoreCategory(context, codecStj, fold, initial, CosmosStore.CachingStrategy.NoCaching, CosmosStore.AccessStrategy.Unoptimized).Resolve
2627
let resolveStreamCosmosRollingUnfolds context =
2728
let access = CosmosStore.AccessStrategy.Custom(ContactPreferences.Fold.isOrigin, ContactPreferences.Fold.transmute)
28-
CosmosStore.CosmosStoreCategory(context, codec, fold, initial, CosmosStore.CachingStrategy.NoCaching, access).Resolve
29+
CosmosStore.CosmosStoreCategory(context, codecStj, fold, initial, CosmosStore.CachingStrategy.NoCaching, access).Resolve
2930

3031
type Tests(testOutputHelper) =
3132
let testOutput = TestOutputAdapter testOutputHelper

0 commit comments

Comments
 (0)