mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-04-25 09:52:12 +00:00
Fix client SDK TypeScript compilation (#942)
This commit is contained in:
parent
2277a3584c
commit
9617a646ec
846
package-lock.json
generated
846
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fluence",
|
"name": "fluence",
|
||||||
"version": "0.7.6",
|
"version": "0.7.7",
|
||||||
"description": "the browser js-libp2p client for the Fluence network",
|
"description": "the browser js-libp2p client for the Fluence network",
|
||||||
"main": "./dist/fluence.js",
|
"main": "./dist/fluence.js",
|
||||||
"typings": "./dist/fluence.d.ts",
|
"typings": "./dist/fluence.d.ts",
|
||||||
@ -21,12 +21,11 @@
|
|||||||
"cids": "0.8.1",
|
"cids": "0.8.1",
|
||||||
"it-length-prefixed": "3.0.1",
|
"it-length-prefixed": "3.0.1",
|
||||||
"it-pipe": "1.1.0",
|
"it-pipe": "1.1.0",
|
||||||
"libp2p": "0.27.4",
|
"libp2p": "0.28.3",
|
||||||
"libp2p-mplex": "0.9.5",
|
"libp2p-mplex": "0.9.5",
|
||||||
"libp2p-secio": "0.12.5",
|
"libp2p-secio": "0.12.5",
|
||||||
"libp2p-websockets": "0.13.6",
|
"libp2p-websockets": "0.13.6",
|
||||||
"peer-id": "0.13.12",
|
"peer-id": "0.13.12",
|
||||||
"peer-info": "0.17.5",
|
|
||||||
"uuid": "8.3.0"
|
"uuid": "8.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -38,7 +37,7 @@
|
|||||||
"assert": "2.0.0",
|
"assert": "2.0.0",
|
||||||
"chai": "4.2.0",
|
"chai": "4.2.0",
|
||||||
"clean-webpack-plugin": "3.0.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",
|
"mocha": "7.2.0",
|
||||||
"ts-loader": "7.0.5",
|
"ts-loader": "7.0.5",
|
||||||
"ts-mocha": "7.0.0",
|
"ts-mocha": "7.0.0",
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as PeerInfo from "peer-info";
|
|
||||||
import * as PeerId from "peer-id";
|
import * as PeerId from "peer-id";
|
||||||
import Multiaddr from "multiaddr"
|
import Multiaddr from "multiaddr"
|
||||||
import {FluenceClient} from "./fluenceClient";
|
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
|
* @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> {
|
static async connect(multiaddr: string | Multiaddr, peerId: PeerId): Promise<FluenceClient> {
|
||||||
let peerInfo = await PeerInfo.create(peerId);
|
let client = new FluenceClient(peerId);
|
||||||
|
|
||||||
let client = new FluenceClient(peerInfo);
|
|
||||||
|
|
||||||
await client.connect(multiaddr);
|
await client.connect(multiaddr);
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import * as PeerId from "peer-id";
|
|||||||
import {LocalServices} from "./localServices";
|
import {LocalServices} from "./localServices";
|
||||||
import Multiaddr from "multiaddr"
|
import Multiaddr from "multiaddr"
|
||||||
import {Subscriptions} from "./subscriptions";
|
import {Subscriptions} from "./subscriptions";
|
||||||
import * as PeerInfo from "peer-info";
|
|
||||||
import {FluenceConnection} from "./fluenceConnection";
|
import {FluenceConnection} from "./fluenceConnection";
|
||||||
import {checkInterface, Interface} from "./Interface";
|
import {checkInterface, Interface} from "./Interface";
|
||||||
import {Service} from "./service";
|
import {Service} from "./service";
|
||||||
@ -51,7 +50,7 @@ interface Call {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class FluenceClient {
|
export class FluenceClient {
|
||||||
readonly selfPeerInfo: PeerInfo;
|
readonly selfPeerId: PeerId;
|
||||||
readonly selfPeerIdStr: string;
|
readonly selfPeerIdStr: string;
|
||||||
private nodePeerIdStr: string;
|
private nodePeerIdStr: string;
|
||||||
|
|
||||||
@ -61,9 +60,9 @@ export class FluenceClient {
|
|||||||
|
|
||||||
private subscriptions: Subscriptions = new Subscriptions();
|
private subscriptions: Subscriptions = new Subscriptions();
|
||||||
|
|
||||||
constructor(selfPeerInfo: PeerInfo) {
|
constructor(selfPeerId: PeerId) {
|
||||||
this.selfPeerInfo = selfPeerInfo;
|
this.selfPeerId = selfPeerId;
|
||||||
this.selfPeerIdStr = selfPeerInfo.id.toB58String();
|
this.selfPeerIdStr = selfPeerId.toB58String();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,7 +304,7 @@ export class FluenceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAvailableBlueprints(peerId?: string): Promise<Blueprint[]> {
|
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;
|
let blueprints = resp.available_blueprints;
|
||||||
|
|
||||||
@ -323,7 +322,7 @@ export class FluenceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getActiveInterfaces(peerId?: string): Promise<Interface[]> {
|
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;
|
let interfaces = resp.active_interfaces;
|
||||||
if (interfaces && interfaces instanceof Array) {
|
if (interfaces && interfaces instanceof Array) {
|
||||||
@ -417,8 +416,8 @@ export class FluenceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let peerId = PeerId.createFromB58String(nodePeerId);
|
let peerId = PeerId.createFromB58String(nodePeerId);
|
||||||
let relayAddress = await createRelayAddress(nodePeerId, this.selfPeerInfo.id, true);
|
let relayAddress = await createRelayAddress(nodePeerId, this.selfPeerId, true);
|
||||||
let connection = new FluenceConnection(multiaddr, peerId, this.selfPeerInfo, relayAddress, this.handleCall());
|
let connection = new FluenceConnection(multiaddr, peerId, this.selfPeerId, relayAddress, this.handleCall());
|
||||||
|
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ import {
|
|||||||
makeProvideMessage,
|
makeProvideMessage,
|
||||||
parseFunctionCall
|
parseFunctionCall
|
||||||
} from "./functionCall";
|
} from "./functionCall";
|
||||||
import * as PeerId from "peer-id";
|
|
||||||
import * as PeerInfo from "peer-info";
|
|
||||||
import Websockets from "libp2p-websockets";
|
import Websockets from "libp2p-websockets";
|
||||||
import Mplex from "libp2p-mplex";
|
import Mplex from "libp2p-mplex";
|
||||||
import SECIO from "libp2p-secio";
|
import SECIO from "libp2p-secio";
|
||||||
@ -32,6 +31,7 @@ import Peer from "libp2p";
|
|||||||
import {decode, encode} from "it-length-prefixed";
|
import {decode, encode} from "it-length-prefixed";
|
||||||
import pipe from "it-pipe";
|
import pipe from "it-pipe";
|
||||||
import Multiaddr from "multiaddr";
|
import Multiaddr from "multiaddr";
|
||||||
|
import PeerId from "peer-id";
|
||||||
|
|
||||||
export const PROTOCOL_NAME = '/fluence/faas/1.0.0';
|
export const PROTOCOL_NAME = '/fluence/faas/1.0.0';
|
||||||
|
|
||||||
@ -43,18 +43,18 @@ enum Status {
|
|||||||
|
|
||||||
export class FluenceConnection {
|
export class FluenceConnection {
|
||||||
|
|
||||||
private readonly selfPeerInfo: PeerInfo;
|
private readonly selfPeerId: PeerId;
|
||||||
readonly sender: Address;
|
readonly sender: Address;
|
||||||
private node: LibP2p;
|
private node: LibP2p;
|
||||||
private readonly address: Multiaddr;
|
private readonly address: Multiaddr;
|
||||||
readonly nodePeerId: PeerId;
|
readonly nodePeerId: PeerId;
|
||||||
private readonly selfPeerId: string;
|
private readonly selfPeerIdStr: string;
|
||||||
private readonly handleCall: (call: FunctionCall) => FunctionCall | undefined;
|
private readonly handleCall: (call: FunctionCall) => FunctionCall | undefined;
|
||||||
|
|
||||||
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerInfo: PeerInfo, sender: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
|
constructor(multiaddr: Multiaddr, hostPeerId: PeerId, selfPeerId: PeerId, sender: Address, handleCall: (call: FunctionCall) => FunctionCall | undefined) {
|
||||||
this.selfPeerInfo = selfPeerInfo;
|
this.selfPeerId = selfPeerId;
|
||||||
this.handleCall = handleCall;
|
this.handleCall = handleCall;
|
||||||
this.selfPeerId = selfPeerInfo.id.toB58String();
|
this.selfPeerIdStr = selfPeerId.toB58String();
|
||||||
this.address = multiaddr;
|
this.address = multiaddr;
|
||||||
this.nodePeerId = hostPeerId;
|
this.nodePeerId = hostPeerId;
|
||||||
this.sender = sender
|
this.sender = sender
|
||||||
@ -71,9 +71,9 @@ export class FluenceConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
let peerInfo = this.selfPeerInfo;
|
let peerInfo = this.selfPeerId;
|
||||||
this.node = await Peer.create({
|
this.node = await Peer.create({
|
||||||
peerInfo,
|
peerId: peerInfo,
|
||||||
config: {},
|
config: {},
|
||||||
modules: {
|
modules: {
|
||||||
transport: [Websockets],
|
transport: [Websockets],
|
||||||
@ -97,7 +97,7 @@ export class FluenceConnection {
|
|||||||
if (this.status === Status.Initializing) {
|
if (this.status === Status.Initializing) {
|
||||||
await this.node.start();
|
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);
|
await this.node.dial(this.address);
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ export class FluenceConnection {
|
|||||||
async function (source: AsyncIterable<string>) {
|
async function (source: AsyncIterable<string>) {
|
||||||
for await (const msg of source) {
|
for await (const msg of source) {
|
||||||
try {
|
try {
|
||||||
console.log(_this.selfPeerId);
|
console.log(_this.selfPeerIdStr);
|
||||||
let call = parseFunctionCall(msg);
|
let call = parseFunctionCall(msg);
|
||||||
let response = _this.handleCall(call);
|
let response = _this.handleCall(call);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user