From c06233c6e480b1966fa27c11c8b794055f9ec737 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 25 Jul 2024 16:59:01 -0300 Subject: composite: simplify getStaticInputMetadata Since it always operates on inputMapping, we can make more assumptions about shape. (All input names are always provided i.e. non-null, and they are always present as input tokens.) --- src/data/composite.js | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/data') diff --git a/src/data/composite.js b/src/data/composite.js index 5af1becf..eb81bb4c 100644 --- a/src/data/composite.js +++ b/src/data/composite.js @@ -72,30 +72,22 @@ function getInputTokenValue(token) { } } -function getStaticInputMetadata(inputOptions) { +function getStaticInputMetadata(inputMapping) { const metadata = {}; - for (const [name, token] of Object.entries(inputOptions)) { - if (typeof token === 'string') { - metadata[input.staticDependency(name)] = token; - metadata[input.staticValue(name)] = null; - } else if (isInputToken(token)) { - const tokenShape = getInputTokenShape(token); - const tokenValue = getInputTokenValue(token); - - metadata[input.staticDependency(name)] = - (tokenShape === 'input.dependency' - ? tokenValue - : null); - - metadata[input.staticValue(name)] = - (tokenShape === 'input.value' - ? tokenValue - : null); - } else { - metadata[input.staticDependency(name)] = null; - metadata[input.staticValue(name)] = null; - } + for (const [name, token] of Object.entries(inputMapping)) { + const tokenShape = getInputTokenShape(token); + const tokenValue = getInputTokenValue(token); + + metadata[input.staticDependency(name)] = + (tokenShape === 'input.dependency' + ? tokenValue + : null); + + metadata[input.staticValue(name)] = + (tokenShape === 'input.value' + ? tokenValue + : null); } return metadata; @@ -350,6 +342,8 @@ export function templateCompositeFrom(description) { if (typeof inputOptions[name] === 'string') { inputMapping[name] = input.dependency(inputOptions[name]); } else { + // This is always an input token, since only a string or + // an input token is a valid input option (asserted above). inputMapping[name] = inputOptions[name]; } } else if (tokenValue.defaultValue) { -- cgit 1.3.0-6-gf8a5