99 lines
3.9 KiB
JavaScript
99 lines
3.9 KiB
JavaScript
|
"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 */
|
||
|
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
|