-
Notifications
You must be signed in to change notification settings - Fork 700
Open
Labels
Description
In the v2 Journalist API, events are explicitly typed as a 2-tuple of:
Event.typeEvent.data(optional)
It occurs to me that they are implicitly typed further as a 3-tuple of (1) and (2) plus:
Although (2) is optional, it's strong: An event will be rejected if its data has the wrong schema for its type.
By contrast, although (3) is required, it's weak: A handler will attempt to process an event with a valid target of the wrong schema, for example an ItemDeleted event with a SourceTarget instead of an ItemTarget. The handler will fail correctly, but it will fail while handling the event rather than while validating it.
I see three options:
- Do nothing. Events with invalid targets will continue to fail during handling rather than validation.
- Define
EVENT_TARGET_TYPESjust likeEVENT_DATA_TYPES. Reject events with invalid targets during validation. - Define a parameterized decorator. Let individual handler methods reject events with unexpected targets, e.g.:
@expect(SourceTarget)@expect(ItemTarget)@expect(ItemTarget, SourceTarget)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Ready to go