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
48 changes: 22 additions & 26 deletions ts/examples/simple-example-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
createSdk,
HerculesActionProjectConfiguration,
HerculesFunctionContext,
RuntimeErrorException
HerculesFunctionContext, Identifier, LinkedDataTypeIdentifiers,
RuntimeErrorException, RuntimeParameter, Signature
} from "@code0-tech/hercules";

const sdk = createSdk({
Expand All @@ -22,33 +22,29 @@ sdk.registerDataTypes({
type: "any",
})

sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions({
definition: {
signature: "(number: number) => number",
parameters: [
{
runtimeName: "number",
defaultValue: 20,
}
],
runtimeName: "fib",
},
//This param is optional and can be omitted
handler: (context: HerculesFunctionContext, number: bigint): bigint => {
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: bigint): bigint {
if (num <= 1) return num;
return fibonacci(num - 1n) + fibonacci(num - 2n);
}
@Identifier("fib")
@Signature("(number: number) => number")
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.

The signature is wrong here and not valid.

Suggested change
@Signature("(number: number) => number")
@Signature("(number: number): number")

@RuntimeParameter({
runtimeName: "number",
defaultValue: 20
})
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

return fibonacci(number)
function fibonacci(num: number): number {
if (num <= 1) return num;
return fibonacci(num - 1) + fibonacci(num - 2);
}

return fibonacci(number)
}
)
}

sdk.registerRuntimeFunctionDefinitionClass(FibonacciFunction)

sdk.registerFlowTypes(
{
Expand Down
19 changes: 13 additions & 6 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.

Loading