/** * module: trigger —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。 */ import type { TriggerConfig } from '@contracts'; import type { PendingFire } from './contract.ts'; 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; /** 运营口:确认配置 —— 设计面的 upsert 不碰这两列 */ setConfirm(id: string, confirm: { required: boolean; staffId?: string; }): Promise; remove(id: string): Promise; /** 幂等:同一键至多起一单 */ claim(key: string): Promise; lastFiredAt(id: string): Promise; markFired(id: string, at: Date): Promise; createPending(pending: PendingFire): Promise; getPending(id: string): Promise; pendingByIds(ids: readonly string[]): Promise; /** 认领:consumed_at 空才认得到 —— 两个人同时点确认,只有一个赢,绝不起两条流 */ claimPending(id: string, at: Date): Promise; /** 起单成功后把流号写回;起单失败时用 releasePending 把认领退回去 */ setPendingWorkflow(id: string, workflowId: string): Promise; releasePending(id: string): Promise; }; /** * 确认台 —— app 注入 `message`(L2):命中但要人点头时, * 把带来件内容的系统消息送到指定人的工作台。 */ export type ConfirmDesk = { request(input: { pendingId: string; staffId: string; triggerName: string; subject: string; preview: Readonly>; }): 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; }>>; };