npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@multiversx/sdk-nestjs-cli

v1.0.2

Published

MultiversX configuration schema helper functions

Downloads

244

Readme

npm

General-purpose CLI tool to assist in microservice development

Installation

Ensure that Node.js is installed on your system and then run:

npm install @multiversx/sdk-nestjs-cli -g

This will install the CLI globally so you can use it from anywhere in your terminal.

Expand schema file

To expand a shorthand configuration schema into a JSON schema, use the expand command with the CLI. Specify the input file containing the shorthand schema and the desired output file for the JSON schema:

mxnest schema expand <inputfile> <outputfile>

Assuming you have a shorthand configuration schema in a file named config.yml:

title: config
apps:
  api:
    urls:
      prefix: string
libs:
  common:
    urls:
      api: string
    redis:
      host: string
      port: integer

Run the command:

mxnest schema expand schema.yaml schema.json

This command will transform the shorthand schema in schema.yaml into a JSON schema and save it in schema.json. The resulting JSON schema will look like:

{
  "title": "config",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "apps": {
      "type": "object",
      "properties": {
        "api": {
          "type": "object",
          "properties": {
            "urls": {
              "type": "object",
              "properties": {
                "prefix": {
                  "type": "string"
                }
              },
              "required": ["prefix"],
              "additionalProperties": false
            }
          },
          "required": ["urls"],
          "additionalProperties": false
        }
      },
      "required": ["api"],
      "additionalProperties": false
    },
    "libs": {
      "type": "object",
      "properties": {
        "common": {
          "type": "object",
          "properties": {
            "urls": {
              "type": "object",
              "properties": {
                "api": {
                  "type": "string"
                }
              },
              "required": ["api"],
              "additionalProperties": false
            },
            "redis": {
              "type": "object",
              "properties": {
                "host": {
                  "type": "string"
                },
                "port": {
                  "type": "integer"
                }
              },
              "required": ["host", "port"],
              "additionalProperties": false
            }
          },
          "required": ["urls", "redis"],
          "additionalProperties": false
        }
      },
      "required": ["common"],
      "additionalProperties": false
    }
  },
  "required": ["apps", "libs"],
  "additionalProperties": false
}

Generate schema file from configuration YAML

Use the generate command to create a YAML schema from a YAML configuration file that contains concrete values. This command infers the types from the actual values in the YAML file:

mxnest schema generate <inputfile> <outputfile>

Assuming you have a YAML configuration file named config.yaml:

apps:
  api:
    urls:
      prefix: 'mx-microservice'
libs:
  common:
    urls:
      api: ${API_URL}
    redis:
      host: '127.0.0.1'
      port: 6379

Run the command:

mxnest schema generate config.yaml schema.yaml

This command will infer the types from the values provided in config.yaml and generate a YAML schema like this:

title: config
apps:
  api:
    urls:
      prefix: string
libs:
  common:
    urls:
      api: string
    redis:
      host: string
      port: integer

Generate TypeScript Interfaces

Use the schema types command to generate TypeScript interfaces from a YAML configuration schema. This command converts the schema into TypeScript interfaces, facilitating type safety in development.

mxnest schema types <inputfile> <outputfile>

Assuming you have a YAML configuration schema named schema.yaml:

title: config
apps:
  api:
    urls:
      prefix: string
libs:
  common:
    urls:
      api: string
    redis:
      host: string
      port: integer

Run the command:

mxnest schema types schema.yaml types.ts

This command will generate TypeScript interfaces in types.ts based on the schema provided in schema.yaml. The resulting TypeScript file will look like this:

/* Autogenerated code */

export interface Config {
  apps: {
    api: {
      urls: {
        prefix: string;
      };
    };
  };
  libs: {
    common: {
      urls: {
        api: string;
      };
      redis: {
        host: string;
        port: number;
      };
    };
  };
}