0.22.0 • Published 9 months ago

@kinobi-so/validators v0.22.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Kinobi ➤ Validators

npm npm-downloads

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 = {
    // The level of importance of a validation item.
    level: 'debug' | 'trace' | 'info' | 'warn' | 'error';
    // A human-readable message describing the issue or information.
    message: string;
    // The node that the validation item is related to.
    node: Node;
    // The stack of nodes that led to the node above.
    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';

// Throw if any "error" items are found.
kinobi.accept(throwValidatorItemsVisitor(getValidationItemsVisitor()));

// Throw if any "warn" or "error" items are found.
kinobi.accept(throwValidatorItemsVisitor(getValidationItemsVisitor(), 'warn'));
0.21.5

10 months ago

0.22.0

9 months ago

0.21.0

12 months ago

0.20.6

12 months ago

0.21.4

11 months ago

0.20.5

1 year ago

0.21.3

11 months ago

0.20.4

1 year ago

0.21.2

11 months ago

0.21.1

11 months ago

0.20.3

1 year ago

0.20.2

1 year ago

0.20.1

1 year ago

0.20.0

1 year ago