@lenne.tech/nest-server 11.4.1 → 11.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "11.4.
|
|
3
|
+
"version": "11.4.2",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -4,27 +4,81 @@ import { validate, ValidationError } from 'class-validator';
|
|
|
4
4
|
|
|
5
5
|
import { isBasicType } from '../helpers/input.helper';
|
|
6
6
|
|
|
7
|
+
// Debug mode can be enabled via environment variable: DEBUG_VALIDATION=true
|
|
8
|
+
const DEBUG_VALIDATION = process.env.DEBUG_VALIDATION === 'true';
|
|
9
|
+
|
|
7
10
|
@Injectable()
|
|
8
11
|
export class MapAndValidatePipe implements PipeTransform {
|
|
9
12
|
async transform(value: any, metadata: ArgumentMetadata) {
|
|
10
13
|
const { metatype } = metadata;
|
|
11
14
|
|
|
15
|
+
if (DEBUG_VALIDATION) {
|
|
16
|
+
console.debug('\n=== MapAndValidatePipe Debug ===');
|
|
17
|
+
console.debug('Metadata:', {
|
|
18
|
+
data: metadata.data,
|
|
19
|
+
metatype: metatype?.name,
|
|
20
|
+
type: metadata.type,
|
|
21
|
+
});
|
|
22
|
+
console.debug('Input value type:', typeof value);
|
|
23
|
+
console.debug('Input value:', JSON.stringify(value, null, 2));
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
if (!value || typeof value !== 'object' || !metatype || isBasicType(metatype)) {
|
|
27
|
+
if (DEBUG_VALIDATION) {
|
|
28
|
+
console.debug('Skipping validation - basic type or no metatype');
|
|
29
|
+
console.debug('=== End Debug ===\n');
|
|
30
|
+
}
|
|
13
31
|
return value;
|
|
14
32
|
}
|
|
15
33
|
|
|
16
34
|
// Convert to metatype
|
|
17
35
|
if (!(value instanceof metatype)) {
|
|
18
36
|
if ((metatype as any)?.map) {
|
|
37
|
+
if (DEBUG_VALIDATION) {
|
|
38
|
+
console.debug('Using custom map function');
|
|
39
|
+
}
|
|
19
40
|
value = (metatype as any)?.map(value);
|
|
20
41
|
} else {
|
|
42
|
+
if (DEBUG_VALIDATION) {
|
|
43
|
+
console.debug('Using plainToInstance to transform to:', metatype.name);
|
|
44
|
+
}
|
|
21
45
|
value = plainToInstance(metatype, value);
|
|
46
|
+
if (DEBUG_VALIDATION) {
|
|
47
|
+
console.debug('Transformed value:', JSON.stringify(value, null, 2));
|
|
48
|
+
console.debug('Transformed value instance of:', value?.constructor?.name);
|
|
49
|
+
}
|
|
22
50
|
}
|
|
23
51
|
}
|
|
24
52
|
|
|
25
53
|
// Validate
|
|
54
|
+
if (DEBUG_VALIDATION) {
|
|
55
|
+
console.debug('Starting validation...');
|
|
56
|
+
}
|
|
26
57
|
const errors = await validate(value, { forbidUnknownValues: false });
|
|
58
|
+
|
|
27
59
|
if (errors.length > 0) {
|
|
60
|
+
if (DEBUG_VALIDATION) {
|
|
61
|
+
console.debug('Validation errors found:', errors.length);
|
|
62
|
+
console.debug('Raw validation errors:');
|
|
63
|
+
errors.forEach((err, index) => {
|
|
64
|
+
console.debug(`\nError ${index + 1}:`);
|
|
65
|
+
console.debug(' Property:', err.property);
|
|
66
|
+
console.debug(' Value:', err.value);
|
|
67
|
+
console.debug(' Constraints:', err.constraints);
|
|
68
|
+
console.debug(' Children:', err.children?.length || 0);
|
|
69
|
+
if (err.children && err.children.length > 0) {
|
|
70
|
+
console.debug(' Children details:');
|
|
71
|
+
err.children.forEach((child, childIndex) => {
|
|
72
|
+
console.debug(` Child ${childIndex + 1}:`);
|
|
73
|
+
console.debug(' Property:', child.property);
|
|
74
|
+
console.debug(' Value:', child.value);
|
|
75
|
+
console.debug(' Constraints:', child.constraints);
|
|
76
|
+
console.debug(' Has children:', (child.children?.length || 0) > 0);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
28
82
|
const result = {};
|
|
29
83
|
|
|
30
84
|
const processErrors = (errorList: ValidationError[], parentKey = '') => {
|
|
@@ -40,9 +94,22 @@ export class MapAndValidatePipe implements PipeTransform {
|
|
|
40
94
|
};
|
|
41
95
|
|
|
42
96
|
processErrors(errors);
|
|
97
|
+
|
|
98
|
+
if (DEBUG_VALIDATION) {
|
|
99
|
+
console.debug('\nProcessed validation result:');
|
|
100
|
+
console.debug(JSON.stringify(result, null, 2));
|
|
101
|
+
console.debug('Result is empty:', Object.keys(result).length === 0);
|
|
102
|
+
console.debug('=== End Debug ===\n');
|
|
103
|
+
}
|
|
104
|
+
|
|
43
105
|
throw new BadRequestException(result);
|
|
44
106
|
}
|
|
45
107
|
|
|
108
|
+
if (DEBUG_VALIDATION) {
|
|
109
|
+
console.debug('Validation successful - no errors');
|
|
110
|
+
console.debug('=== End Debug ===\n');
|
|
111
|
+
}
|
|
112
|
+
|
|
46
113
|
return value;
|
|
47
114
|
}
|
|
48
115
|
}
|