Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/interfaces

Package Overview
Dependencies
Maintainers
4
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/interfaces - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

25

dist/src/index.d.ts

@@ -22,2 +22,27 @@ import type { PeerId } from './peer-id/index.js';

}
interface EventCallback<EventType> {
(evt: EventType): void;
}
declare type EventHandler<EventType> = EventCallback<EventType> | ({
handleEvent: EventCallback<EventType>;
}) | null;
/**
* Adds types to the EventTarget class. Hopefully this won't be necessary forever.
*
* https://github.com/microsoft/TypeScript/issues/28357
* https://github.com/microsoft/TypeScript/issues/43477
* https://github.com/microsoft/TypeScript/issues/299
* etc
*/
export declare class EventEmitter<EventMap> extends EventTarget {
#private;
listenerCount(type: string): number;
addEventListener<U extends keyof EventMap>(type: U, callback: EventHandler<EventMap[U]>, options?: AddEventListenerOptions | boolean): void;
removeEventListener<U extends keyof EventMap>(type: U, callback: EventHandler<EventMap[U]> | undefined, options?: EventListenerOptions | boolean): void;
}
export declare const CustomEvent: {
new <T>(type: string, eventInitDict?: CustomEventInit<T> | undefined): CustomEvent<T>;
prototype: CustomEvent<any>;
};
export {};
//# sourceMappingURL=index.d.ts.map

59

dist/src/index.js

@@ -1,2 +0,59 @@

export {};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EventEmitter_listeners;
/**
* Adds types to the EventTarget class. Hopefully this won't be necessary forever.
*
* https://github.com/microsoft/TypeScript/issues/28357
* https://github.com/microsoft/TypeScript/issues/43477
* https://github.com/microsoft/TypeScript/issues/299
* etc
*/
export class EventEmitter extends EventTarget {
constructor() {
super(...arguments);
_EventEmitter_listeners.set(this, new Map());
}
listenerCount(type) {
return __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type) ?? 0;
}
// @ts-expect-error EventTarget is not typed
addEventListener(type, callback, options) {
// @ts-expect-error EventTarget is not typed
super.addEventListener(type, callback);
const count = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type) ?? 0;
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, count + 1);
}
// @ts-expect-error EventTarget is not typed
removeEventListener(type, callback, options) {
// @ts-expect-error EventTarget is not typed
super.removeEventListener(type, callback);
const count = __classPrivateFieldGet(this, _EventEmitter_listeners, "f").get(type) ?? 0;
if (count === 1) {
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").delete(type);
}
else {
__classPrivateFieldGet(this, _EventEmitter_listeners, "f").set(type, count - 1);
}
}
}
_EventEmitter_listeners = new WeakMap();
/**
* CustomEvent is a standard event but it's not supported by node.
*
* Remove this when https://github.com/nodejs/node/issues/40678 is closed.
*
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
*/
class CustomEventPolyfill extends Event {
constructor(message, data) {
super(message, data);
// @ts-expect-error could be undefined
this.detail = data?.detail;
}
}
export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill;
//# sourceMappingURL=index.js.map

14

dist/src/peer-discovery/index.d.ts

@@ -1,5 +0,3 @@

/// <reference types="node" />
import type { EventEmitter } from 'events';
import type { PeerData } from '../peer-data/index.js';
import type { Startable } from '../index.js';
import type { EventEmitter, Startable } from '../index.js';
export interface PeerDiscoveryFactory {

@@ -9,11 +7,7 @@ new (options?: any): PeerDiscovery;

}
interface PeerDiscoveryEvents {
'peer': PeerData;
export interface PeerDiscoveryEvents {
'peer': CustomEvent<PeerData>;
}
export interface PeerDiscovery extends EventEmitter, Startable {
on: (<U extends keyof PeerDiscoveryEvents>(event: U, listener: (event: PeerDiscoveryEvents[U]) => void) => this) & ((event: string, listener: (...args: any[]) => void) => this);
once: (<U extends keyof PeerDiscoveryEvents>(event: U, listener: (event: PeerDiscoveryEvents[U]) => void) => this) & ((event: string, listener: (...args: any[]) => void) => this);
emit: (<U extends keyof PeerDiscoveryEvents>(name: U, event: PeerDiscoveryEvents[U]) => boolean) & ((name: string, ...args: any[]) => boolean);
export interface PeerDiscovery extends EventEmitter<PeerDiscoveryEvents>, Startable {
}
export default PeerDiscovery;
//# sourceMappingURL=index.d.ts.map

@@ -1,5 +0,4 @@

/// <reference types="node" />
import type { PeerId } from '../peer-id/index.js';
import type { Multiaddr } from '@multiformats/multiaddr';
import type { EventEmitter } from 'events';
import type { EventEmitter } from '../index.js';
import type { Envelope } from '../record/index.js';

@@ -156,15 +155,18 @@ export interface Address {

}
export interface PeerProtocolsChangeEvent {
export interface PeerData {
peerId: PeerId;
}
export interface PeerProtocolsChangeData {
peerId: PeerId;
protocols: string[];
}
export interface PeerMultiaddrsChangeEvent {
export interface PeerMultiaddrsChangeData {
peerId: PeerId;
multiaddrs: Multiaddr[];
}
export interface PeerPublicKeyChangeEvent {
export interface PeerPublicKeyChangeData {
peerId: PeerId;
pubKey?: Uint8Array;
}
export interface PeerMetadataChangeEvent {
export interface PeerMetadataChangeData {
peerId: PeerId;

@@ -175,9 +177,9 @@ metadata: Map<string, Uint8Array>;

export interface PeerStoreEvents {
'peer': (event: PeerId) => void;
'change:protocols': (event: PeerProtocolsChangeEvent) => void;
'change:multiaddrs': (event: PeerMultiaddrsChangeEvent) => void;
'change:pubkey': (event: PeerPublicKeyChangeEvent) => void;
'change:metadata': (event: PeerMetadataChangeEvent) => void;
'peer': CustomEvent<PeerData>;
'change:protocols': CustomEvent<PeerProtocolsChangeData>;
'change:multiaddrs': CustomEvent<PeerMultiaddrsChangeData>;
'change:pubkey': CustomEvent<PeerPublicKeyChangeData>;
'change:metadata': CustomEvent<PeerMetadataChangeData>;
}
export interface PeerStore extends EventEmitter {
export interface PeerStore extends EventEmitter<PeerStoreEvents> {
addressBook: AddressBook;

@@ -191,6 +193,3 @@ keyBook: KeyBook;

get: (peerId: PeerId) => Promise<Peer>;
on: <U extends keyof PeerStoreEvents>(event: U, listener: PeerStoreEvents[U]) => this;
once: <U extends keyof PeerStoreEvents>(event: U, listener: PeerStoreEvents[U]) => this;
emit: <U extends keyof PeerStoreEvents>(event: U, ...args: Parameters<PeerStoreEvents[U]>) => boolean;
}
//# sourceMappingURL=index.d.ts.map

@@ -1,6 +0,5 @@

/// <reference types="node" />
import type { PeerId } from '../peer-id';
import type { Pushable } from 'it-pushable';
import type { Registrar } from '../registrar';
import type { EventEmitter } from 'events';
import type { EventEmitter, Startable } from '../index.js';
/**

@@ -66,10 +65,10 @@ * On the producing side:

}
interface SubscriptionChangeEvent {
interface SubscriptionChangeData {
peerId: PeerId;
subscriptions: Subscription[];
}
interface PubSubEvents {
'pubsub:subscription-change': SubscriptionChangeEvent;
export interface PubsubEvents {
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData>;
}
export interface PubSub extends EventEmitter {
export interface PubSub<EventMap extends PubsubEvents> extends EventEmitter<EventMap>, Startable {
peerId: PeerId;

@@ -88,7 +87,9 @@ started: boolean;

validate: (message: Message) => Promise<void>;
on: (<U extends keyof PubSubEvents>(event: U, listener: (event: PubSubEvents[U]) => void) => this) & ((event: string, listener: (event: Message) => void) => this);
once: (<U extends keyof PubSubEvents>(event: U, listener: (event: PubSubEvents[U]) => void) => this) & ((event: string, listener: (event: Message) => void) => this);
emit: (<U extends keyof PubSubEvents>(name: U, event: PubSubEvents[U]) => boolean) & ((name: string, event: Message) => boolean);
}
export interface PeerStreamEvents {
'stream:inbound': CustomEvent<never>;
'stream:outbound': CustomEvent<never>;
'close': CustomEvent<never>;
}
export {};
//# sourceMappingURL=index.d.ts.map

@@ -1,4 +0,4 @@

import type { Connection, Stream } from '../connection';
import type { PeerId } from '../peer-id';
import type { PeerStore } from '../peer-store';
import type { EventEmitter } from '../index.js';
import type { Connection, Stream } from '../connection/index.js';
import type { PeerId } from '../peer-id/index.js';
export interface IncomingStreamEvent {

@@ -9,2 +9,8 @@ protocol: string;

}
export interface ConnectionManagerEvents {
'peer:connect': CustomEvent<Connection>;
}
export interface ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
getConnection: (peerId: PeerId) => Connection | undefined;
}
export interface Registrar {

@@ -15,8 +21,3 @@ handle: (multicodec: string | string[], handler: (event: IncomingStreamEvent) => void) => void;

unregister: (id: string) => void;
getConnection: (peerId: PeerId) => Connection | undefined;
peerStore: PeerStore;
connectionManager: {
on: (event: 'peer:connect', handler: (connection: Connection) => void) => void;
};
}
//# sourceMappingURL=index.d.ts.map

@@ -1,3 +0,5 @@

import type { PeerId } from '../peer-id';
import type { Connection } from '../connection';
import type { PeerId } from '../peer-id/index.js';
import type { Connection } from '../connection/index.js';
import type { ConnectionManager } from '../registrar/index.js';
import type { PeerStore } from '../peer-store/index.js';
export interface onConnectHandler {

@@ -32,2 +34,4 @@ (peerId: PeerId, conn: Connection): void;

multicodecs: string[];
peerStore: PeerStore;
connectionManager: ConnectionManager;
}

@@ -34,0 +38,0 @@ export interface MulticodecTopology extends Topology {

@@ -1,6 +0,4 @@

/// <reference types="node" />
import type { EventEmitter } from 'events';
import type { EventEmitter, AbortOptions } from '../index.js';
import type { Multiaddr } from '@multiformats/multiaddr';
import type { Connection } from '../connection/index.js';
import type { AbortOptions } from '../index.js';
import type { Duplex } from 'it-stream-types';

@@ -38,3 +36,9 @@ export interface TransportFactory<DialOptions extends {

}
export interface Listener extends EventEmitter {
export interface ListenerEvents {
'connection': CustomEvent<Connection>;
'listening': CustomEvent<Connection>;
'error': CustomEvent<Error>;
'close': CustomEvent<Connection>;
}
export interface Listener extends EventEmitter<ListenerEvents> {
/**

@@ -41,0 +45,0 @@ * Start a listener

{
"name": "@libp2p/interfaces",
"version": "1.3.0",
"version": "1.3.1",
"description": "Interfaces for JS Libp2p",

@@ -217,3 +217,3 @@ "license": "Apache-2.0 OR MIT",

"lint": "aegir lint",
"dep-check": "aegir dep-check dist/src/**/*.js",
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
"build": "tsc"

@@ -220,0 +220,0 @@ },

@@ -24,1 +24,64 @@ import type { PeerId } from './peer-id/index.js'

}
interface EventCallback<EventType> { (evt: EventType): void }
type EventHandler<EventType> = EventCallback<EventType> | ({ handleEvent: EventCallback<EventType> }) | null
/**
* Adds types to the EventTarget class. Hopefully this won't be necessary forever.
*
* https://github.com/microsoft/TypeScript/issues/28357
* https://github.com/microsoft/TypeScript/issues/43477
* https://github.com/microsoft/TypeScript/issues/299
* etc
*/
export class EventEmitter<EventMap> extends EventTarget {
#listeners: Map<any, number> = new Map()
listenerCount (type: string) {
return this.#listeners.get(type) ?? 0
}
// @ts-expect-error EventTarget is not typed
addEventListener<U extends keyof EventMap> (type: U, callback: EventHandler<EventMap[U]>, options?: AddEventListenerOptions | boolean) {
// @ts-expect-error EventTarget is not typed
super.addEventListener(type, callback)
const count = this.#listeners.get(type) ?? 0
this.#listeners.set(type, count + 1)
}
// @ts-expect-error EventTarget is not typed
removeEventListener<U extends keyof EventMap> (type: U, callback: EventHandler<EventMap[U]> | undefined, options?: EventListenerOptions | boolean) {
// @ts-expect-error EventTarget is not typed
super.removeEventListener(type, callback)
const count = this.#listeners.get(type) ?? 0
if (count === 1) {
this.#listeners.delete(type)
} else {
this.#listeners.set(type, count - 1)
}
}
}
/**
* CustomEvent is a standard event but it's not supported by node.
*
* Remove this when https://github.com/nodejs/node/issues/40678 is closed.
*
* Ref: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent
*/
class CustomEventPolyfill<T = any> extends Event {
/** Returns any custom data event was created with. Typically used for synthetic events. */
public detail: T
constructor (message: string, data?: EventInit & { detail: T }) {
super(message, data)
// @ts-expect-error could be undefined
this.detail = data?.detail
}
}
export const CustomEvent = globalThis.CustomEvent ?? CustomEventPolyfill

@@ -1,4 +0,3 @@

import type { EventEmitter } from 'events'
import type { PeerData } from '../peer-data/index.js'
import type { Startable } from '../index.js'
import type { EventEmitter, Startable } from '../index.js'

@@ -10,18 +9,8 @@ export interface PeerDiscoveryFactory {

interface PeerDiscoveryEvents {
'peer': PeerData
export interface PeerDiscoveryEvents {
'peer': CustomEvent<PeerData>
}
export interface PeerDiscovery extends EventEmitter, Startable {
export interface PeerDiscovery extends EventEmitter<PeerDiscoveryEvents>, Startable {
on: (<U extends keyof PeerDiscoveryEvents> (event: U, listener: (event: PeerDiscoveryEvents[U]) => void) => this) &
((event: string, listener: (...args: any[]) => void) => this)
once: (<U extends keyof PeerDiscoveryEvents> (event: U, listener: (event: PeerDiscoveryEvents[U]) => void) => this) &
((event: string, listener: (...args: any[]) => void) => this)
emit: (<U extends keyof PeerDiscoveryEvents> (name: U, event: PeerDiscoveryEvents[U]) => boolean) &
((name: string, ...args: any[]) => boolean)
}
export default PeerDiscovery
import type { PeerId } from '../peer-id/index.js'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { EventEmitter } from 'events'
import type { EventEmitter } from '../index.js'
import type { Envelope } from '../record/index.js'

@@ -185,8 +185,12 @@

export interface PeerProtocolsChangeEvent {
export interface PeerData {
peerId: PeerId
}
export interface PeerProtocolsChangeData {
peerId: PeerId
protocols: string[]
}
export interface PeerMultiaddrsChangeEvent {
export interface PeerMultiaddrsChangeData {
peerId: PeerId

@@ -196,3 +200,3 @@ multiaddrs: Multiaddr[]

export interface PeerPublicKeyChangeEvent {
export interface PeerPublicKeyChangeData {
peerId: PeerId

@@ -202,3 +206,3 @@ pubKey?: Uint8Array

export interface PeerMetadataChangeEvent {
export interface PeerMetadataChangeData {
peerId: PeerId

@@ -211,10 +215,10 @@ metadata: Map<string, Uint8Array>

export interface PeerStoreEvents {
'peer': (event: PeerId) => void
'change:protocols': (event: PeerProtocolsChangeEvent) => void
'change:multiaddrs': (event: PeerMultiaddrsChangeEvent) => void
'change:pubkey': (event: PeerPublicKeyChangeEvent) => void
'change:metadata': (event: PeerMetadataChangeEvent) => void
'peer': CustomEvent<PeerData>
'change:protocols': CustomEvent<PeerProtocolsChangeData>
'change:multiaddrs': CustomEvent<PeerMultiaddrsChangeData>
'change:pubkey': CustomEvent<PeerPublicKeyChangeData>
'change:metadata': CustomEvent<PeerMetadataChangeData>
}
export interface PeerStore extends EventEmitter {
export interface PeerStore extends EventEmitter<PeerStoreEvents> {
addressBook: AddressBook

@@ -229,11 +233,2 @@ keyBook: KeyBook

get: (peerId: PeerId) => Promise<Peer>
on: <U extends keyof PeerStoreEvents>(
event: U, listener: PeerStoreEvents[U]
) => this
once: <U extends keyof PeerStoreEvents>(
event: U, listener: PeerStoreEvents[U]
) => this
emit: <U extends keyof PeerStoreEvents>(
event: U, ...args: Parameters<PeerStoreEvents[U]>
) => boolean
}
import type { PeerId } from '../peer-id'
import type { Pushable } from 'it-pushable'
import type { Registrar } from '../registrar'
import type { EventEmitter } from 'events'
import type { EventEmitter, Startable } from '../index.js'

@@ -76,3 +76,3 @@ /**

interface SubscriptionChangeEvent {
interface SubscriptionChangeData {
peerId: PeerId

@@ -82,7 +82,7 @@ subscriptions: Subscription[]

interface PubSubEvents {
'pubsub:subscription-change': SubscriptionChangeEvent
export interface PubsubEvents {
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData>
}
export interface PubSub extends EventEmitter {
export interface PubSub<EventMap extends PubsubEvents> extends EventEmitter<EventMap>, Startable {
peerId: PeerId

@@ -102,11 +102,8 @@ started: boolean

validate: (message: Message) => Promise<void>
}
on: (<U extends keyof PubSubEvents> (event: U, listener: (event: PubSubEvents[U]) => void) => this) &
((event: string, listener: (event: Message) => void) => this)
once: (<U extends keyof PubSubEvents> (event: U, listener: (event: PubSubEvents[U]) => void) => this) &
((event: string, listener: (event: Message) => void) => this)
emit: (<U extends keyof PubSubEvents> (name: U, event: PubSubEvents[U]) => boolean) &
((name: string, event: Message) => boolean)
export interface PeerStreamEvents {
'stream:inbound': CustomEvent<never>
'stream:outbound': CustomEvent<never>
'close': CustomEvent<never>
}

@@ -1,4 +0,4 @@

import type { Connection, Stream } from '../connection'
import type { PeerId } from '../peer-id'
import type { PeerStore } from '../peer-store'
import type { EventEmitter } from '../index.js'
import type { Connection, Stream } from '../connection/index.js'
import type { PeerId } from '../peer-id/index.js'

@@ -11,14 +11,15 @@ export interface IncomingStreamEvent {

export interface ConnectionManagerEvents {
'peer:connect': CustomEvent<Connection>
}
export interface ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
getConnection: (peerId: PeerId) => Connection | undefined
}
export interface Registrar {
handle: (multicodec: string | string[], handler: (event: IncomingStreamEvent) => void) => void
unhandle: (multicodec: string) => void
register: (topology: any) => string
unregister: (id: string) => void
getConnection: (peerId: PeerId) => Connection | undefined
peerStore: PeerStore
connectionManager: {
on: (event: 'peer:connect', handler: (connection: Connection) => void) => void
}
}

@@ -1,3 +0,5 @@

import type { PeerId } from '../peer-id'
import type { Connection } from '../connection'
import type { PeerId } from '../peer-id/index.js'
import type { Connection } from '../connection/index.js'
import type { ConnectionManager } from '../registrar/index.js'
import type { PeerStore } from '../peer-store/index.js'

@@ -35,2 +37,4 @@ export interface onConnectHandler { (peerId: PeerId, conn: Connection): void }

multicodecs: string[]
peerStore: PeerStore
connectionManager: ConnectionManager
}

@@ -37,0 +41,0 @@

@@ -1,5 +0,4 @@

import type { EventEmitter } from 'events'
import type { EventEmitter, AbortOptions } from '../index.js'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { Connection } from '../connection/index.js'
import type { AbortOptions } from '../index.js'
import type { Duplex } from 'it-stream-types'

@@ -37,3 +36,10 @@

export interface Listener extends EventEmitter {
export interface ListenerEvents {
'connection': CustomEvent<Connection>
'listening': CustomEvent<Connection>
'error': CustomEvent<Error>
'close': CustomEvent<Connection>
}
export interface Listener extends EventEmitter<ListenerEvents> {
/**

@@ -40,0 +46,0 @@ * Start a listener

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc