@x-spacy/pagination 1.0.7 → 1.0.8

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 CHANGED
@@ -138,7 +138,7 @@ The paginated response follows this format:
138
138
  {
139
139
  "url": null,
140
140
  "label": "« Previous",
141
- "type": "PREV",
141
+ "type": "PREVIOUS",
142
142
  "active": false
143
143
  },
144
144
  {
@@ -203,7 +203,7 @@ Enum that defines the types of navigation links:
203
203
  enum PaginationLinkType {
204
204
  FIRST = 'FIRST',
205
205
  LAST = 'LAST',
206
- PREV = 'PREV',
206
+ PREV = 'PREVIOUS',
207
207
  NEXT = 'NEXT',
208
208
  PAGE = 'PAGE'
209
209
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-spacy/pagination",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A pagination library for NestJS",
5
5
  "license": "X SPACY LICENSE AGREEMENT",
6
6
  "private": false,
package/tsconfig.json CHANGED
@@ -2,13 +2,16 @@
2
2
  "compilerOptions": {
3
3
  "target": "es2024",
4
4
  "module": "commonjs",
5
+ "rootDir": ".",
5
6
  "outDir": "dist",
7
+ "declarationDir": "@types",
6
8
  "paths": {
7
9
  "@x-spacy/pagination/*": [
8
10
  "./src/*"
9
11
  ]
10
12
  },
11
13
  "strict": true,
14
+ "declaration": true,
12
15
  "skipLibCheck": true,
13
16
  "removeComments": true,
14
17
  "esModuleInterop": true,
package/@types/index.d.ts DELETED
@@ -1,18 +0,0 @@
1
- declare module '@x-spacy/pagination' {
2
- import { Page } from '@x-spacy/pagination/schemas/Page';
3
- import { PaginatedResponse } from '@x-spacy/pagination/schemas/Paginate';
4
-
5
- export enum PaginationLinkType {
6
- FIRST = 'FIRST',
7
- LAST = 'LAST',
8
- PREVIOUS = 'PREVIOUS',
9
- NEXT = 'NEXT',
10
- PAGE = 'PAGE'
11
- }
12
-
13
- export declare class PaginateInterceptor<T> implements NestInterceptor {
14
- intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<PaginatedResponse<T>>>;
15
- }
16
-
17
- export function paginate<T>(items: Array<T>, total: number): Page<T>;
18
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PaginationLinkType = void 0;
4
- var PaginationLinkType;
5
- (function (PaginationLinkType) {
6
- PaginationLinkType["FIRST"] = "FIRST";
7
- PaginationLinkType["LAST"] = "LAST";
8
- PaginationLinkType["PREVIOUS"] = "PREVIOUS";
9
- PaginationLinkType["NEXT"] = "NEXT";
10
- PaginationLinkType["PAGE"] = "PAGE";
11
- })(PaginationLinkType || (exports.PaginationLinkType = PaginationLinkType = {}));
package/dist/index.js DELETED
@@ -1,22 +0,0 @@
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("./interceptors/PaginationInterceptor"), exports);
18
- __exportStar(require("./operators/paginate"), exports);
19
- __exportStar(require("./schemas/Page"), exports);
20
- __exportStar(require("./schemas/PaginatedResponse"), exports);
21
- __exportStar(require("./schemas/PaginationLink"), exports);
22
- __exportStar(require("./schemas/PaginationMeta"), exports);
@@ -1,52 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.PaginateInterceptor = void 0;
10
- const common_1 = require("@nestjs/common");
11
- const operators_1 = require("rxjs/operators");
12
- const Page_1 = require("../schemas/Page");
13
- const PaginatedResponse_1 = require("../schemas/PaginatedResponse");
14
- const PaginationLink_1 = require("../schemas/PaginationLink");
15
- const PaginationMeta_1 = require("../schemas/PaginationMeta");
16
- const PaginationLinkType_1 = require("../enums/PaginationLinkType");
17
- let PaginateInterceptor = class PaginateInterceptor {
18
- intercept(context, next) {
19
- const request = context.switchToHttp().getRequest();
20
- const page = Math.max(1, parseInt(request.query.page, 10) ?? 1);
21
- const perPage = Math.min(100, Math.max(1, parseInt(request.query.perPage, 10) ?? 10));
22
- const path = `${request.protocol}://${request.get('host') + request.path}`;
23
- return next.handle().pipe((0, operators_1.map)((data) => {
24
- if (!(data instanceof Page_1.Page)) {
25
- return data;
26
- }
27
- const { total, items } = data;
28
- const lastPage = Math.max(1, Math.ceil(total / perPage));
29
- const currentPage = Math.min(page, lastPage);
30
- const startIndex = (currentPage - 1) * perPage;
31
- const endIndex = Math.min(startIndex + perPage, total);
32
- const from = total > 0 ? startIndex + 1 : 0;
33
- const to = endIndex;
34
- const buildUrl = (pageNumber) => `${path}?page=${pageNumber}&perPage=${perPage}`;
35
- const links = this.buildLinks(currentPage, lastPage, buildUrl);
36
- return new PaginatedResponse_1.PaginatedResponse(items, new PaginationMeta_1.PaginationMeta(from, to, currentPage, lastPage, perPage, total), path, buildUrl(1), currentPage > 1 ? buildUrl(currentPage - 1) : null, currentPage < lastPage ? buildUrl(currentPage + 1) : null, buildUrl(lastPage), links);
37
- }));
38
- }
39
- buildLinks(currentPage, lastPage, buildUrl) {
40
- const links = new Array();
41
- links.push(new PaginationLink_1.PaginationLink(currentPage > 1 ? buildUrl(currentPage - 1) : null, '&laquo; Anterior', PaginationLinkType_1.PaginationLinkType.PREVIOUS, false));
42
- for (let i = 1; i <= lastPage; i++) {
43
- links.push(new PaginationLink_1.PaginationLink(buildUrl(i), String(i), PaginationLinkType_1.PaginationLinkType.PAGE, i === currentPage));
44
- }
45
- links.push(new PaginationLink_1.PaginationLink(currentPage < lastPage ? buildUrl(currentPage + 1) : null, 'Próximo &raquo;', PaginationLinkType_1.PaginationLinkType.NEXT, false));
46
- return links;
47
- }
48
- };
49
- exports.PaginateInterceptor = PaginateInterceptor;
50
- exports.PaginateInterceptor = PaginateInterceptor = __decorate([
51
- (0, common_1.Injectable)()
52
- ], PaginateInterceptor);
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.paginate = paginate;
4
- const Page_1 = require("../schemas/Page");
5
- function paginate(items, total) {
6
- return new Page_1.Page(items, total);
7
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Page = void 0;
4
- class Page {
5
- items;
6
- total;
7
- constructor(items, total) {
8
- this.items = items;
9
- this.total = total;
10
- }
11
- }
12
- exports.Page = Page;
@@ -1,67 +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.PaginatedResponse = void 0;
13
- const class_transformer_1 = require("class-transformer");
14
- const PaginationMeta_1 = require("./PaginationMeta");
15
- class PaginatedResponse {
16
- items;
17
- meta;
18
- path;
19
- firstPageURL;
20
- previousPageURL;
21
- nextPageURL;
22
- lastPageURL;
23
- links;
24
- constructor(items, meta, path, firstPageURL, previousPageURL, nextPageURL, lastPageURL, links) {
25
- this.items = items;
26
- this.meta = meta;
27
- this.path = path;
28
- this.firstPageURL = firstPageURL;
29
- this.previousPageURL = previousPageURL;
30
- this.nextPageURL = nextPageURL;
31
- this.lastPageURL = lastPageURL;
32
- this.links = links;
33
- }
34
- }
35
- exports.PaginatedResponse = PaginatedResponse;
36
- __decorate([
37
- (0, class_transformer_1.Expose)({ name: 'items' }),
38
- __metadata("design:type", Array)
39
- ], PaginatedResponse.prototype, "items", void 0);
40
- __decorate([
41
- (0, class_transformer_1.Expose)({ name: 'meta' }),
42
- __metadata("design:type", PaginationMeta_1.PaginationMeta)
43
- ], PaginatedResponse.prototype, "meta", void 0);
44
- __decorate([
45
- (0, class_transformer_1.Expose)({ name: 'path' }),
46
- __metadata("design:type", String)
47
- ], PaginatedResponse.prototype, "path", void 0);
48
- __decorate([
49
- (0, class_transformer_1.Expose)({ name: 'first_page_url' }),
50
- __metadata("design:type", String)
51
- ], PaginatedResponse.prototype, "firstPageURL", void 0);
52
- __decorate([
53
- (0, class_transformer_1.Expose)({ name: 'previous_page_url' }),
54
- __metadata("design:type", Object)
55
- ], PaginatedResponse.prototype, "previousPageURL", void 0);
56
- __decorate([
57
- (0, class_transformer_1.Expose)({ name: 'next_page_url' }),
58
- __metadata("design:type", Object)
59
- ], PaginatedResponse.prototype, "nextPageURL", void 0);
60
- __decorate([
61
- (0, class_transformer_1.Expose)({ name: 'last_page_url' }),
62
- __metadata("design:type", String)
63
- ], PaginatedResponse.prototype, "lastPageURL", void 0);
64
- __decorate([
65
- (0, class_transformer_1.Expose)({ name: 'links' }),
66
- __metadata("design:type", Array)
67
- ], PaginatedResponse.prototype, "links", void 0);
@@ -1,43 +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.PaginationLink = void 0;
13
- const class_transformer_1 = require("class-transformer");
14
- const PaginationLinkType_1 = require("../enums/PaginationLinkType");
15
- class PaginationLink {
16
- url;
17
- label;
18
- type;
19
- active;
20
- constructor(url, label, type, active) {
21
- this.url = url;
22
- this.label = label;
23
- this.type = type;
24
- this.active = active;
25
- }
26
- }
27
- exports.PaginationLink = PaginationLink;
28
- __decorate([
29
- (0, class_transformer_1.Expose)({ name: 'url' }),
30
- __metadata("design:type", Object)
31
- ], PaginationLink.prototype, "url", void 0);
32
- __decorate([
33
- (0, class_transformer_1.Expose)({ name: 'label' }),
34
- __metadata("design:type", String)
35
- ], PaginationLink.prototype, "label", void 0);
36
- __decorate([
37
- (0, class_transformer_1.Expose)({ name: 'type' }),
38
- __metadata("design:type", String)
39
- ], PaginationLink.prototype, "type", void 0);
40
- __decorate([
41
- (0, class_transformer_1.Expose)({ name: 'active' }),
42
- __metadata("design:type", Boolean)
43
- ], PaginationLink.prototype, "active", void 0);
@@ -1,54 +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.PaginationMeta = void 0;
13
- const class_transformer_1 = require("class-transformer");
14
- class PaginationMeta {
15
- from;
16
- to;
17
- currentPage;
18
- lastPage;
19
- perPage;
20
- total;
21
- constructor(from, to, currentPage, lastPage, perPage, total) {
22
- this.from = from;
23
- this.to = to;
24
- this.currentPage = currentPage;
25
- this.lastPage = lastPage;
26
- this.perPage = perPage;
27
- this.total = total;
28
- }
29
- }
30
- exports.PaginationMeta = PaginationMeta;
31
- __decorate([
32
- (0, class_transformer_1.Expose)({ name: 'from' }),
33
- __metadata("design:type", Number)
34
- ], PaginationMeta.prototype, "from", void 0);
35
- __decorate([
36
- (0, class_transformer_1.Expose)({ name: 'to' }),
37
- __metadata("design:type", Number)
38
- ], PaginationMeta.prototype, "to", void 0);
39
- __decorate([
40
- (0, class_transformer_1.Expose)({ name: 'current_page' }),
41
- __metadata("design:type", Number)
42
- ], PaginationMeta.prototype, "currentPage", void 0);
43
- __decorate([
44
- (0, class_transformer_1.Expose)({ name: 'last_page' }),
45
- __metadata("design:type", Number)
46
- ], PaginationMeta.prototype, "lastPage", void 0);
47
- __decorate([
48
- (0, class_transformer_1.Expose)({ name: 'per_page' }),
49
- __metadata("design:type", Number)
50
- ], PaginationMeta.prototype, "perPage", void 0);
51
- __decorate([
52
- (0, class_transformer_1.Expose)({ name: 'total' }),
53
- __metadata("design:type", Number)
54
- ], PaginationMeta.prototype, "total", void 0);