import { OrchestrationContext } from "../task/context/orchestration-context"; import { ParentOrchestrationInstance } from "../types/parent-orchestration-instance.type"; import * as pb from "../proto/orchestrator_service_pb"; import { CompletableTask } from "../task/completable-task"; import { RetryTaskBase } from "../task/retry-task-base"; import { RetryTimerTask } from "../task/retry-timer-task"; import { TimerTask } from "../task/timer-task"; import { TaskOptions, SubOrchestrationOptions } from "../task/options"; import { TActivity } from "../types/activity.type"; import { TOrchestrator } from "../types/orchestrator.type"; import { Task } from "../task/task"; import { OrchestrationEntityFeature, CriticalSectionInfo, LockHandle } from "../entities/orchestration-entity-feature"; import { EntityInstanceId } from "../entities/entity-instance-id"; import { SignalEntityOptions, CallEntityOptions } from "../entities/signal-entity-options"; export declare class RuntimeOrchestrationContext extends OrchestrationContext { _generator?: Generator, any, any>; _previousTask?: Task; _isReplaying: boolean; _isComplete: boolean; _result: any; _pendingActions: Record; _pendingTasks: Record>; _sequenceNumber: number; _newGuidCounter: number; _currentUtcDatetime: Date; _instanceId: string; _executionId: string; _version: string; _parent?: ParentOrchestrationInstance; _completionStatus?: pb.OrchestrationStatus; _receivedEvents: Record; _pendingEvents: Record[]>; _newInput?: any; _saveEvents: boolean; _customStatus?: string; _entityFeature: RuntimeOrchestrationEntityFeature; constructor(instanceId: string); get instanceId(): string; get entities(): OrchestrationEntityFeature; get parent(): ParentOrchestrationInstance | undefined; get currentUtcDateTime(): Date; get isReplaying(): boolean; get version(): string; /** * This is the main entry point for the orchestrator. It will run the generator * and return the first task to be executed. It is typically executed from the * orchestrator executor. * * @param generator */ run(generator: Generator, any, any>): Promise; resume(): Promise; setComplete(result: any, status: pb.OrchestrationStatus, isResultEncoded?: boolean): void; setFailed(e: Error): void; setContinuedAsNew(newInput: any, saveEvents: boolean): void; getActions(): pb.OrchestratorAction[]; nextSequenceNumber(): number; /** * Create a timer * * @param fireAt number Amount of seconds between now and when the timer should fire * @param fireAt Date The date when the timer should fire * @returns */ createTimer(fireAt: number | Date): TimerTask; callActivity(activity: TActivity | string, input?: TInput | undefined, options?: TaskOptions): Task; callSubOrchestrator(orchestrator: TOrchestrator | string, input?: TInput | undefined, options?: SubOrchestrationOptions): Task; waitForExternalEvent(name: string): Task; /** * Orchestrations can be continued as new. This API allows an orchestration to restart itself from scratch, optionally with a new input. */ continueAsNew(newInput: any, saveEvents?: boolean): void; /** * Sets a custom status value for the current orchestration instance. * * The value is serialized eagerly via JSON.stringify so that serialization * errors surface inside the orchestrator execution (where they are caught * by the executor's try-catch) rather than after execution completes. */ setCustomStatus(customStatus: any): void; /** * Gets the encoded custom status value for the current orchestration instance. * This is used internally when building the orchestrator response. * * Returns the pre-serialized JSON string set by setCustomStatus(). */ getCustomStatus(): string | undefined; /** * Sends an event to another orchestration instance. */ sendEvent(instanceId: string, eventName: string, eventData?: any): void; /** * Creates a new deterministic UUID that is safe for replay within an orchestration. * * Uses UUID v5 (name-based with SHA-1) per RFC 4122 ยง4.3. * The generated GUID is deterministic based on instanceId, currentUtcDateTime, and a counter, * ensuring the same value is produced during replay. */ newGuid(): string; /** * Generates a deterministic GUID using UUID v5 algorithm. * The output format is compatible with other Durable Task SDKs. */ private generateDeterministicGuid; /** * Swaps bytes to convert between UUID (big-endian) and GUID (mixed-endian) byte order. * GUIDs store the first 3 components (Data1, Data2, Data3) in little-endian format. */ private swapGuidBytes; /** * Parses a UUID string to a byte buffer in big-endian (network) order. */ private parseUuidToBytes; /** * Formats a GUID byte buffer as a string in standard GUID format (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). */ private formatGuidBytes; /** * Creates a retry timer for a retryable task. * The timer will be associated with the retryable task so that when it fires, * the original task can be rescheduled. * * @param retryableTask - The retryable task to create a timer for * @param delayMs - The delay in milliseconds before the timer fires * @returns The timer task */ createRetryTimer(retryableTask: RetryTaskBase, delayMs: number): RetryTimerTask; /** * Creates the appropriate retry task or a plain CompletableTask based on the options. * * @param action - The orchestrator action * @param id - The sequence ID for task tracking * @param options - The task options (may contain retry configuration) * @param taskType - Whether this is an activity or sub-orchestration * @returns The created task */ private createRetryTaskOrDefault; /** * Reschedules a retry task for retry by creating a new action with a new ID. * This is called when a retry timer fires or a retry handler returns true. * * @param retryTask - The retry task to reschedule (RetryableTask or RetryHandlerTask) */ rescheduleRetryTask(retryTask: RetryTaskBase): void; } /** * Implementation of OrchestrationEntityFeature for interacting with entities from orchestrations. * * @remarks * This class provides the entity feature for the RuntimeOrchestrationContext. * It allows orchestrations to call entities (request/response), signal entities (one-way), * and acquire locks on entities for critical sections. */ declare class RuntimeOrchestrationEntityFeature implements OrchestrationEntityFeature { private readonly context; /** * Tracks pending entity calls by requestId. * Used to correlate responses (EntityOperationCompleted/Failed) with the original call. */ readonly pendingEntityCalls: Map; entityId: EntityInstanceId; operationName: string; }>; /** * Tracks pending lock acquisitions by criticalSectionId. * Used to correlate EntityLockGranted events with the original lock request. */ readonly pendingLockRequests: Map; lockSet: EntityInstanceId[]; }>; /** * Current critical section state. Null if not in a critical section. */ private criticalSection; /** * Whether a lock acquisition is pending (lock request sent but not yet granted). * This is used to prevent calling entities before the lock is granted. */ private lockAcquisitionPending; constructor(context: RuntimeOrchestrationContext); /** * Whether this orchestration is currently inside a critical section. */ get isInsideCriticalSection(): boolean; /** * The ID of the current critical section, or undefined if not in a critical section. */ get currentCriticalSectionId(): string | undefined; /** * Calls an operation on an entity and waits for it to complete. * * @param id - The target entity instance ID. * @param operationName - The name of the operation to invoke. * @param input - Optional input to pass to the operation. * @param options - Optional call options. * @returns A task that completes when the entity operation finishes. * * @remarks * This creates a SendEntityMessageAction with an EntityOperationCalledEvent. * The orchestration waits for EntityOperationCompletedEvent or EntityOperationFailedEvent. */ callEntity(id: EntityInstanceId, operationName: string, input?: unknown, options?: CallEntityOptions): Task; /** * Called after an entity call within a critical section completes. * Makes the entity available for calls again. */ recoverLockAfterCall(entityId: EntityInstanceId): void; /** * Signals an operation on an entity without waiting for a response. * * @param id - The target entity instance ID. * @param operationName - The name of the operation to invoke. * @param input - Optional input to pass to the operation. * @param options - Optional signal options (e.g., scheduled time). * * @remarks * This creates a SendEntityMessageAction with an EntityOperationSignaledEvent. * The orchestration does not wait for the entity to process the operation. */ signalEntity(id: EntityInstanceId, operationName: string, input?: unknown, options?: SignalEntityOptions): void; /** * Acquires locks on one or more entities for a critical section. * * @param entityIds - The entities to lock. * @returns A task that completes when all locks are acquired, with a handle to release the locks. * * @remarks * Entities are sorted before lock acquisition to prevent deadlocks. * Duplicates are removed automatically. */ lockEntities(...entityIds: EntityInstanceId[]): Task; /** * Called when EntityLockGrantedEvent is received. * Completes the pending lock request and returns the lock handle. */ completeLockAcquisition(criticalSectionId: string): void; /** * Checks whether the orchestration is currently inside a critical section. * * @returns Information about the current critical section state. */ isInCriticalSection(): CriticalSectionInfo; /** * Exits the critical section, releasing all locks. * * @param criticalSectionId - Optional: only exit if the ID matches. */ exitCriticalSection(criticalSectionId?: string): void; } export {};