/** * Workflow imports stub module. * * This module provides stubs for workflow functionality needed by interceptors. * When bundled by the workflow bundler, this is replaced with the real * implementation via NormalModuleReplacementPlugin. * * @module */ import type { inWorkflowContext as inWorkflowContextT, workflowInfo as workflowInfoT, proxySinks as proxySinksT, AsyncLocalStorage as AsyncLocalStorageT, ContinueAsNew as ContinueAsNewT, getRandomStream as getRandomStreamT, } from '@temporalio/workflow'; import { IllegalStateError } from '@temporalio/common'; // always returns false since if using this implementation, we are outside of workflow context export const inWorkflowContext: typeof inWorkflowContextT = () => false; // All of the following stubs will throw if used export const workflowInfo: typeof workflowInfoT = () => { throw new IllegalStateError('Workflow.workflowInfo(...) may only be used from a Workflow Execution.'); }; export const ContinueAsNew = class ContinueAsNew {} as unknown as typeof ContinueAsNewT; export const AsyncLocalStorage = class AsyncLocalStorage {} as unknown as typeof AsyncLocalStorageT; export const proxySinks: typeof proxySinksT = () => { throw new IllegalStateError('Proxied sinks functions may only be used from a Workflow Execution.'); }; export const getRandomStream: typeof getRandomStreamT = () => { throw new IllegalStateError('Workflow.getRandomStream(...) may only be used from a Workflow Execution.'); };