feat: wrap aqua api (#807)

This commit is contained in:
shamsartem
2023-08-09 16:32:27 +02:00
committed by GitHub
parent a5e9354aeb
commit c7fca40f67
10 changed files with 582 additions and 190 deletions

View File

@ -1,32 +1,20 @@
import {
Aqua,
Call,
Path,
} from "@fluencelabs/aqua-api/aqua-api.js";
//@ts-check
const aquaPath = new Path("test.aqua")
// write function that we want to call and arguments
const args = {num: 42}
const call = new Call("getNumber(num)", args, aquaPath)
import { compileAquaCallFromPath } from '@fluencelabs/aqua-api'
// compile call
const compilationResult = await Aqua.compile(call, [])
const compilationResult = await compileAquaCallFromPath({
filePath: 'test.aqua',
data: { num: 3 },
funcCall: 'getNumber(num)',
})
const {
errors,
functionCall: { funcDef, script },
functions,
generatedSources,
services,
} = compilationResult
/*
// Compilation result definition
export class CompilationResult {
// List of service definitions to register in Fluence JS Client
services: Record<string, ServiceDef>
// List of function definitions to call in Fluence JS Client
functions: Record<string, AquaFunction>
// Definition of wrapped function to call in Fluence JS Client
functionCall?: AquaFunction
// List of errors. All other fields will be empty if `errors` not empty
errors: string[]
}
*/
// get function definition, that describes types of arguments and results of a function
// and AIR script
const {funcDef, script} = compilationResult.functionCall
console.log(script)