diff --git a/aqua/examples/tryCatch.aqua b/aqua/examples/tryCatch.aqua new file mode 100644 index 0000000..e234709 --- /dev/null +++ b/aqua/examples/tryCatch.aqua @@ -0,0 +1,19 @@ +service Unexisted("unex"): + getStr() -> string + +data LastError: + instruction: string + msg: string + peer_id: string + +service OpA("op"): + identity(s: string) -> string + +func tryCatchTest(node_id: string) -> []string: + on node_id: + f: *string + try: + f <- Unexisted.getStr() + catch err: + f <- OpA.identity(err.msg) + <- f \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1a3c9b0..0ebd1d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,21 +5,21 @@ "requires": true, "dependencies": { "@fluencelabs/aqua-cli": { - "version": "0.1.4-136", - "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.4-136.tgz", - "integrity": "sha512-hvoS+Mc5xOlyWV2i7tCvnABSuSifoKQehoepaREerUhRvymAFwg7nOSc9HPtLY9Ou0j3H3TWhRgTI27+4wZrlA==", + "version": "0.1.6-143", + "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-cli/-/aqua-cli-0.1.6-143.tgz", + "integrity": "sha512-lphQale+0Yib63VvuSN3CoWWHbZukOQ82OihHVt06XXS2Uh/WurCqq8fc9Uo3YpqVWqbAbFtNvWVxp1Tjl7E4g==", "dev": true }, "@fluencelabs/aqua-lib": { - "version": "0.1.3", - "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.3.tgz", - "integrity": "sha512-hLMdScE2l7VCv8jSyP8ZqmJ44FODmGnJIwgsuYpb9PdPGdVZE1lBhWuyldBXYgcaiz/njfJ2bNQ69KqGZkg8WQ==", + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@fluencelabs/aqua-lib/-/aqua-lib-0.1.5.tgz", + "integrity": "sha512-0f5Lo9NT4ZvN+S/oGYiNxLUtpZsTfDy2qL0D4SFPVoj2+YPPK2PKSzZnja2clfM1KHHP6kT6Jd20sHVBIxBMtw==", "dev": true }, "@fluencelabs/avm": { - "version": "0.9.12", - "resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.9.12.tgz", - "integrity": "sha512-NCRGJafLa1Zs98IIOIALrPUoOEjesITsB9of2/r+IDgGKunf0NjI2/tqU5pK+37ye/qro5W+FJsHyseDh7zSDQ==", + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@fluencelabs/avm/-/avm-0.10.5.tgz", + "integrity": "sha512-R65qY8PeVdlF27UDlcODTnxSBfEbiqXivHWoM62e7mZYr4T/lcZEklqMPOkRrymJWs7y/zP/D8N7zxecDNLBOA==", "requires": { "base64-js": "1.5.1" }, @@ -32,11 +32,11 @@ } }, "@fluencelabs/fluence": { - "version": "0.9.50", - "resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.9.50.tgz", - "integrity": "sha512-BQv3+CXm8fmuMRDcYVRhkm6e8zZiFs8my8TSzwg4bTO0CJC+vdzylinl0KWIDgic4FFohWQc/0v/PKzTf+1KnA==", + "version": "0.9.53", + "resolved": "https://registry.npmjs.org/@fluencelabs/fluence/-/fluence-0.9.53.tgz", + "integrity": "sha512-DxazRumUWM4idI55ZSbfI26lRm5tvrgBYPa4XwPmxSbjgkLE5OjZ+sUStesMiUSst6ROQkwMM4v8BK7WqAyMuw==", "requires": { - "@fluencelabs/avm": "0.9.12", + "@fluencelabs/avm": "0.10.5", "async": "3.2.0", "base64-js": "1.3.1", "bs58": "4.0.1", @@ -176,9 +176,9 @@ "integrity": "sha512-5tXH6Bx/kNGd3MgffdmP4dy2Z+G4eaXw0SE81Tq3BNadtnMR5/ySMzX4SLEzHJzSmPNn4HIdpQsBvXMUykr58w==" }, "@types/node": { - "version": "15.12.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.0.tgz", - "integrity": "sha512-+aHJvoCsVhO2ZCuT4o5JtcPrCPyDE3+1nvbDprYes+pPkEsbjH7AGUCNtjMOXS0fqH14t+B7yLzaqSz92FPWyw==" + "version": "15.12.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.2.tgz", + "integrity": "sha512-zjQ69G564OCIWIOHSXyQEEDpdpGl+G348RAKY0XXy9Z5kU9Vzv1GMNnkar/ZJ8dzXB3COzD9Mo9NtRZ4xfgUww==" }, "@types/retry": { "version": "0.12.0", @@ -736,9 +736,9 @@ "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==" }, "execa": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.0.tgz", - "integrity": "sha512-CkdUB7s2y6S+d4y+OM/+ZtQcJCiKUCth4cNImGMqrt2zEVtW2rfHGspQBE1GDo6LjeNIQmTPKXqTCKjqFKyu3A==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", "requires": { "cross-spawn": "^7.0.3", "get-stream": "^6.0.0", diff --git a/package.json b/package.json index ea47242..7bd6c98 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ "compile-aqua:air": "aqua-cli -i ./aqua/ -o ./compiled-air -a" }, "devDependencies": { - "@fluencelabs/aqua-cli": "^0.1.4-136", - "@fluencelabs/aqua-lib": "^0.1.3", + "@fluencelabs/aqua-cli": "^0.1.6-143", + "@fluencelabs/aqua-lib": "^0.1.5", "ts-node": "^9.1.1", "typescript": "^4.2.4" }, "dependencies": { - "@fluencelabs/fluence": "^0.9.50", + "@fluencelabs/fluence": "^0.9.53", "@fluencelabs/fluence-network-environment": "^1.0.9", "deep-equal": "^2.0.5" }, diff --git a/src/compiled/examples/assignment.ts b/src/compiled/examples/assignment.ts index d3afa03..ff9d6cc 100644 --- a/src/compiled/examples/assignment.ts +++ b/src/compiled/examples/assignment.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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/callArrow.ts b/src/compiled/examples/callArrow.ts index 7aa250f..ed319bc 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -12,50 +12,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow'; -export async function print(client: FluenceClient, str: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "str") [] str) - ) - (call %init_peer_id% ("println-service-id" "print") [str]) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'str', () => {return str;}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for print'); - }) - .build(); - }); - await client.initiateFlow(request!); - return Promise.race([promise, Promise.resolve()]); -} - - - export async function passFunctionAsArg(client: FluenceClient, node: string, str: string, c: (arg0: string) => string): Promise { let request: RequestFlow; const promise = new Promise((resolve, reject) => { @@ -102,7 +58,7 @@ export async function passFunctionAsArg(client: FluenceClient, node: string, str ) (call -relay- ("op" "identity") []) ) - (call %init_peer_id% ("println-service-id" "print") [init_call_res]) + (null) ) (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) diff --git a/src/compiled/examples/complex.ts b/src/compiled/examples/complex.ts index 31f4dae..b40d8c8 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -12,161 +12,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow'; -export async function helloWorld(client: FluenceClient, name: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "name") [] name) - ) - (call %init_peer_id% ("service-id" "addNameToHello") [name] res) - ) - (xor - (call %init_peer_id% ("callbackSrv" "response") [res]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - (seq - (call -relay- ("op" "identity") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'name', () => {return name;}); - h.onEvent('callbackSrv', 'response', (args) => { - const [res] = args; - resolve(res); -}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for helloWorld'); - }) - .build(); - }); - await client.initiateFlow(request!); - return promise; -} - - - -export async function print(client: FluenceClient, str: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "str") [] str) - ) - (call %init_peer_id% ("println-service-id" "print") [str]) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'str', () => {return str;}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for print'); - }) - .build(); - }); - await client.initiateFlow(request!); - return Promise.race([promise, Promise.resolve()]); -} - - - -export async function testFunc(client: FluenceClient): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("test-service-id" "str") [] res) - ) - (xor - (call %init_peer_id% ("callbackSrv" "response") [res]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - ) - (seq - (call -relay- ("op" "identity") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - - h.onEvent('callbackSrv', 'response', (args) => { - const [res] = args; - resolve(res); -}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for testFunc'); - }) - .build(); - }); - await client.initiateFlow(request!); - return promise; -} - - - export async function doStuff(client: FluenceClient, a: string, b: string, c: boolean, d: boolean, e: string[], g: string[], str: string): Promise { let request: RequestFlow; const promise = new Promise((resolve, reject) => { diff --git a/src/compiled/examples/constants.ts b/src/compiled/examples/constants.ts index 144e3df..d267fc7 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -12,50 +12,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow'; -export async function print(client: FluenceClient, str: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "str") [] str) - ) - (call %init_peer_id% ("println-service-id" "print") [str]) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'str', () => {return str;}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for print'); - }) - .build(); - }); - await client.initiateFlow(request!); - return Promise.race([promise, Promise.resolve()]); -} - - - export async function callConstant(client: FluenceClient, cb: (arg0: string) => void): Promise { let request: RequestFlow; const promise = new Promise((resolve, reject) => { diff --git a/src/compiled/examples/dataAlias.ts b/src/compiled/examples/dataAlias.ts index 62b23b3..e3e80fb 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/example.ts b/src/compiled/examples/example.ts index 2de5bab..caddfc7 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/fldist-sample.ts b/src/compiled/examples/fldist-sample.ts index 851d2fe..f8ca759 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/fold.ts b/src/compiled/examples/fold.ts index 7749612..fb724d4 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -12,50 +12,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow'; -export async function print(client: FluenceClient, str: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "str") [] str) - ) - (call %init_peer_id% ("println-service-id" "print") [str]) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'str', () => {return str;}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for print'); - }) - .build(); - }); - await client.initiateFlow(request!); - return Promise.race([promise, Promise.resolve()]); -} - - - export async function iterateAndPrint(client: FluenceClient, strings: string[]): Promise { let request: RequestFlow; const promise = new Promise((resolve, reject) => { @@ -71,7 +27,7 @@ export async function iterateAndPrint(client: FluenceClient, strings: string[]): ) (fold strings s (seq - (call %init_peer_id% ("println-service-id" "print") [s]) + (null) (next s) ) ) diff --git a/src/compiled/examples/foldJoin.ts b/src/compiled/examples/foldJoin.ts index 869ec25..501088d 100644 --- a/src/compiled/examples/foldJoin.ts +++ b/src/compiled/examples/foldJoin.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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/func.ts b/src/compiled/examples/func.ts index d81b626..d98fa55 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/helloWorld.ts b/src/compiled/examples/helloWorld.ts index 69d13c6..4263681 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/if.ts b/src/compiled/examples/if.ts index 783137a..61b8bbc 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; @@ -12,50 +12,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow'; -export async function print(client: FluenceClient, str: string): Promise { - let request: RequestFlow; - const promise = new Promise((resolve, reject) => { - request = new RequestFlowBuilder() - .disableInjections() - .withRawScript( - ` -(xor - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "str") [] str) - ) - (call %init_peer_id% ("println-service-id" "print") [str]) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) -) - - `, - ) - .configHandler((h) => { - h.on('getDataSrv', '-relay-', () => { - return client.relayPeerId!; - }); - h.on('getDataSrv', 'str', () => {return str;}); - - h.onEvent('errorHandlingSrv', 'error', (args) => { - // assuming error is the single argument - const [err] = args; - reject(err); - }); - }) - .handleScriptError(reject) - .handleTimeout(() => { - reject('Request timed out for print'); - }) - .build(); - }); - await client.initiateFlow(request!); - return Promise.race([promise, Promise.resolve()]); -} - - - export async function ifElseCall(client: FluenceClient, condition: boolean): Promise { let request: RequestFlow; const promise = new Promise((resolve, reject) => { diff --git a/src/compiled/examples/nestedFuncs.ts b/src/compiled/examples/nestedFuncs.ts index 743765a..47959f9 100644 --- a/src/compiled/examples/nestedFuncs.ts +++ b/src/compiled/examples/nestedFuncs.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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/on.ts b/src/compiled/examples/on.ts index 25a46bc..ecbfcf9 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/option.ts b/src/compiled/examples/option.ts index d18225e..0005bc7 100644 --- a/src/compiled/examples/option.ts +++ b/src/compiled/examples/option.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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/par.ts b/src/compiled/examples/par.ts index cd6e6bb..d8cccbc 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/println.ts b/src/compiled/examples/println.ts index 2c8b8a7..b80852f 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/stream.ts b/src/compiled/examples/stream.ts index b916f39..ccf61cc 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/topology.ts b/src/compiled/examples/topology.ts index 8f2963e..7125222 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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/compiled/examples/via.ts b/src/compiled/examples/via.ts index 4cf8870..988fc52 100644 --- a/src/compiled/examples/via.ts +++ b/src/compiled/examples/via.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.5-SNAPSHOT + * Aqua version: 0.1.6-143 * */ import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence'; diff --git a/src/examples/tryCatchCall.ts b/src/examples/tryCatchCall.ts new file mode 100644 index 0000000..d52ea2f --- /dev/null +++ b/src/examples/tryCatchCall.ts @@ -0,0 +1,8 @@ +import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; +import {topologyTest} from "../compiled/examples/topology"; +import {tryCatchTest} from "../compiled/examples/tryCatch"; + +export async function tryCatchCall(client: FluenceClient): Promise { + + return await tryCatchTest(client, client.relayPeerId!) +} \ No newline at end of file diff --git a/src/run-examples.ts b/src/run-examples.ts index aa6af25..e2ab33f 100644 --- a/src/run-examples.ts +++ b/src/run-examples.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import {createClient, registerServiceFunction, setLogLevel} from "@fluencelabs/fluence"; -import {testNet} from "@fluencelabs/fluence-network-environment"; +import {krasnodar, testNet} from "@fluencelabs/fluence-network-environment"; import {callArrowCall} from "./examples/callArrowCall"; import {dataAliasCall} from "./examples/dataAliasCall"; import {onCall} from "./examples/onCall"; @@ -19,6 +19,7 @@ import {useOptionalCall} from "./examples/useOptionalCall"; import {viaCall} from "./examples/viaCall"; import {nestedFuncsCall} from "./examples/nestedFuncsCall"; import {assignmentCall} from "./examples/assignment"; +import {tryCatchCall} from "./examples/tryCatchCall"; let deepEqual = require('deep-equal') function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) { @@ -42,8 +43,8 @@ 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]); + const client = await createClient(krasnodar[0]); + const client2 = await createClient(krasnodar[1]); // this could be called from `println.aqua` registerServiceFunction(client, "println-service-id", "print", (args: any[], _) => { @@ -108,6 +109,11 @@ const main = async () => { // assignment.aqua let assignmentResult = await assignmentCall(client) + // tryCatch.aqua + let tryCatchResult = await tryCatchCall(client) + + console.log(tryCatchResult[0]) + await client.disconnect(); let success = true; @@ -147,6 +153,8 @@ const main = async () => { checkCall("assignmentCall", assignmentResult, ["abc", "hello"], cb) + checkCallBy("tryCatchCall", tryCatchResult, (res) => (res[0] as string).includes("Local service error: ret_code is 1024"), cb) + if (success) { process.exit(0) } else {