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

141 lines
4.3 KiB
TypeScript
Raw Normal View History

2021-04-23 17:21:58 +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-08-04 12:26:59 +03:00
* Aqua version: 0.1.11-SNAPSHOT
2021-04-23 17:21:58 +03:00
*
*/
2021-04-15 18:19:24 +03:00
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
import { RequestFlowBuilder } from '@fluencelabs/fluence/dist/api.unstable';
2021-05-18 10:14:54 +03:00
import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
2021-04-15 18:19:24 +03:00
2021-06-22 12:29:01 +03:00
export async function print(client: FluenceClient, str: string, config?: {ttl?: number}): Promise<void> {
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
2021-07-13 17:30:12 +03:00
const r = new RequestFlowBuilder()
2021-06-22 12:29:01 +03:00
.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');
})
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-22 12:29:01 +03:00
});
await client.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
}
2021-06-15 13:14:39 +03:00
export async function passFunctionAsArg(client: FluenceClient, node: string, str: string, c: (arg0: string) => string, config?: {ttl?: number}): Promise<void> {
2021-05-18 10:14:54 +03:00
let request: RequestFlow;
2021-04-15 18:19:24 +03:00
const promise = new Promise<void>((resolve, reject) => {
2021-07-13 17:30:12 +03:00
const r = new RequestFlowBuilder()
2021-04-23 17:21:58 +03:00
.disableInjections()
2021-04-15 18:19:24 +03:00
.withRawScript(
`
(xor
(seq
(seq
(seq
(seq
2021-05-04 18:49:59 +03:00
(seq
(seq
2021-06-07 17:23:27 +03:00
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "node") [] node)
2021-05-04 18:49:59 +03:00
)
2021-06-07 17:23:27 +03:00
(call %init_peer_id% ("getDataSrv" "str") [] str)
2021-05-04 18:49:59 +03:00
)
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
2021-05-04 18:49:59 +03:00
)
(xor
2021-04-15 18:19:24 +03:00
(seq
(seq
(seq
(seq
2021-05-04 18:49:59 +03:00
(call node ("peer" "identify") [])
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
2021-05-04 18:49:59 +03:00
)
(xor
(call %init_peer_id% ("callbackSrv" "c") [str] init_call_res)
2021-06-22 12:29:01 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
2021-04-15 18:19:24 +03:00
)
)
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
2021-04-15 18:19:24 +03:00
)
2021-05-04 18:49:59 +03:00
(call node ("peer" "identify") [])
)
(seq
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
2021-04-15 18:19:24 +03:00
)
)
)
2021-06-22 12:29:01 +03:00
(call -relay- ("op" "noop") [])
2021-04-15 18:19:24 +03:00
)
2021-06-22 12:29:01 +03:00
(call %init_peer_id% ("println-service-id" "print") [init_call_res])
2021-04-29 11:56:02 +03:00
)
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
2021-04-15 18:19:24 +03:00
)
`,
)
.configHandler((h) => {
2021-05-04 18:49:59 +03:00
h.on('getDataSrv', '-relay-', () => {
2021-04-23 17:21:58 +03:00
return client.relayPeerId!;
2021-04-15 18:19:24 +03:00
});
h.on('getDataSrv', 'node', () => {return node;});
h.on('getDataSrv', 'str', () => {return str;});
2021-04-15 18:19:24 +03:00
h.on('callbackSrv', 'c', (args) => {return c(args[0]);});
2021-04-23 17:21:58 +03:00
h.onEvent('errorHandlingSrv', 'error', (args) => {
2021-04-15 18:19:24 +03:00
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
2021-04-23 17:21:58 +03:00
reject('Request timed out for passFunctionAsArg');
2021-04-15 18:19:24 +03:00
})
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-04-15 18:19:24 +03:00
});
2021-05-18 10:14:54 +03:00
await client.initiateFlow(request!);
2021-04-15 18:19:24 +03:00
return Promise.race([promise, Promise.resolve()]);
}