@russ-b/nestjs-common-tools 1.14.4 → 2.0.0
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/README.md +139 -1
- package/dist/common/pagination/index.d.ts +1 -5
- package/dist/common/pagination/index.js +1 -5
- package/dist/common/pagination/index.js.map +1 -1
- package/dist/jest.setup.d.ts +1 -0
- package/dist/jest.setup.js +4 -0
- package/dist/jest.setup.js.map +1 -0
- package/dist/pagination/dto/paginated-request.dto.d.ts +7 -0
- package/dist/{common/pagination → pagination}/dto/paginated-request.dto.js +18 -2
- package/dist/pagination/dto/paginated-request.dto.js.map +1 -0
- package/dist/pagination/dto/paginated-response.dto.d.ts +24 -0
- package/dist/pagination/dto/paginated-response.dto.js +89 -0
- package/dist/pagination/dto/paginated-response.dto.js.map +1 -0
- package/dist/pagination/dto/sortable-paginated-request.dto.d.ts +8 -0
- package/dist/pagination/dto/sortable-paginated-request.dto.js +34 -0
- package/dist/pagination/dto/sortable-paginated-request.dto.js.map +1 -0
- package/dist/pagination/exceptions/index.d.ts +1 -0
- package/dist/pagination/exceptions/index.js +18 -0
- package/dist/pagination/exceptions/index.js.map +1 -0
- package/dist/pagination/exceptions/pagination-out-of-range.error.d.ts +8 -0
- package/dist/pagination/exceptions/pagination-out-of-range.error.js +22 -0
- package/dist/pagination/exceptions/pagination-out-of-range.error.js.map +1 -0
- package/dist/pagination/index.d.ts +7 -0
- package/dist/pagination/index.js +24 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/{common/pagination → pagination}/interfaces/pagination.interface.d.ts +11 -11
- package/dist/pagination/interfaces/pagination.interface.js.map +1 -0
- package/dist/pagination/pagination.d.ts +11 -0
- package/dist/pagination/pagination.js +61 -0
- package/dist/pagination/pagination.js.map +1 -0
- package/dist/pagination/swagger/api-property-optional-if-available.decorator.d.ts +12 -0
- package/dist/pagination/swagger/api-property-optional-if-available.decorator.js +20 -0
- package/dist/pagination/swagger/api-property-optional-if-available.decorator.js.map +1 -0
- package/dist/pagination/swagger/index.d.ts +1 -0
- package/dist/pagination/swagger/index.js +18 -0
- package/dist/pagination/swagger/index.js.map +1 -0
- package/dist/pagination/swagger/paginated-response.schema.d.ts +14 -0
- package/dist/pagination/swagger/paginated-response.schema.js +79 -0
- package/dist/pagination/swagger/paginated-response.schema.js.map +1 -0
- package/dist/typeorm/enums/index.d.ts +1 -0
- package/dist/{common/pagination/exceptions → typeorm/enums}/index.js +1 -1
- package/dist/typeorm/enums/index.js.map +1 -0
- package/dist/typeorm/enums/sort-order.enum.d.ts +4 -0
- package/dist/typeorm/enums/sort-order.enum.js +9 -0
- package/dist/typeorm/enums/sort-order.enum.js.map +1 -0
- package/dist/typeorm/index.d.ts +1 -0
- package/dist/typeorm/index.js +1 -0
- package/dist/typeorm/index.js.map +1 -1
- package/dist/typeorm/utils/index.d.ts +1 -0
- package/dist/typeorm/utils/index.js +18 -0
- package/dist/typeorm/utils/index.js.map +1 -0
- package/dist/typeorm/utils/query-sort.util.d.ts +19 -0
- package/dist/typeorm/utils/query-sort.util.js +23 -0
- package/dist/typeorm/utils/query-sort.util.js.map +1 -0
- package/package.json +14 -4
- package/dist/common/pagination/dto/paginated-request.dto.d.ts +0 -7
- package/dist/common/pagination/dto/paginated-request.dto.js.map +0 -1
- package/dist/common/pagination/dto/paginated-response.dto.d.ts +0 -12
- package/dist/common/pagination/dto/paginated-response.dto.js +0 -50
- package/dist/common/pagination/dto/paginated-response.dto.js.map +0 -1
- package/dist/common/pagination/exceptions/index.d.ts +0 -1
- package/dist/common/pagination/exceptions/index.js.map +0 -1
- package/dist/common/pagination/exceptions/out-of-range.exception.d.ts +0 -3
- package/dist/common/pagination/exceptions/out-of-range.exception.js +0 -11
- package/dist/common/pagination/exceptions/out-of-range.exception.js.map +0 -1
- package/dist/common/pagination/interfaces/pagination.interface.js.map +0 -1
- package/dist/common/pagination/pagination.d.ts +0 -7
- package/dist/common/pagination/pagination.js +0 -45
- package/dist/common/pagination/pagination.js.map +0 -1
- /package/dist/{common/pagination → pagination}/interfaces/pagination.interface.js +0 -0
package/README.md
CHANGED
|
@@ -26,10 +26,148 @@ This package uses subpath exports for most features.
|
|
|
26
26
|
| `@russ-b/nestjs-common-tools/validators` | validation decorators and constraints |
|
|
27
27
|
| `@russ-b/nestjs-common-tools/typeorm` | TypeORM filters, helpers, transformers, and types |
|
|
28
28
|
| `@russ-b/nestjs-common-tools/logger` | logger builder and logger-related interfaces/types |
|
|
29
|
+
| `@russ-b/nestjs-common-tools/pagination` | pagination DTOs, response builders, and errors |
|
|
29
30
|
| `@russ-b/nestjs-common-tools/common/util` | generic utility helpers |
|
|
30
|
-
| `@russ-b/nestjs-common-tools/common/pagination` |
|
|
31
|
+
| `@russ-b/nestjs-common-tools/common/pagination` | legacy compatibility alias for `pagination` |
|
|
31
32
|
| `@russ-b/nestjs-common-tools/common/filters` | shared filter exports |
|
|
32
33
|
|
|
34
|
+
## Pagination
|
|
35
|
+
|
|
36
|
+
Import pagination helpers from `@russ-b/nestjs-common-tools/pagination`.
|
|
37
|
+
|
|
38
|
+
The pagination module includes:
|
|
39
|
+
|
|
40
|
+
- request DTOs for `page` and `perPage`
|
|
41
|
+
- a sortable request DTO with `sortOrder`
|
|
42
|
+
- response builders for the standard and legacy response shapes
|
|
43
|
+
- a transport-agnostic out-of-range error
|
|
44
|
+
- Swagger schema helpers
|
|
45
|
+
|
|
46
|
+
### Request DTOs
|
|
47
|
+
|
|
48
|
+
`PaginatedRequestDto` gives you validated pagination query params with sensible defaults:
|
|
49
|
+
|
|
50
|
+
- `page` defaults to `1`
|
|
51
|
+
- `perPage` defaults to `50`
|
|
52
|
+
- `perPage` is limited to `1000`
|
|
53
|
+
- string query values such as `?page=2&perPage=25` are coerced to numbers
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Controller, Get, Query } from '@nestjs/common';
|
|
57
|
+
import { PaginatedRequestDto } from '@russ-b/nestjs-common-tools/pagination';
|
|
58
|
+
|
|
59
|
+
@Controller('users')
|
|
60
|
+
export class UsersController {
|
|
61
|
+
@Get()
|
|
62
|
+
findAll(@Query() query: PaginatedRequestDto) {
|
|
63
|
+
return {
|
|
64
|
+
page: query.page,
|
|
65
|
+
perPage: query.perPage,
|
|
66
|
+
offset: query.offset,
|
|
67
|
+
params: query.getParams(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
If you also want a sort direction, use `SortablePaginatedRequestDto`:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { SortablePaginatedRequestDto } from '@russ-b/nestjs-common-tools/pagination';
|
|
77
|
+
|
|
78
|
+
export class UserListQueryDto extends SortablePaginatedRequestDto {}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`sortOrder` accepts `asc` or `desc`.
|
|
82
|
+
|
|
83
|
+
### Building Responses
|
|
84
|
+
|
|
85
|
+
Use `Pagination.createResponse(...)` for the standard contract with `total` and `pages`.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { Pagination, PaginatedRequestDto } from '@russ-b/nestjs-common-tools/pagination';
|
|
89
|
+
|
|
90
|
+
async findAll(query: PaginatedRequestDto) {
|
|
91
|
+
const [users, total] = await this.userRepository.findAndCount({
|
|
92
|
+
skip: query.offset,
|
|
93
|
+
take: query.perPage,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return Pagination.createResponse(query, [users, total]);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This returns:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
{
|
|
104
|
+
data: users,
|
|
105
|
+
pagination: {
|
|
106
|
+
total: 125,
|
|
107
|
+
pages: 13,
|
|
108
|
+
page: 1,
|
|
109
|
+
perPage: 10,
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If you still need the old contract with `totalItems` and `totalPages`, use `Pagination.createLegacyResponse(...)`.
|
|
115
|
+
|
|
116
|
+
### Out-Of-Range Errors
|
|
117
|
+
|
|
118
|
+
`Pagination.createResponse(...)` and `Pagination.createLegacyResponse(...)` throw a transport-agnostic pagination error when the requested page is out of range.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import {
|
|
122
|
+
PAGINATION_OUT_OF_RANGE,
|
|
123
|
+
Pagination,
|
|
124
|
+
PaginationOutOfRangeError,
|
|
125
|
+
} from '@russ-b/nestjs-common-tools/pagination';
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
return Pagination.createResponse(query, [users, total]);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if (
|
|
131
|
+
error instanceof PaginationOutOfRangeError &&
|
|
132
|
+
error.code === PAGINATION_OUT_OF_RANGE
|
|
133
|
+
) {
|
|
134
|
+
// map to the transport or framework you use
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Pagination And Swagger
|
|
142
|
+
|
|
143
|
+
Generic DTOs such as `PaginationResponseDto<T>` are useful at runtime, but Swagger usually does not infer the concrete `T` item type automatically.
|
|
144
|
+
|
|
145
|
+
For Swagger/OpenAPI responses, this package exposes explicit schema helpers from `@russ-b/nestjs-common-tools/pagination`.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
|
|
149
|
+
import {
|
|
150
|
+
createPaginatedResponseSchema,
|
|
151
|
+
PaginationResponseDto,
|
|
152
|
+
} from '@russ-b/nestjs-common-tools/pagination';
|
|
153
|
+
|
|
154
|
+
@ApiExtraModels(UserDto, PaginationResponseDto)
|
|
155
|
+
@ApiOkResponse({
|
|
156
|
+
schema: createPaginatedResponseSchema({
|
|
157
|
+
$ref: getSchemaPath(UserDto),
|
|
158
|
+
}),
|
|
159
|
+
})
|
|
160
|
+
findAll() {
|
|
161
|
+
// ...
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
If you still return the legacy pagination shape, use `createLegacyPaginatedResponseSchema(...)` instead.
|
|
166
|
+
|
|
167
|
+
`PaginationResponseDto` is the standard response DTO with `total` and `pages`.
|
|
168
|
+
`LegacyPaginatedResponseDto` preserves the old `totalItems` and `totalPages` shape.
|
|
169
|
+
The older `PaginatedResponseDto` name remains only as a deprecated legacy alias.
|
|
170
|
+
|
|
33
171
|
## Class Transformer Helpers
|
|
34
172
|
|
|
35
173
|
This package also exposes small reusable decorators for `class-transformer`.
|
|
@@ -14,9 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("
|
|
18
|
-
__exportStar(require("./dto/paginated-request.dto"), exports);
|
|
19
|
-
__exportStar(require("./dto/paginated-response.dto"), exports);
|
|
20
|
-
__exportStar(require("./interfaces/pagination.interface"), exports);
|
|
21
|
-
__exportStar(require("./exceptions"), exports);
|
|
17
|
+
__exportStar(require("../../pagination"), exports);
|
|
22
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/pagination/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/pagination/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,mDAAiC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.setup.js","sourceRoot":"","sources":["../src/jest.setup.ts"],"names":[],"mappings":";;AAAA,4BAA0B"}
|
|
@@ -10,8 +10,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PaginatedRequestDto = void 0;
|
|
13
|
-
const class_validator_1 = require("class-validator");
|
|
14
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
const api_property_optional_if_available_decorator_1 = require("../swagger/api-property-optional-if-available.decorator");
|
|
15
16
|
class PaginatedRequestDto {
|
|
16
17
|
constructor() {
|
|
17
18
|
this.page = 1;
|
|
@@ -20,7 +21,7 @@ class PaginatedRequestDto {
|
|
|
20
21
|
get offset() {
|
|
21
22
|
return (this.page - 1) * this.perPage;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
getParams() {
|
|
24
25
|
return {
|
|
25
26
|
perPage: this.perPage,
|
|
26
27
|
offset: this.offset,
|
|
@@ -29,6 +30,13 @@ class PaginatedRequestDto {
|
|
|
29
30
|
}
|
|
30
31
|
exports.PaginatedRequestDto = PaginatedRequestDto;
|
|
31
32
|
__decorate([
|
|
33
|
+
(0, api_property_optional_if_available_decorator_1.ApiPropertyOptionalIfAvailable)({
|
|
34
|
+
type: 'integer',
|
|
35
|
+
example: 1,
|
|
36
|
+
default: 1,
|
|
37
|
+
minimum: 1,
|
|
38
|
+
description: 'Page number starting from 1.',
|
|
39
|
+
}),
|
|
32
40
|
(0, class_validator_1.IsOptional)(),
|
|
33
41
|
(0, class_validator_1.IsNumber)(),
|
|
34
42
|
(0, class_validator_1.Min)(1),
|
|
@@ -36,6 +44,14 @@ __decorate([
|
|
|
36
44
|
__metadata("design:type", Number)
|
|
37
45
|
], PaginatedRequestDto.prototype, "page", void 0);
|
|
38
46
|
__decorate([
|
|
47
|
+
(0, api_property_optional_if_available_decorator_1.ApiPropertyOptionalIfAvailable)({
|
|
48
|
+
type: 'integer',
|
|
49
|
+
example: 50,
|
|
50
|
+
default: 50,
|
|
51
|
+
minimum: 1,
|
|
52
|
+
maximum: 1000,
|
|
53
|
+
description: 'Number of items to return per page.',
|
|
54
|
+
}),
|
|
39
55
|
(0, class_validator_1.IsOptional)(),
|
|
40
56
|
(0, class_validator_1.IsNumber)(),
|
|
41
57
|
(0, class_validator_1.Max)(1000),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginated-request.dto.js","sourceRoot":"","sources":["../../../src/pagination/dto/paginated-request.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAyC;AACzC,qDAAiE;AAKjE,0HAAyG;AAEzG,MAAa,mBAAmB;IAAhC;QAYE,SAAI,GAAW,CAAC,CAAC;QAejB,YAAO,GAAW,EAAE,CAAC;IAYvB,CAAC;IAVC,IAAI,MAAM;QACR,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,SAAS;QACP,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAvCD,kDAuCC;AA3BC;IAXC,IAAA,6EAA8B,EAAC;QAC9B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,8BAA8B;KAC5C,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;iDACF;AAejB;IAbC,IAAA,6EAA8B,EAAC;QAC9B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,qCAAqC;KACnD,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,IAAI,CAAC;IACT,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;oDACE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LegacyPaginatedResponse, LegacyPaginationMeta, PaginatedResponse, PaginationMeta } from '../interfaces/pagination.interface';
|
|
2
|
+
declare class PaginationMetaDto implements PaginationMeta {
|
|
3
|
+
total: number;
|
|
4
|
+
pages: number;
|
|
5
|
+
page: number;
|
|
6
|
+
perPage: number;
|
|
7
|
+
}
|
|
8
|
+
declare class LegacyPaginationMetaDto implements LegacyPaginationMeta {
|
|
9
|
+
totalItems: number;
|
|
10
|
+
totalPages: number;
|
|
11
|
+
page: number;
|
|
12
|
+
perPage: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class PaginationResponseDto<T> implements PaginatedResponse<T> {
|
|
15
|
+
pagination: PaginationMetaDto;
|
|
16
|
+
data: T[];
|
|
17
|
+
}
|
|
18
|
+
export declare class LegacyPaginatedResponseDto<T> implements LegacyPaginatedResponse<T> {
|
|
19
|
+
pagination: LegacyPaginationMetaDto;
|
|
20
|
+
data: T[];
|
|
21
|
+
}
|
|
22
|
+
export declare class PaginatedResponseDto<T> extends LegacyPaginatedResponseDto<T> {
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaginatedResponseDto = exports.LegacyPaginatedResponseDto = exports.PaginationResponseDto = void 0;
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
let PaginationMetaDto = class PaginationMetaDto {
|
|
15
|
+
};
|
|
16
|
+
__decorate([
|
|
17
|
+
(0, class_transformer_1.Expose)(),
|
|
18
|
+
__metadata("design:type", Number)
|
|
19
|
+
], PaginationMetaDto.prototype, "total", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, class_transformer_1.Expose)(),
|
|
22
|
+
__metadata("design:type", Number)
|
|
23
|
+
], PaginationMetaDto.prototype, "pages", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_transformer_1.Expose)(),
|
|
26
|
+
__metadata("design:type", Number)
|
|
27
|
+
], PaginationMetaDto.prototype, "page", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_transformer_1.Expose)(),
|
|
30
|
+
__metadata("design:type", Number)
|
|
31
|
+
], PaginationMetaDto.prototype, "perPage", void 0);
|
|
32
|
+
PaginationMetaDto = __decorate([
|
|
33
|
+
(0, class_transformer_1.Exclude)()
|
|
34
|
+
], PaginationMetaDto);
|
|
35
|
+
let LegacyPaginationMetaDto = class LegacyPaginationMetaDto {
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, class_transformer_1.Expose)(),
|
|
39
|
+
__metadata("design:type", Number)
|
|
40
|
+
], LegacyPaginationMetaDto.prototype, "totalItems", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, class_transformer_1.Expose)(),
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], LegacyPaginationMetaDto.prototype, "totalPages", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, class_transformer_1.Expose)(),
|
|
47
|
+
__metadata("design:type", Number)
|
|
48
|
+
], LegacyPaginationMetaDto.prototype, "page", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, class_transformer_1.Expose)(),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], LegacyPaginationMetaDto.prototype, "perPage", void 0);
|
|
53
|
+
LegacyPaginationMetaDto = __decorate([
|
|
54
|
+
(0, class_transformer_1.Exclude)()
|
|
55
|
+
], LegacyPaginationMetaDto);
|
|
56
|
+
let PaginationResponseDto = class PaginationResponseDto {
|
|
57
|
+
};
|
|
58
|
+
exports.PaginationResponseDto = PaginationResponseDto;
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, class_transformer_1.Expose)(),
|
|
61
|
+
(0, class_transformer_1.Type)(() => PaginationMetaDto),
|
|
62
|
+
__metadata("design:type", PaginationMetaDto)
|
|
63
|
+
], PaginationResponseDto.prototype, "pagination", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, class_transformer_1.Expose)(),
|
|
66
|
+
__metadata("design:type", Array)
|
|
67
|
+
], PaginationResponseDto.prototype, "data", void 0);
|
|
68
|
+
exports.PaginationResponseDto = PaginationResponseDto = __decorate([
|
|
69
|
+
(0, class_transformer_1.Exclude)()
|
|
70
|
+
], PaginationResponseDto);
|
|
71
|
+
let LegacyPaginatedResponseDto = class LegacyPaginatedResponseDto {
|
|
72
|
+
};
|
|
73
|
+
exports.LegacyPaginatedResponseDto = LegacyPaginatedResponseDto;
|
|
74
|
+
__decorate([
|
|
75
|
+
(0, class_transformer_1.Expose)(),
|
|
76
|
+
(0, class_transformer_1.Type)(() => LegacyPaginationMetaDto),
|
|
77
|
+
__metadata("design:type", LegacyPaginationMetaDto)
|
|
78
|
+
], LegacyPaginatedResponseDto.prototype, "pagination", void 0);
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, class_transformer_1.Expose)(),
|
|
81
|
+
__metadata("design:type", Array)
|
|
82
|
+
], LegacyPaginatedResponseDto.prototype, "data", void 0);
|
|
83
|
+
exports.LegacyPaginatedResponseDto = LegacyPaginatedResponseDto = __decorate([
|
|
84
|
+
(0, class_transformer_1.Exclude)()
|
|
85
|
+
], LegacyPaginatedResponseDto);
|
|
86
|
+
class PaginatedResponseDto extends LegacyPaginatedResponseDto {
|
|
87
|
+
}
|
|
88
|
+
exports.PaginatedResponseDto = PaginatedResponseDto;
|
|
89
|
+
//# sourceMappingURL=paginated-response.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginated-response.dto.js","sourceRoot":"","sources":["../../../src/pagination/dto/paginated-response.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA0D;AAS1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAYtB,CAAA;AAVC;IADC,IAAA,0BAAM,GAAE;;gDACK;AAGd;IADC,IAAA,0BAAM,GAAE;;gDACK;AAGd;IADC,IAAA,0BAAM,GAAE;;+CACI;AAGb;IADC,IAAA,0BAAM,GAAE;;kDACO;AAXZ,iBAAiB;IADtB,IAAA,2BAAO,GAAE;GACJ,iBAAiB,CAYtB;AAGD,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;CAY5B,CAAA;AAVC;IADC,IAAA,0BAAM,GAAE;;2DACU;AAGnB;IADC,IAAA,0BAAM,GAAE;;2DACU;AAGnB;IADC,IAAA,0BAAM,GAAE;;qDACI;AAGb;IADC,IAAA,0BAAM,GAAE;;wDACO;AAXZ,uBAAuB;IAD5B,IAAA,2BAAO,GAAE;GACJ,uBAAuB,CAY5B;AAGM,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;CAOjC,CAAA;AAPY,sDAAqB;AAGhC;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC;8BAClB,iBAAiB;yDAAC;AAG9B;IADC,IAAA,0BAAM,GAAE;;mDACC;gCANC,qBAAqB;IADjC,IAAA,2BAAO,GAAE;GACG,qBAAqB,CAOjC;AAGM,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;CAStC,CAAA;AATY,gEAA0B;AAKrC;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,uBAAuB,CAAC;8BACxB,uBAAuB;8DAAC;AAGpC;IADC,IAAA,0BAAM,GAAE;;wDACC;qCARC,0BAA0B;IADtC,IAAA,2BAAO,GAAE;GACG,0BAA0B,CAStC;AAQD,MAAa,oBAAwB,SAAQ,0BAA6B;CAAG;AAA7E,oDAA6E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SortablePaginatedRequestDto = exports.SortOrder = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const paginated_request_dto_1 = require("./paginated-request.dto");
|
|
15
|
+
const api_property_optional_if_available_decorator_1 = require("../swagger/api-property-optional-if-available.decorator");
|
|
16
|
+
var SortOrder;
|
|
17
|
+
(function (SortOrder) {
|
|
18
|
+
SortOrder["ASC"] = "asc";
|
|
19
|
+
SortOrder["DESC"] = "desc";
|
|
20
|
+
})(SortOrder || (exports.SortOrder = SortOrder = {}));
|
|
21
|
+
class SortablePaginatedRequestDto extends paginated_request_dto_1.PaginatedRequestDto {
|
|
22
|
+
}
|
|
23
|
+
exports.SortablePaginatedRequestDto = SortablePaginatedRequestDto;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, api_property_optional_if_available_decorator_1.ApiPropertyOptionalIfAvailable)({
|
|
26
|
+
enum: SortOrder,
|
|
27
|
+
example: SortOrder.ASC,
|
|
28
|
+
description: 'Sort direction for the requested collection.',
|
|
29
|
+
}),
|
|
30
|
+
(0, class_validator_1.IsEnum)(SortOrder),
|
|
31
|
+
(0, class_validator_1.IsOptional)(),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], SortablePaginatedRequestDto.prototype, "sortOrder", void 0);
|
|
34
|
+
//# sourceMappingURL=sortable-paginated-request.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortable-paginated-request.dto.js","sourceRoot":"","sources":["../../../src/pagination/dto/sortable-paginated-request.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAqD;AACrD,mEAA8D;AAC9D,0HAAyG;AAEzG,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,0BAAa,CAAA;AACf,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB;AAED,MAAa,2BAA4B,SAAQ,2CAAmB;CASnE;AATD,kEASC;AADC;IAPC,IAAA,6EAA8B,EAAC;QAC9B,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,SAAS,CAAC,GAAG;QACtB,WAAW,EAAE,8CAA8C;KAC5D,CAAC;IACD,IAAA,wBAAM,EAAC,SAAS,CAAC;IACjB,IAAA,4BAAU,GAAE;;8DACS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pagination-out-of-range.error';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pagination-out-of-range.error"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pagination/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const PAGINATION_OUT_OF_RANGE = "PAGINATION_OUT_OF_RANGE";
|
|
2
|
+
export declare class PaginationOutOfRangeError extends Error {
|
|
3
|
+
readonly code = "PAGINATION_OUT_OF_RANGE";
|
|
4
|
+
constructor(message?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class OutOfRangeException extends PaginationOutOfRangeError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutOfRangeException = exports.PaginationOutOfRangeError = exports.PAGINATION_OUT_OF_RANGE = void 0;
|
|
4
|
+
const DEFAULT_MESSAGE = 'Page is out of range';
|
|
5
|
+
exports.PAGINATION_OUT_OF_RANGE = 'PAGINATION_OUT_OF_RANGE';
|
|
6
|
+
class PaginationOutOfRangeError extends Error {
|
|
7
|
+
constructor(message = DEFAULT_MESSAGE) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = exports.PAGINATION_OUT_OF_RANGE;
|
|
10
|
+
this.name = 'PaginationOutOfRangeError';
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PaginationOutOfRangeError = PaginationOutOfRangeError;
|
|
15
|
+
class OutOfRangeException extends PaginationOutOfRangeError {
|
|
16
|
+
constructor(message = DEFAULT_MESSAGE) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'OutOfRangeException';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.OutOfRangeException = OutOfRangeException;
|
|
22
|
+
//# sourceMappingURL=pagination-out-of-range.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination-out-of-range.error.js","sourceRoot":"","sources":["../../../src/pagination/exceptions/pagination-out-of-range.error.ts"],"names":[],"mappings":";;;AAAA,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAElC,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE,MAAa,yBAA0B,SAAQ,KAAK;IAGlD,YAAY,UAAkB,eAAe;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAG,+BAAuB,CAAC;QAItC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AARD,8DAQC;AAED,MAAa,mBAAoB,SAAQ,yBAAyB;IAChE,YAAY,UAAkB,eAAe;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AALD,kDAKC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './pagination';
|
|
2
|
+
export * from './dto/paginated-request.dto';
|
|
3
|
+
export * from './dto/paginated-response.dto';
|
|
4
|
+
export * from './dto/sortable-paginated-request.dto';
|
|
5
|
+
export * from './interfaces/pagination.interface';
|
|
6
|
+
export * from './exceptions';
|
|
7
|
+
export * from './swagger';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pagination"), exports);
|
|
18
|
+
__exportStar(require("./dto/paginated-request.dto"), exports);
|
|
19
|
+
__exportStar(require("./dto/paginated-response.dto"), exports);
|
|
20
|
+
__exportStar(require("./dto/sortable-paginated-request.dto"), exports);
|
|
21
|
+
__exportStar(require("./interfaces/pagination.interface"), exports);
|
|
22
|
+
__exportStar(require("./exceptions"), exports);
|
|
23
|
+
__exportStar(require("./swagger"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pagination/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,8DAA4C;AAC5C,+DAA6C;AAC7C,uEAAqD;AACrD,oEAAkD;AAClD,+CAA6B;AAC7B,4CAA0B"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface PaginationRequest {
|
|
2
2
|
page: number;
|
|
3
3
|
perPage: number;
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
5
|
+
export interface PaginationParams {
|
|
6
6
|
perPage: number;
|
|
7
7
|
offset: number;
|
|
8
8
|
}
|
|
9
|
-
export interface IPaginatedResponse<T> {
|
|
10
|
-
data: T[];
|
|
11
|
-
pagination: IPaginationData;
|
|
12
|
-
}
|
|
13
|
-
export interface PaginatedResponse<T> {
|
|
14
|
-
data: T[];
|
|
15
|
-
pagination: PaginationMeta;
|
|
16
|
-
}
|
|
17
9
|
export interface PaginationMeta {
|
|
18
10
|
total: number;
|
|
19
11
|
pages: number;
|
|
20
12
|
page: number;
|
|
21
13
|
perPage: number;
|
|
22
14
|
}
|
|
23
|
-
export interface
|
|
15
|
+
export interface LegacyPaginationMeta {
|
|
24
16
|
totalItems: number;
|
|
25
17
|
totalPages: number;
|
|
26
18
|
page: number;
|
|
27
19
|
perPage: number;
|
|
28
20
|
}
|
|
21
|
+
export interface PaginatedResponse<T> {
|
|
22
|
+
data: T[];
|
|
23
|
+
pagination: PaginationMeta;
|
|
24
|
+
}
|
|
25
|
+
export interface LegacyPaginatedResponse<T> {
|
|
26
|
+
data: T[];
|
|
27
|
+
pagination: LegacyPaginationMeta;
|
|
28
|
+
}
|
|
29
29
|
export type CountableResponse<T> = [T[], number];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.interface.js","sourceRoot":"","sources":["../../../src/pagination/interfaces/pagination.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CountableResponse, LegacyPaginatedResponse, PaginatedResponse, PaginationParams, PaginationRequest } from './interfaces/pagination.interface';
|
|
2
|
+
export declare abstract class Pagination {
|
|
3
|
+
static params(page: number, perPage: number): PaginationParams;
|
|
4
|
+
static paginationParams(page: number, perPage: number): PaginationParams;
|
|
5
|
+
static offset(page: number, perPage: number): number;
|
|
6
|
+
static createResponse<T>({ page, perPage }: PaginationRequest, [data, total]: CountableResponse<T>): PaginatedResponse<T>;
|
|
7
|
+
static createLegacyResponse<T>({ page, perPage }: PaginationRequest, [data, total]: CountableResponse<T>): LegacyPaginatedResponse<T>;
|
|
8
|
+
static response<T>(pagination: PaginationRequest, result: CountableResponse<T>): LegacyPaginatedResponse<T>;
|
|
9
|
+
private static createMeta;
|
|
10
|
+
private static createLegacyMeta;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pagination = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const exceptions_1 = require("./exceptions");
|
|
6
|
+
class Pagination {
|
|
7
|
+
static params(page, perPage) {
|
|
8
|
+
return { perPage, offset: Pagination.offset(page, perPage) };
|
|
9
|
+
}
|
|
10
|
+
static paginationParams(page, perPage) {
|
|
11
|
+
return Pagination.params(page, perPage);
|
|
12
|
+
}
|
|
13
|
+
static offset(page, perPage) {
|
|
14
|
+
return (page - 1) * perPage;
|
|
15
|
+
}
|
|
16
|
+
static createResponse({ page, perPage }, [data, total]) {
|
|
17
|
+
return {
|
|
18
|
+
data,
|
|
19
|
+
pagination: Pagination.createMeta(page, perPage, total),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static createLegacyResponse({ page, perPage }, [data, total]) {
|
|
23
|
+
return {
|
|
24
|
+
data,
|
|
25
|
+
pagination: Pagination.createLegacyMeta(Pagination.createMeta(page, perPage, total)),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
static response(pagination, result) {
|
|
29
|
+
try {
|
|
30
|
+
return Pagination.createLegacyResponse(pagination, result);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof exceptions_1.PaginationOutOfRangeError) {
|
|
34
|
+
throw new common_1.BadRequestException(error.message);
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
static createMeta(page, perPage, total) {
|
|
40
|
+
const pages = Math.ceil(total / perPage);
|
|
41
|
+
if (page > pages && pages > 0) {
|
|
42
|
+
throw new exceptions_1.OutOfRangeException();
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
total,
|
|
46
|
+
pages,
|
|
47
|
+
perPage,
|
|
48
|
+
page,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
static createLegacyMeta({ total, pages, page, perPage, }) {
|
|
52
|
+
return {
|
|
53
|
+
totalItems: total,
|
|
54
|
+
totalPages: pages,
|
|
55
|
+
perPage,
|
|
56
|
+
page,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Pagination = Pagination;
|
|
61
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/pagination/pagination.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAUrD,6CAA8E;AAE9E,MAAsB,UAAU;IAC9B,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,OAAe;QACzC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAKD,MAAM,CAAC,gBAAgB,CAAC,IAAY,EAAE,OAAe;QACnD,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,OAAe;QACzC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,EAAE,IAAI,EAAE,OAAO,EAAqB,EACpC,CAAC,IAAI,EAAE,KAAK,CAAuB;QAEnC,OAAO;YACL,IAAI;YACJ,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC;SACxD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CACzB,EAAE,IAAI,EAAE,OAAO,EAAqB,EACpC,CAAC,IAAI,EAAE,KAAK,CAAuB;QAEnC,OAAO;YACL,IAAI;YACJ,UAAU,EAAE,UAAU,CAAC,gBAAgB,CACrC,UAAU,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAC5C;SACF,CAAC;IACJ,CAAC;IAKD,MAAM,CAAC,QAAQ,CACb,UAA6B,EAC7B,MAA4B;QAE5B,IAAI,CAAC;YACH,OAAO,UAAU,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,sCAAyB,EAAE,CAAC;gBAC/C,MAAM,IAAI,4BAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC/C,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,UAAU,CACvB,IAAY,EACZ,OAAe,EACf,KAAa;QAEb,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;QAEzC,IAAI,IAAI,GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,gCAAmB,EAAE,CAAC;QAClC,CAAC;QAED,OAAO;YACL,KAAK;YACL,KAAK;YACL,OAAO;YACP,IAAI;SACL,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,EAC9B,KAAK,EACL,KAAK,EACL,IAAI,EACJ,OAAO,GACQ;QACf,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,UAAU,EAAE,KAAK;YACjB,OAAO;YACP,IAAI;SACL,CAAC;IACJ,CAAC;CACF;AAxFD,gCAwFC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface SwaggerApiPropertyOptions {
|
|
2
|
+
default?: unknown;
|
|
3
|
+
description?: string;
|
|
4
|
+
enum?: object;
|
|
5
|
+
example?: unknown;
|
|
6
|
+
format?: string;
|
|
7
|
+
maximum?: number;
|
|
8
|
+
minimum?: number;
|
|
9
|
+
type?: 'array' | 'boolean' | 'integer' | 'number' | 'object' | 'string';
|
|
10
|
+
}
|
|
11
|
+
export declare function ApiPropertyOptionalIfAvailable(options?: SwaggerApiPropertyOptions): PropertyDecorator;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiPropertyOptionalIfAvailable = ApiPropertyOptionalIfAvailable;
|
|
4
|
+
function loadApiPropertyOptionalDecorator() {
|
|
5
|
+
try {
|
|
6
|
+
const swaggerModule = require('@nestjs/swagger');
|
|
7
|
+
return swaggerModule.ApiPropertyOptional;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function ApiPropertyOptionalIfAvailable(options) {
|
|
14
|
+
const apiPropertyOptional = loadApiPropertyOptionalDecorator();
|
|
15
|
+
if (!apiPropertyOptional) {
|
|
16
|
+
return () => undefined;
|
|
17
|
+
}
|
|
18
|
+
return apiPropertyOptional(options);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=api-property-optional-if-available.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-property-optional-if-available.decorator.js","sourceRoot":"","sources":["../../../src/pagination/swagger/api-property-optional-if-available.decorator.ts"],"names":[],"mappings":";;AA6BA,wEAUC;AAxBD,SAAS,gCAAgC;IAGvC,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAE9C,CAAC;QAEF,OAAO,aAAa,CAAC,mBAAmB,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAgB,8BAA8B,CAC5C,OAAmC;IAEnC,MAAM,mBAAmB,GAAG,gCAAgC,EAAE,CAAC;IAE/D,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC;IACzB,CAAC;IAED,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './paginated-response.schema';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./paginated-response.schema"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pagination/swagger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8DAA4C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface OpenApiSchema {
|
|
2
|
+
$ref?: string;
|
|
3
|
+
allOf?: OpenApiSchema[];
|
|
4
|
+
description?: string;
|
|
5
|
+
example?: unknown;
|
|
6
|
+
format?: string;
|
|
7
|
+
items?: OpenApiSchema;
|
|
8
|
+
nullable?: boolean;
|
|
9
|
+
properties?: Record<string, OpenApiSchema>;
|
|
10
|
+
required?: string[];
|
|
11
|
+
type?: 'array' | 'boolean' | 'integer' | 'number' | 'object' | 'string';
|
|
12
|
+
}
|
|
13
|
+
export declare function createPaginatedResponseSchema(itemSchema: OpenApiSchema): OpenApiSchema;
|
|
14
|
+
export declare function createLegacyPaginatedResponseSchema(itemSchema: OpenApiSchema): OpenApiSchema;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPaginatedResponseSchema = createPaginatedResponseSchema;
|
|
4
|
+
exports.createLegacyPaginatedResponseSchema = createLegacyPaginatedResponseSchema;
|
|
5
|
+
function createPaginationMetaSchema() {
|
|
6
|
+
return {
|
|
7
|
+
type: 'object',
|
|
8
|
+
required: ['total', 'pages', 'page', 'perPage'],
|
|
9
|
+
properties: {
|
|
10
|
+
total: {
|
|
11
|
+
type: 'integer',
|
|
12
|
+
example: 125,
|
|
13
|
+
},
|
|
14
|
+
pages: {
|
|
15
|
+
type: 'integer',
|
|
16
|
+
example: 13,
|
|
17
|
+
},
|
|
18
|
+
page: {
|
|
19
|
+
type: 'integer',
|
|
20
|
+
example: 1,
|
|
21
|
+
},
|
|
22
|
+
perPage: {
|
|
23
|
+
type: 'integer',
|
|
24
|
+
example: 10,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createLegacyPaginationMetaSchema() {
|
|
30
|
+
return {
|
|
31
|
+
type: 'object',
|
|
32
|
+
required: ['totalItems', 'totalPages', 'page', 'perPage'],
|
|
33
|
+
properties: {
|
|
34
|
+
totalItems: {
|
|
35
|
+
type: 'integer',
|
|
36
|
+
example: 125,
|
|
37
|
+
},
|
|
38
|
+
totalPages: {
|
|
39
|
+
type: 'integer',
|
|
40
|
+
example: 13,
|
|
41
|
+
},
|
|
42
|
+
page: {
|
|
43
|
+
type: 'integer',
|
|
44
|
+
example: 1,
|
|
45
|
+
},
|
|
46
|
+
perPage: {
|
|
47
|
+
type: 'integer',
|
|
48
|
+
example: 10,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function createPaginatedResponseSchema(itemSchema) {
|
|
54
|
+
return {
|
|
55
|
+
type: 'object',
|
|
56
|
+
required: ['data', 'pagination'],
|
|
57
|
+
properties: {
|
|
58
|
+
data: {
|
|
59
|
+
type: 'array',
|
|
60
|
+
items: itemSchema,
|
|
61
|
+
},
|
|
62
|
+
pagination: createPaginationMetaSchema(),
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createLegacyPaginatedResponseSchema(itemSchema) {
|
|
67
|
+
return {
|
|
68
|
+
type: 'object',
|
|
69
|
+
required: ['data', 'pagination'],
|
|
70
|
+
properties: {
|
|
71
|
+
data: {
|
|
72
|
+
type: 'array',
|
|
73
|
+
items: itemSchema,
|
|
74
|
+
},
|
|
75
|
+
pagination: createLegacyPaginationMetaSchema(),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=paginated-response.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginated-response.schema.js","sourceRoot":"","sources":["../../../src/pagination/swagger/paginated-response.schema.ts"],"names":[],"mappings":";;AA+DA,sEAcC;AAED,kFAcC;AAhFD,SAAS,0BAA0B;IACjC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC;QAC/C,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG;aACb;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;aACZ;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,CAAC;aACX;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;aACZ;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,gCAAgC;IACvC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC;QACzD,UAAU,EAAE;YACV,UAAU,EAAE;gBACV,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,GAAG;aACb;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;aACZ;YACD,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,CAAC;aACX;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;aACZ;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,6BAA6B,CAC3C,UAAyB;IAEzB,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC;QAChC,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,UAAU;aAClB;YACD,UAAU,EAAE,0BAA0B,EAAE;SACzC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,mCAAmC,CACjD,UAAyB;IAEzB,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC;QAChC,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,UAAU;aAClB;YACD,UAAU,EAAE,gCAAgC,EAAE;SAC/C;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sort-order.enum';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./sort-order.enum"), exports);
|
|
18
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/typeorm/enums/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SortOrder = void 0;
|
|
4
|
+
var SortOrder;
|
|
5
|
+
(function (SortOrder) {
|
|
6
|
+
SortOrder["ASC"] = "asc";
|
|
7
|
+
SortOrder["DESC"] = "desc";
|
|
8
|
+
})(SortOrder || (exports.SortOrder = SortOrder = {}));
|
|
9
|
+
//# sourceMappingURL=sort-order.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-order.enum.js","sourceRoot":"","sources":["../../../src/typeorm/enums/sort-order.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,0BAAa,CAAA;AACf,CAAC,EAHW,SAAS,yBAAT,SAAS,QAGpB"}
|
package/dist/typeorm/index.d.ts
CHANGED
package/dist/typeorm/index.js
CHANGED
|
@@ -18,4 +18,5 @@ __exportStar(require("./filters"), exports);
|
|
|
18
18
|
__exportStar(require("./errors"), exports);
|
|
19
19
|
__exportStar(require("./transformers"), exports);
|
|
20
20
|
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/typeorm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/typeorm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './query-sort.util';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./query-sort.util"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/typeorm/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
import { SortOrder } from '../enums';
|
|
3
|
+
export type QueryOrderNulls = 'NULLS FIRST' | 'NULLS LAST';
|
|
4
|
+
export interface QuerySortConfig {
|
|
5
|
+
column: string;
|
|
6
|
+
nulls?: QueryOrderNulls;
|
|
7
|
+
selectExpression?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface QueryOrderByConfig extends QuerySortConfig {
|
|
10
|
+
order: 'ASC' | 'DESC';
|
|
11
|
+
}
|
|
12
|
+
export type QuerySortMap<TSort extends string> = Record<TSort, QuerySortConfig>;
|
|
13
|
+
export declare function applyQuerySorting<TEntity extends ObjectLiteral, TSort extends string>(qb: SelectQueryBuilder<TEntity>, params: {
|
|
14
|
+
sortBy?: TSort;
|
|
15
|
+
sortOrder?: SortOrder;
|
|
16
|
+
sortMap: QuerySortMap<TSort>;
|
|
17
|
+
defaultSort: QuerySortConfig;
|
|
18
|
+
tieBreakers?: QueryOrderByConfig[];
|
|
19
|
+
}): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyQuerySorting = applyQuerySorting;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
function applyQuerySorting(qb, params) {
|
|
6
|
+
const primarySort = params.sortBy
|
|
7
|
+
? (params.sortMap[params.sortBy] ?? params.defaultSort)
|
|
8
|
+
: params.defaultSort;
|
|
9
|
+
const resolvedSortOrder = params.sortOrder === enums_1.SortOrder.ASC ? 'ASC' : 'DESC';
|
|
10
|
+
const orderedColumns = new Set([primarySort.column]);
|
|
11
|
+
if (primarySort.selectExpression) {
|
|
12
|
+
qb.addSelect(primarySort.selectExpression, primarySort.column);
|
|
13
|
+
}
|
|
14
|
+
qb.orderBy(primarySort.column, resolvedSortOrder, primarySort.nulls);
|
|
15
|
+
for (const tieBreaker of params.tieBreakers ?? []) {
|
|
16
|
+
if (orderedColumns.has(tieBreaker.column)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
qb.addOrderBy(tieBreaker.column, tieBreaker.order, tieBreaker.nulls);
|
|
20
|
+
orderedColumns.add(tieBreaker.column);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=query-sort.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-sort.util.js","sourceRoot":"","sources":["../../../src/typeorm/utils/query-sort.util.ts"],"names":[],"mappings":";;AAiBA,8CAiCC;AAjDD,oCAAqC;AAgBrC,SAAgB,iBAAiB,CAI/B,EAA+B,EAC/B,MAMC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM;QAC/B,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC;QACvD,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IACvB,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,KAAK,iBAAS,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;IAC9E,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAErD,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;QACjC,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,iBAAiB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IAErE,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;QAClD,IAAI,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,SAAS;QACX,CAAC;QAED,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;QACrE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@russ-b/nestjs-common-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "NestJS utility tools",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
"types": "./dist/index.d.ts",
|
|
36
36
|
"default": "./dist/index.js"
|
|
37
37
|
},
|
|
38
|
+
"./pagination": {
|
|
39
|
+
"types": "./dist/pagination/index.d.ts",
|
|
40
|
+
"default": "./dist/pagination/index.js"
|
|
41
|
+
},
|
|
38
42
|
"./common/util": {
|
|
39
43
|
"types": "./dist/common/util/index.d.ts",
|
|
40
44
|
"default": "./dist/common/util/index.js"
|
|
@@ -71,6 +75,9 @@
|
|
|
71
75
|
},
|
|
72
76
|
"typesVersions": {
|
|
73
77
|
"*": {
|
|
78
|
+
"pagination": [
|
|
79
|
+
"dist/pagination/index.d.ts"
|
|
80
|
+
],
|
|
74
81
|
"validators": [
|
|
75
82
|
"dist/validators/index.d.ts"
|
|
76
83
|
],
|
|
@@ -100,8 +107,7 @@
|
|
|
100
107
|
"dependencies": {
|
|
101
108
|
"class-transformer": "^0.5.1",
|
|
102
109
|
"class-validator": "^0.14.1",
|
|
103
|
-
"uuid": "^11.0.5"
|
|
104
|
-
"winston-loki": "^6.1.3"
|
|
110
|
+
"uuid": "^11.0.5"
|
|
105
111
|
},
|
|
106
112
|
"peerDependencies": {
|
|
107
113
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
@@ -112,7 +118,8 @@
|
|
|
112
118
|
"nest-winston": "^1.10.2",
|
|
113
119
|
"typeorm": "^0.3.20",
|
|
114
120
|
"winston": "^3.17.0",
|
|
115
|
-
"winston-transport": "^4.9.0"
|
|
121
|
+
"winston-transport": "^4.9.0",
|
|
122
|
+
"winston-loki": "^6.1.3"
|
|
116
123
|
},
|
|
117
124
|
"devDependencies": {
|
|
118
125
|
"@eslint/eslintrc": "^3.2.0",
|
|
@@ -137,6 +144,9 @@
|
|
|
137
144
|
"ts"
|
|
138
145
|
],
|
|
139
146
|
"rootDir": "src",
|
|
147
|
+
"setupFiles": [
|
|
148
|
+
"<rootDir>/jest.setup.ts"
|
|
149
|
+
],
|
|
140
150
|
"testRegex": ".*\\.spec\\.ts$",
|
|
141
151
|
"transform": {
|
|
142
152
|
"^.+\\.(t|j)s$": "ts-jest"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IPaginationParams, IPaginationRequestParams } from '../interfaces/pagination.interface';
|
|
2
|
-
export declare class PaginatedRequestDto implements IPaginationRequestParams {
|
|
3
|
-
page: number;
|
|
4
|
-
perPage: number;
|
|
5
|
-
get offset(): number;
|
|
6
|
-
getPaginationParams(): IPaginationParams;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginated-request.dto.js","sourceRoot":"","sources":["../../../../src/common/pagination/dto/paginated-request.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAiE;AACjE,yDAAyC;AAMzC,MAAa,mBAAmB;IAAhC;QAKE,SAAI,GAAW,CAAC,CAAC;QAOjB,YAAO,GAAW,EAAE,CAAC;IAYvB,CAAC;IAVC,IAAI,MAAM;QACR,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;IACxC,CAAC;IAED,mBAAmB;QACjB,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AAxBD,kDAwBC;AAnBC;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;iDACF;AAOjB;IALC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,IAAI,CAAC;IACT,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;oDACE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { IPaginatedResponse, IPaginationData } from '../interfaces/pagination.interface';
|
|
2
|
-
declare class PaginationDataDto implements IPaginationData {
|
|
3
|
-
totalItems: number;
|
|
4
|
-
totalPages: number;
|
|
5
|
-
page: number;
|
|
6
|
-
perPage: number;
|
|
7
|
-
}
|
|
8
|
-
export declare class PaginatedResponseDto<T> implements IPaginatedResponse<T> {
|
|
9
|
-
pagination: PaginationDataDto;
|
|
10
|
-
data: T[];
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.PaginatedResponseDto = void 0;
|
|
13
|
-
const class_transformer_1 = require("class-transformer");
|
|
14
|
-
let PaginationDataDto = class PaginationDataDto {
|
|
15
|
-
};
|
|
16
|
-
__decorate([
|
|
17
|
-
(0, class_transformer_1.Expose)(),
|
|
18
|
-
__metadata("design:type", Number)
|
|
19
|
-
], PaginationDataDto.prototype, "totalItems", void 0);
|
|
20
|
-
__decorate([
|
|
21
|
-
(0, class_transformer_1.Expose)(),
|
|
22
|
-
__metadata("design:type", Number)
|
|
23
|
-
], PaginationDataDto.prototype, "totalPages", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
(0, class_transformer_1.Expose)(),
|
|
26
|
-
__metadata("design:type", Number)
|
|
27
|
-
], PaginationDataDto.prototype, "page", void 0);
|
|
28
|
-
__decorate([
|
|
29
|
-
(0, class_transformer_1.Expose)(),
|
|
30
|
-
__metadata("design:type", Number)
|
|
31
|
-
], PaginationDataDto.prototype, "perPage", void 0);
|
|
32
|
-
PaginationDataDto = __decorate([
|
|
33
|
-
(0, class_transformer_1.Exclude)()
|
|
34
|
-
], PaginationDataDto);
|
|
35
|
-
let PaginatedResponseDto = class PaginatedResponseDto {
|
|
36
|
-
};
|
|
37
|
-
exports.PaginatedResponseDto = PaginatedResponseDto;
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, class_transformer_1.Expose)(),
|
|
40
|
-
(0, class_transformer_1.Type)(() => PaginationDataDto),
|
|
41
|
-
__metadata("design:type", PaginationDataDto)
|
|
42
|
-
], PaginatedResponseDto.prototype, "pagination", void 0);
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, class_transformer_1.Expose)(),
|
|
45
|
-
__metadata("design:type", Array)
|
|
46
|
-
], PaginatedResponseDto.prototype, "data", void 0);
|
|
47
|
-
exports.PaginatedResponseDto = PaginatedResponseDto = __decorate([
|
|
48
|
-
(0, class_transformer_1.Exclude)()
|
|
49
|
-
], PaginatedResponseDto);
|
|
50
|
-
//# sourceMappingURL=paginated-response.dto.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginated-response.dto.js","sourceRoot":"","sources":["../../../../src/common/pagination/dto/paginated-response.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA0D;AAO1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAYtB,CAAA;AAVC;IADC,IAAA,0BAAM,GAAE;;qDACU;AAGnB;IADC,IAAA,0BAAM,GAAE;;qDACU;AAGnB;IADC,IAAA,0BAAM,GAAE;;+CACI;AAGb;IADC,IAAA,0BAAM,GAAE;;kDACO;AAXZ,iBAAiB;IADtB,IAAA,2BAAO,GAAE;GACJ,iBAAiB,CAYtB;AAGM,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;CAOhC,CAAA;AAPY,oDAAoB;AAG/B;IAFC,IAAA,0BAAM,GAAE;IACR,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC;8BAClB,iBAAiB;wDAAC;AAG9B;IADC,IAAA,0BAAM,GAAE;;kDACC;+BANC,oBAAoB;IADhC,IAAA,2BAAO,GAAE;GACG,oBAAoB,CAOhC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './out-of-range.exception';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/common/pagination/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OutOfRangeException = void 0;
|
|
4
|
-
class OutOfRangeException extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.message = 'Page is out of range';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.OutOfRangeException = OutOfRangeException;
|
|
11
|
-
//# sourceMappingURL=out-of-range.exception.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"out-of-range.exception.js","sourceRoot":"","sources":["../../../../src/common/pagination/exceptions/out-of-range.exception.ts"],"names":[],"mappings":";;;AAAA,MAAa,mBAAoB,SAAQ,KAAK;IAA9C;;QACE,YAAO,GAAG,sBAAsB,CAAC;IACnC,CAAC;CAAA;AAFD,kDAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.interface.js","sourceRoot":"","sources":["../../../../src/common/pagination/interfaces/pagination.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CountableResponse, IPaginatedResponse, IPaginationParams, IPaginationRequestParams, PaginatedResponse } from './interfaces/pagination.interface';
|
|
2
|
-
export declare abstract class Pagination {
|
|
3
|
-
static paginationParams(page: number, perPage: number): IPaginationParams;
|
|
4
|
-
static offset(page: number, perPage: number): number;
|
|
5
|
-
static createResponse<T>({ page, perPage }: IPaginationRequestParams, [data, total]: CountableResponse<T>): PaginatedResponse<T>;
|
|
6
|
-
static response<T>({ page, perPage }: IPaginationRequestParams, [data, total]: CountableResponse<T>): IPaginatedResponse<T>;
|
|
7
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pagination = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
const out_of_range_exception_1 = require("./exceptions/out-of-range.exception");
|
|
6
|
-
class Pagination {
|
|
7
|
-
static paginationParams(page, perPage) {
|
|
8
|
-
return { perPage, offset: Pagination.offset(page, perPage) };
|
|
9
|
-
}
|
|
10
|
-
static offset(page, perPage) {
|
|
11
|
-
return (page - 1) * perPage;
|
|
12
|
-
}
|
|
13
|
-
static createResponse({ page, perPage }, [data, total]) {
|
|
14
|
-
const pages = Math.ceil(total / perPage);
|
|
15
|
-
if (page > pages && pages > 0) {
|
|
16
|
-
throw new out_of_range_exception_1.OutOfRangeException();
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
data,
|
|
20
|
-
pagination: {
|
|
21
|
-
total,
|
|
22
|
-
pages,
|
|
23
|
-
perPage,
|
|
24
|
-
page,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
static response({ page, perPage }, [data, total]) {
|
|
29
|
-
const totalPages = Math.ceil(total / perPage);
|
|
30
|
-
if (page > totalPages && totalPages > 0) {
|
|
31
|
-
throw new common_1.BadRequestException('Page is out of range');
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
data,
|
|
35
|
-
pagination: {
|
|
36
|
-
totalItems: total,
|
|
37
|
-
totalPages,
|
|
38
|
-
perPage,
|
|
39
|
-
page,
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Pagination = Pagination;
|
|
45
|
-
//# sourceMappingURL=pagination.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../../src/common/pagination/pagination.ts"],"names":[],"mappings":";;;AAAA,2CAAqD;AAQrD,gFAA0E;AAE1E,MAAsB,UAAU;IAC9B,MAAM,CAAC,gBAAgB,CAAC,IAAY,EAAE,OAAe;QACnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,OAAe;QACzC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,EAAE,IAAI,EAAE,OAAO,EAA4B,EAC3C,CAAC,IAAI,EAAE,KAAK,CAAuB;QAEnC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;QAEzC,IAAI,IAAI,GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,4CAAmB,EAAE,CAAC;QAClC,CAAC;QAED,OAAO;YACL,IAAI;YACJ,UAAU,EAAE;gBACV,KAAK;gBACL,KAAK;gBACL,OAAO;gBACP,IAAI;aACL;SACF,CAAC;IACJ,CAAC;IAKD,MAAM,CAAC,QAAQ,CACb,EAAE,IAAI,EAAE,OAAO,EAA4B,EAC3C,CAAC,IAAI,EAAE,KAAK,CAAuB;QAEnC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC;QAE9C,IAAI,IAAI,GAAG,UAAU,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,4BAAmB,CAAC,sBAAsB,CAAC,CAAC;QACxD,CAAC;QAED,OAAO;YACL,IAAI;YACJ,UAAU,EAAE;gBACV,UAAU,EAAE,KAAK;gBACjB,UAAU;gBACV,OAAO;gBACP,IAAI;aACL;SACF,CAAC;IACJ,CAAC;CACF;AArDD,gCAqDC"}
|
|
File without changes
|