typespeed 2.3.6 → 2.4.2

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