@hashgraph/sdk
Version:
77 lines (71 loc) • 2.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var HieroProto = _interopRequireWildcard(require("@hashgraph/proto"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
// SPDX-License-Identifier: Apache-2.0
/**
* Represents a semantic versioning structure for software components.
*
* This class encapsulates the major, minor, and patch version numbers, following
* the Semantic Versioning (SemVer) specification. It provides methods for creating,
* comparing, and manipulating version numbers, ensuring that versioning adheres to
* the SemVer rules.
*/
class SemanticVersion {
/**
* @private
* @param {object} props
* @param {number} props.major
* @param {number} props.minor
* @param {number} props.patch
*/
constructor(props) {
/** @readonly */
this.major = props.major;
/** @readonly */
this.minor = props.minor;
/** @readonly */
this.patch = props.patch;
Object.freeze(this);
}
/**
* @internal
* @param {HieroProto.proto.ISemanticVersion} version
* @returns {SemanticVersion}
*/
static _fromProtobuf(version) {
return new SemanticVersion({
major: (/** @type {number} */version.major),
minor: (/** @type {number} */version.minor),
patch: (/** @type {number} */version.patch)
});
}
/**
* @internal
* @returns {HieroProto.proto.ISemanticVersion}
*/
_toProtobuf() {
return {
major: this.major,
minor: this.minor,
patch: this.patch
};
}
/**
* @param {Uint8Array} bytes
* @returns {SemanticVersion}
*/
static fromBytes(bytes) {
return SemanticVersion._fromProtobuf(HieroProto.proto.SemanticVersion.decode(bytes));
}
/**
* @returns {Uint8Array}
*/
toBytes() {
return HieroProto.proto.SemanticVersion.encode(this._toProtobuf()).finish();
}
}
exports.default = SemanticVersion;
;