@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.
142 lines (141 loc) • 7.13 kB
TypeScript
import 'reflect-metadata';
import { ILogObj, Logger } from 'tslog';
import { IModule } from '.';
import { OcppRequest, OcppResponse } from '../..';
import { SystemConfig } from '../../config/types';
import { CallAction, OcppError, OCPPVersionType } from '../../ocpp/rpc/message';
import { ICache } from '../cache/cache';
import { EventGroup, HandlerProperties, IMessage, IMessageConfirmation, IMessageHandler, IMessageSender, MessageOrigin } from '../messages';
export declare abstract class AbstractModule implements IModule {
static readonly CALLBACK_URL_CACHE_PREFIX: string;
protected _config: SystemConfig;
protected readonly _cache: ICache;
protected readonly _handler: IMessageHandler;
protected readonly _sender: IMessageSender;
protected readonly _eventGroup: EventGroup;
protected readonly _logger: Logger<ILogObj>;
protected _requests: CallAction[];
protected _responses: CallAction[];
private startTime;
constructor(config: SystemConfig, cache: ICache, handler: IMessageHandler, sender: IMessageSender, eventGroup: EventGroup, logger?: Logger<ILogObj>);
/**
* Getters & Setters
*/
get cache(): ICache;
get sender(): IMessageSender;
get handler(): IMessageHandler;
get config(): SystemConfig;
/**
* Sets the system configuration for the module.
*
* @param {SystemConfig} config - The new configuration to set.
*/
set config(config: SystemConfig);
/**
* Methods
*/
/**
* Handles a message with an OcppRequest or OcppResponse payload.
*
* @param {IMessage<OcppRequest | OcppResponse>} message - The message to handle.
* @param {HandlerProperties} props - Optional properties for the handler.
* @return {void} This function does not return anything.
*/
handle(message: IMessage<OcppRequest | OcppResponse>, props?: HandlerProperties): Promise<void>;
/**
* Interface methods.
*/
/**
* Unimplemented method to handle incoming {@link IMessage}.
*
* **Note**: This method is **programmatically** overridden by the {@link ModuleHandlers} annotation.
*
* @param message The {@link IMessage} to handle. Can contain either a {@link OcppRequest} or a {@link OcppResponse} as payload.
* @param props The {@link HandlerProperties} for this {@link IMessage} containing implementation specific metadata. Metadata is not used in the base implementation.
*/
handleMessageApiCallback(message: IMessage<OcppResponse>): Promise<void>;
/**
* Calls shutdown on the handler and sender.
*
* Note: To be overwritten by subclass if other logic is necessary.
*
*/
shutdown(): Promise<void>;
/**
* Default implementation
*/
/**
* Sends a call with the specified identifier, tenantId, protocol, action, payload, and origin.
*
* @param {string} identifier - The identifier of the call.
* @param {string} tenantId - The tenant ID.
* @param {string} protocol - The subprotocol of the Websocket, i.e. "ocpp1.6" or "ocpp2.0.1".
* @param {CallAction} action - The action to be performed.
* @param {OcppRequest} payload - The payload of the call.
* @param {string} [callbackUrl] - The callback URL for the call.
* @param {string} [correlationId] - The correlation ID of the call.
* @param {MessageOrigin} [origin] - The origin of the call.
* @return {Promise<IMessageConfirmation>} A promise that resolves to the message confirmation.
*/
sendCall(identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppRequest, callbackUrl?: string, correlationId?: string, origin?: MessageOrigin): Promise<IMessageConfirmation>;
/**
* Sends the call result message and returns a Promise that resolves with the confirmation message.
*
* @param {string} correlationId - The correlation ID of the message.
* @param {string} identifier - The identifier of the message.
* @param {string} tenantId - The ID of the tenant.
* @param {CallAction} action - The call action.
* @param {OcppResponse} payload - The payload of the call result message.
* @param {MessageOrigin} origin - (optional) The origin of the message.
* @return {Promise<IMessageConfirmation>} A Promise that resolves with the confirmation message.
*/
sendCallResult(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppResponse, origin?: MessageOrigin): Promise<IMessageConfirmation>;
/**
* Sends the call result using the request message's fields.
* Payload will overwrite message.payload.
*
* @param {IMessage<OcppRequest>} message - The request message object.
* @param {OcppResponse} payload - The payload to send.
* @return {Promise<IMessageConfirmation>} A promise that resolves to the message confirmation.
*/
sendCallResultWithMessage(message: IMessage<OcppRequest>, payload: OcppResponse): Promise<IMessageConfirmation>;
/**
* Sends the call error message and returns a Promise that resolves with the confirmation message.
*
* @param {string} correlationId - The correlation ID of the message.
* @param {string} identifier - The identifier of the message.
* @param {string} tenantId - The ID of the tenant.
* @param {CallAction} action - The call action.
* @param {OcppError} payload - The payload of the call error message.
* @param {MessageOrigin} origin - (optional) The origin of the message.
* @return {Promise<IMessageConfirmation>} A Promise that resolves with the confirmation message.
*/
sendCallError(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppError, origin?: MessageOrigin): Promise<IMessageConfirmation>;
/**
* Sends the call error using the request message's fields.
* Payload will overwrite message.payload.
*
* @param {IMessage<OcppRequest>} message - The request message object.
* @param {OcppResponse} payload - The payload to send.
* @return {Promise<IMessageConfirmation>} A promise that resolves to the message confirmation.
*/
sendCallErrorWithMessage(message: IMessage<OcppRequest>, payload: OcppError): Promise<IMessageConfirmation>;
/**
* Initializes the logger for the class.
*
* @return {Logger<ILogObj>} The initialized logger.
*/
protected _initLogger(baseLogger?: Logger<ILogObj>): Logger<ILogObj>;
/**
* Initializes the handler for handling requests and responses.
*/
initHandlers(): Promise<void>;
/**
* Initializes the handler for handling requests and responses.
*
* @param {CallAction[]} requests - The array of call actions for requests.
* @param {CallAction[]} responses - The array of call actions for responses.
* @return {Promise<boolean>} Returns a promise that resolves to a boolean indicating if the initialization was successful.
*/
private _initHandler;
}