codemod 2.0.0-alpha.1 → 2.0.0-alpha.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 (89) hide show
  1. package/README.md +57 -2
  2. package/codemod +17 -30
  3. package/package.json +78 -10
  4. package/register.d.mts +11 -0
  5. package/register.mjs +60 -0
  6. package/runtime/addon.mjs +59 -0
  7. package/runtime/ast-grep.mjs +93 -0
  8. package/runtime/context.mjs +77 -0
  9. package/runtime/hooks.mjs +9 -0
  10. package/runtime/host.d.mts +120 -0
  11. package/runtime/host.mjs +390 -0
  12. package/runtime/llm.mjs +11 -0
  13. package/runtime/metrics.mjs +45 -0
  14. package/runtime/modules.mjs +19 -0
  15. package/runtime/orchestrator.mjs +657 -0
  16. package/runtime/runtime.mjs +48 -0
  17. package/runtime/workflow.mjs +135 -0
  18. package/testing/index.d.mts +203 -0
  19. package/testing/index.mjs +638 -0
  20. package/types/index.d.ts +8 -0
  21. package/types/langs/angular.d.ts +5 -0
  22. package/types/langs/c.d.ts +5 -0
  23. package/types/langs/c_sharp.d.ts +5 -0
  24. package/types/langs/cpp.d.ts +5 -0
  25. package/types/langs/css.d.ts +5 -0
  26. package/types/langs/elixir.d.ts +5 -0
  27. package/types/langs/go.d.ts +5 -0
  28. package/types/langs/html.d.ts +5 -0
  29. package/types/langs/java.d.ts +5 -0
  30. package/types/langs/javascript.d.ts +5 -0
  31. package/types/langs/json.d.ts +5 -0
  32. package/types/langs/kotlin.d.ts +5 -0
  33. package/types/langs/php.d.ts +5 -0
  34. package/types/langs/python.d.ts +5 -0
  35. package/types/langs/ruby.d.ts +5 -0
  36. package/types/langs/rust.d.ts +5 -0
  37. package/types/langs/scala.d.ts +5 -0
  38. package/types/langs/toml.d.ts +5 -0
  39. package/types/langs/tsx.d.ts +5 -0
  40. package/types/langs/typescript.d.ts +5 -0
  41. package/types/langs/xml.d.ts +5 -0
  42. package/types/langs/yaml.d.ts +5 -0
  43. package/types/llm.d.ts +6 -0
  44. package/types/llrt/abort.d.ts +69 -0
  45. package/types/llrt/assert.d.ts +39 -0
  46. package/types/llrt/async_hooks.d.ts +210 -0
  47. package/types/llrt/buffer.d.ts +1186 -0
  48. package/types/llrt/child_process.d.ts +447 -0
  49. package/types/llrt/console.d.ts +210 -0
  50. package/types/llrt/crypto.d.ts +854 -0
  51. package/types/llrt/dgram.d.ts +381 -0
  52. package/types/llrt/dns.d.ts +124 -0
  53. package/types/llrt/dom-events.d.ts +51 -0
  54. package/types/llrt/events.d.ts +245 -0
  55. package/types/llrt/exceptions.d.ts +26 -0
  56. package/types/llrt/fetch.d.ts +332 -0
  57. package/types/llrt/fs/promises.d.ts +554 -0
  58. package/types/llrt/fs.d.ts +360 -0
  59. package/types/llrt/globals.d.ts +23 -0
  60. package/types/llrt/https.d.ts +27 -0
  61. package/types/llrt/index.d.ts +33 -0
  62. package/types/llrt/module.d.ts +285 -0
  63. package/types/llrt/navigator.d.ts +9 -0
  64. package/types/llrt/net.d.ts +488 -0
  65. package/types/llrt/os.d.ts +293 -0
  66. package/types/llrt/path.d.ts +150 -0
  67. package/types/llrt/perf_hooks.d.ts +23 -0
  68. package/types/llrt/process.d.ts +502 -0
  69. package/types/llrt/stream/web.d.ts +526 -0
  70. package/types/llrt/stream.d.ts +366 -0
  71. package/types/llrt/string_decoder.d.ts +63 -0
  72. package/types/llrt/timers.d.ts +72 -0
  73. package/types/llrt/timezone.d.ts +101 -0
  74. package/types/llrt/tty.d.ts +11 -0
  75. package/types/llrt/url.d.ts +774 -0
  76. package/types/llrt/util.d.ts +240 -0
  77. package/types/llrt/zlib.d.ts +177 -0
  78. package/types/main.d.ts +5 -0
  79. package/types/metrics.d.ts +5 -0
  80. package/types/modules/ast-grep.d.ts +634 -0
  81. package/types/modules/langs.d.ts +87 -0
  82. package/types/modules/llm.d.ts +23 -0
  83. package/types/modules/metrics.d.ts +107 -0
  84. package/types/modules/runtime.d.ts +66 -0
  85. package/types/modules/workflow.d.ts +750 -0
  86. package/types/runtime.d.ts +6 -0
  87. package/types/workflow.d.ts +5 -0
  88. package/vite.d.mts +24 -0
  89. package/vite.mjs +26 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * The `dgram` module provides an implementation of UDP datagram sockets.
3
+ *
4
+ * ```js
5
+ * import dgram from 'dgram';
6
+ *
7
+ * const server = dgram.createSocket('udp4');
8
+ *
9
+ * server.on('message', (msg, rinfo) => {
10
+ * console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
11
+ * });
12
+ *
13
+ * server.bind(41234);
14
+ * ```
15
+ */
16
+ declare module "dgram" {
17
+ import { EventEmitter } from "events";
18
+ import { Buffer } from "buffer";
19
+
20
+ interface RemoteInfo {
21
+ /**
22
+ * The IP address of the sender.
23
+ */
24
+ address: string;
25
+ /**
26
+ * The address family ('IPv4' or 'IPv6').
27
+ */
28
+ family: "IPv4" | "IPv6";
29
+ /**
30
+ * The port number of the sender.
31
+ */
32
+ port: number;
33
+ }
34
+
35
+ interface BindOptions {
36
+ /**
37
+ * The port to bind to.
38
+ */
39
+ port?: number | undefined;
40
+ /**
41
+ * The address to bind to.
42
+ */
43
+ address?: string | undefined;
44
+ }
45
+
46
+ interface SocketOptions {
47
+ /**
48
+ * The type of socket. Must be either 'udp4' or 'udp6'.
49
+ */
50
+ type: SocketType;
51
+ }
52
+
53
+ type SocketType = "udp4" | "udp6";
54
+
55
+ /**
56
+ * Encapsulates the datagram functionality.
57
+ *
58
+ * New instances of `dgram.Socket` are created using {@link createSocket}.
59
+ * The `new` keyword is not to be used to create `dgram.Socket` instances.
60
+ */
61
+ class Socket extends EventEmitter {
62
+ /**
63
+ * Tells the kernel to join a multicast group at the given `multicastAddress` and `multicastInterface` using the `IP_ADD_MEMBERSHIP` socket option.
64
+ * If the `multicastInterface` argument is not specified, the operating system will choose one interface and will add membership to it.
65
+ * To add membership to every available interface, call `addMembership` multiple times, once per interface.
66
+ */
67
+ addMembership(
68
+ multicastAddress: string,
69
+ multicastInterface?: string
70
+ ): void;
71
+ /**
72
+ * Returns an object containing the address information for a socket.
73
+ * For UDP sockets, this object will contain `address`, `family`, and `port` properties.
74
+ *
75
+ * This method throws `EBADF` if called on an unbound socket.
76
+ */
77
+ address(): AddressInfo;
78
+ /**
79
+ * For UDP sockets, causes the `dgram.Socket` to listen for datagram messages on a named `port` and optional `address`.
80
+ * If `port` is not specified or is `0`, the operating system will attempt to bind to a random port.
81
+ * If `address` is not specified, the operating system will attempt to listen on all addresses.
82
+ * Once binding is complete, a `'listening'` event is emitted and the optional `callback` function is called.
83
+ *
84
+ * Specifying both a `'listening'` event listener and passing a `callback` to the `socket.bind()` method is not harmful but not very useful.
85
+ *
86
+ * @param port The port to listen on.
87
+ * @param address The address to listen on.
88
+ * @param callback Called when binding is complete.
89
+ */
90
+ bind(port?: number, address?: string, callback?: () => void): this;
91
+ bind(port?: number, callback?: () => void): this;
92
+ bind(callback?: () => void): this;
93
+ bind(options: BindOptions, callback?: () => void): this;
94
+ /**
95
+ * Close the underlying socket and stop listening for data on it. If a callback is provided, it is added as a listener for the `'close'` event.
96
+ *
97
+ * @param callback Called when the socket has been closed.
98
+ */
99
+ close(callback?: () => void): this;
100
+ /**
101
+ * Instructs the kernel to leave a multicast group at `multicastAddress` using the `IP_DROP_MEMBERSHIP` socket option.
102
+ * This method is automatically called by the kernel when the socket is closed or the process terminates, so most apps will never have reason to call this.
103
+ *
104
+ * If `multicastInterface` is not specified, the operating system will attempt to drop membership on all valid interfaces.
105
+ */
106
+ dropMembership(
107
+ multicastAddress: string,
108
+ multicastInterface?: string
109
+ ): void;
110
+ /**
111
+ * By default, binding a socket will cause it to block the LLRT process from exiting as long as the socket is open.
112
+ * The `socket.unref()` method can be used to exclude the socket from the reference counting that keeps the LLRT process active.
113
+ * The `socket.ref()` method adds the socket back to the reference counting and restores the default behavior.
114
+ *
115
+ * Calling `socket.ref()` multiples times will have no additional effect.
116
+ *
117
+ * The `socket.ref()` method returns a reference to the socket so calls can be chained.
118
+ */
119
+ ref(): this;
120
+ /**
121
+ * Broadcasts a datagram on the socket.
122
+ * For connectionless sockets, the destination `port` and `address` must be specified.
123
+ * Connected sockets, on the other hand, will use their associated remote endpoint, so the `port` and `address` arguments must not be set.
124
+ *
125
+ * The `msg` argument contains the message to be sent.
126
+ * Depending on its type, different behavior can apply.
127
+ * If `msg` is a `Buffer`, any `TypedArray` or a `DataView`, the `offset` and `length` specify the offset within the `Buffer` where the message begins and the number of bytes in the message, respectively.
128
+ * If `msg` is a `String`, then it is automatically converted to a `Buffer` with `'utf8'` encoding.
129
+ * With messages that contain multi-byte characters, `offset` and `length` will be calculated with respect to byte length and not the character position.
130
+ * If `msg` is an array, `offset` and `length` must not be specified.
131
+ *
132
+ * The `address` argument is a string. If the value of `address` is a host name, DNS will be used to resolve the address of the host.
133
+ * If `address` is not provided or otherwise nullish, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets) will be used by default.
134
+ *
135
+ * If the socket has not been previously bound with a call to `bind`, the socket is assigned a random port number and is bound to the "all interfaces" address (`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
136
+ *
137
+ * An optional `callback` function may be specified to as a way of reporting DNS errors or for determining when it is safe to reuse the `buf` object.
138
+ * DNS lookups delay the time to send for at least one tick of the LLRT event loop.
139
+ *
140
+ * The only way to know for sure that the datagram has been sent is by using a `callback`. If an error occurs and a `callback` is given, the error will be passed as the first argument to the `callback`.
141
+ * If a `callback` is not given, the error is emitted as an `'error'` event on the `socket` object.
142
+ *
143
+ * Offset and length are optional but both _must_ be set if either are used.
144
+ * They are supported only when the first argument is a `Buffer`, a `TypedArray`, or a `DataView`.
145
+ *
146
+ * @param msg Message to be sent.
147
+ * @param port Destination port.
148
+ * @param address Destination host name or IP address.
149
+ * @param callback Called when the message has been sent.
150
+ */
151
+ send(
152
+ msg: string | Uint8Array | readonly any[],
153
+ port?: number,
154
+ address?: string,
155
+ callback?: (error: Error | null, bytes: number) => void
156
+ ): void;
157
+ send(
158
+ msg: string | Uint8Array | readonly any[],
159
+ port?: number,
160
+ callback?: (error: Error | null, bytes: number) => void
161
+ ): void;
162
+ send(
163
+ msg: string | Uint8Array,
164
+ offset: number,
165
+ length: number,
166
+ port?: number,
167
+ address?: string,
168
+ callback?: (error: Error | null, bytes: number) => void
169
+ ): void;
170
+ send(
171
+ msg: string | Uint8Array,
172
+ offset: number,
173
+ length: number,
174
+ port?: number,
175
+ callback?: (error: Error | null, bytes: number) => void
176
+ ): void;
177
+ /**
178
+ * Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP packets may be sent to a local interface's broadcast address.
179
+ *
180
+ * This method throws `EBADF` if called on an unbound socket.
181
+ */
182
+ setBroadcast(flag: boolean): void;
183
+ /**
184
+ * _All references to scope in this section are referring to [IPv6 Zone Indices](https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses), which are defined by [RFC 4007](https://tools.ietf.org/html/rfc4007). In string form, an IP_
185
+ * _with a scope index is written as `'IP%scope'` where scope is an interface name or interface number._
186
+ *
187
+ * Sets the default outgoing multicast interface of the socket to a chosen interface or back to system interface selection.
188
+ * The `multicastInterface` must be a valid string representation of an IP from the socket's family.
189
+ *
190
+ * For IPv4 sockets, this should be the IP configured for the desired physical interface.
191
+ * All packets sent to multicast on the socket will be sent on the interface determined by the most recent successful use of this call.
192
+ *
193
+ * For IPv6 sockets, `multicastInterface` should include a scope to indicate the interface as in the examples that follow.
194
+ * In IPv6, individual `send` calls can also use explicit scope in addresses, so only packets sent to a multicast address without specifying an explicit scope are affected by the most recent successful use of this call.
195
+ *
196
+ * This method throws `EBADF` if called on an unbound socket.
197
+ *
198
+ * #### Example: IPv6 outgoing multicast interface
199
+ *
200
+ * On most systems, where scope format uses the interface name:
201
+ *
202
+ * ```js
203
+ * const socket = dgram.createSocket('udp6');
204
+ *
205
+ * socket.bind(1234, () => {
206
+ * socket.setMulticastInterface('::%eth1');
207
+ * });
208
+ * ```
209
+ *
210
+ * On Windows, where scope format uses an interface number:
211
+ *
212
+ * ```js
213
+ * const socket = dgram.createSocket('udp6');
214
+ *
215
+ * socket.bind(1234, () => {
216
+ * socket.setMulticastInterface('::%2');
217
+ * });
218
+ * ```
219
+ *
220
+ * #### Example: IPv4 outgoing multicast interface
221
+ *
222
+ * All systems use an IP of the host on the desired physical interface:
223
+ *
224
+ * ```js
225
+ * const socket = dgram.createSocket('udp4');
226
+ *
227
+ * socket.bind(1234, () => {
228
+ * socket.setMulticastInterface('10.0.0.2');
229
+ * });
230
+ * ```
231
+ */
232
+ setMulticastInterface(multicastInterface: string): void;
233
+ /**
234
+ * Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`, multicast packets will also be received on the local interface.
235
+ *
236
+ * This method throws `EBADF` if called on an unbound socket.
237
+ */
238
+ setMulticastLoopback(flag: boolean): void;
239
+ /**
240
+ * Sets the `IP_MULTICAST_TTL` socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through, specifically for multicast traffic.
241
+ * Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
242
+ *
243
+ * The `ttl` argument may be between 0 and 255. The default on most systems is `1`.
244
+ *
245
+ * This method throws `EBADF` if called on an unbound socket.
246
+ */
247
+ setMulticastTTL(ttl: number): void;
248
+ /**
249
+ * Sets the `IP_RECVTOS` socket option. When enabled, the socket will return the Type of Service (TOS) header field on received packets.
250
+ *
251
+ * This method throws `EBADF` if called on an unbound socket.
252
+ */
253
+ setRecvBufferSize(size: number): void;
254
+ /**
255
+ * Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer in bytes.
256
+ *
257
+ * This method throws `EBADF` if called on an unbound socket.
258
+ */
259
+ setSendBufferSize(size: number): void;
260
+ /**
261
+ * Sets the `IP_TTL` socket option. While TTL generally stands for "Time to Live", in this context it specifies the number of IP hops that a packet is allowed to travel through.
262
+ * Each router or gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
263
+ * Changing TTL values is typically done for network probes or when multicasting.
264
+ *
265
+ * The `ttl` argument may be between 1 and 255. The default on most systems is 64.
266
+ *
267
+ * This method throws `EBADF` if called on an unbound socket.
268
+ */
269
+ setTTL(ttl: number): void;
270
+ /**
271
+ * By default, binding a socket will cause it to block the LLRT process from exiting as long as the socket is open.
272
+ * The `socket.unref()` method can be used to exclude the socket from the reference counting that keeps the LLRT process active, allowing the process to exit even if the socket is still listening.
273
+ *
274
+ * Calling `socket.unref()` multiple times will have no addition effect.
275
+ *
276
+ * The `socket.unref()` method returns a reference to the socket so calls can be chained.
277
+ */
278
+ unref(): this;
279
+ /**
280
+ * Emitted when the socket is closed with {@link close}.
281
+ * No new `'message'` events will be emitted on this socket.
282
+ */
283
+ addListener(event: "close", listener: () => void): this;
284
+ /**
285
+ * Emitted when the socket is ready to receive data.
286
+ */
287
+ addListener(event: "listening", listener: () => void): this;
288
+ /**
289
+ * Emitted when a new datagram is available on a socket.
290
+ * The event handler function is passed two arguments: `msg` and `rinfo`.
291
+ */
292
+ addListener(
293
+ event: "message",
294
+ listener: (msg: Buffer, rinfo: RemoteInfo) => void
295
+ ): this;
296
+ /**
297
+ * Emitted when an error occurs. The event handler function is passed a single `Error` object.
298
+ */
299
+ addListener(event: "error", listener: (err: Error) => void): this;
300
+ addListener(event: string, listener: (...args: any[]) => void): this;
301
+ emit(event: "close"): boolean;
302
+ emit(event: "listening"): boolean;
303
+ emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean;
304
+ emit(event: "error", err: Error): boolean;
305
+ emit(event: string | symbol, ...args: any[]): boolean;
306
+ on(event: "close", listener: () => void): this;
307
+ on(event: "listening", listener: () => void): this;
308
+ on(
309
+ event: "message",
310
+ listener: (msg: Buffer, rinfo: RemoteInfo) => void
311
+ ): this;
312
+ on(event: "error", listener: (err: Error) => void): this;
313
+ on(event: string, listener: (...args: any[]) => void): this;
314
+ once(event: "close", listener: () => void): this;
315
+ once(event: "listening", listener: () => void): this;
316
+ once(
317
+ event: "message",
318
+ listener: (msg: Buffer, rinfo: RemoteInfo) => void
319
+ ): this;
320
+ once(event: "error", listener: (err: Error) => void): this;
321
+ once(event: string, listener: (...args: any[]) => void): this;
322
+ prependListener(event: "close", listener: () => void): this;
323
+ prependListener(event: "listening", listener: () => void): this;
324
+ prependListener(
325
+ event: "message",
326
+ listener: (msg: Buffer, rinfo: RemoteInfo) => void
327
+ ): this;
328
+ prependListener(event: "error", listener: (err: Error) => void): this;
329
+ prependListener(event: string, listener: (...args: any[]) => void): this;
330
+ prependOnceListener(event: "close", listener: () => void): this;
331
+ prependOnceListener(event: "listening", listener: () => void): this;
332
+ prependOnceListener(
333
+ event: "message",
334
+ listener: (msg: Buffer, rinfo: RemoteInfo) => void
335
+ ): this;
336
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
337
+ prependOnceListener(
338
+ event: string,
339
+ listener: (...args: any[]) => void
340
+ ): this;
341
+ }
342
+
343
+ interface AddressInfo {
344
+ address: string;
345
+ family: "IPv4" | "IPv6";
346
+ port: number;
347
+ }
348
+
349
+ /**
350
+ * Creates a `dgram.Socket` object. Once the socket is created, calling `socket.bind()` will instruct the socket to begin listening for datagram messages.
351
+ * When `address` and `port` are not passed to `socket.bind()` the method will bind the socket to the "all interfaces" address on a random port (it does the right thing for both `udp4` and `udp6` sockets).
352
+ * The bound address and port can be retrieved using `socket.address().address` and `socket.address().port`.
353
+ *
354
+ * If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the socket:
355
+ *
356
+ * ```js
357
+ * const controller = new AbortController();
358
+ * const { signal } = controller;
359
+ * const server = dgram.createSocket({ type: 'udp4', signal });
360
+ * server.on('message', (msg, rinfo) => {
361
+ * console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
362
+ * });
363
+ * // Later, when you want to close the server.
364
+ * controller.abort();
365
+ * ```
366
+ *
367
+ * @param type The family of socket. Must be either 'udp4' or 'udp6'.
368
+ * @param callback Attached as a listener to `'message'` events.
369
+ */
370
+ function createSocket(
371
+ type: SocketType,
372
+ callback?: (msg: Buffer, rinfo: RemoteInfo) => void
373
+ ): Socket;
374
+ function createSocket(
375
+ options: SocketOptions,
376
+ callback?: (msg: Buffer, rinfo: RemoteInfo) => void
377
+ ): Socket;
378
+ }
379
+ declare module "node:dgram" {
380
+ export * from "dgram";
381
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The `dns` module enables name resolution. For example, use it to look up IP
3
+ * addresses of host names.
4
+ *
5
+ * Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the
6
+ * DNS protocol for lookups. {@link lookup} uses the operating system
7
+ * facilities to perform name resolution. It may not need to perform any network
8
+ * communication. To perform name resolution the way other applications on the same
9
+ * system do, use {@link lookup}.
10
+ *
11
+ * ```js
12
+ * import dns from 'dns';
13
+ *
14
+ * dns.lookup('example.org', (err, address, family) => {
15
+ * console.log('address: %j family: IPv%s', address, family);
16
+ * });
17
+ * // address: "93.184.216.34" family: IPv4
18
+ * ```
19
+ *
20
+ */
21
+ declare module "dns" {
22
+ export interface LookupOptions {
23
+ /**
24
+ * The record family. Must be `4`, `6`, or `0`.
25
+ * The value 0 indicates that either an IPv4 or IPv6 address is returned.
26
+ * @default 0
27
+ */
28
+ family?: number | "IPv4" | "IPv6" | undefined;
29
+ /**
30
+ * When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address.
31
+ * @default false
32
+ */
33
+ all?: boolean | undefined;
34
+ /**
35
+ * When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted
36
+ * by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6
37
+ * addresses before IPv4 addresses. Default value is configurable using
38
+ * {@link setDefaultResultOrder} or [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder).
39
+ * @default `verbatim` (addresses are not reordered)
40
+ */
41
+ order?: "verbatim" | "ipv4first" | "ipv6first" | undefined;
42
+ }
43
+ export interface LookupOneOptions extends LookupOptions {
44
+ all?: false | undefined;
45
+ }
46
+ export interface LookupAllOptions extends LookupOptions {
47
+ all: true;
48
+ }
49
+ export interface LookupAddress {
50
+ /**
51
+ * A string representation of an IPv4 or IPv6 address.
52
+ */
53
+ address: string;
54
+ /**
55
+ * `4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a
56
+ * bug in the name resolution service used by the operating system.
57
+ */
58
+ family: number;
59
+ }
60
+ /**
61
+ * Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
62
+ * AAAA (IPv6) record. All `option` properties are optional. If `options` is an
63
+ * integer, then it must be `4` or `6` – if `options` is `0` or not provided, then
64
+ * IPv4 and IPv6 addresses are both returned if found.
65
+ *
66
+ * On error, `err` is an `Error` object, where `err.code` is the error code.
67
+ * Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
68
+ * the host name does not exist but also when the lookup fails in other ways
69
+ * such as no available file descriptors.
70
+ *
71
+ * `dns.lookup()` does not necessarily have anything to do with the DNS protocol.
72
+ * The implementation uses an operating system facility that can associate names
73
+ * with addresses and vice versa.
74
+ *
75
+ * Example usage:
76
+ *
77
+ * ```js
78
+ * import dns from 'dns';
79
+ * const options = {
80
+ * family: 6,
81
+ * };
82
+ * dns.lookup('example.com', options, (err, address, family) =>
83
+ * console.log('address: %j family: IPv%s', address, family));
84
+ * // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
85
+ *
86
+ * ```
87
+ *
88
+ */
89
+ export function lookup(
90
+ hostname: string,
91
+ family: number,
92
+ callback: (
93
+ err: DOMException | null,
94
+ address: string,
95
+ family: number
96
+ ) => void
97
+ ): void;
98
+ export function lookup(
99
+ hostname: string,
100
+ options: LookupOneOptions,
101
+ callback: (err: Error | null, address: string, family: number) => void
102
+ ): void;
103
+ export function lookup(
104
+ hostname: string,
105
+ options: LookupAllOptions,
106
+ callback: (err: Error | null, addresses: LookupAddress[]) => void
107
+ ): void;
108
+ export function lookup(
109
+ hostname: string,
110
+ options: LookupOptions,
111
+ callback: (
112
+ err: Error | null,
113
+ address: string | LookupAddress[],
114
+ family: number
115
+ ) => void
116
+ ): void;
117
+ export function lookup(
118
+ hostname: string,
119
+ callback: (err: Error | null, address: string, family: number) => void
120
+ ): void;
121
+ }
122
+ declare module "dns" {
123
+ export * from "dns";
124
+ }
@@ -0,0 +1,51 @@
1
+ export {};
2
+
3
+ interface EventListener {
4
+ (evt: Event): void;
5
+ }
6
+
7
+ interface AddEventListenerOptions {
8
+ /** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
9
+ once?: boolean;
10
+ }
11
+
12
+ declare global {
13
+ type EventKey = string | symbol;
14
+
15
+ /** An event which takes place in the system. */
16
+ interface Event {
17
+ /** Returns the type of event, e.g. "click", "hashchange", or "submit". */
18
+ readonly type: EventKey;
19
+ }
20
+
21
+ class CustomEvent<D = any> implements Event {
22
+ constructor(type: string, opts?: { details?: D });
23
+ readonly type: string;
24
+ readonly details: D | null;
25
+ }
26
+
27
+ /**
28
+ * EventTarget is an interface implemented by objects that can
29
+ * receive events and may have listeners for them.
30
+ */
31
+ class EventTarget {
32
+ constructor();
33
+
34
+ /**
35
+ * Adds a new handler for the `type` event. Any given `listener` is added only once per `type`.
36
+ *
37
+ * If the `once` option is true, the `listener` is removed after the next time a `type` event is dispatched.
38
+ */
39
+ addEventListener(
40
+ type: EventKey,
41
+ listener: EventListener,
42
+ options?: AddEventListenerOptions
43
+ ): void;
44
+
45
+ /** Dispatches a synthetic event event to target */
46
+ dispatchEvent(event: Event): void;
47
+
48
+ /** Removes the event listener in target's event listener list with the same type and callback */
49
+ removeEventListener(type: EventKey, listener: EventListener): void;
50
+ }
51
+ }