Comparing version 4.4.0 to 4.4.1
@@ -25,3 +25,3 @@ { | ||
], | ||
"version": "4.4.0" | ||
"version": "4.4.1" | ||
} |
@@ -5,2 +5,12 @@ # Changelog | ||
### [4.4.1](https://github.com/mongodb/js-bson/compare/v4.4.0...v4.4.1) (2021-07-06) | ||
### Bug Fixes | ||
* **NODE-3247:** DBRef special handling ([#443](https://github.com/mongodb/js-bson/issues/443)) ([f5d984d](https://github.com/mongodb/js-bson/commit/f5d984d88b2e20310ec5cc3a39b91b0fd1e0b3c9)) | ||
* **NODE-3282:** BSONRegExp options not alphabetized ([#441](https://github.com/mongodb/js-bson/issues/441)) ([18c3512](https://github.com/mongodb/js-bson/commit/18c3512befe54908e4b816056dbde0d1b998d81b)) | ||
* **NODE-3376:** use standard JS methods for copying Buffers ([#444](https://github.com/mongodb/js-bson/issues/444)) ([804050d](https://github.com/mongodb/js-bson/commit/804050d40b03a02116995e63671e05ffa033dc45)) | ||
* **NODE-3390:** serialize non-finite doubles correctly in EJSON ([#445](https://github.com/mongodb/js-bson/issues/445)) ([7eb7998](https://github.com/mongodb/js-bson/commit/7eb79981e16d73a391c567b7f9748943997a424d)) | ||
## [4.4.0](https://github.com/mongodb/js-bson/compare/v4.3.0...v4.4.0) (2021-05-18) | ||
@@ -7,0 +17,0 @@ |
@@ -7,3 +7,6 @@ "use strict"; | ||
function isDBRefLike(value) { | ||
return utils_1.isObjectLike(value) && value['$id'] != null && value['$ref'] != null; | ||
return (utils_1.isObjectLike(value) && | ||
value.$id != null && | ||
typeof value.$ref === 'string' && | ||
(value.$db == null || typeof value.$db === 'string')); | ||
} | ||
@@ -10,0 +13,0 @@ exports.isDBRefLike = isDBRefLike; |
@@ -101,3 +101,3 @@ "use strict"; | ||
} | ||
if (value.$ref != null || value.$dbPointer != null) { | ||
if (db_ref_1.isDBRefLike(value) || value.$dbPointer) { | ||
var v = value.$ref ? value : value.$dbPointer; | ||
@@ -179,3 +179,3 @@ // we run into this in a "degenerate EJSON" case (with $id and $ref order flipped) | ||
} | ||
if (typeof value === 'number' && !options.relaxed) { | ||
if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) { | ||
// it's an integer | ||
@@ -266,3 +266,3 @@ if (Math.floor(value) === value) { | ||
else if (bsontype === 'DBRef' && outDoc.oid) { | ||
outDoc = new db_ref_1.DBRef(outDoc.collection, serializeValue(outDoc.oid, options), outDoc.db, outDoc.fields); | ||
outDoc = new db_ref_1.DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options)); | ||
} | ||
@@ -269,0 +269,0 @@ return outDoc.toExtendedJSON(options); |
@@ -221,4 +221,6 @@ "use strict"; | ||
} | ||
else if (value.id && value.id.copy) { | ||
value.id.copy(buffer, index, 0, 12); | ||
else if (utils_1.isUint8Array(value.id)) { | ||
// Use the standard JS methods here because buffer.copy() is buggy with the | ||
// browser polyfill | ||
buffer.set(value.id.subarray(0, 12), index); | ||
} | ||
@@ -293,3 +295,5 @@ else { | ||
// Write the data from the value | ||
value.bytes.copy(buffer, index, 0, 16); | ||
// Prefer the standard JS methods because their typechecking is not buggy, | ||
// unlike the `buffer` polyfill's. | ||
buffer.set(value.bytes.subarray(0, 16), index); | ||
return index + 16; | ||
@@ -296,0 +300,0 @@ } |
@@ -20,5 +20,3 @@ "use strict"; | ||
this.pattern = pattern; | ||
this.options = options !== null && options !== void 0 ? options : ''; | ||
// Execute | ||
alphabetize(this.options); | ||
this.options = alphabetize(options !== null && options !== void 0 ? options : ''); | ||
// Validate options | ||
@@ -25,0 +23,0 @@ for (var i = 0; i < this.options.length; i++) { |
@@ -18,3 +18,3 @@ { | ||
"types": "bson.d.ts", | ||
"version": "4.4.0", | ||
"version": "4.4.1", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -63,5 +63,5 @@ "license": "Apache-2.0", | ||
"rollup-plugin-node-polyfills": "^0.2.1", | ||
"standard-version": "^8.0.1", | ||
"standard-version": "^9.3.0", | ||
"ts-node": "^9.0.0", | ||
"typedoc": "^0.18.0", | ||
"typedoc": "^0.21.2", | ||
"typescript": "^4.0.2", | ||
@@ -68,0 +68,0 @@ "typescript-cached-transpile": "0.0.6", |
@@ -15,3 +15,8 @@ import type { Document } from './bson'; | ||
export function isDBRefLike(value: unknown): value is DBRefLike { | ||
return isObjectLike(value) && value['$id'] != null && value['$ref'] != null; | ||
return ( | ||
isObjectLike(value) && | ||
value.$id != null && | ||
typeof value.$ref === 'string' && | ||
(value.$db == null || typeof value.$db === 'string') | ||
); | ||
} | ||
@@ -18,0 +23,0 @@ |
import { Binary } from './binary'; | ||
import type { Document } from './bson'; | ||
import { Code } from './code'; | ||
import { DBRef } from './db_ref'; | ||
import { DBRef, isDBRefLike } from './db_ref'; | ||
import { Decimal128 } from './decimal128'; | ||
@@ -123,3 +123,3 @@ import { Double } from './double'; | ||
if (value.$ref != null || value.$dbPointer != null) { | ||
if (isDBRefLike(value) || value.$dbPointer) { | ||
const v = value.$ref ? value : value.$dbPointer; | ||
@@ -217,3 +217,3 @@ | ||
if (typeof value === 'number' && !options.relaxed) { | ||
if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) { | ||
// it's an integer | ||
@@ -315,6 +315,6 @@ if (Math.floor(value) === value) { | ||
outDoc = new DBRef( | ||
outDoc.collection, | ||
serializeValue(outDoc.collection, options), | ||
serializeValue(outDoc.oid, options), | ||
outDoc.db, | ||
outDoc.fields | ||
serializeValue(outDoc.db, options), | ||
serializeValue(outDoc.fields, options) | ||
); | ||
@@ -321,0 +321,0 @@ } |
@@ -309,4 +309,6 @@ import type { Buffer } from 'buffer'; | ||
buffer.write(value.id, index, undefined, 'binary'); | ||
} else if (value.id && value.id.copy) { | ||
value.id.copy(buffer, index, 0, 12); | ||
} else if (isUint8Array(value.id)) { | ||
// Use the standard JS methods here because buffer.copy() is buggy with the | ||
// browser polyfill | ||
buffer.set(value.id.subarray(0, 12), index); | ||
} else { | ||
@@ -410,3 +412,5 @@ throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId'); | ||
// Write the data from the value | ||
value.bytes.copy(buffer, index, 0, 16); | ||
// Prefer the standard JS methods because their typechecking is not buggy, | ||
// unlike the `buffer` polyfill's. | ||
buffer.set(value.bytes.subarray(0, 16), index); | ||
return index + 16; | ||
@@ -413,0 +417,0 @@ } |
@@ -38,5 +38,3 @@ import type { EJSONOptions } from './extended_json'; | ||
this.pattern = pattern; | ||
this.options = options ?? ''; | ||
// Execute | ||
alphabetize(this.options); | ||
this.options = alphabetize(options ?? ''); | ||
@@ -43,0 +41,0 @@ // Validate options |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3312519
44072