- Add #domain, #protocol, #utils aliases to package.json imports map - Replace all relative imports (./, ../, ../..) in app/ and database/mongo_migrations/ with the corresponding #alias imports, eliminating relative path traversal across the codebase - Remove dead code: ConfigurationVersionModel.findByConfigurationIdentifier (unused, superseded by paginateVersions) and unused exception classes (NotFoundException, UnprocessableEntityException, DatabaseException) from app/exceptions/index.ts, keeping only BadRequestException - Fix pre-existing syntax error in configuration_version.ts (mismatched parenthesis) that broke tsc - Fix eqeqeq violation in configuration_service.ts and isNaN -> Number.isNaN in configuration_engine.ts / cwmp-1-0.ts / exchange_controller.ts - Fix no-shadow violation in cwmp-1-0.ts EventStruct constructor - Prettier formatting pass on touched files Validated: tsc --noEmit clean, eslint app/ clean, full test suite green.
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { type Device } from '#domain/device/device'
|
|
import { type CWMPTaskQueue } from '#services/cwmp/task_queue'
|
|
import { DeviceActionExecutor } from '#services/cwmp/device_action_executor'
|
|
import {
|
|
ExecutingCommandsState,
|
|
type DeviceContext,
|
|
type DeviceStateResult,
|
|
} from '#services/cwmp/main_state_machine'
|
|
import type { CWMPTaskResultData } from '#protocol/tr069_types'
|
|
import logger from '@adonisjs/core/services/logger'
|
|
|
|
/**
|
|
* State machine for "6 CONNECTION REQUEST" events.
|
|
* Only executes pending Immediate (I) commands - does NOT include NI commands.
|
|
*/
|
|
export class ImmediateCommandStateMachine {
|
|
private currentState: ExecutingCommandsState
|
|
private context: DeviceContext
|
|
|
|
constructor(device: Device, session: string, taskQueue: CWMPTaskQueue) {
|
|
// includeNI = false: only execute Immediate commands
|
|
this.currentState = new ExecutingCommandsState(false)
|
|
this.context = {
|
|
device,
|
|
session,
|
|
taskQueue,
|
|
services: {
|
|
deviceAction: new DeviceActionExecutor(taskQueue),
|
|
},
|
|
}
|
|
}
|
|
|
|
async start(): Promise<string> {
|
|
logger.info(
|
|
`Starting immediate-command state machine for device ${this.context.device.deviceId?.serialNumber}`
|
|
)
|
|
return this.execute()
|
|
}
|
|
|
|
async handleResponse(success: boolean, message: CWMPTaskResultData): Promise<string> {
|
|
this.context.message = { success, data: message }
|
|
return this.execute()
|
|
}
|
|
|
|
getCurrentStateName(): string {
|
|
return this.currentState.name
|
|
}
|
|
|
|
isCompleted(): boolean {
|
|
return (
|
|
this.currentState.name === 'completed' ||
|
|
this.currentState.name === 'operational' ||
|
|
this.currentState.name === 'partial_operational'
|
|
)
|
|
}
|
|
|
|
private async execute(): Promise<string> {
|
|
try {
|
|
const result: DeviceStateResult = await this.currentState.handle(this.context)
|
|
|
|
if (result.isComplete) {
|
|
return ''
|
|
}
|
|
|
|
if (result.response && result.response !== '') {
|
|
return result.response
|
|
}
|
|
|
|
return ''
|
|
} catch (error) {
|
|
logger.error(`Immediate-command state machine error: ${error}`)
|
|
return ''
|
|
}
|
|
}
|
|
}
|