jet / dotnet-templates

Example app and service templates `dotnet new -i Equinox.Templates; dotnet new eqx*/pro*` https://github.com/jet/equinox https://github.com/jet/FsCodec
https://github.com/jet/propulsion
Apache License 2.0
64 stars 16 forks source link

refactor: Track updates, CategoryName #134

Closed bartelink closed 9 months ago

bartelink commented 1 year ago

@nordfjord

bartelink commented 1 year ago

(comment at time pf first commit)

maybe sid.Gen should be called streamId and kept private in the CategoryId impl?

then sid can be called catId or cid ?

as for sid.Category, maybe that means going back to it being a top level Literal? But it was actually good that the default was that people cant just randomly refer to Aggregate.Category from anywhere across the galaxy

bartelink commented 1 year ago

Tried to apply here but it does not make things better

However in a closed source codebase where things are symmetric (i.e. all SNs get roundtripped in tests or reactors), this helper works well

type internal CategoryId<'ids>(name, gen: 'ids -> FsCodec.StreamId, dec: FsCodec.StreamId -> 'ids) =
    member _.StreamName = gen >> FsCodec.StreamName.create name
    member _.DecodeId = dec
    member _.TryDecode = FsCodec.StreamName.tryFind name >> ValueOption.map dec

it also forces instances to be internal, e.g.

let [<Literal>] private CategoryName = "invitationprocess"
let private catId = CategoryId(CategoryName, streamId, FsCodec.StreamId.dec2 TenantId.parse InvitationId.parse)

which is consumed by tests and reactions via:

module Reactions =

    let [<return: Struct>] (|For|_|) = catId.TryDecode

    let dec = Streams.Codec.dec<Events.Event>
    let config = catId.StreamName, dec
    let [<return: Struct>] (|Decode|_|) = function
        | struct (For id, _) & Streams.Decode dec events -> ValueSome struct (id, events)
        | _ -> ValueNone
    let deletionNamePrefix tenantIdStr = $"%s{CategoryName}-%s{tenantIdStr}"

So maybe module Stream goes away in the guidance to be replaced with that canonical helper?

bartelink commented 1 year ago

related https://github.com/jet/FsCodec/pull/103

bartelink commented 9 months ago

@nordfjord I ended up putting CategoryId into the mix in https://github.com/jet/dotnet-templates/pull/134/commits/e0ed634119534c1915135059614a5e2c276d663a for any place where there's a .dec being used, which works well IME... Now I need to update the docs

bartelink commented 9 months ago

(thought this was merging to master 🤦 - ended up cherry-picking it to master in 482203a3df085a584fbbf8391da928d88b700978)