Compare commits

...

3 Commits

Author SHA1 Message Date
Kamil Myśliwiec
e51ab047d2 chore(@nestjs) publish v7.6.9 release 2021-02-02 11:24:11 +01:00
Kamil Myśliwiec
2ba2b99325 fix(common): validate all array items when stop at first disabled (#6263) 2021-02-02 11:12:45 +01:00
Kamil Myśliwiec
ba37eee5b0 Merge branch 'andrewda-host-array' 2021-02-02 10:35:50 +01:00
12 changed files with 72 additions and 18 deletions

View File

@@ -3,5 +3,5 @@
"packages": [
"packages/*"
],
"version": "7.6.8"
"version": "7.6.9"
}

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/common",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
"author": "Kamil Mysliwiec",
"homepage": "https://nestjs.com",

View File

@@ -86,7 +86,29 @@ export class ParseArrayPipe implements PipeTransform {
} catch {}
return this.validationPipe.transform(item, validationMetadata);
};
value = await Promise.all(value.map(toClassInstance));
if (this.options.stopAtFirstError === false) {
// strict compare to "false" to make sure
// that this option is disabled by default
let errors = [];
const targetArray = value as Array<unknown>;
for (let i = 0; i < targetArray.length; i++) {
try {
targetArray[i] = await toClassInstance(targetArray[i]);
} catch (err) {
const message = err.getResponse
? `[${i}] ` + err.getResponse().message
: err;
errors = errors.concat(message);
}
}
if (errors.length > 0) {
throw this.exceptionFactory(errors as any);
}
return targetArray;
} else {
value = await Promise.all(value.map(toClassInstance));
}
}
return value;
}

View File

@@ -1,7 +1,11 @@
import * as chai from 'chai';
import { expect } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import { IsNumber } from 'class-validator';
import { BadRequestException } from '../../exceptions';
import { ArgumentMetadata } from '../../interfaces/features/pipe-transform.interface';
import { ParseArrayPipe } from '../../pipes/parse-array.pipe';
chai.use(chaiAsPromised);
describe('ParseArrayPipe', () => {
let target: ParseArrayPipe;
@@ -102,6 +106,34 @@ describe('ParseArrayPipe', () => {
expect(item).to.be.instanceOf(ArrItem);
});
});
describe('when "stopAtFirstError" is explicitly turned off', () => {
it('should validate each item and concat errors', async () => {
class ArrItemWithProp {
@IsNumber()
number: number;
}
const pipe = new ParseArrayPipe({
items: ArrItemWithProp,
stopAtFirstError: false,
});
try {
await pipe.transform(
[
{ number: '1' },
{ number: '1' },
{ number: 1 },
] as ArrItemWithProp[],
{} as ArgumentMetadata,
);
} catch (err) {
expect(err).to.be.instanceOf(BadRequestException);
expect(err.getResponse().message).to.deep.equal([
'[0] number must be a number conforming to the specified constraints',
'[1] number must be a number conforming to the specified constraints',
]);
}
});
});
});
});
});

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/core",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
"author": "Kamil Mysliwiec",
"license": "MIT",
@@ -36,7 +36,7 @@
"uuid": "8.3.2"
},
"devDependencies": {
"@nestjs/common": "7.6.8"
"@nestjs/common": "7.6.9"
},
"peerDependencies": {
"@nestjs/common": "^7.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/microservices",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@microservices)",
"author": "Kamil Mysliwiec",
"license": "MIT",
@@ -22,8 +22,8 @@
"tslib": "2.1.0"
},
"devDependencies": {
"@nestjs/common": "7.6.8",
"@nestjs/core": "7.6.8"
"@nestjs/common": "7.6.9",
"@nestjs/core": "7.6.9"
},
"peerDependencies": {
"@nestjs/common": "^7.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/platform-express",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@platform-express)",
"author": "Kamil Mysliwiec",
"license": "MIT",
@@ -24,8 +24,8 @@
"tslib": "2.1.0"
},
"devDependencies": {
"@nestjs/common": "7.6.8",
"@nestjs/core": "7.6.8"
"@nestjs/common": "7.6.9",
"@nestjs/core": "7.6.9"
},
"peerDependencies": {
"@nestjs/common": "^7.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/platform-fastify",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
"author": "Kamil Mysliwiec",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/platform-socket.io",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@platform-socket.io)",
"author": "Kamil Mysliwiec",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/platform-ws",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@platform-ws)",
"author": "Kamil Mysliwiec",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/testing",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@testing)",
"author": "Kamil Mysliwiec",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@nestjs/websockets",
"version": "7.6.8",
"version": "7.6.9",
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
"author": "Kamil Mysliwiec",
"license": "MIT",
@@ -16,8 +16,8 @@
"tslib": "2.1.0"
},
"devDependencies": {
"@nestjs/common": "7.6.8",
"@nestjs/core": "7.6.8"
"@nestjs/common": "7.6.9",
"@nestjs/core": "7.6.9"
},
"peerDependencies": {
"@nestjs/common": "^7.0.0",