Skip to content

Commit f7d5ad2

Browse files
authored
docs: Improve API reference (#871)
1 parent 9e75c40 commit f7d5ad2

File tree

15 files changed

+77
-79
lines changed

15 files changed

+77
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ Breaking changes marked with a :boom:
14851485
- Add Workflow and WorkflowCreator interfaces to support pluggable workflow environments (prepare for VM)
14861486
- :boom: Simplify external dependencies mechanism to only support void functions and remove the isolated-vm transfer options.
14871487

1488-
- Support [`ms`](https://www.npmjs.com/package/ms) formatted string for activity.Context.sleep ([#322](https://github.com/temporalio/sdk-typescript/pull/322))
1488+
- Support [`ms`](https://www.npmjs.com/package/ms)-formatted string for activity.Context.sleep ([#322](https://github.com/temporalio/sdk-typescript/pull/322))
14891489
- :boom: Runtime determinism tweaks ([#326](https://github.com/temporalio/sdk-typescript/pull/326))
14901490
- Undelete WeakMap and WeakSet
14911491
- Delete FinalizationRegistry

packages/activity/src/index.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,45 @@
1515
*
1616
* ### Cancellation
1717
*
18-
* Activity Cancellation serves three purposes:
18+
* Activity Cancellation:
1919
*
20-
* - It lets an Activity know it doesn't need to keep doing work.
21-
* - It gives the Activity time to clean up any resources it has created.
20+
* - lets the Activity know it doesn't need to keep doing work, and
21+
* - gives the Activity time to clean up any resources it has created.
2222
*
23-
* Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
23+
* Activities can only receive Cancellation if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
2424
* (which can't heartbeat but receive Cancellation anyway).
2525
*
26-
* There are two ways to handle Activity cancellation:
26+
* An Activity may receive Cancellation if:
27+
*
28+
* - The Workflow scope containing the Activity call was requested to be Cancelled and
29+
* {@link ActivityOptions.cancellationType} was **not** set to {@link ActivityCancellationType.ABANDON}. The scope can
30+
* be cancelled in either of the following ways:
31+
* - The entire Workflow was Cancelled (via {@link WorkflowHandle.cancel}).
32+
* - Calling {@link CancellationScope.cancel}) from inside a Workflow.
33+
* - The Worker has started to shut down. Shutdown is initiated by either:
34+
* - One of the {@link RuntimeOptions.shutdownSignals} was sent to the process.
35+
* - {@link Worker.shutdown | `Worker.shutdown()`} was called.
36+
* - The Activity was considered failed by the Server because any of the Activity timeouts have triggered (for example,
37+
* the Server didn't receive a heartbeat within the {@link ActivityOptions.heartbeatTimeout}). The
38+
* {@link CancelledFailure} will have `message: 'TIMED_OUT'`.
39+
* - An Activity sends a heartbeat with `Context.current().heartbeat()` and the heartbeat details can't be converted by
40+
* the Worker's configured {@link DataConverter}.
41+
* - The Workflow Run reached a {@link https://docs.temporal.io/workflows#status | Closed state}, in which case the
42+
* {@link CancelledFailure} will have `message: 'NOT_FOUND'`.
43+
*
44+
* The reason for the Cancellation is available at {@link CancelledFailure.message} or
45+
* {@link Context#cancellationSignal | Context.cancellationSignal.reason}.
46+
*
47+
* There are two ways to handle Activity Cancellation:
48+
*
2749
* 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
2850
* {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
2951
* 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
3052
* {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
3153
*
3254
* ### Examples
3355
*
34-
* #### An Activity that sends progress heartbeats and can be cancelled
56+
* #### An Activity that sends progress heartbeats and can be Cancelled
3557
*
3658
* <!--SNIPSTART typescript-activity-fake-progress-->
3759
* <!--SNIPEND-->
@@ -254,7 +276,7 @@ export class Context {
254276

255277
/**
256278
* Helper function for sleeping in an Activity.
257-
* @param ms Sleep duration: an {@link https://www.npmjs.com/package/ms | ms}-formatted string or number of milliseconds
279+
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
258280
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
259281
*/
260282
public sleep(ms: number | string): Promise<void> {

packages/client/src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface ConnectionOptions {
6363
* Used either when connecting eagerly with {@link Connection.connect} or
6464
* calling {@link Connection.ensureConnected}.
6565
*
66-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
66+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
6767
* @default 10 seconds
6868
*/
6969
connectTimeout?: number | string;

packages/client/src/interceptors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface WorkflowClientCallsInterceptor {
112112
describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
113113
}
114114

115-
interface WorkflowClientCallsInterceptorFactoryInput {
115+
export interface WorkflowClientCallsInterceptorFactoryInput {
116116
workflowId: string;
117117
runId?: string;
118118
}

packages/client/src/workflow-client.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
120120
terminate(reason?: string): Promise<TerminateWorkflowExecutionResponse>;
121121

122122
/**
123-
* Cancel a running Workflow
123+
* Cancel a running Workflow.
124+
*
125+
* When a Workflow is cancelled, the root scope throws {@link CancelledFailure} with `message: 'Workflow canceled'`.
126+
* That means that all cancellable scopes will throw `CancelledFailure`.
127+
*
128+
* Cancellation may be propagated to Activities depending on {@link ActivityOptions#cancellationType}, after which
129+
* Activity calls may throw an {@link ActivityFailure}, and `isCancellation(error)` will be true (see {@link isCancellation}).
130+
*
131+
* Cancellation may be propagated to Child Workflows depending on {@link ChildWorkflowOptions#cancellationType}, after
132+
* which calls to {@link executeChild} and {@link ChildWorkflowHandle#result} will throw, and `isCancellation(error)`
133+
* will be true (see {@link isCancellation}).
124134
*/
125135
cancel(): Promise<RequestCancelWorkflowExecutionResponse>;
126136

packages/internal-workflow-common/src/activity-options.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ActivityOptions {
3535

3636
/**
3737
* Heartbeat interval. Activity must heartbeat before this interval passes after a last heartbeat or activity start.
38-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
38+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
3939
*/
4040
heartbeatTimeout?: string | number;
4141

@@ -49,14 +49,14 @@ export interface ActivityOptions {
4949
Note that the Temporal Server doesn't detect Worker process failures directly. It relies on this timeout to detect that an Activity that didn't complete on time. So this timeout should be as short as the longest possible execution of the Activity body. Potentially long running Activities must specify {@link heartbeatTimeout} and call {@link activity.Context.heartbeat} periodically for timely failure detection.
5050
5151
* Either this option or {@link scheduleToCloseTimeout} is required.
52-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
52+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
5353
*/
5454
startToCloseTimeout?: string | number;
5555
/**
5656
* Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker. Do not specify this timeout unless using host specific Task Queues for Activity Tasks are being used for routing.
5757
* `scheduleToStartTimeout` is always non-retryable. Retrying after this timeout doesn't make sense as it would just put the Activity Task back into the same Task Queue.
5858
* @default unlimited
59-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
59+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
6060
*/
6161
scheduleToStartTimeout?: string | number;
6262

@@ -66,7 +66,7 @@ Note that the Temporal Server doesn't detect Worker process failures directly. I
6666
*
6767
* Either this option or {@link startToCloseTimeout} is required
6868
* @default unlimited
69-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
69+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
7070
*/
7171
scheduleToCloseTimeout?: string | number;
7272

@@ -110,7 +110,7 @@ export interface LocalActivityOptions {
110110
* Either this option or {@link scheduleToCloseTimeout} is required.
111111
* If set, this must be <= {@link scheduleToCloseTimeout}, otherwise, it will be clamped down.
112112
*
113-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
113+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
114114
*/
115115
startToCloseTimeout?: string | number;
116116

@@ -122,7 +122,7 @@ export interface LocalActivityOptions {
122122
* {@link scheduleToCloseTimeout} when set, otherwise, it will be clamped down.
123123
*
124124
* @default unlimited
125-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
125+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
126126
*/
127127
scheduleToStartTimeout?: string | number;
128128

@@ -134,7 +134,7 @@ export interface LocalActivityOptions {
134134
* Either this option or {@link startToCloseTimeout} is required.
135135
*
136136
* @default unlimited
137-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
137+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
138138
*/
139139
scheduleToCloseTimeout?: string | number;
140140

@@ -143,7 +143,7 @@ export interface LocalActivityOptions {
143143
* Otherwise, backoff will happen internally in the SDK.
144144
*
145145
* @default 1 minute
146-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
146+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
147147
**/
148148
localRetryThreshold?: string | number;
149149

packages/internal-workflow-common/src/retry-policy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface RetryPolicy {
1616
/**
1717
* Interval of the first retry.
1818
* If coefficient is 1 then it is used for all retries
19-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
19+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
2020
* @default 1 second
2121
*/
2222
initialInterval?: string | number;
@@ -33,7 +33,7 @@ export interface RetryPolicy {
3333
* This value is the cap of the increase.
3434
*
3535
* @default 100x of {@link initialInterval}
36-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
36+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
3737
*/
3838
maximumInterval?: string | number;
3939

packages/internal-workflow-common/src/workflow-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export interface WorkflowDurationOptions {
111111
* rely on run timeout for business level timeouts. It is preferred to use in workflow timers
112112
* for this purpose.
113113
*
114-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
114+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
115115
*/
116116
workflowRunTimeout?: string | number;
117117

@@ -121,14 +121,14 @@ export interface WorkflowDurationOptions {
121121
* automatically terminated by Temporal service. Do not rely on execution timeout for business
122122
* level timeouts. It is preferred to use in workflow timers for this purpose.
123123
*
124-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
124+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
125125
*/
126126
workflowExecutionTimeout?: string | number;
127127

128128
/**
129129
* Maximum execution time of a single workflow task. Default is 10 seconds.
130130
*
131-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
131+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
132132
*/
133133
workflowTaskTimeout?: string | number;
134134
}

packages/test/src/worker/external-logger-example.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/testing/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class TestWorkflowEnvironment {
310310
*
311311
* This method is _likely_ to resolve in less than `durationMs` of "real time".
312312
*
313-
* @param durationMs {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
313+
* @param durationMs number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
314314
*
315315
* @example
316316
*

packages/worker/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121
export { ActivityInboundLogInterceptor, activityLogAttributes } from './activity-log-interceptor';
2222
export { NativeConnection as NativeConnection } from './connection';
2323
export { NativeConnectionOptions, RequiredNativeConnectionOptions, TLSConfig } from './connection-options';
24+
export { startDebugReplayer } from './debug-replayer';
2425
export * from './errors';
2526
export * from './interceptors';
2627
export * from './logger';
@@ -33,11 +34,10 @@ export {
3334
defaultSinks,
3435
ReplayWorkerOptions,
3536
WorkerOptions,
36-
WorkflowBundleOption,
3737
WorkflowBundle,
38+
WorkflowBundleOption,
3839
WorkflowBundlePath,
3940
WorkflowBundlePathWithSourceMap, // eslint-disable-line deprecation/deprecation
4041
} from './worker-options';
41-
export { WorkflowInboundLogInterceptor, workflowLogAttributes } from './workflow-log-interceptor';
42+
export { LoggerSinks, WorkflowInboundLogInterceptor, workflowLogAttributes } from './workflow-log-interceptor';
4243
export { BundleOptions, bundleWorkflowCode, WorkflowBundleWithSourceMap } from './workflow/bundler';
43-
export { startDebugReplayer } from './debug-replayer';

packages/worker/src/worker-options.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export interface WorkerOptions {
123123
/**
124124
* Time to wait for pending tasks to drain after shutdown was requested.
125125
*
126-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
126+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
127127
* @default 10s
128128
*/
129129
shutdownGraceTime?: string | number;
@@ -185,7 +185,7 @@ export interface WorkerOptions {
185185
/**
186186
* How long a workflow task is allowed to sit on the sticky queue before it is timed out
187187
* and moved to the non-sticky queue where it may be picked up by any worker.
188-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
188+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
189189
* @default 10s
190190
*/
191191
stickyQueueScheduleToStartTimeout?: string;
@@ -208,7 +208,7 @@ export interface WorkerOptions {
208208

209209
/**
210210
* Longest interval for throttling activity heartbeats
211-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
211+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
212212
* @default 60 seconds
213213
*/
214214
maxHeartbeatThrottleInterval?: number | string;
@@ -219,7 +219,7 @@ export interface WorkerOptions {
219219
* When the timeout *is* set in the `ActivityOptions`, throttling is set to
220220
* `heartbeat_timeout * 0.8`.
221221
*
222-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
222+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
223223
* @default 30 seconds
224224
*/
225225
defaultHeartbeatThrottleInterval?: number | string;
@@ -342,7 +342,7 @@ export type WorkerOptionsWithDefaults = WorkerOptions &
342342

343343
/**
344344
* Time to wait for result when calling a Workflow isolate function.
345-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
345+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
346346
*
347347
* This value is not exposed at the moment.
348348
*

packages/workflow/src/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* The recommended way of scheduling timers is by using the {@link sleep} function. We've replaced `setTimeout` and
1010
* `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well
11-
* with {@link https://docs.temporal.io/typescript/workflow-scopes-and-cancellation | cancellation scopes}.
11+
* with {@link https://docs.temporal.io/typescript/cancellation-scopes | cancellation scopes}.
1212
*
1313
* <!--SNIPSTART typescript-sleep-workflow-->
1414
* <!--SNIPEND-->
@@ -34,16 +34,14 @@
3434
* <!--SNIPSTART typescript-workflow-signal-implementation-->
3535
* <!--SNIPEND-->
3636
*
37-
* ### Deterministic built-ins
38-
* It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We
39-
* also provide a deterministic {@link uuid4} function for convenience.
37+
* ### More
4038
*
41-
* ### [Cancellation and scopes](https://docs.temporal.io/typescript/workflow-scopes-and-cancellation)
42-
* - {@link CancellationScope}
43-
* - {@link Trigger}
44-
*
45-
* ### [Sinks](https://docs.temporal.io/typescript/sinks)
46-
* - {@link Sinks}
39+
* - [Deterministic built-ins](https://docs.temporal.io/typescript/determinism#sources-of-non-determinism)
40+
* - [Cancellation and scopes](https://docs.temporal.io/typescript/cancellation-scopes)
41+
* - {@link CancellationScope}
42+
* - {@link Trigger}
43+
* - [Sinks](https://docs.temporal.io/application-development/observability/?lang=ts#logging)
44+
* - {@link Sinks}
4745
*
4846
* @module
4947
*/

packages/workflow/src/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ export interface ContinueAsNewOptions {
169169
taskQueue?: string;
170170
/**
171171
* Timeout for the entire Workflow run
172-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
172+
* @format {@link https://www.npmjs.com/package/ms | ms-formatted string}
173173
*/
174174
workflowRunTimeout?: string;
175175
/**
176176
* Timeout for a single Workflow task
177-
* @format {@link https://www.npmjs.com/package/ms | ms} formatted string
177+
* @format {@link https://www.npmjs.com/package/ms | ms-formatted string}
178178
*/
179179
workflowTaskTimeout?: string;
180180
/**

packages/workflow/src/workflow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function timerNextHandler(input: TimerInput) {
102102
*
103103
* Schedules a timer on the Temporal service.
104104
*
105-
* @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds.
105+
* @param ms sleep duration - number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}.
106106
* If given a negative number or 0, value will be set to 1.
107107
*/
108108
export function sleep(ms: number | string): Promise<void> {
@@ -1068,7 +1068,7 @@ function patchInternal(patchId: string, deprecated: boolean): boolean {
10681068
/**
10691069
* Returns a Promise that resolves when `fn` evaluates to `true` or `timeout` expires.
10701070
*
1071-
* @param timeout {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds
1071+
* @param timeout number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
10721072
*
10731073
* @returns a boolean indicating whether the condition was true before the timeout expires
10741074
*/

0 commit comments

Comments
 (0)