/** * vapor-chamber - Core plugins (sync) * * logger, validator, history (not a plugin: it installs its own recorder), * authGuard. Pacing is the sender's (`pace`, src/pace.ts). */ import type { Command, PluginParts, CommandBus, AsyncCommandBus, ScopeOptions } from './command-bus'; /** * Logger plugin - logs all commands and results * * Successful dispatches log at 'info', failed dispatches at 'error'. * The default `level: 'info'` shows both. Raise it to * 'warn' or 'error' to hide successful dispatches and only see failures. * * @example * bus.use(logger()); // logs every dispatch and query * * @example * // Failures only, with fixed-width [ OK ] / [ FAIL ] badges * // (colored via %c in browsers, plain brackets in Node) * bus.use(logger({ level: 'error', badges: true })); */ export declare function logger(options?: ScopeOptions & { collapsed?: boolean; /** Minimum level to log. Ok results log at 'info', failures at 'error'. Default: 'info'. */ level?: 'debug' | 'info' | 'warn' | 'error'; /** Prefix the group label with a fixed-width [ OK ] / [ FAIL ] badge. Default: false. */ badges?: boolean; }): PluginParts; /** * Validator - each action's rule, run before every plugin and the work: a * message refuses the command, `null` lets it through. A `validate` part * (PluginParts), so install it with `bus.use()`. */ export declare function validator(rules: { [action: string]: (cmd: Command) => string | null; }): PluginParts; /** What `history().getState()` returns: the ledger's stacks, `readonly` (each change writes new ones). */ export interface HistoryState { past: readonly Command[]; future: readonly Command[]; canUndo: boolean; canRedo: boolean; } /** * history - undo/redo of the commands dispatched on `bus`, recorded from the * call on. Not a plugin: the recorder is the ledger's (ledger.ts), so it * records what the caller got wherever plugins sit. undo() dispatches * `$undo`, which runs the inverse registered with `{ undo: fn }` via * bus.register(); with none it only moves the step. `undoAction` / * `redoAction` register actions that press undo and redo. */ export declare function history(options: ScopeOptions & { /** Either bus: recorded on, an undo handler read and a redo dispatched through it. */ bus: CommandBus | AsyncCommandBus; maxSize?: number; undoAction?: string; redoAction?: string; }): { getState: () => HistoryState; undo: () => Command | undefined; redo: () => Command | undefined; clear: () => void; dispose: () => void; }; /** * Auth guard - refuses a protected command when not authenticated, before * every validator, plugin and the work. An `authorize` part (PluginParts), so * install it with `bus.use()`. */ export declare function authGuard(options: { isAuthenticated: () => boolean; /** * Protected actions, each a pattern as everywhere in the library: `'admin'` * that action only, `'admin*'` every action that starts with admin, `'*'` * every action. tests/auth-guard-pattern.test.ts. */ protected: string[]; onUnauthenticated?: (cmd: Command) => void; }): PluginParts; //# sourceMappingURL=plugins-core.d.ts.map