28 lines
834 B
TypeScript
28 lines
834 B
TypeScript
import type { EventHandler, Unsubscribe } from "./events";
|
|
|
|
export type Awaitable<T> = T | Promise<T>;
|
|
export type ExtensionConfig = Record<string, unknown>;
|
|
|
|
export interface ExtensionSetupContext {
|
|
add<T>(name: string, value: T): void;
|
|
on<T>(event: string, handler: EventHandler<T>): Unsubscribe;
|
|
}
|
|
|
|
export interface ExtensionRuntimeContext {
|
|
get<T>(name: string): T;
|
|
all<T>(name: string): T[];
|
|
on<T>(event: string, handler: EventHandler<T>): Unsubscribe;
|
|
emit<T>(event: string, payload: T): Promise<unknown[]>;
|
|
}
|
|
|
|
export interface Extension {
|
|
setup(context: ExtensionSetupContext): Awaitable<void>;
|
|
start?(context: ExtensionRuntimeContext): Awaitable<void>;
|
|
stop?(context: ExtensionRuntimeContext): Awaitable<void>;
|
|
}
|
|
|
|
export interface ExtensionFactory {
|
|
id: string;
|
|
(options?: ExtensionConfig): Extension;
|
|
}
|