@wooksjs/event-core 0.5.2 → 0.5.3

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.
package/dist/index.cjs CHANGED
@@ -4,8 +4,9 @@ var crypto = require('crypto');
4
4
  var node_async_hooks = require('node:async_hooks');
5
5
  var logger = require('@prostojs/logger');
6
6
 
7
- class Hookable {
7
+ class Hookable extends node_async_hooks.AsyncResource {
8
8
  constructor() {
9
+ super('hookable');
9
10
  this.hooks = {};
10
11
  }
11
12
  hook(name, cb) {
@@ -21,7 +22,7 @@ class Hookable {
21
22
  if (this.hooks[name]) {
22
23
  for (const cb of this.hooks[name]) {
23
24
  try {
24
- cb(...args);
25
+ this.runInAsyncScope(cb, null, ...args);
25
26
  }
26
27
  catch (error) {
27
28
  console.error(`Error in hook ${name}:`, error);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _prostojs_logger from '@prostojs/logger';
2
2
  import { TProstoLoggerOptions, ProstoLogger } from '@prostojs/logger';
3
- import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
4
4
 
5
5
  declare function useEventId(): {
6
6
  getId: () => string;
@@ -292,7 +292,8 @@ declare function useRouteParams<T extends object = Record<string, string | strin
292
292
  };
293
293
 
294
294
  type HookCallback = (...args: any[]) => any;
295
- declare class Hookable {
295
+ declare class Hookable extends AsyncResource {
296
+ constructor();
296
297
  private hooks;
297
298
  /**
298
299
  * Registers a callback to a specific hook name.
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { randomUUID } from 'crypto';
2
- import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { AsyncResource, AsyncLocalStorage } from 'node:async_hooks';
3
3
  import { ProstoLogger, createConsoleTransort, coloredConsole } from '@prostojs/logger';
4
4
 
5
- class Hookable {
5
+ class Hookable extends AsyncResource {
6
6
  constructor() {
7
+ super('hookable');
7
8
  this.hooks = {};
8
9
  }
9
10
  hook(name, cb) {
@@ -19,7 +20,7 @@ class Hookable {
19
20
  if (this.hooks[name]) {
20
21
  for (const cb of this.hooks[name]) {
21
22
  try {
22
- cb(...args);
23
+ this.runInAsyncScope(cb, null, ...args);
23
24
  }
24
25
  catch (error) {
25
26
  console.error(`Error in hook ${name}:`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-core",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "@wooksjs/event-core",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",