Skip to content

Commit

Permalink
Merge pull request #65 from castore-dev/take-learnings-from-real-life
Browse files Browse the repository at this point in the history
fix: rework types following real life usage pbs
  • Loading branch information
ThomasAribart authored Mar 14, 2023
2 parents 5bbe173 + 899ccad commit 28901b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
30 changes: 11 additions & 19 deletions packages/core/src/messaging/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,21 @@ import type {

export type NotificationMessage<
EVENT_STORE_ID extends string = string,
EVENT_DETAILS extends EventDetail = EventDetail,
> = EVENT_DETAILS extends infer EVENT_DETAIL
? EVENT_DETAIL extends EventDetail
? {
eventStoreId: EVENT_STORE_ID;
event: EVENT_DETAIL;
}
: never
: never;
EVENT_DETAIL extends EventDetail = EventDetail,
> = {
eventStoreId: EVENT_STORE_ID;
event: EVENT_DETAIL;
};

export type StateCarryingMessage<
EVENT_STORE_ID extends string = string,
EVENT_DETAILS extends EventDetail = EventDetail,
EVENT_DETAIL extends EventDetail = EventDetail,
AGGREGATE extends Aggregate = Aggregate,
> = EVENT_DETAILS extends infer EVENT_DETAIL
? EVENT_DETAIL extends EventDetail
? {
eventStoreId: EVENT_STORE_ID;
event: EVENT_DETAIL;
aggregate: AGGREGATE;
}
: never
: never;
> = {
eventStoreId: EVENT_STORE_ID;
event: EVENT_DETAIL;
aggregate: AGGREGATE;
};

export type Message = NotificationMessage | StateCarryingMessage;

Expand Down
9 changes: 3 additions & 6 deletions packages/in-memory-message-bus-adapter/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ export type InMemoryMessageBusMessage<
> = Prettify<
EVENT_STORE_IDS extends infer EVENT_STORE_ID
? EVENT_STORE_ID extends string
? EVENT_TYPES extends infer EVENT_TYPE
? Extract<
MESSAGE,
{ eventStoreId: EVENT_STORE_IDS; event: { type: EVENT_TYPE } }
>
: never
? Extract<MESSAGE, { eventStoreId: EVENT_STORE_ID }> & {
event: { type: EVENT_TYPES };
}
: never
: never
>;
Expand Down

0 comments on commit 28901b6

Please sign in to comment.