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

@synanetics/settings-mixin

v2.0.0

Published

Mixin for Moleculer JS service to apply JSON settings resolved by file pattern

Downloads

14

Readme

@synanetics/settings-mixin

Settings Mixin for Moleculer JS services. The mixin will attempt to resolve a local (default) settings file named after your service. Resolve environment configured overrides. Merge setting values into the service settings.

It will validate that default and override settings are structured correctly. It will also optionally look at the services existing settings.schema property and apply this validation schema to the resolved values.

Usage

const { settingsMixinSchema } = require('@synanetics/settings-mixin');
// or
import { settingsMixinSchema } from '@synanetics/settings-mixin';

...

const someService: ServiceSchema {
  name: 'some',
  mixins: [settingsMixinSchema],
}

Defaults

For this mixin to work you must provide a default settings file co-located with your service. Assume you have a service like above:

some.service.ts

const someService: ServiceSchema {
  name: 'some',
  mixins: [settingsMixinSchema],
}

then a corresponding file named some.settings.json must exist. For the structure of the contents please follow this guidance on settings-resolver defaults.

Overrides

The mixin will look for an environment variable following the name of the service. For example some.service.ts with name: 'some' would attempt to check process.env.SOME_SETTINGS. Please follow the guidance on settings-resolver overrides to see what this value can be.

If the service specific environment variable cannot be found, the mixin will fallback to checking process.env.SETTINGS. If both are undefined just the default file values will be set on the service settings.

Value Validation

You can optionally supply additional validation schema to apply to the resolved settings to ensure that your values conform as expected. This is done by setting the service settings.schema to the desired validation schema. There is additional guidance on settings-resolver additional validation but you would look to define a fastest-validator compliant schema.

some.service.ts

const someService: ServiceSchema {
  name: 'some',
  settings: {
    schema: { ...your validation schema },
  },
  mixins: [settingsMixinSchema],
}

Errors

Any errors encountered are raised as Moleculer JS specific MoleculerError or ValidationError.