@temporalio/nexus 1.15.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.
|
@@ -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;AAoD9D;;;;;;;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,KAAK,EAAgC,CAAC;IACpD,IAAI,GAAG,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;YACjC,IAAI,CAAC;gBACH,KAAK,CAAC,IAAI,CAAC;oBACT,aAAa,EAAE,IAAA,oDAAmC,EAAC,CAAC,CAAC;iBACtD,CAAC,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C;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK,EAAE,MAAM,CAAC,mBAAmB;KACO,CAAC;AAC7C,CAAC;AAYD;;;;GAIG;AACH,MAAa,2BAA2B;IACjB;IAArB,YAAqB,OAA+C;QAA/C,YAAO,GAAP,OAAO,CAAwC;IAAG,CAAC;IAExE,KAAK,CAAC,KAAK,CAAC,GAAgC,EAAE,KAAQ;QACpD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,2BAAiB,GAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9C,OAAO,KAAK,CAAC,2BAA2B,CAAC,KAAK,CAAC,IAAA,yCAAiC,EAAC,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IAClH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAkC,EAAE,KAAa;QAC5D,MAAM,OAAO,GAAG,IAAA,qCAA6B,EAAC,KAAK,CAAC,CAAC;QACrD,MAAM,IAAA,mBAAS,GAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7D,CAAC;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/proto": "1.
|
|
20
|
-
"@temporalio/common": "1.
|
|
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"
|
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();
|