diff --git a/early-return/.nvmrc b/early-return/.nvmrc index b6a7d89c..2bd5a0a9 100644 --- a/early-return/.nvmrc +++ b/early-return/.nvmrc @@ -1 +1 @@ -16 +22 diff --git a/early-return/.post-create b/early-return/.post-create index a682bb78..24ad744e 100644 --- a/early-return/.post-create +++ b/early-return/.post-create @@ -7,9 +7,9 @@ Start Temporal Server: {cyan temporal server start-dev} -Use Node version 16+: +Use Node version 18+ (v22.x is recommended): - Mac: {cyan brew install node@16} + Mac: {cyan brew install node@22} Other: https://nodejs.org/en/download/ Then, in the project directory, using two other shells, run these commands: diff --git a/early-return/README.md b/early-return/README.md index 94c81e23..3c7b169e 100644 --- a/early-return/README.md +++ b/early-return/README.md @@ -1,17 +1,23 @@ +# Early Return + This sample demonstrates how to use the "Early Return" pattern via update-with-start. -The "Early Return" pattern involves using update-with-start to start a Workflow and send an Update in the -first Workflow Task. The Update handler waits until the Workflow reaches a certain state of interest, and then -returns some data to the caller. The Workflow continues to execute in the background, and the caller has -possession of a `WorkflowHandle` to follow up on the Workflow progress. +The "Early Return" pattern involves using update-with-start to start a Workflow and send an Update +in the first Workflow Task. The Update handler waits until the Workflow reaches a certain state of +interest, and then returns some data to the caller. The Workflow continues to execute in the background, +and the caller has possession of a `WorkflowHandle` to follow up on the Workflow progress. -In this example, the Workflow represents a financial transaction, and we use Early Return to wait until the -transaction has been confirmed, leaving the Workflow to complete the remaining stages of the transaction in -the background. +In this example, the Workflow represents a financial transaction, and we use Early Return to wait +until the transaction has been confirmed, leaving the Workflow to complete the remaining stages of +the transaction in the background. ### Running this sample -1. `pnpm install` to install dependencies. -1. Run a Temporal Server via `temporal server start-dev --dynamic-config-value frontend.enableExecuteMultiOperation=true`, using at least version `v1.1.2` of the `temporal` CLI. -1. `pnpm run start.watch` to start the Worker. -1 `pnpm run workflow tx-abc123` to run a transaction workflow, obtaining an "early return" via Update-With-Start. +1. Start a Temporal Server via: + ``` + temporal server start-dev --dynamic-config-value frontend.enableExecuteMultiOperation=true + ``` + Update-with-Start requires version `v1.1.2` or later of the `temporal` CLI. +2. `npm install` to install dependencies (or `pnpm` or `yarn`). +3. `npm run start.watch` to start the Worker. +4 `npm run workflow tx-abc123` to run a transaction workflow, obtaining an "early return" via Update-With-Start. diff --git a/early-return/package.json b/early-return/package.json index a96b9e87..c587bdee 100644 --- a/early-return/package.json +++ b/early-return/package.json @@ -5,6 +5,8 @@ "scripts": { "build": "tsc --build", "build.watch": "tsc --build --watch", + "format": "prettier --write .", + "format:check": "prettier --check .", "lint": "eslint .", "start": "ts-node src/worker.ts", "start.watch": "nodemon src/worker.ts", @@ -21,15 +23,15 @@ ] }, "dependencies": { - "@temporalio/activity": "file:~/src/temporalio/sdk-typescript/packages/activity", - "@temporalio/client": "file:~/src/temporalio/sdk-typescript/packages/client", - "@temporalio/worker": "file:~/src/temporalio/sdk-typescript/packages/worker", - "@temporalio/workflow": "file:~/src/temporalio/sdk-typescript/packages/workflow", + "@temporalio/activity": "^1.11.6", + "@temporalio/client": "^1.11.6", + "@temporalio/worker": "^1.11.6", + "@temporalio/workflow": "^1.11.6", "async-mutex": "^0.5.0", "nanoid": "3.x" }, "devDependencies": { - "@temporalio/testing": "file:~/src/temporalio/sdk-typescript/packages/testing", + "@temporalio/testing": "^1.11.6", "@tsconfig/node18": "^18.2.4", "@types/mocha": "8.x", "@types/node": "^22.9.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 40855644..bb8f3f27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -496,17 +496,17 @@ importers: early-return: dependencies: '@temporalio/activity': - specifier: file:~/src/temporalio/sdk-typescript/packages/activity - version: file:../sdk-typescript/packages/activity + specifier: ^1.11.6 + version: 1.11.6 '@temporalio/client': - specifier: file:~/src/temporalio/sdk-typescript/packages/client - version: file:../sdk-typescript/packages/client + specifier: ^1.11.6 + version: 1.11.6 '@temporalio/worker': - specifier: file:~/src/temporalio/sdk-typescript/packages/worker - version: file:../sdk-typescript/packages/worker(@swc/helpers@0.5.15) + specifier: ^1.11.6 + version: 1.11.6(@swc/helpers@0.5.15) '@temporalio/workflow': - specifier: file:~/src/temporalio/sdk-typescript/packages/workflow - version: file:../sdk-typescript/packages/workflow + specifier: ^1.11.6 + version: 1.11.6 async-mutex: specifier: ^0.5.0 version: 0.5.0 @@ -515,8 +515,8 @@ importers: version: 3.3.8 devDependencies: '@temporalio/testing': - specifier: file:~/src/temporalio/sdk-typescript/packages/testing - version: file:../sdk-typescript/packages/testing(@swc/helpers@0.5.15) + specifier: ^1.11.6 + version: 1.11.6(@swc/helpers@0.5.15) '@tsconfig/node18': specifier: ^18.2.4 version: 18.2.4 @@ -5411,31 +5411,15 @@ packages: '@temporalio/activity@1.11.6': resolution: {integrity: sha512-sEXB8wTmb5Jz02rh0sEIgT7eGhc68ASY0ccmJUCSgETVUzm+KsUszZygCaTImN6Zmpr1yIcoJ9+AQ3MTzUP/hg==} - '@temporalio/activity@file:../sdk-typescript/packages/activity': - resolution: {directory: ../sdk-typescript/packages/activity, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/client@1.11.6': resolution: {integrity: sha512-UxzX700i4AROxS9YIXK074A53wSuujoeIRnRxs7uVOdgzu8pLf30Wk+ZDq+ty6IeHA60qsTcZRs+PlBHqeuMUA==} - '@temporalio/client@file:../sdk-typescript/packages/client': - resolution: {directory: ../sdk-typescript/packages/client, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/common@1.11.6': resolution: {integrity: sha512-7yjHpJeDbVcqa2rk6spHTVhNob/oCXXrInZPSov9i2Pa0VElquiWpx8d9pJ8sATuxpBpvozNmTEnGWgNEI+G6w==} - '@temporalio/common@file:../sdk-typescript/packages/common': - resolution: {directory: ../sdk-typescript/packages/common, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/core-bridge@1.11.6': resolution: {integrity: sha512-6C+eOFKzs8SJ1q2t6a1HyIVj3E8YLC3k9u3n6doxrGo+d/QxJhs/3tJgW6cwFEKY1tdCNGR/gVM+BwvffLqykQ==} - '@temporalio/core-bridge@file:../sdk-typescript/packages/core-bridge': - resolution: {directory: ../sdk-typescript/packages/core-bridge, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/interceptors-opentelemetry@1.11.6': resolution: {integrity: sha512-/HjWnDeUq3E8Dp3dm+JxdS8VDG0jc7JvjZEJknaV3+w8j4NErlSS4whu6SJdjk7hEbVZCbSCK7Qnz1IklYifwQ==} peerDependencies: @@ -5456,32 +5440,16 @@ packages: '@temporalio/proto@1.11.6': resolution: {integrity: sha512-N9qnyNabiY2LySft4fBrMCBNRoxbmADMdpP9+CX8RSVCHVLlf32FzkTUTFwZX1dOU+g2JsYrUzHFEBOPBpD8dQ==} - '@temporalio/proto@file:../sdk-typescript/packages/proto': - resolution: {directory: ../sdk-typescript/packages/proto, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/testing@1.11.6': resolution: {integrity: sha512-Vsxd7d6cO2CbjyLDezWUdaQUb0uXRZbUb7i7O4ALZ64yXX8FdYTn3IYmihNunjD1Eb3I1zu8yv+DhA9TMJce6w==} - '@temporalio/testing@file:../sdk-typescript/packages/testing': - resolution: {directory: ../sdk-typescript/packages/testing, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/worker@1.11.6': resolution: {integrity: sha512-Y8ccZBN0c4KLe06DfWbw1Is11y2ENuN+oQvrl9Tw66OGCRLE1Kk08m59iQrWiehiXYzW1DRQG4IHlMjv0Tl8Rg==} engines: {node: '>= 16.0.0'} - '@temporalio/worker@file:../sdk-typescript/packages/worker': - resolution: {directory: ../sdk-typescript/packages/worker, type: directory} - engines: {node: '>= 18.0.0'} - '@temporalio/workflow@1.11.6': resolution: {integrity: sha512-WxPxjTJccP0tD5FwAQjdXZfqx6s5eYaBGgN9+VkMAEeW1KRfYs6dkaUj4qzzu5sN95zr71Euohk/sJG2jd3efQ==} - '@temporalio/workflow@file:../sdk-typescript/packages/workflow': - resolution: {directory: ../sdk-typescript/packages/workflow, type: directory} - engines: {node: '>= 18.0.0'} - '@testing-library/dom@7.31.2': resolution: {integrity: sha512-3UqjCpey6HiTZT92vODYLPxTBWlM8ZOOjr3LX5F37/VRipW2M1kX6I/Cm4VXzteZqfGfagg8yXywpcOgQBlNsQ==} engines: {node: '>=10'} @@ -16027,11 +15995,6 @@ snapshots: '@temporalio/common': 1.11.6 abort-controller: 3.0.0 - '@temporalio/activity@file:../sdk-typescript/packages/activity': - dependencies: - '@temporalio/common': file:../sdk-typescript/packages/common - abort-controller: 3.0.0 - '@temporalio/client@1.11.6': dependencies: '@grpc/grpc-js': 1.12.4 @@ -16041,15 +16004,6 @@ snapshots: long: 5.2.3 uuid: 9.0.1 - '@temporalio/client@file:../sdk-typescript/packages/client': - dependencies: - '@grpc/grpc-js': 1.12.4 - '@temporalio/common': file:../sdk-typescript/packages/common - '@temporalio/proto': file:../sdk-typescript/packages/proto - abort-controller: 3.0.0 - long: 5.2.3 - uuid: 9.0.1 - '@temporalio/common@1.11.6': dependencies: '@temporalio/proto': 1.11.6 @@ -16057,13 +16011,6 @@ snapshots: ms: 3.0.0-canary.1 proto3-json-serializer: 2.0.2 - '@temporalio/common@file:../sdk-typescript/packages/common': - dependencies: - '@temporalio/proto': file:../sdk-typescript/packages/proto - long: 5.2.3 - ms: 3.0.0-canary.1 - proto3-json-serializer: 2.0.2 - '@temporalio/core-bridge@1.11.6': dependencies: '@temporalio/common': 1.11.6 @@ -16071,13 +16018,6 @@ snapshots: cargo-cp-artifact: 0.1.9 which: 4.0.0 - '@temporalio/core-bridge@file:../sdk-typescript/packages/core-bridge': - dependencies: - '@temporalio/common': file:../sdk-typescript/packages/common - arg: 5.0.2 - cargo-cp-artifact: 0.1.9 - which: 4.0.0 - '@temporalio/interceptors-opentelemetry@1.11.6(@temporalio/activity@1.11.6)(@temporalio/client@1.11.6)(@temporalio/common@1.11.6)(@temporalio/worker@1.11.6(@swc/helpers@0.5.15))(@temporalio/workflow@1.11.6)': dependencies: '@opentelemetry/api': 1.9.0 @@ -16109,11 +16049,6 @@ snapshots: long: 5.2.3 protobufjs: 7.4.0 - '@temporalio/proto@file:../sdk-typescript/packages/proto': - dependencies: - long: 5.2.3 - protobufjs: 7.4.0 - '@temporalio/testing@1.11.6(@swc/helpers@0.5.15)': dependencies: '@temporalio/activity': 1.11.6 @@ -16130,22 +16065,6 @@ snapshots: - uglify-js - webpack-cli - '@temporalio/testing@file:../sdk-typescript/packages/testing(@swc/helpers@0.5.15)': - dependencies: - '@temporalio/activity': file:../sdk-typescript/packages/activity - '@temporalio/client': file:../sdk-typescript/packages/client - '@temporalio/common': file:../sdk-typescript/packages/common - '@temporalio/core-bridge': file:../sdk-typescript/packages/core-bridge - '@temporalio/proto': file:../sdk-typescript/packages/proto - '@temporalio/worker': file:../sdk-typescript/packages/worker(@swc/helpers@0.5.15) - '@temporalio/workflow': file:../sdk-typescript/packages/workflow - abort-controller: 3.0.0 - transitivePeerDependencies: - - '@swc/helpers' - - esbuild - - uglify-js - - webpack-cli - '@temporalio/worker@1.11.6(@swc/helpers@0.5.15)': dependencies: '@swc/core': 1.10.1(@swc/helpers@0.5.15) @@ -16171,41 +16090,11 @@ snapshots: - uglify-js - webpack-cli - '@temporalio/worker@file:../sdk-typescript/packages/worker(@swc/helpers@0.5.15)': - dependencies: - '@swc/core': 1.10.1(@swc/helpers@0.5.15) - '@temporalio/activity': file:../sdk-typescript/packages/activity - '@temporalio/client': file:../sdk-typescript/packages/client - '@temporalio/common': file:../sdk-typescript/packages/common - '@temporalio/core-bridge': file:../sdk-typescript/packages/core-bridge - '@temporalio/proto': file:../sdk-typescript/packages/proto - '@temporalio/workflow': file:../sdk-typescript/packages/workflow - abort-controller: 3.0.0 - heap-js: 2.5.0 - memfs: 4.15.0 - rxjs: 7.8.1 - source-map: 0.7.4 - source-map-loader: 4.0.2(webpack@5.96.1(@swc/core@1.10.1(@swc/helpers@0.5.15))) - supports-color: 8.1.1 - swc-loader: 0.2.6(@swc/core@1.10.1(@swc/helpers@0.5.15))(webpack@5.96.1(@swc/core@1.10.1(@swc/helpers@0.5.15))) - unionfs: 4.5.4 - webpack: 5.96.1(@swc/core@1.10.1(@swc/helpers@0.5.15)) - transitivePeerDependencies: - - '@swc/helpers' - - esbuild - - uglify-js - - webpack-cli - '@temporalio/workflow@1.11.6': dependencies: '@temporalio/common': 1.11.6 '@temporalio/proto': 1.11.6 - '@temporalio/workflow@file:../sdk-typescript/packages/workflow': - dependencies: - '@temporalio/common': file:../sdk-typescript/packages/common - '@temporalio/proto': file:../sdk-typescript/packages/proto - '@testing-library/dom@7.31.2': dependencies: '@babel/code-frame': 7.26.2