172 lines
5.2 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-06-07 17:23:27 +03:00
* Aqua version: 0.1.5-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
export async function print(client: FluenceClient, str: string): 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) => {
request = new RequestFlowBuilder()
2021-04-23 17:21:58 +03:00
.disableInjections()
2021-04-15 18:19:24 +03:00
.withRawScript(
`
(xor
(seq
(seq
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "str") [] str)
2021-04-15 18:19:24 +03:00
)
(call %init_peer_id% ("println-service-id" "print") [str])
)
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
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', 'str', () => {return str;});
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 print');
2021-04-15 18:19:24 +03:00
})
.build();
});
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()]);
}
export async function ifElseCall(client: FluenceClient, condition: boolean): 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) => {
request = new RequestFlowBuilder()
2021-04-23 17:21:58 +03:00
.disableInjections()
2021-04-15 18:19:24 +03:00
.withRawScript(
`
(xor
(seq
(seq
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "condition") [] condition)
2021-04-15 18:19:24 +03:00
)
(xor
(match condition true
(xor
(call %init_peer_id% ("println-service-id" "print") ["it is true"])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(seq
(seq
(call -relay- ("op" "identity") [])
(call %init_peer_id% ("println-service-id" "print") ["it is false"])
)
(call -relay- ("op" "identity") [])
2021-04-15 18:19:24 +03:00
)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
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', 'condition', () => {return condition;});
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 ifElseCall');
2021-04-15 18:19:24 +03:00
})
.build();
});
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()]);
}
export async function ifElseNumCall(client: FluenceClient, condition: 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) => {
request = new RequestFlowBuilder()
2021-04-23 17:21:58 +03:00
.disableInjections()
2021-04-15 18:19:24 +03:00
.withRawScript(
`
(xor
(seq
(seq
2021-05-04 18:49:59 +03:00
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
2021-04-23 17:21:58 +03:00
(call %init_peer_id% ("getDataSrv" "condition") [] condition)
2021-04-15 18:19:24 +03:00
)
(xor
(match condition 1
(xor
(call %init_peer_id% ("println-service-id" "print") ["it is 1"])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(seq
(seq
(call -relay- ("op" "identity") [])
(call %init_peer_id% ("println-service-id" "print") ["it is not 1"])
)
(call -relay- ("op" "identity") [])
2021-04-15 18:19:24 +03:00
)
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
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', 'condition', () => {return condition;});
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 ifElseNumCall');
2021-04-15 18:19:24 +03:00
})
.build();
});
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()]);
}