@ykdz/template 0.0.38 → 0.0.41

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 (227) hide show
  1. package/dist/application.d.ts +1 -52
  2. package/dist/application.js +0 -81
  3. package/dist/cli.js +14 -28
  4. package/dist/input-schemas.d.ts +30 -0
  5. package/dist/input-schemas.js +75 -0
  6. package/dist/main.d.ts +3 -14
  7. package/dist/main.js +496 -378
  8. package/dist/result-schemas.d.ts +222 -0
  9. package/dist/result-schemas.js +74 -0
  10. package/dist/standard-schema.d.ts +3 -0
  11. package/dist/standard-schema.js +29 -0
  12. package/node_modules/@standard-schema/spec/LICENSE +21 -0
  13. package/node_modules/@standard-schema/spec/README.md +198 -0
  14. package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
  15. package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
  16. package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
  17. package/node_modules/@standard-schema/spec/dist/index.js +0 -0
  18. package/node_modules/@standard-schema/spec/package.json +52 -0
  19. package/node_modules/@types/node/LICENSE +21 -0
  20. package/node_modules/@types/node/README.md +15 -0
  21. package/node_modules/@types/node/assert/strict.d.ts +111 -0
  22. package/node_modules/@types/node/assert.d.ts +1115 -0
  23. package/node_modules/@types/node/async_hooks.d.ts +619 -0
  24. package/node_modules/@types/node/buffer.buffer.d.ts +477 -0
  25. package/node_modules/@types/node/buffer.d.ts +1941 -0
  26. package/node_modules/@types/node/child_process.d.ts +1480 -0
  27. package/node_modules/@types/node/cluster.d.ts +578 -0
  28. package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  29. package/node_modules/@types/node/console.d.ts +453 -0
  30. package/node_modules/@types/node/constants.d.ts +21 -0
  31. package/node_modules/@types/node/crypto.d.ts +5484 -0
  32. package/node_modules/@types/node/dgram.d.ts +715 -0
  33. package/node_modules/@types/node/diagnostics_channel.d.ts +576 -0
  34. package/node_modules/@types/node/dns/promises.d.ts +503 -0
  35. package/node_modules/@types/node/dns.d.ts +923 -0
  36. package/node_modules/@types/node/domain.d.ts +166 -0
  37. package/node_modules/@types/node/events.d.ts +967 -0
  38. package/node_modules/@types/node/fs/promises.d.ts +1354 -0
  39. package/node_modules/@types/node/fs.d.ts +4777 -0
  40. package/node_modules/@types/node/globals.d.ts +170 -0
  41. package/node_modules/@types/node/globals.typedarray.d.ts +41 -0
  42. package/node_modules/@types/node/http.d.ts +2246 -0
  43. package/node_modules/@types/node/http2.d.ts +2882 -0
  44. package/node_modules/@types/node/https.d.ts +585 -0
  45. package/node_modules/@types/node/index.d.ts +101 -0
  46. package/node_modules/@types/node/inspector.d.ts +323 -0
  47. package/node_modules/@types/node/inspector.generated.d.ts +4406 -0
  48. package/node_modules/@types/node/module.d.ts +844 -0
  49. package/node_modules/@types/node/net.d.ts +1197 -0
  50. package/node_modules/@types/node/os.d.ts +507 -0
  51. package/node_modules/@types/node/package.json +140 -0
  52. package/node_modules/@types/node/path.d.ts +200 -0
  53. package/node_modules/@types/node/perf_hooks.d.ts +1054 -0
  54. package/node_modules/@types/node/process.d.ts +2101 -0
  55. package/node_modules/@types/node/punycode.d.ts +117 -0
  56. package/node_modules/@types/node/querystring.d.ts +152 -0
  57. package/node_modules/@types/node/readline/promises.d.ts +161 -0
  58. package/node_modules/@types/node/readline.d.ts +600 -0
  59. package/node_modules/@types/node/repl.d.ts +438 -0
  60. package/node_modules/@types/node/sea.d.ts +162 -0
  61. package/node_modules/@types/node/sqlite.d.ts +1182 -0
  62. package/node_modules/@types/node/stream/consumers.d.ts +45 -0
  63. package/node_modules/@types/node/stream/promises.d.ts +90 -0
  64. package/node_modules/@types/node/stream/web.d.ts +596 -0
  65. package/node_modules/@types/node/stream.d.ts +1707 -0
  66. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  67. package/node_modules/@types/node/test.d.ts +2656 -0
  68. package/node_modules/@types/node/timers/promises.d.ts +108 -0
  69. package/node_modules/@types/node/timers.d.ts +285 -0
  70. package/node_modules/@types/node/tls.d.ts +1314 -0
  71. package/node_modules/@types/node/trace_events.d.ts +197 -0
  72. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +473 -0
  73. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +71 -0
  74. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +36 -0
  75. package/node_modules/@types/node/ts5.6/index.d.ts +103 -0
  76. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +72 -0
  77. package/node_modules/@types/node/ts5.7/index.d.ts +103 -0
  78. package/node_modules/@types/node/tty.d.ts +209 -0
  79. package/node_modules/@types/node/url.d.ts +1103 -0
  80. package/node_modules/@types/node/util.d.ts +2376 -0
  81. package/node_modules/@types/node/v8.d.ts +1010 -0
  82. package/node_modules/@types/node/vm.d.ts +1160 -0
  83. package/node_modules/@types/node/wasi.d.ts +202 -0
  84. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  85. package/node_modules/@types/node/web-globals/crypto.d.ts +32 -0
  86. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  87. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  88. package/node_modules/@types/node/web-globals/fetch.d.ts +62 -0
  89. package/node_modules/@types/node/web-globals/navigator.d.ts +25 -0
  90. package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  91. package/node_modules/@types/node/web-globals/streams.d.ts +22 -0
  92. package/node_modules/@types/node/worker_threads.d.ts +894 -0
  93. package/node_modules/@types/node/zlib.d.ts +768 -0
  94. package/node_modules/@valibot/to-json-schema/LICENSE.md +9 -0
  95. package/node_modules/@valibot/to-json-schema/README.md +475 -0
  96. package/node_modules/@valibot/to-json-schema/dist/index.cjs +800 -0
  97. package/node_modules/@valibot/to-json-schema/dist/index.d.cts +991 -0
  98. package/node_modules/@valibot/to-json-schema/dist/index.d.mts +991 -0
  99. package/node_modules/@valibot/to-json-schema/dist/index.min.cjs +1 -0
  100. package/node_modules/@valibot/to-json-schema/dist/index.min.mjs +1 -0
  101. package/node_modules/@valibot/to-json-schema/dist/index.mjs +795 -0
  102. package/node_modules/@valibot/to-json-schema/package.json +75 -0
  103. package/node_modules/@ykdz/cli-contract/LICENSE +21 -0
  104. package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.d.ts +17 -0
  105. package/node_modules/@ykdz/cli-contract/dist/atomic-variant-compiler.js +55 -0
  106. package/node_modules/@ykdz/cli-contract/dist/cli-contract.d.ts +1164 -0
  107. package/node_modules/@ykdz/cli-contract/dist/cli-contract.js +1408 -0
  108. package/node_modules/@ykdz/cli-contract/dist/cli-execution.d.ts +54 -0
  109. package/node_modules/@ykdz/cli-contract/dist/cli-execution.js +708 -0
  110. package/node_modules/@ykdz/cli-contract/dist/cli-invocation.d.ts +174 -0
  111. package/node_modules/@ykdz/cli-contract/dist/cli-invocation.js +524 -0
  112. package/node_modules/@ykdz/cli-contract/dist/cli-write-error.d.ts +10 -0
  113. package/node_modules/@ykdz/cli-contract/dist/cli-write-error.js +14 -0
  114. package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.d.ts +260 -0
  115. package/node_modules/@ykdz/cli-contract/dist/contract-definition-error.js +130 -0
  116. package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.d.ts +63 -0
  117. package/node_modules/@ykdz/cli-contract/dist/contract-execution-error.js +17 -0
  118. package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.d.ts +6 -0
  119. package/node_modules/@ykdz/cli-contract/dist/contract-schema-compiler.js +532 -0
  120. package/node_modules/@ykdz/cli-contract/dist/contract-schema.d.ts +14 -0
  121. package/node_modules/@ykdz/cli-contract/dist/contract-schema.js +1 -0
  122. package/node_modules/@ykdz/cli-contract/dist/description.d.ts +2 -0
  123. package/node_modules/@ykdz/cli-contract/dist/description.js +13 -0
  124. package/node_modules/@ykdz/cli-contract/dist/index.d.ts +8 -0
  125. package/node_modules/@ykdz/cli-contract/dist/index.js +7 -0
  126. package/node_modules/@ykdz/cli-contract/dist/json-value.d.ts +4 -0
  127. package/node_modules/@ykdz/cli-contract/dist/json-value.js +64 -0
  128. package/node_modules/@ykdz/cli-contract/dist/node.d.ts +21 -0
  129. package/node_modules/@ykdz/cli-contract/dist/node.js +109 -0
  130. package/node_modules/@ykdz/cli-contract/dist/outcome-fact.d.ts +162 -0
  131. package/node_modules/@ykdz/cli-contract/dist/outcome-fact.js +113 -0
  132. package/node_modules/@ykdz/cli-contract/dist/outcome-wire.d.ts +53 -0
  133. package/node_modules/@ykdz/cli-contract/dist/outcome-wire.js +189 -0
  134. package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.d.ts +16 -0
  135. package/node_modules/@ykdz/cli-contract/dist/stream-variant-compiler.js +45 -0
  136. package/node_modules/@ykdz/cli-contract/package.json +69 -0
  137. package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.d.ts +20 -0
  138. package/node_modules/@ykdz/template-builtin-presets/dist/src/foundation.js +38 -2
  139. package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.d.ts +19 -0
  140. package/node_modules/@ykdz/template-builtin-presets/dist/src/generation-record.js +1 -1
  141. package/node_modules/@ykdz/template-builtin-presets/dist/src/index.d.ts +2 -1
  142. package/node_modules/@ykdz/template-builtin-presets/dist/src/index.js +2 -1
  143. package/node_modules/@ykdz/template-builtin-presets/dist/src/ts-cli/definition.js +9 -5
  144. package/node_modules/@ykdz/template-builtin-presets/package.json +2 -1
  145. package/node_modules/@ykdz/template-builtin-presets/templates/foundation/AGENTS.md.template +5 -3
  146. package/node_modules/@ykdz/template-builtin-presets/templates/{shared/devcontainer/node-pnpm.Dockerfile → foundation/devcontainer/base.Dockerfile} +14 -1
  147. package/node_modules/@ykdz/template-builtin-presets/templates/rust-bin/devcontainer/rust.Dockerfile +1 -5
  148. package/node_modules/@ykdz/template-builtin-presets/templates/shared/devcontainer/github-cli.Dockerfile +1 -3
  149. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/artifact.ts +128 -59
  150. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/handoff.ts +80 -8
  151. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/publication/readiness.ts +7 -3
  152. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/cli.ts +9 -19
  153. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/main.ts +144 -60
  154. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/src/standard-schema.ts +37 -0
  155. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/lookup.journey.ts +71 -0
  156. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/integration/command.test.ts +118 -59
  157. package/node_modules/@ykdz/template-core/dist/dependency-catalog.d.ts +0 -1
  158. package/node_modules/@ykdz/template-core/dist/dependency-catalog.js +0 -19
  159. package/node_modules/@ykdz/template-core/dist/pnpm-workspace.yaml +3 -2
  160. package/node_modules/@ykdz/template-core/dist/project-blueprint.d.ts +15 -0
  161. package/node_modules/@ykdz/template-core/dist/project-blueprint.js +1 -1
  162. package/node_modules/@ykdz/template-core/dist/project-github.d.ts +0 -59
  163. package/node_modules/@ykdz/template-core/dist/project-github.js +0 -67
  164. package/node_modules/undici-types/LICENSE +21 -0
  165. package/node_modules/undici-types/README.md +6 -0
  166. package/node_modules/undici-types/agent.d.ts +32 -0
  167. package/node_modules/undici-types/api.d.ts +43 -0
  168. package/node_modules/undici-types/balanced-pool.d.ts +30 -0
  169. package/node_modules/undici-types/cache-interceptor.d.ts +179 -0
  170. package/node_modules/undici-types/cache.d.ts +36 -0
  171. package/node_modules/undici-types/client-stats.d.ts +15 -0
  172. package/node_modules/undici-types/client.d.ts +123 -0
  173. package/node_modules/undici-types/connector.d.ts +36 -0
  174. package/node_modules/undici-types/content-type.d.ts +21 -0
  175. package/node_modules/undici-types/cookies.d.ts +30 -0
  176. package/node_modules/undici-types/diagnostics-channel.d.ts +74 -0
  177. package/node_modules/undici-types/dispatcher.d.ts +279 -0
  178. package/node_modules/undici-types/env-http-proxy-agent.d.ts +22 -0
  179. package/node_modules/undici-types/errors.d.ts +177 -0
  180. package/node_modules/undici-types/eventsource.d.ts +66 -0
  181. package/node_modules/undici-types/fetch.d.ts +211 -0
  182. package/node_modules/undici-types/formdata.d.ts +108 -0
  183. package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  184. package/node_modules/undici-types/global-origin.d.ts +7 -0
  185. package/node_modules/undici-types/h2c-client.d.ts +73 -0
  186. package/node_modules/undici-types/handlers.d.ts +15 -0
  187. package/node_modules/undici-types/header.d.ts +160 -0
  188. package/node_modules/undici-types/index.d.ts +91 -0
  189. package/node_modules/undici-types/interceptors.d.ts +80 -0
  190. package/node_modules/undici-types/mock-agent.d.ts +68 -0
  191. package/node_modules/undici-types/mock-call-history.d.ts +111 -0
  192. package/node_modules/undici-types/mock-client.d.ts +27 -0
  193. package/node_modules/undici-types/mock-errors.d.ts +12 -0
  194. package/node_modules/undici-types/mock-interceptor.d.ts +94 -0
  195. package/node_modules/undici-types/mock-pool.d.ts +27 -0
  196. package/node_modules/undici-types/package.json +55 -0
  197. package/node_modules/undici-types/patch.d.ts +29 -0
  198. package/node_modules/undici-types/pool-stats.d.ts +19 -0
  199. package/node_modules/undici-types/pool.d.ts +41 -0
  200. package/node_modules/undici-types/proxy-agent.d.ts +29 -0
  201. package/node_modules/undici-types/readable.d.ts +68 -0
  202. package/node_modules/undici-types/retry-agent.d.ts +8 -0
  203. package/node_modules/undici-types/retry-handler.d.ts +125 -0
  204. package/node_modules/undici-types/round-robin-pool.d.ts +41 -0
  205. package/node_modules/undici-types/snapshot-agent.d.ts +109 -0
  206. package/node_modules/undici-types/socks5-proxy-agent.d.ts +25 -0
  207. package/node_modules/undici-types/util.d.ts +18 -0
  208. package/node_modules/undici-types/utility.d.ts +7 -0
  209. package/node_modules/undici-types/webidl.d.ts +347 -0
  210. package/node_modules/undici-types/websocket.d.ts +188 -0
  211. package/package.json +5 -3
  212. package/dist/command-result.d.ts +0 -9
  213. package/dist/command-result.js +0 -231
  214. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/e2e/journeys/greet.journey.ts +0 -46
  215. package/node_modules/@ykdz/template-builtin-presets/templates/ts-cli/test/unit/greet.test.ts +0 -15
  216. package/node_modules/commander/LICENSE +0 -22
  217. package/node_modules/commander/Readme.md +0 -1172
  218. package/node_modules/commander/index.js +0 -21
  219. package/node_modules/commander/lib/argument.js +0 -147
  220. package/node_modules/commander/lib/command.js +0 -2790
  221. package/node_modules/commander/lib/error.js +0 -36
  222. package/node_modules/commander/lib/help.js +0 -731
  223. package/node_modules/commander/lib/option.js +0 -377
  224. package/node_modules/commander/lib/suggestSimilar.js +0 -99
  225. package/node_modules/commander/package-support.json +0 -19
  226. package/node_modules/commander/package.json +0 -64
  227. package/node_modules/commander/typings/index.d.ts +0 -1113
@@ -0,0 +1,1197 @@
1
+ /**
2
+ * > Stability: 2 - Stable
3
+ *
4
+ * The `node: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
+ * import net from 'node:net';
12
+ * ```
13
+ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/net.js)
14
+ */
15
+ declare module "net" {
16
+ import { NonSharedBuffer } from "node:buffer";
17
+ import * as stream from "node:stream";
18
+ import { Abortable, EventEmitter } from "node:events";
19
+ import * as dns from "node:dns";
20
+ type LookupFunction = (
21
+ hostname: string,
22
+ options: dns.LookupOptions,
23
+ callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
24
+ ) => void;
25
+ interface AddressInfo {
26
+ address: string;
27
+ family: string;
28
+ port: number;
29
+ }
30
+ interface SocketConstructorOpts {
31
+ fd?: number | undefined;
32
+ allowHalfOpen?: boolean | undefined;
33
+ onread?: OnReadOpts | undefined;
34
+ readable?: boolean | undefined;
35
+ writable?: boolean | undefined;
36
+ signal?: AbortSignal | undefined;
37
+ noDelay?: boolean | undefined;
38
+ keepAlive?: boolean | undefined;
39
+ keepAliveInitialDelay?: number | undefined;
40
+ blockList?: BlockList | undefined;
41
+ typeOfService?: number | undefined;
42
+ handle?: BoundSocket | undefined;
43
+ }
44
+ interface OnReadOpts {
45
+ buffer: Uint8Array | (() => Uint8Array);
46
+ /**
47
+ * This function is called for every chunk of incoming data.
48
+ * Two arguments are passed to it: the number of bytes written to `buffer` and a reference to `buffer`.
49
+ * Return `false` from this function to implicitly `pause()` the socket.
50
+ */
51
+ callback(bytesWritten: number, buffer: Uint8Array): boolean;
52
+ }
53
+ interface TcpSocketConnectOpts {
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
+ /**
62
+ * @since v18.13.0
63
+ */
64
+ autoSelectFamily?: boolean | undefined;
65
+ /**
66
+ * @since v18.13.0
67
+ */
68
+ autoSelectFamilyAttemptTimeout?: number | undefined;
69
+ }
70
+ interface IpcSocketConnectOpts {
71
+ path: string;
72
+ }
73
+ type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
74
+ type SocketReadyState = "opening" | "open" | "readOnly" | "writeOnly" | "closed";
75
+ interface SetKeepAliveOptions {
76
+ enable?: boolean | undefined;
77
+ initialDelay?: number | undefined;
78
+ interval?: number | undefined;
79
+ count?: number | undefined;
80
+ }
81
+ /**
82
+ * This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
83
+ * (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
84
+ * an `EventEmitter`.
85
+ *
86
+ * A `net.Socket` can be created by the user and used directly to interact with
87
+ * a server. For example, it is returned by {@link createConnection},
88
+ * so the user can use it to talk to the server.
89
+ *
90
+ * It can also be created by Node.js and passed to the user when a connection
91
+ * is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
92
+ * it to interact with the client.
93
+ * @since v0.3.4
94
+ */
95
+ class Socket extends stream.Duplex {
96
+ constructor(options?: SocketConstructorOpts);
97
+ /**
98
+ * Destroys the socket after all data is written. If the `finish` event was already emitted the socket is destroyed immediately.
99
+ * If the socket is still writable it implicitly calls `socket.end()`.
100
+ * @since v0.3.4
101
+ */
102
+ destroySoon(): void;
103
+ /**
104
+ * Sends data on the socket. The second parameter specifies the encoding in the
105
+ * case of a string. It defaults to UTF8 encoding.
106
+ *
107
+ * Returns `true` if the entire data was flushed successfully to the kernel
108
+ * 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.
109
+ *
110
+ * The optional `callback` parameter will be executed when the data is finally
111
+ * written out, which may not be immediately.
112
+ *
113
+ * See `Writable` stream `write()` method for more
114
+ * information.
115
+ * @since v0.1.90
116
+ */
117
+ write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
118
+ /**
119
+ * Sends data on the socket, with an explicit encoding for string data.
120
+ * @see {@link Socket.write} for full details.
121
+ * @since v0.1.90
122
+ * @param [encoding='utf8'] Only used when data is `string`.
123
+ */
124
+ write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
125
+ /**
126
+ * Initiate a connection on a given socket.
127
+ *
128
+ * Possible signatures:
129
+ *
130
+ * * `socket.connect(options[, connectListener])`
131
+ * * `socket.connect(path[, connectListener])` for `IPC` connections.
132
+ * * `socket.connect(port[, host][, connectListener])` for TCP connections.
133
+ * * Returns: `net.Socket` The socket itself.
134
+ *
135
+ * This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
136
+ * instead of a `'connect'` event, an `'error'` event will be emitted with
137
+ * the error passed to the `'error'` listener.
138
+ * The last parameter `connectListener`, if supplied, will be added as a listener
139
+ * for the `'connect'` event **once**.
140
+ *
141
+ * This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
142
+ * behavior.
143
+ */
144
+ connect(options: SocketConnectOpts, connectionListener?: () => void): this;
145
+ connect(port: number, host: string, connectionListener?: () => void): this;
146
+ connect(port: number, connectionListener?: () => void): this;
147
+ connect(path: string, connectionListener?: () => void): this;
148
+ /**
149
+ * Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
150
+ * @since v0.1.90
151
+ * @return The socket itself.
152
+ */
153
+ setEncoding(encoding?: BufferEncoding): this;
154
+ /**
155
+ * Pauses the reading of data. That is, `'data'` events will not be emitted.
156
+ * Useful to throttle back an upload.
157
+ * @return The socket itself.
158
+ */
159
+ pause(): this;
160
+ /**
161
+ * Close the TCP connection by sending an RST packet and destroy the stream.
162
+ * If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.
163
+ * Otherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error.
164
+ * If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.
165
+ * @since v18.3.0, v16.17.0
166
+ */
167
+ resetAndDestroy(): this;
168
+ /**
169
+ * Resumes reading after a call to `socket.pause()`.
170
+ * @return The socket itself.
171
+ */
172
+ resume(): this;
173
+ /**
174
+ * Sets the socket to timeout after `timeout` milliseconds of inactivity on
175
+ * the socket. By default `net.Socket` do not have a timeout.
176
+ *
177
+ * 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
178
+ * end the connection.
179
+ *
180
+ * ```js
181
+ * socket.setTimeout(3000);
182
+ * socket.on('timeout', () => {
183
+ * console.log('socket timeout');
184
+ * socket.end();
185
+ * });
186
+ * ```
187
+ *
188
+ * If `timeout` is 0, then the existing idle timeout is disabled.
189
+ *
190
+ * The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
191
+ * @since v0.1.90
192
+ * @return The socket itself.
193
+ */
194
+ setTimeout(timeout: number, callback?: () => void): this;
195
+ /**
196
+ * Enable/disable the use of Nagle's algorithm.
197
+ *
198
+ * When a TCP connection is created, it will have Nagle's algorithm enabled.
199
+ *
200
+ * Nagle's algorithm delays data before it is sent via the network. It attempts
201
+ * to optimize throughput at the expense of latency.
202
+ *
203
+ * Passing `true` for `noDelay` or not passing an argument will disable Nagle's
204
+ * algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
205
+ * algorithm.
206
+ * @since v0.1.90
207
+ * @param [noDelay=true]
208
+ * @return The socket itself.
209
+ */
210
+ setNoDelay(noDelay?: boolean): this;
211
+ /**
212
+ * Configure keep-alive using an options object. See `socket.setKeepAlive()`
213
+ * for a description of each property.
214
+ *
215
+ * ```js
216
+ * socket.setKeepAlive({ enable: true, initialDelay: 1000, interval: 1000, count: 10 });
217
+ * ```
218
+ * @since v24.19.0
219
+ * @returns The socket itself.
220
+ */
221
+ setKeepAlive(options: SetKeepAliveOptions): this;
222
+ /**
223
+ * Configure keep-alive using positional arguments. See
224
+ * `socket.setKeepAlive()` for a description of each argument.
225
+ * @since v0.1.92
226
+ * @param enable **Default:** `false`
227
+ * @param initialDelay **Default:** `0`
228
+ * @param interval **Default:** `1000`
229
+ * @param count **Default:** `10`
230
+ * @returns The socket itself.
231
+ */
232
+ setKeepAlive(enable?: boolean, initialDelay?: number, interval?: number, count?: number): this;
233
+ /**
234
+ * Returns the current Type of Service (TOS) field for IPv4 packets or Traffic
235
+ * Class for IPv6 packets for this socket.
236
+ *
237
+ * `setTypeOfService()` may be called before the socket is connected; the value
238
+ * will be cached and applied when the socket establishes a connection.
239
+ * `getTypeOfService()` will return the currently set value even before connection.
240
+ *
241
+ * On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
242
+ * and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
243
+ * should verify platform-specific semantics.
244
+ * @since v24.15.0
245
+ * @returns The current TOS value.
246
+ */
247
+ getTypeOfService(): number;
248
+ /**
249
+ * Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6
250
+ * Packets sent from this socket. This can be used to prioritize network traffic.
251
+ *
252
+ * `setTypeOfService()` may be called before the socket is connected; the value
253
+ * will be cached and applied when the socket establishes a connection.
254
+ * `getTypeOfService()` will return the currently set value even before connection.
255
+ *
256
+ * On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
257
+ * and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
258
+ * should verify platform-specific semantics.
259
+ * @since v24.15.0
260
+ * @param tos The TOS value to set (0-255).
261
+ * @returns The socket itself.
262
+ */
263
+ setTypeOfService(tos: number): this;
264
+ /**
265
+ * Returns the bound `address`, the address `family` name and `port` of the
266
+ * socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
267
+ * @since v0.1.90
268
+ */
269
+ address(): AddressInfo | {};
270
+ /**
271
+ * Calling `unref()` on a socket will allow the program to exit if this is the only
272
+ * active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
273
+ * @since v0.9.1
274
+ * @return The socket itself.
275
+ */
276
+ unref(): this;
277
+ /**
278
+ * 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).
279
+ * If the socket is `ref`ed calling `ref` again will have no effect.
280
+ * @since v0.9.1
281
+ * @return The socket itself.
282
+ */
283
+ ref(): this;
284
+ /**
285
+ * This property is only present if the family autoselection algorithm is enabled in `socket.connect(options)`
286
+ * and it is an array of the addresses that have been attempted.
287
+ *
288
+ * Each address is a string in the form of `$IP:$PORT`.
289
+ * If the connection was successful, then the last address is the one that the socket is currently connected to.
290
+ * @since v19.4.0
291
+ */
292
+ readonly autoSelectFamilyAttemptedAddresses: string[];
293
+ /**
294
+ * This property shows the number of characters buffered for writing. The buffer
295
+ * may contain strings whose length after encoding is not yet known. So this number
296
+ * is only an approximation of the number of bytes in the buffer.
297
+ *
298
+ * `net.Socket` has the property that `socket.write()` always works. This is to
299
+ * help users get up and running quickly. The computer cannot always keep up
300
+ * with the amount of data that is written to a socket. The network connection
301
+ * simply might be too slow. Node.js will internally queue up the data written to a
302
+ * socket and send it out over the wire when it is possible.
303
+ *
304
+ * The consequence of this internal buffering is that memory may grow.
305
+ * Users who experience large or growing `bufferSize` should attempt to
306
+ * "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
307
+ * @since v0.3.8
308
+ * @deprecated Since v14.6.0 - Use `writableLength` instead.
309
+ */
310
+ readonly bufferSize: number;
311
+ /**
312
+ * The amount of received bytes.
313
+ * @since v0.5.3
314
+ */
315
+ readonly bytesRead: number;
316
+ /**
317
+ * The amount of bytes sent.
318
+ * @since v0.5.3
319
+ */
320
+ readonly bytesWritten: number;
321
+ /**
322
+ * If `true`, `socket.connect(options[, connectListener])` was
323
+ * called and has not yet finished. It will stay `true` until the socket becomes
324
+ * connected, then it is set to `false` and the `'connect'` event is emitted. Note
325
+ * that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
326
+ * @since v6.1.0
327
+ */
328
+ readonly connecting: boolean;
329
+ /**
330
+ * 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
331
+ * (see `socket.connecting`).
332
+ * @since v11.2.0, v10.16.0
333
+ */
334
+ readonly pending: boolean;
335
+ /**
336
+ * See `writable.destroyed` for further details.
337
+ */
338
+ readonly destroyed: boolean;
339
+ /**
340
+ * The string representation of the local IP address the remote client is
341
+ * connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
342
+ * connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
343
+ * @since v0.9.6
344
+ */
345
+ readonly localAddress?: string;
346
+ /**
347
+ * The numeric representation of the local port. For example, `80` or `21`.
348
+ * @since v0.9.6
349
+ */
350
+ readonly localPort?: number;
351
+ /**
352
+ * The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
353
+ * @since v18.8.0, v16.18.0
354
+ */
355
+ readonly localFamily?: string;
356
+ /**
357
+ * This property represents the state of the connection as a string.
358
+ *
359
+ * * If the stream is connecting `socket.readyState` is `opening`.
360
+ * * If the stream is readable and writable, it is `open`.
361
+ * * If the stream is readable and not writable, it is `readOnly`.
362
+ * * If the stream is not readable and writable, it is `writeOnly`.
363
+ * @since v0.5.0
364
+ */
365
+ readonly readyState: SocketReadyState;
366
+ /**
367
+ * The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
368
+ * the socket is destroyed (for example, if the client disconnected).
369
+ * @since v0.5.10
370
+ */
371
+ readonly remoteAddress: string | undefined;
372
+ /**
373
+ * The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if
374
+ * the socket is destroyed (for example, if the client disconnected).
375
+ * @since v0.11.14
376
+ */
377
+ readonly remoteFamily: string | undefined;
378
+ /**
379
+ * The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if
380
+ * the socket is destroyed (for example, if the client disconnected).
381
+ * @since v0.5.10
382
+ */
383
+ readonly remotePort: number | undefined;
384
+ /**
385
+ * The socket timeout in milliseconds as set by `socket.setTimeout()`.
386
+ * It is `undefined` if a timeout has not been set.
387
+ * @since v10.7.0
388
+ */
389
+ readonly timeout?: number;
390
+ /**
391
+ * Half-closes the socket. i.e., it sends a FIN packet. It is possible the
392
+ * server will still send some data.
393
+ *
394
+ * See `writable.end()` for further details.
395
+ * @since v0.1.90
396
+ * @param callback Optional callback for when the socket is finished.
397
+ * @return The socket itself.
398
+ */
399
+ end(callback?: () => void): this;
400
+ /**
401
+ * Half-closes the socket, with one final chunk of data.
402
+ * @see {@link Socket.end} for full details.
403
+ * @since v0.1.90
404
+ * @param callback Optional callback for when the socket is finished.
405
+ * @return The socket itself.
406
+ */
407
+ end(buffer: Uint8Array | string, callback?: () => void): this;
408
+ /**
409
+ * Half-closes the socket, with one final chunk of data.
410
+ * @see {@link Socket.end} for full details.
411
+ * @since v0.1.90
412
+ * @param [encoding='utf8'] Only used when data is `string`.
413
+ * @param callback Optional callback for when the socket is finished.
414
+ * @return The socket itself.
415
+ */
416
+ end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
417
+ /**
418
+ * events.EventEmitter
419
+ * 1. close
420
+ * 2. connect
421
+ * 3. connectionAttempt
422
+ * 4. connectionAttemptFailed
423
+ * 5. connectionAttemptTimeout
424
+ * 6. data
425
+ * 7. drain
426
+ * 8. end
427
+ * 9. error
428
+ * 10. lookup
429
+ * 11. ready
430
+ * 12. timeout
431
+ */
432
+ addListener(event: string, listener: (...args: any[]) => void): this;
433
+ addListener(event: "close", listener: (hadError: boolean) => void): this;
434
+ addListener(event: "connect", listener: () => void): this;
435
+ addListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
436
+ addListener(
437
+ event: "connectionAttemptFailed",
438
+ listener: (ip: string, port: number, family: number, error: Error) => void,
439
+ ): this;
440
+ addListener(
441
+ event: "connectionAttemptTimeout",
442
+ listener: (ip: string, port: number, family: number) => void,
443
+ ): this;
444
+ addListener(event: "data", listener: (data: NonSharedBuffer) => void): this;
445
+ addListener(event: "drain", listener: () => void): this;
446
+ addListener(event: "end", listener: () => void): this;
447
+ addListener(event: "error", listener: (err: Error) => void): this;
448
+ addListener(
449
+ event: "lookup",
450
+ listener: (err: Error, address: string, family: string | number, host: string) => void,
451
+ ): this;
452
+ addListener(event: "ready", listener: () => void): this;
453
+ addListener(event: "timeout", listener: () => void): this;
454
+ emit(event: string | symbol, ...args: any[]): boolean;
455
+ emit(event: "close", hadError: boolean): boolean;
456
+ emit(event: "connect"): boolean;
457
+ emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean;
458
+ emit(event: "connectionAttemptFailed", ip: string, port: number, family: number, error: Error): boolean;
459
+ emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean;
460
+ emit(event: "data", data: NonSharedBuffer): boolean;
461
+ emit(event: "drain"): boolean;
462
+ emit(event: "end"): boolean;
463
+ emit(event: "error", err: Error): boolean;
464
+ emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;
465
+ emit(event: "ready"): boolean;
466
+ emit(event: "timeout"): boolean;
467
+ on(event: string, listener: (...args: any[]) => void): this;
468
+ on(event: "close", listener: (hadError: boolean) => void): this;
469
+ on(event: "connect", listener: () => void): this;
470
+ on(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
471
+ on(
472
+ event: "connectionAttemptFailed",
473
+ listener: (ip: string, port: number, family: number, error: Error) => void,
474
+ ): this;
475
+ on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;
476
+ on(event: "data", listener: (data: NonSharedBuffer) => void): this;
477
+ on(event: "drain", listener: () => void): this;
478
+ on(event: "end", listener: () => void): this;
479
+ on(event: "error", listener: (err: Error) => void): this;
480
+ on(
481
+ event: "lookup",
482
+ listener: (err: Error, address: string, family: string | number, host: string) => void,
483
+ ): this;
484
+ on(event: "ready", listener: () => void): this;
485
+ on(event: "timeout", listener: () => void): this;
486
+ once(event: string, listener: (...args: any[]) => void): this;
487
+ once(event: "close", listener: (hadError: boolean) => void): this;
488
+ once(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
489
+ once(
490
+ event: "connectionAttemptFailed",
491
+ listener: (ip: string, port: number, family: number, error: Error) => void,
492
+ ): this;
493
+ once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;
494
+ once(event: "connect", listener: () => void): this;
495
+ once(event: "data", listener: (data: NonSharedBuffer) => void): this;
496
+ once(event: "drain", listener: () => void): this;
497
+ once(event: "end", listener: () => void): this;
498
+ once(event: "error", listener: (err: Error) => void): this;
499
+ once(
500
+ event: "lookup",
501
+ listener: (err: Error, address: string, family: string | number, host: string) => void,
502
+ ): this;
503
+ once(event: "ready", listener: () => void): this;
504
+ once(event: "timeout", listener: () => void): this;
505
+ prependListener(event: string, listener: (...args: any[]) => void): this;
506
+ prependListener(event: "close", listener: (hadError: boolean) => void): this;
507
+ prependListener(event: "connect", listener: () => void): this;
508
+ prependListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
509
+ prependListener(
510
+ event: "connectionAttemptFailed",
511
+ listener: (ip: string, port: number, family: number, error: Error) => void,
512
+ ): this;
513
+ prependListener(
514
+ event: "connectionAttemptTimeout",
515
+ listener: (ip: string, port: number, family: number) => void,
516
+ ): this;
517
+ prependListener(event: "data", listener: (data: NonSharedBuffer) => void): this;
518
+ prependListener(event: "drain", listener: () => void): this;
519
+ prependListener(event: "end", listener: () => void): this;
520
+ prependListener(event: "error", listener: (err: Error) => void): this;
521
+ prependListener(
522
+ event: "lookup",
523
+ listener: (err: Error, address: string, family: string | number, host: string) => void,
524
+ ): this;
525
+ prependListener(event: "ready", listener: () => void): this;
526
+ prependListener(event: "timeout", listener: () => void): this;
527
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
528
+ prependOnceListener(event: "close", listener: (hadError: boolean) => void): this;
529
+ prependOnceListener(event: "connect", listener: () => void): this;
530
+ prependOnceListener(
531
+ event: "connectionAttempt",
532
+ listener: (ip: string, port: number, family: number) => void,
533
+ ): this;
534
+ prependOnceListener(
535
+ event: "connectionAttemptFailed",
536
+ listener: (ip: string, port: number, family: number, error: Error) => void,
537
+ ): this;
538
+ prependOnceListener(
539
+ event: "connectionAttemptTimeout",
540
+ listener: (ip: string, port: number, family: number) => void,
541
+ ): this;
542
+ prependOnceListener(event: "data", listener: (data: NonSharedBuffer) => void): this;
543
+ prependOnceListener(event: "drain", listener: () => void): this;
544
+ prependOnceListener(event: "end", listener: () => void): this;
545
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
546
+ prependOnceListener(
547
+ event: "lookup",
548
+ listener: (err: Error, address: string, family: string | number, host: string) => void,
549
+ ): this;
550
+ prependOnceListener(event: "ready", listener: () => void): this;
551
+ prependOnceListener(event: "timeout", listener: () => void): this;
552
+ }
553
+ interface BoundSocketOptions {
554
+ /**
555
+ * Local address to bind. Must be a numeric IP literal; no DNS
556
+ * resolution is performed. **Default:** `'0.0.0.0'`, or `'::'` when
557
+ * `ipv6Only` is `true`.
558
+ */
559
+ host?: string | undefined;
560
+ /**
561
+ * Local port. `0` requests an OS-assigned ephemeral port.
562
+ * **Default:** `0`.
563
+ */
564
+ port?: number | undefined;
565
+ /**
566
+ * Sets `IPV6_V6ONLY`, disabling dual-stack support so the
567
+ * socket binds IPv6 only. Only meaningful for IPv6 binds. **Default:**
568
+ * `false`.
569
+ */
570
+ ipv6Only?: boolean | undefined;
571
+ /**
572
+ * Sets `SO_REUSEPORT`, allowing multiple sockets to bind
573
+ * the same address and port for kernel-level load balancing. Support is
574
+ * platform-dependent. **Default:** `false`.
575
+ */
576
+ reusePort?: boolean | undefined;
577
+ }
578
+ /**
579
+ * Allows for the synchronous creation of a pre-bound socket, that can be passed
580
+ * to `listen()` or `new net.Socket()` later on. For `listen()` this enables
581
+ * synchronous port reservation, while for `new net.Socket()`, it allows control
582
+ * over the local egress port/IP, via `bind(2)` semantics.
583
+ *
584
+ * Adoption transfers ownership of the socket; afterwards `address()` and `close()`
585
+ * throw `ERR_SOCKET_HANDLE_ADOPTED`. A handle that is never adopted must be
586
+ * closed to avoid leaking the socket.
587
+ *
588
+ * ```js
589
+ * import net from 'node:net';
590
+ *
591
+ * const bound = new net.BoundSocket();
592
+ * const { port } = bound.address();
593
+ * console.log(`Reserved port ${port} for server`);
594
+ *
595
+ * const server = net.createServer();
596
+ * server.listen(bound); // Adopt as a server, or pass to new net.Socket() instead.
597
+ * ```
598
+ * @since v24.19.0
599
+ */
600
+ class BoundSocket {
601
+ /**
602
+ * @since v26.4.0
603
+ */
604
+ constructor(options?: BoundSocketOptions);
605
+ /**
606
+ * Returns the bound local address. When bound with `port: 0`, `port` is the
607
+ * OS-assigned ephemeral port.
608
+ * @since v24.19.0
609
+ * @returns An object with `address`, `family`, and `port` properties,
610
+ * as `server.address()` returns.
611
+ */
612
+ address(): AddressInfo;
613
+ /**
614
+ * Returns the file descriptor of the bound socket. Ownership remains with the
615
+ * `BoundSocket`, so the descriptor must not be closed by the caller. The
616
+ * descriptor is only available before the handle is adopted; afterwards it belongs
617
+ * to the adopting `net.Server` or `net.Socket` and `fd()` throws
618
+ * `ERR_SOCKET_HANDLE_ADOPTED`.
619
+ * @since v24.19.0
620
+ * @returns The underlying OS file descriptor, or `-1` on platforms
621
+ * that do not expose one for sockets (such as Windows).
622
+ */
623
+ fd(): number;
624
+ /**
625
+ * Releases the bound socket. Only needed when the handle is never adopted.
626
+ * @since v24.19.0
627
+ */
628
+ close(): void;
629
+ /**
630
+ * Closes the handle if it has not been adopted or closed; otherwise a no-op.
631
+ * @since v24.19.0
632
+ */
633
+ [Symbol.dispose](): void;
634
+ }
635
+ interface ListenOptions extends Abortable {
636
+ backlog?: number | undefined;
637
+ exclusive?: boolean | undefined;
638
+ handle?: BoundSocket | undefined;
639
+ host?: string | undefined;
640
+ /**
641
+ * @default false
642
+ */
643
+ ipv6Only?: boolean | undefined;
644
+ reusePort?: boolean | undefined;
645
+ path?: string | undefined;
646
+ port?: number | undefined;
647
+ readableAll?: boolean | undefined;
648
+ writableAll?: boolean | undefined;
649
+ }
650
+ interface ServerOpts {
651
+ /**
652
+ * Indicates whether half-opened TCP connections are allowed.
653
+ * @default false
654
+ */
655
+ allowHalfOpen?: boolean | undefined;
656
+ /**
657
+ * Indicates whether the socket should be paused on incoming connections.
658
+ * @default false
659
+ */
660
+ pauseOnConnect?: boolean | undefined;
661
+ /**
662
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
663
+ * @default false
664
+ * @since v16.5.0
665
+ */
666
+ noDelay?: boolean | undefined;
667
+ /**
668
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
669
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
670
+ * @default false
671
+ * @since v16.5.0
672
+ */
673
+ keepAlive?: boolean | undefined;
674
+ /**
675
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
676
+ * @default 0
677
+ * @since v16.5.0
678
+ */
679
+ keepAliveInitialDelay?: number | undefined;
680
+ /**
681
+ * Optionally overrides all `net.Socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
682
+ * @default See [stream.getDefaultHighWaterMark()](https://nodejs.org/docs/latest-v24.x/api/stream.html#streamgetdefaulthighwatermarkobjectmode).
683
+ * @since v18.17.0, v20.1.0
684
+ */
685
+ highWaterMark?: number | undefined;
686
+ /**
687
+ * `blockList` can be used for disabling inbound
688
+ * access to specific IP addresses, IP ranges, or IP subnets. This does not
689
+ * work if the server is behind a reverse proxy, NAT, etc. because the address
690
+ * checked against the block list is the address of the proxy, or the one
691
+ * specified by the NAT.
692
+ * @since v22.13.0
693
+ */
694
+ blockList?: BlockList | undefined;
695
+ }
696
+ interface DropArgument {
697
+ localAddress?: string;
698
+ localPort?: number;
699
+ localFamily?: string;
700
+ remoteAddress?: string;
701
+ remotePort?: number;
702
+ remoteFamily?: string;
703
+ }
704
+ /**
705
+ * This class is used to create a TCP or `IPC` server.
706
+ * @since v0.1.90
707
+ */
708
+ class Server extends EventEmitter {
709
+ constructor(connectionListener?: (socket: Socket) => void);
710
+ constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
711
+ /**
712
+ * Start a server listening for connections. A `net.Server` can be a TCP or
713
+ * an `IPC` server depending on what it listens to.
714
+ *
715
+ * Possible signatures:
716
+ *
717
+ * * `server.listen(handle[, backlog][, callback])`
718
+ * * `server.listen(options[, callback])`
719
+ * * `server.listen(path[, backlog][, callback])` for `IPC` servers
720
+ * * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
721
+ *
722
+ * 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'`
723
+ * event.
724
+ *
725
+ * All `listen()` methods can take a `backlog` parameter to specify the maximum
726
+ * length of the queue of pending connections. The actual length will be determined
727
+ * 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).
728
+ *
729
+ * All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
730
+ * details).
731
+ *
732
+ * The `server.listen()` method can be called again if and only if there was an
733
+ * error during the first `server.listen()` call or `server.close()` has been
734
+ * called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
735
+ *
736
+ * One of the most common errors raised when listening is `EADDRINUSE`.
737
+ * This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
738
+ * after a certain amount of time:
739
+ *
740
+ * ```js
741
+ * server.on('error', (e) => {
742
+ * if (e.code === 'EADDRINUSE') {
743
+ * console.error('Address in use, retrying...');
744
+ * setTimeout(() => {
745
+ * server.close();
746
+ * server.listen(PORT, HOST);
747
+ * }, 1000);
748
+ * }
749
+ * });
750
+ * ```
751
+ */
752
+ listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
753
+ listen(port?: number, hostname?: string, listeningListener?: () => void): this;
754
+ listen(port?: number, backlog?: number, listeningListener?: () => void): this;
755
+ listen(port?: number, listeningListener?: () => void): this;
756
+ listen(path: string, backlog?: number, listeningListener?: () => void): this;
757
+ listen(path: string, listeningListener?: () => void): this;
758
+ listen(options: ListenOptions, listeningListener?: () => void): this;
759
+ listen(handle: any, backlog?: number, listeningListener?: () => void): this;
760
+ listen(handle: any, listeningListener?: () => void): this;
761
+ /**
762
+ * Stops the server from accepting new connections and keeps existing
763
+ * connections. This function is asynchronous, the server is finally closed
764
+ * when all connections are ended and the server emits a `'close'` event.
765
+ * The optional `callback` will be called once the `'close'` event occurs. Unlike
766
+ * that event, it will be called with an `Error` as its only argument if the server
767
+ * was not open when it was closed.
768
+ * @since v0.1.90
769
+ * @param callback Called when the server is closed.
770
+ */
771
+ close(callback?: (err?: Error) => void): this;
772
+ /**
773
+ * Returns the bound `address`, the address `family` name, and `port` of the server
774
+ * as reported by the operating system if listening on an IP socket
775
+ * (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
776
+ *
777
+ * For a server listening on a pipe or Unix domain socket, the name is returned
778
+ * as a string.
779
+ *
780
+ * ```js
781
+ * const server = net.createServer((socket) => {
782
+ * socket.end('goodbye\n');
783
+ * }).on('error', (err) => {
784
+ * // Handle errors here.
785
+ * throw err;
786
+ * });
787
+ *
788
+ * // Grab an arbitrary unused port.
789
+ * server.listen(() => {
790
+ * console.log('opened server on', server.address());
791
+ * });
792
+ * ```
793
+ *
794
+ * `server.address()` returns `null` before the `'listening'` event has been
795
+ * emitted or after calling `server.close()`.
796
+ * @since v0.1.90
797
+ */
798
+ address(): AddressInfo | string | null;
799
+ /**
800
+ * Asynchronously get the number of concurrent connections on the server. Works
801
+ * when sockets were sent to forks.
802
+ *
803
+ * Callback should take two arguments `err` and `count`.
804
+ * @since v0.9.7
805
+ */
806
+ getConnections(cb: (error: Error | null, count: number) => void): this;
807
+ /**
808
+ * 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).
809
+ * If the server is `ref`ed calling `ref()` again will have no effect.
810
+ * @since v0.9.1
811
+ */
812
+ ref(): this;
813
+ /**
814
+ * Calling `unref()` on a server will allow the program to exit if this is the only
815
+ * active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
816
+ * @since v0.9.1
817
+ */
818
+ unref(): this;
819
+ /**
820
+ * Set this property to reject connections when the server's connection count gets
821
+ * high.
822
+ *
823
+ * It is not recommended to use this option once a socket has been sent to a child
824
+ * with `child_process.fork()`.
825
+ * @since v0.2.0
826
+ */
827
+ maxConnections: number;
828
+ connections: number;
829
+ /**
830
+ * Indicates whether or not the server is listening for connections.
831
+ * @since v5.7.0
832
+ */
833
+ readonly listening: boolean;
834
+ /**
835
+ * events.EventEmitter
836
+ * 1. close
837
+ * 2. connection
838
+ * 3. error
839
+ * 4. listening
840
+ * 5. drop
841
+ */
842
+ addListener(event: string, listener: (...args: any[]) => void): this;
843
+ addListener(event: "close", listener: () => void): this;
844
+ addListener(event: "connection", listener: (socket: Socket) => void): this;
845
+ addListener(event: "error", listener: (err: Error) => void): this;
846
+ addListener(event: "listening", listener: () => void): this;
847
+ addListener(event: "drop", listener: (data?: DropArgument) => void): this;
848
+ emit(event: string | symbol, ...args: any[]): boolean;
849
+ emit(event: "close"): boolean;
850
+ emit(event: "connection", socket: Socket): boolean;
851
+ emit(event: "error", err: Error): boolean;
852
+ emit(event: "listening"): boolean;
853
+ emit(event: "drop", data?: DropArgument): boolean;
854
+ on(event: string, listener: (...args: any[]) => void): this;
855
+ on(event: "close", listener: () => void): this;
856
+ on(event: "connection", listener: (socket: Socket) => void): this;
857
+ on(event: "error", listener: (err: Error) => void): this;
858
+ on(event: "listening", listener: () => void): this;
859
+ on(event: "drop", listener: (data?: DropArgument) => void): this;
860
+ once(event: string, listener: (...args: any[]) => void): this;
861
+ once(event: "close", listener: () => void): this;
862
+ once(event: "connection", listener: (socket: Socket) => void): this;
863
+ once(event: "error", listener: (err: Error) => void): this;
864
+ once(event: "listening", listener: () => void): this;
865
+ once(event: "drop", listener: (data?: DropArgument) => void): this;
866
+ prependListener(event: string, listener: (...args: any[]) => void): this;
867
+ prependListener(event: "close", listener: () => void): this;
868
+ prependListener(event: "connection", listener: (socket: Socket) => void): this;
869
+ prependListener(event: "error", listener: (err: Error) => void): this;
870
+ prependListener(event: "listening", listener: () => void): this;
871
+ prependListener(event: "drop", listener: (data?: DropArgument) => void): this;
872
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
873
+ prependOnceListener(event: "close", listener: () => void): this;
874
+ prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
875
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
876
+ prependOnceListener(event: "listening", listener: () => void): this;
877
+ prependOnceListener(event: "drop", listener: (data?: DropArgument) => void): this;
878
+ /**
879
+ * Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
880
+ * @since v20.5.0
881
+ */
882
+ [Symbol.asyncDispose](): Promise<void>;
883
+ }
884
+ type IPVersion = "ipv4" | "ipv6";
885
+ /**
886
+ * The `BlockList` object can be used with some network APIs to specify rules for
887
+ * disabling inbound or outbound access to specific IP addresses, IP ranges, or
888
+ * IP subnets.
889
+ * @since v15.0.0, v14.18.0
890
+ */
891
+ class BlockList {
892
+ /**
893
+ * Adds a rule to block the given IP address.
894
+ * @since v15.0.0, v14.18.0
895
+ * @param address An IPv4 or IPv6 address.
896
+ * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
897
+ */
898
+ addAddress(address: string, type?: IPVersion): void;
899
+ addAddress(address: SocketAddress): void;
900
+ /**
901
+ * Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
902
+ * @since v15.0.0, v14.18.0
903
+ * @param start The starting IPv4 or IPv6 address in the range.
904
+ * @param end The ending IPv4 or IPv6 address in the range.
905
+ * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
906
+ */
907
+ addRange(start: string, end: string, type?: IPVersion): void;
908
+ addRange(start: SocketAddress, end: SocketAddress): void;
909
+ /**
910
+ * Adds a rule to block a range of IP addresses specified as a subnet mask.
911
+ * @since v15.0.0, v14.18.0
912
+ * @param net The network IPv4 or IPv6 address.
913
+ * @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`.
914
+ * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
915
+ */
916
+ addSubnet(net: SocketAddress, prefix: number): void;
917
+ addSubnet(net: string, prefix: number, type?: IPVersion): void;
918
+ /**
919
+ * Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
920
+ *
921
+ * ```js
922
+ * const blockList = new net.BlockList();
923
+ * blockList.addAddress('123.123.123.123');
924
+ * blockList.addRange('10.0.0.1', '10.0.0.10');
925
+ * blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
926
+ *
927
+ * console.log(blockList.check('123.123.123.123')); // Prints: true
928
+ * console.log(blockList.check('10.0.0.3')); // Prints: true
929
+ * console.log(blockList.check('222.111.111.222')); // Prints: false
930
+ *
931
+ * // IPv6 notation for IPv4 addresses works:
932
+ * console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
933
+ * console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
934
+ * ```
935
+ * @since v15.0.0, v14.18.0
936
+ * @param address The IP address to check
937
+ * @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
938
+ */
939
+ check(address: SocketAddress): boolean;
940
+ check(address: string, type?: IPVersion): boolean;
941
+ /**
942
+ * The list of rules added to the blocklist.
943
+ * @since v15.0.0, v14.18.0
944
+ */
945
+ rules: readonly string[];
946
+ /**
947
+ * Returns `true` if the `value` is a `net.BlockList`.
948
+ * @since v22.13.0
949
+ * @param value Any JS value
950
+ */
951
+ static isBlockList(value: unknown): value is BlockList;
952
+ /**
953
+ * ```js
954
+ * const blockList = new net.BlockList();
955
+ * const data = [
956
+ * 'Subnet: IPv4 192.168.1.0/24',
957
+ * 'Address: IPv4 10.0.0.5',
958
+ * 'Range: IPv4 192.168.2.1-192.168.2.10',
959
+ * 'Range: IPv4 10.0.0.1-10.0.0.10',
960
+ * ];
961
+ * blockList.fromJSON(data);
962
+ * blockList.fromJSON(JSON.stringify(data));
963
+ * ```
964
+ * @since v24.5.0
965
+ * @experimental
966
+ */
967
+ fromJSON(data: string | readonly string[]): void;
968
+ /**
969
+ * @since v24.5.0
970
+ * @experimental
971
+ */
972
+ toJSON(): readonly string[];
973
+ }
974
+ interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
975
+ timeout?: number | undefined;
976
+ }
977
+ interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
978
+ timeout?: number | undefined;
979
+ }
980
+ type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
981
+ /**
982
+ * Creates a new TCP or `IPC` server.
983
+ *
984
+ * If `allowHalfOpen` is set to `true`, when the other end of the socket
985
+ * signals the end of transmission, the server will only send back the end of
986
+ * transmission when `socket.end()` is explicitly called. For example, in the
987
+ * context of TCP, when a FIN packed is received, a FIN packed is sent
988
+ * back only when `socket.end()` is explicitly called. Until then the
989
+ * 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.
990
+ *
991
+ * If `pauseOnConnect` is set to `true`, then the socket associated with each
992
+ * incoming connection will be paused, and no data will be read from its handle.
993
+ * This allows connections to be passed between processes without any data being
994
+ * read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
995
+ *
996
+ * The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
997
+ *
998
+ * Here is an example of a TCP echo server which listens for connections
999
+ * on port 8124:
1000
+ *
1001
+ * ```js
1002
+ * import net from 'node:net';
1003
+ * const server = net.createServer((c) => {
1004
+ * // 'connection' listener.
1005
+ * console.log('client connected');
1006
+ * c.on('end', () => {
1007
+ * console.log('client disconnected');
1008
+ * });
1009
+ * c.write('hello\r\n');
1010
+ * c.pipe(c);
1011
+ * });
1012
+ * server.on('error', (err) => {
1013
+ * throw err;
1014
+ * });
1015
+ * server.listen(8124, () => {
1016
+ * console.log('server bound');
1017
+ * });
1018
+ * ```
1019
+ *
1020
+ * Test this by using `telnet`:
1021
+ *
1022
+ * ```bash
1023
+ * telnet localhost 8124
1024
+ * ```
1025
+ *
1026
+ * To listen on the socket `/tmp/echo.sock`:
1027
+ *
1028
+ * ```js
1029
+ * server.listen('/tmp/echo.sock', () => {
1030
+ * console.log('server bound');
1031
+ * });
1032
+ * ```
1033
+ *
1034
+ * Use `nc` to connect to a Unix domain socket server:
1035
+ *
1036
+ * ```bash
1037
+ * nc -U /tmp/echo.sock
1038
+ * ```
1039
+ * @since v0.5.0
1040
+ * @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
1041
+ */
1042
+ function createServer(connectionListener?: (socket: Socket) => void): Server;
1043
+ function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
1044
+ /**
1045
+ * Aliases to {@link createConnection}.
1046
+ *
1047
+ * Possible signatures:
1048
+ *
1049
+ * * {@link connect}
1050
+ * * {@link connect} for `IPC` connections.
1051
+ * * {@link connect} for TCP connections.
1052
+ */
1053
+ function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
1054
+ function connect(port: number, host?: string, connectionListener?: () => void): Socket;
1055
+ function connect(path: string, connectionListener?: () => void): Socket;
1056
+ /**
1057
+ * A factory function, which creates a new {@link Socket},
1058
+ * immediately initiates connection with `socket.connect()`,
1059
+ * then returns the `net.Socket` that starts the connection.
1060
+ *
1061
+ * When the connection is established, a `'connect'` event will be emitted
1062
+ * on the returned socket. The last parameter `connectListener`, if supplied,
1063
+ * will be added as a listener for the `'connect'` event **once**.
1064
+ *
1065
+ * Possible signatures:
1066
+ *
1067
+ * * {@link createConnection}
1068
+ * * {@link createConnection} for `IPC` connections.
1069
+ * * {@link createConnection} for TCP connections.
1070
+ *
1071
+ * The {@link connect} function is an alias to this function.
1072
+ */
1073
+ function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
1074
+ function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
1075
+ function createConnection(path: string, connectionListener?: () => void): Socket;
1076
+ /**
1077
+ * Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`.
1078
+ * The initial default value is `true`, unless the command line option`--no-network-family-autoselection` is provided.
1079
+ * @since v19.4.0
1080
+ */
1081
+ function getDefaultAutoSelectFamily(): boolean;
1082
+ /**
1083
+ * Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`.
1084
+ * @param value The new default value.
1085
+ * The initial default value is `true`, unless the command line option
1086
+ * `--no-network-family-autoselection` is provided.
1087
+ * @since v19.4.0
1088
+ */
1089
+ function setDefaultAutoSelectFamily(value: boolean): void;
1090
+ /**
1091
+ * Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
1092
+ * The initial default value is `250` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`.
1093
+ * @returns The current default value of the `autoSelectFamilyAttemptTimeout` option.
1094
+ * @since v19.8.0, v18.8.0
1095
+ */
1096
+ function getDefaultAutoSelectFamilyAttemptTimeout(): number;
1097
+ /**
1098
+ * Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
1099
+ * @param value The new default value, which must be a positive number. If the number is less than `10`, the value `10` is used instead. The initial default value is `250` or the value specified via the command line
1100
+ * option `--network-family-autoselection-attempt-timeout`.
1101
+ * @since v19.8.0, v18.8.0
1102
+ */
1103
+ function setDefaultAutoSelectFamilyAttemptTimeout(value: number): void;
1104
+ /**
1105
+ * Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
1106
+ * address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
1107
+ *
1108
+ * ```js
1109
+ * net.isIP('::1'); // returns 6
1110
+ * net.isIP('127.0.0.1'); // returns 4
1111
+ * net.isIP('127.000.000.001'); // returns 0
1112
+ * net.isIP('127.0.0.1/24'); // returns 0
1113
+ * net.isIP('fhqwhgads'); // returns 0
1114
+ * ```
1115
+ * @since v0.3.0
1116
+ */
1117
+ function isIP(input: string): number;
1118
+ /**
1119
+ * Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
1120
+ * leading zeroes. Otherwise, returns `false`.
1121
+ *
1122
+ * ```js
1123
+ * net.isIPv4('127.0.0.1'); // returns true
1124
+ * net.isIPv4('127.000.000.001'); // returns false
1125
+ * net.isIPv4('127.0.0.1/24'); // returns false
1126
+ * net.isIPv4('fhqwhgads'); // returns false
1127
+ * ```
1128
+ * @since v0.3.0
1129
+ */
1130
+ function isIPv4(input: string): boolean;
1131
+ /**
1132
+ * Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
1133
+ *
1134
+ * ```js
1135
+ * net.isIPv6('::1'); // returns true
1136
+ * net.isIPv6('fhqwhgads'); // returns false
1137
+ * ```
1138
+ * @since v0.3.0
1139
+ */
1140
+ function isIPv6(input: string): boolean;
1141
+ interface SocketAddressInitOptions {
1142
+ /**
1143
+ * The network address as either an IPv4 or IPv6 string.
1144
+ * @default 127.0.0.1
1145
+ */
1146
+ address?: string | undefined;
1147
+ /**
1148
+ * @default `'ipv4'`
1149
+ */
1150
+ family?: IPVersion | undefined;
1151
+ /**
1152
+ * An IPv6 flow-label used only if `family` is `'ipv6'`.
1153
+ * @default 0
1154
+ */
1155
+ flowlabel?: number | undefined;
1156
+ /**
1157
+ * An IP port.
1158
+ * @default 0
1159
+ */
1160
+ port?: number | undefined;
1161
+ }
1162
+ /**
1163
+ * @since v15.14.0, v14.18.0
1164
+ */
1165
+ class SocketAddress {
1166
+ constructor(options: SocketAddressInitOptions);
1167
+ /**
1168
+ * Either \`'ipv4'\` or \`'ipv6'\`.
1169
+ * @since v15.14.0, v14.18.0
1170
+ */
1171
+ readonly address: string;
1172
+ /**
1173
+ * Either \`'ipv4'\` or \`'ipv6'\`.
1174
+ * @since v15.14.0, v14.18.0
1175
+ */
1176
+ readonly family: IPVersion;
1177
+ /**
1178
+ * @since v15.14.0, v14.18.0
1179
+ */
1180
+ readonly port: number;
1181
+ /**
1182
+ * @since v15.14.0, v14.18.0
1183
+ */
1184
+ readonly flowlabel: number;
1185
+ /**
1186
+ * @since v22.13.0
1187
+ * @param input An input string containing an IP address and optional port,
1188
+ * e.g. `123.1.2.3:1234` or `[1::1]:1234`.
1189
+ * @returns Returns a `SocketAddress` if parsing was successful.
1190
+ * Otherwise returns `undefined`.
1191
+ */
1192
+ static parse(input: string): SocketAddress | undefined;
1193
+ }
1194
+ }
1195
+ declare module "node:net" {
1196
+ export * from "net";
1197
+ }