@tothalex/cloud 0.0.40

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.
package/src/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /// <reference types="./cloud/cache.d.ts" />
2
+ /// <reference types="./cloud/event.d.ts" />
3
+ /// <reference types="./cloud/index.d.ts" />
4
+ /// <reference types="./cloud/postgres.d.ts" />
5
+ /// <reference types="./cloud/secret.d.ts" />
6
+ /// <reference types="./cloud/uuid.d.ts" />
7
+
8
+ /// <reference types="./assert.d.ts" />
9
+ /// <reference types="./buffer.d.ts" />
10
+ /// <reference types="./crypto.d.ts" />
11
+ /// <reference types="./dns.d.ts" />
12
+ /// <reference types="./events.d.ts" />
13
+ /// <reference types="./net.d.ts" />
14
+ /// <reference types="./os.d.ts" />
15
+ /// <reference types="./process.d.ts" />
16
+ /// <reference types="./stream/web.d.ts" />
17
+ /// <reference types="./string_decoder.d.ts" />
18
+ /// <reference types="./timers.d.ts" />
19
+ /// <reference types="./tty.d.ts" />
20
+ /// <reference types="./url.d.ts" />
21
+ /// <reference types="./util.d.ts" />
22
+ /// <reference types="./zlib.d.ts" />
package/src/net.d.ts ADDED
@@ -0,0 +1,488 @@
1
+ /**
2
+ * The `net` module provides an asynchronous network API for creating stream-based
3
+ * TCP or `IPC` servers ({@link createServer}) and clients ({@link createConnection}).
4
+ *
5
+ * It can be accessed using:
6
+ *
7
+ * ```js
8
+ * import * as net from 'net';
9
+ * ```
10
+ */
11
+ declare module "net" {
12
+ import { Buffer } from "buffer";
13
+ import { EventEmitter } from "events";
14
+ import { DefaultDuplexStream as Duplex } from "stream";
15
+
16
+ interface AddressInfo {
17
+ address: string;
18
+ family: string;
19
+ port: number;
20
+ }
21
+
22
+ interface SocketConstructorOpts {
23
+ allowHalfOpen?: boolean | undefined;
24
+ }
25
+ interface TcpSocketConnectOpts {
26
+ port: number;
27
+ host?: string | undefined;
28
+ }
29
+ interface IpcSocketConnectOpts {
30
+ path: string;
31
+ }
32
+ type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
33
+ type SocketReadyState =
34
+ | "opening"
35
+ | "open"
36
+ | "readOnly"
37
+ | "writeOnly"
38
+ | "closed";
39
+
40
+ /**
41
+ * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint (only available on Unix with domain sockets).
42
+ * It is also an `EventEmitter`.
43
+ *
44
+ * A `net.Socket` can be created by the user and used directly to interact with a server. For example, it is returned by {@link createConnection},
45
+ * so the user can use it to talk to the server.
46
+ *
47
+ * It can also be created by LLRT and passed to the user when a connection is received.
48
+ * For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use it to interact with the client.
49
+ */
50
+ class Socket extends Duplex {
51
+ constructor(options?: SocketConstructorOpts);
52
+
53
+ /**
54
+ * Initiate a connection on a given socket.
55
+ *
56
+ * Possible signatures:
57
+ *
58
+ * * `socket.connect(options[, connectListener])`
59
+ * * `socket.connect(path[, connectListener])` for `IPC` connections.
60
+ * * `socket.connect(port[, host][, connectListener])` for TCP connections.
61
+ * * Returns: `net.Socket` The socket itself.
62
+ *
63
+ * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
64
+ * instead of a `'connect'` event, an `'error'` event will be emitted with
65
+ * the error passed to the `'error'` listener.
66
+ * The last parameter `connectListener`, if supplied, will be added as a listener
67
+ * for the `'connect'` event **once**.
68
+ *
69
+ * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
70
+ * behavior.
71
+ */
72
+ connect(options: SocketConnectOpts, connectionListener?: () => void): this;
73
+ connect(port: number, host: string, connectionListener?: () => void): this;
74
+ connect(port: number, connectionListener?: () => void): this;
75
+ connect(path: string, connectionListener?: () => void): this;
76
+
77
+ /**
78
+ * Returns the bound `address`, the address `family` name and `port` of the
79
+ * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
80
+ * @since v0.1.90
81
+ */
82
+ address(): AddressInfo | {};
83
+
84
+ /**
85
+ * If `true`, `socket.connect(options[, connectListener])` was
86
+ * called and has not yet finished. It will stay `true` until the socket becomes
87
+ * connected, then it is set to `false` and the `'connect'` event is emitted. Note
88
+ * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
89
+ */
90
+ readonly connecting: boolean;
91
+
92
+ /**
93
+ * This is `true` if the socket is not connected yet, either because `.connect()`has not yet been called or because it is still in the process of connecting
94
+ * (see `socket.connecting`).
95
+ */
96
+ readonly pending: boolean;
97
+
98
+ /**
99
+ * The string representation of the local IP address the remote client is
100
+ * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
101
+ * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
102
+ */
103
+ readonly localAddress?: string;
104
+
105
+ /**
106
+ * The numeric representation of the local port. For example, `80` or `21`.
107
+ */
108
+ readonly localPort?: number;
109
+
110
+ /**
111
+ * The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
112
+ */
113
+ readonly localFamily?: string;
114
+
115
+ /**
116
+ * This property represents the state of the connection as a string.
117
+ *
118
+ * * If the stream is connecting `socket.readyState` is `opening`.
119
+ * * If the stream is readable and writable, it is `open`.
120
+ * * If the stream is readable and not writable, it is `readOnly`.
121
+ * * If the stream is not readable and writable, it is `writeOnly`.
122
+ */
123
+ readonly readyState: SocketReadyState;
124
+
125
+ /**
126
+ * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
127
+ * the socket is destroyed (for example, if the client disconnected).
128
+ */
129
+ readonly remoteAddress?: string;
130
+
131
+ /**
132
+ * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if
133
+ * the socket is destroyed (for example, if the client disconnected).
134
+ */
135
+ readonly remoteFamily?: string;
136
+
137
+ /**
138
+ * The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if
139
+ * the socket is destroyed (for example, if the client disconnected).
140
+ */
141
+ readonly remotePort?: number | undefined;
142
+
143
+ /**
144
+ * Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.
145
+ *
146
+ * @param callback Optional callback for when the socket is finished.
147
+ * @return The socket itself.
148
+ */
149
+ end(callback?: () => void): this;
150
+
151
+ /**
152
+ * events.EventEmitter
153
+ * 1. close
154
+ * 2. connect
155
+ * 3. data
156
+ * 4. end
157
+ * 5. error
158
+ */
159
+ addListener(event: string, listener: (...args: any[]) => void): this;
160
+ addListener(event: "close", listener: (hadError: boolean) => void): this;
161
+ addListener(event: "connect", listener: () => void): this;
162
+ addListener(event: "data", listener: (data: Buffer) => void): this;
163
+ addListener(event: "drain", listener: () => void): this;
164
+ addListener(event: "end", listener: () => void): this;
165
+ addListener(event: "error", listener: (err: Error) => void): this;
166
+ emit(event: string | symbol, ...args: any[]): boolean;
167
+ emit(event: "close", hadError: boolean): boolean;
168
+ emit(event: "connect"): boolean;
169
+ emit(event: "data", data: Buffer): boolean;
170
+ emit(event: "end"): boolean;
171
+ emit(event: "error", err: Error): boolean;
172
+ on(event: string, listener: (...args: any[]) => void): this;
173
+ on(event: "close", listener: (hadError: boolean) => void): this;
174
+ on(event: "connect", listener: () => void): this;
175
+ on(event: "data", listener: (data: Buffer) => void): this;
176
+ on(event: "end", listener: () => void): this;
177
+ on(event: "error", listener: (err: Error) => void): this;
178
+ once(event: string, listener: (...args: any[]) => void): this;
179
+ once(event: "close", listener: (hadError: boolean) => void): this;
180
+ once(event: "connect", listener: () => void): this;
181
+ once(event: "data", listener: (data: Buffer) => void): this;
182
+ once(event: "end", listener: () => void): this;
183
+ once(event: "error", listener: (err: Error) => void): this;
184
+ prependListener(event: string, listener: (...args: any[]) => void): this;
185
+ prependListener(
186
+ event: "close",
187
+ listener: (hadError: boolean) => void
188
+ ): this;
189
+ prependListener(event: "connect", listener: () => void): this;
190
+ prependListener(event: "data", listener: (data: Buffer) => void): this;
191
+ prependListener(event: "end", listener: () => void): this;
192
+ prependListener(event: "error", listener: (err: Error) => void): this;
193
+ prependOnceListener(
194
+ event: string,
195
+ listener: (...args: any[]) => void
196
+ ): this;
197
+ prependOnceListener(
198
+ event: "close",
199
+ listener: (hadError: boolean) => void
200
+ ): this;
201
+ prependOnceListener(event: "connect", listener: () => void): this;
202
+ prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
203
+ prependOnceListener(event: "end", listener: () => void): this;
204
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
205
+ }
206
+
207
+ interface ListenOptions {
208
+ port?: number | undefined;
209
+ host?: string | undefined;
210
+ backlog?: number | undefined;
211
+ path?: string | undefined;
212
+ }
213
+
214
+ interface ServerOpts {
215
+ /**
216
+ * Indicates whether half-opened TCP connections are allowed.
217
+ * @default false
218
+ */
219
+ allowHalfOpen?: boolean | undefined;
220
+ }
221
+
222
+ /**
223
+ * This class is used to create a TCP or `IPC` server.
224
+ */
225
+ class Server extends EventEmitter {
226
+ constructor(connectionListener?: (socket: Socket) => void);
227
+ constructor(
228
+ options?: ServerOpts,
229
+ connectionListener?: (socket: Socket) => void
230
+ );
231
+
232
+ /**
233
+ * Start a server listening for connections. A `net.Server` can be a TCP or
234
+ * an `IPC` server depending on what it listens to.
235
+ *
236
+ * Possible signatures:
237
+ *
238
+ * * `server.listen(options[, callback])`
239
+ * * `server.listen(path[, backlog][, callback])` for `IPC` servers
240
+ * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
241
+ *
242
+ * 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'`
243
+ * event.
244
+ *
245
+ * All `listen()` methods can take a `backlog` parameter to specify the maximum length of the queue of pending connections.
246
+ * Currently this parameter is IGNORED, support will be added in the future.
247
+ *
248
+ * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for details).
249
+ *
250
+ * The `server.listen()` method can be called again if and only if there was an error during the first `server.listen()`
251
+ * call or `server.close()` has been called. Otherwise, an error will be thrown.
252
+ */
253
+ listen(listeningListener?: () => void): void;
254
+ listen(
255
+ port?: number,
256
+ hostname?: string,
257
+ backlog?: number,
258
+ listeningListener?: () => void
259
+ ): void;
260
+ listen(
261
+ port?: number,
262
+ hostname?: string,
263
+ listeningListener?: () => void
264
+ ): void;
265
+ listen(
266
+ port?: number,
267
+ backlog?: number,
268
+ listeningListener?: () => void
269
+ ): void;
270
+ listen(port?: number, listeningListener?: () => void): void;
271
+ listen(
272
+ path: string,
273
+ backlog?: number,
274
+ listeningListener?: () => void
275
+ ): void;
276
+ listen(path: string, listeningListener?: () => void): void;
277
+ listen(options: ListenOptions, listeningListener?: () => void): void;
278
+
279
+ /**
280
+ * Stops the server from accepting new connections and keeps existing
281
+ * connections. This function is asynchronous, the server is finally closed
282
+ * when all connections are ended and the server emits a `'close'` event.
283
+ * The optional `callback` will be called once the `'close'` event occurs. Unlike
284
+ * that event, it will be called with an `Error` as its only argument if the server
285
+ * was not open when it was closed.
286
+ * @param callback Called when the server is closed.
287
+ */
288
+ close(callback?: (err?: Error) => void): this;
289
+
290
+ /**
291
+ * Returns the bound `address`, the address `family` name, and `port` of the server
292
+ * as reported by the operating system if listening on an IP socket
293
+ * (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
294
+ *
295
+ * For a server listening on a pipe or Unix domain socket, the name is returned
296
+ * as a string.
297
+ *
298
+ * ```js
299
+ * const server = net.createServer((socket) => {
300
+ * socket.end('goodbye\n');
301
+ * }).on('error', (err) => {
302
+ * // Handle errors here.
303
+ * throw err;
304
+ * });
305
+ *
306
+ * // Grab an arbitrary unused port.
307
+ * server.listen(() => {
308
+ * console.log('opened server on', server.address());
309
+ * });
310
+ * ```
311
+ *
312
+ * `server.address()` returns `null` before the `'listening'` event has been
313
+ * emitted or after calling `server.close()`.
314
+ */
315
+ address(): AddressInfo | string | null;
316
+
317
+ /**
318
+ * events.EventEmitter
319
+ * 1. close
320
+ * 2. connection
321
+ * 3. error
322
+ * 4. listening
323
+ */
324
+ addListener(event: string, listener: (...args: any[]) => void): this;
325
+ addListener(event: "close", listener: () => void): this;
326
+ addListener(event: "connection", listener: (socket: Socket) => void): this;
327
+ addListener(event: "error", listener: (err: Error) => void): this;
328
+ addListener(event: "listening", listener: () => void): this;
329
+ emit(event: string | symbol, ...args: any[]): boolean;
330
+ emit(event: "close"): boolean;
331
+ emit(event: "connection", socket: Socket): boolean;
332
+ emit(event: "error", err: Error): boolean;
333
+ emit(event: "listening"): boolean;
334
+ on(event: string, listener: (...args: any[]) => void): this;
335
+ on(event: "close", listener: () => void): this;
336
+ on(event: "connection", listener: (socket: Socket) => void): this;
337
+ on(event: "error", listener: (err: Error) => void): this;
338
+ on(event: "listening", listener: () => void): this;
339
+ once(event: string, listener: (...args: any[]) => void): this;
340
+ once(event: "close", listener: () => void): this;
341
+ once(event: "connection", listener: (socket: Socket) => void): this;
342
+ once(event: "error", listener: (err: Error) => void): this;
343
+ once(event: "listening", listener: () => void): this;
344
+ prependListener(event: string, listener: (...args: any[]) => void): this;
345
+ prependListener(event: "close", listener: () => void): this;
346
+ prependListener(
347
+ event: "connection",
348
+ listener: (socket: Socket) => void
349
+ ): this;
350
+ prependListener(event: "error", listener: (err: Error) => void): this;
351
+ prependListener(event: "listening", listener: () => void): this;
352
+ prependOnceListener(
353
+ event: string,
354
+ listener: (...args: any[]) => void
355
+ ): this;
356
+ prependOnceListener(event: "close", listener: () => void): this;
357
+ prependOnceListener(
358
+ event: "connection",
359
+ listener: (socket: Socket) => void
360
+ ): this;
361
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
362
+ prependOnceListener(event: "listening", listener: () => void): this;
363
+ }
364
+
365
+ type NetConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
366
+
367
+ /**
368
+ * Creates a new TCP or `IPC` server.
369
+ *
370
+ * If `allowHalfOpen` is set to `true`, when the other end of the socket
371
+ * signals the end of transmission, the server will only send back the end of
372
+ * transmission when `socket.end()` is explicitly called. For example, in the
373
+ * context of TCP, when a FIN packed is received, a FIN packed is sent
374
+ * back only when `socket.end()` is explicitly called. Until then the
375
+ * 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.
376
+ *
377
+ * If `pauseOnConnect` is set to `true`, then the socket associated with each
378
+ * incoming connection will be paused, and no data will be read from its handle.
379
+ * This allows connections to be passed between processes without any data being
380
+ * read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
381
+ *
382
+ * The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
383
+ *
384
+ * Here is an example of a TCP echo server which listens for connections
385
+ * on port 8124:
386
+ *
387
+ * ```js
388
+ * import * as net from 'net';
389
+ * const server = net.createServer((c) => {
390
+ * // 'connection' listener.
391
+ * console.log('client connected');
392
+ * c.on('end', () => {
393
+ * console.log('client disconnected');
394
+ * });
395
+ * c.write('hello\r\n');
396
+ *
397
+ * });
398
+ * server.on('error', (err) => {
399
+ * throw err;
400
+ * });
401
+ * server.listen(8124, () => {
402
+ * console.log('server bound');
403
+ * });
404
+ * ```
405
+ *
406
+ * Test this by using `telnet`:
407
+ *
408
+ * ```bash
409
+ * telnet localhost 8124
410
+ * ```
411
+ *
412
+ * To listen on the socket `/tmp/echo.sock`:
413
+ *
414
+ * ```js
415
+ * server.listen('/tmp/echo.sock', () => {
416
+ * console.log('server bound');
417
+ * });
418
+ * ```
419
+ *
420
+ * Use `nc` to connect to a Unix domain socket server:
421
+ *
422
+ * ```bash
423
+ * nc -U /tmp/echo.sock
424
+ * ```
425
+ * @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
426
+ */
427
+ function createServer(connectionListener?: (socket: Socket) => void): Server;
428
+ function createServer(
429
+ options?: ServerOpts,
430
+ connectionListener?: (socket: Socket) => void
431
+ ): Server;
432
+
433
+ /**
434
+ * Aliases to {@link createConnection}.
435
+ *
436
+ * Possible signatures:
437
+ *
438
+ * * {@link connect}
439
+ * * {@link connect} for `IPC` connections.
440
+ * * {@link connect} for TCP connections.
441
+ */
442
+ function connect(
443
+ options: NetConnectOpts,
444
+ connectionListener?: () => void
445
+ ): Socket;
446
+ function connect(
447
+ port: number,
448
+ host: string,
449
+ connectionListener?: () => void
450
+ ): Socket;
451
+ function connect(port: number, connectionListener?: () => void): Socket;
452
+ function connect(path: string, connectionListener?: () => void): Socket;
453
+
454
+ /**
455
+ * A factory function, which creates a new {@link Socket},
456
+ * immediately initiates connection with `socket.connect()`,
457
+ * then returns the `net.Socket` that starts the connection.
458
+ *
459
+ * When the connection is established, a `'connect'` event will be emitted
460
+ * on the returned socket. The last parameter `connectListener`, if supplied,
461
+ * will be added as a listener for the `'connect'` event **once**.
462
+ *
463
+ * Possible signatures:
464
+ *
465
+ * * {@link createConnection}
466
+ * * {@link createConnection} for `IPC` connections.
467
+ * * {@link createConnection} for TCP connections.
468
+ *
469
+ * The {@link connect} function is an alias to this function.
470
+ */
471
+ function createConnection(
472
+ options: NetConnectOpts,
473
+ connectionListener?: () => void
474
+ ): Socket;
475
+ function createConnection(
476
+ port: number,
477
+ host: string,
478
+ connectionListener?: () => void
479
+ ): Socket;
480
+ function createConnection(
481
+ port: number,
482
+ connectionListener?: () => void
483
+ ): Socket;
484
+ function createConnection(
485
+ path: string,
486
+ connectionListener?: () => void
487
+ ): Socket;
488
+ }