Skip to content
Merged
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
46 changes: 22 additions & 24 deletions ts/examples/simple-example-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import {

const sdk = createSdk({
authToken: "token",
aquilaUrl: "127.0.0.1:50051",
actionId: "service",
aquilaUrl: "127.0.0.1:8081",
actionId: "example",
version: "0.0.0",
}, [
{
type: "LIST<STRING>",
linkedDataTypes: ["STRING", "LIST"],
type: "string[]",
identifier: "config_discord_bot_token",
}
])
Expand All @@ -25,38 +24,35 @@ sdk.registerDataTypes({

sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions({
definition: {
signature: "(n: NUMBER) => NUMBER",
linkedDataTypes: ["NUMBER"],
signature: "(number: number) => number",
parameters: [
{
runtimeName: "n",
runtimeName: "number",
defaultValue: 20,
}
],
runtimeName: "fib",
},
//This param is optional and can be omitted
handler: (context: HerculesFunctionContext, n: 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);
}

throw new RuntimeErrorException("ERROR_CALCULATING_FIB", "An error occurred while calculating the Fibonacci number.");
//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);
}

return fibonacci(number)
}
}
)

sdk.registerFlowTypes(
{
signature: "(): TEXT",
linkedDataTypes: ["TEXT"],
signature: "(): string",
editable: false,
identifier: "test_flow",
}
Expand All @@ -68,11 +64,13 @@ 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((_error) => {
console.error("Error connecting SDK:");
}).catch(() => {
// will be handled by logger internally
process.exit(1)
})

sdk.onError((error) => {
Expand Down
Loading