UNPKG

@mulutime/plugin-sdk

Version:

SDK for developing MuluTime booking platform plugins

129 lines 4.84 kB
import { PluginContext } from '@mulutime/plugin-types'; import { LifecycleAction, ValidationResult } from '../types'; export interface LifecycleHandlerOptions { enableLogging?: boolean; timeout?: number; maxRetries?: number; retryDelay?: number; } export interface LifecycleExecution { id: string; action: string; timestamp: Date; duration: number; success: boolean; error?: string; pluginId: string; version?: string; oldVersion?: string; } export type LifecycleActionType = 'onInstall' | 'onUninstall' | 'onUpdate' | 'onEnable' | 'onDisable' | 'validateConfig'; export declare class LifecycleActionHandler { private actions; private executions; private options; constructor(options?: LifecycleHandlerOptions); /** * Register lifecycle actions for a plugin */ register(pluginId: string, actions: LifecycleAction): void; /** * Unregister lifecycle actions for a plugin */ unregister(pluginId: string): void; /** * Execute the install lifecycle action */ executeInstall(pluginId: string, context: PluginContext): Promise<void>; /** * Execute the uninstall lifecycle action */ executeUninstall(pluginId: string, context: PluginContext): Promise<void>; /** * Execute the update lifecycle action */ executeUpdate(pluginId: string, context: PluginContext, oldVersion: string): Promise<void>; /** * Execute the enable lifecycle action */ executeEnable(pluginId: string, context: PluginContext): Promise<void>; /** * Execute the disable lifecycle action */ executeDisable(pluginId: string, context: PluginContext): Promise<void>; /** * Execute configuration validation */ validateConfig(pluginId: string, config: Record<string, any>): Promise<ValidationResult>; /** * Execute a lifecycle action with error handling and retries */ private executeLifecycleAction; /** * Execute a function with timeout */ private executeWithTimeout; /** * Delay utility for retries */ private delay; /** * Log lifecycle execution */ private logExecution; /** * Get execution history for a plugin */ getExecutionHistory(pluginId?: string, limit?: number): LifecycleExecution[]; /** * Get lifecycle statistics */ getStats(): { totalExecutions: number; successfulExecutions: number; failedExecutions: number; averageExecutionTime: number; executionsByAction: Record<LifecycleActionType, number>; executionsByPlugin: Record<string, number>; }; /** * Check if a plugin has lifecycle actions registered */ hasActions(pluginId: string): boolean; /** * Get the lifecycle actions for a plugin */ getActions(pluginId: string): LifecycleAction | undefined; /** * Get all registered plugins */ getRegisteredPlugins(): string[]; /** * Clear all registered actions and execution history */ clear(): void; /** * Validate plugin state before lifecycle operations */ validatePluginState(pluginId: string, actionType: LifecycleActionType, context: PluginContext): Promise<ValidationResult>; } export declare class LifecycleActionBuilder { private actions; static create(): LifecycleActionBuilder; onInstall(handler: NonNullable<LifecycleAction['onInstall']>): LifecycleActionBuilder; onUninstall(handler: NonNullable<LifecycleAction['onUninstall']>): LifecycleActionBuilder; onUpdate(handler: NonNullable<LifecycleAction['onUpdate']>): LifecycleActionBuilder; onEnable(handler: NonNullable<LifecycleAction['onEnable']>): LifecycleActionBuilder; onDisable(handler: NonNullable<LifecycleAction['onDisable']>): LifecycleActionBuilder; validateConfig(handler: NonNullable<LifecycleAction['validateConfig']>): LifecycleActionBuilder; build(): LifecycleAction; } export declare function OnInstall(): any; export declare function OnUninstall(): any; export declare function OnUpdate(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; export declare function OnEnable(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; export declare function OnDisable(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; export declare function ValidateConfig(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; export declare function createLifecycleActions(handlers: Partial<LifecycleAction>): LifecycleAction; export declare function extractLifecycleActions(pluginClass: any): LifecycleAction; //# sourceMappingURL=lifecycle-handler.d.ts.map