bson
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -1,3 +0,3 @@ | ||
<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) | ||
<a name="3.0.2"></a> | ||
## [3.0.2](https://github.com/mongodb/js-bson/compare/v3.0.1...v3.0.2) (2018-07-13) | ||
@@ -7,13 +7,6 @@ | ||
* **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)) | ||
* **revert:** Reverting v3.0.1 ([efb0720](https://github.com/mongodb/js-bson/commit/efb0720)) | ||
### 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> | ||
@@ -20,0 +13,0 @@ # [3.0.0](https://github.com/mongodb/js-bson/compare/v2.0.8...v3.0.0) (2018-06-13) |
45
index.js
@@ -1,3 +0,46 @@ | ||
var BSON = require('./lib/bson/bson'); | ||
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'); | ||
// 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; | ||
/** | ||
@@ -10,2 +8,8 @@ * 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 | ||
} | ||
/** | ||
@@ -12,0 +16,0 @@ * A class representation of the BSON Binary type. |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Map = require('./map'), | ||
@@ -24,4 +23,2 @@ Long = require('./long'), | ||
const ensureBuffer = require('./ensure_buffer'); | ||
/** | ||
@@ -89,3 +86,3 @@ * @ignore | ||
* @param {Object} object the Javascript object to serialize. | ||
* @param {Buffer|Uint8Array} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. | ||
@@ -118,5 +115,2 @@ * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. | ||
); | ||
finalBuffer = ensureBuffer(finalBuffer); | ||
buffer.copy(finalBuffer, startIndex, 0, serializationIndex); | ||
@@ -131,3 +125,3 @@ | ||
* | ||
* @param {Buffer|Uint8Array} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer} 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. | ||
@@ -146,3 +140,2 @@ * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. | ||
BSON.prototype.deserialize = function(buffer, options) { | ||
buffer = ensureBuffer(buffer); | ||
return deserialize(buffer, options); | ||
@@ -174,3 +167,3 @@ }; | ||
* | ||
* @param {Buffer|Uint8Array} data the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer} 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. | ||
@@ -201,3 +194,2 @@ * @param {Number} numberOfDocuments number of documents to deserialize. | ||
options = Object.assign({ allowObjectSmallerThanBufferSize: true }, options); | ||
data = ensureBuffer(data); | ||
var index = startIndex; | ||
@@ -394,3 +386,2 @@ // Loop over all documents | ||
module.exports.Binary = Binary; | ||
module.exports.ObjectId = ObjectID; | ||
module.exports.ObjectID = ObjectID; | ||
@@ -397,0 +388,0 @@ module.exports.Long = Long; |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
let Long = require('./long'); | ||
@@ -5,0 +4,0 @@ |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
const Long = require('./long'); | ||
@@ -5,0 +4,0 @@ |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
// We have an ES6 Map available, return the native instance | ||
@@ -6,0 +4,0 @@ if (typeof global.Map !== 'undefined') { |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
const hostname = require('os').hostname; | ||
@@ -5,0 +4,0 @@ const fnv1a24 = require('./fnv1a').fnv1a24; |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Long = require('../long').Long, | ||
@@ -5,0 +4,0 @@ Double = require('../double').Double, |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var Long = require('../long').Long, | ||
@@ -31,13 +30,13 @@ Double = require('../double').Double, | ||
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 be >= bson size ${size}`); | ||
} | ||
if (!options.allowObjectSmallerThanBufferSize && Buffer.byteLength(buffer) !== size) { | ||
throw new Error(`buffer length ${Buffer.byteLength(buffer)} must === bson size ${size}`); | ||
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) { | ||
throw new Error(`buffer length ${buffer.length} must === bson size ${size}`); | ||
} | ||
if (size + index > Buffer.byteLength(buffer)) { | ||
if (size + index > buffer.length) { | ||
throw new Error( | ||
`(bson size ${size} + options.index ${index} must be <= buffer length ${Buffer.byteLength(buffer)})` | ||
`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer.length})` | ||
); | ||
@@ -80,3 +79,3 @@ } | ||
// Validate that we have at least 4 bytes of buffer | ||
if (Buffer.byteLength(buffer) < 5) throw new Error('corrupt bson message < 5 bytes long'); | ||
if (buffer.length < 5) throw new Error('corrupt bson message < 5 bytes long'); | ||
@@ -88,3 +87,3 @@ // Read the document size | ||
// Ensure buffer is valid size | ||
if (size < 5 || size > Buffer.byteLength(buffer)) throw new Error('corrupt bson message'); | ||
if (size < 5 || size > buffer.length) throw new Error('corrupt bson message'); | ||
@@ -108,3 +107,3 @@ // Create holding object | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
i++; | ||
@@ -114,3 +113,3 @@ } | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); | ||
@@ -128,3 +127,3 @@ | ||
stringSize <= 0 || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
stringSize > buffer.length - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -186,3 +185,3 @@ ) | ||
(buffer[index + 3] << 24); | ||
if (objectSize <= 0 || objectSize > Buffer.byteLength(buffer) - index) | ||
if (objectSize <= 0 || objectSize > buffer.length - index) | ||
throw new Error('bad embedded document length in bson'); | ||
@@ -272,3 +271,3 @@ | ||
// Is the length longer than the document | ||
if (binarySize > Buffer.byteLength(buffer)) throw new Error('Binary type size larger than document size'); | ||
if (binarySize > buffer.length) throw new Error('Binary type size larger than document size'); | ||
@@ -335,7 +334,7 @@ // Decode as raw Buffer object if options specifies it | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -349,7 +348,7 @@ var source = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -382,7 +381,7 @@ var regExpOptions = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -395,7 +394,7 @@ source = buffer.toString('utf8', index, i); | ||
// Locate the end of the c string | ||
while (buffer[i] !== 0x00 && i < Buffer.byteLength(buffer)) { | ||
while (buffer[i] !== 0x00 && i < buffer.length) { | ||
i++; | ||
} | ||
// If are at the end of the buffer there is a problem with the document | ||
if (i >= Buffer.byteLength(buffer)) throw new Error('Bad BSON Document: illegal CString'); | ||
if (i >= buffer.length) throw new Error('Bad BSON Document: illegal CString'); | ||
// Return the C string | ||
@@ -415,3 +414,3 @@ regExpOptions = buffer.toString('utf8', index, i); | ||
stringSize <= 0 || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
stringSize > buffer.length - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -448,3 +447,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
stringSize > buffer.length - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -492,3 +491,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
stringSize > buffer.length - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -550,3 +549,3 @@ ) | ||
stringSize <= 0 || | ||
stringSize > Buffer.byteLength(buffer) - index || | ||
stringSize > buffer.length - index || | ||
buffer[index + stringSize - 1] !== 0 | ||
@@ -553,0 +552,0 @@ ) |
'use strict'; | ||
const Buffer = require('buffer').Buffer; | ||
var writeIEEE754 = require('../float_parser').writeIEEE754, | ||
@@ -5,0 +4,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.1", | ||
"version": "3.0.2", | ||
"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.1", | ||
"benchmark": "^2.1.4", | ||
"babel-preset-env": "^1.6.0", | ||
"chai": "^4.1.2", | ||
@@ -36,7 +36,2 @@ "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", | ||
@@ -47,5 +42,3 @@ "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" | ||
@@ -56,11 +49,7 @@ }, | ||
}, | ||
"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" | ||
}, | ||
"main": "./index", | ||
"directories": { | ||
"lib": "./lib/bson" | ||
}, | ||
"browser": "dist/bson.js", | ||
"engines": { | ||
@@ -70,5 +59,3 @@ "node": ">=4.0.0" | ||
"scripts": { | ||
"test": "npm run-script test-node && npm run-script test-browser", | ||
"test-node": "mocha ./test/node", | ||
"test-browser": "npm run-script build && karma start", | ||
"test": "mocha ./test/node", | ||
"build": "rollup -c", | ||
@@ -80,6 +67,3 @@ "lint": "eslint lib test", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"dependencies": { | ||
"buffer": "^5.1.0" | ||
} | ||
} |
@@ -21,3 +21,3 @@ # BSON parser | ||
```html | ||
<script src="./dist/bson.bundle.js"></script> | ||
<script src="./dist/bson.js"></script> | ||
@@ -95,3 +95,3 @@ <script> | ||
* @param {Object} object the JavaScript object to serialize. | ||
* @param {Buffer|Uint8Array} buffer the Buffer you pre-allocated to store the serialized BSON object. | ||
* @param {Buffer} 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|Uint8Array} buffer the buffer containing the serialized set of BSON documents. | ||
* @param {Buffer} 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,8 +172,1 @@ * @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. |
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
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
0
16
3
418690
28
11580
169
- Removedbuffer@^5.1.0
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedieee754@1.2.1(transitive)