Update the compiler and JS SDK version to support udpate public JS API (#13)

This commit is contained in:
Pavel
2021-09-10 19:48:26 +03:00
committed by GitHub
parent 5c9a59f14d
commit 37cc0c8d37
58 changed files with 9677 additions and 4586 deletions

View File

@ -1,12 +1,12 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* 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.0-SNAPSHOT
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
@ -14,38 +14,41 @@ import {
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
// Services
export interface TestSDef {
multiline: (a: string, b: string, c: boolean, callParams: CallParams<'a' | 'b' | 'c'>) => string;
t: (arg0: string, callParams: CallParams<'arg0'>) => string;
}
export interface TestSDef {
multiline: (a: string, b: string, c: boolean, callParams: CallParams<'a' | 'b' | 'c'>) => string;
t: (arg0: string, callParams: CallParams<'arg0'>) => string;
}
export function registerTestS(service: TestSDef): void;
export function registerTestS(service: TestSDef): void;
export function registerTestS(serviceId: string, service: TestSDef): void;
export function registerTestS(peer: FluencePeer, service: TestSDef): void;
export function registerTestS(peer: FluencePeer, serviceId: string, service: TestSDef): void;
export function registerTestS(...args: any) {
export function registerTestS(...args: any) {
let peer: FluencePeer;
let serviceId: any;
let service: any;
if (args[0] instanceof FluencePeer) {
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
serviceId = args[0];
} else if (typeof args[1] === 'string') {
serviceId = args[1];
}
else {
serviceId = "some-id"
}
} else {
serviceId = 'some-id';
}
if (!(args[0] instanceof FluencePeer) && typeof args[0] === 'object') {
// Figuring out which overload is the service.
// If the first argument is not Fluence Peer and it is an object, then it can only be the service def
// 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') {
service = args[0];
} else if (typeof args[1] === 'object') {
service = args[1];
@ -53,89 +56,101 @@ export function registerTestS(peer: FluencePeer, serviceId: string, service: Tes
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'multiline') {
const callParams = {
...req.particleContext,
tetraplets: {
a: req.tetraplets[0],b: req.tetraplets[1],c: req.tetraplets[2]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.multiline(req.args[0], req.args[1], req.args[2], callParams)
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
}
if (req.fnName === 'multiline') {
const callParams = {
...req.particleContext,
tetraplets: {
a: req.tetraplets[0],
b: req.tetraplets[1],
c: req.tetraplets[2],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.multiline(req.args[0], req.args[1], req.args[2], callParams);
}
if (req.fnName === 't') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.t(req.args[0], callParams);
}
if (req.fnName === 't') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.t(req.args[0], callParams)
}
next();
});
}
next();
});
}
// Functions
export function doStuff(a: string, b: string, c: boolean, d: boolean, e: string[], g: string[], str: string, config?: {ttl?: number}) : Promise<string[]>;
export function doStuff(peer: FluencePeer, a: string, b: string, c: boolean, d: boolean, e: string[], g: string[], str: string, config?: {ttl?: number}) : Promise<string[]>;
export function doStuff(...args: any) {
let peer: FluencePeer;
let a: any;
let b: any;
let c: any;
let d: any;
let e: any;
let g: any;
let str: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
a = args[1];
b = args[2];
c = args[3];
d = args[4];
e = args[5];
g = args[6];
str = args[7];
config = args[8];
} else {
peer = FluencePeer.default;
a = args[0];
b = args[1];
c = args[2];
d = args[3];
e = args[4];
g = args[5];
str = args[6];
config = args[7];
}
let request: RequestFlow;
const promise = new Promise<string[]>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function doStuff(
a: string,
b: string,
c: boolean,
d: boolean,
e: string[],
g: string[],
str: string,
config?: { ttl?: number },
): Promise<string[]>;
export function doStuff(
peer: FluencePeer,
a: string,
b: string,
c: boolean,
d: boolean,
e: string[],
g: string[],
str: string,
config?: { ttl?: number },
): Promise<string[]>;
export function doStuff(...args: any) {
let peer: FluencePeer;
let a: any;
let b: any;
let c: any;
let d: any;
let e: any;
let g: any;
let str: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
a = args[1];
b = args[2];
c = args[3];
d = args[4];
e = args[5];
g = args[6];
str = args[7];
config = args[8];
} else {
peer = Fluence.getPeer();
a = args[0];
b = args[1];
c = args[2];
d = args[3];
e = args[4];
g = args[5];
str = args[6];
config = args[7];
}
let request: RequestFlow;
const promise = new Promise<string[]>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -249,22 +264,36 @@ config = args[7];
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'a', () => {
return a;
});
h.on('getDataSrv', 'b', () => {
return b;
});
h.on('getDataSrv', 'c', () => {
return c;
});
h.on('getDataSrv', 'd', () => {
return d;
});
h.on('getDataSrv', 'e', () => {
return e;
});
h.on('getDataSrv', 'g', () => {
return g;
});
h.on('getDataSrv', 'str', () => {
return str;
});
h.on('getDataSrv', 'a', () => {return a;});
h.on('getDataSrv', 'b', () => {return b;});
h.on('getDataSrv', 'c', () => {return c;});
h.on('getDataSrv', 'd', () => {return d;});
h.on('getDataSrv', 'e', () => {return e;});
h.on('getDataSrv', 'g', () => {return g;});
h.on('getDataSrv', 'str', () => {return str;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
@ -274,13 +303,12 @@ h.on('getDataSrv', 'str', () => {return str;});
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for doStuff');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
});
if (config && config.ttl) {
r.withTTL(config.ttl);
}
request = r.build();
});
peer.internals.initiateFlow(request!);
return promise;
}