Skip to content

Commit

Permalink
bugfix: deprecate missing @pipe() decorator, fix HttpModule
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 18, 2018
1 parent 4fad0ae commit 5f735b1
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 46 deletions.
Binary file modified bundle/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion bundle/common/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
Expand Down
2 changes: 1 addition & 1 deletion bundle/core/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
Expand Down
2 changes: 1 addition & 1 deletion bundle/microservices/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
Expand Down
2 changes: 1 addition & 1 deletion bundle/testing/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
Expand Down
2 changes: 1 addition & 1 deletion bundle/websockets/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
Expand Down
24 changes: 20 additions & 4 deletions packages/common/decorators/core/component.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,58 @@ export function Injectable(): ClassDecorator {
}

/**
* @deprecated
* Defines the Component. The component can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
export function Component(): ClassDecorator {
deprecate('The @Component() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.')
deprecate(
'The @Component() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.',
);
return (target: object) => {};
}

/**
* @deprecated
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
*/
export function Pipe(): ClassDecorator {
deprecate(
'The @Pipe() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.',
);
return (target: object) => {};
}

/**
* @deprecated
* Defines the Guard. The Guard should implement the `CanActivate` interface.
*/
export function Guard(): ClassDecorator {
deprecate('The @Guard() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.')
deprecate(
'The @Guard() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.',
);
return (target: object) => {};
}

/**
* @deprecated
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
*/
export function Middleware(): ClassDecorator {
deprecate('The @Middleware() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.')
deprecate(
'The @Middleware() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.',
);
return (target: object) => {};
}

/**
* @deprecated
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
*/
export function Interceptor(): ClassDecorator {
deprecate('The @Interceptor() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.')
deprecate(
'The @Interceptor() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.',
);
return (target: object) => {};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/http/http.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Module } from '../decorators/modules/module.decorator';
import { HttpService } from './http.service';

@Module({
components: [HttpService],
providers: [HttpService],
exports: [HttpService],
})
export class HttpModule {}
4 changes: 2 additions & 2 deletions packages/common/pipes/parse-int.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BadRequestException } from '../exceptions/bad-request.exception';
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
import { ArgumentMetadata, Pipe } from '../index';
import { ArgumentMetadata, Injectable } from '../index';

@Pipe()
@Injectable()
export class ParseIntPipe implements PipeTransform<string> {
async transform(value: string, metadata: ArgumentMetadata): Promise<number> {
const isNumeric =
Expand Down
4 changes: 2 additions & 2 deletions packages/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { classToPlain, plainToClass } from 'class-transformer';
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
import { ArgumentMetadata, BadRequestException } from '../index';
import { isNil } from '../utils/shared.utils';
import { Pipe } from './../decorators/core/component.decorator';
import { Injectable } from './../decorators/core/component.decorator';

export interface ValidationPipeOptions extends ValidatorOptions {
transform?: boolean;
}

@Pipe()
@Injectable()
export class ValidationPipe implements PipeTransform<any> {
private isTransformEnabled: boolean;
private validatorOptions: ValidatorOptions;
Expand Down
10 changes: 8 additions & 2 deletions packages/microservices/test/context/rpc-context-creator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as sinon from 'sinon';
import { expect } from 'chai';
import { Guard, Pipe, UseGuards, Component, UsePipes } from './../../../common';
import {
Guard,
Injectable,
UseGuards,
Component,
UsePipes,
} from './../../../common';
import { RpcProxy } from './../../context/rpc-proxy';
import { RpcContextCreator } from './../../context/rpc-context-creator';
import { RpcExceptionsHandler } from '../../exceptions/rpc-exceptions-handler';
Expand All @@ -23,7 +29,7 @@ class TestGuard {
canActivate: () => true;
}

@Pipe()
@Injectable()
class TestPipe {
transform(val) {
return val;
Expand Down
10 changes: 8 additions & 2 deletions packages/websockets/test/context/ws-context-creator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as sinon from 'sinon';
import { expect } from 'chai';
import { Guard, Pipe, UseGuards, Component, UsePipes } from './../../../common';
import {
Guard,
Injectable,
UseGuards,
Component,
UsePipes,
} from './../../../common';
import { WsProxy } from './../../context/ws-proxy';
import { WsContextCreator } from './../../context/ws-context-creator';
import { WsExceptionsHandler } from '../../exceptions/ws-exceptions-handler';
Expand All @@ -22,7 +28,7 @@ class TestGuard {
canActivate: () => true;
}

@Pipe()
@Injectable()
class TestPipe {
transform(val) {
return val;
Expand Down
8 changes: 2 additions & 6 deletions sample/01-cats-app/src/common/pipes/parse-int.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { BadRequestException } from '@nestjs/common';
import {
PipeTransform,
Pipe,
ArgumentMetadata,
} from '@nestjs/common';
import { PipeTransform, Pipe, ArgumentMetadata } from '@nestjs/common';

@Pipe()
@Injectable()
export class ParseIntPipe implements PipeTransform<string> {
async transform(value: string, metadata: ArgumentMetadata) {
const val = parseInt(value, 10);
Expand Down
4 changes: 2 additions & 2 deletions sample/01-cats-app/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BadRequestException } from '@nestjs/common';
import {
PipeTransform,
Pipe,
Injectable,
ArgumentMetadata,
HttpStatus,
} from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';

@Pipe()
@Injectable()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
Expand Down
8 changes: 2 additions & 6 deletions sample/10-fastify/src/common/pipes/parse-int.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { BadRequestException } from '@nestjs/common';
import {
PipeTransform,
Pipe,
ArgumentMetadata,
} from '@nestjs/common';
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';

@Pipe()
@Injectable()
export class ParseIntPipe implements PipeTransform<string> {
async transform(value: string, metadata: ArgumentMetadata) {
const val = parseInt(value, 10);
Expand Down
4 changes: 2 additions & 2 deletions sample/10-fastify/src/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BadRequestException } from '@nestjs/common';
import {
PipeTransform,
Pipe,
Injectable,
ArgumentMetadata,
HttpStatus,
} from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';

@Pipe()
@Injectable()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
Expand Down
2 changes: 1 addition & 1 deletion sample/19-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@nestjs/core": "^5.0.0",
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.0",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.5.6",
Expand All @@ -22,7 +23,6 @@
"@types/jest": "^20.0.8",
"@types/node": "^7.0.41",
"jest": "^20.0.4",
"passport-jwt": "^4.0.0",
"supertest": "^3.0.0",
"ts-jest": "^20.0.14",
"ts-node": "^3.3.0"
Expand Down
14 changes: 7 additions & 7 deletions sample/19-auth/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import * as jwt from 'jsonwebtoken';
import { Injectable } from '@nestjs/common';
import { JwtPayload } from './interfaces/jwt-payload.interface';

@Injectable()
export class AuthService {
async createToken() {
const expiresIn = 3600,
secretOrKey = 'secretKey';
const user = { email: '[email protected]' };
const expiresIn = 3600;
const user: JwtPayload = { email: '[email protected]' };
return {
expiresIn: expiresIn,
accessToken: jwt.sign(user, secretOrKey, { expiresIn }),
accessToken: jwt.sign(user, 'secretKey', { expiresIn }),
};
}

async validateUser(signedUser): Promise<boolean> {
async validateUser(payload: JwtPayload): Promise<any> {
// put some validation logic here
// for example query user by id / email / username
return true;
// for example query user by id/email/username
return {};
}
}
3 changes: 3 additions & 0 deletions sample/19-auth/src/auth/interfaces/jwt-payload.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface JwtPayload {
email: string;
}
9 changes: 5 additions & 4 deletions sample/19-auth/src/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExtractJwt, Strategy } from 'passport-jwt';
import { AuthService } from './auth.service';
import { PassportStrategy } from '../passport/passport.strategy';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtPayload } from './interfaces/jwt-payload.interface';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
Expand All @@ -12,11 +13,11 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
});
}

async validate(payload: any, done: Function) {
const isValid = await this.authService.validateUser(payload);
if (!isValid) {
async validate(payload: JwtPayload, done: Function) {
const user = await this.authService.validateUser(payload);
if (!user) {
return done(new UnauthorizedException(), false);
}
done(null, payload);
done(null, user);
}
}

0 comments on commit 5f735b1

Please sign in to comment.