Files
aqua-playground/src/compiled/examples/assignment.ts

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-06-07 17:23:27 +03:00
/**
*
* 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
2021-07-29 17:28:09 +03:00
* Aqua version: 0.1.10-188
2021-06-07 17:23:27 +03:00
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
2021-06-15 13:14:39 +03:00
export async function doSmth(client: FluenceClient, arg: {value:string}, config?: {ttl?: number}): Promise<string[]> {
2021-06-07 17:23:27 +03:00
let request: RequestFlow;
2021-06-07 18:17:01 +03:00
const promise = new Promise<string[]>((resolve, reject) => {
2021-07-13 17:30:12 +03:00
const r = new RequestFlowBuilder()
2021-06-07 17:23:27 +03:00
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
2021-06-07 18:17:01 +03:00
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "arg") [] arg)
)
(call %init_peer_id% ("op" "identity") [arg.$.value!] a)
2021-06-07 17:23:27 +03:00
)
2021-06-07 18:17:01 +03:00
(call %init_peer_id% ("op" "array") [a "hello"] res)
2021-06-07 17:23:27 +03:00
)
(xor
2021-06-07 18:17:01 +03:00
(call %init_peer_id% ("callbackSrv" "response") [res])
2021-06-07 17:23:27 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
2021-06-18 15:15:34 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
2021-06-07 17:23:27 +03:00
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'arg', () => {return arg;});
h.onEvent('callbackSrv', 'response', (args) => {
2021-07-28 16:24:07 +03:00
const [res] = args;
2021-06-07 17:23:27 +03:00
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 doSmth');
})
2021-07-23 11:57:44 +03:00
if(config && config.ttl) {
2021-07-13 17:30:12 +03:00
r.withTTL(config.ttl)
}
request = r.build();
2021-06-07 17:23:27 +03:00
});
await client.initiateFlow(request!);
return promise;
}