perform checkMatchesObjectStructure in parseValidObject

This commit is contained in:
marlon-erler
2024-07-22 01:40:00 +02:00
parent d85ced4e36
commit 53399ba2b4
4 changed files with 25 additions and 18 deletions
+10 -10
View File
@@ -1,11 +1,11 @@
// this file is responsible for reading and writing persistent data; all storage shall be handled by this file.
import { DATA_VERSION, ValidObject, checkMatchesObjectStructure } from "./Utility/typeSafety";
import {
localeCompare,
parseValidObject,
stringify,
} from "./Utility/utility";
DATA_VERSION,
ValidObject,
checkMatchesObjectStructure,
} from "./Utility/typeSafety";
import { localeCompare, parseValidObject, stringify } from "./Utility/utility";
export const PATH_COMPONENT_SEPARATOR = "\\";
@@ -77,16 +77,16 @@ export default class StorageModel {
this.write(pathComponents, valueString);
};
readStringifiable = <T extends ValidObject>(pathComponents: string[], reference: T): T | null => {
readStringifiable = <T extends ValidObject>(
pathComponents: string[],
reference: T
): T | null => {
const valueString: string | null = this.read(pathComponents);
if (!valueString) return null;
const object: any | null = parseValidObject(valueString);
const object: any | null = parseValidObject(valueString, reference);
if (object == null) return null;
const doesMatchReference: boolean = checkMatchesObjectStructure(object, reference);
if (doesMatchReference == false) return null;
return object;
};