@@ -298,9 +298,7 @@ Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
298
298
export type UUIDExtended = {
299
299
$uuid : string ;
300
300
} ;
301
- const BYTE_LENGTH = 16 ;
302
-
303
- const kId = Symbol ( 'id' ) ;
301
+ const UUID_BYTE_LENGTH = 16 ;
304
302
305
303
/**
306
304
* A class representation of the BSON UUID type.
@@ -309,8 +307,6 @@ const kId = Symbol('id');
309
307
export class UUID extends Binary {
310
308
static cacheHexString : boolean ;
311
309
312
- /** UUID Bytes @internal */
313
- private [ kId ] ! : Buffer ;
314
310
/** UUID hexString cache @internal */
315
311
private __id ?: string ;
316
312
@@ -325,9 +321,9 @@ export class UUID extends Binary {
325
321
if ( input == null ) {
326
322
bytes = UUID . generate ( ) ;
327
323
} else if ( input instanceof UUID ) {
328
- bytes = Buffer . from ( input [ kId ] ) ;
324
+ bytes = Buffer . from ( input . buffer ) ;
329
325
hexStr = input . __id ;
330
- } else if ( ArrayBuffer . isView ( input ) && input . byteLength === BYTE_LENGTH ) {
326
+ } else if ( ArrayBuffer . isView ( input ) && input . byteLength === UUID_BYTE_LENGTH ) {
331
327
bytes = ensureBuffer ( input ) ;
332
328
} else if ( typeof input === 'string' ) {
333
329
bytes = uuidHexStringToBuffer ( input ) ;
@@ -337,7 +333,7 @@ export class UUID extends Binary {
337
333
) ;
338
334
}
339
335
super ( bytes , BSON_BINARY_SUBTYPE_UUID_NEW ) ;
340
- this [ kId ] = bytes ;
336
+ this . buffer = bytes ;
341
337
this . __id = hexStr ;
342
338
}
343
339
@@ -346,11 +342,11 @@ export class UUID extends Binary {
346
342
* @readonly
347
343
*/
348
344
get id ( ) : Buffer {
349
- return this [ kId ] ;
345
+ return this . buffer ;
350
346
}
351
347
352
348
set id ( value : Buffer ) {
353
- this [ kId ] = value ;
349
+ this . buffer = value ;
354
350
355
351
if ( UUID . cacheHexString ) {
356
352
this . __id = bufferToUuidHexString ( value ) ;
@@ -426,7 +422,7 @@ export class UUID extends Binary {
426
422
* Generates a populated buffer containing a v4 uuid
427
423
*/
428
424
static generate ( ) : Buffer {
429
- const bytes = randomBytes ( BYTE_LENGTH ) ;
425
+ const bytes = randomBytes ( UUID_BYTE_LENGTH ) ;
430
426
431
427
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
432
428
// Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
@@ -455,7 +451,7 @@ export class UUID extends Binary {
455
451
456
452
if ( isUint8Array ( input ) ) {
457
453
// check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
458
- if ( input . length !== BYTE_LENGTH ) {
454
+ if ( input . length !== UUID_BYTE_LENGTH ) {
459
455
return false ;
460
456
}
461
457
0 commit comments