Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@nodeteam/nestjs-prisma-pagination
Advanced tools
npm install --save @nodeteam/nestjs-prisma-pagination
// import paginators
import { paginator, searchPaginator } from '@nodeteam/nestjs-prisma-pagination';
// import types
import { PaginatorTypes } from '@nodeteam/nestjs-prisma-pagination';
page
- number of page
perPage
- number of records per page
Options can be redefined
{
data: T[],
meta: {
total: number,
lastPage: number,
currentPage: number,
perPage: number,
prev: number | null,
next: number | null,
},
}
Create new paginator function with default options
const paginate: PaginatorTypes.PaginateFunction = paginator({
page: 1,
perPage: 10,
});
full example:
import PrismaService from '@providers/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { PaginatorTypes, paginator } from '@nodeteam/nestjs-prisma-pagination';
const paginate: PaginatorTypes.PaginateFunction = paginator({ perPage: 10 });
@Injectable()
export default class UserService {
constructor(private prisma: PrismaService) {}
async findMany({ where, orderBy, pagination }: {
where?: Prisma.UserWhereInput,
orderBy?: Prisma.UserOrderByWithRelationInput
page?: number,
perPage?: number,
}): Promise<PaginatorTypes.PaginatedResult<User>> {
return paginate(
this.prisma.user,
{
where,
orderBy,
},
{
page,
perPage,
},
);
}
}
paginate(
this.prisma.user,
{
where,
orderBy,
},
{
page: 2, // Rendefine page
perPage: 5, // Rendefine perPage
},
);
https://exmaple.com/api/v1/user?page=1&where=Jake
page
- number of page
perPage
- number of records per page
skip
- number of records to skip
searchColumns
- array of columns in db
searchValue
- string to search
Options can be redefined
model
- PrismaClient['modelName']
modelName
- Name of model
create new search paginator function with default options
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({
page: 1,
perPage: 10,
});
full example:
import PrismaService from '@providers/prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import { PaginatorTypes, searchPaginator } from '@nodeteam/nestjs-prisma-pagination';
const searchPaginate: PaginatorTypes.SearchPaginateFunction = searchPaginator({ perPage: 10 });
@Injectable()
export default class UserService {
constructor(private prisma: PrismaService) {}
async searchUser({
page,
perPage,
skip,
searchValue
}: {
page: number,
perPage: number,
skip: number,
searchValue?: string,
}): Promise<PaginatorTypes.PaginatedResult<User>> {
const searchColumns = ['firstName', 'lastName', 'description'];
return searchPaginate(
this.prisma,
'User',
{
page,
perPage,
skip,
searchValue,
searchColumns,
},
);
}
}
searchPaginate(
this.prisma,
'User',
{
page: 2, // Rendefine page
perPage: 5, // Rendefine perPage
skip,
searchValue,
searchColumns,
},
);
https://example.com/api/v1/users/full-text/search?search=Lions&page=1
getPagination
options:rawPage
- number of page (optional)
rawPerPage
- number of records per page (optional)
const result = getPagination(1, 10);
result => {
perPage: 10,
page: 1,
skip: 0,
};
getPaginatedResult
options:data
- array of entities
pagination
- page, perPage, skip
count
- total count
const result = getPaginatedResult({
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
pagination: {
page: 1,
perPage: 10,
skip: 0,
},
count: 100,
});
result => {
data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
meta: {
total: 100,
lastPage: 10,
currentPage: 1,
perPage: 10,
prev: 0,
next: 1,
},
};
Check useful npm packages from NodeTeam: https://www.npmjs.com/org/nodeteam
FAQs
Paginators for Nest.JS app
We found that @nodeteam/nestjs-prisma-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.