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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ export function messagePublicKey(message: any): Promise<any>;
* @param {Message} message * @param {Message} message
* @returns {Promise<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; export const SignPrefix: any;
/** /**
* Verifies the signature of the given message * Verifies the signature of the given message
@ -21,3 +21,4 @@ export const SignPrefix: any;
* @returns {Promise<Boolean>} * @returns {Promise<Boolean>}
*/ */
export function verifySignature(message: any): 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 * @param {string} properties.protocol
*/ */
constructor({ id, protocol }: { constructor({ id, protocol }: {
id: import("peer-id"); id: PeerId;
protocol: string; protocol: string;
}); });
/** /**
@ -38,19 +38,19 @@ declare class PeerStreams {
* @private * @private
* @type {DuplexIterableStream} * @type {DuplexIterableStream}
*/ */
_rawOutboundStream: DuplexIterableStream; private _rawOutboundStream;
/** /**
* The raw inbound stream, as retrieved from the callback from libp2p.handle * The raw inbound stream, as retrieved from the callback from libp2p.handle
* @private * @private
* @type {DuplexIterableStream} * @type {DuplexIterableStream}
*/ */
_rawInboundStream: DuplexIterableStream; private _rawInboundStream;
/** /**
* An AbortController for controlled shutdown of the inbound stream * An AbortController for controlled shutdown of the inbound stream
* @private * @private
* @type {typeof AbortController} * @type {typeof AbortController}
*/ */
_inboundAbortController: typeof AbortController; private _inboundAbortController;
/** /**
* Write stream -- its preferable to use the write method * Write stream -- its preferable to use the write method
* @type {import('it-pushable').Pushable<Uint8Array>>} * @type {import('it-pushable').Pushable<Uint8Array>>}
@ -106,8 +106,7 @@ declare namespace PeerStreams {
} }
type DuplexIterableStream = { type DuplexIterableStream = {
sink: Sink; 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 PeerId = import("peer-id");
type Sink = (source: Uint8Array) => Promise<Uint8Array>;

View File

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

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

@ -1,7 +1,13 @@
export function randomSeqno(): Uint8Array; export function randomSeqno(): Uint8Array;
export function msgId(from: string, seqno: Uint8Array): Uint8Array; export function msgId(from: string, seqno: Uint8Array): Uint8Array;
export function noSignMsgId(data: Uint8Array): Uint8Array; export function noSignMsgId(data: Uint8Array): Uint8Array;
export function anyMatch(a: any[] | Set<any>, b: any[] | Set<any>): boolean; export function anyMatch(a: Set<any> | any[], b: Set<any> | any[]): boolean;
export function ensureArray(maybeArray: any): any[]; export function ensureArray<T>(maybeArray: T | T[]): T[];
export function normalizeInRpcMessage(message: any, peerId: string): any; export function normalizeInRpcMessage<T extends unknown>(message: T, peerId?: string): T & {
export function normalizeOutRpcMessage(message: any): any; 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 = Topology;
export = _exports;
declare class 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 {Object} props
* @param {number} props.min minimum needed connections (default: 0) * @param {number} [props.min] minimum needed connections (default: 0)
* @param {number} props.max maximum needed connections (default: Infinity) * @param {number} [props.max] maximum needed connections (default: Infinity)
* @param {Object} [props.handlers] * @param {Object} [props.handlers]
* @param {function} [props.handlers.onConnect] protocol "onConnect" handler * @param {function} [props.handlers.onConnect] protocol "onConnect" handler
* @param {function} [props.handlers.onDisconnect] protocol "onDisconnect" handler * @param {function} [props.handlers.onDisconnect] protocol "onDisconnect" handler
@ -13,9 +19,9 @@ declare class Topology {
constructor({ min, max, handlers }: { constructor({ min, max, handlers }: {
min: number; min: number;
max: number; max: number;
handlers?: { handlers: {
onConnect?: Function; onConnect: Function;
onDisconnect?: Function; onDisconnect: Function;
}; };
}); });
min: number; min: number;
@ -27,6 +33,7 @@ declare class Topology {
* @type {Set<string>} * @type {Set<string>}
*/ */
peers: Set<string>; peers: Set<string>;
get [Symbol.toStringTag](): string;
set registrar(arg: any); set registrar(arg: any);
_registrar: any; _registrar: any;
/** /**
@ -39,4 +46,6 @@ declare class Topology {
* @returns {void} * @returns {void}
*/ */
disconnect(peerId: import("peer-id")): void; disconnect(peerId: import("peer-id")): void;
get [topologySymbol](): boolean;
} }
declare const topologySymbol: unique symbol;

View File

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