-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly page through undefs and nulls
- Loading branch information
Showing
9 changed files
with
361 additions
and
74 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,15 +1,21 @@ | ||
const { EJSON } = require('bson'); | ||
const base64url = require('base64-url'); | ||
|
||
// BSON can't encode undefined values, so we will use this value instead: | ||
const BSON_UNDEFINED = '__mixmax__undefined__'; | ||
|
||
/** | ||
* These will take a BSON object (an database result returned by the MongoDB library) and | ||
* encode/decode as a URL-safe string. | ||
* These will take a paging handle (`next` or `previous`) and encode/decode it | ||
* as a string which can be passed in a URL. | ||
*/ | ||
|
||
module.exports.encode = function(obj) { | ||
if (Array.isArray(obj) && obj[0] === undefined) obj[0] = BSON_UNDEFINED; | ||
return base64url.encode(EJSON.stringify(obj)); | ||
}; | ||
|
||
module.exports.decode = function(str) { | ||
return EJSON.parse(base64url.decode(str)); | ||
const obj = EJSON.parse(base64url.decode(str)); | ||
if (Array.isArray(obj) && obj[0] === BSON_UNDEFINED) obj[0] = undefined; | ||
return obj; | ||
}; |
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
Oops, something went wrong.