Skip to content

ProcessData

ProcessData is the base interface every saga state extends. It declares a single required field — correlationId — that the framework uses to key the row in the ISagaStore. Your own saga-state types add whatever extra fields the business logic needs.

The companion types ConcurrencyToken and FoundSaga<TData> describe the values an ISagaStore returns: an opaque optimistic-concurrency token, and a { data, concurrencyToken } pair handed back from findByCorrelationId.

import type {
ConcurrencyToken,
FoundSaga,
ProcessData,
} from '@serviceconnect/core';
export interface ProcessData {
correlationId: string;
}
  • correlationId (required) — the saga’s identity. Returned by each ProcessHandler.correlate(message) call and used by the ISagaStore as the row key. The framework sets it for you when a startsWith handler creates a new saga; you do not need to mutate it inside handle.

Extend the interface with whatever state your saga needs:

interface OrderState extends ProcessData {
status: 'pending' | 'paid' | 'shipped';
itemCount: number;
totalCents: number;
}

State is a plain mutable object — mutate it in handle(message, data, context) and the bus persists the result.

export type ConcurrencyToken = string;

The opaque optimistic-concurrency token returned by ISagaStore.insert and ISagaStore.update. The bus holds onto the token across a handle call and passes it back as expectedToken on the next update; if the row was changed between load and save the store should throw ConcurrencyError and the bus retries with the fresh state. Applications never construct or inspect a ConcurrencyToken directly — it is an implementation detail of the store.

export interface FoundSaga<TData extends ProcessData> {
readonly data: TData;
readonly concurrencyToken: ConcurrencyToken;
}

The value returned by ISagaStore.findByCorrelationId when a row exists. data is the deserialised saga state; concurrencyToken is the token to pass back into update. findByCorrelationId returns undefined instead of a FoundSaga when no row exists for the given correlationId.