Gathering detailed insights and metrics for @pwease/nestjs-paginate
Gathering detailed insights and metrics for @pwease/nestjs-paginate
Gathering detailed insights and metrics for @pwease/nestjs-paginate
Gathering detailed insights and metrics for @pwease/nestjs-paginate
Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework :book::paperclip:📎
npm install @pwease/nestjs-paginate
Typescript
Module System
Node Version
NPM Version
TypeScript (99.93%)
Shell (0.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
530 Stars
908 Commits
116 Forks
7 Watchers
16 Branches
42 Contributors
Updated on Jul 11, 2025
Latest Version
0.1.3
Package Id
@pwease/nestjs-paginate@0.1.3
Unpacked Size
323.41 kB
Size
79.44 kB
File Count
34
NPM Version
8.11.0
Node Version
16.15.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework.
$eq
, $not
, $null
, $in
, $gt
, $gte
, $lt
, $lte
, $btw
, $ilike
)npm install nestjs-paginate
The following code exposes a route that can be utilized like so:
1http://localhost:3000/cats?limit=5&page=2&sortBy=color:DESC&search=i&filter.age=$gte:3
1{ 2 "data": [ 3 { 4 "id": 4, 5 "name": "George", 6 "color": "white", 7 "age": 3 8 }, 9 { 10 "id": 5, 11 "name": "Leche", 12 "color": "white", 13 "age": 6 14 }, 15 { 16 "id": 2, 17 "name": "Garfield", 18 "color": "ginger", 19 "age": 4 20 }, 21 { 22 "id": 1, 23 "name": "Milo", 24 "color": "brown", 25 "age": 5 26 }, 27 { 28 "id": 3, 29 "name": "Kitty", 30 "color": "black", 31 "age": 3 32 } 33 ], 34 "meta": { 35 "itemsPerPage": 5, 36 "totalItems": 12, 37 "currentPage": 2, 38 "totalPages": 3, 39 "sortBy": [["color", "DESC"]], 40 "search": "i", 41 "filter": { 42 "age": "$gte:3" 43 } 44 }, 45 "links": { 46 "first": "http://localhost:3000/cats?limit=5&page=1&sortBy=color:DESC&search=i&filter.age=$gte:3", 47 "previous": "http://localhost:3000/cats?limit=5&page=1&sortBy=color:DESC&search=i&filter.age=$gte:3", 48 "current": "http://localhost:3000/cats?limit=5&page=2&sortBy=color:DESC&search=i&filter.age=$gte:3", 49 "next": "http://localhost:3000/cats?limit=5&page=3&sortBy=color:DESC&search=i&filter.age=$gte:3", 50 "last": "http://localhost:3000/cats?limit=5&page=3&sortBy=color:DESC&search=i&filter.age=$gte:3" 51 } 52}
Array values for filter operators such as $in
should be provided as comma-separated values:
http://localhost:3000/cats?filter.name=$in:George,Milo
1import { Controller, Injectable, Get } from '@nestjs/common' 2import { InjectRepository } from '@nestjs/typeorm' 3import { FilterOperator, Paginate, PaginateQuery, paginate, Paginated } from 'nestjs-paginate' 4import { Repository, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' 5 6@Entity() 7export class CatEntity { 8 @PrimaryGeneratedColumn() 9 id: number 10 11 @Column('text') 12 name: string 13 14 @Column('text') 15 color: string 16 17 @Column('int') 18 age: number 19} 20 21@Injectable() 22export class CatsService { 23 constructor( 24 @InjectRepository(CatEntity) 25 private readonly catsRepository: Repository<CatEntity> 26 ) {} 27 28 public findAll(query: PaginateQuery): Promise<Paginated<CatEntity>> { 29 return paginate(query, this.catsRepository, { 30 sortableColumns: ['id', 'name', 'color', 'age'], 31 nullSort: 'last', 32 searchableColumns: ['name', 'color', 'age'], 33 defaultSortBy: [['id', 'DESC']], 34 filterableColumns: { 35 age: [FilterOperator.GTE, FilterOperator.LTE], 36 }, 37 }) 38 } 39} 40 41@Controller('cats') 42export class CatsController { 43 constructor(private readonly catsService: CatsService) {} 44 45 @Get() 46 public findAll(@Paginate() query: PaginateQuery): Promise<Paginated<CatEntity>> { 47 return this.catsService.findAll(query) 48 } 49}
1const paginateConfig: PaginateConfig<CatEntity> { 2 /** 3 * Required: true (must have a minimum of one column) 4 * Type: (keyof CatEntity)[] 5 * Description: These are the columns that are valid to be sorted by. 6 */ 7 sortableColumns: ['id', 'name', 'color'], 8 9 /** 10 * Required: false 11 * Type: 'first' | 'last' 12 * Default: 'first' 13 * Description: (ONLY WORKS WITH POSTGRES) Define whether to put null values 14 * at the beginning or end of the result set. 15 */ 16 nullSort: 'last', 17 18 /** 19 * Required: false 20 * Type: [keyof CatEntity, 'ASC' | 'DESC'][] 21 * Default: [[sortableColumns[0], 'ASC]] 22 * Description: The order to display the sorted entities. 23 */ 24 defaultSortBy: [['name', 'DESC']], 25 26 /** 27 * Required: false 28 * Type: (keyof CatEntity)[] 29 * Description: These columns will be searched through when using the search query 30 * param. Limit search scope further by using `searchBy` query param. 31 */ 32 searchableColumns: ['name', 'color'], 33 34 /** 35 * Required: false 36 * Type: TypeORM partial selection 37 * Default: None 38 * https://typeorm.io/select-query-builder#partial-selection 39 */ 40 select: ['name', 'color'], 41 42 /** 43 * Required: false 44 * Type: number 45 * Default: 100 46 * Description: The maximum amount of entities to return per page. 47 */ 48 maxLimit: 20, 49 50 /** 51 * Required: false 52 * Type: number 53 * Default: 20 54 */ 55 defaultLimit: 50, 56 57 /** 58 * Required: false 59 * Type: TypeORM find options 60 * Default: None 61 * https://typeorm.io/#/find-optionsfind-options.md 62 */ 63 where: { color: 'ginger' }, 64 65 /** 66 * Required: false 67 * Type: { [key in CatEntity]?: FilterOperator[] } - Operators based on TypeORM find operators 68 * Default: None 69 * https://typeorm.io/#/find-options/advanced-options 70 */ 71 filterableColumns: { age: [FilterOperator.EQ, FilterOperator.IN] }, 72 73 /** 74 * Required: false 75 * Type: RelationColumn<CatEntity> 76 * Description: Indicates what relations of entity should be loaded. 77 */ 78 relations: [], 79 80 /** 81 * Required: false 82 * Type: boolean 83 * Description: Disables the global condition of "non-deleted" for the entity with delete date columns. 84 * https://typeorm.io/select-query-builder#querying-deleted-rows 85 */ 86 withDeleted: false, 87 88 /** 89 * Required: false 90 * Type: boolean 91 * Default: false 92 * Description: Generate relative paths in the resource links. 93 */ 94 relativePath: true, 95 96 /** 97 * Required: false 98 * Type: string 99 * Description: Overrides the origin of absolute resource links if set. 100 */ 101 origin: 'http://cats.example', 102}
You can paginate custom queries by passing on the query builder:
1const queryBuilder = repo 2 .createQueryBuilder('cats') 3 .leftJoinAndSelect('cats.owner', 'owner') 4 .where('cats.owner = :ownerId', { ownerId }) 5 6const result = await paginate<CatEntity>(query, queryBuilder, config)
Similar as with repositories, you can utilize relations
as a simplified left-join form:
1http://localhost:3000/cats?filter.toys.name=$in:Mouse,String
1const config: PaginateConfig<CatEntity> = { 2 relations: ['toys'], 3 sortableColumns: ['id', 'name', 'toys.name'], 4 filterableColumns: { 5 'toys.name': [FilterOperator.IN], 6 }, 7} 8 9const result = await paginate<CatEntity>(query, catRepo, config)
The package does not report error reasons in the response bodies. They are instead
reported as debug
level logging.
Common errors include missing sortableColumns
or filterableColumns
(the latter only affects filtering).
No vulnerabilities found.
Reason
7 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 13/14 approved changesets -- score normalized to 9
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More