import type { ChildExecution, ExecutionHandle, ExecutionID } from "./execution.js"; import { WorkflowSpec } from "./internal/service-spec.js"; import type { DurationSchedule, Schedule } from "./schedule.js"; import type { StartExecutionRequest } from "./service-client.js"; export interface WorkflowHandler { (input: Input, context: WorkflowContext): Promise; } /** * Workflow options available when invoked by another workflow. */ export interface ChildWorkflowOptions { timeout?: Promise | Schedule; } /** * Options which determine how an execution operates. * * Overrides those provided by the workflow definition. */ export interface WorkflowExecutionOptions { /** * Number of seconds before or a time to time the workflow out at. * * @default - workflow will never timeout. */ timeout?: Schedule; } /** * Options which determine how a workflow operates. * * Can be provided at workflow definition time and/or overridden by the caller of {@link WorkflowClient.startWorkflow}. */ export interface WorkflowDefinitionOptions { /** * Number of seconds before execution times out. * * @default - workflow will never timeout. */ timeout?: DurationSchedule; } export type WorkflowOutput = W extends Workflow ? Out : never; export type WorkflowInput = W extends Workflow ? In : undefined; export type WorkflowArguments = [Input] extends [undefined] ? [input?: Input, options?: ChildWorkflowOptions] : [input: Input, options?: ChildWorkflowOptions]; /** * A {@link Workflow} is a long-running process that orchestrates calls * to other services in a durable and observable way. */ export interface Workflow extends WorkflowSpec { options?: WorkflowDefinitionOptions; kind: "Workflow"; /** * Invokes the {@link Workflow} from within another workflow. * * This can only be called from within another workflow because it's not possible * to wait for completion synchronously - it relies on the event-driven environment * of a workflow execution. * * To start a workflow from another environment, use {@link start}. */ (...args: WorkflowArguments): Promise & ChildExecution; /** * Starts a workflow execution */ startExecution(request: Omit>, "workflow">): Promise>>; } /** * Creates and registers a long-running workflow. * * Example: * ```ts * import { task, workflow } from "@eventual/core"; * * export default workflow("my-workflow", async ({ name }: { name: string }) => { * const result = await hello(name); * console.log(result); * return `you said ${result}`; * }); * * const hello = task("hello", async (name: string) => { * return `hello ${name}`; * }); * * Logging using `console.info` (or similar) in a workflow will write logs to the * execution's log stream in the service's workflow. * * To see these logs run `eventual get logs -e ` or find the log group using * `eventual show service`. * ``` * @param name a globally unique ID for this workflow. * @param definition the workflow definition. */ export declare function workflow(name: Name, definition: WorkflowHandler): Workflow; export declare function workflow(name: Name, opts: WorkflowDefinitionOptions, definition: WorkflowHandler): Workflow; /** * Context values related to the current execution of the workflow. */ export interface WorkflowExecutionContext { /** * Computed, Unique ID of the execution. */ id: ExecutionID; /** * Unique name of the execution, optionally provided in the startWorkflow call. */ name: string; /** * ID of the parent execution if this is a child workflow */ parentId?: ExecutionID; /** * The ISO 8601 UTC time the execution started. */ startTime: string; } /** * Context values related to the workflow definition. */ export interface WorkflowDefinitionContext { /** * The name of the workflow. */ name: string; } /** * Context values provided to each workflow execution. */ export interface WorkflowContext { /** * Context values related to the current execution of the workflow. */ workflow: WorkflowDefinitionContext; /** * Context values related to the workflow definition. */ execution: WorkflowExecutionContext; } //# sourceMappingURL=workflow.d.ts.map