« get me outta code hell

data: compositeFrom: validate static token shapes for normal input - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-28 13:19:52 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-28 13:19:52 -0300
commitd719eff73be9b18a3c83b984e68469c3be91457c (patch)
treed240f60b560e7f95916315c93ce821be6607dd56
parent1e09cfe3fcaa3f6e020e50ce49ea77c254b04dfd (diff)
data: compositeFrom: validate static token shapes for normal input
-rw-r--r--src/data/things/composite.js49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index e58b6524..de6827c6 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -576,7 +576,7 @@ export function templateCompositeFrom(description) {
         expectedInputNames
           .filter(name => !providedInputNames.includes(name))
           .filter(name => {
-            const inputDescription = description.inputs[name].value;
+            const inputDescription = getInputTokenValue(description.inputs[name]);
             if (!inputDescription) return true;
             if ('defaultValue' in inputDescription) return false;
             if ('defaultDependency' in inputDescription) return false;
@@ -587,6 +587,7 @@ export function templateCompositeFrom(description) {
 
       const expectedStaticValueInputNames = [];
       const expectedStaticDependencyInputNames = [];
+      const expectedValueProvidingTokenInputNames = [];
 
       const validateFailedErrors = [];
 
@@ -605,18 +606,33 @@ export function templateCompositeFrom(description) {
         const tokenShape = (isInputToken(value) ? getInputTokenShape(value) : null);
         const tokenValue = (isInputToken(value) ? getInputTokenValue(value) : null);
 
-        if (descriptionShape === 'input.staticValue') {
-          if (tokenShape !== 'input.value') {
-            expectedStaticValueInputNames.push(name);
-            continue;
-          }
-        }
+        switch (descriptionShape) {
+          case'input.staticValue':
+            if (tokenShape !== 'input.value') {
+              expectedStaticValueInputNames.push(name);
+              continue;
+            }
+            break;
 
-        if (descriptionShape === 'input.staticDependency') {
-          if (typeof value !== 'string' && tokenShape !== 'input.dependency') {
-            expectedStaticDependencyInputNames.push(name);
-            continue;
-          }
+          case 'input.staticDependency':
+            if (typeof value !== 'string' && tokenShape !== 'input.dependency') {
+              expectedStaticDependencyInputNames.push(name);
+              continue;
+            }
+            break;
+
+          case 'input':
+            if (typeof value !== 'string' && ![
+              'input',
+              'input.value',
+              'input.dependency',
+              'input.myself',
+              'input.updateValue',
+            ].includes(tokenShape)) {
+              expectedValueProvidingTokenInputNames.push(name);
+              continue;
+            }
+            break;
         }
 
         if (tokenShape === 'input.value') {
@@ -645,6 +661,15 @@ export function templateCompositeFrom(description) {
         push(new Error(`Expected static values: ${expectedStaticValueInputNames.join(', ')}`));
       }
 
+      for (const name of expectedValueProvidingTokenInputNames) {
+        const shapeOrType =
+          (isInputToken(inputOptions[name])
+            ? getInputTokenShape(inputOptions[name])
+            : typeof inputOptions[name]);
+
+        push(new Error(`${name}: Expected dependency name or value-providing input() call, got ${shapeOrType}`));
+      }
+
       for (const name of wrongTypeInputNames) {
         const type = typeof inputOptions[name];
         push(new Error(`${name}: Expected string or input() call, got ${type}`));