forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(NODE-6503): Add Int32 as a SchemaType #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
05ce588
initial commit
aditi-khare-mongoDB df7c715
ready for review
aditi-khare-mongoDB 68f2ebd
API docs for promoteValues
aditi-khare-mongoDB 021f84b
requested changes
aditi-khare-mongoDB 538629c
fix failing tests
aditi-khare-mongoDB 4492a3e
requested changes 2
aditi-khare-mongoDB 8226905
requested changes 3
aditi-khare-mongoDB 7c6ff5c
requested changes 4
aditi-khare-mongoDB c5dc226
requested changes 4 cont.
aditi-khare-mongoDB 9537974
remove extranous changes
aditi-khare-mongoDB 49804ed
fix failing tests
aditi-khare-mongoDB c6bbafb
remove extranous file
aditi-khare-mongoDB 18d18a7
suggested changes
aditi-khare-mongoDB 0e4b257
lint
aditi-khare-mongoDB 010d1e2
misc change
aditi-khare-mongoDB 0f78bf1
misc change
aditi-khare-mongoDB 9dcada3
use isBsonType
aditi-khare-mongoDB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
|
|
||
| /** | ||
| * Given a value, cast it to a Int32, or throw an `Error` if the value | ||
| * cannot be casted. `null` and `undefined` are considered valid. | ||
| * | ||
| * @param {Any} value | ||
| * @return {Number} | ||
| * @throws {Error} if `value` does not represent an integer, or is outside the bounds of an 32-bit integer. | ||
| * @api private | ||
| */ | ||
|
|
||
| module.exports = function castInt32(val) { | ||
| if (val == null) { | ||
| return val; | ||
| } | ||
| if (val === '') { | ||
| return null; | ||
| } | ||
|
|
||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const coercedVal = val._bsontype === 'Long' ? val.toNumber() : Number(val); | ||
|
|
||
| const INT32_MAX = 0x7FFFFFFF; | ||
| const INT32_MIN = -0x80000000; | ||
|
|
||
| if (coercedVal === (coercedVal | 0) && | ||
| coercedVal >= INT32_MIN && | ||
| coercedVal <= INT32_MAX | ||
| ) { | ||
| return coercedVal; | ||
| } | ||
| assert.ok(false); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.