UNPKG

@citrineos/base

Version:

The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.

88 lines (87 loc) 4.58 kB
import type { ErrorObject } from 'ajv'; import type { ILogObj } from 'tslog'; import { Logger } from 'tslog'; import type { Call, CallAction, CallResult, OCPPVersionType } from '../../ocpp/rpc/message.js'; import type { ICache } from '../cache/cache.js'; import type { IMessage } from '../messages/Message.js'; import type { IMessageConfirmation } from '../messages/MessageConfirmation.js'; import type { IMessageHandler } from '../messages/MessageHandler.js'; import type { IMessageSender } from '../messages/MessageSender.js'; import type { SystemConfig } from '../../config/types.js'; import { OcppError } from '../../ocpp/rpc/message.js'; import { MessageOrigin } from '../messages/internal-types.js'; import type { OcppRequest, OcppResponse } from '../../ocpp/internal-types.js'; import { OCPPValidator } from '../modules/OCPPValidator.js'; import type { IMessageRouter } from '../router/Router.js'; export declare abstract class AbstractMessageRouter implements IMessageRouter { /** * Fields */ protected _ocppValidator: OCPPValidator; protected _cache: ICache; protected _config: SystemConfig; protected _logger: Logger<ILogObj>; protected readonly _handler: IMessageHandler; protected readonly _sender: IMessageSender; protected _networkHook: (identifier: string, message: string) => Promise<void>; /** * Constructor of abstract ocpp router. * * @param {OCPPValidator} ocppValidator - The OCPPValidator instance to use for message validation. */ constructor(config: SystemConfig, cache: ICache, handler: IMessageHandler, sender: IMessageSender, networkHook: (identifier: string, message: string) => Promise<void>, logger?: Logger<ILogObj>, ocppValidator?: OCPPValidator); /** * Getters & Setters */ get ocppValidator(): OCPPValidator; get cache(): ICache; get sender(): IMessageSender; get handler(): IMessageHandler; get config(): SystemConfig; set networkHook(value: (identifier: string, message: string) => Promise<void>); /** * Sets the system configuration for the module. * * @param {SystemConfig} config - The new configuration to set. */ set config(config: SystemConfig); /** * Public Methods */ handle(message: IMessage<OcppRequest | OcppResponse | OcppError>): Promise<void>; /** * Protected Methods */ /** * Validates a Call object against its schema. * * @param {string} identifier - The identifier of the EVSE. * @param {Call} message - The Call object to validate. * @param {string} protocol - The subprotocol of the Websocket, i.e. "ocpp1.6" or "ocpp2.0.1". * @return {boolean} - Returns true if the Call object is valid, false otherwise. */ protected _validateCall(identifier: string, message: Call, protocol: string): { isValid: boolean; errors?: ErrorObject[] | null; }; /** * Validates a CallResult object against its schema. * * @param {string} identifier - The identifier of the EVSE. * @param {CallAction} action - The original CallAction. * @param {CallResult} message - The CallResult object to validate. * @param {string} protocol - The protocol of the Websocket. * @return {boolean} - Returns true if the CallResult object is valid, false otherwise. */ protected _validateCallResult(identifier: string, action: CallAction, message: CallResult, protocol: string): { isValid: boolean; errors?: ErrorObject[] | null; }; abstract onMessage(identifier: string, message: string, timestamp: Date, protocol: string): Promise<boolean>; abstract registerConnection(tenantId: number, ocppConnectionName: string, protocol: string): Promise<boolean>; abstract deregisterConnection(tenantId: number, ocppConnectionName: string): Promise<boolean>; abstract sendCall(ocppConnectionName: string, tenantId: number, protocol: OCPPVersionType, action: CallAction, payload: OcppRequest, correlationId?: string, origin?: MessageOrigin): Promise<IMessageConfirmation>; abstract sendCallResult(correlationId: string, ocppConnectionName: string, tenantId: number, protocol: OCPPVersionType, action: CallAction, payload: OcppResponse, origin?: MessageOrigin): Promise<IMessageConfirmation>; abstract sendCallError(correlationId: string, ocppConnectionName: string, tenantId: number, protocol: OCPPVersionType, action: CallAction, error: OcppError, origin?: MessageOrigin): Promise<IMessageConfirmation>; abstract shutdown(): Promise<void>; }