diff --git a/src/connection/connection.d.ts b/src/connection/connection.d.ts deleted file mode 100644 index 1e962dd..0000000 --- a/src/connection/connection.d.ts +++ /dev/null @@ -1,258 +0,0 @@ -export = Connection; -/** - * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream - */ -/** - * @typedef {Object} ConectionStat - * @property {string} direction - connection establishment direction ("inbound" or "outbound"). - * @property {object} timeline - connection relevant events timestamp. - * @property {number} timeline.open - connection opening timestamp. - * @property {number} [timeline.upgraded] - connection upgraded timestamp. - * @property {number} [timeline.close] - connection upgraded timestamp. - * @property {string} [multiplexer] - connection multiplexing identifier. - * @property {string} [encryption] - connection encryption method identifier. - * - * @typedef {Object} ConnectionOptions - * @property {multiaddr} [localAddr] - local multiaddr of the connection if known. - * @property {multiaddr} remoteAddr - remote multiaddr of the connection. - * @property {PeerId} localPeer - local peer-id. - * @property {PeerId} remotePeer - remote peer-id. - * @property {(protocols: string|string[]) => Promise<{stream: MuxedStream, protocol: string}>} newStream - new stream muxer function. - * @property {() => Promise} close - close raw connection function. - * @property {() => MuxedStream[]} getStreams - get streams from muxer function. - * @property {ConectionStat} stat - metadata of the 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; - /** - * An implementation of the js-libp2p connection. - * Any libp2p transport should use an upgrader to return this connection. - * - * @class - * @param {ConnectionOptions} options - */ - constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: ConnectionOptions); - /** - * Connection identifier. - */ - id: string; - /** - * Observed multiaddr of the local peer - */ - localAddr: import("multiaddr") | undefined; - /** - * Observed multiaddr of the remote peer - */ - remoteAddr: import("multiaddr"); - /** - * Local peer id. - */ - localPeer: import("peer-id"); - /** - * Remote peer id. - */ - remotePeer: import("peer-id"); - /** - * Connection metadata. - */ - _stat: { - status: "open"; - /** - * - connection establishment direction ("inbound" or "outbound"). - */ - direction: string; - /** - * - connection relevant events timestamp. - */ - timeline: { - open: number; - upgraded: number | undefined; - close: number | undefined; - }; - /** - * - connection multiplexing identifier. - */ - multiplexer?: string | undefined; - /** - * - connection encryption method identifier. - */ - encryption?: string | undefined; - }; - /** - * Reference to the new stream function of the multiplexer - */ - _newStream: (protocols: string | string[]) => Promise<{ - stream: MuxedStream; - protocol: string; - }>; - /** - * Reference to the close function of the raw connection - */ - _close: () => Promise; - /** - * Reference to the getStreams function of the muxer - */ - _getStreams: () => MuxedStream[]; - /** - * Connection streams registry - */ - registry: Map; - /** - * User provided tags - * - * @type {string[]} - */ - tags: string[]; - get [Symbol.toStringTag](): string; - /** - * Get connection metadata - * - * @this {Connection} - */ - get stat(): { - status: "open"; - /** - * - connection establishment direction ("inbound" or "outbound"). - */ - direction: string; - /** - * - connection relevant events timestamp. - */ - timeline: { - open: number; - upgraded: number | undefined; - close: number | undefined; - }; - /** - * - connection multiplexing identifier. - */ - multiplexer?: string | undefined; - /** - * - connection encryption method identifier. - */ - encryption?: string | undefined; - }; - /** - * Get all the streams of the muxer. - * - * @this {Connection} - */ - get streams(): import("../stream-muxer/types").MuxedStream[]; - /** - * Create a new stream from this connection - * - * @param {string|string[]} protocols - intended protocol for the stream - * @returns {Promise<{stream: MuxedStream, protocol: string}>} with muxed+multistream-selected stream and selected protocol - */ - newStream(protocols: string | string[]): Promise<{ - stream: MuxedStream; - protocol: string; - }>; - /** - * Add a stream when it is opened to the registry. - * - * @param {MuxedStream} muxedStream - a muxed stream - * @param {object} properties - the stream properties to be registered - * @param {string} properties.protocol - the protocol used by the stream - * @param {object} properties.metadata - metadata of the stream - * @returns {void} - */ - addStream(muxedStream: MuxedStream, { protocol, metadata }: { - protocol: string; - metadata: object; - }): void; - /** - * Remove stream registry after it is closed. - * - * @param {string} id - identifier of the stream - */ - removeStream(id: string): void; - /** - * Close the connection. - * - * @returns {Promise} - */ - close(): Promise; - _closing: void | undefined; -} -declare namespace Connection { - export { MuxedStream, ConectionStat, ConnectionOptions }; -} -type MuxedStream = { - close: () => void; - abort: () => void; - reset: () => void; - sink: (source: Uint8Array) => Promise; - source: () => AsyncIterable; - timeline: import("../stream-muxer/types").MuxedTimeline; - id: string; -}; -type ConnectionOptions = { - /** - * - local multiaddr of the connection if known. - */ - localAddr?: import("multiaddr") | undefined; - /** - * - remote multiaddr of the connection. - */ - remoteAddr: import("multiaddr"); - /** - * - local peer-id. - */ - localPeer: import("peer-id"); - /** - * - remote peer-id. - */ - remotePeer: import("peer-id"); - /** - * - new stream muxer function. - */ - newStream: (protocols: string | string[]) => Promise<{ - stream: MuxedStream; - protocol: string; - }>; - /** - * - close raw connection function. - */ - close: () => Promise; - /** - * - get streams from muxer function. - */ - getStreams: () => MuxedStream[]; - /** - * - metadata of the connection. - */ - stat: ConectionStat; -}; -type ConectionStat = { - /** - * - connection establishment direction ("inbound" or "outbound"). - */ - direction: string; - /** - * - connection relevant events timestamp. - */ - timeline: { - open: number; - upgraded: number | undefined; - close: number | undefined; - }; - /** - * - connection multiplexing identifier. - */ - multiplexer?: string | undefined; - /** - * - connection encryption method identifier. - */ - encryption?: string | undefined; -}; diff --git a/src/connection/index.d.ts b/src/connection/index.d.ts deleted file mode 100644 index 5dc4503..0000000 --- a/src/connection/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export var Connection: typeof import('./connection'); diff --git a/src/connection/status.d.ts b/src/connection/status.d.ts deleted file mode 100644 index cef75f2..0000000 --- a/src/connection/status.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const OPEN: 'open'; -export const CLOSING: 'closing'; -export const CLOSED: 'closed'; diff --git a/src/crypto/errors.d.ts b/src/crypto/errors.d.ts deleted file mode 100644 index 0e1afe5..0000000 --- a/src/crypto/errors.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export class UnexpectedPeerError extends Error { - static get code(): string; - constructor(message?: string); - code: string; -} -export class InvalidCryptoExchangeError extends Error { - static get code(): string; - constructor(message?: string); - code: string; -} -export class InvalidCryptoTransmissionError extends Error { - static get code(): string; - constructor(message?: string); - code: string; -} diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/pubsub/errors.d.ts b/src/pubsub/errors.d.ts deleted file mode 100644 index b5349d1..0000000 --- a/src/pubsub/errors.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -export namespace codes { - 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; -} diff --git a/src/pubsub/index.d.ts b/src/pubsub/index.d.ts deleted file mode 100644 index db50582..0000000 --- a/src/pubsub/index.d.ts +++ /dev/null @@ -1,332 +0,0 @@ -export = PubsubBaseProtocol; -/** - * @typedef {Object} InMessage - * @property {string} [from] - * @property {string} receivedFrom - * @property {string[]} topicIDs - * @property {Uint8Array} [seqno] - * @property {Uint8Array} data - * @property {Uint8Array} [signature] - * @property {Uint8Array} [key] - * - * @typedef PeerId - * @type import('peer-id') - */ -/** - * PubsubBaseProtocol handles the peers and connections logic for pubsub routers - * and specifies the API that pubsub routers should have. - */ -declare class PubsubBaseProtocol { - /** - * @param {Object} props - * @param {string} props.debugName - log namespace - * @param {Array|string} props.multicodecs - protocol identificers to connect - * @param {Libp2p} props.libp2p - * @param {SignaturePolicy} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled - * @param {boolean} [props.canRelayMessage = false] - if can relay messages not subscribed - * @param {boolean} [props.emitSelf = false] - if publish should emit to self, if subscribed - * @abstract - */ - constructor({ debugName, multicodecs, libp2p, globalSignaturePolicy, canRelayMessage, emitSelf }: { - debugName: string; - multicodecs: Array | string; - libp2p: any; - globalSignaturePolicy: any; - canRelayMessage: boolean | undefined; - emitSelf: boolean | undefined; - }); - log: any; - /** - * @type {Array} - */ - multicodecs: Array; - _libp2p: any; - registrar: any; - /** - * @type {PeerId} - */ - peerId: PeerId; - started: boolean; - /** - * Map of topics to which peers are subscribed to - * - * @type {Map>} - */ - topics: Map>; - /** - * List of our subscriptions - * - * @type {Set} - */ - subscriptions: Set; - /** - * Map of peer streams - * - * @type {Map} - */ - peers: Map; - /** - * The signature policy to follow by default - * - * @type {string} - */ - globalSignaturePolicy: string; - /** - * If router can relay received messages, even if not subscribed - * - * @type {boolean} - */ - canRelayMessage: boolean; - /** - * if publish should emit to self, if subscribed - * - * @type {boolean} - */ - emitSelf: boolean; - /** - * Topic validator function - * - * @typedef {function(string, InMessage): Promise} validator - */ - /** - * Topic validator map - * - * Keyed by topic - * Topic validators are functions with the following input: - * - * @type {Map} - */ - topicValidators: Map Promise>; - _registrarId: any; - /** - * On an inbound stream opened. - * - * @private - * @param {Object} props - * @param {string} props.protocol - * @param {DuplexIterableStream} props.stream - * @param {Connection} props.connection - connection - */ - private _onIncomingStream; - /** - * Registrar notifies an established connection with pubsub protocol. - * - * @private - * @param {PeerId} peerId - remote peer-id - * @param {Connection} conn - connection to the peer - */ - private _onPeerConnected; - /** - * Registrar notifies a closing connection with pubsub protocol. - * - * @private - * @param {PeerId} peerId - peerId - * @param {Error} err - error for connection end - */ - private _onPeerDisconnected; - /** - * Register the pubsub protocol onto the libp2p node. - * - * @returns {void} - */ - start(): void; - /** - * Unregister the pubsub protocol and the streams with other peers will be closed. - * - * @returns {void} - */ - stop(): void; - /** - * Notifies the router that a peer has been connected - * - * @private - * @param {PeerId} peerId - * @param {string} protocol - * @returns {PeerStreams} - */ - private _addPeer; - /** - * Notifies the router that a peer has been disconnected. - * - * @private - * @param {PeerId} peerId - * @returns {PeerStreams | undefined} - */ - private _removePeer; - /** - * Responsible for processing each RPC message received by other peers. - * - * @param {string} idB58Str - peer id string in base58 - * @param {DuplexIterableStream} stream - inbound stream - * @param {PeerStreams} peerStreams - PubSub peer - * @returns {Promise} - */ - _processMessages(idB58Str: string, stream: any, peerStreams: import("./peer-streams")): Promise; - /** - * Handles an rpc request from a peer - * - * @param {string} idB58Str - * @param {PeerStreams} peerStreams - * @param {RPC} rpc - * @returns {boolean} - */ - _processRpc(idB58Str: string, peerStreams: import("./peer-streams"), rpc: any): boolean; - /** - * Handles a subscription change from a peer - * - * @param {string} id - * @param {RPC.SubOpt} subOpt - */ - _processRpcSubOpt(id: string, subOpt: any): void; - /** - * Handles an message from a peer - * - * @param {InMessage} msg - * @returns {Promise} - */ - _processRpcMessage(msg: InMessage): Promise; - /** - * Emit a message from a peer - * - * @param {InMessage} message - */ - _emitMessage(message: InMessage): void; - /** - * The default msgID implementation - * Child class can override this. - * - * @param {RPC.Message} msg - the message object - * @returns {Uint8Array} message id as bytes - */ - getMsgId(msg: any): Uint8Array; - /** - * Whether to accept a message from a peer - * Override to create a graylist - * - * @override - * @param {string} id - * @returns {boolean} - */ - _acceptFrom(id: string): boolean; - /** - * Decode Uint8Array into an RPC object. - * This can be override to use a custom router protobuf. - * - * @param {Uint8Array} bytes - * @returns {RPC} - */ - _decodeRpc(bytes: Uint8Array): any; - /** - * Encode RPC object into a Uint8Array. - * This can be override to use a custom router protobuf. - * - * @param {RPC} rpc - * @returns {Uint8Array} - */ - _encodeRpc(rpc: any): Uint8Array; - /** - * Send an rpc object to a peer - * - * @param {string} id - peer id - * @param {RPC} rpc - * @returns {void} - */ - _sendRpc(id: string, rpc: any): void; - /** - * Send subscroptions to a peer - * - * @param {string} id - peer id - * @param {string[]} topics - * @param {boolean} subscribe - set to false for unsubscriptions - * @returns {void} - */ - _sendSubscriptions(id: string, topics: string[], subscribe: boolean): void; - /** - * Validates the given message. The signature will be checked for authenticity. - * Throws an error on invalid messages - * - * @param {InMessage} message - * @returns {Promise} - */ - validate(message: InMessage): Promise; - /** - * Normalizes the message and signs it, if signing is enabled. - * Should be used by the routers to create the message to send. - * - * @private - * @param {Message} message - * @returns {Promise} - */ - private _buildMessage; - /** - * Get a list of the peer-ids that are subscribed to one topic. - * - * @param {string} topic - * @returns {Array} - */ - getSubscribers(topic: string): Array; - /** - * Publishes messages to all subscribed peers - * - * @override - * @param {string} topic - * @param {Buffer} message - * @returns {Promise} - */ - publish(topic: string, message: Buffer): Promise; - /** - * Overriding the implementation of publish should handle the appropriate algorithms for the publish/subscriber implementation. - * For example, a Floodsub implementation might simply publish each message to each topic for every peer - * - * @abstract - * @param {InMessage} message - * @returns {Promise} - * - */ - _publish(message: InMessage): Promise; - /** - * Subscribes to a given topic. - * - * @abstract - * @param {string} topic - * @returns {void} - */ - subscribe(topic: string): void; - /** - * Unsubscribe from the given topic. - * - * @override - * @param {string} topic - * @returns {void} - */ - unsubscribe(topic: string): void; - /** - * Get the list of topics which the peer is subscribed to. - * - * @override - * @returns {Array} - */ - getTopics(): Array; -} -declare namespace PubsubBaseProtocol { - export { message, utils, SignaturePolicy, InMessage, PeerId }; -} -type PeerId = import("peer-id"); -type InMessage = { - from?: string | undefined; - receivedFrom: string; - topicIDs: string[]; - seqno?: Uint8Array | undefined; - data: Uint8Array; - signature?: Uint8Array | undefined; - key?: Uint8Array | undefined; -}; -/** - * @type {typeof import('./message')} - */ -declare const message: typeof import('./message'); -declare const utils: typeof import("./utils"); -declare const SignaturePolicy: { - StrictSign: "StrictSign"; - StrictNoSign: string; -}; diff --git a/src/pubsub/message/index.d.ts b/src/pubsub/message/index.d.ts deleted file mode 100644 index 62df1ce..0000000 --- a/src/pubsub/message/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export var rpc: any; -export var td: any; -export var RPC: any; -export var Message: any; -export var SubOpts: any; diff --git a/src/pubsub/message/rpc.proto.d.ts b/src/pubsub/message/rpc.proto.d.ts deleted file mode 100644 index 763ab62..0000000 --- a/src/pubsub/message/rpc.proto.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const _exports: string; -export = _exports; diff --git a/src/pubsub/message/sign.d.ts b/src/pubsub/message/sign.d.ts deleted file mode 100644 index cdecc35..0000000 --- a/src/pubsub/message/sign.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Returns the PublicKey associated with the given message. - * If no, valid PublicKey can be retrieved an error will be returned. - * - * @param {InMessage} message - * @returns {Promise} - */ -export function messagePublicKey(message: any): Promise; -/** - * Signs the provided message with the given `peerId` - * - * @param {PeerId} peerId - * @param {Message} message - * @returns {Promise} - */ -export function signMessage(peerId: import("peer-id"), message: any): Promise; -export const SignPrefix: any; -/** - * Verifies the signature of the given message - * - * @param {InMessage} message - * @returns {Promise} - */ -export function verifySignature(message: any): Promise; diff --git a/src/pubsub/message/topic-descriptor.proto.d.ts b/src/pubsub/message/topic-descriptor.proto.d.ts deleted file mode 100644 index 763ab62..0000000 --- a/src/pubsub/message/topic-descriptor.proto.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare const _exports: string; -export = _exports; diff --git a/src/pubsub/peer-streams.d.ts b/src/pubsub/peer-streams.d.ts deleted file mode 100644 index 9f8d9cc..0000000 --- a/src/pubsub/peer-streams.d.ts +++ /dev/null @@ -1,119 +0,0 @@ -export = PeerStreams; -/** - * @callback Sink - * @param {Uint8Array} source - * @returns {Promise} - * - * @typedef {object} DuplexIterableStream - * @property {Sink} sink - * @property {() AsyncIterator} source - * - * @typedef PeerId - * @type import('peer-id') - */ -/** - * Thin wrapper around a peer's inbound / outbound pubsub streams - */ -declare class PeerStreams { - /** - * @param {object} properties - properties of the PeerStreams. - * @param {PeerId} properties.id - * @param {string} properties.protocol - */ - constructor({ id, protocol }: { - id: PeerId; - protocol: string; - }); - /** - * @type {import('peer-id')} - */ - id: import('peer-id'); - /** - * Established protocol - * - * @type {string} - */ - protocol: string; - /** - * The raw outbound stream, as retrieved from conn.newStream - * - * @private - * @type {DuplexIterableStream} - */ - private _rawOutboundStream; - /** - * The raw inbound stream, as retrieved from the callback from libp2p.handle - * - * @private - * @type {DuplexIterableStream} - */ - private _rawInboundStream; - /** - * An AbortController for controlled shutdown of the inbound stream - * - * @private - * @type {typeof AbortController} - */ - private _inboundAbortController; - /** - * Write stream -- its preferable to use the write method - * - * @type {import('it-pushable').Pushable>} - */ - outboundStream: import('it-pushable').Pushable; - /** - * Read stream - * - * @type {DuplexIterableStream} - */ - inboundStream: DuplexIterableStream; - /** - * Do we have a connection to read from? - * - * @type {boolean} - */ - get isReadable(): boolean; - /** - * Do we have a connection to write on? - * - * @type {boolean} - */ - get isWritable(): boolean; - /** - * Send a message to this peer. - * Throws if there is no `stream` to write to available. - * - * @param {Uint8Array} data - * @returns {void} - */ - write(data: Uint8Array): void; - /** - * Attach a raw inbound stream and setup a read stream - * - * @param {DuplexIterableStream} stream - * @returns {void} - */ - attachInboundStream(stream: DuplexIterableStream): void; - /** - * Attach a raw outbound stream and setup a write stream - * - * @param {Stream} stream - * @returns {Promise} - */ - attachOutboundStream(stream: any): Promise; - /** - * Closes the open connection to peer - * - * @returns {void} - */ - close(): void; -} -declare namespace PeerStreams { - export { Sink, DuplexIterableStream, PeerId }; -} -type DuplexIterableStream = { - sink: Sink; - source: () => AsyncIterator; -}; -type PeerId = import("peer-id"); -type Sink = (source: Uint8Array) => Promise; diff --git a/src/pubsub/signature-policy.d.ts b/src/pubsub/signature-policy.d.ts deleted file mode 100644 index f8b07a1..0000000 --- a/src/pubsub/signature-policy.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export namespace SignaturePolicy { - const StrictSign: 'StrictSign'; - const StrictNoSign: string; -} diff --git a/src/pubsub/utils.d.ts b/src/pubsub/utils.d.ts deleted file mode 100644 index 3a95fdd..0000000 --- a/src/pubsub/utils.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export function randomSeqno(): Uint8Array; -export function msgId(from: string, seqno: Uint8Array): Uint8Array; -export function noSignMsgId(data: Uint8Array): Uint8Array; -export function anyMatch(a: Set | any[], b: Set | any[]): boolean; -export function ensureArray(maybeArray: T | T[]): T[]; -export function normalizeInRpcMessage(message: T, peerId?: string | undefined): T & { - from?: string | undefined; - peerId?: string | undefined; -}; -export function normalizeOutRpcMessage(message: T): T & { - from?: Uint8Array | undefined; - data?: Uint8Array | undefined; -}; diff --git a/src/record/index.d.ts b/src/record/index.d.ts deleted file mode 100644 index 781889c..0000000 --- a/src/record/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -export = Record; -/** - * Record is the base implementation of a record that can be used as the payload of a libp2p envelope. - */ -declare class Record { - /** - * @class - * @param {string} domain - signature domain - * @param {Uint8Array} codec - identifier of the type of record - */ - constructor(domain: string, codec: Uint8Array); - domain: string; - codec: Uint8Array; - /** - * Marshal a record to be used in an envelope. - * @returns {Uint8Array} - */ - marshal(): Uint8Array; - /** - * Verifies if the other provided Record is identical to this one. - * - * @param {Record} other - * @returns {boolean} - */ - equals(other: Record): boolean; -} diff --git a/src/stream-muxer/types.d.ts b/src/stream-muxer/types.d.ts deleted file mode 100644 index bc2a925..0000000 --- a/src/stream-muxer/types.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * A libp2p stream muxer - */ -export interface StreamMuxerInterface { - readonly streams: Array; - /** - * Initiate a new stream with the given name. If no name is - * provided, the id of th stream will be used. - * - * @param {string} [name] - If name is not a string it will be cast to one - * @returns {Stream} - */ - newStream(name?: string): MuxedStream; - onStream(stream: MuxedStream): void; - onStreamEnd(stream: MuxedStream): void; -} -export declare class Muxer implements StreamMuxerInterface { - multicodec: string; - readonly streams: Array; - newStream(name?: string): MuxedStream; - onStream(stream: MuxedStream): void; - onStreamEnd(stream: MuxedStream): void; -} -export declare type MuxedTimeline = { - open: number; - close?: number; -}; -export declare type MuxedStream = { - close: () => void; - abort: () => void; - reset: () => void; - sink: Sink; - source: () => AsyncIterable; - timeline: MuxedTimeline; - id: string; -}; -declare type Sink = (source: Uint8Array) => Promise; -export {}; diff --git a/src/topology/index.d.ts b/src/topology/index.d.ts deleted file mode 100644 index 17f0768..0000000 --- a/src/topology/index.d.ts +++ /dev/null @@ -1,74 +0,0 @@ -export = Topology; -/** - * @typedef {import('peer-id')} PeerId - */ -/** - * @typedef {Object} Options - * @property {number} [min=0] - minimum needed connections. - * @property {number} [max=Infinity] - maximum needed connections. - * @property {Handlers} [handlers] - * - * @typedef {Object} Handlers - * @property {(peerId: PeerId, conn: import('../connection')) => void} [onConnect] - protocol "onConnect" handler - * @property {(peerId: PeerId) => void} [onDisconnect] - protocol "onDisconnect" handler - */ -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 {Options} options - */ - constructor({ min, max, handlers }: Options); - min: number; - max: number; - _onConnect: (peerId: PeerId, conn: import('../connection')) => void; - _onDisconnect: (peerId: PeerId) => void; - /** - * Set of peers that support the protocol. - * - * @type {Set} - */ - peers: Set; - get [Symbol.toStringTag](): string; - set registrar(arg: any); - _registrar: any; - /** - * Notify about peer disconnected event. - * - * @param {PeerId} peerId - * @returns {void} - */ - disconnect(peerId: PeerId): void; - get [topologySymbol](): boolean; -} -declare namespace Topology { - export { PeerId, Options, Handlers }; -} -type PeerId = import("peer-id"); -declare const topologySymbol: unique symbol; -type Options = { - /** - * - minimum needed connections. - */ - min?: number | undefined; - /** - * - maximum needed connections. - */ - max?: number | undefined; - handlers?: Handlers | undefined; -}; -type Handlers = { - /** - * - protocol "onConnect" handler - */ - onConnect?: ((peerId: PeerId, conn: import('../connection')) => void) | undefined; - /** - * - protocol "onDisconnect" handler - */ - onDisconnect?: ((peerId: PeerId) => void) | undefined; -}; diff --git a/src/topology/multicodec-topology.d.ts b/src/topology/multicodec-topology.d.ts deleted file mode 100644 index d3e83f3..0000000 --- a/src/topology/multicodec-topology.d.ts +++ /dev/null @@ -1,81 +0,0 @@ -export = MulticodecTopology; -declare const MulticodecTopology_base: typeof import("."); -declare class MulticodecTopology extends MulticodecTopology_base { - /** - * Checks if the given value is a `MulticodecTopology` instance. - * - * @param {any} other - * @returns {other is MulticodecTopology} - */ - static isMulticodecTopology(other: any): other is MulticodecTopology; - /** - * @param {TopologyOptions & MulticodecOptions} props - */ - constructor({ min, max, multicodecs, handlers }: TopologyOptions & MulticodecOptions); - multicodecs: string[]; - /** - * Check if a new peer support the multicodecs for this topology. - * - * @param {Object} props - * @param {PeerId} props.peerId - * @param {Array} props.protocols - */ - _onProtocolChange({ peerId, protocols }: { - peerId: PeerId; - protocols: Array; - }): void; - /** - * Verify if a new connected peer has a topology multicodec and call _onConnect. - * - * @param {Connection} connection - * @returns {void} - */ - _onPeerConnect(connection: Connection): void; - /** - * Update topology. - * - * @param {Array<{id: PeerId, multiaddrs: Array, protocols: Array}>} peerDataIterable - * @returns {void} - */ - _updatePeers(peerDataIterable: Array<{ - id: PeerId; - multiaddrs: Array; - protocols: Array; - }>): void; - get [multicodecTopologySymbol](): boolean; -} -declare namespace MulticodecTopology { - export { PeerId, Multiaddr, Connection, TopologyOptions, MulticodecOptions, Handlers }; -} -type PeerId = import("peer-id"); -type Connection = typeof import("../connection"); -type Multiaddr = import("multiaddr"); -declare const multicodecTopologySymbol: unique symbol; -type TopologyOptions = { - /** - * - minimum needed connections. - */ - min?: number | undefined; - /** - * - maximum needed connections. - */ - max?: number | undefined; - handlers?: import(".").Handlers | undefined; -}; -type MulticodecOptions = { - /** - * - protocol multicodecs - */ - multicodecs: string[]; - handlers: Required; -}; -type Handlers = { - /** - * - protocol "onConnect" handler - */ - onConnect?: ((peerId: import("peer-id"), conn: typeof import("../connection")) => void) | undefined; - /** - * - protocol "onDisconnect" handler - */ - onDisconnect?: ((peerId: import("peer-id")) => void) | undefined; -}; diff --git a/src/transport/errors.d.ts b/src/transport/errors.d.ts deleted file mode 100644 index 45b4751..0000000 --- a/src/transport/errors.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class AbortError extends Error { - static get code(): string; - static get type(): string; - code: string; - type: string; -}