@nestarc/pagination 0.1.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/LICENSE +21 -0
- package/README.md +334 -0
- package/dist/cursor/cursor.encoder.d.ts +2 -0
- package/dist/cursor/cursor.encoder.js +25 -0
- package/dist/decorators/api-paginated-response.decorator.d.ts +3 -0
- package/dist/decorators/api-paginated-response.decorator.js +91 -0
- package/dist/decorators/paginate-defaults.decorator.d.ts +9 -0
- package/dist/decorators/paginate-defaults.decorator.js +7 -0
- package/dist/decorators/paginate.decorator.d.ts +1 -0
- package/dist/decorators/paginate.decorator.js +9 -0
- package/dist/errors/invalid-cursor.error.d.ts +4 -0
- package/dist/errors/invalid-cursor.error.js +11 -0
- package/dist/errors/invalid-filter-column.error.d.ts +4 -0
- package/dist/errors/invalid-filter-column.error.js +14 -0
- package/dist/errors/invalid-sort-column.error.d.ts +4 -0
- package/dist/errors/invalid-sort-column.error.js +11 -0
- package/dist/filter/filter-parser.d.ts +2 -0
- package/dist/filter/filter-parser.js +89 -0
- package/dist/filter/search-builder.d.ts +1 -0
- package/dist/filter/search-builder.js +13 -0
- package/dist/filter/sort-builder.d.ts +3 -0
- package/dist/filter/sort-builder.js +25 -0
- package/dist/helpers/link-builder.d.ts +13 -0
- package/dist/helpers/link-builder.js +71 -0
- package/dist/helpers/type-coercion.d.ts +1 -0
- package/dist/helpers/type-coercion.js +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +31 -0
- package/dist/interfaces/filter-operator.type.d.ts +2 -0
- package/dist/interfaces/filter-operator.type.js +2 -0
- package/dist/interfaces/paginate-config.interface.d.ts +29 -0
- package/dist/interfaces/paginate-config.interface.js +2 -0
- package/dist/interfaces/paginate-query.interface.d.ts +11 -0
- package/dist/interfaces/paginate-query.interface.js +2 -0
- package/dist/interfaces/paginated.interface.d.ts +39 -0
- package/dist/interfaces/paginated.interface.js +2 -0
- package/dist/interfaces/pagination-options.interface.d.ts +15 -0
- package/dist/interfaces/pagination-options.interface.js +2 -0
- package/dist/paginate.d.ts +7 -0
- package/dist/paginate.js +179 -0
- package/dist/paginate.service.d.ts +15 -0
- package/dist/paginate.service.js +59 -0
- package/dist/pagination.constants.d.ts +5 -0
- package/dist/pagination.constants.js +8 -0
- package/dist/pagination.module.d.ts +6 -0
- package/dist/pagination.module.js +52 -0
- package/dist/pipes/paginate-query.pipe.d.ts +2 -0
- package/dist/pipes/paginate-query.pipe.js +43 -0
- package/dist/testing/create-paginate-query.d.ts +2 -0
- package/dist/testing/create-paginate-query.js +9 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/test-pagination.module.d.ts +5 -0
- package/dist/testing/test-pagination.module.js +30 -0
- package/package.json +53 -0
|
@@ -0,0 +1,52 @@
|
|
|
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 PaginationModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.PaginationModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const pagination_constants_1 = require("./pagination.constants");
|
|
14
|
+
const paginate_service_1 = require("./paginate.service");
|
|
15
|
+
let PaginationModule = PaginationModule_1 = class PaginationModule {
|
|
16
|
+
static forRoot(options) {
|
|
17
|
+
return {
|
|
18
|
+
module: PaginationModule_1,
|
|
19
|
+
global: true,
|
|
20
|
+
providers: [
|
|
21
|
+
{
|
|
22
|
+
provide: pagination_constants_1.PAGINATION_MODULE_OPTIONS,
|
|
23
|
+
useValue: options ?? {},
|
|
24
|
+
},
|
|
25
|
+
paginate_service_1.PaginateService,
|
|
26
|
+
core_1.Reflector,
|
|
27
|
+
],
|
|
28
|
+
exports: [pagination_constants_1.PAGINATION_MODULE_OPTIONS, paginate_service_1.PaginateService],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static forRootAsync(options) {
|
|
32
|
+
return {
|
|
33
|
+
module: PaginationModule_1,
|
|
34
|
+
global: true,
|
|
35
|
+
imports: options.imports ?? [],
|
|
36
|
+
providers: [
|
|
37
|
+
{
|
|
38
|
+
provide: pagination_constants_1.PAGINATION_MODULE_OPTIONS,
|
|
39
|
+
useFactory: options.useFactory,
|
|
40
|
+
inject: options.inject ?? [],
|
|
41
|
+
},
|
|
42
|
+
paginate_service_1.PaginateService,
|
|
43
|
+
core_1.Reflector,
|
|
44
|
+
],
|
|
45
|
+
exports: [pagination_constants_1.PAGINATION_MODULE_OPTIONS, paginate_service_1.PaginateService],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.PaginationModule = PaginationModule;
|
|
50
|
+
exports.PaginationModule = PaginationModule = PaginationModule_1 = __decorate([
|
|
51
|
+
(0, common_1.Module)({})
|
|
52
|
+
], PaginationModule);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePaginateQuery = parsePaginateQuery;
|
|
4
|
+
function parsePaginateQuery(request) {
|
|
5
|
+
const query = request.query || {};
|
|
6
|
+
const path = request.path || request.url || '/';
|
|
7
|
+
const result = { path };
|
|
8
|
+
if (query.page !== undefined) {
|
|
9
|
+
const page = parseInt(query.page, 10);
|
|
10
|
+
result.page = isNaN(page) || page < 1 ? 1 : page;
|
|
11
|
+
}
|
|
12
|
+
if (query.limit !== undefined) {
|
|
13
|
+
const limit = parseInt(query.limit, 10);
|
|
14
|
+
result.limit = isNaN(limit) || limit < 1 ? 1 : limit;
|
|
15
|
+
}
|
|
16
|
+
if (query.sortBy !== undefined) {
|
|
17
|
+
const sortValues = Array.isArray(query.sortBy) ? query.sortBy : [query.sortBy];
|
|
18
|
+
result.sortBy = sortValues.map((s) => {
|
|
19
|
+
const [column, order = 'ASC'] = s.split(':');
|
|
20
|
+
return [column, order.toUpperCase()];
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (query.search !== undefined) {
|
|
24
|
+
result.search = query.search;
|
|
25
|
+
}
|
|
26
|
+
const filterEntries = [];
|
|
27
|
+
for (const key of Object.keys(query)) {
|
|
28
|
+
if (key.startsWith('filter.')) {
|
|
29
|
+
const column = key.substring('filter.'.length);
|
|
30
|
+
filterEntries.push([column, query[key]]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (filterEntries.length > 0) {
|
|
34
|
+
result.filter = Object.fromEntries(filterEntries);
|
|
35
|
+
}
|
|
36
|
+
if (query.after !== undefined) {
|
|
37
|
+
result.after = query.after;
|
|
38
|
+
}
|
|
39
|
+
if (query.before !== undefined) {
|
|
40
|
+
result.before = query.before;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestPaginationModule = exports.createPaginateQuery = void 0;
|
|
4
|
+
var create_paginate_query_1 = require("./create-paginate-query");
|
|
5
|
+
Object.defineProperty(exports, "createPaginateQuery", { enumerable: true, get: function () { return create_paginate_query_1.createPaginateQuery; } });
|
|
6
|
+
var test_pagination_module_1 = require("./test-pagination.module");
|
|
7
|
+
Object.defineProperty(exports, "TestPaginationModule", { enumerable: true, get: function () { return test_pagination_module_1.TestPaginationModule; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
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 TestPaginationModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TestPaginationModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const pagination_constants_1 = require("../pagination.constants");
|
|
13
|
+
let TestPaginationModule = TestPaginationModule_1 = class TestPaginationModule {
|
|
14
|
+
static register(options) {
|
|
15
|
+
return {
|
|
16
|
+
module: TestPaginationModule_1,
|
|
17
|
+
providers: [
|
|
18
|
+
{
|
|
19
|
+
provide: pagination_constants_1.PAGINATION_MODULE_OPTIONS,
|
|
20
|
+
useValue: options ?? {},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
exports: [pagination_constants_1.PAGINATION_MODULE_OPTIONS],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.TestPaginationModule = TestPaginationModule;
|
|
28
|
+
exports.TestPaginationModule = TestPaginationModule = TestPaginationModule_1 = __decorate([
|
|
29
|
+
(0, common_1.Module)({})
|
|
30
|
+
], TestPaginationModule);
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestarc/pagination",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Prisma cursor & offset pagination for NestJS with filtering, sorting, search, and Swagger auto-documentation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./testing": {
|
|
13
|
+
"types": "./dist/testing/index.d.ts",
|
|
14
|
+
"default": "./dist/testing/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"test": "jest",
|
|
23
|
+
"test:cov": "jest --coverage"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
27
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
28
|
+
"@prisma/client": "^5.0.0 || ^6.0.0",
|
|
29
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
30
|
+
"rxjs": "^7.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"@nestjs/swagger": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@nestjs/common": "^11.0.0",
|
|
39
|
+
"@nestjs/core": "^11.0.0",
|
|
40
|
+
"@nestjs/swagger": "^11.0.0",
|
|
41
|
+
"@nestjs/testing": "^11.0.0",
|
|
42
|
+
"@prisma/client": "^6.0.0",
|
|
43
|
+
"@types/jest": "^29.5.0",
|
|
44
|
+
"@types/node": "^22.0.0",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"reflect-metadata": "^0.2.0",
|
|
47
|
+
"rxjs": "^7.8.0",
|
|
48
|
+
"ts-jest": "^29.2.0",
|
|
49
|
+
"ts-node": "^10.9.2",
|
|
50
|
+
"typescript": "^5.7.0"
|
|
51
|
+
},
|
|
52
|
+
"license": "MIT"
|
|
53
|
+
}
|