mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-05-05 17:12:22 +00:00
200 lines
6.7 KiB
TypeScript
200 lines
6.7 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 iterateAndPrint(strings: string[], config?: { ttl?: number }): Promise<void>;
|
||
|
export function iterateAndPrint(peer: FluencePeer, strings: string[], config?: { ttl?: number }): Promise<void>;
|
||
|
export function iterateAndPrint(...args: any) {
|
||
|
let peer: FluencePeer;
|
||
|
let strings: any;
|
||
|
let config: any;
|
||
|
if (FluencePeer.isInstance(args[0])) {
|
||
|
peer = args[0];
|
||
|
strings = args[1];
|
||
|
config = args[2];
|
||
|
} else {
|
||
|
peer = Fluence.getPeer();
|
||
|
strings = args[0];
|
||
|
config = args[1];
|
||
|
}
|
||
|
|
||
|
let request: RequestFlow;
|
||
|
const promise = new Promise<void>((resolve, reject) => {
|
||
|
const r = new RequestFlowBuilder()
|
||
|
.disableInjections()
|
||
|
.withRawScript(
|
||
|
`
|
||
|
(xor
|
||
|
(seq
|
||
|
(seq
|
||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||
|
(call %init_peer_id% ("getDataSrv" "strings") [] strings)
|
||
|
)
|
||
|
(fold strings s
|
||
|
(seq
|
||
|
(call %init_peer_id% ("println-service-id" "print") [s])
|
||
|
(next s)
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||
|
)
|
||
|
`,
|
||
|
)
|
||
|
.configHandler((h) => {
|
||
|
h.on('getDataSrv', '-relay-', () => {
|
||
|
return peer.getStatus().relayPeerId;
|
||
|
});
|
||
|
h.on('getDataSrv', 'strings', () => {
|
||
|
return strings;
|
||
|
});
|
||
|
h.onEvent('callbackSrv', 'response', (args) => {});
|
||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||
|
const [err] = args;
|
||
|
reject(err);
|
||
|
});
|
||
|
})
|
||
|
.handleScriptError(reject)
|
||
|
.handleTimeout(() => {
|
||
|
reject('Request timed out for iterateAndPrint');
|
||
|
});
|
||
|
|
||
|
if (config && config.ttl) {
|
||
|
r.withTTL(config.ttl);
|
||
|
}
|
||
|
|
||
|
request = r.build();
|
||
|
});
|
||
|
peer.internals.initiateFlow(request!);
|
||
|
return Promise.race([promise, Promise.resolve()]);
|
||
|
}
|
||
|
|
||
|
export function iterateAndPrintParallel(
|
||
|
nodes: string[],
|
||
|
c: (arg0: { external_addresses: string[] }, callParams: CallParams<'arg0'>) => void,
|
||
|
config?: { ttl?: number },
|
||
|
): Promise<void>;
|
||
|
export function iterateAndPrintParallel(
|
||
|
peer: FluencePeer,
|
||
|
nodes: string[],
|
||
|
c: (arg0: { external_addresses: string[] }, callParams: CallParams<'arg0'>) => void,
|
||
|
config?: { ttl?: number },
|
||
|
): Promise<void>;
|
||
|
export function iterateAndPrintParallel(...args: any) {
|
||
|
let peer: FluencePeer;
|
||
|
let nodes: any;
|
||
|
let c: any;
|
||
|
let config: any;
|
||
|
if (FluencePeer.isInstance(args[0])) {
|
||
|
peer = args[0];
|
||
|
nodes = args[1];
|
||
|
c = args[2];
|
||
|
config = args[3];
|
||
|
} else {
|
||
|
peer = Fluence.getPeer();
|
||
|
nodes = args[0];
|
||
|
c = args[1];
|
||
|
config = args[2];
|
||
|
}
|
||
|
|
||
|
let request: RequestFlow;
|
||
|
const promise = new Promise<void>((resolve, reject) => {
|
||
|
const r = new RequestFlowBuilder()
|
||
|
.disableInjections()
|
||
|
.withRawScript(
|
||
|
`
|
||
|
(xor
|
||
|
(seq
|
||
|
(seq
|
||
|
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||
|
(call %init_peer_id% ("getDataSrv" "nodes") [] nodes)
|
||
|
)
|
||
|
(fold nodes s
|
||
|
(par
|
||
|
(seq
|
||
|
(call -relay- ("op" "noop") [])
|
||
|
(xor
|
||
|
(seq
|
||
|
(seq
|
||
|
(call s ("peer" "identify") [] ads)
|
||
|
(call -relay- ("op" "noop") [])
|
||
|
)
|
||
|
(xor
|
||
|
(call %init_peer_id% ("callbackSrv" "c") [ads])
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||
|
)
|
||
|
)
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||
|
)
|
||
|
)
|
||
|
(next s)
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||
|
)
|
||
|
`,
|
||
|
)
|
||
|
.configHandler((h) => {
|
||
|
h.on('getDataSrv', '-relay-', () => {
|
||
|
return peer.getStatus().relayPeerId;
|
||
|
});
|
||
|
h.on('getDataSrv', 'nodes', () => {
|
||
|
return nodes;
|
||
|
});
|
||
|
h.use((req, resp, next) => {
|
||
|
if (req.serviceId === 'callbackSrv' && req.fnName === 'c') {
|
||
|
const callParams = {
|
||
|
...req.particleContext,
|
||
|
tetraplets: {
|
||
|
arg0: req.tetraplets[0],
|
||
|
},
|
||
|
};
|
||
|
resp.retCode = ResultCodes.success;
|
||
|
c(req.args[0], callParams);
|
||
|
resp.result = {};
|
||
|
}
|
||
|
next();
|
||
|
});
|
||
|
|
||
|
h.onEvent('callbackSrv', 'response', (args) => {});
|
||
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||
|
const [err] = args;
|
||
|
reject(err);
|
||
|
});
|
||
|
})
|
||
|
.handleScriptError(reject)
|
||
|
.handleTimeout(() => {
|
||
|
reject('Request timed out for iterateAndPrintParallel');
|
||
|
});
|
||
|
|
||
|
if (config && config.ttl) {
|
||
|
r.withTTL(config.ttl);
|
||
|
}
|
||
|
|
||
|
request = r.build();
|
||
|
});
|
||
|
peer.internals.initiateFlow(request!);
|
||
|
return Promise.race([promise, Promise.resolve()]);
|
||
|
}
|