From 4405f465d1ac88a4d0ef25bf7f7b92a6b8e34acd Mon Sep 17 00:00:00 2001 From: DieMyst Date: Tue, 25 May 2021 13:35:52 +0300 Subject: [PATCH] move examples, use index.ts as playground, update aqua-cli version --- README.md | 11 ++- package-lock.json | 6 +- package.json | 5 +- src/compiled/builtin.ts | 2 +- src/compiled/callArrow.ts | 2 +- src/compiled/complex.ts | 26 +++--- src/compiled/constants.ts | 2 +- src/compiled/dataAlias.ts | 2 +- src/compiled/example.ts | 7 +- src/compiled/fldist-sample.ts | 2 +- src/compiled/fold.ts | 2 +- src/compiled/func.ts | 2 +- src/compiled/helloWorld.ts | 2 +- src/compiled/if.ts | 2 +- src/compiled/on.ts | 2 +- src/compiled/par.ts | 12 +-- src/compiled/println.ts | 2 +- src/compiled/stream.ts | 2 +- src/compiled/topology.ts | 47 +++++------ src/{ => examples}/callArrowCall.ts | 2 +- src/{ => examples}/complex.ts | 2 +- src/{ => examples}/constantsCall.ts | 2 +- src/{ => examples}/dataAliasCall.ts | 2 +- src/{ => examples}/foldCall.ts | 2 +- src/{ => examples}/funcCall.ts | 2 +- src/{ => examples}/helloWorldCall.ts | 2 +- src/{ => examples}/if.ts | 2 +- src/{ => examples}/onCall.ts | 2 +- src/{ => examples}/parCall.ts | 2 +- src/{ => examples}/streamCall.ts | 2 +- src/{ => examples}/topologyCall.ts | 2 +- src/index.ts | 122 ++++----------------------- src/run-examples.ts | 120 ++++++++++++++++++++++++++ 33 files changed, 220 insertions(+), 184 deletions(-) rename src/{ => examples}/callArrowCall.ts (86%) rename src/{ => examples}/complex.ts (90%) rename src/{ => examples}/constantsCall.ts (88%) rename src/{ => examples}/dataAliasCall.ts (86%) rename src/{ => examples}/foldCall.ts (86%) rename src/{ => examples}/funcCall.ts (87%) rename src/{ => examples}/helloWorldCall.ts (87%) rename src/{ => examples}/if.ts (81%) rename src/{ => examples}/onCall.ts (77%) rename src/{ => examples}/parCall.ts (93%) rename src/{ => examples}/streamCall.ts (86%) rename src/{ => examples}/topologyCall.ts (92%) create mode 100644 src/run-examples.ts diff --git a/README.md b/README.md index 555e38f..5a4c1cc 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,15 @@ To compile the aqua files execute 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: @@ -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` +Code that call all examples and check results: `/src/run-examples.ts` + ## References \- Documentation for the compiler can be found in the official repo: https://github.com/fluencelabs/aqua \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 555cfb7..bdd8eb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@fluencelabs/aqua-cli": { - "version": "0.1.1-105", - "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.1-105.tgz", - "integrity": "sha512-G5TFGzp9AW7oE4jsYOt5685LIFcteSg3uvMH1e6jqMqyAElQZJ1NReZ5cuLHy89x9fp4/kljTxVwra3J31QtrQ==", + "version": "0.1.1-110", + "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.1-110.tgz", + "integrity": "sha512-GZaZbzZiaJDFNJ23+AEMe2ezu/KId57pnADyu7FYIfdfRBU7JSGHFLxHqoYRAOp9ZGLLE8Ic+aA0etCME734Aw==", "dev": true }, "@fluencelabs/aquamarine-interpreter": { diff --git a/package.json b/package.json index 3b980e8..31c6cf0 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,13 @@ ], "scripts": { "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:air": "aqua-cli -i ./aqua/ -o ./compiled-air -a" }, "devDependencies": { - "@fluencelabs/aqua-cli": "^0.1.1-105", + "@fluencelabs/aqua-cli": "^0.1.1-110", "ts-node": "^9.1.1", "typescript": "^4.2.4" }, diff --git a/src/compiled/builtin.ts b/src/compiled/builtin.ts index 24305bd..7e6bea3 100644 --- a/src/compiled/builtin.ts +++ b/src/compiled/builtin.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/callArrow.ts b/src/compiled/callArrow.ts index 893a731..c60d2e4 100644 --- a/src/compiled/callArrow.ts +++ b/src/compiled/callArrow.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/complex.ts b/src/compiled/complex.ts index ba6eba1..a9209b5 100644 --- a/src/compiled/complex.ts +++ b/src/compiled/complex.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ 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 - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "a") [] a) + (seq + (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 - (call %init_peer_id% ("some-id" "t") [str] $stream) - (call %init_peer_id% ("println-service-id" "print") [a]) - ) + (call %init_peer_id% ("println-service-id" "print") [a]) (seq (seq (seq diff --git a/src/compiled/constants.ts b/src/compiled/constants.ts index 11daff9..c8d3714 100644 --- a/src/compiled/constants.ts +++ b/src/compiled/constants.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/dataAlias.ts b/src/compiled/dataAlias.ts index 3249c7d..a84dbc1 100644 --- a/src/compiled/dataAlias.ts +++ b/src/compiled/dataAlias.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/example.ts b/src/compiled/example.ts index 78eabe5..ef6da66 100644 --- a/src/compiled/example.ts +++ b/src/compiled/example.ts @@ -3,16 +3,17 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-SNAPSHOT + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; 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 { - let request; + let request: RequestFlow; const promise = new Promise((resolve, reject) => { request = new RequestFlowBuilder() .disableInjections() @@ -69,7 +70,7 @@ export async function betterMessage(client: FluenceClient, relay: string): Promi }) .build(); }); - await client.initiateFlow(request); + await client.initiateFlow(request!); return Promise.race([promise, Promise.resolve()]); } \ No newline at end of file diff --git a/src/compiled/fldist-sample.ts b/src/compiled/fldist-sample.ts index ebda3d7..e1eb619 100644 --- a/src/compiled/fldist-sample.ts +++ b/src/compiled/fldist-sample.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/fold.ts b/src/compiled/fold.ts index 586dbcc..b3378cc 100644 --- a/src/compiled/fold.ts +++ b/src/compiled/fold.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/func.ts b/src/compiled/func.ts index 7c57c98..27b75be 100644 --- a/src/compiled/func.ts +++ b/src/compiled/func.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/helloWorld.ts b/src/compiled/helloWorld.ts index 078434b..8af7392 100644 --- a/src/compiled/helloWorld.ts +++ b/src/compiled/helloWorld.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/if.ts b/src/compiled/if.ts index af01127..e2942f9 100644 --- a/src/compiled/if.ts +++ b/src/compiled/if.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/on.ts b/src/compiled/on.ts index ab1be8a..9a58b75 100644 --- a/src/compiled/on.ts +++ b/src/compiled/on.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/par.ts b/src/compiled/par.ts index 7232cca..d38862f 100644 --- a/src/compiled/par.ts +++ b/src/compiled/par.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -63,10 +63,10 @@ export async function parFunc(client: FluenceClient, node: string, c: (arg0: {ex (xor (seq (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "node") [] node) - ) - (par + (seq + (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) + (call %init_peer_id% ("getDataSrv" "node") [] node) + ) (par (call %init_peer_id% ("parservice-id" "call") [] y) (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% ("parservice-id" "call") [] x) ) + (call %init_peer_id% ("parservice-id" "call") [] x) ) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) diff --git a/src/compiled/println.ts b/src/compiled/println.ts index 743f83b..8a607e8 100644 --- a/src/compiled/println.ts +++ b/src/compiled/println.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/stream.ts b/src/compiled/stream.ts index 636db66..6d9b6be 100644 --- a/src/compiled/stream.ts +++ b/src/compiled/stream.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/topology.ts b/src/compiled/topology.ts index c670392..8c04d03 100644 --- a/src/compiled/topology.ts +++ b/src/compiled/topology.ts @@ -3,7 +3,7 @@ * This file is auto-generated. Do not edit manually: changes may be erased. * 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 - * Aqua version: 0.1.1-105 + * Aqua version: 0.1.1-110 * */ 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 - (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 - (call -relay- ("op" "identity") []) - (call friendRelay ("op" "identity") []) - ) - (xor - (call friend ("testo" "getString") ["friends string via"] str2) (seq (seq - (call friendRelay ("op" "identity") []) - (call -relay- ("op" "identity") []) + (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% ("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 -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]) ) diff --git a/src/callArrowCall.ts b/src/examples/callArrowCall.ts similarity index 86% rename from src/callArrowCall.ts rename to src/examples/callArrowCall.ts index 7c71d40..ab88d16 100644 --- a/src/callArrowCall.ts +++ b/src/examples/callArrowCall.ts @@ -1,5 +1,5 @@ import {FluenceClient} from "@fluencelabs/fluence"; -import {passFunctionAsArg} from "./compiled/callArrow"; +import {passFunctionAsArg} from "../compiled/callArrow"; export async function callArrowCall(client: FluenceClient): Promise { return new Promise((resolve, reject) => { diff --git a/src/complex.ts b/src/examples/complex.ts similarity index 90% rename from src/complex.ts rename to src/examples/complex.ts index 0c39a48..0fe18b5 100644 --- a/src/complex.ts +++ b/src/examples/complex.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {doStuff} from "./compiled/complex"; +import {doStuff} from "../compiled/complex"; import {testNet} from "@fluencelabs/fluence-network-environment"; export async function complexCall(client: FluenceClient) { diff --git a/src/constantsCall.ts b/src/examples/constantsCall.ts similarity index 88% rename from src/constantsCall.ts rename to src/examples/constantsCall.ts index f1177a3..3dde170 100644 --- a/src/constantsCall.ts +++ b/src/examples/constantsCall.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {callConstant} from "./compiled/constants"; +import {callConstant} from "../compiled/constants"; export async function constantsCall(client: FluenceClient) { registerServiceFunction(client, "test", "getNum", (args: any[], _) => { diff --git a/src/dataAliasCall.ts b/src/examples/dataAliasCall.ts similarity index 86% rename from src/dataAliasCall.ts rename to src/examples/dataAliasCall.ts index 7ee9f79..f843f0b 100644 --- a/src/dataAliasCall.ts +++ b/src/examples/dataAliasCall.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {getAliasedData} from "./compiled/dataAlias"; +import {getAliasedData} from "../compiled/dataAlias"; export async function dataAliasCall(client: FluenceClient) { registerServiceFunction(client, "somesrv", "get", (args: any[], _) => { diff --git a/src/foldCall.ts b/src/examples/foldCall.ts similarity index 86% rename from src/foldCall.ts rename to src/examples/foldCall.ts index 546054b..f6b8a14 100644 --- a/src/foldCall.ts +++ b/src/examples/foldCall.ts @@ -1,5 +1,5 @@ import {FluenceClient} from "@fluencelabs/fluence"; - import {iterateAndPrint, iterateAndPrintParallel} from "./compiled/fold"; + import {iterateAndPrint, iterateAndPrintParallel} from "../compiled/fold"; export async function foldCall(client: FluenceClient) { await iterateAndPrint(client, [client.relayPeerId!]) diff --git a/src/funcCall.ts b/src/examples/funcCall.ts similarity index 87% rename from src/funcCall.ts rename to src/examples/funcCall.ts index b6afe29..89e3155 100644 --- a/src/funcCall.ts +++ b/src/examples/funcCall.ts @@ -1,4 +1,4 @@ -import {testFunc} from "./compiled/func"; +import {testFunc} from "../compiled/func"; import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; export async function funcCall(client: FluenceClient) { diff --git a/src/helloWorldCall.ts b/src/examples/helloWorldCall.ts similarity index 87% rename from src/helloWorldCall.ts rename to src/examples/helloWorldCall.ts index 244b754..fe683fa 100644 --- a/src/helloWorldCall.ts +++ b/src/examples/helloWorldCall.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {helloWorld} from "./compiled/helloWorld"; +import {helloWorld} from "../compiled/helloWorld"; export async function helloWorldCall(client: FluenceClient) { // helloWorld.aqua diff --git a/src/if.ts b/src/examples/if.ts similarity index 81% rename from src/if.ts rename to src/examples/if.ts index ff29230..e8f469e 100644 --- a/src/if.ts +++ b/src/examples/if.ts @@ -1,5 +1,5 @@ import {FluenceClient} from "@fluencelabs/fluence"; -import {ifElseCall, ifElseNumCall} from "./compiled/if"; +import {ifElseCall, ifElseNumCall} from "../compiled/if"; export async function ifCall(client: FluenceClient) { await ifElseCall(client, false) diff --git a/src/onCall.ts b/src/examples/onCall.ts similarity index 77% rename from src/onCall.ts rename to src/examples/onCall.ts index 53d59ed..8b5423c 100644 --- a/src/onCall.ts +++ b/src/examples/onCall.ts @@ -1,5 +1,5 @@ import {FluenceClient} from "@fluencelabs/fluence"; -import {getPeerExternalAddresses} from "./compiled/on"; +import {getPeerExternalAddresses} from "../compiled/on"; export async function onCall(client: FluenceClient): Promise { return await getPeerExternalAddresses(client, client.relayPeerId!) diff --git a/src/parCall.ts b/src/examples/parCall.ts similarity index 93% rename from src/parCall.ts rename to src/examples/parCall.ts index bad1f9d..8a76bfa 100644 --- a/src/parCall.ts +++ b/src/examples/parCall.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {parFunc} from "./compiled/par"; +import {parFunc} from "../compiled/par"; export async function parCall(client: FluenceClient) { diff --git a/src/streamCall.ts b/src/examples/streamCall.ts similarity index 86% rename from src/streamCall.ts rename to src/examples/streamCall.ts index f2263a8..d0395fd 100644 --- a/src/streamCall.ts +++ b/src/examples/streamCall.ts @@ -1,5 +1,5 @@ import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; -import {checkStreams} from "./compiled/stream"; +import {checkStreams} from "../compiled/stream"; export async function streamCall(client: FluenceClient) { registerServiceFunction(client, "stringer-id", "returnString", (args: any[], _) => { diff --git a/src/topologyCall.ts b/src/examples/topologyCall.ts similarity index 92% rename from src/topologyCall.ts rename to src/examples/topologyCall.ts index 86ca115..cb19e0e 100644 --- a/src/topologyCall.ts +++ b/src/examples/topologyCall.ts @@ -1,5 +1,5 @@ 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 { diff --git a/src/index.ts b/src/index.ts index 9ca6dc3..19f0b8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,119 +2,29 @@ import {createClient, registerServiceFunction} from "@fluencelabs/fluence"; import {testNet} from "@fluencelabs/fluence-network-environment"; -import {callArrowCall} from "./callArrowCall"; -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() - } -} +import {helloWorld} from "./compiled/helloWorld"; const main = async () => { - const client = await createClient(testNet[0]); - const client2 = await createClient(testNet[1]); + // each compiled aqua function require a connected client + const client = await createClient(testNet[0]); - // this could be called from `println.aqua` - registerServiceFunction(client, "println-service-id", "print", (args: any[], _) => { - console.log("println: " + args[0]) - return {} - }) + // example to how register a local service + // it could be used in aqua code as follows + // service StringExtra("service-id"): + // 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) - } else { - process.exit(1) - } - }; main().catch((err) => { - console.log(err) - process.exit(1) + console.log(err) + process.exit(1) }) diff --git a/src/run-examples.ts b/src/run-examples.ts new file mode 100644 index 0000000..124b139 --- /dev/null +++ b/src/run-examples.ts @@ -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) +})