/** * module: trigger —— 对外类型(编码规范 §10.1;语义出处 OS 3.1)。 * * 触发器三类,**独立配置存放**,判定与调用接口调起。 * 触发器与流程包平级:增删启停不改流程包的任何版本。 */ import type { TriggerConfig, TriggerKind } from '@contracts'; import type { AssemblyResult, EventScope } from './internal/domain/matching.ts'; export type { AssemblyResult, EventScope, TriggerConfig, TriggerKind }; export declare class TriggerInputMissingError extends Error { readonly triggerId: string; readonly fields: readonly string[]; constructor(triggerId: string, fields: readonly string[]); } export type FireOutcome = { readonly triggerId: string; readonly workflowId?: string; /** 命中但勾了「需人工确认」:没起单,等指定人点头 —— 这一票的号 */ readonly pendingId?: string; readonly skipped?: 'duplicate' | 'disabled' | 'input-missing' | 'no-confirmer'; readonly missing?: readonly string[]; }; /** 待确认单:装配好的一次起单,等指定人点「确认起单」 */ export type PendingFire = { readonly id: string; readonly triggerId: string; readonly packageId: string; /** 确认人快照 —— 确认路由按它认门 */ readonly staffId: string; readonly subject: string; readonly data: Record; readonly source: { readonly kind: 'periodic' | 'event' | 'registration'; readonly ref: string; readonly by?: string; }; readonly preview: Readonly>; readonly createdAt: string; readonly consumedAt?: string; readonly workflowId?: string; }; export type TriggerService = { list(): Promise; upsert(config: TriggerConfig): Promise; setEnabled(id: string, enabled: boolean): Promise; remove(id: string): Promise; /** 事件到达:命中判定 —— 供 `event` 的 `TriggerMatcher` 端口使用 */ match(scope: EventScope): Promise; /** 命中即起单;同一事件对同一触发器**至多起一单**(事件 ID 为幂等键) */ fireByEvent(triggerId: string, eventId: string, scope: EventScope): Promise; /** 登记触发:人工起单的统一形态 —— 登记人即来源 */ fireByRegistration(triggerId: string, by: string, data: Record): Promise; /** 周期触发的到点扫描(由 pg-boss 定时调起) */ sweepPeriodic(now: Date): Promise; /** 运营口:要不要人工确认、谁来确认 —— 与设计面的 upsert 分口 */ setConfirm(id: string, confirm: { required: boolean; staffId?: string; }): Promise; /** 指定人点头 —— 幂等:已被确认过就回那条流的号,绝不起第二条 */ confirmPending(pendingId: string, by: string): Promise<{ workflowId: string; alreadyStarted: boolean; }>; /** 待确认单批读 —— 工作台消息列表就地贴确认状态用 */ pendingByIds(ids: readonly string[]): Promise; };