@tsed/socketio 8.11.1 → 8.11.2-rc.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.
- package/lib/esm/SocketIOModule.js +0 -1
- package/lib/esm/class/SocketHandlersBuilder.js +0 -1
- package/lib/esm/class/SocketProviderMetadata.js +0 -1
- package/lib/esm/class/SocketSessionData.js +0 -1
- package/lib/esm/constants/constants.js +0 -1
- package/lib/esm/decorators/args.js +0 -1
- package/lib/esm/decorators/broadcast.js +0 -1
- package/lib/esm/decorators/broadcastOthers.js +0 -1
- package/lib/esm/decorators/emit.js +0 -1
- package/lib/esm/decorators/input.js +0 -1
- package/lib/esm/decorators/inputAndBroadcast.js +0 -1
- package/lib/esm/decorators/inputAndBroadcastOthers.js +0 -1
- package/lib/esm/decorators/inputAndEmit.js +0 -1
- package/lib/esm/decorators/io.js +0 -1
- package/lib/esm/decorators/nsp.js +0 -1
- package/lib/esm/decorators/reason.js +0 -1
- package/lib/esm/decorators/socket.js +0 -1
- package/lib/esm/decorators/socketErr.js +0 -1
- package/lib/esm/decorators/socketEventName.js +0 -1
- package/lib/esm/decorators/socketFilter.js +0 -1
- package/lib/esm/decorators/socketMiddleware.js +0 -1
- package/lib/esm/decorators/socketMiddlewareError.js +0 -1
- package/lib/esm/decorators/socketNsp.js +0 -1
- package/lib/esm/decorators/socketReturns.js +0 -1
- package/lib/esm/decorators/socketService.js +0 -1
- package/lib/esm/decorators/socketSession.js +0 -1
- package/lib/esm/decorators/socketUseAfter.js +0 -1
- package/lib/esm/decorators/socketUseBefore.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/interfaces/OnNamespaceInit.js +0 -1
- package/lib/esm/interfaces/SocketFilters.js +0 -1
- package/lib/esm/interfaces/SocketHandlerMetadata.js +0 -1
- package/lib/esm/interfaces/SocketInjectableNsp.js +0 -1
- package/lib/esm/interfaces/SocketParamMetadata.js +0 -1
- package/lib/esm/interfaces/SocketProviderTypes.js +0 -1
- package/lib/esm/interfaces/SocketReturnsTypes.js +0 -1
- package/lib/esm/interfaces/interfaces.js +0 -1
- package/lib/esm/services/SocketIOServer.js +0 -1
- package/lib/esm/services/SocketIOService.js +0 -1
- package/package.json +15 -12
- package/lib/esm/SocketIOModule.js.map +0 -1
- package/lib/esm/class/SocketHandlersBuilder.js.map +0 -1
- package/lib/esm/class/SocketProviderMetadata.js.map +0 -1
- package/lib/esm/class/SocketSessionData.js.map +0 -1
- package/lib/esm/constants/constants.js.map +0 -1
- package/lib/esm/decorators/args.js.map +0 -1
- package/lib/esm/decorators/broadcast.js.map +0 -1
- package/lib/esm/decorators/broadcastOthers.js.map +0 -1
- package/lib/esm/decorators/emit.js.map +0 -1
- package/lib/esm/decorators/input.js.map +0 -1
- package/lib/esm/decorators/inputAndBroadcast.js.map +0 -1
- package/lib/esm/decorators/inputAndBroadcastOthers.js.map +0 -1
- package/lib/esm/decorators/inputAndEmit.js.map +0 -1
- package/lib/esm/decorators/io.js.map +0 -1
- package/lib/esm/decorators/nsp.js.map +0 -1
- package/lib/esm/decorators/reason.js.map +0 -1
- package/lib/esm/decorators/socket.js.map +0 -1
- package/lib/esm/decorators/socketErr.js.map +0 -1
- package/lib/esm/decorators/socketEventName.js.map +0 -1
- package/lib/esm/decorators/socketFilter.js.map +0 -1
- package/lib/esm/decorators/socketMiddleware.js.map +0 -1
- package/lib/esm/decorators/socketMiddlewareError.js.map +0 -1
- package/lib/esm/decorators/socketNsp.js.map +0 -1
- package/lib/esm/decorators/socketReturns.js.map +0 -1
- package/lib/esm/decorators/socketService.js.map +0 -1
- package/lib/esm/decorators/socketSession.js.map +0 -1
- package/lib/esm/decorators/socketUseAfter.js.map +0 -1
- package/lib/esm/decorators/socketUseBefore.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/interfaces/OnNamespaceInit.js.map +0 -1
- package/lib/esm/interfaces/SocketFilters.js.map +0 -1
- package/lib/esm/interfaces/SocketHandlerMetadata.js.map +0 -1
- package/lib/esm/interfaces/SocketInjectableNsp.js.map +0 -1
- package/lib/esm/interfaces/SocketParamMetadata.js.map +0 -1
- package/lib/esm/interfaces/SocketProviderTypes.js.map +0 -1
- package/lib/esm/interfaces/SocketReturnsTypes.js.map +0 -1
- package/lib/esm/interfaces/interfaces.js.map +0 -1
- package/lib/esm/services/SocketIOServer.js.map +0 -1
- package/lib/esm/services/SocketIOService.js.map +0 -1
- package/src/SocketIOModule.spec.ts +0 -88
- package/src/SocketIOModule.ts +0 -114
- package/src/class/SocketHandlersBuilder.spec.ts +0 -988
- package/src/class/SocketHandlersBuilder.ts +0 -266
- package/src/class/SocketProviderMetadata.ts +0 -57
- package/src/class/SocketSessionData.spec.ts +0 -190
- package/src/class/SocketSessionData.ts +0 -81
- package/src/constants/constants.ts +0 -1
- package/src/decorators/args.spec.ts +0 -57
- package/src/decorators/args.ts +0 -60
- package/src/decorators/broadcast.spec.ts +0 -23
- package/src/decorators/broadcast.ts +0 -28
- package/src/decorators/broadcastOthers.spec.ts +0 -23
- package/src/decorators/broadcastOthers.ts +0 -28
- package/src/decorators/emit.spec.ts +0 -23
- package/src/decorators/emit.ts +0 -28
- package/src/decorators/input.spec.ts +0 -22
- package/src/decorators/input.ts +0 -33
- package/src/decorators/inputAndBroadcast.spec.ts +0 -25
- package/src/decorators/inputAndBroadcast.ts +0 -28
- package/src/decorators/inputAndBroadcastOthers.spec.ts +0 -24
- package/src/decorators/inputAndBroadcastOthers.ts +0 -28
- package/src/decorators/inputAndEmit.spec.ts +0 -24
- package/src/decorators/inputAndEmit.ts +0 -28
- package/src/decorators/io.ts +0 -34
- package/src/decorators/nsp.spec.ts +0 -70
- package/src/decorators/nsp.ts +0 -101
- package/src/decorators/reason.spec.ts +0 -26
- package/src/decorators/reason.ts +0 -30
- package/src/decorators/socket.spec.ts +0 -26
- package/src/decorators/socket.ts +0 -32
- package/src/decorators/socketErr.spec.ts +0 -25
- package/src/decorators/socketErr.ts +0 -26
- package/src/decorators/socketEventName.spec.ts +0 -25
- package/src/decorators/socketEventName.ts +0 -26
- package/src/decorators/socketFilter.ts +0 -27
- package/src/decorators/socketMiddleware.spec.ts +0 -21
- package/src/decorators/socketMiddleware.ts +0 -72
- package/src/decorators/socketMiddlewareError.spec.ts +0 -22
- package/src/decorators/socketMiddlewareError.ts +0 -70
- package/src/decorators/socketNsp.spec.ts +0 -26
- package/src/decorators/socketNsp.ts +0 -32
- package/src/decorators/socketReturns.ts +0 -25
- package/src/decorators/socketService.spec.ts +0 -44
- package/src/decorators/socketService.ts +0 -24
- package/src/decorators/socketSession.spec.ts +0 -47
- package/src/decorators/socketSession.ts +0 -53
- package/src/decorators/socketUseAfter.spec.ts +0 -38
- package/src/decorators/socketUseAfter.ts +0 -69
- package/src/decorators/socketUseBefore.spec.ts +0 -34
- package/src/decorators/socketUseBefore.ts +0 -73
- package/src/index.ts +0 -41
- package/src/interfaces/OnNamespaceInit.ts +0 -8
- package/src/interfaces/SocketFilters.ts +0 -14
- package/src/interfaces/SocketHandlerMetadata.ts +0 -17
- package/src/interfaces/SocketInjectableNsp.ts +0 -4
- package/src/interfaces/SocketParamMetadata.ts +0 -9
- package/src/interfaces/SocketProviderTypes.ts +0 -7
- package/src/interfaces/SocketReturnsTypes.ts +0 -8
- package/src/interfaces/interfaces.ts +0 -9
- package/src/services/SocketIOServer.spec.ts +0 -33
- package/src/services/SocketIOServer.ts +0 -15
- package/src/services/SocketIOService.spec.ts +0 -54
- package/src/services/SocketIOService.ts +0 -69
- package/vitest.config.mts +0 -21
package/src/decorators/args.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
});
|
package/src/decorators/emit.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
});
|
package/src/decorators/input.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
package/src/decorators/io.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
});
|
package/src/decorators/nsp.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
});
|