« get me outta code hell

data: annotatedReferenceList, reference-list-helpers - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-properties/helpers
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-16 14:07:15 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 13:40:00 -0400
commit35137cbe060a2c2ec8fcdc09fc6b6bd9e932239f (patch)
tree90820a774fc87cad75c4967620a1e5301dcc628d /src/data/composite/wiki-properties/helpers
parentd28e04697429b607c38042ac09418adfceb06baf (diff)
data: annotatedReferenceList, reference-list-helpers
Diffstat (limited to 'src/data/composite/wiki-properties/helpers')
-rw-r--r--src/data/composite/wiki-properties/helpers/reference-list-helpers.js44
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)),
+  });
+}