/** * Operation types for OTEL tracking */ export type HOOKS_BRIDGE_OPERATIONS = string; export namespace HOOKS_BRIDGE_OPERATIONS { let REGISTER_HOOK: string; let EVALUATE_CONDITION: string; let EXECUTE_EFFECT: string; let EXECUTE_HOOKS: string; let GET_RECEIPT_CHAIN: string; let COMPILE_HOOK_CHAIN: string; let VALIDATE_HOOK: string; } /** * HooksBridge: BiDirectional bridge between Erlang and JS hooks engine * * Manages hook lifecycle, condition evaluation, and effect execution * across the BEAM/JS boundary with deterministic receipt generation. */ export class HooksBridge { /** * Create a new HooksBridge instance * * @param {object} store - Oxigraph RDF store instance * @param {object} [options={}] - Configuration options * @param {string} [options.nodeId] - Node identifier for receipts * @param {number} [options.maxHooks=1000] - Maximum hooks to register * @param {boolean} [options.enableReceiptChaining=true] - Chain receipts via BLAKE3 * @param {boolean} [options.enableJIT=true] - Enable JIT compilation of hook chains */ constructor(store: object, options?: { nodeId?: string; maxHooks?: number; enableReceiptChaining?: boolean; enableJIT?: boolean; }); store: any; engine: KnowledgeHookEngine; hooks: Map; receipts: any[]; conditionEvaluator: any; options: { nodeId: string; maxHooks: number; enableReceiptChaining: boolean; enableJIT: boolean; }; /** * Register a hook from Erlang * * Message format: {hook_name, hook_type, condition, effects, priority?, meta?} * * @param {object} hookSpec - Hook specification from Erlang * @returns {Promise<{hookId: string, registered: boolean, receipt: object}>} * @throws {Error} If hook validation fails */ registerHook(hookSpec: object): Promise<{ hookId: string; registered: boolean; receipt: object; }>; /** * Evaluate a condition from Erlang * * Supports all 9 condition kinds: * - SPARQL ASK (boolean queries) * - N3 (rule-based logic) * - Datalog (logic programming) * - SHACL (shape validation) * - S-Expression (Scheme-like syntax) * - DQL (SPARQL dialect) * - Regex (pattern matching) * - Path Queries (graph traversal) * - Temporal (time-based evaluation) * * @param {object} conditionSpec - Condition specification with type and spec * @returns {Promise<{result: boolean, metadata: object, receipt: object}>} * @throws {Error} If condition evaluation fails */ evaluateCondition(conditionSpec: object): Promise<{ result: boolean; metadata: object; receipt: object; }>; /** * Execute an effect from Erlang * * Handles: * - JS function effects (execute arbitrary JS) * - SPARQL CONSTRUCT effects (generate new triples) * - Side-effect operations (mutations, logging, etc.) * - Receipt chaining (link execution history) * * @param {object} effectSpec - Effect specification * @returns {Promise<{executed: boolean, result: unknown, receipt: object}>} * @throws {Error} If effect execution fails */ executeEffect(effectSpec: object): Promise<{ executed: boolean; result: unknown; receipt: object; }>; /** * Execute full hook workflow * * 1. Create deterministic context * 2. Evaluate all hook conditions * 3. Execute matching effects * 4. Generate unified receipt with chain * * @param {object} context - Execution context * @returns {Promise<{success: boolean, conditions: Array, effects: Array, receipt: object, receipts: Array}>} */ executeHooks(context: object): Promise<{ success: boolean; conditions: any[]; effects: any[]; receipt: object; receipts: any[]; }>; /** * Get full receipt chain * * Returns all receipts with BLAKE3 hash chain for verification * * @returns {Array} Receipts with chain metadata */ getReceiptChain(): Array; /** * Get hook by ID * * @param {string} hookId - Hook identifier * @returns {object|null} Hook specification or null */ getHook(hookId: string): object | null; /** * List all registered hooks * * @returns {Array} All registered hooks */ listHooks(): Array; /** * Clear all hooks and receipts * * @returns {void} */ clear(): void; /** * Validate condition specification * @private */ private _validateCondition; /** * Evaluate SPARQL ASK query * @private */ private _evaluateSPARQLAsk; /** * Evaluate N3 rule * @private */ private _evaluateN3Rule; /** * Evaluate Datalog query * @private */ private _evaluateDatalog; /** * Evaluate SHACL shape validation * @private */ private _evaluateSHACL; /** * Evaluate S-Expression * @private */ private _evaluateSExpression; /** * Evaluate DQL (SPARQL dialect) * @private */ private _evaluateDQL; /** * Evaluate regex pattern * @private */ private _evaluateRegex; /** * Evaluate graph path query * @private */ private _evaluatePathQuery; /** * Evaluate temporal condition * @private */ private _evaluateTemporal; /** * Execute JavaScript function effect * @private */ private _executeJSFunction; /** * Execute SPARQL CONSTRUCT effect * @private */ private _executeSPARQLConstruct; /** * Execute side-effect * @private */ private _executeSideEffect; /** * Execute receipt chain operation * @private */ private _executeReceiptChain; /** * Create deterministic receipt * @private */ private _createReceipt; } import { KnowledgeHookEngine } from '@unrdf/hooks';