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

@beonica/bn.core.config-helper-tool

v1.3.2

Published

Config Helper Tool

Downloads

46

Readme

bn.core.config-helper-tool

Installation

Copy the env files

cp .env.example .env

Install NPM

npm install

Run

npm run start

Run tests

npm run test

Install plugin in a service

Add this plugin and class-validator to the project with NPM

npm i @beonica/bn.core.config-helper-tool
npm i class-validator class-validator-jsonschema

Create a class for each scope with all configs of the service using the validations and types described in the class-validator plugin. Additionally, add JSON Schema definitions to better describe your data models.

class TenantConfig {
    @IsString()
    @Length(10, 20)
    @JSONSchema({
        description: 'The title attribute',
        format: 'text',
    })
    title: string;

    @IsString()
    @Contains('a')
    @Length(10, 20)
    text: string;

    @MaxLength(20, {
        each: true,
    })
    tags: string[];
}

In the project main file, call the plugin passing the service name, a config class and the Redis String Connection.

const configs = new ConfigHelperTool('SERVICE_NAME', new TenantConfig(), {
    redisConnectionString: REDIS_CONNECTION_STRING,
});

General

In the set() and get() method, always use a dot notation.

await configs.get('default','tags.0');
await configs.set('tenant2','param1','A');

The methods getAll() always return a object formatted in dot notation.

The methods that handle sets relates directly to Redis defautl set commands, except for the action commands, like sadd, srem, which response is translated to booleans.

Avoid using dot notation on set names.

Methods

describe()

Converts data model definition into OpenAPI-compatible JSON Schema. Usefull to describe model definitions to APIs and frontend apps.

const configs = new ConfigHelperTool('SERVICE_NAME', new TenantConfig(), {
    redisConnectionString: REDIS_CONNECTION_STRING,
});

config.describe();

setAll(scope:string, values: object)

In this case, the service have to fill the "ServiceConfig" class and pass to this function.

let defaultConfig = new TenantConfig();
defaultConfig.title = 'My Service Title';
defaultConfig.text = 'Used to make something';
defaultConfig.tags = ['a','b','c']

await configs.setAll('default',defaultConfig);

getAll(scope:string)

This method return all configs setted in dot notation for the scope

await configs.getAll('default');
//Response
{
    'title': 'My Service Title',
    'text': 'Used to make something',
    'tags[0]': 'a',
    'tags[1]': 'b',
    'tags[2]': 'c'
}

set(scope:string, key:string, value:string)

This method set only one property for the scope

await configs.set('default','text','Changing Text Property');
await configs.set('tenant0','text','A+A');

get(scope:string, key:string)

This method return one config in dot notation

await configs.get('default','title');
//Response
'My Service Title'
await configs.get('tenant0','text');
//Response
'A'

Dealing with sets

A Redis Set is a list of items, on wich we could store, move, delete and check if given is a member.

All sets must exists under an unique key, the set name. Unlike the get () and set () methods, where you specify a scope, a parameter name and a value, when dealing with sets you specify a scope, the name of the set and the name of the item - which must be a string.

push(scope:string, set:string, item:string)

This method adds an item to set, then return true.

await configs.push('default', 'colors', 'blue');
await configs.push('default', 'colors', 'red');
await configs.push('default', 'colors', 'yellow');

//Response
true
true
true

remove(scope:string, set:string, item:string)

This method removes an item to set, then return true.

await configs.remove('default', 'colors', 'blue');
//Response
true

members(scope:string, set:string)

This method returns an array containing all set members.

await configs.members('default', 'colors');
//Response
['red', 'yellow]

exists(scope:string, set:string, item:string)

This method check if given item is present on set. Returns boolean.

await configs.exists('default', 'colors', 'blue');
//Response
false

await configs.exists('default', 'colors', 'red');
//Response
true

length(scope:string, set:string)

This method returns set cardinality - its length.

await configs.length('default', 'colors');
//Response
2

Publish in NPM

Always change de package version in package.json

npm login
npm publish --access=public