Record validation/normalization module.
- Implements:
Requires
Classes
Mixins
Methods
-
<static> addDefaultValidators(desc, validators)
-
Can be used by record types library extensions to add validators to the default set of validators on a record type or property descriptor. Note that the validators module installs validators on properties and record types in an
onContainerCompletehandler, so extensions must call this function before that.Parameters:
Name Type Description descmodule:x2node-records~RecordTypeDescriptor | module:x2node-records~PropertyDescriptor The descriptor. May not be a view. validatorsObject.<string, Array.<(string|Array)>> Validator specifications as would be provided on the definition. -
<static> createValidationErrors()
-
Create new, empty validation errors object.
Returns:
Validation errors object. -
<static> dep(depPtrs, validatorFunc)
-
Create validator function that checks that specified properties in the context do not have any errors.
Parameters:
Name Type Description depPtrsArray.<string> JSON pointers for properties, none of which should have errors for the validator to be invoked. validatorFuncmodule:x2node-validators.curriedValidator The validator function to invoke if all dependency properties are valid. The returned value is ignored. Returns:
Single-element array with the resulting validator function.- Type
- Array.<module:x2node-validators.validator>
-
<static> isSupported(obj)
-
Tell if the provided object is supported by the module. Currently, only a record types library instance can be tested using this function and it tells if the library was constructed with the
x2node-validatorsextension.Parameters:
Name Type Description obj* Object to test. Returns:
trueif supported by the validators module.- Type
- boolean
-
<static> isValidationErrors(obj)
-
Tell if the provided object is a validation errors object.
Parameters:
Name Type Description obj* The object to test. Returns:
trueif instance of ValidationErrors.- Type
- boolean
-
<static> listpat(list)
-
Create regular expression for a list of valid values. Useful with the "pattern" standard validator.
Parameters:
Name Type Description listArray.<string> List of valid values. Returns:
The resular expression.- Type
- RegExp
-
<static> normalizeRecord(recordType, recordTypeName, record [, lang] [, validationSets])
-
Validate and normalize the specified record.
Parameters:
Name Type Argument Description recordTypemodule:x2node-records~RecordTypesLibrary Record types library. recordTypeNamestring Record type name. recordObject The record to validate. May not be nullorundefined.langstring <optional>
Language for the error messages in the same format as used by the HTTP's "Accept-Language" request header. If not provided, "*" is assumed. validationSetsstring <optional>
Comma-separated validation set names. If not provided, the default validation set is used. Throws:
-
If unknown record type, record was not provided or invalid language or validation set specification.
Returns:
Errors if the record is invalid, ornullif it has been successfully validated and normalized. -
-
<static> registerValidationErrorMessage(ctx, messageId, messageDef)
-
Can be used by record types library extensions to register additional validation error messages available to the library. Depending on where the function is called the registred message scope is determined. For example, if called in the extention's
extendRecordTypesLibrary()method, the message is registred for the whole library.Parameters:
Name Type Description ctxmodule:x2node-records~LibraryConstructionContext Library construction context. messageIdstring Message identifier. messageDefObject.<string, string> Message definition. The keys are language codes, the values are message templates. -
<static> registerValidator(ctx, validatorId, Validator)
-
Can be used by record types library extensions to register additional validators available to the library. Depending on where the function is called the registred validator scope is determined. For example, if called in the extention's
extendRecordTypesLibrary()method, the validator is registred for the whole library.Parameters:
Name Type Description ctxmodule:x2node-records~LibraryConstructionContext Library construction context. validatorIdstring Validator id. Validatormodule:x2node-validators.validator function. -
<static> replaceDefaultValidators(desc, validators)
-
Can be used by record types library extensions to replace the default set of validators on a record type or property descriptor. Note that the validators module installs validators on properties and record types in an
onContainerCompletehandler, so extensions must call this function before that.Parameters:
Name Type Description descmodule:x2node-records~RecordTypeDescriptor | module:x2node-records~PropertyDescriptor The descriptor. May not be a view. validatorsObject.<string, Array.<(string|Array)>> Validator specifications as would be provided on the definition.
Type Definitions
-
curriedValidator(ctx, value)
-
Validator/normalizer function curried with the parameters.
Parameters:
Name Type Description ctxmodule:x2node-validators~ValidationContext Current validation context. value* The value to validate/normalize. Returns:
Normalized value, which, if different from the current value, is set back into the record object.- Type
- *
-
validator( [params], ctx, value)
-
Validator/normalizer function.
Parameters:
Name Type Argument Description paramsArray <optional>
Validator parameters from the subject definition. ctxmodule:x2node-validators~ValidationContext Current validation context. value* The value to validate/normalize. Returns:
Normalized value, which, if different from the current value, is set back into the record object.- Type
- *