-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
149 lines (111 loc) · 3.13 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import EventEmitter, { EventMap } from 'bare-events'
import { Duplex, DuplexEvents } from 'bare-stream'
interface PipeEvents extends DuplexEvents {
connect: []
}
interface PipeOptions {
readBufferSize?: number
allowHalfOpen?: boolean
}
interface PipeConnectOptions {
path?: string
}
interface Pipe<M extends PipeEvents = PipeEvents> extends Duplex<M> {
readonly connecting: boolean
readonly pending: boolean
readonly readyState: 'open' | 'readOnly' | 'writeOnly'
open(fd: number, opts?: { fd?: number }, onconnect?: () => void): this
open(fd: number, onconnect: () => void): this
open(opts: { fd: number }, onconnect?: () => void): this
connect(path: string, opts?: PipeConnectOptions, onconnect?: () => void): this
connect(path: string, onconnect: () => void): this
connect(opts: PipeConnectOptions, onconnect?: () => void): this
ref(): void
unref(): void
}
declare class Pipe<M extends PipeEvents = PipeEvents> extends Duplex<M> {
constructor(path: string | number, opts?: PipeOptions)
constructor(opts?: PipeOptions)
}
interface ServerEvents extends EventMap {
close: []
connection: [pipe: Pipe]
err: [err: Error]
listening: []
}
interface ServerOptions {
readBufferSize?: number
allowHalfOpen?: boolean
}
interface ServerListenOptions {
path?: string
backlog?: number
}
interface Server<M extends ServerEvents = ServerEvents>
extends EventEmitter<M> {
readonly listening: boolean
address(): string | null
listen(
path: string,
backlog?: number,
opts?: ServerListenOptions,
onlistening?: () => void
): this
listen(path: string, backlog: number, onlistening: () => void): this
listen(path: string, onlistening: () => void): this
listen(opts: ServerListenOptions): this
close(onclose?: () => void): void
ref(): void
unref(): void
}
declare class Server<
M extends ServerEvents = ServerEvents
> extends EventEmitter<M> {
constructor(opts?: ServerOptions, onconnection?: () => void)
constructor(onconnection: () => void)
}
declare class PipeError extends Error {
static PIPE_ALREADY_CONNECTED(msg: string): PipeError
static SERVER_ALREADY_LISTENING(msg: string): PipeError
static SERVER_IS_CLOSED(msg: string): PipeError
}
declare namespace Pipe {
export interface CreateConnectionOptions
extends PipeOptions,
PipeConnectOptions {}
export function createConnection(
path: string,
opts?: CreateConnectionOptions,
onconnect?: () => void
): Pipe
export function createConnection(path: string, onconnect: () => void): Pipe
export function createConnection(
opts: CreateConnectionOptions,
onconnect?: () => void
): Pipe
export function createServer(
opts?: ServerOptions,
onconnection?: () => void
): Server
export function pipe(): [read: number, write: number]
export const constants: {
CONNECTING: number
CONNECTED: number
BINDING: number
BOUND: number
READING: number
CLOSING: number
READABLE: number
WRITABLE: number
}
export {
Pipe,
PipeEvents,
PipeOptions,
PipeConnectOptions,
PipeError as errors,
ServerEvents,
ServerOptions
}
}
export = Pipe