Skip to content

Commit

Permalink
Merge pull request #225 from nexus-aissam/main
Browse files Browse the repository at this point in the history
feat: support for leanWithVirtuals option to work with mongoose-lean-virtuals plugin
  • Loading branch information
aravindnc authored Jan 6, 2025
2 parents 9c1bb84 + 30f18f4 commit b78f359
Show file tree
Hide file tree
Showing 9 changed files with 3,813 additions and 121 deletions.
86 changes: 49 additions & 37 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,193 +1,205 @@
# Changelog

## v1.8.6

[2025-01-05]

- Add: support for leanWithVirtuals option to work with mongoose-lean-virtuals plugin

## v1.8.5

[2024-09-29]
* Fix: correct PaginateDocument type parameters and merge PaginateModel interface

- Fix: correct PaginateDocument type parameters and merge PaginateModel interface

## v1.8.4

[2024-09-26]
* Fix for Inconsistent declaration of Query (#220)

- Fix for Inconsistent declaration of Query (#220)

## v1.8.3

[2024-07-23]
* Added support for queryHelpers.

- Added support for queryHelpers.

## v1.8.2

[2024-05-29]

* MongoDB < 3.4: Fix for countDocument
- MongoDB < 3.4: Fix for countDocument

## v1.8.1

[2024-05-17]

* Fix #186
* Fix - Use default values for page and limit when passing undefined
- Fix #186
- Fix - Use default values for page and limit when passing undefined

## v1.8.0

[2024-01-05]

* Support for Mongoose v8
- Support for Mongoose v8

## v1.7.4

* Set dynamic type for docs items
- Set dynamic type for docs items

## v1.7.3

[2023-07-26]

* Fix - set limit when limit is 0
- Fix - set limit when limit is 0

## v1.7.2

* Fix #194
- Fix #194

## v1.7.1

* Added support for custom find method.
- Added support for custom find method.

## v1.7.0

[2022-07-04]

* Added support for sub-document pagination.
- Added support for sub-document pagination.

[2022-02-28]

* Added support for Mongoose 6
- Added support for Mongoose 6

## v1.6.3

[2022-02-28]

* Added support for Mongoose 6
- Added support for Mongoose 6

## v1.6.2

[2022-02-11]

* Removed 2D test cases to support Mongoose 6.
- Removed 2D test cases to support Mongoose 6.

## v1.6.1

[2022-02-05]

* Fix: update paginate options typings #154, #156
- Fix: update paginate options typings #154, #156

## v1.6.0

[2022-02-03]

* Added Typescript version.
- Added Typescript version.

## v1.5.0

[2022-01-09]

* Added feature: PaginationParameters helper class
- Added feature: PaginationParameters helper class

## v1.4.3

[2022-01-06]

* Fix hasPrevPage behaviour with limit > offset > 0
- Fix hasPrevPage behaviour with limit > offset > 0

## v1.4.2

[2021-08-15]

* Removed 'cursor' text across the project.
- Removed 'cursor' text across the project.

## v1.4.1

[2021-07-08]

* Removed test case for allowDiskUse, which cause build to fail on lower MongoDB versions.
- Removed test case for allowDiskUse, which cause build to fail on lower MongoDB versions.

## v1.4.0

[2021-07-08]

* Added allowDiskUse option as a workaround for QueryExceededMemoryLimitNoDiskUseAllowed error with large data sets.
- Added allowDiskUse option as a workaround for QueryExceededMemoryLimitNoDiskUseAllowed error with large data sets.

## v1.3.18

[2021-05-17]

* Fixed issue #85
- Fixed issue #85

## v1.3.17

[2021-03-26]

* Fix for page value is less than 1
- Fix for page value is less than 1

## v1.3.16

[2021-02-24]

* Collation fix for MongoDB v3.4 and less.
- Collation fix for MongoDB v3.4 and less.

## v1.3.15

[2021-02-21]

* Fixed issues where no results or incorrect count are returned when using collations.
- Fixed issues where no results or incorrect count are returned when using collations.

## v1.3.14

[2021-01-27]

* Fixed issue hasPrevPage and prevPage returned values are not correct at page=1 (#119)
- Fixed issue hasPrevPage and prevPage returned values are not correct at page=1 (#119)

## v1.3.13

[2020-12-22]

### Fixed

* Sorting issue after population.
- Sorting issue after population.

## v1.3.12

[2020-12-04]

### Added

* New option for custom count function.
- New option for custom count function.

## v1.3.11

[2020-11-06]

### Fixed

* estimateDocumentCount implementation.
* Package version updates to support Node v12.
- estimateDocumentCount implementation.
- Package version updates to support Node v12.

## v1.3.10

[2020-11-01]

### Added

* support for estimatedCountDocuments for larger datasets. Set useEstimatedCount=true
- support for estimatedCountDocuments for larger datasets. Set useEstimatedCount=true

## v1.3.9

[2020-04-02]

### Fixed

* [#54](https://github.com/aravindnc/mongoose-paginate-v2/issues/54)
- [#54](https://github.com/aravindnc/mongoose-paginate-v2/issues/54)

* [#65](https://github.com/aravindnc/mongoose-paginate-v2/issues/65)
- [#65](https://github.com/aravindnc/mongoose-paginate-v2/issues/65)

### Added

* Get all docs if pagination is not enabled.
* Support to determines the MongoDB nodes from which to read.
* New option forceCountFn to support $near and $nearSphere (Ref: https://github.com/aravindnc/mongoose-paginate-v2#note)
- Get all docs if pagination is not enabled.
- Support to determines the MongoDB nodes from which to read.
- New option forceCountFn to support $near and $nearSphere (Ref: https://github.com/aravindnc/mongoose-paginate-v2#note)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
![npms.io](https://img.shields.io/npms-io/maintenance-score/mongoose-paginate-v2)
![npms.io](https://img.shields.io/npms-io/quality-score/mongoose-paginate-v2)


> A custom pagination library for [Mongoose](http://mongoosejs.com) with customizable labels.
If you are looking for aggregate query pagination, use this one [mongoose-aggregate-paginate-v2](https://github.com/aravindnc/mongoose-aggregate-paginate-v2)
Expand Down Expand Up @@ -91,6 +90,7 @@ Returns promise
- `[projection]` {String | Object} - Get/set the query projection. [Documentation](https://mongoosejs.com/docs/api/query.html#query_Query-projection)
- `[lean=false]` {Boolean} - Should return plain javascript objects instead of Mongoose documents? [Documentation](http://mongoosejs.com/docs/api.html#query_Query-lean)
- `[leanWithId=true]` {Boolean} - If `lean` and `leanWithId` are `true`, adds `id` field with string representation of `_id` to every document
- `[leanWithVirtuals=false]` {Boolean} - If `lean` and `leanWithVirtuals` are `true`, includes virtuals in lean output. Requires [mongoose-lean-virtuals](https://www.npmjs.com/package/mongoose-lean-virtuals) plugin.
- `[offset=0]` {Number} - Use `offset` or `page` to set skip position
- `[page=1]` {Number}
- `[limit=10]` {Number}
Expand Down
81 changes: 54 additions & 27 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ declare module 'mongoose' {
collation?: import('mongodb').CollationOptions | undefined;
sort?: object | string | undefined;
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
projection?: any;
lean?: boolean | undefined;
leanWithId?: boolean | undefined;
leanWithVirtuals?: boolean | undefined;
offset?: number | undefined;
page?: number | undefined;
limit?: number | undefined;
Expand All @@ -49,25 +50,25 @@ declare module 'mongoose' {
interface SubPaginateOptions {
select?: object | string | undefined;
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
pagination?: boolean | undefined;
read?: ReadOptions | undefined;
pagingOptions: SubDocumentPagingOptions | undefined;
}

interface SubDocumentPagingOptions {
populate?:
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
| PopulateOptions[]
| string[]
| PopulateOptions
| string
| PopulateOptions
| undefined;
page?: number | undefined;
limit?: number | undefined;
}
Expand Down Expand Up @@ -96,6 +97,8 @@ declare module 'mongoose' {
> = O['lean'] extends true
? O['leanWithId'] extends true
? T & { id: string }
: O['leanWithVirtuals'] extends true
? T & { [key: string]: any }
: T
: HydratedDocument<T, TMethods, TQueryHelpers>;

Expand All @@ -115,37 +118,61 @@ declare module 'mongoose' {
options?: O,
callback?: (
err: any,
result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
result: PaginateResult<
PaginateDocument<UserType, TMethods, TQueryHelpers, O>
>
) => void
): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
): Promise<
PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>
>;

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

// @ts-ignore
interface Query<
ResultType,
DocType,
THelpers = NonNullable<unknown>,
RawDocType = DocType,
QueryOp = 'find',
TInstanceMethods = Record<string, never>,
TInstanceMethods = Record<string, never>
> {
paginate<O extends PaginateOptions>(
options?: O
): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>>
paginate<UserType = ResultType, O extends PaginateOptions = PaginateOptions>(
): Promise<
PaginateResult<
PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>
>
>;
paginate<
UserType = ResultType,
O extends PaginateOptions = PaginateOptions
>(
options?: O
): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>>
): Promise<
PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>
>;
paginate<UserType = ResultType>(
options?: PaginateOptions
): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>>
): Promise<
PaginateResult<
PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>
>
>;
}
}

Expand Down
Loading

0 comments on commit b78f359

Please sign in to comment.