Table validation presenter for Unifig
Transforms configuration validation errors into clear table.
Table of contents
Installation
npm i @unifig/validation-presenter-table
yarn add @unifig/validation-presenter-table
Quick Start
import { Config, PlainConfigAdapter } from '@unifig/core';
import { toTable } from '@unifig/validation-presenter-table';
async function bootstrap() {
const validationError = await Config.register({
templates: [StorageOptions, NetworkOptions],
adapter: new PlainConfigAdapter({}),
});
if (validationError) {
console.error(toTable(validationError));
process.exit(1);
}
}
bootstrap();
Example output
┌──────────────────┬─────────────┬────────┬─────────────┬───────────────┬────────────────────┐
│ Template │ Property │ Type │ Source │ Current Value │ Failed constraints │
├──────────────────┼─────────────┼────────┼─────────────┼───────────────┼────────────────────┤
│ │ port │ Number │ PORT │ "not-a-port" │ isInt │
│ ├─────────────┼────────┼─────────────┼───────────────┼────────────────────┤
│ TemplateMock │ db.url │ String │ DB_URL │ undefined │ isString │
│ ├─────────────┼────────┼─────────────┼───────────────┼────────────────────┤
│ │ db.password │ String │ DB_PASSWORD │ undefined │ isString │
└──────────────────┴─────────────┴────────┴─────────────┴───────────────┴────────────────────┘
Source
column presents where property value was taken from.
Example: from env variables in case of Env Adapter.
License
This project is licensed under the MIT License - see the LICENSE file for details.