UNPKG

@eang/core

Version:

eang - model driven enterprise event processing

121 lines (120 loc) 3.53 kB
import { ConsumerStream, NatsStreamService } from './NatsStreamingService.js'; import { NatsConnection } from '@nats-io/nats-core'; import { JetStreamClient, JetStreamManager, JetStreamPublishOptions } from '@nats-io/jetstream'; import { FunctionStartContext, IFunctionStopContext } from './context.js'; import { EntityEvent } from './entity.js'; export type EangFunctionHandler<TInput extends object = any, TOutput extends object = any> = (input: TInput, eang: EangFunction, context?: FunctionStartContext) => Promise<IFunctionStopContext<TOutput>>; export interface EangServiceOptions { consumerName: string; subscriptions: string[]; env?: { [key: string]: string; }; secrets?: { [key: string]: string; }; } export interface EangFunctionOptions { handler: EangFunctionHandler; env?: { [key: string]: string; }; secrets?: { [key: string]: string; }; } export interface IPublishingOptions { tenant: string; organizationalUnit?: string; user: string; jetStreamOptions?: Partial<JetStreamPublishOptions>; } export interface IEangBase { env: { [key: string]: string; }; secrets: { [key: string]: string; }; log: any; publish(events: EntityEvent[], options?: IPublishingOptions): Promise<any>; shutdown(): Promise<void>; } export declare abstract class EangBase implements IEangBase { protected _env: { [key: string]: string; }; protected _secrets: { [key: string]: string; }; protected _natConf: { servers: string; user: string; pass: string; }; protected _nss: NatsStreamService; protected _natsConnection: { nc: NatsConnection; js: JetStreamClient; jsm: JetStreamManager; } | undefined; log: import("pino").Logger<never, boolean>; constructor(env?: { [key: string]: string; }, secrets?: { [key: string]: string; }, isService?: boolean); protected configure(env?: { [key: string]: string; }, secrets?: { [key: string]: string; }, isService?: boolean): void; protected loadEnv(env: { [key: string]: string; }): { [key: string]: string; }; protected loadSecrets(): { [key: string]: string; }; protected validateEnv(isService?: boolean): void; protected validateSecrets(): void; ensureStream(streamName: string, subjects: string[]): Promise<{ created: boolean; streamInfo: import("@nats-io/jetstream").StreamInfo; }>; publish(events: EntityEvent[], options?: IPublishingOptions): Promise<import("@nats-io/jetstream").PubAck[]>; shutdown(): Promise<void>; get env(): { [key: string]: string; }; get secrets(): { [key: string]: string; }; } export declare class EangPublisher extends EangBase { constructor(env?: { [key: string]: string; }, secrets?: { [key: string]: string; }); } export declare class EangFunction extends EangBase { private _subscription; private _handler; constructor(opts: EangFunctionOptions); get env(): { [key: string]: string; }; get secrets(): { [key: string]: string; }; start(): Promise<void>; shutdown(): Promise<void>; } export declare class EangService extends EangBase { private _consumerName; private _subscriptions; constructor(opts: EangServiceOptions); start(): Promise<ConsumerStream>; }