@message-queue-toolkit/core
Advanced tools
Comparing version 13.1.0 to 13.2.0
@@ -0,3 +1,4 @@ | ||
import type { MessageMetadataType } from '../messages/baseMessageSchemas'; | ||
import type { EventRegistry } from './EventRegistry'; | ||
import type { AnyEventHandler, SingleEventHandler, CommonEventDefinition, CommonEventDefinitionSchemaType, EventTypeNames } from './eventTypes'; | ||
import type { AnyEventHandler, SingleEventHandler, CommonEventDefinition, EventTypeNames, CommonEventDefinitionPublisherSchemaType } from './eventTypes'; | ||
export declare class DomainEventEmitter<SupportedEvents extends CommonEventDefinition[]> { | ||
@@ -10,3 +11,3 @@ private readonly eventRegistry; | ||
}); | ||
emit<SupportedEvent extends SupportedEvents[number]>(supportedEvent: SupportedEvent, data: Omit<CommonEventDefinitionSchemaType<SupportedEvent>, 'type'>): Promise<void>; | ||
emit<SupportedEvent extends SupportedEvents[number]>(supportedEvent: SupportedEvent, data: Omit<CommonEventDefinitionPublisherSchemaType<SupportedEvent>, 'type'>, metadata?: Partial<MessageMetadataType>): Promise<void>; | ||
/** | ||
@@ -13,0 +14,0 @@ * Register handler for a specific event |
@@ -12,4 +12,4 @@ "use strict"; | ||
} | ||
async emit(supportedEvent, data) { | ||
const eventTypeName = supportedEvent.consumerSchema.shape.type.value; | ||
async emit(supportedEvent, data, metadata) { | ||
const eventTypeName = supportedEvent.publisherSchema.shape.type.value; | ||
if (!this.eventRegistry.isSupportedEvent(eventTypeName)) { | ||
@@ -34,7 +34,7 @@ throw new node_core_1.InternalError({ | ||
for (const handler of eventHandlers) { | ||
await handler.handleEvent(validatedEvent); | ||
await handler.handleEvent(validatedEvent, metadata); | ||
} | ||
} | ||
for (const handler of this.anyHandlers) { | ||
await handler.handleEvent(validatedEvent); | ||
await handler.handleEvent(validatedEvent, metadata); | ||
} | ||
@@ -41,0 +41,0 @@ } |
import type { ZodObject, ZodTypeAny } from 'zod'; | ||
import type z from 'zod'; | ||
import type { MessageMetadataType } from '../messages/baseMessageSchemas'; | ||
import type { CONSUMER_BASE_EVENT_SCHEMA, PUBLISHER_BASE_EVENT_SCHEMA } from './baseEventSchemas'; | ||
export type EventTypeNames<EventDefinition extends CommonEventDefinition> = CommonEventDefinitionSchemaType<EventDefinition>['type']; | ||
export type EventTypeNames<EventDefinition extends CommonEventDefinition> = CommonEventDefinitionConsumerSchemaType<EventDefinition>['type']; | ||
export type CommonEventDefinition = { | ||
@@ -14,11 +15,12 @@ consumerSchema: ZodObject<Omit<(typeof CONSUMER_BASE_EVENT_SCHEMA)['shape'], 'payload'> & { | ||
}; | ||
export type CommonEventDefinitionSchemaType<T extends CommonEventDefinition> = z.infer<T['consumerSchema']>; | ||
export type EventHandler<EventDefinitionSchema extends CommonEventDefinitionSchemaType<CommonEventDefinition> = CommonEventDefinitionSchemaType<CommonEventDefinition>> = { | ||
handleEvent(event: EventDefinitionSchema): void | Promise<void>; | ||
export type CommonEventDefinitionConsumerSchemaType<T extends CommonEventDefinition> = z.infer<T['consumerSchema']>; | ||
export type CommonEventDefinitionPublisherSchemaType<T extends CommonEventDefinition> = z.infer<T['publisherSchema']>; | ||
export type EventHandler<EventDefinitionSchema extends CommonEventDefinitionConsumerSchemaType<CommonEventDefinition> = CommonEventDefinitionConsumerSchemaType<CommonEventDefinition>, MetadataDefinitionSchema extends Partial<MessageMetadataType> = Partial<MessageMetadataType>> = { | ||
handleEvent(event: EventDefinitionSchema, metadata?: MetadataDefinitionSchema): void | Promise<void>; | ||
}; | ||
export type AnyEventHandler<EventDefinitions extends CommonEventDefinition[]> = EventHandler<CommonEventDefinitionSchemaType<EventDefinitions[number]>>; | ||
export type AnyEventHandler<EventDefinitions extends CommonEventDefinition[]> = EventHandler<CommonEventDefinitionConsumerSchemaType<EventDefinitions[number]>>; | ||
export type SingleEventHandler<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = EventHandler<EventFromArrayByTypeName<EventDefinition, EventTypeName>>; | ||
type EventFromArrayByTypeName<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = Extract<CommonEventDefinitionSchemaType<EventDefinition[number]>, { | ||
type EventFromArrayByTypeName<EventDefinition extends CommonEventDefinition[], EventTypeName extends EventTypeNames<EventDefinition[number]>> = Extract<CommonEventDefinitionConsumerSchemaType<EventDefinition[number]>, { | ||
type: EventTypeName; | ||
}>; | ||
export {}; |
@@ -0,6 +1,8 @@ | ||
import type { MessageMetadataType } from '../../messages/baseMessageSchemas'; | ||
import type { AnyEventHandler, CommonEventDefinition } from '../eventTypes'; | ||
export declare class FakeListener<SupportedEvents extends CommonEventDefinition[]> implements AnyEventHandler<SupportedEvents> { | ||
receivedEvents: SupportedEvents[number]['consumerSchema']['_output'][]; | ||
receivedMetadata: MessageMetadataType[]; | ||
constructor(_supportedEvents: SupportedEvents); | ||
handleEvent(event: SupportedEvents[number]['consumerSchema']['_output']): void | Promise<void>; | ||
handleEvent(event: SupportedEvents[number]['consumerSchema']['_output'], metadata: MessageMetadataType): void | Promise<void>; | ||
} |
@@ -6,7 +6,9 @@ "use strict"; | ||
receivedEvents = []; | ||
receivedMetadata = []; | ||
constructor(_supportedEvents) { | ||
this.receivedEvents = []; | ||
} | ||
handleEvent(event) { | ||
handleEvent(event, metadata) { | ||
this.receivedEvents.push(event); | ||
this.receivedMetadata.push(metadata); | ||
} | ||
@@ -13,0 +15,0 @@ } |
{ | ||
"name": "@message-queue-toolkit/core", | ||
"version": "13.1.0", | ||
"version": "13.2.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
108722
1634