diff --git a/aqua/examples/option.aqua b/aqua/examples/option.aqua new file mode 100644 index 0000000..6d425f8 --- /dev/null +++ b/aqua/examples/option.aqua @@ -0,0 +1,8 @@ +service SomeS("test2"): + getStr: ?string -> ?string + getStr2: string -> string + +func useOptional(opt: ?string, ackEm: string -> (), ack: string, ?string -> (), ack2: string, string -> ()) -> string: + ackEm("before") + ack("first", opt) + <- opt! \ No newline at end of file diff --git a/package.json b/package.json index 97edbb3..a96dd76 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,12 @@ "build": "tsc", "examples": "node -r ts-node/register src/run-examples.ts", "exec": "npm run compile-aqua && node -r ts-node/register src/index.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.2-129", + "@fluencelabs/aqua-cli": "^0.1.4-133", "@fluencelabs/aqua-lib": "^0.1.3", "ts-node": "^9.1.1", "typescript": "^4.2.4" diff --git a/src/compiled/examples/callArrow.ts b/src/compiled/examples/callArrow.ts index a70ae34..6e141da 100644 --- a/src/compiled/examples/callArrow.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/complex.ts b/src/compiled/examples/complex.ts index 17f531c..2292772 100644 --- a/src/compiled/examples/complex.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/constants.ts b/src/compiled/examples/constants.ts index 38afe99..cb7f76c 100644 --- a/src/compiled/examples/constants.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/dataAlias.ts b/src/compiled/examples/dataAlias.ts index 07e6c14..a0ca94a 100644 --- a/src/compiled/examples/dataAlias.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/example.ts b/src/compiled/examples/example.ts index 8ba7aa0..4fc51fb 100644 --- a/src/compiled/examples/example.ts +++ b/src/compiled/examples/example.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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/fldist-sample.ts b/src/compiled/examples/fldist-sample.ts index 821ef24..08a44fc 100644 --- a/src/compiled/examples/fldist-sample.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/fold.ts b/src/compiled/examples/fold.ts index 71f29ef..15b7d40 100644 --- a/src/compiled/examples/fold.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/func.ts b/src/compiled/examples/func.ts index 3e3453a..f5186fb 100644 --- a/src/compiled/examples/func.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/helloWorld.ts b/src/compiled/examples/helloWorld.ts index 1d10398..317465e 100644 --- a/src/compiled/examples/helloWorld.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/if.ts b/src/compiled/examples/if.ts index 00b719c..285a39d 100644 --- a/src/compiled/examples/if.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/on.ts b/src/compiled/examples/on.ts index 9407a16..0cecfde 100644 --- a/src/compiled/examples/on.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/par.ts b/src/compiled/examples/par.ts index 66513f2..820d622 100644 --- a/src/compiled/examples/par.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/println.ts b/src/compiled/examples/println.ts index 6d24ded..94f6572 100644 --- a/src/compiled/examples/println.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/stream.ts b/src/compiled/examples/stream.ts index 4c5f08c..ed8f6ad 100644 --- a/src/compiled/examples/stream.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/topology.ts b/src/compiled/examples/topology.ts index 96bb720..c691c25 100644 --- a/src/compiled/examples/topology.ts +++ b/src/compiled/examples/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.3-SNAPSHOT + * Aqua version: 0.1.4-SNAPSHOT * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/examples/useOptionalCall.ts b/src/examples/useOptionalCall.ts new file mode 100644 index 0000000..02e8b92 --- /dev/null +++ b/src/examples/useOptionalCall.ts @@ -0,0 +1,21 @@ +import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; +import {getTwoResults} from "../compiled/examples/foldJoin"; +import {useOptional} from "../compiled/examples/option"; + +export async function useOptionalCall(client: FluenceClient): Promise { + registerServiceFunction(client, "test2", "getStr", (args: any[], _) => { + console.log("getStr:") + console.log(args) + return args[0] + }) + + registerServiceFunction(client, "test2", "getStr2", (args: any[], _) => { + console.log("getStr2:") + console.log(args) + return args[0] + }) + + let cbEm = (str: string) => console.log(str) + let cb = (str: string, arg: any) => console.log(str, arg) + return await useOptional(client, "hello", cbEm, cb, cb) +} diff --git a/src/run-examples.ts b/src/run-examples.ts index c1507b2..c8870b0 100644 --- a/src/run-examples.ts +++ b/src/run-examples.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import {createClient, registerServiceFunction} from "@fluencelabs/fluence"; +import {createClient, registerServiceFunction, setLogLevel} from "@fluencelabs/fluence"; import {testNet} from "@fluencelabs/fluence-network-environment"; import {callArrowCall} from "./examples/callArrowCall"; import {dataAliasCall} from "./examples/dataAliasCall"; @@ -15,13 +15,16 @@ import {constantsCall} from "./examples/constantsCall"; import {streamCall} from "./examples/streamCall"; import {topologyCall} from "./examples/topologyCall"; import {foldJoinCall} from "./examples/foldJoinCall"; +import {useOptionalCall} from "./examples/useOptionalCall"; 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) + console.error("expected: ") + console.dir(expected) + console.error("actual: ") + console.dir(actual) callBackOnError() } } @@ -35,6 +38,7 @@ function checkCallBy(name: string, actual: any, by: (res: any) => boolean, callB } const main = async () => { + // setLogLevel("trace") const client = await createClient(testNet[0]); const client2 = await createClient(testNet[1]); @@ -89,6 +93,9 @@ const main = async () => { // foldJoin.aqua let foldJoinResult = await foldJoinCall(client) + // option.aqua + let optionResult = await useOptionalCall(client) + await client.disconnect(); let success = true; @@ -120,6 +127,8 @@ const main = async () => { checkCallBy("foldJoinCall", foldJoinResult, (res) => res.length == 3, cb) + checkCall("useOptional", optionResult, "hello", cb) + if (success) { process.exit(0) } else {