denwa-nest-shared 1.2.4 → 1.2.6
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/CHANGELOG.md +4 -0
- package/README.md +124 -0
- package/cjs/decorators.d.ts +4 -2
- package/cjs/decorators.js +59 -30
- package/cjs/decorators.js.map +1 -1
- package/cjs/dto.js +10 -3
- package/cjs/dto.js.map +1 -1
- package/cjs/interceptors/fields-roles.interceptor.js +9 -3
- package/cjs/interceptors/fields-roles.interceptor.js.map +1 -1
- package/cjs/lib.js +79 -35
- package/cjs/lib.js.map +1 -1
- package/cjs/openapi-axios/interpolate-params.js +1 -12
- package/cjs/openapi-axios/interpolate-params.js.map +1 -1
- package/cjs/openapi-axios/types/serializer.d.ts +1 -0
- package/cjs/openapi-axios/types/serializer.js +1 -0
- package/cjs/openapi-axios/types/serializer.js.map +1 -1
- package/cjs/opensearch-core.js +1 -1
- package/cjs/opensearch-core.js.map +1 -1
- package/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/cjs/validation/validation.exception.d.ts +2 -2
- package/cjs/validation/validation.exception.js +1 -1
- package/cjs/validation/validation.exception.js.map +1 -1
- package/cjs/validation/validation.pipe.d.ts +2 -0
- package/cjs/validation/validation.pipe.js +27 -11
- package/cjs/validation/validation.pipe.js.map +1 -1
- package/dist/decorators.d.ts +4 -2
- package/dist/decorators.js +60 -31
- package/dist/decorators.js.map +1 -1
- package/dist/dto.js +11 -4
- package/dist/dto.js.map +1 -1
- package/dist/interceptors/fields-roles.interceptor.js +9 -3
- package/dist/interceptors/fields-roles.interceptor.js.map +1 -1
- package/dist/lib.js +79 -35
- package/dist/lib.js.map +1 -1
- package/dist/openapi-axios/interpolate-params.js +1 -12
- package/dist/openapi-axios/interpolate-params.js.map +1 -1
- package/dist/openapi-axios/types/serializer.d.ts +1 -0
- package/dist/openapi-axios/types/serializer.js +1 -0
- package/dist/openapi-axios/types/serializer.js.map +1 -1
- package/dist/opensearch-core.js +1 -1
- package/dist/opensearch-core.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/validation/validation.exception.d.ts +2 -2
- package/dist/validation/validation.exception.js +1 -1
- package/dist/validation/validation.exception.js.map +1 -1
- package/dist/validation/validation.pipe.d.ts +2 -0
- package/dist/validation/validation.pipe.js +27 -11
- package/dist/validation/validation.pipe.js.map +1 -1
- package/package.json +16 -6
- package/skills/auth-security/SKILL.md +3 -3
- package/skills/data-access-typeorm/SKILL.md +22 -4
- package/skills/file-management/SKILL.md +27 -21
- package/skills/schema-definition/SKILL.md +83 -16
|
@@ -21,6 +21,6 @@ let ValidationException = class ValidationException extends common_1.HttpExcepti
|
|
|
21
21
|
exports.ValidationException = ValidationException;
|
|
22
22
|
exports.ValidationException = ValidationException = __decorate([
|
|
23
23
|
(0, common_1.Injectable)(),
|
|
24
|
-
__metadata("design:paramtypes", [
|
|
24
|
+
__metadata("design:paramtypes", [Object])
|
|
25
25
|
], ValidationException);
|
|
26
26
|
//# sourceMappingURL=validation.exception.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../src/validation/validation.exception.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAuE;AAGhE,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,sBAAa;IACpD,QAAQ,
|
|
1
|
+
{"version":3,"file":"validation.exception.js","sourceRoot":"","sources":["../../src/validation/validation.exception.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAuE;AAGhE,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,sBAAa;IACpD,QAAQ,CAAU;IAElB,YAAY,QAAyB;QACnC,KAAK,CAAC,QAAQ,EAAE,mBAAU,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF,CAAA;AAPY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;;GACA,mBAAmB,CAO/B","sourcesContent":["import { HttpException, HttpStatus, Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class ValidationException extends HttpException {\n messages: unknown;\n\n constructor(response: string | object) {\n super(response, HttpStatus.BAD_REQUEST);\n this.messages = response;\n }\n}\n"]}
|
|
@@ -13,29 +13,45 @@ const class_validator_1 = require("class-validator");
|
|
|
13
13
|
const validation_exception_1 = require("./validation.exception");
|
|
14
14
|
let ValidationPipe = class ValidationPipe {
|
|
15
15
|
async transform(value, metadata) {
|
|
16
|
-
if (!metadata.metatype ||
|
|
16
|
+
if (!metadata.metatype ||
|
|
17
|
+
!this.toValidate(metadata.metatype) ||
|
|
18
|
+
(value && typeof value === 'object' && 'fieldNodes' in value)) {
|
|
17
19
|
return value;
|
|
18
20
|
}
|
|
19
|
-
const obj = (0, class_transformer_1.plainToClass)(metadata.metatype, value);
|
|
20
|
-
if (typeof obj !== 'object'
|
|
21
|
+
const obj = (0, class_transformer_1.plainToClass)(metadata.metatype, value ?? {});
|
|
22
|
+
if (!obj || typeof obj !== 'object')
|
|
21
23
|
return value;
|
|
22
|
-
const
|
|
23
|
-
const errors = validateErrors.filter((item) => item.value !== undefined);
|
|
24
|
+
const errors = await (0, class_validator_1.validate)(obj);
|
|
24
25
|
if (errors.length) {
|
|
25
|
-
const messages =
|
|
26
|
-
if (!err.constraints)
|
|
27
|
-
return `${err.property}`;
|
|
28
|
-
return `${err.property} - ${Object.values(err.constraints).join(', ')}`;
|
|
29
|
-
});
|
|
26
|
+
const messages = this.formatErrors(errors);
|
|
30
27
|
const response = {
|
|
31
28
|
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
32
29
|
error: 'Bad request',
|
|
33
30
|
messages,
|
|
34
31
|
};
|
|
35
|
-
throw new validation_exception_1.ValidationException(
|
|
32
|
+
throw new validation_exception_1.ValidationException(response);
|
|
36
33
|
}
|
|
37
34
|
return value;
|
|
38
35
|
}
|
|
36
|
+
toValidate(metatype) {
|
|
37
|
+
const types = [String, Boolean, Number, Array, Object];
|
|
38
|
+
return !types.includes(metatype);
|
|
39
|
+
}
|
|
40
|
+
formatErrors(errors) {
|
|
41
|
+
const messages = [];
|
|
42
|
+
for (const err of errors) {
|
|
43
|
+
if (err.constraints) {
|
|
44
|
+
messages.push(`${err.property} - ${Object.values(err.constraints).join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
else if (err.children && err.children.length > 0) {
|
|
47
|
+
messages.push(...this.formatErrors(err.children).map((subMsg) => `${err.property}.${subMsg}`));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
messages.push(err.property);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return messages;
|
|
54
|
+
}
|
|
39
55
|
};
|
|
40
56
|
exports.ValidationPipe = ValidationPipe;
|
|
41
57
|
exports.ValidationPipe = ValidationPipe = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.pipe.js","sourceRoot":"","sources":["../../src/validation/validation.pipe.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAyF;AACzF,yDAAiD;AACjD,
|
|
1
|
+
{"version":3,"file":"validation.pipe.js","sourceRoot":"","sources":["../../src/validation/validation.pipe.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAyF;AACzF,yDAAiD;AACjD,qDAA4D;AAI5D,iEAA6D;AAGtD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,KAAK,CAAC,SAAS,CAAC,KAAc,EAAE,QAA0B;QACxD,IACE,CAAC,QAAQ,CAAC,QAAQ;YAClB,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACnC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,YAAY,IAAI,KAAK,CAAC,EAC7D,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,GAAG,GAAW,IAAA,gCAAY,EAAC,QAAQ,CAAC,QAAQ,EA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AAC,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,IAAI,MAAM,EAAE,CAAC,CAChF,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAnDY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;GACA,cAAc,CAmD1B","sourcesContent":["import { ArgumentMetadata, HttpStatus, Injectable, PipeTransform } from '@nestjs/common';\nimport { plainToClass } from 'class-transformer';\nimport { validate, ValidationError } from 'class-validator';\n\nimport { IResponse } from '../types';\n\nimport { ValidationException } from './validation.exception';\n\n@Injectable()\nexport class ValidationPipe implements PipeTransform<unknown> {\n async transform(value: unknown, metadata: ArgumentMetadata): Promise<unknown> {\n if (\n !metadata.metatype ||\n !this.toValidate(metadata.metatype) ||\n (value && typeof value === 'object' && 'fieldNodes' in value)\n ) {\n return value;\n }\n\n const obj: object = plainToClass(metadata.metatype, value ?? {});\n if (!obj || typeof obj !== 'object') return value;\n\n const errors = await validate(obj);\n\n if (errors.length) {\n const messages = this.formatErrors(errors);\n\n const response: IResponse<HttpStatus.BAD_REQUEST> = {\n statusCode: HttpStatus.BAD_REQUEST,\n error: 'Bad request',\n messages,\n };\n\n throw new ValidationException(response);\n }\n return value;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n private toValidate(metatype: Function): boolean {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n const types: Function[] = [String, Boolean, Number, Array, Object];\n return !types.includes(metatype);\n }\n\n private formatErrors(errors: ValidationError[]): string[] {\n const messages: string[] = [];\n for (const err of errors) {\n if (err.constraints) {\n messages.push(`${err.property} - ${Object.values(err.constraints).join(', ')}`);\n } else if (err.children && err.children.length > 0) {\n messages.push(\n ...this.formatErrors(err.children).map((subMsg) => `${err.property}.${subMsg}`),\n );\n } else {\n messages.push(err.property);\n }\n }\n return messages;\n }\n}\n"]}
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CustomDecorator } from '@nestjs/common';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type ClassRef = new (...args: never[]) => unknown;
|
|
3
|
+
export declare const ApiValidationProperty: ({ type, enumObject, swaggerType, objectType, min, max, arrayMinSize, arrayMaxSize, divisibleBy, example, description, isSwaggerArray, isOptional, isUUID, isArray, isJson, isJWT, isUrl, isPositive, isNegative, isEmail, isMobilePhone, isPhoneNumber, isLatitude, isLongitude, isStrongPassword, isArrayNotEmpty, isArrayUnique, isDateString, }: {
|
|
4
|
+
type: "string" | "int" | "float" | "date" | "boolean" | "object";
|
|
4
5
|
enumObject?: object;
|
|
5
6
|
swaggerType?: any;
|
|
7
|
+
objectType?: ClassRef;
|
|
6
8
|
min?: number;
|
|
7
9
|
max?: number;
|
|
8
10
|
arrayMinSize?: number;
|
package/dist/decorators.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { applyDecorators, createParamDecorator, SetMetadata, } from '@nestjs/common';
|
|
2
2
|
import { Field, Float, Int } from '@nestjs/graphql';
|
|
3
3
|
import { ApiProperty as SwaggerApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
4
|
-
import { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, ArrayUnique, IsArray, IsBoolean, IsDate, IsEmail, IsEnum, IsInt, IsJSON, IsJWT, IsLatitude, IsLongitude, IsMobilePhone, IsNegative, IsNumber, IsOptional, IsPhoneNumber, IsPositive, IsString, IsStrongPassword, IsUrl, IsUUID, Max, MaxLength, Min, MinLength, IsDivisibleBy, IsDateString, } from 'class-validator';
|
|
4
|
+
import { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, ArrayUnique, IsArray, IsBoolean, IsDate, IsEmail, IsEnum, IsInt, IsJSON, IsJWT, IsLatitude, IsLongitude, IsMobilePhone, IsNegative, IsNumber, IsOptional, IsPhoneNumber, IsPositive, IsString, IsStrongPassword, IsUrl, IsUUID, Max, MaxLength, Min, MinLength, IsDivisibleBy, IsDateString, ValidateNested, } from 'class-validator';
|
|
5
5
|
import { Type } from 'class-transformer';
|
|
6
6
|
import { ROLES_KEY } from './const';
|
|
7
7
|
import { prepareRequestContext } from './lib';
|
|
8
|
-
|
|
8
|
+
const BUILT_IN_TYPES = new Set([String, Number, Boolean, Object, Date, Array, Function]);
|
|
9
|
+
const isClassRef = (value) => typeof value === 'function' && !BUILT_IN_TYPES.has(value);
|
|
10
|
+
const resolveObjectType = (objectType, swaggerType) => {
|
|
11
|
+
const raw = objectType ?? swaggerType;
|
|
12
|
+
const candidate = Array.isArray(raw) ? raw[0] : raw;
|
|
13
|
+
return isClassRef(candidate) ? candidate : null;
|
|
14
|
+
};
|
|
15
|
+
export const ApiValidationProperty = ({ type, enumObject, swaggerType, objectType, min, max, arrayMinSize, arrayMaxSize, divisibleBy, example, description, isSwaggerArray, isOptional = false, isUUID = false, isArray = false, isJson = false, isJWT = false, isUrl = false, isPositive = false, isNegative = false, isEmail = false, isMobilePhone = false, isPhoneNumber = false, isLatitude = false, isLongitude = false, isStrongPassword = false, isArrayNotEmpty = false, isArrayUnique = false, isDateString = false, }) => {
|
|
9
16
|
const decorators = [];
|
|
17
|
+
const schemaType = swaggerType ?? (objectType ? (isArray ? [objectType] : objectType) : undefined);
|
|
10
18
|
const swaggerData = {
|
|
11
19
|
example,
|
|
12
20
|
description,
|
|
13
21
|
enum: enumObject,
|
|
14
22
|
isArray: isSwaggerArray,
|
|
15
|
-
type:
|
|
23
|
+
type: schemaType,
|
|
16
24
|
};
|
|
17
25
|
if (!enumObject) {
|
|
18
26
|
delete swaggerData.enum;
|
|
@@ -20,7 +28,7 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
20
28
|
if (!isSwaggerArray) {
|
|
21
29
|
delete swaggerData.isArray;
|
|
22
30
|
}
|
|
23
|
-
if (!
|
|
31
|
+
if (!schemaType) {
|
|
24
32
|
delete swaggerData.type;
|
|
25
33
|
}
|
|
26
34
|
if (isOptional) {
|
|
@@ -29,6 +37,29 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
29
37
|
else {
|
|
30
38
|
decorators.push(SwaggerApiProperty(swaggerData));
|
|
31
39
|
}
|
|
40
|
+
const nestedType = resolveObjectType(objectType, swaggerType);
|
|
41
|
+
if (nestedType) {
|
|
42
|
+
decorators.push(Field(() => (isArray ? [nestedType] : nestedType), { nullable: isOptional }));
|
|
43
|
+
if (isOptional)
|
|
44
|
+
decorators.push(IsOptional());
|
|
45
|
+
if (isArray) {
|
|
46
|
+
decorators.push(IsArray());
|
|
47
|
+
if (isArrayNotEmpty)
|
|
48
|
+
decorators.push(ArrayNotEmpty());
|
|
49
|
+
if (isArrayUnique)
|
|
50
|
+
decorators.push(ArrayUnique());
|
|
51
|
+
if (arrayMinSize !== undefined)
|
|
52
|
+
decorators.push(ArrayMinSize(arrayMinSize));
|
|
53
|
+
if (arrayMaxSize !== undefined)
|
|
54
|
+
decorators.push(ArrayMaxSize(arrayMaxSize));
|
|
55
|
+
}
|
|
56
|
+
decorators.push(ValidateNested({ each: isArray }));
|
|
57
|
+
decorators.push(Type(() => nestedType));
|
|
58
|
+
return applyDecorators(...decorators);
|
|
59
|
+
}
|
|
60
|
+
if (type === 'object') {
|
|
61
|
+
throw new Error('ApiValidationProperty: `type: "object"` requires a nested DTO class in `objectType` or `swaggerType`');
|
|
62
|
+
}
|
|
32
63
|
switch (type) {
|
|
33
64
|
case 'int':
|
|
34
65
|
decorators.push(Field(() => (isArray ? [Int] : Int), { nullable: isOptional }));
|
|
@@ -40,20 +71,18 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
40
71
|
decorators.push(ArrayNotEmpty());
|
|
41
72
|
if (isArrayUnique)
|
|
42
73
|
decorators.push(ArrayUnique());
|
|
43
|
-
if (arrayMinSize)
|
|
74
|
+
if (arrayMinSize !== undefined)
|
|
44
75
|
decorators.push(ArrayMinSize(arrayMinSize));
|
|
45
|
-
if (arrayMaxSize)
|
|
76
|
+
if (arrayMaxSize !== undefined)
|
|
46
77
|
decorators.push(ArrayMaxSize(arrayMaxSize));
|
|
47
|
-
if (divisibleBy)
|
|
48
|
-
decorators.push(IsDivisibleBy(divisibleBy));
|
|
49
78
|
}
|
|
50
|
-
decorators.push(IsNumber());
|
|
51
|
-
decorators.push(IsInt());
|
|
52
|
-
if (min)
|
|
79
|
+
decorators.push(IsNumber({}, { each: isArray }));
|
|
80
|
+
decorators.push(IsInt({ each: isArray }));
|
|
81
|
+
if (min !== undefined)
|
|
53
82
|
decorators.push(Min(min, { each: isArray }));
|
|
54
|
-
if (max)
|
|
83
|
+
if (max !== undefined)
|
|
55
84
|
decorators.push(Max(max, { each: isArray }));
|
|
56
|
-
if (divisibleBy)
|
|
85
|
+
if (divisibleBy !== undefined)
|
|
57
86
|
decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));
|
|
58
87
|
break;
|
|
59
88
|
case 'float':
|
|
@@ -66,17 +95,17 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
66
95
|
decorators.push(ArrayNotEmpty());
|
|
67
96
|
if (isArrayUnique)
|
|
68
97
|
decorators.push(ArrayUnique());
|
|
69
|
-
if (arrayMinSize)
|
|
98
|
+
if (arrayMinSize !== undefined)
|
|
70
99
|
decorators.push(ArrayMinSize(arrayMinSize));
|
|
71
|
-
if (arrayMaxSize)
|
|
100
|
+
if (arrayMaxSize !== undefined)
|
|
72
101
|
decorators.push(ArrayMaxSize(arrayMaxSize));
|
|
73
102
|
}
|
|
74
|
-
decorators.push(IsNumber());
|
|
75
|
-
if (min)
|
|
103
|
+
decorators.push(IsNumber({}, { each: isArray }));
|
|
104
|
+
if (min !== undefined)
|
|
76
105
|
decorators.push(Min(min, { each: isArray }));
|
|
77
|
-
if (max)
|
|
106
|
+
if (max !== undefined)
|
|
78
107
|
decorators.push(Max(max, { each: isArray }));
|
|
79
|
-
if (divisibleBy)
|
|
108
|
+
if (divisibleBy !== undefined)
|
|
80
109
|
decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));
|
|
81
110
|
break;
|
|
82
111
|
case 'date':
|
|
@@ -89,9 +118,9 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
89
118
|
decorators.push(ArrayNotEmpty());
|
|
90
119
|
if (isArrayUnique)
|
|
91
120
|
decorators.push(ArrayUnique());
|
|
92
|
-
if (arrayMinSize)
|
|
121
|
+
if (arrayMinSize !== undefined)
|
|
93
122
|
decorators.push(ArrayMinSize(arrayMinSize));
|
|
94
|
-
if (arrayMaxSize)
|
|
123
|
+
if (arrayMaxSize !== undefined)
|
|
95
124
|
decorators.push(ArrayMaxSize(arrayMaxSize));
|
|
96
125
|
}
|
|
97
126
|
decorators.push(IsDate({ each: isArray }));
|
|
@@ -119,9 +148,9 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
119
148
|
decorators.push(ArrayNotEmpty());
|
|
120
149
|
if (isArrayUnique)
|
|
121
150
|
decorators.push(ArrayUnique());
|
|
122
|
-
if (arrayMinSize)
|
|
151
|
+
if (arrayMinSize !== undefined)
|
|
123
152
|
decorators.push(ArrayMinSize(arrayMinSize));
|
|
124
|
-
if (arrayMaxSize)
|
|
153
|
+
if (arrayMaxSize !== undefined)
|
|
125
154
|
decorators.push(ArrayMaxSize(arrayMaxSize));
|
|
126
155
|
}
|
|
127
156
|
decorators.push(IsString({ each: isArray }));
|
|
@@ -137,9 +166,9 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
137
166
|
decorators.push(IsPositive({ each: isArray }));
|
|
138
167
|
if (isNegative)
|
|
139
168
|
decorators.push(IsNegative({ each: isArray }));
|
|
140
|
-
if (min)
|
|
169
|
+
if (min !== undefined)
|
|
141
170
|
decorators.push(MinLength(min, { each: isArray }));
|
|
142
|
-
if (max)
|
|
171
|
+
if (max !== undefined)
|
|
143
172
|
decorators.push(MaxLength(max, { each: isArray }));
|
|
144
173
|
if (enumObject)
|
|
145
174
|
decorators.push(IsEnum(enumObject, { each: isArray }));
|
|
@@ -163,11 +192,11 @@ export const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max,
|
|
|
163
192
|
export const Roles = (roles) => SetMetadata(ROLES_KEY, roles);
|
|
164
193
|
export const GetCurrentUserId = createParamDecorator((_data, context) => {
|
|
165
194
|
const request = prepareRequestContext(context);
|
|
166
|
-
return request
|
|
195
|
+
return request?.user?.['id'];
|
|
167
196
|
});
|
|
168
197
|
export const GetCurrentRoles = createParamDecorator((_data, context) => {
|
|
169
198
|
const request = prepareRequestContext(context);
|
|
170
|
-
return (request
|
|
199
|
+
return (request?.user?.['roles']?.map((item) => {
|
|
171
200
|
if (typeof item === 'string')
|
|
172
201
|
return item;
|
|
173
202
|
return item.value;
|
|
@@ -176,8 +205,8 @@ export const GetCurrentRoles = createParamDecorator((_data, context) => {
|
|
|
176
205
|
export const GetCurrentUser = createParamDecorator((data, context) => {
|
|
177
206
|
const request = prepareRequestContext(context);
|
|
178
207
|
if (!data)
|
|
179
|
-
return request
|
|
180
|
-
return request
|
|
208
|
+
return request?.user;
|
|
209
|
+
return request?.user?.[data];
|
|
181
210
|
});
|
|
182
211
|
export const Public = () => SetMetadata('isPublic', true);
|
|
183
212
|
export const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';
|
|
@@ -187,8 +216,8 @@ export function MutableBy(roles) {
|
|
|
187
216
|
return (target, propertyKey) => {
|
|
188
217
|
const proto = (target.constructor?.prototype ?? target);
|
|
189
218
|
const existing = Reflect.getMetadata(MUTABLE_BY_KEY, proto) ?? {};
|
|
190
|
-
existing[String(propertyKey)]
|
|
191
|
-
Reflect.defineMetadata(MUTABLE_BY_KEY,
|
|
219
|
+
const updated = { ...existing, [String(propertyKey)]: roles };
|
|
220
|
+
Reflect.defineMetadata(MUTABLE_BY_KEY, updated, proto);
|
|
192
221
|
};
|
|
193
222
|
}
|
|
194
223
|
//# sourceMappingURL=decorators.js.map
|
package/dist/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,oBAAoB,EAGpB,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,GAAG,EACH,SAAS,EACT,GAAG,EACH,SAAS,EACT,aAAa,EACb,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAE9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,EACpC,IAAI,EACJ,UAAU,EACV,WAAW,EACX,GAAG,EACH,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,OAAO,EACP,WAAW,EACX,cAAc,EACd,UAAU,GAAG,KAAK,EAClB,MAAM,GAAG,KAAK,EACd,OAAO,GAAG,KAAK,EACf,MAAM,GAAG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CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,GAA4B,EAAE,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAEnF,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,cAEhC,EAA2B,EAAE,CAAC,WAAW,CAAC,sBAAsB,EAAE,cAAc,CAAC,CAAC;AAMnF,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAkB1C,MAAM,UAAU,SAAS,CAAC,KAAe;IACvC,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,MAAM,KAAK,GAAW,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,IAAI,MAAM,CAAW,CAAC;QAC1E,MAAM,QAAQ,GACX,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,CAA0C,IAAI,EAAE,CAAC;QAC7F,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC;QACtC,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n applyDecorators,\n createParamDecorator,\n CustomDecorator,\n ExecutionContext,\n SetMetadata,\n} from '@nestjs/common';\nimport { Field, Float, Int } from '@nestjs/graphql';\nimport { ApiProperty as SwaggerApiProperty, ApiPropertyOptional } from '@nestjs/swagger';\nimport {\n ArrayMaxSize,\n ArrayMinSize,\n ArrayNotEmpty,\n ArrayUnique,\n IsArray,\n IsBoolean,\n IsDate,\n IsEmail,\n IsEnum,\n IsInt,\n IsJSON,\n IsJWT,\n IsLatitude,\n IsLongitude,\n IsMobilePhone,\n IsNegative,\n IsNumber,\n IsOptional,\n IsPhoneNumber,\n IsPositive,\n IsString,\n IsStrongPassword,\n IsUrl,\n IsUUID,\n Max,\n MaxLength,\n Min,\n MinLength,\n IsDivisibleBy,\n IsDateString,\n} from 'class-validator';\nimport { Type } from 'class-transformer';\nimport { ROLES_KEY } from './const';\nimport { prepareRequestContext } from './lib';\n\nexport const ApiValidationProperty = ({\n type,\n enumObject,\n swaggerType,\n min,\n max,\n arrayMinSize,\n arrayMaxSize,\n divisibleBy,\n example,\n description,\n isSwaggerArray,\n isOptional = false,\n isUUID = false,\n isArray = false,\n isJson = false,\n isJWT = false,\n isUrl = false,\n isPositive = false,\n isNegative = false,\n isEmail = false,\n isMobilePhone = false,\n isPhoneNumber = false,\n isLatitude = false,\n isLongitude = false,\n isStrongPassword = false,\n isArrayNotEmpty = false,\n isArrayUnique = false,\n isDateString = false,\n}: {\n type: 'string' | 'int' | 'float' | 'date' | 'boolean';\n enumObject?: object;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swaggerType?: any;\n min?: number;\n max?: number;\n arrayMinSize?: number;\n arrayMaxSize?: number;\n divisibleBy?: number;\n example?: string;\n description?: string;\n isOptional?: boolean;\n isUUID?: boolean;\n isArray?: boolean;\n isSwaggerArray?: boolean;\n isJson?: boolean;\n isJWT?: boolean;\n isUrl?: boolean;\n isPositive?: boolean;\n isNegative?: boolean;\n isEmail?: boolean;\n isMobilePhone?: boolean;\n isPhoneNumber?: boolean;\n isLatitude?: boolean;\n isLongitude?: boolean;\n isStrongPassword?: boolean;\n isArrayNotEmpty?: boolean;\n isArrayUnique?: boolean;\n isDateString?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n}): (<TFunction extends Function, Y>(\n target: TFunction | object,\n propertyKey?: string | symbol,\n descriptor?: TypedPropertyDescriptor<Y>,\n) => void) => {\n const decorators = [];\n\n const swaggerData = {\n example,\n description,\n enum: enumObject,\n isArray: isSwaggerArray,\n type: swaggerType,\n };\n\n if (!enumObject) {\n delete swaggerData.enum;\n }\n\n if (!isSwaggerArray) {\n delete swaggerData.isArray;\n }\n\n if (!swaggerType) {\n delete swaggerData.type;\n }\n\n if (isOptional) {\n decorators.push(ApiPropertyOptional(swaggerData));\n } else {\n decorators.push(SwaggerApiProperty(swaggerData));\n }\n\n switch (type) {\n case 'int':\n decorators.push(Field(() => (isArray ? [Int] : Int), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n if (divisibleBy) decorators.push(IsDivisibleBy(divisibleBy));\n }\n\n decorators.push(IsNumber());\n decorators.push(IsInt());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n if (divisibleBy) decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));\n\n break;\n case 'float':\n decorators.push(Field(() => (isArray ? [Float] : Float), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n if (divisibleBy) decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));\n\n break;\n case 'date':\n decorators.push(Field(() => (isArray ? [Date] : Date), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsDate({ each: isArray }));\n decorators.push(Type(() => Date));\n break;\n case 'boolean':\n decorators.push(Field({ nullable: isOptional }));\n if (isOptional) decorators.push(IsOptional());\n decorators.push(IsBoolean());\n break;\n case 'string':\n default:\n if (enumObject) {\n decorators.push(\n Field(() => (isArray ? [enumObject] : enumObject), { nullable: isOptional }),\n );\n } else {\n decorators.push(Field(() => (isArray ? [String] : String), { nullable: isOptional }));\n }\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsString({ each: isArray }));\n\n if (isUUID) decorators.push(IsUUID(undefined, { each: isArray }));\n if (isEmail) decorators.push(IsEmail(undefined, { each: isArray }));\n if (isMobilePhone) decorators.push(IsMobilePhone(undefined, undefined, { each: isArray }));\n if (isPhoneNumber) decorators.push(IsPhoneNumber(undefined, { each: isArray }));\n if (isPositive) decorators.push(IsPositive({ each: isArray }));\n if (isNegative) decorators.push(IsNegative({ each: isArray }));\n if (min) decorators.push(MinLength(min, { each: isArray }));\n if (max) decorators.push(MaxLength(max, { each: isArray }));\n if (enumObject) decorators.push(IsEnum(enumObject, { each: isArray }));\n if (isJson) decorators.push(IsJSON({ each: isArray }));\n if (isJWT) decorators.push(IsJWT({ each: isArray }));\n if (isUrl) decorators.push(IsUrl(undefined, { each: isArray }));\n if (isLatitude) decorators.push(IsLatitude({ each: isArray }));\n if (isLongitude) decorators.push(IsLongitude({ each: isArray }));\n if (isStrongPassword) decorators.push(IsStrongPassword(undefined, { each: isArray }));\n if (isDateString) decorators.push(IsDateString(undefined, { each: isArray }));\n }\n\n return applyDecorators(...decorators);\n};\n\nexport const Roles = (roles: string[]): CustomDecorator<string[]> => SetMetadata(ROLES_KEY, roles);\n\nexport const GetCurrentUserId = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user['id'];\n },\n);\n\nexport const GetCurrentRoles = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n request.user['roles']?.map((item: { value: string } | string) => {\n if (typeof item === 'string') return item;\n return item.value;\n }) ?? []\n );\n },\n);\n\nexport const GetCurrentUser = createParamDecorator(\n (data: string | undefined, context: ExecutionContext) => {\n const request = prepareRequestContext(context);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (!data) return request.user;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user[data];\n },\n);\n\nexport const Public = (): CustomDecorator<string> => SetMetadata('isPublic', true);\n\nexport const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';\nexport const CheckFieldsRoles = (fieldsRolesMap: {\n [field: string]: string[];\n}): CustomDecorator<string> => SetMetadata(CHECK_FIELDS_ROLES_KEY, fieldsRolesMap);\n\n/**\n * Metadata key for `@MutableBy()` — marks a DTO field as editable only by specific roles.\n * Fields without this decorator are editable by anyone.\n */\nexport const MUTABLE_BY_KEY = 'mutableBy';\n\n/**\n * Property decorator that marks an input DTO field as restricted to specific roles.\n * The `sanitizeDto()` utility reads this metadata and strips the field if the\n * current user lacks the required role.\n *\n * @example\n * ```ts\n * class CreateProductDto {\n * \\@MutableBy([ROLES.super_admin, ROLES.admin])\n * priority?: number;\n *\n * nameRU: string; // no decorator — anyone can set\n * }\n * ```\n */\n\nexport function MutableBy(roles: string[]): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const proto: object = (target.constructor?.prototype ?? target) as object;\n const existing: Record<string, string[]> =\n (Reflect.getMetadata(MUTABLE_BY_KEY, proto) as Record<string, string[]> | undefined) ?? {};\n existing[String(propertyKey)] = roles;\n Reflect.defineMetadata(MUTABLE_BY_KEY, existing, proto);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,oBAAoB,EAGpB,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,OAAO,EACP,SAAS,EACT,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,MAAM,EACN,GAAG,EACH,SAAS,EACT,GAAG,EACH,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAM9C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAElG,MAAM,UAAU,GAAG,CAAC,KAAc,EAAqB,EAAE,CACvD,OAAO,KAAK,KAAK,UAAU,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAM5D,MAAM,iBAAiB,GAAG,CACxB,UAAgC,EAChC,WAAoB,EACH,EAAE;I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,MAAM,UAAU,SAAS,CAAC,KAAe;IACvC,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,EAAE;QACtD,MAAM,KAAK,GAAW,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,IAAI,MAAM,CAAW,CAAC;QAC1E,MAAM,QAAQ,GACX,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,CAA0C,IAAI,EAAE,CAAC;QAC7F,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QAC9D,OAAO,CAAC,cAAc,CAAC,cAAc,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n applyDecorators,\n createParamDecorator,\n CustomDecorator,\n ExecutionContext,\n SetMetadata,\n} from '@nestjs/common';\nimport { Field, Float, Int } from '@nestjs/graphql';\nimport { ApiProperty as SwaggerApiProperty, ApiPropertyOptional } from '@nestjs/swagger';\nimport {\n ArrayMaxSize,\n ArrayMinSize,\n ArrayNotEmpty,\n ArrayUnique,\n IsArray,\n IsBoolean,\n IsDate,\n IsEmail,\n IsEnum,\n IsInt,\n IsJSON,\n IsJWT,\n IsLatitude,\n IsLongitude,\n IsMobilePhone,\n IsNegative,\n IsNumber,\n IsOptional,\n IsPhoneNumber,\n IsPositive,\n IsString,\n IsStrongPassword,\n IsUrl,\n IsUUID,\n Max,\n MaxLength,\n Min,\n MinLength,\n IsDivisibleBy,\n IsDateString,\n ValidateNested,\n} from 'class-validator';\nimport { Type } from 'class-transformer';\nimport { ROLES_KEY } from './const';\nimport { prepareRequestContext } from './lib';\n\n/** Конструктор класса вложенного DTO. */\nexport type ClassRef = new (...args: never[]) => unknown;\n\n/** Встроенные конструкторы, которые не считаются вложенным DTO. */\nconst BUILT_IN_TYPES = new Set<unknown>([String, Number, Boolean, Object, Date, Array, Function]);\n\nconst isClassRef = (value: unknown): value is ClassRef =>\n typeof value === 'function' && !BUILT_IN_TYPES.has(value);\n\n/**\n * Достаёт класс вложенного DTO из `objectType` или `swaggerType`.\n * Поддерживает как одиночный класс (`SomeDto`), так и массив из одного класса (`[SomeDto]`).\n */\nconst resolveObjectType = (\n objectType: ClassRef | undefined,\n swaggerType: unknown,\n): ClassRef | null => {\n const raw: unknown = objectType ?? swaggerType;\n const candidate = Array.isArray(raw) ? raw[0] : raw;\n\n return isClassRef(candidate) ? candidate : null;\n};\n\n/**\n * Единый декоратор для GraphQL, Swagger и class-validator.\n *\n * Для вложенных DTO передавайте класс в `objectType` (предпочтительно) или в `swaggerType`\n * (обратная совместимость, в т.ч. массив `[SomeDto]`). Тогда вместо `IsString` эмитятся\n * `@Field(() => SomeDto)`, `@ValidateNested()` и `@Type(() => SomeDto)`.\n */\nexport const ApiValidationProperty = ({\n type,\n enumObject,\n swaggerType,\n objectType,\n min,\n max,\n arrayMinSize,\n arrayMaxSize,\n divisibleBy,\n example,\n description,\n isSwaggerArray,\n isOptional = false,\n isUUID = false,\n isArray = false,\n isJson = false,\n isJWT = false,\n isUrl = false,\n isPositive = false,\n isNegative = false,\n isEmail = false,\n isMobilePhone = false,\n isPhoneNumber = false,\n isLatitude = false,\n isLongitude = false,\n isStrongPassword = false,\n isArrayNotEmpty = false,\n isArrayUnique = false,\n isDateString = false,\n}: {\n type: 'string' | 'int' | 'float' | 'date' | 'boolean' | 'object';\n enumObject?: object;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swaggerType?: any;\n objectType?: ClassRef;\n min?: number;\n max?: number;\n arrayMinSize?: number;\n arrayMaxSize?: number;\n divisibleBy?: number;\n example?: string;\n description?: string;\n isOptional?: boolean;\n isUUID?: boolean;\n isArray?: boolean;\n isSwaggerArray?: boolean;\n isJson?: boolean;\n isJWT?: boolean;\n isUrl?: boolean;\n isPositive?: boolean;\n isNegative?: boolean;\n isEmail?: boolean;\n isMobilePhone?: boolean;\n isPhoneNumber?: boolean;\n isLatitude?: boolean;\n isLongitude?: boolean;\n isStrongPassword?: boolean;\n isArrayNotEmpty?: boolean;\n isArrayUnique?: boolean;\n isDateString?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n}): (<TFunction extends Function, Y>(\n target: TFunction | object,\n propertyKey?: string | symbol,\n descriptor?: TypedPropertyDescriptor<Y>,\n) => void) => {\n const decorators = [];\n\n const schemaType =\n swaggerType ?? (objectType ? (isArray ? [objectType] : objectType) : undefined);\n\n const swaggerData = {\n example,\n description,\n enum: enumObject,\n isArray: isSwaggerArray,\n type: schemaType,\n };\n\n if (!enumObject) {\n delete swaggerData.enum;\n }\n\n if (!isSwaggerArray) {\n delete swaggerData.isArray;\n }\n\n if (!schemaType) {\n delete swaggerData.type;\n }\n\n if (isOptional) {\n decorators.push(ApiPropertyOptional(swaggerData));\n } else {\n decorators.push(SwaggerApiProperty(swaggerData));\n }\n\n const nestedType = resolveObjectType(objectType, swaggerType);\n\n if (nestedType) {\n decorators.push(Field(() => (isArray ? [nestedType] : nestedType), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize !== undefined) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize !== undefined) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(ValidateNested({ each: isArray }));\n decorators.push(Type(() => nestedType));\n\n return applyDecorators(...decorators);\n }\n\n if (type === 'object') {\n throw new Error(\n 'ApiValidationProperty: `type: \"object\"` requires a nested DTO class in `objectType` or `swaggerType`',\n );\n }\n\n switch (type) {\n case 'int':\n decorators.push(Field(() => (isArray ? [Int] : Int), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize !== undefined) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize !== undefined) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber({}, { each: isArray }));\n decorators.push(IsInt({ each: isArray }));\n\n if (min !== undefined) decorators.push(Min(min, { each: isArray }));\n if (max !== undefined) decorators.push(Max(max, { each: isArray }));\n if (divisibleBy !== undefined) decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));\n\n break;\n case 'float':\n decorators.push(Field(() => (isArray ? [Float] : Float), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize !== undefined) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize !== undefined) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber({}, { each: isArray }));\n\n if (min !== undefined) decorators.push(Min(min, { each: isArray }));\n if (max !== undefined) decorators.push(Max(max, { each: isArray }));\n if (divisibleBy !== undefined) decorators.push(IsDivisibleBy(divisibleBy, { each: isArray }));\n\n break;\n case 'date':\n decorators.push(Field(() => (isArray ? [Date] : Date), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize !== undefined) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize !== undefined) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsDate({ each: isArray }));\n decorators.push(Type(() => Date));\n break;\n case 'boolean':\n decorators.push(Field({ nullable: isOptional }));\n if (isOptional) decorators.push(IsOptional());\n decorators.push(IsBoolean());\n break;\n case 'string':\n default:\n if (enumObject) {\n decorators.push(\n Field(() => (isArray ? [enumObject] : enumObject), { nullable: isOptional }),\n );\n } else {\n decorators.push(Field(() => (isArray ? [String] : String), { nullable: isOptional }));\n }\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize !== undefined) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize !== undefined) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsString({ each: isArray }));\n\n if (isUUID) decorators.push(IsUUID(undefined, { each: isArray }));\n if (isEmail) decorators.push(IsEmail(undefined, { each: isArray }));\n if (isMobilePhone) decorators.push(IsMobilePhone(undefined, undefined, { each: isArray }));\n if (isPhoneNumber) decorators.push(IsPhoneNumber(undefined, { each: isArray }));\n if (isPositive) decorators.push(IsPositive({ each: isArray }));\n if (isNegative) decorators.push(IsNegative({ each: isArray }));\n if (min !== undefined) decorators.push(MinLength(min, { each: isArray }));\n if (max !== undefined) decorators.push(MaxLength(max, { each: isArray }));\n if (enumObject) decorators.push(IsEnum(enumObject, { each: isArray }));\n if (isJson) decorators.push(IsJSON({ each: isArray }));\n if (isJWT) decorators.push(IsJWT({ each: isArray }));\n if (isUrl) decorators.push(IsUrl(undefined, { each: isArray }));\n if (isLatitude) decorators.push(IsLatitude({ each: isArray }));\n if (isLongitude) decorators.push(IsLongitude({ each: isArray }));\n if (isStrongPassword) decorators.push(IsStrongPassword(undefined, { each: isArray }));\n if (isDateString) decorators.push(IsDateString(undefined, { each: isArray }));\n }\n\n return applyDecorators(...decorators);\n};\n\nexport const Roles = (roles: string[]): CustomDecorator<string[]> => SetMetadata(ROLES_KEY, roles);\n\nexport const GetCurrentUserId = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string | undefined => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request?.user?.['id'];\n },\n);\n\nexport const GetCurrentRoles = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string[] => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n request?.user?.['roles']?.map((item: { value: string } | string) => {\n if (typeof item === 'string') return item;\n return item.value;\n }) ?? []\n );\n },\n);\n\nexport const GetCurrentUser = createParamDecorator(\n (data: string | undefined, context: ExecutionContext) => {\n const request = prepareRequestContext(context);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (!data) return request?.user;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request?.user?.[data];\n },\n);\n\nexport const Public = (): CustomDecorator<string> => SetMetadata('isPublic', true);\n\nexport const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';\nexport const CheckFieldsRoles = (fieldsRolesMap: {\n [field: string]: string[];\n}): CustomDecorator<string> => SetMetadata(CHECK_FIELDS_ROLES_KEY, fieldsRolesMap);\n\n/**\n * Metadata key for `@MutableBy()` — marks a DTO field as editable only by specific roles.\n * Fields without this decorator are editable by anyone.\n */\nexport const MUTABLE_BY_KEY = 'mutableBy';\n\n/**\n * Property decorator that marks an input DTO field as restricted to specific roles.\n * The `sanitizeDto()` utility reads this metadata and strips the field if the\n * current user lacks the required role.\n *\n * @example\n * ```ts\n * class CreateProductDto {\n * \\@MutableBy([ROLES.super_admin, ROLES.admin])\n * priority?: number;\n *\n * nameRU: string; // no decorator — anyone can set\n * }\n * ```\n */\n\nexport function MutableBy(roles: string[]): PropertyDecorator {\n return (target: object, propertyKey: string | symbol) => {\n const proto: object = (target.constructor?.prototype ?? target) as object;\n const existing: Record<string, string[]> =\n (Reflect.getMetadata(MUTABLE_BY_KEY, proto) as Record<string, string[]> | undefined) ?? {};\n const updated = { ...existing, [String(propertyKey)]: roles };\n Reflect.defineMetadata(MUTABLE_BY_KEY, updated, proto);\n };\n}\n"]}
|
package/dist/dto.js
CHANGED
|
@@ -9,7 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
|
|
11
11
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
12
|
-
import {
|
|
12
|
+
import { Type } from 'class-transformer';
|
|
13
|
+
import { IsArray, IsOptional, IsString, IsUUID, Length, ValidateNested } from 'class-validator';
|
|
13
14
|
import { ApiValidationProperty } from './decorators';
|
|
14
15
|
let Paginate = class Paginate {
|
|
15
16
|
page;
|
|
@@ -429,7 +430,7 @@ __decorate([
|
|
|
429
430
|
ApiProperty({ example: 'jpg', description: 'Расширение оригинального файла' }),
|
|
430
431
|
Field(),
|
|
431
432
|
IsString(),
|
|
432
|
-
Length(
|
|
433
|
+
Length(1, 10),
|
|
433
434
|
__metadata("design:type", String)
|
|
434
435
|
], PreparedImageDto.prototype, "originalFileExtension", void 0);
|
|
435
436
|
__decorate([
|
|
@@ -566,7 +567,7 @@ __decorate([
|
|
|
566
567
|
ApiProperty({ example: 'jpg', description: 'Расширение оригинального файла' }),
|
|
567
568
|
Field(),
|
|
568
569
|
IsString(),
|
|
569
|
-
Length(
|
|
570
|
+
Length(1, 10),
|
|
570
571
|
__metadata("design:type", String)
|
|
571
572
|
], InputPreparedImageDto.prototype, "originalFileExtension", void 0);
|
|
572
573
|
__decorate([
|
|
@@ -733,6 +734,9 @@ __decorate([
|
|
|
733
734
|
__decorate([
|
|
734
735
|
ApiProperty({ description: 'Информация о фотографиях' }),
|
|
735
736
|
IsOptional(),
|
|
737
|
+
IsArray(),
|
|
738
|
+
ValidateNested({ each: true }),
|
|
739
|
+
Type(() => AllImagesData),
|
|
736
740
|
__metadata("design:type", Array)
|
|
737
741
|
], UpdateImagesRequest.prototype, "allImages", void 0);
|
|
738
742
|
__decorate([
|
|
@@ -783,6 +787,9 @@ __decorate([
|
|
|
783
787
|
__decorate([
|
|
784
788
|
ApiProperty({ description: 'Информация о файлах' }),
|
|
785
789
|
IsOptional(),
|
|
790
|
+
IsArray(),
|
|
791
|
+
ValidateNested({ each: true }),
|
|
792
|
+
Type(() => AllFilesData),
|
|
786
793
|
__metadata("design:type", Array)
|
|
787
794
|
], UpdateFilesRequest.prototype, "allFiles", void 0);
|
|
788
795
|
__decorate([
|
|
@@ -800,7 +807,7 @@ __decorate([
|
|
|
800
807
|
__metadata("design:type", Number)
|
|
801
808
|
], UpdateFilesResponse.prototype, "statusCode", void 0);
|
|
802
809
|
__decorate([
|
|
803
|
-
ApiProperty({ example: '
|
|
810
|
+
ApiProperty({ example: 'Файлы обновлены', description: 'Сообщение' }),
|
|
804
811
|
__metadata("design:type", String)
|
|
805
812
|
], UpdateFilesResponse.prototype, "message", void 0);
|
|
806
813
|
let SortFieldDto = class SortFieldDto {
|