1- /**
2- * Definitions for Activity interceptors.
3- *
4- * (The Worker also accepts Workflow interceptors but those are passed as module names)
5- *
6- * @module
7- */
8-
91import { Context as ActivityContext } from '@temporalio/activity' ;
102import { ClientInterceptors } from '@temporalio/client' ;
113import { Headers , MetricTags , Next } from '@temporalio/common' ;
124
135export { Next , Headers } ;
146
15- /** Input for ActivityInboundCallsInterceptor.execute */
16- export interface ActivityExecuteInput {
17- readonly args : unknown [ ] ;
18- readonly headers : Headers ;
7+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
8+ // Activity Interceptors
9+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10+
11+ export type ActivityInterceptorsFactory = ( ctx : ActivityContext ) => ActivityInterceptors ;
12+
13+ /**
14+ * A function that takes Activity Context and returns an interceptor
15+ */
16+
17+ export interface ActivityInterceptors {
18+ inbound ?: ActivityInboundCallsInterceptor ;
19+ outbound ?: ActivityOutboundCallsInterceptor ;
1920}
2021
2122/**
@@ -27,24 +28,17 @@ export interface ActivityInboundCallsInterceptor {
2728 *
2829 * @return result of Activity function
2930 */
30- execute ?: ( input : ActivityExecuteInput , next : Next < this , 'execute' > ) => Promise < unknown > ;
31+ execute ?: ( input : ActivityExecuteInput , next : Next < ActivityInboundCallsInterceptor , 'execute' > ) => Promise < unknown > ;
3132}
3233
3334/**
34- * A function that takes Activity Context and returns an interceptor
35- *
36- * @deprecated Use {@link ActivityInterceptorsFactory} instead
35+ * Input for {@link ActivityInboundCallsInterceptor.execute}
3736 */
38- export interface ActivityInboundCallsInterceptorFactory {
39- ( ctx : ActivityContext ) : ActivityInboundCallsInterceptor ;
37+ export interface ActivityExecuteInput {
38+ readonly args : unknown [ ] ;
39+ readonly headers : Headers ;
4040}
4141
42- /** Input for ActivityOutboundCallsInterceptor.getLogAttributes */
43- export type GetLogAttributesInput = Record < string , unknown > ;
44-
45- /** Input for ActivityOutboundCallsInterceptor.getMetricTags */
46- export type GetMetricTagsInput = MetricTags ;
47-
4842/**
4943 * Implement any of these methods to intercept Activity outbound calls
5044 */
@@ -54,7 +48,10 @@ export interface ActivityOutboundCallsInterceptor {
5448 *
5549 * The attributes returned in this call are attached to every log message.
5650 */
57- getLogAttributes ?: ( input : GetLogAttributesInput , next : Next < this, 'getLogAttributes' > ) => Record < string , unknown > ;
51+ getLogAttributes ?: (
52+ input : GetLogAttributesInput ,
53+ next : Next < ActivityOutboundCallsInterceptor , 'getLogAttributes' >
54+ ) => Record < string , unknown > ;
5855
5956 /**
6057 * Called once every time a metric is emitted from an Activity metric
@@ -63,18 +60,34 @@ export interface ActivityOutboundCallsInterceptor {
6360 * Tags returned by this hook are _prepended_ to tags defined at the metric level and tags defined
6461 * on the emitter function itself.
6562 */
66- getMetricTags ?: ( input : GetMetricTagsInput , next : Next < this, 'getMetricTags' > ) => MetricTags ;
63+ getMetricTags ?: (
64+ input : GetMetricTagsInput ,
65+ next : Next < ActivityOutboundCallsInterceptor , 'getMetricTags' >
66+ ) => MetricTags ;
6767}
6868
69- export interface ActivityInterceptors {
70- inbound ?: ActivityInboundCallsInterceptor ;
71- outbound ?: ActivityOutboundCallsInterceptor ;
72- }
69+ /**
70+ * Input for {@link ActivityOutboundCallsInterceptor.getLogAttributes}
71+ */
72+ export type GetLogAttributesInput = Record < string , unknown > ;
73+
74+ /**
75+ * Input for {@link ActivityOutboundCallsInterceptor.getMetricTags}
76+ */
77+ export type GetMetricTagsInput = MetricTags ;
7378
7479/**
7580 * A function that takes Activity Context and returns an interceptor
81+ *
82+ * @deprecated Use {@link ActivityInterceptorsFactory} instead
7683 */
77- export type ActivityInterceptorsFactory = ( ctx : ActivityContext ) => ActivityInterceptors ;
84+ export interface ActivityInboundCallsInterceptorFactory {
85+ ( ctx : ActivityContext ) : ActivityInboundCallsInterceptor ;
86+ }
87+
88+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89+ // Worker Interceptors Configuration
90+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7891
7992/**
8093 * Structure for passing in Worker interceptors via {@link WorkerOptions}
@@ -88,11 +101,13 @@ export interface WorkerInterceptors {
88101 * instead. Client doesn't support cancellation through a Signal.
89102 */
90103 client ?: ClientInterceptors ;
104+
91105 /**
92106 * List of factory functions that instanciate {@link ActivityInboundCallsInterceptor}s and
93107 * {@link ActivityOutboundCallsInterceptor}s.
94108 */
95109 activity ?: ActivityInterceptorsFactory [ ] ;
110+
96111 /**
97112 * List of factory functions returning {@link ActivityInboundCallsInterceptor}s. If both `activity` and
98113 * `activityInbound` is supplied, then entries from `activityInbound` will be prepended to inbound interceptors
@@ -101,6 +116,7 @@ export interface WorkerInterceptors {
101116 * @deprecated Use {@link WorkerInterceptors.activity} instead.
102117 */
103118 activityInbound ?: ActivityInboundCallsInterceptorFactory [ ] ; // eslint-disable-line deprecation/deprecation
119+
104120 /**
105121 * List of modules to search for Workflow interceptors in
106122 * - Modules should export an `interceptors` variable of type {@link WorkflowInterceptorsFactory}
0 commit comments