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.
prisma-pagination
Advanced tools
Helper library for [Prisma](https://www.prisma.io/docs/concepts/components/prisma-client/pagination) offset pagination with Typescript support.
Helper library for Prisma offset pagination with Typescript support.
npm i prisma-pagination
import { createPaginator } from 'prisma-pagination'
import { User, Prisma } from '@prisma/client'
// ...
app.get('/', async ({ prisma }, res) => {
const paginate = createPaginator({ page: 2 })
// You can pass generic types: <Model> and <Model>FindManyArgs
// to have args and result typed
const result = await paginate<User, Prisma.UserFindManyArgs>(
prisma.user,
{
where: {
name: {
contains: 'Alice'
}
}
orderBy: {
id: 'desc',
}
}
})
/* Result structure:
{
data: User[]
meta: {
total: number
lastPage: number
currentPage: number
perPage: number
prev: number | null
next: number | null
}
}
*/
})
If you use Express-like framework, initializing createPaginator
could be moved to the middleware:
import { createPaginator } from 'prisma-pagination'
const pagination = (req, res, next) => {
const page = Number(req.query.page) || 1
req.paginate = createPaginator({ page, perPage: 20 })
next()
}
app.use(pagination)
so then it can be used in any route handler:
app.get('/', async ({ paginate, prisma }, res) => {
return await paginate(prisma.user)
})
To have proper Typescript support you can extend Request interface like so:
import { PaginateFunction } from 'prisma-pagination'
declare global {
namespace Express {
export interface Request {
paginate: PaginateFunction
}
}
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
FAQs
Helper library for [Prisma](https://www.prisma.io/docs/concepts/components/prisma-client/pagination) offset pagination with Typescript support.
The npm package prisma-pagination receives a total of 1,567 weekly downloads. As such, prisma-pagination popularity was classified as popular.
We found that 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.