mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-06-22 08:31:42 +00:00
dump compiled
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
* 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
|
||||
* Aqua version: 0.3.2-SNAPSHOT
|
||||
*
|
||||
*/
|
||||
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
|
||||
@ -11,11 +11,12 @@ import {
|
||||
ResultCodes,
|
||||
RequestFlow,
|
||||
RequestFlowBuilder,
|
||||
CallParams,
|
||||
CallParams
|
||||
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
|
||||
|
||||
|
||||
function missingFields(obj: any, fields: string[]): string[] {
|
||||
return fields.filter((f) => !(f in obj));
|
||||
return fields.filter(f => !(f in obj))
|
||||
}
|
||||
|
||||
// Services
|
||||
@ -23,11 +24,12 @@ function missingFields(obj: any, fields: string[]): string[] {
|
||||
export interface PeerDef {
|
||||
is_connected: (arg0: string, callParams: CallParams<'arg0'>) => boolean;
|
||||
}
|
||||
|
||||
export function registerPeer(service: PeerDef): void;
|
||||
export function registerPeer(serviceId: string, service: PeerDef): void;
|
||||
export function registerPeer(peer: FluencePeer, service: PeerDef): void;
|
||||
export function registerPeer(peer: FluencePeer, serviceId: string, service: PeerDef): void;
|
||||
|
||||
|
||||
export function registerPeer(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
@ -43,7 +45,7 @@ export function registerPeer(...args: any) {
|
||||
} else if (typeof args[1] === 'string') {
|
||||
serviceId = args[1];
|
||||
} else {
|
||||
serviceId = 'peer';
|
||||
serviceId = "peer"
|
||||
}
|
||||
|
||||
// Figuring out which overload is the service.
|
||||
@ -51,7 +53,7 @@ export function registerPeer(...args: any) {
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === 'object') {
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
@ -61,10 +63,7 @@ export function registerPeer(...args: any) {
|
||||
|
||||
const incorrectServiceDefinitions = missingFields(service, ['is_connected']);
|
||||
if (!!incorrectServiceDefinitions.length) {
|
||||
throw new Error(
|
||||
'Error registering service Peer: missing functions: ' +
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(', '),
|
||||
);
|
||||
throw new Error("Error registering service Peer: missing functions: " + incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", "))
|
||||
}
|
||||
|
||||
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||
@ -77,25 +76,28 @@ export function registerPeer(...args: any) {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {
|
||||
arg0: req.tetraplets[0],
|
||||
arg0: req.tetraplets[0]
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.is_connected(req.args[0], callParams);
|
||||
resp.result = service.is_connected(req.args[0], callParams)
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface OpDef {
|
||||
identity: (callParams: CallParams<null>) => void;
|
||||
}
|
||||
|
||||
export function registerOp(service: OpDef): void;
|
||||
export function registerOp(serviceId: string, service: OpDef): void;
|
||||
export function registerOp(peer: FluencePeer, service: OpDef): void;
|
||||
export function registerOp(peer: FluencePeer, serviceId: string, service: OpDef): void;
|
||||
|
||||
|
||||
export function registerOp(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
@ -111,7 +113,7 @@ export function registerOp(...args: any) {
|
||||
} else if (typeof args[1] === 'string') {
|
||||
serviceId = args[1];
|
||||
} else {
|
||||
serviceId = 'op';
|
||||
serviceId = "op"
|
||||
}
|
||||
|
||||
// Figuring out which overload is the service.
|
||||
@ -119,7 +121,7 @@ export function registerOp(...args: any) {
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === 'object') {
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
@ -129,10 +131,7 @@ export function registerOp(...args: any) {
|
||||
|
||||
const incorrectServiceDefinitions = missingFields(service, ['identity']);
|
||||
if (!!incorrectServiceDefinitions.length) {
|
||||
throw new Error(
|
||||
'Error registering service Op: missing functions: ' +
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(', '),
|
||||
);
|
||||
throw new Error("Error registering service Op: missing functions: " + incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", "))
|
||||
}
|
||||
|
||||
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||
@ -144,26 +143,30 @@ export function registerOp(...args: any) {
|
||||
if (req.fnName === 'identity') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {},
|
||||
tetraplets: {
|
||||
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
service.identity(callParams);
|
||||
resp.result = {};
|
||||
service.identity(callParams); resp.result = {}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface TestDef {
|
||||
doSomething: (callParams: CallParams<null>) => boolean;
|
||||
getUserList: (callParams: CallParams<null>) => { name: string; peer_id: string; relay_id: string }[];
|
||||
getUserList: (callParams: CallParams<null>) => { name: string; peer_id: string; relay_id: string; }[];
|
||||
}
|
||||
|
||||
export function registerTest(service: TestDef): void;
|
||||
export function registerTest(serviceId: string, service: TestDef): void;
|
||||
export function registerTest(peer: FluencePeer, service: TestDef): void;
|
||||
export function registerTest(peer: FluencePeer, serviceId: string, service: TestDef): void;
|
||||
|
||||
|
||||
export function registerTest(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let serviceId: any;
|
||||
@ -179,7 +182,7 @@ export function registerTest(...args: any) {
|
||||
} else if (typeof args[1] === 'string') {
|
||||
serviceId = args[1];
|
||||
} else {
|
||||
serviceId = 'test';
|
||||
serviceId = "test"
|
||||
}
|
||||
|
||||
// Figuring out which overload is the service.
|
||||
@ -187,7 +190,7 @@ export function registerTest(...args: any) {
|
||||
// If the first argument is peer, we are checking further. The second argument might either be
|
||||
// an object, that it must be the service object
|
||||
// or a string, which is the service id. In that case the service is the third argument
|
||||
if (!FluencePeer.isInstance(args[0]) && typeof args[0] === 'object') {
|
||||
if (!(FluencePeer.isInstance(args[0])) && typeof args[0] === 'object') {
|
||||
service = args[0];
|
||||
} else if (typeof args[1] === 'object') {
|
||||
service = args[1];
|
||||
@ -197,10 +200,7 @@ export function registerTest(...args: any) {
|
||||
|
||||
const incorrectServiceDefinitions = missingFields(service, ['doSomething', 'getUserList']);
|
||||
if (!!incorrectServiceDefinitions.length) {
|
||||
throw new Error(
|
||||
'Error registering service Test: missing functions: ' +
|
||||
incorrectServiceDefinitions.map((d) => "'" + d + "'").join(', '),
|
||||
);
|
||||
throw new Error("Error registering service Test: missing functions: " + incorrectServiceDefinitions.map((d) => "'" + d + "'").join(", "))
|
||||
}
|
||||
|
||||
peer.internals.callServiceHandler.use((req, resp, next) => {
|
||||
@ -212,29 +212,34 @@ export function registerTest(...args: any) {
|
||||
if (req.fnName === 'doSomething') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {},
|
||||
tetraplets: {
|
||||
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.doSomething(callParams);
|
||||
resp.result = service.doSomething(callParams)
|
||||
}
|
||||
|
||||
if (req.fnName === 'getUserList') {
|
||||
if (req.fnName === 'getUserList') {
|
||||
const callParams = {
|
||||
...req.particleContext,
|
||||
tetraplets: {},
|
||||
tetraplets: {
|
||||
|
||||
},
|
||||
};
|
||||
resp.retCode = ResultCodes.success;
|
||||
resp.result = service.getUserList(callParams);
|
||||
resp.result = service.getUserList(callParams)
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
|
||||
export function betterMessage(relay: string, config?: { ttl?: number }): Promise<void>;
|
||||
export function betterMessage(peer: FluencePeer, relay: string, config?: { ttl?: number }): Promise<void>;
|
||||
export function betterMessage(relay: string, config?: {ttl?: number}): Promise<void>;
|
||||
export function betterMessage(peer: FluencePeer, relay: string, config?: {ttl?: number}): Promise<void>;
|
||||
export function betterMessage(...args: any) {
|
||||
let peer: FluencePeer;
|
||||
let relay: any;
|
||||
@ -252,9 +257,8 @@ export function betterMessage(...args: any) {
|
||||
let request: RequestFlow;
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
const r = new RequestFlowBuilder()
|
||||
.disableInjections()
|
||||
.withRawScript(
|
||||
`
|
||||
.disableInjections()
|
||||
.withRawScript(`
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
@ -289,30 +293,30 @@ export function betterMessage(...args: any) {
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
`,
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'relay', () => {
|
||||
return relay;
|
||||
});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {});
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for betterMessage');
|
||||
});
|
||||
)
|
||||
.configHandler((h) => {
|
||||
h.on('getDataSrv', '-relay-', () => {
|
||||
return peer.getStatus().relayPeerId;
|
||||
});
|
||||
h.on('getDataSrv', 'relay', () => {return relay;});
|
||||
h.onEvent('callbackSrv', 'response', (args) => {
|
||||
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl);
|
||||
}
|
||||
});
|
||||
h.onEvent('errorHandlingSrv', 'error', (args) => {
|
||||
const [err] = args;
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.handleScriptError(reject)
|
||||
.handleTimeout(() => {
|
||||
reject('Request timed out for betterMessage');
|
||||
})
|
||||
|
||||
request = r.build();
|
||||
if (config && config.ttl) {
|
||||
r.withTTL(config.ttl)
|
||||
}
|
||||
|
||||
request = r.build();
|
||||
});
|
||||
peer.internals.initiateFlow(request!);
|
||||
return Promise.race([promise, Promise.resolve()]);
|
||||
|
Reference in New Issue
Block a user