Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ts/.gitignore
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
4 changes: 4 additions & 0 deletions ts/examples/simple-example-ts/example.env
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
83 changes: 0 additions & 83 deletions ts/examples/simple-example-ts/index.ts

This file was deleted.

25 changes: 16 additions & 9 deletions ts/examples/simple-example-ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ts/examples/simple-example-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"type": "module",
"main": "index.js",
"scripts": {
"build": "tsc -p tsconfig.json",
"dev": "cd ../.. && npm install && npm run build && npm pack && cd examples/simple-example-ts && npm install ../../code0-tech-hercules-0.0.0.tgz && npx tsx index.ts"
"build": "vite build .",
"start": "cd ../.. && npm install && npm run build && npm pack && cd examples/simple-example-ts && npm install && npm run build && node dist/index.js"
},
"dependencies": {
"@code0-tech/hercules": "file:../../code0-tech-hercules-0.0.0.tgz"
Expand Down
6 changes: 6 additions & 0 deletions ts/examples/simple-example-ts/src/exampleDataType.ts
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",
}
7 changes: 7 additions & 0 deletions ts/examples/simple-example-ts/src/exampleEventType.ts
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",
}
23 changes: 23 additions & 0 deletions ts/examples/simple-example-ts/src/fibonacciFunction.ts
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)
}
}
44 changes: 44 additions & 0 deletions ts/examples/simple-example-ts/src/index.ts
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)
})
}
7 changes: 5 additions & 2 deletions ts/examples/simple-example-ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
"baseUrl": ".",
"paths": {
"@code0-tech/hercules": ["../../ts"]
}
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"types": ["vite/client"]
},
"include": [
"index.ts"
"src/index.ts"
]
}
18 changes: 18 additions & 0 deletions ts/examples/simple-example-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'vite';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing in package.json

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

import { resolve } from 'path';

export default defineConfig({
build: {
target: "node18",
ssr: resolve(__dirname, 'src/index.ts'),
rollupOptions: {
external: (id) =>
[
'fs',
'path',
'typescript',
'@code0-tech/hercules'
].includes(id) || id.startsWith('node:')
}
}
});
Loading