UNPKG

alinea

Version:
25 lines (24 loc) 1.09 kB
import type { Entry } from 'alinea/core'; import type { CMS } from 'alinea/core/CMS'; import type { RemoteConnection, RequestContext } from 'alinea/core/Connection'; import type { LocalDB } from 'alinea/core/db/LocalDB'; export interface Handler { (request: Request, context: RequestContext): Promise<Response>; } export type HookResponse<T = void> = void | T | Promise<T> | Promise<void>; export interface HandlerHooks { beforeCreate?(entry: Entry): HookResponse<Entry>; afterCreate?(entry: Entry): HookResponse; beforeUpdate?(entry: Entry): HookResponse<Entry>; afterUpdate?(entry: Entry): HookResponse; beforeArchive?(entryId: string): HookResponse; afterArchive?(entryId: string): HookResponse; beforeRemove?(entryId: string): HookResponse; afterRemove?(entryId: string): HookResponse; } export interface HandlerOptions extends HandlerHooks { cms: CMS; db: LocalDB | Promise<LocalDB>; remote?: (context: RequestContext) => RemoteConnection; } export declare function createHandler({ cms, remote, db, ...hooks }: HandlerOptions): Handler;