UNPKG

@getanthill/datastore

Version:

Event-Sourced Datastore

72 lines (71 loc) 4.71 kB
/// <reference types="node" /> /// <reference types="node" /> import type { ProcessDestroySignal, HandlerBuilderFunc, RunnerServices, StopFunc, HandlerFunc, RunnerTrigger, AnyObject, Source } from '../typings'; import type { IncomingMessage, Server, ServerResponse } from 'http'; import type { MessageOptions, Route } from '../services/broker'; import { Command } from 'commander'; import type Datastore from './Datastore'; declare let server: Server<typeof IncomingMessage, typeof ServerResponse> | null; export interface ProcessingStats { processingTimeWindowInMilliseconds: number; queuing: number; waiting: number; waited: number; processing: number; processed: number; progress: number; totalWaitingDurationInMilliseconds: number; averageWaitingDurationInMilliseconds: number; totalProcessingDurationInMilliseconds: number; averageProcessingDurationInMilliseconds: number; maxParallelEvents: number; } export declare function getServer(): Server<typeof IncomingMessage, typeof ServerResponse> | null; export declare function setServer(_server: typeof server): Server<typeof IncomingMessage, typeof ServerResponse> | null; export declare function log(services: RunnerServices | undefined, options: { verbose?: boolean; }, level: string, message: string, context?: { [key: string]: any; }): void; export declare function init(services: RunnerServices, stopHandler: StopFunc, options: any): void; export declare function signalHandler(services: RunnerServices, stopHandler: StopFunc, options: any, signal: ProcessDestroySignal, destroyHandler?: typeof destroy): () => Promise<NodeJS.Timeout>; export declare function errorHandler(services: RunnerServices, stopHandler: StopFunc, options: any, signal: ProcessDestroySignal, destroyHandler?: typeof destroy): (err: Error) => Promise<NodeJS.Timeout>; /** * Cleanup and stop the process properly, then exit the process. * @param signal - Signal to stop the process with * @param err - Error that caused the destruction of the process */ export declare function destroy(services: RunnerServices | undefined, stopHandler: StopFunc | undefined, options: any, signal: ProcessDestroySignal, err?: Error): Promise<NodeJS.Timeout>; export declare function stop(services?: RunnerServices, options?: any, stopHandler?: StopFunc): Promise<void>; export declare function heartbeat(port?: string | undefined): Promise<{ app: import("express-serve-static-core").Express; server: Server<typeof IncomingMessage, typeof ServerResponse>; port: string | undefined; }>; export declare function getDatastoreFromTrigger(services: RunnerServices, trigger: RunnerTrigger, options: { timeout: number; }): Promise<Datastore>; export declare function mapReceivedData(input: string | object, raw: boolean): string | object; export declare function readyForProcessing(stats: ProcessingStats): boolean; export declare function waitForProcessing(stats: ProcessingStats, queueId: number, waitTimeInMilliseconds?: number, maxWaitInMilliseconds?: number): Promise<void>; export declare function isDataProcessed(services: RunnerServices, datastore: string, model: string, input: any, processingStateIndex: number, processing?: RunnerTrigger['processing']): Promise<boolean>; export declare function shouldProcessData(services: RunnerServices, datastore: string, model: string, input: any, processing?: RunnerTrigger['processing']): Promise<boolean>; export declare function getProcessingStats(from?: Partial<ProcessingStats>): ProcessingStats; export declare function localEventHandler(services: RunnerServices, handler: HandlerFunc, handlerId: string, datastore: string, model: string, source: Source, raw: boolean, stats?: ProcessingStats, processing?: RunnerTrigger['processing']): (input: string | object, route?: Route, headers?: AnyObject, opts?: MessageOptions) => Promise<any>; export declare function buildHandler(handlerId: string, cmd: any, handlersForTest?: { [key: string]: HandlerBuilderFunc; }): Promise<{ services: RunnerServices; triggers: RunnerTrigger[]; stop: StopFunc; handler: HandlerFunc; }>; export declare function start(): (handlerIds: string[], options: any, command: any, handlersForTest?: { [key: string]: HandlerBuilderFunc; }) => Promise<void>; export declare function replayHandler(handlerId: string, options: any, services: RunnerServices, triggers: RunnerTrigger[], stopHandler: StopFunc, handler: HandlerFunc): Promise<void>; export declare function replay(): (handlerIds: string[], options: any, command: any, handlersForTest?: { [key: string]: HandlerBuilderFunc; }) => Promise<void>; export default function register(name?: string): Command; export {};