UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

99 lines 3.6 kB
// SPDX-License-Identifier: Apache-2.0 import { SemanticVersion } from './semantic-version.js'; /** * A range of versions which includes the beginning version and excludes the end version. */ export class VersionRange { begin; end; constructor( /** * The beginning of the version range (inclusive). */ begin, /** * The end of the version range (exclusive). */ end) { this.begin = begin; this.end = end; if (this.begin !== null && this.end !== null && this.begin.compare(this.end) >= 0) { throw new RangeError('Invalid version range'); } } /** * Creates a version range from the given integer bounds. * * @param begin - the beginning of the version range (inclusive). * @param end - the end of the version range (exclusive). * @returns the version range. * @throws RangeError if the bounds are invalid. */ static fromIntegerBounds(begin, end) { return new VersionRange(new SemanticVersion(begin), new SemanticVersion(end)); } /** * Creates a version range from the given integer version. * * @param version - the specific version for which to create a range. * @returns the version range. * @throws RangeError if the version is invalid. */ static fromIntegerVersion(version) { return new VersionRange(new SemanticVersion(version), new SemanticVersion(version + 1)); } /** * Creates a version range from the given semantic version bounds. * * @param begin - the beginning of the version range (inclusive). * @param end - the end of the version range (exclusive). * @returns the version range. * @throws RangeError if the bounds are invalid. */ static fromSemanticVersionBounds(begin, end) { return new VersionRange(new SemanticVersion(begin), new SemanticVersion(end)); } /** * Creates a version range which includes all patch releases for the given major and minor version. * * @param version - the semantic version. * @returns the version range. */ static patchVersionBounds(version) { // clone the version to avoid modifying the original const rangeEnd = new SemanticVersion(version.toString()); return new VersionRange(new SemanticVersion(version), new SemanticVersion(rangeEnd.bumpMinor())); } /** * Creates a version range which includes all minor and patch releases for the given major version. * * @param version - the semantic version. * @returns the version range. */ static minorVersionBounds(version) { return new VersionRange(new SemanticVersion(version), version.bumpMajor()); } equals(other) { return this.begin !== null && this.end !== null && this.begin.equals(other.begin) && this.end.equals(other.end); } compare(other) { if (this.begin === null || this.end === null) { throw new RangeError('Invalid version range'); } const beginComparison = this.begin.compare(other.begin); if (beginComparison !== 0) { return beginComparison; } return this.end.compare(other.end); } contains(version) { if (this.begin === null || this.end === null) { throw new RangeError('Invalid version range'); } return this.begin.compare(version) <= 0 && this.end.compare(version) > 0; } toString() { return `[${this.begin}, ${this.end})`; } } //# sourceMappingURL=version-range.js.map