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

tbs-site-config

v0.0.8

Published

Package for handling site config distribution between repository. Which site config data saved on server memory as variable, so data can be consumed much faster than HTTP request.

Downloads

101

Readme

TBS Site Configs

Package for handling site config distribution between repository. Which site config data saved on server memory as variable, so data can be consumed much faster than HTTP request.

Installation

Yarn

yarn add tbs-site-config

NPM

npm install tbs-site-config

Getting Started

For initializing package you need to write in 2 file

app.module.ts

  • Master repository initialization
import { TbsSiteConfigModule } from 'tbs-site-config';

@Module({
  imports: [
    TbsSiteConfigModule.registerAsync({
      options: {
        name: "redis", // this line will be overrided on library, so you can write as you want caused it wont be used
        transport: Transport.REDIS,
        options: { port: +process.env.REDIS_PORT, host: process.env.REDIS_HOST },
      },
      isMaster: true,
      mongoDbUrl: process.env.MONGO_URL,
      mongoDbName: "tbs_db_utils",
      mongoDbCollection: SiteConfig.name.toLowerCase() + "s",
    })
  ],
  controllers: [],
  providers: [],
})
export class ExampleModule {}

The initialization code above is intended for the master repository, which means that the repository is the one that owns and manipulates the site config data. isMaster being filled with true indicates that this is the master repository

  • client repository initialization
import { TbsSiteConfigModule } from 'tbs-site-config';

@Module({
  imports: [
    TbsSiteConfigModule.registerAsync({
      configUrl: process.env.UTIL_SERVICE_URL + "/api/v1/configs",
      options: {
        name: "redis", // this line will be overrided on library, so you can write as you want caused it wont be used
        transport: Transport.REDIS,
        options: { port: +process.env.REDIS_PORT, host: process.env.REDIS_HOST },
      },
    })
  ],
  controllers: [],
  providers: [],
})
export class ExampleModule {}

On client repository only need the config url for fetching initial data from that endpoint.

main.ts

import {TbsSiteConfigServer} from 'tbs-site-config'

TbsSiteConfigServer(app, {
  transport: Transport.REDIS,
  options: { port: +process.env.REDIS_PORT, host: process.env.REDIS_HOST },
});

await app.startAllMicroservices();

Master and client repository must initialize above code for start the microservice server. Which microservice server will be used for listening any changes on master repository

Get The Site Config

import { SITE_CONFIGS } from 'tbs-site-config';

@Injectable()
export class SiteConfigService {
  constructor(
    @Inject(SITE_CONFIGS) private readonly siteConfig: Record<string, any>,
  ) {
  }

  async findAll() {
    return this.siteConfig;
  }
  
  async findOne(key: string) {
    return this.siteConfig[key]
  }
}

note: While injecting site config the data type is must be Record<string,any> also for accessing single data you must pass the key

Update The Site Config

import { TbsSiteConfigService, SITE_CONFIGS } from 'tbs-site-config';

@Controller()
export class SiteConfigController {
  constructor(
    private readonly siteConfigService: TbsSiteConfigService,
    @Inject(SITE_CONFIGS) private readonly siteConfig: Record<string, any>
  ) {
  }

  async updateOne(key: string, data: Record<string, any>) {
    return this.siteConfigService.update(data);
  }
  
  async updateSpecificField(key: string, value: string, status: number) {
    return this.siteConfigService.update({ ...this.siteConfig[key], value, status });
  }
}

note: To modify the current data, it only supports modifying all the data, and cannot only modify some or certain fields