chore: generate fixed types

This commit is contained in:
Irakli Gozalishvili 2020-11-30 13:59:28 -08:00
parent 4e25c6e51c
commit 7ccaf27e24
No known key found for this signature in database
GPG Key ID: C80F9B292FB470DE
12 changed files with 120 additions and 95 deletions

View File

@ -41,7 +41,6 @@
"abortable-iterator": "^3.0.0",
"chai": "^4.2.0",
"chai-checkmark": "^1.0.1",
"class-is": "^1.1.0",
"debug": "^4.1.1",
"delay": "^4.3.0",
"detect-node": "^2.0.4",
@ -70,7 +69,7 @@
"aegir": "^25.0.0",
"it-handshake": "^1.0.1",
"rimraf": "^3.0.2",
"typescript": "3.7.5"
"typescript": "^4.1.2"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",

View File

@ -1,10 +1,16 @@
declare const _exports: typeof Connection;
export = _exports;
export = Connection;
/**
* An implementation of the js-libp2p connection.
* Any libp2p transport should use an upgrader to return this connection.
*/
declare class Connection {
/**
* Checks if the given value is a `Connection` instance.
*
* @param {any} other
* @returns {other is Connection}
*/
static isConnection(other: any): other is Connection;
/**
* Creates an instance of Connection.
* @param {object} properties properties of the connection.
@ -24,10 +30,10 @@ declare class Connection {
* @param {string} [properties.stat.encryption] connection encryption method identifier.
*/
constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: {
localAddr?: import("multiaddr");
remoteAddr?: import("multiaddr");
localPeer: import("peer-id");
remotePeer: import("peer-id");
localAddr: multiaddr;
remoteAddr: multiaddr;
localPeer: PeerId;
remotePeer: PeerId;
newStream: Function;
close: Function;
getStreams: () => any[];
@ -37,35 +43,35 @@ declare class Connection {
open: string;
upgraded: string;
};
multiplexer?: string;
encryption?: string;
multiplexer: string;
encryption: string;
};
});
/**
* Connection identifier.
*/
id: any;
id: string;
/**
* Observed multiaddr of the local peer
*/
localAddr: import("multiaddr");
localAddr: multiaddr;
/**
* Observed multiaddr of the remote peer
*/
remoteAddr: import("multiaddr");
remoteAddr: multiaddr;
/**
* Local peer id.
*/
localPeer: import("peer-id");
localPeer: PeerId;
/**
* Remote peer id.
*/
remotePeer: import("peer-id");
remotePeer: PeerId;
/**
* Connection metadata.
*/
_stat: {
status: string;
status: "open";
direction: string;
timeline: {
open: string;
@ -95,12 +101,13 @@ declare class Connection {
* @type {string[]}
*/
tags: string[];
get [Symbol.toStringTag](): string;
/**
* Get connection metadata
* @this {Connection}
*/
get stat(): {
status: string;
status: "open";
direction: string;
timeline: {
open: string;
@ -133,7 +140,7 @@ declare class Connection {
*/
addStream(muxedStream: any, { protocol, metadata }: {
protocol: string;
metadata: any;
metadata: object;
}): void;
/**
* Remove stream registry after it is closed.
@ -146,4 +153,8 @@ declare class Connection {
*/
close(): Promise<void>;
_closing: any;
get [connectionSymbol](): boolean;
}
import multiaddr = require("multiaddr");
import PeerId = require("peer-id");
declare const connectionSymbol: unique symbol;

View File

@ -1,3 +1,3 @@
export declare const OPEN: string;
export declare const CLOSING: string;
export declare const CLOSED: string;
export const OPEN: 'open';
export const CLOSING: 'closing';
export const CLOSED: 'closed';

View File

@ -1,11 +1,11 @@
export namespace codes {
export const ERR_INVALID_SIGNATURE_POLICY: string;
export const ERR_UNHANDLED_SIGNATURE_POLICY: string;
export const ERR_MISSING_SIGNATURE: string;
export const ERR_MISSING_SEQNO: string;
export const ERR_INVALID_SIGNATURE: string;
export const ERR_UNEXPECTED_FROM: string;
export const ERR_UNEXPECTED_SIGNATURE: string;
export const ERR_UNEXPECTED_KEY: string;
export const ERR_UNEXPECTED_SEQNO: string;
const ERR_INVALID_SIGNATURE_POLICY: string;
const ERR_UNHANDLED_SIGNATURE_POLICY: string;
const ERR_MISSING_SIGNATURE: string;
const ERR_MISSING_SEQNO: string;
const ERR_INVALID_SIGNATURE: string;
const ERR_UNEXPECTED_FROM: string;
const ERR_UNEXPECTED_SIGNATURE: string;
const ERR_UNEXPECTED_KEY: string;
const ERR_UNEXPECTED_SEQNO: string;
}

49
src/pubsub/index.d.ts vendored
View File

@ -29,11 +29,14 @@ declare class PubsubBaseProtocol {
*/
constructor({ debugName, multicodecs, libp2p, globalSignaturePolicy, canRelayMessage, emitSelf }: {
debugName: string;
multicodecs: string | string[];
multicodecs: Array<string> | string;
libp2p: any;
globalSignaturePolicy?: any;
canRelayMessage?: boolean;
emitSelf?: boolean;
globalSignaturePolicy: {
StrictSign: "StrictSign";
StrictNoSign: string;
};
canRelayMessage: boolean;
emitSelf: boolean;
});
log: any;
/**
@ -91,7 +94,7 @@ declare class PubsubBaseProtocol {
* Topic validators are functions with the following input:
* @type {Map<string, validator>}
*/
topicValidators: Map<string, validator>;
topicValidators: Map<string, (arg0: string, arg1: InMessage) => Promise<void>>;
_registrarId: any;
/**
* On an inbound stream opened.
@ -101,25 +104,21 @@ declare class PubsubBaseProtocol {
* @param {DuplexIterableStream} props.stream
* @param {Connection} props.connection connection
*/
_onIncomingStream({ protocol, stream, connection }: {
protocol: string;
stream: any;
connection: any;
}): void;
private _onIncomingStream;
/**
* Registrar notifies an established connection with pubsub protocol.
* @private
* @param {PeerId} peerId remote peer-id
* @param {Connection} conn connection to the peer
*/
_onPeerConnected(peerId: import("peer-id"), conn: any): Promise<void>;
private _onPeerConnected;
/**
* Registrar notifies a closing connection with pubsub protocol.
* @private
* @param {PeerId} peerId peerId
* @param {Error} err error for connection end
*/
_onPeerDisconnected(peerId: import("peer-id"), err: Error): void;
private _onPeerDisconnected;
/**
* Register the pubsub protocol onto the libp2p node.
* @returns {void}
@ -137,14 +136,14 @@ declare class PubsubBaseProtocol {
* @param {string} protocol
* @returns {PeerStreams}
*/
_addPeer(peerId: import("peer-id"), protocol: string): import("./peer-streams");
private _addPeer;
/**
* Notifies the router that a peer has been disconnected.
* @private
* @param {PeerId} peerId
* @returns {PeerStreams | undefined}
*/
_removePeer(peerId: import("peer-id")): import("./peer-streams");
private _removePeer;
/**
* Responsible for processing each RPC message received by other peers.
* @param {string} idB58Str peer id string in base58
@ -152,7 +151,7 @@ declare class PubsubBaseProtocol {
* @param {PeerStreams} peerStreams PubSub peer
* @returns {Promise<void>}
*/
_processMessages(idB58Str: string, stream: any, peerStreams: import("./peer-streams")): Promise<void>;
_processMessages(idB58Str: string, stream: any, peerStreams: PeerStreams): Promise<void>;
/**
* Handles an rpc request from a peer
* @param {String} idB58Str
@ -160,7 +159,7 @@ declare class PubsubBaseProtocol {
* @param {RPC} rpc
* @returns {boolean}
*/
_processRpc(idB58Str: string, peerStreams: import("./peer-streams"), rpc: any): boolean;
_processRpc(idB58Str: string, peerStreams: PeerStreams, rpc: any): boolean;
/**
* Handles a subscription change from a peer
* @param {string} id
@ -236,13 +235,13 @@ declare class PubsubBaseProtocol {
* @param {Message} message
* @returns {Promise<Message>}
*/
_buildMessage(message: any): Promise<any>;
private _buildMessage;
/**
* Get a list of the peer-ids that are subscribed to one topic.
* @param {string} topic
* @returns {Array<string>}
*/
getSubscribers(topic: string): string[];
getSubscribers(topic: string): Array<string>;
/**
* Publishes messages to all subscribed peers
* @override
@ -279,16 +278,12 @@ declare class PubsubBaseProtocol {
* @override
* @returns {Array<String>}
*/
getTopics(): string[];
getTopics(): Array<string>;
}
declare namespace PubsubBaseProtocol {
export { message, utils, SignaturePolicy, InMessage, PeerId };
}
type PeerId = import("peer-id");
/**
* Topic validator function
*/
type validator = (arg0: string, arg1: InMessage) => Promise<void>;
type InMessage = {
from?: string;
receivedFrom: string;
@ -298,12 +293,10 @@ type InMessage = {
signature?: Uint8Array;
key?: Uint8Array;
};
import PeerStreams = require("./peer-streams");
/**
* @type {typeof import('./message')}
*/
declare const message: typeof import('./message');
declare const utils: typeof import("./utils");
declare const SignaturePolicy: {
StrictSign: string;
StrictNoSign: string;
};
import utils = require("./utils");
import { SignaturePolicy } from "./signature-policy";

View File

@ -1,5 +1,4 @@
export var rpc: any;
export var td: any;
export var RPC: any;
export var Message: any;
export var SubOpts: any;
declare const rpcProto: any;
declare const topicDescriptorProto: any;
export const RPC: any;
export { rpcProto as rpc, topicDescriptorProto as td };

View File

@ -13,7 +13,7 @@ export function messagePublicKey(message: any): Promise<any>;
* @param {Message} message
* @returns {Promise<Message>}
*/
export function signMessage(peerId: import("peer-id"), message: any): Promise<any>;
export function signMessage(peerId: PeerId, message: any): Promise<any>;
export const SignPrefix: any;
/**
* Verifies the signature of the given message
@ -21,3 +21,4 @@ export const SignPrefix: any;
* @returns {Promise<Boolean>}
*/
export function verifySignature(message: any): Promise<boolean>;
import PeerId = require("peer-id");

View File

@ -21,7 +21,7 @@ declare class PeerStreams {
* @param {string} properties.protocol
*/
constructor({ id, protocol }: {
id: import("peer-id");
id: PeerId;
protocol: string;
});
/**
@ -38,19 +38,19 @@ declare class PeerStreams {
* @private
* @type {DuplexIterableStream}
*/
_rawOutboundStream: DuplexIterableStream;
private _rawOutboundStream;
/**
* The raw inbound stream, as retrieved from the callback from libp2p.handle
* @private
* @type {DuplexIterableStream}
*/
_rawInboundStream: DuplexIterableStream;
private _rawInboundStream;
/**
* An AbortController for controlled shutdown of the inbound stream
* @private
* @type {typeof AbortController}
*/
_inboundAbortController: typeof AbortController;
private _inboundAbortController;
/**
* Write stream -- its preferable to use the write method
* @type {import('it-pushable').Pushable<Uint8Array>>}
@ -106,8 +106,7 @@ declare namespace PeerStreams {
}
type DuplexIterableStream = {
sink: Sink;
source: () => AsyncIterator<Uint8Array, any, undefined>;
source: () => AsyncIterator<Uint8Array>;
};
declare const AbortController: typeof import("abort-controller");
type Sink = (source: Uint8Array) => Promise<Uint8Array>;
type PeerId = import("peer-id");
type Sink = (source: Uint8Array) => Promise<Uint8Array>;

View File

@ -1,4 +1,4 @@
export namespace SignaturePolicy {
export const StrictSign: string;
export const StrictNoSign: string;
const StrictSign: 'StrictSign';
const StrictNoSign: string;
}

14
src/pubsub/utils.d.ts vendored
View File

@ -1,7 +1,13 @@
export function randomSeqno(): Uint8Array;
export function msgId(from: string, seqno: Uint8Array): Uint8Array;
export function noSignMsgId(data: Uint8Array): Uint8Array;
export function anyMatch(a: any[] | Set<any>, b: any[] | Set<any>): boolean;
export function ensureArray(maybeArray: any): any[];
export function normalizeInRpcMessage(message: any, peerId: string): any;
export function normalizeOutRpcMessage(message: any): any;
export function anyMatch(a: Set<any> | any[], b: Set<any> | any[]): boolean;
export function ensureArray<T>(maybeArray: T | T[]): T[];
export function normalizeInRpcMessage<T extends unknown>(message: T, peerId?: string): T & {
from?: string;
peerId?: string;
};
export function normalizeOutRpcMessage<T extends unknown>(message: T): T & {
from?: Uint8Array;
data?: Uint8Array;
};

View File

@ -1,10 +1,16 @@
declare const _exports: Topology;
export = _exports;
export = Topology;
declare class Topology {
/**
* Checks if the given value is a Topology instance.
*
* @param {any} other
* @returns {other is Topology}
*/
static isTopology(other: any): other is Topology;
/**
* @param {Object} props
* @param {number} props.min minimum needed connections (default: 0)
* @param {number} props.max maximum needed connections (default: Infinity)
* @param {number} [props.min] minimum needed connections (default: 0)
* @param {number} [props.max] maximum needed connections (default: Infinity)
* @param {Object} [props.handlers]
* @param {function} [props.handlers.onConnect] protocol "onConnect" handler
* @param {function} [props.handlers.onDisconnect] protocol "onDisconnect" handler
@ -13,9 +19,9 @@ declare class Topology {
constructor({ min, max, handlers }: {
min: number;
max: number;
handlers?: {
onConnect?: Function;
onDisconnect?: Function;
handlers: {
onConnect: Function;
onDisconnect: Function;
};
});
min: number;
@ -27,6 +33,7 @@ declare class Topology {
* @type {Set<string>}
*/
peers: Set<string>;
get [Symbol.toStringTag](): string;
set registrar(arg: any);
_registrar: any;
/**
@ -39,4 +46,6 @@ declare class Topology {
* @returns {void}
*/
disconnect(peerId: import("peer-id")): void;
get [topologySymbol](): boolean;
}
declare const topologySymbol: unique symbol;

View File

@ -1,5 +1,12 @@
export = MulticodecTopology;
declare class MulticodecTopology {
declare class MulticodecTopology extends Topology {
/**
* Checks if the given value is a `MulticodecTopology` instance.
*
* @param {any} other
* @returns {other is MulticodecTopology}
*/
static isMulticodecTopology(other: any): other is MulticodecTopology;
/**
* @param {Object} props
* @param {number} [props.min] minimum needed connections (default: 0)
@ -11,16 +18,15 @@ declare class MulticodecTopology {
* @constructor
*/
constructor({ min, max, multicodecs, handlers }: {
min?: number;
max?: number;
multicodecs: string[];
min: number;
max: number;
multicodecs: Array<string>;
handlers: {
onConnect: Function;
onDisconnect: Function;
};
});
multicodecs: string[];
_registrar: any;
/**
* Check if a new peer support the multicodecs for this topology.
* @param {Object} props
@ -29,7 +35,7 @@ declare class MulticodecTopology {
*/
_onProtocolChange({ peerId, protocols }: {
peerId: any;
protocols: string[];
protocols: Array<string>;
}): void;
/**
* Verify if a new connected peer has a topology multicodec and call _onConnect.
@ -37,15 +43,17 @@ declare class MulticodecTopology {
* @returns {void}
*/
_onPeerConnect(connection: any): void;
set registrar(arg: any);
/**
* Update topology.
* @param {Array<{id: PeerId, multiaddrs: Array<Multiaddr>, protocols: Array<string>}>} peerDataIterable
* @returns {void}
*/
_updatePeers(peerDataIterable: {
_updatePeers(peerDataIterable: Array<{
id: any;
multiaddrs: any[];
protocols: string[];
}[]): void;
multiaddrs: Array<any>;
protocols: Array<string>;
}>): void;
get [multicodecTopologySymbol](): boolean;
}
import Topology = require(".");
declare const multicodecTopologySymbol: unique symbol;