denwa-nest-shared 1.2.1 → 1.2.3

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/cjs/types.d.ts CHANGED
@@ -24,6 +24,7 @@ export type QueryDataType<Entity> = {
24
24
  take: number;
25
25
  order?: FindOptionsOrder<Entity>;
26
26
  where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;
27
+ relations?: string[];
27
28
  };
28
29
  export type OkNotFoundType = IResponse<404 | 200>;
29
30
  export type OkNotFoundBadRequestType = IResponse<404 | 400 | 200>;
package/cjs/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,IAIX;AAJD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,iBAAS,CAAA;IACT,iBAAS,CAAA;AACX,CAAC,EAJW,IAAI,oBAAJ,IAAI,QAIf;AAwED,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,+CAAyB,CAAA;IACzB,6EAAuD,CAAA;AACzD,CAAC,EANW,oBAAoB,oCAApB,oBAAoB,QAM/B","sourcesContent":["import { FindOptionsOrder, FindOptionsWhere } from 'typeorm';\n\nexport enum LANG {\n RU = 'ru',\n EN = 'en',\n AR = 'ar',\n}\n\nexport interface IResponse<StatusCode, Data = object> {\n statusCode: StatusCode;\n messages?: string[];\n message?: string;\n error?: string;\n data?: Data;\n}\nexport interface IPaginate {\n page: number;\n pages: number;\n previous?: number;\n next?: number;\n count: number;\n limit: number;\n}\n\nexport type QueryDataType<Entity> = {\n skip: number;\n take: number;\n order?: FindOptionsOrder<Entity>;\n where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;\n};\n\nexport type OkNotFoundType = IResponse<404 | 200>;\nexport type OkNotFoundBadRequestType = IResponse<404 | 400 | 200>;\nexport type OkNotFoundForbiddenType = IResponse<404 | 403 | 200>;\n\nexport type FilterType = 'and' | 'or';\nexport type SortOrderType = 'asc' | 'desc' | 'ASC' | 'DESC';\n\nexport interface IPreparedImage {\n name: string;\n fileExtensions?: string[];\n prefixes?: string[];\n originalFileExtension: string;\n entityId: string;\n folder?: string;\n fullPathExample: string;\n altRU?: string;\n altEN?: string;\n altAR?: string;\n}\n\nexport interface IPreparedFile {\n name: string;\n fullName: string;\n extension: string;\n entityId: string;\n fullPathExample: string;\n folder?: string;\n}\n\nexport interface IPreparedImageAndOrder extends IPreparedImage {\n order: number;\n}\n\nexport interface IPreparedFileAndOrder extends IPreparedFile {\n order: number;\n}\n\nexport interface IGetQuery {\n page?: number;\n limit?: number;\n sortField?: string;\n sortOrder?: SortOrderType;\n filterType?: FilterType;\n filter?: object;\n search?: object;\n}\n\nexport enum ImageContentTypeEnum {\n 'image/avif' = 'image/avif',\n 'image/webp' = 'image/webp',\n 'image/jpeg' = 'image/jpeg',\n 'image/png' = 'image/png',\n 'application/octet-stream' = 'application/octet-stream',\n}\n\nexport type NullToUndefined<T> = T extends null\n ? undefined\n : T extends (infer U)[]\n ? NullToUndefined<U>[]\n : T extends object\n ? { [K in keyof T]: NullToUndefined<T[K]> }\n : T;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,IAAY,IAIX;AAJD,WAAY,IAAI;IACd,iBAAS,CAAA;IACT,iBAAS,CAAA;IACT,iBAAS,CAAA;AACX,CAAC,EAJW,IAAI,oBAAJ,IAAI,QAIf;AAyED,IAAY,oBAMX;AAND,WAAY,oBAAoB;IAC9B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,iDAA2B,CAAA;IAC3B,+CAAyB,CAAA;IACzB,6EAAuD,CAAA;AACzD,CAAC,EANW,oBAAoB,oCAApB,oBAAoB,QAM/B","sourcesContent":["import { FindOptionsOrder, FindOptionsWhere } from 'typeorm';\n\nexport enum LANG {\n RU = 'ru',\n EN = 'en',\n AR = 'ar',\n}\n\nexport interface IResponse<StatusCode, Data = object> {\n statusCode: StatusCode;\n messages?: string[];\n message?: string;\n error?: string;\n data?: Data;\n}\nexport interface IPaginate {\n page: number;\n pages: number;\n previous?: number;\n next?: number;\n count: number;\n limit: number;\n}\n\nexport type QueryDataType<Entity> = {\n skip: number;\n take: number;\n order?: FindOptionsOrder<Entity>;\n where?: FindOptionsWhere<Entity>[] | FindOptionsWhere<Entity>;\n relations?: string[];\n};\n\nexport type OkNotFoundType = IResponse<404 | 200>;\nexport type OkNotFoundBadRequestType = IResponse<404 | 400 | 200>;\nexport type OkNotFoundForbiddenType = IResponse<404 | 403 | 200>;\n\nexport type FilterType = 'and' | 'or';\nexport type SortOrderType = 'asc' | 'desc' | 'ASC' | 'DESC';\n\nexport interface IPreparedImage {\n name: string;\n fileExtensions?: string[];\n prefixes?: string[];\n originalFileExtension: string;\n entityId: string;\n folder?: string;\n fullPathExample: string;\n altRU?: string;\n altEN?: string;\n altAR?: string;\n}\n\nexport interface IPreparedFile {\n name: string;\n fullName: string;\n extension: string;\n entityId: string;\n fullPathExample: string;\n folder?: string;\n}\n\nexport interface IPreparedImageAndOrder extends IPreparedImage {\n order: number;\n}\n\nexport interface IPreparedFileAndOrder extends IPreparedFile {\n order: number;\n}\n\nexport interface IGetQuery {\n page?: number;\n limit?: number;\n sortField?: string;\n sortOrder?: SortOrderType;\n filterType?: FilterType;\n filter?: object;\n search?: object;\n}\n\nexport enum ImageContentTypeEnum {\n 'image/avif' = 'image/avif',\n 'image/webp' = 'image/webp',\n 'image/jpeg' = 'image/jpeg',\n 'image/png' = 'image/png',\n 'application/octet-stream' = 'application/octet-stream',\n}\n\nexport type NullToUndefined<T> = T extends null\n ? undefined\n : T extends (infer U)[]\n ? NullToUndefined<U>[]\n : T extends object\n ? { [K in keyof T]: NullToUndefined<T[K]> }\n : T;\n"]}
@@ -38,3 +38,5 @@ export declare const CHECK_FIELDS_ROLES_KEY = "checkFieldsRoles";
38
38
  export declare const CheckFieldsRoles: (fieldsRolesMap: {
39
39
  [field: string]: string[];
40
40
  }) => CustomDecorator<string>;
41
+ export declare const MUTABLE_BY_KEY = "mutableBy";
42
+ export declare function MutableBy(roles: string[]): PropertyDecorator;
@@ -182,4 +182,13 @@ export const GetCurrentUser = createParamDecorator((data, context) => {
182
182
  export const Public = () => SetMetadata('isPublic', true);
183
183
  export const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';
184
184
  export const CheckFieldsRoles = (fieldsRolesMap) => SetMetadata(CHECK_FIELDS_ROLES_KEY, fieldsRolesMap);
185
+ export const MUTABLE_BY_KEY = 'mutableBy';
186
+ export function MutableBy(roles) {
187
+ return (target, propertyKey) => {
188
+ const proto = (target.constructor?.prototype ?? target);
189
+ const existing = Reflect.getMetadata(MUTABLE_BY_KEY, proto) ?? {};
190
+ existing[String(propertyKey)] = roles;
191
+ Reflect.defineMetadata(MUTABLE_BY_KEY, existing, proto);
192
+ };
193
+ }
185
194
  //# sourceMappingURL=decorators.js.map
@@ -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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,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,IAAgC,EAAE,EAAE;QAC9D,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC,CAAC,IAAI,EAAE,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,oBAAoB,CAChD,CAAC,IAAwB,EAAE,OAAyB,EAAE,EAAE;IACtD,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAG/C,IAAI,CAAC,IAAI;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC;IAE/B,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CACF,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","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"]}
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,Q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AAC;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"]}
@@ -0,0 +1 @@
1
+ export declare function sanitizeDto<T extends Record<string, unknown>>(dto: T, userRoles: string[]): T;
@@ -0,0 +1,17 @@
1
+ import { MUTABLE_BY_KEY } from './decorators';
2
+ export function sanitizeDto(dto, userRoles) {
3
+ const prototype = Object.getPrototypeOf(dto);
4
+ if (!prototype || prototype === Object.prototype)
5
+ return dto;
6
+ const fieldRolesMap = Reflect.getMetadata(MUTABLE_BY_KEY, prototype);
7
+ if (!fieldRolesMap)
8
+ return dto;
9
+ const hasSuperAdmin = userRoles.some((r) => r === 'super_admin' || r === 'super-admin');
10
+ for (const [field, allowedRoles] of Object.entries(fieldRolesMap)) {
11
+ if (field in dto && !hasSuperAdmin && !userRoles.some((r) => allowedRoles.includes(r))) {
12
+ delete dto[field];
13
+ }
14
+ }
15
+ return dto;
16
+ }
17
+ //# sourceMappingURL=dto-sanitizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto-sanitizer.js","sourceRoot":"","sources":["../src/dto-sanitizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAuB9C,MAAM,UAAU,WAAW,CAAoC,GAAM,EAAE,SAAmB;IACxF,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,CAAkB,CAAC;IAC9D,IAAI,CAAC,SAAS,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS;QAAE,OAAO,GAAG,CAAC;IAE7D,MAAM,aAAa,GAAyC,OAAO,CAAC,WAAW,CAC7E,cAAc,EACd,SAAS,CAC8B,CAAC;IAE1C,IAAI,CAAC,aAAa;QAAE,OAAO,GAAG,CAAC;IAE/B,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,aAAa,CAAC,CAAC;IAExF,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;QAClE,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACvF,OAAO,GAAG,CAAC,KAAgB,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { MUTABLE_BY_KEY } from './decorators';\n\n/**\n * Strips DTO fields that the current user is not allowed to edit,\n * based on `@MutableBy()` decorators on the DTO class.\n *\n * Fields without `@MutableBy()` are considered public — no restriction.\n * If the user has `super_admin` role, all fields pass through.\n *\n * @example\n * ```ts\n * // DTO\n * class UpdateProductDto {\n * \\@MutableBy([ROLES.admin])\n * priority?: number;\n *\n * nameRU: string;\n * }\n *\n * // Resolver\n * sanitizeDto(data, ctx.req?.user?.roles ?? []);\n * ```\n */\nexport function sanitizeDto<T extends Record<string, unknown>>(dto: T, userRoles: string[]): T {\n const prototype = Object.getPrototypeOf(dto) as object | null;\n if (!prototype || prototype === Object.prototype) return dto;\n\n const fieldRolesMap: Record<string, string[]> | undefined = Reflect.getMetadata(\n MUTABLE_BY_KEY,\n prototype,\n ) as Record<string, string[]> | undefined;\n\n if (!fieldRolesMap) return dto;\n\n const hasSuperAdmin = userRoles.some((r) => r === 'super_admin' || r === 'super-admin');\n\n for (const [field, allowedRoles] of Object.entries(fieldRolesMap)) {\n if (field in dto && !hasSuperAdmin && !userRoles.some((r) => allowedRoles.includes(r))) {\n delete dto[field as keyof T];\n }\n }\n\n return dto;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './types';
4
4
  export * from './const';
5
5
  export * from './validation';
6
6
  export * from './decorators';
7
+ export * from './dto-sanitizer';
7
8
  export * from './interceptors';
8
9
  export * from './openapi-axios';
9
10
  export * from './opensearch-core';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export * from './types';
4
4
  export * from './const';
5
5
  export * from './validation';
6
6
  export * from './decorators';
7
+ export * from './dto-sanitizer';
7
8
  export * from './interceptors';
8
9
  export * from './openapi-axios';
9
10
  export * from './opensearch-core';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './dto';\nexport * from './lib';\nexport * from './types';\nexport * from './const';\nexport * from './validation';\nexport * from './decorators';\nexport * from './interceptors';\nexport * from './openapi-axios';\nexport * from './opensearch-core';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './dto';\nexport * from './lib';\nexport * from './types';\nexport * from './const';\nexport * from './validation';\nexport * from './decorators';\nexport * from './dto-sanitizer';\nexport * from './interceptors';\nexport * from './openapi-axios';\nexport * from './opensearch-core';\n"]}
package/dist/lib.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare const checkPageAndLimit: (page: number, limit: number, maxLimit?:
25
25
  checkedLimit: number;
26
26
  };
27
27
  export declare const isCorrectOrder: (order: string) => boolean;
28
- export declare const createQueryData: <Entity>({ page, limit, sortField, sortFields, sortOrder, filterType, searchType, filter, filters, search, fromToFields, oneEntryArrayFields, }: {
28
+ export declare const createQueryData: <Entity>({ page, limit, sortField, sortFields, sortOrder, filterType, searchType, filter, filters, search, fromToFields, oneEntryArrayFields, fields, relationsMap, searchFields, }: {
29
29
  page: number;
30
30
  limit: number;
31
31
  sortField: string;
@@ -38,7 +38,7 @@ export declare const createQueryData: <Entity>({ page, limit, sortField, sortFie
38
38
  searchType?: string;
39
39
  filter?: object;
40
40
  filters?: object[];
41
- search?: object;
41
+ search?: object | string;
42
42
  fromToFields?: {
43
43
  fromFieldName: string;
44
44
  toFieldName: string;
@@ -48,6 +48,9 @@ export declare const createQueryData: <Entity>({ page, limit, sortField, sortFie
48
48
  key: string;
49
49
  originalKey: string;
50
50
  }[];
51
+ fields?: string[];
52
+ relationsMap?: Record<string, string | string[]>;
53
+ searchFields?: string[];
51
54
  }) => QueryDataType<Entity>;
52
55
  export declare const extractGraphqlFields: (info: GraphQLResolveInfo) => string[];
53
56
  export declare const prepareTempImages: (files: ImageFileDto[], tempImages: TempImagesDto[]) => IPreparedImage[];
package/dist/lib.js CHANGED
@@ -63,7 +63,7 @@ export const checkPageAndLimit = (page, limit, maxLimit = 500) => {
63
63
  export const isCorrectOrder = (order) => {
64
64
  return order.toLocaleLowerCase() === 'asc' || order.toLocaleLowerCase() === 'desc';
65
65
  };
66
- export const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filterType, searchType = 'or', filter, filters, search, fromToFields, oneEntryArrayFields, }) => {
66
+ export const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filterType, searchType = 'or', filter, filters, search, fromToFields, oneEntryArrayFields, fields, relationsMap, searchFields, }) => {
67
67
  const getFromToFields = (key, value, fromToMap) => {
68
68
  if (fromToFields) {
69
69
  fromToFields.find((item) => {
@@ -149,7 +149,27 @@ export const createQueryData = ({ page, limit, sortField, sortFields, sortOrder,
149
149
  const where = getFilterWhere(filter, filterType);
150
150
  queryData.where = where;
151
151
  }
152
- if (search && !!Object.keys(search).length) {
152
+ if (typeof search === 'string' && searchFields?.length) {
153
+ const searchTerm = search.trim();
154
+ if (searchTerm) {
155
+ const orConditions = searchFields.map((field) => ({
156
+ [field]: ILike(`%${searchTerm}%`),
157
+ }));
158
+ if (!queryData.where) {
159
+ queryData.where = orConditions;
160
+ }
161
+ else if (Array.isArray(queryData.where)) {
162
+ queryData.where = [...queryData.where, ...orConditions];
163
+ }
164
+ else {
165
+ queryData.where = orConditions.map((cond) => ({
166
+ ...cond,
167
+ ...queryData.where,
168
+ }));
169
+ }
170
+ }
171
+ }
172
+ else if (search && typeof search === 'object' && !!Object.keys(search).length) {
153
173
  const searchWhereAnd = {};
154
174
  const searchWhereOr = [];
155
175
  for (const [key, value] of Object.entries(search)) {
@@ -291,6 +311,27 @@ export const createQueryData = ({ page, limit, sortField, sortFields, sortOrder,
291
311
  else
292
312
  return whereAnd;
293
313
  }
314
+ if (fields && relationsMap) {
315
+ const filterKeys = filter ? Object.keys(filter) : [];
316
+ const extraFilterKeys = filters?.flatMap((f) => Object.keys(f)) ?? [];
317
+ const allFilterKeys = [...new Set([...filterKeys, ...extraFilterKeys])];
318
+ const relations = [];
319
+ for (const [entityKey, relationValue] of Object.entries(relationsMap)) {
320
+ const inFields = fields.includes(`data.${entityKey}`);
321
+ const inFilterKeys = allFilterKeys.includes(entityKey);
322
+ if (inFields || inFilterKeys) {
323
+ if (Array.isArray(relationValue)) {
324
+ relations.push(...relationValue);
325
+ }
326
+ else {
327
+ relations.push(relationValue);
328
+ }
329
+ }
330
+ }
331
+ if (relations.length) {
332
+ queryData.relations = relations;
333
+ }
334
+ }
294
335
  return queryData;
295
336
  };
296
337
  export const extractGraphqlFields = (info) => {