« get me outta code hell

data: improve selecting values for input tokens in dependencies - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-22 14:00:43 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-23 20:24:32 -0300
commit7f7c50e7976bebc937c302638cade5e1fd543ff4 (patch)
tree521a78851e38977f97022c50e038487e95fc6d76 /src/data
parente14ed656f5bd1577118d053317037377c1a7a818 (diff)
data: improve selecting values for input tokens in dependencies
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things/composite.js45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 98537c95..da2848f8 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -1163,21 +1163,46 @@ export function compositeFrom(description) {
 
       let continuationStorage;
 
+      const filterableDependencies = {
+        ...availableDependencies,
+        ...inputMetadata,
+        ...inputValues,
+        ...
+          (expectingTransform
+            ? {[input.updateValue()]: valueSoFar}
+            : {}),
+        [input.myself()]: initialDependencies?.['this'] ?? null,
+      };
+
+      const selectDependencies =
+        (expose.dependencies ?? []).map(dependency => {
+          if (!isInputToken(dependency)) return dependency;
+          const tokenShape = getInputTokenShape(dependency);
+          const tokenValue = getInputTokenValue(dependency);
+          switch (tokenShape) {
+            case 'input':
+            case 'input.staticDependency':
+            case 'input.staticValue':
+              return dependency;
+            case 'input.myself':
+              return input.myself();
+            case 'input.dependency':
+              return tokenValue;
+            case 'input.updateValue':
+              return input.updateValue();
+            default:
+              throw new Error(`Unexpected token ${tokenShape} as dependency`);
+          }
+        })
+
       const filteredDependencies =
-        filterProperties({
-          ...availableDependencies,
-          ...inputMetadata,
-          ...inputValues,
-          ...
-            (callingTransformForThisStep
-              ? {[input.updateValue()]: valueSoFar}
-              : {}),
-          [input.myself()]: initialDependencies['this'],
-        }, expose.dependencies ?? []);
+        filterProperties(filterableDependencies, selectDependencies);
 
       debug(() => [
         `step #${i+1} - ${callingTransformForThisStep ? 'transform' : 'compute'}`,
         `with dependencies:`, filteredDependencies,
+        `selecting:`, selectDependencies,
+        `from available:`, filterableDependencies,
         ...callingTransformForThisStep ? [`from value:`, valueSoFar] : []]);
 
       let result;