Class UUID

A class representation of the BSON UUID type.

Hierarchy (view full)

Constructors

  • Create a UUID type

    When the argument to the constructor is omitted a random v4 UUID will be generated.

    Parameters

    • Optionalinput: string | Uint8Array | UUID

      Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.

    Returns UUID

Properties

buffer: Uint8Array

The bytes of the Binary value.

The format of a Binary value in BSON is defined as:

binary	::= int32 subtype (byte*)

This buffer is the "(byte*)" segment.

Unless the value is subtype 2, then deserialize will read the first 4 bytes as an int32 and set this to the remaining bytes.

binary	::= int32 unsigned_byte(2) int32 (byte*)
position: number

The Binary's buffer can be larger than the Binary's content. This property is used to determine where the content ends in the buffer.

sub_type: number

The binary subtype.

Current defined values are:

  • unsigned_byte(0) Generic binary subtype
  • unsigned_byte(1) Function
  • unsigned_byte(2) Binary (Deprecated)
  • unsigned_byte(3) UUID (Deprecated)
  • unsigned_byte(4) UUID
  • unsigned_byte(5) MD5
  • unsigned_byte(6) Encrypted BSON value
  • unsigned_byte(7) Compressed BSON column
  • unsigned_byte(8) Sensitive
  • unsigned_byte(9) Vector
  • unsigned_byte(128) - unsigned_byte(255) User defined
BUFFER_SIZE: 256 = 256

Initial buffer default size

SUBTYPE_BYTE_ARRAY: 2 = 2

Byte Array BSON type

SUBTYPE_COLUMN: 7 = 7

Column BSON type

SUBTYPE_DEFAULT: 0 = 0

Default BSON type

SUBTYPE_ENCRYPTED: 6 = 6

Encrypted BSON type

SUBTYPE_FUNCTION: 1 = 1

Function BSON type

SUBTYPE_MD5: 5 = 5

MD5 BSON type

SUBTYPE_SENSITIVE: 8 = 8

Sensitive BSON type

SUBTYPE_USER_DEFINED: 128 = 128

User BSON type

SUBTYPE_UUID: 4 = 4

UUID BSON type

SUBTYPE_UUID_OLD: 3 = 3

Deprecated UUID BSON type

Please use SUBTYPE_UUID

SUBTYPE_VECTOR: 9 = 9

Vector BSON type

VECTOR_TYPE: Readonly<{
    Float32: 39;
    Int8: 3;
    PackedBit: 16;
}>

datatype of a Binary Vector (subtype: 9)

Accessors

  • get _bsontype(): "Binary"
  • Returns "Binary"

  • get id(): Uint8Array
  • The UUID bytes

    Returns Uint8Array

Methods

  • Compares the equality of this UUID with otherID.

    Parameters

    • otherId: string | Uint8Array | UUID

      UUID instance to compare against.

    Returns boolean

  • Converts to a string representation of this Id.

    Parameters

    • Optionaldepth: number
    • Optionaloptions: unknown
    • Optionalinspect: InspectFn

    Returns string

    return the 36 character hex string representation.

  • the length of the binary sequence

    Returns number

  • Updates this binary with byte_value.

    Parameters

    • byteValue:
          | string
          | number
          | Uint8Array
          | number[]

      a single byte we wish to write.

    Returns void

  • Returns a view of length bytes starting at position.

    Parameters

    • position: number

      read from the given position in the Binary.

    • length: number

      the number of bytes to read.

    Returns Uint8Array

  • Creates a Binary instance from the current UUID.

    Returns Binary

  • If this Binary represents a Packed bit Vector (binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit), returns a copy of the bit unpacked into a new Int8Array.

    Use toPackedBits to get the bits still in packed form.

    If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.

    Returns Int8Array

  • If this Binary represents a Float32 Vector (binary.buffer[0] === Binary.VECTOR_TYPE.Float32), returns a copy of the bytes in a new Float32Array.

    If the Binary is not a Vector, or the datatype is not Float32, an error is thrown.

    Returns Float32Array

  • Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)

    Parameters

    • OptionalincludeDashes: boolean

      should the string exclude dash-separators.

    Returns string

  • If this Binary represents a Int8 Vector (binary.buffer[0] === Binary.VECTOR_TYPE.Int8), returns a copy of the bytes in a new Int8Array.

    If the Binary is not a Vector, or the datatype is not Int8, an error is thrown.

    Returns Int8Array

  • Converts the id into its JSON string representation. A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    Returns string

  • If this Binary represents packed bit Vector (binary.buffer[0] === Binary.VECTOR_TYPE.PackedBit), returns a copy of the bytes that are packed bits.

    Use toBits to get the unpacked bits.

    If the Binary is not a Vector, or the datatype is not PackedBit, an error is thrown.

    Returns Uint8Array

  • Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.

    Parameters

    • Optionalencoding: "base64" | "hex"

    Returns string

  • returns a view of the binary value as a Uint8Array

    Returns Uint8Array

  • Writes a buffer to the binary.

    Parameters

    • sequence: BinarySequence

      a string or buffer to be written to the Binary BSON object.

    • offset: number

      specify the binary of where to write the content.

    Returns void

  • Creates an UUID from a base64 string representation of an UUID.

    Parameters

    • base64: string

    Returns UUID

  • Creates an UUID from a hex string representation of an UUID.

    Parameters

    • hexString: string

      32 or 36 character hex string (dashes excluded/included).

    Returns UUID

  • Constructs a Binary representing an Packed Bit Vector.

    Parameters

    • bits: ArrayLike<number>

    Returns Binary

  • Constructs a Binary representing an Float32 Vector.

    Parameters

    • array: Float32Array

    Returns Binary

  • Constructs a Binary representing an Int8 Vector.

    Parameters

    • array: Int8Array

      The array to store as a view on the Binary class

    Returns Binary

  • Constructs a Binary representing a packed bit Vector.

    Use fromBits to pack an array of 1s and 0s.

    Parameters

    • array: Uint8Array
    • Optionalpadding: number

    Returns Binary

  • Generates a populated buffer containing a v4 uuid

    Returns Uint8Array

  • Checks if a value is a valid bson UUID

    Parameters

    • input:
          | string
          | Uint8Array
          | Binary
          | UUID

      UUID, string or Buffer to validate.

    Returns boolean