-
Notifications
You must be signed in to change notification settings - Fork 148
Add SANO sample #474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VegetarianOrc
wants to merge
12
commits into
main
Choose a base branch
from
amazzeo/sano-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add SANO sample #474
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e1ad71b
Add SANO sample
VegetarianOrc e3b809a
pre-push hook
VegetarianOrc eef3ebe
Use temporal operation handler
VegetarianOrc 7f717df
run formatter, fix linter, upgrade nanoid
VegetarianOrc 86ada50
more broadly upgrade nanoid
VegetarianOrc e235eaf
Upgrade mocha to remove vulnerable nanoid dependency
VegetarianOrc 0cf1b07
Update nexus-standalone-operations/src/mocha/nexus-standalone-operati…
VegetarianOrc 04274f1
Add getting a handle to an existing operation
VegetarianOrc 562615a
Run formatter
VegetarianOrc 03f96a0
PR feedback
VegetarianOrc 31d3823
Update to 1.18.1
VegetarianOrc 0119b1f
run pnpm install from root
VegetarianOrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules | ||
| lib | ||
| .eslintrc.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| const { builtinModules } = require('module'); | ||
|
|
||
| const ALLOWED_NODE_BUILTINS = new Set(['assert']); | ||
|
|
||
| module.exports = { | ||
| root: true, | ||
| parser: '@typescript-eslint/parser', | ||
| parserOptions: { | ||
| project: './tsconfig.json', | ||
| tsconfigRootDir: __dirname, | ||
| }, | ||
| plugins: ['@typescript-eslint', 'deprecation'], | ||
| extends: [ | ||
| 'eslint:recommended', | ||
| 'plugin:@typescript-eslint/eslint-recommended', | ||
| 'plugin:@typescript-eslint/recommended', | ||
| 'prettier', | ||
| ], | ||
| rules: { | ||
| // recommended for safety | ||
| '@typescript-eslint/no-floating-promises': 'error', // forgetting to await Activities and Workflow APIs is bad | ||
| 'deprecation/deprecation': 'warn', | ||
|
|
||
| // code style preference | ||
| 'object-shorthand': ['error', 'always'], | ||
|
|
||
| // relaxed rules, for convenience | ||
| '@typescript-eslint/no-unused-vars': [ | ||
| 'warn', | ||
| { | ||
| argsIgnorePattern: '^_', | ||
| varsIgnorePattern: '^_', | ||
| }, | ||
| ], | ||
| '@typescript-eslint/no-explicit-any': 'off', | ||
| }, | ||
| overrides: [ | ||
| { | ||
| files: ['src/workflows.ts', 'src/workflows-*.ts', 'src/workflows/*.ts'], | ||
| rules: { | ||
| 'no-restricted-imports': [ | ||
| 'error', | ||
| ...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]), | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lib | ||
| node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package-lock=false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| To begin development, install the Temporal CLI: | ||
|
|
||
| Mac: {cyan brew install temporal} | ||
| Other: Download and extract the latest release from https://github.com/temporalio/cli/releases/latest | ||
|
|
||
| Start Temporal Server: | ||
|
|
||
| {cyan temporal server start-dev} | ||
|
|
||
| Use Node version 18+ (v22.x is recommended): | ||
|
|
||
| Mac: {cyan brew install node@22} | ||
| Other: https://nodejs.org/en/download/ | ||
|
|
||
| Then, in the project directory, using two other shells, run these commands: | ||
|
|
||
| {cyan npm run start.watch} | ||
| {cyan npm run workflow} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| printWidth: 120 | ||
| singleQuote: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Nexus Standalone Operations | ||
|
|
||
| This sample demonstrates how to execute Nexus Operations directly from client code, without wrapping them in a caller Workflow. It shows both synchronous and workflow-backed Operations, plus listing and counting standalone Nexus Operation executions. | ||
|
|
||
| ### Temporal Typescript SDK support for Standalone Nexus Operations is at [Pre-release](https://docs.temporal.io/evaluate/development-production-features/release-stages#pre-release). | ||
|
|
||
| All APIs are experimental and may be subject to backwards-incompatible changes. | ||
|
|
||
| Standalone Nexus operations require a server version that supports this feature. Use the dev server build at https://github.com/temporalio/cli/releases/tag/v1.7.2-standalone-nexus-operations. | ||
|
|
||
| ## Structure | ||
|
|
||
| - `src/api.ts` - Defines the Nexus Service, including its input and output types. | ||
| - `src/service/handler.ts` - Implements the synchronous `echo` Operation and the workflow-backed `hello` Operation. | ||
| - `src/service/workflows.ts` - Defines the Workflow used by the `hello` Operation. | ||
| - `src/service/worker.ts` - Runs the Worker that hosts the Nexus Service handler. | ||
| - `src/starter.ts` - Executes standalone Nexus Operations from a Temporal Client. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| A Temporal dev server with the dynamic config flags required for standalone Nexus operations: | ||
|
|
||
| ```bash | ||
| temporal server start-dev \ | ||
| --dynamic-config-value "nexusoperation.enableStandalone=true" \ | ||
| --dynamic-config-value "history.enableChasmCallbacks=true" | ||
| ``` | ||
|
|
||
| ## Running the sample | ||
|
|
||
| 1. Install NPM dependencies: | ||
|
|
||
| ```sh | ||
| npm install # or `pnpm` or `yarn` | ||
| ``` | ||
|
|
||
| 2. Create the Nexus endpoint: | ||
|
|
||
| ```sh | ||
| temporal operator nexus endpoint create \ | ||
| --name nexus-standalone-operations-endpoint \ | ||
| --target-namespace default \ | ||
| --target-task-queue nexus-standalone-operations | ||
| ``` | ||
|
|
||
| 3. In one shell, start the Worker: | ||
|
|
||
| ```sh | ||
| npm run worker | ||
| ``` | ||
|
|
||
| 4. In another shell, execute the sample: | ||
|
|
||
| ```sh | ||
| npm run starter | ||
| ``` | ||
|
|
||
| Example output: | ||
|
|
||
| ``` | ||
| Echo result: hello | ||
| Echo result from existing operation handle: hello | ||
|
|
||
| Started myNexusService.hello. Operation ID: hello-... | ||
| myNexusService.hello result: Hello, World! | ||
|
|
||
| Listing Nexus operations: | ||
| Operation ID: hello-..., Operation: hello, Status: COMPLETED | ||
| Operation ID: echo-..., Operation: echo, Status: COMPLETED | ||
|
|
||
| Total Nexus operations: 2 | ||
| ``` | ||
|
|
||
| If you run the starter multiple times, the listing and count will include additional Operations for the endpoint. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "name": "nexus-standalone-operations", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "build": "tsc --build", | ||
| "build.watch": "tsc --build --watch", | ||
| "format": "prettier --write .", | ||
| "format:check": "prettier --check .", | ||
| "lint": "eslint .", | ||
| "worker": "ts-node src/worker/worker.ts", | ||
| "worker.watch": "nodemon --watch src src/worker/worker.ts", | ||
| "starter": "ts-node src/starter.ts", | ||
| "test": "mocha --exit --require ts-node/register --require source-map-support/register src/mocha/*.test.ts" | ||
| }, | ||
| "nodemonConfig": { | ||
| "execMap": { | ||
| "ts": "ts-node" | ||
| }, | ||
| "ext": "ts", | ||
| "watch": [ | ||
| "src" | ||
| ] | ||
| }, | ||
| "dependencies": { | ||
| "@temporalio/client": "1.18.1", | ||
| "@temporalio/envconfig": "1.18.1", | ||
| "@temporalio/nexus": "1.18.1", | ||
| "@temporalio/worker": "1.18.1", | ||
| "@temporalio/workflow": "1.18.1", | ||
| "nanoid": "~3.3.12", | ||
| "nexus-rpc": "^0.0.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@temporalio/testing": "1.18.1", | ||
| "@tsconfig/node22": "^22.0.0", | ||
| "@types/mocha": "10.x", | ||
| "@types/node": "^22.9.1", | ||
| "@typescript-eslint/eslint-plugin": "^8.18.0", | ||
| "@typescript-eslint/parser": "^8.18.0", | ||
| "eslint": "^8.57.1", | ||
| "eslint-config-prettier": "^9.1.0", | ||
| "eslint-plugin-deprecation": "^3.0.0", | ||
| "mocha": "10.x", | ||
| "nodemon": "^3.1.7", | ||
| "prettier": "^3.4.2", | ||
| "source-map-support": "^0.5.21", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.6.3" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as nexus from 'nexus-rpc'; | ||
|
|
||
| export const myNexusService = nexus.service('myNexusService', { | ||
| echo: nexus.operation<EchoInput, EchoOutput>(), | ||
| hello: nexus.operation<HelloInput, HelloOutput>(), | ||
| }); | ||
|
|
||
| export interface EchoInput { | ||
| message: string; | ||
| } | ||
|
|
||
| export interface EchoOutput { | ||
| message: string; | ||
| } | ||
|
|
||
| export interface HelloInput { | ||
| name: string; | ||
| } | ||
|
|
||
| export interface HelloOutput { | ||
| greeting: string; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.