From 899ccadfbea4519591f3151d419b349a3bcf3b21 Mon Sep 17 00:00:00 2001 From: ThomasAribart Date: Tue, 14 Mar 2023 20:51:03 +0100 Subject: [PATCH] reworks type following real life usage pbs --- packages/core/src/messaging/message.ts | 30 +++++++------------ .../src/message.ts | 9 ++---- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/packages/core/src/messaging/message.ts b/packages/core/src/messaging/message.ts index c237d5b9..f8bfe418 100644 --- a/packages/core/src/messaging/message.ts +++ b/packages/core/src/messaging/message.ts @@ -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; diff --git a/packages/in-memory-message-bus-adapter/src/message.ts b/packages/in-memory-message-bus-adapter/src/message.ts index 08d54538..2694eb68 100644 --- a/packages/in-memory-message-bus-adapter/src/message.ts +++ b/packages/in-memory-message-bus-adapter/src/message.ts @@ -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 & { + event: { type: EVENT_TYPES }; + } : never : never >;