-
Notifications
You must be signed in to change notification settings - Fork 0
Add class registering way of registering stuff #21
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
Knerio
wants to merge
6
commits into
main
Choose a base branch
from
20-add-new-way-of-registering-functions
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77b8cb2
Add class registering way
Knerio 508fd70
Fix signature
Knerio 52d7868
Change tooling to vite build
Knerio 1e73962
Refactor Hercules interfaces to use HerculesTranslation for localization
Knerio 667265f
Refactor some code to make the structure clearer
Knerio 8719635
Apply some ideas of code review
Knerio 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| node_modules | ||
| dist | ||
| code0-tech-hercules-*.tgz | ||
| code0-tech-hercules-*.tgz | ||
| .env |
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,4 @@ | ||
| AUTH_TOKEN=your_auth_token_here | ||
| AQUILA_URL=https://127.0.0.1:8000 | ||
| ACTION_ID=your_action_id_here | ||
| VERSION=0.0.0 |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 @@ | ||
| import {HerculesDataType} from "@code0-tech/hercules"; | ||
|
|
||
| export const someDataType: HerculesDataType = { | ||
| identifier: "SOME_DATATYPE", | ||
| type: "any", | ||
| } |
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,7 @@ | ||
| import {HerculesEventType} from "@code0-tech/hercules" | ||
|
|
||
| export const someEventType: HerculesEventType = { | ||
| signature: "(): string", | ||
| editable: false, | ||
| identifier: "test_flow", | ||
| } |
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,23 @@ | ||
| import {HerculesFunctionContext, Identifier, RuntimeParameter, Signature} from "@code0-tech/hercules"; | ||
|
|
||
| @Identifier("fib") | ||
| @Signature("(number: number): number") | ||
| @RuntimeParameter({ | ||
| runtimeName: "number", | ||
| defaultValue: 20 | ||
| }) | ||
| export class FibonacciFunction { | ||
| run(context: HerculesFunctionContext, number: number): number { | ||
| console.log(context) | ||
| console.log("Project id:", context.projectId); | ||
| console.log("Execution id:", context.executionId); | ||
| console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution | ||
|
|
||
| function fibonacci(num: number): number { | ||
| if (num <= 1) return num; | ||
| return fibonacci(num - 1) + fibonacci(num - 2); | ||
| } | ||
|
|
||
| return fibonacci(number) | ||
| } | ||
| } |
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,44 @@ | ||
| import {createSdk, HerculesActionProjectConfiguration} from "@code0-tech/hercules"; | ||
| import {FibonacciFunction} from "./fibonacciFunction"; | ||
| import {someEventType} from "./exampleEventType"; | ||
| import {someDataType} from "./exampleDataType"; | ||
|
|
||
| const sdk = createSdk({ | ||
| authToken: process.env.AUTH_TOKEN || "token", | ||
| aquilaUrl: process.env.AQUILA_URL || "127.0.0.1:8081", | ||
| actionId: process.env.ACTION_ID || "example", | ||
| version: process.env.VERSION || "0.0.0", | ||
| }, [ | ||
| { | ||
| type: "string[]", | ||
| identifier: "EXAMPLE_CONFIG_IDENTIFIER", | ||
| } | ||
| ]) | ||
|
|
||
| sdk.registerDataTypes(someDataType) | ||
| sdk.registerRuntimeFunctionDefinitionClass(FibonacciFunction) | ||
| sdk.registerEventTypes(someEventType) | ||
|
|
||
|
|
||
| connectToSdk(); | ||
|
|
||
| function connectToSdk() { | ||
| sdk.connect().then((configs: HerculesActionProjectConfiguration[]) => { | ||
| console.log("SDK connected successfully"); | ||
|
|
||
| sdk.dispatchEvent("test_flow", configs[0].projectId, "Hello, World! Configs loaded: " + configs.length).then(() => { | ||
| console.log("Event dispatched successfully"); | ||
| }) | ||
| }).catch(() => { | ||
| // will be handled by logger internally | ||
| process.exit(1) | ||
| }) | ||
|
|
||
| sdk.onError((error) => { | ||
| console.error("SDK Error occurred:", error.message); | ||
| console.log("Attempting to reconnect in 5s..."); | ||
| setTimeout(() => { | ||
| connectToSdk(); | ||
| }, 5000) | ||
| }) | ||
| } |
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,18 @@ | ||
| import { defineConfig } from 'vite'; | ||
| import { resolve } from 'path'; | ||
|
|
||
| export default defineConfig({ | ||
| build: { | ||
| target: "node18", | ||
| ssr: resolve(__dirname, 'src/index.ts'), | ||
| rollupOptions: { | ||
Knerio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| external: (id) => | ||
| [ | ||
| 'fs', | ||
| 'path', | ||
| 'typescript', | ||
| '@code0-tech/hercules' | ||
| ].includes(id) || id.startsWith('node:') | ||
| } | ||
| } | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing in package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?