import { EventEmitter } from "events";
import { IDistributedTransactionStorage } from "./datastore/abstract-storage";
import { TransactionStep, TransactionStepHandler } from "./transaction-step";
import { TransactionFlow, TransactionHandlerType, TransactionState } from "./types";
/**
 * @typedef TransactionMetadata
 * @property model_id - The id of the model_id that created the transaction (modelId).
 * @property idempotency_key - The idempotency key of the transaction.
 * @property action - The action of the transaction.
 * @property action_type - The type of the transaction.
 * @property attempt - The number of attempts for the transaction.
 * @property timestamp - The timestamp of the transaction.
 */
export type TransactionMetadata = {
    model_id: string;
    idempotency_key: string;
    action: string;
    action_type: TransactionHandlerType;
    attempt: number;
    timestamp: number;
};
/**
 * @typedef TransactionContext
 * @property payload - Object containing the initial payload.
 * @property invoke - Object containing responses of Invoke handlers on steps flagged with saveResponse.
 * @property compensate - Object containing responses of Compensate handlers on steps flagged with saveResponse.
 */
export declare class TransactionContext {
    payload: unknown;
    invoke: Record<string, unknown>;
    compensate: Record<string, unknown>;
    constructor(payload?: unknown, invoke?: Record<string, unknown>, compensate?: Record<string, unknown>);
}
export declare class TransactionStepError {
    action: string;
    handlerType: TransactionHandlerType;
    error: Error | any;
    constructor(action: string, handlerType: TransactionHandlerType, error: Error | any);
}
export declare class TransactionCheckpoint {
    #private;
    flow: TransactionFlow;
    context: TransactionContext;
    errors: TransactionStepError[];
    constructor(flow: TransactionFlow, context: TransactionContext, errors?: TransactionStepError[]);
    /**
     * Merge the current checkpoint with incoming data from a concurrent save operation.
     * This handles race conditions when multiple steps complete simultaneously.
     *
     * @param storedData - The checkpoint data being saved
     * @param savingStepId - Optional step ID if this is a step-specific save
     */
    static mergeCheckpoints(currentTransactionData: TransactionCheckpoint, storedData?: TransactionCheckpoint): TransactionCheckpoint;
}
export declare class TransactionPayload {
    metadata: TransactionMetadata;
    data: Record<string, unknown>;
    context: TransactionContext;
    /**
     * @param metadata - The metadata of the transaction.
     * @param data - The initial payload data to begin a transation.
     * @param context - Object gathering responses of all steps flagged with saveResponse.
     */
    constructor(metadata: TransactionMetadata, data: Record<string, unknown>, context: TransactionContext);
}
/**
 * DistributedTransaction represents a distributed transaction, which is a transaction that is composed of multiple steps that are executed in a specific order.
 */
declare class DistributedTransaction extends EventEmitter {
    #private;
    private flow;
    handler: TransactionStepHandler;
    payload?: any | undefined;
    modelId: string;
    transactionId: string;
    runId: string;
    private errors;
    private context;
    private static keyValueStore;
    static setStorage(storage: IDistributedTransactionStorage): void;
    static keyPrefix: string;
    constructor(flow: TransactionFlow, handler: TransactionStepHandler, payload?: any | undefined, errors?: TransactionStepError[], context?: TransactionContext);
    getFlow(): TransactionFlow;
    getContext(): TransactionContext;
    getErrors(handlerType?: TransactionHandlerType): TransactionStepError[];
    addError(action: string, handlerType: TransactionHandlerType, error: Error | any): void;
    addResponse(action: string, handlerType: TransactionHandlerType, response: unknown): void;
    hasFinished(): boolean;
    getState(): TransactionState;
    get isPartiallyCompleted(): boolean;
    canInvoke(): boolean;
    canRevert(): boolean;
    hasTimeout(): boolean;
    getTimeout(): number | undefined;
    saveCheckpoint({ ttl, parallelSteps, stepId, _v, }?: {
        ttl?: number;
        parallelSteps?: number;
        stepId?: string;
        _v?: number;
    }): Promise<TransactionCheckpoint | undefined>;
    static loadTransaction(modelId: string, transactionId: string, options?: {
        isCancelling?: boolean;
    }): Promise<TransactionCheckpoint | null>;
    scheduleRetry(step: TransactionStep, interval: number): Promise<void>;
    clearRetry(step: TransactionStep): Promise<void>;
    scheduleTransactionTimeout(interval: number): Promise<void>;
    clearTransactionTimeout(): Promise<void>;
    scheduleStepTimeout(step: TransactionStep, interval: number): Promise<void>;
    clearStepTimeout(step: TransactionStep): Promise<void>;
    setTemporaryData(key: string, value: unknown): void;
    getTemporaryData(key: string): unknown;
    hasTemporaryData(key: string): boolean;
}
declare const GlobalDistributedTransaction: typeof DistributedTransaction;
export { GlobalDistributedTransaction as DistributedTransaction, DistributedTransaction as DistributedTransactionType, };
//# sourceMappingURL=distributed-transaction.d.ts.map