
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
@overture-stack/lectern-validation
Advanced tools
Logic for validating data using a Lectern dictionary
Note
This may not be the module you are looking to import.
This is a sub-module used as a dependency by both the Lectern Client and Lectern Server.
If you are building an application that will interact with a Lectern Server over HTTP, or wants to validate data using a Lectern Dictionary, you likely want to import the Lectern Client.
This package provides tools to parse and validate data based on the schemas in Lectern Dictionaries.
Parsing data involves reading string values for fields defined in a Lectern Schema and converting the values into properly typed data. For example, if a field has "dataType": "number"
and the provided value "123"
this will be converted from the string value into the numeric 123
. A more complicated example would take a comma-separated array value, convert each element, and return the final array. If any values cannot be properly parsed and converted based on the schema's rules, an error is returned instead.
There are four separate parsing functions exported, mapping to different collections of data to be processed together:
parseFieldValue
: Parse a string value for an individual field.parseRecordValues
: Parse all fields in an UnprocessedDataRecord based on a schema definition. Applies parseFieldValue
to each field.parseSchemaValues
: Parse all records in a collection belonging to an individual schema. Applies parseRecordValues
to each record.parseDictionaryValues
: Parse all records for multiple schemas in a dictionary. Applies parseSchemaValues
to each array of records provided.Each parsing function will return a Result object that indicates if the parsing completed successfully. When parsing completes without any errors the response will include the parsed data with all fields converted to the correct type.
If the parsing failed, part of the response will be an array of errors indicating which record and which fields had parsing errors. The response will also include the partially parsed data record(s); fields that were succesfully parsed will have been updated to their correct data types, but fields that failed to parse will still contain their original string values.
Validation functions are provided to test parsed DataRecords with all restrictions defined in a Lectern dictionary. These functions will identify all restrictions that must be tested from the provided schema and apply these to the given data, including resolving conditional restrictions. Different restrictions are applied depending on which data collection is provided; validating an individual fields will only test field level restrictions, while validating a whole schema will also validated unique
and uniqueKey
constraints.
There are four main validation functions, provided to validate data at the field, record, schema, and dictionary levels:
validateField
: Validate the field value, testing all field level restrictions such as regex
, and codeList
validateRecord
: Validate all fields in a record, testing that all fields belong to that schema, that all required fields are present, and applying validateField
to all fields in the record.validateSchema
: Validate a collection of records from a single schema, testing all unique
and uniqueKey
requirements for that schema and then applying validateRecord
to all records.validateDictionary
: Validates multiple collections of records each belonging to schemas from a dictionary. This checks that each schema specified is a member of the given dictionary, and tests foreignKey
restrictions on each schema, in addition to applying validateSchema
to each colleciton.All validation functions return a TestResult
object that will indicate if the validation passed or failed. If the validation is successful then this result will simply indicate that the data is valid. If there were any errors then the response will include a error information.
FAQs
Logic for validating data using a Lectern dictionary
The npm package @overture-stack/lectern-validation receives a total of 33 weekly downloads. As such, @overture-stack/lectern-validation popularity was classified as not popular.
We found that @overture-stack/lectern-validation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.