From 1e09cfe3fcaa3f6e020e50ce49ea77c254b04dfd Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 28 Sep 2023 11:51:16 -0300 Subject: data: reuse validateInputValue for static inputs --- src/data/things/composite.js | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/data/things/composite.js b/src/data/things/composite.js index 26be4a6..e58b652 100644 --- a/src/data/things/composite.js +++ b/src/data/things/composite.js @@ -588,7 +588,6 @@ export function templateCompositeFrom(description) { const expectedStaticValueInputNames = []; const expectedStaticDependencyInputNames = []; - const validateFailedInputNames = []; const validateFailedErrors = []; for (const [name, value] of Object.entries(inputOptions)) { @@ -602,7 +601,6 @@ export function templateCompositeFrom(description) { } const descriptionShape = getInputTokenShape(description.inputs[name]); - const descriptionValue = getInputTokenValue(description.inputs[name]); const tokenShape = (isInputToken(value) ? getInputTokenShape(value) : null); const tokenValue = (isInputToken(value) ? getInputTokenValue(value) : null); @@ -621,14 +619,12 @@ export function templateCompositeFrom(description) { } } - if (descriptionValue && 'validate' in descriptionValue) { - if (tokenShape === 'input.value') { - try { - descriptionValue.validate(tokenValue); - } catch (error) { - validateFailedInputNames.push(name); - validateFailedErrors.push(error); - } + if (tokenShape === 'input.value') { + try { + validateInputValue(tokenValue, description.inputs[name]); + } catch (error) { + error.message = `${name}: ${error.message}`; + validateFailedErrors.push(error); } } } @@ -649,19 +645,14 @@ export function templateCompositeFrom(description) { push(new Error(`Expected static values: ${expectedStaticValueInputNames.join(', ')}`)); } - for (const {name, validationError} of stitchArrays({ - name: validateFailedInputNames, - validationError: validateFailedErrors, - })) { - const error = new Error(`${name}: Validation failed for static value`); - error.cause = validationError; - push(error); - } - for (const name of wrongTypeInputNames) { const type = typeof inputOptions[name]; push(new Error(`${name}: Expected string or input() call, got ${type}`)); } + + for (const error of validateFailedErrors) { + push(error); + } }); const inputMetadata = getStaticInputMetadata(inputOptions); @@ -1211,7 +1202,7 @@ export function compositeFrom(description) { } }); - withAggregate({message: `Errors in dynamic input values provided to ${compositionName}`}, ({push}) => { + withAggregate({message: `Errors in input values provided to ${compositionName}`}, ({push}) => { for (const {dynamic, name, value, description} of stitchArrays({ dynamic: inputsMayBeDynamicValue, name: inputNames, @@ -1223,7 +1214,7 @@ export function compositeFrom(description) { validateInputValue(value, description); } catch (error) { error.message = `${name}: ${error.message}`; - throw error; + push(error); } } }); -- cgit 1.3.0-6-gf8a5