Skip to content

Commit 6dc72fd

Browse files
committed
fixed doc issues
1 parent 7466134 commit 6dc72fd

File tree

3 files changed

+117
-81
lines changed

3 files changed

+117
-81
lines changed

browser_build/bson.js

+90-81
Original file line numberDiff line numberDiff line change
@@ -7308,7 +7308,8 @@ return /******/ (function(modules) { // webpackBootstrap
73087308
!(function(global) {
73097309
"use strict";
73107310

7311-
var hasOwn = Object.prototype.hasOwnProperty;
7311+
var Op = Object.prototype;
7312+
var hasOwn = Op.hasOwnProperty;
73127313
var undefined; // More compressible than void 0.
73137314
var $Symbol = typeof Symbol === "function" ? Symbol : {};
73147315
var iteratorSymbol = $Symbol.iterator || "@@iterator";
@@ -7380,10 +7381,29 @@ return /******/ (function(modules) { // webpackBootstrap
73807381
function GeneratorFunction() {}
73817382
function GeneratorFunctionPrototype() {}
73827383

7383-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype;
7384+
// This is a polyfill for %IteratorPrototype% for environments that
7385+
// don't natively support it.
7386+
var IteratorPrototype = {};
7387+
IteratorPrototype[iteratorSymbol] = function () {
7388+
return this;
7389+
};
7390+
7391+
var getProto = Object.getPrototypeOf;
7392+
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
7393+
if (NativeIteratorPrototype &&
7394+
NativeIteratorPrototype !== Op &&
7395+
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
7396+
// This environment has a native %IteratorPrototype%; use it instead
7397+
// of the polyfill.
7398+
IteratorPrototype = NativeIteratorPrototype;
7399+
}
7400+
7401+
var Gp = GeneratorFunctionPrototype.prototype =
7402+
Generator.prototype = Object.create(IteratorPrototype);
73847403
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
73857404
GeneratorFunctionPrototype.constructor = GeneratorFunction;
7386-
GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction";
7405+
GeneratorFunctionPrototype[toStringTagSymbol] =
7406+
GeneratorFunction.displayName = "GeneratorFunction";
73877407

73887408
// Helper for defining the .next, .throw, and .return methods of the
73897409
// Iterator interface in terms of a single ._invoke method.
@@ -7420,17 +7440,12 @@ return /******/ (function(modules) { // webpackBootstrap
74207440

74217441
// Within the body of any async function, `await x` is transformed to
74227442
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
7423-
// `value instanceof AwaitArgument` to determine if the yielded value is
7424-
// meant to be awaited. Some may consider the name of this method too
7425-
// cutesy, but they are curmudgeons.
7443+
// `hasOwn.call(value, "__await")` to determine if the yielded value is
7444+
// meant to be awaited.
74267445
runtime.awrap = function(arg) {
7427-
return new AwaitArgument(arg);
7446+
return { __await: arg };
74287447
};
74297448

7430-
function AwaitArgument(arg) {
7431-
this.arg = arg;
7432-
}
7433-
74347449
function AsyncIterator(generator) {
74357450
function invoke(method, arg, resolve, reject) {
74367451
var record = tryCatch(generator[method], generator, arg);
@@ -7439,8 +7454,10 @@ return /******/ (function(modules) { // webpackBootstrap
74397454
} else {
74407455
var result = record.arg;
74417456
var value = result.value;
7442-
if (value instanceof AwaitArgument) {
7443-
return Promise.resolve(value.arg).then(function(value) {
7457+
if (value &&
7458+
typeof value === "object" &&
7459+
hasOwn.call(value, "__await")) {
7460+
return Promise.resolve(value.__await).then(function(value) {
74447461
invoke("next", value, resolve, reject);
74457462
}, function(err) {
74467463
invoke("throw", err, resolve, reject);
@@ -7509,6 +7526,7 @@ return /******/ (function(modules) { // webpackBootstrap
75097526
}
75107527

75117528
defineIteratorMethods(AsyncIterator.prototype);
7529+
runtime.AsyncIterator = AsyncIterator;
75127530

75137531
// Note that simple async functions are implemented on top of
75147532
// AsyncIterator objects; they just return a Promise for the value of
@@ -7669,10 +7687,6 @@ return /******/ (function(modules) { // webpackBootstrap
76697687
// unified ._invoke helper method.
76707688
defineIteratorMethods(Gp);
76717689

7672-
Gp[iteratorSymbol] = function() {
7673-
return this;
7674-
};
7675-
76767690
Gp[toStringTagSymbol] = "Generator";
76777691

76787692
Gp.toString = function() {
@@ -8291,11 +8305,6 @@ return /******/ (function(modules) { // webpackBootstrap
82918305
var serializeFunctions = typeof options.serializeFunctions == 'boolean' ? options.serializeFunctions : false;
82928306
var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : true;
82938307

8294-
// console.log("===================================== serialize")
8295-
// console.log("checkKeys = " + checkKeys)
8296-
// console.log("serializeFunctions = " + serializeFunctions)
8297-
// console.log("ignoreUndefined = " + ignoreUndefined)
8298-
82998308
// Attempt to serialize
83008309
var serializationIndex = serializer(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
83018310
// Create the final buffer
@@ -8326,12 +8335,6 @@ return /******/ (function(modules) { // webpackBootstrap
83268335
var ignoreUndefined = typeof options.ignoreUndefined == 'boolean' ? options.ignoreUndefined : true;
83278336
var startIndex = typeof options.index == 'number' ? options.index : 0;
83288337

8329-
// console.log("===================================== serializeWithBufferAndIndex")
8330-
// console.log("checkKeys = " + checkKeys)
8331-
// console.log("serializeFunctions = " + serializeFunctions)
8332-
// console.log("ignoreUndefined = " + ignoreUndefined)
8333-
// console.log("startIndex = " + startIndex)
8334-
83358338
// Attempt to serialize
83368339
var serializationIndex = serializer(buffer, object, checkKeys, startIndex || 0, 0, serializeFunctions, ignoreUndefined);
83378340
buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
@@ -8343,20 +8346,20 @@ return /******/ (function(modules) { // webpackBootstrap
83438346
/**
83448347
* Deserialize data as BSON.
83458348
*
8346-
* Options
8347-
* - **evalFunctions** {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
8348-
* - **cacheFunctions** {Boolean, default:false}, cache evaluated functions for reuse.
8349-
* - **cacheFunctionsCrc32** {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
8350-
* - **promoteLongs** {Boolean, default:true}, when deserializing a Long will fit it into a Number if it's smaller than 53 bits
8351-
*
83528349
* @param {Buffer} buffer the buffer containing the serialized set of BSON documents.
8353-
* @param {Object} [options] additional options used for the deserialization.
8354-
* @param {Boolean} [isArray] ignore used for recursive parsing.
8350+
* @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.
8351+
* @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.
8352+
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
8353+
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
8354+
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
8355+
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
8356+
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
8357+
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
83558358
* @return {Object} returns the deserialized Javascript Object.
83568359
* @api public
83578360
*/
8358-
BSON.prototype.deserialize = function (data, options) {
8359-
return deserialize(data, options);
8361+
BSON.prototype.deserialize = function (buffer, options) {
8362+
return deserialize(buffer, options);
83608363
};
83618364

83628365
/**
@@ -8380,23 +8383,24 @@ return /******/ (function(modules) { // webpackBootstrap
83808383
/**
83818384
* Deserialize stream data as BSON documents.
83828385
*
8383-
* Options
8384-
* - **evalFunctions** {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
8385-
* - **cacheFunctions** {Boolean, default:false}, cache evaluated functions for reuse.
8386-
* - **cacheFunctionsCrc32** {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
8387-
* - **promoteLongs** {Boolean, default:true}, when deserializing a Long will fit it into a Number if it's smaller than 53 bits
8388-
*
83898386
* @param {Buffer} data the buffer containing the serialized set of BSON documents.
83908387
* @param {Number} startIndex the start index in the data Buffer where the deserialization is to start.
83918388
* @param {Number} numberOfDocuments number of documents to deserialize.
83928389
* @param {Array} documents an array where to store the deserialized documents.
83938390
* @param {Number} docStartIndex the index in the documents array from where to start inserting documents.
83948391
* @param {Object} [options] additional options used for the deserialization.
8392+
* @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.
8393+
* @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.
8394+
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
8395+
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
8396+
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
8397+
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
8398+
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
8399+
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
83958400
* @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents.
83968401
* @api public
83978402
*/
83988403
BSON.prototype.deserializeStream = function (data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
8399-
// if(numberOfDocuments !== documents.length) throw new Error("Number of expected results back is less than the number of documents");
84008404
options = options != null ? options : {};
84018405
var index = startIndex;
84028406
// Loop over all documents
@@ -8603,7 +8607,7 @@ return /******/ (function(modules) { // webpackBootstrap
86038607
/* 300 */
86048608
/***/ function(module, exports, __webpack_require__) {
86058609

8606-
/* WEBPACK VAR INJECTION */(function(Buffer, global) {/*!
8610+
/* WEBPACK VAR INJECTION */(function(global) {/*!
86078611
* The buffer module from node.js, for the browser.
86088612
*
86098613
* @author Feross Aboukhadijeh <[email protected]> <http://feross.org>
@@ -10393,7 +10397,7 @@ return /******/ (function(modules) { // webpackBootstrap
1039310397
return val !== val // eslint-disable-line no-self-compare
1039410398
}
1039510399

10396-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(300).Buffer, (function() { return this; }())))
10400+
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
1039710401

1039810402
/***/ },
1039910403
/* 301 */
@@ -12626,7 +12630,7 @@ return /******/ (function(modules) { // webpackBootstrap
1262612630
/* 309 */
1262712631
/***/ function(module, exports, __webpack_require__) {
1262812632

12629-
/* WEBPACK VAR INJECTION */(function(process, Buffer) {/**
12633+
/* WEBPACK VAR INJECTION */(function(Buffer, process) {/**
1263012634
* Machine id.
1263112635
*
1263212636
* Create a random 3-byte value (i.e. unique for this
@@ -12638,6 +12642,12 @@ return /******/ (function(modules) { // webpackBootstrap
1263812642

1263912643
// Regular expression that checks for hex value
1264012644
var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
12645+
var hasBufferType = false;
12646+
12647+
// Check if buffer exists
12648+
try {
12649+
if (Buffer && Buffer.from) hasBufferType = true;
12650+
} catch (err) {};
1264112651

1264212652
/**
1264312653
* Create a new ObjectID instance
@@ -12654,17 +12664,26 @@ return /******/ (function(modules) { // webpackBootstrap
1265412664

1265512665
this._bsontype = 'ObjectID';
1265612666

12657-
var __id = null;
12667+
// The most common usecase (blank id, new objectId instance)
12668+
if (id == null || typeof id == 'number') {
12669+
// Generate a new id
12670+
this.id = this.generate(id);
12671+
// If we are caching the hex string
12672+
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
12673+
// Return the object
12674+
return;
12675+
}
12676+
12677+
// Check if the passed in id is valid
1265812678
var valid = ObjectID.isValid(id);
1265912679

1266012680
// Throw an error if it's not a valid setup
1266112681
if (!valid && id != null) {
1266212682
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
12683+
} else if (valid && typeof id == 'string' && id.length == 24 && hasBufferType) {
12684+
return new ObjectID(new Buffer(id, 'hex'));
1266312685
} else if (valid && typeof id == 'string' && id.length == 24) {
1266412686
return ObjectID.createFromHexString(id);
12665-
} else if (id == null || typeof id == 'number') {
12666-
// convert to 12 byte binary string
12667-
this.id = this.generate(id);
1266812687
} else if (id != null && id.length === 12) {
1266912688
// assume 12 byte string
1267012689
this.id = id;
@@ -12675,7 +12694,7 @@ return /******/ (function(modules) { // webpackBootstrap
1267512694
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
1267612695
}
1267712696

12678-
if (ObjectID.cacheHexString) this.__id = this.toHexString();
12697+
if (ObjectID.cacheHexString) this.__id = this.toString('hex');
1267912698
};
1268012699

1268112700
// Allow usage of ObjectId as well as ObjectID
@@ -12777,10 +12796,17 @@ return /******/ (function(modules) { // webpackBootstrap
1277712796
/**
1277812797
* Converts the id into a 24 byte hex string for printing
1277912798
*
12799+
* @param {String} format The Buffer toString format parameter.
1278012800
* @return {String} return the 24 byte hex string representation.
1278112801
* @ignore
1278212802
*/
12783-
ObjectID.prototype.toString = function () {
12803+
ObjectID.prototype.toString = function (format) {
12804+
// Is the id a buffer then use the buffer toString method to return the format
12805+
if (this.id && this.id.copy) {
12806+
return this.id.toString(typeof format === 'string' ? format : 'hex');
12807+
}
12808+
12809+
// if(this.buffer )
1278412810
return this.toHexString();
1278512811
};
1278612812

@@ -12891,21 +12917,19 @@ return /******/ (function(modules) { // webpackBootstrap
1289112917
*/
1289212918
ObjectID.createFromHexString = function createFromHexString(string) {
1289312919
// Throw an error if it's not a valid setup
12894-
if (typeof string === 'undefined' || string != null && string.length != 24) throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
12895-
12896-
var length = string.length;
12897-
12898-
if (length > 12 * 2) {
12899-
throw new Error('Id cannot be longer than 12 bytes');
12920+
if (typeof string === 'undefined' || string != null && string.length != 24) {
12921+
throw new Error("Argument passed in must be a single String of 12 bytes or a string of 24 hex characters");
1290012922
}
1290112923

12924+
// Use Buffer.from method if available
12925+
if (hasBufferType) return new ObjectID(new Buffer(string, 'hex'));
12926+
1290212927
// Calculate lengths
12903-
var sizeof = length >> 1;
12904-
var array = new _Buffer(sizeof);
12928+
var array = new _Buffer(12);
1290512929
var n = 0;
1290612930
var i = 0;
1290712931

12908-
while (i < length) {
12932+
while (i < 24) {
1290912933
array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)];
1291012934
}
1291112935

@@ -12968,7 +12992,7 @@ return /******/ (function(modules) { // webpackBootstrap
1296812992
module.exports = ObjectID;
1296912993
module.exports.ObjectID = ObjectID;
1297012994
module.exports.ObjectId = ObjectID;
12971-
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(294), __webpack_require__(300).Buffer))
12995+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(300).Buffer, __webpack_require__(294)))
1297212996

1297312997
/***/ },
1297412998
/* 310 */
@@ -15683,17 +15707,6 @@ return /******/ (function(modules) { // webpackBootstrap
1568315707
return index;
1568415708
};
1568515709

15686-
var serializeUndefined = function (buffer, key, value, index, isArray) {
15687-
// Set long type
15688-
buffer[index++] = BSON.BSON_DATA_UNDEFINED;
15689-
// Number of written bytes
15690-
var numberOfWrittenBytes = !isArray ? buffer.write(key, index, 'utf8') : buffer.write(key, index, 'ascii');
15691-
// Encode the name
15692-
index = index + numberOfWrittenBytes;
15693-
buffer[index++] = 0;
15694-
return index;
15695-
};
15696-
1569715710
var serializeNull = function (buffer, key, value, index, isArray) {
1569815711
// Set long type
1569915712
buffer[index++] = BSON.BSON_DATA_NULL;
@@ -16252,9 +16265,7 @@ return /******/ (function(modules) { // webpackBootstrap
1625216265
index = serializeBoolean(buffer, key, value, index);
1625316266
} else if (value instanceof Date || isDate(value)) {
1625416267
index = serializeDate(buffer, key, value, index);
16255-
} else if (value === undefined && ignoreUndefined == true) {} else if (value === undefined) {
16256-
index = serializeUndefined(buffer, key, value, index);
16257-
} else if (value === null) {
16268+
} else if (value === undefined && ignoreUndefined == true) {} else if (value === null || value === undefined) {
1625816269
index = serializeNull(buffer, key, value, index);
1625916270
} else if (value['_bsontype'] == 'ObjectID') {
1626016271
index = serializeObjectId(buffer, key, value, index);
@@ -16333,9 +16344,7 @@ return /******/ (function(modules) { // webpackBootstrap
1633316344
index = serializeBoolean(buffer, key, value, index);
1633416345
} else if (value instanceof Date || isDate(value)) {
1633516346
index = serializeDate(buffer, key, value, index);
16336-
} else if (value === undefined && ignoreUndefined == true) {} else if (value === undefined) {
16337-
index = serializeUndefined(buffer, key, value, index);
16338-
} else if (value === null) {
16347+
} else if (value === undefined && ignoreUndefined == true) {} else if (value === null || value === undefined) {
1633916348
index = serializeNull(buffer, key, value, index);
1634016349
} else if (value['_bsontype'] == 'ObjectID') {
1634116350
index = serializeObjectId(buffer, key, value, index);

lib/bson/decimal128.js

+20
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,25 @@ var int32toHex = function(value) {
122122
return buffer.reverse().toString('hex');
123123
}
124124

125+
/**
126+
* A class representation of the BSON Decimal128 type.
127+
*
128+
* @class
129+
* @param {Buffer} bytes a buffer containing the raw Decimal128 bytes.
130+
* @return {Double}
131+
*/
125132
var Decimal128 = function(bytes) {
126133
this._bsontype = 'Decimal128';
127134
this.bytes = bytes;
128135
}
129136

137+
/**
138+
* Create a Decimal128 instance from a string representation
139+
*
140+
* @method
141+
* @param {string} string a numeric string representation.
142+
* @return {Decimal128} returns a Decimal128 instance.
143+
*/
130144
Decimal128.fromString = function(string) {
131145
// Parse state tracking
132146
var isNegative = false;
@@ -515,6 +529,12 @@ var COMBINATION_SNAN = 32;
515529
// decimal128 exponent bias
516530
var EXPONENT_BIAS = 6176;
517531

532+
/**
533+
* Create a string representation of the raw Decimal128 value
534+
*
535+
* @method
536+
* @return {string} returns a Decimal128 string representation.
537+
*/
518538
Decimal128.prototype.toString = function() {
519539
// Note: bits in this routine are referred to starting at 0,
520540
// from the sign bit, towards the coefficient.

0 commit comments

Comments
 (0)