bson 4.0.4 → 4.2.2
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.md +56 -1
- package/README.md +7 -9
- package/bower.json +1 -1
- package/bson.d.ts +983 -0
- package/dist/bson.browser.esm.js +7261 -5004
- package/dist/bson.browser.esm.js.map +1 -0
- package/dist/bson.browser.umd.js +7319 -5099
- package/dist/bson.browser.umd.js.map +1 -0
- package/dist/bson.bundle.js +8168 -9216
- package/dist/bson.bundle.js.map +1 -0
- package/dist/bson.esm.js +5643 -5409
- package/dist/bson.esm.js.map +1 -0
- package/etc/prepare.js +19 -0
- package/lib/binary.js +194 -377
- package/lib/binary.js.map +1 -0
- package/lib/bson.js +200 -243
- package/lib/bson.js.map +1 -0
- package/lib/code.js +36 -39
- package/lib/code.js.map +1 -0
- package/lib/constants.js +78 -203
- package/lib/constants.js.map +1 -0
- package/lib/db_ref.js +79 -79
- package/lib/db_ref.js.map +1 -0
- package/lib/decimal128.js +647 -760
- package/lib/decimal128.js.map +1 -0
- package/lib/double.js +61 -58
- package/lib/double.js.map +1 -0
- package/lib/ensure_buffer.js +22 -18
- package/lib/ensure_buffer.js.map +1 -0
- package/lib/extended_json.js +305 -322
- package/lib/extended_json.js.map +1 -0
- package/lib/float_parser.js +98 -104
- package/lib/float_parser.js.map +1 -0
- package/lib/int_32.js +45 -47
- package/lib/int_32.js.map +1 -0
- package/lib/long.js +876 -16
- package/lib/long.js.map +1 -0
- package/lib/map.js +123 -124
- package/lib/map.js.map +1 -0
- package/lib/max_key.js +21 -23
- package/lib/max_key.js.map +1 -0
- package/lib/min_key.js +21 -23
- package/lib/min_key.js.map +1 -0
- package/lib/objectid.js +264 -382
- package/lib/objectid.js.map +1 -0
- package/lib/parser/calculate_size.js +185 -224
- package/lib/parser/calculate_size.js.map +1 -0
- package/lib/parser/deserializer.js +543 -620
- package/lib/parser/deserializer.js.map +1 -0
- package/lib/parser/serializer.js +774 -918
- package/lib/parser/serializer.js.map +1 -0
- package/lib/parser/utils.js +81 -30
- package/lib/parser/utils.js.map +1 -0
- package/lib/regexp.js +54 -70
- package/lib/regexp.js.map +1 -0
- package/lib/symbol.js +40 -56
- package/lib/symbol.js.map +1 -0
- package/lib/timestamp.js +70 -95
- package/lib/timestamp.js.map +1 -0
- package/lib/uuid.js +48 -0
- package/lib/uuid.js.map +1 -0
- package/lib/validate_utf8.js +32 -33
- package/lib/validate_utf8.js.map +1 -0
- package/package.json +53 -31
- package/src/binary.ts +270 -0
- package/src/bson.ts +326 -0
- package/src/code.ts +57 -0
- package/src/constants.ts +104 -0
- package/src/db_ref.ts +115 -0
- package/src/decimal128.ts +801 -0
- package/src/double.ts +85 -0
- package/src/ensure_buffer.ts +26 -0
- package/src/extended_json.ts +395 -0
- package/src/float_parser.ts +152 -0
- package/src/int_32.ts +64 -0
- package/src/long.ts +1000 -0
- package/src/map.ts +139 -0
- package/src/max_key.ts +33 -0
- package/src/min_key.ts +33 -0
- package/src/objectid.ts +377 -0
- package/src/parser/calculate_size.ts +230 -0
- package/src/parser/deserializer.ts +655 -0
- package/src/parser/serializer.ts +1069 -0
- package/src/parser/utils.ts +93 -0
- package/src/regexp.ts +92 -0
- package/src/symbol.ts +57 -0
- package/src/timestamp.ts +103 -0
- package/src/uuid.ts +57 -0
- package/src/validate_utf8.ts +47 -0
- package/lib/fnv1a.js +0 -48
package/lib/bson.js
CHANGED
|
@@ -1,279 +1,236 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeStream = exports.calculateObjectSize = exports.deserialize = exports.serializeWithBufferAndIndex = exports.serialize = exports.setInternalBufferSize = exports.ObjectID = exports.Decimal128 = exports.BSONRegExp = exports.MaxKey = exports.MinKey = exports.Int32 = exports.Double = exports.Timestamp = exports.Long = exports.ObjectId = exports.Binary = exports.DBRef = exports.BSONSymbol = exports.Map = exports.Code = exports.LongWithoutOverridesClass = exports.EJSON = exports.BSON_INT64_MIN = exports.BSON_INT64_MAX = exports.BSON_INT32_MIN = exports.BSON_INT32_MAX = exports.BSON_DATA_UNDEFINED = exports.BSON_DATA_TIMESTAMP = exports.BSON_DATA_SYMBOL = exports.BSON_DATA_STRING = exports.BSON_DATA_REGEXP = exports.BSON_DATA_OID = exports.BSON_DATA_OBJECT = exports.BSON_DATA_NUMBER = exports.BSON_DATA_NULL = exports.BSON_DATA_MIN_KEY = exports.BSON_DATA_MAX_KEY = exports.BSON_DATA_LONG = exports.BSON_DATA_INT = exports.BSON_DATA_DECIMAL128 = exports.BSON_DATA_DBPOINTER = exports.BSON_DATA_DATE = exports.BSON_DATA_CODE_W_SCOPE = exports.BSON_DATA_CODE = exports.BSON_DATA_BOOLEAN = exports.BSON_DATA_BINARY = exports.BSON_DATA_ARRAY = exports.BSON_BINARY_SUBTYPE_UUID_NEW = exports.BSON_BINARY_SUBTYPE_UUID = exports.BSON_BINARY_SUBTYPE_USER_DEFINED = exports.BSON_BINARY_SUBTYPE_MD5 = exports.BSON_BINARY_SUBTYPE_FUNCTION = exports.BSON_BINARY_SUBTYPE_DEFAULT = exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
const binary_1 = require("./binary");
|
|
6
|
+
Object.defineProperty(exports, "Binary", { enumerable: true, get: function () { return binary_1.Binary; } });
|
|
7
|
+
const code_1 = require("./code");
|
|
8
|
+
Object.defineProperty(exports, "Code", { enumerable: true, get: function () { return code_1.Code; } });
|
|
9
|
+
const db_ref_1 = require("./db_ref");
|
|
10
|
+
Object.defineProperty(exports, "DBRef", { enumerable: true, get: function () { return db_ref_1.DBRef; } });
|
|
11
|
+
const decimal128_1 = require("./decimal128");
|
|
12
|
+
Object.defineProperty(exports, "Decimal128", { enumerable: true, get: function () { return decimal128_1.Decimal128; } });
|
|
13
|
+
const double_1 = require("./double");
|
|
14
|
+
Object.defineProperty(exports, "Double", { enumerable: true, get: function () { return double_1.Double; } });
|
|
15
|
+
const ensure_buffer_1 = require("./ensure_buffer");
|
|
16
|
+
const extended_json_1 = require("./extended_json");
|
|
17
|
+
const int_32_1 = require("./int_32");
|
|
18
|
+
Object.defineProperty(exports, "Int32", { enumerable: true, get: function () { return int_32_1.Int32; } });
|
|
19
|
+
const long_1 = require("./long");
|
|
20
|
+
Object.defineProperty(exports, "Long", { enumerable: true, get: function () { return long_1.Long; } });
|
|
21
|
+
const map_1 = require("./map");
|
|
22
|
+
Object.defineProperty(exports, "Map", { enumerable: true, get: function () { return map_1.Map; } });
|
|
23
|
+
const max_key_1 = require("./max_key");
|
|
24
|
+
Object.defineProperty(exports, "MaxKey", { enumerable: true, get: function () { return max_key_1.MaxKey; } });
|
|
25
|
+
const min_key_1 = require("./min_key");
|
|
26
|
+
Object.defineProperty(exports, "MinKey", { enumerable: true, get: function () { return min_key_1.MinKey; } });
|
|
27
|
+
const objectid_1 = require("./objectid");
|
|
28
|
+
Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return objectid_1.ObjectId; } });
|
|
29
|
+
Object.defineProperty(exports, "ObjectID", { enumerable: true, get: function () { return objectid_1.ObjectId; } });
|
|
30
|
+
const calculate_size_1 = require("./parser/calculate_size");
|
|
21
31
|
// Parts of the parser
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const deserializer_1 = require("./parser/deserializer");
|
|
33
|
+
const serializer_1 = require("./parser/serializer");
|
|
34
|
+
const regexp_1 = require("./regexp");
|
|
35
|
+
Object.defineProperty(exports, "BSONRegExp", { enumerable: true, get: function () { return regexp_1.BSONRegExp; } });
|
|
36
|
+
const symbol_1 = require("./symbol");
|
|
37
|
+
Object.defineProperty(exports, "BSONSymbol", { enumerable: true, get: function () { return symbol_1.BSONSymbol; } });
|
|
38
|
+
const timestamp_1 = require("./timestamp");
|
|
39
|
+
Object.defineProperty(exports, "Timestamp", { enumerable: true, get: function () { return timestamp_1.Timestamp; } });
|
|
40
|
+
var constants_1 = require("./constants");
|
|
41
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_BYTE_ARRAY", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_BYTE_ARRAY; } });
|
|
42
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_DEFAULT", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_DEFAULT; } });
|
|
43
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_FUNCTION", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_FUNCTION; } });
|
|
44
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_MD5", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_MD5; } });
|
|
45
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_USER_DEFINED", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_USER_DEFINED; } });
|
|
46
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_UUID; } });
|
|
47
|
+
Object.defineProperty(exports, "BSON_BINARY_SUBTYPE_UUID_NEW", { enumerable: true, get: function () { return constants_1.BSON_BINARY_SUBTYPE_UUID_NEW; } });
|
|
48
|
+
Object.defineProperty(exports, "BSON_DATA_ARRAY", { enumerable: true, get: function () { return constants_1.BSON_DATA_ARRAY; } });
|
|
49
|
+
Object.defineProperty(exports, "BSON_DATA_BINARY", { enumerable: true, get: function () { return constants_1.BSON_DATA_BINARY; } });
|
|
50
|
+
Object.defineProperty(exports, "BSON_DATA_BOOLEAN", { enumerable: true, get: function () { return constants_1.BSON_DATA_BOOLEAN; } });
|
|
51
|
+
Object.defineProperty(exports, "BSON_DATA_CODE", { enumerable: true, get: function () { return constants_1.BSON_DATA_CODE; } });
|
|
52
|
+
Object.defineProperty(exports, "BSON_DATA_CODE_W_SCOPE", { enumerable: true, get: function () { return constants_1.BSON_DATA_CODE_W_SCOPE; } });
|
|
53
|
+
Object.defineProperty(exports, "BSON_DATA_DATE", { enumerable: true, get: function () { return constants_1.BSON_DATA_DATE; } });
|
|
54
|
+
Object.defineProperty(exports, "BSON_DATA_DBPOINTER", { enumerable: true, get: function () { return constants_1.BSON_DATA_DBPOINTER; } });
|
|
55
|
+
Object.defineProperty(exports, "BSON_DATA_DECIMAL128", { enumerable: true, get: function () { return constants_1.BSON_DATA_DECIMAL128; } });
|
|
56
|
+
Object.defineProperty(exports, "BSON_DATA_INT", { enumerable: true, get: function () { return constants_1.BSON_DATA_INT; } });
|
|
57
|
+
Object.defineProperty(exports, "BSON_DATA_LONG", { enumerable: true, get: function () { return constants_1.BSON_DATA_LONG; } });
|
|
58
|
+
Object.defineProperty(exports, "BSON_DATA_MAX_KEY", { enumerable: true, get: function () { return constants_1.BSON_DATA_MAX_KEY; } });
|
|
59
|
+
Object.defineProperty(exports, "BSON_DATA_MIN_KEY", { enumerable: true, get: function () { return constants_1.BSON_DATA_MIN_KEY; } });
|
|
60
|
+
Object.defineProperty(exports, "BSON_DATA_NULL", { enumerable: true, get: function () { return constants_1.BSON_DATA_NULL; } });
|
|
61
|
+
Object.defineProperty(exports, "BSON_DATA_NUMBER", { enumerable: true, get: function () { return constants_1.BSON_DATA_NUMBER; } });
|
|
62
|
+
Object.defineProperty(exports, "BSON_DATA_OBJECT", { enumerable: true, get: function () { return constants_1.BSON_DATA_OBJECT; } });
|
|
63
|
+
Object.defineProperty(exports, "BSON_DATA_OID", { enumerable: true, get: function () { return constants_1.BSON_DATA_OID; } });
|
|
64
|
+
Object.defineProperty(exports, "BSON_DATA_REGEXP", { enumerable: true, get: function () { return constants_1.BSON_DATA_REGEXP; } });
|
|
65
|
+
Object.defineProperty(exports, "BSON_DATA_STRING", { enumerable: true, get: function () { return constants_1.BSON_DATA_STRING; } });
|
|
66
|
+
Object.defineProperty(exports, "BSON_DATA_SYMBOL", { enumerable: true, get: function () { return constants_1.BSON_DATA_SYMBOL; } });
|
|
67
|
+
Object.defineProperty(exports, "BSON_DATA_TIMESTAMP", { enumerable: true, get: function () { return constants_1.BSON_DATA_TIMESTAMP; } });
|
|
68
|
+
Object.defineProperty(exports, "BSON_DATA_UNDEFINED", { enumerable: true, get: function () { return constants_1.BSON_DATA_UNDEFINED; } });
|
|
69
|
+
Object.defineProperty(exports, "BSON_INT32_MAX", { enumerable: true, get: function () { return constants_1.BSON_INT32_MAX; } });
|
|
70
|
+
Object.defineProperty(exports, "BSON_INT32_MIN", { enumerable: true, get: function () { return constants_1.BSON_INT32_MIN; } });
|
|
71
|
+
Object.defineProperty(exports, "BSON_INT64_MAX", { enumerable: true, get: function () { return constants_1.BSON_INT64_MAX; } });
|
|
72
|
+
Object.defineProperty(exports, "BSON_INT64_MIN", { enumerable: true, get: function () { return constants_1.BSON_INT64_MIN; } });
|
|
73
|
+
var extended_json_2 = require("./extended_json");
|
|
74
|
+
Object.defineProperty(exports, "EJSON", { enumerable: true, get: function () { return extended_json_2.EJSON; } });
|
|
75
|
+
var timestamp_2 = require("./timestamp");
|
|
76
|
+
Object.defineProperty(exports, "LongWithoutOverridesClass", { enumerable: true, get: function () { return timestamp_2.LongWithoutOverridesClass; } });
|
|
77
|
+
/** @internal */
|
|
30
78
|
// Default Max Size
|
|
31
79
|
const MAXSIZE = 1024 * 1024 * 17;
|
|
32
|
-
|
|
33
80
|
// Current Internal Temporary Serialization Buffer
|
|
34
|
-
let buffer = Buffer.alloc(MAXSIZE);
|
|
35
|
-
|
|
81
|
+
let buffer = buffer_1.Buffer.alloc(MAXSIZE);
|
|
36
82
|
/**
|
|
37
83
|
* Sets the size of the internal serialization buffer.
|
|
38
84
|
*
|
|
39
|
-
* @
|
|
40
|
-
* @
|
|
85
|
+
* @param size - The desired size for the internal serialization buffer
|
|
86
|
+
* @public
|
|
41
87
|
*/
|
|
42
88
|
function setInternalBufferSize(size) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
89
|
+
// Resize the internal serialization buffer if needed
|
|
90
|
+
if (buffer.length < size) {
|
|
91
|
+
buffer = buffer_1.Buffer.alloc(size);
|
|
92
|
+
}
|
|
47
93
|
}
|
|
48
|
-
|
|
94
|
+
exports.setInternalBufferSize = setInternalBufferSize;
|
|
49
95
|
/**
|
|
50
96
|
* Serialize a Javascript object.
|
|
51
97
|
*
|
|
52
|
-
* @param
|
|
53
|
-
* @
|
|
54
|
-
* @
|
|
55
|
-
* @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**.
|
|
56
|
-
* @return {Buffer} returns the Buffer object containing the serialized object.
|
|
98
|
+
* @param object - the Javascript object to serialize.
|
|
99
|
+
* @returns Buffer object containing the serialized object.
|
|
100
|
+
* @public
|
|
57
101
|
*/
|
|
58
|
-
function serialize(object, options) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
typeof options.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
buffer,
|
|
77
|
-
object,
|
|
78
|
-
checkKeys,
|
|
79
|
-
0,
|
|
80
|
-
0,
|
|
81
|
-
serializeFunctions,
|
|
82
|
-
ignoreUndefined,
|
|
83
|
-
[]
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// Create the final buffer
|
|
87
|
-
const finishedBuffer = Buffer.alloc(serializationIndex);
|
|
88
|
-
|
|
89
|
-
// Copy into the finished buffer
|
|
90
|
-
buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length);
|
|
91
|
-
|
|
92
|
-
// Return the buffer
|
|
93
|
-
return finishedBuffer;
|
|
102
|
+
function serialize(object, options = {}) {
|
|
103
|
+
// Unpack the options
|
|
104
|
+
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
|
|
105
|
+
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
|
106
|
+
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
|
107
|
+
const minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
|
|
108
|
+
// Resize the internal serialization buffer if needed
|
|
109
|
+
if (buffer.length < minInternalBufferSize) {
|
|
110
|
+
buffer = buffer_1.Buffer.alloc(minInternalBufferSize);
|
|
111
|
+
}
|
|
112
|
+
// Attempt to serialize
|
|
113
|
+
const serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []);
|
|
114
|
+
// Create the final buffer
|
|
115
|
+
const finishedBuffer = buffer_1.Buffer.alloc(serializationIndex);
|
|
116
|
+
// Copy into the finished buffer
|
|
117
|
+
buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length);
|
|
118
|
+
// Return the buffer
|
|
119
|
+
return finishedBuffer;
|
|
94
120
|
}
|
|
95
|
-
|
|
121
|
+
exports.serialize = serialize;
|
|
96
122
|
/**
|
|
97
|
-
* Serialize a Javascript object using a predefined Buffer and index into the buffer,
|
|
123
|
+
* Serialize a Javascript object using a predefined Buffer and index into the buffer,
|
|
124
|
+
* useful when pre-allocating the space for serialization.
|
|
98
125
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
102
|
-
* @
|
|
103
|
-
* @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**.
|
|
104
|
-
* @param {Number} [options.index] the index in the buffer where we wish to start serializing into.
|
|
105
|
-
* @return {Number} returns the index pointing to the last written byte in the buffer.
|
|
126
|
+
* @param object - the Javascript object to serialize.
|
|
127
|
+
* @param finalBuffer - the Buffer you pre-allocated to store the serialized BSON object.
|
|
128
|
+
* @returns the index pointing to the last written byte in the buffer.
|
|
129
|
+
* @public
|
|
106
130
|
*/
|
|
107
|
-
function serializeWithBufferAndIndex(object, finalBuffer, options) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
typeof options.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const serializationIndex = internalSerialize(
|
|
119
|
-
buffer,
|
|
120
|
-
object,
|
|
121
|
-
checkKeys,
|
|
122
|
-
0,
|
|
123
|
-
0,
|
|
124
|
-
serializeFunctions,
|
|
125
|
-
ignoreUndefined
|
|
126
|
-
);
|
|
127
|
-
buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
|
|
128
|
-
|
|
129
|
-
// Return the index
|
|
130
|
-
return startIndex + serializationIndex - 1;
|
|
131
|
+
function serializeWithBufferAndIndex(object, finalBuffer, options = {}) {
|
|
132
|
+
// Unpack the options
|
|
133
|
+
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
|
|
134
|
+
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
|
135
|
+
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
|
136
|
+
const startIndex = typeof options.index === 'number' ? options.index : 0;
|
|
137
|
+
// Attempt to serialize
|
|
138
|
+
const serializationIndex = serializer_1.serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
|
|
139
|
+
buffer.copy(finalBuffer, startIndex, 0, serializationIndex);
|
|
140
|
+
// Return the index
|
|
141
|
+
return startIndex + serializationIndex - 1;
|
|
131
142
|
}
|
|
132
|
-
|
|
143
|
+
exports.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
|
|
133
144
|
/**
|
|
134
145
|
* Deserialize data as BSON.
|
|
135
146
|
*
|
|
136
|
-
* @param
|
|
137
|
-
* @
|
|
138
|
-
* @
|
|
139
|
-
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
|
|
140
|
-
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
|
|
141
|
-
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
|
|
142
|
-
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
|
|
143
|
-
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
|
|
144
|
-
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
|
|
145
|
-
* @param {boolean} [options.allowObjectSmallerThanBufferSize=false] allows the buffer to be larger than the parsed BSON object
|
|
146
|
-
* @return {Object} returns the deserialized Javascript Object.
|
|
147
|
+
* @param buffer - the buffer containing the serialized set of BSON documents.
|
|
148
|
+
* @returns returns the deserialized Javascript Object.
|
|
149
|
+
* @public
|
|
147
150
|
*/
|
|
148
|
-
function deserialize(buffer, options) {
|
|
149
|
-
|
|
150
|
-
return internalDeserialize(buffer, options);
|
|
151
|
+
function deserialize(buffer, options = {}) {
|
|
152
|
+
return deserializer_1.deserialize(ensure_buffer_1.ensureBuffer(buffer), options);
|
|
151
153
|
}
|
|
152
|
-
|
|
154
|
+
exports.deserialize = deserialize;
|
|
153
155
|
/**
|
|
154
156
|
* Calculate the bson size for a passed in Javascript object.
|
|
155
157
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @
|
|
158
|
-
* @
|
|
159
|
-
* @return {Number} returns the number of bytes the BSON object will take up.
|
|
158
|
+
* @param object - the Javascript object to calculate the BSON byte size for
|
|
159
|
+
* @returns size of BSON object in bytes
|
|
160
|
+
* @public
|
|
160
161
|
*/
|
|
161
|
-
function calculateObjectSize(object, options) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const ignoreUndefined =
|
|
167
|
-
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
|
168
|
-
|
|
169
|
-
return internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined);
|
|
162
|
+
function calculateObjectSize(object, options = {}) {
|
|
163
|
+
options = options || {};
|
|
164
|
+
const serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
|
|
165
|
+
const ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
|
|
166
|
+
return calculate_size_1.calculateObjectSize(object, serializeFunctions, ignoreUndefined);
|
|
170
167
|
}
|
|
171
|
-
|
|
168
|
+
exports.calculateObjectSize = calculateObjectSize;
|
|
172
169
|
/**
|
|
173
170
|
* Deserialize stream data as BSON documents.
|
|
174
171
|
*
|
|
175
|
-
* @param
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
180
|
-
* @param
|
|
181
|
-
* @
|
|
182
|
-
* @
|
|
183
|
-
* @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
|
|
184
|
-
* @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
|
|
185
|
-
* @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
|
|
186
|
-
* @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
|
|
187
|
-
* @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
|
|
188
|
-
* @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
|
|
189
|
-
* @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents.
|
|
172
|
+
* @param data - the buffer containing the serialized set of BSON documents.
|
|
173
|
+
* @param startIndex - the start index in the data Buffer where the deserialization is to start.
|
|
174
|
+
* @param numberOfDocuments - number of documents to deserialize.
|
|
175
|
+
* @param documents - an array where to store the deserialized documents.
|
|
176
|
+
* @param docStartIndex - the index in the documents array from where to start inserting documents.
|
|
177
|
+
* @param options - additional options used for the deserialization.
|
|
178
|
+
* @returns next index in the buffer after deserialization **x** numbers of documents.
|
|
179
|
+
* @public
|
|
190
180
|
*/
|
|
191
181
|
function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
182
|
+
const internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options);
|
|
183
|
+
const bufferData = ensure_buffer_1.ensureBuffer(data);
|
|
184
|
+
let index = startIndex;
|
|
185
|
+
// Loop over all documents
|
|
186
|
+
for (let i = 0; i < numberOfDocuments; i++) {
|
|
187
|
+
// Find size of the document
|
|
188
|
+
const size = bufferData[index] |
|
|
189
|
+
(bufferData[index + 1] << 8) |
|
|
190
|
+
(bufferData[index + 2] << 16) |
|
|
191
|
+
(bufferData[index + 3] << 24);
|
|
192
|
+
// Update options with index
|
|
193
|
+
internalOptions.index = index;
|
|
194
|
+
// Parse the document at this point
|
|
195
|
+
documents[docStartIndex + i] = deserializer_1.deserialize(bufferData, internalOptions);
|
|
196
|
+
// Adjust index by the document size
|
|
197
|
+
index = index + size;
|
|
198
|
+
}
|
|
199
|
+
// Return object containing end index of parsing and list of documents
|
|
200
|
+
return index;
|
|
211
201
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
BSON_BINARY_SUBTYPE_FUNCTION: constants.BSON_BINARY_SUBTYPE_FUNCTION,
|
|
245
|
-
BSON_BINARY_SUBTYPE_BYTE_ARRAY: constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY,
|
|
246
|
-
BSON_BINARY_SUBTYPE_UUID: constants.BSON_BINARY_SUBTYPE_UUID,
|
|
247
|
-
BSON_BINARY_SUBTYPE_MD5: constants.BSON_BINARY_SUBTYPE_MD5,
|
|
248
|
-
BSON_BINARY_SUBTYPE_USER_DEFINED: constants.BSON_BINARY_SUBTYPE_USER_DEFINED,
|
|
249
|
-
|
|
250
|
-
// wrapped types
|
|
251
|
-
Code,
|
|
252
|
-
Map,
|
|
253
|
-
BSONSymbol,
|
|
254
|
-
DBRef,
|
|
255
|
-
Binary,
|
|
256
|
-
ObjectId,
|
|
257
|
-
Long,
|
|
258
|
-
Timestamp,
|
|
259
|
-
Double,
|
|
260
|
-
Int32,
|
|
261
|
-
MinKey,
|
|
262
|
-
MaxKey,
|
|
263
|
-
BSONRegExp,
|
|
264
|
-
Decimal128,
|
|
265
|
-
|
|
266
|
-
// methods
|
|
267
|
-
serialize,
|
|
268
|
-
serializeWithBufferAndIndex,
|
|
269
|
-
deserialize,
|
|
270
|
-
calculateObjectSize,
|
|
271
|
-
deserializeStream,
|
|
272
|
-
setInternalBufferSize,
|
|
273
|
-
|
|
274
|
-
// legacy support
|
|
275
|
-
ObjectID: ObjectId,
|
|
276
|
-
|
|
277
|
-
// Extended JSON
|
|
278
|
-
EJSON
|
|
202
|
+
exports.deserializeStream = deserializeStream;
|
|
203
|
+
/**
|
|
204
|
+
* BSON default export
|
|
205
|
+
* @deprecated Please use named exports
|
|
206
|
+
* @privateRemarks
|
|
207
|
+
* We want to someday deprecate the default export,
|
|
208
|
+
* so none of the new TS types are being exported on the default
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
const BSON = {
|
|
212
|
+
Binary: binary_1.Binary,
|
|
213
|
+
Code: code_1.Code,
|
|
214
|
+
DBRef: db_ref_1.DBRef,
|
|
215
|
+
Decimal128: decimal128_1.Decimal128,
|
|
216
|
+
Double: double_1.Double,
|
|
217
|
+
Int32: int_32_1.Int32,
|
|
218
|
+
Long: long_1.Long,
|
|
219
|
+
Map: map_1.Map,
|
|
220
|
+
MaxKey: max_key_1.MaxKey,
|
|
221
|
+
MinKey: min_key_1.MinKey,
|
|
222
|
+
ObjectId: objectid_1.ObjectId,
|
|
223
|
+
ObjectID: objectid_1.ObjectId,
|
|
224
|
+
BSONRegExp: regexp_1.BSONRegExp,
|
|
225
|
+
BSONSymbol: symbol_1.BSONSymbol,
|
|
226
|
+
Timestamp: timestamp_1.Timestamp,
|
|
227
|
+
EJSON: extended_json_1.EJSON,
|
|
228
|
+
setInternalBufferSize,
|
|
229
|
+
serialize,
|
|
230
|
+
serializeWithBufferAndIndex,
|
|
231
|
+
deserialize,
|
|
232
|
+
calculateObjectSize,
|
|
233
|
+
deserializeStream
|
|
279
234
|
};
|
|
235
|
+
exports.default = BSON;
|
|
236
|
+
//# sourceMappingURL=bson.js.map
|
package/lib/bson.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bson.js","sourceRoot":"","sources":["../src/bson.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,qCAAkC;AAg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;IAClB,UAAU,EAAV,mBAAU;IACV,UAAU,EAAV,mBAAU;IACV,SAAS,EAAT,qBAAS;IACT,KAAK,EAAL,qBAAK;IACL,qBAAqB;IACrB,SAAS;IACT,2BAA2B;IAC3B,WAAW;IACX,mBAAmB;IACnB,iBAAiB;CAClB,CAAC;AACF,kBAAe,IAAI,CAAC"}
|
package/lib/code.js
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Code = void 0;
|
|
3
4
|
/**
|
|
4
5
|
* A class representation of the BSON Code type.
|
|
6
|
+
* @public
|
|
5
7
|
*/
|
|
6
8
|
class Code {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param code - a string or function.
|
|
11
|
+
* @param scope - an optional scope for the function.
|
|
12
|
+
*/
|
|
13
|
+
constructor(code, scope) {
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.scope = scope;
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
toJSON() {
|
|
19
|
+
return { code: this.code, scope: this.scope };
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
toExtendedJSON() {
|
|
23
|
+
if (this.scope) {
|
|
24
|
+
return { $code: this.code, $scope: this.scope };
|
|
25
|
+
}
|
|
26
|
+
return { $code: this.code };
|
|
27
|
+
}
|
|
28
|
+
/** @internal */
|
|
29
|
+
static fromExtendedJSON(doc) {
|
|
30
|
+
return new Code(doc.$code, doc.$scope);
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
34
|
+
return this.inspect();
|
|
35
|
+
}
|
|
36
|
+
inspect() {
|
|
37
|
+
const codeJson = this.toJSON();
|
|
38
|
+
return `Code("${codeJson.code}"${codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : ''})`;
|
|
32
39
|
}
|
|
33
|
-
|
|
34
|
-
return { $code: this.code };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @ignore
|
|
39
|
-
*/
|
|
40
|
-
static fromExtendedJSON(doc) {
|
|
41
|
-
return new Code(doc.$code, doc.$scope);
|
|
42
|
-
}
|
|
43
40
|
}
|
|
44
|
-
|
|
41
|
+
exports.Code = Code;
|
|
45
42
|
Object.defineProperty(Code.prototype, '_bsontype', { value: 'Code' });
|
|
46
|
-
|
|
43
|
+
//# sourceMappingURL=code.js.map
|
package/lib/code.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../src/code.ts"],"names":[],"mappings":";;;AAQA;;;GAGG;AACH,MAAa,IAAI;IAKf;;;OAGG;IACH,YAAY,IAAuB,EAAE,KAAgB;QACnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,gBAAgB;IAChB,MAAM;QACJ,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAChD,CAAC;IAED,gBAAgB;IAChB,cAAc;QACZ,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;SACjD;QAED,OAAO,EAAE,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