Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Continue validation in production env #279

Open
andrewcharnley opened this issue May 2, 2017 · 3 comments
Open

Continue validation in production env #279

andrewcharnley opened this issue May 2, 2017 · 3 comments

Comments

@andrewcharnley
Copy link

andrewcharnley commented May 2, 2017

Presently there are a bunch of NODE_ENV checks which disable validation in production. As we're mostly using flow rather than tcomb specific checks this appears to be doing much the same as stripping the flow out. If some checking continues but is watered down for performance reasons we may not catch the logic switch upon production, and no documentation exists to explain it. We'd rather the logic was environment agnostic, settable by config.

Although we may not always want production validation (it could be per module based) we definitely need it for function input arguments, simply to cut down on manual typeof checks, thus as a starting point we need the NODE_ENV check to be configurable. The best means to do this I believe is by a flag on the library, which can additionally be set via a new .babelrc 'tcomb' plugin flag.

@andrewcharnley
Copy link
Author

andrewcharnley commented May 2, 2017

In addition this plugin flag should be an object with something like;

check: {
inputs: boolean (fn args),
internal: boolean
output: boolean (fn return)
}

@rjhilgefort
Copy link

Bump. Would like to see this change as well.

@beac0n
Copy link
Contributor

beac0n commented Jun 23, 2018

We should make something like a big HINT sign in the docs, because this behaviour is only documented with one small sentence and completly caught me off guard, because the behaviour only occured in production.

I ended up using tcomb-validation and this function, to reproduce the same error throwing behaviour:

import * as T from 'tcomb-validation';
const throwIfInvalidCreator = (type: T.Type) => (value: any): any => {
	const validation = T.validate(value, type);
	return validation.isValid() ? value : T.fail(validation.firstError().message);
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants