@libp2p/interfaces
Advanced tools
Comparing version 1.3.16 to 1.3.17
export const symbol = Symbol.for('@libp2p/connection'); | ||
export function isConnection(other) { | ||
return symbol in other; | ||
return other != null && Boolean(other[symbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -5,6 +5,43 @@ import type { Multiaddr } from '@multiformats/multiaddr'; | ||
} | ||
/** | ||
* Implemented by components that have a lifecycle | ||
*/ | ||
export interface Startable { | ||
isStarted: () => boolean; | ||
/** | ||
* If implemented, this method will be invoked before the start method. | ||
* | ||
* It should not assume any other components have been started. | ||
*/ | ||
beforeStart?: () => void | Promise<void>; | ||
/** | ||
* This method will be invoked to start the component. | ||
* | ||
* It should not assume that any other components have been started. | ||
*/ | ||
start: () => void | Promise<void>; | ||
/** | ||
* If implemented, this method will be invoked after the start method. | ||
* | ||
* All other components will have had their start method invoked before this method is called. | ||
*/ | ||
afterStart?: () => void | Promise<void>; | ||
/** | ||
* If implemented, this method will be invoked before the stop method. | ||
* | ||
* Any other components will still be running when this method is called. | ||
*/ | ||
beforeStop?: () => void | Promise<void>; | ||
/** | ||
* This method will be invoked to stop the component. | ||
* | ||
* It should not assume any other components are running when it is called. | ||
*/ | ||
stop: () => void | Promise<void>; | ||
/** | ||
* If implemented, this method will be invoked after the stop method. | ||
* | ||
* All other components will have had their stop method invoked before this method is called. | ||
*/ | ||
afterStop?: () => void | Promise<void>; | ||
} | ||
@@ -11,0 +48,0 @@ export declare function isStartable(obj: any): obj is Startable; |
export const symbol = Symbol.for('@libp2p/peer-id'); | ||
export function isPeerId(other) { | ||
return symbol in other; | ||
return other != null && Boolean(other[symbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
export const symbol = Symbol.for('@libp2p/topology'); | ||
export function isTopology(other) { | ||
return symbol in other; | ||
return other != null && Boolean(other[symbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
export const symbol = Symbol.for('@libp2p/transport'); | ||
export function isTransport(other) { | ||
return symbol in other; | ||
return other != null && Boolean(other[symbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@libp2p/interfaces", | ||
"version": "1.3.16", | ||
"version": "1.3.17", | ||
"description": "Interfaces for JS Libp2p", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -70,3 +70,3 @@ import type { Multiaddr } from '@multiformats/multiaddr' | ||
export function isConnection (other: any): other is Connection { | ||
return symbol in other | ||
return other != null && Boolean(other[symbol]) | ||
} | ||
@@ -73,0 +73,0 @@ |
@@ -7,6 +7,49 @@ import type { Multiaddr } from '@multiformats/multiaddr' | ||
/** | ||
* Implemented by components that have a lifecycle | ||
*/ | ||
export interface Startable { | ||
isStarted: () => boolean | ||
/** | ||
* If implemented, this method will be invoked before the start method. | ||
* | ||
* It should not assume any other components have been started. | ||
*/ | ||
beforeStart?: () => void | Promise<void> | ||
/** | ||
* This method will be invoked to start the component. | ||
* | ||
* It should not assume that any other components have been started. | ||
*/ | ||
start: () => void | Promise<void> | ||
/** | ||
* If implemented, this method will be invoked after the start method. | ||
* | ||
* All other components will have had their start method invoked before this method is called. | ||
*/ | ||
afterStart?: () => void | Promise<void> | ||
/** | ||
* If implemented, this method will be invoked before the stop method. | ||
* | ||
* Any other components will still be running when this method is called. | ||
*/ | ||
beforeStop?: () => void | Promise<void> | ||
/** | ||
* This method will be invoked to stop the component. | ||
* | ||
* It should not assume any other components are running when it is called. | ||
*/ | ||
stop: () => void | Promise<void> | ||
/** | ||
* If implemented, this method will be invoked after the stop method. | ||
* | ||
* All other components will have had their stop method invoked before this method is called. | ||
*/ | ||
afterStop?: () => void | Promise<void> | ||
} | ||
@@ -13,0 +56,0 @@ |
@@ -36,3 +36,3 @@ import type { CID } from 'multiformats/cid' | ||
export function isPeerId (other: any): other is PeerId { | ||
return symbol in other | ||
return other != null && Boolean(other[symbol]) | ||
} |
@@ -40,3 +40,3 @@ import type { PeerId } from '../peer-id/index.js' | ||
export function isTopology (other: any): other is Topology { | ||
return symbol in other | ||
return other != null && Boolean(other[symbol]) | ||
} |
@@ -114,3 +114,3 @@ import type { EventEmitter, AbortOptions } from '../index.js' | ||
export function isTransport (other: any): other is Transport { | ||
return symbol in other | ||
return other != null && Boolean(other[symbol]) | ||
} | ||
@@ -117,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1366490
3346