/** * Plugin Registry * @module @plyaz/storage/plugins * * Manages storage plugins and executes lifecycle hooks in priority order. */ import type { StoragePlugin, StoragePluginContext, StoragePluginFile, StoragePluginUploadResult, StoragePluginDeleteResult, StoragePluginAccessEvent, StoragePluginExecutionResult, FileMetadata, PluginRegistryConfig, StoragePluginExecutionOptions } from '@plyaz/types/storage'; import type { BaseStorageAdapter } from '../../adapters/base/BaseStorageAdapter'; /** * Plugin Registry * * Central registry for managing and executing storage plugins. * Handles plugin registration, initialization, and lifecycle hook execution. * * @example * ```typescript * const registry = new PluginRegistry({ logger }); * * // Register plugins * await registry.register(virusScanPlugin); * await registry.register(metadataPlugin); * * // Execute beforeUpload hooks * const result = await registry.executeBeforeUpload(file, context); * if (!result.allowed) { * throw new Error(result.reason); * } * * // Execute afterUpload hooks (async) * await registry.executeAfterUpload(uploadResult, context); * ``` */ export declare class PluginRegistry { private readonly plugins; private readonly logger?; private readonly continueOnError; private readonly maxExecutionTime; private currentAdapter?; constructor(config?: PluginRegistryConfig); /** * Register a plugin * Initializes the plugin if it has an initialize method */ register(plugin: StoragePlugin): Promise; /** * Unregister a plugin * Destroys the plugin if it has a destroy method */ unregister(name: string): Promise; /** * Get a plugin by name */ get(name: string): StoragePlugin | undefined; /** * Get all registered plugins */ getAll(): StoragePlugin[]; /** * Set the storage adapter for all registered plugins * Called by StorageService when adapter is initialized or changed * * @param adapter - The storage adapter instance */ setStorageAdapter(adapter: BaseStorageAdapter): void; /** * Get enabled plugins sorted by priority (lower priority first) */ private getEnabledPluginsSorted; /** * Filter plugins based on skip/only rules */ private filterPlugins; /** * Execute beforeUpload hooks * BLOCKING - All plugins must allow upload or it will be rejected */ executeBeforeUpload(file: StoragePluginFile, context: StoragePluginContext, options?: StoragePluginExecutionOptions): Promise; /** * Execute afterUpload hooks * ASYNC - Runs in background, doesn't block */ executeAfterUpload(result: StoragePluginUploadResult, context: StoragePluginContext, options?: StoragePluginExecutionOptions): Promise; /** * Execute beforeDelete hooks * BLOCKING - All plugins must allow deletion or it will be rejected */ executeBeforeDelete(fileId: string, metadata: FileMetadata | undefined, context: StoragePluginContext, options?: StoragePluginExecutionOptions): Promise; /** * Execute afterDelete hooks * ASYNC - Runs in background, doesn't block */ executeAfterDelete(result: StoragePluginDeleteResult, context: StoragePluginContext, options?: StoragePluginExecutionOptions): Promise; /** * Execute onAccess hooks * ASYNC - Runs in background, doesn't block */ executeOnAccess(event: StoragePluginAccessEvent, context: StoragePluginContext, options?: StoragePluginExecutionOptions): Promise; /** * Check health of all plugins */ healthCheckAll(): Promise>; /** * Destroy all plugins */ destroyAll(): Promise; /** * Helper: Execute promise with timeout */ private withTimeout; }