diff options
Diffstat (limited to 'src/data/composite/wiki-properties/helpers')
-rw-r--r-- | src/data/composite/wiki-properties/helpers/reference-list-helpers.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/data/composite/wiki-properties/helpers/reference-list-helpers.js b/src/data/composite/wiki-properties/helpers/reference-list-helpers.js new file mode 100644 index 00000000..dfdc6b41 --- /dev/null +++ b/src/data/composite/wiki-properties/helpers/reference-list-helpers.js @@ -0,0 +1,44 @@ +import {input} from '#composite'; +import {anyOf, isString, isThingClass, validateArrayItems} from '#validators'; + +export function referenceListInputDescriptions() { + return { + class: input.staticValue({ + validate: + anyOf( + isThingClass, + validateArrayItems(isThingClass)), + + acceptsNull: true, + defaultValue: null, + }), + + referenceType: input.staticValue({ + validate: + anyOf( + isString, + validateArrayItems(isString)), + + acceptsNull: true, + defaultValue: null, + }), + }; +} + +export function referenceListUpdateDescription({ + validateReferenceList, +}) { + return ({ + [input.staticValue('class')]: thingClass, + [input.staticValue('referenceType')]: referenceType, + }) => ({ + validate: + validateReferenceList( + (Array.isArray(thingClass) + ? thingClass.map(thingClass => + thingClass[Symbol.for('Thing.referenceType')]) + : thingClass + ? thingClass[Symbol.for('Thing.referenceType')] + : referenceType)), + }); +} |