Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: add types #74

Merged
merged 23 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c1cb68e
fix: typedefs for MulticodecTopology
Gozala Nov 27, 2020
cba6394
feat: remove is-class that broke typings
Gozala Nov 30, 2020
4e25c6e
fix: add type annotations to improve innference
Gozala Nov 30, 2020
7ccaf27
chore: generate fixed types
Gozala Nov 30, 2020
f2d6a76
fix: missing type imports
Gozala Dec 1, 2020
3143efd
fix: tsconfig to generate optionals correctly
Gozala Dec 1, 2020
b7f1072
fix: lint issues by disabling valid-jsdoc rules
Gozala Dec 1, 2020
7fd26cf
fix: optional fields
Gozala Dec 1, 2020
6a95834
feat: add types
vasco-santos Dec 1, 2020
bac57b0
chore: remove generated types from vsc
Gozala Dec 1, 2020
67a5f51
fix: type incompatibilities (#75)
Gozala Dec 2, 2020
6f09061
chore: address review
vasco-santos Dec 2, 2020
8fdc05d
chore: use github actions and remove travis
vasco-santos Dec 2, 2020
0801fc3
chore: add interface constructors
vasco-santos Dec 2, 2020
5cb2025
chore: address review
vasco-santos Dec 2, 2020
5cfaf41
chore: make inboundStream a asyncIterable
vasco-santos Dec 2, 2020
ef86c87
chore: fix latest comments
vasco-santos Dec 2, 2020
7597875
chore: record interface instead of class, transport and stream muxer …
vasco-santos Dec 3, 2020
56e606e
chore: remove record class file
vasco-santos Dec 3, 2020
0b4b09f
chore: enable ts error reporter
vasco-santos Dec 3, 2020
e73646c
chore: add listener options
vasco-santos Dec 4, 2020
a99b958
chore: update interface record per libp2p pr feedback
vasco-santos Dec 10, 2020
a24fafd
chore: make metadata optional on addStream
vasco-santos Dec 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
"pregenerate:types": "rimraf './src/**/*.d.ts'",
"generate:types": "tsc",
"test": "aegir test",
"test:node": "aegir test --target node",
"test:browser": "aegir test --target browser",
"test:types": "aegir ts -p check",
"prepublishOnly": "npm run generate:types",
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
"release": "aegir release -t node -t browser",
"release-minor": "aegir release --type minor -t node -t browser",
"release-major": "aegir release --type major -t node -t browser"
"release-major": "aegir release --type major -t node -t browser",
"remove:types": "rimraf './src/**/*.d.ts'"
},
"repository": {
"type": "git",
Expand All @@ -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",
Expand All @@ -64,13 +63,13 @@
"protons": "^2.0.0",
"sinon": "^9.0.2",
"streaming-iterables": "^5.0.2",
"typescript": "^4.1.2",
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
"uint8arrays": "^1.1.0"
},
"devDependencies": {
"aegir": "^25.0.0",
"aegir": "^29.2.0",
"it-handshake": "^1.0.1",
"rimraf": "^3.0.2",
"typescript": "3.7.5"
"rimraf": "^3.0.2"
},
"contributors": [
"Alan Shaw <[email protected]>",
Expand Down
243 changes: 176 additions & 67 deletions src/connection/connection.d.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
declare const _exports: typeof Connection;
export = _exports;
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<void>} 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 {
/**
* Creates an instance of Connection.
* @param {object} properties properties of the connection.
* @param {multiaddr} [properties.localAddr] local multiaddr of the connection if known.
* @param {multiaddr} [properties.remoteAddr] remote multiaddr of the connection.
* @param {PeerId} properties.localPeer local peer-id.
* @param {PeerId} properties.remotePeer remote peer-id.
* @param {function} properties.newStream new stream muxer function.
* @param {function} properties.close close raw connection function.
* @param {function(): Stream[]} properties.getStreams get streams from muxer function.
* @param {object} properties.stat metadata of the connection.
* @param {string} properties.stat.direction connection establishment direction ("inbound" or "outbound").
* @param {object} properties.stat.timeline connection relevant events timestamp.
* @param {string} properties.stat.timeline.open connection opening timestamp.
* @param {string} properties.stat.timeline.upgraded connection upgraded timestamp.
* @param {string} [properties.stat.multiplexer] connection multiplexing identifier.
* @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");
newStream: Function;
close: Function;
getStreams: () => any[];
stat: {
direction: string;
timeline: {
open: string;
upgraded: string;
};
multiplexer?: string;
encryption?: string;
};
});
* 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: any;
id: string;
/**
* Observed multiaddr of the local peer
*/
localAddr: import("multiaddr");
localAddr: import("multiaddr") | undefined;
/**
* Observed multiaddr of the remote peer
*/
Expand All @@ -65,85 +66,193 @@ declare class Connection {
* Connection metadata.
*/
_stat: {
status: string;
status: "open";
/**
* - connection establishment direction ("inbound" or "outbound").
*/
direction: string;
/**
* - connection relevant events timestamp.
*/
timeline: {
open: string;
upgraded: string;
open: number;
upgraded: number | undefined;
close: number | undefined;
};
multiplexer?: string;
encryption?: string;
/**
* - connection multiplexing identifier.
*/
multiplexer?: string | undefined;
/**
* - connection encryption method identifier.
*/
encryption?: string | undefined;
};
/**
* Reference to the new stream function of the multiplexer
*/
_newStream: Function;
_newStream: (protocols: string | string[]) => Promise<{
stream: MuxedStream;
protocol: string;
}>;
/**
* Reference to the close function of the raw connection
*/
_close: Function;
_close: () => Promise<void>;
/**
* Reference to the getStreams function of the muxer
*/
_getStreams: () => any[];
_getStreams: () => MuxedStream[];
/**
* Connection streams registry
*/
registry: Map<any, any>;
/**
* User provided tags
*
* @type {string[]}
*/
tags: string[];
get [Symbol.toStringTag](): string;
/**
* Get connection metadata
*
* @this {Connection}
*/
get stat(): {
status: string;
status: "open";
/**
* - connection establishment direction ("inbound" or "outbound").
*/
direction: string;
/**
* - connection relevant events timestamp.
*/
timeline: {
open: string;
upgraded: string;
open: number;
upgraded: number | undefined;
close: number | undefined;
};
multiplexer?: string;
encryption?: string;
/**
* - connection multiplexing identifier.
*/
multiplexer?: string | undefined;
/**
* - connection encryption method identifier.
*/
encryption?: string | undefined;
};
/**
* Get all the streams of the muxer.
*
* @this {Connection}
*/
get streams(): any[];
get streams(): import("../stream-muxer/types").MuxedStream[];
/**
* Create a new stream from this connection
* @param {string[]} protocols intended protocol for the stream
* @return {Promise<{stream: Stream, protocol: string}>} with muxed+multistream-selected stream and selected protocol
*
* @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[]): Promise<{
stream: any;
newStream(protocols: string | string[]): Promise<{
stream: MuxedStream;
protocol: string;
}>;
/**
* Add a stream when it is opened to the registry.
* @param {*} 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
* @return {void}
*
* @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: any, { protocol, metadata }: {
addStream(muxedStream: MuxedStream, { protocol, metadata }: {
protocol: string;
metadata: any;
metadata: object;
}): void;
/**
* Remove stream registry after it is closed.
* @param {string} id identifier of the stream
*
* @param {string} id - identifier of the stream
*/
removeStream(id: string): void;
/**
* Close the connection.
* @return {Promise<void>}
*
* @returns {Promise<void>}
*/
close(): Promise<void>;
_closing: any;
_closing: void | undefined;
}
declare namespace Connection {
export { MuxedStream, ConectionStat, ConnectionOptions };
}
type MuxedStream = {
close: () => void;
abort: () => void;
reset: () => void;
sink: (source: Uint8Array) => Promise<Uint8Array>;
source: () => AsyncIterable<Uint8Array>;
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<void>;
/**
* - 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;
};
Loading