EventSauce icon indicating copy to clipboard operation
EventSauce copied to clipboard

Prioritise generic type of payload over aggregate root

Open lcobucci opened this issue 6 months ago • 8 comments

As per @shirshir's comment, not every use case uses aggregates but the payload is always present...

Having TPayload as the first type information would be extremely valuable for advanced static analysis without forcing folks to always pass the TId.

Sample use: https://phpstan.org/r/12e2b0f9-4689-4694-a0b9-ba7f8facf689

This is technically a BC-break, though...

@frankdejonge @markinigor what are your thoughts on this?

lcobucci avatar Jul 04 '25 08:07 lcobucci

I think we can make it non BC breaking by providing a default of object.

frankdejonge avatar Jul 04 '25 08:07 frankdejonge

Love this idea! Happy to help implement this if you'd like. Let me know if you want to collaborate on a PR or if you're planning to tackle it yourself.

markinigor avatar Jul 04 '25 09:07 markinigor

That's exactly what I'm suggesting on the sample link.

However, people who are using Message<MyCustomAggregateId> will be hit when rolling out a version that expects that to be the payload, and have to change it to Message<object, MyCustomAggregateId>.

In theory the adoption is limited, so shouldn't be a huge impact buuuut I wanted to check before sending something in.

lcobucci avatar Jul 04 '25 09:07 lcobucci

Let me know if you want to collaborate on a PR or if you're planning to tackle it yourself.

Thanks for the offer @markinigor. It's a pretty quick patch: https://github.com/EventSaucePHP/EventSauce/pull/242

(no need to rush things, btw)

lcobucci avatar Jul 04 '25 09:07 lcobucci

@lcobucci while I understand for your use-case, this prioritisation makes sense, I actually think it's not the dominant case for people who use this for event-sourcing primarily. In the default case, I think it'll be common to hint only the aggregate ID whilst doing instanceof checks in consumers and what not. I'll have a ponder of it, but I think we should entertain the idea to append that type, rather than making the BC break.

frankdejonge avatar Jul 04 '25 10:07 frankdejonge

@frankdejonge that makes sense and I'm quite fine with shifting the payload type to the end 👍

I'll apply the changes next week.

lcobucci avatar Jul 04 '25 11:07 lcobucci

@lcobucci feel free to ping me on signal for a review 👍

frankdejonge avatar Jul 04 '25 12:07 frankdejonge

@frankdejonge 5 centuries later... I've just pushed the requested changes to https://github.com/EventSaucePHP/EventSauce/pull/242

lcobucci avatar Oct 02 '25 14:10 lcobucci