From 18dd81903cebb8cbd97c6b6e530bd8e517477da1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 3 Jan 2024 19:13:16 -0400 Subject: validators: validateAllPropertyValues: express in terms of validateProperties --- src/data/things/validators.js | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) (limited to 'src/data/things') diff --git a/src/data/things/validators.js b/src/data/things/validators.js index 939d78d5..5cbe33de 100644 --- a/src/data/things/validators.js +++ b/src/data/things/validators.js @@ -401,35 +401,10 @@ export function validateProperties(spec) { validateProperties.validateOtherKeys = Symbol(); validateProperties.allowOtherKeys = Symbol(); -export function validateAllPropertyValues(validator) { - return (object) => { - isObject(object); - - if (Array.isArray(object)) - throw new TypeError(`Expected an object, got array`); - - const errors = []; - - for (const key of Reflect.ownKeys(object)) { - const value = object[key]; - try { - validator(value); - } catch (error) { - const keyPart = colors.green(key.toString()); - const valuePart = inspect(value); - error.message = `(key: ${keyPart}, value: ${valuePart}) ${error.message}`; - errors.push(error); - } - } - - if (empty(errors)) { - return true; - } - - throw new AggregateError(errors, - `Errors validating object properties`); - }; -} +export const validateAllPropertyValues = (validator) => + validateProperties({ + [validateProperties.validateOtherKeys]: validator, + }); export const isContribution = validateProperties({ who: isArtistRef, -- cgit 1.3.0-6-gf8a5