Skip to content

Commit

Permalink
build: properly workaround Ajv TS type definitions bug
Browse files Browse the repository at this point in the history
ajv-validator/ajv#2132

Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
Jérôme Benoit committed Dec 28, 2023
1 parent 8fc5fda commit f5a1ff8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/charging-station/ocpp/OCPPIncomingRequestService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import ajvFormats from 'ajv-formats';
import _Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import _ajvFormats from 'ajv-formats';

import { OCPPConstants } from './OCPPConstants.js';
import { OCPPServiceUtils } from './OCPPServiceUtils.js';
Expand All @@ -13,6 +13,9 @@ import type {
OCPPVersion,
} from '../../types/index.js';
import { logger, setDefaultErrorParams } from '../../utils/index.js';
type Ajv = _Ajv.default;
const Ajv = _Ajv.default;
const ajvFormats = _ajvFormats.default;

const moduleName = 'OCPPIncomingRequestService';

Expand All @@ -25,7 +28,6 @@ export abstract class OCPPIncomingRequestService {

protected constructor(version: OCPPVersion) {
this.version = version;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.ajv = new Ajv({
keywords: ['javaType'],
multipleOfPrecision: 2,
Expand Down Expand Up @@ -118,7 +120,6 @@ export abstract class OCPPIncomingRequestService {
schema: JSONSchemaType<T>,
) {
if (this.jsonValidateFunctions.has(commandName) === false) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
}
return this.jsonValidateFunctions.get(commandName)!;
Expand Down
12 changes: 5 additions & 7 deletions src/charging-station/ocpp/OCPPRequestService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import ajvFormats from 'ajv-formats';
import _Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import _ajvFormats from 'ajv-formats';

import { OCPPConstants } from './OCPPConstants.js';
import type { OCPPResponseService } from './OCPPResponseService.js';
Expand Down Expand Up @@ -30,6 +30,9 @@ import {
isNullOrUndefined,
logger,
} from '../../utils/index.js';
type Ajv = _Ajv.default;
const Ajv = _Ajv.default;
const ajvFormats = _ajvFormats.default;

const moduleName = 'OCPPRequestService';

Expand All @@ -49,7 +52,6 @@ export abstract class OCPPRequestService {

protected constructor(version: OCPPVersion, ocppResponseService: OCPPResponseService) {
this.version = version;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.ajv = new Ajv({
keywords: ['javaType'],
multipleOfPrecision: 2,
Expand Down Expand Up @@ -234,7 +236,6 @@ export abstract class OCPPRequestService {
if (this.jsonValidateFunctions.has(commandName) === false) {
this.jsonValidateFunctions.set(
commandName,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
this.ajv.compile<T>(this.jsonSchemas.get(commandName)!).bind(this),
);
}
Expand Down Expand Up @@ -289,11 +290,8 @@ export abstract class OCPPRequestService {
) {
this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.set(
commandName,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
this.ajv
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.compile<T>(this.ocppResponseService.jsonIncomingRequestResponseSchemas.get(commandName)!)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.bind(this),
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/charging-station/ocpp/OCPPResponseService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import ajvFormats from 'ajv-formats';
import _Ajv, { type JSONSchemaType, type ValidateFunction } from 'ajv';
import _ajvFormats from 'ajv-formats';

import { OCPPServiceUtils } from './OCPPServiceUtils.js';
import type { ChargingStation } from '../../charging-station/index.js';
Expand All @@ -11,6 +11,9 @@ import type {
RequestCommand,
} from '../../types/index.js';
import { logger } from '../../utils/index.js';
type Ajv = _Ajv.default;
const Ajv = _Ajv.default;
const ajvFormats = _ajvFormats.default;

const moduleName = 'OCPPResponseService';

Expand All @@ -33,7 +36,6 @@ export abstract class OCPPResponseService {

protected constructor(version: OCPPVersion) {
this.version = version;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.ajv = new Ajv({
keywords: ['javaType'],
multipleOfPrecision: 2,
Expand Down Expand Up @@ -102,7 +104,6 @@ export abstract class OCPPResponseService {
schema: JSONSchemaType<T>,
) {
if (this.jsonRequestValidateFunctions.has(commandName) === false) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
this.jsonRequestValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
}
return this.jsonRequestValidateFunctions.get(commandName)!;
Expand Down

0 comments on commit f5a1ff8

Please sign in to comment.