@bool-ts/core 1.8.0 → 1.8.1

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.
@@ -2,9 +2,11 @@ import type { TWebSocketEventHandlerMetadata } from "../decorators";
2
2
  export declare class WebSocketRoute {
3
3
  readonly eventName: string;
4
4
  readonly metadata: TWebSocketEventHandlerMetadata;
5
+ private _context;
5
6
  constructor({ eventName, metadata }: {
6
7
  eventName: string;
7
8
  metadata: TWebSocketEventHandlerMetadata;
8
9
  });
9
10
  bind(instance: Object): ThisType<WebSocketRoute>;
11
+ execute(): Readonly<TWebSocketEventHandlerMetadata>;
10
12
  }
@@ -1,15 +1,22 @@
1
1
  export class WebSocketRoute {
2
2
  eventName;
3
3
  metadata;
4
+ _context = undefined;
4
5
  constructor({ eventName, metadata }) {
5
6
  this.eventName = eventName;
6
7
  this.metadata = metadata;
7
8
  }
8
9
  bind(instance) {
9
- if (typeof this.metadata.descriptor.value !== "function") {
10
- return this;
11
- }
12
- this.metadata.descriptor.value = this.metadata.descriptor.value.bind(instance);
10
+ this._context = instance;
13
11
  return this;
14
12
  }
13
+ execute() {
14
+ return Object.freeze({
15
+ methodName: this.metadata.methodName,
16
+ descriptor: !this._context || typeof this.metadata.descriptor.value !== "function"
17
+ ? this.metadata.descriptor
18
+ : this.metadata.descriptor.value.bind(this._context),
19
+ arguments: this.metadata.arguments
20
+ });
21
+ }
15
22
  }
@@ -16,7 +16,7 @@ export declare class WebSocketRouter {
16
16
  * @param instance
17
17
  * @returns
18
18
  */
19
- bind(instance: Object): this;
19
+ bind(instance: Object): ThisType<WebSocketRouter>;
20
20
  /**
21
21
  * Generate map for websocket handler metadata
22
22
  * @returns
@@ -37,7 +37,7 @@ export class WebSocketRouter {
37
37
  execute() {
38
38
  const map = new Map();
39
39
  for (const route of this.routes) {
40
- map.set(`${this.alias}:::${route.eventName}`, route.metadata);
40
+ map.set(`${this.alias}:::${route.eventName}`, route.execute());
41
41
  }
42
42
  return map;
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -3,6 +3,7 @@ import type { TWebSocketEventHandlerMetadata } from "../decorators";
3
3
  export class WebSocketRoute {
4
4
  public readonly eventName: string;
5
5
  public readonly metadata: TWebSocketEventHandlerMetadata;
6
+ private _context: Object | undefined = undefined;
6
7
 
7
8
  constructor({
8
9
  eventName,
@@ -16,12 +17,19 @@ export class WebSocketRoute {
16
17
  }
17
18
 
18
19
  public bind(instance: Object): ThisType<WebSocketRoute> {
19
- if (typeof this.metadata.descriptor.value !== "function") {
20
- return this;
21
- }
22
-
23
- this.metadata.descriptor.value = this.metadata.descriptor.value.bind(instance);
20
+ this._context = instance;
24
21
 
25
22
  return this;
26
23
  }
24
+
25
+ public execute(): Readonly<TWebSocketEventHandlerMetadata> {
26
+ return Object.freeze({
27
+ methodName: this.metadata.methodName,
28
+ descriptor:
29
+ !this._context || typeof this.metadata.descriptor.value !== "function"
30
+ ? this.metadata.descriptor
31
+ : this.metadata.descriptor.value.bind(this._context),
32
+ arguments: this.metadata.arguments
33
+ });
34
+ }
27
35
  }
@@ -29,7 +29,7 @@ export class WebSocketRouter {
29
29
  * @param instance
30
30
  * @returns
31
31
  */
32
- public bind(instance: Object) {
32
+ public bind(instance: Object): ThisType<WebSocketRouter> {
33
33
  for (const route of this.routes) {
34
34
  route.bind(instance);
35
35
  }
@@ -45,7 +45,7 @@ export class WebSocketRouter {
45
45
  const map = new Map<string, TWebSocketEventHandlerMetadata>();
46
46
 
47
47
  for (const route of this.routes) {
48
- map.set(`${this.alias}:::${route.eventName}`, route.metadata);
48
+ map.set(`${this.alias}:::${route.eventName}`, route.execute());
49
49
  }
50
50
 
51
51
  return map;