@temporalio/nexus 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/link-converter.js +9 -13
- package/lib/link-converter.js.map +1 -1
- package/lib/workflow-helpers.d.ts +41 -4
- package/lib/workflow-helpers.js +109 -19
- package/lib/workflow-helpers.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +2 -0
- package/src/link-converter.ts +9 -14
- package/src/workflow-helpers.ts +192 -22
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
export { log, getClient, metricMeter, operationInfo, type OperationInfo, type TemporalCancelOperationContext, type TemporalStartOperationContext, } from './context';
|
|
7
|
-
export { startWorkflow, type CancelWorkflowRunOptions, type TemporalOperationHandlerOptions, TemporalOperationHandler, TemporalOperationResult, type TemporalNexusClient, type TemporalOperationStartHandler, WorkflowHandle, WorkflowRunOperationHandler, WorkflowRunOperationStartHandler, WorkflowStartOptions, } from './workflow-helpers';
|
|
7
|
+
export { startWorkflow, signalWithStartWorkflow, type CancelWorkflowRunOptions, type TemporalOperationHandlerOptions, TemporalOperationHandler, TemporalOperationResult, type TemporalNexusClient, type TemporalOperationStartHandler, WorkflowHandle, WorkflowRunOperationHandler, WorkflowRunOperationStartHandler, WorkflowStartOptions, WorkflowSignalWithStartOptions, } from './workflow-helpers';
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.WorkflowRunOperationHandler = exports.TemporalOperationResult = exports.TemporalOperationHandler = exports.startWorkflow = exports.operationInfo = exports.metricMeter = exports.getClient = exports.log = void 0;
|
|
8
|
+
exports.WorkflowRunOperationHandler = exports.TemporalOperationResult = exports.TemporalOperationHandler = exports.signalWithStartWorkflow = exports.startWorkflow = exports.operationInfo = exports.metricMeter = exports.getClient = exports.log = void 0;
|
|
9
9
|
var context_1 = require("./context");
|
|
10
10
|
//
|
|
11
11
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return context_1.log; } });
|
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "metricMeter", { enumerable: true, get: function
|
|
|
14
14
|
Object.defineProperty(exports, "operationInfo", { enumerable: true, get: function () { return context_1.operationInfo; } });
|
|
15
15
|
var workflow_helpers_1 = require("./workflow-helpers");
|
|
16
16
|
Object.defineProperty(exports, "startWorkflow", { enumerable: true, get: function () { return workflow_helpers_1.startWorkflow; } });
|
|
17
|
+
Object.defineProperty(exports, "signalWithStartWorkflow", { enumerable: true, get: function () { return workflow_helpers_1.signalWithStartWorkflow; } });
|
|
17
18
|
Object.defineProperty(exports, "TemporalOperationHandler", { enumerable: true, get: function () { return workflow_helpers_1.TemporalOperationHandler; } });
|
|
18
19
|
Object.defineProperty(exports, "TemporalOperationResult", { enumerable: true, get: function () { return workflow_helpers_1.TemporalOperationResult; } });
|
|
19
20
|
Object.defineProperty(exports, "WorkflowRunOperationHandler", { enumerable: true, get: function () { return workflow_helpers_1.WorkflowRunOperationHandler; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCASmB;AARjB,EAAE;AACF,8FAAA,GAAG,OAAA;AACH,oGAAA,SAAS,OAAA;AACT,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AAMf,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCASmB;AARjB,EAAE;AACF,8FAAA,GAAG,OAAA;AACH,oGAAA,SAAS,OAAA;AACT,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AAMf,uDAc4B;AAb1B,iHAAA,aAAa,OAAA;AACb,2HAAA,uBAAuB,OAAA;AAGvB,4HAAA,wBAAwB,OAAA;AACxB,2HAAA,uBAAuB,OAAA;AAIvB,+HAAA,2BAA2B,OAAA"}
|
package/lib/link-converter.js
CHANGED
|
@@ -15,7 +15,6 @@ const LINK_EVENT_ID_PARAM = 'eventID';
|
|
|
15
15
|
const LINK_EVENT_TYPE_PARAM = 'eventType';
|
|
16
16
|
const LINK_REQUEST_ID_PARAM = 'requestID';
|
|
17
17
|
const LINK_REFERENCE_TYPE_KEY = 'referenceType';
|
|
18
|
-
const LINK_RUN_ID_KEY = 'runID';
|
|
19
18
|
const EVENT_REFERENCE_TYPE = 'EventReference';
|
|
20
19
|
const REQUEST_ID_REFERENCE_TYPE = 'RequestIdReference';
|
|
21
20
|
// fullName isn't part of the generated typed unfortunately.
|
|
@@ -64,15 +63,10 @@ function convertWorkflowEventLinkToNexusLink(we) {
|
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
65
|
function convertNexusOperationLinkToNexusLink(opLink) {
|
|
67
|
-
if (!opLink.namespace || !opLink.operationId) {
|
|
68
|
-
throw new TypeError('Missing required fields: namespace, or
|
|
69
|
-
}
|
|
70
|
-
const url = new URL(`temporal:///namespaces/${encodeURIComponent(opLink.namespace)}/nexus-operations/${encodeURIComponent(opLink.operationId)}`);
|
|
71
|
-
if (opLink.runId != null) {
|
|
72
|
-
const searchParams = new URLSearchParams();
|
|
73
|
-
searchParams.set(LINK_RUN_ID_KEY, opLink.runId);
|
|
74
|
-
url.search = searchParams.toString();
|
|
66
|
+
if (!opLink.namespace || !opLink.operationId || !opLink.runId) {
|
|
67
|
+
throw new TypeError('Missing required fields: namespace, operationId, or runId');
|
|
75
68
|
}
|
|
69
|
+
const url = new URL(`temporal:///namespaces/${encodeURIComponent(opLink.namespace)}/nexus-operations/${encodeURIComponent(opLink.operationId)}/${encodeURIComponent(opLink.runId)}/details`);
|
|
76
70
|
return {
|
|
77
71
|
url,
|
|
78
72
|
type: NEXUS_OPERATION_TYPE,
|
|
@@ -107,15 +101,17 @@ function convertNexusLinkToWorkflowEventLink(link) {
|
|
|
107
101
|
return workflowEventLink;
|
|
108
102
|
}
|
|
109
103
|
function convertNexusLinkToNexusOperationLink(link) {
|
|
110
|
-
// /namespaces/:namespace/nexus-operations/:operationId
|
|
104
|
+
// /namespaces/:namespace/nexus-operations/:operationId/:runId/details
|
|
111
105
|
const parts = link.url.pathname.split('/');
|
|
112
|
-
if (parts.length !==
|
|
106
|
+
if (parts.length !== 7 || parts[1] !== 'namespaces' || parts[3] !== 'nexus-operations' || parts[6] !== 'details') {
|
|
113
107
|
throw new TypeError(`Invalid URL path: ${link.url}`);
|
|
114
108
|
}
|
|
115
109
|
const namespace = decodeURIComponent(parts[2]);
|
|
116
110
|
const operationId = decodeURIComponent(parts[4]);
|
|
117
|
-
const
|
|
118
|
-
|
|
111
|
+
const runId = decodeURIComponent(parts[5]);
|
|
112
|
+
if (!namespace || !operationId || !runId) {
|
|
113
|
+
throw new TypeError('Missing required fields: namespace, operationId, or runId');
|
|
114
|
+
}
|
|
119
115
|
return {
|
|
120
116
|
namespace,
|
|
121
117
|
operationId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-converter.js","sourceRoot":"","sources":["../src/link-converter.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"link-converter.js","sourceRoot":"","sources":["../src/link-converter.ts"],"names":[],"mappings":";;;;;AAuBA,wEAUC;AAED,wEAkBC;AAED,kFAoBC;AAED,oFAeC;AAED,kFA8BC;AA5HD,gDAAwB;AAExB,6CAA6C;AAE7C,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;AAO5C,MAAM,mBAAmB,GAAG,SAAS,CAAC;AACtC,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAC1C,M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;QAC9B,KAAK,GAAG,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,wBAAwB,CAAC,CAAS;IACzC,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAC1E,CAAC;AAED,SAAS,wBAAwB,CAAC,CAAS;IACzC,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as nexus from 'nexus-rpc';
|
|
2
|
-
import type { Workflow, WorkflowResultType } from '@temporalio/common';
|
|
2
|
+
import type { Workflow, WorkflowResultType, WithWorkflowArgs, SignalDefinition } from '@temporalio/common';
|
|
3
3
|
import type { Replace } from '@temporalio/common/lib/type-helpers';
|
|
4
|
-
import type { Client, WorkflowStartOptions as ClientWorkflowStartOptions } from '@temporalio/client';
|
|
4
|
+
import type { Client, WorkflowStartOptions as ClientWorkflowStartOptions, WorkflowSignalWithStartOptions as ClientWorkflowSignalWithStartOptions } from '@temporalio/client';
|
|
5
5
|
import { type TemporalCancelOperationContext, type TemporalStartOperationContext } from './context';
|
|
6
6
|
declare const isNexusWorkflowHandle: unique symbol;
|
|
7
7
|
declare const workflowResultType: unique symbol;
|
|
@@ -17,7 +17,8 @@ declare const workflowResultType: unique symbol;
|
|
|
17
17
|
*/
|
|
18
18
|
export interface WorkflowHandle<T> {
|
|
19
19
|
readonly workflowId: string;
|
|
20
|
-
readonly runId
|
|
20
|
+
readonly runId?: string;
|
|
21
|
+
signal<Args extends any[] = [], Name extends string = string>(def: SignalDefinition<Args, Name> | string, ...args: Args): Promise<void>;
|
|
21
22
|
/**
|
|
22
23
|
* Virtual type brand to maintain a distinction between {@link WorkflowHandle} provided by the
|
|
23
24
|
* {@link startWorkflow} helper (which will have attached links, request ID, completion URL, etc)
|
|
@@ -53,12 +54,27 @@ export type WorkflowStartOptions<T extends Workflow> = Replace<ClientWorkflowSta
|
|
|
53
54
|
/**
|
|
54
55
|
* Starts a workflow run for a {@link WorkflowRunOperationStartHandler}, linking the execution chain
|
|
55
56
|
* to a Nexus Operation (subsequent runs started from continue-as-new and retries). Automatically
|
|
56
|
-
* propagates the callback, request ID, and
|
|
57
|
+
* propagates the callback, request ID, and request and response links from the Nexus options to the
|
|
57
58
|
* Workflow.
|
|
58
59
|
*
|
|
59
60
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
60
61
|
*/
|
|
61
62
|
export declare function startWorkflow<T extends Workflow>(ctx: nexus.StartOperationContext, workflowTypeOrFunc: string | T, workflowOptions: WorkflowStartOptions<T>): Promise<WorkflowHandle<WorkflowResultType<T>>>;
|
|
63
|
+
/**
|
|
64
|
+
* Options for {@link signalWithStartWorkflow}, identical to the client's `WorkflowSignalWithStartOptions`
|
|
65
|
+
* except that `taskQueue` is optional and defaults to the current worker's task queue.
|
|
66
|
+
*
|
|
67
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
68
|
+
*/
|
|
69
|
+
export type WorkflowSignalWithStartOptions<SignalArgs extends any[] = []> = Replace<ClientWorkflowSignalWithStartOptions<SignalArgs>, {
|
|
70
|
+
taskQueue?: string;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Signals a Workflow, starting it first if it is not already running, as part of a Nexus Operation.
|
|
74
|
+
*
|
|
75
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
76
|
+
*/
|
|
77
|
+
export declare function signalWithStartWorkflow<T extends Workflow, SignalArgs extends any[] = []>(ctx: nexus.StartOperationContext, workflowTypeOrFunc: string | T, workflowOptions: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SignalArgs>>): Promise<WorkflowHandle<WorkflowResultType<T>>>;
|
|
62
78
|
/**
|
|
63
79
|
* A handler function for the {@link WorkflowRunOperationHandler} constructor.
|
|
64
80
|
*
|
|
@@ -111,6 +127,27 @@ export interface TemporalNexusClient {
|
|
|
111
127
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
112
128
|
*/
|
|
113
129
|
startWorkflow<T extends Workflow>(workflowTypeOrFunc: string | T, workflowOptions: WorkflowStartOptions<T>): Promise<TemporalOperationResult<WorkflowResultType<T>>>;
|
|
130
|
+
/**
|
|
131
|
+
* Create a Nexus-aware handle to an existing Workflow.
|
|
132
|
+
*
|
|
133
|
+
* - If only `workflowId` is passed, and there are multiple Workflow Executions with that ID, the handle will refer to
|
|
134
|
+
* the most recent one.
|
|
135
|
+
* - If `workflowId` and `runId` are passed, the handle will refer to the specific Workflow Execution with that Run
|
|
136
|
+
* ID.
|
|
137
|
+
*
|
|
138
|
+
* This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
|
|
139
|
+
* methods like `handle.signal()` will throw a {@link WorkflowNotFoundError} error.
|
|
140
|
+
*
|
|
141
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
142
|
+
*/
|
|
143
|
+
getWorkflowHandle<T extends Workflow>(workflowId: string, runId?: string): WorkflowHandle<WorkflowResultType<T>>;
|
|
144
|
+
/**
|
|
145
|
+
* Signals a Workflow, starting it first if it is not already running, forwarding the Nexus
|
|
146
|
+
* Operation's request links and propagating the response link the server returns (when supported).
|
|
147
|
+
*
|
|
148
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
149
|
+
*/
|
|
150
|
+
signalWithStartWorkflow<T extends Workflow, SignalArgs extends any[] = []>(workflowTypeOrFunc: string | T, workflowOptions: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SignalArgs>>): Promise<void>;
|
|
114
151
|
}
|
|
115
152
|
/**
|
|
116
153
|
* A handler function for the {@link TemporalOperationHandler} constructor.
|
package/lib/workflow-helpers.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.TemporalOperationHandler = exports.TemporalOperationResult = exports.WorkflowRunOperationHandler = void 0;
|
|
27
27
|
exports.startWorkflow = startWorkflow;
|
|
28
|
+
exports.signalWithStartWorkflow = signalWithStartWorkflow;
|
|
28
29
|
const nexus = __importStar(require("nexus-rpc"));
|
|
29
30
|
const internal_1 = require("@temporalio/client/lib/internal");
|
|
30
31
|
const link_converter_1 = require("./link-converter");
|
|
@@ -33,24 +34,14 @@ const context_1 = require("./context");
|
|
|
33
34
|
/**
|
|
34
35
|
* Starts a workflow run for a {@link WorkflowRunOperationStartHandler}, linking the execution chain
|
|
35
36
|
* to a Nexus Operation (subsequent runs started from continue-as-new and retries). Automatically
|
|
36
|
-
* propagates the callback, request ID, and
|
|
37
|
+
* propagates the callback, request ID, and request and response links from the Nexus options to the
|
|
37
38
|
* Workflow.
|
|
38
39
|
*
|
|
39
40
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
40
41
|
*/
|
|
41
42
|
async function startWorkflow(ctx, workflowTypeOrFunc, workflowOptions) {
|
|
42
43
|
const { client, taskQueue } = (0, context_1.getHandlerContext)();
|
|
43
|
-
const links =
|
|
44
|
-
if (ctx.inboundLinks?.length > 0) {
|
|
45
|
-
for (const l of ctx.inboundLinks) {
|
|
46
|
-
try {
|
|
47
|
-
links.push((0, link_converter_1.convertNexusLinkToTemporalLink)(l));
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
context_1.log.warn('failed to convert Nexus link to Workflow event link', { error });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
44
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
54
45
|
const internalOptions = {
|
|
55
46
|
links,
|
|
56
47
|
requestId: ctx.requestId,
|
|
@@ -81,17 +72,92 @@ async function startWorkflow(ctx, workflowTypeOrFunc, workflowOptions) {
|
|
|
81
72
|
[internal_1.InternalWorkflowStartOptionsSymbol]: internalOptions,
|
|
82
73
|
};
|
|
83
74
|
const handle = await client.workflow.start(workflowTypeOrFunc, startOptions);
|
|
84
|
-
if (internalOptions.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
if (internalOptions.responseLink != null) {
|
|
76
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
77
|
+
}
|
|
78
|
+
return createWorkflowHandle(ctx, handle.workflowId, handle.firstExecutionRunId);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts the request links carried on the operation start context into Temporal links so
|
|
82
|
+
* they can be forwarded onto an outgoing Workflow RPC (signal, signalWithStart, start). Links that
|
|
83
|
+
* fail to convert are logged and dropped.
|
|
84
|
+
*/
|
|
85
|
+
function requestLinksToTemporalLinks(ctx) {
|
|
86
|
+
const links = Array();
|
|
87
|
+
if (ctx.inboundLinks?.length > 0) {
|
|
88
|
+
for (const l of ctx.inboundLinks) {
|
|
89
|
+
try {
|
|
90
|
+
links.push((0, link_converter_1.convertNexusLinkToTemporalLink)(l));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
context_1.log.warn('failed to convert Nexus link to Workflow event link', { error });
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
}
|
|
97
|
+
return links;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Pushes a response link returned by an outbound Workflow RPC onto the operation's outbound links so
|
|
101
|
+
* the Nexus task handler attaches it to the StartOperationResponse, linking the caller Workflow's
|
|
102
|
+
* NexusOperation history event back to the callee Workflow's event. Callers only invoke this when the
|
|
103
|
+
* server returned a response link; older servers (or CHASM signal response links disabled) leave it
|
|
104
|
+
* unset, in which case there is nothing to push.
|
|
105
|
+
*/
|
|
106
|
+
function pushResponseLink(ctx, responseLink) {
|
|
107
|
+
try {
|
|
108
|
+
ctx.outboundLinks.push((0, link_converter_1.convertTemporalLinkToNexusLink)(responseLink));
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
context_1.log.warn('failed to convert temporal link to Nexus link', { error });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function createWorkflowHandle(ctx, workflowId, runId) {
|
|
115
|
+
return {
|
|
116
|
+
workflowId,
|
|
117
|
+
runId,
|
|
118
|
+
async signal(def, ...args) {
|
|
119
|
+
const { client } = (0, context_1.getHandlerContext)();
|
|
120
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
121
|
+
// Signal through a regular WorkflowHandle rather than a dedicated client method, so the Nexus
|
|
122
|
+
// link-forwarding plumbing stays off the public WorkflowClient surface. We attach the request
|
|
123
|
+
// links to the handle via the SDK-internal symbol; the signal handler reads them and writes the
|
|
124
|
+
// server's response link back onto the same payload.
|
|
125
|
+
const handle = client.workflow.getHandle(this.workflowId, this.runId);
|
|
126
|
+
const internalOptions = {
|
|
127
|
+
links,
|
|
128
|
+
};
|
|
129
|
+
handle[internal_1.InternalWorkflowSignalOptionsSymbol] = internalOptions;
|
|
130
|
+
await handle.signal(def, ...args);
|
|
131
|
+
if (internalOptions.responseLink != null) {
|
|
132
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Signals a Workflow, starting it first if it is not already running, as part of a Nexus Operation.
|
|
139
|
+
*
|
|
140
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
141
|
+
*/
|
|
142
|
+
async function signalWithStartWorkflow(ctx, workflowTypeOrFunc, workflowOptions) {
|
|
143
|
+
const { client, taskQueue } = (0, context_1.getHandlerContext)();
|
|
144
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
145
|
+
const internalOptions = {
|
|
146
|
+
links,
|
|
147
|
+
};
|
|
148
|
+
const { taskQueue: userSpecifiedTaskQueue, ...rest } = workflowOptions;
|
|
149
|
+
const signalWithStartOptions = {
|
|
150
|
+
...rest,
|
|
151
|
+
taskQueue: userSpecifiedTaskQueue || taskQueue,
|
|
152
|
+
[internal_1.InternalWorkflowStartOptionsSymbol]: internalOptions,
|
|
153
|
+
};
|
|
154
|
+
const handle = await client.workflow.signalWithStart(workflowTypeOrFunc, signalWithStartOptions);
|
|
155
|
+
if (internalOptions.responseLink != null) {
|
|
156
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
157
|
+
}
|
|
92
158
|
return {
|
|
93
159
|
workflowId: handle.workflowId,
|
|
94
|
-
runId: handle.
|
|
160
|
+
runId: handle.signaledRunId,
|
|
95
161
|
};
|
|
96
162
|
}
|
|
97
163
|
/**
|
|
@@ -145,6 +211,22 @@ class TemporalNexusClientImpl {
|
|
|
145
211
|
get client() {
|
|
146
212
|
return (0, context_1.getClient)();
|
|
147
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Create a Nexus-aware handle to an existing Workflow.
|
|
216
|
+
*
|
|
217
|
+
* - If only `workflowId` is passed, and there are multiple Workflow Executions with that ID, the handle will refer to
|
|
218
|
+
* the most recent one.
|
|
219
|
+
* - If `workflowId` and `runId` are passed, the handle will refer to the specific Workflow Execution with that Run
|
|
220
|
+
* ID.
|
|
221
|
+
*
|
|
222
|
+
* This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
|
|
223
|
+
* methods like `handle.signal()` will throw a {@link WorkflowNotFoundError} error.
|
|
224
|
+
*
|
|
225
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
226
|
+
*/
|
|
227
|
+
getWorkflowHandle(workflowId, runId) {
|
|
228
|
+
return createWorkflowHandle(this.startOperationContext, workflowId, runId);
|
|
229
|
+
}
|
|
148
230
|
/**
|
|
149
231
|
* Starts a workflow run as the asynchronous backing operation for the current Nexus Operation.
|
|
150
232
|
*
|
|
@@ -157,6 +239,14 @@ class TemporalNexusClientImpl {
|
|
|
157
239
|
return exports.TemporalOperationResult.async((0, token_1.generateWorkflowRunOperationToken)(namespace, handle.workflowId));
|
|
158
240
|
});
|
|
159
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Signals a Workflow, starting it first if it is not already running.
|
|
244
|
+
*
|
|
245
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
246
|
+
*/
|
|
247
|
+
async signalWithStartWorkflow(workflowTypeOrFunc, workflowOptions) {
|
|
248
|
+
await signalWithStartWorkflow(this.startOperationContext, workflowTypeOrFunc, workflowOptions);
|
|
249
|
+
}
|
|
160
250
|
async withAsyncOperationStartReservation(fn) {
|
|
161
251
|
if (this.asyncOperationStarted) {
|
|
162
252
|
throw new nexus.HandlerError('BAD_REQUEST', 'Only one async operation can be started per operation handler invocation. Use TemporalNexusClient.client for additional workflow interactions');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-helpers.js","sourceRoot":"","sources":["../src/workflow-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"workflow-helpers.js","sourceRoot":"","sources":["../src/workflow-helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,sCA+CC;AAqFD,0DA2BC;AAhQD,iDAAmC;AAcnC,8DAGyC;AACzC,qDAAkG;AAClG,mCAMiB;AACjB,uCAMmB;AAyDnB;;;;;;;GAOG;AACI,KAAK,UAAU,aAAa,CACjC,GAAgC,EAChC,kBAA8B,EAC9B,eAAwC;IAExC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,2BAAiB,GAAE,CAAC;IAClD,MAAM,KAAK,GAAG,2BAA2B,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,eAAe,GAA4E;QAC/F,KAAK;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;IACH,CAAC;CACF;AAxCD,4DAwCC;AAED,KAAK,UAAU,wBAAwB,CAAC,IAAoC,EAAE,OAAiC;IAC7G,MAAM,IAAA,mBAAS,GAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,CAAC;AACpE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/nexus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Temporal.io SDK Nexus sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"long": "^5.2.3",
|
|
22
22
|
"nexus-rpc": "^0.0.2",
|
|
23
|
-
"@temporalio/client": "1.
|
|
24
|
-
"@temporalio/common": "1.
|
|
25
|
-
"@temporalio/proto": "1.
|
|
23
|
+
"@temporalio/client": "1.19.0",
|
|
24
|
+
"@temporalio/common": "1.19.0",
|
|
25
|
+
"@temporalio/proto": "1.19.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"ava": "^5.3.1"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
|
-
"node": ">= 20.
|
|
43
|
+
"node": ">= 20.3.0"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"src",
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export {
|
|
|
17
17
|
|
|
18
18
|
export {
|
|
19
19
|
startWorkflow,
|
|
20
|
+
signalWithStartWorkflow,
|
|
20
21
|
type CancelWorkflowRunOptions,
|
|
21
22
|
type TemporalOperationHandlerOptions,
|
|
22
23
|
TemporalOperationHandler,
|
|
@@ -27,4 +28,5 @@ export {
|
|
|
27
28
|
WorkflowRunOperationHandler,
|
|
28
29
|
WorkflowRunOperationStartHandler,
|
|
29
30
|
WorkflowStartOptions,
|
|
31
|
+
WorkflowSignalWithStartOptions,
|
|
30
32
|
} from './workflow-helpers';
|
package/src/link-converter.ts
CHANGED
|
@@ -13,7 +13,6 @@ const LINK_EVENT_ID_PARAM = 'eventID';
|
|
|
13
13
|
const LINK_EVENT_TYPE_PARAM = 'eventType';
|
|
14
14
|
const LINK_REQUEST_ID_PARAM = 'requestID';
|
|
15
15
|
const LINK_REFERENCE_TYPE_KEY = 'referenceType';
|
|
16
|
-
const LINK_RUN_ID_KEY = 'runID';
|
|
17
16
|
|
|
18
17
|
const EVENT_REFERENCE_TYPE = 'EventReference';
|
|
19
18
|
const REQUEST_ID_REFERENCE_TYPE = 'RequestIdReference';
|
|
@@ -77,22 +76,16 @@ export function convertWorkflowEventLinkToNexusLink(we: WorkflowEventLink): Nexu
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
export function convertNexusOperationLinkToNexusLink(opLink: NexusOperationLink): NexusLink {
|
|
80
|
-
if (!opLink.namespace || !opLink.operationId) {
|
|
81
|
-
throw new TypeError('Missing required fields: namespace, or
|
|
79
|
+
if (!opLink.namespace || !opLink.operationId || !opLink.runId) {
|
|
80
|
+
throw new TypeError('Missing required fields: namespace, operationId, or runId');
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
const url = new URL(
|
|
85
84
|
`temporal:///namespaces/${encodeURIComponent(opLink.namespace)}/nexus-operations/${encodeURIComponent(
|
|
86
85
|
opLink.operationId
|
|
87
|
-
)}`
|
|
86
|
+
)}/${encodeURIComponent(opLink.runId)}/details`
|
|
88
87
|
);
|
|
89
88
|
|
|
90
|
-
if (opLink.runId != null) {
|
|
91
|
-
const searchParams = new URLSearchParams();
|
|
92
|
-
searchParams.set(LINK_RUN_ID_KEY, opLink.runId);
|
|
93
|
-
url.search = searchParams.toString();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
89
|
return {
|
|
97
90
|
url,
|
|
98
91
|
type: NEXUS_OPERATION_TYPE,
|
|
@@ -132,16 +125,18 @@ export function convertNexusLinkToWorkflowEventLink(link: NexusLink): WorkflowEv
|
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
function convertNexusLinkToNexusOperationLink(link: NexusLink): NexusOperationLink {
|
|
135
|
-
// /namespaces/:namespace/nexus-operations/:operationId
|
|
128
|
+
// /namespaces/:namespace/nexus-operations/:operationId/:runId/details
|
|
136
129
|
const parts = link.url.pathname.split('/');
|
|
137
|
-
if (parts.length !==
|
|
130
|
+
if (parts.length !== 7 || parts[1] !== 'namespaces' || parts[3] !== 'nexus-operations' || parts[6] !== 'details') {
|
|
138
131
|
throw new TypeError(`Invalid URL path: ${link.url}`);
|
|
139
132
|
}
|
|
140
133
|
const namespace = decodeURIComponent(parts[2]!);
|
|
141
134
|
const operationId = decodeURIComponent(parts[4]!);
|
|
135
|
+
const runId = decodeURIComponent(parts[5]!);
|
|
142
136
|
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
if (!namespace || !operationId || !runId) {
|
|
138
|
+
throw new TypeError('Missing required fields: namespace, operationId, or runId');
|
|
139
|
+
}
|
|
145
140
|
|
|
146
141
|
return {
|
|
147
142
|
namespace,
|
package/src/workflow-helpers.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import * as nexus from 'nexus-rpc';
|
|
2
|
-
import type { Workflow, WorkflowResultType } from '@temporalio/common';
|
|
2
|
+
import type { Workflow, WorkflowResultType, WithWorkflowArgs, SignalDefinition } from '@temporalio/common';
|
|
3
3
|
import type { Replace } from '@temporalio/common/lib/type-helpers';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
Client,
|
|
6
|
+
WorkflowStartOptions as ClientWorkflowStartOptions,
|
|
7
|
+
WorkflowSignalWithStartOptions as ClientWorkflowSignalWithStartOptions,
|
|
8
|
+
} from '@temporalio/client';
|
|
5
9
|
import { type temporal } from '@temporalio/proto';
|
|
6
|
-
import type {
|
|
7
|
-
|
|
10
|
+
import type {
|
|
11
|
+
InternalWorkflowHandle,
|
|
12
|
+
InternalWorkflowSignalOptions,
|
|
13
|
+
InternalWorkflowStartOptions,
|
|
14
|
+
} from '@temporalio/client/lib/internal';
|
|
15
|
+
import {
|
|
16
|
+
InternalWorkflowSignalOptionsSymbol,
|
|
17
|
+
InternalWorkflowStartOptionsSymbol,
|
|
18
|
+
} from '@temporalio/client/lib/internal';
|
|
8
19
|
import { convertNexusLinkToTemporalLink, convertTemporalLinkToNexusLink } from './link-converter';
|
|
9
20
|
import {
|
|
10
21
|
assertWorkflowRunOperationToken,
|
|
@@ -36,7 +47,12 @@ declare const workflowResultType: unique symbol;
|
|
|
36
47
|
*/
|
|
37
48
|
export interface WorkflowHandle<T> {
|
|
38
49
|
readonly workflowId: string;
|
|
39
|
-
readonly runId
|
|
50
|
+
readonly runId?: string;
|
|
51
|
+
|
|
52
|
+
signal<Args extends any[] = [], Name extends string = string>(
|
|
53
|
+
def: SignalDefinition<Args, Name> | string,
|
|
54
|
+
...args: Args
|
|
55
|
+
): Promise<void>;
|
|
40
56
|
|
|
41
57
|
/**
|
|
42
58
|
* Virtual type brand to maintain a distinction between {@link WorkflowHandle} provided by the
|
|
@@ -74,7 +90,7 @@ export type WorkflowStartOptions<T extends Workflow> = Replace<ClientWorkflowSta
|
|
|
74
90
|
/**
|
|
75
91
|
* Starts a workflow run for a {@link WorkflowRunOperationStartHandler}, linking the execution chain
|
|
76
92
|
* to a Nexus Operation (subsequent runs started from continue-as-new and retries). Automatically
|
|
77
|
-
* propagates the callback, request ID, and
|
|
93
|
+
* propagates the callback, request ID, and request and response links from the Nexus options to the
|
|
78
94
|
* Workflow.
|
|
79
95
|
*
|
|
80
96
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
@@ -85,16 +101,7 @@ export async function startWorkflow<T extends Workflow>(
|
|
|
85
101
|
workflowOptions: WorkflowStartOptions<T>
|
|
86
102
|
): Promise<WorkflowHandle<WorkflowResultType<T>>> {
|
|
87
103
|
const { client, taskQueue } = getHandlerContext();
|
|
88
|
-
const links =
|
|
89
|
-
if (ctx.inboundLinks?.length > 0) {
|
|
90
|
-
for (const l of ctx.inboundLinks) {
|
|
91
|
-
try {
|
|
92
|
-
links.push(convertNexusLinkToTemporalLink(l));
|
|
93
|
-
} catch (error) {
|
|
94
|
-
log.warn('failed to convert Nexus link to Workflow event link', { error });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
104
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
98
105
|
const internalOptions: InternalWorkflowStartOptions[typeof InternalWorkflowStartOptionsSymbol] = {
|
|
99
106
|
links,
|
|
100
107
|
requestId: ctx.requestId,
|
|
@@ -130,17 +137,122 @@ export async function startWorkflow<T extends Workflow>(
|
|
|
130
137
|
};
|
|
131
138
|
|
|
132
139
|
const handle = await client.workflow.start(workflowTypeOrFunc, startOptions);
|
|
133
|
-
if (internalOptions.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
if (internalOptions.responseLink != null) {
|
|
141
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return createWorkflowHandle(ctx, handle.workflowId, handle.firstExecutionRunId);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Converts the request links carried on the operation start context into Temporal links so
|
|
149
|
+
* they can be forwarded onto an outgoing Workflow RPC (signal, signalWithStart, start). Links that
|
|
150
|
+
* fail to convert are logged and dropped.
|
|
151
|
+
*/
|
|
152
|
+
function requestLinksToTemporalLinks(ctx: nexus.StartOperationContext): temporal.api.common.v1.ILink[] {
|
|
153
|
+
const links = Array<temporal.api.common.v1.ILink>();
|
|
154
|
+
if (ctx.inboundLinks?.length > 0) {
|
|
155
|
+
for (const l of ctx.inboundLinks) {
|
|
156
|
+
try {
|
|
157
|
+
links.push(convertNexusLinkToTemporalLink(l));
|
|
158
|
+
} catch (error) {
|
|
159
|
+
log.warn('failed to convert Nexus link to Workflow event link', { error });
|
|
160
|
+
}
|
|
138
161
|
}
|
|
139
162
|
}
|
|
163
|
+
return links;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Pushes a response link returned by an outbound Workflow RPC onto the operation's outbound links so
|
|
168
|
+
* the Nexus task handler attaches it to the StartOperationResponse, linking the caller Workflow's
|
|
169
|
+
* NexusOperation history event back to the callee Workflow's event. Callers only invoke this when the
|
|
170
|
+
* server returned a response link; older servers (or CHASM signal response links disabled) leave it
|
|
171
|
+
* unset, in which case there is nothing to push.
|
|
172
|
+
*/
|
|
173
|
+
function pushResponseLink(ctx: nexus.StartOperationContext, responseLink: temporal.api.common.v1.ILink) {
|
|
174
|
+
try {
|
|
175
|
+
ctx.outboundLinks.push(convertTemporalLinkToNexusLink(responseLink));
|
|
176
|
+
} catch (error) {
|
|
177
|
+
log.warn('failed to convert temporal link to Nexus link', { error });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function createWorkflowHandle<T extends Workflow>(
|
|
182
|
+
ctx: nexus.StartOperationContext,
|
|
183
|
+
workflowId: string,
|
|
184
|
+
runId?: string
|
|
185
|
+
): WorkflowHandle<WorkflowResultType<T>> {
|
|
186
|
+
return {
|
|
187
|
+
workflowId,
|
|
188
|
+
runId,
|
|
189
|
+
|
|
190
|
+
async signal<Args extends any[] = [], Name extends string = string>(
|
|
191
|
+
def: SignalDefinition<Args, Name> | string,
|
|
192
|
+
...args: Args
|
|
193
|
+
): Promise<void> {
|
|
194
|
+
const { client } = getHandlerContext();
|
|
195
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
196
|
+
|
|
197
|
+
// Signal through a regular WorkflowHandle rather than a dedicated client method, so the Nexus
|
|
198
|
+
// link-forwarding plumbing stays off the public WorkflowClient surface. We attach the request
|
|
199
|
+
// links to the handle via the SDK-internal symbol; the signal handler reads them and writes the
|
|
200
|
+
// server's response link back onto the same payload.
|
|
201
|
+
const handle = client.workflow.getHandle(this.workflowId, this.runId) as InternalWorkflowHandle;
|
|
202
|
+
const internalOptions: InternalWorkflowSignalOptions[typeof InternalWorkflowSignalOptionsSymbol] = {
|
|
203
|
+
links,
|
|
204
|
+
};
|
|
205
|
+
handle[InternalWorkflowSignalOptionsSymbol] = internalOptions;
|
|
206
|
+
await handle.signal(def, ...args);
|
|
207
|
+
if (internalOptions.responseLink != null) {
|
|
208
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
} as WorkflowHandle<WorkflowResultType<T>>;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Options for {@link signalWithStartWorkflow}, identical to the client's `WorkflowSignalWithStartOptions`
|
|
216
|
+
* except that `taskQueue` is optional and defaults to the current worker's task queue.
|
|
217
|
+
*
|
|
218
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
219
|
+
*/
|
|
220
|
+
export type WorkflowSignalWithStartOptions<SignalArgs extends any[] = []> = Replace<
|
|
221
|
+
ClientWorkflowSignalWithStartOptions<SignalArgs>,
|
|
222
|
+
{ taskQueue?: string }
|
|
223
|
+
>;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Signals a Workflow, starting it first if it is not already running, as part of a Nexus Operation.
|
|
227
|
+
*
|
|
228
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
229
|
+
*/
|
|
230
|
+
export async function signalWithStartWorkflow<T extends Workflow, SignalArgs extends any[] = []>(
|
|
231
|
+
ctx: nexus.StartOperationContext,
|
|
232
|
+
workflowTypeOrFunc: string | T,
|
|
233
|
+
workflowOptions: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SignalArgs>>
|
|
234
|
+
): Promise<WorkflowHandle<WorkflowResultType<T>>> {
|
|
235
|
+
const { client, taskQueue } = getHandlerContext();
|
|
236
|
+
const links = requestLinksToTemporalLinks(ctx);
|
|
237
|
+
const internalOptions: InternalWorkflowStartOptions[typeof InternalWorkflowStartOptionsSymbol] = {
|
|
238
|
+
links,
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const { taskQueue: userSpecifiedTaskQueue, ...rest } = workflowOptions;
|
|
242
|
+
const signalWithStartOptions = {
|
|
243
|
+
...rest,
|
|
244
|
+
taskQueue: userSpecifiedTaskQueue || taskQueue,
|
|
245
|
+
[InternalWorkflowStartOptionsSymbol]: internalOptions,
|
|
246
|
+
} as unknown as WithWorkflowArgs<T, ClientWorkflowSignalWithStartOptions<SignalArgs>>;
|
|
247
|
+
|
|
248
|
+
const handle = await client.workflow.signalWithStart(workflowTypeOrFunc, signalWithStartOptions);
|
|
249
|
+
if (internalOptions.responseLink != null) {
|
|
250
|
+
pushResponseLink(ctx, internalOptions.responseLink);
|
|
251
|
+
}
|
|
140
252
|
|
|
141
253
|
return {
|
|
142
254
|
workflowId: handle.workflowId,
|
|
143
|
-
runId: handle.
|
|
255
|
+
runId: handle.signaledRunId,
|
|
144
256
|
} as WorkflowHandle<WorkflowResultType<T>>;
|
|
145
257
|
}
|
|
146
258
|
|
|
@@ -225,6 +337,32 @@ export interface TemporalNexusClient {
|
|
|
225
337
|
workflowTypeOrFunc: string | T,
|
|
226
338
|
workflowOptions: WorkflowStartOptions<T>
|
|
227
339
|
): Promise<TemporalOperationResult<WorkflowResultType<T>>>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Create a Nexus-aware handle to an existing Workflow.
|
|
343
|
+
*
|
|
344
|
+
* - If only `workflowId` is passed, and there are multiple Workflow Executions with that ID, the handle will refer to
|
|
345
|
+
* the most recent one.
|
|
346
|
+
* - If `workflowId` and `runId` are passed, the handle will refer to the specific Workflow Execution with that Run
|
|
347
|
+
* ID.
|
|
348
|
+
*
|
|
349
|
+
* This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
|
|
350
|
+
* methods like `handle.signal()` will throw a {@link WorkflowNotFoundError} error.
|
|
351
|
+
*
|
|
352
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
353
|
+
*/
|
|
354
|
+
getWorkflowHandle<T extends Workflow>(workflowId: string, runId?: string): WorkflowHandle<WorkflowResultType<T>>;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Signals a Workflow, starting it first if it is not already running, forwarding the Nexus
|
|
358
|
+
* Operation's request links and propagating the response link the server returns (when supported).
|
|
359
|
+
*
|
|
360
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
361
|
+
*/
|
|
362
|
+
signalWithStartWorkflow<T extends Workflow, SignalArgs extends any[] = []>(
|
|
363
|
+
workflowTypeOrFunc: string | T,
|
|
364
|
+
workflowOptions: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SignalArgs>>
|
|
365
|
+
): Promise<void>;
|
|
228
366
|
}
|
|
229
367
|
|
|
230
368
|
class TemporalNexusClientImpl implements TemporalNexusClient {
|
|
@@ -241,6 +379,26 @@ class TemporalNexusClientImpl implements TemporalNexusClient {
|
|
|
241
379
|
return getClient();
|
|
242
380
|
}
|
|
243
381
|
|
|
382
|
+
/**
|
|
383
|
+
* Create a Nexus-aware handle to an existing Workflow.
|
|
384
|
+
*
|
|
385
|
+
* - If only `workflowId` is passed, and there are multiple Workflow Executions with that ID, the handle will refer to
|
|
386
|
+
* the most recent one.
|
|
387
|
+
* - If `workflowId` and `runId` are passed, the handle will refer to the specific Workflow Execution with that Run
|
|
388
|
+
* ID.
|
|
389
|
+
*
|
|
390
|
+
* This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
|
|
391
|
+
* methods like `handle.signal()` will throw a {@link WorkflowNotFoundError} error.
|
|
392
|
+
*
|
|
393
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
394
|
+
*/
|
|
395
|
+
public getWorkflowHandle<T extends Workflow>(
|
|
396
|
+
workflowId: string,
|
|
397
|
+
runId?: string
|
|
398
|
+
): WorkflowHandle<WorkflowResultType<T>> {
|
|
399
|
+
return createWorkflowHandle(this.startOperationContext, workflowId, runId);
|
|
400
|
+
}
|
|
401
|
+
|
|
244
402
|
/**
|
|
245
403
|
* Starts a workflow run as the asynchronous backing operation for the current Nexus Operation.
|
|
246
404
|
*
|
|
@@ -257,6 +415,18 @@ class TemporalNexusClientImpl implements TemporalNexusClient {
|
|
|
257
415
|
});
|
|
258
416
|
}
|
|
259
417
|
|
|
418
|
+
/**
|
|
419
|
+
* Signals a Workflow, starting it first if it is not already running.
|
|
420
|
+
*
|
|
421
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
422
|
+
*/
|
|
423
|
+
public async signalWithStartWorkflow<T extends Workflow, SignalArgs extends any[] = []>(
|
|
424
|
+
workflowTypeOrFunc: string | T,
|
|
425
|
+
workflowOptions: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SignalArgs>>
|
|
426
|
+
): Promise<void> {
|
|
427
|
+
await signalWithStartWorkflow(this.startOperationContext, workflowTypeOrFunc, workflowOptions);
|
|
428
|
+
}
|
|
429
|
+
|
|
260
430
|
private async withAsyncOperationStartReservation<T>(fn: () => Promise<T>): Promise<T> {
|
|
261
431
|
if (this.asyncOperationStarted) {
|
|
262
432
|
throw new nexus.HandlerError(
|