31 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-06-21 14:38:41 +02:00
// Type definitions for interface-connection 0.3.2
// Project: https://github.com/libp2p/interface-connection
// Definitions by: Jaco Greeff <https://github.com/jacogr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
2020-02-06 16:27:03 +07:00
/// <reference types="multiaddr"/>
2018-06-21 14:38:41 +02:00
// model after abortable-iterator
type Source<T> = AsyncIterable<T> | Iterable<T>;
2020-07-23 16:05:32 +07:00
type Sink<TSource, TReturn = void> = (source: Source<TSource>) => TReturn;
declare interface Stream<TSource = unknown, TReturn = unknown> {
source: Source<TSource>;
sink: Sink<TSource, TReturn>;
close: () => void;
2020-02-07 09:17:27 +07:00
}
2018-06-24 10:16:29 +02:00
declare interface LibP2pConnection {
2020-02-06 16:27:03 +07:00
localPeer: import("peer-id");
remotePeer: import("peer-id");
id: string;
2020-02-07 09:17:27 +07:00
newStream(protocols: string[]): Promise<{stream: Stream; protocol: string}>;
addStream( stream: Stream, meta: {protocol: string, metadata: Object}): void;
removeStream(id: string): void;
streams: Stream[];
registry: Map<string, Stream>;
2020-04-04 15:05:16 -05:00
localAddr: import("multiaddr");
remoteAddr: import("multiaddr");
2020-02-07 09:17:27 +07:00
stat: {status: 'open' | 'closing' | 'closed'; timeline: {open: Date; upgraded: Date; close: Date}; direction: 'inbound' | 'outbound'; multiplexer: string; encryption: string; tags: string[]}
2020-02-06 16:27:03 +07:00
close(): Promise<void>;
2018-06-21 14:38:41 +02:00
}