bson 4.6.3 → 4.7.0
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/bower.json +1 -1
- package/bson.d.ts +9 -9
- package/dist/bson.browser.esm.js +352 -400
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +355 -403
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +355 -403
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +349 -400
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +196 -10
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +8 -9
- package/lib/bson.js.map +1 -1
- package/lib/code.js +1 -1
- package/lib/code.js.map +1 -1
- package/lib/db_ref.js +2 -2
- package/lib/db_ref.js.map +1 -1
- package/lib/decimal128.js +13 -13
- package/lib/decimal128.js.map +1 -1
- package/lib/double.js +2 -2
- package/lib/double.js.map +1 -1
- package/lib/ensure_buffer.js +1 -1
- package/lib/ensure_buffer.js.map +1 -1
- package/lib/extended_json.js +24 -12
- package/lib/extended_json.js.map +1 -1
- package/lib/int_32.js +1 -1
- package/lib/int_32.js.map +1 -1
- package/lib/long.js +3 -3
- package/lib/long.js.map +1 -1
- package/lib/map.js +1 -1
- package/lib/map.js.map +1 -1
- package/lib/objectid.js +9 -8
- package/lib/objectid.js.map +1 -1
- package/lib/parser/calculate_size.js +10 -9
- package/lib/parser/calculate_size.js.map +1 -1
- package/lib/parser/deserializer.js +20 -11
- package/lib/parser/deserializer.js.map +1 -1
- package/lib/parser/serializer.js +25 -22
- package/lib/parser/serializer.js.map +1 -1
- package/lib/parser/utils.js +23 -19
- package/lib/parser/utils.js.map +1 -1
- package/lib/regexp.js +4 -4
- package/lib/regexp.js.map +1 -1
- package/lib/symbol.js +1 -1
- package/lib/symbol.js.map +1 -1
- package/lib/timestamp.js +3 -3
- package/lib/timestamp.js.map +1 -1
- package/lib/utils/global.js +1 -1
- package/lib/utils/global.js.map +1 -1
- package/lib/uuid_utils.js +1 -1
- package/lib/uuid_utils.js.map +1 -1
- package/package.json +17 -24
- package/src/binary.ts +197 -3
- package/src/bson.ts +18 -23
- package/src/code.ts +1 -1
- package/src/db_ref.ts +1 -1
- package/src/decimal128.ts +3 -3
- package/src/extended_json.ts +13 -2
- package/src/long.ts +32 -7
- package/src/objectid.ts +3 -2
- package/src/parser/calculate_size.ts +4 -3
- package/src/parser/deserializer.ts +12 -4
- package/src/parser/serializer.ts +14 -7
- package/src/parser/utils.ts +24 -20
- package/src/timestamp.ts +1 -1
- package/src/utils/global.ts +1 -1
- package/bson-ts34.d.ts +0 -1133
- package/lib/float_parser.js +0 -137
- package/lib/float_parser.js.map +0 -1
- package/lib/uuid.js +0 -179
- package/lib/uuid.js.map +0 -1
- package/src/float_parser.ts +0 -152
- package/src/uuid.ts +0 -209
package/lib/float_parser.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
3
|
-
// All rights reserved.
|
|
4
|
-
//
|
|
5
|
-
// Redistribution and use in source and binary forms, with or without
|
|
6
|
-
// modification, are permitted provided that the following conditions are met:
|
|
7
|
-
//
|
|
8
|
-
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
-
// this list of conditions and the following disclaimer.
|
|
10
|
-
//
|
|
11
|
-
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
-
// this list of conditions and the following disclaimer in the documentation
|
|
13
|
-
// and/or other materials provided with the distribution.
|
|
14
|
-
//
|
|
15
|
-
// * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
|
|
16
|
-
// may be used to endorse or promote products derived from this software
|
|
17
|
-
// without specific prior written permission.
|
|
18
|
-
//
|
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
-
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
-
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
22
|
-
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
23
|
-
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
24
|
-
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
25
|
-
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
26
|
-
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
27
|
-
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
28
|
-
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
29
|
-
// POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// Modifications to writeIEEE754 to support negative zeroes made by Brian White
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.writeIEEE754 = exports.readIEEE754 = void 0;
|
|
35
|
-
function readIEEE754(buffer, offset, endian, mLen, nBytes) {
|
|
36
|
-
var e;
|
|
37
|
-
var m;
|
|
38
|
-
var bBE = endian === 'big';
|
|
39
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
40
|
-
var eMax = (1 << eLen) - 1;
|
|
41
|
-
var eBias = eMax >> 1;
|
|
42
|
-
var nBits = -7;
|
|
43
|
-
var i = bBE ? 0 : nBytes - 1;
|
|
44
|
-
var d = bBE ? 1 : -1;
|
|
45
|
-
var s = buffer[offset + i];
|
|
46
|
-
i += d;
|
|
47
|
-
e = s & ((1 << -nBits) - 1);
|
|
48
|
-
s >>= -nBits;
|
|
49
|
-
nBits += eLen;
|
|
50
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8)
|
|
51
|
-
;
|
|
52
|
-
m = e & ((1 << -nBits) - 1);
|
|
53
|
-
e >>= -nBits;
|
|
54
|
-
nBits += mLen;
|
|
55
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8)
|
|
56
|
-
;
|
|
57
|
-
if (e === 0) {
|
|
58
|
-
e = 1 - eBias;
|
|
59
|
-
}
|
|
60
|
-
else if (e === eMax) {
|
|
61
|
-
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
m = m + Math.pow(2, mLen);
|
|
65
|
-
e = e - eBias;
|
|
66
|
-
}
|
|
67
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
68
|
-
}
|
|
69
|
-
exports.readIEEE754 = readIEEE754;
|
|
70
|
-
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
|
|
71
|
-
var e;
|
|
72
|
-
var m;
|
|
73
|
-
var c;
|
|
74
|
-
var bBE = endian === 'big';
|
|
75
|
-
var eLen = nBytes * 8 - mLen - 1;
|
|
76
|
-
var eMax = (1 << eLen) - 1;
|
|
77
|
-
var eBias = eMax >> 1;
|
|
78
|
-
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
79
|
-
var i = bBE ? nBytes - 1 : 0;
|
|
80
|
-
var d = bBE ? -1 : 1;
|
|
81
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
82
|
-
value = Math.abs(value);
|
|
83
|
-
if (isNaN(value) || value === Infinity) {
|
|
84
|
-
m = isNaN(value) ? 1 : 0;
|
|
85
|
-
e = eMax;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
89
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
90
|
-
e--;
|
|
91
|
-
c *= 2;
|
|
92
|
-
}
|
|
93
|
-
if (e + eBias >= 1) {
|
|
94
|
-
value += rt / c;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
98
|
-
}
|
|
99
|
-
if (value * c >= 2) {
|
|
100
|
-
e++;
|
|
101
|
-
c /= 2;
|
|
102
|
-
}
|
|
103
|
-
if (e + eBias >= eMax) {
|
|
104
|
-
m = 0;
|
|
105
|
-
e = eMax;
|
|
106
|
-
}
|
|
107
|
-
else if (e + eBias >= 1) {
|
|
108
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
109
|
-
e = e + eBias;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
113
|
-
e = 0;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (isNaN(value))
|
|
117
|
-
m = 0;
|
|
118
|
-
while (mLen >= 8) {
|
|
119
|
-
buffer[offset + i] = m & 0xff;
|
|
120
|
-
i += d;
|
|
121
|
-
m /= 256;
|
|
122
|
-
mLen -= 8;
|
|
123
|
-
}
|
|
124
|
-
e = (e << mLen) | m;
|
|
125
|
-
if (isNaN(value))
|
|
126
|
-
e += 8;
|
|
127
|
-
eLen += mLen;
|
|
128
|
-
while (eLen > 0) {
|
|
129
|
-
buffer[offset + i] = e & 0xff;
|
|
130
|
-
i += d;
|
|
131
|
-
e /= 256;
|
|
132
|
-
eLen -= 8;
|
|
133
|
-
}
|
|
134
|
-
buffer[offset + i - d] |= s * 128;
|
|
135
|
-
}
|
|
136
|
-
exports.writeIEEE754 = writeIEEE754;
|
|
137
|
-
//# sourceMappingURL=float_parser.js.map
|
package/lib/float_parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"float_parser.js","sourceRoot":"","sources":["../src/float_parser.ts"],"names":[],"mappings":";AAAA,2CAA2C;AAC3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,IAAI,CAAC,CAAC;QACP,CAAC,IAAI,GAAG,CAAC;QACT,IAAI,IAAI,CAAC,CAAC;KACX;IAED,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAEpB,IAAI,KAAK,CAAC,KAAK,CAAC;QAAE,CAAC,IAAI,CAAC,CAAC;IAEzB,IAAI,IAAI,IAAI,CAAC;IAEb,OAAO,IAAI,GAAG,CAAC,EAAE;QACf,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QAC9B,CAAC,IAAI,CAAC,CAAC;QACP,CAAC,IAAI,GAAG,CAAC;QACT,IAAI,IAAI,CAAC,CAAC;KACX;IAED,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;AACpC,CAAC;AA5ED,oCA4EC"}
|
package/lib/uuid.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UUID = void 0;
|
|
4
|
-
var buffer_1 = require("buffer");
|
|
5
|
-
var ensure_buffer_1 = require("./ensure_buffer");
|
|
6
|
-
var binary_1 = require("./binary");
|
|
7
|
-
var uuid_utils_1 = require("./uuid_utils");
|
|
8
|
-
var utils_1 = require("./parser/utils");
|
|
9
|
-
var error_1 = require("./error");
|
|
10
|
-
var BYTE_LENGTH = 16;
|
|
11
|
-
var kId = Symbol('id');
|
|
12
|
-
/**
|
|
13
|
-
* A class representation of the BSON UUID type.
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
var UUID = /** @class */ (function () {
|
|
17
|
-
/**
|
|
18
|
-
* Create an UUID type
|
|
19
|
-
*
|
|
20
|
-
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
|
|
21
|
-
*/
|
|
22
|
-
function UUID(input) {
|
|
23
|
-
if (typeof input === 'undefined') {
|
|
24
|
-
// The most common use case (blank id, new UUID() instance)
|
|
25
|
-
this.id = UUID.generate();
|
|
26
|
-
}
|
|
27
|
-
else if (input instanceof UUID) {
|
|
28
|
-
this[kId] = buffer_1.Buffer.from(input.id);
|
|
29
|
-
this.__id = input.__id;
|
|
30
|
-
}
|
|
31
|
-
else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
|
|
32
|
-
this.id = ensure_buffer_1.ensureBuffer(input);
|
|
33
|
-
}
|
|
34
|
-
else if (typeof input === 'string') {
|
|
35
|
-
this.id = uuid_utils_1.uuidHexStringToBuffer(input);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
throw new error_1.BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
Object.defineProperty(UUID.prototype, "id", {
|
|
42
|
-
/**
|
|
43
|
-
* The UUID bytes
|
|
44
|
-
* @readonly
|
|
45
|
-
*/
|
|
46
|
-
get: function () {
|
|
47
|
-
return this[kId];
|
|
48
|
-
},
|
|
49
|
-
set: function (value) {
|
|
50
|
-
this[kId] = value;
|
|
51
|
-
if (UUID.cacheHexString) {
|
|
52
|
-
this.__id = uuid_utils_1.bufferToUuidHexString(value);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
enumerable: false,
|
|
56
|
-
configurable: true
|
|
57
|
-
});
|
|
58
|
-
/**
|
|
59
|
-
* Generate a 16 byte uuid v4 buffer used in UUIDs
|
|
60
|
-
*/
|
|
61
|
-
/**
|
|
62
|
-
* Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
|
|
63
|
-
* @param includeDashes - should the string exclude dash-separators.
|
|
64
|
-
* */
|
|
65
|
-
UUID.prototype.toHexString = function (includeDashes) {
|
|
66
|
-
if (includeDashes === void 0) { includeDashes = true; }
|
|
67
|
-
if (UUID.cacheHexString && this.__id) {
|
|
68
|
-
return this.__id;
|
|
69
|
-
}
|
|
70
|
-
var uuidHexString = uuid_utils_1.bufferToUuidHexString(this.id, includeDashes);
|
|
71
|
-
if (UUID.cacheHexString) {
|
|
72
|
-
this.__id = uuidHexString;
|
|
73
|
-
}
|
|
74
|
-
return uuidHexString;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
|
|
78
|
-
*/
|
|
79
|
-
UUID.prototype.toString = function (encoding) {
|
|
80
|
-
return encoding ? this.id.toString(encoding) : this.toHexString();
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Converts the id into its JSON string representation.
|
|
84
|
-
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
85
|
-
*/
|
|
86
|
-
UUID.prototype.toJSON = function () {
|
|
87
|
-
return this.toHexString();
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Compares the equality of this UUID with `otherID`.
|
|
91
|
-
*
|
|
92
|
-
* @param otherId - UUID instance to compare against.
|
|
93
|
-
*/
|
|
94
|
-
UUID.prototype.equals = function (otherId) {
|
|
95
|
-
if (!otherId) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
if (otherId instanceof UUID) {
|
|
99
|
-
return otherId.id.equals(this.id);
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
return new UUID(otherId).id.equals(this.id);
|
|
103
|
-
}
|
|
104
|
-
catch (_a) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Creates a Binary instance from the current UUID.
|
|
110
|
-
*/
|
|
111
|
-
UUID.prototype.toBinary = function () {
|
|
112
|
-
return new binary_1.Binary(this.id, binary_1.Binary.SUBTYPE_UUID);
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Generates a populated buffer containing a v4 uuid
|
|
116
|
-
*/
|
|
117
|
-
UUID.generate = function () {
|
|
118
|
-
var bytes = utils_1.randomBytes(BYTE_LENGTH);
|
|
119
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
120
|
-
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
|
121
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
122
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
123
|
-
return buffer_1.Buffer.from(bytes);
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Checks if a value is a valid bson UUID
|
|
127
|
-
* @param input - UUID, string or Buffer to validate.
|
|
128
|
-
*/
|
|
129
|
-
UUID.isValid = function (input) {
|
|
130
|
-
if (!input) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
if (input instanceof UUID) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
if (typeof input === 'string') {
|
|
137
|
-
return uuid_utils_1.uuidValidateString(input);
|
|
138
|
-
}
|
|
139
|
-
if (utils_1.isUint8Array(input)) {
|
|
140
|
-
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
|
|
141
|
-
if (input.length !== BYTE_LENGTH) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
// get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
|
|
146
|
-
// check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
|
|
147
|
-
return parseInt(input[6].toString(16)[0], 10) === binary_1.Binary.SUBTYPE_UUID;
|
|
148
|
-
}
|
|
149
|
-
catch (_a) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* Creates an UUID from a hex string representation of an UUID.
|
|
157
|
-
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
158
|
-
*/
|
|
159
|
-
UUID.createFromHexString = function (hexString) {
|
|
160
|
-
var buffer = uuid_utils_1.uuidHexStringToBuffer(hexString);
|
|
161
|
-
return new UUID(buffer);
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Converts to a string representation of this Id.
|
|
165
|
-
*
|
|
166
|
-
* @returns return the 36 character hex string representation.
|
|
167
|
-
* @internal
|
|
168
|
-
*/
|
|
169
|
-
UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
170
|
-
return this.inspect();
|
|
171
|
-
};
|
|
172
|
-
UUID.prototype.inspect = function () {
|
|
173
|
-
return "new UUID(\"" + this.toHexString() + "\")";
|
|
174
|
-
};
|
|
175
|
-
return UUID;
|
|
176
|
-
}());
|
|
177
|
-
exports.UUID = UUID;
|
|
178
|
-
Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
|
|
179
|
-
//# sourceMappingURL=uuid.js.map
|
package/lib/uuid.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,iDAA+C;AAC/C,mCAAkC;AAClC,2CAAgG;AAChG,wCAA2D;AAC3D,iCAAwC;AAOxC,IAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,IAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAEzB;;;GAGG;AACH;IAWE;;;;OAIG;IACH,cAAY,KAA8B;QACxC,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAChC,2DAA2D;YAC3D,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;SAC3B;aAAM,IAAI,KAAK,YAAY,IAAI,EAAE;YAChC,IAAI,CAAC,GAAG,CAAC,GAAG,eAAM,CAAC,IAAI,C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;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,+BAAkB,CAAC,KAAK,CAAC,CAAC;SAClC;QAED,IAAI,oBAAY,CAAC,KAAK,CAAC,EAAE;YACvB,sFAAsF;YACtF,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE;gBAChC,OAAO,KAAK,CAAC;aACd;YAED,IAAI;gBACF,yEAAyE;gBACzE,yEAAyE;gBACzE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,eAAM,CAAC,YAAY,CAAC;aACvE;YAAC,WAAM;gBACN,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,wBAAmB,GAA1B,UAA2B,SAAiB;QAC1C,IAAM,MAAM,GAAG,kCAAqB,CAAC,SAAS,CAAC,CAAC;QAChD,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,eAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,GAA1C;QACE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,sBAAO,GAAP;QACE,OAAO,gBAAa,IAAI,CAAC,WAAW,EAAE,QAAI,CAAC;IAC7C,CAAC;IACH,WAAC;AAAD,CAAC,AA1LD,IA0LC;AA1LY,oBAAI;AA4LjB,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC"}
|
package/src/float_parser.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
2
|
-
// All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
// Redistribution and use in source and binary forms, with or without
|
|
5
|
-
// modification, are permitted provided that the following conditions are met:
|
|
6
|
-
//
|
|
7
|
-
// * Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
// this list of conditions and the following disclaimer.
|
|
9
|
-
//
|
|
10
|
-
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
-
// this list of conditions and the following disclaimer in the documentation
|
|
12
|
-
// and/or other materials provided with the distribution.
|
|
13
|
-
//
|
|
14
|
-
// * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
|
|
15
|
-
// may be used to endorse or promote products derived from this software
|
|
16
|
-
// without specific prior written permission.
|
|
17
|
-
//
|
|
18
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
-
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
-
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
-
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
22
|
-
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
23
|
-
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
24
|
-
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
25
|
-
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
26
|
-
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
27
|
-
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
28
|
-
// POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
// Modifications to writeIEEE754 to support negative zeroes made by Brian White
|
|
32
|
-
|
|
33
|
-
type NumericalSequence = { [index: number]: number };
|
|
34
|
-
|
|
35
|
-
export function readIEEE754(
|
|
36
|
-
buffer: NumericalSequence,
|
|
37
|
-
offset: number,
|
|
38
|
-
endian: 'big' | 'little',
|
|
39
|
-
mLen: number,
|
|
40
|
-
nBytes: number
|
|
41
|
-
): number {
|
|
42
|
-
let e: number;
|
|
43
|
-
let m: number;
|
|
44
|
-
const bBE = endian === 'big';
|
|
45
|
-
const eLen = nBytes * 8 - mLen - 1;
|
|
46
|
-
const eMax = (1 << eLen) - 1;
|
|
47
|
-
const eBias = eMax >> 1;
|
|
48
|
-
let nBits = -7;
|
|
49
|
-
let i = bBE ? 0 : nBytes - 1;
|
|
50
|
-
const d = bBE ? 1 : -1;
|
|
51
|
-
let s = buffer[offset + i];
|
|
52
|
-
|
|
53
|
-
i += d;
|
|
54
|
-
|
|
55
|
-
e = s & ((1 << -nBits) - 1);
|
|
56
|
-
s >>= -nBits;
|
|
57
|
-
nBits += eLen;
|
|
58
|
-
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
59
|
-
|
|
60
|
-
m = e & ((1 << -nBits) - 1);
|
|
61
|
-
e >>= -nBits;
|
|
62
|
-
nBits += mLen;
|
|
63
|
-
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
|
|
64
|
-
|
|
65
|
-
if (e === 0) {
|
|
66
|
-
e = 1 - eBias;
|
|
67
|
-
} else if (e === eMax) {
|
|
68
|
-
return m ? NaN : (s ? -1 : 1) * Infinity;
|
|
69
|
-
} else {
|
|
70
|
-
m = m + Math.pow(2, mLen);
|
|
71
|
-
e = e - eBias;
|
|
72
|
-
}
|
|
73
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function writeIEEE754(
|
|
77
|
-
buffer: NumericalSequence,
|
|
78
|
-
value: number,
|
|
79
|
-
offset: number,
|
|
80
|
-
endian: 'big' | 'little',
|
|
81
|
-
mLen: number,
|
|
82
|
-
nBytes: number
|
|
83
|
-
): void {
|
|
84
|
-
let e: number;
|
|
85
|
-
let m: number;
|
|
86
|
-
let c: number;
|
|
87
|
-
const bBE = endian === 'big';
|
|
88
|
-
let eLen = nBytes * 8 - mLen - 1;
|
|
89
|
-
const eMax = (1 << eLen) - 1;
|
|
90
|
-
const eBias = eMax >> 1;
|
|
91
|
-
const rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
92
|
-
let i = bBE ? nBytes - 1 : 0;
|
|
93
|
-
const d = bBE ? -1 : 1;
|
|
94
|
-
const s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
95
|
-
|
|
96
|
-
value = Math.abs(value);
|
|
97
|
-
|
|
98
|
-
if (isNaN(value) || value === Infinity) {
|
|
99
|
-
m = isNaN(value) ? 1 : 0;
|
|
100
|
-
e = eMax;
|
|
101
|
-
} else {
|
|
102
|
-
e = Math.floor(Math.log(value) / Math.LN2);
|
|
103
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
104
|
-
e--;
|
|
105
|
-
c *= 2;
|
|
106
|
-
}
|
|
107
|
-
if (e + eBias >= 1) {
|
|
108
|
-
value += rt / c;
|
|
109
|
-
} else {
|
|
110
|
-
value += rt * Math.pow(2, 1 - eBias);
|
|
111
|
-
}
|
|
112
|
-
if (value * c >= 2) {
|
|
113
|
-
e++;
|
|
114
|
-
c /= 2;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (e + eBias >= eMax) {
|
|
118
|
-
m = 0;
|
|
119
|
-
e = eMax;
|
|
120
|
-
} else if (e + eBias >= 1) {
|
|
121
|
-
m = (value * c - 1) * Math.pow(2, mLen);
|
|
122
|
-
e = e + eBias;
|
|
123
|
-
} else {
|
|
124
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
125
|
-
e = 0;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (isNaN(value)) m = 0;
|
|
130
|
-
|
|
131
|
-
while (mLen >= 8) {
|
|
132
|
-
buffer[offset + i] = m & 0xff;
|
|
133
|
-
i += d;
|
|
134
|
-
m /= 256;
|
|
135
|
-
mLen -= 8;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
e = (e << mLen) | m;
|
|
139
|
-
|
|
140
|
-
if (isNaN(value)) e += 8;
|
|
141
|
-
|
|
142
|
-
eLen += mLen;
|
|
143
|
-
|
|
144
|
-
while (eLen > 0) {
|
|
145
|
-
buffer[offset + i] = e & 0xff;
|
|
146
|
-
i += d;
|
|
147
|
-
e /= 256;
|
|
148
|
-
eLen -= 8;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
buffer[offset + i - d] |= s * 128;
|
|
152
|
-
}
|
package/src/uuid.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { ensureBuffer } from './ensure_buffer';
|
|
3
|
-
import { Binary } from './binary';
|
|
4
|
-
import { bufferToUuidHexString, uuidHexStringToBuffer, uuidValidateString } from './uuid_utils';
|
|
5
|
-
import { isUint8Array, randomBytes } from './parser/utils';
|
|
6
|
-
import { BSONTypeError } from './error';
|
|
7
|
-
|
|
8
|
-
/** @public */
|
|
9
|
-
export type UUIDExtended = {
|
|
10
|
-
$uuid: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const BYTE_LENGTH = 16;
|
|
14
|
-
|
|
15
|
-
const kId = Symbol('id');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A class representation of the BSON UUID type.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
export class UUID {
|
|
22
|
-
// This property is not meant for direct serialization, but simply an indication that this type originates from this package.
|
|
23
|
-
_bsontype!: 'UUID';
|
|
24
|
-
|
|
25
|
-
static cacheHexString: boolean;
|
|
26
|
-
|
|
27
|
-
/** UUID Bytes @internal */
|
|
28
|
-
private [kId]: Buffer;
|
|
29
|
-
/** UUID hexString cache @internal */
|
|
30
|
-
private __id?: string;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create an UUID type
|
|
34
|
-
*
|
|
35
|
-
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
|
|
36
|
-
*/
|
|
37
|
-
constructor(input?: string | Buffer | UUID) {
|
|
38
|
-
if (typeof input === 'undefined') {
|
|
39
|
-
// The most common use case (blank id, new UUID() instance)
|
|
40
|
-
this.id = UUID.generate();
|
|
41
|
-
} else if (input instanceof UUID) {
|
|
42
|
-
this[kId] = Buffer.from(input.id);
|
|
43
|
-
this.__id = input.__id;
|
|
44
|
-
} else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
|
|
45
|
-
this.id = ensureBuffer(input);
|
|
46
|
-
} else if (typeof input === 'string') {
|
|
47
|
-
this.id = uuidHexStringToBuffer(input);
|
|
48
|
-
} else {
|
|
49
|
-
throw new BSONTypeError(
|
|
50
|
-
'Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The UUID bytes
|
|
57
|
-
* @readonly
|
|
58
|
-
*/
|
|
59
|
-
get id(): Buffer {
|
|
60
|
-
return this[kId];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
set id(value: Buffer) {
|
|
64
|
-
this[kId] = value;
|
|
65
|
-
|
|
66
|
-
if (UUID.cacheHexString) {
|
|
67
|
-
this.__id = bufferToUuidHexString(value);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Generate a 16 byte uuid v4 buffer used in UUIDs
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
|
|
77
|
-
* @param includeDashes - should the string exclude dash-separators.
|
|
78
|
-
* */
|
|
79
|
-
toHexString(includeDashes = true): string {
|
|
80
|
-
if (UUID.cacheHexString && this.__id) {
|
|
81
|
-
return this.__id;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const uuidHexString = bufferToUuidHexString(this.id, includeDashes);
|
|
85
|
-
|
|
86
|
-
if (UUID.cacheHexString) {
|
|
87
|
-
this.__id = uuidHexString;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return uuidHexString;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
|
|
95
|
-
*/
|
|
96
|
-
toString(encoding?: string): string {
|
|
97
|
-
return encoding ? this.id.toString(encoding) : this.toHexString();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Converts the id into its JSON string representation.
|
|
102
|
-
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
103
|
-
*/
|
|
104
|
-
toJSON(): string {
|
|
105
|
-
return this.toHexString();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Compares the equality of this UUID with `otherID`.
|
|
110
|
-
*
|
|
111
|
-
* @param otherId - UUID instance to compare against.
|
|
112
|
-
*/
|
|
113
|
-
equals(otherId: string | Buffer | UUID): boolean {
|
|
114
|
-
if (!otherId) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (otherId instanceof UUID) {
|
|
119
|
-
return otherId.id.equals(this.id);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
return new UUID(otherId).id.equals(this.id);
|
|
124
|
-
} catch {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Creates a Binary instance from the current UUID.
|
|
131
|
-
*/
|
|
132
|
-
toBinary(): Binary {
|
|
133
|
-
return new Binary(this.id, Binary.SUBTYPE_UUID);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Generates a populated buffer containing a v4 uuid
|
|
138
|
-
*/
|
|
139
|
-
static generate(): Buffer {
|
|
140
|
-
const bytes = randomBytes(BYTE_LENGTH);
|
|
141
|
-
|
|
142
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
143
|
-
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
|
144
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
145
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
146
|
-
|
|
147
|
-
return Buffer.from(bytes);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Checks if a value is a valid bson UUID
|
|
152
|
-
* @param input - UUID, string or Buffer to validate.
|
|
153
|
-
*/
|
|
154
|
-
static isValid(input: string | Buffer | UUID): boolean {
|
|
155
|
-
if (!input) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (input instanceof UUID) {
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (typeof input === 'string') {
|
|
164
|
-
return uuidValidateString(input);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isUint8Array(input)) {
|
|
168
|
-
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
|
|
169
|
-
if (input.length !== BYTE_LENGTH) {
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
// get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
|
|
175
|
-
// check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
|
|
176
|
-
return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
|
|
177
|
-
} catch {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Creates an UUID from a hex string representation of an UUID.
|
|
187
|
-
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
188
|
-
*/
|
|
189
|
-
static createFromHexString(hexString: string): UUID {
|
|
190
|
-
const buffer = uuidHexStringToBuffer(hexString);
|
|
191
|
-
return new UUID(buffer);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Converts to a string representation of this Id.
|
|
196
|
-
*
|
|
197
|
-
* @returns return the 36 character hex string representation.
|
|
198
|
-
* @internal
|
|
199
|
-
*/
|
|
200
|
-
[Symbol.for('nodejs.util.inspect.custom')](): string {
|
|
201
|
-
return this.inspect();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
inspect(): string {
|
|
205
|
-
return `new UUID("${this.toHexString()}")`;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
|