omegon 0.8.4 → 0.9.0

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 (138) hide show
  1. package/extensions/cleave/dispatcher.ts +213 -20
  2. package/extensions/cleave/rpc-child.ts +269 -0
  3. package/extensions/cleave/types.ts +52 -0
  4. package/node_modules/@types/node/README.md +3 -3
  5. package/node_modules/@types/node/assert/strict.d.ts +11 -5
  6. package/node_modules/@types/node/assert.d.ts +173 -50
  7. package/node_modules/@types/node/async_hooks.d.ts +8 -28
  8. package/node_modules/@types/node/buffer.buffer.d.ts +7 -1
  9. package/node_modules/@types/node/buffer.d.ts +168 -44
  10. package/node_modules/@types/node/child_process.d.ts +70 -27
  11. package/node_modules/@types/node/cluster.d.ts +332 -240
  12. package/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
  13. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  14. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  15. package/node_modules/@types/node/compatibility/iterators.d.ts +0 -1
  16. package/node_modules/@types/node/console.d.ts +350 -49
  17. package/node_modules/@types/node/constants.d.ts +4 -3
  18. package/node_modules/@types/node/crypto.d.ts +1110 -630
  19. package/node_modules/@types/node/dgram.d.ts +51 -15
  20. package/node_modules/@types/node/diagnostics_channel.d.ts +6 -4
  21. package/node_modules/@types/node/dns/promises.d.ts +4 -4
  22. package/node_modules/@types/node/dns.d.ts +133 -132
  23. package/node_modules/@types/node/domain.d.ts +17 -13
  24. package/node_modules/@types/node/events.d.ts +663 -734
  25. package/node_modules/@types/node/fs/promises.d.ts +9 -43
  26. package/node_modules/@types/node/fs.d.ts +411 -628
  27. package/node_modules/@types/node/globals.d.ts +30 -8
  28. package/node_modules/@types/node/globals.typedarray.d.ts +0 -63
  29. package/node_modules/@types/node/http.d.ts +265 -364
  30. package/node_modules/@types/node/http2.d.ts +715 -551
  31. package/node_modules/@types/node/https.d.ts +239 -65
  32. package/node_modules/@types/node/index.d.ts +6 -24
  33. package/node_modules/@types/node/inspector.d.ts +53 -69
  34. package/node_modules/@types/node/inspector.generated.d.ts +410 -759
  35. package/node_modules/@types/node/module.d.ts +186 -52
  36. package/node_modules/@types/node/net.d.ts +194 -70
  37. package/node_modules/@types/node/os.d.ts +11 -12
  38. package/node_modules/@types/node/package.json +3 -13
  39. package/node_modules/@types/node/path.d.ts +133 -120
  40. package/node_modules/@types/node/perf_hooks.d.ts +643 -318
  41. package/node_modules/@types/node/process.d.ts +132 -223
  42. package/node_modules/@types/node/punycode.d.ts +5 -5
  43. package/node_modules/@types/node/querystring.d.ts +4 -4
  44. package/node_modules/@types/node/readline/promises.d.ts +3 -3
  45. package/node_modules/@types/node/readline.d.ts +120 -68
  46. package/node_modules/@types/node/repl.d.ts +100 -87
  47. package/node_modules/@types/node/sea.d.ts +1 -10
  48. package/node_modules/@types/node/sqlite.d.ts +19 -363
  49. package/node_modules/@types/node/stream/consumers.d.ts +10 -10
  50. package/node_modules/@types/node/stream/promises.d.ts +15 -136
  51. package/node_modules/@types/node/stream/web.d.ts +502 -176
  52. package/node_modules/@types/node/stream.d.ts +475 -581
  53. package/node_modules/@types/node/string_decoder.d.ts +4 -4
  54. package/node_modules/@types/node/test.d.ts +196 -308
  55. package/node_modules/@types/node/timers/promises.d.ts +4 -4
  56. package/node_modules/@types/node/timers.d.ts +132 -4
  57. package/node_modules/@types/node/tls.d.ts +226 -110
  58. package/node_modules/@types/node/trace_events.d.ts +9 -9
  59. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +7 -1
  60. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -2
  61. package/node_modules/@types/node/ts5.6/index.d.ts +6 -26
  62. package/node_modules/@types/node/tty.d.ts +16 -58
  63. package/node_modules/@types/node/url.d.ts +573 -130
  64. package/node_modules/@types/node/util.d.ts +1100 -181
  65. package/node_modules/@types/node/v8.d.ts +8 -76
  66. package/node_modules/@types/node/vm.d.ts +72 -280
  67. package/node_modules/@types/node/wasi.d.ts +4 -25
  68. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +2 -27
  69. package/node_modules/@types/node/web-globals/events.d.ts +0 -9
  70. package/node_modules/@types/node/web-globals/fetch.d.ts +0 -14
  71. package/node_modules/@types/node/web-globals/navigator.d.ts +0 -3
  72. package/node_modules/@types/node/worker_threads.d.ts +335 -268
  73. package/node_modules/@types/node/zlib.d.ts +74 -9
  74. package/node_modules/undici-types/agent.d.ts +12 -13
  75. package/node_modules/undici-types/api.d.ts +26 -26
  76. package/node_modules/undici-types/balanced-pool.d.ts +12 -13
  77. package/node_modules/undici-types/client.d.ts +19 -19
  78. package/node_modules/undici-types/connector.d.ts +2 -2
  79. package/node_modules/undici-types/cookies.d.ts +0 -2
  80. package/node_modules/undici-types/diagnostics-channel.d.ts +10 -18
  81. package/node_modules/undici-types/dispatcher.d.ts +103 -123
  82. package/node_modules/undici-types/env-http-proxy-agent.d.ts +3 -4
  83. package/node_modules/undici-types/errors.d.ts +54 -66
  84. package/node_modules/undici-types/eventsource.d.ts +4 -9
  85. package/node_modules/undici-types/fetch.d.ts +20 -22
  86. package/node_modules/undici-types/file.d.ts +39 -0
  87. package/node_modules/undici-types/filereader.d.ts +54 -0
  88. package/node_modules/undici-types/formdata.d.ts +7 -7
  89. package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
  90. package/node_modules/undici-types/global-origin.d.ts +5 -5
  91. package/node_modules/undici-types/handlers.d.ts +8 -8
  92. package/node_modules/undici-types/header.d.ts +1 -157
  93. package/node_modules/undici-types/index.d.ts +47 -64
  94. package/node_modules/undici-types/interceptors.d.ts +8 -64
  95. package/node_modules/undici-types/mock-agent.d.ts +18 -36
  96. package/node_modules/undici-types/mock-client.d.ts +4 -6
  97. package/node_modules/undici-types/mock-errors.d.ts +3 -3
  98. package/node_modules/undici-types/mock-interceptor.d.ts +20 -21
  99. package/node_modules/undici-types/mock-pool.d.ts +4 -6
  100. package/node_modules/undici-types/package.json +1 -1
  101. package/node_modules/undici-types/patch.d.ts +4 -0
  102. package/node_modules/undici-types/pool-stats.d.ts +8 -8
  103. package/node_modules/undici-types/pool.d.ts +13 -15
  104. package/node_modules/undici-types/proxy-agent.d.ts +4 -5
  105. package/node_modules/undici-types/readable.d.ts +16 -19
  106. package/node_modules/undici-types/retry-agent.d.ts +1 -1
  107. package/node_modules/undici-types/retry-handler.d.ts +10 -19
  108. package/node_modules/undici-types/util.d.ts +3 -3
  109. package/node_modules/undici-types/webidl.d.ts +29 -142
  110. package/node_modules/undici-types/websocket.d.ts +10 -46
  111. package/package.json +2 -1
  112. package/skills/cleave/SKILL.md +62 -2
  113. package/node_modules/@types/node/inspector/promises.d.ts +0 -41
  114. package/node_modules/@types/node/path/posix.d.ts +0 -8
  115. package/node_modules/@types/node/path/win32.d.ts +0 -8
  116. package/node_modules/@types/node/quic.d.ts +0 -910
  117. package/node_modules/@types/node/test/reporters.d.ts +0 -96
  118. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +0 -71
  119. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +0 -72
  120. package/node_modules/@types/node/ts5.7/index.d.ts +0 -117
  121. package/node_modules/@types/node/util/types.d.ts +0 -558
  122. package/node_modules/@types/node/web-globals/blob.d.ts +0 -23
  123. package/node_modules/@types/node/web-globals/console.d.ts +0 -9
  124. package/node_modules/@types/node/web-globals/crypto.d.ts +0 -39
  125. package/node_modules/@types/node/web-globals/encoding.d.ts +0 -11
  126. package/node_modules/@types/node/web-globals/importmeta.d.ts +0 -13
  127. package/node_modules/@types/node/web-globals/messaging.d.ts +0 -23
  128. package/node_modules/@types/node/web-globals/performance.d.ts +0 -45
  129. package/node_modules/@types/node/web-globals/streams.d.ts +0 -115
  130. package/node_modules/@types/node/web-globals/timers.d.ts +0 -44
  131. package/node_modules/@types/node/web-globals/url.d.ts +0 -24
  132. package/node_modules/undici-types/cache-interceptor.d.ts +0 -173
  133. package/node_modules/undici-types/client-stats.d.ts +0 -15
  134. package/node_modules/undici-types/h2c-client.d.ts +0 -73
  135. package/node_modules/undici-types/mock-call-history.d.ts +0 -111
  136. package/node_modules/undici-types/round-robin-pool.d.ts +0 -41
  137. package/node_modules/undici-types/snapshot-agent.d.ts +0 -109
  138. package/node_modules/undici-types/utility.d.ts +0 -7
@@ -32,47 +32,58 @@
32
32
  * });
33
33
  * myEmitter.emit('event');
34
34
  * ```
35
- * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/events.js)
35
+ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/events.js)
36
36
  */
37
- declare module "node:events" {
37
+ declare module "events" {
38
38
  import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
39
- // #region Event map helpers
40
- type EventMap<T> = Record<keyof T, any[]>;
41
- type IfEventMap<Events extends EventMap<Events>, True, False> = {} extends Events ? False : True;
42
- type Args<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
43
- Events,
44
- EventName extends keyof Events ? Events[EventName]
45
- : EventName extends keyof EventEmitterEventMap ? EventEmitterEventMap[EventName]
46
- : any[],
47
- any[]
48
- >;
49
- type EventNames<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
50
- Events,
51
- EventName | (keyof Events & (string | symbol)) | keyof EventEmitterEventMap,
52
- string | symbol
53
- >;
54
- type Listener<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
55
- Events,
56
- (
57
- ...args: EventName extends keyof Events ? Events[EventName]
58
- : EventName extends keyof EventEmitterEventMap ? EventEmitterEventMap[EventName]
59
- : any[]
60
- ) => void,
61
- (...args: any[]) => void
62
- >;
63
- interface EventEmitterEventMap {
64
- newListener: [eventName: string | symbol, listener: (...args: any[]) => void];
65
- removeListener: [eventName: string | symbol, listener: (...args: any[]) => void];
66
- }
67
- // #endregion
68
39
  interface EventEmitterOptions {
69
40
  /**
70
- * It enables
71
- * [automatic capturing of promise rejection](https://nodejs.org/docs/latest-v25.x/api/events.html#capture-rejections-of-promises).
72
- * @default false
41
+ * Enables automatic capturing of promise rejection.
73
42
  */
74
43
  captureRejections?: boolean | undefined;
75
44
  }
45
+ interface StaticEventEmitterOptions {
46
+ /**
47
+ * Can be used to cancel awaiting events.
48
+ */
49
+ signal?: AbortSignal | undefined;
50
+ }
51
+ interface StaticEventEmitterIteratorOptions extends StaticEventEmitterOptions {
52
+ /**
53
+ * Names of events that will end the iteration.
54
+ */
55
+ close?: string[] | undefined;
56
+ /**
57
+ * The high watermark. The emitter is paused every time the size of events being buffered is higher than it.
58
+ * Supported only on emitters implementing `pause()` and `resume()` methods.
59
+ * @default Number.MAX_SAFE_INTEGER
60
+ */
61
+ highWaterMark?: number | undefined;
62
+ /**
63
+ * The low watermark. The emitter is resumed every time the size of events being buffered is lower than it.
64
+ * Supported only on emitters implementing `pause()` and `resume()` methods.
65
+ * @default 1
66
+ */
67
+ lowWaterMark?: number | undefined;
68
+ }
69
+ interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
70
+ type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
71
+ type DefaultEventMap = [never];
72
+ type AnyRest = [...args: any[]];
73
+ type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
74
+ K extends keyof T ? T[K] : never
75
+ );
76
+ type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
77
+ type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
78
+ type Listener<K, T, F> = T extends DefaultEventMap ? F : (
79
+ K extends keyof T ? (
80
+ T[K] extends unknown[] ? (...args: T[K]) => void : never
81
+ )
82
+ : never
83
+ );
84
+ type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
85
+ type Listener2<K, T> = Listener<K, T, Function>;
86
+
76
87
  /**
77
88
  * The `EventEmitter` class is defined and exposed by the `node:events` module:
78
89
  *
@@ -86,589 +97,96 @@ declare module "node:events" {
86
97
  * It supports the following option:
87
98
  * @since v0.1.26
88
99
  */
89
- class EventEmitter<T extends EventMap<T> = any> {
100
+ class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
90
101
  constructor(options?: EventEmitterOptions);
91
- }
92
- interface EventEmitter<T extends EventMap<T> = any> extends NodeJS.EventEmitter<T> {}
93
- global {
94
- namespace NodeJS {
95
- interface EventEmitter<T extends EventMap<T> = any> {
96
- /**
97
- * The `Symbol.for('nodejs.rejection')` method is called in case a
98
- * promise rejection happens when emitting an event and
99
- * `captureRejections` is enabled on the emitter.
100
- * It is possible to use `events.captureRejectionSymbol` in
101
- * place of `Symbol.for('nodejs.rejection')`.
102
- *
103
- * ```js
104
- * import { EventEmitter, captureRejectionSymbol } from 'node:events';
105
- *
106
- * class MyClass extends EventEmitter {
107
- * constructor() {
108
- * super({ captureRejections: true });
109
- * }
110
- *
111
- * [captureRejectionSymbol](err, event, ...args) {
112
- * console.log('rejection happened for', event, 'with', err, ...args);
113
- * this.destroy(err);
114
- * }
115
- *
116
- * destroy(err) {
117
- * // Tear the resource down here.
118
- * }
119
- * }
120
- * ```
121
- * @since v13.4.0, v12.16.0
122
- */
123
- [EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
124
- /**
125
- * Alias for `emitter.on(eventName, listener)`.
126
- * @since v0.1.26
127
- */
128
- addListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
129
- /**
130
- * Synchronously calls each of the listeners registered for the event named
131
- * `eventName`, in the order they were registered, passing the supplied arguments
132
- * to each.
133
- *
134
- * Returns `true` if the event had listeners, `false` otherwise.
135
- *
136
- * ```js
137
- * import { EventEmitter } from 'node:events';
138
- * const myEmitter = new EventEmitter();
139
- *
140
- * // First listener
141
- * myEmitter.on('event', function firstListener() {
142
- * console.log('Helloooo! first listener');
143
- * });
144
- * // Second listener
145
- * myEmitter.on('event', function secondListener(arg1, arg2) {
146
- * console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
147
- * });
148
- * // Third listener
149
- * myEmitter.on('event', function thirdListener(...args) {
150
- * const parameters = args.join(', ');
151
- * console.log(`event with parameters ${parameters} in third listener`);
152
- * });
153
- *
154
- * console.log(myEmitter.listeners('event'));
155
- *
156
- * myEmitter.emit('event', 1, 2, 3, 4, 5);
157
- *
158
- * // Prints:
159
- * // [
160
- * // [Function: firstListener],
161
- * // [Function: secondListener],
162
- * // [Function: thirdListener]
163
- * // ]
164
- * // Helloooo! first listener
165
- * // event with parameters 1, 2 in second listener
166
- * // event with parameters 1, 2, 3, 4, 5 in third listener
167
- * ```
168
- * @since v0.1.26
169
- */
170
- emit<E extends string | symbol>(eventName: EventNames<T, E>, ...args: Args<T, E>): boolean;
171
- /**
172
- * Returns an array listing the events for which the emitter has registered
173
- * listeners.
174
- *
175
- * ```js
176
- * import { EventEmitter } from 'node:events';
177
- *
178
- * const myEE = new EventEmitter();
179
- * myEE.on('foo', () => {});
180
- * myEE.on('bar', () => {});
181
- *
182
- * const sym = Symbol('symbol');
183
- * myEE.on(sym, () => {});
184
- *
185
- * console.log(myEE.eventNames());
186
- * // Prints: [ 'foo', 'bar', Symbol(symbol) ]
187
- * ```
188
- * @since v6.0.0
189
- */
190
- eventNames(): (string | symbol)[];
191
- /**
192
- * Returns the current max listener value for the `EventEmitter` which is either
193
- * set by `emitter.setMaxListeners(n)` or defaults to
194
- * `events.defaultMaxListeners`.
195
- * @since v1.0.0
196
- */
197
- getMaxListeners(): number;
198
- /**
199
- * Returns the number of listeners listening for the event named `eventName`.
200
- * If `listener` is provided, it will return how many times the listener is found
201
- * in the list of the listeners of the event.
202
- * @since v3.2.0
203
- * @param eventName The name of the event being listened for
204
- * @param listener The event handler function
205
- */
206
- listenerCount<E extends string | symbol>(
207
- eventName: EventNames<T, E>,
208
- listener?: Listener<T, E>,
209
- ): number;
210
- /**
211
- * Returns a copy of the array of listeners for the event named `eventName`.
212
- *
213
- * ```js
214
- * server.on('connection', (stream) => {
215
- * console.log('someone connected!');
216
- * });
217
- * console.log(util.inspect(server.listeners('connection')));
218
- * // Prints: [ [Function] ]
219
- * ```
220
- * @since v0.1.26
221
- */
222
- listeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
223
- /**
224
- * Alias for `emitter.removeListener()`.
225
- * @since v10.0.0
226
- */
227
- off<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
228
- /**
229
- * Adds the `listener` function to the end of the listeners array for the
230
- * event named `eventName`. No checks are made to see if the `listener` has
231
- * already been added. Multiple calls passing the same combination of `eventName`
232
- * and `listener` will result in the `listener` being added, and called, multiple
233
- * times.
234
- *
235
- * ```js
236
- * server.on('connection', (stream) => {
237
- * console.log('someone connected!');
238
- * });
239
- * ```
240
- *
241
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
242
- *
243
- * By default, event listeners are invoked in the order they are added. The
244
- * `emitter.prependListener()` method can be used as an alternative to add the
245
- * event listener to the beginning of the listeners array.
246
- *
247
- * ```js
248
- * import { EventEmitter } from 'node:events';
249
- * const myEE = new EventEmitter();
250
- * myEE.on('foo', () => console.log('a'));
251
- * myEE.prependListener('foo', () => console.log('b'));
252
- * myEE.emit('foo');
253
- * // Prints:
254
- * // b
255
- * // a
256
- * ```
257
- * @since v0.1.101
258
- * @param eventName The name of the event.
259
- * @param listener The callback function
260
- */
261
- on<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
262
- /**
263
- * Adds a **one-time** `listener` function for the event named `eventName`. The
264
- * next time `eventName` is triggered, this listener is removed and then invoked.
265
- *
266
- * ```js
267
- * server.once('connection', (stream) => {
268
- * console.log('Ah, we have our first user!');
269
- * });
270
- * ```
271
- *
272
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
273
- *
274
- * By default, event listeners are invoked in the order they are added. The
275
- * `emitter.prependOnceListener()` method can be used as an alternative to add the
276
- * event listener to the beginning of the listeners array.
277
- *
278
- * ```js
279
- * import { EventEmitter } from 'node:events';
280
- * const myEE = new EventEmitter();
281
- * myEE.once('foo', () => console.log('a'));
282
- * myEE.prependOnceListener('foo', () => console.log('b'));
283
- * myEE.emit('foo');
284
- * // Prints:
285
- * // b
286
- * // a
287
- * ```
288
- * @since v0.3.0
289
- * @param eventName The name of the event.
290
- * @param listener The callback function
291
- */
292
- once<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
293
- /**
294
- * Adds the `listener` function to the _beginning_ of the listeners array for the
295
- * event named `eventName`. No checks are made to see if the `listener` has
296
- * already been added. Multiple calls passing the same combination of `eventName`
297
- * and `listener` will result in the `listener` being added, and called, multiple
298
- * times.
299
- *
300
- * ```js
301
- * server.prependListener('connection', (stream) => {
302
- * console.log('someone connected!');
303
- * });
304
- * ```
305
- *
306
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
307
- * @since v6.0.0
308
- * @param eventName The name of the event.
309
- * @param listener The callback function
310
- */
311
- prependListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
312
- /**
313
- * Adds a **one-time** `listener` function for the event named `eventName` to the
314
- * _beginning_ of the listeners array. The next time `eventName` is triggered, this
315
- * listener is removed, and then invoked.
316
- *
317
- * ```js
318
- * server.prependOnceListener('connection', (stream) => {
319
- * console.log('Ah, we have our first user!');
320
- * });
321
- * ```
322
- *
323
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
324
- * @since v6.0.0
325
- * @param eventName The name of the event.
326
- * @param listener The callback function
327
- */
328
- prependOnceListener<E extends string | symbol>(
329
- eventName: EventNames<T, E>,
330
- listener: Listener<T, E>,
331
- ): this;
332
- /**
333
- * Returns a copy of the array of listeners for the event named `eventName`,
334
- * including any wrappers (such as those created by `.once()`).
335
- *
336
- * ```js
337
- * import { EventEmitter } from 'node:events';
338
- * const emitter = new EventEmitter();
339
- * emitter.once('log', () => console.log('log once'));
340
- *
341
- * // Returns a new Array with a function `onceWrapper` which has a property
342
- * // `listener` which contains the original listener bound above
343
- * const listeners = emitter.rawListeners('log');
344
- * const logFnWrapper = listeners[0];
345
- *
346
- * // Logs "log once" to the console and does not unbind the `once` event
347
- * logFnWrapper.listener();
348
- *
349
- * // Logs "log once" to the console and removes the listener
350
- * logFnWrapper();
351
- *
352
- * emitter.on('log', () => console.log('log persistently'));
353
- * // Will return a new Array with a single function bound by `.on()` above
354
- * const newListeners = emitter.rawListeners('log');
355
- *
356
- * // Logs "log persistently" twice
357
- * newListeners[0]();
358
- * emitter.emit('log');
359
- * ```
360
- * @since v9.4.0
361
- */
362
- rawListeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
363
- /**
364
- * Removes all listeners, or those of the specified `eventName`.
365
- *
366
- * It is bad practice to remove listeners added elsewhere in the code,
367
- * particularly when the `EventEmitter` instance was created by some other
368
- * component or module (e.g. sockets or file streams).
369
- *
370
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
371
- * @since v0.1.26
372
- */
373
- // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
374
- removeAllListeners<E extends string | symbol>(eventName?: EventNames<T, E>): this;
375
- /**
376
- * Removes the specified `listener` from the listener array for the event named
377
- * `eventName`.
378
- *
379
- * ```js
380
- * const callback = (stream) => {
381
- * console.log('someone connected!');
382
- * };
383
- * server.on('connection', callback);
384
- * // ...
385
- * server.removeListener('connection', callback);
386
- * ```
387
- *
388
- * `removeListener()` will remove, at most, one instance of a listener from the
389
- * listener array. If any single listener has been added multiple times to the
390
- * listener array for the specified `eventName`, then `removeListener()` must be
391
- * called multiple times to remove each instance.
392
- *
393
- * Once an event is emitted, all listeners attached to it at the
394
- * time of emitting are called in order. This implies that any
395
- * `removeListener()` or `removeAllListeners()` calls _after_ emitting and
396
- * _before_ the last listener finishes execution will not remove them from
397
- * `emit()` in progress. Subsequent events behave as expected.
398
- *
399
- * ```js
400
- * import { EventEmitter } from 'node:events';
401
- * class MyEmitter extends EventEmitter {}
402
- * const myEmitter = new MyEmitter();
403
- *
404
- * const callbackA = () => {
405
- * console.log('A');
406
- * myEmitter.removeListener('event', callbackB);
407
- * };
408
- *
409
- * const callbackB = () => {
410
- * console.log('B');
411
- * };
412
- *
413
- * myEmitter.on('event', callbackA);
414
- *
415
- * myEmitter.on('event', callbackB);
416
- *
417
- * // callbackA removes listener callbackB but it will still be called.
418
- * // Internal listener array at time of emit [callbackA, callbackB]
419
- * myEmitter.emit('event');
420
- * // Prints:
421
- * // A
422
- * // B
423
- *
424
- * // callbackB is now removed.
425
- * // Internal listener array [callbackA]
426
- * myEmitter.emit('event');
427
- * // Prints:
428
- * // A
429
- * ```
430
- *
431
- * Because listeners are managed using an internal array, calling this will
432
- * change the position indexes of any listener registered _after_ the listener
433
- * being removed. This will not impact the order in which listeners are called,
434
- * but it means that any copies of the listener array as returned by
435
- * the `emitter.listeners()` method will need to be recreated.
436
- *
437
- * When a single function has been added as a handler multiple times for a single
438
- * event (as in the example below), `removeListener()` will remove the most
439
- * recently added instance. In the example the `once('ping')`
440
- * listener is removed:
441
- *
442
- * ```js
443
- * import { EventEmitter } from 'node:events';
444
- * const ee = new EventEmitter();
445
- *
446
- * function pong() {
447
- * console.log('pong');
448
- * }
449
- *
450
- * ee.on('ping', pong);
451
- * ee.once('ping', pong);
452
- * ee.removeListener('ping', pong);
453
- *
454
- * ee.emit('ping');
455
- * ee.emit('ping');
456
- * ```
457
- *
458
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
459
- * @since v0.1.26
460
- */
461
- removeListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
462
- /**
463
- * By default `EventEmitter`s will print a warning if more than `10` listeners are
464
- * added for a particular event. This is a useful default that helps finding
465
- * memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
466
- * modified for this specific `EventEmitter` instance. The value can be set to
467
- * `Infinity` (or `0`) to indicate an unlimited number of listeners.
468
- *
469
- * Returns a reference to the `EventEmitter`, so that calls can be chained.
470
- * @since v0.3.5
471
- */
472
- setMaxListeners(n: number): this;
473
- }
474
- }
475
- }
476
- namespace EventEmitter {
477
- export { EventEmitter, EventEmitterEventMap, EventEmitterOptions };
478
- }
479
- namespace EventEmitter {
480
- interface Abortable {
481
- signal?: AbortSignal | undefined;
482
- }
483
- /**
484
- * See how to write a custom [rejection handler](https://nodejs.org/docs/latest-v25.x/api/events.html#emittersymbolfornodejsrejectionerr-eventname-args).
485
- * @since v13.4.0, v12.16.0
486
- */
487
- const captureRejectionSymbol: unique symbol;
488
- /**
489
- * Change the default `captureRejections` option on all new `EventEmitter` objects.
490
- * @since v13.4.0, v12.16.0
491
- */
492
- let captureRejections: boolean;
102
+
103
+ [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
104
+
493
105
  /**
494
- * By default, a maximum of `10` listeners can be registered for any single
495
- * event. This limit can be changed for individual `EventEmitter` instances
496
- * using the `emitter.setMaxListeners(n)` method. To change the default
497
- * for _all_ `EventEmitter` instances, the `events.defaultMaxListeners`
498
- * property can be used. If this value is not a positive number, a `RangeError`
499
- * is thrown.
500
- *
501
- * Take caution when setting the `events.defaultMaxListeners` because the
502
- * change affects _all_ `EventEmitter` instances, including those created before
503
- * the change is made. However, calling `emitter.setMaxListeners(n)` still has
504
- * precedence over `events.defaultMaxListeners`.
505
- *
506
- * This is not a hard limit. The `EventEmitter` instance will allow
507
- * more listeners to be added but will output a trace warning to stderr indicating
508
- * that a "possible EventEmitter memory leak" has been detected. For any single
509
- * `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()`
510
- * methods can be used to temporarily avoid this warning:
106
+ * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
107
+ * event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
108
+ * The `Promise` will resolve with an array of all the arguments emitted to the
109
+ * given event.
511
110
  *
512
- * `defaultMaxListeners` has no effect on `AbortSignal` instances. While it is
513
- * still possible to use `emitter.setMaxListeners(n)` to set a warning limit
514
- * for individual `AbortSignal` instances, per default `AbortSignal` instances will not warn.
111
+ * This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
112
+ * semantics and does not listen to the `'error'` event.
515
113
  *
516
114
  * ```js
517
- * import { EventEmitter } from 'node:events';
518
- * const emitter = new EventEmitter();
519
- * emitter.setMaxListeners(emitter.getMaxListeners() + 1);
520
- * emitter.once('event', () => {
521
- * // do stuff
522
- * emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
523
- * });
524
- * ```
115
+ * import { once, EventEmitter } from 'node:events';
116
+ * import process from 'node:process';
525
117
  *
526
- * The `--trace-warnings` command-line flag can be used to display the
527
- * stack trace for such warnings.
118
+ * const ee = new EventEmitter();
528
119
  *
529
- * The emitted warning can be inspected with `process.on('warning')` and will
530
- * have the additional `emitter`, `type`, and `count` properties, referring to
531
- * the event emitter instance, the event's name and the number of attached
532
- * listeners, respectively.
533
- * Its `name` property is set to `'MaxListenersExceededWarning'`.
534
- * @since v0.11.2
535
- */
536
- let defaultMaxListeners: number;
537
- /**
538
- * This symbol shall be used to install a listener for only monitoring `'error'`
539
- * events. Listeners installed using this symbol are called before the regular
540
- * `'error'` listeners are called.
120
+ * process.nextTick(() => {
121
+ * ee.emit('myevent', 42);
122
+ * });
541
123
  *
542
- * Installing a listener using this symbol does not change the behavior once an
543
- * `'error'` event is emitted. Therefore, the process will still crash if no
544
- * regular `'error'` listener is installed.
545
- * @since v13.6.0, v12.17.0
546
- */
547
- const errorMonitor: unique symbol;
548
- /**
549
- * Listens once to the `abort` event on the provided `signal`.
124
+ * const [value] = await once(ee, 'myevent');
125
+ * console.log(value);
550
126
  *
551
- * Listening to the `abort` event on abort signals is unsafe and may
552
- * lead to resource leaks since another third party with the signal can
553
- * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
554
- * this since it would violate the web standard. Additionally, the original
555
- * API makes it easy to forget to remove listeners.
127
+ * const err = new Error('kaboom');
128
+ * process.nextTick(() => {
129
+ * ee.emit('error', err);
130
+ * });
556
131
  *
557
- * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
558
- * two issues by listening to the event such that `stopImmediatePropagation` does
559
- * not prevent the listener from running.
132
+ * try {
133
+ * await once(ee, 'myevent');
134
+ * } catch (err) {
135
+ * console.error('error happened', err);
136
+ * }
137
+ * ```
560
138
  *
561
- * Returns a disposable so that it may be unsubscribed from more easily.
139
+ * The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the
140
+ * '`error'` event itself, then it is treated as any other kind of event without
141
+ * special handling:
562
142
  *
563
143
  * ```js
564
- * import { addAbortListener } from 'node:events';
565
- *
566
- * function example(signal) {
567
- * let disposable;
568
- * try {
569
- * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
570
- * disposable = addAbortListener(signal, (e) => {
571
- * // Do something when signal is aborted.
572
- * });
573
- * } finally {
574
- * disposable?.[Symbol.dispose]();
575
- * }
576
- * }
577
- * ```
578
- * @since v20.5.0
579
- * @return Disposable that removes the `abort` listener.
580
- */
581
- function addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
582
- /**
583
- * Returns a copy of the array of listeners for the event named `eventName`.
144
+ * import { EventEmitter, once } from 'node:events';
584
145
  *
585
- * For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
586
- * the emitter.
146
+ * const ee = new EventEmitter();
587
147
  *
588
- * For `EventTarget`s this is the only way to get the event listeners for the
589
- * event target. This is useful for debugging and diagnostic purposes.
148
+ * once(ee, 'error')
149
+ * .then(([err]) => console.log('ok', err.message))
150
+ * .catch((err) => console.error('error', err.message));
590
151
  *
591
- * ```js
592
- * import { getEventListeners, EventEmitter } from 'node:events';
152
+ * ee.emit('error', new Error('boom'));
593
153
  *
594
- * {
595
- * const ee = new EventEmitter();
596
- * const listener = () => console.log('Events are fun');
597
- * ee.on('foo', listener);
598
- * console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
599
- * }
600
- * {
601
- * const et = new EventTarget();
602
- * const listener = () => console.log('Events are fun');
603
- * et.addEventListener('foo', listener);
604
- * console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
605
- * }
154
+ * // Prints: ok boom
606
155
  * ```
607
- * @since v15.2.0, v14.17.0
608
- */
609
- function getEventListeners(emitter: EventEmitter, name: string | symbol): ((...args: any[]) => void)[];
610
- function getEventListeners(emitter: EventTarget, name: string): ((...args: any[]) => void)[];
611
- /**
612
- * Returns the currently set max amount of listeners.
613
- *
614
- * For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
615
- * the emitter.
616
156
  *
617
- * For `EventTarget`s this is the only way to get the max event listeners for the
618
- * event target. If the number of event handlers on a single EventTarget exceeds
619
- * the max set, the EventTarget will print a warning.
157
+ * An `AbortSignal` can be used to cancel waiting for the event:
620
158
  *
621
159
  * ```js
622
- * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
160
+ * import { EventEmitter, once } from 'node:events';
623
161
  *
624
- * {
625
- * const ee = new EventEmitter();
626
- * console.log(getMaxListeners(ee)); // 10
627
- * setMaxListeners(11, ee);
628
- * console.log(getMaxListeners(ee)); // 11
629
- * }
630
- * {
631
- * const et = new EventTarget();
632
- * console.log(getMaxListeners(et)); // 10
633
- * setMaxListeners(11, et);
634
- * console.log(getMaxListeners(et)); // 11
635
- * }
636
- * ```
637
- * @since v19.9.0
638
- */
639
- function getMaxListeners(emitter: EventEmitter | EventTarget): number;
640
- /**
641
- * Returns the number of registered listeners for the event named `eventName`.
162
+ * const ee = new EventEmitter();
163
+ * const ac = new AbortController();
642
164
  *
643
- * For `EventEmitter`s this behaves exactly the same as calling `.listenerCount`
644
- * on the emitter.
165
+ * async function foo(emitter, event, signal) {
166
+ * try {
167
+ * await once(emitter, event, { signal });
168
+ * console.log('event emitted!');
169
+ * } catch (error) {
170
+ * if (error.name === 'AbortError') {
171
+ * console.error('Waiting for the event was canceled!');
172
+ * } else {
173
+ * console.error('There was an error', error.message);
174
+ * }
175
+ * }
176
+ * }
645
177
  *
646
- * For `EventTarget`s this is the only way to obtain the listener count. This can
647
- * be useful for debugging and diagnostic purposes.
648
- * @since v0.9.12
178
+ * foo(ee, 'foo', ac.signal);
179
+ * ac.abort(); // Abort waiting for the event
180
+ * ee.emit('foo'); // Prints: Waiting for the event was canceled!
181
+ * ```
182
+ * @since v11.13.0, v10.16.0
649
183
  */
650
- function listenerCount(emitter: EventEmitter, eventName: string | symbol): number;
651
- function listenerCount(emitter: EventTarget, eventName: string): number;
652
- interface OnOptions extends Abortable {
653
- /**
654
- * Names of events that will end the iteration.
655
- */
656
- close?: readonly string[] | undefined;
657
- /**
658
- * The high watermark. The emitter is paused every time the size of events
659
- * being buffered is higher than it. Supported only on emitters implementing
660
- * `pause()` and `resume()` methods.
661
- * @default Number.MAX_SAFE_INTEGER
662
- */
663
- highWaterMark?: number | undefined;
664
- /**
665
- * The low watermark. The emitter is resumed every time the size of events
666
- * being buffered is lower than it. Supported only on emitters implementing
667
- * `pause()` and `resume()` methods.
668
- * @default 1
669
- */
670
- lowWaterMark?: number | undefined;
671
- }
184
+ static once(
185
+ emitter: NodeJS.EventEmitter,
186
+ eventName: string | symbol,
187
+ options?: StaticEventEmitterOptions,
188
+ ): Promise<any[]>;
189
+ static once(emitter: EventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
672
190
  /**
673
191
  * ```js
674
192
  * import { on, EventEmitter } from 'node:events';
@@ -724,106 +242,116 @@ declare module "node:events" {
724
242
  *
725
243
  * process.nextTick(() => ac.abort());
726
244
  * ```
727
- * @since v13.6.0, v12.16.0
728
- * @returns `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
729
- */
730
- function on(
731
- emitter: EventEmitter,
732
- eventName: string | symbol,
733
- options?: OnOptions,
734
- ): NodeJS.AsyncIterator<any[]>;
735
- function on(
736
- emitter: EventTarget,
737
- eventName: string,
738
- options?: OnOptions,
739
- ): NodeJS.AsyncIterator<any[]>;
740
- interface OnceOptions extends Abortable {}
741
- /**
742
- * Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
743
- * event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
744
- * The `Promise` will resolve with an array of all the arguments emitted to the
745
- * given event.
746
245
  *
747
- * This method is intentionally generic and works with the web platform
748
- * [EventTarget][WHATWG-EventTarget] interface, which has no special
749
- * `'error'` event semantics and does not listen to the `'error'` event.
246
+ * Use the `close` option to specify an array of event names that will end the iteration:
750
247
  *
751
248
  * ```js
752
- * import { once, EventEmitter } from 'node:events';
249
+ * import { on, EventEmitter } from 'node:events';
753
250
  * import process from 'node:process';
754
251
  *
755
252
  * const ee = new EventEmitter();
756
253
  *
254
+ * // Emit later on
757
255
  * process.nextTick(() => {
758
- * ee.emit('myevent', 42);
759
- * });
760
- *
761
- * const [value] = await once(ee, 'myevent');
762
- * console.log(value);
763
- *
764
- * const err = new Error('kaboom');
765
- * process.nextTick(() => {
766
- * ee.emit('error', err);
256
+ * ee.emit('foo', 'bar');
257
+ * ee.emit('foo', 42);
258
+ * ee.emit('close');
767
259
  * });
768
260
  *
769
- * try {
770
- * await once(ee, 'myevent');
771
- * } catch (err) {
772
- * console.error('error happened', err);
261
+ * for await (const event of on(ee, 'foo', { close: ['close'] })) {
262
+ * console.log(event); // prints ['bar'] [42]
773
263
  * }
264
+ * // the loop will exit after 'close' is emitted
265
+ * console.log('done'); // prints 'done'
774
266
  * ```
775
- *
776
- * The special handling of the `'error'` event is only used when `events.once()`
777
- * is used to wait for another event. If `events.once()` is used to wait for the
778
- * '`error'` event itself, then it is treated as any other kind of event without
779
- * special handling:
267
+ * @since v13.6.0, v12.16.0
268
+ * @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
269
+ */
270
+ static on(
271
+ emitter: NodeJS.EventEmitter,
272
+ eventName: string | symbol,
273
+ options?: StaticEventEmitterIteratorOptions,
274
+ ): NodeJS.AsyncIterator<any[]>;
275
+ static on(
276
+ emitter: EventTarget,
277
+ eventName: string,
278
+ options?: StaticEventEmitterIteratorOptions,
279
+ ): NodeJS.AsyncIterator<any[]>;
280
+ /**
281
+ * A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
780
282
  *
781
283
  * ```js
782
- * import { EventEmitter, once } from 'node:events';
284
+ * import { EventEmitter, listenerCount } from 'node:events';
783
285
  *
784
- * const ee = new EventEmitter();
286
+ * const myEmitter = new EventEmitter();
287
+ * myEmitter.on('event', () => {});
288
+ * myEmitter.on('event', () => {});
289
+ * console.log(listenerCount(myEmitter, 'event'));
290
+ * // Prints: 2
291
+ * ```
292
+ * @since v0.9.12
293
+ * @deprecated Since v3.2.0 - Use `listenerCount` instead.
294
+ * @param emitter The emitter to query
295
+ * @param eventName The event name
296
+ */
297
+ static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
298
+ /**
299
+ * Returns a copy of the array of listeners for the event named `eventName`.
785
300
  *
786
- * once(ee, 'error')
787
- * .then(([err]) => console.log('ok', err.message))
788
- * .catch((err) => console.error('error', err.message));
301
+ * For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
302
+ * the emitter.
789
303
  *
790
- * ee.emit('error', new Error('boom'));
304
+ * For `EventTarget`s this is the only way to get the event listeners for the
305
+ * event target. This is useful for debugging and diagnostic purposes.
791
306
  *
792
- * // Prints: ok boom
307
+ * ```js
308
+ * import { getEventListeners, EventEmitter } from 'node:events';
309
+ *
310
+ * {
311
+ * const ee = new EventEmitter();
312
+ * const listener = () => console.log('Events are fun');
313
+ * ee.on('foo', listener);
314
+ * console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
315
+ * }
316
+ * {
317
+ * const et = new EventTarget();
318
+ * const listener = () => console.log('Events are fun');
319
+ * et.addEventListener('foo', listener);
320
+ * console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
321
+ * }
793
322
  * ```
323
+ * @since v15.2.0, v14.17.0
324
+ */
325
+ static getEventListeners(emitter: EventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
326
+ /**
327
+ * Returns the currently set max amount of listeners.
794
328
  *
795
- * An `AbortSignal` can be used to cancel waiting for the event:
329
+ * For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
330
+ * the emitter.
796
331
  *
797
- * ```js
798
- * import { EventEmitter, once } from 'node:events';
332
+ * For `EventTarget`s this is the only way to get the max event listeners for the
333
+ * event target. If the number of event handlers on a single EventTarget exceeds
334
+ * the max set, the EventTarget will print a warning.
799
335
  *
800
- * const ee = new EventEmitter();
801
- * const ac = new AbortController();
336
+ * ```js
337
+ * import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
802
338
  *
803
- * async function foo(emitter, event, signal) {
804
- * try {
805
- * await once(emitter, event, { signal });
806
- * console.log('event emitted!');
807
- * } catch (error) {
808
- * if (error.name === 'AbortError') {
809
- * console.error('Waiting for the event was canceled!');
810
- * } else {
811
- * console.error('There was an error', error.message);
812
- * }
813
- * }
339
+ * {
340
+ * const ee = new EventEmitter();
341
+ * console.log(getMaxListeners(ee)); // 10
342
+ * setMaxListeners(11, ee);
343
+ * console.log(getMaxListeners(ee)); // 11
344
+ * }
345
+ * {
346
+ * const et = new EventTarget();
347
+ * console.log(getMaxListeners(et)); // 10
348
+ * setMaxListeners(11, et);
349
+ * console.log(getMaxListeners(et)); // 11
814
350
  * }
815
- *
816
- * foo(ee, 'foo', ac.signal);
817
- * ac.abort(); // Prints: Waiting for the event was canceled!
818
351
  * ```
819
- * @since v11.13.0, v10.16.0
352
+ * @since v19.9.0
820
353
  */
821
- function once(
822
- emitter: EventEmitter,
823
- eventName: string | symbol,
824
- options?: OnceOptions,
825
- ): Promise<any[]>;
826
- function once(emitter: EventTarget, eventName: string, options?: OnceOptions): Promise<any[]>;
354
+ static getMaxListeners(emitter: EventTarget | NodeJS.EventEmitter): number;
827
355
  /**
828
356
  * ```js
829
357
  * import { setMaxListeners, EventEmitter } from 'node:events';
@@ -835,68 +363,134 @@ declare module "node:events" {
835
363
  * ```
836
364
  * @since v15.4.0
837
365
  * @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
838
- * @param eventTargets Zero or more `EventTarget`
839
- * or `EventEmitter` instances. If none are specified, `n` is set as the default
840
- * max for all newly created `EventTarget` and `EventEmitter` objects.
366
+ * @param eventTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter}
841
367
  * objects.
842
368
  */
843
- function setMaxListeners(n: number, ...eventTargets: ReadonlyArray<EventEmitter | EventTarget>): void;
369
+ static setMaxListeners(n?: number, ...eventTargets: Array<EventTarget | NodeJS.EventEmitter>): void;
370
+ /**
371
+ * Listens once to the `abort` event on the provided `signal`.
372
+ *
373
+ * Listening to the `abort` event on abort signals is unsafe and may
374
+ * lead to resource leaks since another third party with the signal can
375
+ * call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
376
+ * this since it would violate the web standard. Additionally, the original
377
+ * API makes it easy to forget to remove listeners.
378
+ *
379
+ * This API allows safely using `AbortSignal`s in Node.js APIs by solving these
380
+ * two issues by listening to the event such that `stopImmediatePropagation` does
381
+ * not prevent the listener from running.
382
+ *
383
+ * Returns a disposable so that it may be unsubscribed from more easily.
384
+ *
385
+ * ```js
386
+ * import { addAbortListener } from 'node:events';
387
+ *
388
+ * function example(signal) {
389
+ * let disposable;
390
+ * try {
391
+ * signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
392
+ * disposable = addAbortListener(signal, (e) => {
393
+ * // Do something when signal is aborted.
394
+ * });
395
+ * } finally {
396
+ * disposable?.[Symbol.dispose]();
397
+ * }
398
+ * }
399
+ * ```
400
+ * @since v20.5.0
401
+ * @return Disposable that removes the `abort` listener.
402
+ */
403
+ static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
404
+ /**
405
+ * This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called.
406
+ *
407
+ * Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no
408
+ * regular `'error'` listener is installed.
409
+ * @since v13.6.0, v12.17.0
410
+ */
411
+ static readonly errorMonitor: unique symbol;
412
+ /**
413
+ * Value: `Symbol.for('nodejs.rejection')`
414
+ *
415
+ * See how to write a custom `rejection handler`.
416
+ * @since v13.4.0, v12.16.0
417
+ */
418
+ static readonly captureRejectionSymbol: unique symbol;
419
+ /**
420
+ * Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
421
+ *
422
+ * Change the default `captureRejections` option on all new `EventEmitter` objects.
423
+ * @since v13.4.0, v12.16.0
424
+ */
425
+ static captureRejections: boolean;
844
426
  /**
845
- * This is the interface from which event-emitting Node.js APIs inherit in the types package.
846
- * **It is not intended for consumer use.**
847
- *
848
- * It provides event-mapped definitions similar to EventEmitter, except that its signatures
849
- * are deliberately permissive: they provide type _hinting_, but not rigid type-checking,
850
- * for compatibility reasons.
851
- *
852
- * Classes that inherit directly from EventEmitter in JavaScript can inherit directly from
853
- * this interface in the type definitions. Classes that are more than one inheritance level
854
- * away from EventEmitter (eg. `net.Socket` > `stream.Duplex` > `EventEmitter`) must instead
855
- * copy these method definitions into the derived class. Search "#region InternalEventEmitter"
856
- * for examples.
857
- * @internal
427
+ * By default, a maximum of `10` listeners can be registered for any single
428
+ * event. This limit can be changed for individual `EventEmitter` instances
429
+ * using the `emitter.setMaxListeners(n)` method. To change the default
430
+ * for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property
431
+ * can be used. If this value is not a positive number, a `RangeError` is thrown.
432
+ *
433
+ * Take caution when setting the `events.defaultMaxListeners` because the
434
+ * change affects _all_ `EventEmitter` instances, including those created before
435
+ * the change is made. However, calling `emitter.setMaxListeners(n)` still has
436
+ * precedence over `events.defaultMaxListeners`.
437
+ *
438
+ * This is not a hard limit. The `EventEmitter` instance will allow
439
+ * more listeners to be added but will output a trace warning to stderr indicating
440
+ * that a "possible EventEmitter memory leak" has been detected. For any single
441
+ * `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to
442
+ * temporarily avoid this warning:
443
+ *
444
+ * ```js
445
+ * import { EventEmitter } from 'node:events';
446
+ * const emitter = new EventEmitter();
447
+ * emitter.setMaxListeners(emitter.getMaxListeners() + 1);
448
+ * emitter.once('event', () => {
449
+ * // do stuff
450
+ * emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
451
+ * });
452
+ * ```
453
+ *
454
+ * The `--trace-warnings` command-line flag can be used to display the
455
+ * stack trace for such warnings.
456
+ *
457
+ * The emitted warning can be inspected with `process.on('warning')` and will
458
+ * have the additional `emitter`, `type`, and `count` properties, referring to
459
+ * the event emitter instance, the event's name and the number of attached
460
+ * listeners, respectively.
461
+ * Its `name` property is set to `'MaxListenersExceededWarning'`.
462
+ * @since v0.11.2
858
463
  */
859
- interface InternalEventEmitter<T extends EventMap<T>> extends EventEmitter {
860
- addListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
861
- addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
862
- emit<E extends keyof T>(eventName: E, ...args: T[E]): boolean;
863
- emit(eventName: string | symbol, ...args: any[]): boolean;
864
- listenerCount<E extends keyof T>(eventName: E, listener?: (...args: T[E]) => void): number;
865
- listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
866
- listeners<E extends keyof T>(eventName: E): ((...args: T[E]) => void)[];
867
- listeners(eventName: string | symbol): ((...args: any[]) => void)[];
868
- off<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
869
- off(eventName: string | symbol, listener: (...args: any[]) => void): this;
870
- on<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
871
- on(eventName: string | symbol, listener: (...args: any[]) => void): this;
872
- once<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
873
- once(eventName: string | symbol, listener: (...args: any[]) => void): this;
874
- prependListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
875
- prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
876
- prependOnceListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
877
- prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
878
- rawListeners<E extends keyof T>(eventName: E): ((...args: T[E]) => void)[];
879
- rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
880
- // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
881
- removeAllListeners<E extends keyof T>(eventName?: E): this;
882
- removeAllListeners(eventName?: string | symbol): this;
883
- removeListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
884
- removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
464
+ static defaultMaxListeners: number;
465
+ }
466
+ import internal = require("node:events");
467
+ namespace EventEmitter {
468
+ // Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
469
+ export { internal as EventEmitter };
470
+ export interface Abortable {
471
+ /**
472
+ * When provided the corresponding `AbortController` can be used to cancel an asynchronous action.
473
+ */
474
+ signal?: AbortSignal | undefined;
885
475
  }
886
- interface EventEmitterReferencingAsyncResource extends AsyncResource {
476
+
477
+ export interface EventEmitterReferencingAsyncResource extends AsyncResource {
887
478
  readonly eventEmitter: EventEmitterAsyncResource;
888
479
  }
889
- interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
480
+
481
+ export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
890
482
  /**
891
- * The type of async event.
892
- * @default new.target.name
483
+ * The type of async event, this is required when instantiating `EventEmitterAsyncResource`
484
+ * directly rather than as a child class.
485
+ * @default new.target.name if instantiated as a child class.
893
486
  */
894
487
  name?: string | undefined;
895
488
  }
489
+
896
490
  /**
897
491
  * Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
898
492
  * require manual async tracking. Specifically, all events emitted by instances
899
- * of `events.EventEmitterAsyncResource` will run within its [async context](https://nodejs.org/docs/latest-v25.x/api/async_context.html).
493
+ * of `events.EventEmitterAsyncResource` will run within its `async context`.
900
494
  *
901
495
  * ```js
902
496
  * import { EventEmitterAsyncResource, EventEmitter } from 'node:events';
@@ -931,17 +525,11 @@ declare module "node:events" {
931
525
  * same options as `EventEmitter` and `AsyncResource` themselves.
932
526
  * @since v17.4.0, v16.14.0
933
527
  */
934
- class EventEmitterAsyncResource extends EventEmitter {
935
- constructor(options?: EventEmitterAsyncResourceOptions);
528
+ export class EventEmitterAsyncResource extends EventEmitter {
936
529
  /**
937
- * The unique `asyncId` assigned to the resource.
938
- */
939
- readonly asyncId: number;
940
- /**
941
- * The returned `AsyncResource` object has an additional `eventEmitter` property
942
- * that provides a reference to this `EventEmitterAsyncResource`.
530
+ * @param options Only optional in child class.
943
531
  */
944
- readonly asyncResource: EventEmitterReferencingAsyncResource;
532
+ constructor(options?: EventEmitterAsyncResourceOptions);
945
533
  /**
946
534
  * Call all `destroy` hooks. This should only ever be called once. An error will
947
535
  * be thrown if it is called more than once. This **must** be manually called. If
@@ -950,17 +538,25 @@ declare module "node:events" {
950
538
  */
951
539
  emitDestroy(): void;
952
540
  /**
953
- * The same `triggerAsyncId` that is passed to the
954
- * `AsyncResource` constructor.
541
+ * The unique `asyncId` assigned to the resource.
542
+ */
543
+ readonly asyncId: number;
544
+ /**
545
+ * The same triggerAsyncId that is passed to the AsyncResource constructor.
955
546
  */
956
547
  readonly triggerAsyncId: number;
548
+ /**
549
+ * The returned `AsyncResource` object has an additional `eventEmitter` property
550
+ * that provides a reference to this `EventEmitterAsyncResource`.
551
+ */
552
+ readonly asyncResource: EventEmitterReferencingAsyncResource;
957
553
  }
958
554
  /**
959
555
  * The `NodeEventTarget` is a Node.js-specific extension to `EventTarget`
960
556
  * that emulates a subset of the `EventEmitter` API.
961
557
  * @since v14.5.0
962
558
  */
963
- interface NodeEventTarget extends EventTarget {
559
+ export interface NodeEventTarget extends EventTarget {
964
560
  /**
965
561
  * Node.js-specific extension to the `EventTarget` class that emulates the
966
562
  * equivalent `EventEmitter` API. The only difference between `addListener()` and
@@ -1034,14 +630,347 @@ declare module "node:events" {
1034
630
  */
1035
631
  removeListener(type: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
1036
632
  }
1037
- /** @internal */
1038
- type InternalEventTargetEventProperties<T> = {
1039
- [K in keyof T & string as `on${K}`]: ((ev: T[K]) => void) | null;
1040
- };
1041
633
  }
1042
- export = EventEmitter;
1043
- }
1044
- declare module "events" {
1045
- import events = require("node:events");
634
+ global {
635
+ namespace NodeJS {
636
+ interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
637
+ [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
638
+ /**
639
+ * Alias for `emitter.on(eventName, listener)`.
640
+ * @since v0.1.26
641
+ */
642
+ addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
643
+ /**
644
+ * Adds the `listener` function to the end of the listeners array for the event
645
+ * named `eventName`. No checks are made to see if the `listener` has already
646
+ * been added. Multiple calls passing the same combination of `eventName` and
647
+ * `listener` will result in the `listener` being added, and called, multiple times.
648
+ *
649
+ * ```js
650
+ * server.on('connection', (stream) => {
651
+ * console.log('someone connected!');
652
+ * });
653
+ * ```
654
+ *
655
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
656
+ *
657
+ * By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the
658
+ * event listener to the beginning of the listeners array.
659
+ *
660
+ * ```js
661
+ * import { EventEmitter } from 'node:events';
662
+ * const myEE = new EventEmitter();
663
+ * myEE.on('foo', () => console.log('a'));
664
+ * myEE.prependListener('foo', () => console.log('b'));
665
+ * myEE.emit('foo');
666
+ * // Prints:
667
+ * // b
668
+ * // a
669
+ * ```
670
+ * @since v0.1.101
671
+ * @param eventName The name of the event.
672
+ * @param listener The callback function
673
+ */
674
+ on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
675
+ /**
676
+ * Adds a **one-time** `listener` function for the event named `eventName`. The
677
+ * next time `eventName` is triggered, this listener is removed and then invoked.
678
+ *
679
+ * ```js
680
+ * server.once('connection', (stream) => {
681
+ * console.log('Ah, we have our first user!');
682
+ * });
683
+ * ```
684
+ *
685
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
686
+ *
687
+ * By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the
688
+ * event listener to the beginning of the listeners array.
689
+ *
690
+ * ```js
691
+ * import { EventEmitter } from 'node:events';
692
+ * const myEE = new EventEmitter();
693
+ * myEE.once('foo', () => console.log('a'));
694
+ * myEE.prependOnceListener('foo', () => console.log('b'));
695
+ * myEE.emit('foo');
696
+ * // Prints:
697
+ * // b
698
+ * // a
699
+ * ```
700
+ * @since v0.3.0
701
+ * @param eventName The name of the event.
702
+ * @param listener The callback function
703
+ */
704
+ once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
705
+ /**
706
+ * Removes the specified `listener` from the listener array for the event named `eventName`.
707
+ *
708
+ * ```js
709
+ * const callback = (stream) => {
710
+ * console.log('someone connected!');
711
+ * };
712
+ * server.on('connection', callback);
713
+ * // ...
714
+ * server.removeListener('connection', callback);
715
+ * ```
716
+ *
717
+ * `removeListener()` will remove, at most, one instance of a listener from the
718
+ * listener array. If any single listener has been added multiple times to the
719
+ * listener array for the specified `eventName`, then `removeListener()` must be
720
+ * called multiple times to remove each instance.
721
+ *
722
+ * Once an event is emitted, all listeners attached to it at the
723
+ * time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
724
+ * will not remove them from`emit()` in progress. Subsequent events behave as expected.
725
+ *
726
+ * ```js
727
+ * import { EventEmitter } from 'node:events';
728
+ * class MyEmitter extends EventEmitter {}
729
+ * const myEmitter = new MyEmitter();
730
+ *
731
+ * const callbackA = () => {
732
+ * console.log('A');
733
+ * myEmitter.removeListener('event', callbackB);
734
+ * };
735
+ *
736
+ * const callbackB = () => {
737
+ * console.log('B');
738
+ * };
739
+ *
740
+ * myEmitter.on('event', callbackA);
741
+ *
742
+ * myEmitter.on('event', callbackB);
743
+ *
744
+ * // callbackA removes listener callbackB but it will still be called.
745
+ * // Internal listener array at time of emit [callbackA, callbackB]
746
+ * myEmitter.emit('event');
747
+ * // Prints:
748
+ * // A
749
+ * // B
750
+ *
751
+ * // callbackB is now removed.
752
+ * // Internal listener array [callbackA]
753
+ * myEmitter.emit('event');
754
+ * // Prints:
755
+ * // A
756
+ * ```
757
+ *
758
+ * Because listeners are managed using an internal array, calling this will
759
+ * change the position indices of any listener registered _after_ the listener
760
+ * being removed. This will not impact the order in which listeners are called,
761
+ * but it means that any copies of the listener array as returned by
762
+ * the `emitter.listeners()` method will need to be recreated.
763
+ *
764
+ * When a single function has been added as a handler multiple times for a single
765
+ * event (as in the example below), `removeListener()` will remove the most
766
+ * recently added instance. In the example the `once('ping')` listener is removed:
767
+ *
768
+ * ```js
769
+ * import { EventEmitter } from 'node:events';
770
+ * const ee = new EventEmitter();
771
+ *
772
+ * function pong() {
773
+ * console.log('pong');
774
+ * }
775
+ *
776
+ * ee.on('ping', pong);
777
+ * ee.once('ping', pong);
778
+ * ee.removeListener('ping', pong);
779
+ *
780
+ * ee.emit('ping');
781
+ * ee.emit('ping');
782
+ * ```
783
+ *
784
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
785
+ * @since v0.1.26
786
+ */
787
+ removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
788
+ /**
789
+ * Alias for `emitter.removeListener()`.
790
+ * @since v10.0.0
791
+ */
792
+ off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
793
+ /**
794
+ * Removes all listeners, or those of the specified `eventName`.
795
+ *
796
+ * It is bad practice to remove listeners added elsewhere in the code,
797
+ * particularly when the `EventEmitter` instance was created by some other
798
+ * component or module (e.g. sockets or file streams).
799
+ *
800
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
801
+ * @since v0.1.26
802
+ */
803
+ removeAllListeners(eventName?: Key<unknown, T>): this;
804
+ /**
805
+ * By default `EventEmitter`s will print a warning if more than `10` listeners are
806
+ * added for a particular event. This is a useful default that helps finding
807
+ * memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
808
+ * modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.
809
+ *
810
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
811
+ * @since v0.3.5
812
+ */
813
+ setMaxListeners(n: number): this;
814
+ /**
815
+ * Returns the current max listener value for the `EventEmitter` which is either
816
+ * set by `emitter.setMaxListeners(n)` or defaults to {@link EventEmitter.defaultMaxListeners}.
817
+ * @since v1.0.0
818
+ */
819
+ getMaxListeners(): number;
820
+ /**
821
+ * Returns a copy of the array of listeners for the event named `eventName`.
822
+ *
823
+ * ```js
824
+ * server.on('connection', (stream) => {
825
+ * console.log('someone connected!');
826
+ * });
827
+ * console.log(util.inspect(server.listeners('connection')));
828
+ * // Prints: [ [Function] ]
829
+ * ```
830
+ * @since v0.1.26
831
+ */
832
+ listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
833
+ /**
834
+ * Returns a copy of the array of listeners for the event named `eventName`,
835
+ * including any wrappers (such as those created by `.once()`).
836
+ *
837
+ * ```js
838
+ * import { EventEmitter } from 'node:events';
839
+ * const emitter = new EventEmitter();
840
+ * emitter.once('log', () => console.log('log once'));
841
+ *
842
+ * // Returns a new Array with a function `onceWrapper` which has a property
843
+ * // `listener` which contains the original listener bound above
844
+ * const listeners = emitter.rawListeners('log');
845
+ * const logFnWrapper = listeners[0];
846
+ *
847
+ * // Logs "log once" to the console and does not unbind the `once` event
848
+ * logFnWrapper.listener();
849
+ *
850
+ * // Logs "log once" to the console and removes the listener
851
+ * logFnWrapper();
852
+ *
853
+ * emitter.on('log', () => console.log('log persistently'));
854
+ * // Will return a new Array with a single function bound by `.on()` above
855
+ * const newListeners = emitter.rawListeners('log');
856
+ *
857
+ * // Logs "log persistently" twice
858
+ * newListeners[0]();
859
+ * emitter.emit('log');
860
+ * ```
861
+ * @since v9.4.0
862
+ */
863
+ rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
864
+ /**
865
+ * Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments
866
+ * to each.
867
+ *
868
+ * Returns `true` if the event had listeners, `false` otherwise.
869
+ *
870
+ * ```js
871
+ * import { EventEmitter } from 'node:events';
872
+ * const myEmitter = new EventEmitter();
873
+ *
874
+ * // First listener
875
+ * myEmitter.on('event', function firstListener() {
876
+ * console.log('Helloooo! first listener');
877
+ * });
878
+ * // Second listener
879
+ * myEmitter.on('event', function secondListener(arg1, arg2) {
880
+ * console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
881
+ * });
882
+ * // Third listener
883
+ * myEmitter.on('event', function thirdListener(...args) {
884
+ * const parameters = args.join(', ');
885
+ * console.log(`event with parameters ${parameters} in third listener`);
886
+ * });
887
+ *
888
+ * console.log(myEmitter.listeners('event'));
889
+ *
890
+ * myEmitter.emit('event', 1, 2, 3, 4, 5);
891
+ *
892
+ * // Prints:
893
+ * // [
894
+ * // [Function: firstListener],
895
+ * // [Function: secondListener],
896
+ * // [Function: thirdListener]
897
+ * // ]
898
+ * // Helloooo! first listener
899
+ * // event with parameters 1, 2 in second listener
900
+ * // event with parameters 1, 2, 3, 4, 5 in third listener
901
+ * ```
902
+ * @since v0.1.26
903
+ */
904
+ emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
905
+ /**
906
+ * Returns the number of listeners listening for the event named `eventName`.
907
+ * If `listener` is provided, it will return how many times the listener is found
908
+ * in the list of the listeners of the event.
909
+ * @since v3.2.0
910
+ * @param eventName The name of the event being listened for
911
+ * @param listener The event handler function
912
+ */
913
+ listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
914
+ /**
915
+ * Adds the `listener` function to the _beginning_ of the listeners array for the
916
+ * event named `eventName`. No checks are made to see if the `listener` has
917
+ * already been added. Multiple calls passing the same combination of `eventName`
918
+ * and `listener` will result in the `listener` being added, and called, multiple times.
919
+ *
920
+ * ```js
921
+ * server.prependListener('connection', (stream) => {
922
+ * console.log('someone connected!');
923
+ * });
924
+ * ```
925
+ *
926
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
927
+ * @since v6.0.0
928
+ * @param eventName The name of the event.
929
+ * @param listener The callback function
930
+ */
931
+ prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
932
+ /**
933
+ * Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this
934
+ * listener is removed, and then invoked.
935
+ *
936
+ * ```js
937
+ * server.prependOnceListener('connection', (stream) => {
938
+ * console.log('Ah, we have our first user!');
939
+ * });
940
+ * ```
941
+ *
942
+ * Returns a reference to the `EventEmitter`, so that calls can be chained.
943
+ * @since v6.0.0
944
+ * @param eventName The name of the event.
945
+ * @param listener The callback function
946
+ */
947
+ prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
948
+ /**
949
+ * Returns an array listing the events for which the emitter has registered
950
+ * listeners. The values in the array are strings or `Symbol`s.
951
+ *
952
+ * ```js
953
+ * import { EventEmitter } from 'node:events';
954
+ *
955
+ * const myEE = new EventEmitter();
956
+ * myEE.on('foo', () => {});
957
+ * myEE.on('bar', () => {});
958
+ *
959
+ * const sym = Symbol('symbol');
960
+ * myEE.on(sym, () => {});
961
+ *
962
+ * console.log(myEE.eventNames());
963
+ * // Prints: [ 'foo', 'bar', Symbol(symbol) ]
964
+ * ```
965
+ * @since v6.0.0
966
+ */
967
+ eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
968
+ }
969
+ }
970
+ }
971
+ export = EventEmitter;
972
+ }
973
+ declare module "node:events" {
974
+ import events = require("events");
1046
975
  export = events;
1047
976
  }