Logic Context - JS/TS
A logic context object would be passed to LOC logic during execution, which contains the following important data:
- Task and execution metadata
- Trigger payload
Logic Type | Available |
---|---|
Generic logic | ✅ |
Aggregator logic | ✅ |
Import and Usage
The run
and handleError
function in a logic, which will be invoked by LOC runtime during execution, should receive a ctx
argument:
- JavaScript
- TypeScript
/** @param {import('@fstnetwork/loc-logic-sdk').GenericContext} ctx */
export async function run(ctx) {
// ctx is the data context
}
/**
* @param {import('@fstnetwork/loc-logic-sdk').GenericContext} ctx
* @param {import('@fstnetwork/loc-logic-sdk').RailwayError} error
*/
export async function handleError(ctx, error) {
// ctx is the data context
}
import {
GenericContext, // or AggregatorContext for aggregator logic
RailwayError,
} from "@fstnetwork/loc-logic-sdk";
export async function run(ctx: GenericContext) {
// ctx is the data context
}
export async function handleError(ctx: GenericContext, error: RailwayError) {
// ctx is the data context
}
For the error
argument, see Logic Error for details.
Class Reference
Type
Logic Type | Context Type |
---|---|
Generic | GenericContext |
Aggregator | AggregatorContext |
Both importable from
@fstnetwork/loc-logic-sdk
Properties
Property | Type | Description |
---|---|---|
task | Task | Return the Task object (lazy loaded) |
Refer to: Task
Method: Load Payload
async payload(): Promise<Payload>
Return the trigger payload (lazy loaded).
Refer to: Payload
Examples
// get task and execution metadata
const task = ctx.task;
// get payload
const payload = await ctx.payload();