diff --git a/samples/Infrastructure/Services.fs b/samples/Infrastructure/Services.fs
index b7e0c2623..14531e341 100644
--- a/samples/Infrastructure/Services.fs
+++ b/samples/Infrastructure/Services.fs
@@ -2,7 +2,6 @@
open Domain
open FsCodec
-open FsCodec.SystemTextJson.Serialization
open Microsoft.Extensions.DependencyInjection
open System
open System.Text.Json
@@ -49,24 +48,24 @@ type ServiceBuilder(storageConfig, handlerLog) =
let snapshot = Favorites.Fold.isOrigin,Favorites.Fold.snapshot
match storageConfig with
- | Storage.StorageConfig.Cosmos _ -> Backend.Favorites.Service(handlerLog, resolver.ResolveWithJsonElementCodec(Favorites.Events.JsonElementCodec.codec JsonSerializer.defaultOptions, fold, initial, snapshot))
- | _ -> Backend.Favorites.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(Favorites.Events.Utf8ArrayCodec.codec, fold, initial, snapshot))
+ | Storage.StorageConfig.Cosmos _ -> Backend.Favorites.Service(handlerLog, resolver.ResolveWithJsonElementCodec(Favorites.Events.codecStj, fold, initial, snapshot))
+ | _ -> Backend.Favorites.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(Favorites.Events.codecNewtonsoft, fold, initial, snapshot))
member __.CreateSaveForLaterService() =
let fold, initial = SavedForLater.Fold.fold, SavedForLater.Fold.initial
let snapshot = SavedForLater.Fold.isOrigin,SavedForLater.Fold.compact
match storageConfig with
- | Storage.StorageConfig.Cosmos _ -> Backend.SavedForLater.Service(handlerLog, resolver.ResolveWithJsonElementCodec(SavedForLater.Events.JsonElementCodec.codec JsonSerializer.defaultOptions,fold,initial,snapshot), maxSavedItems=50)
- | _ -> Backend.SavedForLater.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(SavedForLater.Events.Utf8ArrayCodec.codec,fold,initial,snapshot), maxSavedItems=50)
+ | Storage.StorageConfig.Cosmos _ -> Backend.SavedForLater.Service(handlerLog, resolver.ResolveWithJsonElementCodec(SavedForLater.Events.codecStj,fold,initial,snapshot), maxSavedItems=50)
+ | _ -> Backend.SavedForLater.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(SavedForLater.Events.codecNewtonsoft,fold,initial,snapshot), maxSavedItems=50)
member __.CreateTodosService() =
let fold, initial = TodoBackend.Fold.fold, TodoBackend.Fold.initial
let snapshot = TodoBackend.Fold.isOrigin, TodoBackend.Fold.snapshot
match storageConfig with
- | Storage.StorageConfig.Cosmos _ -> TodoBackend.Service(handlerLog, resolver.ResolveWithJsonElementCodec(TodoBackend.Events.JsonElementCodec.codec JsonSerializer.defaultOptions,fold,initial,snapshot))
- | _ -> TodoBackend.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(TodoBackend.Events.Utf8ArrayCodec.codec,fold,initial,snapshot))
+ | Storage.StorageConfig.Cosmos _ -> TodoBackend.Service(handlerLog, resolver.ResolveWithJsonElementCodec(TodoBackend.Events.codecStj,fold,initial,snapshot))
+ | _ -> TodoBackend.Service(handlerLog, resolver.ResolveWithUtf8ArrayCodec(TodoBackend.Events.codecNewtonsoft,fold,initial,snapshot))
let register (services : IServiceCollection, storageConfig, handlerLog) =
let regF (factory : IServiceProvider -> 'T) = services.AddSingleton<'T>(fun (sp: IServiceProvider) -> factory sp) |> ignore
diff --git a/samples/Store/Backend/Backend.fsproj b/samples/Store/Backend/Backend.fsproj
index fec9bcd4f..0288582cb 100644
--- a/samples/Store/Backend/Backend.fsproj
+++ b/samples/Store/Backend/Backend.fsproj
@@ -1,7 +1,7 @@
- netstandard2.0;net461
+ netstandard2.1
5
false
true
@@ -23,8 +23,7 @@
-
-
+
\ No newline at end of file
diff --git a/samples/Store/Domain/Cart.fs b/samples/Store/Domain/Cart.fs
index bf6ce47e2..ecaf1c059 100644
--- a/samples/Store/Domain/Cart.fs
+++ b/samples/Store/Domain/Cart.fs
@@ -25,33 +25,8 @@ module Events =
| ItemWaiveReturnsChanged of ItemWaiveReturnsInfo
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) =
- fun (evt: Event) ->
- match evt with
- | Snapshotted state -> "Snapshotted", JsonSerializer.SerializeToElement(state, options)
- | ItemAdded addInfo -> "ItemAdded", JsonSerializer.SerializeToElement(addInfo, options)
- | ItemRemoved removeInfo -> "ItemRemoved", JsonSerializer.SerializeToElement(removeInfo, options)
- | ItemQuantityChanged changeInfo -> "ItemQuantityChanged", JsonSerializer.SerializeToElement(changeInfo, options)
- | ItemWaiveReturnsChanged waiveInfo -> "ItemWaiveReturnsChanged", JsonSerializer.SerializeToElement(waiveInfo, options)
-
- let private tryDecode (options: JsonSerializerOptions) =
- fun (eventType, data: JsonElement) ->
- match eventType with
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement(data, options))
- | "ItemAdded" -> Some (ItemAdded <| JsonSerializer.DeserializeElement(data, options))
- | "ItemRemoved" -> Some (ItemRemoved <| JsonSerializer.DeserializeElement(data, options))
- | "ItemQuantityChanged" -> Some (ItemQuantityChanged <| JsonSerializer.DeserializeElement(data, options))
- | "ItemWaiveReturnsChanged" -> Some (ItemWaiveReturnsChanged <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
type ItemInfo = { skuId: SkuId; quantity: int; returnsWaived: bool }
@@ -106,4 +81,4 @@ module Commands =
match waived with
| Some waived when itemExistsWithDifferentWaiveStatus skuId waived ->
yield Events.ItemWaiveReturnsChanged { context = c; skuId = skuId; waived = waived }
- | _ -> () ]
+ | _ -> () ]
diff --git a/samples/Store/Domain/ContactPreferences.fs b/samples/Store/Domain/ContactPreferences.fs
index 140220496..3613f5562 100644
--- a/samples/Store/Domain/ContactPreferences.fs
+++ b/samples/Store/Domain/ContactPreferences.fs
@@ -14,25 +14,8 @@ module Events =
| []Updated of Value
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) =
- fun (evt: Event) ->
- match evt with
- | Updated value -> "contactPreferencesChanged", JsonSerializer.SerializeToElement(value, options)
-
- let private tryDecode (options: JsonSerializerOptions) =
- fun (eventType, data: JsonElement) ->
- match eventType with
- | "contactPreferencesChanged" -> Some (Updated <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
@@ -56,4 +39,4 @@ module Commands =
match command with
| Update ({ preferences = preferences } as value) ->
if state = preferences then [] else
- [ Events.Updated value ]
+ [ Events.Updated value ]
diff --git a/samples/Store/Domain/Domain.fsproj b/samples/Store/Domain/Domain.fsproj
index d2f66d3b3..90393441a 100644
--- a/samples/Store/Domain/Domain.fsproj
+++ b/samples/Store/Domain/Domain.fsproj
@@ -1,7 +1,7 @@
- netstandard2.0;net461
+ netstandard2.1
5
false
true
@@ -19,9 +19,10 @@
-
+
-
+
+
diff --git a/samples/Store/Domain/Favorites.fs b/samples/Store/Domain/Favorites.fs
index c350052ef..428232fa3 100644
--- a/samples/Store/Domain/Favorites.fs
+++ b/samples/Store/Domain/Favorites.fs
@@ -15,27 +15,8 @@ module Events =
| Unfavorited of Unfavorited
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) = fun (evt: Event) ->
- match evt with
- | Snapshotted snapshotted -> "Snapshotted", JsonSerializer.SerializeToElement(snapshotted, options)
- | Favorited favorited -> "Favorited", JsonSerializer.SerializeToElement(favorited, options)
- | Unfavorited unfavorited -> "Unfavorited", JsonSerializer.SerializeToElement(unfavorited, options)
-
- let private tryDecode (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement(data, options))
- | "Favorited" -> Some (Favorited <| JsonSerializer.DeserializeElement(data, options))
- | "Unfavorited" -> Some (Unfavorited <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
diff --git a/samples/Store/Domain/SavedForLater.fs b/samples/Store/Domain/SavedForLater.fs
index f936ac535..44ba972dd 100644
--- a/samples/Store/Domain/SavedForLater.fs
+++ b/samples/Store/Domain/SavedForLater.fs
@@ -30,31 +30,8 @@ module Events =
| Added of Added
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) =
- fun (evt: Event) ->
- match evt with
- | Compacted compacted -> Compaction.EventType, JsonSerializer.SerializeToElement(compacted, options)
- | Merged merged -> "Merged", JsonSerializer.SerializeToElement(merged, options)
- | Removed removed -> "Removed", JsonSerializer.SerializeToElement(removed, options)
- | Added added -> "Added", JsonSerializer.SerializeToElement(added, options)
-
- let private tryDecode (options: JsonSerializerOptions) =
- fun (eventType, data: JsonElement) ->
- match eventType with
- | Compaction.EventType -> Some (Compacted <| JsonSerializer.DeserializeElement(data, options))
- | "Merged" -> Some (Merged <| JsonSerializer.DeserializeElement(data, options))
- | "Removed" -> Some (Removed <| JsonSerializer.DeserializeElement(data, options))
- | "Added" -> Some (Added <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
open Events
@@ -129,4 +106,4 @@ module Commands =
let index = Index state
let net = skus |> Array.filter (index.DoesNotAlreadyContainSameOrMoreRecent dateSaved)
if Array.isEmpty net then true, []
- else validateAgainstInvariants [ Events.Added { skus = net ; dateSaved = dateSaved } ]
+ else validateAgainstInvariants [ Events.Added { skus = net ; dateSaved = dateSaved } ]
diff --git a/samples/Store/Integration/CartIntegration.fs b/samples/Store/Integration/CartIntegration.fs
index 4d7db0cbd..f917c7bb4 100644
--- a/samples/Store/Integration/CartIntegration.fs
+++ b/samples/Store/Integration/CartIntegration.fs
@@ -4,7 +4,6 @@ open Equinox
open Equinox.Cosmos.Integration
open Equinox.EventStore
open Equinox.MemoryStore
-open FsCodec.SystemTextJson.Serialization
open Swensen.Unquote
#nowarn "1182" // From hereon in, we may have some 'unused' privates (the tests)
@@ -16,15 +15,15 @@ let createMemoryStore () =
// we want to validate that the JSON UTF8 is working happily
VolatileStore()
let createServiceMemory log store =
- Backend.Cart.Service(log, fun (id,opt) -> MemoryStore.Resolver(store, Domain.Cart.Events.Utf8ArrayCodec.codec, fold, initial).Resolve(id,?option=opt))
+ Backend.Cart.Service(log, fun (id,opt) -> MemoryStore.Resolver(store, Domain.Cart.Events.codecNewtonsoft, fold, initial).Resolve(id,?option=opt))
-let eventStoreCodec = Domain.Cart.Events.Utf8ArrayCodec.codec
+let eventStoreCodec = Domain.Cart.Events.codecNewtonsoft
let resolveGesStreamWithRollingSnapshots gateway =
fun (id,opt) -> EventStore.Resolver(gateway, eventStoreCodec, fold, initial, access = AccessStrategy.RollingSnapshots snapshot).Resolve(id,?option=opt)
let resolveGesStreamWithoutCustomAccessStrategy gateway =
fun (id,opt) -> EventStore.Resolver(gateway, eventStoreCodec, fold, initial).Resolve(id,?option=opt)
-let cosmosCodec = Domain.Cart.Events.JsonElementCodec.codec JsonSerializer.defaultOptions
+let cosmosCodec = Domain.Cart.Events.codecStj
let resolveCosmosStreamWithSnapshotStrategy gateway =
fun (id,opt) -> Cosmos.Resolver(gateway, cosmosCodec, fold, initial, Cosmos.CachingStrategy.NoCaching, Cosmos.AccessStrategy.Snapshot snapshot).Resolve(id,?option=opt)
let resolveCosmosStreamWithoutCustomAccessStrategy gateway =
diff --git a/samples/Store/Integration/ContactPreferencesIntegration.fs b/samples/Store/Integration/ContactPreferencesIntegration.fs
index c04fb7360..120f1a50f 100644
--- a/samples/Store/Integration/ContactPreferencesIntegration.fs
+++ b/samples/Store/Integration/ContactPreferencesIntegration.fs
@@ -2,26 +2,24 @@
open Equinox
open Equinox.Cosmos.Integration
-open FsCodec.SystemTextJson.Serialization
open Swensen.Unquote
-open Xunit
#nowarn "1182" // From hereon in, we may have some 'unused' privates (the tests)
let fold, initial = Domain.ContactPreferences.Fold.fold, Domain.ContactPreferences.Fold.initial
let createMemoryStore () =
- new MemoryStore.VolatileStore<_>()
+ MemoryStore.VolatileStore<_>()
let createServiceMemory log store =
Backend.ContactPreferences.Service(log, MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve)
-let eventStoreCodec = Domain.ContactPreferences.Events.Utf8ArrayCodec.codec
+let eventStoreCodec = Domain.ContactPreferences.Events.codecNewtonsoft
let resolveStreamGesWithOptimizedStorageSemantics gateway =
EventStore.Resolver(gateway 1, eventStoreCodec, fold, initial, access = EventStore.AccessStrategy.LatestKnownEvent).Resolve
let resolveStreamGesWithoutAccessStrategy gateway =
EventStore.Resolver(gateway defaultBatchSize, eventStoreCodec, fold, initial).Resolve
-let cosmosCodec = Domain.ContactPreferences.Events.JsonElementCodec.codec JsonSerializer.defaultOptions
+let cosmosCodec = Domain.ContactPreferences.Events.codecStj
let resolveStreamCosmosWithLatestKnownEventSemantics gateway =
Cosmos.Resolver(gateway 1, cosmosCodec, fold, initial, Cosmos.CachingStrategy.NoCaching, Cosmos.AccessStrategy.LatestKnownEvent).Resolve
let resolveStreamCosmosUnoptimized gateway =
@@ -76,7 +74,7 @@ type Tests(testOutputHelper) =
let! service = arrange connectToSpecifiedCosmosOrSimulator createCosmosContext resolveStreamCosmosWithLatestKnownEventSemantics
do! act service args
}
-
+
[]
let ``Can roundtrip against Cosmos, correctly folding the events with RollingUnfold semantics`` args = Async.RunSynchronously <| async {
let! service = arrange connectToSpecifiedCosmosOrSimulator createCosmosContext resolveStreamCosmosRollingUnfolds
diff --git a/samples/Store/Integration/FavoritesIntegration.fs b/samples/Store/Integration/FavoritesIntegration.fs
index 2d3e90430..ef72c5a0e 100644
--- a/samples/Store/Integration/FavoritesIntegration.fs
+++ b/samples/Store/Integration/FavoritesIntegration.fs
@@ -2,7 +2,6 @@
open Equinox
open Equinox.Cosmos.Integration
-open FsCodec.SystemTextJson.Serialization
open Swensen.Unquote
#nowarn "1182" // From hereon in, we may have some 'unused' privates (the tests)
@@ -15,12 +14,12 @@ let createMemoryStore () =
let createServiceMemory log store =
Backend.Favorites.Service(log, MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve)
-let eventStoreCodec = Domain.Favorites.Events.Utf8ArrayCodec.codec
+let eventStoreCodec = Domain.Favorites.Events.codecNewtonsoft
let createServiceGes gateway log =
let resolve = EventStore.Resolver(gateway, eventStoreCodec, fold, initial, access = EventStore.AccessStrategy.RollingSnapshots snapshot).Resolve
Backend.Favorites.Service(log, resolve)
-let cosmosCodec = Domain.Favorites.Events.JsonElementCodec.codec JsonSerializer.defaultOptions
+let cosmosCodec = Domain.Favorites.Events.codecStj
let createServiceCosmos gateway log =
let resolve = Cosmos.Resolver(gateway, cosmosCodec, fold, initial, Cosmos.CachingStrategy.NoCaching, Cosmos.AccessStrategy.Snapshot snapshot).Resolve
Backend.Favorites.Service(log, resolve)
@@ -68,7 +67,7 @@ type Tests(testOutputHelper) =
let service = createServiceCosmos gateway log
do! act service args
}
-
+
[]
let ``Can roundtrip against Cosmos, correctly folding the events with rolling unfolds`` args = Async.RunSynchronously <| async {
let log = createLog ()
diff --git a/samples/TodoBackend/Todo.fs b/samples/TodoBackend/Todo.fs
index 133e7d40c..a60dfddba 100644
--- a/samples/TodoBackend/Todo.fs
+++ b/samples/TodoBackend/Todo.fs
@@ -20,33 +20,8 @@ module Events =
| Snapshotted of Snapshotted
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) =
- fun (evt: Event) ->
- match evt with
- | Added todo -> "Added", JsonSerializer.SerializeToElement(todo, options)
- | Updated todo -> "Updated", JsonSerializer.SerializeToElement(todo, options)
- | Deleted deleted -> "Deleted", JsonSerializer.SerializeToElement(deleted, options)
- | Cleared -> "Cleared", Unchecked.defaultof
- | Snapshotted snapshotted -> "Snapshotted", JsonSerializer.SerializeToElement(snapshotted, options)
-
- let private tryDecode (options: JsonSerializerOptions) =
- fun (eventType, data: JsonElement) ->
- match eventType with
- | "Added" -> Some (Added <| JsonSerializer.DeserializeElement(data, options))
- | "Updated" -> Some (Updated <| JsonSerializer.DeserializeElement(data, options))
- | "Deleted" -> Some (Deleted <| JsonSerializer.DeserializeElement(data, options))
- | "Cleared" -> Some Cleared
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
type State = { items : Events.Todo list; nextId : int }
diff --git a/samples/TodoBackend/TodoBackend.fsproj b/samples/TodoBackend/TodoBackend.fsproj
index 42dc7a64a..c8646fa1e 100644
--- a/samples/TodoBackend/TodoBackend.fsproj
+++ b/samples/TodoBackend/TodoBackend.fsproj
@@ -1,7 +1,7 @@
- netstandard2.0;net461
+ netstandard2.1
5
false
true
@@ -13,8 +13,7 @@
-
-
+
diff --git a/samples/Tutorial/Gapless.fs b/samples/Tutorial/Gapless.fs
index e4d1180bd..68aa82aea 100644
--- a/samples/Tutorial/Gapless.fs
+++ b/samples/Tutorial/Gapless.fs
@@ -19,30 +19,8 @@ module Events =
| Snapshotted of Snapshotted
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) = fun (evt: Event) ->
- match evt with
- | Reserved item -> "Reserved", JsonSerializer.SerializeToElement(item, options)
- | Confirmed item -> "Confirmed", JsonSerializer.SerializeToElement(item, options)
- | Released item -> "Released", JsonSerializer.SerializeToElement(item, options)
- | Snapshotted snapshot -> "Snapshotted", JsonSerializer.SerializeToElement(snapshot, options)
-
- let private tryDecode (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "Reserved" -> Some (Reserved <| JsonSerializer.DeserializeElement- (data, options))
- | "Confirmed" -> Some (Confirmed <| JsonSerializer.DeserializeElement
- (data, options))
- | "Released" -> Some (Released <| JsonSerializer.DeserializeElement
- (data, options))
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
-
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
@@ -103,12 +81,10 @@ let [] appName = "equinox-tutorial-gapless"
module Cosmos =
open Equinox.Cosmos
- open FsCodec.SystemTextJson.Serialization
let private createService (context,cache,accessStrategy) =
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.) // OR CachingStrategy.NoCaching
- let codec = Events.JsonElementCodec.codec JsonSerializer.defaultOptions
- let resolve = Resolver(context, codec, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
+ let resolve = Resolver(context, Events.codecStj, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
Service(Serilog.Log.Logger, resolve)
module Snapshot =
diff --git a/samples/Tutorial/Index.fs b/samples/Tutorial/Index.fs
index 6d39b4ca5..9da5af0b0 100644
--- a/samples/Tutorial/Index.fs
+++ b/samples/Tutorial/Index.fs
@@ -14,27 +14,8 @@ module Events =
| Snapshotted of Items<'v>
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec<'v> = FsCodec.NewtonsoftJson.Codec.Create>()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode<'v> (options: JsonSerializerOptions) = fun (evt: Event<'v>) ->
- match evt with
- | Added items -> "Added", JsonSerializer.SerializeToElement(items, options)
- | Deleted itemIds -> "Deleted", JsonSerializer.SerializeToElement(itemIds, options)
- | Snapshotted items -> "Snapshotted", JsonSerializer.SerializeToElement(items, options)
-
- let private tryDecode<'v> (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "Added" -> Some (Added <| JsonSerializer.DeserializeElement>(data, options))
- | "Deleted" -> Some (Deleted <| JsonSerializer.DeserializeElement(data, options))
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement>(data, options))
- | _ -> None
-
- let codec<'v> options = FsCodec.Codec.Create, JsonElement>(encode<'v> options, tryDecode<'v> options)
+ let codecNewtonsoft<'v> = FsCodec.NewtonsoftJson.Codec.Create>()
+ let codecStj<'v> = FsCodec.SystemTextJson.Codec.Create>()
module Fold =
@@ -75,17 +56,15 @@ let create resolve indexId = Service(indexId, resolve, maxAttempts = 3)
module Cosmos =
open Equinox.Cosmos
- open FsCodec.SystemTextJson.Serialization
let createService<'v> (context,cache) =
let cacheStrategy = CachingStrategy.SlidingWindow (cache, System.TimeSpan.FromMinutes 20.)
let accessStrategy = AccessStrategy.RollingState Fold.snapshot
- let codec = Events.JsonElementCodec.codec<'v> JsonSerializer.defaultOptions
- let resolve = Resolver(context, codec, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
+ let resolve = Resolver(context, Events.codecStj, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
create resolve
module MemoryStore =
let createService store =
- let resolve = Equinox.MemoryStore.Resolver(store, Events.Utf8ArrayCodec.codec, Fold.fold, Fold.initial).Resolve
+ let resolve = Equinox.MemoryStore.Resolver(store, Events.codecNewtonsoft, Fold.fold, Fold.initial).Resolve
create resolve
diff --git a/samples/Tutorial/Sequence.fs b/samples/Tutorial/Sequence.fs
index 264e26b50..e8931e361 100644
--- a/samples/Tutorial/Sequence.fs
+++ b/samples/Tutorial/Sequence.fs
@@ -26,23 +26,8 @@ module Events =
| Reserved of Reserved
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) = fun (evt: Event) ->
- match evt with
- | Reserved reserved -> "Reserved", JsonSerializer.SerializeToElement(reserved, options)
-
- let private tryDecode (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "Reserved" -> Some (Reserved <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options= FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
@@ -71,12 +56,10 @@ let create resolve = Service(Serilog.Log.ForContext(), resolve, maxAtte
module Cosmos =
open Equinox.Cosmos
- open FsCodec.SystemTextJson.Serialization
let private createService (context,cache,accessStrategy) =
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.) // OR CachingStrategy.NoCaching
- let codec = Events.JsonElementCodec.codec JsonSerializer.defaultOptions
- let resolve = Resolver(context, codec, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
+ let resolve = Resolver(context, Events.codecStj, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
create resolve
module LatestKnownEvent =
diff --git a/samples/Tutorial/Set.fs b/samples/Tutorial/Set.fs
index c500df008..f0eb7e4de 100644
--- a/samples/Tutorial/Set.fs
+++ b/samples/Tutorial/Set.fs
@@ -13,27 +13,8 @@ module Events =
| Snapshotted of Items
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let private encode (options: JsonSerializerOptions) = fun (evt: Event) ->
- match evt with
- | Added items -> "Added", JsonSerializer.SerializeToElement(items, options)
- | Deleted items -> "Deleted", JsonSerializer.SerializeToElement(items, options)
- | Snapshotted items -> "Snapshotted", JsonSerializer.SerializeToElement(items, options)
-
- let private tryDecode (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "Added" -> Some (Added <| JsonSerializer.DeserializeElement(data, options))
- | "Deleted" -> Some (Deleted <| JsonSerializer.DeserializeElement(data, options))
- | "Snapshotted" -> Some (Snapshotted <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
@@ -75,17 +56,15 @@ let create resolve setId = Service(Serilog.Log.ForContext(), setId, res
module Cosmos =
open Equinox.Cosmos
- open FsCodec.SystemTextJson.Serialization
let createService (context,cache) =
let cacheStrategy = CachingStrategy.SlidingWindow (cache, System.TimeSpan.FromMinutes 20.)
let accessStrategy = AccessStrategy.RollingState Fold.snapshot
- let codec = Events.JsonElementCodec.codec JsonSerializer.defaultOptions
- let resolve = Resolver(context, codec, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
+ let resolve = Resolver(context, Events.codecStj, Fold.fold, Fold.initial, cacheStrategy, accessStrategy).Resolve
create resolve
module MemoryStore =
let createService store =
- let resolve = Equinox.MemoryStore.Resolver(store, Events.Utf8ArrayCodec.codec, Fold.fold, Fold.initial).Resolve
+ let resolve = Equinox.MemoryStore.Resolver(store, Events.codecNewtonsoft, Fold.fold, Fold.initial).Resolve
create resolve
diff --git a/samples/Tutorial/Upload.fs b/samples/Tutorial/Upload.fs
index aa80caa5f..b360bd81f 100644
--- a/samples/Tutorial/Upload.fs
+++ b/samples/Tutorial/Upload.fs
@@ -41,23 +41,8 @@ module Events =
| IdAssigned of IdAssigned
interface TypeShape.UnionContract.IUnionContract
- module Utf8ArrayCodec =
- let codec = FsCodec.NewtonsoftJson.Codec.Create()
-
- module JsonElementCodec =
- open FsCodec.SystemTextJson
- open System.Text.Json
-
- let encode (options: JsonSerializerOptions) = fun (evt: Event) ->
- match evt with
- | IdAssigned id -> "IdAssigned", JsonSerializer.SerializeToElement(id, options)
-
- let tryDecode (options: JsonSerializerOptions) = fun (eventType, data: JsonElement) ->
- match eventType with
- | "IdAssigned" -> Some (IdAssigned <| JsonSerializer.DeserializeElement(data, options))
- | _ -> None
-
- let codec options = FsCodec.Codec.Create(encode options, tryDecode options)
+ let codecNewtonsoft = FsCodec.NewtonsoftJson.Codec.Create()
+ let codecStj = FsCodec.SystemTextJson.Codec.Create()
module Fold =
@@ -86,16 +71,14 @@ let create resolve = Service(Serilog.Log.ForContext(), resolve, 3)
module Cosmos =
open Equinox.Cosmos
- open FsCodec.SystemTextJson.Serialization
let createService (context,cache) =
let cacheStrategy = CachingStrategy.SlidingWindow (cache, TimeSpan.FromMinutes 20.) // OR CachingStrategy.NoCaching
- let codec = Events.JsonElementCodec.codec JsonSerializer.defaultOptions
- let resolve = Resolver(context, codec, Fold.fold, Fold.initial, cacheStrategy, AccessStrategy.LatestKnownEvent).Resolve
+ let resolve = Resolver(context, Events.codecStj, Fold.fold, Fold.initial, cacheStrategy, AccessStrategy.LatestKnownEvent).Resolve
create resolve
module EventStore =
open Equinox.EventStore
let createService context =
- let resolve = Resolver(context, Events.Utf8ArrayCodec.codec, Fold.fold, Fold.initial, access=AccessStrategy.LatestKnownEvent).Resolve
+ let resolve = Resolver(context, Events.codecNewtonsoft, Fold.fold, Fold.initial, access=AccessStrategy.LatestKnownEvent).Resolve
create resolve
diff --git a/src/Equinox.Core/Equinox.Core.fsproj b/src/Equinox.Core/Equinox.Core.fsproj
index c0e768822..95dde0c5c 100644
--- a/src/Equinox.Core/Equinox.Core.fsproj
+++ b/src/Equinox.Core/Equinox.Core.fsproj
@@ -17,10 +17,6 @@
-
-
-
-
diff --git a/src/Equinox.Core/Json/JsonElementHelpers.fs b/src/Equinox.Core/Json/JsonElementHelpers.fs
deleted file mode 100644
index f753f73f8..000000000
--- a/src/Equinox.Core/Json/JsonElementHelpers.fs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace FsCodec.SystemTextJson
-
-open System
-open System.Buffers
-open System.Runtime.InteropServices
-open System.Text.Json
-
-[]
-module JsonSerializerExtensions =
- type JsonSerializer with
- static member SerializeToElement(value: 'T, [] ?options: JsonSerializerOptions) =
- JsonSerializer.Deserialize(ReadOnlySpan.op_Implicit(JsonSerializer.SerializeToUtf8Bytes(value, defaultArg options null)))
-
- static member DeserializeElement<'T>(element: JsonElement, [] ?options: JsonSerializerOptions) =
-#if NETSTANDARD2_1
- let bufferWriter = ArrayBufferWriter()
- (
- use jsonWriter = new Utf8JsonWriter(bufferWriter)
- element.WriteTo(jsonWriter)
- )
- JsonSerializer.Deserialize<'T>(bufferWriter.WrittenSpan, defaultArg options null)
-#else
- let json = element.GetRawText()
- JsonSerializer.Deserialize<'T>(json, defaultArg options null)
-#endif
diff --git a/src/Equinox.Core/Json/JsonRecordConverter.fs b/src/Equinox.Core/Json/JsonRecordConverter.fs
deleted file mode 100644
index 079382003..000000000
--- a/src/Equinox.Core/Json/JsonRecordConverter.fs
+++ /dev/null
@@ -1,161 +0,0 @@
-namespace FsCodec.SystemTextJson.Serialization
-
-open Equinox.Core
-open System
-open System.Collections.Generic
-open System.Linq
-open System.Linq.Expressions
-open System.Text.Json
-open System.Text.Json.Serialization
-open FSharp.Reflection
-
-type JsonRecordConverterActivator = delegate of JsonSerializerOptions -> JsonConverter
-
-type IRecordFieldConverter =
- abstract member Initialize: converter: JsonConverter -> unit
- abstract member Read: reader: byref * typ: Type * options: JsonSerializerOptions -> obj
- abstract member Write: writer: Utf8JsonWriter * value: obj * options: JsonSerializerOptions -> unit
-
-type RecordFieldConverter<'F> () =
- let mutable converter = Unchecked.defaultof>
-
- interface IRecordFieldConverter with
- member __.Initialize (c) =
- converter <- c :?> JsonConverter<'F>
-
- member __.Read (reader, typ, options) =
- converter.Read(&reader, typ, options) :> obj
-
- member __.Write (writer, value, options) =
- converter.Write(writer, value :?> 'F, options)
-
-[]
-type RecordField = {
- name: string
- fieldType: Type
- index: int
- isIgnored: bool
- converter: IRecordFieldConverter option
-}
-
-type JsonRecordConverter<'T> (options: JsonSerializerOptions) =
- inherit JsonConverter<'T> ()
-
- let recordType = typeof<'T>
-
- let constructor = FSharpValue.PreComputeRecordConstructor(recordType, true)
- let getFieldValues = FSharpValue.PreComputeRecordReader(typeof<'T>, true)
-
- let fields =
- FSharpType.GetRecordFields(recordType, true)
- |> Array.mapi (fun idx f ->
- {
- name =
- f.GetCustomAttributes(typedefof, true)
- |> Array.tryHead
- |> Option.map (fun attr -> (attr :?> JsonPropertyNameAttribute).Name)
- |> Option.defaultWith (fun () ->
- if options.PropertyNamingPolicy |> isNull
- then f.Name
- else options.PropertyNamingPolicy.ConvertName f.Name)
-
- fieldType = f.PropertyType
- index = idx
- isIgnored = f.GetCustomAttributes(typeof, true) |> Array.isEmpty |> not
- converter =
- f.GetCustomAttributes(typeof, true)
- |> Array.tryHead
- |> Option.map (fun attr -> attr :?> JsonConverterAttribute)
- |> Option.bind (fun attr ->
- let baseConverter = attr.CreateConverter(f.PropertyType)
-
- if baseConverter |> isNull then
- failwithf "Field %s is decorated with a JsonConverter attribute, but it does not implement a CreateConverter method." f.Name
-
- if baseConverter.CanConvert(f.PropertyType) then
- let converterType = typedefof>.MakeGenericType(f.PropertyType)
- let converter = Activator.CreateInstance(converterType) :?> IRecordFieldConverter
- converter.Initialize(baseConverter)
- Some converter
- else
- None
- )
- })
-
- let fieldsByName =
- fields
- |> Array.map (fun f -> f.name, f)
-#if NETSTANDARD2_1
- |> Array.map KeyValuePair.Create
- |> (fun kvp -> Dictionary(kvp, StringComparer.OrdinalIgnoreCase))
-#else
- |> Array.map KeyValuePair
- |> (fun kvp -> kvp.ToDictionary((fun item -> item.Key), (fun item -> item.Value), StringComparer.OrdinalIgnoreCase))
-#endif
-
- let tryGetFieldByName name =
- match fieldsByName.TryGetValue(name) with
- | true, field -> Some field
- | _ -> None
-
- let getFieldByName name =
- match tryGetFieldByName name with
- | Some field -> field
- | _ -> KeyNotFoundException(sprintf "Failed to find a field named '%s' on record type '%s'." name recordType.Name) |> raise
-
- override __.Read (reader, typ, options) =
- reader.ValidateTokenType(JsonTokenType.StartObject)
-
- let fields = Array.zeroCreate <| fields.Length
-
- while reader.Read() && reader.TokenType <> JsonTokenType.EndObject do
- reader.ValidateTokenType(JsonTokenType.PropertyName)
-
- match tryGetFieldByName <| reader.GetString() with
- | Some field ->
- fields.[field.index] <-
- match field.converter with
- | Some converter ->
- reader.Read() |> ignore
- converter.Read(&reader, field.fieldType, options)
- | None ->
- JsonSerializer.Deserialize(&reader, field.fieldType, options)
- | _ ->
- reader.Skip()
-
- constructor fields :?> 'T
-
- override __.Write (writer, record, options) =
- writer.WriteStartObject()
-
- let fieldValues = getFieldValues record
-
- (fields, fieldValues)
- ||> Array.iter2 (fun field value ->
- match value with
- | :? JsonElement as je when je.ValueKind = JsonValueKind.Undefined -> ()
- | _ ->
- if not field.isIgnored && not (options.IgnoreNullValues && isNull value) then
- writer.WritePropertyName(field.name)
-
- match field.converter with
- | Some converter -> converter.Write(writer, value, options)
- | None -> JsonSerializer.Serialize(writer, value, options))
-
- writer.WriteEndObject()
-
-type JsonRecordConverter () =
- inherit JsonConverterFactory()
-
- override __.CanConvert typ =
- FSharpType.IsRecord (typ, true)
-
- override __.CreateConverter (typ, options) =
- let constructor = typedefof>.MakeGenericType(typ).GetConstructor(typeof |> Array.singleton)
- let optionsParameter = Expression.Parameter(typeof, "options")
-
- let newExpression = Expression.New(constructor, optionsParameter)
- let lambda = Expression.Lambda(typeof, newExpression, optionsParameter)
-
- let activator = lambda.Compile() :?> JsonRecordConverterActivator
- activator.Invoke(options)
diff --git a/src/Equinox.Core/Json/Options.fs b/src/Equinox.Core/Json/Options.fs
deleted file mode 100644
index 6867c76f6..000000000
--- a/src/Equinox.Core/Json/Options.fs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace FsCodec.SystemTextJson.Serialization
-
-open System.Text.Json
-
-[]
-module JsonSerializerOptionExtensions =
- type JsonSerializerOptions with
- static member Create() =
- let options = JsonSerializerOptions()
- options.Converters.Add(new JsonRecordConverter())
- options
-
-module JsonSerializer =
- let defaultOptions = JsonSerializerOptions.Create()
diff --git a/src/Equinox.Core/Json/Utf8JsonReaderExtensions.fs b/src/Equinox.Core/Json/Utf8JsonReaderExtensions.fs
deleted file mode 100644
index 9e29bb5d3..000000000
--- a/src/Equinox.Core/Json/Utf8JsonReaderExtensions.fs
+++ /dev/null
@@ -1,22 +0,0 @@
-namespace FsCodec.SystemTextJson.Serialization
-
-open System.Text.Json
-open System.Runtime.CompilerServices
-
-[]
-type Utf8JsonReaderExtension =
- []
- static member ValidateTokenType(reader: Utf8JsonReader, expectedTokenType) =
- if reader.TokenType <> expectedTokenType then
- sprintf "Expected a %A token, but encountered a %A token when parsing JSON." expectedTokenType (reader.TokenType)
- |> JsonException
- |> raise
-
- []
- static member ValidatePropertyName(reader: Utf8JsonReader, expectedPropertyName: string) =
- reader.ValidateTokenType(JsonTokenType.PropertyName)
-
- if not <| reader.ValueTextEquals expectedPropertyName then
- sprintf "Expected a property named '%s', but encountered property with name '%s'." expectedPropertyName (reader.GetString())
- |> JsonException
- |> raise
diff --git a/src/Equinox.Cosmos/Cosmos.fs b/src/Equinox.Cosmos/Cosmos.fs
index 7dbd01ef8..e63a92eed 100644
--- a/src/Equinox.Cosmos/Cosmos.fs
+++ b/src/Equinox.Cosmos/Cosmos.fs
@@ -30,7 +30,7 @@ type [] // TODO for STJ v5: All fields required unless
/// Optional causationId
causationId : string // TODO for STJ v5: Optional, not serialized if missing
- }
+ }
interface IEventData with
member __.EventType = __.c
@@ -749,7 +749,7 @@ module internal Tip =
let! page = retryingLoggingReadPage e batchLog
match page with
- | Some (evts, _pos, rus) ->
+ | Some (evts, _pos, rus) ->
ru <- ru + rus
allEvents.AddRange(evts)
@@ -798,7 +798,6 @@ open Equinox
open Equinox.Core
open Equinox.Cosmos.Store
open FsCodec
-open FsCodec.SystemTextJson.Serialization
open FSharp.Control
open Serilog
open System
@@ -1141,7 +1140,10 @@ type Connector
/// ClientOptions for this Connector as configured
member val ClientOptions =
let maxAttempts, maxWait, timeout = Nullable maxRetryAttemptsOnRateLimitedRequests, Nullable maxRetryWaitTimeOnRateLimitedRequests, requestTimeout
- let co = CosmosClientOptions(MaxRetryAttemptsOnRateLimitedRequests = maxAttempts, MaxRetryWaitTimeOnRateLimitedRequests = maxWait, RequestTimeout = timeout, Serializer = CosmosJsonSerializer(JsonSerializer.defaultOptions))
+ let co =
+ CosmosClientOptions(
+ MaxRetryAttemptsOnRateLimitedRequests = maxAttempts, MaxRetryWaitTimeOnRateLimitedRequests = maxWait, RequestTimeout = timeout,
+ Serializer = CosmosJsonSerializer(FsCodec.SystemTextJson.Options.CreateDefault(converters=[|FsCodec.SystemTextJson.Converters.JsonRecordConverter()|])))
match mode with
| Some ConnectionMode.Direct -> co.ConnectionMode <- ConnectionMode.Direct
| None | Some ConnectionMode.Gateway | Some _ (* enum total match :( *) -> co.ConnectionMode <- ConnectionMode.Gateway // default; only supports Https
diff --git a/src/Equinox.Cosmos/Equinox.Cosmos.fsproj b/src/Equinox.Cosmos/Equinox.Cosmos.fsproj
index 4659eff70..0e29ccdf6 100644
--- a/src/Equinox.Cosmos/Equinox.Cosmos.fsproj
+++ b/src/Equinox.Cosmos/Equinox.Cosmos.fsproj
@@ -1,7 +1,7 @@
- netstandard2.1
+ netstandard2.1
5
false
true
@@ -23,13 +23,13 @@
-
+
+
-
\ No newline at end of file
diff --git a/src/Equinox.EventStore/Equinox.EventStore.fsproj b/src/Equinox.EventStore/Equinox.EventStore.fsproj
index 15847dde4..20699c979 100644
--- a/src/Equinox.EventStore/Equinox.EventStore.fsproj
+++ b/src/Equinox.EventStore/Equinox.EventStore.fsproj
@@ -26,7 +26,7 @@
-
+
diff --git a/src/Equinox.MemoryStore/Equinox.MemoryStore.fsproj b/src/Equinox.MemoryStore/Equinox.MemoryStore.fsproj
index 4895d6ccb..26c6cfefe 100644
--- a/src/Equinox.MemoryStore/Equinox.MemoryStore.fsproj
+++ b/src/Equinox.MemoryStore/Equinox.MemoryStore.fsproj
@@ -24,7 +24,7 @@
-
+
\ No newline at end of file
diff --git a/src/Equinox.SqlStreamStore/Equinox.SqlStreamStore.fsproj b/src/Equinox.SqlStreamStore/Equinox.SqlStreamStore.fsproj
index e7addd071..724ef3d28 100644
--- a/src/Equinox.SqlStreamStore/Equinox.SqlStreamStore.fsproj
+++ b/src/Equinox.SqlStreamStore/Equinox.SqlStreamStore.fsproj
@@ -24,7 +24,7 @@
-
+
diff --git a/tests/Equinox.Cosmos.Integration/CosmosCoreIntegration.fs b/tests/Equinox.Cosmos.Integration/CosmosCoreIntegration.fs
index 0e0e6138d..77d2b97b6 100644
--- a/tests/Equinox.Cosmos.Integration/CosmosCoreIntegration.fs
+++ b/tests/Equinox.Cosmos.Integration/CosmosCoreIntegration.fs
@@ -16,8 +16,8 @@ type TestEvents() =
static member private Create(i, ?eventType, ?json) =
EventData.FromUtf8Bytes
( sprintf "%s:%d" (defaultArg eventType "test_event") i,
- IntegrationJsonSerializer.deserialize(defaultArg json "{\"d\":\"d\"}"),
- IntegrationJsonSerializer.deserialize("{\"m\":\"m\"}") )
+ FsCodec.NewtonsoftJson.Serdes.Deserialize(defaultArg json "{\"d\":\"d\"}"),
+ FsCodec.NewtonsoftJson.Serdes.Deserialize("{\"m\":\"m\"}"))
static member Create(i, c) = Array.init c (fun x -> TestEvents.Create(x+i))
type Tests(testOutputHelper) =
diff --git a/tests/Equinox.Cosmos.Integration/CosmosIntegration.fs b/tests/Equinox.Cosmos.Integration/CosmosIntegration.fs
index b74282e46..c6c7fd8b1 100644
--- a/tests/Equinox.Cosmos.Integration/CosmosIntegration.fs
+++ b/tests/Equinox.Cosmos.Integration/CosmosIntegration.fs
@@ -11,7 +11,7 @@ open System.Threading
module Cart =
let fold, initial = Domain.Cart.Fold.fold, Domain.Cart.Fold.initial
let snapshot = Domain.Cart.Fold.isOrigin, Domain.Cart.Fold.snapshot
- let codec = Domain.Cart.Events.JsonElementCodec.codec IntegrationJsonSerializer.options
+ let codec = Domain.Cart.Events.codecStj
let createServiceWithoutOptimization connection batchSize log =
let store = createCosmosContext connection batchSize
let resolve (id,opt) = Resolver(store, codec, fold, initial, CachingStrategy.NoCaching, AccessStrategy.Unoptimized).Resolve(id,?option=opt)
@@ -40,7 +40,7 @@ module Cart =
module ContactPreferences =
let fold, initial = Domain.ContactPreferences.Fold.fold, Domain.ContactPreferences.Fold.initial
- let codec = Domain.ContactPreferences.Events.JsonElementCodec.codec IntegrationJsonSerializer.options
+ let codec = Domain.ContactPreferences.Events.codecStj
let createServiceWithoutOptimization createGateway defaultBatchSize log _ignoreWindowSize _ignoreCompactionPredicate =
let gateway = createGateway defaultBatchSize
let resolve = Resolver(gateway, codec, fold, initial, CachingStrategy.NoCaching, AccessStrategy.Unoptimized).Resolve
diff --git a/tests/Equinox.Cosmos.Integration/Json.fs b/tests/Equinox.Cosmos.Integration/Json.fs
index 398679399..80a5c976a 100644
--- a/tests/Equinox.Cosmos.Integration/Json.fs
+++ b/tests/Equinox.Cosmos.Integration/Json.fs
@@ -2,13 +2,10 @@
module Equinox.Cosmos.Integration.Json
open System
-open System.Text.Json
open System.Text.Json.Serialization
open Domain
-open FsCodec.SystemTextJson
-open FsCodec.SystemTextJson.Serialization
-type JsonSkuIdConverter () =
+type JsonSkuIdConverter() =
inherit JsonConverter()
override __.Read (reader, _typ, _options) =
@@ -18,10 +15,5 @@ type JsonSkuIdConverter () =
writer.WriteStringValue(string value)
module IntegrationJsonSerializer =
- let options = JsonSerializer.defaultOptions
- options.Converters.Add(JsonSkuIdConverter())
-
- let serialize (value: 'T) = JsonSerializer.Serialize(value, options)
- let serializeToElement (value: 'T) = JsonSerializer.SerializeToElement(value, options)
- let deserialize<'T> (json: string) = JsonSerializer.Deserialize<'T>(json, options)
- let deserializeElement<'T> (jsonElement: JsonElement) = JsonSerializer.DeserializeElement<'T>(jsonElement, options)
+ let options = FsCodec.SystemTextJson.Options.Create()
+ options.Converters.Add <| JsonSkuIdConverter()
diff --git a/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs b/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs
index 7bcbecb31..ecbcf6278 100644
--- a/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs
+++ b/tests/Equinox.Cosmos.Integration/JsonConverterTests.fs
@@ -13,21 +13,10 @@ type Union =
| B of Embedded
interface TypeShape.UnionContract.IUnionContract
-let defaultSettings = FsCodec.NewtonsoftJson.Settings.CreateDefault()
-
-let encode (evt: Union) =
- match evt with
- | A e -> "A", IntegrationJsonSerializer.serializeToElement(e)
- | B e -> "B", IntegrationJsonSerializer.serializeToElement(e)
-
-let tryDecode (eventType, data: JsonElement) =
- match eventType with
- | "A" -> Some (A <| IntegrationJsonSerializer.deserializeElement(data))
- | "B" -> Some (B <| IntegrationJsonSerializer.deserializeElement(data))
- | _ -> None
+let defaultOptions = FsCodec.SystemTextJson.Options.CreateDefault()
type Base64ZipUtf8Tests() =
- let eventCodec = FsCodec.Codec.Create(encode, tryDecode)
+ let eventCodec = FsCodec.SystemTextJson.Codec.Create(defaultOptions)
[]
let ``serializes, achieving compression`` () =
@@ -38,7 +27,7 @@ type Base64ZipUtf8Tests() =
d = encoded.Data
m = Unchecked.defaultof
t = DateTimeOffset.MinValue }
- let res = IntegrationJsonSerializer.serialize(e)
+ let res = FsCodec.SystemTextJson.Serdes.Serialize(e, defaultOptions)
test <@ res.Contains("\"d\":\"") && res.Length < 138 @>
[]
@@ -56,9 +45,9 @@ type Base64ZipUtf8Tests() =
d = encoded.Data
m = Unchecked.defaultof
t = DateTimeOffset.MinValue }
- let ser = IntegrationJsonSerializer.serialize(e)
+ let ser = FsCodec.SystemTextJson.Serdes.Serialize(e, defaultOptions)
test <@ ser.Contains("\"d\":\"") @>
- let des = IntegrationJsonSerializer.deserialize(ser)
+ let des = FsCodec.SystemTextJson.Serdes.Deserialize(ser, defaultOptions)
let d = FsCodec.Core.TimelineEvent.Create(-1L, des.c, des.d)
let decoded = eventCodec.TryDecode d |> Option.get
test <@ value = decoded @>
diff --git a/tests/Equinox.EventStore.Integration/Equinox.EventStore.Integration.fsproj b/tests/Equinox.EventStore.Integration/Equinox.EventStore.Integration.fsproj
index 746cf3153..06db62a14 100644
--- a/tests/Equinox.EventStore.Integration/Equinox.EventStore.Integration.fsproj
+++ b/tests/Equinox.EventStore.Integration/Equinox.EventStore.Integration.fsproj
@@ -22,7 +22,7 @@
-
+
diff --git a/tests/Equinox.EventStore.Integration/StoreIntegration.fs b/tests/Equinox.EventStore.Integration/StoreIntegration.fs
index f2e4c76c2..29c8aff0f 100644
--- a/tests/Equinox.EventStore.Integration/StoreIntegration.fs
+++ b/tests/Equinox.EventStore.Integration/StoreIntegration.fs
@@ -48,10 +48,10 @@ let createGesGateway connection batchSize = Context(connection, BatchingPolicy(m
module Cart =
let fold, initial = Domain.Cart.Fold.fold, Domain.Cart.Fold.initial
- let codec = Domain.Cart.Events.Utf8ArrayCodec.codec
+ let codec = Domain.Cart.Events.codecNewtonsoft
let snapshot = Domain.Cart.Fold.isOrigin, Domain.Cart.Fold.snapshot
let createServiceWithoutOptimization log gateway =
- Backend.Cart.Service(log, fun (id,opt) -> Resolver(gateway, Domain.Cart.Events.Utf8ArrayCodec.codec, fold, initial).Resolve(id,?option=opt))
+ Backend.Cart.Service(log, fun (id,opt) -> Resolver(gateway, Domain.Cart.Events.codecNewtonsoft, fold, initial).Resolve(id,?option=opt))
let createServiceWithCompaction log gateway =
let resolve (id,opt) = Resolver(gateway, codec, fold, initial, access = AccessStrategy.RollingSnapshots snapshot).Resolve(id,?option=opt)
Backend.Cart.Service(log, resolve)
@@ -64,7 +64,7 @@ module Cart =
module ContactPreferences =
let fold, initial = Domain.ContactPreferences.Fold.fold, Domain.ContactPreferences.Fold.initial
- let codec = Domain.ContactPreferences.Events.Utf8ArrayCodec.codec
+ let codec = Domain.ContactPreferences.Events.codecNewtonsoft
let createServiceWithoutOptimization log connection =
let gateway = createGesGateway connection defaultBatchSize
Backend.ContactPreferences.Service(log, Resolver(gateway, codec, fold, initial).Resolve)