/** * The primitives every mailbox transition shares (WFT-84): * the rejection vocabulary, the transition result shape, non-terminal * narrowing, identity-field carry-over, and retry backoff. * * Extracted so `mailbox-transitions.ts` and * `mailbox-transitions-recovery.ts` can both use them without * importing each other — a runtime cycle this repository forbids outright. * * @module core/mailbox-transition-helpers */ import { computeRetryBackoffMs } from './application-primitive-timing.ts'; import type { ApplicationCommandAccepted, ApplicationCommandAvailable, ApplicationCommandCancelling, ApplicationCommandClaimed, ApplicationCommandRecord, ApplicationCommandTerminalRecord } from './mailbox-types.ts'; export { computeRetryBackoffMs }; /** * Why a proposed transition is illegal. Stable and low-cardinality, so callers * can map each reason onto a discriminated result without string matching. */ export type MailboxTransitionRejection = 'stale-attempt' | 'not-leased' | 'not-waiting' | 'not-due' | 'deadline-exceeded' | 'already-terminal'; /** * The outcome of a proposed transition: the record to persist, or why the edge * is illegal. */ export type MailboxTransition = { readonly ok: true; readonly next: TNext; } | { readonly ok: false; readonly reason: MailboxTransitionRejection; }; export declare function rejectedTransition(reason: MailboxTransitionRejection): MailboxTransition; export declare function succeededTransition(next: TNext): MailboxTransition; /** * Narrow a record to the four non-terminal states. * * `isApplicationCommandTerminalState` narrows the `state` string but not the * record it came from, so every transition below needs this to stay cast-free. */ export declare function isTerminalCommandRecord(record: ApplicationCommandRecord): record is ApplicationCommandTerminalRecord; export declare function nonTerminalCommandRecord(record: ApplicationCommandRecord): ApplicationCommandAccepted | ApplicationCommandAvailable | ApplicationCommandClaimed | ApplicationCommandCancelling | null; /** Strip the state-specific fields so a transition rebuilds a record from identity alone. */ export declare function applicationCommandIdentityFields(record: ApplicationCommandRecord): { readonly recordVersion: 1; readonly namespace: string; readonly resourceId: string; readonly commandId: string; readonly sequence: number; readonly idempotencyKey: string | undefined; readonly caller: string; readonly target: string; readonly kind: string; readonly payload: import("./mailbox-types.ts").ApplicationCommandPayload; readonly payloadDigest: string; readonly payloadMediaType: string | undefined; readonly payloadSchema: string | undefined; readonly causation: Readonly<{ correlationId?: string | undefined; causationId?: string | undefined; traceparent?: string | undefined; }> | undefined; readonly acceptedAt: number; readonly absoluteDeadlineAt: number; readonly maxAttempts: number; readonly visibilityTimeoutMs: number; readonly generation: number; readonly attempt: number; readonly retryCount: number; readonly firstClaimedAt: number | undefined; readonly availableAt: number; };