npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@generazioneai/paginator

v0.1.0

Published

Efficient, framework-agnostic Prisma paginator — offset + cursor pagination, optional COUNT, stable tie-breaker ordering, optional class-transformer mapping.

Readme

@generazioneai/paginator

Efficient, framework-agnostic Prisma paginator: offset + cursor pagination, an optional COUNT query, stable tie-breaker ordering, and optional class-transformer mapping. No NestJS, no project coupling. Works directly on an authz-scoped delegate, so pagination respects row-level scoping for free.

Install

npm i @generazioneai/paginator
# optional peers (only if you use them):
npm i @prisma/client class-transformer

Quick start

import { paginate } from "@generazioneai/paginator";

const res = await paginate(prisma.user, { where: { active: true }, orderBy: { name: "asc" } }, {
  page,
  perPage,
  orderByTieBreaker: "id",   // deterministic ordering across pages
});
// res = { data, meta: { total, lastPage, currentPage, perPage, prev, next, hasPrev, hasNext } }

Skip the COUNT on large tables

COUNT is the expensive part. When the frontend only needs next/prev (infinite scroll), set withTotal: false — the paginator fetches perPage + 1 rows to derive hasNext and issues no COUNT query. total/lastPage are then omitted.

const res = await paginate(prisma.event, { where }, { page, perPage, withTotal: false });
// res.meta = { currentPage, perPage, prev, next, hasPrev, hasNext }  (no total/lastPage)

Cursor pagination (O(1) deep pages)

No growing OFFSET, no COUNT — the efficient choice for large datasets / infinite scroll.

let res = await paginateCursor(prisma.post, { where }, { perPage: 20 });
// next page:
res = await paginateCursor(prisma.post, { where }, { perPage: 20, cursor: res.meta.nextCursor });
// res.meta = { perPage, nextCursor, prevCursor, hasNext, hasPrev }

cursorField (default "id") must be unique & sequential; it is appended to your orderBy so ordering is deterministic.

Mapping rows

Two ways, both optional:

// class-transformer entity (requires the optional peer):
await paginate(prisma.user, args, { page, perPage, type: UserEntity });
// → plainToInstance(UserEntity, rows, {excludeExtraneousValues, enableImplicitConversion})
//   then instanceToPlain(..., {exposeUnsetFields:true})

// or a custom mapper (takes precedence, no peer needed):
await paginate(prisma.user, args, { page, perPage, transform: (rows) => rows.map(toDto) });

API

| Export | Purpose | |---|---| | paginate(model, args, options) | Offset pagination → PaginatedResult<T> | | paginator(options)(model, args) | Legacy-compatible factory (drop-in for the old util) | | paginateCursor(model, args, options) | Cursor pagination → CursorPaginatedResult<T> | | getPagination(page, perPage) | { page, perPage, skip } helper | | getPaginatedResult({ data, pagination, count }) | Paginate an in-memory array | | buildMeta({ page, perPage, total?, hasNext? }) | Build meta directly | | transformWithClass(cls, rows) | The class-transformer mapping, standalone | | PaginatorTypes | Back-compat type namespace |

model contract

Any object with count(args?) and findMany(args?) — i.e. a Prisma model delegate, including an authz-scoped one. The library never imports @prisma/client.

Options (offset)

| Option | Default | Notes | |---|---|---| | page | 0 | 0/undefined ⇒ return ALL rows (no pagination, no meta) | | perPage | 10 | | | withTotal | true | false ⇒ no COUNT query | | orderByTieBreaker | — | field name(s) appended asc for stable paging | | type | — | class-transformer target class | | transform | — | custom row mapper (wins over type) |

Migrating from the old utils/paginator

Change only the import — the paginator(...) factory, PaginatorTypes, getPagination, and getPaginatedResult keep the same shapes:

- import { paginator, PaginatorTypes } from "src/utilities/utils/paginator";
+ import { paginator, PaginatorTypes } from "@generazioneai/paginator";

License

MIT