@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
98 lines • 4.47 kB
JavaScript
/**
* SPDX-License-Identifier: Apache-2.0
*/
import { Migration } from './migration.js';
import { SoloError } from '../../errors.js';
import * as k8s from '@kubernetes/client-node';
/**
* Represent the remote config metadata object and handles:
* - Validation
* - Reading
* - Making a migration
* - Converting from and to plain object
*/
export class RemoteConfigMetadata {
namespace;
deploymentName;
lastUpdatedAt;
lastUpdateBy;
soloVersion;
soloChartVersion;
hederaPlatformVersion;
hederaMirrorNodeChartVersion;
hederaExplorerChartVersion;
hederaJsonRpcRelayChartVersion;
_migration;
constructor(namespace, deploymentName, lastUpdatedAt, lastUpdateBy, soloVersion, soloChartVersion = '', hederaPlatformVersion = '', hederaMirrorNodeChartVersion = '', hederaExplorerChartVersion = '', hederaJsonRpcRelayChartVersion = '', migration) {
this.namespace = namespace;
this.deploymentName = deploymentName;
this.lastUpdatedAt = lastUpdatedAt;
this.lastUpdateBy = lastUpdateBy;
this.soloVersion = soloVersion;
this.soloChartVersion = soloChartVersion;
this.hederaPlatformVersion = hederaPlatformVersion;
this.hederaMirrorNodeChartVersion = hederaMirrorNodeChartVersion;
this.hederaExplorerChartVersion = hederaExplorerChartVersion;
this.hederaJsonRpcRelayChartVersion = hederaJsonRpcRelayChartVersion;
this._migration = migration;
this.validate();
}
/* -------- Modifiers -------- */
/** Simplifies making a migration */
makeMigration(email, fromVersion) {
this._migration = new Migration(new Date(), email, fromVersion);
}
/* -------- Getters -------- */
/** Retrieves the migration if such exists */
get migration() {
return this._migration;
}
/* -------- Utilities -------- */
/** Handles conversion from a plain object to instance */
static fromObject(metadata) {
let migration = undefined;
if (metadata.migration) {
const { migration: { migratedAt, migratedBy, fromVersion }, } = metadata;
migration = new Migration(new Date(migratedAt), migratedBy, fromVersion);
}
return new RemoteConfigMetadata(metadata.namespace, metadata.deploymentName, new Date(metadata.lastUpdatedAt), metadata.lastUpdateBy, metadata.soloVersion, metadata.soloChartVersion, metadata.hederaPlatformVersion, metadata.hederaMirrorNodeChartVersion, metadata.hederaExplorerChartVersion, metadata.hederaJsonRpcRelayChartVersion, migration);
}
validate() {
if (!this.namespace || !(typeof this.namespace === 'string')) {
throw new SoloError(`Invalid namespace: ${this.namespace}, is type string: ${typeof this.namespace === 'string'}`);
}
if (!this.deploymentName || !(typeof this.deploymentName === 'string')) {
throw new SoloError(`Invalid deploymentName: ${this.deploymentName}, is type string: ${typeof this.deploymentName === 'string'}`);
}
if (!(this.lastUpdatedAt instanceof Date)) {
throw new SoloError(`Invalid lastUpdatedAt: ${this.lastUpdatedAt}`);
}
if (!this.lastUpdateBy || typeof this.lastUpdateBy !== 'string') {
throw new SoloError(`Invalid lastUpdateBy: ${this.lastUpdateBy}`);
}
if (!this.soloVersion || typeof this.soloVersion !== 'string') {
throw new SoloError(`Invalid soloVersion: ${this.soloVersion}`);
}
if (this.migration && !(this.migration instanceof Migration)) {
throw new SoloError(`Invalid migration: ${this.migration}`);
}
}
toObject() {
const data = {
namespace: this.namespace,
deploymentName: this.deploymentName,
lastUpdatedAt: new k8s.V1MicroTime(this.lastUpdatedAt),
lastUpdateBy: this.lastUpdateBy,
soloChartVersion: this.soloChartVersion,
hederaPlatformVersion: this.hederaPlatformVersion,
hederaMirrorNodeChartVersion: this.hederaMirrorNodeChartVersion,
hederaExplorerChartVersion: this.hederaExplorerChartVersion,
hederaJsonRpcRelayChartVersion: this.hederaJsonRpcRelayChartVersion,
soloVersion: this.soloVersion,
};
if (this.migration)
data.migration = this.migration.toObject();
return data;
}
}
//# sourceMappingURL=metadata.js.map