|
|
1 жил өмнө | |
|---|---|---|
| .. | ||
| src | 5f5a74d2cc Add renderers-js-umi package (#12) | 1 жил өмнө |
| test | dbbdf9ec20 Use vitest as a test framework (#18) | 1 жил өмнө |
| .gitignore | 586b3e6fb0 Add validators package (#7) | 1 жил өмнө |
| .prettierignore | bb2289e537 Make prettier ignore CHANGELOG.md files | 1 жил өмнө |
| CHANGELOG.md | 05e7fe0668 [0.21] Publish packages (#205) | 1 жил өмнө |
| LICENSE | 586b3e6fb0 Add validators package (#7) | 1 жил өмнө |
| README.md | f883c88094 Add package documentation — Part 2: renderers and validators (#105) | 1 жил өмнө |
| package.json | 05e7fe0668 [0.21] Publish packages (#205) | 1 жил өмнө |
| tsconfig.declarations.json | 586b3e6fb0 Add validators package (#7) | 1 жил өмнө |
| tsconfig.json | 586b3e6fb0 Add validators package (#7) | 1 жил өмнө |
This package offers a set of validation rules for Kinobi IDLs to ensure that they are correctly formatted.
pnpm install @kinobi-so/validators
[!NOTE] This package is included in the main
kinobipackage. 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.ts 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.ts 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.
ts 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')); ```