Skip to content

Commit 1feb631

Browse files
Update package.json
1 parent 066059f commit 1feb631

12 files changed

Lines changed: 58 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.1.0
2+
- **common**: add `@Bind()` and `@Dependencies()` decorators to fix route parameters decorators (pure JavaScript compatibility issue)
3+
- **core**: improve performance
4+
15
## 4.0.1
26
- **core**: add possibility to setup global guards and global interceptors
37
- **common**: `INestApplication` has `useGlobalInterceptors()` and `useGlobalGuards()` now

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ $ npm install
5959
$ npm run start
6060
```
6161

62+
**Install the JavaScript (Babel) Starter Project with Git:**
63+
```bash
64+
$ git clone https://github.com/nestjs/javascript-starter.git project
65+
$ cd project
66+
$ npm install
67+
$ npm run start
68+
```
69+
6270
**Start a New Project from Scratch with NPM:**
6371
```bash
6472
$ npm i --save @nestjs/core @nestjs/common @nestjs/microservices @nestjs/websockets @nestjs/testing reflect-metadata rxjs

examples/09-babel-example/.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["env", "stage-0"],
3+
"plugins": ["transform-decorators-legacy"]
4+
}

examples/09-babel-example/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
"scripts": {
77
"build": "babel src -d dist",
88
"prestart": "npm run build",
9-
"start": "node index.js",
10-
"start:prod": "node dist/server.js"
9+
"start": "node index.js"
1110
},
1211
"dependencies": {
1312
"@nestjs/common": "^4.0.1",
1413
"@nestjs/core": "^4.0.1",
1514
"@nestjs/microservices": "^4.0.1",
1615
"@nestjs/testing": "^4.0.1",
1716
"@nestjs/websockets": "^4.0.1",
17+
"babel-core": "^6.26.0",
18+
"babel-polyfill": "^6.26.0",
1819
"body-parser": "^1.17.2",
1920
"redis": "^2.7.1",
2021
"reflect-metadata": "^0.1.10",
2122
"rxjs": "^5.4.3"
2223
},
2324
"devDependencies": {
2425
"babel-cli": "^6.26.0",
25-
"babel-core": "^6.26.0",
2626
"babel-plugin-transform-decorators-legacy": "^1.3.4",
27-
"babel-polyfill": "^6.26.0",
28-
"babel-preset-es2015": "^6.24.1",
27+
"babel-preset-env": "^1.6.0",
2928
"babel-preset-stage-0": "^6.24.1"
3029
}
3130
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs",
3-
"version": "4.0.4",
3+
"version": "4.1.0",
44
"description": "Modern, fast, powerful node.js web framework",
55
"main": "index.js",
66
"scripts": {

src/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestjs/common",
3-
"version": "4.0.3",
3+
"version": "4.1.0",
44
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
55
"author": "Kamil Mysliwiec",
66
"license": "MIT",

src/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestjs/core",
3-
"version": "4.0.4",
3+
"version": "4.1.0",
44
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
55
"author": "Kamil Mysliwiec",
66
"license": "MIT",

src/core/router/router-execution-context.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export class RouterExecutionContext {
4444
const guards = this.guardsContextCreator.create(instance, callback, module);
4545
const interceptors = this.interceptorsContextCreator.create(instance, callback, module);
4646
const httpCode = this.reflectHttpStatusCode(callback);
47-
const paramProperties = this.exchangeKeysForValues(keys, metadata);
48-
const isResponseObj = paramProperties.some(({ type }) => type === RouteParamtypes.RESPONSE);
47+
const paramsMetadata = this.exchangeKeysForValues(keys, metadata);
48+
const isResponseObj = paramsMetadata.some(({ type }) => type === RouteParamtypes.RESPONSE);
49+
const paramsOptions = this.mergeParamsMetatypes(paramsMetadata, paramtypes);
4950

5051
return async (req, res, next) => {
5152
const args = this.createNullArray(argsLength);
@@ -54,9 +55,8 @@ export class RouterExecutionContext {
5455
throw new HttpException(FORBIDDEN_MESSAGE, HttpStatus.FORBIDDEN);
5556
}
5657

57-
await Promise.all(paramProperties.map(async (param) => {
58-
const { index, extractValue, type, data, pipes: paramPipes } = param;
59-
const metatype = paramtypes ? paramtypes[index] : null;
58+
await Promise.all(paramsOptions.map(async (param) => {
59+
const { index, extractValue, type, data, metatype, pipes: paramPipes } = param;
6060
const value = extractValue(req, res, next);
6161

6262
args[index] = await this.getParamValue(
@@ -109,6 +109,16 @@ export class RouterExecutionContext {
109109
});
110110
}
111111

112+
public mergeParamsMetatypes(
113+
paramsProperties: ParamProperties[],
114+
paramtypes: any[],
115+
): (ParamProperties & { metatype?: any })[] {
116+
if (!paramtypes) {
117+
return paramsProperties;
118+
}
119+
return paramsProperties.map((param) => ({ ...param, metatype: paramtypes[param.index] }));
120+
}
121+
112122
public async getParamValue<T>(
113123
value: T,
114124
{ metatype, type, data },

src/core/test/router/router-execution-context.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('RouterExecutionContext', () => {
4141
describe('create', () => {
4242
describe('when callback metadata is not undefined', () => {
4343
let metadata: RouteParamsMetadata;
44+
let exchangeKeysForValuesSpy: sinon.SinonSpy;
4445
beforeEach(() => {
4546
metadata = {
4647
[RouteParamtypes.NEXT]: { index: 0 },
@@ -51,6 +52,17 @@ describe('RouterExecutionContext', () => {
5152
};
5253
sinon.stub(contextCreator, 'reflectCallbackMetadata').returns(metadata);
5354
sinon.stub(contextCreator, 'reflectCallbackParamtypes').returns([]);
55+
exchangeKeysForValuesSpy = sinon.spy(contextCreator, 'exchangeKeysForValues');
56+
});
57+
it('should call "exchangeKeysForValues" with expected arguments', (done) => {
58+
const keys = Object.keys(metadata);
59+
60+
contextCreator.create({ foo: 'bar' }, callback as any, '', 0);
61+
expect(exchangeKeysForValuesSpy.called).to.be.true;
62+
expect(
63+
exchangeKeysForValuesSpy.calledWith(keys, metadata),
64+
).to.be.true;
65+
done();
5466
});
5567
describe('returns proxy function', () => {
5668
let proxyContext;
@@ -64,7 +76,6 @@ describe('RouterExecutionContext', () => {
6476
expect(proxyContext).to.be.a('function');
6577
});
6678
describe('when proxy function called', () => {
67-
let exchangeKeysForValuesSpy: sinon.SinonSpy;
6879
let request;
6980
const response = {
7081
status: () => response,
@@ -79,18 +90,6 @@ describe('RouterExecutionContext', () => {
7990
test: 3,
8091
},
8192
};
82-
exchangeKeysForValuesSpy = sinon.spy(contextCreator, 'exchangeKeysForValues');
83-
});
84-
it('should call "exchangeKeysForValues" with expected arguments', (done) => {
85-
proxyContext(request, response, next).then(() => {
86-
const keys = Object.keys(metadata);
87-
88-
expect(exchangeKeysForValuesSpy.called).to.be.true;
89-
expect(
90-
exchangeKeysForValuesSpy.calledWith(keys, metadata, { req: request, res: response, next }),
91-
).to.be.true;
92-
done();
93-
});
9493
});
9594
it('should apply expected context and arguments to callback', (done) => {
9695
proxyContext(request, response, next).then(() => {
@@ -161,12 +160,13 @@ describe('RouterExecutionContext', () => {
161160
},
162161
};
163162
const keys = Object.keys(metadata);
164-
const values = contextCreator.exchangeKeysForValues(keys, metadata, { res, req, next });
163+
const values = contextCreator.exchangeKeysForValues(keys, metadata);
165164
const expectedValues = [
166-
{ index: 0, value: req, type: RouteParamtypes.REQUEST, data: 'test', pipes: [] },
167-
{ index: 2, value: req.body.test, type: RouteParamtypes.BODY, data: 'test', pipes: [] },
165+
{ index: 0, type: RouteParamtypes.REQUEST, data: 'test' },
166+
{ index: 2, type: RouteParamtypes.BODY, data: 'test' },
168167
];
169-
expect(values).to.deep.equal(expectedValues);
168+
expect(values[0]).to.deep.include(expectedValues[0]);
169+
expect(values[1]).to.deep.include(expectedValues[1]);
170170
});
171171
});
172172
describe('getParamValue', () => {

src/microservices/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nestjs/microservices",
3-
"version": "4.0.2",
3+
"version": "4.1.0",
44
"description": "Nest - modern, fast, powerful node.js web framework (@microservices)",
55
"author": "Kamil Mysliwiec",
66
"license": "MIT",

0 commit comments

Comments
 (0)