@tsed/socketio 6.87.1 → 6.89.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.
- package/lib/{SocketIOModule.d.ts → cjs/SocketIOModule.d.ts} +0 -0
- package/lib/{SocketIOModule.js → cjs/SocketIOModule.js} +20 -20
- package/lib/cjs/SocketIOModule.js.map +1 -0
- package/lib/{class → cjs/class}/SocketHandlersBuilder.d.ts +0 -0
- package/lib/{class → cjs/class}/SocketHandlersBuilder.js +1 -1
- package/lib/cjs/class/SocketHandlersBuilder.js.map +1 -0
- package/lib/{class → cjs/class}/SocketProviderMetadata.d.ts +0 -0
- package/lib/{class → cjs/class}/SocketProviderMetadata.js +0 -0
- package/lib/cjs/class/SocketProviderMetadata.js.map +1 -0
- package/lib/{constants → cjs/constants}/index.d.ts +0 -0
- package/lib/{constants → cjs/constants}/index.js +0 -0
- package/lib/cjs/constants/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/args.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/args.js +1 -1
- package/lib/cjs/decorators/args.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/broadcast.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/broadcast.js +1 -1
- package/lib/cjs/decorators/broadcast.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/broadcastOthers.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/broadcastOthers.js +1 -1
- package/lib/cjs/decorators/broadcastOthers.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/emit.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/emit.js +1 -1
- package/lib/cjs/decorators/emit.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/input.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/input.js +0 -0
- package/lib/cjs/decorators/input.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcast.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcast.js +2 -2
- package/lib/cjs/decorators/inputAndBroadcast.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcastOthers.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndBroadcastOthers.js +2 -2
- package/lib/cjs/decorators/inputAndBroadcastOthers.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/inputAndEmit.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/inputAndEmit.js +2 -2
- package/lib/cjs/decorators/inputAndEmit.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/io.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/io.js +1 -1
- package/lib/cjs/decorators/io.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/nsp.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/nsp.js +2 -2
- package/lib/cjs/decorators/nsp.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socket.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socket.js +1 -1
- package/lib/cjs/decorators/socket.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketErr.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketErr.js +1 -1
- package/lib/cjs/decorators/socketErr.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketEventName.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketEventName.js +1 -1
- package/lib/cjs/decorators/socketEventName.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketFilter.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketFilter.js +0 -0
- package/lib/cjs/decorators/socketFilter.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketMiddleware.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketMiddleware.js +1 -1
- package/lib/cjs/decorators/socketMiddleware.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketMiddlewareError.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketMiddlewareError.js +1 -1
- package/lib/cjs/decorators/socketMiddlewareError.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketReturns.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketReturns.js +0 -0
- package/lib/cjs/decorators/socketReturns.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketService.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketService.js +1 -1
- package/lib/cjs/decorators/socketService.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketSession.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketSession.js +1 -1
- package/lib/cjs/decorators/socketSession.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketUseAfter.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketUseAfter.js +0 -0
- package/lib/cjs/decorators/socketUseAfter.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/socketUseBefore.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/socketUseBefore.js +0 -0
- package/lib/cjs/decorators/socketUseBefore.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +32 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/OnNamespaceInit.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/OnNamespaceInit.js +0 -0
- package/lib/cjs/interfaces/OnNamespaceInit.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketFilters.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketFilters.js +0 -0
- package/lib/cjs/interfaces/SocketFilters.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketHandlerMetadata.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketHandlerMetadata.js +0 -0
- package/lib/cjs/interfaces/SocketHandlerMetadata.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketInjectableNsp.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketInjectableNsp.js +0 -0
- package/lib/cjs/interfaces/SocketInjectableNsp.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketParamMetadata.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketParamMetadata.js +0 -0
- package/lib/cjs/interfaces/SocketParamMetadata.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketProviderTypes.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketProviderTypes.js +0 -0
- package/lib/cjs/interfaces/SocketProviderTypes.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SocketReturnsTypes.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/SocketReturnsTypes.js +0 -0
- package/lib/cjs/interfaces/SocketReturnsTypes.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/cjs/interfaces/index.js +11 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/{registries → cjs/registries}/NspSessionRegistry.d.ts +0 -0
- package/lib/{registries → cjs/registries}/NspSessionRegistry.js +0 -0
- package/lib/cjs/registries/NspSessionRegistry.js.map +1 -0
- package/lib/{services → cjs/services}/SocketIOServer.d.ts +0 -0
- package/lib/{services → cjs/services}/SocketIOServer.js +1 -1
- package/lib/cjs/services/SocketIOServer.js.map +1 -0
- package/lib/{services → cjs/services}/SocketIOService.d.ts +0 -0
- package/lib/{services → cjs/services}/SocketIOService.js +5 -5
- package/lib/cjs/services/SocketIOService.js.map +1 -0
- package/lib/esm/SocketIOModule.js +105 -0
- package/lib/esm/SocketIOModule.js.map +1 -0
- package/lib/esm/class/SocketHandlersBuilder.js +202 -0
- package/lib/esm/class/SocketHandlersBuilder.js.map +1 -0
- package/lib/esm/class/SocketProviderMetadata.js +44 -0
- package/lib/esm/class/SocketProviderMetadata.js.map +1 -0
- package/lib/esm/constants/index.js +2 -0
- package/lib/esm/constants/index.js.map +1 -0
- package/lib/esm/decorators/args.js +57 -0
- package/lib/esm/decorators/args.js.map +1 -0
- package/lib/esm/decorators/broadcast.js +28 -0
- package/lib/esm/decorators/broadcast.js.map +1 -0
- package/lib/esm/decorators/broadcastOthers.js +28 -0
- package/lib/esm/decorators/broadcastOthers.js.map +1 -0
- package/lib/esm/decorators/emit.js +28 -0
- package/lib/esm/decorators/emit.js.map +1 -0
- package/lib/esm/decorators/input.js +33 -0
- package/lib/esm/decorators/input.js.map +1 -0
- package/lib/esm/decorators/inputAndBroadcast.js +28 -0
- package/lib/esm/decorators/inputAndBroadcast.js.map +1 -0
- package/lib/esm/decorators/inputAndBroadcastOthers.js +28 -0
- package/lib/esm/decorators/inputAndBroadcastOthers.js.map +1 -0
- package/lib/esm/decorators/inputAndEmit.js +28 -0
- package/lib/esm/decorators/inputAndEmit.js.map +1 -0
- package/lib/esm/decorators/io.js +23 -0
- package/lib/esm/decorators/io.js.map +1 -0
- package/lib/esm/decorators/nsp.js +83 -0
- package/lib/esm/decorators/nsp.js.map +1 -0
- package/lib/esm/decorators/socket.js +28 -0
- package/lib/esm/decorators/socket.js.map +1 -0
- package/lib/esm/decorators/socketErr.js +26 -0
- package/lib/esm/decorators/socketErr.js.map +1 -0
- package/lib/esm/decorators/socketEventName.js +26 -0
- package/lib/esm/decorators/socketEventName.js.map +1 -0
- package/lib/esm/decorators/socketFilter.js +25 -0
- package/lib/esm/decorators/socketFilter.js.map +1 -0
- package/lib/esm/decorators/socketMiddleware.js +70 -0
- package/lib/esm/decorators/socketMiddleware.js.map +1 -0
- package/lib/esm/decorators/socketMiddlewareError.js +67 -0
- package/lib/esm/decorators/socketMiddlewareError.js.map +1 -0
- package/lib/esm/decorators/socketReturns.js +23 -0
- package/lib/esm/decorators/socketReturns.js.map +1 -0
- package/lib/esm/decorators/socketService.js +20 -0
- package/lib/esm/decorators/socketService.js.map +1 -0
- package/lib/esm/decorators/socketSession.js +27 -0
- package/lib/esm/decorators/socketSession.js.map +1 -0
- package/lib/esm/decorators/socketUseAfter.js +70 -0
- package/lib/esm/decorators/socketUseAfter.js.map +1 -0
- package/lib/esm/decorators/socketUseBefore.js +74 -0
- package/lib/esm/decorators/socketUseBefore.js.map +1 -0
- package/lib/esm/index.js +29 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/OnNamespaceInit.js +2 -0
- package/lib/esm/interfaces/OnNamespaceInit.js.map +1 -0
- package/lib/esm/interfaces/SocketFilters.js +13 -0
- package/lib/esm/interfaces/SocketFilters.js.map +1 -0
- package/lib/esm/interfaces/SocketHandlerMetadata.js +2 -0
- package/lib/esm/interfaces/SocketHandlerMetadata.js.map +1 -0
- package/lib/esm/interfaces/SocketInjectableNsp.js +2 -0
- package/lib/esm/interfaces/SocketInjectableNsp.js.map +1 -0
- package/lib/esm/interfaces/SocketParamMetadata.js +2 -0
- package/lib/esm/interfaces/SocketParamMetadata.js.map +1 -0
- package/lib/esm/interfaces/SocketProviderTypes.js +9 -0
- package/lib/esm/interfaces/SocketProviderTypes.js.map +1 -0
- package/lib/esm/interfaces/SocketReturnsTypes.js +10 -0
- package/lib/esm/interfaces/SocketReturnsTypes.js.map +1 -0
- package/lib/esm/interfaces/index.js +8 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/registries/NspSessionRegistry.js +12 -0
- package/lib/esm/registries/NspSessionRegistry.js.map +1 -0
- package/lib/esm/services/SocketIOServer.js +12 -0
- package/lib/esm/services/SocketIOServer.js.map +1 -0
- package/lib/esm/services/SocketIOService.js +64 -0
- package/lib/esm/services/SocketIOService.js.map +1 -0
- package/lib/types/SocketIOModule.d.ts +29 -0
- package/lib/types/class/SocketHandlersBuilder.d.ts +47 -0
- package/lib/types/class/SocketProviderMetadata.d.ts +19 -0
- package/lib/types/constants/index.d.ts +1 -0
- package/lib/types/decorators/args.d.ts +28 -0
- package/lib/types/decorators/broadcast.d.ts +23 -0
- package/lib/types/decorators/broadcastOthers.d.ts +23 -0
- package/lib/types/decorators/emit.d.ts +23 -0
- package/lib/types/decorators/input.d.ts +20 -0
- package/lib/types/decorators/inputAndBroadcast.d.ts +20 -0
- package/lib/types/decorators/inputAndBroadcastOthers.d.ts +20 -0
- package/lib/types/decorators/inputAndEmit.d.ts +20 -0
- package/lib/types/decorators/io.d.ts +19 -0
- package/lib/types/decorators/nsp.d.ts +64 -0
- package/lib/types/decorators/socket.d.ts +25 -0
- package/lib/types/decorators/socketErr.d.ts +21 -0
- package/lib/types/decorators/socketEventName.d.ts +21 -0
- package/lib/types/decorators/socketFilter.d.ts +9 -0
- package/lib/types/decorators/socketMiddleware.d.ts +54 -0
- package/lib/types/decorators/socketMiddlewareError.d.ts +50 -0
- package/lib/types/decorators/socketReturns.d.ts +9 -0
- package/lib/types/decorators/socketService.d.ts +11 -0
- package/lib/types/decorators/socketSession.d.ts +23 -0
- package/lib/types/decorators/socketUseAfter.d.ts +52 -0
- package/lib/types/decorators/socketUseBefore.d.ts +56 -0
- package/lib/types/index.d.ts +25 -0
- package/lib/types/interfaces/OnNamespaceInit.d.ts +7 -0
- package/lib/types/interfaces/SocketFilters.d.ts +11 -0
- package/lib/types/interfaces/SocketHandlerMetadata.d.ts +18 -0
- package/lib/types/interfaces/SocketInjectableNsp.d.ts +4 -0
- package/lib/types/interfaces/SocketParamMetadata.d.ts +7 -0
- package/lib/types/interfaces/SocketProviderTypes.d.ts +7 -0
- package/lib/types/interfaces/SocketReturnsTypes.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +15 -0
- package/lib/types/registries/NspSessionRegistry.d.ts +1 -0
- package/lib/types/services/SocketIOServer.d.ts +4 -0
- package/lib/types/services/SocketIOService.d.ts +30 -0
- package/package.json +25 -17
- package/tsconfig.compile.esm.json +23 -0
- package/lib/SocketIOModule.js.map +0 -1
- package/lib/class/SocketHandlersBuilder.js.map +0 -1
- package/lib/class/SocketProviderMetadata.js.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/decorators/args.js.map +0 -1
- package/lib/decorators/broadcast.js.map +0 -1
- package/lib/decorators/broadcastOthers.js.map +0 -1
- package/lib/decorators/emit.js.map +0 -1
- package/lib/decorators/input.js.map +0 -1
- package/lib/decorators/inputAndBroadcast.js.map +0 -1
- package/lib/decorators/inputAndBroadcastOthers.js.map +0 -1
- package/lib/decorators/inputAndEmit.js.map +0 -1
- package/lib/decorators/io.js.map +0 -1
- package/lib/decorators/nsp.js.map +0 -1
- package/lib/decorators/socket.js.map +0 -1
- package/lib/decorators/socketErr.js.map +0 -1
- package/lib/decorators/socketEventName.js.map +0 -1
- package/lib/decorators/socketFilter.js.map +0 -1
- package/lib/decorators/socketMiddleware.js.map +0 -1
- package/lib/decorators/socketMiddlewareError.js.map +0 -1
- package/lib/decorators/socketReturns.js.map +0 -1
- package/lib/decorators/socketService.js.map +0 -1
- package/lib/decorators/socketSession.js.map +0 -1
- package/lib/decorators/socketUseAfter.js.map +0 -1
- package/lib/decorators/socketUseBefore.js.map +0 -1
- package/lib/index.js +0 -32
- package/lib/index.js.map +0 -1
- package/lib/interfaces/OnNamespaceInit.js.map +0 -1
- package/lib/interfaces/SocketFilters.js.map +0 -1
- package/lib/interfaces/SocketHandlerMetadata.js.map +0 -1
- package/lib/interfaces/SocketInjectableNsp.js.map +0 -1
- package/lib/interfaces/SocketParamMetadata.js.map +0 -1
- package/lib/interfaces/SocketProviderTypes.js.map +0 -1
- package/lib/interfaces/SocketReturnsTypes.js.map +0 -1
- package/lib/interfaces/index.js +0 -11
- package/lib/interfaces/index.js.map +0 -1
- package/lib/registries/NspSessionRegistry.js.map +0 -1
- package/lib/services/SocketIOServer.js.map +0 -1
- package/lib/services/SocketIOService.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isCollection, Metadata, Store } from "@tsed/core";
|
|
2
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
3
|
+
/**
|
|
4
|
+
* Inject the list of arguments in the decorated parameter.
|
|
5
|
+
*
|
|
6
|
+
* `@Args` accept an index parameter to pick up directly the item in the arguments list.
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @SocketService("/nsp")
|
|
12
|
+
* export class MyWS {
|
|
13
|
+
*
|
|
14
|
+
* @Input("event")
|
|
15
|
+
* myMethod(@Args() arguments: any[]) {
|
|
16
|
+
*
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* @Input("event2")
|
|
20
|
+
* myMethod2(@Args(0) data: any) {
|
|
21
|
+
*
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @decorator
|
|
27
|
+
* @param mapIndex
|
|
28
|
+
* @param useType
|
|
29
|
+
*/
|
|
30
|
+
export function Args(mapIndex, useType) {
|
|
31
|
+
return (target, propertyKey, index) => {
|
|
32
|
+
const store = Store.from(target);
|
|
33
|
+
const type = Metadata.getParamTypes(target, propertyKey)[index];
|
|
34
|
+
const param = {
|
|
35
|
+
filter: SocketFilters.ARGS,
|
|
36
|
+
useConverter: false
|
|
37
|
+
};
|
|
38
|
+
if (mapIndex !== undefined) {
|
|
39
|
+
Object.assign(param, {
|
|
40
|
+
mapIndex,
|
|
41
|
+
useConverter: true,
|
|
42
|
+
type: useType || type,
|
|
43
|
+
collectionType: isCollection(type) ? type : undefined
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
store.merge("socketIO", {
|
|
47
|
+
handlers: {
|
|
48
|
+
[propertyKey]: {
|
|
49
|
+
parameters: {
|
|
50
|
+
[index]: param
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/decorators/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AACzD,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,IAAI,CAAC,QAAiB,EAAE,OAAa;IACnD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa,EAAE,EAAE;QACzD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC;QAChE,MAAM,KAAK,GAAG;YACZ,MAAM,EAAE,aAAa,CAAC,IAAI;YAC1B,YAAY,EAAE,KAAK;SACpB,CAAC;QAEF,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;gBACnB,QAAQ;gBACR,YAAY,EAAE,IAAI;gBAClB,IAAI,EAAE,OAAO,IAAI,IAAI;gBACrB,cAAc,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;aACtD,CAAC,CAAC;SACJ;QAED,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE;YACtB,QAAQ,EAAE;gBACR,CAAC,WAAW,CAAC,EAAE;oBACb,UAAU,EAAE;wBACV,CAAC,KAAK,CAAC,EAAE,KAAK;qBACf;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {isCollection, Metadata, Store} from \"@tsed/core\";\nimport {SocketFilters} from \"../interfaces/SocketFilters\";\n\n/**\n * Inject the list of arguments in the decorated parameter.\n *\n * `@Args` accept an index parameter to pick up directly the item in the arguments list.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * myMethod(@Args() arguments: any[]) {\n *\n * }\n *\n * @Input(\"event2\")\n * myMethod2(@Args(0) data: any) {\n *\n * }\n * }\n * ```\n *\n * @decorator\n * @param mapIndex\n * @param useType\n */\nexport function Args(mapIndex?: number, useType?: any): any {\n return (target: any, propertyKey: string, index: number) => {\n const store = Store.from(target);\n const type = Metadata.getParamTypes(target, propertyKey)[index];\n const param = {\n filter: SocketFilters.ARGS,\n useConverter: false\n };\n\n if (mapIndex !== undefined) {\n Object.assign(param, {\n mapIndex,\n useConverter: true,\n type: useType || type,\n collectionType: isCollection(type) ? type : undefined\n });\n }\n\n store.merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n parameters: {\n [index]: param\n }\n }\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SocketReturnsTypes } from "../interfaces/SocketReturnsTypes";
|
|
2
|
+
import { SocketReturns } from "./socketReturns";
|
|
3
|
+
/**
|
|
4
|
+
* Broadcast the response for all client registered in the same namespace.
|
|
5
|
+
*
|
|
6
|
+
* With the `@Broadcast` decorator, the method will accept a return type (Promise or not).
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @SocketService("/nsp")
|
|
12
|
+
* export class MyWS {
|
|
13
|
+
*
|
|
14
|
+
* @Input("event")
|
|
15
|
+
* @Broadcast("returnEvent")
|
|
16
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
17
|
+
* return Promise.resolve({data})
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @decorator
|
|
23
|
+
* @param eventName
|
|
24
|
+
*/
|
|
25
|
+
export function Broadcast(eventName) {
|
|
26
|
+
return SocketReturns(eventName, SocketReturnsTypes.BROADCAST);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=broadcast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcast.js","sourceRoot":"","sources":["../../../src/decorators/broadcast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,SAAS,CAAC,SAAiB;IACzC,OAAO,aAAa,CAAC,SAAS,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import {SocketReturnsTypes} from \"../interfaces/SocketReturnsTypes\";\nimport {SocketReturns} from \"./socketReturns\";\n\n/**\n * Broadcast the response for all client registered in the same namespace.\n *\n * With the `@Broadcast` decorator, the method will accept a return type (Promise or not).\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * @Broadcast(\"returnEvent\")\n * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {\n * return Promise.resolve({data})\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function Broadcast(eventName: string) {\n return SocketReturns(eventName, SocketReturnsTypes.BROADCAST);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SocketReturnsTypes } from "../interfaces/SocketReturnsTypes";
|
|
2
|
+
import { SocketReturns } from "./socketReturns";
|
|
3
|
+
/**
|
|
4
|
+
* Broadcast the response for all client registered in the same namespace except to the current client.
|
|
5
|
+
*
|
|
6
|
+
* With the `@BroadcastOthers` decorator, the method will accept a return type (Promise or not).
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @SocketService("/nsp")
|
|
12
|
+
* export class MyWS {
|
|
13
|
+
*
|
|
14
|
+
* @Input("event")
|
|
15
|
+
* @BroadcastOthers("returnEvent")
|
|
16
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
17
|
+
* return Promise.resolve({data})
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @decorator
|
|
23
|
+
* @param eventName
|
|
24
|
+
*/
|
|
25
|
+
export function BroadcastOthers(eventName) {
|
|
26
|
+
return SocketReturns(eventName, SocketReturnsTypes.BROADCAST_OTHERS);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=broadcastOthers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcastOthers.js","sourceRoot":"","sources":["../../../src/decorators/broadcastOthers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiB;IAC/C,OAAO,aAAa,CAAC,SAAS,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import {SocketReturnsTypes} from \"../interfaces/SocketReturnsTypes\";\nimport {SocketReturns} from \"./socketReturns\";\n\n/**\n * Broadcast the response for all client registered in the same namespace except to the current client.\n *\n * With the `@BroadcastOthers` decorator, the method will accept a return type (Promise or not).\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * @BroadcastOthers(\"returnEvent\")\n * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {\n * return Promise.resolve({data})\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function BroadcastOthers(eventName: string) {\n return SocketReturns(eventName, SocketReturnsTypes.BROADCAST_OTHERS);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SocketReturnsTypes } from "../interfaces/SocketReturnsTypes";
|
|
2
|
+
import { SocketReturns } from "./socketReturns";
|
|
3
|
+
/**
|
|
4
|
+
* Emit the response to the client.
|
|
5
|
+
*
|
|
6
|
+
* With the `@Emit` decorator, the method will accept a return type (Promise or not).
|
|
7
|
+
*
|
|
8
|
+
* ### Example
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @SocketService("/nsp")
|
|
12
|
+
* export class MyWS {
|
|
13
|
+
*
|
|
14
|
+
* @Input("event")
|
|
15
|
+
* @Emit("returnEvent")
|
|
16
|
+
* async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {
|
|
17
|
+
* return Promise.resolve({data})
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @decorator
|
|
23
|
+
* @param eventName
|
|
24
|
+
*/
|
|
25
|
+
export function Emit(eventName) {
|
|
26
|
+
return SocketReturns(eventName, SocketReturnsTypes.EMIT);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=emit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../../src/decorators/emit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,IAAI,CAAC,SAAiB;IACpC,OAAO,aAAa,CAAC,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import {SocketReturnsTypes} from \"../interfaces/SocketReturnsTypes\";\nimport {SocketReturns} from \"./socketReturns\";\n\n/**\n * Emit the response to the client.\n *\n * With the `@Emit` decorator, the method will accept a return type (Promise or not).\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * @Emit(\"returnEvent\")\n * async myMethod(@Args(0) data: any, @Nsp socket): Promise<any> {\n * return Promise.resolve({data})\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function Emit(eventName: string) {\n return SocketReturns(eventName, SocketReturnsTypes.EMIT);\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
* Attach the decorated method to the socket event.
|
|
4
|
+
*
|
|
5
|
+
* ### Example
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* @SocketService("/nsp")
|
|
9
|
+
* export class MyWS {
|
|
10
|
+
*
|
|
11
|
+
* @Input("event")
|
|
12
|
+
* myMethod(@Args(0) data: any, @Nsp socket) {
|
|
13
|
+
*
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @decorator
|
|
19
|
+
* @param eventName
|
|
20
|
+
*/
|
|
21
|
+
export function Input(eventName) {
|
|
22
|
+
return (target, propertyKey, descriptor) => {
|
|
23
|
+
Store.from(target).merge("socketIO", {
|
|
24
|
+
handlers: {
|
|
25
|
+
[propertyKey]: {
|
|
26
|
+
eventName,
|
|
27
|
+
methodClassName: propertyKey
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/decorators/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,KAAK,CAAC,SAAiB;IACrC,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,QAAQ,EAAE;gBACR,CAAC,WAAW,CAAC,EAAE;oBACb,SAAS;oBACT,eAAe,EAAE,WAAW;iBAC7B;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\n\n/**\n * Attach the decorated method to the socket event.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * myMethod(@Args(0) data: any, @Nsp socket) {\n *\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function Input(eventName: string) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Store.from(target).merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n eventName,\n methodClassName: propertyKey\n }\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Broadcast } from "./broadcast";
|
|
2
|
+
import { Input } from "./input";
|
|
3
|
+
/**
|
|
4
|
+
* Attach the decorated method to the socket event and broadcast the response to all clients.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @InputAndBroadcast("event")
|
|
13
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
14
|
+
* return {data: "data"};
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @decorator
|
|
20
|
+
* @param eventName
|
|
21
|
+
*/
|
|
22
|
+
export function InputAndBroadcast(eventName) {
|
|
23
|
+
return (target, propertyKey, descriptor) => {
|
|
24
|
+
Input(eventName)(target, propertyKey, descriptor);
|
|
25
|
+
Broadcast(eventName)(target, propertyKey, descriptor);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=inputAndBroadcast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputAndBroadcast.js","sourceRoot":"","sources":["../../../src/decorators/inputAndBroadcast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAClD,SAAS,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Broadcast} from \"./broadcast\";\nimport {Input} from \"./input\";\n\n/**\n * Attach the decorated method to the socket event and broadcast the response to all clients.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @InputAndBroadcast(\"event\")\n * async myMethod(@Args(0) data: any, @Nsp socket) {\n * return {data: \"data\"};\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function InputAndBroadcast(eventName: string) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Input(eventName)(target, propertyKey, descriptor);\n Broadcast(eventName)(target, propertyKey, descriptor);\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BroadcastOthers } from "./broadcastOthers";
|
|
2
|
+
import { Input } from "./input";
|
|
3
|
+
/**
|
|
4
|
+
* Attach the decorated method to the socket event and broadcast the response to all clients with the exception of the connected customer.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @InputAndBroadcastOthers("event")
|
|
13
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
14
|
+
* return {data: "data"};
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @decorator
|
|
20
|
+
* @param eventName
|
|
21
|
+
*/
|
|
22
|
+
export function InputAndBroadcastOthers(eventName) {
|
|
23
|
+
return (target, propertyKey, descriptor) => {
|
|
24
|
+
Input(eventName)(target, propertyKey, descriptor);
|
|
25
|
+
BroadcastOthers(eventName)(target, propertyKey, descriptor);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=inputAndBroadcastOthers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputAndBroadcastOthers.js","sourceRoot":"","sources":["../../../src/decorators/inputAndBroadcastOthers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAClD,eAAe,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {BroadcastOthers} from \"./broadcastOthers\";\nimport {Input} from \"./input\";\n\n/**\n * Attach the decorated method to the socket event and broadcast the response to all clients with the exception of the connected customer.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @InputAndBroadcastOthers(\"event\")\n * async myMethod(@Args(0) data: any, @Nsp socket) {\n * return {data: \"data\"};\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function InputAndBroadcastOthers(eventName: string) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Input(eventName)(target, propertyKey, descriptor);\n BroadcastOthers(eventName)(target, propertyKey, descriptor);\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Emit } from "./emit";
|
|
2
|
+
import { Input } from "./input";
|
|
3
|
+
/**
|
|
4
|
+
* Attach the decorated method to the socket event and emit the response to the client.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @InputAndEmit("event")
|
|
13
|
+
* async myMethod(@Args(0) data: any, @Nsp socket) {
|
|
14
|
+
* return {data: "data"};
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @decorator
|
|
20
|
+
* @param eventName
|
|
21
|
+
*/
|
|
22
|
+
export function InputAndEmit(eventName) {
|
|
23
|
+
return (target, propertyKey, descriptor) => {
|
|
24
|
+
Input(eventName)(target, propertyKey, descriptor);
|
|
25
|
+
Emit(eventName)(target, propertyKey, descriptor);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=inputAndEmit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputAndEmit.js","sourceRoot":"","sources":["../../../src/decorators/inputAndEmit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Emit} from \"./emit\";\nimport {Input} from \"./input\";\n\n/**\n * Attach the decorated method to the socket event and emit the response to the client.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @InputAndEmit(\"event\")\n * async myMethod(@Args(0) data: any, @Nsp socket) {\n * return {data: \"data\"};\n * }\n * }\n * ```\n *\n * @decorator\n * @param eventName\n */\nexport function InputAndEmit(eventName: string) {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Input(eventName)(target, propertyKey, descriptor);\n Emit(eventName)(target, propertyKey, descriptor);\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Inject } from "@tsed/common";
|
|
2
|
+
import { Server } from "../services/SocketIOServer";
|
|
3
|
+
/**
|
|
4
|
+
* Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
* constructor(@IO private io: Server) {}
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @param target
|
|
16
|
+
* @param targetKey
|
|
17
|
+
* @param descriptor
|
|
18
|
+
* @decorator
|
|
19
|
+
*/
|
|
20
|
+
export function IO(target, targetKey, descriptor) {
|
|
21
|
+
return Inject(Server)(target, targetKey, descriptor);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../../src/decorators/io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,EAAE,CAAC,MAAiB,EAAE,SAAiB,EAAE,UAAsD;IAC7G,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import {Inject} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport {Server} from \"../services/SocketIOServer\";\n\n/**\n * Inject the [SocketIO.Server](https://socket.io/docs/server-api/) instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n * constructor(@IO private io: Server) {}\n * }\n * ```\n *\n * @param target\n * @param targetKey\n * @param descriptor\n * @decorator\n */\nexport function IO(target: Type<any>, targetKey: string, descriptor: TypedPropertyDescriptor<Function> | number) {\n return Inject(Server)(target, targetKey, descriptor);\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { decoratorTypeOf, DecoratorTypes, Store } from "@tsed/core";
|
|
2
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
3
|
+
import { SocketFilter } from "./socketFilter";
|
|
4
|
+
/**
|
|
5
|
+
* Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Nsp, SocketService, Input} from "@tsed/socketio";
|
|
11
|
+
*
|
|
12
|
+
* @SocketService("/nsp")
|
|
13
|
+
* export class MyWS {
|
|
14
|
+
*
|
|
15
|
+
* @Nsp
|
|
16
|
+
* nsp: SocketIO.Namespace; // will inject SocketIO.Namespace (not available on constructor)
|
|
17
|
+
*
|
|
18
|
+
* @Nsp("/my-other-namespace")
|
|
19
|
+
* nspOther: SocketIO.Namespace; // communication between two namespace
|
|
20
|
+
*
|
|
21
|
+
* @Input("event")
|
|
22
|
+
* myMethod(@Nsp namespace: SocketIO.Namespace) {
|
|
23
|
+
*
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param target
|
|
29
|
+
* @param {string} propertyKey
|
|
30
|
+
* @param {number} index
|
|
31
|
+
* @decorator
|
|
32
|
+
*/
|
|
33
|
+
export function Nsp(target, propertyKey, index) {
|
|
34
|
+
return Namespace(target, propertyKey, index);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.
|
|
38
|
+
*
|
|
39
|
+
* ### Example
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import {Namespace, SocketService, Input} from "@tsed/socketio";
|
|
43
|
+
*
|
|
44
|
+
* @SocketService("/nsp")
|
|
45
|
+
* export class MyWS {
|
|
46
|
+
*
|
|
47
|
+
* @Nsp
|
|
48
|
+
* nsp: Namespace; // will inject SocketIO.Namespace (not available on constructor)
|
|
49
|
+
*
|
|
50
|
+
* @Nsp("/my-other-namespace")
|
|
51
|
+
* nspOther: Namespace; // communication between two namespace
|
|
52
|
+
*
|
|
53
|
+
* @Input("event")
|
|
54
|
+
* myMethod(@Namespace namespace: Namespace) {
|
|
55
|
+
*
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param target
|
|
61
|
+
* @param {string} propertyKey
|
|
62
|
+
* @param {number} index
|
|
63
|
+
* @alias {Nsp}
|
|
64
|
+
* @decorator
|
|
65
|
+
*/
|
|
66
|
+
export function Namespace(target, propertyKey, index) {
|
|
67
|
+
if (typeof target === "string") {
|
|
68
|
+
const nsp = target;
|
|
69
|
+
return (target, propertyKey) => {
|
|
70
|
+
Store.from(target).merge("socketIO", {
|
|
71
|
+
injectNamespaces: [{ propertyKey, nsp }]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (decoratorTypeOf([target, propertyKey, index]) === DecoratorTypes.PROP) {
|
|
76
|
+
Store.from(target).merge("socketIO", {
|
|
77
|
+
injectNamespaces: [{ propertyKey }]
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return SocketFilter(SocketFilters.NSP)(target, propertyKey, index);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=nsp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nsp.js","sourceRoot":"","sources":["../../../src/decorators/nsp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAElE,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAK5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,GAAG,CAAC,MAAW,EAAE,WAAoB,EAAE,KAAc;IACnE,OAAO,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,SAAS,CAAC,MAAW,EAAE,WAAoB,EAAE,KAAc;IACzE,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,MAAM,GAAG,GAAG,MAAgB,CAAC;QAE7B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;YAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;gBACnC,gBAAgB,EAAE,CAAC,EAAC,WAAW,EAAE,GAAG,EAAC,CAAC;aACvC,CAAC,CAAC;QACL,CAAC,CAAC;KACH;IAED,IAAI,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,KAAK,cAAc,CAAC,IAAI,EAAE;QACzE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,gBAAgB,EAAE,CAAC,EAAC,WAAW,EAAC,CAAC;SAClC,CAAC,CAAC;QAEH,OAAO;KACR;IAED,OAAO,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAY,EAAE,KAAM,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store} from \"@tsed/core\";\nimport {Namespace as NamespaceType} from \"socket.io\";\nimport {SocketFilters} from \"../interfaces/SocketFilters\";\nimport {SocketFilter} from \"./socketFilter\";\n\nexport type Namespace = NamespaceType;\nexport type Nsp = NamespaceType;\n\n/**\n * Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * import {Nsp, SocketService, Input} from \"@tsed/socketio\";\n *\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Nsp\n * nsp: SocketIO.Namespace; // will inject SocketIO.Namespace (not available on constructor)\n *\n * @Nsp(\"/my-other-namespace\")\n * nspOther: SocketIO.Namespace; // communication between two namespace\n *\n * @Input(\"event\")\n * myMethod(@Nsp namespace: SocketIO.Namespace) {\n *\n * }\n * }\n * ```\n *\n * @param target\n * @param {string} propertyKey\n * @param {number} index\n * @decorator\n */\nexport function Nsp(target: any, propertyKey?: string, index?: number): any {\n return Namespace(target, propertyKey, index);\n}\n\n/**\n * Inject the [SocketIO.Namespace](https://socket.io/docs/rooms-and-namespaces/#namespaces) instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * import {Namespace, SocketService, Input} from \"@tsed/socketio\";\n *\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Nsp\n * nsp: Namespace; // will inject SocketIO.Namespace (not available on constructor)\n *\n * @Nsp(\"/my-other-namespace\")\n * nspOther: Namespace; // communication between two namespace\n *\n * @Input(\"event\")\n * myMethod(@Namespace namespace: Namespace) {\n *\n * }\n * }\n * ```\n *\n * @param target\n * @param {string} propertyKey\n * @param {number} index\n * @alias {Nsp}\n * @decorator\n */\nexport function Namespace(target: any, propertyKey?: string, index?: number): any {\n if (typeof target === \"string\") {\n const nsp = target as string;\n\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(\"socketIO\", {\n injectNamespaces: [{propertyKey, nsp}]\n });\n };\n }\n\n if (decoratorTypeOf([target, propertyKey, index]) === DecoratorTypes.PROP) {\n Store.from(target).merge(\"socketIO\", {\n injectNamespaces: [{propertyKey}]\n });\n\n return;\n }\n\n return SocketFilter(SocketFilters.NSP)(target, propertyKey!, index!);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
2
|
+
import { SocketFilter } from "./socketFilter";
|
|
3
|
+
/**
|
|
4
|
+
* Inject the Socket instance in the decorated parameter.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketService("/nsp")
|
|
10
|
+
* export class MyWS {
|
|
11
|
+
*
|
|
12
|
+
* @Input("event")
|
|
13
|
+
* myMethod(@Socket socket) {
|
|
14
|
+
*
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
* @param target
|
|
21
|
+
* @param {string} propertyKey
|
|
22
|
+
* @param {number} index
|
|
23
|
+
* @decorator
|
|
24
|
+
*/
|
|
25
|
+
export function Socket(target, propertyKey, index) {
|
|
26
|
+
return SocketFilter(SocketFilters.SOCKET)(target, propertyKey, index);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=socket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../src/decorators/socket.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa;IACpE,OAAO,YAAY,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import {Socket as SocketType} from \"socket.io\";\nimport {SocketFilters} from \"../interfaces/SocketFilters\";\nimport {SocketFilter} from \"./socketFilter\";\n\nexport type Socket = SocketType;\n\n/**\n * Inject the Socket instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketService(\"/nsp\")\n * export class MyWS {\n *\n * @Input(\"event\")\n * myMethod(@Socket socket) {\n *\n * }\n * }\n * ```\n *\n * @experimental\n * @param target\n * @param {string} propertyKey\n * @param {number} index\n * @decorator\n */\nexport function Socket(target: any, propertyKey: string, index: number): any {\n return SocketFilter(SocketFilters.SOCKET)(target, propertyKey, index);\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
2
|
+
import { SocketFilter } from "./socketFilter";
|
|
3
|
+
/**
|
|
4
|
+
* Inject the error in the parameters
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketMiddlewareError()
|
|
10
|
+
* export class MyMiddleware {
|
|
11
|
+
*
|
|
12
|
+
* myMethod(@SocketErr err: any, @Args() arguments: any[]) {
|
|
13
|
+
*
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @decorator
|
|
19
|
+
* @param target
|
|
20
|
+
* @param propertyKey
|
|
21
|
+
* @param index
|
|
22
|
+
*/
|
|
23
|
+
export function SocketErr(target, propertyKey, index) {
|
|
24
|
+
return SocketFilter(SocketFilters.ERR)(target, propertyKey, index);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=socketErr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketErr.js","sourceRoot":"","sources":["../../../src/decorators/socketErr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa;IACvE,OAAO,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import {SocketFilters} from \"../interfaces/SocketFilters\";\nimport {SocketFilter} from \"./socketFilter\";\n\n/**\n * Inject the error in the parameters\n *\n * ### Example\n *\n * ```typescript\n * @SocketMiddlewareError()\n * export class MyMiddleware {\n *\n * myMethod(@SocketErr err: any, @Args() arguments: any[]) {\n *\n * }\n * }\n * ```\n *\n * @decorator\n * @param target\n * @param propertyKey\n * @param index\n */\nexport function SocketErr(target: any, propertyKey: string, index: number): any {\n return SocketFilter(SocketFilters.ERR)(target, propertyKey, index);\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SocketFilters } from "../interfaces/SocketFilters";
|
|
2
|
+
import { SocketFilter } from "./socketFilter";
|
|
3
|
+
/**
|
|
4
|
+
* Inject the Socket instance in the decorated parameter.
|
|
5
|
+
*
|
|
6
|
+
* ### Example
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* @SocketMiddleware("/nsp")
|
|
10
|
+
* export class MyMiddleware {
|
|
11
|
+
* use(@SocketEventName eventName: string) {
|
|
12
|
+
*
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @experimental
|
|
18
|
+
* @param target
|
|
19
|
+
* @param {string} propertyKey
|
|
20
|
+
* @param {number} index
|
|
21
|
+
* @decorator
|
|
22
|
+
*/
|
|
23
|
+
export function SocketEventName(target, propertyKey, index) {
|
|
24
|
+
return SocketFilter(SocketFilters.EVENT_NAME)(target, propertyKey, index);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=socketEventName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketEventName.js","sourceRoot":"","sources":["../../../src/decorators/socketEventName.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa;IAC7E,OAAO,YAAY,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import {SocketFilters} from \"../interfaces/SocketFilters\";\nimport {SocketFilter} from \"./socketFilter\";\n\n/**\n * Inject the Socket instance in the decorated parameter.\n *\n * ### Example\n *\n * ```typescript\n * @SocketMiddleware(\"/nsp\")\n * export class MyMiddleware {\n * use(@SocketEventName eventName: string) {\n *\n * }\n * }\n * ```\n *\n * @experimental\n * @param target\n * @param {string} propertyKey\n * @param {number} index\n * @decorator\n */\nexport function SocketEventName(target: any, propertyKey: string, index: number): any {\n return SocketFilter(SocketFilters.EVENT_NAME)(target, propertyKey, index);\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {SocketFilters} filter
|
|
5
|
+
* @param {number} mapIndex
|
|
6
|
+
* @returns {(target: any, propertyKey: string, index: number) => Store}
|
|
7
|
+
* @decorator
|
|
8
|
+
*/
|
|
9
|
+
export function SocketFilter(filter, mapIndex) {
|
|
10
|
+
return (target, propertyKey, index) => {
|
|
11
|
+
Store.from(target).merge("socketIO", {
|
|
12
|
+
handlers: {
|
|
13
|
+
[propertyKey]: {
|
|
14
|
+
parameters: {
|
|
15
|
+
[index]: {
|
|
16
|
+
filter,
|
|
17
|
+
mapIndex
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=socketFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketFilter.js","sourceRoot":"","sources":["../../../src/decorators/socketFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAGjC;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAAqB,EAAE,QAAiB;IACnE,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,KAAa,EAAE,EAAE;QACzD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,QAAQ,EAAE;gBACR,CAAC,WAAW,CAAC,EAAE;oBACb,UAAU,EAAE;wBACV,CAAC,KAAK,CAAC,EAAE;4BACP,MAAM;4BACN,QAAQ;yBACT;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {SocketFilters} from \"../interfaces/SocketFilters\";\n\n/**\n *\n * @param {SocketFilters} filter\n * @param {number} mapIndex\n * @returns {(target: any, propertyKey: string, index: number) => Store}\n * @decorator\n */\nexport function SocketFilter(filter: SocketFilters, mapIndex?: number) {\n return (target: any, propertyKey: string, index: number) => {\n Store.from(target).merge(\"socketIO\", {\n handlers: {\n [propertyKey]: {\n parameters: {\n [index]: {\n filter,\n mapIndex\n }\n }\n }\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Middleware } from "@tsed/common";
|
|
2
|
+
import { Store } from "@tsed/core";
|
|
3
|
+
import { SocketProviderTypes } from "../interfaces";
|
|
4
|
+
/**
|
|
5
|
+
* Declare a new SocketMiddleware.
|
|
6
|
+
*
|
|
7
|
+
* ### Example
|
|
8
|
+
*
|
|
9
|
+
* A middleware can be also used on a `SocketService` either on a class or on a method.
|
|
10
|
+
*
|
|
11
|
+
* Here an example of a middleware:
|
|
12
|
+
*
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @SocketMiddleware()
|
|
15
|
+
* export class UserConverterSocketMiddleware {
|
|
16
|
+
* constructor(private converterService: ConverterService) {
|
|
17
|
+
* }
|
|
18
|
+
* async use(@Args() args: any[]) {
|
|
19
|
+
*
|
|
20
|
+
* let [user] = args;
|
|
21
|
+
* // update Arguments
|
|
22
|
+
* user = this.converterService.deserialize(user, User);
|
|
23
|
+
*
|
|
24
|
+
* return [user];
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
* > The user instance will be forwarded to the next middleware and to your decorated method.
|
|
29
|
+
*
|
|
30
|
+
* Then:
|
|
31
|
+
*
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from "@tsed/socketio";
|
|
34
|
+
* import {UserConverterSocketMiddleware} from "../middlewares";
|
|
35
|
+
* import {User} from "../models/User";
|
|
36
|
+
*
|
|
37
|
+
* @SocketService("/my-namespace")
|
|
38
|
+
* @SocketUseBefore(UserConverterSocketMiddleware) // global version
|
|
39
|
+
* export class MySocketService {
|
|
40
|
+
*
|
|
41
|
+
* @Input("eventName")
|
|
42
|
+
* @Emit("responseEventName") // or Broadcast or BroadcastOthers
|
|
43
|
+
* @SocketUseBefore(UserConverterSocketMiddleware)
|
|
44
|
+
* async myMethod(@Args(0) user: User) {
|
|
45
|
+
*
|
|
46
|
+
* console.log(user);
|
|
47
|
+
*
|
|
48
|
+
* return user;
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @returns {Function}
|
|
54
|
+
* @decorator
|
|
55
|
+
* @experimental
|
|
56
|
+
*/
|
|
57
|
+
export function SocketMiddleware() {
|
|
58
|
+
return (target) => {
|
|
59
|
+
Store.from(target).merge("socketIO", {
|
|
60
|
+
type: SocketProviderTypes.MIDDLEWARE,
|
|
61
|
+
handlers: {
|
|
62
|
+
use: {
|
|
63
|
+
methodClassName: "use"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return Middleware()(target);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=socketMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socketMiddleware.js","sourceRoot":"","sources":["../../../src/decorators/socketMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,MAAiB,EAAE,EAAE;QAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE;YACnC,IAAI,EAAE,mBAAmB,CAAC,UAAU;YACpC,QAAQ,EAAE;gBACR,GAAG,EAAE;oBACH,eAAe,EAAE,KAAK;iBACvB;aACF;SACF,CAAC,CAAC;QAEH,OAAO,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Middleware} from \"@tsed/common\";\nimport {Store, Type} from \"@tsed/core\";\nimport {SocketProviderTypes} from \"../interfaces\";\n\n/**\n * Declare a new SocketMiddleware.\n *\n * ### Example\n *\n * A middleware can be also used on a `SocketService` either on a class or on a method.\n *\n * Here an example of a middleware:\n *\n * ```typescript\n * @SocketMiddleware()\n * export class UserConverterSocketMiddleware {\n * constructor(private converterService: ConverterService) {\n * }\n * async use(@Args() args: any[]) {\n *\n * let [user] = args;\n * // update Arguments\n * user = this.converterService.deserialize(user, User);\n *\n * return [user];\n * }\n * }\n * ```\n * > The user instance will be forwarded to the next middleware and to your decorated method.\n *\n * Then:\n *\n * ```typescript\n * import {SocketService, SocketUseAfter, SocketUseBefore, Emit, Input, Args} from \"@tsed/socketio\";\n * import {UserConverterSocketMiddleware} from \"../middlewares\";\n * import {User} from \"../models/User\";\n *\n * @SocketService(\"/my-namespace\")\n * @SocketUseBefore(UserConverterSocketMiddleware) // global version\n * export class MySocketService {\n *\n * @Input(\"eventName\")\n * @Emit(\"responseEventName\") // or Broadcast or BroadcastOthers\n * @SocketUseBefore(UserConverterSocketMiddleware)\n * async myMethod(@Args(0) user: User) {\n *\n * console.log(user);\n *\n * return user;\n * }\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n * @experimental\n */\nexport function SocketMiddleware(): Function {\n return (target: Type<any>) => {\n Store.from(target).merge(\"socketIO\", {\n type: SocketProviderTypes.MIDDLEWARE,\n handlers: {\n use: {\n methodClassName: \"use\"\n }\n }\n });\n\n return Middleware()(target);\n };\n}\n"]}
|