1
0
mirror of https://github.com/koloml/philomena-tagging-assistant.git synced 2026-05-09 07:12:19 +00:00

Validate exclusive and conditional as optional booleans

This commit is contained in:
2026-04-05 18:33:34 +04:00
parent 66fd093e5a
commit b4419b5de3

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!');