bson 4.6.5 → 4.7.1
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 +1 -8
- package/dist/bson.browser.esm.js +262 -268
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +265 -271
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +265 -271
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +262 -268
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +183 -4
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +2 -16
- package/lib/bson.js.map +1 -1
- package/lib/double.js +5 -10
- package/lib/double.js.map +1 -1
- package/lib/parser/deserializer.js +7 -1
- package/lib/parser/deserializer.js.map +1 -1
- package/package.json +2 -1
- package/src/binary.ts +190 -3
- package/src/bson.ts +18 -23
- package/src/double.ts +5 -11
- package/src/parser/deserializer.ts +6 -1
- package/lib/uuid.js +0 -179
- package/lib/uuid.js.map +0 -1
- package/src/uuid.ts +0 -209
package/dist/bson.browser.umd.js
CHANGED
|
@@ -2271,174 +2271,84 @@
|
|
|
2271
2271
|
: buffer.toString('hex');
|
|
2272
2272
|
};
|
|
2273
2273
|
|
|
2274
|
-
|
|
2275
|
-
var
|
|
2274
|
+
/** @internal */
|
|
2275
|
+
var BSON_INT32_MAX$1 = 0x7fffffff;
|
|
2276
|
+
/** @internal */
|
|
2277
|
+
var BSON_INT32_MIN$1 = -0x80000000;
|
|
2278
|
+
/** @internal */
|
|
2279
|
+
var BSON_INT64_MAX$1 = Math.pow(2, 63) - 1;
|
|
2280
|
+
/** @internal */
|
|
2281
|
+
var BSON_INT64_MIN$1 = -Math.pow(2, 63);
|
|
2276
2282
|
/**
|
|
2277
|
-
*
|
|
2278
|
-
* @
|
|
2283
|
+
* Any integer up to 2^53 can be precisely represented by a double.
|
|
2284
|
+
* @internal
|
|
2279
2285
|
*/
|
|
2280
|
-
var
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
/**
|
|
2347
|
-
* Converts the id into its JSON string representation.
|
|
2348
|
-
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
2349
|
-
*/
|
|
2350
|
-
UUID.prototype.toJSON = function () {
|
|
2351
|
-
return this.toHexString();
|
|
2352
|
-
};
|
|
2353
|
-
/**
|
|
2354
|
-
* Compares the equality of this UUID with `otherID`.
|
|
2355
|
-
*
|
|
2356
|
-
* @param otherId - UUID instance to compare against.
|
|
2357
|
-
*/
|
|
2358
|
-
UUID.prototype.equals = function (otherId) {
|
|
2359
|
-
if (!otherId) {
|
|
2360
|
-
return false;
|
|
2361
|
-
}
|
|
2362
|
-
if (otherId instanceof UUID) {
|
|
2363
|
-
return otherId.id.equals(this.id);
|
|
2364
|
-
}
|
|
2365
|
-
try {
|
|
2366
|
-
return new UUID(otherId).id.equals(this.id);
|
|
2367
|
-
}
|
|
2368
|
-
catch (_a) {
|
|
2369
|
-
return false;
|
|
2370
|
-
}
|
|
2371
|
-
};
|
|
2372
|
-
/**
|
|
2373
|
-
* Creates a Binary instance from the current UUID.
|
|
2374
|
-
*/
|
|
2375
|
-
UUID.prototype.toBinary = function () {
|
|
2376
|
-
return new Binary(this.id, Binary.SUBTYPE_UUID);
|
|
2377
|
-
};
|
|
2378
|
-
/**
|
|
2379
|
-
* Generates a populated buffer containing a v4 uuid
|
|
2380
|
-
*/
|
|
2381
|
-
UUID.generate = function () {
|
|
2382
|
-
var bytes = randomBytes(BYTE_LENGTH);
|
|
2383
|
-
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
2384
|
-
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
|
2385
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
2386
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
2387
|
-
return buffer_1.from(bytes);
|
|
2388
|
-
};
|
|
2389
|
-
/**
|
|
2390
|
-
* Checks if a value is a valid bson UUID
|
|
2391
|
-
* @param input - UUID, string or Buffer to validate.
|
|
2392
|
-
*/
|
|
2393
|
-
UUID.isValid = function (input) {
|
|
2394
|
-
if (!input) {
|
|
2395
|
-
return false;
|
|
2396
|
-
}
|
|
2397
|
-
if (input instanceof UUID) {
|
|
2398
|
-
return true;
|
|
2399
|
-
}
|
|
2400
|
-
if (typeof input === 'string') {
|
|
2401
|
-
return uuidValidateString(input);
|
|
2402
|
-
}
|
|
2403
|
-
if (isUint8Array(input)) {
|
|
2404
|
-
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
|
|
2405
|
-
if (input.length !== BYTE_LENGTH) {
|
|
2406
|
-
return false;
|
|
2407
|
-
}
|
|
2408
|
-
try {
|
|
2409
|
-
// get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
|
|
2410
|
-
// check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
|
|
2411
|
-
return parseInt(input[6].toString(16)[0], 10) === Binary.SUBTYPE_UUID;
|
|
2412
|
-
}
|
|
2413
|
-
catch (_a) {
|
|
2414
|
-
return false;
|
|
2415
|
-
}
|
|
2416
|
-
}
|
|
2417
|
-
return false;
|
|
2418
|
-
};
|
|
2419
|
-
/**
|
|
2420
|
-
* Creates an UUID from a hex string representation of an UUID.
|
|
2421
|
-
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
2422
|
-
*/
|
|
2423
|
-
UUID.createFromHexString = function (hexString) {
|
|
2424
|
-
var buffer = uuidHexStringToBuffer(hexString);
|
|
2425
|
-
return new UUID(buffer);
|
|
2426
|
-
};
|
|
2427
|
-
/**
|
|
2428
|
-
* Converts to a string representation of this Id.
|
|
2429
|
-
*
|
|
2430
|
-
* @returns return the 36 character hex string representation.
|
|
2431
|
-
* @internal
|
|
2432
|
-
*/
|
|
2433
|
-
UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
2434
|
-
return this.inspect();
|
|
2435
|
-
};
|
|
2436
|
-
UUID.prototype.inspect = function () {
|
|
2437
|
-
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
2438
|
-
};
|
|
2439
|
-
return UUID;
|
|
2440
|
-
}());
|
|
2441
|
-
Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
|
|
2286
|
+
var JS_INT_MAX = Math.pow(2, 53);
|
|
2287
|
+
/**
|
|
2288
|
+
* Any integer down to -2^53 can be precisely represented by a double.
|
|
2289
|
+
* @internal
|
|
2290
|
+
*/
|
|
2291
|
+
var JS_INT_MIN = -Math.pow(2, 53);
|
|
2292
|
+
/** Number BSON Type @internal */
|
|
2293
|
+
var BSON_DATA_NUMBER = 1;
|
|
2294
|
+
/** String BSON Type @internal */
|
|
2295
|
+
var BSON_DATA_STRING = 2;
|
|
2296
|
+
/** Object BSON Type @internal */
|
|
2297
|
+
var BSON_DATA_OBJECT = 3;
|
|
2298
|
+
/** Array BSON Type @internal */
|
|
2299
|
+
var BSON_DATA_ARRAY = 4;
|
|
2300
|
+
/** Binary BSON Type @internal */
|
|
2301
|
+
var BSON_DATA_BINARY = 5;
|
|
2302
|
+
/** Binary BSON Type @internal */
|
|
2303
|
+
var BSON_DATA_UNDEFINED = 6;
|
|
2304
|
+
/** ObjectId BSON Type @internal */
|
|
2305
|
+
var BSON_DATA_OID = 7;
|
|
2306
|
+
/** Boolean BSON Type @internal */
|
|
2307
|
+
var BSON_DATA_BOOLEAN = 8;
|
|
2308
|
+
/** Date BSON Type @internal */
|
|
2309
|
+
var BSON_DATA_DATE = 9;
|
|
2310
|
+
/** null BSON Type @internal */
|
|
2311
|
+
var BSON_DATA_NULL = 10;
|
|
2312
|
+
/** RegExp BSON Type @internal */
|
|
2313
|
+
var BSON_DATA_REGEXP = 11;
|
|
2314
|
+
/** Code BSON Type @internal */
|
|
2315
|
+
var BSON_DATA_DBPOINTER = 12;
|
|
2316
|
+
/** Code BSON Type @internal */
|
|
2317
|
+
var BSON_DATA_CODE = 13;
|
|
2318
|
+
/** Symbol BSON Type @internal */
|
|
2319
|
+
var BSON_DATA_SYMBOL = 14;
|
|
2320
|
+
/** Code with Scope BSON Type @internal */
|
|
2321
|
+
var BSON_DATA_CODE_W_SCOPE = 15;
|
|
2322
|
+
/** 32 bit Integer BSON Type @internal */
|
|
2323
|
+
var BSON_DATA_INT = 16;
|
|
2324
|
+
/** Timestamp BSON Type @internal */
|
|
2325
|
+
var BSON_DATA_TIMESTAMP = 17;
|
|
2326
|
+
/** Long BSON Type @internal */
|
|
2327
|
+
var BSON_DATA_LONG = 18;
|
|
2328
|
+
/** Decimal128 BSON Type @internal */
|
|
2329
|
+
var BSON_DATA_DECIMAL128 = 19;
|
|
2330
|
+
/** MinKey BSON Type @internal */
|
|
2331
|
+
var BSON_DATA_MIN_KEY = 0xff;
|
|
2332
|
+
/** MaxKey BSON Type @internal */
|
|
2333
|
+
var BSON_DATA_MAX_KEY = 0x7f;
|
|
2334
|
+
/** Binary Default Type @internal */
|
|
2335
|
+
var BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
2336
|
+
/** Binary Function Type @internal */
|
|
2337
|
+
var BSON_BINARY_SUBTYPE_FUNCTION = 1;
|
|
2338
|
+
/** Binary Byte Array Type @internal */
|
|
2339
|
+
var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
|
|
2340
|
+
/** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
|
|
2341
|
+
var BSON_BINARY_SUBTYPE_UUID = 3;
|
|
2342
|
+
/** Binary UUID Type @internal */
|
|
2343
|
+
var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
|
2344
|
+
/** Binary MD5 Type @internal */
|
|
2345
|
+
var BSON_BINARY_SUBTYPE_MD5 = 5;
|
|
2346
|
+
/** Encrypted BSON type @internal */
|
|
2347
|
+
var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
|
|
2348
|
+
/** Column BSON type @internal */
|
|
2349
|
+
var BSON_BINARY_SUBTYPE_COLUMN = 7;
|
|
2350
|
+
/** Binary User Defined Type @internal */
|
|
2351
|
+
var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
|
2442
2352
|
|
|
2443
2353
|
/**
|
|
2444
2354
|
* A class representation of the BSON Binary type.
|
|
@@ -2639,7 +2549,7 @@
|
|
|
2639
2549
|
if (!data) {
|
|
2640
2550
|
throw new BSONTypeError("Unexpected Binary Extended JSON format ".concat(JSON.stringify(doc)));
|
|
2641
2551
|
}
|
|
2642
|
-
return new Binary(data, type);
|
|
2552
|
+
return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new Binary(data, type);
|
|
2643
2553
|
};
|
|
2644
2554
|
/** @internal */
|
|
2645
2555
|
Binary.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
@@ -2677,6 +2587,168 @@
|
|
|
2677
2587
|
return Binary;
|
|
2678
2588
|
}());
|
|
2679
2589
|
Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
|
|
2590
|
+
var UUID_BYTE_LENGTH = 16;
|
|
2591
|
+
/**
|
|
2592
|
+
* A class representation of the BSON UUID type.
|
|
2593
|
+
* @public
|
|
2594
|
+
*/
|
|
2595
|
+
var UUID = /** @class */ (function (_super) {
|
|
2596
|
+
__extends(UUID, _super);
|
|
2597
|
+
/**
|
|
2598
|
+
* Create an UUID type
|
|
2599
|
+
*
|
|
2600
|
+
* @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
|
|
2601
|
+
*/
|
|
2602
|
+
function UUID(input) {
|
|
2603
|
+
var _this = this;
|
|
2604
|
+
var bytes;
|
|
2605
|
+
var hexStr;
|
|
2606
|
+
if (input == null) {
|
|
2607
|
+
bytes = UUID.generate();
|
|
2608
|
+
}
|
|
2609
|
+
else if (input instanceof UUID) {
|
|
2610
|
+
bytes = buffer_1.from(input.buffer);
|
|
2611
|
+
hexStr = input.__id;
|
|
2612
|
+
}
|
|
2613
|
+
else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
|
|
2614
|
+
bytes = ensureBuffer(input);
|
|
2615
|
+
}
|
|
2616
|
+
else if (typeof input === 'string') {
|
|
2617
|
+
bytes = uuidHexStringToBuffer(input);
|
|
2618
|
+
}
|
|
2619
|
+
else {
|
|
2620
|
+
throw new 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).');
|
|
2621
|
+
}
|
|
2622
|
+
_this = _super.call(this, bytes, BSON_BINARY_SUBTYPE_UUID_NEW) || this;
|
|
2623
|
+
_this.__id = hexStr;
|
|
2624
|
+
return _this;
|
|
2625
|
+
}
|
|
2626
|
+
Object.defineProperty(UUID.prototype, "id", {
|
|
2627
|
+
/**
|
|
2628
|
+
* The UUID bytes
|
|
2629
|
+
* @readonly
|
|
2630
|
+
*/
|
|
2631
|
+
get: function () {
|
|
2632
|
+
return this.buffer;
|
|
2633
|
+
},
|
|
2634
|
+
set: function (value) {
|
|
2635
|
+
this.buffer = value;
|
|
2636
|
+
if (UUID.cacheHexString) {
|
|
2637
|
+
this.__id = bufferToUuidHexString(value);
|
|
2638
|
+
}
|
|
2639
|
+
},
|
|
2640
|
+
enumerable: false,
|
|
2641
|
+
configurable: true
|
|
2642
|
+
});
|
|
2643
|
+
/**
|
|
2644
|
+
* Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
|
|
2645
|
+
* @param includeDashes - should the string exclude dash-separators.
|
|
2646
|
+
* */
|
|
2647
|
+
UUID.prototype.toHexString = function (includeDashes) {
|
|
2648
|
+
if (includeDashes === void 0) { includeDashes = true; }
|
|
2649
|
+
if (UUID.cacheHexString && this.__id) {
|
|
2650
|
+
return this.__id;
|
|
2651
|
+
}
|
|
2652
|
+
var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
|
|
2653
|
+
if (UUID.cacheHexString) {
|
|
2654
|
+
this.__id = uuidHexString;
|
|
2655
|
+
}
|
|
2656
|
+
return uuidHexString;
|
|
2657
|
+
};
|
|
2658
|
+
/**
|
|
2659
|
+
* Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
|
|
2660
|
+
*/
|
|
2661
|
+
UUID.prototype.toString = function (encoding) {
|
|
2662
|
+
return encoding ? this.id.toString(encoding) : this.toHexString();
|
|
2663
|
+
};
|
|
2664
|
+
/**
|
|
2665
|
+
* Converts the id into its JSON string representation.
|
|
2666
|
+
* A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
2667
|
+
*/
|
|
2668
|
+
UUID.prototype.toJSON = function () {
|
|
2669
|
+
return this.toHexString();
|
|
2670
|
+
};
|
|
2671
|
+
/**
|
|
2672
|
+
* Compares the equality of this UUID with `otherID`.
|
|
2673
|
+
*
|
|
2674
|
+
* @param otherId - UUID instance to compare against.
|
|
2675
|
+
*/
|
|
2676
|
+
UUID.prototype.equals = function (otherId) {
|
|
2677
|
+
if (!otherId) {
|
|
2678
|
+
return false;
|
|
2679
|
+
}
|
|
2680
|
+
if (otherId instanceof UUID) {
|
|
2681
|
+
return otherId.id.equals(this.id);
|
|
2682
|
+
}
|
|
2683
|
+
try {
|
|
2684
|
+
return new UUID(otherId).id.equals(this.id);
|
|
2685
|
+
}
|
|
2686
|
+
catch (_a) {
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
/**
|
|
2691
|
+
* Creates a Binary instance from the current UUID.
|
|
2692
|
+
*/
|
|
2693
|
+
UUID.prototype.toBinary = function () {
|
|
2694
|
+
return new Binary(this.id, Binary.SUBTYPE_UUID);
|
|
2695
|
+
};
|
|
2696
|
+
/**
|
|
2697
|
+
* Generates a populated buffer containing a v4 uuid
|
|
2698
|
+
*/
|
|
2699
|
+
UUID.generate = function () {
|
|
2700
|
+
var bytes = randomBytes(UUID_BYTE_LENGTH);
|
|
2701
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
2702
|
+
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
|
|
2703
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
2704
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
2705
|
+
return buffer_1.from(bytes);
|
|
2706
|
+
};
|
|
2707
|
+
/**
|
|
2708
|
+
* Checks if a value is a valid bson UUID
|
|
2709
|
+
* @param input - UUID, string or Buffer to validate.
|
|
2710
|
+
*/
|
|
2711
|
+
UUID.isValid = function (input) {
|
|
2712
|
+
if (!input) {
|
|
2713
|
+
return false;
|
|
2714
|
+
}
|
|
2715
|
+
if (input instanceof UUID) {
|
|
2716
|
+
return true;
|
|
2717
|
+
}
|
|
2718
|
+
if (typeof input === 'string') {
|
|
2719
|
+
return uuidValidateString(input);
|
|
2720
|
+
}
|
|
2721
|
+
if (isUint8Array(input)) {
|
|
2722
|
+
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
|
|
2723
|
+
if (input.length !== UUID_BYTE_LENGTH) {
|
|
2724
|
+
return false;
|
|
2725
|
+
}
|
|
2726
|
+
return (input[6] & 0xf0) === 0x40 && (input[8] & 0x80) === 0x80;
|
|
2727
|
+
}
|
|
2728
|
+
return false;
|
|
2729
|
+
};
|
|
2730
|
+
/**
|
|
2731
|
+
* Creates an UUID from a hex string representation of an UUID.
|
|
2732
|
+
* @param hexString - 32 or 36 character hex string (dashes excluded/included).
|
|
2733
|
+
*/
|
|
2734
|
+
UUID.createFromHexString = function (hexString) {
|
|
2735
|
+
var buffer = uuidHexStringToBuffer(hexString);
|
|
2736
|
+
return new UUID(buffer);
|
|
2737
|
+
};
|
|
2738
|
+
/**
|
|
2739
|
+
* Converts to a string representation of this Id.
|
|
2740
|
+
*
|
|
2741
|
+
* @returns return the 36 character hex string representation.
|
|
2742
|
+
* @internal
|
|
2743
|
+
*/
|
|
2744
|
+
UUID.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
|
|
2745
|
+
return this.inspect();
|
|
2746
|
+
};
|
|
2747
|
+
UUID.prototype.inspect = function () {
|
|
2748
|
+
return "new UUID(\"".concat(this.toHexString(), "\")");
|
|
2749
|
+
};
|
|
2750
|
+
return UUID;
|
|
2751
|
+
}(Binary));
|
|
2680
2752
|
|
|
2681
2753
|
/**
|
|
2682
2754
|
* A class representation of the BSON Code type.
|
|
@@ -4405,22 +4477,17 @@
|
|
|
4405
4477
|
if (options && (options.legacy || (options.relaxed && isFinite(this.value)))) {
|
|
4406
4478
|
return this.value;
|
|
4407
4479
|
}
|
|
4408
|
-
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
|
4409
|
-
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
|
4410
4480
|
if (Object.is(Math.sign(this.value), -0)) {
|
|
4411
|
-
|
|
4481
|
+
// NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
|
|
4482
|
+
// explicitly provided `-0` then we need to ensure the sign makes it into the output
|
|
4483
|
+
return { $numberDouble: '-0.0' };
|
|
4412
4484
|
}
|
|
4413
|
-
var $numberDouble;
|
|
4414
4485
|
if (Number.isInteger(this.value)) {
|
|
4415
|
-
$numberDouble
|
|
4416
|
-
if ($numberDouble.length >= 13) {
|
|
4417
|
-
$numberDouble = this.value.toExponential(13).toUpperCase();
|
|
4418
|
-
}
|
|
4486
|
+
return { $numberDouble: "".concat(this.value, ".0") };
|
|
4419
4487
|
}
|
|
4420
4488
|
else {
|
|
4421
|
-
$numberDouble
|
|
4489
|
+
return { $numberDouble: "".concat(this.value) };
|
|
4422
4490
|
}
|
|
4423
|
-
return { $numberDouble: $numberDouble };
|
|
4424
4491
|
};
|
|
4425
4492
|
/** @internal */
|
|
4426
4493
|
Double.fromExtendedJSON = function (doc, options) {
|
|
@@ -5040,12 +5107,12 @@
|
|
|
5040
5107
|
return (isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string');
|
|
5041
5108
|
}
|
|
5042
5109
|
// INT32 boundaries
|
|
5043
|
-
var BSON_INT32_MAX
|
|
5044
|
-
var BSON_INT32_MIN
|
|
5110
|
+
var BSON_INT32_MAX = 0x7fffffff;
|
|
5111
|
+
var BSON_INT32_MIN = -0x80000000;
|
|
5045
5112
|
// INT64 boundaries
|
|
5046
5113
|
// const BSON_INT64_MAX = 0x7fffffffffffffff; // TODO(NODE-4377): This number cannot be precisely represented in JS
|
|
5047
|
-
var BSON_INT64_MAX
|
|
5048
|
-
var BSON_INT64_MIN
|
|
5114
|
+
var BSON_INT64_MAX = 0x8000000000000000;
|
|
5115
|
+
var BSON_INT64_MIN = -0x8000000000000000;
|
|
5049
5116
|
// all the types where we don't need to do any special processing and can just pass the EJSON
|
|
5050
5117
|
//straight to type.fromExtendedJSON
|
|
5051
5118
|
var keysToCodecs = {
|
|
@@ -5073,9 +5140,9 @@
|
|
|
5073
5140
|
// if it's an integer, should interpret as smallest BSON integer
|
|
5074
5141
|
// that can represent it exactly. (if out of range, interpret as double.)
|
|
5075
5142
|
if (Math.floor(value) === value) {
|
|
5076
|
-
if (value >= BSON_INT32_MIN
|
|
5143
|
+
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX)
|
|
5077
5144
|
return new Int32(value);
|
|
5078
|
-
if (value >= BSON_INT64_MIN
|
|
5145
|
+
if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX)
|
|
5079
5146
|
return Long.fromNumber(value);
|
|
5080
5147
|
}
|
|
5081
5148
|
// If the number is a non-integer or out of integer range, should interpret as BSON Double.
|
|
@@ -5199,7 +5266,7 @@
|
|
|
5199
5266
|
if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
|
|
5200
5267
|
// it's an integer
|
|
5201
5268
|
if (Math.floor(value) === value) {
|
|
5202
|
-
var int32Range = value >= BSON_INT32_MIN
|
|
5269
|
+
var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX, int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX;
|
|
5203
5270
|
// interpret as being of the smallest BSON integer type that can represent the number exactly
|
|
5204
5271
|
if (int32Range)
|
|
5205
5272
|
return { $numberInt: value.toString() };
|
|
@@ -5524,85 +5591,6 @@
|
|
|
5524
5591
|
}());
|
|
5525
5592
|
}
|
|
5526
5593
|
|
|
5527
|
-
/** @internal */
|
|
5528
|
-
var BSON_INT32_MAX = 0x7fffffff;
|
|
5529
|
-
/** @internal */
|
|
5530
|
-
var BSON_INT32_MIN = -0x80000000;
|
|
5531
|
-
/** @internal */
|
|
5532
|
-
var BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
5533
|
-
/** @internal */
|
|
5534
|
-
var BSON_INT64_MIN = -Math.pow(2, 63);
|
|
5535
|
-
/**
|
|
5536
|
-
* Any integer up to 2^53 can be precisely represented by a double.
|
|
5537
|
-
* @internal
|
|
5538
|
-
*/
|
|
5539
|
-
var JS_INT_MAX = Math.pow(2, 53);
|
|
5540
|
-
/**
|
|
5541
|
-
* Any integer down to -2^53 can be precisely represented by a double.
|
|
5542
|
-
* @internal
|
|
5543
|
-
*/
|
|
5544
|
-
var JS_INT_MIN = -Math.pow(2, 53);
|
|
5545
|
-
/** Number BSON Type @internal */
|
|
5546
|
-
var BSON_DATA_NUMBER = 1;
|
|
5547
|
-
/** String BSON Type @internal */
|
|
5548
|
-
var BSON_DATA_STRING = 2;
|
|
5549
|
-
/** Object BSON Type @internal */
|
|
5550
|
-
var BSON_DATA_OBJECT = 3;
|
|
5551
|
-
/** Array BSON Type @internal */
|
|
5552
|
-
var BSON_DATA_ARRAY = 4;
|
|
5553
|
-
/** Binary BSON Type @internal */
|
|
5554
|
-
var BSON_DATA_BINARY = 5;
|
|
5555
|
-
/** Binary BSON Type @internal */
|
|
5556
|
-
var BSON_DATA_UNDEFINED = 6;
|
|
5557
|
-
/** ObjectId BSON Type @internal */
|
|
5558
|
-
var BSON_DATA_OID = 7;
|
|
5559
|
-
/** Boolean BSON Type @internal */
|
|
5560
|
-
var BSON_DATA_BOOLEAN = 8;
|
|
5561
|
-
/** Date BSON Type @internal */
|
|
5562
|
-
var BSON_DATA_DATE = 9;
|
|
5563
|
-
/** null BSON Type @internal */
|
|
5564
|
-
var BSON_DATA_NULL = 10;
|
|
5565
|
-
/** RegExp BSON Type @internal */
|
|
5566
|
-
var BSON_DATA_REGEXP = 11;
|
|
5567
|
-
/** Code BSON Type @internal */
|
|
5568
|
-
var BSON_DATA_DBPOINTER = 12;
|
|
5569
|
-
/** Code BSON Type @internal */
|
|
5570
|
-
var BSON_DATA_CODE = 13;
|
|
5571
|
-
/** Symbol BSON Type @internal */
|
|
5572
|
-
var BSON_DATA_SYMBOL = 14;
|
|
5573
|
-
/** Code with Scope BSON Type @internal */
|
|
5574
|
-
var BSON_DATA_CODE_W_SCOPE = 15;
|
|
5575
|
-
/** 32 bit Integer BSON Type @internal */
|
|
5576
|
-
var BSON_DATA_INT = 16;
|
|
5577
|
-
/** Timestamp BSON Type @internal */
|
|
5578
|
-
var BSON_DATA_TIMESTAMP = 17;
|
|
5579
|
-
/** Long BSON Type @internal */
|
|
5580
|
-
var BSON_DATA_LONG = 18;
|
|
5581
|
-
/** Decimal128 BSON Type @internal */
|
|
5582
|
-
var BSON_DATA_DECIMAL128 = 19;
|
|
5583
|
-
/** MinKey BSON Type @internal */
|
|
5584
|
-
var BSON_DATA_MIN_KEY = 0xff;
|
|
5585
|
-
/** MaxKey BSON Type @internal */
|
|
5586
|
-
var BSON_DATA_MAX_KEY = 0x7f;
|
|
5587
|
-
/** Binary Default Type @internal */
|
|
5588
|
-
var BSON_BINARY_SUBTYPE_DEFAULT = 0;
|
|
5589
|
-
/** Binary Function Type @internal */
|
|
5590
|
-
var BSON_BINARY_SUBTYPE_FUNCTION = 1;
|
|
5591
|
-
/** Binary Byte Array Type @internal */
|
|
5592
|
-
var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
|
|
5593
|
-
/** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
|
|
5594
|
-
var BSON_BINARY_SUBTYPE_UUID = 3;
|
|
5595
|
-
/** Binary UUID Type @internal */
|
|
5596
|
-
var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
|
5597
|
-
/** Binary MD5 Type @internal */
|
|
5598
|
-
var BSON_BINARY_SUBTYPE_MD5 = 5;
|
|
5599
|
-
/** Encrypted BSON type @internal */
|
|
5600
|
-
var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
|
|
5601
|
-
/** Column BSON type @internal */
|
|
5602
|
-
var BSON_BINARY_SUBTYPE_COLUMN = 7;
|
|
5603
|
-
/** Binary User Defined Type @internal */
|
|
5604
|
-
var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
|
5605
|
-
|
|
5606
5594
|
function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
|
|
5607
5595
|
var totalLength = 4 + 1;
|
|
5608
5596
|
if (Array.isArray(object)) {
|
|
@@ -5640,7 +5628,7 @@
|
|
|
5640
5628
|
if (Math.floor(value) === value &&
|
|
5641
5629
|
value >= JS_INT_MIN &&
|
|
5642
5630
|
value <= JS_INT_MAX) {
|
|
5643
|
-
if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
|
|
5631
|
+
if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) {
|
|
5644
5632
|
// 32 bit
|
|
5645
5633
|
return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
|
|
5646
5634
|
}
|
|
@@ -6142,6 +6130,9 @@
|
|
|
6142
6130
|
}
|
|
6143
6131
|
else {
|
|
6144
6132
|
value = new Binary(buffer.slice(index, index + binarySize), subType);
|
|
6133
|
+
if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
|
|
6134
|
+
value = value.toUUID();
|
|
6135
|
+
}
|
|
6145
6136
|
}
|
|
6146
6137
|
}
|
|
6147
6138
|
else {
|
|
@@ -6167,8 +6158,11 @@
|
|
|
6167
6158
|
if (promoteBuffers && promoteValues) {
|
|
6168
6159
|
value = _buffer;
|
|
6169
6160
|
}
|
|
6161
|
+
else if (subType === BSON_BINARY_SUBTYPE_UUID_NEW) {
|
|
6162
|
+
value = new Binary(buffer.slice(index, index + binarySize), subType).toUUID();
|
|
6163
|
+
}
|
|
6170
6164
|
else {
|
|
6171
|
-
value = new Binary(
|
|
6165
|
+
value = new Binary(buffer.slice(index, index + binarySize), subType);
|
|
6172
6166
|
}
|
|
6173
6167
|
}
|
|
6174
6168
|
// Update the index
|
|
@@ -6495,8 +6489,8 @@
|
|
|
6495
6489
|
// We have an integer value
|
|
6496
6490
|
// TODO(NODE-2529): Add support for big int
|
|
6497
6491
|
if (Number.isInteger(value) &&
|
|
6498
|
-
value >= BSON_INT32_MIN &&
|
|
6499
|
-
value <= BSON_INT32_MAX) {
|
|
6492
|
+
value >= BSON_INT32_MIN$1 &&
|
|
6493
|
+
value <= BSON_INT32_MAX$1) {
|
|
6500
6494
|
// If the value fits in 32 bits encode as int32
|
|
6501
6495
|
// Set int type 32 bits or less
|
|
6502
6496
|
buffer[index++] = BSON_DATA_INT;
|
|
@@ -7506,10 +7500,10 @@
|
|
|
7506
7500
|
exports.BSON_DATA_SYMBOL = BSON_DATA_SYMBOL;
|
|
7507
7501
|
exports.BSON_DATA_TIMESTAMP = BSON_DATA_TIMESTAMP;
|
|
7508
7502
|
exports.BSON_DATA_UNDEFINED = BSON_DATA_UNDEFINED;
|
|
7509
|
-
exports.BSON_INT32_MAX = BSON_INT32_MAX;
|
|
7510
|
-
exports.BSON_INT32_MIN = BSON_INT32_MIN;
|
|
7511
|
-
exports.BSON_INT64_MAX = BSON_INT64_MAX;
|
|
7512
|
-
exports.BSON_INT64_MIN = BSON_INT64_MIN;
|
|
7503
|
+
exports.BSON_INT32_MAX = BSON_INT32_MAX$1;
|
|
7504
|
+
exports.BSON_INT32_MIN = BSON_INT32_MIN$1;
|
|
7505
|
+
exports.BSON_INT64_MAX = BSON_INT64_MAX$1;
|
|
7506
|
+
exports.BSON_INT64_MIN = BSON_INT64_MIN$1;
|
|
7513
7507
|
exports.Binary = Binary;
|
|
7514
7508
|
exports.Code = Code;
|
|
7515
7509
|
exports.DBRef = DBRef;
|