@ilijanl/temporalio-utils
Version:
A set of utils around temporalio typescript sdk
69 lines (65 loc) • 3.46 kB
TypeScript
import { ActivityOptions, Duration } from '@temporalio/common';
declare const inputSymbol: unique symbol;
declare const outputSymbol: unique symbol;
type _InputType = typeof inputSymbol;
type _OutputType = typeof outputSymbol;
type WorkflowConfig = {
/**
* Optional task queue that the workflow should be scheduled on.
* If not provided, a task queue will be determined by the invoker of the workflow.
*/
taskQueue?: string;
};
type WorkflowFn<TInput, TOutput> = (input: TInput) => Promise<TOutput>;
type WorkflowBaseDefinition = {
workflowType: string;
taskQueue: string | undefined;
};
type TypedFn<TInput, TOutput> = {
[inputSymbol]: TInput;
[outputSymbol]: TOutput;
};
type WorkflowDefinition<TInput, TOutput = void> = WorkflowBaseDefinition & TypedFn<TInput, TOutput>;
type InType<T extends TypedFn<unknown, unknown>> = T[_InputType];
type OutType<T extends TypedFn<unknown, unknown>> = T[_OutputType];
type WorkflowType<T extends WorkflowDefinition<unknown, unknown>> = WorkflowFn<InType<T>, OutType<T>>;
/**
* Defines a workflow with a given name and settings
*/
declare const defineWorkflow: <TInput, TOutput = void>(workflowType: string, config?: WorkflowConfig) => WorkflowDefinition<TInput, TOutput>;
type WorkflowImplementation<TInput, TOutput> = {
definition: WorkflowDefinition<TInput, TOutput>;
executeFn: WorkflowFn<TInput, TOutput>;
};
type ActivityFn<TInput, TOutput> = (input: TInput) => Promise<TOutput>;
type Activity<TName, TInput, TOutput> = {
definition: ActivityDefinition<TName, TInput, TOutput>;
executeFn: ActivityFn<TInput, TOutput>;
};
type ActivityDefinitionConfig = Omit<ActivityOptions, "scheduleToCloseTimeout" | "activityId" | "scheduleToStartTimeout">;
type ActivityExecuteOptions = Partial<{
/**
* Total time that a workflow is willing to wait for the Activity to complete.
* `timeout` limits the total time of an Activity's execution including retries (use {@link startToCloseTimeout} to limit the time of a single attempt).
*
* @default unlimited
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
*/
timeout: Duration;
}>;
type ActivityDefinition<TName, TInput, TOutput> = {
activityType: TName;
config: ActivityDefinitionConfig;
} & TypedFn<TInput, TOutput>;
declare const defaultActivityOptions: ActivityDefinitionConfig;
/**
* Defines an activity with a given name and config.
*
* By default {@link defaultActivityOptions} is used as a base for activity options.
*/
declare const defineActivity: <TName extends string>(activityType: TName) => <TInput, TOutput = void>(config?: ActivityDefinitionConfig) => ActivityDefinition<TName, TInput, TOutput>;
type ActivityType<TDef extends ActivityDefinition<string, any, any>> = ActivityFn<InType<TDef>, OutType<TDef>>;
type ActivitiesType<TRecord extends Record<string, ActivityDefinition<string, any, any>>> = {
[K in keyof TRecord as TRecord[K]["activityType"]]: ActivityType<TRecord[K]>;
};
export { type ActivityDefinition as A, type InType as I, type OutType as O, type WorkflowDefinition as W, type ActivityFn as a, type Activity as b, type WorkflowFn as c, type WorkflowImplementation as d, type ActivityExecuteOptions as e, type WorkflowType as f, defineWorkflow as g, type ActivityDefinitionConfig as h, defaultActivityOptions as i, defineActivity as j, type ActivityType as k, type ActivitiesType as l };