{"_id":"@cgvweb/mongoose-cursor-pagination","_rev":"4-534cbe4c226205a4f0476e686a2b82af","name":"@cgvweb/mongoose-cursor-pagination","description":"A simple Mongoose plugin that allows defining cursor pagination for your Schemas.","dist-tags":{"latest":"1.2.1"},"versions":{"1.0.6":{"name":"@cgvweb/mongoose-cursor-pagination","version":"1.0.6","author":{"url":"https://chrisgvdev.com","name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com"},"license":"MIT","_id":"@cgvweb/mongoose-cursor-pagination@1.0.6","maintainers":[{"name":"cgvweb","email":"christian@chrisgvdev.com"}],"dist":{"shasum":"5fba7289b07fa22c6ce660b1978f59853bf04a6d","tarball":"https://registry.npmjs.org/@cgvweb/mongoose-cursor-pagination/-/mongoose-cursor-pagination-1.0.6.tgz","fileCount":8,"integrity":"sha512-nx9bhkwkRZMc1fyTKxuhgi1PVv3QxLqqGpwXaq6G2b+ccvLN1Q1F5mVtl15ZeWIHYgP8SeUV+O8ZzdxiCoUrOQ==","signatures":[{"sig":"MEUCIQCEqp3AIh8S3wn1IJyYSRGgs1a+7HHob+P56j7cmy3msAIgfgLGWox9rcZO+xBc+6JTZAeUHs/x5GNiMlX/95be1FM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14060},"main":"dist/index.js","_from":"file:cgvweb-mongoose-cursor-pagination-1.0.6.tgz","types":"dist/index.d.ts","module":"dist/index.mjs","scripts":{"lint":"tsc","build":"tsup src/*.ts --format cjs,esm --dts","release":"pnpm build && pnpm version patch && pnpm publish --access=public"},"_npmUser":{"name":"cgvweb","email":"christian@chrisgvdev.com"},"_resolved":"/private/var/folders/nc/zlv2phs53kl4s6f54h3kpvv40000gn/T/60c1e7a051659320350f3b58a03b6657/cgvweb-mongoose-cursor-pagination-1.0.6.tgz","_integrity":"sha512-nx9bhkwkRZMc1fyTKxuhgi1PVv3QxLqqGpwXaq6G2b+ccvLN1Q1F5mVtl15ZeWIHYgP8SeUV+O8ZzdxiCoUrOQ==","_npmVersion":"10.2.0","directories":{},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"devDependencies":{"zod":"^3.21.4","tsup":"^6.7.0","mongoose":"^7.0.3","typescript":"^5.0.4","@types/node":"^18.15.11","@changesets/cli":"^2.26.1"},"peerDependencies":{"zod":"^3","mongoose":"^7"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-cursor-pagination_1.0.6_1697500667015_0.7428318822873718","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@cgvweb/mongoose-cursor-pagination","version":"1.1.0","author":{"url":"https://cgvweb.com","name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com"},"license":"MIT","_id":"@cgvweb/mongoose-cursor-pagination@1.1.0","maintainers":[{"name":"cgvweb","email":"christian@chrisgvdev.com"}],"dist":{"shasum":"8900e1c3b8b58b59f10986bac81ac046c7f14a40","tarball":"https://registry.npmjs.org/@cgvweb/mongoose-cursor-pagination/-/mongoose-cursor-pagination-1.1.0.tgz","fileCount":14,"integrity":"sha512-BUtV20JM+bpHvgphmPqYpSzJYXurfj2ELokramnuMj9a45V/hmctJeLa0Yf8aQywkyeKNUlY3T4yt08urSnMlA==","signatures":[{"sig":"MEUCIQCI5gOgFYYvmHbnnPFM6UfTUudSePqL8t3NGuKrLUQwNQIgfbUkSFaqVylZOh/9ae0Gpu3lHJfZy6vzcGPgTwOSl0o=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":21480},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"9646b474d31967594a3a877d32c486a0e5cc8df1","scripts":{"lint":"tsc","build":"tsup src/*.ts --format cjs,esm --dts","release":"release-it && npm run build && npm publish"},"_npmUser":{"name":"cgvweb","email":"christian@chrisgvdev.com"},"repository":{"type":"git","directory":"https://github.com/ChrisGV04/mongoose-cursor-pagination"},"_npmVersion":"10.5.0","directories":{},"_nodeVersion":"18.17.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","tsup":"^8.0.2","mongoose":"^8.2.1","prettier":"^3.2.5","release-it":"^17.1.1","typescript":"^5.4.2","@types/node":"^20.11.25","changelogen":"^0.5.5","@changesets/cli":"^2.27.1","@release-it/conventional-changelog":"^8.0.1"},"peerDependencies":{"zod":"^3","mongoose":"^7 || ^8"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-cursor-pagination_1.1.0_1709755284362_0.8658604190391399","host":"s3://npm-registry-packages"}},"1.1.1":{"name":"@cgvweb/mongoose-cursor-pagination","version":"1.1.1","author":{"url":"https://cgvweb.com","name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com"},"license":"MIT","_id":"@cgvweb/mongoose-cursor-pagination@1.1.1","maintainers":[{"name":"cgvweb","email":"christian@chrisgvdev.com"}],"dist":{"shasum":"f911b9370f9f2f0896c41ef184bbad8dbbe085d1","tarball":"https://registry.npmjs.org/@cgvweb/mongoose-cursor-pagination/-/mongoose-cursor-pagination-1.1.1.tgz","fileCount":12,"integrity":"sha512-n9uXURAl9JfUUrtLY3cRTYW7HlVZI+0jNCa6Gtc5FbSIgi647rGD1r2pQHxtpt5DIAEUjSZOWb9vaBwlLLUxrQ==","signatures":[{"sig":"MEUCIE2SIzwFod/mTcKzS1AuB2pFhliMkzPp88j1gXS6xVyiAiEAyX++gdHZXykNkZ/T11W8uQicHQqJXsAum3DaOsFc9fQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17277},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"0b368344317741a7915a129d40b227e5e43d6531","scripts":{"lint":"tsc","build":"pnpx rimraf dist && tsup src/*.ts --format cjs,esm --dts --minify","release":"release-it && npm run build && npm publish"},"_npmUser":{"name":"cgvweb","email":"christian@chrisgvdev.com"},"repository":{"type":"git","directory":"https://github.com/ChrisGV04/mongoose-cursor-pagination"},"_npmVersion":"10.5.0","description":"A simple Mongoose plugin that allows defining cursor pagination for your Schemas.","directories":{},"_nodeVersion":"18.17.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"zod":"^3.22.4","tsup":"^8.0.2","mongoose":"^8.2.1","prettier":"^3.2.5","release-it":"^17.1.1","typescript":"^5.4.2","@types/node":"^20.11.25","changelogen":"^0.5.5","@changesets/cli":"^2.27.1","@release-it/conventional-changelog":"^8.0.1"},"peerDependencies":{"zod":"^3","mongoose":"^7 || ^8"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-cursor-pagination_1.1.1_1709759539095_0.1803813586282057","host":"s3://npm-registry-packages"}},"1.2.0":{"name":"@cgvweb/mongoose-cursor-pagination","version":"1.2.0","author":{"url":"https://cgvweb.com","name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com"},"license":"MIT","_id":"@cgvweb/mongoose-cursor-pagination@1.2.0","dist":{"shasum":"ce6a9c6ae55b1c9086c97cef69dc4e6fad86e2b1","tarball":"https://registry.npmjs.org/@cgvweb/mongoose-cursor-pagination/-/mongoose-cursor-pagination-1.2.0.tgz","fileCount":7,"integrity":"sha512-wC2GnJ8g8qxXycOOBIJht8G46y7K6NyT/1IkRf6vQLEAtNeDSIVmNo95FMp9h8iN41eqk4f8tmSIxSM90EIXBA==","signatures":[{"sig":"MEYCIQClHE/eonx4PsYSLob1+ck3pBqmyNBFdPMrMaVVv46nmAIhAPvKtTUVGvnY7m7xnCDqAkB081c6dnAUx6bj9sDi+zb8","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":25976},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","gitHead":"2060601d9bf8e17107248887db11418db6bbf51c","scripts":{"lint":"biome lint ./src","build":"rimraf dist && tsup src/*.ts --format cjs,esm --dts","release":"release-it && npm run build && npm publish"},"_npmUser":{"name":"cgvweb","email":"christian@chrisgvdev.com"},"repository":{"type":"git","directory":"https://github.com/ChrisGV04/mongoose-cursor-pagination"},"_npmVersion":"10.5.2","description":"A simple Mongoose plugin that allows defining cursor pagination for your Schemas.","directories":{},"_nodeVersion":"20.12.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"zod":"3.23.8","tsup":"8.1.0","rimraf":"5.0.7","mongoose":"8.4.4","prettier":"3.3.2","release-it":"17.4.0","typescript":"5.5.2","@types/node":"20.14.9","changelogen":"0.5.5","@biomejs/biome":"1.8.2","@changesets/cli":"2.27.6","@microsoft/api-extractor":"^7.47.0","@release-it/conventional-changelog":"8.0.1"},"peerDependencies":{"zod":"^3","mongoose":"^7 || ^8"},"_npmOperationalInternal":{"tmp":"tmp/mongoose-cursor-pagination_1.2.0_1719385488519_0.15472903952639006","host":"s3://npm-registry-packages"}},"1.2.1":{"name":"@cgvweb/mongoose-cursor-pagination","version":"1.2.1","license":"MIT","type":"module","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","repository":{"directory":"https://github.com/ChrisGV04/mongoose-cursor-pagination","type":"git"},"author":{"name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com","url":"https://cgvweb.com"},"publishConfig":{"access":"public"},"scripts":{"build":"rimraf dist && tsup src/*.ts --format cjs,esm --dts","lint":"biome lint ./src","release":"release-it && npm run build && npm publish"},"peerDependencies":{"mongoose":"^7 || ^8","zod":"^3"},"devDependencies":{"@biomejs/biome":"1.8.2","@changesets/cli":"2.27.6","@microsoft/api-extractor":"^7.47.0","@release-it/conventional-changelog":"8.0.1","@types/node":"20.14.9","changelogen":"0.5.5","mongoose":"8.4.4","prettier":"3.3.2","release-it":"17.4.0","rimraf":"5.0.7","tsup":"8.1.0","typescript":"5.5.2","zod":"3.23.8"},"_id":"@cgvweb/mongoose-cursor-pagination@1.2.1","gitHead":"bcaae8739f1ab4779767438269f08282852044bd","description":"A simple Mongoose plugin that allows defining cursor pagination for your Schemas.","_nodeVersion":"20.12.2","_npmVersion":"10.5.2","dist":{"integrity":"sha512-sR2o0N8IboTNb9UQxfbN8iRuQe74SIUWjmAJpnIpzsYMGNRL6XfJRIlDtc3iwSfcbDTOK0J2nR4J24BjApRPMA==","shasum":"ee2bb0a1f23e7dfe04b4e21c84e43429dcc96942","tarball":"https://registry.npmjs.org/@cgvweb/mongoose-cursor-pagination/-/mongoose-cursor-pagination-1.2.1.tgz","fileCount":7,"unpackedSize":26222,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHyKC9ojroeNAwh6wX75g9XxDtq7NfYZKegBHkEzNnL2AiB6DdMD/LKS/73Ty2wbNTmn+IGEys10tiUwfC0Ekt/iAw=="}]},"_npmUser":{"name":"cgvweb","email":"christian@chrisgvdev.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongoose-cursor-pagination_1.2.1_1719386741554_0.7582721047429188"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-16T23:57:46.883Z","modified":"2024-06-26T07:25:41.994Z","1.0.6":"2023-10-16T23:57:47.229Z","1.1.0":"2024-03-06T20:01:24.519Z","1.1.1":"2024-03-06T21:12:19.254Z","1.2.0":"2024-06-26T07:04:48.689Z","1.2.1":"2024-06-26T07:25:41.816Z"},"maintainers":[{"name":"cgvweb","email":"christian@chrisgvdev.com"}],"author":{"name":"Christian Gil Villaseñor","email":"christian@chrisgvdev.com","url":"https://cgvweb.com"},"repository":{"directory":"https://github.com/ChrisGV04/mongoose-cursor-pagination","type":"git"},"license":"MIT","readme":"# Mongoose Cursor Pagination\n\nA simple Mongoose plugin that allows defining cursor pagination for your Schemas.\n\nThis plugin is developed by [Christian Gil](https://cgvweb.com) mainly to be used on his own projects, since it provides common utilities used in many back-end projects.\n\n## Installation\n\n```bash\npnpm install @cgvweb/mongoose-cursor-pagination\n```\n\n> [!IMPORTANT]\n> This package requires `mongoose ^7 || ^8` and `zod ^3` to be installed as peer dependencies.\n\n## Usage\n\nTo use the cursor pagination functionality, you must install the plugin on your Schema and optionally add the type to the model:\n\n```ts\n// user.schema.ts\nimport { paginatePlugin, type PaginateFn } from '@cgvweb/mongoose-cursor-pagination';\nimport { Schema, model, type Model } from 'mongoose';\n\nexport interface UserFields {\n  id: string;\n  email: string;\n  name: string;\n}\n\n/** Adds the `paginate` method type to the User model */\nexport interface UserModel extends Model<UserFields> {\n  paginate: PaginateFn<UserFields>;\n}\n\nconst userSchema = new Schema<UserFields>({\n  name: { type: String, required: true },\n  email: { type: String, required: true, unique: true },\n});\n\n// Add the cursor pagination plugin\nuserSchema.plugin(paginatePlugin);\n\nexport const User = model<UserFields, UserModel>('user', userSchema);\n```\n\nNow you can use the `paginate` method on your schema to query the data using cursor pagination:\n\n```ts\nimport { User } from './user.schema.ts';\n\nasync function searchUsers() {\n  const result = await User.paginate({\n    pagination: { limit: 10, order: 'asc' },\n  });\n  return result;\n}\n```\n\n## Pagination Options\n\n| Option                  | Type                | Required | Description                                                                                                                      |\n| ----------------------- | ------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------- |\n| `pagination`            | `object`            | Yes      | The options for the paginated query.                                                                                             |\n| `pagination.limit`      | `number`            | Yes      | The maximum number of docs to fetch per page.                                                                                    |\n| `pagination.order`      | \"asc\" \\| \"desc\"     | Yes      | The sorting order of the cursor.                                                                                                 |\n| `pagination.prevCursor` | `string`            | No       | The cursor to fetch the previous page from.                                                                                      |\n| `pagination.nextCursor` | `string`            | No       | The cursor to fetch the next page from. If used with `prevCursor` it will be ignored.                                            |\n| `filters`               | `FilterQuery<T>`    | No       | Same filters you would pass to a regular Mongoose query.<br/><br/>For example: `{ filters: { status: \"active\" } }`               |\n| `queryOpts`             | `QueryOptions<T>`   | No       | The same query options you would pass to a regular Mongoose query.<br/><br/>For example: `{ queryOpts: { populate: \"author\" } }` |\n| `projection`            | `ProjectionType<T>` | No       | The same projection options you would pass to a regular Mongoose query.<br/><br/>For example: `{ projection: { email: false } }` |\n\n## Pagination Response\n\n| Field        | Type               | Description                                                                                                   |\n| ------------ | ------------------ | ------------------------------------------------------------------------------------------------------------- |\n| `data`       | `T[]`              | The subset of documents on the current page based on the limit, order and cursors provided.                   |\n| `totalCount` | `number`           | The total number of documents that match the query provided, including the ones on the current page.          |\n| `nextCursor` | `string` \\| `null` | The cursor you can use to fetch the next page of documents. If `null`, the current page is the last one.      |\n| `prevCursor` | `string` \\| `null` | The cursor you can use to fetch the previous page of documents. If `null`, the current page is the first one. |\n\n## Additional Exports\n\nTo make sure you can use the pagination functions with data validation, this plugin also exports a few Zod schemas and types:\n\n| Resource           | Type        | Description                                                                                                                                      |\n| ------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `Paginated<T>`     | `type`      | The type of the response from the `paginate` method. The `T` generic is used to type the `data` array.                                           |\n| `PaginateFn<T>`    | `type`      | The type used to add the `paginate` method to the Mongoose Schema. The `T` generic is used to add the document fields to the `paginate` options. |\n| `PaginationSchema` | `ZodObject` | A Zod schema you can use to validate the options passed to `pagination`.                                                                         |\n| `PaginationFields` | `type`      | The inferred type of `PaginationSchema`.                                                                                                         |\n| `SortOrderType`    | `type`      | `asc` \\| `desc`                                                                                                                                  |\n\n## License\n\n[MIT](./LICENSE) License © 2018-PRESENT [CGV WEB](https://github.com/ChrisGV04)\n","readmeFilename":"README.md"}