Skip to content

Commit 6e7401d

Browse files
committed
fix: restore express dependency and improve findWithPagination function
Signed-off-by: Alejandro Dominguez <[email protected]>
1 parent 240dc62 commit 6e7401d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

package-lock.json

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
},
4040
"homepage": "https://github.com/mixmaxhq/mongo-cursor-pagination#readme",
4141
"dependencies": {
42-
"@types/express": "^4.17.21",
4342
"base64-url": "^2.2.0",
4443
"bson": "^4.7.2",
4544
"object-path": "^0.11.8",
@@ -55,6 +54,7 @@
5554
"@mixmaxhq/ts-config": "^1.2.1",
5655
"@types/jest": "^29.5.12",
5756
"@types/node": "^18.19.70",
57+
"@types/express": "^4.17.21",
5858
"@typescript-eslint/eslint-plugin": "^4.33.0",
5959
"@typescript-eslint/parser": "^4.33.0",
6060
"cz-conventional-changelog": "^3.2.0",

src/find.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default async function findWithPagination(
4949

5050
// Support both the native 'mongodb' driver and 'mongoist'. See:
5151
// https://www.npmjs.com/package/mongoist#cursor-operations
52-
const findMethod = (collection as any).findAsCursor
52+
const findMethod = hasFindAsCursor(collection)
5353
? COLLECTION_METHODS.FIND_AS_CURSOR
5454
: COLLECTION_METHODS.FIND;
5555

@@ -79,9 +79,15 @@ export default async function findWithPagination(
7979
}
8080

8181
// Remove fields that we added to the query (such as paginatedField and _id) that the user didn't ask for.
82-
if (removePaginatedFieldInResponse) {
82+
if (removePaginatedFieldInResponse && params.paginatedField) {
8383
response.results = _.map(response.results, (result) => _.omit(result, params.paginatedField));
8484
}
8585

8686
return response;
8787
}
88+
89+
function hasFindAsCursor(
90+
collection: unknown
91+
): collection is Collection<Document> & { findAsCursor: Function } {
92+
return typeof (collection as any).findAsCursor === 'function';
93+
}

0 commit comments

Comments
 (0)