UNPKG

@hashgraph/solo

Version:

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

183 lines (182 loc) 11.1 kB
/** * A class representing a semantic version, which can be initialized with either a string or a number. * The class provides methods for comparing semantic versions, as well as validating and formatting them. * It supports both standard semantic versioning (e.g., "1.0.0", "2.1.3-alpha+001") and a simplified numeric versioning (e.g., 1, 2). * The class also includes a static method for validating and formatting semantic version strings with optional 'v' prefix handling. * * @template T - The type of the original value used to create the semantic version, either string or number */ export declare class SemanticVersion<T extends string | number> { private readonly originalValue; /** * Constant value representing a zero version number. */ static readonly ZERO: SemanticVersion<string>; /** * The major version number, which is incremented for incompatible API changes. * Initialized to 0 by default. * * @readonly */ readonly major: number; /** * The minor version number, which is incremented for added functionality in a backwards-compatible manner. * Initialized to 0 by default. * * @readonly */ readonly minor: number; /** * The patch version number, which is incremented for backwards-compatible bug fixes. * Initialized to 0 by default. * * @readonly */ readonly patch: number; /** * The pre-release version, which is denoted by a hyphen and can contain alphanumeric identifiers separated by dots. * It indicates that the version is unstable and may not satisfy the intended compatibility requirements as denoted by * its associated normal version. * Initialized to null by default. * * @readonly */ readonly preRelease: string | null; /** * The build metadata, which is denoted by a plus sign and can contain alphanumeric identifiers separated by dots. * It is ignored when determining version precedence but can be used to provide additional build information. * Initialized to null by default. * * @readonly */ readonly buildMetadata: string | null; /** * The type of the original value used to create the semantic version, either 'string' or 'number'. * This is used to determine how to format the version when converting it back to a string. * * @readonly */ readonly tType: 'string' | 'number'; /** * Creates a new SemanticVersion instance from a string or number. The constructor validates the input and parses it * into its components (major, minor, patch, pre-release, build metadata) based on the type of the original value. * @param originalValue - The original value used to create the semantic version, which can be a string * (e.g., "1.0.0", "2.1.3-alpha+001") or a number (e.g., 1, 2) * @throws IllegalArgumentError if the original value is not a valid semantic version string or a non-negative integer */ constructor(originalValue: T | SemanticVersion<T>); /** * Checks if this semantic version is equal to another semantic version or a valid string/number representation of a semantic version. * @param other - The other semantic version or a valid string/number to compare against * @returns true if they are equal, false otherwise */ equals(other: SemanticVersion<T> | T): boolean; /** * Compares this semantic version to another semantic version or a valid string/number representation of a semantic version. * @returns 0 if they are equal, 1 if this version is greater, -1 if this version is less, or NaN if the other value is not a valid semantic version * @param other - The other semantic version or a valid string/number to compare against * @throws IllegalArgumentError if the other value is not a valid semantic version * @remarks The comparison is based on the precedence rules defined in the Semantic Versioning specification, which * considers major, minor, patch, pre-release, and build metadata components. Pre-release versions are considered * less than their associated normal versions, and build metadata does not affect precedence. */ compare(other: SemanticVersion<T> | T): number; /** * Determines if this semantic version is greater than another semantic version or a valid string/number representation of a semantic version. * @returns true if this version is greater, false otherwise * @param other - The other semantic version or a valid string/number to compare against * @remarks The comparison is based on the precedence rules defined in the Semantic Versioning specification, which * considers major, minor, patch, pre-release, and build metadata components. Pre-release versions are considered * less than their associated normal versions, and build metadata does not affect precedence. */ greaterThan(other: SemanticVersion<T> | T): boolean; /** * Determines if this semantic version is less than another semantic version or a valid string/number representation of a semantic version. * @returns true if this version is less, false otherwise * @param other - The other semantic version or a valid string/number to compare against * @remarks The comparison is based on the precedence rules defined in the Semantic Versioning specification, which * considers major, minor, patch, pre-release, and build metadata components. Pre-release versions are considered * less than their associated normal versions, and build metadata does not affect precedence. */ lessThan(other: SemanticVersion<T> | T): boolean; /** * Determines if this semantic version is greater than or equal to another semantic version or a valid string/number representation of a semantic version. * @returns true if this version is greater than or equal, false otherwise * @param other - The other semantic version or a valid string/number to compare against * @remarks The comparison is based on the precedence rules defined in the Semantic Versioning specification, which * considers major, minor, patch, pre-release, and build metadata components. Pre-release versions are considered * less than their associated normal versions, and build metadata does not affect precedence. */ greaterThanOrEqual(other: SemanticVersion<T> | T): boolean; /** * Determines if this semantic version is less than or equal to another semantic version or a valid string/number * representation of a semantic version. * @returns true if this version is less than or equal, false otherwise * @param other - The other semantic version or a valid string/number to compare against * @remarks The comparison is based on the precedence rules defined in the Semantic Versioning specification, which * considers major, minor, patch, pre-release, and build metadata components. Pre-release versions are considered * less than their associated normal versions, and build metadata does not affect precedence. */ lessThanOrEqual(other: SemanticVersion<T> | T): boolean; /** * Converts this semantic version to a string representation. If the original type was a number, it returns just the * major version as a string. * If the original type was a string, it returns the full semantic version string, including pre-release and build * metadata if present. * @returns The string representation of this semantic version */ toString(): string; /** * Converts this semantic version to a string representation with a 'v' prefix. If the original type was a number, it * returns just the major version with a 'v' prefix. * If the original type was a string, it returns the full semantic version string with a 'v' prefix, including * pre-release and build metadata if present. * @returns The string representation of this semantic version with a 'v' prefix */ toPrefixedString(): string; /** * Validates if a value is a valid semantic version, which can be an instance of SemanticVersion, a numeric value, or a * string that matches the semantic version pattern. * The validation allows for an optional 'v' prefix in string representations and ensures that numeric values are * non-negative safe integers. * @returns true if the value is a valid semantic version, false otherwise * @param value - The value to validate, which can be an instance of SemanticVersion, a numeric value, or a string * @private */ private static isSemanticVersion; /** * Validates if a string is a valid semantic version and handles the 'v' prefix * * @param versionString - The version string to validate * @param isNeedPrefix - If true, adds 'v' prefix if missing; if false, removes 'v' prefix if present * @param label - Label to use in error messages (e.g., 'Release tag', 'SemanticVersion') * @returns The processed version string with proper prefix handling * @throws SoloError or IllegalArgumentError if the version string is invalid */ static getValidSemanticVersion(versionString: string, isNeedPrefix?: boolean, label?: string): string; /** * Returns a new SemanticVersion instance with the minor version incremented by 1 and major versions unchanged. * The patch version is reset to 0, and pre-release and build metadata are cleared. * The returned instance is always of type SemanticVersion<string> to ensure that the version is represented in a * standard semantic version format. * @returns A new SemanticVersion instance with the minor version incremented by 1 * @remarks This method is useful for automatically generating the next minor version based on the current version, * following semantic versioning rules. * For example, if the current version is "1.2.3", calling bumpMinor() will return a new SemanticVersion instance * representing "1.3.0". * If the current version is "1.2.3-alpha+001", calling bumpMinor() will return a new SemanticVersion instance * representing "1.3.0" (pre-release and build metadata are cleared). */ bumpMinor(): SemanticVersion<string>; /** * Returns a new SemanticVersion instance with the major version incremented by 1 and minor and patch versions reset to 0. * Pre-release and build metadata are cleared. * The returned instance is of the same type as the original (string or number) to maintain consistency in version representation. * @returns A new SemanticVersion instance with the major version incremented by 1 * @remarks This method is useful for automatically generating the next major version based on the current version, * following semantic versioning rules. * For example, if the current version is "1.2.3", calling bumpMajor() will return a new SemanticVersion instance * representing "2.0.0". */ bumpMajor(): SemanticVersion<T>; }