import type { Bud, Registry } from '@roots/bud-framework'; /** * Hooks service */ export interface Hooks { /** * Store callback to an action handler */ action: (id: T, ...input: Array>) => Bud; /** * Register an async function to filter a value. * * @example * ```js * app.hooks.on( * 'namespace.name.value', * value => 'replaced by this string', * ) * ``` */ async: (id: T, value: Registry.AsyncCallback[T]) => Bud; /** * Async hooks value store */ asyncStore: any; /** * Events value store */ events: any; /** * Filter a value * * @example * ```js * bud.hooks.filter( * 'namespace.name.event', * ['array', 'of', 'items'], * ) * ``` */ filter: (id: K, callback?: Registry.SyncRegistry[K]) => Registry.SyncRegistry[K]; /** * Async version of hook.filter * * @remarks * Hooks are processed as a waterfall. * * @example * ```js * bud.hooks.filter( * 'namespace.name.event', * ['array', 'of', 'items'], * ) * ``` */ filterAsync: (id: T, fallback?: Registry.AsyncCallback[T]) => Promise; /** * Execute an action */ fire: (id: T, ...obj: Registry.Events[T]) => Promise; /** * Register a recordset of functions or values to modify or replace existing values * * @example * ```js * app.hooks.fromAsyncMap({ * 'namespace.name.value': 'replaced by this string', * 'namespace.name.value2': async value => value.push('modified by this string'), * }) * ``` */ fromAsyncMap: (map: Registry.AsyncCallback) => Bud; /** * Register a recordset of functions or values to modify or replace existing values * * @example * ```js * app.hooks.fromMap({ * 'namespace.name.value': 'replaced by this string', * 'namespace.name.value2': value => value.push('modified by this string'), * }) * ``` */ fromMap: (map: Partial) => Bud; hasAsyncHook: (hook: keyof Registry.AsyncStore) => boolean; hasEvent: (hook: keyof Registry.EventsStore) => boolean; hasSyncHook: (hook: keyof Registry.SyncStore) => boolean; /** * Register a function or value to modify or replace a filtered value * * @example * ```js * app.hooks.on( * 'namespace.name.value', * value => 'replaced by this string', * ) * ``` */ on: (id: T, input: Registry.SyncCallback[T]) => Bud; /** * Sync hooks value store */ syncStore: any; }