import { DynamicModule, OnModuleInit } from '@nestjs/common'; import { TriggerClientOptions, TriggerClient, ActionContext, TLogContent, ILogAttributes, ActionMetadata, Action } from './client/index.js'; export { ActionHandler, ENUM_ENV, ENUM_ERROR, ENUM_PHASE, ENUM_STATUS, ILogContentParsed, Logger, convertActionContextToReportData } from './client/index.js'; import { DiscoveryService, MetadataScanner, Reflector } from '@nestjs/core'; /** * AutomationModule * * 自动化任务模块,提供声明式任务注册与执行能力 */ declare class AutomationModule { /** * 创建并配置 AutomationModule * * @param options - TriggerClient 配置选项 * @returns 配置好的 DynamicModule */ static forRoot(options?: TriggerClientOptions): DynamicModule; } /** * 任务执行结果接口 */ interface ActionExecutionResult { trigger: string; success: boolean; result?: any; error?: string; startTime: Date; endTime: Date; duration: number; } /** * AutomationService * * 提供自动化任务的执行、查询和管理功能 */ declare class AutomationService { private readonly triggerClient; constructor(triggerClient: TriggerClient); /** * 执行指定的自动化任务 * * @param trigger - 任务触发器标识 * @param instanceID - 任务实例ID * @param context - 任务执行上下文 * @returns 任务执行报告数据 */ executeAction(trigger: string, instanceID: string, context: ActionContext): ActionContext; /** * 上报任务执行结果 */ report(msg: TLogContent, attributes: ILogAttributes): void; /** * 获取指定任务的元数据信息 * * @param trigger - 任务触发器标识 * @returns 任务元数据 * @throws NotFoundException - 当任务不存在时抛出异常 */ getActionInfo(trigger: string): ActionMetadata; /** * 检查指定任务是否存在 * * @param trigger - 任务触发器标识 * @returns 存在返回 true,否则返回 false */ hasAction(trigger: string): boolean; /** * 获取指定任务的处理器 * * @param trigger - 任务触发器标识 * @returns 任务处理器 */ getAction(trigger: string): Action | undefined; /** * 获取所有已注册的任务 * * @returns 所有任务映射 */ getAllActions(): Map; } /** * AutomationDiscoveryService * * 自动化任务发现服务,负责扫描并注册所有标记了 @Automation 和 @BindTrigger 的任务 */ declare class AutomationDiscoveryService implements OnModuleInit { private readonly discoveryService; private readonly metadataScanner; private readonly reflector; private readonly triggerClient; private readonly logger; constructor(discoveryService: DiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector, triggerClient: TriggerClient); /** * 模块初始化时触发任务发现 */ onModuleInit(): Promise; /** * 发现并注册所有自动化任务 * * 扫描流程: * 1. 获取所有 providers 和 controllers * 2. 筛选出标记了 @Automation 的类 * 3. 扫描类中标记了 @BindTrigger 的方法 * 4. 将任务注册到 TriggerClient */ private discover; /** * 注册单个自动化任务 * * @param instance - 任务实例 * @param methodName - 方法名称 * @param method - 方法引用 * @param metadata - 任务元数据 * @param _wrapper - 实例包装器 */ private registerAction; } /** * 自动化控制器元数据键 */ declare const AUTOMATION_METADATA_KEY = "automation:controller"; /** * @Automation 装饰器 * * 类装饰器,用于标记一个类为自动化任务控制器 * 自动包含 @Injectable(),无需额外添加 * * @example * ```typescript * @Automation() * export class MyAutomation { * // 任务方法 * } * ``` */ declare const Automation: () => ClassDecorator; /** * 绑定动作元数据键 */ declare const BIND_ACTION_METADATA_KEY = "automation:action"; /** * 绑定动作元数据接口 */ interface BindActionMetadata { trigger: string; actionName?: string; actionDesc?: string; } /** * 获取已注册的 triggers */ declare const getRegisteredTriggers: () => Map; /** * 清空 trigger 注册表 */ declare const clearTriggerRegistry: () => void; /** * @BindTrigger 装饰器 * * 方法装饰器,将方法绑定到指定的 trigger * * 重要特性: * - 1:1 绑定约束:每个 trigger 只能绑定一个方法 * - 重复绑定会抛出错误 * * @param trigger - Trigger 唯一标识符 * @param options - 可选配置 * @param options.actionName - 任务名称 * @param options.actionDesc - 任务描述 * * @example * ```typescript * @Automation() * @Injectable() * export class EmailAutomation { * @BindTrigger('send-email', { * actionName: 'SendEmail', * actionDesc: '发送邮件通知' * }) * async sendEmail(to: string, subject: string) { * // 邮件发送逻辑 * } * } * ``` */ declare const BindTrigger: (trigger: string, options?: { actionName?: string; actionDesc?: string; }) => MethodDecorator; /** * TriggerClient 执行请求 (从 Trigger Server 接收) */ interface TriggerExecutionDto { trigger?: string; triggerID?: string; triggerType?: string; instanceID?: string; startAt?: number; parameter?: string; } /** * TriggerClient 执行响应 */ interface TriggerExecutionResponseDto { code?: number; message?: string; } /** * AutomationController * * 接收来自 Trigger Server 的自动化任务执行请求 */ declare class AutomationController { private readonly automationService; constructor(automationService: AutomationService); /** * Trigger Server 执行接口 * * POST /__innerapi__/automation/invoke * * 执行流程: * 1. 验证请求参数完整性 * 2. 构建任务执行上下文 * 3. 调用 AutomationService 执行任务 * 4. 返回执行结果 * * @param req - HTTP 请求对象 * @param dto - 任务执行数据传输对象 * @returns 任务执行响应 */ execute(dto: TriggerExecutionDto): Promise; } export { AUTOMATION_METADATA_KEY, Action, ActionContext, type ActionExecutionResult, ActionMetadata, Automation, AutomationController, AutomationDiscoveryService, AutomationModule, AutomationService, BIND_ACTION_METADATA_KEY, type BindActionMetadata, BindTrigger, ILogAttributes, TLogContent, TriggerClient, TriggerClientOptions, type TriggerExecutionDto, type TriggerExecutionResponseDto, clearTriggerRegistry, getRegisteredTriggers };