/** * Event Guard / Prerequisite Registry with combinators (AND, OR, sequence). * * Usage: * const guard = new EventGuard() * guard.when(all('EDITOR_MOUNTED', 'WORKSPACE_INITIALIZED'), () => { ... }) * guard.when(any('PROVIDER_CONNECTED:remixd', 'PROVIDER_CONNECTED:electron'), () => { ... }) * guard.when(sequence('PLUGIN_ACTIVATED:solidity', 'CACHE_READY'), () => { ... }) * guard.when(all('A', any('B', 'C')), () => { ... }) // nested * await guard.waitFor(all('EDITOR_MOUNTED', 'WORKSPACE_INITIALIZED')) * guard.has('EDITOR_MOUNTED') // synchronous check */ import type { Condition, ConditionInput, AllCondition, AnyCondition, SequenceCondition, EventId, SerializedCondition } from './types'; /** All conditions must be satisfied (any order) */ export declare function all(...inputs: ConditionInput[]): AllCondition; /** At least one condition must be satisfied */ export declare function any(...inputs: ConditionInput[]): AnyCondition; /** All conditions must be satisfied in the given order */ export declare function sequence(...inputs: ConditionInput[]): SequenceCondition; export declare function deserializeCondition(input: SerializedCondition): Condition; export declare class EventGuard { private firedEvents; private orderedEvents; private registrations; private nextId; private evaluating; private debug; private label; constructor(options?: { debug?: boolean; label?: string; }); private log; /** Record that an event has occurred, then evaluate all pending guards */ fire(eventId: EventId): void; /** Check if a specific event has ever been fired */ has(eventId: EventId): boolean; /** * Remove a previously fired event from the context. * Useful for mutually exclusive state flags (e.g. logged_in vs not_logged_in). */ unfire(eventId: EventId): void; /** Get a snapshot of all fired events */ getFiredEvents(): string[]; /** * Register a callback to execute when a condition is satisfied. * If the condition is already satisfied, the callback fires immediately (synchronously). * By default, callbacks are one-shot (fire once, then auto-removed). */ when(input: ConditionInput, callback: () => void, options?: { once?: boolean; }): () => void; /** * Returns a Promise that resolves when the condition is satisfied. * Optionally accepts a timeout in ms — rejects with Error on timeout. */ waitFor(input: ConditionInput, timeoutMs?: number): Promise; /** Re-evaluate all pending registrations after a new event fires */ private evaluate; /** Reset all state (primarily for testing) */ reset(): void; }