@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
71 lines • 2.12 kB
JavaScript
/**
* SPDX-License-Identifier: Apache-2.0
*/
import { isDns1123Label } from '../../kube_validation.js';
import { NamespaceNameInvalidError } from '../../errors/namespace_name_invalid_error.js';
/**
* Represents a Kubernetes namespace name. A Kubernetes namespace name must
* be a valid RFC-1123 DNS label.
*
* @include DNS_1123_LABEL
*/
export class NamespaceName {
name;
constructor(name) {
this.name = name;
if (!this.isValid()) {
throw new NamespaceNameInvalidError(name);
}
}
/**
* Creates a namespace. A Kubernetes namespace name must be a valid RFC-1123 DNS label.
*
* @include DNS_1123_LABEL
* @param name The name of the namespace.
* @returns An instance of NamespaceName.
* @throws NamespaceNameInvalidError if the namespace name is invalid.
*/
static of(name) {
return new NamespaceName(name);
}
/**
* Returns true if the namespace name is valid. A Kubernetes namespace name must be a valid RFC-1123 DNS label.
*
* @include DNS_1123_LABEL
*
* @returns true if the namespace name is valid.
* @throws NamespaceNameInvalidError if the namespace name is invalid.
*/
isValid() {
return isDns1123Label(this.name);
}
/**
* Compares this instance with another NamespaceName.
* @param other The other NamespaceName instance.
* @returns true if both instances have the same name.
*/
equals(other) {
return other instanceof NamespaceName && this.name === other.name;
}
/**
* Allows implicit conversion to a string.
* @returns The namespace name as a string.
*/
toString() {
return this.name;
}
/**
* Allows `NamespaceName` to be used as a primitive string in operations.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[Symbol.toPrimitive](hint) {
return this.name;
}
/**
* Returns the primitive value of the object.
*/
valueOf() {
return this.name;
}
}
//# sourceMappingURL=namespace_name.js.map