Skip to content

Commit c4c25de

Browse files
authored
Update to TS SDK 1.9 (#328)
1 parent 2496f37 commit c4c25de

File tree

76 files changed

+310
-364
lines changed

Some content is hidden

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

76 files changed

+310
-364
lines changed

.scripts/copy-shared-files.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Run with https://github.com/google/zx
2+
const { readFileSync } = require('fs');
3+
24
const STORED_SAMPLES = new Set(require('./list-of-samples.json').samples);
35

46
const yaml = require('yaml');
@@ -180,8 +182,10 @@ testProjectsNode.value.items = [];
180182
lintProjectsNode.value.items = [];
181183

182184
for (const sample of samples) {
183-
const hasTestScript = !!require(`../${sample}/package.json`).scripts.test;
184-
const hasLintScript = !!require(`../${sample}/package.json`).scripts.lint;
185+
// Don't use require, because it won't work with ESM samples
186+
const packageJson = JSON.parse(readFileSync(`../${sample}/package.json`));
187+
const hasTestScript = !!packageJson.scripts.test;
188+
const hasLintScript = !!packageJson.scripts.lint;
185189

186190
if (hasTestScript) {
187191
testProjectsNode.value.items.push(sample);

activities-cancellation-heartbeating/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Running [`src/client.ts`](./src/client.ts) does this:
1313
- The `fakeProgress` activity starts and heartbeats
1414
- Waits 40s
1515
- Uses the handle to `cancel()` the workflow
16-
- The activity's `Context.current().sleep` receives the cancellation signal and throws a `CancelledFailure` for you to handle
16+
- The activity's `sleep` receives the cancellation signal and throws a `CancelledFailure` for you to handle
1717
- Activity catches the `CancelledFailure` which you can check with `isCancellation(err)`
1818
- Prints `Fake progress activity cancelled` in the Worker terminal
1919
- Workflow prints `Workflow cancelled along with its activity` in the Worker terminal

activities-cancellation-heartbeating/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
]
2121
},
2222
"dependencies": {
23-
"@temporalio/activity": "^1.8.4",
24-
"@temporalio/client": "^1.8.4",
25-
"@temporalio/worker": "^1.8.4",
26-
"@temporalio/workflow": "^1.8.4"
23+
"@temporalio/activity": "^1.9.0",
24+
"@temporalio/client": "^1.9.0",
25+
"@temporalio/worker": "^1.9.0",
26+
"@temporalio/workflow": "^1.9.0"
2727
},
2828
"devDependencies": {
2929
"@tsconfig/node16": "^1.0.0",

activities-cancellation-heartbeating/src/activities.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// @@@SNIPSTART typescript-activity-fake-progress
2-
import { CancelledFailure, Context } from '@temporalio/activity';
2+
import { activityInfo, log, sleep, CancelledFailure, heartbeat } from '@temporalio/activity';
33

44
export async function fakeProgress(sleepIntervalMs = 1000): Promise<void> {
5-
const { log, info, sleep, heartbeat } = Context.current();
65
try {
76
// allow for resuming from heartbeat
8-
const startingPoint = info.heartbeatDetails || 1;
7+
const startingPoint = activityInfo().heartbeatDetails || 1;
98
log.info('Starting activity at progress', { startingPoint });
109
for (let progress = startingPoint; progress <= 100; ++progress) {
1110
// simple utility to sleep in activity for given interval or throw if Activity is cancelled

activities-dependency-injection/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
]
2121
},
2222
"dependencies": {
23-
"@temporalio/activity": "^1.8.4",
24-
"@temporalio/client": "^1.8.4",
25-
"@temporalio/worker": "^1.8.4",
26-
"@temporalio/workflow": "^1.8.4"
23+
"@temporalio/activity": "^1.9.0",
24+
"@temporalio/client": "^1.9.0",
25+
"@temporalio/worker": "^1.9.0",
26+
"@temporalio/workflow": "^1.9.0"
2727
},
2828
"devDependencies": {
2929
"@tsconfig/node16": "^1.0.0",

activities-examples/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
]
2525
},
2626
"dependencies": {
27-
"@temporalio/activity": "^1.8.4",
28-
"@temporalio/client": "^1.8.4",
29-
"@temporalio/worker": "^1.8.4",
30-
"@temporalio/workflow": "^1.8.4",
27+
"@temporalio/activity": "^1.9.0",
28+
"@temporalio/client": "^1.9.0",
29+
"@temporalio/worker": "^1.9.0",
30+
"@temporalio/workflow": "^1.9.0",
3131
"axios": "^0.26.0",
3232
"node-fetch": "2.x"
3333
},
3434
"devDependencies": {
35-
"@temporalio/nyc-test-coverage": "^1.8.4",
36-
"@temporalio/testing": "^1.8.4",
35+
"@temporalio/nyc-test-coverage": "^1.9.0",
36+
"@temporalio/testing": "^1.9.0",
3737
"@tsconfig/node16": "^1.0.0",
3838
"@types/jest": "^27.5.1",
3939
"@types/mocha": "8.x",

activities-examples/src/activities/async-completion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// @@@SNIPSTART typescript-activity-complete-async
2-
import { CompleteAsyncError, Context } from '@temporalio/activity';
2+
import { CompleteAsyncError, activityInfo } from '@temporalio/activity';
33
import { AsyncCompletionClient } from '@temporalio/client';
44

55
export async function doSomethingAsync(): Promise<string> {
6-
const taskToken = Context.current().info.taskToken;
6+
const taskToken = activityInfo().taskToken;
77
setTimeout(() => doSomeWork(taskToken), 1000);
88
throw new CompleteAsyncError();
99
}

activities-examples/src/activities/cancellable-fetch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// @@@SNIPSTART typescript-activity-cancellable-fetch
22
import fetch from 'node-fetch';
3-
import { Context } from '@temporalio/activity';
3+
import { cancellationSignal, heartbeat } from '@temporalio/activity';
44
import type { AbortSignal as FetchAbortSignal } from 'node-fetch/externals';
55

66
export async function cancellableFetch(url: string): Promise<Uint8Array> {
7-
const response = await fetch(url, { signal: Context.current().cancellationSignal as FetchAbortSignal });
7+
const response = await fetch(url, { signal: cancellationSignal() as FetchAbortSignal });
88
const contentLengthHeader = response.headers.get('Content-Length');
99
if (contentLengthHeader === null) {
1010
throw new Error('expected Content-Length header to be set');
@@ -19,7 +19,7 @@ export async function cancellableFetch(url: string): Promise<Uint8Array> {
1919
}
2020
bytesRead += chunk.length;
2121
chunks.push(chunk);
22-
Context.current().heartbeat(bytesRead / contentLength);
22+
heartbeat(bytesRead / contentLength);
2323
}
2424
return Buffer.concat(chunks);
2525
}

activities-examples/src/mocha/workflows.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('example workflow', async function () {
2323
before(async function () {
2424
// Filter INFO log messages for clearer test output
2525
Runtime.install({ logger: new DefaultLogger('WARN') });
26-
const env = await TestWorkflowEnvironment.createTimeSkipping();
26+
const env = await TestWorkflowEnvironment.createLocal();
2727

2828
const worker = await Worker.create(
2929
workflowCoverage.augmentWorkerOptions({

activities-examples/src/workflows.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ beforeAll(async () => {
1515
logger: new DefaultLogger('WARN', (entry: LogEntry) => console.log(`[${entry.level}]`, entry.message)),
1616
});
1717

18-
testEnv = await TestWorkflowEnvironment.createTimeSkipping();
18+
testEnv = await TestWorkflowEnvironment.createLocal();
1919
});
2020

2121
afterAll(async () => {

0 commit comments

Comments
 (0)