feat: generalize event serialization/deserialization with decorators - #10
feat: generalize event serialization/deserialization with decorators#10tjschutte wants to merge 4 commits into
Conversation
tjschutte
commented
Aug 25, 2025
- Add EventRegistry with @registerEvent and @serializable decorators
- Replace hard-coded event type mappings with automatic registration
- Eliminate repetitive serialization/deserialization code per event type
- Update ApplicationSubmitted and ApplicationEvaluated to use decorators
- Add EventRegistry with @registerEvent and @serializable decorators - Replace hard-coded event type mappings with automatic registration - Eliminate repetitive serialization/deserialization code per event type - Update ApplicationSubmitted and ApplicationEvaluated to use decorators
|
The thing about this approach is that the compiler has no way to tell us when we get things incorrectly like the fields required for the event payload when calling We want to leverage the type-checker's knowledge of the fields in each event from the event's declaration to make sure that we can never get this wrong. One very important issue with this approach is that if the serialised payload has incorrect fields for whatever reason (e.g. a field is a string but the event constructor expected a number) this passes this value with the incorrect type to the event constructor. This breaks the type contract of the constructor and will cause undefined behaviour. We want all of our functions to be able to specify a type for their parameters and be confident that they will never be given different types and will never have to check that the types are correct. This is the cornerstone of type safety. So if a serialised value has an unexpected type, we want this to be a deserialisation error and the constructor should never be called. Another relevant point is that we will want to have rich abstract types as part of events, but their serialised representation might be different from their runtime representation. For example, an On the Ashraf repo, for example, we allow that and have a rich set of types with independent runtime representation. |
|
I'm closing this as we have a type-directed encoding and decoding approach in place now.
This gives us:
With this in place we have a very strong barrier between our system and the outside world and we are guaranteeing that any data within the system conforms to our strict type expectations. |