@@ -7,6 +7,7 @@ import { InternalWorkflowStartOptionsKey, InternalWorkflowStartOptions } from '@
77import { generateWorkflowRunOperationToken , loadWorkflowRunOperationToken } from './token' ;
88import { convertNexusLinkToWorkflowEventLink , convertWorkflowEventLinkToNexusLink } from './link-converter' ;
99
10+ // Context used internally in the SDK to propagate information from the worker to the Temporal Nexus helpers.
1011export interface HandlerContext extends BaseHandlerContext {
1112 log : Logger ;
1213 client : Client ;
@@ -44,18 +45,27 @@ export const log: Logger = {
4445// TODO: also support getting a metrics handler.
4546
4647/**
47- * Returns a client to be used in a Nexus Operation's context, this Client is powered by the same Connection that the
48- * worker was created with.
48+ * Returns a client to be used in a Nexus Operation's context, this Client is powered by the same NativeConnection that
49+ * the worker was created with.
4950 */
5051export function getClient ( ) : Client {
5152 return getHandlerContext < HandlerContext > ( ) . client ;
5253}
5354
55+ /**
56+ * A handle to a running workflow that is returned by the {@link startWorkflow} helper.
57+ * This handle should be returned by {@link WorkflowRunOperationHandler} implementations.
58+ */
5459export interface WorkflowHandle < _T > {
5560 readonly workflowId : string ;
5661 readonly runId : string ;
5762}
5863
64+ /**
65+ * Starts a workflow run for a {@link WorkflowRunOperationHandler}, linking the execution chain to a Nexus Operation
66+ * (subsequent runs started from continue-as-new and retries). Automatically propagates the callback, request ID, and
67+ * back and forward links from the Nexus options to the Workflow.
68+ */
5969export async function startWorkflow < T extends Workflow > (
6070 workflowTypeOrFunc : string | T ,
6171 workflowOptions : WorkflowStartOptions < T > ,
@@ -87,7 +97,7 @@ export async function startWorkflow<T extends Workflow>(
8797 internalOptions . completionCallbacks = [
8898 {
8999 nexus : { url : nexusOptions . callbackURL , header : nexusOptions . callbackHeaders } ,
90- links, // pass in links here as well, the server dedupes them.
100+ links, // pass in links here as well for older servers, newer servers dedupe them.
91101 } ,
92102 ] ;
93103 }
@@ -103,11 +113,17 @@ export async function startWorkflow<T extends Workflow>(
103113 return { workflowId : handle . workflowId , runId : handle . firstExecutionRunId } ;
104114}
105115
116+ /**
117+ * A handler function for the {@link WorkflowRunOperation} constructor.
118+ */
106119export type WorkflowRunOperationHandler < I , O > = (
107120 input : I ,
108121 options : nexus . StartOperationOptions
109122) => Promise < WorkflowHandle < O > > ;
110123
124+ /**
125+ * A Nexus Operation implementation that is backed by a Workflow run.
126+ */
111127export class WorkflowRunOperation < I , O > implements nexus . OperationHandler < I , O > {
112128 constructor ( readonly handler : WorkflowRunOperationHandler < I , O > ) { }
113129
0 commit comments