import { Observable } from "rxjs"; import { NostrEvent } from "nostr-tools"; import { EventFactory } from "applesauce-factory"; import { IEventStoreActions, IEventStoreRead } from "applesauce-core"; /** A callback used to tell the upstream app to publish an event */ export type PublishMethod = (event: NostrEvent) => void | Promise; /** The context that is passed to actions for them to use to preform actions */ export type ActionContext = { /** The event store to load events from */ events: IEventStoreRead; /** The pubkey of the signer in the event factory */ self: string; /** The event factory used to build and modify events */ factory: EventFactory; }; /** An action that can be run in a context to preform an action */ export type Action = (ctx: ActionContext) => Observable | AsyncGenerator | Generator; export type ActionConstructor> = (...args: Args) => Action; /** The main class that runs actions */ export declare class ActionHub { events: IEventStoreRead & IEventStoreActions; factory: EventFactory; publish?: PublishMethod | undefined; /** Whether to save all events created by actions to the event store */ saveToStore: boolean; constructor(events: IEventStoreRead & IEventStoreActions, factory: EventFactory, publish?: PublishMethod | undefined); protected context: ActionContext | undefined; protected getContext(): Promise; /** Runs an action in a ActionContext and converts the result to an Observable */ static runAction(ctx: ActionContext, action: Action): Observable; /** Run an action and publish events using the publish method */ run>(Action: ActionConstructor, ...args: Args): Promise; /** Run an action without publishing the events */ exec>(Action: ActionConstructor, ...args: Args): Observable; }