@types/node 18.19.21 → 18.19.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. node v18.19/README.md +2 -2
  2. node v18.19/package.json +3 -15
  3. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  4. node v18.19/ts4.8/assert.d.ts +0 -985
  5. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  6. node v18.19/ts4.8/buffer.d.ts +0 -2353
  7. node v18.19/ts4.8/child_process.d.ts +0 -1544
  8. node v18.19/ts4.8/cluster.d.ts +0 -432
  9. node v18.19/ts4.8/console.d.ts +0 -412
  10. node v18.19/ts4.8/constants.d.ts +0 -19
  11. node v18.19/ts4.8/crypto.d.ts +0 -4457
  12. node v18.19/ts4.8/dgram.d.ts +0 -596
  13. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  14. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  15. node v18.19/ts4.8/dns.d.ts +0 -809
  16. node v18.19/ts4.8/dom-events.d.ts +0 -122
  17. node v18.19/ts4.8/domain.d.ts +0 -170
  18. node v18.19/ts4.8/events.d.ts +0 -819
  19. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  20. node v18.19/ts4.8/fs.d.ts +0 -4231
  21. node v18.19/ts4.8/globals.d.ts +0 -377
  22. node v18.19/ts4.8/globals.global.d.ts +0 -1
  23. node v18.19/ts4.8/http.d.ts +0 -1803
  24. node v18.19/ts4.8/http2.d.ts +0 -2386
  25. node v18.19/ts4.8/https.d.ts +0 -544
  26. node v18.19/ts4.8/index.d.ts +0 -88
  27. node v18.19/ts4.8/inspector.d.ts +0 -2739
  28. node v18.19/ts4.8/module.d.ts +0 -298
  29. node v18.19/ts4.8/net.d.ts +0 -918
  30. node v18.19/ts4.8/os.d.ts +0 -473
  31. node v18.19/ts4.8/path.d.ts +0 -191
  32. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  33. node v18.19/ts4.8/process.d.ts +0 -1548
  34. node v18.19/ts4.8/punycode.d.ts +0 -117
  35. node v18.19/ts4.8/querystring.d.ts +0 -141
  36. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  37. node v18.19/ts4.8/readline.d.ts +0 -666
  38. node v18.19/ts4.8/repl.d.ts +0 -430
  39. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  40. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  41. node v18.19/ts4.8/stream/web.d.ts +0 -352
  42. node v18.19/ts4.8/stream.d.ts +0 -1731
  43. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  44. node v18.19/ts4.8/test.d.ts +0 -1113
  45. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  46. node v18.19/ts4.8/timers.d.ts +0 -126
  47. node v18.19/ts4.8/tls.d.ts +0 -1203
  48. node v18.19/ts4.8/trace_events.d.ts +0 -171
  49. node v18.19/ts4.8/tty.d.ts +0 -206
  50. node v18.19/ts4.8/url.d.ts +0 -954
  51. node v18.19/ts4.8/util.d.ts +0 -2075
  52. node v18.19/ts4.8/v8.d.ts +0 -753
  53. node v18.19/ts4.8/vm.d.ts +0 -667
  54. node v18.19/ts4.8/wasi.d.ts +0 -158
  55. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  56. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,918 +0,0 @@
1
- /**
2
- * > Stability: 2 - Stable
3
- *
4
- * The `net` module provides an asynchronous network API for creating stream-based
5
- * TCP or `IPC` servers ({@link createServer}) and clients
6
- * ({@link createConnection}).
7
- *
8
- * It can be accessed using:
9
- *
10
- * ```js
11
- * const net = require('net');
12
- * ```
13
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/net.js)
14
- */
15
- declare module "net" {
16
- import * as stream from "node:stream";
17
- import { Abortable, EventEmitter } from "node:events";
18
- import * as dns from "node:dns";
19
- type LookupFunction = (
20
- hostname: string,
21
- options: dns.LookupOptions,
22
- callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
23
- ) => void;
24
- interface AddressInfo {
25
- address: string;
26
- family: string;
27
- port: number;
28
- }
29
- interface SocketConstructorOpts {
30
- fd?: number | undefined;
31
- allowHalfOpen?: boolean | undefined;
32
- readable?: boolean | undefined;
33
- writable?: boolean | undefined;
34
- signal?: AbortSignal;
35
- }
36
- interface OnReadOpts {
37
- buffer: Uint8Array | (() => Uint8Array);
38
- /**
39
- * This function is called for every chunk of incoming data.
40
- * Two arguments are passed to it: the number of bytes written to buffer and a reference to buffer.
41
- * Return false from this function to implicitly pause() the socket.
42
- */
43
- callback(bytesWritten: number, buf: Uint8Array): boolean;
44
- }
45
- interface ConnectOpts {
46
- /**
47
- * If specified, incoming data is stored in a single buffer and passed to the supplied callback when data arrives on the socket.
48
- * Note: this will cause the streaming functionality to not provide any data, however events like 'error', 'end', and 'close' will
49
- * still be emitted as normal and methods like pause() and resume() will also behave as expected.
50
- */
51
- onread?: OnReadOpts | undefined;
52
- }
53
- interface TcpSocketConnectOpts extends ConnectOpts {
54
- port: number;
55
- host?: string | undefined;
56
- localAddress?: string | undefined;
57
- localPort?: number | undefined;
58
- hints?: number | undefined;
59
- family?: number | undefined;
60
- lookup?: LookupFunction | undefined;
61
- noDelay?: boolean | undefined;
62
- keepAlive?: boolean | undefined;
63
- keepAliveInitialDelay?: number | undefined;
64
- /**
65
- * @since v18.13.0
66
- */
67
- autoSelectFamily?: boolean | undefined;
68
- /**
69
- * @since v18.13.0
70
- */
71
- autoSelectFamilyAttemptTimeout?: number | undefined;
72
- }
73
- interface IpcSocketConnectOpts extends ConnectOpts {
74
- path: string;
75
- }
76
- type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
77
- type SocketReadyState = "opening" | "open" | "readOnly" | "writeOnly" | "closed";
78
- /**
79
- * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
80
- * (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
81
- * an `EventEmitter`.
82
- *
83
- * A `net.Socket` can be created by the user and used directly to interact with
84
- * a server. For example, it is returned by {@link createConnection},
85
- * so the user can use it to talk to the server.
86
- *
87
- * It can also be created by Node.js and passed to the user when a connection
88
- * is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
89
- * it to interact with the client.
90
- * @since v0.3.4
91
- */
92
- class Socket extends stream.Duplex {
93
- constructor(options?: SocketConstructorOpts);
94
- /**
95
- * Destroys the socket after all data is written. If the `finish` event was already emitted the socket is destroyed immediately.
96
- * If the socket is still writable it implicitly calls `socket.end()`.
97
- * @since v0.3.4
98
- */
99
- destroySoon(): void;
100
- /**
101
- * Sends data on the socket. The second parameter specifies the encoding in the
102
- * case of a string. It defaults to UTF8 encoding.
103
- *
104
- * Returns `true` if the entire data was flushed successfully to the kernel
105
- * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is again free.
106
- *
107
- * The optional `callback` parameter will be executed when the data is finally
108
- * written out, which may not be immediately.
109
- *
110
- * See `Writable` stream `write()` method for more
111
- * information.
112
- * @since v0.1.90
113
- * @param [encoding='utf8'] Only used when data is `string`.
114
- */
115
- write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
116
- write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
117
- /**
118
- * Initiate a connection on a given socket.
119
- *
120
- * Possible signatures:
121
- *
122
- * * `socket.connect(options[, connectListener])`
123
- * * `socket.connect(path[, connectListener])` for `IPC` connections.
124
- * * `socket.connect(port[, host][, connectListener])` for TCP connections.
125
- * * Returns: `net.Socket` The socket itself.
126
- *
127
- * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
128
- * instead of a `'connect'` event, an `'error'` event will be emitted with
129
- * the error passed to the `'error'` listener.
130
- * The last parameter `connectListener`, if supplied, will be added as a listener
131
- * for the `'connect'` event **once**.
132
- *
133
- * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
134
- * behavior.
135
- */
136
- connect(options: SocketConnectOpts, connectionListener?: () => void): this;
137
- connect(port: number, host: string, connectionListener?: () => void): this;
138
- connect(port: number, connectionListener?: () => void): this;
139
- connect(path: string, connectionListener?: () => void): this;
140
- /**
141
- * Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
142
- * @since v0.1.90
143
- * @return The socket itself.
144
- */
145
- setEncoding(encoding?: BufferEncoding): this;
146
- /**
147
- * Pauses the reading of data. That is, `'data'` events will not be emitted.
148
- * Useful to throttle back an upload.
149
- * @return The socket itself.
150
- */
151
- pause(): this;
152
- /**
153
- * Close the TCP connection by sending an RST packet and destroy the stream.
154
- * If this TCP socket is in connecting status, it will send an RST packet
155
- * and destroy this TCP socket once it is connected. Otherwise, it will call
156
- * `socket.destroy` with an `ERR_SOCKET_CLOSED` Error. If this is not a TCP socket
157
- * (for example, a pipe), calling this method will immediately throw
158
- * an `ERR_INVALID_HANDLE_TYPE` Error.
159
- * @since v18.3.0
160
- * @return The socket itself.
161
- */
162
- resetAndDestroy(): this;
163
- /**
164
- * Resumes reading after a call to `socket.pause()`.
165
- * @return The socket itself.
166
- */
167
- resume(): this;
168
- /**
169
- * Sets the socket to timeout after `timeout` milliseconds of inactivity on
170
- * the socket. By default `net.Socket` do not have a timeout.
171
- *
172
- * When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed. The user must manually call `socket.end()` or `socket.destroy()` to
173
- * end the connection.
174
- *
175
- * ```js
176
- * socket.setTimeout(3000);
177
- * socket.on('timeout', () => {
178
- * console.log('socket timeout');
179
- * socket.end();
180
- * });
181
- * ```
182
- *
183
- * If `timeout` is 0, then the existing idle timeout is disabled.
184
- *
185
- * The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
186
- * @since v0.1.90
187
- * @return The socket itself.
188
- */
189
- setTimeout(timeout: number, callback?: () => void): this;
190
- /**
191
- * Enable/disable the use of Nagle's algorithm.
192
- *
193
- * When a TCP connection is created, it will have Nagle's algorithm enabled.
194
- *
195
- * Nagle's algorithm delays data before it is sent via the network. It attempts
196
- * to optimize throughput at the expense of latency.
197
- *
198
- * Passing `true` for `noDelay` or not passing an argument will disable Nagle's
199
- * algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
200
- * algorithm.
201
- * @since v0.1.90
202
- * @param [noDelay=true]
203
- * @return The socket itself.
204
- */
205
- setNoDelay(noDelay?: boolean): this;
206
- /**
207
- * Enable/disable keep-alive functionality, and optionally set the initial
208
- * delay before the first keepalive probe is sent on an idle socket.
209
- *
210
- * Set `initialDelay` (in milliseconds) to set the delay between the last
211
- * data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
212
- * (or previous) setting.
213
- *
214
- * Enabling the keep-alive functionality will set the following socket options:
215
- *
216
- * * `SO_KEEPALIVE=1`
217
- * * `TCP_KEEPIDLE=initialDelay`
218
- * * `TCP_KEEPCNT=10`
219
- * * `TCP_KEEPINTVL=1`
220
- * @since v0.1.92
221
- * @param [enable=false]
222
- * @param [initialDelay=0]
223
- * @return The socket itself.
224
- */
225
- setKeepAlive(enable?: boolean, initialDelay?: number): this;
226
- /**
227
- * Returns the bound `address`, the address `family` name and `port` of the
228
- * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
229
- * @since v0.1.90
230
- */
231
- address(): AddressInfo | {};
232
- /**
233
- * Calling `unref()` on a socket will allow the program to exit if this is the only
234
- * active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
235
- * @since v0.9.1
236
- * @return The socket itself.
237
- */
238
- unref(): this;
239
- /**
240
- * Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will _not_ let the program exit if it's the only socket left (the default behavior).
241
- * If the socket is `ref`ed calling `ref` again will have no effect.
242
- * @since v0.9.1
243
- * @return The socket itself.
244
- */
245
- ref(): this;
246
- /**
247
- * This property shows the number of characters buffered for writing. The buffer
248
- * may contain strings whose length after encoding is not yet known. So this number
249
- * is only an approximation of the number of bytes in the buffer.
250
- *
251
- * `net.Socket` has the property that `socket.write()` always works. This is to
252
- * help users get up and running quickly. The computer cannot always keep up
253
- * with the amount of data that is written to a socket. The network connection
254
- * simply might be too slow. Node.js will internally queue up the data written to a
255
- * socket and send it out over the wire when it is possible.
256
- *
257
- * The consequence of this internal buffering is that memory may grow.
258
- * Users who experience large or growing `bufferSize` should attempt to
259
- * "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
260
- * @since v0.3.8
261
- * @deprecated Since v14.6.0 - Use `writableLength` instead.
262
- */
263
- readonly bufferSize: number;
264
- /**
265
- * The amount of received bytes.
266
- * @since v0.5.3
267
- */
268
- readonly bytesRead: number;
269
- /**
270
- * The amount of bytes sent.
271
- * @since v0.5.3
272
- */
273
- readonly bytesWritten: number;
274
- /**
275
- * If `true`,`socket.connect(options[, connectListener])` was
276
- * called and has not yet finished. It will stay `true` until the socket becomes
277
- * connected, then it is set to `false` and the `'connect'` event is emitted. Note
278
- * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
279
- * @since v6.1.0
280
- */
281
- readonly connecting: boolean;
282
- /**
283
- * This is `true` if the socket is not connected yet, either because `.connect()`
284
- * has not yet been called or because it is still in the process of connecting (see `socket.connecting`).
285
- * @since v10.16.0
286
- */
287
- readonly pending: boolean;
288
- /**
289
- * See `writable.destroyed` for further details.
290
- */
291
- readonly destroyed: boolean;
292
- /**
293
- * The string representation of the local IP address the remote client is
294
- * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
295
- * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
296
- * @since v0.9.6
297
- */
298
- readonly localAddress?: string;
299
- /**
300
- * The numeric representation of the local port. For example, `80` or `21`.
301
- * @since v0.9.6
302
- */
303
- readonly localPort?: number;
304
- /**
305
- * The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
306
- * @since v18.8.0
307
- */
308
- readonly localFamily?: string;
309
- /**
310
- * This property represents the state of the connection as a string.
311
- * @see {https://nodejs.org/api/net.html#socketreadystate}
312
- * @since v0.5.0
313
- */
314
- readonly readyState: SocketReadyState;
315
- /**
316
- * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
317
- * the socket is destroyed (for example, if the client disconnected).
318
- * @since v0.5.10
319
- */
320
- readonly remoteAddress?: string | undefined;
321
- /**
322
- * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
323
- * @since v0.11.14
324
- */
325
- readonly remoteFamily?: string | undefined;
326
- /**
327
- * The numeric representation of the remote port. For example, `80` or `21`.
328
- * @since v0.5.10
329
- */
330
- readonly remotePort?: number | undefined;
331
- /**
332
- * The socket timeout in milliseconds as set by socket.setTimeout(). It is undefined if a timeout has not been set.
333
- * @since v10.7.0
334
- */
335
- readonly timeout?: number | undefined;
336
- /**
337
- * Half-closes the socket. i.e., it sends a FIN packet. It is possible the
338
- * server will still send some data.
339
- *
340
- * See `writable.end()` for further details.
341
- * @since v0.1.90
342
- * @param [encoding='utf8'] Only used when data is `string`.
343
- * @param callback Optional callback for when the socket is finished.
344
- * @return The socket itself.
345
- */
346
- end(callback?: () => void): this;
347
- end(buffer: Uint8Array | string, callback?: () => void): this;
348
- end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
349
- /**
350
- * events.EventEmitter
351
- * 1. close
352
- * 2. connect
353
- * 3. data
354
- * 4. drain
355
- * 5. end
356
- * 6. error
357
- * 7. lookup
358
- * 8. ready
359
- * 9. timeout
360
- */
361
- addListener(event: string, listener: (...args: any[]) => void): this;
362
- addListener(event: "close", listener: (hadError: boolean) => void): this;
363
- addListener(event: "connect", listener: () => void): this;
364
- addListener(event: "data", listener: (data: Buffer) => void): this;
365
- addListener(event: "drain", listener: () => void): this;
366
- addListener(event: "end", listener: () => void): this;
367
- addListener(event: "error", listener: (err: Error) => void): this;
368
- addListener(
369
- event: "lookup",
370
- listener: (err: Error, address: string, family: string | number, host: string) => void,
371
- ): this;
372
- addListener(event: "ready", listener: () => void): this;
373
- addListener(event: "timeout", listener: () => void): this;
374
- emit(event: string | symbol, ...args: any[]): boolean;
375
- emit(event: "close", hadError: boolean): boolean;
376
- emit(event: "connect"): boolean;
377
- emit(event: "data", data: Buffer): boolean;
378
- emit(event: "drain"): boolean;
379
- emit(event: "end"): boolean;
380
- emit(event: "error", err: Error): boolean;
381
- emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;
382
- emit(event: "ready"): boolean;
383
- emit(event: "timeout"): boolean;
384
- on(event: string, listener: (...args: any[]) => void): this;
385
- on(event: "close", listener: (hadError: boolean) => void): this;
386
- on(event: "connect", listener: () => void): this;
387
- on(event: "data", listener: (data: Buffer) => void): this;
388
- on(event: "drain", listener: () => void): this;
389
- on(event: "end", listener: () => void): this;
390
- on(event: "error", listener: (err: Error) => void): this;
391
- on(
392
- event: "lookup",
393
- listener: (err: Error, address: string, family: string | number, host: string) => void,
394
- ): this;
395
- on(event: "ready", listener: () => void): this;
396
- on(event: "timeout", listener: () => void): this;
397
- once(event: string, listener: (...args: any[]) => void): this;
398
- once(event: "close", listener: (hadError: boolean) => void): this;
399
- once(event: "connect", listener: () => void): this;
400
- once(event: "data", listener: (data: Buffer) => void): this;
401
- once(event: "drain", listener: () => void): this;
402
- once(event: "end", listener: () => void): this;
403
- once(event: "error", listener: (err: Error) => void): this;
404
- once(
405
- event: "lookup",
406
- listener: (err: Error, address: string, family: string | number, host: string) => void,
407
- ): this;
408
- once(event: "ready", listener: () => void): this;
409
- once(event: "timeout", listener: () => void): this;
410
- prependListener(event: string, listener: (...args: any[]) => void): this;
411
- prependListener(event: "close", listener: (hadError: boolean) => void): this;
412
- prependListener(event: "connect", listener: () => void): this;
413
- prependListener(event: "data", listener: (data: Buffer) => void): this;
414
- prependListener(event: "drain", listener: () => void): this;
415
- prependListener(event: "end", listener: () => void): this;
416
- prependListener(event: "error", listener: (err: Error) => void): this;
417
- prependListener(
418
- event: "lookup",
419
- listener: (err: Error, address: string, family: string | number, host: string) => void,
420
- ): this;
421
- prependListener(event: "ready", listener: () => void): this;
422
- prependListener(event: "timeout", listener: () => void): this;
423
- prependOnceListener(event: string, listener: (...args: any[]) => void): this;
424
- prependOnceListener(event: "close", listener: (hadError: boolean) => void): this;
425
- prependOnceListener(event: "connect", listener: () => void): this;
426
- prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
427
- prependOnceListener(event: "drain", listener: () => void): this;
428
- prependOnceListener(event: "end", listener: () => void): this;
429
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
430
- prependOnceListener(
431
- event: "lookup",
432
- listener: (err: Error, address: string, family: string | number, host: string) => void,
433
- ): this;
434
- prependOnceListener(event: "ready", listener: () => void): this;
435
- prependOnceListener(event: "timeout", listener: () => void): this;
436
- }
437
- interface ListenOptions extends Abortable {
438
- port?: number | undefined;
439
- host?: string | undefined;
440
- backlog?: number | undefined;
441
- path?: string | undefined;
442
- exclusive?: boolean | undefined;
443
- readableAll?: boolean | undefined;
444
- writableAll?: boolean | undefined;
445
- /**
446
- * @default false
447
- */
448
- ipv6Only?: boolean | undefined;
449
- }
450
- interface ServerOpts {
451
- /**
452
- * Indicates whether half-opened TCP connections are allowed.
453
- * @default false
454
- */
455
- allowHalfOpen?: boolean | undefined;
456
- /**
457
- * Indicates whether the socket should be paused on incoming connections.
458
- * @default false
459
- */
460
- pauseOnConnect?: boolean | undefined;
461
- /**
462
- * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
463
- * @default false
464
- * @since v16.5.0
465
- */
466
- noDelay?: boolean | undefined;
467
- /**
468
- * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
469
- * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
470
- * @default false
471
- * @since v16.5.0
472
- */
473
- keepAlive?: boolean | undefined;
474
- /**
475
- * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
476
- * @default 0
477
- * @since v16.5.0
478
- */
479
- keepAliveInitialDelay?: number | undefined;
480
- }
481
- interface DropArgument {
482
- localAddress?: string;
483
- localPort?: number;
484
- localFamily?: string;
485
- remoteAddress?: string;
486
- remotePort?: number;
487
- remoteFamily?: string;
488
- }
489
- /**
490
- * This class is used to create a TCP or `IPC` server.
491
- * @since v0.1.90
492
- */
493
- class Server extends EventEmitter {
494
- constructor(connectionListener?: (socket: Socket) => void);
495
- constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
496
- /**
497
- * Start a server listening for connections. A `net.Server` can be a TCP or
498
- * an `IPC` server depending on what it listens to.
499
- *
500
- * Possible signatures:
501
- *
502
- * * `server.listen(handle[, backlog][, callback])`
503
- * * `server.listen(options[, callback])`
504
- * * `server.listen(path[, backlog][, callback])` for `IPC` servers
505
- * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
506
- *
507
- * This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. The last parameter `callback`will be added as a listener for the `'listening'`
508
- * event.
509
- *
510
- * All `listen()` methods can take a `backlog` parameter to specify the maximum
511
- * length of the queue of pending connections. The actual length will be determined
512
- * by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn`on Linux. The default value of this parameter is 511 (not 512).
513
- *
514
- * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
515
- * details).
516
- *
517
- * The `server.listen()` method can be called again if and only if there was an
518
- * error during the first `server.listen()` call or `server.close()` has been
519
- * called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
520
- *
521
- * One of the most common errors raised when listening is `EADDRINUSE`.
522
- * This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
523
- * after a certain amount of time:
524
- *
525
- * ```js
526
- * server.on('error', (e) => {
527
- * if (e.code === 'EADDRINUSE') {
528
- * console.log('Address in use, retrying...');
529
- * setTimeout(() => {
530
- * server.close();
531
- * server.listen(PORT, HOST);
532
- * }, 1000);
533
- * }
534
- * });
535
- * ```
536
- */
537
- listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
538
- listen(port?: number, hostname?: string, listeningListener?: () => void): this;
539
- listen(port?: number, backlog?: number, listeningListener?: () => void): this;
540
- listen(port?: number, listeningListener?: () => void): this;
541
- listen(path: string, backlog?: number, listeningListener?: () => void): this;
542
- listen(path: string, listeningListener?: () => void): this;
543
- listen(options: ListenOptions, listeningListener?: () => void): this;
544
- listen(handle: any, backlog?: number, listeningListener?: () => void): this;
545
- listen(handle: any, listeningListener?: () => void): this;
546
- /**
547
- * Stops the server from accepting new connections and keeps existing
548
- * connections. This function is asynchronous, the server is finally closed
549
- * when all connections are ended and the server emits a `'close'` event.
550
- * The optional `callback` will be called once the `'close'` event occurs. Unlike
551
- * that event, it will be called with an `Error` as its only argument if the server
552
- * was not open when it was closed.
553
- * @since v0.1.90
554
- * @param callback Called when the server is closed.
555
- */
556
- close(callback?: (err?: Error) => void): this;
557
- /**
558
- * Returns the bound `address`, the address `family` name, and `port` of the server
559
- * as reported by the operating system if listening on an IP socket
560
- * (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
561
- *
562
- * For a server listening on a pipe or Unix domain socket, the name is returned
563
- * as a string.
564
- *
565
- * ```js
566
- * const server = net.createServer((socket) => {
567
- * socket.end('goodbye\n');
568
- * }).on('error', (err) => {
569
- * // Handle errors here.
570
- * throw err;
571
- * });
572
- *
573
- * // Grab an arbitrary unused port.
574
- * server.listen(() => {
575
- * console.log('opened server on', server.address());
576
- * });
577
- * ```
578
- *
579
- * `server.address()` returns `null` before the `'listening'` event has been
580
- * emitted or after calling `server.close()`.
581
- * @since v0.1.90
582
- */
583
- address(): AddressInfo | string | null;
584
- /**
585
- * Asynchronously get the number of concurrent connections on the server. Works
586
- * when sockets were sent to forks.
587
- *
588
- * Callback should take two arguments `err` and `count`.
589
- * @since v0.9.7
590
- */
591
- getConnections(cb: (error: Error | null, count: number) => void): void;
592
- /**
593
- * Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will _not_ let the program exit if it's the only server left (the default behavior).
594
- * If the server is `ref`ed calling `ref()` again will have no effect.
595
- * @since v0.9.1
596
- */
597
- ref(): this;
598
- /**
599
- * Calling `unref()` on a server will allow the program to exit if this is the only
600
- * active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
601
- * @since v0.9.1
602
- */
603
- unref(): this;
604
- /**
605
- * Set this property to reject connections when the server's connection count gets
606
- * high.
607
- *
608
- * It is not recommended to use this option once a socket has been sent to a child
609
- * with `child_process.fork()`.
610
- * @since v0.2.0
611
- */
612
- maxConnections: number;
613
- connections: number;
614
- /**
615
- * Indicates whether or not the server is listening for connections.
616
- * @since v5.7.0
617
- */
618
- listening: boolean;
619
- /**
620
- * events.EventEmitter
621
- * 1. close
622
- * 2. connection
623
- * 3. error
624
- * 4. listening
625
- * 5. drop
626
- */
627
- addListener(event: string, listener: (...args: any[]) => void): this;
628
- addListener(event: "close", listener: () => void): this;
629
- addListener(event: "connection", listener: (socket: Socket) => void): this;
630
- addListener(event: "error", listener: (err: Error) => void): this;
631
- addListener(event: "listening", listener: () => void): this;
632
- addListener(event: "drop", listener: (data?: DropArgument) => void): this;
633
- emit(event: string | symbol, ...args: any[]): boolean;
634
- emit(event: "close"): boolean;
635
- emit(event: "connection", socket: Socket): boolean;
636
- emit(event: "error", err: Error): boolean;
637
- emit(event: "listening"): boolean;
638
- emit(event: "drop", data?: DropArgument): boolean;
639
- on(event: string, listener: (...args: any[]) => void): this;
640
- on(event: "close", listener: () => void): this;
641
- on(event: "connection", listener: (socket: Socket) => void): this;
642
- on(event: "error", listener: (err: Error) => void): this;
643
- on(event: "listening", listener: () => void): this;
644
- on(event: "drop", listener: (data?: DropArgument) => void): this;
645
- once(event: string, listener: (...args: any[]) => void): this;
646
- once(event: "close", listener: () => void): this;
647
- once(event: "connection", listener: (socket: Socket) => void): this;
648
- once(event: "error", listener: (err: Error) => void): this;
649
- once(event: "listening", listener: () => void): this;
650
- once(event: "drop", listener: (data?: DropArgument) => void): this;
651
- prependListener(event: string, listener: (...args: any[]) => void): this;
652
- prependListener(event: "close", listener: () => void): this;
653
- prependListener(event: "connection", listener: (socket: Socket) => void): this;
654
- prependListener(event: "error", listener: (err: Error) => void): this;
655
- prependListener(event: "listening", listener: () => void): this;
656
- prependListener(event: "drop", listener: (data?: DropArgument) => void): this;
657
- prependOnceListener(event: string, listener: (...args: any[]) => void): this;
658
- prependOnceListener(event: "close", listener: () => void): this;
659
- prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
660
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
661
- prependOnceListener(event: "listening", listener: () => void): this;
662
- prependOnceListener(event: "drop", listener: (data?: DropArgument) => void): this;
663
- /**
664
- * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
665
- * @since v18.18.0
666
- */
667
- [Symbol.asyncDispose](): Promise<void>;
668
- }
669
- type IPVersion = "ipv4" | "ipv6";
670
- /**
671
- * The `BlockList` object can be used with some network APIs to specify rules for
672
- * disabling inbound or outbound access to specific IP addresses, IP ranges, or
673
- * IP subnets.
674
- * @since v15.0.0, v14.18.0
675
- */
676
- class BlockList {
677
- /**
678
- * Adds a rule to block the given IP address.
679
- * @since v15.0.0, v14.18.0
680
- * @param address An IPv4 or IPv6 address.
681
- * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
682
- */
683
- addAddress(address: string, type?: IPVersion): void;
684
- addAddress(address: SocketAddress): void;
685
- /**
686
- * Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
687
- * @since v15.0.0, v14.18.0
688
- * @param start The starting IPv4 or IPv6 address in the range.
689
- * @param end The ending IPv4 or IPv6 address in the range.
690
- * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
691
- */
692
- addRange(start: string, end: string, type?: IPVersion): void;
693
- addRange(start: SocketAddress, end: SocketAddress): void;
694
- /**
695
- * Adds a rule to block a range of IP addresses specified as a subnet mask.
696
- * @since v15.0.0, v14.18.0
697
- * @param net The network IPv4 or IPv6 address.
698
- * @param prefix The number of CIDR prefix bits. For IPv4, this must be a value between `0` and `32`. For IPv6, this must be between `0` and `128`.
699
- * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
700
- */
701
- addSubnet(net: SocketAddress, prefix: number): void;
702
- addSubnet(net: string, prefix: number, type?: IPVersion): void;
703
- /**
704
- * Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
705
- *
706
- * ```js
707
- * const blockList = new net.BlockList();
708
- * blockList.addAddress('123.123.123.123');
709
- * blockList.addRange('10.0.0.1', '10.0.0.10');
710
- * blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
711
- *
712
- * console.log(blockList.check('123.123.123.123')); // Prints: true
713
- * console.log(blockList.check('10.0.0.3')); // Prints: true
714
- * console.log(blockList.check('222.111.111.222')); // Prints: false
715
- *
716
- * // IPv6 notation for IPv4 addresses works:
717
- * console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
718
- * console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
719
- * ```
720
- * @since v15.0.0, v14.18.0
721
- * @param address The IP address to check
722
- * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
723
- */
724
- check(address: SocketAddress): boolean;
725
- check(address: string, type?: IPVersion): boolean;
726
- /**
727
- * The list of rules added to the blocklist.
728
- * @since v15.0.0, v14.18.0
729
- */
730
- rules: readonly string[];
731
- }
732
- interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
733
- timeout?: number | undefined;
734
- }
735
- interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
736
- timeout?: number | undefined;
737
- }
738
- type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
739
- /**
740
- * Creates a new TCP or `IPC` server.
741
- *
742
- * If `allowHalfOpen` is set to `true`, when the other end of the socket
743
- * signals the end of transmission, the server will only send back the end of
744
- * transmission when `socket.end()` is explicitly called. For example, in the
745
- * context of TCP, when a FIN packed is received, a FIN packed is sent
746
- * back only when `socket.end()` is explicitly called. Until then the
747
- * connection is half-closed (non-readable but still writable). See `'end'` event and [RFC 1122](https://tools.ietf.org/html/rfc1122) (section 4.2.2.13) for more information.
748
- *
749
- * If `pauseOnConnect` is set to `true`, then the socket associated with each
750
- * incoming connection will be paused, and no data will be read from its handle.
751
- * This allows connections to be passed between processes without any data being
752
- * read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
753
- *
754
- * The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
755
- *
756
- * Here is an example of a TCP echo server which listens for connections
757
- * on port 8124:
758
- *
759
- * ```js
760
- * const net = require('net');
761
- * const server = net.createServer((c) => {
762
- * // 'connection' listener.
763
- * console.log('client connected');
764
- * c.on('end', () => {
765
- * console.log('client disconnected');
766
- * });
767
- * c.write('hello\r\n');
768
- * c.pipe(c);
769
- * });
770
- * server.on('error', (err) => {
771
- * throw err;
772
- * });
773
- * server.listen(8124, () => {
774
- * console.log('server bound');
775
- * });
776
- * ```
777
- *
778
- * Test this by using `telnet`:
779
- *
780
- * ```console
781
- * $ telnet localhost 8124
782
- * ```
783
- *
784
- * To listen on the socket `/tmp/echo.sock`:
785
- *
786
- * ```js
787
- * server.listen('/tmp/echo.sock', () => {
788
- * console.log('server bound');
789
- * });
790
- * ```
791
- *
792
- * Use `nc` to connect to a Unix domain socket server:
793
- *
794
- * ```console
795
- * $ nc -U /tmp/echo.sock
796
- * ```
797
- * @since v0.5.0
798
- * @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
799
- */
800
- function createServer(connectionListener?: (socket: Socket) => void): Server;
801
- function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
802
- /**
803
- * Aliases to {@link createConnection}.
804
- *
805
- * Possible signatures:
806
- *
807
- * * {@link connect}
808
- * * {@link connect} for `IPC` connections.
809
- * * {@link connect} for TCP connections.
810
- */
811
- function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
812
- function connect(port: number, host?: string, connectionListener?: () => void): Socket;
813
- function connect(path: string, connectionListener?: () => void): Socket;
814
- /**
815
- * A factory function, which creates a new {@link Socket},
816
- * immediately initiates connection with `socket.connect()`,
817
- * then returns the `net.Socket` that starts the connection.
818
- *
819
- * When the connection is established, a `'connect'` event will be emitted
820
- * on the returned socket. The last parameter `connectListener`, if supplied,
821
- * will be added as a listener for the `'connect'` event **once**.
822
- *
823
- * Possible signatures:
824
- *
825
- * * {@link createConnection}
826
- * * {@link createConnection} for `IPC` connections.
827
- * * {@link createConnection} for TCP connections.
828
- *
829
- * The {@link connect} function is an alias to this function.
830
- */
831
- function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
832
- function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
833
- function createConnection(path: string, connectionListener?: () => void): Socket;
834
- /**
835
- * Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
836
- * address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
837
- *
838
- * ```js
839
- * net.isIP('::1'); // returns 6
840
- * net.isIP('127.0.0.1'); // returns 4
841
- * net.isIP('127.000.000.001'); // returns 0
842
- * net.isIP('127.0.0.1/24'); // returns 0
843
- * net.isIP('fhqwhgads'); // returns 0
844
- * ```
845
- * @since v0.3.0
846
- */
847
- function isIP(input: string): number;
848
- /**
849
- * Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
850
- * leading zeroes. Otherwise, returns `false`.
851
- *
852
- * ```js
853
- * net.isIPv4('127.0.0.1'); // returns true
854
- * net.isIPv4('127.000.000.001'); // returns false
855
- * net.isIPv4('127.0.0.1/24'); // returns false
856
- * net.isIPv4('fhqwhgads'); // returns false
857
- * ```
858
- * @since v0.3.0
859
- */
860
- function isIPv4(input: string): boolean;
861
- /**
862
- * Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
863
- *
864
- * ```js
865
- * net.isIPv6('::1'); // returns true
866
- * net.isIPv6('fhqwhgads'); // returns false
867
- * ```
868
- * @since v0.3.0
869
- */
870
- function isIPv6(input: string): boolean;
871
- interface SocketAddressInitOptions {
872
- /**
873
- * The network address as either an IPv4 or IPv6 string.
874
- * @default 127.0.0.1
875
- */
876
- address?: string | undefined;
877
- /**
878
- * @default `'ipv4'`
879
- */
880
- family?: IPVersion | undefined;
881
- /**
882
- * An IPv6 flow-label used only if `family` is `'ipv6'`.
883
- * @default 0
884
- */
885
- flowlabel?: number | undefined;
886
- /**
887
- * An IP port.
888
- * @default 0
889
- */
890
- port?: number | undefined;
891
- }
892
- /**
893
- * @since v15.14.0, v14.18.0
894
- */
895
- class SocketAddress {
896
- constructor(options: SocketAddressInitOptions);
897
- /**
898
- * @since v15.14.0, v14.18.0
899
- */
900
- readonly address: string;
901
- /**
902
- * Either \`'ipv4'\` or \`'ipv6'\`.
903
- * @since v15.14.0, v14.18.0
904
- */
905
- readonly family: IPVersion;
906
- /**
907
- * @since v15.14.0, v14.18.0
908
- */
909
- readonly port: number;
910
- /**
911
- * @since v15.14.0, v14.18.0
912
- */
913
- readonly flowlabel: number;
914
- }
915
- }
916
- declare module "node:net" {
917
- export * from "net";
918
- }