@tsed/socketio 8.0.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/package.json +16 -15
  2. package/src/SocketIOModule.spec.ts +87 -0
  3. package/src/SocketIOModule.ts +113 -0
  4. package/src/class/SocketHandlersBuilder.spec.ts +988 -0
  5. package/src/class/SocketHandlersBuilder.ts +266 -0
  6. package/src/class/SocketProviderMetadata.ts +57 -0
  7. package/src/class/SocketSessionData.spec.ts +190 -0
  8. package/src/class/SocketSessionData.ts +81 -0
  9. package/src/constants/constants.ts +1 -0
  10. package/src/decorators/args.spec.ts +57 -0
  11. package/src/decorators/args.ts +60 -0
  12. package/src/decorators/broadcast.spec.ts +23 -0
  13. package/src/decorators/broadcast.ts +28 -0
  14. package/src/decorators/broadcastOthers.spec.ts +23 -0
  15. package/src/decorators/broadcastOthers.ts +28 -0
  16. package/src/decorators/emit.spec.ts +23 -0
  17. package/src/decorators/emit.ts +28 -0
  18. package/src/decorators/input.spec.ts +22 -0
  19. package/src/decorators/input.ts +33 -0
  20. package/src/decorators/inputAndBroadcast.spec.ts +25 -0
  21. package/src/decorators/inputAndBroadcast.ts +28 -0
  22. package/src/decorators/inputAndBroadcastOthers.spec.ts +24 -0
  23. package/src/decorators/inputAndBroadcastOthers.ts +28 -0
  24. package/src/decorators/inputAndEmit.spec.ts +24 -0
  25. package/src/decorators/inputAndEmit.ts +28 -0
  26. package/src/decorators/io.ts +34 -0
  27. package/src/decorators/nsp.spec.ts +70 -0
  28. package/src/decorators/nsp.ts +101 -0
  29. package/src/decorators/reason.spec.ts +26 -0
  30. package/src/decorators/reason.ts +30 -0
  31. package/src/decorators/socket.spec.ts +26 -0
  32. package/src/decorators/socket.ts +32 -0
  33. package/src/decorators/socketErr.spec.ts +25 -0
  34. package/src/decorators/socketErr.ts +26 -0
  35. package/src/decorators/socketEventName.spec.ts +25 -0
  36. package/src/decorators/socketEventName.ts +26 -0
  37. package/src/decorators/socketFilter.ts +27 -0
  38. package/src/decorators/socketMiddleware.spec.ts +21 -0
  39. package/src/decorators/socketMiddleware.ts +72 -0
  40. package/src/decorators/socketMiddlewareError.spec.ts +22 -0
  41. package/src/decorators/socketMiddlewareError.ts +70 -0
  42. package/src/decorators/socketNsp.spec.ts +26 -0
  43. package/src/decorators/socketNsp.ts +32 -0
  44. package/src/decorators/socketReturns.ts +25 -0
  45. package/src/decorators/socketService.spec.ts +44 -0
  46. package/src/decorators/socketService.ts +24 -0
  47. package/src/decorators/socketSession.spec.ts +47 -0
  48. package/src/decorators/socketSession.ts +53 -0
  49. package/src/decorators/socketUseAfter.spec.ts +38 -0
  50. package/src/decorators/socketUseAfter.ts +69 -0
  51. package/src/decorators/socketUseBefore.spec.ts +34 -0
  52. package/src/decorators/socketUseBefore.ts +73 -0
  53. package/src/index.ts +41 -0
  54. package/src/interfaces/OnNamespaceInit.ts +8 -0
  55. package/src/interfaces/SocketFilters.ts +14 -0
  56. package/src/interfaces/SocketHandlerMetadata.ts +17 -0
  57. package/src/interfaces/SocketInjectableNsp.ts +4 -0
  58. package/src/interfaces/SocketParamMetadata.ts +9 -0
  59. package/src/interfaces/SocketProviderTypes.ts +7 -0
  60. package/src/interfaces/SocketReturnsTypes.ts +8 -0
  61. package/src/interfaces/interfaces.ts +9 -0
  62. package/src/services/SocketIOServer.spec.ts +33 -0
  63. package/src/services/SocketIOServer.ts +15 -0
  64. package/src/services/SocketIOService.spec.ts +54 -0
  65. package/src/services/SocketIOService.ts +69 -0
@@ -0,0 +1,60 @@
1
+ import {isCollection, Metadata, Store} from "@tsed/core";
2
+
3
+ import {SocketFilters} from "../interfaces/SocketFilters.js";
4
+
5
+ /**
6
+ * Inject the list of arguments in the decorated parameter.
7
+ *
8
+ * `@Args` accept an index parameter to pick up directly the item in the arguments list.
9
+ *
10
+ * ### Example
11
+ *
12
+ * ```typescript
13
+ * @SocketService("/nsp")
14
+ * export class MyWS {
15
+ *
16
+ * @Input("event")
17
+ * myMethod(@Args() arguments: any[]) {
18
+ *
19
+ * }
20
+ *
21
+ * @Input("event2")
22
+ * myMethod2(@Args(0) data: any) {
23
+ *
24
+ * }
25
+ * }
26
+ * ```
27
+ *
28
+ * @decorator
29
+ * @param mapIndex
30
+ * @param useType
31
+ */
32
+ export function Args(mapIndex?: number, useType?: any): any {
33
+ return (target: any, propertyKey: string, index: number) => {
34
+ const store = Store.from(target);
35
+ const type = Metadata.getParamTypes(target, propertyKey)[index];
36
+ const param = {
37
+ filter: SocketFilters.ARGS,
38
+ useMapper: false
39
+ };
40
+
41
+ if (mapIndex !== undefined) {
42
+ Object.assign(param, {
43
+ mapIndex,
44
+ useMapper: true,
45
+ type: useType || type,
46
+ collectionType: isCollection(type) ? type : undefined
47
+ });
48
+ }
49
+
50
+ store.merge("socketIO", {
51
+ handlers: {
52
+ [propertyKey]: {
53
+ parameters: {
54
+ [index]: param
55
+ }
56
+ }
57
+ }
58
+ });
59
+ };
60
+ }
@@ -0,0 +1,23 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {Broadcast} from "../index.js";
4
+
5
+ describe("Broadcast", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ Broadcast("eventName")(Test, "test", {} as any);
10
+ const store = Store.from(Test);
11
+
12
+ expect(store.get("socketIO")).toEqual({
13
+ handlers: {
14
+ test: {
15
+ returns: {
16
+ eventName: "eventName",
17
+ type: "broadcast"
18
+ }
19
+ }
20
+ }
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,28 @@
1
+ import {SocketReturnsTypes} from "../interfaces/SocketReturnsTypes.js";
2
+ import {SocketReturns} from "./socketReturns.js";
3
+
4
+ /**
5
+ * Broadcast the response for all client registered in the same namespace.
6
+ *
7
+ * With the `@Broadcast` decorator, the method will accept a return type (Promise or not).
8
+ *
9
+ * ### Example
10
+ *
11
+ * ```typescript
12
+ * @SocketService("/nsp")
13
+ * export class MyWS {
14
+ *
15
+ * @Input("event")
16
+ * @Broadcast("returnEvent")
17
+ * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
18
+ * return Promise.resolve({data})
19
+ * }
20
+ * }
21
+ * ```
22
+ *
23
+ * @decorator
24
+ * @param eventName
25
+ */
26
+ export function Broadcast(eventName: string) {
27
+ return SocketReturns(eventName, SocketReturnsTypes.BROADCAST);
28
+ }
@@ -0,0 +1,23 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {BroadcastOthers} from "../index.js";
4
+
5
+ describe("BroadcastOthers", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ BroadcastOthers("eventName")(Test, "test", {} as any);
10
+ const store = Store.from(Test);
11
+
12
+ expect(store.get("socketIO")).toEqual({
13
+ handlers: {
14
+ test: {
15
+ returns: {
16
+ eventName: "eventName",
17
+ type: "broadcastOthers"
18
+ }
19
+ }
20
+ }
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,28 @@
1
+ import {SocketReturnsTypes} from "../interfaces/SocketReturnsTypes.js";
2
+ import {SocketReturns} from "./socketReturns.js";
3
+
4
+ /**
5
+ * Broadcast the response for all client registered in the same namespace except to the current client.
6
+ *
7
+ * With the `@BroadcastOthers` decorator, the method will accept a return type (Promise or not).
8
+ *
9
+ * ### Example
10
+ *
11
+ * ```typescript
12
+ * @SocketService("/nsp")
13
+ * export class MyWS {
14
+ *
15
+ * @Input("event")
16
+ * @BroadcastOthers("returnEvent")
17
+ * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
18
+ * return Promise.resolve({data})
19
+ * }
20
+ * }
21
+ * ```
22
+ *
23
+ * @decorator
24
+ * @param eventName
25
+ */
26
+ export function BroadcastOthers(eventName: string) {
27
+ return SocketReturns(eventName, SocketReturnsTypes.BROADCAST_OTHERS);
28
+ }
@@ -0,0 +1,23 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {Emit} from "../index.js";
4
+
5
+ describe("Emit", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ Emit("eventName")(Test, "test", {} as any);
10
+
11
+ const store = Store.from(Test);
12
+ expect(store.get("socketIO")).toEqual({
13
+ handlers: {
14
+ test: {
15
+ returns: {
16
+ eventName: "eventName",
17
+ type: "emit"
18
+ }
19
+ }
20
+ }
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,28 @@
1
+ import {SocketReturnsTypes} from "../interfaces/SocketReturnsTypes.js";
2
+ import {SocketReturns} from "./socketReturns.js";
3
+
4
+ /**
5
+ * Emit the response to the client.
6
+ *
7
+ * With the `@Emit` decorator, the method will accept a return type (Promise or not).
8
+ *
9
+ * ### Example
10
+ *
11
+ * ```typescript
12
+ * @SocketService("/nsp")
13
+ * export class MyWS {
14
+ *
15
+ * @Input("event")
16
+ * @Emit("returnEvent")
17
+ * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
18
+ * return Promise.resolve({data})
19
+ * }
20
+ * }
21
+ * ```
22
+ *
23
+ * @decorator
24
+ * @param eventName
25
+ */
26
+ export function Emit(eventName: string) {
27
+ return SocketReturns(eventName, SocketReturnsTypes.EMIT);
28
+ }
@@ -0,0 +1,22 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {Input} from "../index.js";
4
+
5
+ describe("Input", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ Input("eventName")(Test, "test", {} as any);
10
+
11
+ const store = Store.from(Test);
12
+
13
+ expect(store.get("socketIO")).toEqual({
14
+ handlers: {
15
+ test: {
16
+ eventName: "eventName",
17
+ methodClassName: "test"
18
+ }
19
+ }
20
+ });
21
+ });
22
+ });
@@ -0,0 +1,33 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ /**
4
+ * Attach the decorated method to the socket event.
5
+ *
6
+ * ### Example
7
+ *
8
+ * ```typescript
9
+ * @SocketService("/nsp")
10
+ * export class MyWS {
11
+ *
12
+ * @Input("event")
13
+ * myMethod(@Args(0) data: any, @Nsp socket) {
14
+ *
15
+ * }
16
+ * }
17
+ * ```
18
+ *
19
+ * @decorator
20
+ * @param eventName
21
+ */
22
+ export function Input(eventName: string) {
23
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
24
+ Store.from(target).merge("socketIO", {
25
+ handlers: {
26
+ [propertyKey]: {
27
+ eventName,
28
+ methodClassName: propertyKey
29
+ }
30
+ }
31
+ });
32
+ };
33
+ }
@@ -0,0 +1,25 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {InputAndBroadcast} from "../index.js";
4
+
5
+ describe("InputAndBroadcast", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ InputAndBroadcast("eventName")(Test, "test", {} as any);
10
+ const store = Store.from(Test);
11
+
12
+ expect(store.get("socketIO")).toEqual({
13
+ handlers: {
14
+ test: {
15
+ eventName: "eventName",
16
+ methodClassName: "test",
17
+ returns: {
18
+ eventName: "eventName",
19
+ type: "broadcast"
20
+ }
21
+ }
22
+ }
23
+ });
24
+ });
25
+ });
@@ -0,0 +1,28 @@
1
+ import {Broadcast} from "./broadcast.js";
2
+ import {Input} from "./input.js";
3
+
4
+ /**
5
+ * Attach the decorated method to the socket event and broadcast the response to all clients.
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * @SocketService("/nsp")
11
+ * export class MyWS {
12
+ *
13
+ * @InputAndBroadcast("event")
14
+ * async myMethod(@Args(0) data: any, @Nsp socket) {
15
+ * return {data: "data"};
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * @decorator
21
+ * @param eventName
22
+ */
23
+ export function InputAndBroadcast(eventName: string) {
24
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
25
+ Input(eventName)(target, propertyKey, descriptor);
26
+ Broadcast(eventName)(target, propertyKey, descriptor);
27
+ };
28
+ }
@@ -0,0 +1,24 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {InputAndBroadcastOthers} from "../index.js";
4
+
5
+ describe("InputAndBroadcastOthers", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ InputAndBroadcastOthers("eventName")(Test, "test", {} as any);
10
+ const store = Store.from(Test);
11
+ expect(store.get("socketIO")).toEqual({
12
+ handlers: {
13
+ test: {
14
+ eventName: "eventName",
15
+ methodClassName: "test",
16
+ returns: {
17
+ eventName: "eventName",
18
+ type: "broadcastOthers"
19
+ }
20
+ }
21
+ }
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,28 @@
1
+ import {BroadcastOthers} from "./broadcastOthers.js";
2
+ import {Input} from "./input.js";
3
+
4
+ /**
5
+ * Attach the decorated method to the socket event and broadcast the response to all clients with the exception of the connected customer.
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * @SocketService("/nsp")
11
+ * export class MyWS {
12
+ *
13
+ * @InputAndBroadcastOthers("event")
14
+ * async myMethod(@Args(0) data: any, @Nsp socket) {
15
+ * return {data: "data"};
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * @decorator
21
+ * @param eventName
22
+ */
23
+ export function InputAndBroadcastOthers(eventName: string) {
24
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
25
+ Input(eventName)(target, propertyKey, descriptor);
26
+ BroadcastOthers(eventName)(target, propertyKey, descriptor);
27
+ };
28
+ }
@@ -0,0 +1,24 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {InputAndEmit} from "../index.js";
4
+
5
+ describe("InputAndEmit", () => {
6
+ it("should set metadata", () => {
7
+ class Test {}
8
+
9
+ InputAndEmit("eventName")(Test, "test", {} as any);
10
+ const store = Store.from(Test);
11
+ expect(store.get("socketIO")).toEqual({
12
+ handlers: {
13
+ test: {
14
+ eventName: "eventName",
15
+ methodClassName: "test",
16
+ returns: {
17
+ eventName: "eventName",
18
+ type: "emit"
19
+ }
20
+ }
21
+ }
22
+ });
23
+ });
24
+ });
@@ -0,0 +1,28 @@
1
+ import {Emit} from "./emit.js";
2
+ import {Input} from "./input.js";
3
+
4
+ /**
5
+ * Attach the decorated method to the socket event and emit the response to the client.
6
+ *
7
+ * ### Example
8
+ *
9
+ * ```typescript
10
+ * @SocketService("/nsp")
11
+ * export class MyWS {
12
+ *
13
+ * @InputAndEmit("event")
14
+ * async myMethod(@Args(0) data: any, @Nsp socket) {
15
+ * return {data: "data"};
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * @decorator
21
+ * @param eventName
22
+ */
23
+ export function InputAndEmit(eventName: string) {
24
+ return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
25
+ Input(eventName)(target, propertyKey, descriptor);
26
+ Emit(eventName)(target, propertyKey, descriptor);
27
+ };
28
+ }
@@ -0,0 +1,34 @@
1
+ import {Type} from "@tsed/core";
2
+ import {Inject} from "@tsed/di";
3
+
4
+ import {Server} from "../services/SocketIOServer.js";
5
+
6
+ /**
7
+ * Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.
8
+ *
9
+ * ### Example
10
+ *
11
+ * ```typescript
12
+ * @SocketService("/nsp")
13
+ * export class MyWS {
14
+ * constructor(@IO private io: Server) {}
15
+ * }
16
+ * ```
17
+ *
18
+ * @param target
19
+ * @param targetKey
20
+ * @param descriptor
21
+ * @decorator
22
+ */
23
+ export function IO(): (...args: any[]) => any;
24
+ export function IO(target: Type<any>, targetKey: string | symbol | undefined, descriptor: TypedPropertyDescriptor<Function> | number): any;
25
+ export function IO(
26
+ target?: Type<any>,
27
+ targetKey?: string | symbol | undefined,
28
+ descriptor?: TypedPropertyDescriptor<Function> | number
29
+ ): any {
30
+ if (target) {
31
+ return Inject(Server)(target, targetKey, descriptor);
32
+ }
33
+ return Inject(Server);
34
+ }
@@ -0,0 +1,70 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {Nsp} from "../index.js";
4
+
5
+ describe("Nsp", () => {
6
+ describe("when it used as param decorator", () => {
7
+ class Test {}
8
+
9
+ it("should set metadata", () => {
10
+ Nsp(Test, "test", 0);
11
+ const store = Store.from(Test);
12
+
13
+ expect(store.get("socketIO")).toEqual({
14
+ handlers: {
15
+ test: {
16
+ parameters: {
17
+ "0": {
18
+ filter: "nsp",
19
+ mapIndex: undefined
20
+ }
21
+ }
22
+ }
23
+ }
24
+ });
25
+ });
26
+ });
27
+
28
+ describe("when it used as property decorator", () => {
29
+ class Test {}
30
+
31
+ beforeAll(() => {});
32
+
33
+ it("should set metadata", () => {
34
+ Nsp(Test.prototype, "test");
35
+
36
+ const store = Store.from(Test);
37
+ expect(store.get("socketIO")).toEqual({
38
+ injectNamespaces: [{propertyKey: "test"}]
39
+ });
40
+ });
41
+ });
42
+
43
+ describe("when it used as property decorator with parameters", () => {
44
+ it("should set metadata (string)", () => {
45
+ class Test {
46
+ @Nsp("/test")
47
+ property: any;
48
+ }
49
+
50
+ const store = Store.from(Test);
51
+ expect(store.get("socketIO")).toEqual({
52
+ injectNamespaces: [{propertyKey: "property", nsp: "/test"}]
53
+ });
54
+ });
55
+
56
+ it("should set metadata (RegExp)", () => {
57
+ const regexp = new RegExp(/test/);
58
+
59
+ class Test {
60
+ @Nsp(regexp)
61
+ property: any;
62
+ }
63
+
64
+ const store = Store.from(Test);
65
+ expect(store.get("socketIO")).toEqual({
66
+ injectNamespaces: [{propertyKey: "property", nsp: regexp}]
67
+ });
68
+ });
69
+ });
70
+ });
@@ -0,0 +1,101 @@
1
+ import {decoratorTypeOf, DecoratorTypes, isRegExp, Store} from "@tsed/core";
2
+ import {Namespace as NamespaceType} from "socket.io";
3
+
4
+ import {SocketFilters} from "../interfaces/SocketFilters.js";
5
+ import {SocketFilter} from "./socketFilter.js";
6
+
7
+ export type Namespace = NamespaceType;
8
+ export type Nsp = NamespaceType;
9
+
10
+ /**
11
+ * Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
12
+ * Note that when using dynamic namespaces, when injecting a parameter, you may want to consider using @SocketNsp instead.
13
+ *
14
+ * ### Example
15
+ *
16
+ * ```typescript
17
+ * import {Nsp, SocketService, Input} from "@tsed/socketio";
18
+ *
19
+ * @SocketService("/nsp")
20
+ * export class MyWS {
21
+ *
22
+ * @Nsp
23
+ * nsp: SocketIO.Namespace; // will inject SocketIO.Namespace (not available on constructor)
24
+ *
25
+ * @Nsp("/my-other-namespace")
26
+ * nspOther: SocketIO.Namespace; // communication between two namespace
27
+ *
28
+ * @Nsp(/regexp/)
29
+ * nspDynamic: SocketIO.Namespace; // will inject a dynamic namespace (not available on constructor)
30
+ *
31
+ * @Input("event")
32
+ * myMethod(@Nsp namespace: SocketIO.Namespace) {
33
+ *
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @param target
39
+ * @param {string} propertyKey
40
+ * @param {number} index
41
+ * @decorator
42
+ */
43
+ export function Nsp(target: any, propertyKey?: string, index?: number): any {
44
+ return Namespace(target, propertyKey, index);
45
+ }
46
+
47
+ /**
48
+ * Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
49
+ * Note that when using dynamic namespaces, when injecting a parameter, you may want to consider using @SocketNsp instead.
50
+ *
51
+ * ### Example
52
+ *
53
+ * ```typescript
54
+ * import {Namespace, SocketService, Input} from "@tsed/socketio";
55
+ *
56
+ * @SocketService("/nsp")
57
+ * export class MyWS {
58
+ *
59
+ * @Namespace
60
+ * nsp: SocketIO.Namespace; // will inject SocketIO.Namespace (not available on constructor)
61
+ *
62
+ * @Namespace("/my-other-namespace")
63
+ * nspOther: SocketIO.Namespace; // communication between two namespace
64
+ *
65
+ * @Namespace(/regexp/)
66
+ * nspDynamic: SocketIO.Namespace; // will inject a dynamic namespace (not available on constructor)
67
+ *
68
+ * @Input("event")
69
+ * myMethod(@Namespace namespace: Namespace) {
70
+ *
71
+ * }
72
+ * }
73
+ * ```
74
+ *
75
+ * @param target
76
+ * @param {string} propertyKey
77
+ * @param {number} index
78
+ * @alias {Nsp}
79
+ * @decorator
80
+ */
81
+ export function Namespace(target: any, propertyKey?: string, index?: number): any {
82
+ if (typeof target === "string" || isRegExp(target)) {
83
+ const nsp = target as string | RegExp;
84
+
85
+ return (target: any, propertyKey: string) => {
86
+ Store.from(target).merge("socketIO", {
87
+ injectNamespaces: [{propertyKey, nsp}]
88
+ });
89
+ };
90
+ }
91
+
92
+ if (decoratorTypeOf([target, propertyKey, index]) === DecoratorTypes.PROP) {
93
+ Store.from(target).merge("socketIO", {
94
+ injectNamespaces: [{propertyKey}]
95
+ });
96
+
97
+ return;
98
+ }
99
+
100
+ return SocketFilter(SocketFilters.NSP)(target, propertyKey!, index!);
101
+ }
@@ -0,0 +1,26 @@
1
+ import {Store} from "@tsed/core";
2
+
3
+ import {Nsp, SocketErr} from "../index.js";
4
+ import {Reason} from "./reason.js";
5
+
6
+ describe("Reason", () => {
7
+ it("should set metadata", () => {
8
+ class Test {}
9
+
10
+ Reason(Test, "test", 0);
11
+ const store = Store.from(Test);
12
+
13
+ expect(store.get("socketIO")).toEqual({
14
+ handlers: {
15
+ test: {
16
+ parameters: {
17
+ "0": {
18
+ filter: "reason",
19
+ mapIndex: undefined
20
+ }
21
+ }
22
+ }
23
+ }
24
+ });
25
+ });
26
+ });