Skip to content

Commit 99117b4

Browse files
Merge pull request nestjs#19 from kamilmysliwiec/master-final
Update to final version
2 parents 93c25a3 + b3bfe51 commit 99117b4

189 files changed

Lines changed: 2679 additions & 1131 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# IDE
55
/.idea
66
/.awcache
7+
/.vscode
78

89
# misc
910
npm-debug.log

CHANGELOG.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,98 @@
1+
## 1.0.0 (Final - 01.05.2017)
2+
3+
- Added **Gateway Middlewares** support:
4+
5+
```
6+
@WebSocketGateway({
7+
port: 2000,
8+
middlewares: [ChatMiddleware],
9+
})
10+
```
11+
Gateway Middleware example:
12+
```
13+
@Middleware()
14+
export class ChatMiddleware implements GatewayMiddleware {
15+
public resolve(): (socket, next) => void {
16+
return (socket, next) => {
17+
console.log('Authorization...');
18+
next();
19+
};
20+
}
21+
}
22+
```
23+
24+
- New Gateway lifecycle interfaces `OnGatewayInit`, `OnGatewayConnection`, `OnGatewayDisconnect`
25+
- `@SubscribeMessage()` now accepts also plain strings:
26+
27+
```
28+
@SubscribeMessage('event')
29+
```
30+
31+
- `@Controller()` now accepts also plain strings:
32+
33+
```
34+
@Controller('users')
35+
```
36+
37+
- `HttpStatus` (`HttpStatus.OK` etc.) enumerator
38+
- **Route params decorators** support
39+
40+
```
41+
Request: () => ParameterDecorator
42+
Response: () => ParameterDecorator
43+
Next: () => ParameterDecorator
44+
Query: (property?: string) => ParameterDecorator
45+
Body: (property?: string) => ParameterDecorator
46+
Param: (property?: string) => ParameterDecorator
47+
Session: () => ParameterDecorator
48+
Headers: (property?: string) => ParameterDecorator
49+
```
50+
51+
- `MiddlewaresBuilder` -> `MiddlewaresConsumer`
52+
- **Exception Filters** support
53+
54+
```
55+
@ExceptionFilters(CustomExceptionFilter, NextExceptionFilter)
56+
export class UsersController {}
57+
```
58+
Exception filter example:
59+
60+
```
61+
export class CustomException {}
62+
63+
@Catch(CustomException)
64+
export class CustomExceptionFilter implements ExceptionFilter {
65+
public catch(exception, response) {
66+
response.status(500).json({
67+
message: 'Custom exception message.',
68+
});
69+
}
70+
}
71+
```
72+
- Module injection support:
73+
74+
```
75+
export class UsersController {
76+
constructor(private module: UsersModule) {}
77+
}
78+
```
79+
80+
- `ModuleRef` support
81+
182
## 1.0.0-RC7 (08.04.2017)
283

384
- MiddlewareBuilder: `use()` deprecated, use `apply()` instead
485
- MiddlewareBuilder: new `apply()` method
586

687
## 1.0.0-RC4 (08.04.2017)
788

8-
- Support for @Post, @Get, @Delete, @Put, @All decorators
89+
- Support for `@Post`, `@Get`, `@Delete`, `@Put`, `@All` decorators
990
- Added ability to pass data to middleware metatypes
1091

1192
## 1.0.0-BETA-1 (23.03.2017)
1293

13-
- @Inject -> @Dependencies
14-
- @Inject decorator for custom constructor parameters
94+
- `@Inject` -> `@Dependencies`
95+
- `@Inject` decorator for custom constructor parameters
1596
- Custom providers support (useClass, useValue, useFactory)
1697

1798
## 1.0.0-ALPHA-23 (19.03.2017)
@@ -20,6 +101,6 @@
20101
- NestRunner -> NestFactory
21102
- Simplify application initialization & configuration
22103
- Added abillity to pass custom express instance
23-
- @Inject decorator for ES6+
104+
- `@Inject` decorator for ES6+
24105
- SocketGateway -> WebSocketGateway
25106
- GatewayServer -> WebSocketServer

Readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ We want to create scalable, modern and easy to maintain applications. Nest helps
5454
Nest is very much still a work in progress. There is still some things to finish:
5555

5656
- Examples(!)
57-
- Exception filters
5857
- Validation helpers
59-
- Gateways middleware
58+
- More test utilities
6059
- and more...
6160

6261
## People

example/math/modules/math.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Controller } from '../../../src/common/utils/controller.decorator';
1+
import { Controller } from '../../../src/common/utils/decorators/controller.decorator';
22
import { MessagePattern } from '../../../src/microservices/utils/pattern.decorator';
33

44
@Controller()

example/math/modules/microservice.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module } from '../../../src/common/utils/module.decorator';
1+
import { Module } from '../../../src/common/utils/decorators/module.decorator';
22
import { MathController } from './math.controller';
33

44
@Module({

example/modules/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { ClientController } from './client/client.controller';
44

55
@Module({
66
modules: [ UsersModule ],
7-
controllers: [ ClientController ]
7+
controllers: [ ClientController ],
88
})
99
export class ApplicationModule {}

example/modules/client/client.controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { Controller } from '../../../src/common/utils/controller.decorator';
1+
import { Controller } from '../../../src/common/utils/decorators/controller.decorator';
22
import { Client } from '../../../src/microservices/utils/client.decorator';
3-
import { RequestMapping } from '../../../src/common/utils/request-mapping.decorator';
3+
import { RequestMapping } from '../../../src/common/utils/decorators/request-mapping.decorator';
44
import { ClientProxy } from '../../../src/microservices/client/client-proxy';
55
import { Observable } from 'rxjs';
66
import { Transport } from '../../../src/common/enums/transport.enum';
77
import 'rxjs/add/operator/catch';
88

9+
const MicroserviceClient = { transport: Transport.TCP, port: 5667 };
10+
911
@Controller()
1012
export class ClientController {
11-
12-
@Client({ transport: Transport.TCP, port: 5667 })
13-
client: ClientProxy;
13+
@Client(MicroserviceClient)
14+
public client: ClientProxy;
1415

1516
@RequestMapping({ path: 'client' })
16-
sendMessage(req, res) {
17+
public sendMessage(req, res) {
1718
const pattern = { command: 'add' };
1819
const data = [ 1, 2, 3, 4, 5 ];
1920

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Module } from '../../../src/common/utils/module.decorator';
1+
import { Module } from '../../../src/common/utils/decorators/module.decorator';
22
import { ChatGateway } from '../users/chat.gateway';
33

44
@Module({
55
components: [ ChatGateway ],
6-
exports: [ ChatGateway ]
6+
exports: [ ChatGateway ],
77
})
88
export class SharedModule {}

example/modules/users/auth.middleware.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ import { NestMiddleware } from '../../../src/core/middlewares/interfaces/nest-mi
77
export class AuthMiddleware implements NestMiddleware {
88
constructor(private usersService: UsersService) {}
99

10-
resolve() {
10+
public resolve() {
1111
return (req, res, next) => {
12-
const userName = req.headers['x-access-token'];
12+
const username = req.headers['x-access-token'];
1313
const users = this.usersService.getUsers();
14-
15-
const user = users.find((user) => user.name === userName);
14+
const user = users.find(({ name }) => name === username);
1615
if (!user) {
1716
throw new HttpException('User not found.', 401);
1817
}
1918
req.user = user;
2019
next();
21-
}
20+
};
2221
}
2322

2423
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { WebSocketGateway } from '../../../src/websockets/utils/socket-gateway.decorator';
22
import { SubscribeMessage } from '../../../src/websockets/utils/subscribe-message.decorator';
3-
import { Subject } from 'rxjs/Subject';
43
import { WebSocketServer } from '../../../src/websockets/utils/gateway-server.decorator';
4+
import { OnGatewayInit, OnGatewayConnection } from '../../../src/websockets/index';
5+
import { ChatMiddleware } from './chat.middleware';
56

6-
@WebSocketGateway({ port: 2000 })
7-
export class ChatGateway {
8-
private msg$ = new Subject<any>();
7+
@WebSocketGateway({
8+
port: 2000,
9+
middlewares: [ ChatMiddleware ],
10+
})
11+
export class ChatGateway implements OnGatewayInit, OnGatewayConnection {
12+
@WebSocketServer() private server;
913

10-
@WebSocketServer() server;
14+
public afterInit(server) {}
15+
public handleConnection(client) {}
1116

12-
get msgStream() {
13-
return this.msg$.asObservable();
17+
@SubscribeMessage('event')
18+
public onMessage(client, data) {
19+
client.emit('event', data);
1420
}
15-
16-
@SubscribeMessage({ value: 'message' })
17-
onMessage(client, data) {
18-
this.msg$.next({ client, data });
19-
}
20-
2121
}

0 commit comments

Comments
 (0)