UNPKG

@auto-engineer/message-bus

Version:

Message bus for handling commands, events, and queries

43 lines 1.53 kB
import type { Command, Event, CommandHandler } from './types'; type CommandData<C> = C extends Command<string, infer D> ? D : never; type CommandType<C> = C extends Command<infer T, Record<string, unknown>> ? T : never; export interface FieldDefinition<T> { description: string; required?: T extends undefined ? false : true; flag?: boolean; } export interface PackageMetadata { name: string; version?: string; description?: string; } export interface UnifiedCommandHandler<C extends Command<string, Record<string, unknown>>> extends CommandHandler { alias: string; description: string; category?: string; package?: PackageMetadata; fields: { [K in keyof CommandData<C>]: FieldDefinition<CommandData<C>[K]>; }; examples: string[]; handle: (command: Command) => Promise<Event | Event[] | void>; } /** * Define a command handler with full type safety and metadata * @param config The command handler configuration * @returns A command handler with manifest metadata */ export declare function defineCommandHandler<C extends Command<string, Record<string, unknown>>>(config: { name: CommandType<C>; alias: string; description: string; category?: string; package?: PackageMetadata; fields: { [K in keyof CommandData<C>]: FieldDefinition<CommandData<C>[K]>; }; examples: string[]; handle: (command: C) => Promise<Event | Event[] | void>; }): UnifiedCommandHandler<C>; export {}; //# sourceMappingURL=define-command.d.ts.map