feat: workspace health (#3344)

* feat: wip workspace health

* feat: split structure and metadata check

* feat: check default value structure health

* feat: check targetColumnMap structure health

* fix: composite types doesn't have default value properly defined

* feat: check default value structure health

* feat: check options structure health

* fix: verbose option not working properly

* fix: word issue

* fix: tests

* fix: remove console.log

* fix: TRUE and FALSE instead of YES and NO

* fix: fieldMetadataType instead of type
This commit is contained in:
Jérémy M
2024-01-11 16:41:25 +01:00
committed by GitHub
parent c8aec95325
commit 5f0c9f67c9
24 changed files with 1010 additions and 52 deletions

View File

@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { WorkspaceHealthCommand } from 'src/workspace/workspace-health/commands/workspace-health.command';
import { WorkspaceHealthModule } from 'src/workspace/workspace-health/workspace-health.module';
@Module({
imports: [WorkspaceHealthModule],
providers: [WorkspaceHealthCommand],
})
export class WorkspaceHealthCommandModule {}

View File

@ -0,0 +1,76 @@
import { Command, CommandRunner, Option } from 'nest-commander';
import chalk from 'chalk';
import { WorkspaceHealthMode } from 'src/workspace/workspace-health/interfaces/workspace-health-options.interface';
import { WorkspaceHealthService } from 'src/workspace/workspace-health/workspace-health.service';
interface WorkspaceHealthCommandOptions {
workspaceId: string;
verbose?: boolean;
mode?: WorkspaceHealthMode;
}
@Command({
name: 'workspace:health',
description: 'Check health of the given workspace.',
})
export class WorkspaceHealthCommand extends CommandRunner {
constructor(private readonly workspaceHealthService: WorkspaceHealthService) {
super();
}
async run(
_passedParam: string[],
options: WorkspaceHealthCommandOptions,
): Promise<void> {
const issues = await this.workspaceHealthService.healthCheck(
options.workspaceId,
{
mode: options.mode ?? WorkspaceHealthMode.All,
},
);
if (issues.length === 0) {
console.log(chalk.green('Workspace is healthy'));
} else {
console.log(chalk.red('Workspace is not healthy'));
if (options.verbose) {
console.group(chalk.red('Issues'));
issues.forEach((issue) => {
console.log(chalk.yellow(JSON.stringify(issue, null, 2)));
});
console.groupEnd();
}
}
}
@Option({
flags: '-w, --workspace-id [workspace_id]',
description: 'workspace id',
required: true,
})
parseWorkspaceId(value: string): string {
return value;
}
@Option({
flags: '-v, --verbose',
description: 'Detailed output',
required: false,
})
parseVerbose(): boolean {
return true;
}
@Option({
flags: '-m, --mode [mode]',
description: 'Mode of the health check [structure, metadata, all]',
required: false,
defaultValue: WorkspaceHealthMode.All,
})
parseMode(value: string): WorkspaceHealthMode {
return value as WorkspaceHealthMode;
}
}