Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog/fixed/tap-dancing-interceptors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve and append Activity and Nexus client interceptors when SimplePlugin merges client or worker client configuration.
13 changes: 11 additions & 2 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
"license": "MIT",
"scripts": {
"build": "tsc --build"
"build": "tsc --build",
"test": "tsx ../../scripts/ava-ci.ts ./lib/__tests__/test-*.js"
},
"ava": {
"timeout": "60s",
"concurrency": 1,
"workerThreads": false
},
"devDependencies": {
"@temporalio/client": "workspace:*",
"@temporalio/common": "workspace:*",
"@temporalio/worker": "workspace:*",
"ava": "^5.3.1",
"nexus-rpc": "^0.0.3"
},
"bugs": {
Expand All @@ -38,6 +45,8 @@
},
"files": [
"src",
"lib"
"lib",
"!src/__tests__",
"!lib/__tests__"
]
}
37 changes: 37 additions & 0 deletions packages/plugin/src/__tests__/test-client-interceptors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import test from 'ava';
import type { ClientInterceptors } from '@temporalio/client';
import { SimplePlugin } from '../plugin';

test('SimplePlugin appends Activity and Nexus client interceptors', (t) => {
const existingActivity = {};
const existingNexus = {};
const pluginActivity = {};
const pluginNexus = {};
const plugin = new SimplePlugin({
name: 'interceptor-merge',
clientInterceptors: { activity: [pluginActivity], nexus: [pluginNexus] },
});
const actual = plugin.configureClient({
interceptors: { activity: [existingActivity], nexus: [existingNexus] },
}).interceptors;

t.is(actual?.activity?.length, 2);
t.is(actual?.activity?.[0], existingActivity);
t.is(actual?.activity?.[1], pluginActivity);
t.is(actual?.nexus?.length, 2);
t.is(actual?.nexus?.[0], existingNexus);
t.is(actual?.nexus?.[1], pluginNexus);
});

test('SimplePlugin clientInterceptors overrides default behavior', (t) => {
const original: ClientInterceptors = { activity: [{}], nexus: [{}] };
const replacement: ClientInterceptors = { activity: [{}], nexus: [{}] };
const plugin = new SimplePlugin({
name: 'custom-merge',
clientInterceptors: (current) => {
t.is(current, original);
return replacement;
},
});
t.is(plugin.configureClient({ interceptors: original }).interceptors, replacement);
});
2 changes: 2 additions & 0 deletions packages/plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ function resolveClientInterceptors(
modernWorkflowInterceptors(parameter?.workflow)
),
schedule: tryConcat(existing?.schedule, parameter?.schedule),
activity: tryConcat(existing?.activity, parameter?.activity),
nexus: tryConcat(existing?.nexus, parameter?.nexus),
}));
}

Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

Loading