Kinobi ➤ Validators
![npm-downloads](https://img.shields.io/npm/dm/@kinobi-so/validators.svg?style=flat)
This package offers a set of validation rules for Kinobi IDLs to ensure that they are correctly formatted.
Installation
pnpm install @kinobi-so/validators
[!NOTE]
This package is included in the main kinobi
package. Meaning, you already have access to its content if you are installing Kinobi this way.
pnpm install kinobi
Types
ValidationItem
A validation item describes a single piece of information — typically a warning or an error — about a node in the Kinobi IDL.
type ValidationItem = {
level: 'debug' | 'trace' | 'info' | 'warn' | 'error';
message: string;
node: Node;
stack: readonly Node[];
};
Functions
getValidationItemsVisitor(visitor)
The getValidationItemsVisitor
function returns a visitor that collects all validation items from a Kinobi IDL. Note that this visitor is still a work in progress and does not cover all validation rules.
import { getValidationItemsVisitor } from '@kinobi-so/validators';
const validationItems = kinobi.accept(getValidationItemsVisitor());
throwValidatorItemsVisitor(visitor)
The throwValidatorItemsVisitor
function accepts a Visitor<ValidationItemp[]>
and throws an error if any validation items above a certain level are found. By default, the level is set to 'error'
but a second argument can be passed to change it.
import { throwValidatorItemsVisitor, getValidationItemsVisitor } from '@kinobi-so/validators';
kinobi.accept(throwValidatorItemsVisitor(getValidationItemsVisitor()));
kinobi.accept(throwValidatorItemsVisitor(getValidationItemsVisitor(), 'warn'));