Skip to content

Commit

Permalink
ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Nov 8, 2024
1 parent 05ce588 commit df7c715
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docs/source/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const files = [
'lib/types/subdocument.js',
'lib/types/arraySubdocument.js',
'lib/types/buffer.js',
'lib/types/decimal128.js',
'lib/types/.js',
'lib/types/map.js',
'lib/types/array/methods/index.js'
];
Expand Down
1 change: 1 addition & 0 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ exports.Schema = require('./schema');
* - [ObjectId](https://mongoosejs.com/docs/schematypes.html#objectids)
* - [Map](https://mongoosejs.com/docs/schematypes.html#maps)
* - [Subdocument](https://mongoosejs.com/docs/schematypes.html#schemas)
* - Int32
*
* Using this exposed access to the `ObjectId` type, we can construct ids on demand.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/cast/int32.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ module.exports = function castInt32(val) {
const INT32_MAX = 0x7FFFFFFF;
const INT32_MIN = -0x80000000;

let _val = Number(val);
const _val = Number(val);

if (!isNaN(_val) && _val === Math.round(_val) && _val > INT32_MIN && _val < INT32_MAX) {
return _val;
}
assert.ok(false);
}
};
};
17 changes: 17 additions & 0 deletions lib/mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ Mongoose.prototype.VirtualType = VirtualType;
* - [ObjectId](https://mongoosejs.com/docs/schematypes.html#objectids)
* - [Map](https://mongoosejs.com/docs/schematypes.html#maps)
* - [Subdocument](https://mongoosejs.com/docs/schematypes.html#schemas)
* - Int32
*
* Using this exposed access to the `ObjectId` type, we can construct ids on demand.
*
Expand Down Expand Up @@ -1138,6 +1139,22 @@ Mongoose.prototype.syncIndexes = function(options) {

Mongoose.prototype.Decimal128 = SchemaTypes.Decimal128;


/**
* The Mongoose Int32 [SchemaType](https://mongoosejs.com/docs/schematypes.html). Used for
* declaring paths in your schema that should be 32-bit integers floating points.
* Do not use this to create a new Int32 instance, use `mongoose.Types.Int32`
* instead.
*
* #### Example:
*
* const vehicleSchema = new Schema({ numberOfCows: mongoose.Int32 });
*
* @property Decimal128
* @api public
*/
Mongoose.prototype.Int32 = SchemaTypes.Int32;

/**
* The Mongoose Mixed [SchemaType](https://mongoosejs.com/docs/schematypes.html). Used for
* declaring paths in your schema that Mongoose's change tracking, casting,
Expand Down
1 change: 1 addition & 0 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ Query.prototype.getOptions = function() {
* - [projection](https://mongoosejs.com/docs/api/query.html#Query.prototype.projection())
* - sanitizeProjection
* - useBigInt64
* - promoteValues
*
* The following options are only for all operations **except** `updateOne()`, `updateMany()`, `deleteOne()`, and `deleteMany()`:
*
Expand Down
1 change: 1 addition & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,7 @@ module.exports = exports = Schema;
* - [Mixed](https://mongoosejs.com/docs/schematypes.html#mixed)
* - [UUID](https://mongoosejs.com/docs/schematypes.html#uuid)
* - [BigInt](https://mongoosejs.com/docs/schematypes.html#bigint)
* - Int32
*
* Using this exposed access to the `Mixed` SchemaType, we can use them in our schema.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/schema/bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function SchemaBigInt(path, options) {

/**
* This schema type's name, to defend against minifiers that mangle
* fun
* function names.
*
* @api public
*/
Expand Down
4 changes: 1 addition & 3 deletions lib/schema/int32.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ SchemaInt32.setters = [];
/**
* Attaches a getter for all Int32 instances
*
*
* @param {Function} getter
* @return {this}
* @function get
Expand All @@ -76,7 +75,6 @@ SchemaInt32.get = SchemaType.get;
/**
* Get/set the function used to cast arbitrary values to booleans.
*
*
* @param {Function} caster
* @return {Function}
* @function get
Expand Down Expand Up @@ -226,4 +224,4 @@ SchemaInt32.prototype._castNullish = function _castNullish(v) {
* Module exports.
*/

module.exports = SchemaInt32;
module.exports = SchemaInt32;
2 changes: 1 addition & 1 deletion test/bigint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('BigInt', function() {
assert.strictEqual(doc.bigint2, 997n);
});

it.only('handles cast errors', async function() {
it('handles cast errors', async function() {
const schema = new Schema({
bigint: 'BigInt'
});
Expand Down
Loading

0 comments on commit df7c715

Please sign in to comment.