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

mongoose-paginate-v2

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-paginate-v2 - npm Package Compare versions

Comparing version 1.7.31 to 1.8.0

10

CHANGELOG.md
# Changelog
## v1.8.0
- Support for Mongoose v8
## v1.7.4
- Set dynamic type for docs items
## v1.7.3
- Fix - set limit when limit is 0
## v1.7.2
- Fix #194

@@ -8,0 +18,0 @@

4

dist/index.js

@@ -133,5 +133,5 @@ "use strict";

if (Object.keys(collation).length > 0) {
countPromise = this.count(query).collation(collation).exec();
countPromise = this.countDocuments(query).collation(collation).exec();
} else {
countPromise = this.count(query).exec();
countPromise = this.countDocuments(query).exec();
}

@@ -138,0 +138,0 @@ } else {

@@ -56,4 +56,4 @@ "use strict";

function populateResult(result, populate, callback) {
return result.populate(populate, callback);
function populateResult(result, populate) {
return result.populate(populate);
}

@@ -175,10 +175,4 @@ /**

populateResult(result, newPopulate, function (err, paginatedResult) {
if (err) {
callback(err, null);
reject(err);
return;
} // convert paginatedResult to pagination docs
populateResult(result, newPopulate).then(function (paginatedResult) {
// convert paginatedResult to pagination docs
if (pagination && pagingOptions) {

@@ -200,2 +194,3 @@ if (Array.isArray(pagingOptions)) {

callback && callback(err, null);
reject(err);
});

@@ -202,0 +197,0 @@ });

@@ -98,4 +98,4 @@ declare module 'mongoose' {

? O['leanWithId'] extends true
? LeanDocument<T & { id: string }>
: LeanDocument<T>
? T & { id: string }
: T
: HydratedDocument<T, TMethods, TVirtuals>;

@@ -114,2 +114,26 @@

}
interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}>
extends Model<T, TQueryHelpers, TMethods> {
paginate<UserType = T, O extends PaginateOptions = PaginateOptions >(
query?: FilterQuery<T>,
options?: O,
callback?: (
err: any,
result: PaginateResult<PaginateDocument<UserType, TMethods, O>>
) => void
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, O>>>;
}
interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}>
extends Model<T, TQueryHelpers, TMethods> {
paginate<UserType = T>(
query?: FilterQuery<T>,
options?: PaginateOptions,
callback?: (
err: any,
result: PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>
) => void
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>>;
}
}

@@ -116,0 +140,0 @@

{
"name": "mongoose-paginate-v2",
"version": "1.7.31",
"version": "1.8.0",
"description": "A custom pagination library for Mongoose with customizable labels.",

@@ -8,8 +8,7 @@ "main": "dist/index.js",

"scripts": {
"pretest": "npm run build",
"test": "mocha tests/*.js -R spec --ui bdd --timeout 9999999",
"build": "babel src -d dist",
"prepare": "babel src -d dist",
"lint": "eslint \"tests\" \"src\" \".eslintrc.js\" --fix",
"prettier": "prettier --write \"{src,tests}/**/*.js\" \"*.md\"",
"prepublish": "npm run test"
"prepublishOnly": "npm run test"
},

@@ -78,3 +77,3 @@ "husky": {

"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/preset-env": "^7.14.7",
"@babel/preset-env": "^7.23.7",
"@typescript-eslint/eslint-plugin": "^5.10.2",

@@ -89,3 +88,3 @@ "@typescript-eslint/parser": "^5.10.2",

"mocha": "^8.4.0",
"mongoose": "^5.13.2",
"mongoose": "^8.0.0",
"prettier": "^2.3.2",

@@ -92,0 +91,0 @@ "typescript": "^4.5.5"

@@ -138,5 +138,5 @@ /**

if (Object.keys(collation).length > 0) {
countPromise = this.count(query).collation(collation).exec();
countPromise = this.countDocuments(query).collation(collation).exec();
} else {
countPromise = this.count(query).exec();
countPromise = this.countDocuments(query).exec();
}

@@ -143,0 +143,0 @@ } else {

@@ -45,4 +45,4 @@ /**

function populateResult(result, populate, callback) {
return result.populate(populate, callback);
function populateResult(result, populate) {
return result.populate(populate);
}

@@ -164,8 +164,3 @@

populateResult(result, newPopulate, (err, paginatedResult) => {
if (err) {
callback(err, null);
reject(err);
return;
}
populateResult(result, newPopulate).then((paginatedResult) => {
// convert paginatedResult to pagination docs

@@ -189,2 +184,3 @@ if (pagination && pagingOptions) {

callback && callback(err, null);
reject(err);
});

@@ -191,0 +187,0 @@ });

@@ -89,15 +89,8 @@ 'use strict';

describe('mongoose-paginate', function () {
before(function (done) {
mongoose.connect(
MONGO_URI,
{
useUnifiedTopology: true,
useNewUrlParser: true,
},
done
);
before(async function () {
await mongoose.connect(MONGO_URI);
});
before(function (done) {
mongoose.connection.db.dropDatabase(done);
before(async function () {
await mongoose.connection.db.dropDatabase();
});

@@ -152,8 +145,5 @@

it('callback test', function (done) {
Book.paginate({}, {}, function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
done();
});
it('callback test', async function () {
const result = await Book.paginate({}, {});
expect(result).to.be.an.instanceOf(Object);
});

@@ -538,3 +528,3 @@

it('Sub documents pagination', () => {
it('Sub documents pagination', async () => {
var query = { title: 'Book #1' };

@@ -551,14 +541,13 @@ var option = {

return Book.paginateSubDocs(query, option).then((result) => {
expect(result.user.docs).to.have.length(3);
expect(result.user.totalPages).to.equal(4);
expect(result.user.page).to.equal(2);
expect(result.user.limit).to.equal(3);
expect(result.user.hasPrevPage).to.equal(true);
expect(result.user.hasNextPage).to.equal(true);
expect(result.user.prevPage).to.equal(1);
expect(result.user.nextPage).to.equal(3);
expect(result.user.pagingCounter).to.equal(4);
expect(result.user.docs[0].age).to.equal(3);
});
const result = await Book.paginateSubDocs(query, option);
expect(result.user.docs).to.have.length(3);
expect(result.user.totalPages).to.equal(4);
expect(result.user.page).to.equal(2);
expect(result.user.limit).to.equal(3);
expect(result.user.hasPrevPage).to.equal(true);
expect(result.user.hasNextPage).to.equal(true);
expect(result.user.prevPage).to.equal(1);
expect(result.user.nextPage).to.equal(3);
expect(result.user.pagingCounter).to.equal(4);
expect(result.user.docs[0].age).to.equal(3);
});

@@ -614,13 +603,10 @@

it('estimated count works', function (done) {
Book.paginate({}, { useEstimatedCount: true }, function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
done();
});
it('estimated count works', async function () {
const result = await Book.paginate({}, { useEstimatedCount: true });
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
});
it('count Custom Fn works', function (done) {
Book.paginate(
it('count Custom Fn works', async function () {
const result = await Book.paginate(
{},

@@ -631,15 +617,12 @@ {

},
},
function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
done();
}
);
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
});
it('count Custom Fn with Promise return works', function (done) {
Book.paginate(
it('count Custom Fn with Promise return works', async function () {
const result = await Book.paginate(
{},

@@ -650,11 +633,8 @@ {

},
},
function (err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
done();
}
);
expect(result).to.be.an.instanceOf(Object);
assert.isNumber(result.totalDocs, 'totalDocs is a number');
expect(result.totalDocs).to.equal(100);
});

@@ -766,8 +746,8 @@

after(function (done) {
mongoose.connection.db.dropDatabase(done);
after(async function () {
await mongoose.connection.db.dropDatabase();
});
after(function (done) {
mongoose.disconnect(done);
after(async function () {
await mongoose.disconnect();
});

@@ -774,0 +754,0 @@ });

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