Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restify-paginate

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-paginate - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

2

index.js

@@ -35,3 +35,3 @@ var extend = require('extend');

baseUrl = req.connection.encrypted ? 'https://' : 'http://';
baseUrl += req.headers.host;
baseUrl += req.headers.host.replace(/\/$/, '') + '/';
}

@@ -38,0 +38,0 @@

{
"name": "restify-paginate",
"version": "0.0.4",
"version": "0.0.5",
"description": "A resitfy a middleware that helps the navigation between pages.",

@@ -35,4 +35,4 @@ "main": "index.js",

"restify": "^4.0.0",
"should": "^7.0.4"
"should": "^13.2.1"
}
}

@@ -120,8 +120,8 @@ # restify-paginate

var query = 'SELECT * FROM my_table'
+ 'OFFSET ' + (req.paginate.page * req.paginate.per_page)
+ ' LIMIT ' + req.params.per_page;
+ 'OFFSET ' + ((req.paginate.page - 1) * req.paginate.per_page)
+ ' LIMIT ' + req.paginate.per_page;
// Mongoose like query
Potatoes.find()
.offset(req.paginate.page * req.paginate.per_page)
.limit(req.params.per_page);
.offset((req.paginate.page - 1) * req.paginate.per_page)
.limit(req.paginate.per_page);
```

@@ -163,8 +163,8 @@

var query = 'SELECT * FROM my_table'
+ 'OFFSET ' + (req.paginate.page * req.paginate.per_page)
+ ' LIMIT ' + req.params.per_page;
+ 'OFFSET ' + ((req.paginate.page - 1) * req.paginate.per_page)
+ ' LIMIT ' + req.paginate.per_page;
// Mongoose like query
Potatoes.find()
.offset(req.paginate.page * req.paginate.per_page)
.limit(req.params.per_page);
.offset((req.paginate.page - 1) * req.paginate.per_page)
.limit(req.paginate.per_page);
```

@@ -171,0 +171,0 @@

@@ -8,2 +8,6 @@ var restify = require('restify'),

describe('Paginate module with default options', function () {
const baseUrl = 'http://localhost';
const basePort = 3333;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -23,3 +27,3 @@ server = restify.createServer({

server.listen(3333, done);
server.listen(basePort, done);

@@ -30,6 +34,7 @@ });

request({
uri: 'http://localhost:3333/test',
baseUrl: baseUri,
uri: 'test',
resolveWithFullResponse: true
}).then(function (res) {
res.headers.link.should.be.eql('<http://localhost:3333/test?page=7>; rel="last", <http://localhost:3333/test?page=2>; rel="next"');
res.headers.link.should.be.eql(`<${baseUri}/test?page=7>; rel="last", <${baseUri}/test?page=2>; rel="next"`);
done();

@@ -43,6 +48,7 @@ }, function (err) {

request({
uri: 'http://localhost:3333/test?page=4',
baseUrl: baseUri,
uri: 'test?page=4',
resolveWithFullResponse: true
}).then(function (res) {
res.headers.link.should.be.eql('<http://localhost:3333/test?page=1>; rel="first", <http://localhost:3333/test?page=3>; rel="prev", <http://localhost:3333/test?page=7>; rel="last", <http://localhost:3333/test?page=5>; rel="next"');
res.headers.link.should.be.eql(`<${baseUri}/test?page=1>; rel="first", <${baseUri}/test?page=3>; rel="prev", <${baseUri}/test?page=7>; rel="last", <${baseUri}/test?page=5>; rel="next"`);
done();

@@ -57,2 +63,5 @@ }, function (err) {

describe('Paginate module without hostnames', function () {
const baseUrl = 'http://localhost';
const basePort = 7777;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -74,3 +83,3 @@ server = restify.createServer({

server.listen(7777, done);
server.listen(basePort, done);

@@ -81,3 +90,4 @@ });

request({
uri: 'http://localhost:7777/test',
baseUrl: baseUri,
uri: 'test',
resolveWithFullResponse: true

@@ -97,2 +107,6 @@ }).then(function (res) {

const baseUrl = 'http://localhost';
const basePort = 9999;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -107,3 +121,3 @@ testServer = restify.createServer({

testServer.listen(9999, done);
testServer.listen(basePort, done);
});

@@ -124,3 +138,4 @@

request({
uri: 'http://localhost:9999/object-test'
baseUrl: baseUri,
uri: 'object-test'
});

@@ -142,5 +157,6 @@ });

request({
uri: 'http://localhost:9999/type-test?page=2&per_page=2'
baseUrl: baseUri,
uri: 'type-test?page=2&per_page=2'
});
});
});

@@ -8,2 +8,5 @@ var restify = require('restify'),

describe('Paginate module with number only', function () {
const baseUrl = 'http://localhost';
const basePort = 4444;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -28,3 +31,3 @@ server = restify.createServer({

server.listen(4444, done);
server.listen(basePort, done);

@@ -35,3 +38,4 @@ });

request({
uri: 'http://localhost:4444/test',
baseUrl: baseUri,
uri: 'test',
json: true

@@ -50,3 +54,4 @@ }).then(function (res) {

request({
uri: 'http://localhost:4444/test?page=2',
baseUrl: baseUri,
uri: 'test?page=2',
json: true

@@ -53,0 +58,0 @@ }).then(function (res) {

@@ -9,2 +9,6 @@ var restify = require('restify'),

describe('The getLinks() function', function () {
const baseUrl = 'http://localhost';
const basePort = 8888;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -21,3 +25,3 @@ server = restify.createServer({

res.send({
pages: res.paginate.getLinks(10)
pages: res.paginate.getLinks(10)
});

@@ -31,14 +35,25 @@ });

server.listen(8888, done);
server.listen(basePort, done);
});
it('should generate a prev, next, first and last page link, if count is provided', function(done) {
it('should generate a prev, next, first and last page link, if count is provided', function (done) {
request({
uri: 'http://localhost:8888/test?page=3&per_page=2',
baseUrl: baseUri,
uri: 'test?page=3&per_page=2',
json: true
}).then(function (res) {
url.parse(res.pages.prev, true).query.should.have.property('page', '2');
url.parse(res.pages.next, true).query.should.have.property('page', '4');
url.parse(res.pages.first, true).query.should.have.property('page', '1');
url.parse(res.pages.last, true).query.should.have.property('page', '5');
should.exist(res.pages);
const prevUrl = Object.assign({}, url.parse(res.pages.prev, true).query);
prevUrl.should.have.property('page', '2');
const nextUrl = Object.assign({}, url.parse(res.pages.next, true).query);
nextUrl.should.have.property('page', '4');
const firstUrl = Object.assign({}, url.parse(res.pages.first, true).query);
firstUrl.should.have.property('page', '1');
const lastUrl = Object.assign({}, url.parse(res.pages.last, true).query);
lastUrl.should.have.property('page', '5');
done();

@@ -51,10 +66,17 @@ }, function (err) {

it('should generate a prev, next and first (but not last) page link, if count isn\'t provided', function(done) {
it('should generate a prev, next and first (but not last) page link, if count isn\'t provided', function (done) {
request({
uri: 'http://localhost:8888/test-no-count?testparam=test&page=3&per_page=2',
baseUrl: baseUri,
uri: 'test-no-count?testparam=test&page=3&per_page=2',
json: true
}).then(function (res) {
url.parse(res.pages.prev, true).query.should.have.property('page', '2');
url.parse(res.pages.next, true).query.should.have.property('page', '4');
url.parse(res.pages.first, true).query.should.have.property('page', '1');
const prevUrl = Object.assign({}, url.parse(res.pages.prev, true).query);
prevUrl.should.have.property('page', '2');
const nextUrl = Object.assign({}, url.parse(res.pages.next, true).query);
nextUrl.should.have.property('page', '4');
const firstUrl = Object.assign({}, url.parse(res.pages.first, true).query);
firstUrl.should.have.property('page', '1');
res.pages.should.not.have.property('last');

@@ -68,8 +90,9 @@ done();

it('should add the params of the initial request to the generated links, except for page', function(done) {
request({
uri: 'http://localhost:8888/test?testparam=test&page=2&per_page=2',
it('should add the params of the initial request to the generated links, except for page', function (done) {
request({
baseUrl: baseUri,
uri: 'test?testparam=test&page=2&per_page=2',
json: true
}).then(function (res) {
var nextLinkParams = url.parse(res.pages.next, true).query;
var nextLinkParams = Object.assign({}, url.parse(res.pages.next, true).query);
nextLinkParams.should.have.property('testparam', 'test');

@@ -85,12 +108,13 @@ nextLinkParams.should.have.property('per_page', '2');

it('shouldn\'t return an empty last page, in case count % per_page === 0', function(done) {
it('shouldn\'t return an empty last page, in case count % per_page === 0', function (done) {
request({
uri: 'http://localhost:8888/test?page=2&per_page=2',
baseUrl: baseUri,
uri: 'test?page=2&per_page=2',
json: true
}).then(function (res) {
var lastLinkParams = url.parse(res.pages.last, true).query;
var lastLinkParams = Object.assign({}, url.parse(res.pages.last, true).query);
// the count is 10 and per_page is 2, therefore the last page should be 5
lastLinkParams.should.have.property('page', '5');
done();

@@ -97,0 +121,0 @@ }, function (err) {

@@ -8,2 +8,6 @@ var restify = require('restify'),

describe('Paginate module with `page` key overridden', function () {
const baseUrl = 'http://localhost';
const basePort = 5555;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -27,3 +31,3 @@ server = restify.createServer({

server.listen(5555, done);
server.listen(basePort, done);

@@ -34,6 +38,7 @@ });

request({
uri: 'http://localhost:5555/test',
baseUrl: baseUri,
uri: 'test',
resolveWithFullResponse: true
}).then(function (res) {
res.headers.link.should.be.eql('<http://localhost:5555/test?page=6>; rel="last", <http://localhost:5555/test?page=1>; rel="next"');
res.headers.link.should.be.eql(`<${baseUri}/test?page=6>; rel="last", <${baseUri}/test?page=1>; rel="next"`);
done();

@@ -48,2 +53,6 @@ }, function (err) {

describe('Paginate module with `per_page` key overridden', function () {
const baseUrl = 'http://localhost';
const basePort = 6666;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {

@@ -67,3 +76,3 @@ server = restify.createServer({

server.listen(6666, done);
server.listen(basePort, done);

@@ -74,6 +83,7 @@ });

request({
uri: 'http://localhost:6666/test',
baseUrl: baseUri,
uri: 'test',
resolveWithFullResponse: true
}).then(function (res) {
res.headers.link.should.be.eql('<http://localhost:6666/test?page=16>; rel="last", <http://localhost:6666/test?page=2>; rel="next"');
res.headers.link.should.be.eql(`<${baseUri}/test?page=16>; rel="last", <${baseUri}/test?page=2>; rel="next"`);
done();

@@ -88,6 +98,7 @@ }, function (err) {

request({
uri: 'http://localhost:6666/test?per_page=30',
baseUrl: baseUri,
uri: 'test?per_page=30',
resolveWithFullResponse: true
}).then(function (res) {
res.headers.link.should.be.eql('<http://localhost:6666/test?per_page=30&page=11>; rel="last", <http://localhost:6666/test?per_page=30&page=2>; rel="next"');
res.headers.link.should.be.eql(`<${baseUri}/test?per_page=30&page=11>; rel="last", <${baseUri}/test?per_page=30&page=2>; rel="next"`);
done();

@@ -94,0 +105,0 @@ }, function (err) {

@@ -10,4 +10,8 @@ var restify = require('restify'),

describe('The getPaginatedResponse() function', function () {
const baseUrl = 'http://localhost';
const basePort = 3434;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {
for(var i = 0; i < 100; i++) {
for (var i = 0; i < 100; i++) {
// generate random string

@@ -29,8 +33,9 @@ testData[i] = Math.random().toString(36).substring(8);

server.listen(3434, done);
server.listen(basePort, done);
});
it('should return the paginated data', function(done) {
it('should return the paginated data', function (done) {
request({
uri: 'http://localhost:3434/test?page=5&per_page=2',
baseUrl: baseUri,
uri: 'test?page=5&per_page=2',
json: true

@@ -46,5 +51,6 @@ }).then(function (res) {

it('should return the pages', function(done) {
it('should return the pages', function (done) {
request({
uri: 'http://localhost:3434/test?page=5&per_page=2',
baseUrl: baseUri,
uri: 'test?page=5&per_page=2',
json: true

@@ -63,5 +69,6 @@ }).then(function (res) {

it('should return status 404 in case the page is out of range', function(done) {
it('should return status 404 in case the page is out of range', function (done) {
request({
uri: 'http://localhost:3434/test?page=500&per_page=10',
baseUrl: baseUri,
uri: 'test?page=500&per_page=10',
json: true

@@ -80,4 +87,8 @@ }).then(function (res) {

describe('The getResponse() function', function () {
const baseUrl = 'http://localhost';
const basePort = 4343;
const baseUri = `${baseUrl}:${basePort}/`;
before(function (done) {
for(var i = 0; i < 5; i++) {
for (var i = 0; i < 5; i++) {
// generate random string

@@ -105,5 +116,6 @@ testData[i] = Math.random().toString(36).substring(8);

it('should return the data', function(done) {
it('should return the data', function (done) {
request({
uri: 'http://localhost:4343/test?page=5&per_page=5',
baseUrl: baseUri,
uri: 'test?page=5&per_page=5',
json: true

@@ -119,5 +131,6 @@ }).then(function (res) {

it('should return the pages', function(done) {
it('should return the pages', function (done) {
request({
uri: 'http://localhost:4343/test?page=5&per_page=5',
baseUrl: baseUri,
uri: 'test?page=5&per_page=5',
json: true

@@ -136,5 +149,6 @@ }).then(function (res) {

it('should not return the last page, if count hasn\'t been provided', function(done) {
it('should not return the last page, if count hasn\'t been provided', function (done) {
request({
uri: 'http://localhost:4343/test-no-count?page=5&per_page=5',
baseUrl: baseUri,
uri: 'test-no-count?page=5&per_page=5',
json: true

@@ -141,0 +155,0 @@ }).then(function (res) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc