Skip to content

Commit 1fec196

Browse files
bergundymjameswh
andauthored
feat(nexus): Initial Nexus support (#1708)
Co-authored-by: James Watkins-Harvey <[email protected]>
1 parent 5473ebd commit 1fec196

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3541
-105
lines changed

package-lock.json

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
"@temporalio/common": "file:packages/common",
4444
"@temporalio/create": "file:packages/create-project",
4545
"@temporalio/interceptors-opentelemetry": "file:packages/interceptors-opentelemetry",
46+
"@temporalio/nexus": "file:packages/nexus",
4647
"@temporalio/nyc-test-coverage": "file:packages/nyc-test-coverage",
4748
"@temporalio/proto": "file:packages/proto",
4849
"@temporalio/test": "file:packages/test",
4950
"@temporalio/testing": "file:packages/testing",
5051
"@temporalio/worker": "file:packages/worker",
5152
"@temporalio/workflow": "file:packages/workflow",
53+
"nexus-rpc": "^0.0.1",
5254
"temporalio": "file:packages/meta"
5355
},
5456
"devDependencies": {
@@ -86,6 +88,7 @@
8688
"packages/core-bridge",
8789
"packages/create-project",
8890
"packages/interceptors-opentelemetry",
91+
"packages/nexus",
8992
"packages/nyc-test-coverage",
9093
"packages/proto",
9194
"packages/test",

packages/client/src/internal.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { temporal } from '@temporalio/proto';
2+
import { WorkflowOptions } from './workflow-options';
3+
4+
/**
5+
* A symbol used to attach extra, SDK-internal options to the `WorkflowClient.start()` call.
6+
*
7+
* These are notably used by the Temporal Nexus helpers.
8+
*
9+
* @internal
10+
* @hidden
11+
*/
12+
export const InternalWorkflowStartOptionsSymbol = Symbol.for('__temporal_internal_client_workflow_start_options');
13+
export interface InternalWorkflowStartOptions extends WorkflowOptions {
14+
[InternalWorkflowStartOptionsSymbol]?: {
15+
/**
16+
* Request ID to be used for the workflow.
17+
*/
18+
requestId?: string;
19+
20+
/**
21+
* Callbacks to be called by the server when this workflow reaches a terminal state.
22+
* If the workflow continues-as-new, these callbacks will be carried over to the new execution.
23+
* Callback addresses must be whitelisted in the server's dynamic configuration.
24+
*/
25+
completionCallbacks?: temporal.api.common.v1.ICallback[];
26+
27+
/**
28+
* Links to be associated with the workflow.
29+
*/
30+
links?: temporal.api.common.v1.ILink[];
31+
32+
/**
33+
* Backlink copied by the client from the StartWorkflowExecutionResponse.
34+
* Only populated in servers newer than 1.27.
35+
*/
36+
backLink?: temporal.api.common.v1.ILink;
37+
38+
/**
39+
* Conflict options for when USE_EXISTING is specified.
40+
*
41+
* Used by the Nexus WorkflowRunOperations to attach to a callback to a running workflow.
42+
*/
43+
onConflictOptions?: temporal.api.workflow.v1.IOnConflictOptions;
44+
};
45+
}

packages/client/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ export type WorkflowExecutionDescription = Replace<
7474
* General fixed details for this workflow execution that may appear in UI/CLI.
7575
* This can be in Temporal markdown format and can span multiple lines.
7676
*
77-
* @experimental User metadata is a new API and suspectible to change.
77+
* @experimental User metadata is a new API and susceptible to change.
7878
*/
7979
staticDetails: () => Promise<string | undefined>;
8080

8181
/**
8282
* A single-line fixed summary for this workflow execution that may appear in the UI/CLI.
8383
* This can be in single-line Temporal markdown format.
8484
*
85-
* @experimental User metadata is a new API and suspectible to change.
85+
* @experimental User metadata is a new API and susceptible to change.
8686
*/
8787
staticSummary: () => Promise<string | undefined>;
8888
};

packages/client/src/workflow-client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import {
9393
} from './base-client';
9494
import { mapAsyncIterable } from './iterators-utils';
9595
import { WorkflowUpdateStage, encodeWorkflowUpdateStage } from './workflow-update-stage';
96+
import { InternalWorkflowStartOptionsSymbol, InternalWorkflowStartOptions } from './internal';
9697

9798
const UpdateWorkflowExecutionLifecycleStage = temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage;
9899

@@ -1248,8 +1249,13 @@ export class WorkflowClient extends BaseClient {
12481249
protected async _startWorkflowHandler(input: WorkflowStartInput): Promise<string> {
12491250
const req = await this.createStartWorkflowRequest(input);
12501251
const { options: opts, workflowType } = input;
1252+
const internalOptions = (opts as InternalWorkflowStartOptions)[InternalWorkflowStartOptionsSymbol];
12511253
try {
1252-
return (await this.workflowService.startWorkflowExecution(req)).runId;
1254+
const response = await this.workflowService.startWorkflowExecution(req);
1255+
if (internalOptions != null) {
1256+
internalOptions.backLink = response.link ?? undefined;
1257+
}
1258+
return response.runId;
12531259
} catch (err: any) {
12541260
if (err.code === grpcStatus.ALREADY_EXISTS) {
12551261
throw new WorkflowExecutionAlreadyStartedError(
@@ -1265,10 +1271,12 @@ export class WorkflowClient extends BaseClient {
12651271
protected async createStartWorkflowRequest(input: WorkflowStartInput): Promise<StartWorkflowExecutionRequest> {
12661272
const { options: opts, workflowType, headers } = input;
12671273
const { identity, namespace } = this.options;
1274+
const internalOptions = (opts as InternalWorkflowStartOptions)[InternalWorkflowStartOptionsSymbol];
1275+
12681276
return {
12691277
namespace,
12701278
identity,
1271-
requestId: uuid4(),
1279+
requestId: internalOptions?.requestId ?? uuid4(),
12721280
workflowId: opts.workflowId,
12731281
workflowIdReusePolicy: encodeWorkflowIdReusePolicy(opts.workflowIdReusePolicy),
12741282
workflowIdConflictPolicy: encodeWorkflowIdConflictPolicy(opts.workflowIdConflictPolicy),
@@ -1295,6 +1303,7 @@ export class WorkflowClient extends BaseClient {
12951303
userMetadata: await encodeUserMetadata(this.dataConverter, opts.staticSummary, opts.staticDetails),
12961304
priority: opts.priority ? compilePriority(opts.priority) : undefined,
12971305
versioningOverride: opts.versioningOverride ?? undefined,
1306+
...filterNullAndUndefined(internalOptions ?? {}),
12981307
};
12991308
}
13001309

packages/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@temporalio/proto": "file:../proto",
1616
"long": "^5.2.3",
1717
"ms": "^3.0.0-canary.1",
18+
"nexus-rpc": "^0.0.1",
1819
"proto3-json-serializer": "^2.0.0"
1920
},
2021
"devDependencies": {

packages/common/src/activity-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export interface ActivityOptions {
129129
* A fixed, single-line summary for this workflow execution that may appear in the UI/CLI.
130130
* This can be in single-line Temporal markdown format.
131131
*
132-
* @experimental User metadata is a new API and suspectible to change.
132+
* @experimental User metadata is a new API and susceptible to change.
133133
*/
134134
summary?: string;
135135

@@ -206,7 +206,7 @@ export interface LocalActivityOptions {
206206
* A fixed, single-line summary for this workflow execution that may appear in the UI/CLI.
207207
* This can be in single-line Temporal markdown format.
208208
*
209-
* @experimental User metadata is a new API and suspectible to change.
209+
* @experimental User metadata is a new API and susceptible to change.
210210
*/
211211
summary?: string;
212212
}

0 commit comments

Comments
 (0)