mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-04-25 23:22:38 +00:00
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
|
/**
|
||
|
*
|
||
|
* 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.3.1-231
|
||
|
*
|
||
|
*/
|
||
|
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||
|
import {
|
||
|
ResultCodes,
|
||
|
RequestFlow,
|
||
|
RequestFlowBuilder,
|
||
|
CallParams,
|
||
|
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
||
|
|
||
|
function missingFields(obj: any, fields: string[]): string[] {
|
||
|
return fields.filter((f) => !(f in obj));
|
||
|
}
|
||
|
|
||
|
// Services
|
||
|
|
||
|
// Functions
|
||
|
|
||
|
export function returnLiteral(config?: { ttl?: number }): Promise<string>;
|
||
|
export function returnLiteral(peer: FluencePeer, config?: { ttl?: number }): Promise<string>;
|
||
|
export function returnLiteral(...args: any) {
|
||
|
let peer: FluencePeer;
|
||
|
|
||
|
let config: any;
|
||
|
if (FluencePeer.isInstance(args[0])) {
|
||
|
peer = args[0];
|
||
|
config = args[1];
|
||
|
} else {
|
||
|
peer = Fluence.getPeer();
|
||
|
config = args[0];
|
||
|
}
|
||
|
|
||
|
let request: RequestFlow;
|
||
|
const promise = new Promise<string>((resolve, reject) => {
|
||
|
const r = new RequestFlowBuilder()
|
||
|
.disableInjections()
|
||
|
.withRawScript(
|
||
|
`
|
||
|
(xor
|
||
|
(seq
|
||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||
|
(xor
|
||
|
(call %init_peer_id% ("callbackSrv" "response") ["some literal"])
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||
|
)
|
||
|
)
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||
|
)
|
||
|
`,
|
||
|
)
|
||
|
.configHandler((h) => {
|
||
|
h.on('getDataSrv', '-relay-', () => {
|
||
|
return peer.getStatus().relayPeerId;
|
||
|
});
|
||
|
|
||
|
h.onEvent('callbackSrv', 'response', (args) => {
|
||
|
const [res] = args;
|
||
|
resolve(res);
|
||
|
});
|
||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||
|
const [err] = args;
|
||
|
reject(err);
|
||
|
});
|
||
|
})
|
||
|
.handleScriptError(reject)
|
||
|
.handleTimeout(() => {
|
||
|
reject('Request timed out for returnLiteral');
|
||
|
});
|
||
|
|
||
|
if (config && config.ttl) {
|
||
|
r.withTTL(config.ttl);
|
||
|
}
|
||
|
|
||
|
request = r.build();
|
||
|
});
|
||
|
peer.internals.initiateFlow(request!);
|
||
|
return promise;
|
||
|
}
|