timestamp.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.Timestamp = exports.LongWithoutOverridesClass = void 0;
  19. var long_1 = require("./long");
  20. /** @public */
  21. exports.LongWithoutOverridesClass = long_1.Long;
  22. /** @public */
  23. var Timestamp = /** @class */ (function (_super) {
  24. __extends(Timestamp, _super);
  25. function Timestamp(low, high) {
  26. var _this = this;
  27. // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  28. ///@ts-expect-error
  29. if (!(_this instanceof Timestamp))
  30. return new Timestamp(low, high);
  31. if (long_1.Long.isLong(low)) {
  32. _this = _super.call(this, low.low, low.high, true) || this;
  33. }
  34. else {
  35. _this = _super.call(this, low, high, true) || this;
  36. }
  37. Object.defineProperty(_this, '_bsontype', {
  38. value: 'Timestamp',
  39. writable: false,
  40. configurable: false,
  41. enumerable: false
  42. });
  43. return _this;
  44. }
  45. Timestamp.prototype.toJSON = function () {
  46. return {
  47. $timestamp: this.toString()
  48. };
  49. };
  50. /** Returns a Timestamp represented by the given (32-bit) integer value. */
  51. Timestamp.fromInt = function (value) {
  52. return new Timestamp(long_1.Long.fromInt(value, true));
  53. };
  54. /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
  55. Timestamp.fromNumber = function (value) {
  56. return new Timestamp(long_1.Long.fromNumber(value, true));
  57. };
  58. /**
  59. * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
  60. *
  61. * @param lowBits - the low 32-bits.
  62. * @param highBits - the high 32-bits.
  63. */
  64. Timestamp.fromBits = function (lowBits, highBits) {
  65. return new Timestamp(lowBits, highBits);
  66. };
  67. /**
  68. * Returns a Timestamp from the given string, optionally using the given radix.
  69. *
  70. * @param str - the textual representation of the Timestamp.
  71. * @param optRadix - the radix in which the text is written.
  72. */
  73. Timestamp.fromString = function (str, optRadix) {
  74. return new Timestamp(long_1.Long.fromString(str, true, optRadix));
  75. };
  76. /** @internal */
  77. Timestamp.prototype.toExtendedJSON = function () {
  78. return { $timestamp: { t: this.high >>> 0, i: this.low >>> 0 } };
  79. };
  80. /** @internal */
  81. Timestamp.fromExtendedJSON = function (doc) {
  82. return new Timestamp(doc.$timestamp.i, doc.$timestamp.t);
  83. };
  84. /** @internal */
  85. Timestamp.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
  86. return this.inspect();
  87. };
  88. Timestamp.prototype.inspect = function () {
  89. return "new Timestamp(" + this.getLowBits().toString() + ", " + this.getHighBits().toString() + ")";
  90. };
  91. Timestamp.MAX_VALUE = long_1.Long.MAX_UNSIGNED_VALUE;
  92. return Timestamp;
  93. }(exports.LongWithoutOverridesClass));
  94. exports.Timestamp = Timestamp;
  95. //# sourceMappingURL=timestamp.js.map