11import {
22 createSdk ,
33 HerculesActionProjectConfiguration ,
4- HerculesFunctionContext ,
5- RuntimeErrorException
4+ HerculesFunctionContext , Identifier , LinkedDataTypeIdentifiers ,
5+ RuntimeErrorException , RuntimeParameter , Signature
66} from "@code0-tech/hercules" ;
77
88const 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
5349sdk . registerFlowTypes (
5450 {
0 commit comments