Skip to content

Commit

Permalink
chore: remove circular dependencies (#925)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon authored Dec 5, 2024
1 parent d5aaa91 commit 88f3458
Show file tree
Hide file tree
Showing 81 changed files with 1,974 additions and 683 deletions.
1,416 changes: 1,357 additions & 59 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"test-e2e-relay": "cross-env MOCHA_SUITE_NAME=\"Mocha E2E Relay Tests\" c8 --report-dir='coverage/e2e-relay' mocha 'test/e2e/commands/relay.test.ts' --reporter-options configFile=mocha-multi-reporter.json,cmrOutput=mocha-junit-reporter+mochaFile+junit-e2e-relay.xml",
"solo-test": "tsx --no-deprecation --no-warnings solo.ts",
"solo": "node --no-deprecation --no-warnings dist/solo.js",
"check": "remark . --quiet --frail && eslint . ; cd docs; jsdoc -c jsdoc.conf.json && tsc",
"format": "remark . --quiet --frail --output && eslint --fix . && tsc",
"check": "remark . --quiet --frail && eslint . && tsc && (madge --circular src/* || true) && cd docs; jsdoc -c jsdoc.conf.json",
"format": "remark . --quiet --frail --output && eslint --fix . && tsc && madge --circular src/* || true",
"test-setup": "./test/e2e/setup-e2e.sh",
"build": "rm -Rf dist && tsc && node resources/post-build-script.js"
},
Expand Down Expand Up @@ -115,6 +115,7 @@
"eslint-plugin-tsdoc": "^0.4.0",
"globals": "^15.13.0",
"jest-mock": "^29.7.0",
"madge": "^8.0.0",
"mocha": "^11.0.1",
"mocha-each": "^2.0.1",
"mocha-junit-reporter": "^2.2.1",
Expand Down
5 changes: 3 additions & 2 deletions src/commands/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import chalk from 'chalk';
import {BaseCommand} from './base.js';
import {SoloError, IllegalArgumentError} from '../core/errors.js';
import {flags} from './index.js';
import {Flags as flags} from './flags.js';
import {Listr} from 'listr2';
import {constants, type AccountManager} from '../core/index.js';
import * as constants from '../core/constants.js';
import {type AccountManager} from '../core/account_manager.js';
import {type AccountId, AccountInfo, HbarUnit, PrivateKey} from '@hashgraph/sdk';
import {FREEZE_ADMIN_ACCOUNT} from '../core/constants.js';
import {type Opts} from '../types/index.js';
Expand Down
48 changes: 36 additions & 12 deletions src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
*/

import paths from 'path';
import {MissingArgumentError} from '../core/errors.js';
import {MissingArgumentError, SoloError} from '../core/errors.js';
import {ShellRunner} from '../core/shell_runner.js';
import type {
ChartManager,
ConfigManager,
Helm,
K8,
DependencyManager,
LeaseManager,
RemoteConfigManager,
LocalConfig,
} from '../core/index.js';
import type {CommandFlag, Opts} from '../types/index.js';
import {type LeaseManager} from '../core/lease/lease_manager.js';
import {type LocalConfig} from '../core/config/local_config.js';
import {type RemoteConfigManager} from '../core/config/remote/remote_config_manager.js';
import {type Helm} from '../core/helm.js';
import {type K8} from '../core/k8.js';
import {type ChartManager} from '../core/chart_manager.js';
import {type ConfigManager} from '../core/config_manager.js';
import {type DependencyManager} from '../core/dependency_managers/index.js';
import type {CommandFlag, CommandHandlers, Opts} from '../types/index.js';
import type {Lease} from '../core/lease/lease.js';
import {Listr} from 'listr2';

export class BaseCommand extends ShellRunner {
protected readonly helm: Helm;
Expand Down Expand Up @@ -178,4 +178,28 @@ export class BaseCommand extends ShellRunner {
getLocalConfig() {
return this.localConfig;
}

commandActionBuilder(actionTasks: any, options: any, errorString: string, lease: Lease | null) {
return async function (argv: any, commandDef: CommandHandlers) {
const tasks = new Listr([...actionTasks], options);

try {
await tasks.run();
} catch (e: Error | any) {
commandDef.parent.logger.error(`${errorString}: ${e.message}`, e);
throw new SoloError(`${errorString}: ${e.message}`, e);
} finally {
const promises = [];

// @ts-ignore
if (commandDef.close) {
// @ts-ignore
promises.push(commandDef.close());
}

if (lease) promises.push(lease.release());
await Promise.all(promises);
}
};
}
}
4 changes: 2 additions & 2 deletions src/commands/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import {ListrEnquirerPromptAdapter} from '@listr2/prompt-adapter-enquirer';
import {Listr} from 'listr2';
import {SoloError} from '../core/errors.js';
import {flags} from './index.js';
import {Flags as flags} from './flags.js';
import {BaseCommand} from './base.js';
import chalk from 'chalk';
import {constants} from '../core/index.js';
import * as constants from '../core/constants.js';
import path from 'path';
import {ListrLease} from '../core/lease/listr_lease.js';
import {type CommandBuilder} from '../types/aliases.js';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/context/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

import {flags} from '../index.js';
import {Flags as flags} from '../flags.js';

export const USE_FLAGS = {
requiredFlags: [],
Expand Down
4 changes: 2 additions & 2 deletions src/commands/context/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {type BaseCommand} from '../base.js';
import {type ContextCommandTasks} from './tasks.js';
import * as helpers from '../../core/helpers.js';
import {constants} from '../../core/index.js';
import * as constants from '../../core/constants.js';
import {type CommandHandlers} from '../../types/index.js';
import * as ContextFlags from './flags.js';

Expand All @@ -33,7 +33,7 @@ export class ContextCommandHandlers implements CommandHandlers {
async connect(argv: any) {
argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);

const action = helpers.commandActionBuilder(
const action = this.parent.commandActionBuilder(
[
this.tasks.initialize(argv),
this.parent.getLocalConfig().promptLocalConfigTask(),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/context/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*
*/

import {YargsCommand} from '../../core/index.js';
import * as ContextFlags from './flags.js';
import {YargsCommand} from '../../core/yargs_command.js';
import {BaseCommand} from './../base.js';
import type {Opts} from '../../types/index.js';
import {ContextCommandTasks} from './tasks.js';
import {ContextCommandHandlers} from './handlers.js';
import * as ContextFlags from './flags.js';

/**
* Defines the core functionalities of 'node' command
Expand Down
5 changes: 3 additions & 2 deletions src/commands/context/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*
*/
import {Task, Templates} from '../../core/index.js';
import {flags} from '../index.js';
import {Task} from '../../core/task.js';
import {Templates} from '../../core/templates.js';
import {Flags as flags} from '../flags.js';
import type {ListrTaskWrapper} from 'listr2';
import {type BaseCommand} from '../base.js';

Expand Down
5 changes: 3 additions & 2 deletions src/commands/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import {Listr, type ListrTaskWrapper} from 'listr2';
import {SoloError} from '../core/errors.js';
import {BaseCommand} from './base.js';
import {flags} from './index.js';
import {constants, Templates} from '../core/index.js';
import {Flags as flags} from './flags.js';
import * as constants from '../core/constants.js';
import {Templates} from '../core/templates.js';
import chalk from 'chalk';
import {RemoteConfigTasks} from '../core/config/remote/remote_config_tasks.js';
import {ListrLease} from '../core/lease/listr_lease.js';
Expand Down
6 changes: 3 additions & 3 deletions src/commands/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*
*/
import {ConfigManager, constants} from '../core/index.js';
import * as core from '../core/index.js';
import * as constants from '../core/constants.js';
import {ConfigManager} from '../core/config_manager.js';
import * as version from '../../version.js';
import path from 'path';
import type {CommandFlag} from '../types/index.js';
Expand Down Expand Up @@ -497,7 +497,7 @@ export class Flags {
name: 'cache-dir',
definition: {
describe: 'Local cache directory',
defaultValue: core.constants.SOLO_CACHE_DIR,
defaultValue: constants.SOLO_CACHE_DIR,
type: 'string',
},
prompt: async function promptCacheDir(task: ListrTaskWrapper<any, any, any>, input: any) {
Expand Down
6 changes: 1 addition & 5 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*
*/
import {Flags as flags} from './flags.js';
import {ClusterCommand} from './cluster.js';
import {ContextCommand} from './context/index.js';
import {InitCommand} from './init.js';
Expand All @@ -31,7 +30,7 @@ import {type Opts} from '../types/index.js';
* @param opts it is an Options object containing logger
* @returns an array of Yargs command builder
*/
function Initialize(opts: Opts) {
export function Initialize(opts: Opts) {
const initCmd = new InitCommand(opts);
const clusterCmd = new ClusterCommand(opts);
const contextCmd = new ContextCommand(opts);
Expand All @@ -55,6 +54,3 @@ function Initialize(opts: Opts) {
deploymentCommand.getCommandDefinition(),
];
}

// Expose components from the command module
export {Initialize, flags};
9 changes: 4 additions & 5 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
import {Listr} from 'listr2';
import path from 'path';
import {BaseCommand} from './base.js';
import * as core from '../core/index.js';
import {constants} from '../core/index.js';
import * as fs from 'fs';
import fs from 'fs';
import * as constants from '../core/constants.js';
import {SoloError} from '../core/errors.js';
import {flags} from './index.js';
import {Flags as flags} from './flags.js';
import chalk from 'chalk';

/**
Expand Down Expand Up @@ -82,7 +81,7 @@ export class InitCommand extends BaseCommand {
{
title: 'Check dependencies',
task: (_, task) => {
const deps = [core.constants.HELM];
const deps = [constants.HELM];

const subTasks = self.depManager.taskCheckDependencies<Context>(deps);

Expand Down
12 changes: 7 additions & 5 deletions src/commands/mirror_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import {ListrEnquirerPromptAdapter} from '@listr2/prompt-adapter-enquirer';
import {Listr} from 'listr2';
import {SoloError, IllegalArgumentError, MissingArgumentError} from '../core/errors.js';
import {constants, type ProfileManager, type AccountManager} from '../core/index.js';
import * as constants from '../core/constants.js';
import {type AccountManager} from '../core/account_manager.js';
import {type ProfileManager} from '../core/profile_manager.js';
import {BaseCommand} from './base.js';
import {flags} from './index.js';
import {getFileContents, getEnvValue} from '../core/helpers.js';
import {Flags as flags} from './flags.js';
import {getEnvValue} from '../core/helpers.js';
import {RemoteConfigTasks} from '../core/config/remote/remote_config_tasks.js';
import {type CommandBuilder, type PodName} from '../types/aliases.js';
import type {Opts} from '../types/index.js';
Expand Down Expand Up @@ -369,8 +371,8 @@ export class MirrorNodeCommand extends BaseCommand {
const exchangeRatesFileIdNum = 112;
const timestamp = Date.now();

const fees = await getFileContents(this.accountManager, namespace, feesFileIdNum);
const exchangeRates = await getFileContents(this.accountManager, namespace, exchangeRatesFileIdNum);
const fees = await this.accountManager.getFileContents(namespace, feesFileIdNum);
const exchangeRates = await this.accountManager.getFileContents(namespace, exchangeRatesFileIdNum);

const importFeesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${fees}', 'hex'), ${timestamp + '000000'}, ${feesFileIdNum}, 17);`;
const importExchangeRatesQuery = `INSERT INTO public.file_data(file_data, consensus_timestamp, entity_id, transaction_type) VALUES (decode('${exchangeRates}', 'hex'), ${
Expand Down
10 changes: 7 additions & 3 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ import chalk from 'chalk';
import {Listr} from 'listr2';
import {SoloError, IllegalArgumentError, MissingArgumentError} from '../core/errors.js';
import {BaseCommand} from './base.js';
import {flags} from './index.js';
import {constants, Templates} from '../core/index.js';
import {Flags as flags} from './flags.js';
import * as constants from '../core/constants.js';
import {Templates} from '../core/templates.js';
import * as helpers from '../core/helpers.js';
import path from 'path';
import {addDebugOptions, validatePath} from '../core/helpers.js';
import fs from 'fs';
import {RemoteConfigTasks} from '../core/config/remote/remote_config_tasks.js';
import type {CertificateManager, KeyManager, PlatformInstaller, ProfileManager} from '../core/index.js';
import {type KeyManager} from '../core/key_manager.js';
import {type PlatformInstaller} from '../core/platform_installer.js';
import {type ProfileManager} from '../core/profile_manager.js';
import {type CertificateManager} from '../core/certificate_manager.js';
import {type CommandBuilder, type NodeAlias, type NodeAliases} from '../types/aliases.js';
import type {Opts} from '../types/index.js';
import {ListrLease} from '../core/lease/listr_lease.js';
Expand Down
5 changes: 3 additions & 2 deletions src/commands/node/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*
*/
import {FREEZE_ADMIN_ACCOUNT} from '../../core/constants.js';
import {constants, Templates} from '../../core/index.js';
import {Templates} from '../../core/templates.js';
import * as constants from '../../core/constants.js';
import {PrivateKey} from '@hashgraph/sdk';
import {SoloError} from '../../core/errors.js';
import * as helpers from '../../core/helpers.js';
import path from 'path';
import fs from 'fs';
import {validatePath} from '../../core/helpers.js';
import {flags} from '../index.js';
import {Flags as flags} from '../flags.js';
import {type NodeAlias, type NodeAliases, type PodName} from '../../types/aliases.js';
import {type NetworkNodeServices} from '../../core/network_node_services.js';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/node/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
import {flags} from '../index.js';
import {Flags as flags} from '../flags.js';

export const DEFAULT_FLAGS = {
requiredFlags: [],
Expand Down
Loading

0 comments on commit 88f3458

Please sign in to comment.