type GetDiagnosticsRequest,
type GetDiagnosticsResponse,
type IncomingRequestHandler,
- type JsonObject,
type JsonType,
OCPP16AuthorizationStatus,
OCPP16AvailabilityType,
const moduleName = 'OCPP16IncomingRequestService';
export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
- protected jsonSchemas: Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonType>>;
private incomingRequestHandlers: Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
this.handleRequestCancelReservation.bind(this) as unknown as IncomingRequestHandler,
],
]);
- this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonType>>([
[
OCPP16IncomingRequestCommand.RESET,
OCPP16ServiceUtils.parseJsonSchemaFile<ResetRequest>(
const moduleName = 'OCPP16RequestService';
export class OCPP16RequestService extends OCPPRequestService {
- protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>;
public constructor(ocppResponseService: OCPPResponseService) {
// if (new.target?.name === moduleName) {
// throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
// }
super(OCPPVersion.VERSION_16, ocppResponseService);
- this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>([
[
OCPP16RequestCommand.AUTHORIZE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
type GenericResponse,
type GetConfigurationResponse,
type GetDiagnosticsResponse,
- type JsonObject,
type JsonType,
OCPP16AuthorizationStatus,
type OCPP16AuthorizeRequest,
export class OCPP16ResponseService extends OCPPResponseService {
public jsonIncomingRequestResponseSchemas: Map<
OCPP16IncomingRequestCommand,
- JSONSchemaType<JsonObject>
+ JSONSchemaType<JsonType>
>;
private responseHandlers: Map<OCPP16RequestCommand, ResponseHandler>;
- private jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
+ private jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>;
public constructor() {
// if (new.target?.name === moduleName) {
this.emptyResponseHandler.bind(this) as ResponseHandler,
],
]);
- this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>([
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
import {
ErrorType,
type IncomingRequestHandler,
- type JsonObject,
type JsonType,
type OCPP20ClearCacheRequest,
OCPP20IncomingRequestCommand,
const moduleName = 'OCPP20IncomingRequestService';
export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
- protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonType>>;
private incomingRequestHandlers: Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>;
public constructor() {
this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
[OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
]);
- this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonType>>([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
const moduleName = 'OCPP20RequestService';
export class OCPP20RequestService extends OCPPRequestService {
- protected jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>;
public constructor(ocppResponseService: OCPPResponseService) {
// if (new.target?.name === moduleName) {
// throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
// }
super(OCPPVersion.VERSION_20, ocppResponseService);
- this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationRequest>(
import { OCPPError } from '../../../exception';
import {
ErrorType,
- type JsonObject,
type JsonType,
type OCPP20BootNotificationResponse,
type OCPP20ClearCacheResponse,
export class OCPP20ResponseService extends OCPPResponseService {
public jsonIncomingRequestResponseSchemas: Map<
OCPP20IncomingRequestCommand,
- JSONSchemaType<JsonObject>
+ JSONSchemaType<JsonType>
>;
private responseHandlers: Map<OCPP20RequestCommand, ResponseHandler>;
- private jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>;
+ private jsonSchemas: Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>;
public constructor() {
// if (new.target?.name === moduleName) {
this.emptyResponseHandler.bind(this) as ResponseHandler,
],
]);
- this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonType>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
ClearCacheResponse,
HandleErrorParams,
IncomingRequestCommand,
- JsonObject,
JsonType,
OCPPVersion,
} from '../../types';
private static instance: OCPPIncomingRequestService | null = null;
private readonly version: OCPPVersion;
private readonly ajv: Ajv;
- private jsonValidateFunctions: Map<IncomingRequestCommand, ValidateFunction<JsonObject>>;
- protected abstract jsonSchemas: Map<IncomingRequestCommand, JSONSchemaType<JsonObject>>;
+ private jsonValidateFunctions: Map<IncomingRequestCommand, ValidateFunction<JsonType>>;
+ protected abstract jsonSchemas: Map<IncomingRequestCommand, JSONSchemaType<JsonType>>;
protected constructor(version: OCPPVersion) {
super(moduleName);
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.jsonValidateFunctions = new Map<IncomingRequestCommand, ValidateFunction<JsonObject>>();
+ this.jsonValidateFunctions = new Map<IncomingRequestCommand, ValidateFunction<JsonType>>();
this.incomingRequestHandler = this.incomingRequestHandler.bind(this) as <
ReqType extends JsonType,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return true;
}
if (this.jsonValidateFunctions.has(commandName) === false) {
- this.jsonValidateFunctions.set(commandName, this.ajv.compile<JsonObject>(schema).bind(this));
+ this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
}
const validate = this.jsonValidateFunctions.get(commandName)!;
if (validate(payload)) {
private readonly version: OCPPVersion;
private readonly ajv: Ajv;
private readonly ocppResponseService: OCPPResponseService;
- private readonly jsonValidateFunctions: Map<RequestCommand, ValidateFunction<JsonObject>>;
- protected abstract jsonSchemas: Map<RequestCommand, JSONSchemaType<JsonObject>>;
+ private readonly jsonValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>;
+ protected abstract jsonSchemas: Map<RequestCommand, JSONSchemaType<JsonType>>;
protected constructor(version: OCPPVersion, ocppResponseService: OCPPResponseService) {
this.version = version;
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.jsonValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonObject>>();
+ this.jsonValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonType>>();
this.ocppResponseService = ocppResponseService;
this.requestHandler = this.requestHandler.bind(this) as <
// eslint-disable-next-line @typescript-eslint/no-unused-vars
responseCallback: ResponseCallback,
errorCallback: ErrorCallback,
) => string;
- this.validateRequestPayload = this.validateRequestPayload.bind(this) as <T extends JsonObject>(
+ this.validateRequestPayload = this.validateRequestPayload.bind(this) as <T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
) => boolean;
this.validateIncomingRequestResponsePayload = this.validateIncomingRequestResponsePayload.bind(
this,
- ) as <T extends JsonObject>(
+ ) as <T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
}
}
- private validateRequestPayload<T extends JsonObject>(
+ private validateRequestPayload<T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
if (this.jsonValidateFunctions.has(commandName as RequestCommand) === false) {
this.jsonValidateFunctions.set(
commandName as RequestCommand,
- this.ajv.compile(this.jsonSchemas.get(commandName as RequestCommand)!).bind(this),
+ this.ajv.compile<T>(this.jsonSchemas.get(commandName as RequestCommand)!).bind(this),
);
}
const validate = this.jsonValidateFunctions.get(commandName as RequestCommand)!;
);
}
- private validateIncomingRequestResponsePayload<T extends JsonObject>(
+ private validateIncomingRequestResponsePayload<T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.set(
commandName as IncomingRequestCommand,
this.ajv
- .compile(
+ .compile<T>(
this.ocppResponseService.jsonIncomingRequestResponseSchemas.get(
commandName as IncomingRequestCommand,
)!,
// Request
case MessageType.CALL_MESSAGE:
// Build request
- this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonObject);
+ this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonType);
chargingStation.requests.set(messageId, [
responseCallback,
errorCallback,
this.validateIncomingRequestResponsePayload(
chargingStation,
commandName,
- messagePayload as JsonObject,
+ messagePayload as JsonType,
);
messageToSend = JSON.stringify([messageType, messageId, messagePayload] as Response);
break;
import { OCPPServiceUtils } from './OCPPServiceUtils';
import type { ChargingStation } from '../../charging-station';
import { OCPPError } from '../../exception';
-import type {
- IncomingRequestCommand,
- JsonObject,
- JsonType,
- OCPPVersion,
- RequestCommand,
-} from '../../types';
+import type { IncomingRequestCommand, JsonType, OCPPVersion, RequestCommand } from '../../types';
import { logger } from '../../utils';
const moduleName = 'OCPPResponseService';
public jsonIncomingRequestResponseValidateFunctions: Map<
IncomingRequestCommand,
- ValidateFunction<JsonObject>
+ ValidateFunction<JsonType>
>;
private readonly version: OCPPVersion;
private readonly ajv: Ajv;
- private jsonRequestValidateFunctions: Map<RequestCommand, ValidateFunction<JsonObject>>;
+ private jsonRequestValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>;
public abstract jsonIncomingRequestResponseSchemas: Map<
IncomingRequestCommand,
- JSONSchemaType<JsonObject>
+ JSONSchemaType<JsonType>
>;
protected constructor(version: OCPPVersion) {
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.jsonRequestValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonObject>>();
+ this.jsonRequestValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonType>>();
this.jsonIncomingRequestResponseValidateFunctions = new Map<
IncomingRequestCommand,
- ValidateFunction<JsonObject>
+ ValidateFunction<JsonType>
>();
this.responseHandler = this.responseHandler.bind(this) as <
ReqType extends JsonType,
if (this.jsonRequestValidateFunctions.has(commandName) === false) {
this.jsonRequestValidateFunctions.set(
commandName,
- this.ajv.compile<JsonObject>(schema).bind(this),
+ this.ajv.compile<JsonType>(schema).bind(this),
);
}
const validate = this.jsonRequestValidateFunctions.get(commandName)!;