@ilijanl/temporalio-utils
Version:
A set of utils around temporalio typescript sdk
69 lines (66 loc) • 4.79 kB
TypeScript
import * as wf from '@temporalio/workflow';
import { ActivityOptions } from '@temporalio/workflow';
import { W as WorkflowDefinition, c as WorkflowFn, d as WorkflowImplementation, A as ActivityDefinition, e as ActivityExecuteOptions, I as InType, O as OutType, a as ActivityFn } from '../definitions-DLuyb94F.js';
import { WorkflowPayload } from '../index.js';
import '@temporalio/common';
/**
* Use this queue name during tests to have a simple retry policy.
*/
declare const testingQueueName = "__testingQueue__";
/**
* Create a workflow implementation for a workflow definition.
*/
declare const createWorkflow: <TInput, TOutput>(definition: WorkflowDefinition<TInput, TOutput>, execution: WorkflowFn<NoInfer<TInput>, NoInfer<TOutput>>) => WorkflowImplementation<NoInfer<TInput>, NoInfer<TOutput>>;
type ChildWorkflowExecuteOptions = Omit<wf.ChildWorkflowOptions, "taskQueue">;
/**
* Start a child Workflow execution from an workflow and await its completion.
*
* - By default, a child will be scheduled on the same task queue as its parent.
* - This operation is cancellable using {@link CancellationScope}s.
*
* @return The result of the child Workflow.
*/
declare const executeChildWorkflow: <TInput, TOutput>(definition: WorkflowDefinition<TInput, TOutput>, payload: WorkflowPayload<NoInfer<TInput>>, options?: ChildWorkflowExecuteOptions) => Promise<TOutput>;
/**
* Start a child Workflow execution from an workflow and don't await its completion.
*
* - By default, a child will be scheduled on the same task queue as its parent.
* - The `parentClosePolicy` is by default {@link wf.ParentClosePolicy.ABANDON}
* - the `cancellationType` is by default {@link wf.ChildWorkflowCancellationType.TRY_CANCEL}
*/
declare const startAsyncChildWorkflow: <TInput, TOutput>(definition: WorkflowDefinition<TInput, TOutput>, payload: WorkflowPayload<NoInfer<TInput>>, options?: ChildWorkflowExecuteOptions) => Promise<wf.ChildWorkflowHandle<WorkflowFn<TInput, TOutput>>>;
/**
* Starts an activity execution and waits for the result.
* The `options` parameter will be deep merged with any options set in the activity definition.
*/
declare function executeActivity<TInput, TOutput>(activityDefinition: ActivityDefinition<string, TInput, TOutput>, input: NoInfer<TInput>): Promise<TOutput>;
declare function executeActivity<TInput, TOutput>(activityDefinition: ActivityDefinition<string, TInput, TOutput>, input: NoInfer<TInput>, options?: ActivityExecuteOptions): Promise<TOutput>;
/**
* Schedule an activity from a workflow defintiion. The workflow name will be used as the activity name.
* Useful when you want to "mock" a child workflow during tests.
*/
declare const executeWorkflowAsActivity: <TInput, TOuput>(workflowDefinition: WorkflowDefinition<TInput, TOuput>, payload: WorkflowPayload<TInput>, activityOptions?: ActivityOptions) => Promise<unknown>;
/**
* For each workflow in `workflowDefinitions`, create an internal workflow that has one activity with the same name as the workflow name.
* This is useful for mocking workflows as activities and can be used when a workflow has child workflows during tests.
*/
declare const workflowsToActivities: (workflowDefinitions: Array<WorkflowDefinition<any, any>>, activityOptions?: ActivityOptions) => Record<string, WorkflowFn<unknown, unknown>>;
/**
* Creates a generic workflow handler from a list of workflow implementations.
*/
declare const createWorkflowsHandler: (workflows: Array<WorkflowImplementation<any, any>>) => wf.Workflow;
type ActivityType<TDef extends ActivityDefinition<string, unknown, unknown>> = ActivityFn<InType<TDef>, OutType<TDef>>;
type ActivitiesType<TRecord extends ActivitiesRecord> = {
[K in keyof TRecord as TRecord[K]["activityType"]]: ActivityType<TRecord[K]>;
};
type CallableActivity<TInput, TOutput> = ((input: TInput) => Promise<TOutput>) | ((input: TInput, options?: ActivityExecuteOptions) => Promise<TOutput>);
type ActivitiesRecord = Record<string, ActivityDefinition<string, unknown, unknown>>;
type CallableActivities<TActivities extends ActivitiesRecord> = {
[K in keyof TActivities]: CallableActivity<InType<TActivities[K]>, OutType<TActivities[K]>>;
};
type CallableActivitiesType<T> = T extends CallableActivities<infer I> ? ActivitiesType<I> : never;
/**
* Creates a record of callable activities from a record of activity definitions.
*/
declare const createCallableActivities: <TActivities extends ActivitiesRecord>(activities: TActivities) => CallableActivities<TActivities>;
export { type CallableActivitiesType, type ChildWorkflowExecuteOptions, createCallableActivities, createWorkflow, createWorkflowsHandler, executeActivity, executeChildWorkflow, executeWorkflowAsActivity, startAsyncChildWorkflow, testingQueueName, workflowsToActivities };