fix(core): tidy formatting and minor fixes across CLI, SNMP, HTTP server, migrations and packaging

This commit is contained in:
2026-01-29 17:10:17 +00:00
parent fda072d15e
commit ff2dc00f31
31 changed files with 693 additions and 362 deletions

View File

@@ -31,7 +31,9 @@ export abstract class BaseMigration {
* @param config - Raw configuration object to check (unknown schema for migrations)
* @returns True if migration should run, false otherwise
*/
abstract shouldRun(config: Record<string, unknown>): Promise<boolean>;
abstract shouldRun(
config: Record<string, unknown>,
): boolean | Promise<boolean>;
/**
* Perform the migration on the given config
@@ -39,7 +41,9 @@ export abstract class BaseMigration {
* @param config - Raw configuration object to migrate (unknown schema for migrations)
* @returns Migrated configuration object
*/
abstract migrate(config: Record<string, unknown>): Promise<Record<string, unknown>>;
abstract migrate(
config: Record<string, unknown>,
): Record<string, unknown> | Promise<Record<string, unknown>>;
/**
* Get human-readable name for this migration

View File

@@ -23,12 +23,12 @@ export class MigrationV1ToV2 extends BaseMigration {
readonly fromVersion = '1.x';
readonly toVersion = '2.0';
async shouldRun(config: any): Promise<boolean> {
shouldRun(config: Record<string, unknown>): boolean {
// V1 format has snmp field directly at root, no upsDevices or upsList
return !!config.snmp && !config.upsDevices && !config.upsList;
}
async migrate(config: any): Promise<any> {
migrate(config: Record<string, unknown>): Record<string, unknown> {
logger.info(`${this.getName()}: Converting single SNMP config to multi-UPS format...`);
const migrated = {

View File

@@ -42,15 +42,16 @@ export class MigrationV3ToV4 extends BaseMigration {
readonly fromVersion = '3.x';
readonly toVersion = '4.0';
async shouldRun(config: any): Promise<boolean> {
shouldRun(config: Record<string, unknown>): boolean {
// V3 format has upsList OR has upsDevices with flat structure (host at top level)
if (config.upsList && !config.upsDevices) {
return true; // Classic v3 with upsList
}
// Check if upsDevices exists but has flat structure (v3 format)
if (config.upsDevices && config.upsDevices.length > 0) {
const firstDevice = config.upsDevices[0];
const upsDevices = config.upsDevices as Array<Record<string, unknown>> | undefined;
if (upsDevices && upsDevices.length > 0) {
const firstDevice = upsDevices[0];
// V3 has host at top level, v4 has it nested in snmp object
return !!firstDevice.host && !firstDevice.snmp;
}
@@ -58,17 +59,17 @@ export class MigrationV3ToV4 extends BaseMigration {
return false;
}
async migrate(config: any): Promise<any> {
migrate(config: Record<string, unknown>): Record<string, unknown> {
logger.info(`${this.getName()}: Migrating v3 config to v4 format...`);
logger.dim(` - Restructuring UPS devices (flat → nested snmp config)`);
// Get devices from either upsList or upsDevices (for partially migrated configs)
const sourceDevices = config.upsList || config.upsDevices;
const sourceDevices = (config.upsList || config.upsDevices) as Array<Record<string, unknown>>;
// Transform each UPS device from v3 flat structure to v4 nested structure
const transformedDevices = sourceDevices.map((device: any) => {
const transformedDevices = sourceDevices.map((device: Record<string, unknown>) => {
// Build SNMP config object
const snmpConfig: any = {
const snmpConfig: Record<string, unknown> = {
host: device.host,
port: device.port || 161,
version: typeof device.version === 'string' ? parseInt(device.version, 10) : device.version,
@@ -112,7 +113,9 @@ export class MigrationV3ToV4 extends BaseMigration {
checkInterval: config.checkInterval || 30000,
};
logger.success(`${this.getName()}: Migration complete (${transformedDevices.length} devices transformed)`);
logger.success(
`${this.getName()}: Migration complete (${transformedDevices.length} devices transformed)`,
);
return migrated;
}
}

View File

@@ -49,7 +49,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
readonly fromVersion = '4.0';
readonly toVersion = '4.1';
async shouldRun(config: Record<string, unknown>): Promise<boolean> {
shouldRun(config: Record<string, unknown>): boolean {
// Run if config is version 4.0
if (config.version === '4.0') {
return true;
@@ -65,7 +65,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
return false;
}
async migrate(config: Record<string, unknown>): Promise<Record<string, unknown>> {
migrate(config: Record<string, unknown>): Record<string, unknown> {
logger.info(`${this.getName()}: Migrating v4.0 config to v4.1 format...`);
logger.dim(` - Moving thresholds from UPS level to action level`);
logger.dim(` - Creating default shutdown actions from existing thresholds`);
@@ -81,7 +81,9 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
};
// If device has thresholds at UPS level, convert to shutdown action
const deviceThresholds = device.thresholds as { battery: number; runtime: number } | undefined;
const deviceThresholds = device.thresholds as
| { battery: number; runtime: number }
| undefined;
if (deviceThresholds) {
migrated.actions = [
{