Validate exclusive and conditional as optional booleans

This commit is contained in:
koloml committed 2026-04-05 18:33:34 +04:00
1 parent 66fd093e5a
commit b4419b5de3
1 file changed
+10 -1
+10 -1
View File
@@ -32,6 +32,14 @@ function validateOptionalArray(value: unknown): boolean {
return typeof value === 'undefined' || value === null || Array.isArray(value);
}
/**
* Check if the following value is not set or is a valid boolean.
* @param value Value to be checked.
*/
function validateOptionalBoolean(value: unknown): boolean {
return typeof value === 'undefined' || typeof value === 'boolean';
}
/**
* Map of validators for each entity. Function should throw the error if validation failed.
*/
@@ -73,7 +81,8 @@ const entitiesValidators: EntitiesValidationMap = {
!validateRequiredString(importedObject?.id)
|| !validateRequiredString(importedObject?.name)
|| !validateOptionalArray(importedObject?.tags)
|| typeof importedObject.conditional !== 'boolean'
|| !validateOptionalBoolean(importedObject?.exclusive)
|| !validateOptionalBoolean(importedObject?.conditional)
|| !validateOptionalArray(importedObject?.requiredTags)
) {
throw new Error('Invalid preset format detected!');