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.
@thomas-smyth/sequelize-cursor-pagination
Advanced tools
Cursor pagination utility for sequelize.
sequelize-cursor-pagination
is a Sequelize modal decorator that implements two kinds of pagination:
This package was created to solve some minor annoyances in and simplify Kaltsoon's sequelize-cursor-pagination, however, has expanded to support the Relay GraphQL Cursor Connections Specification in order for it to be suitable for GraphQL APIs.
There is a small number of packages out there that provide cursor based pagination queries for Sequelize. The most prominent of these is Kaltsoon's sequelize-cursor-pagination, which this package uses as a base with the intent to improve upon it.
[[field1, direction1], [field2, direction2], ...]
.before
or after
cursor in order for it to decide whether you are requesting the previous or next page. Although this is similar to the Relay GraphQL Cursor Connections Specification, the package is not a full implementation of the specification and therefore the two cursor input options add unnecessary complexity to the package as the caller has to specify both the cursor and the direction even though the cursor will be unique to the direction. This version simplifies this by embedding the direction in each cursor, so the caller only needs to input the appropriate cursor for the previous/next page to be returned. In addition to this, it provides an implementation that fully meets the Relay GraphQL Cursor Connections Specification for use in GraphQL APIs.yarn add @thomas-smyth/sequelize-cursor-pagination
const { withSimplePagination } = require('@thomas-smyth/sequelize-cursor-pagination');
const Counter = sequelize.define('counter', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
value: Sequelize.INTEGER,
});
const options = {
methodName: 'paginate',
primaryKeyField: 'id',
};
withSimplePagination(options)(Counter);
const { withRelayPagination } = require('@thomas-smyth/sequelize-cursor-pagination');
const Counter = sequelize.define('counter', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
value: Sequelize.INTEGER,
});
const options = {
methodName: 'paginate',
primaryKeyField: 'id',
};
withRelayPagination(options)(Counter);
The withSimplePagination
/withRelayPagination
function has the following options:
methodName
- The name of the pagination method. The default value is paginate
.primaryKeyField
- The primary key field of the model which all queries will be ordered by last in order to ensure cursors are unique. The default value is id
.const page = await Counter.paginate({
where: { value: { $gt: 2 } },
limit: 10
});
The paginate
method returns an object with the following properties:
results
- An array of Sequelize model instances.cursors
- Object containing information related to cursors.
cursors.hasPrev
- Has previous value(s).cursors.hasNext
- Has next value(s).cursors.prevCursor
- The cursor for the previous page.cursors.nextCursor
- The cursor for the next page.const page = await Counter.paginate({
where: { value: { $gt: 2 } },
first: 10
});
The paginate
method returns an object with the following properties:
edges
- An array of edges.
edges[].cursor
- The cursor of the edge.edges[].node
- The node of the edge.pageInfo
- Object containing information related to cursors.
pageInfo.hasPreviousPage
- Has previous value(s).pageInfo.hasNextPage
- Has next value(s).pageInfo.startCursor
- The cursor for the first edge page.pageInfo.endCursor
- The cursor for the last edge page.For more information, please see the Relay GraphQL Cursor Connections Specification.
To call the next/previous page pass the appropriate prevCursor
/nextCursor
values to the cursor
option. For example, to go to the next page:
const pageOne = await Counter.paginate({
where: { value: { $gt: 2 } },
limit: 10
});
const pageTwo = await Counter.paginate({
where: { value: { $gt: 2 } },
limit: 10,
cursor: pageOne.cursors.nextCursor
});
To call the next/previous page pass the appropriate endCursor
/startCursor
value to the appropriate after
/before
option, as well as the appropriate first
/last
option as a replacement to the limit
option. For example, to go to the next page:
const pageOne = await Counter.paginate({
where: { value: { $gt: 2 } },
limit: 10
});
const pageTwo = await Counter.paginate({
where: { value: { $gt: 2 } },
after: pageOne.pageInfo.endCursor,
first: 10
});
For more information, please see the Relay GraphQL Cursor Connections Specification.
The paginate
method accepts a paginationField
cursor that overrides the previously specified primary key. It should be , like a primary key, this field should be unique to ensure cursors are unique.
The paginate
method should also accept all the same arguments as Sequelizer's findAll
finder, however, this has not been as extensively tested. Open to issues/PRs to address any issues found regarding this.
yarn run test
FAQs
Cursor pagination utility for sequelize.
We found that @thomas-smyth/sequelize-cursor-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.