mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-06-20 22:56:48 +00:00
test for options
This commit is contained in:
8
aqua/examples/option.aqua
Normal file
8
aqua/examples/option.aqua
Normal file
@ -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!
|
@ -19,11 +19,12 @@
|
|||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"examples": "node -r ts-node/register src/run-examples.ts",
|
"examples": "node -r ts-node/register src/run-examples.ts",
|
||||||
"exec": "npm run compile-aqua && node -r ts-node/register src/index.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": "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.2-129",
|
"@fluencelabs/aqua-cli": "^0.1.4-133",
|
||||||
"@fluencelabs/aqua-lib": "^0.1.3",
|
"@fluencelabs/aqua-lib": "^0.1.3",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
@ -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.3-SNAPSHOT
|
* Aqua version: 0.1.4-SNAPSHOT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
|
||||||
|
21
src/examples/useOptionalCall.ts
Normal file
21
src/examples/useOptionalCall.ts
Normal file
@ -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<string> {
|
||||||
|
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)
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/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 {testNet} from "@fluencelabs/fluence-network-environment";
|
||||||
import {callArrowCall} from "./examples/callArrowCall";
|
import {callArrowCall} from "./examples/callArrowCall";
|
||||||
import {dataAliasCall} from "./examples/dataAliasCall";
|
import {dataAliasCall} from "./examples/dataAliasCall";
|
||||||
@ -15,13 +15,16 @@ import {constantsCall} from "./examples/constantsCall";
|
|||||||
import {streamCall} from "./examples/streamCall";
|
import {streamCall} from "./examples/streamCall";
|
||||||
import {topologyCall} from "./examples/topologyCall";
|
import {topologyCall} from "./examples/topologyCall";
|
||||||
import {foldJoinCall} from "./examples/foldJoinCall";
|
import {foldJoinCall} from "./examples/foldJoinCall";
|
||||||
|
import {useOptionalCall} from "./examples/useOptionalCall";
|
||||||
let deepEqual = require('deep-equal')
|
let deepEqual = require('deep-equal')
|
||||||
|
|
||||||
function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) {
|
function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) {
|
||||||
if (!deepEqual(actual, expected)) {
|
if (!deepEqual(actual, expected)) {
|
||||||
console.error(`${name} call has the wrong result`)
|
console.error(`${name} call has the wrong result`)
|
||||||
console.error("expected: " + expected)
|
console.error("expected: ")
|
||||||
console.error("actual: " + actual)
|
console.dir(expected)
|
||||||
|
console.error("actual: ")
|
||||||
|
console.dir(actual)
|
||||||
callBackOnError()
|
callBackOnError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,6 +38,7 @@ function checkCallBy(name: string, actual: any, by: (res: any) => boolean, callB
|
|||||||
}
|
}
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
// setLogLevel("trace")
|
||||||
const client = await createClient(testNet[0]);
|
const client = await createClient(testNet[0]);
|
||||||
const client2 = await createClient(testNet[1]);
|
const client2 = await createClient(testNet[1]);
|
||||||
|
|
||||||
@ -89,6 +93,9 @@ const main = async () => {
|
|||||||
// foldJoin.aqua
|
// foldJoin.aqua
|
||||||
let foldJoinResult = await foldJoinCall(client)
|
let foldJoinResult = await foldJoinCall(client)
|
||||||
|
|
||||||
|
// option.aqua
|
||||||
|
let optionResult = await useOptionalCall(client)
|
||||||
|
|
||||||
await client.disconnect();
|
await client.disconnect();
|
||||||
|
|
||||||
let success = true;
|
let success = true;
|
||||||
@ -120,6 +127,8 @@ const main = async () => {
|
|||||||
|
|
||||||
checkCallBy("foldJoinCall", foldJoinResult, (res) => res.length == 3, cb)
|
checkCallBy("foldJoinCall", foldJoinResult, (res) => res.length == 3, cb)
|
||||||
|
|
||||||
|
checkCall("useOptional", optionResult, "hello", cb)
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user