bson 0.4.15 → 0.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY +17 -0
- package/README.md +1 -0
- package/lib/bson/index.js +2 -2
- package/lib/bson/map.js +105 -106
- package/lib/bson/objectid.js +9 -4
- package/lib/bson/parser/deserializer.js +15 -4
- package/lib/bson/parser/serializer.js +3 -0
- package/package.json +1 -1
package/HISTORY
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
0.4.19 2015-10-15
|
|
2
|
+
-----------------
|
|
3
|
+
- Remove all support for bson-ext.
|
|
4
|
+
|
|
5
|
+
0.4.18 2015-10-15
|
|
6
|
+
-----------------
|
|
7
|
+
- ObjectID equality check should return boolean instead of throwing exception for invalid oid string #139
|
|
8
|
+
- add option for deserializing binary into Buffer object #116
|
|
9
|
+
|
|
10
|
+
0.4.17 2015-10-15
|
|
11
|
+
-----------------
|
|
12
|
+
- Validate regexp string for null bytes and throw if there is one.
|
|
13
|
+
|
|
14
|
+
0.4.16 2015-10-07
|
|
15
|
+
-----------------
|
|
16
|
+
- Fixed issue with return statement in Map.js.
|
|
17
|
+
|
|
1
18
|
0.4.15 2015-10-06
|
|
2
19
|
-----------------
|
|
3
20
|
- Exposed Map correctly via index.js file.
|
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ The API consists of two simple methods to serialize/deserialize objects to/from
|
|
|
63
63
|
* **evalFunctions** {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
|
|
64
64
|
* **cacheFunctions** {Boolean, default:false}, cache evaluated functions for reuse.
|
|
65
65
|
* **cacheFunctionsCrc32** {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
|
|
66
|
+
* **promoteBuffers** {Boolean, default:false}, deserialize Binary data directly into node.js Buffer object.
|
|
66
67
|
* @param {TypedArray/Array} a TypedArray/Array containing the BSON data
|
|
67
68
|
* @param {Object} [options] additional options used for the deserialization.
|
|
68
69
|
* @param {Boolean} [isArray] ignore used for recursive parsing.
|
package/lib/bson/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
try {
|
|
2
2
|
exports.BSONPure = require('./bson');
|
|
3
|
-
exports.BSONNative = require('bson
|
|
3
|
+
exports.BSONNative = require('./bson');
|
|
4
4
|
} catch(err) {
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -76,7 +76,7 @@ exports.native = function() {
|
|
|
76
76
|
|
|
77
77
|
// Catch error and return no classes found
|
|
78
78
|
try {
|
|
79
|
-
classes['BSON'] = require('bson
|
|
79
|
+
classes['BSON'] = require('./bson');
|
|
80
80
|
} catch(err) {
|
|
81
81
|
return exports.pure();
|
|
82
82
|
}
|
package/lib/bson/map.js
CHANGED
|
@@ -4,124 +4,123 @@
|
|
|
4
4
|
if(typeof global.Map !== 'undefined') {
|
|
5
5
|
module.exports = global.Map;
|
|
6
6
|
module.exports.Map = global.Map;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this._values[key] = {v: value, i: this._keys.length - 1};
|
|
7
|
+
} else {
|
|
8
|
+
// We will return a polyfill
|
|
9
|
+
var Map = function(array) {
|
|
10
|
+
this._keys = [];
|
|
11
|
+
this._values = {};
|
|
12
|
+
|
|
13
|
+
for(var i = 0; i < array.length; i++) {
|
|
14
|
+
if(array[i] == null) continue; // skip null and undefined
|
|
15
|
+
var entry = array[i];
|
|
16
|
+
var key = entry[0];
|
|
17
|
+
var value = entry[1];
|
|
18
|
+
// Add the key to the list of keys in order
|
|
19
|
+
this._keys.push(key);
|
|
20
|
+
// Add the key and value to the values dictionary with a point
|
|
21
|
+
// to the location in the ordered keys list
|
|
22
|
+
this._values[key] = {v: value, i: this._keys.length - 1};
|
|
23
|
+
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
25
|
+
|
|
26
|
+
Map.prototype.clear = function() {
|
|
27
|
+
this._keys = [];
|
|
28
|
+
this._values = {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Map.prototype.delete = function(key) {
|
|
32
|
+
var value = this._values[key];
|
|
33
|
+
if(value == null) return false;
|
|
34
|
+
// Delete entry
|
|
35
|
+
delete this._values[key];
|
|
36
|
+
// Remove the key from the ordered keys list
|
|
37
|
+
this._keys.splice(value.i, 1);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Map.prototype.entries = function() {
|
|
42
|
+
var self = this;
|
|
43
|
+
var index = 0;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
next: function() {
|
|
47
|
+
var key = self._keys[index++];
|
|
48
|
+
return {
|
|
49
|
+
value: key !== undefined ? [key, self._values[key].v] : undefined,
|
|
50
|
+
done: key !== undefined ? false : true
|
|
51
|
+
}
|
|
53
52
|
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Map.prototype.forEach = function(callback, self) {
|
|
57
|
+
self = self || this;
|
|
58
|
+
|
|
59
|
+
for(var i = 0; i < this._keys.length; i++) {
|
|
60
|
+
var key = this._keys[i];
|
|
61
|
+
// Call the forEach callback
|
|
62
|
+
callback.call(self, this._values[key].v, key, self);
|
|
54
63
|
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
64
|
+
}
|
|
57
65
|
|
|
58
|
-
Map.prototype.
|
|
59
|
-
|
|
66
|
+
Map.prototype.get = function(key) {
|
|
67
|
+
return this._values[key] ? this._values[key].v : undefined;
|
|
68
|
+
}
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Call the forEach callback
|
|
64
|
-
callback.call(self, this._values[key].v, key, self);
|
|
70
|
+
Map.prototype.has = function(key) {
|
|
71
|
+
return this._values[key] != null;
|
|
65
72
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var index = 0;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
next: function() {
|
|
82
|
-
var key = self._keys[index++];
|
|
83
|
-
return {
|
|
84
|
-
value: key !== undefined ? key : undefined,
|
|
85
|
-
done: key !== undefined ? false : true
|
|
73
|
+
|
|
74
|
+
Map.prototype.keys = function(key) {
|
|
75
|
+
var self = this;
|
|
76
|
+
var index = 0;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
next: function() {
|
|
80
|
+
var key = self._keys[index++];
|
|
81
|
+
return {
|
|
82
|
+
value: key !== undefined ? key : undefined,
|
|
83
|
+
done: key !== undefined ? false : true
|
|
84
|
+
}
|
|
86
85
|
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Map.prototype.set = function(key, value) {
|
|
90
|
+
if(this._values[key]) {
|
|
91
|
+
this._values[key].v = value;
|
|
92
|
+
return this;
|
|
87
93
|
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
// Add the key to the list of keys in order
|
|
96
|
+
this._keys.push(key);
|
|
97
|
+
// Add the key and value to the values dictionary with a point
|
|
98
|
+
// to the location in the ordered keys list
|
|
99
|
+
this._values[key] = {v: value, i: this._keys.length - 1};
|
|
94
100
|
return this;
|
|
95
101
|
}
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
next: function() {
|
|
111
|
-
var key = self._keys[index++];
|
|
112
|
-
return {
|
|
113
|
-
value: key !== undefined ? self._values[key].v : undefined,
|
|
114
|
-
done: key !== undefined ? false : true
|
|
103
|
+
Map.prototype.values = function(key, value) {
|
|
104
|
+
var self = this;
|
|
105
|
+
var index = 0;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
next: function() {
|
|
109
|
+
var key = self._keys[index++];
|
|
110
|
+
return {
|
|
111
|
+
value: key !== undefined ? self._values[key].v : undefined,
|
|
112
|
+
done: key !== undefined ? false : true
|
|
113
|
+
}
|
|
115
114
|
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
119
117
|
|
|
120
|
-
// Last ismaster
|
|
121
|
-
Object.defineProperty(Map.prototype, 'size', {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
118
|
+
// Last ismaster
|
|
119
|
+
Object.defineProperty(Map.prototype, 'size', {
|
|
120
|
+
enumerable:true,
|
|
121
|
+
get: function() { return this._keys.length; }
|
|
122
|
+
});
|
|
125
123
|
|
|
126
|
-
module.exports = Map;
|
|
127
|
-
module.exports.Map = Map;
|
|
124
|
+
module.exports = Map;
|
|
125
|
+
module.exports.Map = Map;
|
|
126
|
+
}
|
package/lib/bson/objectid.js
CHANGED
|
@@ -156,10 +156,15 @@ ObjectID.prototype.toJSON = function() {
|
|
|
156
156
|
* @return {boolean} the result of comparing two ObjectID's
|
|
157
157
|
*/
|
|
158
158
|
ObjectID.prototype.equals = function equals (otherID) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
159
|
+
var id;
|
|
160
|
+
|
|
161
|
+
if(otherID != null && (otherID instanceof ObjectID || otherID.toHexString)) {
|
|
162
|
+
id = otherID.id;
|
|
163
|
+
} else if(typeof otherID == 'string' && ObjectID.isValid(otherID)) {
|
|
164
|
+
id = ObjectID.createFromHexString(otherID).id;
|
|
165
|
+
} else {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
163
168
|
|
|
164
169
|
return this.id === id;
|
|
165
170
|
}
|
|
@@ -62,6 +62,7 @@ var deserializeObject = function(buffer, options, isArray) {
|
|
|
62
62
|
var fieldsAsRaw = options['fieldsAsRaw'] == null ? {} : options['fieldsAsRaw'];
|
|
63
63
|
// Return BSONRegExp objects instead of native regular expressions
|
|
64
64
|
var bsonRegExp = typeof options['bsonRegExp'] == 'boolean' ? options['bsonRegExp'] : false;
|
|
65
|
+
var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers'];
|
|
65
66
|
|
|
66
67
|
// Validate that we have at least 4 bytes of buffer
|
|
67
68
|
if(buffer.length < 5) throw new Error("corrupt bson message < 5 bytes long");
|
|
@@ -136,8 +137,13 @@ var deserializeObject = function(buffer, options, isArray) {
|
|
|
136
137
|
if(subType == Binary.SUBTYPE_BYTE_ARRAY) {
|
|
137
138
|
binarySize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
if(promoteBuffers) {
|
|
141
|
+
// assign reference to sliced Buffer object
|
|
142
|
+
object[name] = buffer.slice(index, index + binarySize);
|
|
143
|
+
} else {
|
|
144
|
+
// Slice the data
|
|
145
|
+
object[name] = new Binary(buffer.slice(index, index + binarySize), subType);
|
|
146
|
+
}
|
|
141
147
|
} else {
|
|
142
148
|
var _buffer = typeof Uint8Array != 'undefined' ? new Uint8Array(new ArrayBuffer(binarySize)) : new Array(binarySize);
|
|
143
149
|
// If we have subtype 2 skip the 4 bytes for the size
|
|
@@ -148,8 +154,13 @@ var deserializeObject = function(buffer, options, isArray) {
|
|
|
148
154
|
for(var i = 0; i < binarySize; i++) {
|
|
149
155
|
_buffer[i] = buffer[index + i];
|
|
150
156
|
}
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
if(promoteBuffers) {
|
|
158
|
+
// assign reference to Buffer object
|
|
159
|
+
object[name] = _buffer;
|
|
160
|
+
} else {
|
|
161
|
+
// Create the binary object
|
|
162
|
+
object[name] = new Binary(_buffer, subType);
|
|
163
|
+
}
|
|
153
164
|
}
|
|
154
165
|
// Update the index
|
|
155
166
|
index = index + binarySize;
|
|
@@ -175,6 +175,9 @@ var serializeRegExp = function(buffer, key, value, index) {
|
|
|
175
175
|
// Encode the name
|
|
176
176
|
index = index + numberOfWrittenBytes;
|
|
177
177
|
buffer[index++] = 0;
|
|
178
|
+
if (value.source && value.source.match(regexp) != null) {
|
|
179
|
+
throw Error("value " + value.source + " must not contain null bytes");
|
|
180
|
+
}
|
|
178
181
|
// Adjust the index
|
|
179
182
|
index = index + buffer.write(value.source, index, 'utf8');
|
|
180
183
|
// Write zero
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{ "name" : "bson"
|
|
2
2
|
, "description" : "A bson parser for node.js and the browser"
|
|
3
3
|
, "keywords" : ["mongodb", "bson", "parser"]
|
|
4
|
-
, "version" : "0.4.
|
|
4
|
+
, "version" : "0.4.19"
|
|
5
5
|
, "author" : "Christian Amor Kvalheim <christkv@gmail.com>"
|
|
6
6
|
, "contributors" : []
|
|
7
7
|
|