@synanetics/settings-mixin
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@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.

Readme

Keywords

none

Package Sidebar

Install

npm i @synanetics/settings-mixin

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

17.6 kB

Total Files

20

Last publish

Collaborators

  • edward-synanetics
  • luke-syn
  • synjy
  • wrobinsonsynanetics
  • whay-syn
  • sarah-gibson
  • lewis-synanetics
  • oliverm-wethey
  • synrichardbrown
  • gregsynanetics
  • tom-synanetics
  • danielpeterbayley
  • leecampbellsynanetics
  • synsteve