Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve types in JSDoc and fix typo in '/src/commands/account.mjs' #507

Merged
merged 13 commits into from
Sep 4, 2024
54 changes: 51 additions & 3 deletions src/commands/account.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
'use strict'
import chalk from 'chalk'
import { BaseCommand } from './base.mjs'
import { FullstackTestingError, IllegalArgumentError } from '../core/errors.mjs'
Expand All @@ -25,6 +26,10 @@ import { AccountInfo, HbarUnit, PrivateKey } from '@hashgraph/sdk'
import { FREEZE_ADMIN_ACCOUNT } from '../core/constants.mjs'

export class AccountCommand extends BaseCommand {
/**
* @param {{accountManager: AccountManager, logger: Logger, helm: Helm, k8: K8, chartManager: ChartManager, configManager: ConfigManager, depManager: DependencyManager}} opts
* @param {number[][]} [systemAccounts]
*/
constructor (opts, systemAccounts = constants.SYSTEM_ACCOUNTS) {
super(opts)

Expand All @@ -35,10 +40,19 @@ export class AccountCommand extends BaseCommand {
this.systemAccounts = systemAccounts
}

/**
* @returns {Promise<void>}
*/
async closeConnections () {
await this.accountManager.close()
}

/**
* @param {AccountInfo} accountInfo
* @param {string} namespace
* @param {boolean} shouldRetrievePrivateKey
* @returns {Promise<{accountId: string, balance: number, publicKey: string}>}
*/
async buildAccountInfo (accountInfo, namespace, shouldRetrievePrivateKey) {
if (!accountInfo || !(accountInfo instanceof AccountInfo)) throw new IllegalArgumentError('An instance of AccountInfo is required')

Expand All @@ -56,6 +70,10 @@ export class AccountCommand extends BaseCommand {
return newAccountInfo
}

/**
* @param {any} ctx
* @returns {Promise<{accountId: AccountId, privateKey: string, publicKey: string, balance: number}>}
*/
async createNewAccount (ctx) {
if (ctx.config.ecdsaPrivateKey) {
ctx.privateKey = PrivateKey.fromStringECDSA(ctx.config.ecdsaPrivateKey)
Expand All @@ -65,14 +83,22 @@ export class AccountCommand extends BaseCommand {
ctx.privateKey = PrivateKey.generateED25519()
}

return await this.accountManager.createNewAccount(ctx.config.namespace,
return this.accountManager.createNewAccount(ctx.config.namespace,
ctx.privateKey, ctx.config.amount, ctx.config.ecdsaPrivateKey ? ctx.config.setAlias : false)
}

/**
* @param {any} ctx
* @returns {Promise<AccountInfo>}
*/
async getAccountInfo (ctx) {
return this.accountManager.accountInfoQuery(ctx.config.accountId)
}

/**
* @param {any} ctx
* @returns {Promise<boolean>}
*/
async updateAccountInfo (ctx) {
let amount = ctx.config.amount
if (ctx.config.privateKey) {
Expand All @@ -99,10 +125,19 @@ export class AccountCommand extends BaseCommand {
return true
}

/**
* @param {AccountId} toAccountId
* @param {number} amount
* @returns {Promise<boolean>}
*/
async transferAmountFromOperator (toAccountId, amount) {
return await this.accountManager.transferAmount(constants.TREASURY_ACCOUNT_ID, toAccountId, amount)
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async init (argv) {
const self = this

Expand Down Expand Up @@ -220,6 +255,10 @@ export class AccountCommand extends BaseCommand {
return true
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async create (argv) {
const self = this

Expand Down Expand Up @@ -282,6 +321,10 @@ export class AccountCommand extends BaseCommand {
return true
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async update (argv) {
const self = this

Expand Down Expand Up @@ -351,6 +394,10 @@ export class AccountCommand extends BaseCommand {
return true
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async get (argv) {
const self = this

Expand Down Expand Up @@ -406,10 +453,11 @@ export class AccountCommand extends BaseCommand {

/**
* Return Yargs command definition for 'node' command
* @param accountCmd an instance of NodeCommand
* @param {AccountCommand} accountCmd an instance of NodeCommand
* @returns {{command: string, desc: string, builder: Function}}
*/
static getCommandDefinition (accountCmd) {
if (!accountCmd | !(accountCmd instanceof AccountCommand)) {
if (!accountCmd || !(accountCmd instanceof AccountCommand)) {
throw new IllegalArgumentError('An instance of AccountCommand is required', accountCmd)
}
return {
Expand Down
13 changes: 13 additions & 0 deletions src/commands/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { MissingArgumentError } from '../core/errors.mjs'
import { ShellRunner } from '../core/shell_runner.mjs'

export class BaseCommand extends ShellRunner {
/**
* @param {string} chartDir
* @param {string} chartRepo
* @param {string} chartReleaseName
* @returns {Promise<string>}
*/
async prepareChartPath (chartDir, chartRepo, chartReleaseName) {
if (!chartRepo) throw new MissingArgumentError('chart repo name is required')
if (!chartReleaseName) throw new MissingArgumentError('chart release name is required')
Expand All @@ -33,6 +39,10 @@ export class BaseCommand extends ShellRunner {
return `${chartRepo}/${chartReleaseName}`
}

/**
* @param {string} valuesFile
* @returns {string}
*/
prepareValuesFiles (valuesFile) {
let valuesArg = ''
if (valuesFile) {
Expand All @@ -46,6 +56,9 @@ export class BaseCommand extends ShellRunner {
return valuesArg
}

/**
* @param {{logger: Logger, helm: Helm, k8: K8, chartManager: ChartManager, configManager: ConfigManager, depManager: DependencyManager}} opts
*/
constructor (opts) {
if (!opts || !opts.logger) throw new Error('An instance of core/Logger is required')
if (!opts || !opts.helm) throw new Error('An instance of core/Helm is required')
Expand Down
25 changes: 15 additions & 10 deletions src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
'use strict'
import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer'
import { Listr } from 'listr2'
import { FullstackTestingError, IllegalArgumentError } from '../core/errors.mjs'
Expand All @@ -28,6 +29,9 @@ import path from 'path'
* Define the core functionalities of 'cluster' command
*/
export class ClusterCommand extends BaseCommand {
/**
* @returns {Promise<boolean>}
*/
async showClusterList () {
this.logger.showList('Clusters', await this.k8.getClusters())
return true
Expand All @@ -52,15 +56,15 @@ export class ClusterCommand extends BaseCommand {

/**
* Show list of installed chart
* @param clusterSetupNamespace
* @param {string} clusterSetupNamespace
*/
async showInstalledChartList (clusterSetupNamespace) {
this.logger.showList('Installed Charts', await this.chartManager.getInstalledCharts(clusterSetupNamespace))
}

/**
* Setup cluster with shared components
* @param argv
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async setup (argv) {
Expand Down Expand Up @@ -155,7 +159,7 @@ export class ClusterCommand extends BaseCommand {

/**
* Uninstall shared components from the cluster and perform any other necessary cleanups
* @param argv
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async reset (argv) {
Expand Down Expand Up @@ -218,7 +222,8 @@ export class ClusterCommand extends BaseCommand {

/**
* Return Yargs command definition for 'cluster' command
* @param clusterCmd an instance of ClusterCommand
* @param {ClusterCommand} clusterCmd - an instance of ClusterCommand
* @returns {{command: string, desc: string, builder: Function}}
*/
static getCommandDefinition (clusterCmd) {
if (!clusterCmd || !(clusterCmd instanceof ClusterCommand)) {
Expand Down Expand Up @@ -315,11 +320,11 @@ export class ClusterCommand extends BaseCommand {
/**
* Prepare values arg for cluster setup command
*
* @param chartDir local charts directory (default is empty)
* @param prometheusStackEnabled a bool to denote whether to install prometheus stack
* @param minioEnabled a bool to denote whether to install minio
* @param certManagerEnabled a bool to denote whether to install cert manager
* @param certManagerCrdsEnabled a bool to denote whether to install cert manager CRDs
* @param {string} chartDir - local charts directory (default is empty)
* @param {boolean} prometheusStackEnabled - a bool to denote whether to install prometheus stack
* @param {boolean} minioEnabled - a bool to denote whether to install minio
* @param {boolean} certManagerEnabled - a bool to denote whether to install cert manager
* @param {boolean} certManagerCrdsEnabled - a bool to denote whether to install cert manager CRDs
* @returns {string}
*/
prepareValuesArg (chartDir = flags.chartDirectory.definition.default,
Expand Down Expand Up @@ -348,7 +353,7 @@ export class ClusterCommand extends BaseCommand {

/**
* Prepare chart path
* @param chartDir local charts directory (default is empty)
* @param {string} [chartDir] - local charts directory (default is empty)
* @returns {Promise<string>}
*/
async prepareChartPath (chartDir = flags.chartDirectory.definition.default) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
'use strict'
import { constants } from '../core/index.mjs'
import * as core from '../core/index.mjs'
import * as version from '../../version.mjs'
Expand Down
6 changes: 4 additions & 2 deletions src/commands/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
'use strict'
import { ClusterCommand } from './cluster.mjs'
import { InitCommand } from './init.mjs'
import { MirrorNodeCommand } from './mirror_node.mjs'
Expand All @@ -23,9 +24,10 @@ import { RelayCommand } from './relay.mjs'
import { AccountCommand } from './account.mjs'
import * as flags from './flags.mjs'

/*
/**
* Return a list of Yargs command builder to be exposed through CLI
* @param opts it is an Options object containing logger
* @param {Object} opts it is an Options object containing logger
* @returns {Array<{command: string, desc: string, builder: Function, handler?: Function}[]>}
*/
function Initialize (opts) {
const initCmd = new InitCommand(opts)
Expand Down
8 changes: 6 additions & 2 deletions src/commands/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
'use strict'
import { Listr } from 'listr2'
import path from 'path'
import { BaseCommand } from './base.mjs'
Expand All @@ -30,7 +31,8 @@ import chalk from 'chalk'
export class InitCommand extends BaseCommand {
/**
* Setup home directories
* @param dirs a list of directories that need to be created in sequence
* @param {string[]} dirs a list of directories that need to be created in sequence
* @returns {string[]}
*/
setupHomeDirectory (dirs = [
constants.SOLO_HOME_DIR,
Expand All @@ -57,6 +59,7 @@ export class InitCommand extends BaseCommand {

/**
* Executes the init CLI command
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async init (argv) {
Expand Down Expand Up @@ -141,7 +144,8 @@ export class InitCommand extends BaseCommand {

/**
* Return Yargs command definition for 'init' command
* @param initCmd an instance of InitCommand
* @param {InitCommand} initCmd - an instance of InitCommand
* @returns {{command: string, desc: string, builder: Function, handler: (argv: Object) => void}}
*/
static getCommandDefinition (initCmd) {
if (!initCmd || !(initCmd instanceof InitCommand)) {
Expand Down
27 changes: 26 additions & 1 deletion src/commands/mirror_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import * as prompts from './prompts.mjs'
import { getFileContents, getEnvValue } from '../core/helpers.mjs'

export class MirrorNodeCommand extends BaseCommand {
/**
* @param {{accountManager: AccountManager, profileManager: ProfileManager, logger: Logger, helm: Helm, k8: K8,
* hartManager: ChartManager, configManager: ConfigManager, depManager: DependencyManager,
* downloader: PackageDownloader}} opts
*/
constructor (opts) {
super(opts)
if (!opts || !opts.accountManager) throw new IllegalArgumentError('An instance of core/AccountManager is required', opts.accountManager)
Expand All @@ -33,10 +38,16 @@ export class MirrorNodeCommand extends BaseCommand {
this.profileManager = opts.profileManager
}

/**
* @returns {string}
*/
static get DEPLOY_CONFIGS_NAME () {
return 'deployConfigs'
}

/**
* @returns {CommandFlag[]}
*/
static get DEPLOY_FLAGS_LIST () {
return [
flags.chartDirectory,
Expand All @@ -49,6 +60,11 @@ export class MirrorNodeCommand extends BaseCommand {
]
}

/**
* @param {string} valuesFile
* @param {boolean} deployHederaExplorer
* @returns {Promise<string>}
*/
async prepareValuesArg (valuesFile, deployHederaExplorer) {
let valuesArg = ''
if (valuesFile) {
Expand All @@ -65,6 +81,10 @@ export class MirrorNodeCommand extends BaseCommand {
return valuesArg
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async deploy (argv) {
const self = this

Expand Down Expand Up @@ -275,6 +295,10 @@ export class MirrorNodeCommand extends BaseCommand {
return true
}

/**
* @param {Object} argv
* @returns {Promise<boolean>}
*/
async destroy (argv) {
const self = this

Expand Down Expand Up @@ -364,7 +388,8 @@ export class MirrorNodeCommand extends BaseCommand {

/**
* Return Yargs command definition for 'mirror-mirror-node' command
* @param mirrorNodeCmd an instance of NodeCommand
* @param {MirrorNodeCommand} mirrorNodeCmd an instance of NodeCommand
instamenta marked this conversation as resolved.
Show resolved Hide resolved
* @returns {{command: string, desc: string, builder: Function}}
*/
static getCommandDefinition (mirrorNodeCmd) {
if (!mirrorNodeCmd || !(mirrorNodeCmd instanceof MirrorNodeCommand)) {
Expand Down
Loading
Loading