
Security News
New CNA Scorecard Tool Ranks CVE Data Quality Across the Ecosystem
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
@overture-stack/lectern-client
Advanced tools
TypeScript client to interact with Lectern servers and perform data validation versus Lectern dictionaries.
The Lectern Client provides developers TypeScript code tools to interact with Lectern servers and Lectern Dictionaries. This package provides data processing functions that will parse and validate submitted data, ensuring that it adheres to the structure defined by the Dictionary. It also provides a REST client to fetch Lectern Dictionary data from a Lectern Server.
Data fetching from a lectern service can be perfromed through the rest
module:
import * as lectern from '@overture-stack/lectern-client';
const lecternUrl = 'http://lectern.example.com';
const dictionaryName = 'my-example-schemas';
const dictionaryVersion = '2.3';
const allAvailableDictionariesResult = await lectern.rest.listDictionaries(lecternUrl);
const filteredByNameDictionariesResult = await lectern.rest.listDictionaries(lecternUrl, { name: dictionaryName });
const exampleDicionaryResult = await lectern.rest.getDictionary(lecternUrl, {
name: dictionaryName,
version: dictionaryVersion,
});
if (exampleDicionaryResult.success) {
// use the data:
console.log(JSON.stringify(exampleDicionaryResult.data));
}
Responses from the rest calls will be Result
objects. Before using the data, check that exampleDicionaryResult.success
is true, and if so, you can get the fully typed response data in exampleDicionaryResult.data
.
The following example shows how to process data using the Lectern Client. The input donorData
is presented as hardcoded, but in a typical scenario this would be submitted to the application through an uploaded TSV, form entry, or similar user submission system.
To process data records which all belong to the same schema we use the processSchema
function:
import * as lectern from '@overture-stack/lectern-client';
import type { Dictionary } from '@overture-stack/lectern-client';
const dictionary: Dictionary; // You will need to provide or fetch the dictionary
const donorData = [{submitter_donor_id: "abc123", gender: "Male", age: "28"}, {submitter_donor_id: "def456", gender: "Female", age: "37"}]
const schemaProcessingResult = lectern.process.processSchema(dictionary, "donors", donorData);
switch (schemaProcessingResult.status) {
case 'SUCCESS': {
const { records } = schemaProcessingResult;
// use converted and validated records
}
case 'ERROR_PARSING': {
const { errors, records } = schemaProcessingResult;
// errors occured parsing records. read the errors that occurred
// records have been return with their values parsed where possible. If an error occurred, the original input string value is returned
}
case 'ERROR_VALIDATION': {
const { records, errors } = schemaProcessingResult;
// errors occured validating records. these errors have been returned
// records were parsed successfully, so this returns all parsed records
}
The function createDataFileTemplate
can be used to create the content of a TSV or CSV formatted template file, based on the fields in a Lectern Schema. This file content includes a header row with all field names for the schema, and a blank row with delimeters for each field. Also provided is a filename for the file, which is the schema name and the appropriate file extension for the TSV or CSV.
This template file can be used to collect data for validation using Lectern.
This function does not produce an actual file or any file system interaction or download, just the expected content and filename.
import * as lectern from '@overture-stack/lectern-client';
import type { Schema } from '@overture-stack/lectern-client';
const schema: Schema; // You will need to provide or fetch a dictionary schema
const dataFileTemplate = lectern.createDataFileTemplate(schema); // tsv by default
const tsvFileContent = dataFileTemplate.content;
const tsvFileName = dataFileTemplate.filename;
Example with CSV file:
// specify csv
const csvFileTemplate = lectern.createDataFileTemplate(schema, { fileType: 'csv' });
Custom delimiter:
// txt file with | as delimiter
const customFileTemplate = lectern.createDataFileTemplate(schema, { delimiter: '|', extension: 'txt' });
The Lectern Client is a wrapper around Lectern submodules that allow functionality to be shared between client and server implementations. If you do not need the REST client, or the combined processing functions, you can consider including submodules directly to access the specific pieces of functionality you require.
Package | Description |
---|---|
lectern-dictionary | Definition of the Lectern Dictionary structure. Includes TS types and schemas for validating the content of Lectern dictionary. Also includes functionality to comparing multiple Lectern Dictionary versions, and to analyze the differences between them. |
lectern-validation | Provides functionality for validating data against a Lectern dictionary. |
FAQs
TypeScript client to interact with Lectern servers and perform data validation versus Lectern dictionaries.
The npm package @overture-stack/lectern-client receives a total of 2 weekly downloads. As such, @overture-stack/lectern-client popularity was classified as not popular.
We found that @overture-stack/lectern-client 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
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.