/** * module: trigger —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。 */ import type { TriggerConfig } from '@contracts'; export type Clock = { now(): Date; }; export type IdGenerator = { next(): string; }; export type TriggerStore = { list(): Promise; get(id: string): Promise; upsert(config: TriggerConfig): Promise; setEnabled(id: string, enabled: boolean): Promise; remove(id: string): Promise; /** 幂等:同一键至多起一单 */ claim(key: string): Promise; lastFiredAt(id: string): Promise; markFired(id: string, at: Date): Promise; }; /** 起单 —— app 注入 `process`(L7 同层?否:trigger 在 process 之上同层,经 app 装配) */ export type ProcessGateway = { start(input: { packageId: string; subject: string; source: { kind: 'periodic' | 'event' | 'registration'; ref: string; by?: string; }; data: Record; }): Promise<{ id: string; }>; /** 调用接口的必填字段 —— 装配缺项即起单失败 */ requiredInputs(packageId: string): Promise; }; export type Sfeel = { condition(expression: string, scope: Readonly>): boolean; expression(expression: string, scope: Readonly>): unknown; }; /** 死信 —— app 注入 `message`(L2):起单失败入死信 */ export type DeadLetterSink = { report(input: { triggerId: string; reason: string; detail: Record; }): Promise; }; /** 数据日历型要读台账 —— app 注入 `ledger`(L1) */ export type LedgerScanner = { scan(input: { domain: string; object: string; dateField: string; filter?: string; }): Promise; date: string; row: Record; }>>; };