stream-chat
Version:
JS SDK for the Stream Chat API
57 lines (56 loc) • 2.42 kB
TypeScript
export type InsertPosition = {
after: string;
before?: never;
} | {
after?: never;
before: string;
};
export type MiddlewareStatus = 'complete' | 'discard';
export type MiddlewareExecutionResult<TValue> = {
state: TValue;
status?: MiddlewareStatus;
};
export type ExecuteParams<TValue> = {
eventName: string;
initialValue: TValue;
mode?: 'concurrent' | 'cancelable';
};
export type MiddlewareHandlerParams<TValue> = {
state: TValue;
next: (state: TValue) => Promise<MiddlewareExecutionResult<TValue>>;
complete: (state: TValue) => Promise<MiddlewareExecutionResult<TValue>>;
discard: () => Promise<MiddlewareExecutionResult<TValue>>;
forward: () => Promise<MiddlewareExecutionResult<TValue>>;
};
export type MiddlewareHandler<TValue> = (params: MiddlewareHandlerParams<TValue>) => Promise<MiddlewareExecutionResult<TValue>>;
export type MiddlewareHandlers<TValue, THandlers extends string> = {
[K in THandlers]: MiddlewareHandler<TValue>;
};
export type Middleware<TValue, THandlers extends string> = {
id: string;
handlers: MiddlewareHandlers<TValue, THandlers>;
};
export declare class MiddlewareExecutor<TValue, THandlers extends string> {
readonly id: string;
private middleware;
constructor();
/**
* The middleware currently installed, in execution order.
*
* Read-only: use `use` / `insert` / `replace` / `setOrder` / `remove` to change the chain. It
* exists so components can ask what the chain is capable of - a middleware may declare
* behaviour its host has to account for, and the host has no other way to find out.
*/
get installedMiddleware(): ReadonlyArray<Middleware<TValue, THandlers>>;
use(middleware: Middleware<TValue, THandlers> | Middleware<TValue, THandlers>[]): this;
replace(middleware: Middleware<TValue, THandlers>[]): this;
insert({ middleware, position, unique, }: {
middleware: Middleware<TValue, THandlers>[];
position: InsertPosition;
unique?: boolean;
}): this;
setOrder(order: string[]): void;
remove(middlewareIds: string | string[]): void;
protected executeMiddlewareChain({ eventName, initialValue, mode, }: ExecuteParams<TValue>): Promise<MiddlewareExecutionResult<TValue>>;
execute({ eventName, initialValue: initialState, mode, }: ExecuteParams<TValue>): Promise<MiddlewareExecutionResult<TValue>>;
}