Comparing version 3.0.0 to 3.0.1
@@ -0,1 +1,18 @@ | ||
<a name="3.0.1"></a> | ||
## [3.0.1](https://github.com/mongodb/js-bson/compare/v3.0.0...v3.0.1) (2018-07-12) | ||
### Bug Fixes | ||
* **bson:** normalizedFunctionString handles named functions ([6b49c23](https://github.com/mongodb/js-bson/commit/6b49c23)) | ||
* **rollup:** fixup dist and bundle in Buffer ([3620ef8](https://github.com/mongodb/js-bson/commit/3620ef8)) | ||
### Features | ||
* **bson:** test bson in browser ([223fbdf](https://github.com/mongodb/js-bson/commit/223fbdf)) | ||
* **UintArray:** Adds support for Uint8Arrays ([2a54053](https://github.com/mongodb/js-bson/commit/2a54053)) | ||
<a name="3.0.0"></a> | ||
@@ -2,0 +19,0 @@ # [3.0.0](https://github.com/mongodb/js-bson/compare/v2.0.8...v3.0.0) (2018-06-13) |
45
index.js
@@ -1,46 +0,3 @@ | ||
var BSON = require('./lib/bson/bson'), | ||
Binary = require('./lib/bson/binary'), | ||
Code = require('./lib/bson/code'), | ||
DBRef = require('./lib/bson/db_ref'), | ||
Decimal128 = require('./lib/bson/decimal128'), | ||
Double = require('./lib/bson/double'), | ||
Int32 = require('./lib/bson/int_32'), | ||
Long = require('./lib/bson/long'), | ||
Map = require('./lib/bson/map'), | ||
MaxKey = require('./lib/bson/max_key'), | ||
MinKey = require('./lib/bson/min_key'), | ||
ObjectId = require('./lib/bson/objectid'), | ||
BSONRegExp = require('./lib/bson/regexp'), | ||
Symbol = require('./lib/bson/symbol'), | ||
Timestamp = require('./lib/bson/timestamp'); | ||
var BSON = require('./lib/bson/bson'); | ||
// BSON MAX VALUES | ||
BSON.BSON_INT32_MAX = 0x7fffffff; | ||
BSON.BSON_INT32_MIN = -0x80000000; | ||
BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; | ||
BSON.BSON_INT64_MIN = -Math.pow(2, 63); | ||
// JS MAX PRECISE VALUES | ||
BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. | ||
BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. | ||
// Add BSON types to function creation | ||
BSON.Binary = Binary; | ||
BSON.Code = Code; | ||
BSON.DBRef = DBRef; | ||
BSON.Decimal128 = Decimal128; | ||
BSON.Double = Double; | ||
BSON.Int32 = Int32; | ||
BSON.Long = Long; | ||
BSON.Map = Map; | ||
BSON.MaxKey = MaxKey; | ||
BSON.MinKey = MinKey; | ||
BSON.ObjectId = ObjectId; | ||
BSON.ObjectID = ObjectId; | ||
BSON.BSONRegExp = BSONRegExp; | ||
BSON.Symbol = Symbol; | ||
BSON.Timestamp = Timestamp; | ||
// Return the BSON | ||
module.exports = BSON; |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
/** | ||
@@ -8,8 +10,2 @@ * Module dependencies. | ||
// Test if we're in Node via presence of "global" not absence of "window" | ||
// to support hybrid environments like Electron | ||
if (typeof global !== 'undefined') { | ||
var Buffer = require('buffer').Buffer; // TODO just use global Buffer | ||
} | ||
/** | ||
@@ -16,0 +12,0 @@ * A class representation of the BSON Binary type. |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Map = require('./map'), | ||
@@ -23,2 +24,4 @@ Long = require('./long'), | ||
const ensureBuffer = require('./ensure_buffer'); | ||
/** | ||
@@ -86,3 +89,3 @@ * @ignore | ||
* @param {Object} object the Javascript object to serialize. | ||
* @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Buffer|Uint8Array} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. | ||
@@ -115,2 +118,5 @@ * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. | ||
); | ||
finalBuffer = ensureBuffer(finalBuffer); | ||
buffer.copy(finalBuffer, startIndex, 0, serializationIndex); | ||
@@ -125,3 +131,3 @@ | ||
* | ||
* @param {Buffer} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer|Uint8Array} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. | ||
@@ -140,2 +146,3 @@ * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. | ||
BSON.prototype.deserialize = function(buffer, options) { | ||
buffer = ensureBuffer(buffer); | ||
return deserialize(buffer, options); | ||
@@ -167,3 +174,3 @@ }; | ||
* | ||
* @param {Buffer} data the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer|Uint8Array} data the buffer containing the serialized set of BSON documents. | ||
* @param {Number} startIndex the start index in the data Buffer where the deserialization is to start. | ||
@@ -194,2 +201,3 @@ * @param {Number} numberOfDocuments number of documents to deserialize. | ||
options = Object.assign({ allowObjectSmallerThanBufferSize: true }, options); | ||
data = ensureBuffer(data); | ||
var index = startIndex; | ||
@@ -386,2 +394,3 @@ // Loop over all documents | ||
module.exports.Binary = Binary; | ||
module.exports.ObjectId = ObjectID; | ||
module.exports.ObjectID = ObjectID; | ||
@@ -388,0 +397,0 @@ module.exports.Long = Long; |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
let Long = require('./long'); | ||
@@ -4,0 +5,0 @@ |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
const Long = require('./long'); | ||
@@ -4,0 +5,0 @@ |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
// We have an ES6 Map available, return the native instance | ||
@@ -4,0 +6,0 @@ if (typeof global.Map !== 'undefined') { |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
const hostname = require('os').hostname; | ||
@@ -4,0 +5,0 @@ const fnv1a24 = require('./fnv1a').fnv1a24; |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Long = require('../long').Long, | ||
@@ -4,0 +5,0 @@ Double = require('../double').Double, |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Long = require('../long').Long, | ||
@@ -30,13 +31,13 @@ Double = require('../double').Double, | ||
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) { | ||
throw new Error(`buffer length ${buffer.length} must be >= bson size ${size}`); | ||
if (options.allowObjectSmallerThanBufferSize && Buffer.byteLength(buffer) < size) { | ||
throw new Error(`buffer length ${Buffer.byteLength(buffer)} must be >= bson size ${size}`); | ||
} | ||
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) { | ||
throw new Error(`buffer length ${buffer.length} must === bson size ${size}`); | ||
if (!options.allowObjectSmallerThanBufferSize && Buffer.byteLength(buffer) !== size) { | ||
throw new Error(`buffer length ${Buffer.byteLength(buffer)} must === bson size ${size}`); | ||
} | ||
if (size + index > buffer.length) { | ||
if (size + index > Buffer.byteLength(buffer)) { | ||
throw new Error( | ||
`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer.length})` | ||
`(bson size ${size} + options.index ${index} must be <= buffer length ${Buffer.byteLength(buffer)})` | ||
); | ||
@@ -79,3 +80,3 @@ } | ||
// Validate that we have at least 4 bytes of buffer | ||
if (buffer.length < 5) throw new Error('corrupt bson message < 5 bytes long'); | ||
if (Buffer.byteLength(buffer) < 5) throw new Error('corrupt bson message < 5 bytes long'); | ||
@@ -87,3 +88,3 @@ // Read the document size | ||
// Ensure buffer is valid size | ||
if (size < 5 || size > buffer.length) throw new Error('corrupt bson message'); | ||
if (size < 5 || size > Buffer.byteLength(buffer)) throw new Error('corrupt bson message'); | ||
@@ -107,3 +108,3 @@ // Create holding object | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
i++; | ||
@@ -113,3 +114,3 @@ } | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); | ||
@@ -127,3 +128,3 @@ | ||
stringSize <= 0 || | ||
stringSize > buffer.length - index || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -185,3 +186,3 @@ ) | ||
(buffer[index + 3] << 24); | ||
if (objectSize <= 0 || objectSize > buffer.length - index) | ||
if (objectSize <= 0 || objectSize > Buffer.byteLength(buffer) - index) | ||
throw new Error('bad embedded document length in bson'); | ||
@@ -271,3 +272,3 @@ | ||
// Is the length longer than the document | ||
if (binarySize > buffer.length) throw new Error('Binary type size larger than document size'); | ||
if (binarySize > Buffer.byteLength(buffer)) throw new Error('Binary type size larger than document size'); | ||
@@ -334,7 +335,7 @@ // Decode as raw Buffer object if options specifies it | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -348,7 +349,7 @@ var source = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -381,7 +382,7 @@ var regExpOptions = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -394,7 +395,7 @@ source = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -414,3 +415,3 @@ regExpOptions = buffer.toString('utf8', index, i); | ||
stringSize <= 0 || | ||
stringSize > buffer.length - index || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -447,3 +448,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > buffer.length - index || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -491,3 +492,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > buffer.length - index || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -549,3 +550,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > buffer.length - index || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -552,0 +553,0 @@ ) |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var writeIEEE754 = require('../float_parser').writeIEEE754, | ||
@@ -4,0 +5,0 @@ Long = require('../long').Long, |
@@ -8,3 +8,3 @@ 'use strict'; | ||
function normalizedFunctionString(fn) { | ||
return fn.toString().replace('function(', 'function ('); | ||
return fn.toString().replace(/function(.*)\(/, 'function ('); | ||
} | ||
@@ -11,0 +11,0 @@ |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -26,6 +26,6 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-env": "^1.6.1", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.1.2", | ||
@@ -36,2 +36,7 @@ "conventional-changelog-cli": "^1.3.5", | ||
"istanbul": "^0.4.5", | ||
"karma": "^2.0.4", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-rollup-preprocessor": "^6.0.0", | ||
"mocha": "^3.5.3", | ||
@@ -42,3 +47,5 @@ "prettier": "~1.12.0", | ||
"rollup-plugin-commonjs": "^8.3.0", | ||
"rollup-plugin-json": "^3.0.0", | ||
"rollup-plugin-node-builtins": "^2.1.2", | ||
"rollup-plugin-node-globals": "^1.2.1", | ||
"rollup-plugin-node-resolve": "^3.0.3" | ||
@@ -49,7 +56,11 @@ }, | ||
}, | ||
"main": "./index", | ||
"main": "index.js", | ||
"module": "dist/bson.esm.js", | ||
"browser": { | ||
"./index.js": "./dist/bson.browser.umd.js", | ||
"./dist/bson.esm.js": "./dist/bson.browser.esm.js" | ||
}, | ||
"directories": { | ||
"lib": "./lib/bson" | ||
}, | ||
"browser": "dist/bson.js", | ||
"engines": { | ||
@@ -59,3 +70,5 @@ "node": ">=4.0.0" | ||
"scripts": { | ||
"test": "mocha ./test/node", | ||
"test": "npm run-script test-node && npm run-script test-browser", | ||
"test-node": "mocha ./test/node", | ||
"test-browser": "npm run-script build && karma start", | ||
"build": "rollup -c", | ||
@@ -67,3 +80,6 @@ "lint": "eslint lib test", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"buffer": "^5.1.0" | ||
} | ||
} |
@@ -21,3 +21,3 @@ # BSON parser | ||
```html | ||
<script src="./dist/bson.js"></script> | ||
<script src="./dist/bson.bundle.js"></script> | ||
@@ -95,3 +95,3 @@ <script> | ||
* @param {Object} object the JavaScript object to serialize. | ||
* @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Buffer|Uint8Array} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Boolean} [options.checkKeys=false] the serializer will check if keys are valid. | ||
@@ -133,3 +133,3 @@ * @param {Boolean} [options.serializeFunctions=false] serialize the JavaScript functions. | ||
* `BSON.deserializeStream(buffer, startIndex, numberOfDocuments, documents, docStartIndex, options)` | ||
* @param {Buffer} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer|Uint8Array} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Number} startIndex the start index in the data Buffer where the deserialization is to start. | ||
@@ -172,1 +172,8 @@ * @param {Number} numberOfDocuments number of documents to deserialize. | ||
``` | ||
#### What are the various files in dist? | ||
* `bson.bundle.js` is a bundled up version of the library that is suitable for inclusion in an HTML page via a `<script>` tag. | ||
* `bson.esm.js` is a rolled up version of the library that is suitable for interoperation with bundlers that work better with ES modules. | ||
* `bson.browser.esm.js` is similar to `bson.esm.js` but is ultimately intened for consumers producing browser bundles. It also pulls in any browser specific dependencies/code that may be needed. | ||
* `bson.browser.umd.js` is similar to the source code of this library but is ultimately intened for consumers producing browser bundlers expecting a UMD format. It also pulls in any browser specific dependencies/code that may be needed. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
925993
32
25686
176
1
23
9
+ Addedbuffer@^5.1.0
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedieee754@1.2.1(transitive)