X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FJsonFileStorage.ts;h=fcb35a4df0507569d941edbcb1aac223561e6be4;hb=e302df1d4573ef07df7c44a210a34e429f571814;hp=2cdab50560fda0cd5e744d8265c4f1f49edeef61;hpb=fe791818e4bb6ae1e37e95c5528e7538c17ec8dd;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 2cdab505..fcb35a4d 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -1,14 +1,12 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -import fs from 'fs'; +import fs from 'node:fs'; import lockfile from 'proper-lockfile'; -import { FileType } from '../../types/FileType'; -import type Statistics from '../../types/Statistics'; -import FileUtils from '../../utils/FileUtils'; -import Utils from '../../utils/Utils'; -import { Storage } from './Storage'; +import { FileType, type Statistics } from '../../types'; +import { Constants, FileUtils, Utils } from '../../utils'; +import { Storage } from '../internal'; export class JsonFileStorage extends Storage { private fd: number | null = null; @@ -36,30 +34,28 @@ export class JsonFileStorage extends Storage { ); } catch (error) { FileUtils.handleFileException( - this.logPrefix, - FileType.PerformanceRecords, this.dbName, - error as NodeJS.ErrnoException + FileType.PerformanceRecords, + error as NodeJS.ErrnoException, + this.logPrefix ); } await release(); }) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); } public open(): void { try { - if (!this?.fd) { + if (Utils.isNullOrUndefined(this?.fd)) { this.fd = fs.openSync(this.dbName, 'a+'); } } catch (error) { FileUtils.handleFileException( - this.logPrefix, - FileType.PerformanceRecords, this.dbName, - error as NodeJS.ErrnoException + FileType.PerformanceRecords, + error as NodeJS.ErrnoException, + this.logPrefix ); } } @@ -72,10 +68,10 @@ export class JsonFileStorage extends Storage { } } catch (error) { FileUtils.handleFileException( - this.logPrefix, - FileType.PerformanceRecords, this.dbName, - error as NodeJS.ErrnoException + FileType.PerformanceRecords, + error as NodeJS.ErrnoException, + this.logPrefix ); } }