Update js-sdk section

This commit is contained in:
Pavel Murygin
2021-09-10 20:08:58 +03:00
parent 128b226739
commit bc1785e463
18 changed files with 31462 additions and 319 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"exec": "node -r ts-node/register src/index.ts",
"start": "node -r ts-node/register src/index.ts",
"compile-aqua": "aqua --import . -i ./aqua/ -o ./src/_aqua",
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\""
},

View File

@ -3,10 +3,10 @@
* 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.0-222
* Aqua version: 0.3.0-226
*
*/
import { FluencePeer } from '@fluencelabs/fluence';
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
ResultCodes,
RequestFlow,
@ -25,14 +25,14 @@ import {
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(peer: FluencePeer, service: HelloWorldDef): void;
export function registerHelloWorld(peer: FluencePeer, serviceId: string, service: HelloWorldDef): void;
export function registerHelloWorld(...args) {
export function registerHelloWorld(...args: any) {
let peer: FluencePeer;
let serviceId;
let service;
if (args[0] instanceof FluencePeer) {
let serviceId: any;
let service: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
}
if (typeof args[0] === 'string') {
@ -44,7 +44,12 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
serviceId = "hello-world"
}
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];
@ -82,15 +87,15 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
export function sayHello(config?: {ttl?: number}) : Promise<void>;
export function sayHello(peer: FluencePeer, config?: {ttl?: number}) : Promise<void>;
export function sayHello(...args) {
export function sayHello(...args: any) {
let peer: FluencePeer;
let config;
if (args[0] instanceof FluencePeer) {
let config: any;
if (FluencePeer.isInstance(args[0])) {
peer = args[0];
config = args[1];
} else {
peer = FluencePeer.default;
peer = Fluence.getPeer();
config = args[0];
}
@ -112,7 +117,7 @@ export function registerHelloWorld(peer: FluencePeer, serviceId: string, service
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return peer.connectionInfo.connectedRelay ;
return peer.getStatus().relayPeerId;
});
h.onEvent('callbackSrv', 'response', (args) => {

View File

@ -1,8 +1,8 @@
import { FluencePeer } from "@fluencelabs/fluence";
import { Fluence } from "@fluencelabs/fluence";
import { registerHelloWorld, sayHello } from "./_aqua/hello-world";
async function main() {
await FluencePeer.default.init();
await Fluence.start();
registerHelloWorld({
hello: async (str) => {
@ -12,7 +12,7 @@ async function main() {
await sayHello();
await FluencePeer.default.uninit();
await Fluence.stop();
}
main();