I am looking at celebrate.js . Object internals
internals
{
DEFAULT_ERROR_ARGS: { celebrated: true },
DEFAULT_ERRORS_OPTS: { statusCode: 400 },
DEFAULT_CELEBRATE_OPTS: { mode: 'partial' }
}
Different actions are applied to this object later.
internals.validateSegment = (segment) => (spec, joiConfig) => {
const finalValidate = (req) => spec.validateAsync(req[segment], joiConfig);
finalValidate.segment = segment;
return finalValidate;
};
What do internals represent?
The internals
object holds a set of default options (called segments here). They are accessed by their identifiers DEFAULT_ERROR_ARGS
, DEFAULT_ERRORS_OPTS
and DEFAULT_CELEBRATE_OPTS
.
The segments are object themselves, that contain options (eg celebrated
) and their default values (eg true
).
All segments of internals
can be passed to and validated by validateSegment()
. Each property is defined by a key (here: spec
) and a value (here: joiConfig
). For each specification the function validateAsync()
is called and the result is assigned to finalValidate
.
The function validateSegment()
can be called for individual segments. See function maybeValidateBody()
in the code that you linked to, for example:
internals.maybeValidateBody = (segment) => {
const validateOne = internals.validateSegment(segment); <-- Called here!
return (spec, joiConfig) => {
...
In the above code block, the segment
is passed to internals.validateSegment()
and the return value is assigned to validateOne
, for example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.