Skip to content

feat(nexus): Early Nexus handler support #1708

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
01502c7
Nexus handler near complete implementation
bergundy Mar 4, 2025
0490e7b
Use the Nexus SDK ServiceRegistry
bergundy May 15, 2025
be83b0d
Upgrade core, TODO fix protos and versioning behavior
bergundy May 15, 2025
2150a48
Link converter
bergundy May 15, 2025
3dcc150
Add worker/src/nexus directory
bergundy May 15, 2025
5e4a5c3
Lint
bergundy May 15, 2025
d29dee1
getClient() and fix versioning strategy
bergundy May 15, 2025
29e6c12
WorkflowRunOperation
bergundy May 16, 2025
244cbbb
Merge remote-tracking branch 'origin/main' into nexus
bergundy May 16, 2025
0e6dad1
Fix build
bergundy May 19, 2025
64cee58
Cleanup
bergundy May 19, 2025
ab2645a
Nexus workflow client
bergundy May 19, 2025
a627bfd
Fail requests with BAD_REQUEST if payload decoding fails
bergundy May 19, 2025
69d01c0
Format code
bergundy May 21, 2025
ebf1311
Merged context and options
bergundy May 23, 2025
9ed2ddf
OperationContext
bergundy May 28, 2025
79c9303
Merge branch 'main' into pr/bergundy/1708
mjameswh Jun 4, 2025
7a836da
stash - fixing build and test issues
mjameswh Jun 5, 2025
64aee0a
Try temp solution to get CI running
mjameswh Jun 6, 2025
386fac6
Try temp solution to get CI running - Take 2
mjameswh Jun 6, 2025
86d6575
Get CI running - Fix some issues
mjameswh Jun 6, 2025
a442b2c
Fixes failing tests
mjameswh Jun 6, 2025
35ef1b9
Fixes failing test on windows
mjameswh Jun 6, 2025
d90ef24
Fixes failing tests on Node 18 and Windows
mjameswh Jun 6, 2025
40d6b52
temporalio/nexus package was not being exported to npm repo (neither …
mjameswh Jun 6, 2025
0728ae2
Fix race in test causing flakyness
mjameswh Jun 6, 2025
9073514
Trivial renames of Nexus APIs
mjameswh Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@
"@temporalio/common": "file:packages/common",
"@temporalio/create": "file:packages/create-project",
"@temporalio/interceptors-opentelemetry": "file:packages/interceptors-opentelemetry",
"@temporalio/nexus": "file:packages/nexus",
"@temporalio/nyc-test-coverage": "file:packages/nyc-test-coverage",
"@temporalio/proto": "file:packages/proto",
"@temporalio/test": "file:packages/test",
"@temporalio/testing": "file:packages/testing",
"@temporalio/worker": "file:packages/worker",
"@temporalio/workflow": "file:packages/workflow",
"nexus-rpc": "github:nexus-rpc/sdk-typescript#pull/6/head",
"temporalio": "file:packages/meta"
},
"devDependencies": {
Expand Down Expand Up @@ -86,6 +88,7 @@
"packages/core-bridge",
"packages/create-project",
"packages/interceptors-opentelemetry",
"packages/nexus",
"packages/nyc-test-coverage",
"packages/proto",
"packages/test",
Expand Down
28 changes: 28 additions & 0 deletions packages/client/src/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { temporal } from '@temporalio/proto';

// A key used internally to pass "hidden options to the WorkflowClient.start() call.
export const InternalWorkflowStartOptionsKey = Symbol.for('__temporal_client_internal_workflow_start_options');

// Hidden internal workflow start options, used by the temporal nexus helpers.
export interface InternalWorkflowStartOptions {
requestId?: string;
/**
* Callbacks to be called by the server when this workflow reaches a terminal state.
* If the workflow continues-as-new, these callbacks will be carried over to the new execution.
* Callback addresses must be whitelisted in the server's dynamic configuration.
*/
completionCallbacks?: temporal.api.common.v1.ICallback[];
/** Links to be associated with the workflow. */
links?: temporal.api.common.v1.ILink[];
/**
* Backlink copied by the client from the StartWorkflowExecutionResponse. Only populated in servers newer than 1.27.
*/
backLink?: temporal.api.common.v1.ILink;

/**
* Conflict options for when USE_EXISTING is specified.
*
* Used by the nexus WorkflowRunOperations to attach to a callback to a running workflow.
*/
onConflictOptions?: temporal.api.workflow.v1.IOnConflictOptions;
}
14 changes: 12 additions & 2 deletions packages/client/src/workflow-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import {
} from './base-client';
import { mapAsyncIterable } from './iterators-utils';
import { WorkflowUpdateStage, encodeWorkflowUpdateStage } from './workflow-update-stage';
import { InternalWorkflowStartOptions, InternalWorkflowStartOptionsKey } from './internal';

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

Expand Down Expand Up @@ -1252,7 +1253,14 @@ export class WorkflowClient extends BaseClient {
const req = await this.createStartWorkflowRequest(input);
const { options: opts, workflowType } = input;
try {
return (await this.workflowService.startWorkflowExecution(req)).runId;
const response = await this.workflowService.startWorkflowExecution(req);
const internalOptions = (opts as any)[InternalWorkflowStartOptionsKey] as
| InternalWorkflowStartOptions
| undefined;
if (internalOptions != null) {
internalOptions.backLink = response.link ?? undefined;
}
return response.runId;
} catch (err: any) {
if (err.code === grpcStatus.ALREADY_EXISTS) {
throw new WorkflowExecutionAlreadyStartedError(
Expand All @@ -1268,11 +1276,12 @@ export class WorkflowClient extends BaseClient {
protected async createStartWorkflowRequest(input: WorkflowStartInput): Promise<StartWorkflowExecutionRequest> {
const { options: opts, workflowType, headers } = input;
const { identity, namespace } = this.options;
const internalOptions = (opts as any)[InternalWorkflowStartOptionsKey] as InternalWorkflowStartOptions | undefined;

return {
namespace,
identity,
requestId: uuid4(),
requestId: internalOptions?.requestId ?? uuid4(),
workflowId: opts.workflowId,
workflowIdReusePolicy: encodeWorkflowIdReusePolicy(opts.workflowIdReusePolicy),
workflowIdConflictPolicy: encodeWorkflowIdConflictPolicy(opts.workflowIdConflictPolicy),
Expand All @@ -1298,6 +1307,7 @@ export class WorkflowClient extends BaseClient {
header: { fields: headers },
priority: opts.priority ? compilePriority(opts.priority) : undefined,
versioningOverride: opts.versioningOverride ?? undefined,
...internalOptions,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@temporalio/proto": "file:../proto",
"long": "^5.2.3",
"ms": "^3.0.0-canary.1",
"nexus-rpc": "github:nexus-rpc/sdk-typescript#pull/6/head",
"proto3-json-serializer": "^2.0.0"
},
"devDependencies": {
Expand Down
Loading
Loading