Fix client SDK TypeScript compilation (#942)

This commit is contained in:
Dima 2020-08-26 18:48:17 +03:00 committed by GitHub
parent 2277a3584c
commit 9617a646ec
5 changed files with 785 additions and 112 deletions

846
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "fluence",
"version": "0.7.6",
"version": "0.7.7",
"description": "the browser js-libp2p client for the Fluence network",
"main": "./dist/fluence.js",
"typings": "./dist/fluence.d.ts",
@ -21,12 +21,11 @@
"cids": "0.8.1",
"it-length-prefixed": "3.0.1",
"it-pipe": "1.1.0",
"libp2p": "0.27.4",
"libp2p": "0.28.3",
"libp2p-mplex": "0.9.5",
"libp2p-secio": "0.12.5",
"libp2p-websockets": "0.13.6",
"peer-id": "0.13.12",
"peer-info": "0.17.5",
"uuid": "8.3.0"
},
"devDependencies": {
@ -38,7 +37,7 @@
"assert": "2.0.0",
"chai": "4.2.0",
"clean-webpack-plugin": "3.0.0",
"libp2p-ts": "https://github.com/fluencelabs/libp2p-ts.git",
"libp2p-ts": "https://github.com/ChainSafe/libp2p-ts.git",
"mocha": "7.2.0",
"ts-loader": "7.0.5",
"ts-mocha": "7.0.0",

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
import * as PeerInfo from "peer-info";
import * as PeerId from "peer-id";
import Multiaddr from "multiaddr"
import {FluenceClient} from "./fluenceClient";
@ -36,9 +35,7 @@ export default class Fluence {
* @param peerId your peer id. Should be with a private key. Could be generated by `generatePeerId()` function
*/
static async connect(multiaddr: string | Multiaddr, peerId: PeerId): Promise<FluenceClient> {
let peerInfo = await PeerInfo.create(peerId);
let client = new FluenceClient(peerInfo);
let client = new FluenceClient(peerId);
await client.connect(multiaddr);

View File

@ -27,7 +27,6 @@ import * as PeerId from "peer-id";
import {LocalServices} from "./localServices";
import Multiaddr from "multiaddr"
import {Subscriptions} from "./subscriptions";
import * as PeerInfo from "peer-info";
import {FluenceConnection} from "./fluenceConnection";
import {checkInterface, Interface} from "./Interface";
import {Service} from "./service";
@ -51,7 +50,7 @@ interface Call {
}
export class FluenceClient {
readonly selfPeerInfo: PeerInfo;
readonly selfPeerId: PeerId;
readonly selfPeerIdStr: string;
private nodePeerIdStr: string;
@ -61,9 +60,9 @@ export class FluenceClient {
private subscriptions: Subscriptions = new Subscriptions();
constructor(selfPeerInfo: PeerInfo) {
this.selfPeerInfo = selfPeerInfo;
this.selfPeerIdStr = selfPeerInfo.id.toB58String();
constructor(selfPeerId: PeerId) {
this.selfPeerId = selfPeerId;
this.selfPeerIdStr = selfPeerId.toB58String();
}
/**
@ -305,7 +304,7 @@ export class FluenceClient {
}
async getAvailableBlueprints(peerId?: string): Promise<Blueprint[]> {
let resp = await this.callPeer("get_available_blueprints", {}, undefined);
let resp = await this.callPeer("get_available_blueprints", {}, undefined, peerId);
let blueprints = resp.available_blueprints;
@ -323,7 +322,7 @@ export class FluenceClient {
}
async getActiveInterfaces(peerId?: string): Promise<Interface[]> {
let resp = await this.callPeer("get_active_interfaces", {}, undefined);
let resp = await this.callPeer("get_active_interfaces", {}, undefined, peerId);
let interfaces = resp.active_interfaces;
if (interfaces && interfaces instanceof Array) {
@ -417,8 +416,8 @@ export class FluenceClient {
}
let peerId = PeerId.createFromB58String(nodePeerId);
let relayAddress = await createRelayAddress(nodePeerId, this.selfPeerInfo.id, true);
let connection = new FluenceConnection(multiaddr, peerId, this.selfPeerInfo, relayAddress, this.handleCall());
let relayAddress = await createRelayAddress(nodePeerId, this.selfPeerId, true);
let connection = new FluenceConnection(multiaddr, peerId, this.selfPeerId, relayAddress, this.handleCall());
await connection.connect();

View File

@ -23,8 +23,7 @@ import {
makeProvideMessage,
parseFunctionCall
} from "./functionCall";
import * as PeerId from "peer-id";
import * as PeerInfo from "peer-info";
import Websockets from "libp2p-websockets";
import Mplex from "libp2p-mplex";
import SECIO from "libp2p-secio";
@ -32,6 +31,7 @@ import Peer from "libp2p";
import {decode, encode} from "it-length-prefixed";
import pipe from "it-pipe";
import Multiaddr from "multiaddr";
import PeerId from "peer-id";
export const PROTOCOL_NAME = '/fluence/faas/1.0.0';
@ -43,18 +43,18 @@ enum Status {
export class FluenceConnection {
private readonly selfPeerInfo: PeerInfo;
private readonly selfPeerId: PeerId;
readonly sender: Address;
private node: LibP2p;
private readonly address: Multiaddr;
readonly nodePeerId: PeerId;
private readonly selfPeerId: string;
private readonly selfPeerIdStr: string;
private readonly handleCall: (call: FunctionCall) => FunctionCall | undefined;
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerInfo: PeerInfo, sender: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
this.selfPeerInfo = selfPeerInfo;
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerId: PeerId, sender: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
this.selfPeerId = selfPeerId;
this.handleCall = handleCall;
this.selfPeerId = selfPeerInfo.id.toB58String();
this.selfPeerIdStr = selfPeerId.toB58String();
this.address = multiaddr;
this.nodePeerId = hostPeerId;
this.sender = sender
@ -71,9 +71,9 @@ export class FluenceConnection {
}
async connect() {
let peerInfo = this.selfPeerInfo;
let peerInfo = this.selfPeerId;
this.node = await Peer.create({
peerInfo,
peerId: peerInfo,
config: {},
modules: {
transport: [Websockets],
@ -97,7 +97,7 @@ export class FluenceConnection {
if (this.status === Status.Initializing) {
await this.node.start();
console.log("dialing to the node with address: " + this.node.peerInfo.id.toB58String());
console.log("dialing to the node with address: " + this.node.peerId.toB58String());
await this.node.dial(this.address);
@ -110,7 +110,7 @@ export class FluenceConnection {
async function (source: AsyncIterable<string>) {
for await (const msg of source) {
try {
console.log(_this.selfPeerId);
console.log(_this.selfPeerIdStr);
let call = parseFunctionCall(msg);
let response = _this.handleCall(call);