{"_id":"@ducnguyen96/sequelize-cursor-pagination","_rev":"2-5e913549042a5cff068c4d29727a2478","name":"@ducnguyen96/sequelize-cursor-pagination","dist-tags":{"latest":"2.3.2"},"versions":{"2.3.1":{"scripts":{"test":"jest","lint":"eslint src"},"name":"@ducnguyen96/sequelize-cursor-pagination","description":"Hot fix bugs for sequelize-cursor-pagination","version":"2.3.1","main":"./src/index.js","license":"MIT","keywords":["sequelize","pagination"],"author":{"name":"ducng948"},"devDependencies":{"babel-eslint":"^10.1.0","eslint":"^7.19.0","eslint-plugin-jest":"^24.1.3","jest":"^26.6.3","sequelize":"^6.5.0","sqlite3":"^5.0.1"},"gitHead":"71858fce2a33cb457590e112b3bd23e7796864e6","_id":"@ducnguyen96/sequelize-cursor-pagination@2.3.1","_nodeVersion":"16.13.0","_npmVersion":"8.3.0","dist":{"integrity":"sha512-PRyQhBlL4BUA6v483JzrzzNKicWqgsxipKkx2TBYNNlOxiJK2byh7cS2u6lRDK0ECYeSlxTFkRPooCIeAFHIyQ==","shasum":"2f8e98ddaefae3c3caba8757885afc0ad0a554a1","tarball":"https://registry.npmjs.org/@ducnguyen96/sequelize-cursor-pagination/-/sequelize-cursor-pagination-2.3.1.tgz","fileCount":10,"unpackedSize":16300,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiRBDgACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqnUQ/+IRUgBzib+ipx0K5WdZjibovPfeIDDDDsjBGYl1rxTv92RMj4\r\nbQuCvq7nr0Aoi5tarSM5yl24u824JgoUXcFoZykgnB5kl8lFTuYMt8l6aX83\r\nFsBbFo2qDDuT6xJ2pQy+2d+aWQUouTtj173jWzrIC+1RN+AXoAOblyeES1XP\r\nbT/A8WdeERPVREtJnwVBvJ6xP1Ma5EiDeez8AejSFm5owqdigDzkceqbwjrQ\r\n7VVVPr/feoV1jKfuTBifnkoX7w9IKn36ONmXuqwzJGzrkblOl1vbY2tC5zmt\r\nfibEDmOJ3sVswLO6DL1/AEGz7nBlTOj5tVA2LOhlXsyGpm1FXFDVbXh3W71J\r\n2tAeA7svJvEmYAnQrXtNZH16CSl3S3z8WH1ndnwRrjqVIaIdS+Z0WkzWdegK\r\nT0vclgusG8WRnpIvxyhA+p12oodmoigJtakg8dbaZJL82fOLpM78QxYIwrmN\r\nziFCrUdUwNNpGZ56PQnujmvcmY1DW3/A4SMl/nXf4JsSIZsS38v/VrYz5btd\r\nFwJGfTA7iOsuIVGETEmyTnr6sP71rIYBGdjAxcTrYOpKM9aeNc6wlXxiiohL\r\nQwAHw2CBRtdZunHybMIri48U9aT/Qfuo5zsT05jhmsSXntTl2JDRG8mqcsjB\r\n2PthQ+FMUWwTiqPHUmH7Czo8/k1zZJjGsxY=\r\n=8nge\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHIGpQH5xGtN33yj4G+L2hzFsx7Usoyd/I9/UeRMZKmAIhAMmVD7NIuUNEznJVPvXbJl9rwindHpWyXWp99NtUjIeo"}]},"_npmUser":{"name":"ducng948","email":"levinguyen.dl@gmail.com"},"directories":{},"maintainers":[{"name":"ducng948","email":"levinguyen.dl@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-cursor-pagination_2.3.1_1648627935958_0.5681804152627077"},"_hasShrinkwrap":false},"2.3.2":{"scripts":{"test":"jest","lint":"eslint src"},"name":"@ducnguyen96/sequelize-cursor-pagination","description":"Hot fix bugs for sequelize-cursor-pagination","version":"2.3.2","main":"./src/index.js","license":"MIT","keywords":["sequelize","pagination"],"author":{"name":"ducng948"},"devDependencies":{"babel-eslint":"^10.1.0","eslint":"^7.19.0","eslint-plugin-jest":"^24.1.3","jest":"^26.6.3","sequelize":"^6.5.0","sqlite3":"^5.0.1"},"gitHead":"71858fce2a33cb457590e112b3bd23e7796864e6","_id":"@ducnguyen96/sequelize-cursor-pagination@2.3.2","_nodeVersion":"16.13.0","_npmVersion":"8.3.0","dist":{"integrity":"sha512-mQxrezbdlgsW+P3Q8DEJbey9STdo66uAcqkLosuUNUt0iK4si5xLgYRo5PuVgKHRytK5Ut4PFNeVkVMjd5K6wA==","shasum":"b98c942bc3803a374187aaee6bd5651f82eab255","tarball":"https://registry.npmjs.org/@ducnguyen96/sequelize-cursor-pagination/-/sequelize-cursor-pagination-2.3.2.tgz","fileCount":10,"unpackedSize":16728,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiRBPRACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqtpw/9GauyN4cPaxMGiq9GkTeFOR6nT2ISOWgXsRUTPEUbYa4HiL7d\r\nTvR29uUHeDYt2SjJNI0ki1Tt4j3okQhqUTecO2x8suNoAWkJct+Znl0X6Zz4\r\nBpefLN8VpxOIuxawiDz8x8q36e1H16KHbVBl/dJZopf2FKvrEJn+PQ3PRLYF\r\nhZFoJvHt929Mh/Dw+ulptXq16naVJw5eCz2FYwL8t6KWt/V5p2wTj8vH8hsN\r\ngYEBV5xRTfrx9VKc3yhXfTLveqkXbC8qIzoOrkkMCMK7/pF6uG41ROJnoNH9\r\n1uXNFjFN9uKo02tUBYw5602OdQ06/Uh37Anbh0GMI1qtPFnjD1yGg4uh1F35\r\nM4ex4/EJl/tx17eXGzEZ1HCy/l/CV6rbWiFhkQunOzYnqNVyS7daOEMSzjiz\r\ngfGp+d32H3e4ur9iTUVrHejEU2BDUbi2l4OCbi8TVr2tvYeXe+SqUjO6UNMB\r\nhhl41lq1B86XgicntP4gh9HrlAVHSOnnXm9NQGr58b0vvnWrqxzcvUmO/t3B\r\nKh5+Tilv6RUVrAmGMhG4wprx9bGGX1lKdX3o+yd705hGL3/yDYJspEnzlgDA\r\n24nRNc9p8TqwL5H+DgLXyhOinXurs6VmJBT3kYswWKU3je5UsPF1wkPg/6K3\r\nAWgZysO3jijORMAX2fk9dGf/gtQhZh0/87U=\r\n=LkVM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGHPNDjmu9NiKk3ikogNr4BRoc6pMW0oYfZ34WY2v+5CAiB7nGygFTbo0874dfW3/HAFM3jBIWU0ji1oWMVlJ6yojw=="}]},"_npmUser":{"name":"ducng948","email":"levinguyen.dl@gmail.com"},"directories":{},"maintainers":[{"name":"ducng948","email":"levinguyen.dl@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sequelize-cursor-pagination_2.3.2_1648628689152_0.45543634547210576"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-30T08:12:15.896Z","2.3.1":"2022-03-30T08:12:16.099Z","modified":"2022-04-05T06:06:47.479Z","2.3.2":"2022-03-30T08:24:49.345Z"},"maintainers":[{"name":"ducng948","email":"levinguyen.dl@gmail.com"}],"description":"Hot fix bugs for sequelize-cursor-pagination","keywords":["sequelize","pagination"],"author":{"name":"ducng948"},"license":"MIT","readme":"![npm](https://img.shields.io/npm/v/sequelize-cursor-pagination) ![Build status](https://github.com/Kaltsoon/sequelize-cursor-pagination/workflows/CI/badge.svg)\n\n# Sequelize Cursor Pagination\n\nSequelize model decorator which provides cursor-based pagination queries. [Some motivation and background](https://dev-blog.apollodata.com/understanding-pagination-rest-graphql-and-relay-b10f835549e7).\n\n## Install\n\nWith npm:\n\n```bash\nnpm install sequelize-cursor-pagination\n```\n\nOr with Yarn:\n\n```bash\nyarn add sequelize-cursor-pagination\n```\n\n## How to use?\n\nDefine a Sequelize model and decorate it with the `withPagination` decorator:\n\n```javascript\n// ...\n\nconst withPagination = require('sequelize-cursor-pagination');\n\nconst Counter = sequelize.define('counter', {\n  id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },\n  value: Sequelize.INTEGER,\n});\n\nconst options = {\n  methodName: 'paginate',\n  primaryKeyField: 'id',\n};\n\nwithPagination(options)(Counter);\n```\n\nThe `withPagination` function has the following options:\n\n- `methodName`: The name of the pagination method. The default value is `paginate`.\n- `primaryKeyField`: The primary key field of the model. With composite primary key provide an array containing the keys, for example `['key1', 'key2']`. The default value is `'id'`.\n\nCall the `paginate` (the default method name) method:\n\n```javascript\nconst result = await Counter.paginate({\n  where: { value: { [Op.gt]: 2 } },\n  limit: 10,\n});\n```\n\nThe `paginate` method returns a promise, which resolves an object with the following properties:\n\n- `edges`: An array containing the results of the query. Each item in the array contains an object with the following properties:\n  - `node`: The model instance\n  - `cursor`: Cursor for the model instance\n- `totalCount`: The total numbers rows matching the query\n- `pageInfo`: An object containing the pagination related data with the following properties:\n  - `startCursor`: The cursor for the first node in the result edges\n  - `endCursor`: The cursor for the last node in the result edges\n  - `hasNextPage`: A boolean that indicates whether there are edges _after_ the `endCursor` (`false` indicates that there are no more edges after the `endCursor`)\n  - `hasPreviousPage`: A boolean that indicates whether there are edges _before_ the `startCursor` (`false` indicates that there are no more edges before the `startCursor`)\n\nThe `paginate` method has the following options:\n\n- `after`: The cursor that indicates _after_ which edge the next set of edges should be fetched\n- `before`: The cursor that indicates _before_ which edge next set of edges should be fetched\n- `limit`: The maximum number of edges returned\n\nOther options passed to the `paginate` method will be directly passed to the model's `findAll` method.\n\n**⚠️ NB:** The `order` option format only supports the `['field']` and `['field', 'DESC']` variations (field name and the optional order direction). For example, ordering by an associated model's field won't work.\n\n## Examples\n\nThe examples use the `Counter` model defined above.\n\nFetch the first `20` edges ordered by the `id` field (the `primaryKeyField` field) in ascending order:\n\n```javascript\nconst result = await Counter.paginate({\n  limit: 20,\n});\n```\n\nFirst, fetch the first `10` edges ordered by the `value` field in a descending order. Second, fetch the first `10` edges after the `endCursor`. Third, fetch the last `10` edges before `startCursor`:\n\n```javascript\nconst firstResult = await Counter.paginate({\n  order: [['value', 'DESC']],\n  limit: 10,\n});\n\nconst secondResult = await Counter.paginate({\n  order: [['value', 'DESC']],\n  limit: 10,\n  after: firstResult.pageInfo.endCursor,\n});\n\nconst thirdResult = await Counter.paginate({\n  order: [['value', 'DESC']],\n  limit: 10,\n  before: secondResult.pageInfo.startCursor,\n});\n```\n\n## Running tests\n\n```\nnpm run test\n```\n","readmeFilename":"README.md"}