Skip to content

Commit 795ef99

Browse files
authored
merge: release v0.1.1 (#547)
2 parents 7ffb712 + 8eeedc2 commit 795ef99

15 files changed

+1305
-923
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Dependabot auto-merge
2+
on:
3+
pull_request_target
4+
jobs:
5+
dependabot:
6+
runs-on: ubuntu-latest
7+
if: github.actor == 'dependabot[bot]'
8+
steps:
9+
- name: 'Auto approve PR by Dependabot'
10+
uses: hmarr/[email protected]
11+
with:
12+
github-token: "${{ secrets.TYPESTACK_BOT_TOKEN }}"
13+
- name: 'Comment merge command'
14+
uses: actions/github-script@v3
15+
with:
16+
github-token: ${{secrets.TYPESTACK_BOT_TOKEN }}
17+
script: |
18+
await github.issues.createComment({
19+
owner: context.repo.owner,
20+
repo: context.repo.repo,
21+
issue_number: context.issue.number,
22+
body: '@dependabot squash and merge'
23+
})

.github/workflows/auto-merge-dependabot-workflow.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
_This changelog follows the [keep a changelog][keep-a-changelog]_ format to maintain a human readable changelog.
44

5+
## [0.1.1](https://github.com/typestack/socket-controllers/compare/v0.1.0...v0.1.1) (2023-01-27)
6+
7+
### Added
8+
9+
- Added `@OnDisconnecting()` decorator
10+
- Added error type filter option to `@EmitOnFail()` decorator
11+
12+
Example: `@EmitOnFail('message', {errorType: TypeError})`
13+
14+
- Added `index` option to `@MessageBody()` decorator to be able to get multiple event arguments
15+
16+
Note: If you don't specify the index it will return the first
17+
18+
- Added support to use the same namespace for multiple controllers
19+
20+
Note: The namespaces must match exactly, providing a differnet pattern will not work due to a socket.io limitation
21+
22+
### Changed
23+
24+
- `glob` package updated from `8.0.3` to `8.1.0`
525

626
## [0.1.0](https://github.com/typestack/socket-controllers/compare/v0.0.5...v0.1.0) (2023-01-18)
727

@@ -107,7 +127,7 @@ _This changelog follows the [keep a changelog][keep-a-changelog]_ format to main
107127

108128
### Added
109129
- Namespace scope support for middlewares
110-
- `transport: boolean` option to decorators that support class-transformer
130+
- `transform: boolean` option to decorators that support class-transformer
111131

112132
### Changed
113133

@@ -117,8 +137,6 @@ _This changelog follows the [keep a changelog][keep-a-changelog]_ format to main
117137
- `socket.io` package updated from `2.0.1` to `4.5.4`
118138
- updated various dev dependencies
119139

120-
### Breaking changes
121-
122140

123141
### [0.0.5][v0.0.5] - 2020-02-04
124142

README.md

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ Use class-based controllers to handle websocket events. Helps to organize your c
9090

9191
## More usage examples
9292

93-
#### Run code on socket client connect / disconnect
93+
#### Run code on socket client connect / disconnect / disconnecting
9494

9595
Controller action marked with `@OnConnect()` decorator is called once new client connected.
9696
Controller action marked with `@OnDisconnect()` decorator is called once client disconnected.
97+
Controller action marked with `@OnDisconnecting()` decorator is called when the client is disconnecting, before the disconnect event.
9798

9899
```typescript
99-
import { SocketController, OnConnect, OnDisconnect } from 'socket-controllers';
100+
import { SocketController, OnConnect, OnDisconnect, OnDisconnecting } from 'socket-controllers';
100101

101102
@SocketController()
102103
export class MessageController {
@@ -109,6 +110,11 @@ export class MessageController {
109110
save() {
110111
console.log('client disconnected');
111112
}
113+
114+
@OnDisconnecting()
115+
save() {
116+
console.log('client is disconnecting');
117+
}
112118
}
113119
```
114120

@@ -146,7 +152,22 @@ export class MessageController {
146152

147153
If you specify a class type to parameter that is decorated with `@MessageBody()`,
148154
socket-controllers will use [class-transformer][1] to create instance of the given class type with the data received in the message.
149-
To disable this behaviour you need to specify a `{ transformOption: { transform: false ] }` in SocketControllerOptions when creating a server.
155+
To disable this behaviour you need to specify `{ transformOption: { transform: false ] }` in SocketControllerOptions when creating a server.
156+
157+
You can define an index to get multiple parameters from the socket event.
158+
159+
```typescript
160+
import { SocketController, OnMessage, MessageBody } from 'socket-controllers';
161+
162+
@SocketController()
163+
export class MessageController {
164+
@OnMessage('save')
165+
save(@MessageBody({index: 0}) param1: any, @MessageBody({index: 1}) param2: any) {
166+
console.log('received message: ', message1);
167+
console.log('received message: ', message2);
168+
}
169+
}
170+
```
150171

151172
#### `@SocketQueryParam()` decorator
152173

@@ -237,6 +258,8 @@ import { SocketController, OnMessage, EmitOnSuccess, EmitOnFail } from 'socket-c
237258
export class MessageController {
238259
@OnMessage('save')
239260
@EmitOnSuccess('save_successfully')
261+
@EmitOnFail('save_error_range', {errorType: RangeError})
262+
@EmitOnFail('save_error_type', {errorType: TypeError})
240263
@EmitOnFail('save_error')
241264
save() {
242265
if (1 === 1) {
@@ -251,6 +274,7 @@ export class MessageController {
251274
```
252275

253276
In this case `save_error` message will be sent to the client with `One is equal to one! Fatal error!` error message.
277+
The order is important when defining multiple `@EmitOnFail()` decorators, the first matching errorType will be served
254278

255279
Sometimes you may want to not emit success/error message if returned result is null or undefined.
256280
In such cases you can use `@SkipEmitOnEmptyResult()` decorator.
@@ -440,25 +464,26 @@ export class MessageController {
440464
441465
## Decorators Reference
442466

443-
| Signature | Description |
444-
| ---------------------------------------------- | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
445-
| `@SocketController(namespace?: string\|Regex)` | Registers a class to be a socket controller that can listen to websocket events and respond to them. |
446-
| `@OnMessage(messageName: string)` | Registers controller's action to be executed when socket receives message with given name. |
447-
| `@OnConnect()` | Registers controller's action to be executed when client connects to the socket. |
448-
| `@OnDisconnect()` | Registers controller's action to be executed when client disconnects from the socket. |
449-
| `@ConnectedSocket()` | Injects connected client's socket object to the controller action. |
450-
| `@SocketIO()` | Injects socket.io object that initialized a connection. |
451-
| `@MessageBody()` | Injects received message body. |
452-
| `@SocketQueryParam(paramName: string)` | Injects query parameter from the received socket request. |
453-
| `@SocketId()` | Injects socket id from the received request. |
454-
| `@SocketRequest()` | Injects request object received by socket. |
455-
| `@SocketRooms()` | Injects rooms of the connected socket client. |
456-
| `@NspParams()` | Injects dynamic namespace params. |
457-
| `@NspParam(paramName: string)` | Injects param from the dynamic namespace. |
458-
| `@Middleware()` | Registers a new middleware to be registered in the socket.io. |
459-
| `@EmitOnSuccess(messageName: string)` | If this decorator is set then after controller action will emit message with the given name after action execution. It will emit message only if controller succeed without errors. If result is a Promise then it will wait until promise is resolved and emit a message. |
460-
| `@EmitOnFail(messageName: string)` | If this decorator is set then after controller action will emit message with the given name after action execution. It will emit message only if controller throw an exception. If result is a Promise then it will wait until promise throw an error and emit a message. |
461-
| `@SkipEmitOnEmptyResult()` | Used in conjunction with @EmitOnSuccess and @EmitOnFail decorators. If result returned by controller action is null or undefined then messages will not be emitted by @EmitOnSuccess or @EmitOnFail decorators. | |
467+
| Signature | Description |
468+
|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
469+
| `@SocketController(namespace?: string\ | Regex)` | Registers a class to be a socket controller that can listen to websocket events and respond to them. |
470+
| `@OnMessage(messageName: string)` | Registers controller's action to be executed when socket receives message with given name. |
471+
| `@OnConnect()` | Registers controller's action to be executed when client connects to the socket. |
472+
| `@OnDisconnect()` | Registers controller's action to be executed when client disconnects from the socket. |
473+
| `@OnDisconnecting()` | Registers controller's action to be executed when client is disconnecting from the socket. |
474+
| `@ConnectedSocket()` | Injects connected client's socket object to the controller action. |
475+
| `@SocketIO()` | Injects socket.io object that initialized a connection. |
476+
| `@MessageBody()` | Injects received message body. |
477+
| `@SocketQueryParam(paramName: string)` | Injects query parameter from the received socket request. |
478+
| `@SocketId()` | Injects socket id from the received request. |
479+
| `@SocketRequest()` | Injects request object received by socket. |
480+
| `@SocketRooms()` | Injects rooms of the connected socket client. |
481+
| `@NspParams()` | Injects dynamic namespace params. |
482+
| `@NspParam(paramName: string)` | Injects param from the dynamic namespace. |
483+
| `@Middleware()` | Registers a new middleware to be registered in the socket.io. |
484+
| `@EmitOnSuccess(messageName: string)` | If this decorator is set then after controller action will emit message with the given name after action execution. It will emit message only if controller succeed without errors. If result is a Promise then it will wait until promise is resolved and emit a message. |
485+
| `@EmitOnFail(messageName: string)` | If this decorator is set then after controller action will emit message with the given name after action execution. It will emit message only if controller throw an exception. If result is a Promise then it will wait until promise throw an error and emit a message. |
486+
| `@SkipEmitOnEmptyResult()` | Used in conjunction with @EmitOnSuccess and @EmitOnFail decorators. If result returned by controller action is null or undefined then messages will not be emitted by @EmitOnSuccess or @EmitOnFail decorators. | |
462487

463488
## Samples
464489

0 commit comments

Comments
 (0)