bson.d.ts 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /**
  2. * A class representation of the BSON Binary type.
  3. * @public
  4. * @category BSONType
  5. */
  6. export declare class Binary extends BSONValue {
  7. get _bsontype(): 'Binary';
  8. /* Excluded from this release type: BSON_BINARY_SUBTYPE_DEFAULT */
  9. /** Initial buffer default size */
  10. static readonly BUFFER_SIZE = 256;
  11. /** Default BSON type */
  12. static readonly SUBTYPE_DEFAULT = 0;
  13. /** Function BSON type */
  14. static readonly SUBTYPE_FUNCTION = 1;
  15. /** Byte Array BSON type */
  16. static readonly SUBTYPE_BYTE_ARRAY = 2;
  17. /** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
  18. static readonly SUBTYPE_UUID_OLD = 3;
  19. /** UUID BSON type */
  20. static readonly SUBTYPE_UUID = 4;
  21. /** MD5 BSON type */
  22. static readonly SUBTYPE_MD5 = 5;
  23. /** Encrypted BSON type */
  24. static readonly SUBTYPE_ENCRYPTED = 6;
  25. /** Column BSON type */
  26. static readonly SUBTYPE_COLUMN = 7;
  27. /** User BSON type */
  28. static readonly SUBTYPE_USER_DEFINED = 128;
  29. buffer: Uint8Array;
  30. sub_type: number;
  31. position: number;
  32. /**
  33. * Create a new Binary instance.
  34. * @param buffer - a buffer object containing the binary data.
  35. * @param subType - the option binary type.
  36. */
  37. constructor(buffer?: BinarySequence, subType?: number);
  38. /**
  39. * Updates this binary with byte_value.
  40. *
  41. * @param byteValue - a single byte we wish to write.
  42. */
  43. put(byteValue: string | number | Uint8Array | number[]): void;
  44. /**
  45. * Writes a buffer to the binary.
  46. *
  47. * @param sequence - a string or buffer to be written to the Binary BSON object.
  48. * @param offset - specify the binary of where to write the content.
  49. */
  50. write(sequence: BinarySequence, offset: number): void;
  51. /**
  52. * Reads **length** bytes starting at **position**.
  53. *
  54. * @param position - read from the given position in the Binary.
  55. * @param length - the number of bytes to read.
  56. */
  57. read(position: number, length: number): BinarySequence;
  58. /** returns a view of the binary value as a Uint8Array */
  59. value(): Uint8Array;
  60. /** the length of the binary sequence */
  61. length(): number;
  62. toJSON(): string;
  63. toString(encoding?: 'hex' | 'base64' | 'utf8' | 'utf-8'): string;
  64. /* Excluded from this release type: toExtendedJSON */
  65. toUUID(): UUID;
  66. /** Creates an Binary instance from a hex digit string */
  67. static createFromHexString(hex: string, subType?: number): Binary;
  68. /** Creates an Binary instance from a base64 string */
  69. static createFromBase64(base64: string, subType?: number): Binary;
  70. /* Excluded from this release type: fromExtendedJSON */
  71. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  72. }
  73. /** @public */
  74. export declare interface BinaryExtended {
  75. $binary: {
  76. subType: string;
  77. base64: string;
  78. };
  79. }
  80. /** @public */
  81. export declare interface BinaryExtendedLegacy {
  82. $type: string;
  83. $binary: string;
  84. }
  85. /** @public */
  86. export declare type BinarySequence = Uint8Array | number[];
  87. declare namespace BSON {
  88. export {
  89. setInternalBufferSize,
  90. serialize,
  91. serializeWithBufferAndIndex,
  92. deserialize,
  93. calculateObjectSize,
  94. deserializeStream,
  95. UUIDExtended,
  96. BinaryExtended,
  97. BinaryExtendedLegacy,
  98. BinarySequence,
  99. CodeExtended,
  100. DBRefLike,
  101. Decimal128Extended,
  102. DoubleExtended,
  103. EJSONOptions,
  104. Int32Extended,
  105. LongExtended,
  106. MaxKeyExtended,
  107. MinKeyExtended,
  108. ObjectIdExtended,
  109. ObjectIdLike,
  110. BSONRegExpExtended,
  111. BSONRegExpExtendedLegacy,
  112. BSONSymbolExtended,
  113. LongWithoutOverrides,
  114. TimestampExtended,
  115. TimestampOverrides,
  116. LongWithoutOverridesClass,
  117. SerializeOptions,
  118. DeserializeOptions,
  119. Code,
  120. BSONSymbol,
  121. DBRef,
  122. Binary,
  123. ObjectId,
  124. UUID,
  125. Long,
  126. Timestamp,
  127. Double,
  128. Int32,
  129. MinKey,
  130. MaxKey,
  131. BSONRegExp,
  132. Decimal128,
  133. BSONValue,
  134. BSONError,
  135. BSONVersionError,
  136. BSONRuntimeError,
  137. BSONType,
  138. EJSON,
  139. Document,
  140. CalculateObjectSizeOptions
  141. }
  142. }
  143. export { BSON }
  144. /**
  145. * @public
  146. * @category Error
  147. *
  148. * `BSONError` objects are thrown when BSON ecounters an error.
  149. *
  150. * This is the parent class for all the other errors thrown by this library.
  151. */
  152. export declare class BSONError extends Error {
  153. /* Excluded from this release type: bsonError */
  154. get name(): string;
  155. constructor(message: string);
  156. /**
  157. * @public
  158. *
  159. * All errors thrown from the BSON library inherit from `BSONError`.
  160. * This method can assist with determining if an error originates from the BSON library
  161. * even if it does not pass an `instanceof` check against this class' constructor.
  162. *
  163. * @param value - any javascript value that needs type checking
  164. */
  165. static isBSONError(value: unknown): value is BSONError;
  166. }
  167. /**
  168. * A class representation of the BSON RegExp type.
  169. * @public
  170. * @category BSONType
  171. */
  172. export declare class BSONRegExp extends BSONValue {
  173. get _bsontype(): 'BSONRegExp';
  174. pattern: string;
  175. options: string;
  176. /**
  177. * @param pattern - The regular expression pattern to match
  178. * @param options - The regular expression options
  179. */
  180. constructor(pattern: string, options?: string);
  181. static parseOptions(options?: string): string;
  182. /* Excluded from this release type: toExtendedJSON */
  183. /* Excluded from this release type: fromExtendedJSON */
  184. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  185. }
  186. /** @public */
  187. export declare interface BSONRegExpExtended {
  188. $regularExpression: {
  189. pattern: string;
  190. options: string;
  191. };
  192. }
  193. /** @public */
  194. export declare interface BSONRegExpExtendedLegacy {
  195. $regex: string | BSONRegExp;
  196. $options: string;
  197. }
  198. /**
  199. * @public
  200. * @category Error
  201. *
  202. * An error generated when BSON functions encounter an unexpected input
  203. * or reaches an unexpected/invalid internal state
  204. *
  205. */
  206. export declare class BSONRuntimeError extends BSONError {
  207. get name(): 'BSONRuntimeError';
  208. constructor(message: string);
  209. }
  210. /**
  211. * A class representation of the BSON Symbol type.
  212. * @public
  213. * @category BSONType
  214. */
  215. export declare class BSONSymbol extends BSONValue {
  216. get _bsontype(): 'BSONSymbol';
  217. value: string;
  218. /**
  219. * @param value - the string representing the symbol.
  220. */
  221. constructor(value: string);
  222. /** Access the wrapped string value. */
  223. valueOf(): string;
  224. toString(): string;
  225. toJSON(): string;
  226. /* Excluded from this release type: toExtendedJSON */
  227. /* Excluded from this release type: fromExtendedJSON */
  228. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  229. }
  230. /** @public */
  231. export declare interface BSONSymbolExtended {
  232. $symbol: string;
  233. }
  234. /** @public */
  235. export declare const BSONType: Readonly<{
  236. readonly double: 1;
  237. readonly string: 2;
  238. readonly object: 3;
  239. readonly array: 4;
  240. readonly binData: 5;
  241. readonly undefined: 6;
  242. readonly objectId: 7;
  243. readonly bool: 8;
  244. readonly date: 9;
  245. readonly null: 10;
  246. readonly regex: 11;
  247. readonly dbPointer: 12;
  248. readonly javascript: 13;
  249. readonly symbol: 14;
  250. readonly javascriptWithScope: 15;
  251. readonly int: 16;
  252. readonly timestamp: 17;
  253. readonly long: 18;
  254. readonly decimal: 19;
  255. readonly minKey: -1;
  256. readonly maxKey: 127;
  257. }>;
  258. /** @public */
  259. export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
  260. /** @public */
  261. export declare abstract class BSONValue {
  262. /** @public */
  263. abstract get _bsontype(): string;
  264. /**
  265. * @public
  266. * Prints a human-readable string of BSON value information
  267. * If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify
  268. */
  269. abstract inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  270. /* Excluded from this release type: toExtendedJSON */
  271. }
  272. /**
  273. * @public
  274. * @category Error
  275. */
  276. export declare class BSONVersionError extends BSONError {
  277. get name(): 'BSONVersionError';
  278. constructor();
  279. }
  280. /**
  281. * Calculate the bson size for a passed in Javascript object.
  282. *
  283. * @param object - the Javascript object to calculate the BSON byte size for
  284. * @returns size of BSON object in bytes
  285. * @public
  286. */
  287. export declare function calculateObjectSize(object: Document, options?: CalculateObjectSizeOptions): number;
  288. /** @public */
  289. export declare type CalculateObjectSizeOptions = Pick<SerializeOptions, 'serializeFunctions' | 'ignoreUndefined'>;
  290. /**
  291. * A class representation of the BSON Code type.
  292. * @public
  293. * @category BSONType
  294. */
  295. export declare class Code extends BSONValue {
  296. get _bsontype(): 'Code';
  297. code: string;
  298. scope: Document | null;
  299. /**
  300. * @param code - a string or function.
  301. * @param scope - an optional scope for the function.
  302. */
  303. constructor(code: string | Function, scope?: Document | null);
  304. toJSON(): {
  305. code: string;
  306. scope?: Document;
  307. };
  308. /* Excluded from this release type: toExtendedJSON */
  309. /* Excluded from this release type: fromExtendedJSON */
  310. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  311. }
  312. /** @public */
  313. export declare interface CodeExtended {
  314. $code: string;
  315. $scope?: Document;
  316. }
  317. /**
  318. * A class representation of the BSON DBRef type.
  319. * @public
  320. * @category BSONType
  321. */
  322. export declare class DBRef extends BSONValue {
  323. get _bsontype(): 'DBRef';
  324. collection: string;
  325. oid: ObjectId;
  326. db?: string;
  327. fields: Document;
  328. /**
  329. * @param collection - the collection name.
  330. * @param oid - the reference ObjectId.
  331. * @param db - optional db name, if omitted the reference is local to the current db.
  332. */
  333. constructor(collection: string, oid: ObjectId, db?: string, fields?: Document);
  334. /* Excluded from this release type: namespace */
  335. /* Excluded from this release type: namespace */
  336. toJSON(): DBRefLike & Document;
  337. /* Excluded from this release type: toExtendedJSON */
  338. /* Excluded from this release type: fromExtendedJSON */
  339. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  340. }
  341. /** @public */
  342. export declare interface DBRefLike {
  343. $ref: string;
  344. $id: ObjectId;
  345. $db?: string;
  346. }
  347. /**
  348. * A class representation of the BSON Decimal128 type.
  349. * @public
  350. * @category BSONType
  351. */
  352. export declare class Decimal128 extends BSONValue {
  353. get _bsontype(): 'Decimal128';
  354. readonly bytes: Uint8Array;
  355. /**
  356. * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
  357. * or a string representation as returned by .toString()
  358. */
  359. constructor(bytes: Uint8Array | string);
  360. /**
  361. * Create a Decimal128 instance from a string representation
  362. *
  363. * @param representation - a numeric string representation.
  364. */
  365. static fromString(representation: string): Decimal128;
  366. /**
  367. * Create a Decimal128 instance from a string representation, allowing for rounding to 34
  368. * significant digits
  369. *
  370. * @example Example of a number that will be rounded
  371. * ```ts
  372. * > let d = Decimal128.fromString('37.499999999999999196428571428571375')
  373. * Uncaught:
  374. * BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
  375. * at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
  376. * at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
  377. * at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)
  378. *
  379. * > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
  380. * new Decimal128("37.49999999999999919642857142857138")
  381. * ```
  382. * @param representation - a numeric string representation.
  383. */
  384. static fromStringWithRounding(representation: string): Decimal128;
  385. private static _fromString;
  386. /** Create a string representation of the raw Decimal128 value */
  387. toString(): string;
  388. toJSON(): Decimal128Extended;
  389. /* Excluded from this release type: toExtendedJSON */
  390. /* Excluded from this release type: fromExtendedJSON */
  391. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  392. }
  393. /** @public */
  394. export declare interface Decimal128Extended {
  395. $numberDecimal: string;
  396. }
  397. /**
  398. * Deserialize data as BSON.
  399. *
  400. * @param buffer - the buffer containing the serialized set of BSON documents.
  401. * @returns returns the deserialized Javascript Object.
  402. * @public
  403. */
  404. export declare function deserialize(buffer: Uint8Array, options?: DeserializeOptions): Document;
  405. /** @public */
  406. export declare interface DeserializeOptions {
  407. /**
  408. * when deserializing a Long return as a BigInt.
  409. * @defaultValue `false`
  410. */
  411. useBigInt64?: boolean;
  412. /**
  413. * when deserializing a Long will fit it into a Number if it's smaller than 53 bits.
  414. * @defaultValue `true`
  415. */
  416. promoteLongs?: boolean;
  417. /**
  418. * when deserializing a Binary will return it as a node.js Buffer instance.
  419. * @defaultValue `false`
  420. */
  421. promoteBuffers?: boolean;
  422. /**
  423. * when deserializing will promote BSON values to their Node.js closest equivalent types.
  424. * @defaultValue `true`
  425. */
  426. promoteValues?: boolean;
  427. /**
  428. * allow to specify if there what fields we wish to return as unserialized raw buffer.
  429. * @defaultValue `null`
  430. */
  431. fieldsAsRaw?: Document;
  432. /**
  433. * return BSON regular expressions as BSONRegExp instances.
  434. * @defaultValue `false`
  435. */
  436. bsonRegExp?: boolean;
  437. /**
  438. * allows the buffer to be larger than the parsed BSON object.
  439. * @defaultValue `false`
  440. */
  441. allowObjectSmallerThanBufferSize?: boolean;
  442. /**
  443. * Offset into buffer to begin reading document from
  444. * @defaultValue `0`
  445. */
  446. index?: number;
  447. raw?: boolean;
  448. /** Allows for opt-out utf-8 validation for all keys or
  449. * specified keys. Must be all true or all false.
  450. *
  451. * @example
  452. * ```js
  453. * // disables validation on all keys
  454. * validation: { utf8: false }
  455. *
  456. * // enables validation only on specified keys a, b, and c
  457. * validation: { utf8: { a: true, b: true, c: true } }
  458. *
  459. * // disables validation only on specified keys a, b
  460. * validation: { utf8: { a: false, b: false } }
  461. * ```
  462. */
  463. validation?: {
  464. utf8: boolean | Record<string, true> | Record<string, false>;
  465. };
  466. }
  467. /**
  468. * Deserialize stream data as BSON documents.
  469. *
  470. * @param data - the buffer containing the serialized set of BSON documents.
  471. * @param startIndex - the start index in the data Buffer where the deserialization is to start.
  472. * @param numberOfDocuments - number of documents to deserialize.
  473. * @param documents - an array where to store the deserialized documents.
  474. * @param docStartIndex - the index in the documents array from where to start inserting documents.
  475. * @param options - additional options used for the deserialization.
  476. * @returns next index in the buffer after deserialization **x** numbers of documents.
  477. * @public
  478. */
  479. export declare function deserializeStream(data: Uint8Array | ArrayBuffer, startIndex: number, numberOfDocuments: number, documents: Document[], docStartIndex: number, options: DeserializeOptions): number;
  480. /** @public */
  481. export declare interface Document {
  482. [key: string]: any;
  483. }
  484. /**
  485. * A class representation of the BSON Double type.
  486. * @public
  487. * @category BSONType
  488. */
  489. export declare class Double extends BSONValue {
  490. get _bsontype(): 'Double';
  491. value: number;
  492. /**
  493. * Create a Double type
  494. *
  495. * @param value - the number we want to represent as a double.
  496. */
  497. constructor(value: number);
  498. /**
  499. * Access the number value.
  500. *
  501. * @returns returns the wrapped double number.
  502. */
  503. valueOf(): number;
  504. toJSON(): number;
  505. toString(radix?: number): string;
  506. /* Excluded from this release type: toExtendedJSON */
  507. /* Excluded from this release type: fromExtendedJSON */
  508. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  509. }
  510. /** @public */
  511. export declare interface DoubleExtended {
  512. $numberDouble: string;
  513. }
  514. /** @public */
  515. export declare const EJSON: {
  516. parse: typeof parse;
  517. stringify: typeof stringify;
  518. serialize: typeof EJSONserialize;
  519. deserialize: typeof EJSONdeserialize;
  520. };
  521. /**
  522. * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
  523. *
  524. * @param ejson - The Extended JSON object to deserialize
  525. * @param options - Optional settings passed to the parse method
  526. */
  527. declare function EJSONdeserialize(ejson: Document, options?: EJSONOptions): any;
  528. /** @public */
  529. export declare type EJSONOptions = {
  530. /**
  531. * Output using the Extended JSON v1 spec
  532. * @defaultValue `false`
  533. */
  534. legacy?: boolean;
  535. /**
  536. * Enable Extended JSON's `relaxed` mode, which attempts to return native JS types where possible, rather than BSON types
  537. * @defaultValue `false` */
  538. relaxed?: boolean;
  539. /**
  540. * Enable native bigint support
  541. * @defaultValue `false`
  542. */
  543. useBigInt64?: boolean;
  544. };
  545. /**
  546. * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
  547. *
  548. * @param value - The object to serialize
  549. * @param options - Optional settings passed to the `stringify` function
  550. */
  551. declare function EJSONserialize(value: any, options?: EJSONOptions): Document;
  552. declare type InspectFn = (x: unknown, options?: unknown) => string;
  553. /**
  554. * A class representation of a BSON Int32 type.
  555. * @public
  556. * @category BSONType
  557. */
  558. export declare class Int32 extends BSONValue {
  559. get _bsontype(): 'Int32';
  560. value: number;
  561. /**
  562. * Create an Int32 type
  563. *
  564. * @param value - the number we want to represent as an int32.
  565. */
  566. constructor(value: number | string);
  567. /**
  568. * Access the number value.
  569. *
  570. * @returns returns the wrapped int32 number.
  571. */
  572. valueOf(): number;
  573. toString(radix?: number): string;
  574. toJSON(): number;
  575. /* Excluded from this release type: toExtendedJSON */
  576. /* Excluded from this release type: fromExtendedJSON */
  577. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  578. }
  579. /** @public */
  580. export declare interface Int32Extended {
  581. $numberInt: string;
  582. }
  583. declare const kId: unique symbol;
  584. /**
  585. * A class representing a 64-bit integer
  586. * @public
  587. * @category BSONType
  588. * @remarks
  589. * The internal representation of a long is the two given signed, 32-bit values.
  590. * We use 32-bit pieces because these are the size of integers on which
  591. * Javascript performs bit-operations. For operations like addition and
  592. * multiplication, we split each number into 16 bit pieces, which can easily be
  593. * multiplied within Javascript's floating-point representation without overflow
  594. * or change in sign.
  595. * In the algorithms below, we frequently reduce the negative case to the
  596. * positive case by negating the input(s) and then post-processing the result.
  597. * Note that we must ALWAYS check specially whether those values are MIN_VALUE
  598. * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
  599. * a positive number, it overflows back into a negative). Not handling this
  600. * case would often result in infinite recursion.
  601. * Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
  602. */
  603. export declare class Long extends BSONValue {
  604. get _bsontype(): 'Long';
  605. /** An indicator used to reliably determine if an object is a Long or not. */
  606. get __isLong__(): boolean;
  607. /**
  608. * The high 32 bits as a signed value.
  609. */
  610. high: number;
  611. /**
  612. * The low 32 bits as a signed value.
  613. */
  614. low: number;
  615. /**
  616. * Whether unsigned or not.
  617. */
  618. unsigned: boolean;
  619. /**
  620. * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
  621. * See the from* functions below for more convenient ways of constructing Longs.
  622. *
  623. * Acceptable signatures are:
  624. * - Long(low, high, unsigned?)
  625. * - Long(bigint, unsigned?)
  626. * - Long(string, unsigned?)
  627. *
  628. * @param low - The low (signed) 32 bits of the long
  629. * @param high - The high (signed) 32 bits of the long
  630. * @param unsigned - Whether unsigned or not, defaults to signed
  631. */
  632. constructor(low?: number | bigint | string, high?: number | boolean, unsigned?: boolean);
  633. static TWO_PWR_24: Long;
  634. /** Maximum unsigned value. */
  635. static MAX_UNSIGNED_VALUE: Long;
  636. /** Signed zero */
  637. static ZERO: Long;
  638. /** Unsigned zero. */
  639. static UZERO: Long;
  640. /** Signed one. */
  641. static ONE: Long;
  642. /** Unsigned one. */
  643. static UONE: Long;
  644. /** Signed negative one. */
  645. static NEG_ONE: Long;
  646. /** Maximum signed value. */
  647. static MAX_VALUE: Long;
  648. /** Minimum signed value. */
  649. static MIN_VALUE: Long;
  650. /**
  651. * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits.
  652. * Each is assumed to use 32 bits.
  653. * @param lowBits - The low 32 bits
  654. * @param highBits - The high 32 bits
  655. * @param unsigned - Whether unsigned or not, defaults to signed
  656. * @returns The corresponding Long value
  657. */
  658. static fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long;
  659. /**
  660. * Returns a Long representing the given 32 bit integer value.
  661. * @param value - The 32 bit integer in question
  662. * @param unsigned - Whether unsigned or not, defaults to signed
  663. * @returns The corresponding Long value
  664. */
  665. static fromInt(value: number, unsigned?: boolean): Long;
  666. /**
  667. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  668. * @param value - The number in question
  669. * @param unsigned - Whether unsigned or not, defaults to signed
  670. * @returns The corresponding Long value
  671. */
  672. static fromNumber(value: number, unsigned?: boolean): Long;
  673. /**
  674. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  675. * @param value - The number in question
  676. * @param unsigned - Whether unsigned or not, defaults to signed
  677. * @returns The corresponding Long value
  678. */
  679. static fromBigInt(value: bigint, unsigned?: boolean): Long;
  680. /**
  681. * Returns a Long representation of the given string, written using the specified radix.
  682. * @param str - The textual representation of the Long
  683. * @param unsigned - Whether unsigned or not, defaults to signed
  684. * @param radix - The radix in which the text is written (2-36), defaults to 10
  685. * @returns The corresponding Long value
  686. */
  687. static fromString(str: string, unsigned?: boolean, radix?: number): Long;
  688. /**
  689. * Creates a Long from its byte representation.
  690. * @param bytes - Byte representation
  691. * @param unsigned - Whether unsigned or not, defaults to signed
  692. * @param le - Whether little or big endian, defaults to big endian
  693. * @returns The corresponding Long value
  694. */
  695. static fromBytes(bytes: number[], unsigned?: boolean, le?: boolean): Long;
  696. /**
  697. * Creates a Long from its little endian byte representation.
  698. * @param bytes - Little endian byte representation
  699. * @param unsigned - Whether unsigned or not, defaults to signed
  700. * @returns The corresponding Long value
  701. */
  702. static fromBytesLE(bytes: number[], unsigned?: boolean): Long;
  703. /**
  704. * Creates a Long from its big endian byte representation.
  705. * @param bytes - Big endian byte representation
  706. * @param unsigned - Whether unsigned or not, defaults to signed
  707. * @returns The corresponding Long value
  708. */
  709. static fromBytesBE(bytes: number[], unsigned?: boolean): Long;
  710. /**
  711. * Tests if the specified object is a Long.
  712. */
  713. static isLong(value: unknown): value is Long;
  714. /**
  715. * Converts the specified value to a Long.
  716. * @param unsigned - Whether unsigned or not, defaults to signed
  717. */
  718. static fromValue(val: number | string | {
  719. low: number;
  720. high: number;
  721. unsigned?: boolean;
  722. }, unsigned?: boolean): Long;
  723. /** Returns the sum of this and the specified Long. */
  724. add(addend: string | number | Long | Timestamp): Long;
  725. /**
  726. * Returns the sum of this and the specified Long.
  727. * @returns Sum
  728. */
  729. and(other: string | number | Long | Timestamp): Long;
  730. /**
  731. * Compares this Long's value with the specified's.
  732. * @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
  733. */
  734. compare(other: string | number | Long | Timestamp): 0 | 1 | -1;
  735. /** This is an alias of {@link Long.compare} */
  736. comp(other: string | number | Long | Timestamp): 0 | 1 | -1;
  737. /**
  738. * Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
  739. * @returns Quotient
  740. */
  741. divide(divisor: string | number | Long | Timestamp): Long;
  742. /**This is an alias of {@link Long.divide} */
  743. div(divisor: string | number | Long | Timestamp): Long;
  744. /**
  745. * Tests if this Long's value equals the specified's.
  746. * @param other - Other value
  747. */
  748. equals(other: string | number | Long | Timestamp): boolean;
  749. /** This is an alias of {@link Long.equals} */
  750. eq(other: string | number | Long | Timestamp): boolean;
  751. /** Gets the high 32 bits as a signed integer. */
  752. getHighBits(): number;
  753. /** Gets the high 32 bits as an unsigned integer. */
  754. getHighBitsUnsigned(): number;
  755. /** Gets the low 32 bits as a signed integer. */
  756. getLowBits(): number;
  757. /** Gets the low 32 bits as an unsigned integer. */
  758. getLowBitsUnsigned(): number;
  759. /** Gets the number of bits needed to represent the absolute value of this Long. */
  760. getNumBitsAbs(): number;
  761. /** Tests if this Long's value is greater than the specified's. */
  762. greaterThan(other: string | number | Long | Timestamp): boolean;
  763. /** This is an alias of {@link Long.greaterThan} */
  764. gt(other: string | number | Long | Timestamp): boolean;
  765. /** Tests if this Long's value is greater than or equal the specified's. */
  766. greaterThanOrEqual(other: string | number | Long | Timestamp): boolean;
  767. /** This is an alias of {@link Long.greaterThanOrEqual} */
  768. gte(other: string | number | Long | Timestamp): boolean;
  769. /** This is an alias of {@link Long.greaterThanOrEqual} */
  770. ge(other: string | number | Long | Timestamp): boolean;
  771. /** Tests if this Long's value is even. */
  772. isEven(): boolean;
  773. /** Tests if this Long's value is negative. */
  774. isNegative(): boolean;
  775. /** Tests if this Long's value is odd. */
  776. isOdd(): boolean;
  777. /** Tests if this Long's value is positive. */
  778. isPositive(): boolean;
  779. /** Tests if this Long's value equals zero. */
  780. isZero(): boolean;
  781. /** Tests if this Long's value is less than the specified's. */
  782. lessThan(other: string | number | Long | Timestamp): boolean;
  783. /** This is an alias of {@link Long#lessThan}. */
  784. lt(other: string | number | Long | Timestamp): boolean;
  785. /** Tests if this Long's value is less than or equal the specified's. */
  786. lessThanOrEqual(other: string | number | Long | Timestamp): boolean;
  787. /** This is an alias of {@link Long.lessThanOrEqual} */
  788. lte(other: string | number | Long | Timestamp): boolean;
  789. /** Returns this Long modulo the specified. */
  790. modulo(divisor: string | number | Long | Timestamp): Long;
  791. /** This is an alias of {@link Long.modulo} */
  792. mod(divisor: string | number | Long | Timestamp): Long;
  793. /** This is an alias of {@link Long.modulo} */
  794. rem(divisor: string | number | Long | Timestamp): Long;
  795. /**
  796. * Returns the product of this and the specified Long.
  797. * @param multiplier - Multiplier
  798. * @returns Product
  799. */
  800. multiply(multiplier: string | number | Long | Timestamp): Long;
  801. /** This is an alias of {@link Long.multiply} */
  802. mul(multiplier: string | number | Long | Timestamp): Long;
  803. /** Returns the Negation of this Long's value. */
  804. negate(): Long;
  805. /** This is an alias of {@link Long.negate} */
  806. neg(): Long;
  807. /** Returns the bitwise NOT of this Long. */
  808. not(): Long;
  809. /** Tests if this Long's value differs from the specified's. */
  810. notEquals(other: string | number | Long | Timestamp): boolean;
  811. /** This is an alias of {@link Long.notEquals} */
  812. neq(other: string | number | Long | Timestamp): boolean;
  813. /** This is an alias of {@link Long.notEquals} */
  814. ne(other: string | number | Long | Timestamp): boolean;
  815. /**
  816. * Returns the bitwise OR of this Long and the specified.
  817. */
  818. or(other: number | string | Long): Long;
  819. /**
  820. * Returns this Long with bits shifted to the left by the given amount.
  821. * @param numBits - Number of bits
  822. * @returns Shifted Long
  823. */
  824. shiftLeft(numBits: number | Long): Long;
  825. /** This is an alias of {@link Long.shiftLeft} */
  826. shl(numBits: number | Long): Long;
  827. /**
  828. * Returns this Long with bits arithmetically shifted to the right by the given amount.
  829. * @param numBits - Number of bits
  830. * @returns Shifted Long
  831. */
  832. shiftRight(numBits: number | Long): Long;
  833. /** This is an alias of {@link Long.shiftRight} */
  834. shr(numBits: number | Long): Long;
  835. /**
  836. * Returns this Long with bits logically shifted to the right by the given amount.
  837. * @param numBits - Number of bits
  838. * @returns Shifted Long
  839. */
  840. shiftRightUnsigned(numBits: Long | number): Long;
  841. /** This is an alias of {@link Long.shiftRightUnsigned} */
  842. shr_u(numBits: number | Long): Long;
  843. /** This is an alias of {@link Long.shiftRightUnsigned} */
  844. shru(numBits: number | Long): Long;
  845. /**
  846. * Returns the difference of this and the specified Long.
  847. * @param subtrahend - Subtrahend
  848. * @returns Difference
  849. */
  850. subtract(subtrahend: string | number | Long | Timestamp): Long;
  851. /** This is an alias of {@link Long.subtract} */
  852. sub(subtrahend: string | number | Long | Timestamp): Long;
  853. /** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
  854. toInt(): number;
  855. /** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */
  856. toNumber(): number;
  857. /** Converts the Long to a BigInt (arbitrary precision). */
  858. toBigInt(): bigint;
  859. /**
  860. * Converts this Long to its byte representation.
  861. * @param le - Whether little or big endian, defaults to big endian
  862. * @returns Byte representation
  863. */
  864. toBytes(le?: boolean): number[];
  865. /**
  866. * Converts this Long to its little endian byte representation.
  867. * @returns Little endian byte representation
  868. */
  869. toBytesLE(): number[];
  870. /**
  871. * Converts this Long to its big endian byte representation.
  872. * @returns Big endian byte representation
  873. */
  874. toBytesBE(): number[];
  875. /**
  876. * Converts this Long to signed.
  877. */
  878. toSigned(): Long;
  879. /**
  880. * Converts the Long to a string written in the specified radix.
  881. * @param radix - Radix (2-36), defaults to 10
  882. * @throws RangeError If `radix` is out of range
  883. */
  884. toString(radix?: number): string;
  885. /** Converts this Long to unsigned. */
  886. toUnsigned(): Long;
  887. /** Returns the bitwise XOR of this Long and the given one. */
  888. xor(other: Long | number | string): Long;
  889. /** This is an alias of {@link Long.isZero} */
  890. eqz(): boolean;
  891. /** This is an alias of {@link Long.lessThanOrEqual} */
  892. le(other: string | number | Long | Timestamp): boolean;
  893. toExtendedJSON(options?: EJSONOptions): number | LongExtended;
  894. static fromExtendedJSON(doc: {
  895. $numberLong: string;
  896. }, options?: EJSONOptions): number | Long | bigint;
  897. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  898. }
  899. /** @public */
  900. export declare interface LongExtended {
  901. $numberLong: string;
  902. }
  903. /** @public */
  904. export declare type LongWithoutOverrides = new (low: unknown, high?: number | boolean, unsigned?: boolean) => {
  905. [P in Exclude<keyof Long, TimestampOverrides>]: Long[P];
  906. };
  907. /** @public */
  908. export declare const LongWithoutOverridesClass: LongWithoutOverrides;
  909. /**
  910. * A class representation of the BSON MaxKey type.
  911. * @public
  912. * @category BSONType
  913. */
  914. export declare class MaxKey extends BSONValue {
  915. get _bsontype(): 'MaxKey';
  916. /* Excluded from this release type: toExtendedJSON */
  917. /* Excluded from this release type: fromExtendedJSON */
  918. inspect(): string;
  919. }
  920. /** @public */
  921. export declare interface MaxKeyExtended {
  922. $maxKey: 1;
  923. }
  924. /**
  925. * A class representation of the BSON MinKey type.
  926. * @public
  927. * @category BSONType
  928. */
  929. export declare class MinKey extends BSONValue {
  930. get _bsontype(): 'MinKey';
  931. /* Excluded from this release type: toExtendedJSON */
  932. /* Excluded from this release type: fromExtendedJSON */
  933. inspect(): string;
  934. }
  935. /** @public */
  936. export declare interface MinKeyExtended {
  937. $minKey: 1;
  938. }
  939. /**
  940. * A class representation of the BSON ObjectId type.
  941. * @public
  942. * @category BSONType
  943. */
  944. export declare class ObjectId extends BSONValue {
  945. get _bsontype(): 'ObjectId';
  946. /* Excluded from this release type: index */
  947. static cacheHexString: boolean;
  948. /* Excluded from this release type: [kId] */
  949. /* Excluded from this release type: __id */
  950. /**
  951. * Create an ObjectId type
  952. *
  953. * @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
  954. */
  955. constructor(inputId?: string | number | ObjectId | ObjectIdLike | Uint8Array);
  956. /**
  957. * The ObjectId bytes
  958. * @readonly
  959. */
  960. get id(): Uint8Array;
  961. set id(value: Uint8Array);
  962. /** Returns the ObjectId id as a 24 lowercase character hex string representation */
  963. toHexString(): string;
  964. /* Excluded from this release type: getInc */
  965. /**
  966. * Generate a 12 byte id buffer used in ObjectId's
  967. *
  968. * @param time - pass in a second based timestamp.
  969. */
  970. static generate(time?: number): Uint8Array;
  971. /**
  972. * Converts the id into a 24 character hex string for printing, unless encoding is provided.
  973. * @param encoding - hex or base64
  974. */
  975. toString(encoding?: 'hex' | 'base64'): string;
  976. /** Converts to its JSON the 24 character hex string representation. */
  977. toJSON(): string;
  978. /* Excluded from this release type: is */
  979. /**
  980. * Compares the equality of this ObjectId with `otherID`.
  981. *
  982. * @param otherId - ObjectId instance to compare against.
  983. */
  984. equals(otherId: string | ObjectId | ObjectIdLike | undefined | null): boolean;
  985. /** Returns the generation date (accurate up to the second) that this ID was generated. */
  986. getTimestamp(): Date;
  987. /* Excluded from this release type: createPk */
  988. /**
  989. * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
  990. *
  991. * @param time - an integer number representing a number of seconds.
  992. */
  993. static createFromTime(time: number): ObjectId;
  994. /**
  995. * Creates an ObjectId from a hex string representation of an ObjectId.
  996. *
  997. * @param hexString - create a ObjectId from a passed in 24 character hexstring.
  998. */
  999. static createFromHexString(hexString: string): ObjectId;
  1000. /** Creates an ObjectId instance from a base64 string */
  1001. static createFromBase64(base64: string): ObjectId;
  1002. /**
  1003. * Checks if a value can be used to create a valid bson ObjectId
  1004. * @param id - any JS value
  1005. */
  1006. static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean;
  1007. /* Excluded from this release type: toExtendedJSON */
  1008. /* Excluded from this release type: fromExtendedJSON */
  1009. /**
  1010. * Converts to a string representation of this Id.
  1011. *
  1012. * @returns return the 24 character hex string representation.
  1013. */
  1014. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  1015. }
  1016. /** @public */
  1017. export declare interface ObjectIdExtended {
  1018. $oid: string;
  1019. }
  1020. /** @public */
  1021. export declare interface ObjectIdLike {
  1022. id: string | Uint8Array;
  1023. __id?: string;
  1024. toHexString(): string;
  1025. }
  1026. /**
  1027. * Parse an Extended JSON string, constructing the JavaScript value or object described by that
  1028. * string.
  1029. *
  1030. * @example
  1031. * ```js
  1032. * const { EJSON } = require('bson');
  1033. * const text = '{ "int32": { "$numberInt": "10" } }';
  1034. *
  1035. * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
  1036. * console.log(EJSON.parse(text, { relaxed: false }));
  1037. *
  1038. * // prints { int32: 10 }
  1039. * console.log(EJSON.parse(text));
  1040. * ```
  1041. */
  1042. declare function parse(text: string, options?: EJSONOptions): any;
  1043. /**
  1044. * Serialize a Javascript object.
  1045. *
  1046. * @param object - the Javascript object to serialize.
  1047. * @returns Buffer object containing the serialized object.
  1048. * @public
  1049. */
  1050. export declare function serialize(object: Document, options?: SerializeOptions): Uint8Array;
  1051. /** @public */
  1052. export declare interface SerializeOptions {
  1053. /**
  1054. * the serializer will check if keys are valid.
  1055. * @defaultValue `false`
  1056. */
  1057. checkKeys?: boolean;
  1058. /**
  1059. * serialize the javascript functions
  1060. * @defaultValue `false`
  1061. */
  1062. serializeFunctions?: boolean;
  1063. /**
  1064. * serialize will not emit undefined fields
  1065. * note that the driver sets this to `false`
  1066. * @defaultValue `true`
  1067. */
  1068. ignoreUndefined?: boolean;
  1069. /* Excluded from this release type: minInternalBufferSize */
  1070. /**
  1071. * the index in the buffer where we wish to start serializing into
  1072. * @defaultValue `0`
  1073. */
  1074. index?: number;
  1075. }
  1076. /**
  1077. * Serialize a Javascript object using a predefined Buffer and index into the buffer,
  1078. * useful when pre-allocating the space for serialization.
  1079. *
  1080. * @param object - the Javascript object to serialize.
  1081. * @param finalBuffer - the Buffer you pre-allocated to store the serialized BSON object.
  1082. * @returns the index pointing to the last written byte in the buffer.
  1083. * @public
  1084. */
  1085. export declare function serializeWithBufferAndIndex(object: Document, finalBuffer: Uint8Array, options?: SerializeOptions): number;
  1086. /**
  1087. * Sets the size of the internal serialization buffer.
  1088. *
  1089. * @param size - The desired size for the internal serialization buffer in bytes
  1090. * @public
  1091. */
  1092. export declare function setInternalBufferSize(size: number): void;
  1093. /**
  1094. * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
  1095. * function is specified or optionally including only the specified properties if a replacer array
  1096. * is specified.
  1097. *
  1098. * @param value - The value to convert to extended JSON
  1099. * @param replacer - A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
  1100. * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
  1101. * @param options - Optional settings
  1102. *
  1103. * @example
  1104. * ```js
  1105. * const { EJSON } = require('bson');
  1106. * const Int32 = require('mongodb').Int32;
  1107. * const doc = { int32: new Int32(10) };
  1108. *
  1109. * // prints '{"int32":{"$numberInt":"10"}}'
  1110. * console.log(EJSON.stringify(doc, { relaxed: false }));
  1111. *
  1112. * // prints '{"int32":10}'
  1113. * console.log(EJSON.stringify(doc));
  1114. * ```
  1115. */
  1116. declare function stringify(value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONOptions, space?: string | number, options?: EJSONOptions): string;
  1117. /**
  1118. * @public
  1119. * @category BSONType
  1120. */
  1121. export declare class Timestamp extends LongWithoutOverridesClass {
  1122. get _bsontype(): 'Timestamp';
  1123. static readonly MAX_VALUE: Long;
  1124. /**
  1125. * @param int - A 64-bit bigint representing the Timestamp.
  1126. */
  1127. constructor(int: bigint);
  1128. /**
  1129. * @param long - A 64-bit Long representing the Timestamp.
  1130. */
  1131. constructor(long: Long);
  1132. /**
  1133. * @param value - A pair of two values indicating timestamp and increment.
  1134. */
  1135. constructor(value: {
  1136. t: number;
  1137. i: number;
  1138. });
  1139. toJSON(): {
  1140. $timestamp: string;
  1141. };
  1142. /** Returns a Timestamp represented by the given (32-bit) integer value. */
  1143. static fromInt(value: number): Timestamp;
  1144. /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
  1145. static fromNumber(value: number): Timestamp;
  1146. /**
  1147. * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
  1148. *
  1149. * @param lowBits - the low 32-bits.
  1150. * @param highBits - the high 32-bits.
  1151. */
  1152. static fromBits(lowBits: number, highBits: number): Timestamp;
  1153. /**
  1154. * Returns a Timestamp from the given string, optionally using the given radix.
  1155. *
  1156. * @param str - the textual representation of the Timestamp.
  1157. * @param optRadix - the radix in which the text is written.
  1158. */
  1159. static fromString(str: string, optRadix: number): Timestamp;
  1160. /* Excluded from this release type: toExtendedJSON */
  1161. /* Excluded from this release type: fromExtendedJSON */
  1162. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  1163. }
  1164. /** @public */
  1165. export declare interface TimestampExtended {
  1166. $timestamp: {
  1167. t: number;
  1168. i: number;
  1169. };
  1170. }
  1171. /** @public */
  1172. export declare type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect';
  1173. /**
  1174. * A class representation of the BSON UUID type.
  1175. * @public
  1176. */
  1177. export declare class UUID extends Binary {
  1178. /**
  1179. * Create a UUID type
  1180. *
  1181. * When the argument to the constructor is omitted a random v4 UUID will be generated.
  1182. *
  1183. * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
  1184. */
  1185. constructor(input?: string | Uint8Array | UUID);
  1186. /**
  1187. * The UUID bytes
  1188. * @readonly
  1189. */
  1190. get id(): Uint8Array;
  1191. set id(value: Uint8Array);
  1192. /**
  1193. * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
  1194. * @param includeDashes - should the string exclude dash-separators.
  1195. */
  1196. toHexString(includeDashes?: boolean): string;
  1197. /**
  1198. * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
  1199. */
  1200. toString(encoding?: 'hex' | 'base64'): string;
  1201. /**
  1202. * Converts the id into its JSON string representation.
  1203. * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  1204. */
  1205. toJSON(): string;
  1206. /**
  1207. * Compares the equality of this UUID with `otherID`.
  1208. *
  1209. * @param otherId - UUID instance to compare against.
  1210. */
  1211. equals(otherId: string | Uint8Array | UUID): boolean;
  1212. /**
  1213. * Creates a Binary instance from the current UUID.
  1214. */
  1215. toBinary(): Binary;
  1216. /**
  1217. * Generates a populated buffer containing a v4 uuid
  1218. */
  1219. static generate(): Uint8Array;
  1220. /**
  1221. * Checks if a value is a valid bson UUID
  1222. * @param input - UUID, string or Buffer to validate.
  1223. */
  1224. static isValid(input: string | Uint8Array | UUID | Binary): boolean;
  1225. /**
  1226. * Creates an UUID from a hex string representation of an UUID.
  1227. * @param hexString - 32 or 36 character hex string (dashes excluded/included).
  1228. */
  1229. static createFromHexString(hexString: string): UUID;
  1230. /** Creates an UUID from a base64 string representation of an UUID. */
  1231. static createFromBase64(base64: string): UUID;
  1232. /* Excluded from this release type: bytesFromString */
  1233. /* Excluded from this release type: isValidUUIDString */
  1234. /**
  1235. * Converts to a string representation of this Id.
  1236. *
  1237. * @returns return the 36 character hex string representation.
  1238. *
  1239. */
  1240. inspect(depth?: number, options?: unknown, inspect?: InspectFn): string;
  1241. }
  1242. /** @public */
  1243. export declare type UUIDExtended = {
  1244. $uuid: string;
  1245. };
  1246. export { }