Skip to content

Commit 77b8cb2

Browse files
committed
Add class registering way
1 parent c2221f6 commit 77b8cb2

6 files changed

Lines changed: 421 additions & 256 deletions

File tree

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
22
createSdk,
33
HerculesActionProjectConfiguration,
4-
HerculesFunctionContext,
5-
RuntimeErrorException
4+
HerculesFunctionContext, Identifier, LinkedDataTypeIdentifiers,
5+
RuntimeErrorException, RuntimeParameter, Signature
66
} from "@code0-tech/hercules";
77

88
const sdk = createSdk({
@@ -22,33 +22,29 @@ sdk.registerDataTypes({
2222
type: "any",
2323
})
2424

25-
sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions({
26-
definition: {
27-
signature: "(number: number) => number",
28-
parameters: [
29-
{
30-
runtimeName: "number",
31-
defaultValue: 20,
32-
}
33-
],
34-
runtimeName: "fib",
35-
},
36-
//This param is optional and can be omitted
37-
handler: (context: HerculesFunctionContext, number: bigint): bigint => {
38-
console.log(context)
39-
console.log("Project id:", context.projectId);
40-
console.log("Execution id:", context.executionId);
41-
console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution
42-
43-
function fibonacci(num: bigint): bigint {
44-
if (num <= 1) return num;
45-
return fibonacci(num - 1n) + fibonacci(num - 2n);
46-
}
25+
@Identifier("fib")
26+
@Signature("(number: number) => number")
27+
@RuntimeParameter({
28+
runtimeName: "number",
29+
defaultValue: 20
30+
})
31+
class FibonacciFunction {
32+
run(context: HerculesFunctionContext, number: number): number {
33+
console.log(context)
34+
console.log("Project id:", context.projectId);
35+
console.log("Execution id:", context.executionId);
36+
console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution
4737

48-
return fibonacci(number)
38+
function fibonacci(num: number): number {
39+
if (num <= 1) return num;
40+
return fibonacci(num - 1) + fibonacci(num - 2);
4941
}
42+
43+
return fibonacci(number)
5044
}
51-
)
45+
}
46+
47+
sdk.registerRuntimeFunctionDefinitionClass(FibonacciFunction)
5248

5349
sdk.registerFlowTypes(
5450
{

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

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)