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

@qiwi/nestjs-enterprise-config

v5.2.2

Published

Config module for nestjs enterprise

Downloads

167

Readme

@qiwi/nestjs-enterprise-config

Nestjs module for processing uniconfig-based configs.

Installation

yarn add @qiwi/nestjs-enterprise-config

Configuration

Static import

import { Module } from '@nestjs/common'
import { ConfigModule } from "@qiwi/nestjs-enterprise-config"

@Module({
  imports: [
    ConfigModule,
    // and so on
  ],
})

export class AppModule {}

Import as dynamic module.

see uniconfig-plugin-path

@Module({
  imports: [
    ConfigModule.register({
      // Absolute or relative path to the config file
      path: '/custom/config/path.json'
      // use <root> or <cwd> tag to form the path.
      // path: '<root>/custom/config/path.json'
    }),
  ]
})

export class AppModule {}

Validation

Module looks for app config json schema in ${process.cwd()}/config/app.config.schema.json and validates output of uniconfig pipeline.

If file is absent, then no validation is performed.

You can specify path to app config schema via opts.schemaPath in ConfigModule.register

app.config.schema.json example:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "local": {
      "type": "string"
    },
    "server": {
      "type": "object",
      "properties": {
        "port": {
          "type": "number"
        },
        "host": {
          "type": "string"
        }
      },
      "required": [
        "port",
        "host"
      ]
    },
    "logger": {
      "type": "object",
      "properties": {
        "level": {
          "type": "string"
        }
      },
      "required": [
        "level"
      ]
    }
  },
  "required": [
    "name",
    "server",
    "logger"
  ]
}

You can also write schema for config file, for example in config.schema.json:

{
  "properties": {
    "data": {
      "$ref": "./app.config.schema.json"
    },
    "$schema": {
      "type": "string"
    }
  },
  "required": ["data"],
  "additionalProperties": {
    "sources": {
      "type": "object"
    }
  }
}

And reference it in your config file to enable IDE suggestions and error highlighting:

{
  "$schema": "./config.schema.json",
  "data": {
    "name": "jslab-gen-api",
    "local": "$env:LOCAL",

    "server": {
      "port": 8080,
      "host": "$host:"
    },

    "logger": {
      "level": "debug"
    }
  },

  "sources": {
    "env": {
      "pipeline": "env"
    },
    "host": {
      "pipeline": "ip"
    }
  }
}

Usage

@Injectable()
export class MyService {
  constructor(@Inject('IConfigService') config: IConfigService) {}

  myMethod() {
    return this.config.get('name')
  }
}

Uniconfig plugins

api-file

read json file

{
  "data": {
    "test": "$testFile:"
  },
  "sources": {
    "testFile": {
      "data": ["config/ci.json"],
      "pipeline": "file>json"
    }
  }
}

api-http

read json from url

{
  "data": {
    "test": "$testWeb:"
  },
  "sources": {
    "testWeb": {
      "data": "URL",
      "pipeline": "http>json"
    }
  }
}

argv

read args

{
  "data": {
    "param": "$test:"
  },
  "sources": {
    "test": {
      "pipeline": "argv"
    }
  }
}
//node target/es6/main --foo=bar
config.get('param') // { _: [], foo: 'bar', '$0': 'target/es6/main' }

datatree

{
  "data": {
    "test": "$test1:"
  },
  "sources": {
    "test1": {
      "data": {
        "test.test": "test1",
        "test.foo": {
          "bar":"baz"
        }
      }
    }
  }
}
config.get('test') // { 'test.test': 'test1', 'test.foo': { bar: 'baz' } }

dot

use doT template

{
  "data": {
    "test": "$test1:"
  },
  "sources": {
    "test1": {
      "data": {
        "data": {
          "data": {
            "foo": "FOO",
            "baz": "BAZ"
          },
          "template": "{{=it.foo}}-bar-{{=it.baz}}"
        }
      },
      "pipeline": "datatree>dot"
    }
  }
}
config.get('test') // FOO-bar-BAZ

env

read ENV variables

{
  "data": {
    "test": "$env:LOCAL"
  },
  "sources": {
    "env": {
      "pipeline": "env"
    }
  }
}
//LOCAL=true node target/es6/main
config.get('test') // true

ip

IP/host resolver

{
  "data": {
    "test": "$host:"
  },
  "sources": {
    "host": {
      "pipeline": "ip"
    }
  }
}
config.get('test') // 192.168.3.5

pkg

read package.json

{
  "data": {
    "test": "$pkg:"
  },
  "sources": {
    "pkg": {
      "pipeline": "pkg"
    }
  }
}
config.get('test') // { name: '', version: '0.0.0', description: '' ...etc }

ConfigService tries to read config file from <cwd>/config/${process.env.ENVIRONMENT_PROFILE_NAME}.json.

If it does not exist, then module will read from <cwd>/config/kube.json (DEFAULT_KUBE_CONFIG_PATH).

If process.env.LOCAL is truthy, then service will read from <cwd>/config/local.json (DEFAULT_LOCAL_CONFIG_PATH).

API

Class ConfigModule

Exports ConfigService with token IConfigService

static register (opts?: { path?: string, schemaPath?: string }): DynamicModule

opts.path path to config file

opts.schemaPath path to app config schema (config.data)

Function resolveConfigPath

resolveConfigPath (path?: string, local?: boolean, env?: string): string

DEFAULT_KUBE_CONFIG_PATH

<cwd>/config/kube.json

DEFAULT_LOCAL_CONFIG_PATH

<cwd>/config/local.json

Docs