Skip to content

Commit

Permalink
Remove usage of __
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 4, 2022
1 parent addfa01 commit bbc5548
Show file tree
Hide file tree
Showing 27 changed files with 146 additions and 147 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ The `Unreleased` section name is replaced by the expected version of next releas

### Added

- `Equinox`: `Decider.Transact(interpret : 'state -> Async<'event list>)` [#308](https://github.com/jet/equinox/pull/308)
- `Equinox`: `Decider.Transact(interpret : 'state -> Async<'event list>)` [#314](https://github.com/jet/equinox/pull/314)

### Changed

- `eqx`/`Equinox.Tool`: Flip `-P` option to opt _in_ to pretty printing [#313](https://github.com/jet/equinox/pull/313)
- `Equinox`: rename `Decider.TransactAsync` to `Transact` [#308](https://github.com/jet/equinox/pull/308)
- `Equinox`: rename `Decider.TransactAsync` to `Transact` [#314](https://github.com/jet/equinox/pull/314)
- `CosmosStore`: Require `Microsoft.Azure.Cosmos` v `3.0.25` [#310](https://github.com/jet/equinox/pull/310)
- `CosmosStore`: Switch to natively using `JsonElement` event bodies [#305](https://github.com/jet/equinox/pull/305) :pray: [@ylibrach](https://github.com/ylibrach)
- `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)
Expand Down
6 changes: 3 additions & 3 deletions samples/Infrastructure/Services.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ type StreamResolver(storage) =
type ServiceBuilder(storageConfig, handlerLog) =
let cat = StreamResolver(storageConfig)

member __.CreateFavoritesService() =
member _.CreateFavoritesService() =
let fold, initial = Favorites.Fold.fold, Favorites.Fold.initial
let snapshot = Favorites.Fold.isOrigin,Favorites.Fold.snapshot
Favorites.create handlerLog (cat.Resolve(Favorites.Events.codec,fold,initial,snapshot))

member __.CreateSaveForLaterService() =
member _.CreateSaveForLaterService() =
let fold, initial = SavedForLater.Fold.fold, SavedForLater.Fold.initial
let snapshot = SavedForLater.Fold.isOrigin,SavedForLater.Fold.compact
SavedForLater.create 50 handlerLog (cat.Resolve(SavedForLater.Events.codec,fold,initial,snapshot))

member __.CreateTodosService() =
member _.CreateTodosService() =
let fold, initial = TodoBackend.Fold.fold, TodoBackend.Fold.initial
let snapshot = TodoBackend.Fold.isOrigin, TodoBackend.Fold.snapshot
TodoBackend.create handlerLog (cat.Resolve(TodoBackend.Events.codec,fold,initial,snapshot))
Expand Down
32 changes: 16 additions & 16 deletions samples/Store/Domain/Cart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,20 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
accumulated |> fold originState

/// Invoke a decision function, gathering the events (if any) that it decides are necessary into the `Accumulated` sequence
member _.Transact(interpret : 'state -> 'event list) : unit =
interpret __.State |> accumulated.AddRange
member x.Transact(interpret : 'state -> 'event list) : unit =
interpret x.State |> accumulated.AddRange
/// Invoke an Async decision function, gathering the events (if any) that it decides are necessary into the `Accumulated` sequence
member _.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret __.State
member x.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret x.State
accumulated.AddRange events }
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
member _.Transact(decide : 'state -> 'result * 'event list) : 'result =
let result, newEvents = decide __.State
member x.Transact(decide : 'state -> 'result * 'event list) : 'result =
let result, newEvents = decide x.State
accumulated.AddRange newEvents
result
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
member _.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide __.State
member x.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide x.State
accumulated.AddRange newEvents
return result }
#else
Expand All @@ -136,29 +136,29 @@ let interpretMany fold interpreters (state : 'state) : 'state * 'event list =

type Service internal (resolve : CartId * Equinox.ResolveOption option -> Equinox.Decider<Events.Event, Fold.State>) =

member __.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
member _.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
#if ACCUMULATOR
let acc = Accumulator(Fold.fold, state)
for cmd in commands do
acc.Transact(interpret cmd)
return acc.State, acc.Accumulated }
return acc.State, acc.Accumulated })
#else
return interpretMany Fold.fold (Seq.map interpret commands) state })
#endif

member __.ExecuteManyAsync(cartId, optimistic, commands : Command seq, ?prepare) : Async<unit> =
__.Run(cartId, optimistic, commands, ?prepare=prepare) |> Async.Ignore
member x.ExecuteManyAsync(cartId, optimistic, commands : Command seq, ?prepare) : Async<unit> =
x.Run(cartId, optimistic, commands, ?prepare=prepare) |> Async.Ignore

member __.Execute(cartId, command) =
__.ExecuteManyAsync(cartId, false, [command])
member x.Execute(cartId, command) =
x.ExecuteManyAsync(cartId, false, [command])

member __.Read cartId =
member _.Read cartId =
let decider = resolve (cartId,None)
decider.Query id
member __.ReadStale cartId =
member _.ReadStale cartId =
let decider = resolve (cartId,Some Equinox.ResolveOption.AllowStale)
decider.Query id

Expand Down
4 changes: 2 additions & 2 deletions samples/Store/Domain/ContactPreferences.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ type Service internal (resolve : Id -> Equinox.Decider<Events.Event, Fold.State>
let command = let (Id email) = email in Update { email = email; preferences = value }
decider.Transact(interpret command)

member __.Update(email, value) =
member _.Update(email, value) =
update email value

member __.Read(email) =
member _.Read(email) =
let decider = resolve email
decider.Query id

Expand Down
8 changes: 4 additions & 4 deletions samples/Store/Domain/Favorites.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ module Fold =
let favorite (e : Events.Favorited) = dict.[e.skuId] <- e
let favoriteAll (xs: Events.Favorited seq) = for x in xs do favorite x
do favoriteAll input
member __.ReplaceAllWith xs = dict.Clear(); favoriteAll xs
member __.Favorite(e : Events.Favorited) = favorite e
member __.Unfavorite id = dict.Remove id |> ignore
member __.AsState() = Seq.toArray dict.Values
member _.ReplaceAllWith xs = dict.Clear(); favoriteAll xs
member _.Favorite(e : Events.Favorited) = favorite e
member _.Unfavorite id = dict.Remove id |> ignore
member _.AsState() = Seq.toArray dict.Values

let initial : State = [||]
let private evolve (s: InternalState) = function
Expand Down
4 changes: 2 additions & 2 deletions samples/Store/Domain/InventoryItem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ let interpret command (state : Fold.State) =

type Service internal (resolve : InventoryItemId -> Equinox.Decider<Events.Event, Fold.State>) =

member __.Execute(itemId, command) =
member _.Execute(itemId, command) =
let decider = resolve itemId
decider.Transact(interpret command)

member __.Read(itemId) =
member _.Read(itemId) =
let decider = resolve itemId
decider.Query id

Expand Down
12 changes: 6 additions & 6 deletions samples/Store/Domain/SavedForLater.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ module Fold =
let index = Dictionary<_,_>()
do for i in externalState do index.[i.skuId] <- i

member __.Replace (skus : seq<Item>) =
member _.Replace (skus : seq<Item>) =
index.Clear() ; for s in skus do index.[s.skuId] <- s
member __.Append(skus : seq<Item>) =
member _.Append(skus : seq<Item>) =
for sku in skus do
let ok,found = index.TryGetValue sku.skuId
if not ok || found |> isSupersededAt sku.dateSaved then
index.[sku.skuId] <- sku
member __.Remove (skus : seq<SkuId>) =
member _.Remove (skus : seq<SkuId>) =
for sku in skus do index.Remove sku |> ignore
member __.ToExernalState () =
member _.ToExernalState () =
index.Values |> Seq.sortBy (fun s -> -s.dateSaved.Ticks, s.skuId) |> Seq.toArray

type State = Item []
Expand Down Expand Up @@ -77,7 +77,7 @@ type private Index(state : Events.Item seq) =
let index = Dictionary<_,_>()
do for i in state do do index.[i.skuId] <- i

member __.DoesNotAlreadyContainSameOrMoreRecent effectiveDate sku =
member _.DoesNotAlreadyContainSameOrMoreRecent effectiveDate sku =
match index.TryGetValue sku with
| true,item when item.dateSaved >= effectiveDate -> false
| _ -> true
Expand Down Expand Up @@ -125,7 +125,7 @@ type Service internal (resolve : ClientId -> Equinox.Decider<Events.Event, Fold.
let _, events = decide maxSavedItems cmd state
return (),events } )

member __.MaxSavedItems = maxSavedItems
member _.MaxSavedItems = maxSavedItems

member __.List clientId : Async<Events.Item []> = read clientId

Expand Down
4 changes: 2 additions & 2 deletions samples/Store/Integration/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type TestOutputAdapter(testOutput : Xunit.Abstractions.ITestOutputHelper) =
use writer = new System.IO.StringWriter()
formatter.Format(logEvent, writer)
writer |> string |> testOutput.WriteLine
interface Serilog.Core.ILogEventSink with member __.Emit logEvent = writeSerilogEvent logEvent
interface Serilog.Core.ILogEventSink with member _.Emit logEvent = writeSerilogEvent logEvent

[<AutoOpen>]
module SerilogHelpers =
Expand All @@ -41,4 +41,4 @@ module SerilogHelpers =
LoggerConfiguration()
.WriteTo.Sink(sink)
.WriteTo.Seq("http://localhost:5341")
.CreateLogger()
.CreateLogger()
2 changes: 1 addition & 1 deletion samples/Store/Integration/LogIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type SerilogMetricsExtractor(emit : string -> unit) =
emitEvent logEvent
| GenericMessage () as logEvent ->
emitEvent logEvent
interface Serilog.Core.ILogEventSink with member __.Emit logEvent = handleLogEvent logEvent
interface Serilog.Core.ILogEventSink with member _.Emit logEvent = handleLogEvent logEvent

let createLoggerWithMetricsExtraction emit =
let capture = SerilogMetricsExtractor emit
Expand Down
6 changes: 3 additions & 3 deletions samples/TodoBackend/Todo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ type Service internal (resolve : ClientId -> Equinox.Decider<Events.Event, Fold.
let state' = Fold.fold state events
state'.items,events)

member __.List(clientId) : Async<Events.Todo seq> =
member _.List(clientId) : Async<Events.Todo seq> =
query clientId (fun s -> s.items |> Seq.ofList)

member __.TryGet(clientId, id) =
member _.TryGet(clientId, id) =
query clientId (fun x -> x.items |> List.tryFind (fun x -> x.id = id))

member __.Execute(clientId, command) : Async<unit> =
member _.Execute(clientId, command) : Async<unit> =
execute clientId command

member __.Create(clientId, template: Events.Todo) : Async<Events.Todo> = async {
Expand Down
6 changes: 3 additions & 3 deletions samples/Tutorial/Cosmos.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ module Favorites =

type Service internal (resolve : string -> Equinox.Decider<Events.Event, Fold.State>) =

member __.Favorite(clientId, sku) =
member _.Favorite(clientId, sku) =
let decider = resolve clientId
decider.Transact(interpret (Add sku))
member __.Unfavorite(clientId, skus) =
member _.Unfavorite(clientId, skus) =
let decider = resolve clientId
decider.Transact(interpret (Remove skus))
member __.List clientId: Async<string list> =
member _.List clientId: Async<string list> =
let decider = resolve clientId
decider.Query id

Expand Down
6 changes: 3 additions & 3 deletions samples/Tutorial/Counter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ let decide command (State state) =

type Service internal (resolve : string -> Equinox.Decider<Event, State>) =

member __.Execute(instanceId, command) : Async<unit> =
member _.Execute(instanceId, command) : Async<unit> =
let decider = resolve instanceId
decider.Transact(decide command)

member __.Reset(instanceId, value) : Async<unit> =
member _.Reset(instanceId, value) : Async<unit> =
__.Execute(instanceId, Clear value)

member __.Read instanceId : Async<int> =
member _.Read instanceId : Async<int> =
let decider = resolve instanceId
decider.Query(fun (State value) -> value)

Expand Down
6 changes: 3 additions & 3 deletions samples/Tutorial/Todo.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ type Service internal (resolve : string -> Equinox.Decider<Event, State>) =
let decider = resolve clientId
decider.Query projection

member __.List clientId : Async<Todo seq> =
member _.List clientId : Async<Todo seq> =
query clientId (fun s -> s.items |> Seq.ofList)
member __.TryGet(clientId, id) =
member _.TryGet(clientId, id) =
query clientId (fun x -> x.items |> List.tryFind (fun x -> x.id = id))
member __.Execute(clientId, command) : Async<unit> =
member _.Execute(clientId, command) : Async<unit> =
execute clientId command
member __.Create(clientId, template: Todo) : Async<Todo> = async {
let! state' = handle clientId (Add template)
Expand Down
4 changes: 2 additions & 2 deletions samples/Web/Controllers/FavoritesController.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ type FavoritesController(service : Favorites.Service) =
inherit ControllerBase()

[<HttpGet>]
member __.Get
member _.Get
( [<FromClientIdHeader>]clientId : ClientId) = async {
let! res = service.List(clientId)
return ActionResult<_> res
}

[<HttpPost>]
member __.Favorite
member _.Favorite
( [<FromClientIdHeader>]clientId : ClientId,
[<FromBody>]skuIds : SkuId[]) = async {
return! service.Favorite(clientId,List.ofArray skuIds)
Expand Down
8 changes: 4 additions & 4 deletions samples/Web/Controllers/SavesController.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ type SavesController(service : SavedForLater.Service) =
inherit ControllerBase()

[<HttpGet>]
member __.Get
member _.Get
( [<FromClientIdHeader>]clientId : ClientId) = async {
let! res = service.List(clientId)
return ActionResult<_> res
}

// Returns 400 if item limit exceeded
[<HttpPost>]
member __.Save
member x.Save
( [<FromClientIdHeader>]clientId : ClientId,
[<FromBody>]skuIds : SkuId[]) : Async<ActionResult> = async {
let! ok = service.Save(clientId, List.ofArray skuIds)
if ok then return __.NoContent() :> _ else return __.BadRequest("Exceeded maximum number of items in Saved list; please validate before requesting Save.") :> _
if ok then return x.NoContent() :> _ else return x.BadRequest("Exceeded maximum number of items in Saved list; please validate before requesting Save.") :> _
}
[<HttpDelete>]
member __.Remove
member _.Remove
( [<FromClientIdHeader>]clientId : ClientId,
[<FromBody>]skuIds : SkuId[]) : Async<unit> = async {
let resolveSkus _hasSavedSku = async { return skuIds }
Expand Down
24 changes: 12 additions & 12 deletions samples/Web/Controllers/TodosController.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,38 @@ type TodosController(service: Service) =

let toModel (value : TodoView) : Events.Todo = { id = value.id; order = value.order; title = value.title; completed = value.completed }

member private __.WithUri(x : Events.Todo) : TodoView =
let url = __.Url.RouteUrl("GetTodo", { id=x.id }, __.Request.Scheme) // Supplying scheme is secret sauce for making it absolute as required by client
member private this.WithUri(x : Events.Todo) : TodoView =
let url = this.Url.RouteUrl("GetTodo", { id=x.id }, this.Request.Scheme) // Supplying scheme is secret sauce for making it absolute as required by client
{ id = x.id; url = url; order = x.order; title = x.title; completed = x.completed }

[<HttpGet>]
member __.Get([<FromClientIdHeader>]clientId : ClientId) = async {
member this.Get([<FromClientIdHeader>]clientId : ClientId) = async {
let! xs = service.List(clientId)
return seq { for x in xs -> __.WithUri(x) }
return seq { for x in xs -> this.WithUri(x) }
}

[<HttpGet("{id}", Name="GetTodo")>]
member __.Get([<FromClientIdHeader>]clientId : ClientId, id) : Async<IActionResult> = async {
member this.Get([<FromClientIdHeader>]clientId : ClientId, id) : Async<IActionResult> = async {
let! x = service.TryGet(clientId, id)
return match x with None -> __.NotFound() :> _ | Some x -> ObjectResult(__.WithUri x) :> _
return match x with None -> this.NotFound() :> _ | Some x -> ObjectResult(this.WithUri x) :> _
}

[<HttpPost>]
member __.Post([<FromClientIdHeader>]clientId : ClientId, [<FromBody>]value : TodoView) : Async<TodoView> = async {
member this.Post([<FromClientIdHeader>]clientId : ClientId, [<FromBody>]value : TodoView) : Async<TodoView> = async {
let! created = service.Create(clientId, toModel value)
return __.WithUri created
return this.WithUri created
}

[<HttpPatch "{id}">]
member __.Patch([<FromClientIdHeader>]clientId : ClientId, id, [<FromBody>]value : TodoView) : Async<TodoView> = async {
member this.Patch([<FromClientIdHeader>]clientId : ClientId, id, [<FromBody>]value : TodoView) : Async<TodoView> = async {
let! updated = service.Patch(clientId, { toModel value with id = id })
return __.WithUri updated
return this.WithUri updated
}

[<HttpDelete "{id}">]
member __.Delete([<FromClientIdHeader>]clientId : ClientId, id): Async<unit> =
member _.Delete([<FromClientIdHeader>]clientId : ClientId, id): Async<unit> =
service.Execute(clientId, Delete id)

[<HttpDelete>]
member __.DeleteAll([<FromClientIdHeader>]clientId : ClientId): Async<unit> =
member _.DeleteAll([<FromClientIdHeader>]clientId : ClientId): Async<unit> =
service.Execute(clientId, Clear)
Loading

0 comments on commit bbc5548

Please sign in to comment.