move examples, use index.ts as playground, update aqua-cli version

This commit is contained in:
DieMyst 2021-05-25 13:35:52 +03:00
parent bb728cb3b5
commit 4405f465d1
33 changed files with 220 additions and 184 deletions

View File

@ -18,10 +18,15 @@ To compile the aqua files execute
npm run compile-aqua npm run compile-aqua
``` ```
To start the program execute To start the `index.ts` execute
``` ```
npm run cli npm run run
```
To run all examples in `example` directory
```
npm run exec
``` ```
If everything works correctly logs without errors will be printed on a screen: If everything works correctly logs without errors will be printed on a screen:
@ -36,6 +41,8 @@ Aqua files are compiled into .ts located in `/src/compiled` directory.
Entry point to use aqua compiled files from TypeScript: `/src/index.ts` Entry point to use aqua compiled files from TypeScript: `/src/index.ts`
Code that call all examples and check results: `/src/run-examples.ts`
## References ## References
\- Documentation for the compiler can be found in the official repo: https://github.com/fluencelabs/aqua \- Documentation for the compiler can be found in the official repo: https://github.com/fluencelabs/aqua

6
package-lock.json generated
View File

@ -5,9 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@fluencelabs/aqua-cli": { "@fluencelabs/aqua-cli": {
"version": "0.1.1-105", "version": "0.1.1-110",
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.1-105.tgz", "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.1-110.tgz",
"integrity": "sha512-G5TFGzp9AW7oE4jsYOt5685LIFcteSg3uvMH1e6jqMqyAElQZJ1NReZ5cuLHy89x9fp4/kljTxVwra3J31QtrQ==", "integrity": "sha512-GZaZbzZiaJDFNJ23+AEMe2ezu/KId57pnADyu7FYIfdfRBU7JSGHFLxHqoYRAOp9ZGLLE8Ic+aA0etCME734Aw==",
"dev": true "dev": true
}, },
"@fluencelabs/aquamarine-interpreter": { "@fluencelabs/aquamarine-interpreter": {

View File

@ -17,12 +17,13 @@
], ],
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"exec": "node -r ts-node/register src/index.ts", "exec": "node -r ts-node/register src/run-examples.ts",
"run": "node -r ts-node/register src/index.ts",
"compile-aqua": "aqua-cli -i ./aqua/ -o ./src/compiled", "compile-aqua": "aqua-cli -i ./aqua/ -o ./src/compiled",
"compile-aqua:air": "aqua-cli -i ./aqua/ -o ./compiled-air -a" "compile-aqua:air": "aqua-cli -i ./aqua/ -o ./compiled-air -a"
}, },
"devDependencies": { "devDependencies": {
"@fluencelabs/aqua-cli": "^0.1.1-105", "@fluencelabs/aqua-cli": "^0.1.1-110",
"ts-node": "^9.1.1", "ts-node": "^9.1.1",
"typescript": "^4.2.4" "typescript": "^4.2.4"
}, },

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
@ -228,26 +228,26 @@ export async function doStuff(client: FluenceClient, a: string, b: string, c: bo
(seq (seq
(seq (seq
(seq (seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) (seq
(call %init_peer_id% ("getDataSrv" "a") [] a) (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "a") [] a)
)
(call %init_peer_id% ("getDataSrv" "b") [] b)
) )
(call %init_peer_id% ("getDataSrv" "b") [] b) (call %init_peer_id% ("getDataSrv" "c") [] c)
) )
(call %init_peer_id% ("getDataSrv" "c") [] c) (call %init_peer_id% ("getDataSrv" "d") [] d)
) )
(call %init_peer_id% ("getDataSrv" "d") [] d) (call %init_peer_id% ("getDataSrv" "e") [] e)
) )
(call %init_peer_id% ("getDataSrv" "e") [] e) (call %init_peer_id% ("getDataSrv" "g") [] g)
) )
(call %init_peer_id% ("getDataSrv" "g") [] g) (call %init_peer_id% ("getDataSrv" "str") [] str)
) )
(call %init_peer_id% ("getDataSrv" "str") [] str) (call %init_peer_id% ("some-id" "t") [str] $stream)
) )
(par (par
(par (call %init_peer_id% ("println-service-id" "print") [a])
(call %init_peer_id% ("some-id" "t") [str] $stream)
(call %init_peer_id% ("println-service-id" "print") [a])
)
(seq (seq
(seq (seq
(seq (seq

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,16 +3,17 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-SNAPSHOT * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable'; import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
export async function betterMessage(client: FluenceClient, relay: string): Promise<void> { export async function betterMessage(client: FluenceClient, relay: string): Promise<void> {
let request; let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => { const promise = new Promise<void>((resolve, reject) => {
request = new RequestFlowBuilder() request = new RequestFlowBuilder()
.disableInjections() .disableInjections()
@ -69,7 +70,7 @@ export async function betterMessage(client: FluenceClient, relay: string): Promi
}) })
.build(); .build();
}); });
await client.initiateFlow(request); await client.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]); return Promise.race([promise, Promise.resolve()]);
} }

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
@ -63,10 +63,10 @@ export async function parFunc(client: FluenceClient, node: string, c: (arg0: {ex
(xor (xor
(seq (seq
(seq (seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) (seq
(call %init_peer_id% ("getDataSrv" "node") [] node) (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
) (call %init_peer_id% ("getDataSrv" "node") [] node)
(par )
(par (par
(call %init_peer_id% ("parservice-id" "call") [] y) (call %init_peer_id% ("parservice-id" "call") [] y)
(seq (seq
@ -95,8 +95,8 @@ export async function parFunc(client: FluenceClient, node: string, c: (arg0: {ex
(call %init_peer_id% ("op" "identity") []) (call %init_peer_id% ("op" "identity") [])
) )
) )
(call %init_peer_id% ("parservice-id" "call") [] x)
) )
(call %init_peer_id% ("parservice-id" "call") [] x)
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
) )

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';

View File

@ -3,7 +3,7 @@
* This file is auto-generated. Do not edit manually: changes may be erased. * This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/. * Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues * If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.1.1-105 * Aqua version: 0.1.1-110
* *
*/ */
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
@ -24,46 +24,43 @@ export async function topologyTest(client: FluenceClient, me: string, myRelay: s
(seq (seq
(seq (seq
(seq (seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "me") [] me)
)
(call %init_peer_id% ("getDataSrv" "myRelay") [] myRelay)
)
(call %init_peer_id% ("getDataSrv" "friend") [] friend)
)
(call %init_peer_id% ("getDataSrv" "friendRelay") [] friendRelay)
)
(par
(seq (seq
(seq (seq
(seq (seq
(seq (seq
(seq (seq
(call -relay- ("op" "identity") [])
(call friendRelay ("op" "identity") [])
)
(xor
(call friend ("testo" "getString") ["friends string via"] str2)
(seq (seq
(seq (seq
(call friendRelay ("op" "identity") []) (seq
(call -relay- ("op" "identity") []) (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "me") [] me)
)
(call %init_peer_id% ("getDataSrv" "myRelay") [] myRelay)
) )
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) (call %init_peer_id% ("getDataSrv" "friend") [] friend)
) )
(call %init_peer_id% ("getDataSrv" "friendRelay") [] friendRelay)
) )
(call -relay- ("op" "identity") [])
) )
(call friendRelay ("op" "identity") []) (call friendRelay ("op" "identity") [])
) )
(call -relay- ("op" "identity") []) (xor
(call friend ("testo" "getString") ["friends string via"] str2)
(seq
(seq
(call friendRelay ("op" "identity") [])
(call -relay- ("op" "identity") [])
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
) )
(call %init_peer_id% ("op" "identity") []) (call friendRelay ("op" "identity") [])
) )
(call %init_peer_id% ("lp" "print") ["my string in par"]) (call -relay- ("op" "identity") [])
) )
(call %init_peer_id% ("lp" "print") ["my string in par"])
) )
(call %init_peer_id% ("lp" "print") [str2]) (call %init_peer_id% ("lp" "print") [str2])
) )

View File

@ -1,5 +1,5 @@
import {FluenceClient} from "@fluencelabs/fluence"; import {FluenceClient} from "@fluencelabs/fluence";
import {passFunctionAsArg} from "./compiled/callArrow"; import {passFunctionAsArg} from "../compiled/callArrow";
export async function callArrowCall(client: FluenceClient): Promise<string> { export async function callArrowCall(client: FluenceClient): Promise<string> {
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {doStuff} from "./compiled/complex"; import {doStuff} from "../compiled/complex";
import {testNet} from "@fluencelabs/fluence-network-environment"; import {testNet} from "@fluencelabs/fluence-network-environment";
export async function complexCall(client: FluenceClient) { export async function complexCall(client: FluenceClient) {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {callConstant} from "./compiled/constants"; import {callConstant} from "../compiled/constants";
export async function constantsCall(client: FluenceClient) { export async function constantsCall(client: FluenceClient) {
registerServiceFunction(client, "test", "getNum", (args: any[], _) => { registerServiceFunction(client, "test", "getNum", (args: any[], _) => {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {getAliasedData} from "./compiled/dataAlias"; import {getAliasedData} from "../compiled/dataAlias";
export async function dataAliasCall(client: FluenceClient) { export async function dataAliasCall(client: FluenceClient) {
registerServiceFunction(client, "somesrv", "get", (args: any[], _) => { registerServiceFunction(client, "somesrv", "get", (args: any[], _) => {

View File

@ -1,5 +1,5 @@
import {FluenceClient} from "@fluencelabs/fluence"; import {FluenceClient} from "@fluencelabs/fluence";
import {iterateAndPrint, iterateAndPrintParallel} from "./compiled/fold"; import {iterateAndPrint, iterateAndPrintParallel} from "../compiled/fold";
export async function foldCall(client: FluenceClient) { export async function foldCall(client: FluenceClient) {
await iterateAndPrint(client, [client.relayPeerId!]) await iterateAndPrint(client, [client.relayPeerId!])

View File

@ -1,4 +1,4 @@
import {testFunc} from "./compiled/func"; import {testFunc} from "../compiled/func";
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
export async function funcCall(client: FluenceClient) { export async function funcCall(client: FluenceClient) {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {helloWorld} from "./compiled/helloWorld"; import {helloWorld} from "../compiled/helloWorld";
export async function helloWorldCall(client: FluenceClient) { export async function helloWorldCall(client: FluenceClient) {
// helloWorld.aqua // helloWorld.aqua

View File

@ -1,5 +1,5 @@
import {FluenceClient} from "@fluencelabs/fluence"; import {FluenceClient} from "@fluencelabs/fluence";
import {ifElseCall, ifElseNumCall} from "./compiled/if"; import {ifElseCall, ifElseNumCall} from "../compiled/if";
export async function ifCall(client: FluenceClient) { export async function ifCall(client: FluenceClient) {
await ifElseCall(client, false) await ifElseCall(client, false)

View File

@ -1,5 +1,5 @@
import {FluenceClient} from "@fluencelabs/fluence"; import {FluenceClient} from "@fluencelabs/fluence";
import {getPeerExternalAddresses} from "./compiled/on"; import {getPeerExternalAddresses} from "../compiled/on";
export async function onCall(client: FluenceClient): Promise<string[]> { export async function onCall(client: FluenceClient): Promise<string[]> {
return await getPeerExternalAddresses(client, client.relayPeerId!) return await getPeerExternalAddresses(client, client.relayPeerId!)

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {parFunc} from "./compiled/par"; import {parFunc} from "../compiled/par";
export async function parCall(client: FluenceClient) { export async function parCall(client: FluenceClient) {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {checkStreams} from "./compiled/stream"; import {checkStreams} from "../compiled/stream";
export async function streamCall(client: FluenceClient) { export async function streamCall(client: FluenceClient) {
registerServiceFunction(client, "stringer-id", "returnString", (args: any[], _) => { registerServiceFunction(client, "stringer-id", "returnString", (args: any[], _) => {

View File

@ -1,5 +1,5 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {topologyTest} from "./compiled/topology"; import {topologyTest} from "../compiled/topology";
export async function topologyCall(client: FluenceClient, client2: FluenceClient): Promise<string> { export async function topologyCall(client: FluenceClient, client2: FluenceClient): Promise<string> {

View File

@ -2,119 +2,29 @@
import {createClient, registerServiceFunction} from "@fluencelabs/fluence"; import {createClient, registerServiceFunction} from "@fluencelabs/fluence";
import {testNet} from "@fluencelabs/fluence-network-environment"; import {testNet} from "@fluencelabs/fluence-network-environment";
import {callArrowCall} from "./callArrowCall"; import {helloWorld} from "./compiled/helloWorld";
import {dataAliasCall} from "./dataAliasCall";
import {onCall} from "./onCall";
import {funcCall} from "./funcCall";
import {helloWorldCall} from "./helloWorldCall";
import {foldCall} from "./foldCall";
import {ifCall} from "./if";
import {parCall} from "./parCall";
import {complexCall} from "./complex";
import {constantsCall} from "./constantsCall";
import {streamCall} from "./streamCall";
import {topologyCall} from "./topologyCall";
let deepEqual = require('deep-equal')
function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) {
if (!deepEqual(actual, expected)) {
console.error(`${name} call has the wrong result`)
console.error("expected: " + expected)
console.error("actual: " + actual)
callBackOnError()
}
}
const main = async () => { const main = async () => {
const client = await createClient(testNet[0]); // each compiled aqua function require a connected client
const client2 = await createClient(testNet[1]); const client = await createClient(testNet[0]);
// this could be called from `println.aqua` // example to how register a local service
registerServiceFunction(client, "println-service-id", "print", (args: any[], _) => { // it could be used in aqua code as follows
console.log("println: " + args[0]) // service StringExtra("service-id"):
return {} // addNameToHello: string -> string
}) // see more in helloWorld.aqua
registerServiceFunction(client, "service-id", "addNameToHello", (args: any[], _) => {
return `Hello, ${args[0]}!`
})
// these is only list of calls. Take a look into functions to see what's going on // call an aqua function thet presented in ../aqua/helloWorld.aqua
const result = await helloWorld(client, "NAME");
console.log(result)
// these calls return void, so they could be executed at any time,
// because promise waits only a fact that particle was sent
// callArrow.aqua
let callArrowResult = await callArrowCall(client)
// fold.aqua
let foldCallResult = await foldCall(client)
//if.aqua
await ifCall(client)
// par.aqua
let parCallResult = await parCall(client)
// these calls waiting for a result, so it will be called sequentially
// helloWorld.aqua
let helloWorldResult = await helloWorldCall(client)
// func.aqua
let funcCallResult = await funcCall(client)
// on.aqua
let onCallResult = await onCall(client)
// dataAlias.aqua
let dataAliasResult = await dataAliasCall(client)
// complex.aqua
let complexCallResult = await complexCall(client)
// constants.aqua
let constantCallResult = await constantsCall(client)
// stream.aqua
let streamResult = await streamCall(client)
// topology.aqua
let topologyResult = await topologyCall(client, client2)
await client.disconnect();
let success = true;
let cb: () => void = () => {
success = false;
}
checkCall("callArrow", callArrowResult, "Hello, callArrow call!", cb)
checkCall("foldCall", foldCallResult, ["/ip4/165.227.164.206/tcp/7001", "/ip4/165.227.164.206/tcp/9001/ws"], cb)
checkCall("onCall", onCallResult, ["/ip4/165.227.164.206/tcp/7001", "/ip4/165.227.164.206/tcp/9001/ws"], cb)
checkCall("parArrow", parCallResult, "hello", cb)
checkCall("helloWorldCall", helloWorldResult, "Hello, NAME!", cb)
checkCall("funcCall", funcCallResult, "some str", cb)
checkCall("dataAliasCall", dataAliasResult, "peer id str", cb)
checkCall("complexCall", complexCallResult, ["some str", "3", "1", "4", "1", "1", "3", "2", "4", "2", "2"], cb)
checkCall("constantCall", constantCallResult, "non-default string", cb)
checkCall("streamCall", streamResult, ["first updated", "second updated", "third updated", "fourth updated"], cb)
checkCall("topologyCall", topologyResult, "finish", cb)
if (success) {
process.exit(0) process.exit(0)
} else {
process.exit(1)
}
}; };
main().catch((err) => { main().catch((err) => {
console.log(err) console.log(err)
process.exit(1) process.exit(1)
}) })

120
src/run-examples.ts Normal file
View File

@ -0,0 +1,120 @@
#!/usr/bin/env node
import {createClient, registerServiceFunction} from "@fluencelabs/fluence";
import {testNet} from "@fluencelabs/fluence-network-environment";
import {callArrowCall} from "./examples/callArrowCall";
import {dataAliasCall} from "./examples/dataAliasCall";
import {onCall} from "./examples/onCall";
import {funcCall} from "./examples/funcCall";
import {helloWorldCall} from "./examples/helloWorldCall";
import {foldCall} from "./examples/foldCall";
import {ifCall} from "./examples/if";
import {parCall} from "./examples/parCall";
import {complexCall} from "./examples/complex";
import {constantsCall} from "./examples/constantsCall";
import {streamCall} from "./examples/streamCall";
import {topologyCall} from "./examples/topologyCall";
let deepEqual = require('deep-equal')
function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) {
if (!deepEqual(actual, expected)) {
console.error(`${name} call has the wrong result`)
console.error("expected: " + expected)
console.error("actual: " + actual)
callBackOnError()
}
}
const main = async () => {
const client = await createClient(testNet[0]);
const client2 = await createClient(testNet[1]);
// this could be called from `println.aqua`
registerServiceFunction(client, "println-service-id", "print", (args: any[], _) => {
console.log("println: " + args[0])
return {}
})
// these is only list of calls. Take a look into functions to see what's going on
// these calls return void, so they could be executed at any time,
// because promise waits only a fact that particle was sent
// callArrow.aqua
let callArrowResult = await callArrowCall(client)
// fold.aqua
let foldCallResult = await foldCall(client)
//if.aqua
await ifCall(client)
// par.aqua
let parCallResult = await parCall(client)
// these calls waiting for a result, so it will be called sequentially
// helloWorld.aqua
let helloWorldResult = await helloWorldCall(client)
// func.aqua
let funcCallResult = await funcCall(client)
// on.aqua
let onCallResult = await onCall(client)
// dataAlias.aqua
let dataAliasResult = await dataAliasCall(client)
// complex.aqua
let complexCallResult = await complexCall(client)
// constants.aqua
let constantCallResult = await constantsCall(client)
// stream.aqua
let streamResult = await streamCall(client)
// topology.aqua
let topologyResult = await topologyCall(client, client2)
await client.disconnect();
let success = true;
let cb: () => void = () => {
success = false;
}
checkCall("callArrow", callArrowResult, "Hello, callArrow call!", cb)
checkCall("foldCall", foldCallResult, ["/ip4/165.227.164.206/tcp/7001", "/ip4/165.227.164.206/tcp/9001/ws"], cb)
checkCall("onCall", onCallResult, ["/ip4/165.227.164.206/tcp/7001", "/ip4/165.227.164.206/tcp/9001/ws"], cb)
checkCall("parArrow", parCallResult, "hello", cb)
checkCall("helloWorldCall", helloWorldResult, "Hello, NAME!", cb)
checkCall("funcCall", funcCallResult, "some str", cb)
checkCall("dataAliasCall", dataAliasResult, "peer id str", cb)
checkCall("complexCall", complexCallResult, ["some str", "3", "1", "4", "1", "1", "3", "2", "4", "2", "2"], cb)
checkCall("constantCall", constantCallResult, "non-default string", cb)
checkCall("streamCall", streamResult, ["first updated", "second updated", "third updated", "fourth updated"], cb)
checkCall("topologyCall", topologyResult, "finish", cb)
if (success) {
process.exit(0)
} else {
process.exit(1)
}
};
main().catch((err) => {
console.log(err)
process.exit(1)
})