hookified 2.1.1 → 2.2.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.
@@ -1,436 +1,534 @@
1
+ //#region src/types.d.ts
1
2
  type Logger = {
2
- trace: (message: string, ...arguments_: unknown[]) => void;
3
- debug: (message: string, ...arguments_: unknown[]) => void;
4
- info: (message: string, ...arguments_: unknown[]) => void;
5
- warn: (message: string, ...arguments_: unknown[]) => void;
6
- error: (message: string, ...arguments_: unknown[]) => void;
7
- fatal: (message: string, ...arguments_: unknown[]) => void;
3
+ trace: (message: string, ...arguments_: unknown[]) => void;
4
+ debug: (message: string, ...arguments_: unknown[]) => void;
5
+ info: (message: string, ...arguments_: unknown[]) => void;
6
+ warn: (message: string, ...arguments_: unknown[]) => void;
7
+ error: (message: string, ...arguments_: unknown[]) => void;
8
+ fatal: (message: string, ...arguments_: unknown[]) => void;
8
9
  };
9
10
  type EventEmitterOptions = {
10
- /**
11
- * Logger instance for logging events.
12
- */
13
- eventLogger?: Logger;
14
- /**
15
- * Whether to throw an error when emit 'error' and there are no listeners. Default is false and only emits an error event.
16
- */
17
- throwOnEmitError?: boolean;
18
- /**
19
- * Whether to throw on 'error' when there are no listeners. This is the standard functionality in EventEmitter
20
- * @default true
21
- */
22
- throwOnEmptyListeners?: boolean;
11
+ /**
12
+ * Logger instance for logging events.
13
+ */
14
+ eventLogger?: Logger;
15
+ /**
16
+ * Whether to throw an error when emit 'error' and there are no listeners. Default is false and only emits an error event.
17
+ */
18
+ throwOnEmitError?: boolean;
19
+ /**
20
+ * Whether to throw on 'error' when there are no listeners. This is the standard functionality in EventEmitter
21
+ * @default true
22
+ */
23
+ throwOnEmptyListeners?: boolean;
23
24
  };
24
25
  type IEventEmitter = {
25
- /**
26
- * Registers a listener for the specified event.
27
- *
28
- * @param eventName - The name (or symbol) of the event to listen for.
29
- * @param listener - A callback function that will be invoked when the event is emitted.
30
- * @returns The current instance of EventEmitter for method chaining.
31
- *
32
- * @example
33
- * emitter.on('data', (message) => {
34
- * console.log(message);
35
- * });
36
- */
37
- on(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
38
- /**
39
- * Alias for `on`. Registers a listener for the specified event.
40
- *
41
- * @param eventName - The name (or symbol) of the event to listen for.
42
- * @param listener - A callback function that will be invoked when the event is emitted.
43
- * @returns The current instance of EventEmitter for method chaining.
44
- */
45
- addListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
46
- /**
47
- * Registers a one-time listener for the specified event. The listener is removed after it is called once.
48
- *
49
- * @param eventName - The name (or symbol) of the event to listen for.
50
- * @param listener - A callback function that will be invoked once when the event is emitted.
51
- * @returns The current instance of EventEmitter for method chaining.
52
- *
53
- * @example
54
- * emitter.once('close', () => {
55
- * console.log('The connection was closed.');
56
- * });
57
- */
58
- once(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
59
- /**
60
- * Removes a previously registered listener for the specified event.
61
- *
62
- * @param eventName - The name (or symbol) of the event to stop listening for.
63
- * @param listener - The specific callback function to remove.
64
- * @returns The current instance of EventEmitter for method chaining.
65
- *
66
- * @example
67
- * emitter.off('data', myListener);
68
- */
69
- off(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
70
- /**
71
- * Alias for `off`. Removes a previously registered listener for the specified event.
72
- *
73
- * @param eventName - The name (or symbol) of the event to stop listening for.
74
- * @param listener - The specific callback function to remove.
75
- * @returns The current instance of EventEmitter for method chaining.
76
- */
77
- removeListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
78
- /**
79
- * Emits the specified event, invoking all registered listeners with the provided arguments.
80
- *
81
- * @param eventName - The name (or symbol) of the event to emit.
82
- * @param args - Arguments passed to each listener.
83
- * @returns `true` if the event had listeners, `false` otherwise.
84
- *
85
- * @example
86
- * emitter.emit('data', 'Hello World');
87
- */
88
- emit(eventName: string | symbol, ...arguments_: any[]): boolean;
89
- /**
90
- * Returns the number of listeners registered for the specified event.
91
- *
92
- * @param eventName - The name (or symbol) of the event.
93
- * @returns The number of registered listeners.
94
- *
95
- * @example
96
- * const count = emitter.listenerCount('data');
97
- * console.log(count); // e.g., 2
98
- */
99
- listenerCount(eventName: string | symbol): number;
100
- /**
101
- * Removes all listeners for the specified event. If no event is specified, it removes all listeners for all events.
102
- *
103
- * @param eventName - (Optional) The name (or symbol) of the event.
104
- * @returns The current instance of EventEmitter for method chaining.
105
- *
106
- * @example
107
- * emitter.removeAllListeners('data');
108
- */
109
- removeAllListeners(eventName?: string | symbol): IEventEmitter;
110
- /**
111
- * Returns an array of event names for which listeners have been registered.
112
- *
113
- * @returns An array of event names (or symbols).
114
- *
115
- * @example
116
- * const events = emitter.eventNames();
117
- * console.log(events); // e.g., ['data', 'close']
118
- */
119
- eventNames(): Array<string | symbol>;
120
- /**
121
- * Returns an array of listeners registered for the specified event.
122
- *
123
- * @param eventName - The name (or symbol) of the event.
124
- * @returns An array of listener functions.
125
- *
126
- * @example
127
- * const listeners = emitter.listeners('data');
128
- * console.log(listeners.length); // e.g., 2
129
- */
130
- listeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
131
- /**
132
- * Returns an array of raw listeners for the specified event. This includes listeners wrapped by internal mechanisms (e.g., once-only listeners).
133
- *
134
- * @param eventName - The name (or symbol) of the event.
135
- * @returns An array of raw listener functions.
136
- *
137
- * @example
138
- * const rawListeners = emitter.rawListeners('data');
139
- */
140
- rawListeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
141
- /**
142
- * Adds a listener to the beginning of the listeners array for the specified event.
143
- *
144
- * @param eventName - The name (or symbol) of the event to listen for.
145
- * @param listener - A callback function that will be invoked when the event is emitted.
146
- * @returns The current instance of EventEmitter for method chaining.
147
- *
148
- * @example
149
- * emitter.prependListener('data', (message) => {
150
- * console.log('This will run first.');
151
- * });
152
- */
153
- prependListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
154
- /**
155
- * Adds a one-time listener to the beginning of the listeners array for the specified event.
156
- *
157
- * @param eventName - The name (or symbol) of the event to listen for.
158
- * @param listener - A callback function that will be invoked once when the event is emitted.
159
- * @returns The current instance of EventEmitter for method chaining.
160
- *
161
- * @example
162
- * emitter.prependOnceListener('data', (message) => {
163
- * console.log('This will run first and only once.');
164
- * });
165
- */
166
- prependOnceListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
26
+ /**
27
+ * Registers a listener for the specified event.
28
+ *
29
+ * @param eventName - The name (or symbol) of the event to listen for.
30
+ * @param listener - A callback function that will be invoked when the event is emitted.
31
+ * @returns The current instance of EventEmitter for method chaining.
32
+ *
33
+ * @example
34
+ * emitter.on('data', (message) => {
35
+ * console.log(message);
36
+ * });
37
+ */
38
+ on(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
39
+ /**
40
+ * Alias for `on`. Registers a listener for the specified event.
41
+ *
42
+ * @param eventName - The name (or symbol) of the event to listen for.
43
+ * @param listener - A callback function that will be invoked when the event is emitted.
44
+ * @returns The current instance of EventEmitter for method chaining.
45
+ */
46
+ addListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
47
+ /**
48
+ * Registers a one-time listener for the specified event. The listener is removed after it is called once.
49
+ *
50
+ * @param eventName - The name (or symbol) of the event to listen for.
51
+ * @param listener - A callback function that will be invoked once when the event is emitted.
52
+ * @returns The current instance of EventEmitter for method chaining.
53
+ *
54
+ * @example
55
+ * emitter.once('close', () => {
56
+ * console.log('The connection was closed.');
57
+ * });
58
+ */
59
+ once(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
60
+ /**
61
+ * Removes a previously registered listener for the specified event.
62
+ *
63
+ * @param eventName - The name (or symbol) of the event to stop listening for.
64
+ * @param listener - The specific callback function to remove.
65
+ * @returns The current instance of EventEmitter for method chaining.
66
+ *
67
+ * @example
68
+ * emitter.off('data', myListener);
69
+ */
70
+ off(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
71
+ /**
72
+ * Alias for `off`. Removes a previously registered listener for the specified event.
73
+ *
74
+ * @param eventName - The name (or symbol) of the event to stop listening for.
75
+ * @param listener - The specific callback function to remove.
76
+ * @returns The current instance of EventEmitter for method chaining.
77
+ */
78
+ removeListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
79
+ /**
80
+ * Emits the specified event, invoking all registered listeners with the provided arguments.
81
+ *
82
+ * @param eventName - The name (or symbol) of the event to emit.
83
+ * @param args - Arguments passed to each listener.
84
+ * @returns `true` if the event had listeners, `false` otherwise.
85
+ *
86
+ * @example
87
+ * emitter.emit('data', 'Hello World');
88
+ */
89
+ emit(eventName: string | symbol, ...arguments_: any[]): boolean;
90
+ /**
91
+ * Returns the number of listeners registered for the specified event.
92
+ *
93
+ * @param eventName - The name (or symbol) of the event.
94
+ * @returns The number of registered listeners.
95
+ *
96
+ * @example
97
+ * const count = emitter.listenerCount('data');
98
+ * console.log(count); // e.g., 2
99
+ */
100
+ listenerCount(eventName: string | symbol): number;
101
+ /**
102
+ * Removes all listeners for the specified event. If no event is specified, it removes all listeners for all events.
103
+ *
104
+ * @param eventName - (Optional) The name (or symbol) of the event.
105
+ * @returns The current instance of EventEmitter for method chaining.
106
+ *
107
+ * @example
108
+ * emitter.removeAllListeners('data');
109
+ */
110
+ removeAllListeners(eventName?: string | symbol): IEventEmitter;
111
+ /**
112
+ * Returns an array of event names for which listeners have been registered.
113
+ *
114
+ * @returns An array of event names (or symbols).
115
+ *
116
+ * @example
117
+ * const events = emitter.eventNames();
118
+ * console.log(events); // e.g., ['data', 'close']
119
+ */
120
+ eventNames(): Array<string | symbol>;
121
+ /**
122
+ * Returns an array of listeners registered for the specified event.
123
+ *
124
+ * @param eventName - The name (or symbol) of the event.
125
+ * @returns An array of listener functions.
126
+ *
127
+ * @example
128
+ * const listeners = emitter.listeners('data');
129
+ * console.log(listeners.length); // e.g., 2
130
+ */
131
+ listeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
132
+ /**
133
+ * Returns an array of raw listeners for the specified event. This includes listeners wrapped by internal mechanisms (e.g., once-only listeners).
134
+ *
135
+ * @param eventName - The name (or symbol) of the event.
136
+ * @returns An array of raw listener functions.
137
+ *
138
+ * @example
139
+ * const rawListeners = emitter.rawListeners('data');
140
+ */
141
+ rawListeners(eventName: string | symbol): Array<(...arguments_: any[]) => void>;
142
+ /**
143
+ * Adds a listener to the beginning of the listeners array for the specified event.
144
+ *
145
+ * @param eventName - The name (or symbol) of the event to listen for.
146
+ * @param listener - A callback function that will be invoked when the event is emitted.
147
+ * @returns The current instance of EventEmitter for method chaining.
148
+ *
149
+ * @example
150
+ * emitter.prependListener('data', (message) => {
151
+ * console.log('This will run first.');
152
+ * });
153
+ */
154
+ prependListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
155
+ /**
156
+ * Adds a one-time listener to the beginning of the listeners array for the specified event.
157
+ *
158
+ * @param eventName - The name (or symbol) of the event to listen for.
159
+ * @param listener - A callback function that will be invoked once when the event is emitted.
160
+ * @returns The current instance of EventEmitter for method chaining.
161
+ *
162
+ * @example
163
+ * emitter.prependOnceListener('data', (message) => {
164
+ * console.log('This will run first and only once.');
165
+ * });
166
+ */
167
+ prependOnceListener(eventName: string | symbol, listener: (...arguments_: any[]) => void): IEventEmitter;
167
168
  };
168
169
  type EventListener = (...arguments_: any[]) => void;
169
170
  type HookFn = (...arguments_: any[]) => Promise<void> | void;
170
171
  interface IHook {
171
- /**
172
- * Unique identifier for the hook. Auto-generated via crypto.randomUUID() if not provided.
173
- */
174
- id?: string;
175
- /**
176
- * The event name for the hook
177
- */
178
- event: string;
179
- /**
180
- * The handler function for the hook
181
- */
182
- handler: HookFn;
172
+ /**
173
+ * Unique identifier for the hook. Auto-generated via crypto.randomUUID() if not provided.
174
+ */
175
+ id?: string;
176
+ /**
177
+ * The event name for the hook
178
+ */
179
+ event: string;
180
+ /**
181
+ * The handler function for the hook
182
+ */
183
+ handler: HookFn;
183
184
  }
184
185
  type WaterfallHookResult = {
185
- /**
186
- * The hook function that produced this result
187
- */
188
- hook: WaterfallHookFn;
189
- /**
190
- * The value returned by the hook
191
- */
192
- result: any;
186
+ /**
187
+ * The hook function that produced this result
188
+ */
189
+ hook: WaterfallHookFn;
190
+ /**
191
+ * The value returned by the hook
192
+ */
193
+ result: any;
193
194
  };
194
195
  type WaterfallHookContext = {
195
- /**
196
- * The original arguments passed to the waterfall execution, before any hooks processed them.
197
- */
198
- initialArgs: any;
199
- /**
200
- * Array of results from previous hooks in execution order, each containing the hook and its result.
201
- * Empty for the first hook.
202
- */
203
- results: WaterfallHookResult[];
196
+ /**
197
+ * The original arguments passed to the waterfall execution, before any hooks processed them.
198
+ */
199
+ initialArgs: any;
200
+ /**
201
+ * Array of results from previous hooks in execution order, each containing the hook and its result.
202
+ * Empty for the first hook.
203
+ */
204
+ results: WaterfallHookResult[];
204
205
  };
205
206
  type WaterfallHookFn = (context: WaterfallHookContext) => Promise<any> | any;
206
207
  interface IWaterfallHook extends IHook {
207
- /**
208
- * Array of hook functions that are called sequentially.
209
- * Each hook receives a WaterfallHookContext with initialArgs and results.
210
- */
211
- hooks: WaterfallHookFn[];
212
- /**
213
- * Adds a hook function to the end of the waterfall chain
214
- */
215
- addHook(hook: WaterfallHookFn): void;
216
- /**
217
- * Removes a specific hook function from the waterfall chain
218
- */
219
- removeHook(hook: WaterfallHookFn): boolean;
208
+ /**
209
+ * Array of hook functions that are called sequentially.
210
+ * Each hook receives a WaterfallHookContext with initialArgs and results.
211
+ */
212
+ hooks: WaterfallHookFn[];
213
+ /**
214
+ * Adds a hook function to the end of the waterfall chain
215
+ */
216
+ addHook(hook: WaterfallHookFn): void;
217
+ /**
218
+ * Removes a specific hook function from the waterfall chain
219
+ */
220
+ removeHook(hook: WaterfallHookFn): boolean;
221
+ }
222
+ type ParallelHookContext<TArgs = any> = {
223
+ /**
224
+ * The original arguments passed to the parallel execution.
225
+ * Every hook receives this same value; hooks do not see each other's results.
226
+ */
227
+ initialArgs: TArgs;
228
+ };
229
+ type ParallelHookFn<TArgs = any, TResult = any> = (context: ParallelHookContext<TArgs>) => Promise<TResult> | TResult;
230
+ type ParallelHookResult<TResult = any> = {
231
+ status: "fulfilled";
232
+ /**
233
+ * The value returned by the hook
234
+ */
235
+ result: TResult;
236
+ } | {
237
+ status: "rejected";
238
+ /**
239
+ * The error or value the hook rejected with. Errors in JS can be of
240
+ * any type, so this stays `unknown` regardless of the result generic.
241
+ */
242
+ reason: unknown;
243
+ };
244
+ type ParallelHookFinalContext<TArgs = any, TResult = any> = {
245
+ /**
246
+ * The original arguments passed to the parallel execution.
247
+ */
248
+ initialArgs: TArgs;
249
+ /**
250
+ * Aggregated outcomes from every parallel hook, keyed by the hook function
251
+ * reference for direct lookup. Iteration order matches registration order.
252
+ */
253
+ results: Map<ParallelHookFn<TArgs, TResult>, ParallelHookResult<TResult>>;
254
+ };
255
+ type ParallelHookFinalFn<TArgs = any, TResult = any> = (context: ParallelHookFinalContext<TArgs, TResult>) => Promise<void> | void;
256
+ interface IParallelHook<TArgs = any, TResult = any> extends IHook {
257
+ /**
258
+ * Array of hook functions that are called concurrently via Promise.allSettled.
259
+ * Each hook receives a ParallelHookContext with only initialArgs.
260
+ */
261
+ hooks: ParallelHookFn<TArgs, TResult>[];
262
+ /**
263
+ * Adds a hook function to the parallel set
264
+ */
265
+ addHook(hook: ParallelHookFn<TArgs, TResult>): void;
266
+ /**
267
+ * Removes a specific hook function from the parallel set
268
+ */
269
+ removeHook(hook: ParallelHookFn<TArgs, TResult>): boolean;
220
270
  }
221
271
  type OnHookOptions = {
222
- /**
223
- * Per-call override for useHookClone.
224
- * When true, hook objects are cloned before storing.
225
- * When false, the original IHook reference is stored directly.
226
- * When undefined, falls back to the instance-level useHookClone setting.
227
- * @type {boolean}
228
- */
229
- useHookClone?: boolean;
230
- /**
231
- * Controls where the hook is inserted in the handlers array.
232
- * - "Top": Insert at the beginning (index 0), before all existing handlers.
233
- * - "Bottom": Append to the end, after all existing handlers. This is the default.
234
- * - number: Insert at a specific index. Values are clamped to the array bounds.
235
- */
236
- position?: "Top" | "Bottom" | number;
272
+ /**
273
+ * Per-call override for useHookClone.
274
+ * When true, hook objects are cloned before storing.
275
+ * When false, the original IHook reference is stored directly.
276
+ * When undefined, falls back to the instance-level useHookClone setting.
277
+ * @type {boolean}
278
+ */
279
+ useHookClone?: boolean;
280
+ /**
281
+ * Controls where the hook is inserted in the handlers array.
282
+ * - "Top": Insert at the beginning (index 0), before all existing handlers.
283
+ * - "Bottom": Append to the end, after all existing handlers. This is the default.
284
+ * - number: Insert at a specific index. Values are clamped to the array bounds.
285
+ */
286
+ position?: "Top" | "Bottom" | number;
237
287
  };
238
288
  type PrependHookOptions = Omit<OnHookOptions, "position">;
239
289
  type HookifiedOptions = {
240
- /**
241
- * Whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
242
- */
243
- throwOnHookError?: boolean;
244
- /**
245
- * Whether to enforce that all hook names start with 'before' or 'after'. Default is false.
246
- * @type {boolean}
247
- * @default false
248
- */
249
- enforceBeforeAfter?: boolean;
250
- /**
251
- * Map of deprecated hook names to deprecation messages. When a deprecated hook is used, a warning will be emitted.
252
- * @type {Map<string, string>}
253
- * @default new Map()
254
- */
255
- deprecatedHooks?: Map<string, string>;
256
- /**
257
- * Whether to allow deprecated hooks to be registered and executed. Default is true.
258
- * @type {boolean}
259
- * @default true
260
- */
261
- allowDeprecated?: boolean;
262
- /**
263
- * Whether to clone hook objects before storing. Default is true.
264
- * When false, the original IHook reference is stored directly.
265
- * @type {boolean}
266
- * @default true
267
- */
268
- useHookClone?: boolean;
290
+ /**
291
+ * Whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
292
+ */
293
+ throwOnHookError?: boolean;
294
+ /**
295
+ * Whether to enforce that all hook names start with 'before' or 'after'. Default is false.
296
+ * @type {boolean}
297
+ * @default false
298
+ */
299
+ enforceBeforeAfter?: boolean;
300
+ /**
301
+ * Map of deprecated hook names to deprecation messages. When a deprecated hook is used, a warning will be emitted.
302
+ * @type {Map<string, string>}
303
+ * @default new Map()
304
+ */
305
+ deprecatedHooks?: Map<string, string>;
306
+ /**
307
+ * Whether to allow deprecated hooks to be registered and executed. Default is true.
308
+ * @type {boolean}
309
+ * @default true
310
+ */
311
+ allowDeprecated?: boolean;
312
+ /**
313
+ * Whether to clone hook objects before storing. Default is true.
314
+ * When false, the original IHook reference is stored directly.
315
+ * @type {boolean}
316
+ * @default true
317
+ */
318
+ useHookClone?: boolean;
269
319
  } & EventEmitterOptions;
270
-
320
+ //#endregion
321
+ //#region src/eventified.d.ts
271
322
  declare class Eventified implements IEventEmitter {
272
- private readonly _eventListeners;
273
- private _maxListeners;
274
- private _eventLogger?;
275
- private _throwOnEmitError;
276
- private _throwOnEmptyListeners;
277
- constructor(options?: EventEmitterOptions);
278
- /**
279
- * Gets the event logger
280
- * @returns {Logger}
281
- */
282
- get eventLogger(): Logger | undefined;
283
- /**
284
- * Sets the event logger
285
- * @param {Logger} eventLogger
286
- */
287
- set eventLogger(eventLogger: Logger | undefined);
288
- /**
289
- * Gets whether an error should be thrown when an emit throws an error. Default is false and only emits an error event.
290
- * @returns {boolean}
291
- */
292
- get throwOnEmitError(): boolean;
293
- /**
294
- * Sets whether an error should be thrown when an emit throws an error. Default is false and only emits an error event.
295
- * @param {boolean} value
296
- */
297
- set throwOnEmitError(value: boolean);
298
- /**
299
- * Gets whether an error should be thrown when emitting 'error' event with no listeners. Default is false.
300
- * @returns {boolean}
301
- */
302
- get throwOnEmptyListeners(): boolean;
303
- /**
304
- * Sets whether an error should be thrown when emitting 'error' event with no listeners. Default is false.
305
- * @param {boolean} value
306
- */
307
- set throwOnEmptyListeners(value: boolean);
308
- /**
309
- * Adds a handler function for a specific event that will run only once
310
- * @param {string | symbol} eventName
311
- * @param {EventListener} listener
312
- * @returns {IEventEmitter} returns the instance of the class for chaining
313
- */
314
- once(eventName: string | symbol, listener: EventListener): IEventEmitter;
315
- /**
316
- * Gets the number of listeners for a specific event. If no event is provided, it returns the total number of listeners
317
- * @param {string} eventName The event name. Not required
318
- * @returns {number} The number of listeners
319
- */
320
- listenerCount(eventName?: string | symbol): number;
321
- /**
322
- * Gets an array of event names
323
- * @returns {Array<string | symbol>} An array of event names
324
- */
325
- eventNames(): Array<string | symbol>;
326
- /**
327
- * Gets an array of listeners for a specific event. If no event is provided, it returns all listeners
328
- * @param {string} [event] (Optional) The event name
329
- * @returns {EventListener[]} An array of listeners
330
- */
331
- rawListeners(event?: string | symbol): EventListener[];
332
- /**
333
- * Prepends a listener to the beginning of the listeners array for the specified event
334
- * @param {string | symbol} eventName
335
- * @param {EventListener} listener
336
- * @returns {IEventEmitter} returns the instance of the class for chaining
337
- */
338
- prependListener(eventName: string | symbol, listener: EventListener): IEventEmitter;
339
- /**
340
- * Prepends a one-time listener to the beginning of the listeners array for the specified event
341
- * @param {string | symbol} eventName
342
- * @param {EventListener} listener
343
- * @returns {IEventEmitter} returns the instance of the class for chaining
344
- */
345
- prependOnceListener(eventName: string | symbol, listener: EventListener): IEventEmitter;
346
- /**
347
- * Gets the maximum number of listeners that can be added for a single event
348
- * @returns {number} The maximum number of listeners
349
- */
350
- maxListeners(): number;
351
- /**
352
- * Adds a listener for a specific event. It is an alias for the on() method
353
- * @param {string | symbol} event
354
- * @param {EventListener} listener
355
- * @returns {IEventEmitter} returns the instance of the class for chaining
356
- */
357
- addListener(event: string | symbol, listener: EventListener): IEventEmitter;
358
- /**
359
- * Adds a listener for a specific event
360
- * @param {string | symbol} event
361
- * @param {EventListener} listener
362
- * @returns {IEventEmitter} returns the instance of the class for chaining
363
- */
364
- on(event: string | symbol, listener: EventListener): IEventEmitter;
365
- /**
366
- * Removes a listener for a specific event. It is an alias for the off() method
367
- * @param {string | symbol} event
368
- * @param {EventListener} listener
369
- * @returns {IEventEmitter} returns the instance of the class for chaining
370
- */
371
- removeListener(event: string, listener: EventListener): IEventEmitter;
372
- /**
373
- * Removes a listener for a specific event
374
- * @param {string | symbol} event
375
- * @param {EventListener} listener
376
- * @returns {IEventEmitter} returns the instance of the class for chaining
377
- */
378
- off(event: string | symbol, listener: EventListener): IEventEmitter;
379
- /**
380
- * Calls all listeners for a specific event
381
- * @param {string | symbol} event
382
- * @param arguments_ The arguments to pass to the listeners
383
- * @returns {boolean} Returns true if the event had listeners, false otherwise
384
- */
385
- emit(event: string | symbol, ...arguments_: any[]): boolean;
386
- /**
387
- * Gets all listeners for a specific event. If no event is provided, it returns all listeners
388
- * @param {string} [event] (Optional) The event name
389
- * @returns {EventListener[]} An array of listeners
390
- */
391
- listeners(event: string | symbol): EventListener[];
392
- /**
393
- * Removes all listeners for a specific event. If no event is provided, it removes all listeners
394
- * @param {string} [event] (Optional) The event name
395
- * @returns {IEventEmitter} returns the instance of the class for chaining
396
- */
397
- removeAllListeners(event?: string | symbol): IEventEmitter;
398
- /**
399
- * Sets the maximum number of listeners that can be added for a single event
400
- * @param {number} n The maximum number of listeners
401
- * @returns {void}
402
- */
403
- setMaxListeners(n: number): void;
404
- /**
405
- * Gets all listeners
406
- * @returns {EventListener[]} An array of listeners
407
- */
408
- getAllListeners(): EventListener[];
409
- /**
410
- * Sends a log message using the configured logger based on the event name
411
- * @param {string | symbol} eventName - The event name that determines the log level
412
- * @param {unknown} data - The data to log
413
- */
414
- private sendToEventLogger;
323
+ private readonly _eventListeners;
324
+ private _maxListeners;
325
+ private _eventLogger?;
326
+ private _throwOnEmitError;
327
+ private _throwOnEmptyListeners;
328
+ constructor(options?: EventEmitterOptions);
329
+ /**
330
+ * Gets the event logger
331
+ * @returns {Logger}
332
+ */
333
+ get eventLogger(): Logger | undefined;
334
+ /**
335
+ * Sets the event logger
336
+ * @param {Logger} eventLogger
337
+ */
338
+ set eventLogger(eventLogger: Logger | undefined);
339
+ /**
340
+ * Gets whether an error should be thrown when an emit throws an error. Default is false and only emits an error event.
341
+ * @returns {boolean}
342
+ */
343
+ get throwOnEmitError(): boolean;
344
+ /**
345
+ * Sets whether an error should be thrown when an emit throws an error. Default is false and only emits an error event.
346
+ * @param {boolean} value
347
+ */
348
+ set throwOnEmitError(value: boolean);
349
+ /**
350
+ * Gets whether an error should be thrown when emitting 'error' event with no listeners. Default is false.
351
+ * @returns {boolean}
352
+ */
353
+ get throwOnEmptyListeners(): boolean;
354
+ /**
355
+ * Sets whether an error should be thrown when emitting 'error' event with no listeners. Default is false.
356
+ * @param {boolean} value
357
+ */
358
+ set throwOnEmptyListeners(value: boolean);
359
+ /**
360
+ * Adds a handler function for a specific event that will run only once
361
+ * @param {string | symbol} eventName
362
+ * @param {EventListener} listener
363
+ * @returns {IEventEmitter} returns the instance of the class for chaining
364
+ */
365
+ once(eventName: string | symbol, listener: EventListener): IEventEmitter;
366
+ /**
367
+ * Gets the number of listeners for a specific event. If no event is provided, it returns the total number of listeners
368
+ * @param {string} eventName The event name. Not required
369
+ * @returns {number} The number of listeners
370
+ */
371
+ listenerCount(eventName?: string | symbol): number;
372
+ /**
373
+ * Gets an array of event names
374
+ * @returns {Array<string | symbol>} An array of event names
375
+ */
376
+ eventNames(): Array<string | symbol>;
377
+ /**
378
+ * Gets an array of listeners for a specific event. If no event is provided, it returns all listeners
379
+ * @param {string} [event] (Optional) The event name
380
+ * @returns {EventListener[]} An array of listeners
381
+ */
382
+ rawListeners(event?: string | symbol): EventListener[];
383
+ /**
384
+ * Prepends a listener to the beginning of the listeners array for the specified event
385
+ * @param {string | symbol} eventName
386
+ * @param {EventListener} listener
387
+ * @returns {IEventEmitter} returns the instance of the class for chaining
388
+ */
389
+ prependListener(eventName: string | symbol, listener: EventListener): IEventEmitter;
390
+ /**
391
+ * Prepends a one-time listener to the beginning of the listeners array for the specified event
392
+ * @param {string | symbol} eventName
393
+ * @param {EventListener} listener
394
+ * @returns {IEventEmitter} returns the instance of the class for chaining
395
+ */
396
+ prependOnceListener(eventName: string | symbol, listener: EventListener): IEventEmitter;
397
+ /**
398
+ * Gets the maximum number of listeners that can be added for a single event
399
+ * @returns {number} The maximum number of listeners
400
+ */
401
+ maxListeners(): number;
402
+ /**
403
+ * Adds a listener for a specific event. It is an alias for the on() method
404
+ * @param {string | symbol} event
405
+ * @param {EventListener} listener
406
+ * @returns {IEventEmitter} returns the instance of the class for chaining
407
+ */
408
+ addListener(event: string | symbol, listener: EventListener): IEventEmitter;
409
+ /**
410
+ * Adds a listener for a specific event
411
+ * @param {string | symbol} event
412
+ * @param {EventListener} listener
413
+ * @returns {IEventEmitter} returns the instance of the class for chaining
414
+ */
415
+ on(event: string | symbol, listener: EventListener): IEventEmitter;
416
+ /**
417
+ * Removes a listener for a specific event. It is an alias for the off() method
418
+ * @param {string | symbol} event
419
+ * @param {EventListener} listener
420
+ * @returns {IEventEmitter} returns the instance of the class for chaining
421
+ */
422
+ removeListener(event: string, listener: EventListener): IEventEmitter;
423
+ /**
424
+ * Removes a listener for a specific event
425
+ * @param {string | symbol} event
426
+ * @param {EventListener} listener
427
+ * @returns {IEventEmitter} returns the instance of the class for chaining
428
+ */
429
+ off(event: string | symbol, listener: EventListener): IEventEmitter;
430
+ /**
431
+ * Calls all listeners for a specific event
432
+ * @param {string | symbol} event
433
+ * @param arguments_ The arguments to pass to the listeners
434
+ * @returns {boolean} Returns true if the event had listeners, false otherwise
435
+ */
436
+ emit(event: string | symbol, ...arguments_: any[]): boolean;
437
+ /**
438
+ * Gets all listeners for a specific event. If no event is provided, it returns all listeners
439
+ * @param {string} [event] (Optional) The event name
440
+ * @returns {EventListener[]} An array of listeners
441
+ */
442
+ listeners(event: string | symbol): EventListener[];
443
+ /**
444
+ * Removes all listeners for a specific event. If no event is provided, it removes all listeners
445
+ * @param {string} [event] (Optional) The event name
446
+ * @returns {IEventEmitter} returns the instance of the class for chaining
447
+ */
448
+ removeAllListeners(event?: string | symbol): IEventEmitter;
449
+ /**
450
+ * Sets the maximum number of listeners that can be added for a single event
451
+ * @param {number} n The maximum number of listeners
452
+ * @returns {void}
453
+ */
454
+ setMaxListeners(n: number): void;
455
+ /**
456
+ * Gets all listeners
457
+ * @returns {EventListener[]} An array of listeners
458
+ */
459
+ getAllListeners(): EventListener[];
460
+ /**
461
+ * Sends a log message using the configured logger based on the event name
462
+ * @param {string | symbol} eventName - The event name that determines the log level
463
+ * @param {unknown} data - The data to log
464
+ */
465
+ private sendToEventLogger;
415
466
  }
416
-
467
+ //#endregion
468
+ //#region src/hooks/hook.d.ts
417
469
  /**
418
470
  * Concrete implementation of the IHook interface.
419
471
  * Provides a convenient class-based way to create hook entries.
420
472
  */
421
473
  declare class Hook implements IHook {
422
- id?: string;
423
- event: string;
424
- handler: HookFn;
425
- /**
426
- * Creates a new Hook instance
427
- * @param {string} event - The event name for the hook
428
- * @param {HookFn} handler - The handler function for the hook
429
- * @param {string} [id] - Optional unique identifier for the hook
430
- */
431
- constructor(event: string, handler: HookFn, id?: string);
474
+ id?: string;
475
+ event: string;
476
+ handler: HookFn;
477
+ /**
478
+ * Creates a new Hook instance
479
+ * @param {string} event - The event name for the hook
480
+ * @param {HookFn} handler - The handler function for the hook
481
+ * @param {string} [id] - Optional unique identifier for the hook
482
+ */
483
+ constructor(event: string, handler: HookFn, id?: string);
484
+ }
485
+ //#endregion
486
+ //#region src/hooks/parallel-hook.d.ts
487
+ /**
488
+ * A ParallelHook fans a single invocation out to many registered hook
489
+ * functions concurrently via Promise.allSettled, then calls a final
490
+ * handler with the aggregated results — including failures — keyed by
491
+ * the hook function reference for direct lookup. Each hook receives only
492
+ * the original arguments; hooks do not see each other's results.
493
+ *
494
+ * Implements IHook for compatibility with Hookified.onHook(); the final
495
+ * handler is called regardless of whether the parallel hook is invoked
496
+ * directly or through Hookified.hook().
497
+ *
498
+ * Generics tighten the per-hook signature when every hook in the set
499
+ * accepts the same `initialArgs` and returns the same result type.
500
+ * Both default to `any` for backwards compatibility.
501
+ *
502
+ * @template TArgs - The shape of `initialArgs` passed to every hook
503
+ * @template TResult - The result type each hook returns
504
+ */
505
+ declare class ParallelHook<TArgs = any, TResult = any> implements IParallelHook<TArgs, TResult> {
506
+ id?: string;
507
+ event: string;
508
+ handler: HookFn;
509
+ hooks: ParallelHookFn<TArgs, TResult>[];
510
+ private readonly _finalHandler;
511
+ /**
512
+ * Creates a new ParallelHook instance
513
+ * @param {string} event - The event name for the hook
514
+ * @param {ParallelHookFinalFn<TArgs, TResult>} finalHandler - Called once with `{ initialArgs, results }` after all parallel hooks settle
515
+ * @param {string} [id] - Optional unique identifier for the hook
516
+ */
517
+ constructor(event: string, finalHandler: ParallelHookFinalFn<TArgs, TResult>, id?: string);
518
+ /**
519
+ * Adds a hook function to the parallel set
520
+ * @param {ParallelHookFn<TArgs, TResult>} hook - The hook function to add
521
+ */
522
+ addHook(hook: ParallelHookFn<TArgs, TResult>): void;
523
+ /**
524
+ * Removes a specific hook function from the parallel set
525
+ * @param {ParallelHookFn<TArgs, TResult>} hook - The hook function to remove
526
+ * @returns {boolean} true if the hook was found and removed
527
+ */
528
+ removeHook(hook: ParallelHookFn<TArgs, TResult>): boolean;
432
529
  }
433
-
530
+ //#endregion
531
+ //#region src/hooks/waterfall-hook.d.ts
434
532
  /**
435
533
  * A WaterfallHook chains multiple hook functions sequentially,
436
534
  * where each hook receives a context with the previous result,
@@ -439,234 +537,235 @@ declare class Hook implements IHook {
439
537
  * Implements IHook for compatibility with Hookified.onHook().
440
538
  */
441
539
  declare class WaterfallHook implements IWaterfallHook {
442
- id?: string;
443
- event: string;
444
- handler: HookFn;
445
- hooks: WaterfallHookFn[];
446
- private readonly _finalHandler;
447
- /**
448
- * Creates a new WaterfallHook instance
449
- * @param {string} event - The event name for the hook
450
- * @param {WaterfallHookFn} finalHandler - The final handler function that receives the transformed result
451
- * @param {string} [id] - Optional unique identifier for the hook
452
- */
453
- constructor(event: string, finalHandler: WaterfallHookFn, id?: string);
454
- /**
455
- * Adds a hook function to the end of the waterfall chain
456
- * @param {WaterfallHookFn} hook - The hook function to add
457
- */
458
- addHook(hook: WaterfallHookFn): void;
459
- /**
460
- * Removes a specific hook function from the waterfall chain
461
- * @param {WaterfallHookFn} hook - The hook function to remove
462
- * @returns {boolean} true if the hook was found and removed
463
- */
464
- removeHook(hook: WaterfallHookFn): boolean;
540
+ id?: string;
541
+ event: string;
542
+ handler: HookFn;
543
+ hooks: WaterfallHookFn[];
544
+ private readonly _finalHandler;
545
+ /**
546
+ * Creates a new WaterfallHook instance
547
+ * @param {string} event - The event name for the hook
548
+ * @param {WaterfallHookFn} finalHandler - The final handler function that receives the transformed result
549
+ * @param {string} [id] - Optional unique identifier for the hook
550
+ */
551
+ constructor(event: string, finalHandler: WaterfallHookFn, id?: string);
552
+ /**
553
+ * Adds a hook function to the end of the waterfall chain
554
+ * @param {WaterfallHookFn} hook - The hook function to add
555
+ */
556
+ addHook(hook: WaterfallHookFn): void;
557
+ /**
558
+ * Removes a specific hook function from the waterfall chain
559
+ * @param {WaterfallHookFn} hook - The hook function to remove
560
+ * @returns {boolean} true if the hook was found and removed
561
+ */
562
+ removeHook(hook: WaterfallHookFn): boolean;
465
563
  }
466
-
564
+ //#endregion
565
+ //#region src/index.d.ts
467
566
  declare class Hookified extends Eventified {
468
- private readonly _hooks;
469
- private _throwOnHookError;
470
- private _enforceBeforeAfter;
471
- private _deprecatedHooks;
472
- private _allowDeprecated;
473
- private _useHookClone;
474
- constructor(options?: HookifiedOptions);
475
- /**
476
- * Gets all hooks
477
- * @returns {Map<string, IHook[]>}
478
- */
479
- get hooks(): Map<string, IHook[]>;
480
- /**
481
- * Gets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
482
- * @returns {boolean}
483
- */
484
- get throwOnHookError(): boolean;
485
- /**
486
- * Sets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
487
- * @param {boolean} value
488
- */
489
- set throwOnHookError(value: boolean);
490
- /**
491
- * Gets whether to enforce that all hook names start with 'before' or 'after'. Default is false.
492
- * @returns {boolean}
493
- * @default false
494
- */
495
- get enforceBeforeAfter(): boolean;
496
- /**
497
- * Sets whether to enforce that all hook names start with 'before' or 'after'. Default is false.
498
- * @param {boolean} value
499
- */
500
- set enforceBeforeAfter(value: boolean);
501
- /**
502
- * Gets the map of deprecated hook names to deprecation messages.
503
- * @returns {Map<string, string>}
504
- */
505
- get deprecatedHooks(): Map<string, string>;
506
- /**
507
- * Sets the map of deprecated hook names to deprecation messages.
508
- * @param {Map<string, string>} value
509
- */
510
- set deprecatedHooks(value: Map<string, string>);
511
- /**
512
- * Gets whether deprecated hooks are allowed to be registered and executed. Default is true.
513
- * @returns {boolean}
514
- */
515
- get allowDeprecated(): boolean;
516
- /**
517
- * Sets whether deprecated hooks are allowed to be registered and executed. Default is true.
518
- * @param {boolean} value
519
- */
520
- set allowDeprecated(value: boolean);
521
- /**
522
- * Gets whether hook objects are cloned before storing. Default is true.
523
- * @returns {boolean}
524
- */
525
- get useHookClone(): boolean;
526
- /**
527
- * Sets whether hook objects are cloned before storing. Default is true.
528
- * When false, the original IHook reference is stored directly.
529
- * @param {boolean} value
530
- */
531
- set useHookClone(value: boolean);
532
- /**
533
- * Adds a handler function for a specific event.
534
- * Supports both object and legacy signatures:
535
- * onHook({ event, handler }, options?)
536
- * onHook(event, handler)
537
- * To register multiple hooks at once, use {@link onHooks}.
538
- * @param {IHook | string} hookOrEvent - the hook object or event name
539
- * @param {OnHookOptions | HookFn} [optionsOrHandler] - options (when using object form) or handler function (when using string form)
540
- * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
541
- */
542
- onHook(hook: IHook, options?: OnHookOptions): IHook | undefined;
543
- onHook(event: string, handler: HookFn): IHook | undefined;
544
- /**
545
- * Alias for onHook. This is provided for compatibility with other libraries that use the `addHook` method.
546
- * @param {string} event - the event name
547
- * @param {HookFn} handler - the handler function
548
- * @returns {void}
549
- */
550
- addHook(event: string, handler: HookFn): void;
551
- /**
552
- * Adds handler functions for specific events
553
- * @param {Array<IHook>} hooks
554
- * @param {OnHookOptions} [options] - optional per-call options (e.g., useHookClone override, position)
555
- * @returns {void}
556
- */
557
- onHooks(hooks: IHook[], options?: OnHookOptions): void;
558
- /**
559
- * Adds a handler function for a specific event that runs before all other handlers.
560
- * Equivalent to calling `onHook(hook, { position: "Top" })`.
561
- * @param {IHook} hook - the hook containing event name and handler
562
- * @param {PrependHookOptions} [options] - optional per-call options (e.g., useHookClone override)
563
- * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
564
- */
565
- prependHook(hook: IHook, options?: PrependHookOptions): IHook | undefined;
566
- /**
567
- * Adds a handler that only executes once for a specific event before all other handlers.
568
- * Equivalent to calling `onHook` with a self-removing wrapper and `{ position: "Top" }`.
569
- * @param {IHook} hook - the hook containing event name and handler
570
- * @param {PrependHookOptions} [options] - optional per-call options (e.g., useHookClone override)
571
- * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
572
- */
573
- prependOnceHook(hook: IHook, options?: PrependHookOptions): IHook | undefined;
574
- /**
575
- * Adds a handler that only executes once for a specific event
576
- * @param {IHook} hook - the hook containing event name and handler
577
- */
578
- onceHook(hook: IHook): void;
579
- /**
580
- * Removes a handler function for a specific event
581
- * @param {IHook} hook - the hook containing event name and handler to remove
582
- * @returns {IHook | undefined} the removed hook, or undefined if not found
583
- */
584
- removeHook(hook: IHook): IHook | undefined;
585
- /**
586
- * Removes multiple hook handlers
587
- * @param {Array<IHook>} hooks
588
- * @returns {IHook[]} the hooks that were successfully removed
589
- */
590
- removeHooks(hooks: IHook[]): IHook[];
591
- /**
592
- * Calls all handlers for a specific event
593
- * @param {string} event
594
- * @param {T[]} arguments_
595
- * @returns {Promise<void>}
596
- */
597
- hook<T>(event: string, ...arguments_: T[]): Promise<void>;
598
- /**
599
- * Calls all synchronous handlers for a specific event.
600
- * Async handlers (declared with `async` keyword) are silently skipped.
601
- *
602
- * Note: The `hook` method is preferred as it executes both sync and async functions.
603
- * Use `hookSync` only when you specifically need synchronous execution.
604
- * @param {string} event
605
- * @param {T[]} arguments_
606
- * @returns {void}
607
- */
608
- hookSync<T>(event: string, ...arguments_: T[]): void;
609
- /**
610
- * Prepends the word `before` to your hook. Example is event is `test`, the before hook is `before:test`.
611
- * @param {string} event - The event name
612
- * @param {T[]} arguments_ - The arguments to pass to the hook
613
- */
614
- beforeHook<T>(event: string, ...arguments_: T[]): Promise<void>;
615
- /**
616
- * Prepends the word `after` to your hook. Example is event is `test`, the after hook is `after:test`.
617
- * @param {string} event - The event name
618
- * @param {T[]} arguments_ - The arguments to pass to the hook
619
- */
620
- afterHook<T>(event: string, ...arguments_: T[]): Promise<void>;
621
- /**
622
- * Calls all handlers for a specific event. This is an alias for `hook` and is provided for
623
- * compatibility with other libraries that use the `callHook` method.
624
- * @param {string} event
625
- * @param {T[]} arguments_
626
- * @returns {Promise<void>}
627
- */
628
- callHook<T>(event: string, ...arguments_: T[]): Promise<void>;
629
- /**
630
- * Gets all hooks for a specific event
631
- * @param {string} event
632
- * @returns {IHook[]}
633
- */
634
- getHooks(event: string): IHook[] | undefined;
635
- /**
636
- * Gets a specific hook by id, searching across all events
637
- * @param {string} id - the hook id
638
- * @returns {IHook | undefined} the hook if found, or undefined
639
- */
640
- getHook(id: string): IHook | undefined;
641
- /**
642
- * Removes one or more hooks by id, searching across all events
643
- * @param {string | string[]} id - the hook id or array of hook ids to remove
644
- * @returns {IHook | IHook[] | undefined} the removed hook(s), or undefined/empty array if not found
645
- */
646
- removeHookById(id: string | string[]): IHook | IHook[] | undefined;
647
- /**
648
- * Removes all hooks
649
- * @returns {void}
650
- */
651
- clearHooks(): void;
652
- /**
653
- * Removes all hooks for a specific event and returns the removed hooks.
654
- * @param {string} event - The event name to remove hooks for.
655
- * @returns {IHook[]} the hooks that were removed
656
- */
657
- removeEventHooks(event: string): IHook[];
658
- /**
659
- * Validates hook event name if enforceBeforeAfter is enabled
660
- * @param {string} event - The event name to validate
661
- * @throws {Error} If enforceBeforeAfter is true and event doesn't start with 'before' or 'after'
662
- */
663
- private validateHookName;
664
- /**
665
- * Checks if a hook is deprecated and emits a warning if it is
666
- * @param {string} event - The event name to check
667
- * @returns {boolean} - Returns true if the hook should proceed, false if it should be blocked
668
- */
669
- private checkDeprecatedHook;
567
+ private readonly _hooks;
568
+ private _throwOnHookError;
569
+ private _enforceBeforeAfter;
570
+ private _deprecatedHooks;
571
+ private _allowDeprecated;
572
+ private _useHookClone;
573
+ constructor(options?: HookifiedOptions);
574
+ /**
575
+ * Gets all hooks
576
+ * @returns {Map<string, IHook[]>}
577
+ */
578
+ get hooks(): Map<string, IHook[]>;
579
+ /**
580
+ * Gets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
581
+ * @returns {boolean}
582
+ */
583
+ get throwOnHookError(): boolean;
584
+ /**
585
+ * Sets whether an error should be thrown when a hook throws an error. Default is false and only emits an error event.
586
+ * @param {boolean} value
587
+ */
588
+ set throwOnHookError(value: boolean);
589
+ /**
590
+ * Gets whether to enforce that all hook names start with 'before' or 'after'. Default is false.
591
+ * @returns {boolean}
592
+ * @default false
593
+ */
594
+ get enforceBeforeAfter(): boolean;
595
+ /**
596
+ * Sets whether to enforce that all hook names start with 'before' or 'after'. Default is false.
597
+ * @param {boolean} value
598
+ */
599
+ set enforceBeforeAfter(value: boolean);
600
+ /**
601
+ * Gets the map of deprecated hook names to deprecation messages.
602
+ * @returns {Map<string, string>}
603
+ */
604
+ get deprecatedHooks(): Map<string, string>;
605
+ /**
606
+ * Sets the map of deprecated hook names to deprecation messages.
607
+ * @param {Map<string, string>} value
608
+ */
609
+ set deprecatedHooks(value: Map<string, string>);
610
+ /**
611
+ * Gets whether deprecated hooks are allowed to be registered and executed. Default is true.
612
+ * @returns {boolean}
613
+ */
614
+ get allowDeprecated(): boolean;
615
+ /**
616
+ * Sets whether deprecated hooks are allowed to be registered and executed. Default is true.
617
+ * @param {boolean} value
618
+ */
619
+ set allowDeprecated(value: boolean);
620
+ /**
621
+ * Gets whether hook objects are cloned before storing. Default is true.
622
+ * @returns {boolean}
623
+ */
624
+ get useHookClone(): boolean;
625
+ /**
626
+ * Sets whether hook objects are cloned before storing. Default is true.
627
+ * When false, the original IHook reference is stored directly.
628
+ * @param {boolean} value
629
+ */
630
+ set useHookClone(value: boolean);
631
+ /**
632
+ * Adds a handler function for a specific event.
633
+ * Supports both object and legacy signatures:
634
+ * onHook({ event, handler }, options?)
635
+ * onHook(event, handler)
636
+ * To register multiple hooks at once, use {@link onHooks}.
637
+ * @param {IHook | string} hookOrEvent - the hook object or event name
638
+ * @param {OnHookOptions | HookFn} [optionsOrHandler] - options (when using object form) or handler function (when using string form)
639
+ * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
640
+ */
641
+ onHook(hook: IHook, options?: OnHookOptions): IHook | undefined;
642
+ onHook(event: string, handler: HookFn): IHook | undefined;
643
+ /**
644
+ * Alias for onHook. This is provided for compatibility with other libraries that use the `addHook` method.
645
+ * @param {string} event - the event name
646
+ * @param {HookFn} handler - the handler function
647
+ * @returns {void}
648
+ */
649
+ addHook(event: string, handler: HookFn): void;
650
+ /**
651
+ * Adds handler functions for specific events
652
+ * @param {Array<IHook>} hooks
653
+ * @param {OnHookOptions} [options] - optional per-call options (e.g., useHookClone override, position)
654
+ * @returns {void}
655
+ */
656
+ onHooks(hooks: IHook[], options?: OnHookOptions): void;
657
+ /**
658
+ * Adds a handler function for a specific event that runs before all other handlers.
659
+ * Equivalent to calling `onHook(hook, { position: "Top" })`.
660
+ * @param {IHook} hook - the hook containing event name and handler
661
+ * @param {PrependHookOptions} [options] - optional per-call options (e.g., useHookClone override)
662
+ * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
663
+ */
664
+ prependHook(hook: IHook, options?: PrependHookOptions): IHook | undefined;
665
+ /**
666
+ * Adds a handler that only executes once for a specific event before all other handlers.
667
+ * Equivalent to calling `onHook` with a self-removing wrapper and `{ position: "Top" }`.
668
+ * @param {IHook} hook - the hook containing event name and handler
669
+ * @param {PrependHookOptions} [options] - optional per-call options (e.g., useHookClone override)
670
+ * @returns {IHook | undefined} the stored hook, or undefined if blocked by deprecation
671
+ */
672
+ prependOnceHook(hook: IHook, options?: PrependHookOptions): IHook | undefined;
673
+ /**
674
+ * Adds a handler that only executes once for a specific event
675
+ * @param {IHook} hook - the hook containing event name and handler
676
+ */
677
+ onceHook(hook: IHook): void;
678
+ /**
679
+ * Removes a handler function for a specific event
680
+ * @param {IHook} hook - the hook containing event name and handler to remove
681
+ * @returns {IHook | undefined} the removed hook, or undefined if not found
682
+ */
683
+ removeHook(hook: IHook): IHook | undefined;
684
+ /**
685
+ * Removes multiple hook handlers
686
+ * @param {Array<IHook>} hooks
687
+ * @returns {IHook[]} the hooks that were successfully removed
688
+ */
689
+ removeHooks(hooks: IHook[]): IHook[];
690
+ /**
691
+ * Calls all handlers for a specific event
692
+ * @param {string} event
693
+ * @param {T[]} arguments_
694
+ * @returns {Promise<void>}
695
+ */
696
+ hook<T>(event: string, ...arguments_: T[]): Promise<void>;
697
+ /**
698
+ * Calls all synchronous handlers for a specific event.
699
+ * Async handlers (declared with `async` keyword) are silently skipped.
700
+ *
701
+ * Note: The `hook` method is preferred as it executes both sync and async functions.
702
+ * Use `hookSync` only when you specifically need synchronous execution.
703
+ * @param {string} event
704
+ * @param {T[]} arguments_
705
+ * @returns {void}
706
+ */
707
+ hookSync<T>(event: string, ...arguments_: T[]): void;
708
+ /**
709
+ * Prepends the word `before` to your hook. Example is event is `test`, the before hook is `before:test`.
710
+ * @param {string} event - The event name
711
+ * @param {T[]} arguments_ - The arguments to pass to the hook
712
+ */
713
+ beforeHook<T>(event: string, ...arguments_: T[]): Promise<void>;
714
+ /**
715
+ * Prepends the word `after` to your hook. Example is event is `test`, the after hook is `after:test`.
716
+ * @param {string} event - The event name
717
+ * @param {T[]} arguments_ - The arguments to pass to the hook
718
+ */
719
+ afterHook<T>(event: string, ...arguments_: T[]): Promise<void>;
720
+ /**
721
+ * Calls all handlers for a specific event. This is an alias for `hook` and is provided for
722
+ * compatibility with other libraries that use the `callHook` method.
723
+ * @param {string} event
724
+ * @param {T[]} arguments_
725
+ * @returns {Promise<void>}
726
+ */
727
+ callHook<T>(event: string, ...arguments_: T[]): Promise<void>;
728
+ /**
729
+ * Gets all hooks for a specific event
730
+ * @param {string} event
731
+ * @returns {IHook[]}
732
+ */
733
+ getHooks(event: string): IHook[] | undefined;
734
+ /**
735
+ * Gets a specific hook by id, searching across all events
736
+ * @param {string} id - the hook id
737
+ * @returns {IHook | undefined} the hook if found, or undefined
738
+ */
739
+ getHook(id: string): IHook | undefined;
740
+ /**
741
+ * Removes one or more hooks by id, searching across all events
742
+ * @param {string | string[]} id - the hook id or array of hook ids to remove
743
+ * @returns {IHook | IHook[] | undefined} the removed hook(s), or undefined/empty array if not found
744
+ */
745
+ removeHookById(id: string | string[]): IHook | IHook[] | undefined;
746
+ /**
747
+ * Removes all hooks
748
+ * @returns {void}
749
+ */
750
+ clearHooks(): void;
751
+ /**
752
+ * Removes all hooks for a specific event and returns the removed hooks.
753
+ * @param {string} event - The event name to remove hooks for.
754
+ * @returns {IHook[]} the hooks that were removed
755
+ */
756
+ removeEventHooks(event: string): IHook[];
757
+ /**
758
+ * Validates hook event name if enforceBeforeAfter is enabled
759
+ * @param {string} event - The event name to validate
760
+ * @throws {Error} If enforceBeforeAfter is true and event doesn't start with 'before' or 'after'
761
+ */
762
+ private validateHookName;
763
+ /**
764
+ * Checks if a hook is deprecated and emits a warning if it is
765
+ * @param {string} event - The event name to check
766
+ * @returns {boolean} - Returns true if the hook should proceed, false if it should be blocked
767
+ */
768
+ private checkDeprecatedHook;
670
769
  }
671
-
672
- export { type EventEmitterOptions, type EventListener, Eventified, Hook, type HookFn, Hookified, type HookifiedOptions, type IEventEmitter, type IHook, type IWaterfallHook, type Logger, type OnHookOptions, type PrependHookOptions, WaterfallHook, type WaterfallHookContext, type WaterfallHookFn, type WaterfallHookResult };
770
+ //#endregion
771
+ export { type EventEmitterOptions, type EventListener, Eventified, Hook, type HookFn, Hookified, type HookifiedOptions, type IEventEmitter, type IHook, type IParallelHook, type IWaterfallHook, type Logger, type OnHookOptions, ParallelHook, type ParallelHookContext, type ParallelHookFinalContext, type ParallelHookFinalFn, type ParallelHookFn, type ParallelHookResult, type PrependHookOptions, WaterfallHook, type WaterfallHookContext, type WaterfallHookFn, type WaterfallHookResult };