Skip to content

Refactors #22

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

Merged
merged 5 commits into from
Jan 24, 2022
Merged
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
5 changes: 1 addition & 4 deletions src/SqlStreamStore.FSharp.Postgres/Create.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SqlStreamStore.FSharp.Postgres

open Prelude.ErrorHandling
open Prelude
open SqlStreamStore

type PostgresConfig =
Expand All @@ -25,9 +25,6 @@ type PostgresConfig =

module Create =

/// Represents an in-memory implementation of a stream store. Use for testing or high/speed + volatile scenarios.
let inMemoryStore : unit -> InMemoryStreamStore = fun _ -> new InMemoryStreamStore()

let postgresStore (config: PostgresConfig) (schema: string option) : PostgresStreamStore =

let storeSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Create.fs"/>
<Compile Include="Create.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.*"/>
<PackageReference Include="FSharp.Core" Version="6.0.*"/>
<PackageReference Include="SqlStreamStore.Postgres" Version="1.2.0-beta.8"/>
<PackageReference Include="FSharp.Prelude" Version="6.0.0-beta-3" />
<PackageReference Include="SqlStreamStore.Postgres" Version="1.2.0-beta.8" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SqlStreamStore.FSharp\SqlStreamStore.FSharp.fsproj"/>
<ProjectReference Include="..\SqlStreamStore.FSharp\SqlStreamStore.FSharp.fsproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/SqlStreamStore.FSharp/Append.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SqlStreamStore.FSharp

open Prelude.ErrorHandling
open Prelude
open System.Threading
open SqlStreamStore

Expand All @@ -13,7 +13,7 @@ module Append =
let streamMessages'
(messages: NewStreamMessage list)
(appendOptions: AppendOption list)
(Stream stream: Stream)
(stream: Stream)
: AsyncResult<Streams.AppendResult, exn> =

let mutable expectedVersion = Streams.ExpectedVersion.Any
Expand Down
16 changes: 7 additions & 9 deletions src/SqlStreamStore.FSharp/Connect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ namespace SqlStreamStore.FSharp

open SqlStreamStore

type private StreamInternal =
{
store: IStreamStore
streamId: string
}

type Stream = private Stream of StreamInternal
type Stream =
private
{
store: IStreamStore
streamId: string
}

module Connect =
let toStream streamId store =
Stream { streamId = streamId; store = store }
let toStream streamId store = { streamId = streamId; store = store }
11 changes: 5 additions & 6 deletions src/SqlStreamStore.FSharp/Extensions.fs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace SqlStreamStore.FSharp

open System.Threading
open Prelude.ErrorHandling
open Prelude
open SqlStreamStore
open SqlStreamStore.Streams
open System

[<AutoOpen>]
module SqlStreamExtensions =
Expand Down Expand Up @@ -172,13 +171,13 @@ module SqlStreamExtensions =

let maxAge' =
match maxAge with
| None -> Nullable()
| Some age -> Nullable age
| None -> System.Nullable()
| Some age -> System.Nullable age

let maxCount' =
match maxCount with
| None -> Nullable()
| Some count -> Nullable count
| None -> System.Nullable()
| Some count -> System.Nullable count

let metadataJson' = defaultArg metadataJson null

Expand Down
75 changes: 35 additions & 40 deletions src/SqlStreamStore.FSharp/Get.fs
Original file line number Diff line number Diff line change
@@ -1,72 +1,67 @@
namespace SqlStreamStore.FSharp

open Prelude.ErrorHandling
open Prelude
open SqlStreamStore.Streams

module Get =

// A function to help wit type inference in this module
let private curriedMap: (ReadStreamPage -> 'a) -> AsyncResult<ReadStreamPage, exn> -> AsyncResult<'a, exn> =
AsyncResult.map
let messages: AsyncResult<ReadStreamPage, exn> -> AsyncResult<StreamMessage list, exn> =
AsyncResult.map (fun page -> page.Messages |> Array.toList)

let messages =
curriedMap (fun page -> page.Messages |> Array.toList)

let messagesData =
let messagesData: AsyncResult<ReadStreamPage, exn> -> AsyncResult<string list, exn> =
messages
>> AsyncResult.bind (AsyncResult.mapM (fun msg -> msg.GetJsonData()))
>> AsyncResult.bind (AsyncResult.traverse (fun msg -> msg.GetJsonData()))

let messagesDataAs<'data> =
let messagesDataAs<'data> : AsyncResult<ReadStreamPage, exn> -> AsyncResult<'data list, exn> =
messages
>> AsyncResult.bind (AsyncResult.mapM (fun msg -> msg.GetJsonDataAs<'data>()))
>> AsyncResult.bind (AsyncResult.traverse (fun msg -> msg.GetJsonDataAs<'data>()))

let status = curriedMap (fun page -> page.Status)
let status: AsyncResult<ReadStreamPage, exn> -> AsyncResult<PageReadStatus, exn> =
AsyncResult.map (fun page -> page.Status)

let isEnd = curriedMap (fun page -> page.IsEnd)
let isEnd: AsyncResult<ReadStreamPage, exn> -> AsyncResult<bool, exn> = AsyncResult.map (fun page -> page.IsEnd)

let readDirection =
curriedMap (fun page -> page.ReadDirection)
let readDirection: AsyncResult<ReadStreamPage, exn> -> AsyncResult<ReadDirection, exn> =
AsyncResult.map (fun page -> page.ReadDirection)

let streamId = curriedMap (fun page -> page.StreamId)
let streamId: AsyncResult<ReadStreamPage, exn> -> AsyncResult<string, exn> =
AsyncResult.map (fun page -> page.StreamId)

let fromStreamVersion =
curriedMap (fun page -> page.FromStreamVersion)
let fromStreamVersion: AsyncResult<ReadStreamPage, exn> -> AsyncResult<int, exn> =
AsyncResult.map (fun page -> page.FromStreamVersion)

let lastStreamPosition =
curriedMap (fun page -> page.LastStreamPosition)
let lastStreamPosition: AsyncResult<ReadStreamPage, exn> -> AsyncResult<int64, exn> =
AsyncResult.map (fun page -> page.LastStreamPosition)

let nextStreamVersion =
curriedMap (fun page -> page.NextStreamVersion)
let nextStreamVersion: AsyncResult<ReadStreamPage, exn> -> AsyncResult<int, exn> =
AsyncResult.map (fun page -> page.NextStreamVersion)

let nextStreamPage =
let nextStreamPage: AsyncResult<ReadStreamPage, exn> -> AsyncResult<ReadStreamPage, exn> =
AsyncResult.bind (fun (page: ReadStreamPage) -> page.ReadNext |> AsyncResult.ofTask)

module GetAll =

// A function to help wit type inference in this module
let private curriedMap: (ReadAllPage -> 'a) -> AsyncResult<ReadAllPage, exn> -> AsyncResult<'a, exn> =
AsyncResult.map

let messages =
curriedMap (fun page -> page.Messages |> Array.toList)
let messages: AsyncResult<ReadAllPage, exn> -> AsyncResult<StreamMessage list, exn> =
AsyncResult.map (fun page -> page.Messages |> Array.toList)

let messagesData =
let messagesData: AsyncResult<ReadAllPage, exn> -> AsyncResult<string list, exn> =
messages
>> AsyncResult.bind (AsyncResult.mapM (fun msg -> msg.GetJsonData()))
>> AsyncResult.bind (AsyncResult.traverse (fun msg -> msg.GetJsonData()))

let messagesDataAs<'data> =
let messagesDataAs<'data> : AsyncResult<ReadAllPage, exn> -> AsyncResult<'data list, exn> =
messages
>> AsyncResult.bind (AsyncResult.mapM (fun msg -> msg.GetJsonDataAs<'data>()))
>> AsyncResult.bind (AsyncResult.traverse (fun msg -> msg.GetJsonDataAs<'data>()))

let direction = curriedMap (fun page -> page.Direction)
let direction: AsyncResult<ReadAllPage, exn> -> AsyncResult<ReadDirection, exn> =
AsyncResult.map (fun page -> page.Direction)

let fromPosition =
curriedMap (fun page -> page.FromPosition)
let fromPosition: AsyncResult<ReadAllPage, exn> -> AsyncResult<int64, exn> =
AsyncResult.map (fun page -> page.FromPosition)

let isEnd = curriedMap (fun page -> page.IsEnd)
let isEnd: AsyncResult<ReadAllPage, exn> -> AsyncResult<bool, exn> = AsyncResult.map (fun page -> page.IsEnd)

let nextPosition =
curriedMap (fun page -> page.NextPosition)
let nextPosition: AsyncResult<ReadAllPage, exn> -> AsyncResult<int64, exn> =
AsyncResult.map (fun page -> page.NextPosition)

let nextAllStreamPage =
let nextAllStreamPage: AsyncResult<ReadAllPage, exn> -> AsyncResult<ReadAllPage, exn> =
AsyncResult.bind (fun (page: ReadAllPage) -> page.ReadNext |> AsyncResult.ofTask)
4 changes: 2 additions & 2 deletions src/SqlStreamStore.FSharp/Read.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SqlStreamStore.FSharp

open Prelude.ErrorHandling
open Prelude
open System.Threading
open SqlStreamStore
open SqlStreamStore.Streams
Expand Down Expand Up @@ -33,7 +33,7 @@ type ReadAllOption =

module Read =

let partial' (readOptions: ReadPartialOption list) (Stream stream: Stream) : AsyncResult<ReadStreamPage, exn> =
let partial' (readOptions: ReadPartialOption list) (stream: Stream) : AsyncResult<ReadStreamPage, exn> =

let mutable cancellationToken = Unchecked.defaultof<CancellationToken>
let mutable fromVersionInclusive: int option = None
Expand Down
24 changes: 11 additions & 13 deletions src/SqlStreamStore.FSharp/SqlStreamStore.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Extensions.fs"/>
<Compile Include="NewStreamMessage.fs"/>
<Compile Include="Connect.fs"/>
<Compile Include="Read.fs"/>
<Compile Include="Get.fs"/>
<Compile Include="Subscribe.fs"/>
<Compile Include="Append.fs"/>
<Compile Include="Create.fs"/>
<Compile Include="Extensions.fs" />
<Compile Include="NewStreamMessage.fs" />
<Compile Include="Connect.fs" />
<Compile Include="Read.fs" />
<Compile Include="Get.fs" />
<Compile Include="Subscribe.fs" />
<Compile Include="Append.fs" />
<Compile Include="Create.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.*"/>
<PackageReference Include="FSharp.Core" Version="6.0.*"/>
<PackageReference Include="FSharp.Prelude" Version="5.0.*"/>
<PackageReference Include="Npgsql" Version="5.0.*"/>
<PackageReference Include="SqlStreamStore" Version="1.2.0-beta.8"/>
<PackageReference Include="FSharp.Prelude" Version="6.0.0-beta-3" />
<PackageReference Include="Npgsql" Version="5.0.*" />
<PackageReference Include="SqlStreamStore" Version="1.2.0-beta.8" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/SqlStreamStore.FSharp/Subscribe.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SqlStreamStore.FSharp

open Prelude.ErrorHandling
open Prelude
open SqlStreamStore
open SqlStreamStore.Streams
open SqlStreamStore.Subscriptions
Expand All @@ -27,7 +27,7 @@ module Subscribe =
(continueAfterVersion: int)
(streamMessageReceived: IStreamSubscription -> StreamMessage -> CancellationToken -> AsyncResult<_, _>)
(streamSubOptions: StreamSubOption list)
(Stream stream: Stream)
(stream: Stream)
: IStreamSubscription =

let mutable hasCaughtUp = null
Expand Down