Skip to content

Commit

Permalink
chore: Aqua API example (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieMyst authored Feb 14, 2023
1 parent 3510845 commit 4119b7e
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
32 changes: 32 additions & 0 deletions api/aqua-api-example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Aqua,
Call,
Path,
} from "@fluencelabs/aqua-api/aqua-api.js";

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)

// compile call
const compilationResult = await Aqua.compile(call, [])


/*
// 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
21 changes: 21 additions & 0 deletions api/aqua-api-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions api/aqua-api-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "aqua-api-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"call": "node index.js"
},
"author": "Fluence Labs",
"type": "module",
"license": "Apache-2.0",
"dependencies": {
"@fluencelabs/aqua-api": "0.9.4"
}
}
4 changes: 4 additions & 0 deletions api/aqua-api-example/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Aqua API Example

An example of how to use Aqua API with Fluence Client.
Documentation and description [here](https://fluence.dev/docs/aqua-book/aqua-js-api).
2 changes: 2 additions & 0 deletions api/aqua-api-example/test.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func getNumber(number: u32) -> u32:
<- number
3 changes: 3 additions & 0 deletions api/aqua-api-npm/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Aqua API

[Documentation](https://fluence.dev/docs/aqua-book/aqua-js-api)
2 changes: 1 addition & 1 deletion api/aqua-api/src/main/scala/aqua/api/AquaAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ object AquaAPI extends App with Logging {

new FuncCompiler[IO](
Some(RelativePath(Path(pathStr))),
imports.toList.map(Path.apply),
imports.map(Path.apply),
transformConfig
).compile()
.map { contextV =>
Expand Down

0 comments on commit 4119b7e

Please sign in to comment.