Closed bartelink closed 9 months 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
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?
@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
(thought this was merging to master 🤦 - ended up cherry-picking it to master in 482203a3df085a584fbbf8391da928d88b700978)
@nordfjord