UNPKG

@getanthill/datastore

Version:

Event-Sourced Datastore

38 lines (37 loc) 1.21 kB
/// <reference types="node" /> import type { JSONSchemaType, ValidateFunction } from 'ajv'; import type { AnyObject, Telemetry } from '../typings'; import { EventEmitter } from 'events'; import Ajv from 'ajv'; export interface Route { original: string; topic: string; regexp: RegExp; paramNames: string[]; params: { [key: string]: string; }; validate: ValidateFunction; } export interface MessageOptions { source: 'amqp' | 'mqtt'; original: any; delivery: number; ack: () => Promise<void>; nack: () => Promise<void>; } export default class BrokerClient extends EventEmitter { static REGEXP_MATCH_PATH_PARAMETERS: RegExp; protected config: any; protected telemetry?: Telemetry; protected ajv: Ajv; protected spec: any; protected topics: Map<string, any>; constructor(config: any, telemetry?: Telemetry); logOnInvalid(event: any, route: any): void; mapTopic(topic: string, schema: JSONSchemaType<AnyObject>): Route; parseTopic(topic: string, route: Route): Route; getRoute(topic: string): Route | null; topicWithNamespace(topic: string): string; addChannelToSpec(topic: string, schema: any): void; }