From 81cdaeb665a80a81b1ab7d7f0f38dc61329ca1ce Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 14 Jun 2020 14:21:29 +0200 Subject: [PATCH] Wrap rules in context that instructs to avoid parsing --- index.js | 6 +++++- package.json | 3 ++- yarn.lock | 9 ++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3e83a59..150088e 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,16 @@ const combinator = require("@validatem/combinator"); const validationResult = require("@validatem/validation-result"); +const withContext = require("@validatem/with-context"); // TODO: Document that this passes on context module.exports = function ignoreResult(rules) { + // TODO: Document the convention of `parseIntoResult`, and that parsing validators can take this from the context to determine whether the result is going to be ignored (which means it may not have to parse in the first place) + let rulesWithParsingDisabled = withContext(rules, { parseIntoResult: false }); + return combinator((value, applyValidators, context) => { - let result = applyValidators(value, rules, context); + let result = applyValidators(value, rulesWithParsingDisabled, context); return validationResult({ errors: result.errors, diff --git a/package.json b/package.json index d992e86..a0664c4 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "@validatem/combinator": "^0.1.2", - "@validatem/validation-result": "^0.1.2" + "@validatem/validation-result": "^0.1.2", + "@validatem/with-context": "^0.1.2" } } diff --git a/yarn.lock b/yarn.lock index cdb8728..170b520 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21,7 +21,7 @@ "@validatem/virtual-property" "^0.1.0" default-value "^1.0.0" -"@validatem/combinator@^0.1.0", "@validatem/combinator@^0.1.2": +"@validatem/combinator@^0.1.0", "@validatem/combinator@^0.1.1", "@validatem/combinator@^0.1.2": version "0.1.2" resolved "https://registry.yarnpkg.com/@validatem/combinator/-/combinator-0.1.2.tgz#eab893d55f1643b9c6857eaf6ff7ed2a728e89ff" integrity sha512-vE8t1tNXknmN62FlN6LxQmA2c6TwVKZ+fl/Wit3H2unFdOhu7SZj2kRPGjAXdK/ARh/3svYfUBeD75pea0j1Sw== @@ -128,6 +128,13 @@ resolved "https://registry.yarnpkg.com/@validatem/virtual-property/-/virtual-property-0.1.0.tgz#880540dfd149f98ecf1095d93912e34443381fe4" integrity sha512-JUUvWtdqoSkOwlsl20oB3qFHYIL05a/TAfdY4AJcs55QeVTiX5iI1b8IoQW644sIWWooBuLv+XwoxjRsQFczlQ== +"@validatem/with-context@^0.1.2": + version "0.1.2" + resolved "https://registry.yarnpkg.com/@validatem/with-context/-/with-context-0.1.2.tgz#3645c04897664f70995104961277e07b61b4f615" + integrity sha512-noAWf4CsmU+BCz+KOg3GPq9+R9BQLWOQnOgWVfkYHFdLnnbLhl8w/ONdzvFzUYGHIZGKZwsWVCp+Kwz/tAfMnA== + dependencies: + "@validatem/combinator" "^0.1.1" + as-expression@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/as-expression/-/as-expression-1.0.0.tgz#7bc620ca4cb2fe0ee90d86729bd6add33b8fd831"