1.0.2 • Published 1 year ago

@unifig/validation-presenter-json v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

JSON validation presenter for Unifig

Transforms configuration validation errors into json string.

JSON of contents

Installation

npm i @unifig/validation-presenter-json
# or
yarn add @unifig/validation-presenter-json

Quick Start

// main.ts
import { Config, PlainConfigAdapter } from '@unifig/core';
import { toJSON } from '@unifig/validation-presenter-json';

async function bootstrap() {
  const validationError = await Config.register({
    templates: [StorageOptions, NetworkOptions],
    adapter: new PlainConfigAdapter({}),
  });
  if (validationError) {
    console.error(toJSON(validationError));
    process.exit(1);
  }
}

bootstrap();

Example output

[
  {
    "template": "StorageOptions",
    "errors": [
      {
        "property": "port",
        "source": "PORT",
        "currentValue": "not-a-port",
        "failedConstraints": [
          {
            "details": "port must be an integer number",
            "name": "isInt"
          }
        ]
      },
      {
        "property": "db",
        "children": [
          {
            "property": "url",
            "source": "DB_URL",
            "failedConstraints": [
              {
                "details": "url must be a string",
                "name": "isString"
              }
            ]
          },
          {
            "property": "password",
            "source": "DB_PASSWORD",
            "failedConstraints": [
              {
                "details": "password must be a string",
                "name": "isString"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "template": "NetworkOptions",
    "errors": [
      {
        "property": "ipRange",
        "failedConstraints": [
          {
            "details": "ipRange must be defined",
            "name": "isDefined"
          }
        ],
        "children": []
      }
    ]
  }
]

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.0.3-dev.4

1 year ago

1.0.3-dev.3

1 year ago

1.0.3-dev.2

1 year ago

1.0.3-dev.0

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.14.2-dev.3

2 years ago

0.13.1-dev.1

2 years ago

0.14.0

2 years ago

0.13.0

2 years ago

0.12.2-dev.11

2 years ago

0.12.2-dev.9

2 years ago

0.12.2-dev.8

2 years ago

0.12.2-dev.7

2 years ago

0.12.2-dev.6

2 years ago

0.12.2-dev.5

2 years ago

0.12.1

2 years ago

0.12.0

2 years ago

0.11.0

2 years ago

0.10.0

3 years ago

0.9.0

3 years ago