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,37 +14,40 @@ import {
CallParams,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v1';
// Services
export interface StringExtraDef {
addNameToHello: (arg0: string, callParams: CallParams<'arg0'>) => string;
}
export interface StringExtraDef {
addNameToHello: (arg0: string, callParams: CallParams<'arg0'>) => string;
}
export function registerStringExtra(service: StringExtraDef): void;
export function registerStringExtra(service: StringExtraDef): void;
export function registerStringExtra(serviceId: string, service: StringExtraDef): void;
export function registerStringExtra(peer: FluencePeer, service: StringExtraDef): void;
export function registerStringExtra(peer: FluencePeer, serviceId: string, service: StringExtraDef): void;
export function registerStringExtra(...args: any) {
export function registerStringExtra(...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 = "service-id"
}
} else {
serviceId = 'service-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];
@ -52,56 +55,51 @@ export function registerStringExtra(peer: FluencePeer, serviceId: string, servic
service = args[2];
}
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
if (req.fnName === 'addNameToHello') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0]
},
};
resp.retCode = ResultCodes.success;
resp.result = service.addNameToHello(req.args[0], callParams)
peer.internals.callServiceHandler.use((req, resp, next) => {
if (req.serviceId !== serviceId) {
next();
return;
}
}
next();
});
}
if (req.fnName === 'addNameToHello') {
const callParams = {
...req.particleContext,
tetraplets: {
arg0: req.tetraplets[0],
},
};
resp.retCode = ResultCodes.success;
resp.result = service.addNameToHello(req.args[0], callParams);
}
next();
});
}
// Functions
export function helloWorld(name: string, config?: {ttl?: number}) : Promise<string>;
export function helloWorld(peer: FluencePeer, name: string, config?: {ttl?: number}) : Promise<string>;
export function helloWorld(...args: any) {
let peer: FluencePeer;
let name: any;
let config: any;
if (args[0] instanceof FluencePeer) {
peer = args[0];
name = args[1];
config = args[2];
} else {
peer = FluencePeer.default;
name = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
export function helloWorld(name: string, config?: { ttl?: number }): Promise<string>;
export function helloWorld(peer: FluencePeer, name: string, config?: { ttl?: number }): Promise<string>;
export function helloWorld(...args: any) {
let peer: FluencePeer;
let name: any;
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
name = args[1];
config = args[2];
} else {
peer = Fluence.getPeer();
name = args[0];
config = args[1];
}
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
@ -120,16 +118,18 @@ config = args[1];
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.getStatus().relayPeerId;
});
h.on('getDataSrv', 'name', () => {
return name;
});
h.on('getDataSrv', 'name', () => {return name;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
const [err] = args;
@ -139,13 +139,12 @@ config = args[1];
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for helloWorld');
})
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;
}