/** * Trigger Processor * * Executes database triggers that integrate with Ductape primitives. * Handles condition evaluation, action execution, and retry logic. */ import { TriggerEvent, ITriggerDefinition, ITriggerCondition, ITriggerContext, ITriggerResult, ITriggerConfig, IConditionClause, ITriggerDatabaseAction, ITriggerStorageAction, ITriggerNotificationAction, ITriggerBrokerAction, ITriggerCacheAction, ITriggerFeatureAction, ITriggerActionExecuteAction, ITriggerAgentAction, ITriggerLogAction, ITriggerCustomAction, ITriggerHttpAction } from '../types/trigger.interface'; /** * Trigger Processor class */ export declare class TriggerProcessor { private triggers; private config; private ductapeInstance; constructor(config?: ITriggerConfig, ductapeInstance?: any); /** * Set the Ductape instance for executing actions */ setDuctapeInstance(instance: any): void; /** * Register a trigger for a table */ register(table: string, trigger: ITriggerDefinition): void; /** * Register multiple triggers */ registerAll(triggers: Array<{ table: string; trigger: ITriggerDefinition; }>): void; /** * Unregister a trigger by name */ unregister(table: string, triggerName: string): boolean; /** * Get all triggers for a table and event */ getTriggersForEvent(table: string, event: TriggerEvent): ITriggerDefinition[]; /** * Execute all triggers for an event */ executeTriggers(event: TriggerEvent, context: ITriggerContext): Promise; /** * Execute a single trigger */ executeTrigger(trigger: ITriggerDefinition, context: ITriggerContext): Promise; /** * Execute a single action with retry support */ private executeAction; /** * Calculate retry delay with exponential backoff */ private calculateRetryDelay; /** * Execute action based on type */ private executeActionByType; /** * Evaluate a condition against context */ evaluateCondition(condition: ITriggerCondition, context: ITriggerContext): boolean; /** * Check if a condition is a simple clause */ private isConditionClause; /** * Evaluate a single condition clause */ private evaluateClause; /** * Execute database action */ private executeDatabaseAction; /** * Execute storage action */ private executeStorageAction; /** * Execute notification action */ private executeNotificationAction; /** * Execute broker action */ private executeBrokerAction; /** * Execute cache action */ private executeCacheAction; /** * Execute feature action */ private executeFeatureAction; /** * Execute app action */ private executeAppAction; /** * Execute agent action */ private executeAgentAction; /** * Execute resilience action (quota/fallback/healthcheck) */ private executeResilienceAction; /** * Execute log action */ private executeLogAction; /** * Execute session action */ private executeSessionAction; /** * Execute vector action */ private executeVectorAction; /** * Execute custom function action */ private executeCustomAction; /** * Execute HTTP action */ private executeHttpAction; } /** * Create a trigger processor instance */ export declare function createTriggerProcessor(config?: ITriggerConfig, ductapeInstance?: any): TriggerProcessor; /** * Helper to build trigger definitions */ export declare const Trigger: { /** * Create a database action */ database: { insert: (table: string, data: Record | string) => ITriggerDatabaseAction; update: (table: string, data: Record | string, where: Record | string) => ITriggerDatabaseAction; delete: (table: string, where: Record | string) => ITriggerDatabaseAction; query: (table: string, where: Record | string) => ITriggerDatabaseAction; }; /** * Create a storage action */ storage: { upload: (storage: string, path: string, options?: Partial) => ITriggerStorageAction; delete: (storage: string, path: string) => ITriggerStorageAction; copy: (storage: string, sourcePath: string, destinationPath: string) => ITriggerStorageAction; }; /** * Create a notification action */ notification: { email: (notification: string, recipients: string | string[], options?: Partial) => ITriggerNotificationAction; sms: (notification: string, recipients: string | string[], options?: Partial) => ITriggerNotificationAction; push: (notification: string, recipients: string | string[], options?: Partial) => ITriggerNotificationAction; callback: (notification: string, options?: Partial) => ITriggerNotificationAction; }; /** * Create a broker action */ broker: { publish: (event: string, message: Record | string, options?: Partial) => ITriggerBrokerAction; }; /** * Create a cache action */ cache: { set: (cache: string, key: string, value: any, ttl?: number) => ITriggerCacheAction; invalidate: (cache: string, pattern: string) => ITriggerCacheAction; delete: (cache: string, key: string) => ITriggerCacheAction; }; /** * Create a feature action */ feature: { execute: (feature: string, input?: Record | string) => ITriggerFeatureAction; dispatch: (feature: string, input?: Record | string) => ITriggerFeatureAction; }; /** * Create an app action */ action: { execute: (app: string, action: string, input?: Record | string) => ITriggerActionExecuteAction; }; /** * Create an agent action */ agent: { run: (agent: string, prompt?: string, input?: Record | string) => ITriggerAgentAction; }; /** * Create a log action */ log: { debug: (message: string, data?: Record | string) => ITriggerLogAction; info: (message: string, data?: Record | string) => ITriggerLogAction; warn: (message: string, data?: Record | string) => ITriggerLogAction; error: (message: string, data?: Record | string) => ITriggerLogAction; }; /** * Create an HTTP action */ http: { get: (url: string, options?: Partial) => ITriggerHttpAction; post: (url: string, body?: Record | string, options?: Partial) => ITriggerHttpAction; put: (url: string, body?: Record | string, options?: Partial) => ITriggerHttpAction; patch: (url: string, body?: Record | string, options?: Partial) => ITriggerHttpAction; delete: (url: string, options?: Partial) => ITriggerHttpAction; }; /** * Create a custom function action */ custom: (handler: (context: ITriggerContext) => Promise) => ITriggerCustomAction; /** * Condition builders */ when: { field: (field: string) => { equals: (value: any) => IConditionClause; notEquals: (value: any) => IConditionClause; greaterThan: (value: any) => IConditionClause; lessThan: (value: any) => IConditionClause; in: (values: any[]) => IConditionClause; contains: (value: string) => IConditionClause; isNull: () => IConditionClause; isNotNull: () => IConditionClause; changed: () => IConditionClause; changedTo: (value: any) => IConditionClause; changedFrom: (value: any) => IConditionClause; }; and: (...conditions: (IConditionClause | ITriggerCondition)[]) => ITriggerCondition; or: (...conditions: (IConditionClause | ITriggerCondition)[]) => ITriggerCondition; not: (condition: IConditionClause | ITriggerCondition) => ITriggerCondition; }; };