Aqua JS API
Aqua JS API allows you to manage all aspects of Aqua development from your JS projects.
To install the Aqua API package:
sh
npm install --save @fluencelabs/aqua-api
sh
npm install --save @fluencelabs/aqua-api
API
API compiles high-level Aqua code into low-level AIR instructions that can be used with Fluence JS client to make peer-to-peer calls.
API has only one function:
typescript
export class Compiler {compile(input: Input | Path | Call, imports: string[], config?: AquaConfig): Promise<CompilationResult>;}
typescript
export class Compiler {compile(input: Input | Path | Call, imports: string[], config?: AquaConfig): Promise<CompilationResult>;}
where input can be:
- Aqua code as a string
typescript
export class Input {input: string}
typescript
export class Input {input: string}
- Path to
.aqua
file or directory with.aqua
files. - Note: paths must be absolute
typescript
export class Path {path: string}
typescript
export class Path {path: string}
- Information about a function that you want to call. It wraps aqua code to gather and print call result. Also, it checks correctness of arguments.
typescript
export class Call {functionCall: stringarguments: anyinput: Input | Path}
typescript
export class Call {functionCall: stringarguments: anyinput: Input | Path}
imports
is a path to files that is necessary for compilation but not needed to be compiled into AIR functions. More information here.config
is the followingAquaConfig
data structure
typescript
export class AquaConfig {// compiler log level. Default: infologLevel?: string// constants can be defined or overrided by this optionconstants?: string[]// switches off error bubbling to initiator. Default: falsenoXor?: boolean// switches off first hop to relay peer. Default: falsenoRelay?: boolean}
typescript
export class AquaConfig {// compiler log level. Default: infologLevel?: string// constants can be defined or overrided by this optionconstants?: string[]// switches off error bubbling to initiator. Default: falsenoXor?: boolean// switches off first hop to relay peer. Default: falsenoRelay?: boolean}
More info about overridable constants here.
Compilation result:
typescript
export class CompilationResult {// list of compiled services. Can be useful to create handlers for this servicesservices: Record<string, ServiceDef>// list of Aqua functionsfunctions: Record<string, AquaFunction>// information about function that is compiled with `Call` inputfunctionCall?: AquaFunction// list of compilation errors in Aqua code. If not empty, then compilation failed and other fields will be emptyerrors: string[]}
typescript
export class CompilationResult {// list of compiled services. Can be useful to create handlers for this servicesservices: Record<string, ServiceDef>// list of Aqua functionsfunctions: Record<string, AquaFunction>// information about function that is compiled with `Call` inputfunctionCall?: AquaFunction// list of compilation errors in Aqua code. If not empty, then compilation failed and other fields will be emptyerrors: string[]}
Usage example
https://github.com/fluencelabs/aqua/tree/main/api/aqua-api-example/