UNPKG

@tmorin/ceb-messaging-simple

Version:

The package is part of the `<ceb/>` library. It provides an implementation of the messaging model leveraging on a vanilla TypeScript/JavaScript environment.

54 lines (53 loc) 1.92 kB
import { EmittableGateway, Gateway, ObservableGateway } from "@tmorin/ceb-messaging-core"; import { SimpleEventBus } from "./event"; import { SimpleCommandBus } from "./command"; import { SimpleQueryBus } from "./query"; /** * The symbol used to register {@link SimpleGateway}. * * @example Creation and destruction * ```typescript * import { Gateway } from "@tmorin/ceb-messaging-core" * import { SimpleGateway } from "@tmorin/ceb-messaging-simple" * const gateway : Gateway = SimpleGateway.create() * gateway.dispose().catche(e => console.error(e)) * ``` * * @example Global instance * ```typescript * import { MessageBuilder } from "@tmorin/ceb-messaging-core" * import { SimpleGateway } from "@tmorin/ceb-messaging-simple" * const event = MessageBuilder.event("EventA").build() * SimpleGateway.GLOBAL.events.publish(event) * ``` */ export declare const SimpleGatewaySymbol: unique symbol; export declare class SimpleGateway implements Gateway { #private; readonly events: SimpleEventBus; readonly commands: SimpleCommandBus; readonly queries: SimpleQueryBus; readonly emitter: EmittableGateway; readonly observer: ObservableGateway; constructor(events: SimpleEventBus, commands: SimpleCommandBus, queries: SimpleQueryBus, emitter: EmittableGateway, observer?: ObservableGateway); /** * The global instance. * * The {@link SimpleGateway} instance is lazily creation. */ static get GLOBAL(): SimpleGateway; /** * A factory method which creates a new {@link SimpleGateway} at each call. * The instance is created with the default {@link GatewayEmitter}, {@link SimpleEventBus}, {@link SimpleCommandBus} and {@link SimpleQueryBus}. */ static create(): SimpleGateway; /** * Dispose all channels: * * - events * - commands * - queries * - observer */ dispose(): Promise<void>; }