From d719eff73be9b18a3c83b984e68469c3be91457c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 28 Sep 2023 13:19:52 -0300 Subject: data: compositeFrom: validate static token shapes for normal input --- src/data/things/composite.js | 49 +++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'src') 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}`)); -- cgit 1.3.0-6-gf8a5