import { StateMachineConfig, HistoryEntry, DeliveryState, DeliveryEvent, DeliveryStateMachineConfig } from "./types"; /** * A fully generic, typed state machine. * * @template S - Your state union type (e.g. "PENDING" | "PAID" | "SHIPPED") * @template E - Your event union type (e.g. "PAY" | "SHIP" | "CANCEL") * * @example * // Custom e-commerce order * type ShopState = "CART" | "CHECKOUT" | "PAID" | "SHIPPED" | "RETURNED"; * type ShopEvent = "CHECKOUT" | "PAY" | "SHIP" | "RETURN"; * * const order = new StateMachine({ * orderId: "ord_123", * initialState: "CART", * transitions: { * CART: { CHECKOUT: "CHECKOUT" }, * CHECKOUT: { PAY: "PAID" }, * PAID: { SHIP: "SHIPPED" }, * SHIPPED: { RETURN: "RETURNED" }, * }, * terminalStates: ["RETURNED", "SHIPPED"], * activeStates: ["CHECKOUT", "PAID"], * }); */ export declare class StateMachine { private _state; private readonly _orderId; private readonly _hooks; private readonly _transitions; private readonly _history; private readonly _terminalStates; private readonly _activeStates; constructor(config: StateMachineConfig); /** Current state */ get state(): S; /** Full transition history */ get history(): Readonly[]>; /** ID of the entity this machine manages */ get orderId(): string; /** * Dispatch an event and transition to the next state. * Throws `InvalidTransitionError` if the event is not valid from the current state. */ dispatch(event: E, metadata?: Record): Promise; /** * Check whether a given event is valid from the current state * without dispatching it. */ can(event: E): boolean; /** Returns all events valid from the current state */ availableEvents(): E[]; /** True if the machine is in one of the configured terminal states */ isTerminal(): boolean; /** True if the machine is in one of the configured active states */ isActive(): boolean; /** Serialize for persistence (DB, Redis, etc.) */ toJSON(): { orderId: string; state: S; history: HistoryEntry[]; }; /** * Restore from a snapshot without re-running hooks. * Pass the same transitions/config used when the machine was first created. */ static fromSnapshot(snapshot: { orderId: string; state: S; history: HistoryEntry[]; }, config: Omit, "orderId" | "initialState">): StateMachine; } /** * A ready-to-use state machine pre-configured for food delivery / logistics. * Uses the built-in DeliveryState and DeliveryEvent types with sensible defaults. * * Drop-in for most delivery use cases. Extend with custom transitions if needed. * * @example * const order = new DeliveryStateMachine({ orderId: "ord_001" }); * await order.dispatch("CONFIRM"); * await order.dispatch("START_PREPARING"); */ export declare class DeliveryStateMachine extends StateMachine { constructor(config: DeliveryStateMachineConfig & { orderId: string; }); /** * Restore a DeliveryStateMachine from a snapshot. */ static fromDeliverySnapshot(snapshot: { orderId: string; state: DeliveryState; history: HistoryEntry[]; }, config?: Pick): DeliveryStateMachine; } //# sourceMappingURL=machine.d.ts.map