Introduction
LOC SDK is a downloadable NPM package that defines the interfaces of data context as well as agents - a series of features provided by LOC's logic runtime that can read and/or write internal and external storages.
The data context contains the following features:
The following agents can be imported:
- Session Storage
- Local Storage
- Event Store
- Result
- Logging
- Local Variable
- HTTP
- Database
- File Storage
This section is currently based on SDK v0.7.0
.
Supported logic code languages/version:
- JavaScript
ES6/ES2015
and above - TypeScript
3.7.0
and above
See Install SDK for installing SDK in CLI projects.
Some of the agents require agent configuration. See tutorial or CLI Handbook for details.
How to Import Agents
From v0.7.0
all logic have to explicitly import agents and related classes from LOC SDK using ECMAScript 6 imports. Below is a short demostration:
If you are using LOC Studio, the imports will be automatically added in the code blocks.
- JavaScript
- TypeScript
import {
SessionStorageAgent,
EventAgent,
LoggingAgent,
} from "@fstnetwork/loc-logic-sdk";
export async function run(ctx) {
const data = await SessionStorageAgent.get("data");
const events = [
{
labelName: data.label,
sourceDID: data.source,
targetDID: data.target,
meta: "",
type: "default",
},
];
await EventAgent.emit(events);
}
export async function handleError(ctx, error) {
LoggingAgent.error(error.message);
}
import { GenericContext, RailwayError } from "@fstnetwork/loc-logic-sdk";
import {
SessionStorageAgent,
EventAgent,
Event,
LoggingAgent,
} from "@fstnetwork/loc-logic-sdk";
interface MyEventSchema {
label: string;
source: string;
target: string;
}
export async function run(ctx: GenericContext) {
const data = (await SessionStorageAgent.get("data")) as MyEventSchema;
const events: Event.Event[] = [
{
labelName: data.label,
sourceDID: data.source,
targetDID: data.target,
meta: "",
type: "default",
},
];
await EventAgent.emit(events);
}
export async function handleError(ctx: GenericContext, error: RailwayError) {
LoggingAgent.error(error.message);
}
Agent Configuration
Four of the agents - HTTP, database, file storage and mail - requires agent configuration to connect external data sources. You can set them either via Studio or CLI.