denwa-nest-shared 1.2.5 → 1.2.7
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 +40 -3
- package/cjs/decorators.d.ts +4 -2
- package/cjs/decorators.js +34 -3
- package/cjs/decorators.js.map +1 -1
- package/cjs/lib.d.ts +17 -7
- package/cjs/lib.js +158 -19
- package/cjs/lib.js.map +1 -1
- package/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/cjs/types.d.ts +12 -1
- package/cjs/types.js.map +1 -1
- package/dist/decorators.d.ts +4 -2
- package/dist/decorators.js +35 -4
- package/dist/decorators.js.map +1 -1
- package/dist/lib.d.ts +17 -7
- package/dist/lib.js +156 -19
- package/dist/lib.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types.d.ts +12 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/skills/schema-definition/SKILL.md +62 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.2.7](https://github.com/Denwa799/nest-shared/compare/v1.2.6...v1.2.7) (2026-09-23)
|
|
6
|
+
|
|
7
|
+
### [1.2.6](https://github.com/Denwa799/nest-shared/compare/v1.2.5...v1.2.6) (2026-09-13)
|
|
8
|
+
|
|
5
9
|
### [1.2.5](https://github.com/Denwa799/nest-shared/compare/v1.2.4...v1.2.5) (2026-09-03)
|
|
6
10
|
|
|
7
11
|
### [1.2.4](https://github.com/Denwa799/nest-shared/compare/v1.2.3...v1.2.4) (2026-07-14)
|
package/README.md
CHANGED
|
@@ -53,10 +53,38 @@ export class CreateProductDto {
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
### 2.
|
|
56
|
+
### 2. Вложенные DTO
|
|
57
|
+
|
|
58
|
+
Для вложенных объектов передавайте класс DTO через `objectType` (или `swaggerType` — для обратной
|
|
59
|
+
совместимости, включая `[SomeDto]`). Тогда `@Field`, `@ValidateNested` и `@Type` проставляются
|
|
60
|
+
автоматически, а ошибочный `IsString` не эмитится.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { InputType } from '@nestjs/graphql';
|
|
64
|
+
import { ApiValidationProperty } from 'denwa-nest-shared';
|
|
65
|
+
|
|
66
|
+
@InputType()
|
|
67
|
+
class ImageDto {
|
|
68
|
+
@ApiValidationProperty({ type: 'string', max: 256 })
|
|
69
|
+
tempName: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@InputType()
|
|
73
|
+
export class UpdateProductDto {
|
|
74
|
+
@ApiValidationProperty({
|
|
75
|
+
type: 'object',
|
|
76
|
+
objectType: ImageDto,
|
|
77
|
+
isArray: true,
|
|
78
|
+
isOptional: true,
|
|
79
|
+
})
|
|
80
|
+
images?: ImageDto[];
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3. Фильтрация и поиск с TypeORM
|
|
57
85
|
|
|
58
86
|
```typescript
|
|
59
|
-
import { createQueryData } from 'denwa-nest-shared';
|
|
87
|
+
import { createQueryData, encodeCursor, decodeCursor } from 'denwa-nest-shared';
|
|
60
88
|
import { Repository } from 'typeorm';
|
|
61
89
|
|
|
62
90
|
async function getUsers(userRepository: Repository<User>, query: any) {
|
|
@@ -69,9 +97,18 @@ async function getUsers(userRepository: Repository<User>, query: any) {
|
|
|
69
97
|
filter: query.filter,
|
|
70
98
|
search: query.search,
|
|
71
99
|
searchFields: ['name', 'email'],
|
|
100
|
+
// ⚡ Опции для высоконагруженных таблиц (сотни тысяч / миллионы строк):
|
|
101
|
+
cursor: query.cursor, // base64url строка или { id, sortValue, sortValues, order, field }
|
|
102
|
+
sortFields: [ // произвольное число полей сортировки с разными направлениями
|
|
103
|
+
{ field: 'priority', order: 'desc' },
|
|
104
|
+
{ field: 'createdAt', order: 'asc' },
|
|
105
|
+
],
|
|
106
|
+
select: ['id'], // для двухшагового Deferred Join
|
|
107
|
+
extraRow: true, // take: limit + 1 (проверка следующей страницы без count(*))
|
|
108
|
+
maxPage: 100, // защита от глубокого OFFSET
|
|
72
109
|
});
|
|
73
110
|
|
|
74
|
-
return await userRepository.
|
|
111
|
+
return await userRepository.find(queryData);
|
|
75
112
|
}
|
|
76
113
|
```
|
|
77
114
|
|
package/cjs/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/cjs/decorators.js
CHANGED
|
@@ -9,14 +9,22 @@ const class_validator_1 = require("class-validator");
|
|
|
9
9
|
const class_transformer_1 = require("class-transformer");
|
|
10
10
|
const const_1 = require("./const");
|
|
11
11
|
const lib_1 = require("./lib");
|
|
12
|
-
const
|
|
12
|
+
const BUILT_IN_TYPES = new Set([String, Number, Boolean, Object, Date, Array, Function]);
|
|
13
|
+
const isClassRef = (value) => typeof value === 'function' && !BUILT_IN_TYPES.has(value);
|
|
14
|
+
const resolveObjectType = (objectType, swaggerType) => {
|
|
15
|
+
const raw = objectType ?? swaggerType;
|
|
16
|
+
const candidate = Array.isArray(raw) ? raw[0] : raw;
|
|
17
|
+
return isClassRef(candidate) ? candidate : null;
|
|
18
|
+
};
|
|
19
|
+
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, }) => {
|
|
13
20
|
const decorators = [];
|
|
21
|
+
const schemaType = swaggerType ?? (objectType ? (isArray ? [objectType] : objectType) : undefined);
|
|
14
22
|
const swaggerData = {
|
|
15
23
|
example,
|
|
16
24
|
description,
|
|
17
25
|
enum: enumObject,
|
|
18
26
|
isArray: isSwaggerArray,
|
|
19
|
-
type:
|
|
27
|
+
type: schemaType,
|
|
20
28
|
};
|
|
21
29
|
if (!enumObject) {
|
|
22
30
|
delete swaggerData.enum;
|
|
@@ -24,7 +32,7 @@ const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max, arrayM
|
|
|
24
32
|
if (!isSwaggerArray) {
|
|
25
33
|
delete swaggerData.isArray;
|
|
26
34
|
}
|
|
27
|
-
if (!
|
|
35
|
+
if (!schemaType) {
|
|
28
36
|
delete swaggerData.type;
|
|
29
37
|
}
|
|
30
38
|
if (isOptional) {
|
|
@@ -33,6 +41,29 @@ const ApiValidationProperty = ({ type, enumObject, swaggerType, min, max, arrayM
|
|
|
33
41
|
else {
|
|
34
42
|
decorators.push((0, swagger_1.ApiProperty)(swaggerData));
|
|
35
43
|
}
|
|
44
|
+
const nestedType = resolveObjectType(objectType, swaggerType);
|
|
45
|
+
if (nestedType) {
|
|
46
|
+
decorators.push((0, graphql_1.Field)(() => (isArray ? [nestedType] : nestedType), { nullable: isOptional }));
|
|
47
|
+
if (isOptional)
|
|
48
|
+
decorators.push((0, class_validator_1.IsOptional)());
|
|
49
|
+
if (isArray) {
|
|
50
|
+
decorators.push((0, class_validator_1.IsArray)());
|
|
51
|
+
if (isArrayNotEmpty)
|
|
52
|
+
decorators.push((0, class_validator_1.ArrayNotEmpty)());
|
|
53
|
+
if (isArrayUnique)
|
|
54
|
+
decorators.push((0, class_validator_1.ArrayUnique)());
|
|
55
|
+
if (arrayMinSize !== undefined)
|
|
56
|
+
decorators.push((0, class_validator_1.ArrayMinSize)(arrayMinSize));
|
|
57
|
+
if (arrayMaxSize !== undefined)
|
|
58
|
+
decorators.push((0, class_validator_1.ArrayMaxSize)(arrayMaxSize));
|
|
59
|
+
}
|
|
60
|
+
decorators.push((0, class_validator_1.ValidateNested)({ each: isArray }));
|
|
61
|
+
decorators.push((0, class_transformer_1.Type)(() => nestedType));
|
|
62
|
+
return (0, common_1.applyDecorators)(...decorators);
|
|
63
|
+
}
|
|
64
|
+
if (type === 'object') {
|
|
65
|
+
throw new Error('ApiValidationProperty: `type: "object"` requires a nested DTO class in `objectType` or `swaggerType`');
|
|
66
|
+
}
|
|
36
67
|
switch (type) {
|
|
37
68
|
case 'int':
|
|
38
69
|
decorators.push((0, graphql_1.Field)(() => (isArray ? [graphql_1.Int] : graphql_1.Int), { nullable: isOptional }));
|
package/cjs/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAmTA,8BAQC;AA3TD,2CAMwB;AACxB,6CAAoD;AACpD,6CAAyF;AACzF,qDA+ByB;AACzB,yDAAyC;AACzC,mCAAoC;AACpC,+BAA8C;AAEvC,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,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,MAAM,KAAK,GAAW,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,IAAI,MAAM,CAAW,CAAC;QAC1E,MAAM,QAAQ,GACX,OAAO,CAAC,WAAW,CAAC,sBAAc,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,sBAAc,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} 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 !== 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"]}
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAkXA,8BAQC;AA1XD,2CAMwB;AACxB,6CAAoD;AACpD,6CAAyF;AACzF,qDAgCyB;AACzB,yDAAyC;AACzC,mCAAoC;AACpC,+BAA8C;AAM9C,MA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CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;QAC9D,OAAO,CAAC,cAAc,CAAC,sBAAc,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/cjs/lib.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import { FindOptionsSelect } from 'typeorm';
|
|
1
2
|
import { GraphQLResolveInfo } from 'graphql';
|
|
2
|
-
import { IPaginate, IPreparedFile, IPreparedImage, QueryDataType } from './types';
|
|
3
|
+
import { ICursorPagination, IPaginate, IPreparedFile, IPreparedImage, QueryDataType } from './types';
|
|
3
4
|
import { AllFilesDto, AllImagesDto, FileDto, ImageFileDto, TempFilesDto, TempImagesDto } from './dto';
|
|
4
5
|
import { ExecutionContext } from '@nestjs/common';
|
|
5
6
|
export declare const getError: ({ error, message }: {
|
|
6
7
|
error?: unknown;
|
|
7
8
|
message?: string;
|
|
8
9
|
}) => void;
|
|
9
|
-
export declare const createPaginate: (page: number, count: number, limit: number, modelsNumber?: number
|
|
10
|
+
export declare const createPaginate: (page: number, count: number, limit: number, modelsNumber?: number, options?: {
|
|
11
|
+
cursor?: string;
|
|
12
|
+
hasNextPage?: boolean;
|
|
13
|
+
}) => IPaginate;
|
|
14
|
+
export declare const encodeCursor: (data: ICursorPagination) => string;
|
|
15
|
+
export declare const decodeCursor: (cursor: string) => ICursorPagination | null;
|
|
10
16
|
export declare const getPaginateSkip: (page: number, limit: number) => number;
|
|
11
17
|
export declare const formatPhone: (phone: string) => string;
|
|
12
18
|
export declare const concatenateTwo32BitNumbers: (low: number, high: number) => number;
|
|
@@ -20,21 +26,21 @@ export declare const prepareTokenExp: (accessExp: number | {
|
|
|
20
26
|
access: number;
|
|
21
27
|
refresh: number;
|
|
22
28
|
};
|
|
23
|
-
export declare const checkPageAndLimit: (page: number, limit: number, maxLimit?: number) => {
|
|
29
|
+
export declare const checkPageAndLimit: (page: number, limit: number, maxLimit?: number, maxPage?: number) => {
|
|
24
30
|
checkedPage: number;
|
|
25
31
|
checkedLimit: number;
|
|
26
32
|
};
|
|
27
33
|
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, fields, relationsMap, searchFields, }: {
|
|
34
|
+
export declare const createQueryData: <Entity>({ page, limit, sortField, sortFields, sortOrder, filterType, searchType, filter, filters, search, fromToFields, oneEntryArrayFields, fields, relationsMap, searchFields, cursor, select, extraRow, maxPage, }: {
|
|
29
35
|
page: number;
|
|
30
36
|
limit: number;
|
|
31
|
-
sortField
|
|
32
|
-
sortOrder
|
|
37
|
+
sortField?: string;
|
|
38
|
+
sortOrder?: string;
|
|
33
39
|
sortFields?: {
|
|
34
40
|
field: string;
|
|
35
41
|
order: string;
|
|
36
42
|
}[];
|
|
37
|
-
filterType
|
|
43
|
+
filterType?: string;
|
|
38
44
|
searchType?: string;
|
|
39
45
|
filter?: object;
|
|
40
46
|
filters?: object[];
|
|
@@ -51,6 +57,10 @@ export declare const createQueryData: <Entity>({ page, limit, sortField, sortFie
|
|
|
51
57
|
fields?: string[];
|
|
52
58
|
relationsMap?: Record<string, string | string[]>;
|
|
53
59
|
searchFields?: string[];
|
|
60
|
+
cursor?: string | ICursorPagination;
|
|
61
|
+
select?: (keyof Entity)[] | FindOptionsSelect<Entity>;
|
|
62
|
+
extraRow?: boolean;
|
|
63
|
+
maxPage?: number;
|
|
54
64
|
}) => QueryDataType<Entity>;
|
|
55
65
|
export declare const extractGraphqlFields: (info: GraphQLResolveInfo) => string[];
|
|
56
66
|
export declare const prepareTempImages: (files: ImageFileDto[], tempImages: TempImagesDto[]) => IPreparedImage[];
|
package/cjs/lib.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cleanContentImages = exports.extractImageUrlsFromContent = exports.serializeContentToHtml = exports.escapeHtml = exports.htmlToSlateString = exports.compareRolesPriority = exports.createValue = exports.getUniqueNumber = exports.getRandomNumber = exports.getGuardAuthContext = exports.prepareRequestContext = exports.checkTranslit = exports.translit = exports.updateEntityFiles = exports.updateEntityImages = exports.prepareImages = exports.getTempFilesInAllFiles = exports.getTempImagesInAllImages = exports.prepareTempImages = exports.extractGraphqlFields = exports.createQueryData = exports.isCorrectOrder = exports.checkPageAndLimit = exports.prepareTokenExp = exports.concatenateTwo32BitNumbers = exports.formatPhone = exports.getPaginateSkip = exports.createPaginate = exports.getError = void 0;
|
|
3
|
+
exports.cleanContentImages = exports.extractImageUrlsFromContent = exports.serializeContentToHtml = exports.escapeHtml = exports.htmlToSlateString = exports.compareRolesPriority = exports.createValue = exports.getUniqueNumber = exports.getRandomNumber = exports.getGuardAuthContext = exports.prepareRequestContext = exports.checkTranslit = exports.translit = exports.updateEntityFiles = exports.updateEntityImages = exports.prepareImages = exports.getTempFilesInAllFiles = exports.getTempImagesInAllImages = exports.prepareTempImages = exports.extractGraphqlFields = exports.createQueryData = exports.isCorrectOrder = exports.checkPageAndLimit = exports.prepareTokenExp = exports.concatenateTwo32BitNumbers = exports.formatPhone = exports.getPaginateSkip = exports.decodeCursor = exports.encodeCursor = exports.createPaginate = exports.getError = void 0;
|
|
4
4
|
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
5
5
|
const typeorm_1 = require("typeorm");
|
|
6
6
|
const jsdom_1 = require("jsdom");
|
|
@@ -13,7 +13,7 @@ const getError = ({ error, message }) => {
|
|
|
13
13
|
console.error(message);
|
|
14
14
|
};
|
|
15
15
|
exports.getError = getError;
|
|
16
|
-
const createPaginate = (page, count, limit, modelsNumber = 1) => {
|
|
16
|
+
const createPaginate = (page, count, limit, modelsNumber = 1, options) => {
|
|
17
17
|
const pages = Math.ceil(count / (limit * modelsNumber));
|
|
18
18
|
const paginate = {
|
|
19
19
|
page,
|
|
@@ -22,10 +22,36 @@ const createPaginate = (page, count, limit, modelsNumber = 1) => {
|
|
|
22
22
|
next: page <= pages - 1 ? page + 1 : undefined,
|
|
23
23
|
count,
|
|
24
24
|
limit,
|
|
25
|
+
...(options?.cursor ? { cursor: options.cursor } : {}),
|
|
26
|
+
...(options?.hasNextPage !== undefined ? { hasNextPage: options.hasNextPage } : {}),
|
|
25
27
|
};
|
|
26
28
|
return paginate;
|
|
27
29
|
};
|
|
28
30
|
exports.createPaginate = createPaginate;
|
|
31
|
+
const encodeCursor = (data) => {
|
|
32
|
+
return Buffer.from(JSON.stringify(data)).toString('base64url');
|
|
33
|
+
};
|
|
34
|
+
exports.encodeCursor = encodeCursor;
|
|
35
|
+
const decodeCursor = (cursor) => {
|
|
36
|
+
try {
|
|
37
|
+
const json = Buffer.from(cursor, 'base64url').toString('utf8');
|
|
38
|
+
const parsed = JSON.parse(json);
|
|
39
|
+
if (parsed && (typeof parsed.id === 'string' || typeof parsed.id === 'number')) {
|
|
40
|
+
return {
|
|
41
|
+
id: parsed.id,
|
|
42
|
+
sortValue: parsed.sortValue,
|
|
43
|
+
sortValues: parsed.sortValues,
|
|
44
|
+
order: parsed.order,
|
|
45
|
+
field: parsed.field,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.decodeCursor = decodeCursor;
|
|
29
55
|
const getPaginateSkip = (page, limit) => {
|
|
30
56
|
return (page - 1) * limit;
|
|
31
57
|
};
|
|
@@ -53,7 +79,7 @@ const prepareTokenExp = (accessExp, refreshExp) => {
|
|
|
53
79
|
return { access, refresh };
|
|
54
80
|
};
|
|
55
81
|
exports.prepareTokenExp = prepareTokenExp;
|
|
56
|
-
const checkPageAndLimit = (page, limit, maxLimit = 500) => {
|
|
82
|
+
const checkPageAndLimit = (page, limit, maxLimit = 500, maxPage) => {
|
|
57
83
|
const paginationData = {
|
|
58
84
|
checkedPage: page,
|
|
59
85
|
checkedLimit: limit,
|
|
@@ -61,6 +87,9 @@ const checkPageAndLimit = (page, limit, maxLimit = 500) => {
|
|
|
61
87
|
if (page < 1) {
|
|
62
88
|
paginationData.checkedPage = 1;
|
|
63
89
|
}
|
|
90
|
+
if (maxPage && page > maxPage) {
|
|
91
|
+
paginationData.checkedPage = maxPage;
|
|
92
|
+
}
|
|
64
93
|
if (limit < 1) {
|
|
65
94
|
paginationData.checkedLimit = 1;
|
|
66
95
|
}
|
|
@@ -74,7 +103,7 @@ const isCorrectOrder = (order) => {
|
|
|
74
103
|
return order.toLocaleLowerCase() === 'asc' || order.toLocaleLowerCase() === 'desc';
|
|
75
104
|
};
|
|
76
105
|
exports.isCorrectOrder = isCorrectOrder;
|
|
77
|
-
const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filterType, searchType = 'or', filter, filters, search, fromToFields, oneEntryArrayFields, fields, relationsMap, searchFields, }) => {
|
|
106
|
+
const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filterType = 'and', searchType = 'or', filter, filters, search, fromToFields, oneEntryArrayFields, fields, relationsMap, searchFields, cursor, select, extraRow = false, maxPage, }) => {
|
|
78
107
|
const getFromToFields = (key, value, fromToMap) => {
|
|
79
108
|
if (fromToFields) {
|
|
80
109
|
const found = fromToFields.find((item) => {
|
|
@@ -133,24 +162,66 @@ const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filter
|
|
|
133
162
|
value: (0, typeorm_1.In)(value),
|
|
134
163
|
};
|
|
135
164
|
};
|
|
165
|
+
const { checkedPage, checkedLimit } = (0, exports.checkPageAndLimit)(page, limit, 500, maxPage);
|
|
166
|
+
let parsedCursor = null;
|
|
167
|
+
if (typeof cursor === 'string') {
|
|
168
|
+
parsedCursor = (0, exports.decodeCursor)(cursor);
|
|
169
|
+
}
|
|
170
|
+
else if (cursor &&
|
|
171
|
+
typeof cursor === 'object' &&
|
|
172
|
+
cursor.id !== undefined &&
|
|
173
|
+
cursor.id !== null) {
|
|
174
|
+
parsedCursor = cursor;
|
|
175
|
+
}
|
|
136
176
|
const queryData = {
|
|
137
|
-
skip: (0, exports.getPaginateSkip)(
|
|
138
|
-
take:
|
|
177
|
+
skip: parsedCursor ? 0 : (0, exports.getPaginateSkip)(checkedPage, checkedLimit),
|
|
178
|
+
take: extraRow ? checkedLimit + 1 : checkedLimit,
|
|
139
179
|
};
|
|
180
|
+
if (select) {
|
|
181
|
+
queryData.select = select;
|
|
182
|
+
}
|
|
183
|
+
let effectiveSortFields = [];
|
|
140
184
|
if (sortFields && sortFields.length > 0) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
queryData.order = order;
|
|
185
|
+
effectiveSortFields = sortFields
|
|
186
|
+
.filter((sortItem) => (0, exports.isCorrectOrder)(sortItem.order))
|
|
187
|
+
.map((sortItem) => ({
|
|
188
|
+
field: sortItem.field,
|
|
189
|
+
order: sortItem.order.toLowerCase(),
|
|
190
|
+
}));
|
|
149
191
|
}
|
|
150
|
-
else if (sortField
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
192
|
+
else if (sortField) {
|
|
193
|
+
const orderStr = sortOrder || parsedCursor?.order || 'desc';
|
|
194
|
+
effectiveSortFields = [
|
|
195
|
+
{
|
|
196
|
+
field: sortField,
|
|
197
|
+
order: (0, exports.isCorrectOrder)(orderStr) ? orderStr.toLowerCase() : 'desc',
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
else if (parsedCursor?.field) {
|
|
202
|
+
const orderStr = sortOrder || parsedCursor.order || 'desc';
|
|
203
|
+
effectiveSortFields = [
|
|
204
|
+
{
|
|
205
|
+
field: parsedCursor.field,
|
|
206
|
+
order: (0, exports.isCorrectOrder)(orderStr) ? orderStr.toLowerCase() : 'desc',
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
}
|
|
210
|
+
if (parsedCursor) {
|
|
211
|
+
const hasId = effectiveSortFields.some((item) => item.field === 'id');
|
|
212
|
+
if (!hasId) {
|
|
213
|
+
const lastOrder = effectiveSortFields.length > 0
|
|
214
|
+
? effectiveSortFields[effectiveSortFields.length - 1].order
|
|
215
|
+
: 'desc';
|
|
216
|
+
effectiveSortFields.push({ field: 'id', order: lastOrder });
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (effectiveSortFields.length > 0) {
|
|
220
|
+
const orderObj = {};
|
|
221
|
+
for (const item of effectiveSortFields) {
|
|
222
|
+
orderObj[item.field] = item.order;
|
|
223
|
+
}
|
|
224
|
+
queryData.order = orderObj;
|
|
154
225
|
}
|
|
155
226
|
if (filters && filters.length > 0) {
|
|
156
227
|
const where = filters.map((item) => {
|
|
@@ -343,11 +414,79 @@ const createQueryData = ({ page, limit, sortField, sortFields, sortOrder, filter
|
|
|
343
414
|
whereOr = [...whereOr, { [key]: (0, typeorm_1.LessThanOrEqual)(item.toFieldValue) }];
|
|
344
415
|
}
|
|
345
416
|
});
|
|
346
|
-
if (filterType
|
|
417
|
+
if (filterType?.toLowerCase() === 'or')
|
|
347
418
|
return whereOr;
|
|
348
419
|
else
|
|
349
420
|
return whereAnd;
|
|
350
421
|
}
|
|
422
|
+
if (parsedCursor) {
|
|
423
|
+
const getCursorVal = (fieldName, index) => {
|
|
424
|
+
if (fieldName === 'id') {
|
|
425
|
+
return parsedCursor.id;
|
|
426
|
+
}
|
|
427
|
+
if (parsedCursor.sortValues && parsedCursor.sortValues[fieldName] !== undefined) {
|
|
428
|
+
return parsedCursor.sortValues[fieldName];
|
|
429
|
+
}
|
|
430
|
+
if (index === 0 && parsedCursor.sortValue !== undefined) {
|
|
431
|
+
return parsedCursor.sortValue;
|
|
432
|
+
}
|
|
433
|
+
return undefined;
|
|
434
|
+
};
|
|
435
|
+
const cursorConditions = [];
|
|
436
|
+
const entriesWithValues = [];
|
|
437
|
+
effectiveSortFields.forEach((item, idx) => {
|
|
438
|
+
const val = getCursorVal(item.field, idx);
|
|
439
|
+
if (val !== undefined && val !== null) {
|
|
440
|
+
entriesWithValues.push({ field: item.field, order: item.order, value: val });
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
if (entriesWithValues.length === 0) {
|
|
444
|
+
entriesWithValues.push({
|
|
445
|
+
field: 'id',
|
|
446
|
+
order: (sortOrder || parsedCursor.order || 'desc').toLowerCase() === 'desc' ? 'desc' : 'asc',
|
|
447
|
+
value: parsedCursor.id,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
for (let i = 0; i < entriesWithValues.length; i++) {
|
|
451
|
+
const branch = {};
|
|
452
|
+
for (let j = 0; j < i; j++) {
|
|
453
|
+
branch[entriesWithValues[j].field] = entriesWithValues[j].value;
|
|
454
|
+
}
|
|
455
|
+
const current = entriesWithValues[i];
|
|
456
|
+
branch[current.field] =
|
|
457
|
+
current.order === 'desc' ? (0, typeorm_1.LessThan)(current.value) : (0, typeorm_1.MoreThan)(current.value);
|
|
458
|
+
cursorConditions.push(branch);
|
|
459
|
+
}
|
|
460
|
+
if (!queryData.where) {
|
|
461
|
+
queryData.where = cursorConditions.length === 1 ? cursorConditions[0] : cursorConditions;
|
|
462
|
+
}
|
|
463
|
+
else if (Array.isArray(queryData.where)) {
|
|
464
|
+
const combined = [];
|
|
465
|
+
for (const whereCond of queryData.where) {
|
|
466
|
+
for (const cursorCond of cursorConditions) {
|
|
467
|
+
combined.push({
|
|
468
|
+
...whereCond,
|
|
469
|
+
...cursorCond,
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
queryData.where = combined;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
if (cursorConditions.length === 1) {
|
|
477
|
+
queryData.where = {
|
|
478
|
+
...queryData.where,
|
|
479
|
+
...cursorConditions[0],
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
queryData.where = cursorConditions.map((cond) => ({
|
|
484
|
+
...queryData.where,
|
|
485
|
+
...cond,
|
|
486
|
+
}));
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
351
490
|
if (fields && relationsMap) {
|
|
352
491
|
const filterKeys = filter ? Object.keys(filter) : [];
|
|
353
492
|
const extraFilterKeys = filters?.flatMap((f) => Object.keys(f)) ?? [];
|