2021-10-07 13:55:10 +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-10-19 13:25:29 +03:00
|
|
|
* Aqua version: 0.3.2-SNAPSHOT
|
2021-10-07 13:55:10 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
|
|
|
import {
|
|
|
|
ResultCodes,
|
|
|
|
RequestFlow,
|
|
|
|
RequestFlowBuilder,
|
2021-10-19 13:25:29 +03:00
|
|
|
CallParams
|
2021-10-07 13:55:10 +03:00
|
|
|
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
|
2021-10-07 13:55:10 +03:00
|
|
|
function missingFields(obj: any, fields: string[]): string[] {
|
2021-10-19 13:25:29 +03:00
|
|
|
return fields.filter(f => !(f in obj))
|
2021-10-07 13:55:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Services
|
|
|
|
|
|
|
|
// Functions
|
2021-10-19 13:25:29 +03:00
|
|
|
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
export function iterateAndPrint(strings: string[], config?: {ttl?: number}): Promise<void>;
|
|
|
|
export function iterateAndPrint(peer: FluencePeer, strings: string[], config?: {ttl?: number}): Promise<void>;
|
2021-10-07 13:55:10 +03:00
|
|
|
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()
|
2021-10-19 13:25:29 +03:00
|
|
|
.disableInjections()
|
|
|
|
.withRawScript(`
|
2021-10-07 13:55:10 +03:00
|
|
|
(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])
|
|
|
|
)
|
|
|
|
`,
|
2021-10-19 13:25:29 +03:00
|
|
|
)
|
|
|
|
.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');
|
|
|
|
})
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
if (config && config.ttl) {
|
|
|
|
r.withTTL(config.ttl)
|
|
|
|
}
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
request = r.build();
|
2021-10-07 13:55:10 +03:00
|
|
|
});
|
|
|
|
peer.internals.initiateFlow(request!);
|
|
|
|
return Promise.race([promise, Promise.resolve()]);
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
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>;
|
2021-10-07 13:55:10 +03:00
|
|
|
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()
|
2021-10-19 13:25:29 +03:00
|
|
|
.disableInjections()
|
|
|
|
.withRawScript(`
|
2021-10-07 13:55:10 +03:00
|
|
|
(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])
|
|
|
|
)
|
|
|
|
`,
|
2021-10-19 13:25:29 +03:00
|
|
|
)
|
|
|
|
.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) => {
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
});
|
|
|
|
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
|
|
|
const [err] = args;
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.handleScriptError(reject)
|
|
|
|
.handleTimeout(() => {
|
|
|
|
reject('Request timed out for iterateAndPrintParallel');
|
|
|
|
})
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
if (config && config.ttl) {
|
|
|
|
r.withTTL(config.ttl)
|
|
|
|
}
|
2021-10-07 13:55:10 +03:00
|
|
|
|
2021-10-19 13:25:29 +03:00
|
|
|
request = r.build();
|
2021-10-07 13:55:10 +03:00
|
|
|
});
|
|
|
|
peer.internals.initiateFlow(request!);
|
|
|
|
return Promise.race([promise, Promise.resolve()]);
|
|
|
|
}
|