-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix default cursor options assign function
- Loading branch information
Showing
6 changed files
with
80 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ [email protected] | |
[email protected] | ||
[email protected] | ||
[email protected] | ||
kolyasya:[email protected].5 | ||
kolyasya:[email protected].8 | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ [email protected] | |
[email protected] | ||
[email protected] | ||
[email protected] | ||
kolyasya:[email protected].6 | ||
kolyasya:[email protected].8 | ||
[email protected] | ||
[email protected] | ||
[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,69 @@ | ||
import handleKeepPreloaded from "./handleKeepPreloaded"; | ||
import getPublishPaginatedLogger from "./getPublishPaginatedLogger"; | ||
|
||
const getCursorOptions = ({ paginationParams, subscriptionParams }) => { | ||
let options = | ||
typeof paginationParams.transformCursorOptions === "function" | ||
? paginationParams.transformCursorOptions({ | ||
paginationParams, | ||
subscriptionParams, | ||
}) | ||
: {}; | ||
const logger = getPublishPaginatedLogger(); | ||
let cursorOptions = {}; | ||
|
||
if (subscriptionParams.limit >= 0) { | ||
options.limit = subscriptionParams.limit; | ||
cursorOptions.limit = subscriptionParams.limit; | ||
} | ||
|
||
if (subscriptionParams.skip >= 0) { | ||
options.skip = subscriptionParams.skip; | ||
cursorOptions.skip = subscriptionParams.skip; | ||
} | ||
|
||
if (subscriptionParams.sort) { | ||
options.sort = subscriptionParams.sort; | ||
cursorOptions.sort = subscriptionParams.sort; | ||
} | ||
|
||
if (subscriptionParams.fields) { | ||
options.fields = subscriptionParams.fields; | ||
cursorOptions.fields = subscriptionParams.fields; | ||
} | ||
|
||
if (subscriptionParams.keepPreloaded) { | ||
options = handleKeepPreloaded({ | ||
cursorOptions = handleKeepPreloaded({ | ||
options, | ||
params: subscriptionParams, | ||
}); | ||
} | ||
|
||
if (subscriptionParams.transform) { | ||
options.transform = subscriptionParams.transform; | ||
cursorOptions.transform = subscriptionParams.transform; | ||
} | ||
|
||
if (typeof subscriptionParams.reactive !== "undefined") { | ||
options.reactive = subscriptionParams.reactive; | ||
cursorOptions.reactive = subscriptionParams.reactive; | ||
} | ||
|
||
return options; | ||
if (typeof paginationParams.transformCursorOptions === "function") { | ||
logger( | ||
"Transforming cursor options with custom functio (transformCursorOptions)..." | ||
); | ||
|
||
cursorOptions = paginationParams.transformCursorOptions({ | ||
paginationParams, | ||
subscriptionParams, | ||
cursorOptions, | ||
}); | ||
|
||
if (typeof cursorOptions !== "object") { | ||
console.warn( | ||
`"transformCursorOptions" function should return object, which will be used as Mongo Cursor options param` | ||
); | ||
} | ||
} | ||
|
||
if ( | ||
typeof cursorOptions.limit !== "number" || | ||
typeof cursorOptions.skip !== "number" | ||
) { | ||
console.warn( | ||
`Check cursor options limit: ${cursorOptions.limit} and skip: ${cursorOptions.skip} params. They should be numbers for pagination to work properly` | ||
); | ||
} | ||
|
||
return cursorOptions; | ||
}; | ||
|
||
export default getCursorOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,69 @@ | ||
import handleKeepPreloaded from "./handleKeepPreloaded"; | ||
import getPublishPaginatedLogger from "./getPublishPaginatedLogger"; | ||
|
||
const getCursorOptions = ({ paginationParams, subscriptionParams }) => { | ||
let options = | ||
typeof paginationParams.transformCursorOptions === "function" | ||
? paginationParams.transformCursorOptions({ | ||
paginationParams, | ||
subscriptionParams, | ||
}) | ||
: {}; | ||
const logger = getPublishPaginatedLogger(); | ||
let cursorOptions = {}; | ||
|
||
if (subscriptionParams.limit >= 0) { | ||
options.limit = subscriptionParams.limit; | ||
cursorOptions.limit = subscriptionParams.limit; | ||
} | ||
|
||
if (subscriptionParams.skip >= 0) { | ||
options.skip = subscriptionParams.skip; | ||
cursorOptions.skip = subscriptionParams.skip; | ||
} | ||
|
||
if (subscriptionParams.sort) { | ||
options.sort = subscriptionParams.sort; | ||
cursorOptions.sort = subscriptionParams.sort; | ||
} | ||
|
||
if (subscriptionParams.fields) { | ||
options.fields = subscriptionParams.fields; | ||
cursorOptions.fields = subscriptionParams.fields; | ||
} | ||
|
||
if (subscriptionParams.keepPreloaded) { | ||
options = handleKeepPreloaded({ | ||
cursorOptions = handleKeepPreloaded({ | ||
options, | ||
params: subscriptionParams, | ||
}); | ||
} | ||
|
||
if (subscriptionParams.transform) { | ||
options.transform = subscriptionParams.transform; | ||
cursorOptions.transform = subscriptionParams.transform; | ||
} | ||
|
||
if (typeof subscriptionParams.reactive !== "undefined") { | ||
options.reactive = subscriptionParams.reactive; | ||
cursorOptions.reactive = subscriptionParams.reactive; | ||
} | ||
|
||
return options; | ||
if (typeof paginationParams.transformCursorOptions === "function") { | ||
logger( | ||
"Transforming cursor options with custom functio (transformCursorOptions)..." | ||
); | ||
|
||
cursorOptions = paginationParams.transformCursorOptions({ | ||
paginationParams, | ||
subscriptionParams, | ||
cursorOptions, | ||
}); | ||
|
||
if (typeof cursorOptions !== "object") { | ||
console.warn( | ||
`"transformCursorOptions" function should return object, which will be used as Mongo Cursor options param` | ||
); | ||
} | ||
} | ||
|
||
if ( | ||
typeof cursorOptions.limit !== "number" || | ||
typeof cursorOptions.skip !== "number" | ||
) { | ||
console.warn( | ||
`Check cursor options limit: ${cursorOptions.limit} and skip: ${cursorOptions.skip} params. They should be numbers for pagination to work properly` | ||
); | ||
} | ||
|
||
return cursorOptions; | ||
}; | ||
|
||
export default getCursorOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters