mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 16:32:32 +00:00
fix: optional fields
This commit is contained in:
parent
b7f10727d6
commit
7fd26cf6b9
@ -13,7 +13,7 @@
|
||||
"lint": "aegir lint",
|
||||
"build": "aegir build",
|
||||
"pregenerate:types": "rimraf './src/**/*.d.ts'",
|
||||
"generate:types": "tsc",
|
||||
"generate:types": "tsc --build",
|
||||
"test": "aegir test",
|
||||
"test:node": "aegir test --target node",
|
||||
"test:browser": "aegir test --target browser",
|
||||
@ -69,7 +69,7 @@
|
||||
"aegir": "^25.0.0",
|
||||
"it-handshake": "^1.0.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^4.1.2"
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"contributors": [
|
||||
"Alan Shaw <alan.shaw@protocol.ai>",
|
||||
|
4
src/pubsub/utils.d.ts
vendored
4
src/pubsub/utils.d.ts
vendored
@ -3,11 +3,11 @@ export function msgId(from: string, seqno: Uint8Array): Uint8Array;
|
||||
export function noSignMsgId(data: Uint8Array): Uint8Array;
|
||||
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 Object>(message: T, peerId?: string | undefined): T & {
|
||||
export function normalizeInRpcMessage<T extends unknown>(message: T, peerId?: string | undefined): T & {
|
||||
from?: string | undefined;
|
||||
peerId?: string | undefined;
|
||||
};
|
||||
export function normalizeOutRpcMessage<T extends Object>(message: T): T & {
|
||||
export function normalizeOutRpcMessage<T extends unknown>(message: T): T & {
|
||||
from?: Uint8Array | undefined;
|
||||
data?: Uint8Array | undefined;
|
||||
};
|
||||
|
41
src/topology/index.d.ts
vendored
41
src/topology/index.d.ts
vendored
@ -8,22 +8,9 @@ declare class 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 {Object} [props.handlers]
|
||||
* @param {function} [props.handlers.onConnect] protocol "onConnect" handler
|
||||
* @param {function} [props.handlers.onDisconnect] protocol "onDisconnect" handler
|
||||
* @constructor
|
||||
* @param {Options} options
|
||||
*/
|
||||
constructor({ min, max, handlers }: {
|
||||
min: number | undefined;
|
||||
max: number | undefined;
|
||||
handlers: {
|
||||
onConnect?: Function | undefined;
|
||||
onDisconnect?: Function | undefined;
|
||||
} | undefined;
|
||||
});
|
||||
constructor({ min, max, handlers }: Options);
|
||||
min: number;
|
||||
max: number;
|
||||
_onConnect: Function;
|
||||
@ -48,4 +35,28 @@ declare class Topology {
|
||||
disconnect(peerId: import("peer-id")): void;
|
||||
get [topologySymbol](): boolean;
|
||||
}
|
||||
declare namespace Topology {
|
||||
export { Options, Handlers };
|
||||
}
|
||||
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?: Function | undefined;
|
||||
/**
|
||||
* - protocol "onDisconnect" handler
|
||||
*/
|
||||
onDisconnect?: Function | undefined;
|
||||
};
|
||||
|
@ -6,13 +6,7 @@ const topologySymbol = Symbol.for('@libp2p/js-interfaces/topology')
|
||||
|
||||
class Topology {
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @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
|
||||
* @constructor
|
||||
* @param {Options} options
|
||||
*/
|
||||
constructor ({
|
||||
min = 0,
|
||||
@ -70,4 +64,15 @@ class Topology {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {number} [min=0] - minimum needed connections.
|
||||
* @property {number} [max=Infinity] - maximum needed connections.
|
||||
* @property {Handlers} [handlers]
|
||||
*
|
||||
* @typedef {Object} Handlers
|
||||
* @property {Function} [onConnect] - protocol "onConnect" handler
|
||||
* @property {Function} [onDisconnect] - protocol "onDisconnect" handler
|
||||
*/
|
||||
|
||||
module.exports = Topology
|
||||
|
51
src/topology/multicodec-topology.d.ts
vendored
51
src/topology/multicodec-topology.d.ts
vendored
@ -8,24 +8,9 @@ declare class MulticodecTopology extends Topology {
|
||||
*/
|
||||
static isMulticodecTopology(other: any): other is MulticodecTopology;
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @param {number} [props.min] minimum needed connections (default: 0)
|
||||
* @param {number} [props.max] maximum needed connections (default: Infinity)
|
||||
* @param {Array<string>} props.multicodecs protocol multicodecs
|
||||
* @param {Object} props.handlers
|
||||
* @param {function} props.handlers.onConnect protocol "onConnect" handler
|
||||
* @param {function} props.handlers.onDisconnect protocol "onDisconnect" handler
|
||||
* @constructor
|
||||
* @param {TopologyOptions & MulticodecOptions} props
|
||||
*/
|
||||
constructor({ min, max, multicodecs, handlers }: {
|
||||
min: number | undefined;
|
||||
max: number | undefined;
|
||||
multicodecs: Array<string>;
|
||||
handlers: {
|
||||
onConnect: Function;
|
||||
onDisconnect: Function;
|
||||
};
|
||||
});
|
||||
constructor({ min, max, multicodecs, handlers }: TopologyOptions & MulticodecOptions);
|
||||
multicodecs: string[];
|
||||
/**
|
||||
* Check if a new peer support the multicodecs for this topology.
|
||||
@ -53,11 +38,41 @@ declare class MulticodecTopology extends Topology {
|
||||
multiaddrs: Array<Multiaddr>;
|
||||
protocols: Array<string>;
|
||||
}>): void;
|
||||
get [multicodecTopologySymbol](): boolean;
|
||||
}
|
||||
declare namespace MulticodecTopology {
|
||||
export { PeerId, Multiaddr, Connection };
|
||||
export { PeerId, Multiaddr, Connection, TopologyOptions, MulticodecOptions, Handlers };
|
||||
}
|
||||
import Topology = require(".");
|
||||
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?: Topology.Handlers | undefined;
|
||||
};
|
||||
type MulticodecOptions = {
|
||||
/**
|
||||
* - protocol multicodecs
|
||||
*/
|
||||
multicodecs: string[];
|
||||
handlers: Required<Handlers>;
|
||||
};
|
||||
type Handlers = {
|
||||
/**
|
||||
* - protocol "onConnect" handler
|
||||
*/
|
||||
onConnect?: Function | undefined;
|
||||
/**
|
||||
* - protocol "onDisconnect" handler
|
||||
*/
|
||||
onDisconnect?: Function | undefined;
|
||||
};
|
||||
|
@ -6,14 +6,7 @@ const multicodecTopologySymbol = Symbol.for('@libp2p/js-interfaces/topology/mult
|
||||
|
||||
class MulticodecTopology extends Topology {
|
||||
/**
|
||||
* @param {Object} props
|
||||
* @param {number} [props.min] minimum needed connections (default: 0)
|
||||
* @param {number} [props.max] maximum needed connections (default: Infinity)
|
||||
* @param {Array<string>} props.multicodecs protocol multicodecs
|
||||
* @param {Object} props.handlers
|
||||
* @param {function} props.handlers.onConnect protocol "onConnect" handler
|
||||
* @param {function} props.handlers.onDisconnect protocol "onDisconnect" handler
|
||||
* @constructor
|
||||
* @param {TopologyOptions & MulticodecOptions} props
|
||||
*/
|
||||
constructor ({
|
||||
min,
|
||||
@ -143,5 +136,10 @@ class MulticodecTopology extends Topology {
|
||||
* @typedef {import('peer-id')} PeerId
|
||||
* @typedef {import('multiaddr')} Multiaddr
|
||||
* @typedef {import('../connection')} Connection
|
||||
* @typedef {import('.').Options} TopologyOptions
|
||||
* @typedef {Object} MulticodecOptions
|
||||
* @property {string[]} multicodecs - protocol multicodecs
|
||||
* @property {Required<Handlers>} handlers
|
||||
* @typedef {import('.').Handlers} Handlers
|
||||
*/
|
||||
module.exports = MulticodecTopology
|
||||
|
@ -6,7 +6,20 @@
|
||||
// Tells TypeScript to read JS files, as
|
||||
// normally they are ignored as source files
|
||||
"allowJs": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitReturns": false,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": false,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"strictBindCallApply": true,
|
||||
"strict": true,
|
||||
"alwaysStrict": true,
|
||||
"stripInternal": true,
|
||||
// Generate d.ts files
|
||||
"declaration": true,
|
||||
// This compiler run should
|
||||
|
Loading…
x
Reference in New Issue
Block a user