Skip to content

Commit 8719635

Browse files
committed
Apply some ideas of code review
1 parent 667265f commit 8719635

File tree

15 files changed

+105
-118
lines changed

15 files changed

+105
-118
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
AUTH_TOKEN=your_auth_token_here
2+
AQUILA_URL=https://127.0.0.1:8000
3+
ACTION_ID=your_action_id_here
4+
VERSION=0.0.0

ts/examples/simple-example-ts/index.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

ts/examples/simple-example-ts/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {HerculesDataType} from "@code0-tech/hercules";
2+
3+
export const someDataType: HerculesDataType = {
4+
identifier: "SOME_DATATYPE",
5+
type: "any",
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {HerculesEventType} from "@code0-tech/hercules"
2+
3+
export const someEventType: HerculesEventType = {
4+
signature: "(): string",
5+
editable: false,
6+
identifier: "test_flow",
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {HerculesFunctionContext, Identifier, RuntimeParameter, Signature} from "@code0-tech/hercules";
2+
3+
@Identifier("fib")
4+
@Signature("(number: number): number")
5+
@RuntimeParameter({
6+
runtimeName: "number",
7+
defaultValue: 20
8+
})
9+
export class FibonacciFunction {
10+
run(context: HerculesFunctionContext, number: number): number {
11+
console.log(context)
12+
console.log("Project id:", context.projectId);
13+
console.log("Execution id:", context.executionId);
14+
console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution
15+
16+
function fibonacci(num: number): number {
17+
if (num <= 1) return num;
18+
return fibonacci(num - 1) + fibonacci(num - 2);
19+
}
20+
21+
return fibonacci(number)
22+
}
23+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {createSdk, HerculesActionProjectConfiguration} from "@code0-tech/hercules";
2+
import {FibonacciFunction} from "./fibonacciFunction";
3+
import {someEventType} from "./exampleEventType";
4+
import {someDataType} from "./exampleDataType";
5+
6+
const sdk = createSdk({
7+
authToken: process.env.AUTH_TOKEN || "token",
8+
aquilaUrl: process.env.AQUILA_URL || "127.0.0.1:8081",
9+
actionId: process.env.ACTION_ID || "example",
10+
version: process.env.VERSION || "0.0.0",
11+
}, [
12+
{
13+
type: "string[]",
14+
identifier: "EXAMPLE_CONFIG_IDENTIFIER",
15+
}
16+
])
17+
18+
sdk.registerDataTypes(someDataType)
19+
sdk.registerRuntimeFunctionDefinitionClass(FibonacciFunction)
20+
sdk.registerEventTypes(someEventType)
21+
22+
23+
connectToSdk();
24+
25+
function connectToSdk() {
26+
sdk.connect().then((configs: HerculesActionProjectConfiguration[]) => {
27+
console.log("SDK connected successfully");
28+
29+
sdk.dispatchEvent("test_flow", configs[0].projectId, "Hello, World! Configs loaded: " + configs.length).then(() => {
30+
console.log("Event dispatched successfully");
31+
})
32+
}).catch(() => {
33+
// will be handled by logger internally
34+
process.exit(1)
35+
})
36+
37+
sdk.onError((error) => {
38+
console.error("SDK Error occurred:", error.message);
39+
console.log("Attempting to reconnect in 5s...");
40+
setTimeout(() => {
41+
connectToSdk();
42+
}, 5000)
43+
})
44+
}

ts/examples/simple-example-ts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"types": ["vite/client"]
1818
},
1919
"include": [
20-
"index.ts"
20+
"src/index.ts"
2121
]
2222
}

ts/examples/simple-example-ts/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resolve } from 'path';
44
export default defineConfig({
55
build: {
66
target: "node18",
7-
ssr: resolve(__dirname, 'index.ts'), // ✅ correct SSR entry
7+
ssr: resolve(__dirname, 'src/index.ts'),
88
rollupOptions: {
99
external: (id) =>
1010
[

ts/src/action_sdk.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ActionTransferServiceClient, TransferRequest} from "@code0-tech/tucana/a
55
import {FlowTypeSetting,} from "@code0-tech/tucana/shared";
66
import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers";
77
import 'reflect-metadata';
8-
import {connect as connectHelper} from "./sdk/connection/connection";
8+
import {connect} from "./sdk/connection/connection";
99
import {registerFunctionDefinitionClass} from "./sdk/builder/registerFunctionDefinitionClass";
1010
import {registerRuntimeFunctionDefinitionClass} from "./builder/registerRuntimeFunctionDefinitionClass";
1111

@@ -52,7 +52,7 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
5252
state.stream?.responses.onError(handler)
5353
},
5454
connect: options => {
55-
return connectHelper(state, config, options);
55+
return connect(state, config, options);
5656
},
5757
getProjectActionConfigurations: () => {
5858
return state.projectConfigurations.map(value => {
@@ -97,14 +97,14 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
9797
linkedDataTypeIdentifiers: dataType.linkedDataTypes || [],
9898
displayMessage: dataType.displayMessage || [],
9999
definitionSource: "action",
100-
version: dataType.version || config.version,
100+
version: config.version,
101101
});
102102
})
103103

104104

105105
return Promise.resolve()
106106
},
107-
registerFlowTypes: async (...flowTypes) => {
107+
registerEventTypes: async (...flowTypes) => {
108108
flowTypes.forEach(flowType => {
109109
state.flowTypes.push({
110110
signature: flowType.signature,
@@ -116,7 +116,7 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
116116
displayMessage: flowType.displayMessage || [],
117117
documentation: flowType.documentation || [],
118118
definitionSource: "action",
119-
version: flowType.version || config.version,
119+
version: config.version,
120120
linkedDataTypeIdentifiers: flowType.linkedDataTypes || [],
121121
settings: (flowType.settings || []).map(setting => ({
122122
name: setting.name || [],
@@ -146,7 +146,7 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
146146
event: {
147147
projectId: projectIdBigInt,
148148
eventType: eventType,
149-
payload: constructValue(payload) || constructValue(null),
149+
payload: constructValue(payload || null),
150150
}
151151
}
152152
})
@@ -161,5 +161,5 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
161161

162162
export {
163163
createSdk,
164-
connectHelper as connect
164+
connect
165165
}

0 commit comments

Comments
 (0)