X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FJsonFileStorage.ts;h=8465290325173d316a24e6ef26f1d6a252675ad1;hb=10572f6c7fcc6787c8ce3e8529b88d9c0b021a10;hp=17f5ad2f62ff92f3b06b7abb7b068208a62a325e;hpb=a95873d8d308a20a7151346ac70d9a551f1a06f5;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 17f5ad2f..84652903 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -1,11 +1,14 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. +import fs from 'fs'; + +import lockfile from 'proper-lockfile'; + import { FileType } from '../../types/FileType'; +import type { Statistics } from '../../types/Statistics'; import FileUtils from '../../utils/FileUtils'; -import Statistics from '../../types/Statistics'; +import Utils from '../../utils/Utils'; import { Storage } from './Storage'; -import fs from 'fs'; -import lockfile from 'proper-lockfile'; export class JsonFileStorage extends Storage { private fd: number | null = null; @@ -28,19 +31,7 @@ export class JsonFileStorage extends Storage { performanceRecords.push(performanceStatistics); fs.writeFileSync( this.dbName, - JSON.stringify( - performanceRecords, - (key, value) => { - if (value instanceof Map) { - return { - dataType: 'Map', - value: [...value], - }; - } - return value as Statistics; - }, - 2 - ), + Utils.JSONStringifyWithMapSupport(performanceRecords, 2), 'utf8' ); } catch (error) {