@temporalio/nexus 1.14.2-canary-release-testing.0 → 1.16.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/context.d.ts +23 -0
- package/lib/context.js +15 -0
- package/lib/context.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/token.d.ts +3 -4
- package/lib/token.js.map +1 -1
- package/lib/workflow-helpers.d.ts +18 -5
- package/lib/workflow-helpers.js +0 -8
- package/lib/workflow-helpers.js.map +1 -1
- package/package.json +6 -6
- package/src/context.ts +32 -0
- package/src/index.ts +2 -0
- package/src/token.ts +3 -5
- package/src/workflow-helpers.ts +20 -14
package/lib/context.d.ts
CHANGED
|
@@ -16,6 +16,21 @@ export interface HandlerContext {
|
|
|
16
16
|
namespace: string;
|
|
17
17
|
taskQueue: string;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds information about the current Nexus Operation Execution.
|
|
21
|
+
*
|
|
22
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
23
|
+
*/
|
|
24
|
+
export interface OperationInfo {
|
|
25
|
+
/**
|
|
26
|
+
* Namespace this Nexus Operation is executing in
|
|
27
|
+
*/
|
|
28
|
+
readonly namespace: string;
|
|
29
|
+
/**
|
|
30
|
+
* Task Queue this Nexus Operation is executing on
|
|
31
|
+
*/
|
|
32
|
+
readonly taskQueue: string;
|
|
33
|
+
}
|
|
19
34
|
/**
|
|
20
35
|
* A logger for use in Nexus Handler scope.
|
|
21
36
|
*
|
|
@@ -46,3 +61,11 @@ export declare const metricMeter: MetricMeter;
|
|
|
46
61
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
47
62
|
*/
|
|
48
63
|
export declare function getClient(): Client;
|
|
64
|
+
/**
|
|
65
|
+
* Get information about the current Nexus Operation.
|
|
66
|
+
*
|
|
67
|
+
* @return OperationInfo for the current Nexus Operation being executed
|
|
68
|
+
*
|
|
69
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
70
|
+
*/
|
|
71
|
+
export declare function operationInfo(): OperationInfo;
|
package/lib/context.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.metricMeter = exports.log = exports.asyncLocalStorage = void 0;
|
|
4
4
|
exports.getHandlerContext = getHandlerContext;
|
|
5
5
|
exports.getClient = getClient;
|
|
6
|
+
exports.operationInfo = operationInfo;
|
|
6
7
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
7
8
|
// Context Storage /////////////////////////////////////////////////////////////////////////////////
|
|
8
9
|
// Make it safe to use @temporalio/nexus with multiple versions installed.
|
|
@@ -83,4 +84,18 @@ exports.metricMeter = {
|
|
|
83
84
|
function getClient() {
|
|
84
85
|
return getHandlerContext().client;
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Get information about the current Nexus Operation.
|
|
89
|
+
*
|
|
90
|
+
* @return OperationInfo for the current Nexus Operation being executed
|
|
91
|
+
*
|
|
92
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
93
|
+
*/
|
|
94
|
+
function operationInfo() {
|
|
95
|
+
const ctx = getHandlerContext();
|
|
96
|
+
return {
|
|
97
|
+
namespace: ctx.namespace,
|
|
98
|
+
taskQueue: ctx.taskQueue,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
86
101
|
//# sourceMappingURL=context.js.map
|
package/lib/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAaA,8CAMC;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":";;;AAaA,8CAMC;AAkGD,8BAEC;AASD,sCAMC;AAtID,uDAAqD;AAIrD,oGAAoG;AAEpG,0EAA0E;AAC1E,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG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Client, metricMeter, } from './context';
|
|
6
|
+
export { log, getClient, metricMeter, operationInfo, type OperationInfo, } from './context';
|
|
7
7
|
export { startWorkflow, WorkflowHandle, WorkflowRunOperationHandler, WorkflowRunOperationStartHandler, WorkflowStartOptions, } from './workflow-helpers';
|
package/lib/index.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.WorkflowRunOperationHandler = exports.startWorkflow = exports.metricMeter = exports.getClient = exports.log = void 0;
|
|
8
|
+
exports.WorkflowRunOperationHandler = 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; } });
|
|
12
12
|
Object.defineProperty(exports, "getClient", { enumerable: true, get: function () { return context_1.getClient; } });
|
|
13
13
|
Object.defineProperty(exports, "metricMeter", { enumerable: true, get: function () { return context_1.metricMeter; } });
|
|
14
|
+
Object.defineProperty(exports, "operationInfo", { enumerable: true, get: function () { return context_1.operationInfo; } });
|
|
14
15
|
var workflow_helpers_1 = require("./workflow-helpers");
|
|
15
16
|
Object.defineProperty(exports, "startWorkflow", { enumerable: true, get: function () { return workflow_helpers_1.startWorkflow; } });
|
|
16
17
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAOmB;AANjB,EAAE;AACF,8FAAA,GAAG,OAAA;AACH,oGAAA,SAAS,OAAA;AACT,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AAIf,uDAM4B;AAL1B,iHAAA,aAAa,OAAA;AAEb,+HAAA,2BAA2B,OAAA"}
|
package/lib/token.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* OperationTokenType is used to identify the type of Operation token.
|
|
3
|
+
* Currently, we only have one type of Operation token: WorkflowRun.
|
|
4
|
+
*
|
|
2
5
|
* @internal
|
|
3
6
|
* @hidden
|
|
4
7
|
*/
|
|
@@ -21,10 +24,6 @@ export interface WorkflowRunOperationToken {
|
|
|
21
24
|
*/
|
|
22
25
|
wid: string;
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
25
|
-
* OperationTokenType is used to identify the type of Operation token.
|
|
26
|
-
* Currently, we only have one type of Operation token: WorkflowRun.
|
|
27
|
-
*/
|
|
28
27
|
type OperationTokenType = (typeof OperationTokenType)[keyof typeof OperationTokenType];
|
|
29
28
|
/**
|
|
30
29
|
* @internal
|
package/lib/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":";;AA0CA,8EAOC;AAKD,sEA8BC;AAGD,4DAGC;AA3DD;;;GAGG;AACH,MAAM,kBAAkB,GAAG;IACzB,YAAY,EAAE,CAAC;CACP,CAAC;AAEX;;GAEG;AACH,SAAgB,iCAAiC,CAAC,SAAiB,EAAE,UAAkB;IACrF,MAAM,KAAK,GAA8B;QACvC,CAAC,EAAE,kBAAkB,CAAC,YAAY;QAClC,EAAE,EAAE,SAAS;QACb,GAAG,EAAE,UAAU;KAChB,CAAC;IACF,OAAO,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;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,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,wBAAwB,CAAC,GAAW;IAC3C,+DAA+D;IAC/D,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,+DAA+D,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IACrC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import * as nexus from 'nexus-rpc';
|
|
2
|
-
import { Workflow } from '@temporalio/common';
|
|
2
|
+
import { Workflow, WorkflowResultType } from '@temporalio/common';
|
|
3
3
|
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
4
4
|
import { WorkflowStartOptions as ClientWorkflowStartOptions } from '@temporalio/client';
|
|
5
5
|
declare const isNexusWorkflowHandle: unique symbol;
|
|
6
|
+
declare const workflowResultType: unique symbol;
|
|
6
7
|
/**
|
|
7
8
|
* A handle to a running workflow that is returned by the {@link startWorkflow} helper.
|
|
8
9
|
* This handle should be returned by {@link WorkflowRunOperationStartHandler} implementations.
|
|
9
10
|
*
|
|
11
|
+
* The type parameter `T` carries the workflow's result type for downstream type inference in
|
|
12
|
+
* {@link WorkflowRunOperationHandler}. It is encoded in the {@link workflowResultType} brand so
|
|
13
|
+
* that `WorkflowHandle<string>` and `WorkflowHandle<number>` are structurally distinct.
|
|
14
|
+
*
|
|
10
15
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
11
16
|
*/
|
|
12
|
-
export interface WorkflowHandle<
|
|
17
|
+
export interface WorkflowHandle<T> {
|
|
13
18
|
readonly workflowId: string;
|
|
14
19
|
readonly runId: string;
|
|
15
20
|
/**
|
|
@@ -23,6 +28,16 @@ export interface WorkflowHandle<_T> {
|
|
|
23
28
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
24
29
|
*/
|
|
25
30
|
readonly [isNexusWorkflowHandle]: typeof isNexusWorkflowHandle;
|
|
31
|
+
/**
|
|
32
|
+
* Type brand that carries the workflow's result type, making `WorkflowHandle<X>` structurally
|
|
33
|
+
* distinct from `WorkflowHandle<Y>` so TypeScript can catch type mismatches.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
* @hidden
|
|
37
|
+
*
|
|
38
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
39
|
+
*/
|
|
40
|
+
readonly [workflowResultType]: T;
|
|
26
41
|
}
|
|
27
42
|
/**
|
|
28
43
|
* Options for starting a workflow using {@link startWorkflow}, this type is identical to the
|
|
@@ -42,7 +57,7 @@ export type WorkflowStartOptions<T extends Workflow> = Replace<ClientWorkflowSta
|
|
|
42
57
|
*
|
|
43
58
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
44
59
|
*/
|
|
45
|
-
export declare function startWorkflow<T extends Workflow>(ctx: nexus.StartOperationContext, workflowTypeOrFunc: string | T, workflowOptions: WorkflowStartOptions<T>): Promise<WorkflowHandle<T
|
|
60
|
+
export declare function startWorkflow<T extends Workflow>(ctx: nexus.StartOperationContext, workflowTypeOrFunc: string | T, workflowOptions: WorkflowStartOptions<T>): Promise<WorkflowHandle<WorkflowResultType<T>>>;
|
|
46
61
|
/**
|
|
47
62
|
* A handler function for the {@link WorkflowRunOperationHandler} constructor.
|
|
48
63
|
*
|
|
@@ -58,8 +73,6 @@ export declare class WorkflowRunOperationHandler<I, O> implements nexus.Operatio
|
|
|
58
73
|
readonly handler: WorkflowRunOperationStartHandler<I, O>;
|
|
59
74
|
constructor(handler: WorkflowRunOperationStartHandler<I, O>);
|
|
60
75
|
start(ctx: nexus.StartOperationContext, input: I): Promise<nexus.HandlerStartOperationResult<O>>;
|
|
61
|
-
getInfo(_ctx: nexus.GetOperationInfoContext, _token: string): Promise<nexus.OperationInfo>;
|
|
62
|
-
getResult(_ctx: nexus.GetOperationResultContext, _token: string): Promise<O>;
|
|
63
76
|
cancel(_ctx: nexus.CancelOperationContext, token: string): Promise<void>;
|
|
64
77
|
}
|
|
65
78
|
export {};
|
package/lib/workflow-helpers.js
CHANGED
|
@@ -105,14 +105,6 @@ class WorkflowRunOperationHandler {
|
|
|
105
105
|
const handle = await this.handler(ctx, input);
|
|
106
106
|
return nexus.HandlerStartOperationResult.async((0, token_1.generateWorkflowRunOperationToken)(namespace, handle.workflowId));
|
|
107
107
|
}
|
|
108
|
-
getInfo(_ctx, _token) {
|
|
109
|
-
// Not implemented in Temporal yet.
|
|
110
|
-
throw new nexus.HandlerError('NOT_IMPLEMENTED', 'Method not implemented');
|
|
111
|
-
}
|
|
112
|
-
getResult(_ctx, _token) {
|
|
113
|
-
// Not implemented in Temporal yet.
|
|
114
|
-
throw new nexus.HandlerError('NOT_IMPLEMENTED', 'Method not implemented');
|
|
115
|
-
}
|
|
116
108
|
async cancel(_ctx, token) {
|
|
117
109
|
const decoded = (0, token_1.loadWorkflowRunOperationToken)(token);
|
|
118
110
|
await (0, context_1.getClient)().workflow.getHandle(decoded.wid).cancel();
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,sCA0DC;AA9HD,iDAAmC;AAKnC,8DAAmH;AACnH,mCAA2F;AAC3F,qDAA4G;AAC5G,uCAA8D;AAo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C;CACF;AAbD,kEAaC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/nexus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "Temporal.io SDK Nexus sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"long": "^5.2.3",
|
|
17
|
-
"nexus-rpc": "^0.0.
|
|
18
|
-
"@temporalio/client": "1.
|
|
19
|
-
"@temporalio/
|
|
20
|
-
"@temporalio/
|
|
17
|
+
"nexus-rpc": "^0.0.2",
|
|
18
|
+
"@temporalio/client": "1.16.0",
|
|
19
|
+
"@temporalio/proto": "1.16.0",
|
|
20
|
+
"@temporalio/common": "1.16.0"
|
|
21
21
|
},
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/temporalio/sdk-typescript/issues"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">= 20.0.0"
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"src",
|
package/src/context.ts
CHANGED
|
@@ -33,6 +33,23 @@ export interface HandlerContext {
|
|
|
33
33
|
taskQueue: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Holds information about the current Nexus Operation Execution.
|
|
38
|
+
*
|
|
39
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
40
|
+
*/
|
|
41
|
+
export interface OperationInfo {
|
|
42
|
+
/**
|
|
43
|
+
* Namespace this Nexus Operation is executing in
|
|
44
|
+
*/
|
|
45
|
+
readonly namespace: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Task Queue this Nexus Operation is executing on
|
|
49
|
+
*/
|
|
50
|
+
readonly taskQueue: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
36
53
|
// Basic APIs //////////////////////////////////////////////////////////////////////////////////////
|
|
37
54
|
|
|
38
55
|
/**
|
|
@@ -101,3 +118,18 @@ export const metricMeter: MetricMeter = {
|
|
|
101
118
|
export function getClient(): Client {
|
|
102
119
|
return getHandlerContext().client;
|
|
103
120
|
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get information about the current Nexus Operation.
|
|
124
|
+
*
|
|
125
|
+
* @return OperationInfo for the current Nexus Operation being executed
|
|
126
|
+
*
|
|
127
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
128
|
+
*/
|
|
129
|
+
export function operationInfo(): OperationInfo {
|
|
130
|
+
const ctx = getHandlerContext();
|
|
131
|
+
return {
|
|
132
|
+
namespace: ctx.namespace,
|
|
133
|
+
taskQueue: ctx.taskQueue,
|
|
134
|
+
};
|
|
135
|
+
}
|
package/src/index.ts
CHANGED
package/src/token.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* OperationTokenType is used to identify the type of Operation token.
|
|
3
|
+
* Currently, we only have one type of Operation token: WorkflowRun.
|
|
4
|
+
*
|
|
2
5
|
* @internal
|
|
3
6
|
* @hidden
|
|
4
7
|
*/
|
|
@@ -24,11 +27,6 @@ export interface WorkflowRunOperationToken {
|
|
|
24
27
|
*/
|
|
25
28
|
wid: string;
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* OperationTokenType is used to identify the type of Operation token.
|
|
30
|
-
* Currently, we only have one type of Operation token: WorkflowRun.
|
|
31
|
-
*/
|
|
32
30
|
type OperationTokenType = (typeof OperationTokenType)[keyof typeof OperationTokenType];
|
|
33
31
|
|
|
34
32
|
/**
|
package/src/workflow-helpers.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as nexus from 'nexus-rpc';
|
|
2
|
-
import { Workflow } from '@temporalio/common';
|
|
2
|
+
import { Workflow, WorkflowResultType } from '@temporalio/common';
|
|
3
3
|
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
4
4
|
import { WorkflowStartOptions as ClientWorkflowStartOptions } from '@temporalio/client';
|
|
5
5
|
import { type temporal } from '@temporalio/proto';
|
|
@@ -9,14 +9,19 @@ import { convertNexusLinkToWorkflowEventLink, convertWorkflowEventLinkToNexusLin
|
|
|
9
9
|
import { getClient, getHandlerContext, log } from './context';
|
|
10
10
|
|
|
11
11
|
declare const isNexusWorkflowHandle: unique symbol;
|
|
12
|
+
declare const workflowResultType: unique symbol;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A handle to a running workflow that is returned by the {@link startWorkflow} helper.
|
|
15
16
|
* This handle should be returned by {@link WorkflowRunOperationStartHandler} implementations.
|
|
16
17
|
*
|
|
18
|
+
* The type parameter `T` carries the workflow's result type for downstream type inference in
|
|
19
|
+
* {@link WorkflowRunOperationHandler}. It is encoded in the {@link workflowResultType} brand so
|
|
20
|
+
* that `WorkflowHandle<string>` and `WorkflowHandle<number>` are structurally distinct.
|
|
21
|
+
*
|
|
17
22
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
18
23
|
*/
|
|
19
|
-
export interface WorkflowHandle<
|
|
24
|
+
export interface WorkflowHandle<T> {
|
|
20
25
|
readonly workflowId: string;
|
|
21
26
|
readonly runId: string;
|
|
22
27
|
|
|
@@ -31,6 +36,17 @@ export interface WorkflowHandle<_T> {
|
|
|
31
36
|
* @experimental Nexus support in Temporal SDK is experimental.
|
|
32
37
|
*/
|
|
33
38
|
readonly [isNexusWorkflowHandle]: typeof isNexusWorkflowHandle;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Type brand that carries the workflow's result type, making `WorkflowHandle<X>` structurally
|
|
42
|
+
* distinct from `WorkflowHandle<Y>` so TypeScript can catch type mismatches.
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
* @hidden
|
|
46
|
+
*
|
|
47
|
+
* @experimental Nexus support in Temporal SDK is experimental.
|
|
48
|
+
*/
|
|
49
|
+
readonly [workflowResultType]: T;
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
/**
|
|
@@ -54,7 +70,7 @@ export async function startWorkflow<T extends Workflow>(
|
|
|
54
70
|
ctx: nexus.StartOperationContext,
|
|
55
71
|
workflowTypeOrFunc: string | T,
|
|
56
72
|
workflowOptions: WorkflowStartOptions<T>
|
|
57
|
-
): Promise<WorkflowHandle<T
|
|
73
|
+
): Promise<WorkflowHandle<WorkflowResultType<T>>> {
|
|
58
74
|
const { client, taskQueue } = getHandlerContext();
|
|
59
75
|
const links = Array<temporal.api.common.v1.ILink>();
|
|
60
76
|
if (ctx.inboundLinks?.length > 0) {
|
|
@@ -107,7 +123,7 @@ export async function startWorkflow<T extends Workflow>(
|
|
|
107
123
|
return {
|
|
108
124
|
workflowId: handle.workflowId,
|
|
109
125
|
runId: handle.firstExecutionRunId,
|
|
110
|
-
} as WorkflowHandle<T
|
|
126
|
+
} as WorkflowHandle<WorkflowResultType<T>>;
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
/**
|
|
@@ -134,16 +150,6 @@ export class WorkflowRunOperationHandler<I, O> implements nexus.OperationHandler
|
|
|
134
150
|
return nexus.HandlerStartOperationResult.async(generateWorkflowRunOperationToken(namespace, handle.workflowId));
|
|
135
151
|
}
|
|
136
152
|
|
|
137
|
-
getInfo(_ctx: nexus.GetOperationInfoContext, _token: string): Promise<nexus.OperationInfo> {
|
|
138
|
-
// Not implemented in Temporal yet.
|
|
139
|
-
throw new nexus.HandlerError('NOT_IMPLEMENTED', 'Method not implemented');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getResult(_ctx: nexus.GetOperationResultContext, _token: string): Promise<O> {
|
|
143
|
-
// Not implemented in Temporal yet.
|
|
144
|
-
throw new nexus.HandlerError('NOT_IMPLEMENTED', 'Method not implemented');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
153
|
async cancel(_ctx: nexus.CancelOperationContext, token: string): Promise<void> {
|
|
148
154
|
const decoded = loadWorkflowRunOperationToken(token);
|
|
149
155
|
await getClient().workflow.getHandle(decoded.wid).cancel();
|