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